import type { Device, Deviceish } from "./device"; import { Shape, Strides } from "./shape"; import { ATypedArray, Dtype } from "./dtype"; import { TensorArrayData, UntypedStorage } from "./storage"; import type { GradientFunction, GradientContext } from "./autograd"; import type { KernelConfigInput, KernelParamsInput } from "./kernel"; import { TensorBase } from "./tensor_base"; export type TensorData = TensorArrayData | ATypedArray | UntypedStorage; export type TensorSpec = { data: TensorData; dtype?: Dtype; requiresGrad?: boolean; device?: Deviceish; shape?: Shape; strides?: Strides; }; export declare class Tensor extends TensorBase { private _device; private _storage; private _dtype; private _shape; private _strides; private _requiresGrad; private _gradFunc; private _gradCtx; grad: Tensor | null; get storage(): UntypedStorage; get dtype(): Dtype; get shape(): Shape; get strides(): Strides; get device(): Device; get isContiguous(): boolean; private get isScalar(); get requiresGrad(): boolean; set requiresGrad(value: boolean); get gradFunc(): GradientFunction | null; constructor(arrayOrSpec: TensorData | TensorSpec, dtype?: Dtype, device?: Deviceish, requiresGrad?: boolean); withShape(shape: Shape, strides: Strides): Tensor; get [Symbol.toStringTag](): string; toString(): string; toArrayAsync(): Promise; runKernelInplace(name: string, config: KernelConfigInput, params: KernelParamsInput, ...additionalInputs: Tensor[]): Tensor; runKernel(name: string, config: KernelConfigInput, params: KernelParamsInput, outputShapes: Shape[], ...additionalInputs: Tensor[]): Tensor[]; detach(): Tensor; setGradientFunction(ctx: GradientContext, gradFunc: GradientFunction): void; backward(gradient?: Tensor): void; expand(shape: Shape): Tensor; mm(other: Tensor): Tensor; t(): Tensor; zero_(): Tensor; /** * ![Plot of abs and its gradient](/plots/abs.svg) * * Calculates: * ```js * output = abs(input) * ``` * * Gradient: * ```js * inputGrad = input == 0 ? 0 : (input > 0 ? outputGrad : -outputGrad) * ``` * * @returns the output tensor */ abs(): Tensor; /** * Alias for `abs`. * * ![Plot of abs and its gradient](/plots/abs.svg) * * Calculates: * ```js * output = abs(input) * ``` * * Gradient: * ```js * inputGrad = input == 0 ? 0 : (input > 0 ? outputGrad : -outputGrad) * ``` * * @returns the output tensor */ absolute(): Tensor; /** * ![Plot of abs and its gradient](/plots/abs.svg) * * Calculates: * ```js * output = abs(input) * ``` * * Gradient: * ```js * inputGrad = input == 0 ? 0 : (input > 0 ? outputGrad : -outputGrad) * ``` * * @returns the output tensor */ abs_(): Tensor; /** * ![Plot of acos and its gradient](/plots/acos.svg) * * Calculates: * ```js * output = acos(input) * ``` * * Gradient: * ```js * inputGrad = -outputGrad / sqrt(1 - input * input) * ``` * * @returns the output tensor */ acos(): Tensor; /** * Alias for `acos`. * * ![Plot of acos and its gradient](/plots/acos.svg) * * Calculates: * ```js * output = acos(input) * ``` * * Gradient: * ```js * inputGrad = -outputGrad / sqrt(1 - input * input) * ``` * * @returns the output tensor */ arccos(): Tensor; /** * ![Plot of acos and its gradient](/plots/acos.svg) * * Calculates: * ```js * output = acos(input) * ``` * * Gradient: * ```js * inputGrad = -outputGrad / sqrt(1 - input * input) * ``` * * @returns the output tensor */ acos_(): Tensor; /** * ![Plot of acosh and its gradient](/plots/acosh.svg) * * Calculates: * ```js * output = acosh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / sqrt(input * input - 1) * ``` * * @returns the output tensor */ acosh(): Tensor; /** * Alias for `acosh`. * * ![Plot of acosh and its gradient](/plots/acosh.svg) * * Calculates: * ```js * output = acosh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / sqrt(input * input - 1) * ``` * * @returns the output tensor */ arccosh(): Tensor; /** * ![Plot of acosh and its gradient](/plots/acosh.svg) * * Calculates: * ```js * output = acosh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / sqrt(input * input - 1) * ``` * * @returns the output tensor */ acosh_(): Tensor; /** * Calculates: * ```js * output = input + other * ``` * * Gradient: * ```js * inputGrad = outputGrad; otherGrad = outputGrad * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @param alpha the alpha value to multiply `other` with * @returns the output tensor */ add(other: Tensor, alpha?: number): Tensor; /** * Calculates: * ```js * output = input + other * ``` * * Gradient: * ```js * inputGrad = outputGrad; otherGrad = outputGrad * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @param alpha the alpha value to multiply `other` with * @returns the output tensor */ add_(other: Tensor, alpha?: number): Tensor; /** * ![Plot of asin and its gradient](/plots/asin.svg) * * Calculates: * ```js * output = asin(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / sqrt(1 - input * input) * ``` * * @returns the output tensor */ asin(): Tensor; /** * Alias for `asin`. * * ![Plot of asin and its gradient](/plots/asin.svg) * * Calculates: * ```js * output = asin(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / sqrt(1 - input * input) * ``` * * @returns the output tensor */ arcsin(): Tensor; /** * ![Plot of asin and its gradient](/plots/asin.svg) * * Calculates: * ```js * output = asin(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / sqrt(1 - input * input) * ``` * * @returns the output tensor */ asin_(): Tensor; /** * ![Plot of asinh and its gradient](/plots/asinh.svg) * * Calculates: * ```js * output = asinh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / sqrt(input * input + 1) * ``` * * @returns the output tensor */ asinh(): Tensor; /** * Alias for `asinh`. * * ![Plot of asinh and its gradient](/plots/asinh.svg) * * Calculates: * ```js * output = asinh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / sqrt(input * input + 1) * ``` * * @returns the output tensor */ arcsinh(): Tensor; /** * ![Plot of asinh and its gradient](/plots/asinh.svg) * * Calculates: * ```js * output = asinh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / sqrt(input * input + 1) * ``` * * @returns the output tensor */ asinh_(): Tensor; /** * ![Plot of atan and its gradient](/plots/atan.svg) * * Calculates: * ```js * output = atan(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / (input * input + 1) * ``` * * @returns the output tensor */ atan(): Tensor; /** * Alias for `atan`. * * ![Plot of atan and its gradient](/plots/atan.svg) * * Calculates: * ```js * output = atan(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / (input * input + 1) * ``` * * @returns the output tensor */ arctan(): Tensor; /** * ![Plot of atan and its gradient](/plots/atan.svg) * * Calculates: * ```js * output = atan(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / (input * input + 1) * ``` * * @returns the output tensor */ atan_(): Tensor; /** * Calculates: * ```js * output = atan2(input, other) * ``` * * Gradient: * ```js * inputGrad = outputGrad * other / (input * input + other * other); otherGrad = -outputGrad * input / (input * input + other * other) * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ atan2(other: Tensor): Tensor; /** * Alias for `atan2`. * * Calculates: * ```js * output = atan2(input, other) * ``` * * Gradient: * ```js * inputGrad = outputGrad * other / (input * input + other * other); otherGrad = -outputGrad * input / (input * input + other * other) * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ arctan2(other: Tensor): Tensor; /** * Calculates: * ```js * output = atan2(input, other) * ``` * * Gradient: * ```js * inputGrad = outputGrad * other / (input * input + other * other); otherGrad = -outputGrad * input / (input * input + other * other) * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ atan2_(other: Tensor): Tensor; /** * ![Plot of ceil and its gradient](/plots/ceil.svg) * * Calculates: * ```js * output = ceil(input) * ``` * * Gradient: * ```js * inputGrad = 0 * ``` * * @returns the output tensor */ ceil(): Tensor; /** * ![Plot of ceil and its gradient](/plots/ceil.svg) * * Calculates: * ```js * output = ceil(input) * ``` * * Gradient: * ```js * inputGrad = 0 * ``` * * @returns the output tensor */ ceil_(): Tensor; /** * Calculates: * ```js * output = other >= 0 ? abs(input) : -abs(input) * ``` * * Gradient: * ```js * var dir = other >= 0 ? (input >= 0 ? 1.0 : -1.0) : (input >= 0 ? -1.0 : 1.0); inputGrad = input == 0.0 ? 0.0 : outputGrad * dir; otherGrad = 0 * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ copysign(other: Tensor): Tensor; /** * Calculates: * ```js * output = other >= 0 ? abs(input) : -abs(input) * ``` * * Gradient: * ```js * var dir = other >= 0 ? (input >= 0 ? 1.0 : -1.0) : (input >= 0 ? -1.0 : 1.0); inputGrad = input == 0.0 ? 0.0 : outputGrad * dir; otherGrad = 0 * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ copysign_(other: Tensor): Tensor; /** * ![Plot of cos and its gradient](/plots/cos.svg) * * Calculates: * ```js * output = cos(input) * ``` * * Gradient: * ```js * inputGrad = -outputGrad * sin(input) * ``` * * @returns the output tensor */ cos(): Tensor; /** * ![Plot of cos and its gradient](/plots/cos.svg) * * Calculates: * ```js * output = cos(input) * ``` * * Gradient: * ```js * inputGrad = -outputGrad * sin(input) * ``` * * @returns the output tensor */ cos_(): Tensor; /** * ![Plot of cosh and its gradient](/plots/cosh.svg) * * Calculates: * ```js * output = cosh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * sinh(input) * ``` * * @returns the output tensor */ cosh(): Tensor; /** * ![Plot of cosh and its gradient](/plots/cosh.svg) * * Calculates: * ```js * output = cosh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * sinh(input) * ``` * * @returns the output tensor */ cosh_(): Tensor; /** * ![Plot of deg2rad and its gradient](/plots/deg2rad.svg) * * Calculates: * ```js * output = input * 0.017453292519943295 * ``` * * Gradient: * ```js * inputGrad = outputGrad * 0.017453292519943295 * ``` * * @returns the output tensor */ deg2rad(): Tensor; /** * ![Plot of deg2rad and its gradient](/plots/deg2rad.svg) * * Calculates: * ```js * output = input * 0.017453292519943295 * ``` * * Gradient: * ```js * inputGrad = outputGrad * 0.017453292519943295 * ``` * * @returns the output tensor */ deg2rad_(): Tensor; /** * Calculates: * ```js * output = input / other * ``` * * Gradient: * ```js * inputGrad = outputGrad / other; otherGrad = -outputGrad * input / (other * other) * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @param alpha the alpha value to multiply `other` with * @returns the output tensor */ div(other: Tensor, alpha?: number): Tensor; /** * Alias for `div`. * * Calculates: * ```js * output = input / other * ``` * * Gradient: * ```js * inputGrad = outputGrad / other; otherGrad = -outputGrad * input / (other * other) * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @param alpha the alpha value to multiply `other` with * @returns the output tensor */ divide(other: Tensor, alpha?: number): Tensor; /** * Calculates: * ```js * output = input / other * ``` * * Gradient: * ```js * inputGrad = outputGrad / other; otherGrad = -outputGrad * input / (other * other) * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @param alpha the alpha value to multiply `other` with * @returns the output tensor */ div_(other: Tensor, alpha?: number): Tensor; /** * ![Plot of exp and its gradient](/plots/exp.svg) * * Calculates: * ```js * output = exp(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * exp(input) * ``` * * @returns the output tensor */ exp(): Tensor; /** * ![Plot of exp and its gradient](/plots/exp.svg) * * Calculates: * ```js * output = exp(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * exp(input) * ``` * * @returns the output tensor */ exp_(): Tensor; /** * ![Plot of exp2 and its gradient](/plots/exp2.svg) * * Calculates: * ```js * output = exp2(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * exp2(input) * 0.6931471805599453 * ``` * * @returns the output tensor */ exp2(): Tensor; /** * ![Plot of exp2 and its gradient](/plots/exp2.svg) * * Calculates: * ```js * output = exp2(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * exp2(input) * 0.6931471805599453 * ``` * * @returns the output tensor */ exp2_(): Tensor; /** * ![Plot of expm1 and its gradient](/plots/expm1.svg) * * Calculates: * ```js * output = exp(input) - 1.0 * ``` * * Gradient: * ```js * inputGrad = outputGrad * exp(input) * ``` * * @returns the output tensor */ expm1(): Tensor; /** * ![Plot of expm1 and its gradient](/plots/expm1.svg) * * Calculates: * ```js * output = exp(input) - 1.0 * ``` * * Gradient: * ```js * inputGrad = outputGrad * exp(input) * ``` * * @returns the output tensor */ expm1_(): Tensor; /** * ![Plot of floor and its gradient](/plots/floor.svg) * * Calculates: * ```js * output = floor(input) * ``` * * Gradient: * ```js * inputGrad = 0 * ``` * * @returns the output tensor */ floor(): Tensor; /** * ![Plot of floor and its gradient](/plots/floor.svg) * * Calculates: * ```js * output = floor(input) * ``` * * Gradient: * ```js * inputGrad = 0 * ``` * * @returns the output tensor */ floor_(): Tensor; /** * ![Plot of frac and its gradient](/plots/frac.svg) * * Calculates: * ```js * output = input >= 0.0 ? fract(input) : -fract(-input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * ``` * * @returns the output tensor */ frac(): Tensor; /** * ![Plot of frac and its gradient](/plots/frac.svg) * * Calculates: * ```js * output = input >= 0.0 ? fract(input) : -fract(-input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * ``` * * @returns the output tensor */ frac_(): Tensor; /** * Calculates: * ```js * output = sqrt(input * input + other * other) * ``` * * Gradient: * ```js * inputGrad = outputGrad * input / sqrt(input * input + other * other); otherGrad = outputGrad * other / sqrt(input * input + other * other) * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ hypot(other: Tensor): Tensor; /** * Calculates: * ```js * output = sqrt(input * input + other * other) * ``` * * Gradient: * ```js * inputGrad = outputGrad * input / sqrt(input * input + other * other); otherGrad = outputGrad * other / sqrt(input * input + other * other) * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ hypot_(other: Tensor): Tensor; /** * Calculates: * ```js * output = input * pow(2.0, other) * ``` * * Gradient: * ```js * var out = pow(2.0, other); inputGrad = outputGrad * out; otherGrad = outputGrad * input * out * 0.6931471805599453 * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ ldexp(other: Tensor): Tensor; /** * Calculates: * ```js * output = input * pow(2.0, other) * ``` * * Gradient: * ```js * var out = pow(2.0, other); inputGrad = outputGrad * out; otherGrad = outputGrad * input * out * 0.6931471805599453 * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ ldexp_(other: Tensor): Tensor; /** * ![Plot of log and its gradient](/plots/log.svg) * * Calculates: * ```js * output = log(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / input * ``` * * @returns the output tensor */ log(): Tensor; /** * ![Plot of log and its gradient](/plots/log.svg) * * Calculates: * ```js * output = log(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / input * ``` * * @returns the output tensor */ log_(): Tensor; /** * ![Plot of log10 and its gradient](/plots/log10.svg) * * Calculates: * ```js * output = log(input) * 0.4342944819032518 * ``` * * Gradient: * ```js * inputGrad = outputGrad / (input * 2.302585092994046) * ``` * * @returns the output tensor */ log10(): Tensor; /** * ![Plot of log10 and its gradient](/plots/log10.svg) * * Calculates: * ```js * output = log(input) * 0.4342944819032518 * ``` * * Gradient: * ```js * inputGrad = outputGrad / (input * 2.302585092994046) * ``` * * @returns the output tensor */ log10_(): Tensor; /** * ![Plot of log1p and its gradient](/plots/log1p.svg) * * Calculates: * ```js * output = log(input + 1.0) * ``` * * Gradient: * ```js * inputGrad = outputGrad / (input + 1.0) * ``` * * @returns the output tensor */ log1p(): Tensor; /** * ![Plot of log1p and its gradient](/plots/log1p.svg) * * Calculates: * ```js * output = log(input + 1.0) * ``` * * Gradient: * ```js * inputGrad = outputGrad / (input + 1.0) * ``` * * @returns the output tensor */ log1p_(): Tensor; /** * ![Plot of log2 and its gradient](/plots/log2.svg) * * Calculates: * ```js * output = log2(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / (input * 0.6931471805599453) * ``` * * @returns the output tensor */ log2(): Tensor; /** * ![Plot of log2 and its gradient](/plots/log2.svg) * * Calculates: * ```js * output = log2(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / (input * 0.6931471805599453) * ``` * * @returns the output tensor */ log2_(): Tensor; /** * Calculates: * ```js * output = log(exp(input) + exp(other)) * ``` * * Gradient: * ```js * var ein = exp(input); var eoth = exp(other); var addeinv = outputGrad/(ein + eoth); inputGrad = addeinv * ein; otherGrad = addeinv * eoth * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ logaddexp(other: Tensor): Tensor; /** * Calculates: * ```js * output = log(exp(input) + exp(other)) * ``` * * Gradient: * ```js * var ein = exp(input); var eoth = exp(other); var addeinv = outputGrad/(ein + eoth); inputGrad = addeinv * ein; otherGrad = addeinv * eoth * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ logaddexp_(other: Tensor): Tensor; /** * Calculates: * ```js * output = log2(exp2(input) + exp2(other)) * ``` * * Gradient: * ```js * var ein = exp2(input); var eoth = exp2(other); var sum_ein_eoth = ein + eoth; inputGrad = outputGrad * (ein / sum_ein_eoth); otherGrad = outputGrad * (eoth / sum_ein_eoth ); * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ logaddexp2(other: Tensor): Tensor; /** * Calculates: * ```js * output = log2(exp2(input) + exp2(other)) * ``` * * Gradient: * ```js * var ein = exp2(input); var eoth = exp2(other); var sum_ein_eoth = ein + eoth; inputGrad = outputGrad * (ein / sum_ein_eoth); otherGrad = outputGrad * (eoth / sum_ein_eoth ); * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ logaddexp2_(other: Tensor): Tensor; /** * Calculates: * ```js * output = input * other * ``` * * Gradient: * ```js * inputGrad = outputGrad * other; otherGrad = outputGrad * input * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @param alpha the alpha value to multiply `other` with * @returns the output tensor */ mul(other: Tensor, alpha?: number): Tensor; /** * Alias for `mul`. * * Calculates: * ```js * output = input * other * ``` * * Gradient: * ```js * inputGrad = outputGrad * other; otherGrad = outputGrad * input * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @param alpha the alpha value to multiply `other` with * @returns the output tensor */ multiply(other: Tensor, alpha?: number): Tensor; /** * Calculates: * ```js * output = input * other * ``` * * Gradient: * ```js * inputGrad = outputGrad * other; otherGrad = outputGrad * input * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @param alpha the alpha value to multiply `other` with * @returns the output tensor */ mul_(other: Tensor, alpha?: number): Tensor; /** * ![Plot of neg and its gradient](/plots/neg.svg) * * Calculates: * ```js * output = -input * ``` * * Gradient: * ```js * inputGrad = -outputGrad * ``` * * @returns the output tensor */ neg(): Tensor; /** * Alias for `neg`. * * ![Plot of neg and its gradient](/plots/neg.svg) * * Calculates: * ```js * output = -input * ``` * * Gradient: * ```js * inputGrad = -outputGrad * ``` * * @returns the output tensor */ negative(): Tensor; /** * ![Plot of neg and its gradient](/plots/neg.svg) * * Calculates: * ```js * output = -input * ``` * * Gradient: * ```js * inputGrad = -outputGrad * ``` * * @returns the output tensor */ neg_(): Tensor; /** * ![Plot of positive and its gradient](/plots/positive.svg) * * Calculates: * ```js * output = input * ``` * * Gradient: * ```js * inputGrad = outputGrad * ``` * * @returns the output tensor */ positive(): Tensor; /** * ![Plot of positive and its gradient](/plots/positive.svg) * * Calculates: * ```js * output = input * ``` * * Gradient: * ```js * inputGrad = outputGrad * ``` * * @returns the output tensor */ positive_(): Tensor; /** * Calculates: * ```js * output = pow(input, other) * ``` * * Gradient: * ```js * inputGrad = outputGrad * other * pow(input, other - 1.0); otherGrad = outputGrad * pow(input, other) * log(input) * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ pow(other: Tensor): Tensor; /** * Calculates: * ```js * output = pow(input, other) * ``` * * Gradient: * ```js * inputGrad = outputGrad * other * pow(input, other - 1.0); otherGrad = outputGrad * pow(input, other) * log(input) * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ pow_(other: Tensor): Tensor; /** * ![Plot of rad2deg and its gradient](/plots/rad2deg.svg) * * Calculates: * ```js * output = input * 57.29577951308232 * ``` * * Gradient: * ```js * inputGrad = outputGrad * 57.29577951308232 * ``` * * @returns the output tensor */ rad2deg(): Tensor; /** * ![Plot of rad2deg and its gradient](/plots/rad2deg.svg) * * Calculates: * ```js * output = input * 57.29577951308232 * ``` * * Gradient: * ```js * inputGrad = outputGrad * 57.29577951308232 * ``` * * @returns the output tensor */ rad2deg_(): Tensor; /** * ![Plot of reciprocal and its gradient](/plots/reciprocal.svg) * * Calculates: * ```js * output = 1.0 / input * ``` * * Gradient: * ```js * inputGrad = -outputGrad / (input * input) * ``` * * @returns the output tensor */ reciprocal(): Tensor; /** * ![Plot of reciprocal and its gradient](/plots/reciprocal.svg) * * Calculates: * ```js * output = 1.0 / input * ``` * * Gradient: * ```js * inputGrad = -outputGrad / (input * input) * ``` * * @returns the output tensor */ reciprocal_(): Tensor; /** * ![Plot of relu and its gradient](/plots/relu.svg) * * Calculates: * ```js * output = max(input, 0.0) * ``` * * Gradient: * ```js * inputGrad = input > 0.0 ? outputGrad : 0.0 * ``` * * @returns the output tensor */ relu(): Tensor; /** * ![Plot of relu and its gradient](/plots/relu.svg) * * Calculates: * ```js * output = max(input, 0.0) * ``` * * Gradient: * ```js * inputGrad = input > 0.0 ? outputGrad : 0.0 * ``` * * @returns the output tensor */ relu_(): Tensor; /** * ![Plot of round and its gradient](/plots/round.svg) * * Calculates: * ```js * output = round(input) * ``` * * Gradient: * ```js * inputGrad = 0 * ``` * * @returns the output tensor */ round(): Tensor; /** * ![Plot of round and its gradient](/plots/round.svg) * * Calculates: * ```js * output = round(input) * ``` * * Gradient: * ```js * inputGrad = 0 * ``` * * @returns the output tensor */ round_(): Tensor; /** * ![Plot of rsqrt and its gradient](/plots/rsqrt.svg) * * Calculates: * ```js * output = 1.0 / sqrt(input) * ``` * * Gradient: * ```js * inputGrad = -outputGrad / (2.0 * sqrt(input) * input) * ``` * * @returns the output tensor */ rsqrt(): Tensor; /** * ![Plot of rsqrt and its gradient](/plots/rsqrt.svg) * * Calculates: * ```js * output = 1.0 / sqrt(input) * ``` * * Gradient: * ```js * inputGrad = -outputGrad / (2.0 * sqrt(input) * input) * ``` * * @returns the output tensor */ rsqrt_(): Tensor; /** * ![Plot of sigmoid and its gradient](/plots/sigmoid.svg) * * Calculates: * ```js * output = 1.0 / (1.0 + exp(-input)) * ``` * * Gradient: * ```js * var out = 1.0 / (1.0 + exp(-input)); inputGrad = outputGrad * out * (1.0 - out) * ``` * * @returns the output tensor */ sigmoid(): Tensor; /** * ![Plot of sigmoid and its gradient](/plots/sigmoid.svg) * * Calculates: * ```js * output = 1.0 / (1.0 + exp(-input)) * ``` * * Gradient: * ```js * var out = 1.0 / (1.0 + exp(-input)); inputGrad = outputGrad * out * (1.0 - out) * ``` * * @returns the output tensor */ sigmoid_(): Tensor; /** * ![Plot of sign and its gradient](/plots/sign.svg) * * Calculates: * ```js * output = sign(input) * ``` * * Gradient: * ```js * inputGrad = 0 * ``` * * @returns the output tensor */ sign(): Tensor; /** * ![Plot of sign and its gradient](/plots/sign.svg) * * Calculates: * ```js * output = sign(input) * ``` * * Gradient: * ```js * inputGrad = 0 * ``` * * @returns the output tensor */ sign_(): Tensor; /** * ![Plot of silu and its gradient](/plots/silu.svg) * * Calculates: * ```js * output = input / (1.0 + exp(-input)) * ``` * * Gradient: * ```js * var out = 1.0 / (1.0 + exp(-input)); inputGrad = outputGrad * (out + input * out * (1.0 - out)) * ``` * * @returns the output tensor */ silu(): Tensor; /** * ![Plot of silu and its gradient](/plots/silu.svg) * * Calculates: * ```js * output = input / (1.0 + exp(-input)) * ``` * * Gradient: * ```js * var out = 1.0 / (1.0 + exp(-input)); inputGrad = outputGrad * (out + input * out * (1.0 - out)) * ``` * * @returns the output tensor */ silu_(): Tensor; /** * ![Plot of sin and its gradient](/plots/sin.svg) * * Calculates: * ```js * output = sin(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * cos(input) * ``` * * @returns the output tensor */ sin(): Tensor; /** * ![Plot of sin and its gradient](/plots/sin.svg) * * Calculates: * ```js * output = sin(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * cos(input) * ``` * * @returns the output tensor */ sin_(): Tensor; /** * ![Plot of sinc and its gradient](/plots/sinc.svg) * * Calculates: * ```js * var inpi = input * 3.141592653589793; output = input == 0.0 ? 1.0 : sin(inpi) / inpi * ``` * * Gradient: * ```js * var inpi = input * 3.141592653589793; inputGrad = input == 0.0 ? 0.0 : (outputGrad * 3.141592653589793 * (inpi*cos(inpi) - sin(inpi)) / (inpi*inpi)) * ``` * * @returns the output tensor */ sinc(): Tensor; /** * ![Plot of sinc and its gradient](/plots/sinc.svg) * * Calculates: * ```js * var inpi = input * 3.141592653589793; output = input == 0.0 ? 1.0 : sin(inpi) / inpi * ``` * * Gradient: * ```js * var inpi = input * 3.141592653589793; inputGrad = input == 0.0 ? 0.0 : (outputGrad * 3.141592653589793 * (inpi*cos(inpi) - sin(inpi)) / (inpi*inpi)) * ``` * * @returns the output tensor */ sinc_(): Tensor; /** * ![Plot of sinh and its gradient](/plots/sinh.svg) * * Calculates: * ```js * output = sinh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * cosh(input) * ``` * * @returns the output tensor */ sinh(): Tensor; /** * ![Plot of sinh and its gradient](/plots/sinh.svg) * * Calculates: * ```js * output = sinh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * cosh(input) * ``` * * @returns the output tensor */ sinh_(): Tensor; /** * ![Plot of sqrt and its gradient](/plots/sqrt.svg) * * Calculates: * ```js * output = sqrt(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / (2.0 * sqrt(input)) * ``` * * @returns the output tensor */ sqrt(): Tensor; /** * ![Plot of sqrt and its gradient](/plots/sqrt.svg) * * Calculates: * ```js * output = sqrt(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / (2.0 * sqrt(input)) * ``` * * @returns the output tensor */ sqrt_(): Tensor; /** * ![Plot of square and its gradient](/plots/square.svg) * * Calculates: * ```js * output = input * input * ``` * * Gradient: * ```js * inputGrad = outputGrad * 2.0 * input * ``` * * @returns the output tensor */ square(): Tensor; /** * ![Plot of square and its gradient](/plots/square.svg) * * Calculates: * ```js * output = input * input * ``` * * Gradient: * ```js * inputGrad = outputGrad * 2.0 * input * ``` * * @returns the output tensor */ square_(): Tensor; /** * Calculates: * ```js * output = input - other * ``` * * Gradient: * ```js * inputGrad = outputGrad; otherGrad = -outputGrad * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @param alpha the alpha value to multiply `other` with * @returns the output tensor */ sub(other: Tensor, alpha?: number): Tensor; /** * Alias for `sub`. * * Calculates: * ```js * output = input - other * ``` * * Gradient: * ```js * inputGrad = outputGrad; otherGrad = -outputGrad * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @param alpha the alpha value to multiply `other` with * @returns the output tensor */ subtract(other: Tensor, alpha?: number): Tensor; /** * Calculates: * ```js * output = input - other * ``` * * Gradient: * ```js * inputGrad = outputGrad; otherGrad = -outputGrad * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @param alpha the alpha value to multiply `other` with * @returns the output tensor */ sub_(other: Tensor, alpha?: number): Tensor; /** * ![Plot of tan and its gradient](/plots/tan.svg) * * Calculates: * ```js * output = tan(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / (cos(input) * cos(input)) * ``` * * @returns the output tensor */ tan(): Tensor; /** * ![Plot of tan and its gradient](/plots/tan.svg) * * Calculates: * ```js * output = tan(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad / (cos(input) * cos(input)) * ``` * * @returns the output tensor */ tan_(): Tensor; /** * ![Plot of tanh and its gradient](/plots/tanh.svg) * * Calculates: * ```js * output = tanh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * (1.0 - tanh(input) * tanh(input)) * ``` * * @returns the output tensor */ tanh(): Tensor; /** * ![Plot of tanh and its gradient](/plots/tanh.svg) * * Calculates: * ```js * output = tanh(input) * ``` * * Gradient: * ```js * inputGrad = outputGrad * (1.0 - tanh(input) * tanh(input)) * ``` * * @returns the output tensor */ tanh_(): Tensor; /** * ![Plot of trunc and its gradient](/plots/trunc.svg) * * Calculates: * ```js * output = trunc(input) * ``` * * Gradient: * ```js * inputGrad = 0 * ``` * * @returns the output tensor */ trunc(): Tensor; /** * Alias for `trunc`. * * ![Plot of trunc and its gradient](/plots/trunc.svg) * * Calculates: * ```js * output = trunc(input) * ``` * * Gradient: * ```js * inputGrad = 0 * ``` * * @returns the output tensor */ fix(): Tensor; /** * ![Plot of trunc and its gradient](/plots/trunc.svg) * * Calculates: * ```js * output = trunc(input) * ``` * * Gradient: * ```js * inputGrad = 0 * ``` * * @returns the output tensor */ trunc_(): Tensor; /** * Calculates: * ```js * output = input == 0.0 ? 0.0 : input * log(other) * ``` * * Gradient: * ```js * inputGrad = input == 0.0 ? 0.0 : outputGrad * log(other); otherGrad = input == 0.0 ? 0.0 : outputGrad * (input / other); * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ xlogy(other: Tensor): Tensor; /** * Calculates: * ```js * output = input == 0.0 ? 0.0 : input * log(other) * ``` * * Gradient: * ```js * inputGrad = input == 0.0 ? 0.0 : outputGrad * log(other); otherGrad = input == 0.0 ? 0.0 : outputGrad * (input / other); * ``` * * @param other the other tensor whose shape is broadcastable with the input tensor * @returns the output tensor */ xlogy_(other: Tensor): Tensor; /** * Calculates: * ```js * output = output && input * ``` * * with an initial value of `output = 1`. * * Gradient: * ```js * inputGrad = output ? outputGrad : 0.0 * ``` * * @returns the output tensor */ all(dim?: number, keepdim?: boolean): Tensor; /** * Calculates: * ```js * output = output || input * ``` * * with an initial value of `output = 0`. * * Gradient: * ```js * inputGrad = output ? outputGrad : 0.0 * ``` * * @returns the output tensor */ any(dim?: number, keepdim?: boolean): Tensor; /** * Calculates: * ```js * output = output + input * ``` * * with an initial value of `output = 0.0`. * * Gradient: * ```js * inputGrad = outputGrad / inputSize * ``` * * @returns the output tensor */ mean(dim?: number, keepdim?: boolean): Tensor; /** * Calculates: * ```js * output = output + input * input * ``` * * with an initial value of `output = 0.0`. * * Gradient: * ```js * inputGrad = outputGrad * input / output * ``` * * @returns the output tensor */ norm(dim?: number, keepdim?: boolean): Tensor; /** * Calculates: * ```js * output = output * input * ``` * * with an initial value of `output = 1.0`. * * Gradient: * ```js * inputGrad = outputGrad * output / input * ``` * * @returns the output tensor */ prod(dim?: number, keepdim?: boolean): Tensor; /** * Calculates: * ```js * output = output + input * ``` * * with an initial value of `output = 0.0`. * * Gradient: * ```js * inputGrad = outputGrad * ``` * * @returns the output tensor */ sum(dim?: number, keepdim?: boolean): Tensor; /** * Calculates: * ```js * output = output + (input != 0) * ``` * * with an initial value of `output = 0.0`. * * @returns the output tensor */ countNonzero(dim?: number, keepdim?: boolean): Tensor; }