import { Tensor } from '../library'; import { CPUTensor } from '../tensor/cpu/tensor'; import { TensorValues, Activation, PadMode, DType } from '../types'; import { BackwardOp, VariableI } from './types'; import { Backend } from '../util/convert'; import REGL from 'regl'; export interface VariableOptions { /** * The gradient can optionally be specified */ grad?: Tensor; /** * Backward edge of this variable * * You most likely do not want to use this */ backEdge?: BackwardOp; /** * When set to true, gradients will not be tracked for this * variable. Useful for data that is passed into a model. */ noGrad?: boolean; } /** * Tensor that also has a gradient associated to it * When noGrad is false, a dynamic computation graph on * this variable will be build. * * Once backward on a scalar variable (eg. a variable with shape [1]) * is called, the gradients for all variables will be computed */ export declare class Variable extends Tensor implements VariableI { value: Tensor; grad?: Tensor; backEdge?: BackwardOp; noGrad: boolean; /** * Creates a variable whose value is the specified value */ constructor(value: Tensor, options?: VariableOptions); static create(shape: ReadonlyArray, values: number[], backend: Backend, options?: VariableOptions, dtype?: DTpe): Variable; /** * Creates a GPU variable from texture data (eg. Image/Video element) */ static fromData(data: REGL.TextureImageData, options?: VariableOptions<'float32'>): Variable<'float32'>; cast(dtype: DTpe2): Tensor; /** * Performs a backward pass and returns wether the grad is needed or can be deleted */ backward(grad?: Tensor): boolean; isLeaf(): boolean; constantLike(value: number): Tensor; singleConstant(value: number): Tensor; getValues(): Promise; getShape(): readonly number[]; delete(): void; protected reshape_impl(shape: readonly number[], copy: boolean): Tensor; exp(): Tensor; log(): Tensor; sqrt(): Tensor; abs(): Tensor; sin(): Tensor; cos(): Tensor; tan(): Tensor; asin(): Tensor; acos(): Tensor; atan(): Tensor; sinh(): Tensor; cosh(): Tensor; tanh(): Tensor; asinh(): Tensor; acosh(): Tensor; atanh(): Tensor; sigmoid(): Tensor; hardSigmoid(alpha: number, beta: number): Tensor; sign(): Tensor; negate(): Tensor; addMultiplyScalar(factor: number, add: number): Tensor; powerScalar(power: number, factor: number): Tensor; setValues(values: Tensor, starts: number[]): Tensor; matMul(tensor: Tensor): Tensor; concat(tensor: Tensor, axis: number): Tensor; clip(min?: number, max?: number): Tensor; clipBackward(grad: Tensor, min?: number, max?: number): Tensor; repeat(repeats: number[]): Tensor; expand(shape: readonly number[]): Tensor; copy(): Tensor; gather(axis: number, indices: CPUTensor<'uint32'>): Tensor; floor(): Tensor; ceil(): Tensor; round(): Tensor; upsample(scales: number[]): Tensor; normalize(mean: Tensor, variance: Tensor, epsilon: number, scale: Tensor, bias: Tensor): Tensor; add_impl(th: Tensor, tensor: Tensor, resultShape: readonly number[], alpha: number, beta: number): Tensor; subtract_impl(th: Tensor, tensor: Tensor, resultShape: readonly number[], alpha: number, beta: number): Tensor; multiply_impl(th: Tensor, tensor: Tensor, resultShape: readonly number[], alpha: number): Tensor; divide_impl(th: Tensor, tensor: Tensor, resultShape: readonly number[], alpha: number): Tensor; power_impl(th: Tensor, tensor: Tensor, resultShape: readonly number[]): Tensor; gemm_impl(b: Tensor, aTranspose: boolean, bTranspose: boolean, alpha: number, beta: number, C?: Tensor): Tensor; protected sum_impl(axes: number[], keepDims: boolean): Tensor; protected sumSquare_impl(axes: number[], keepDims: boolean): Tensor; protected product_impl(axes: number[], keepDims: boolean): Tensor; protected max_impl(axes: number[], keepDims: boolean): Tensor; protected min_impl(axes: number[], keepDims: boolean): Tensor; protected reduceMean_impl(axes: number[], keepDims: boolean): Tensor; protected reduceMeanSquare_impl(axes: number[], keepDims: boolean): Tensor; protected reduceLogSum_impl(axes: number[], keepDims: boolean): Tensor; protected reduceLogSumExp_impl(axes: number[], keepDims: boolean): Tensor; protected conv_impl(kernel: Tensor, dilations: number[], group: number, pads: number[], strides: number[], activation: Activation, bias?: Tensor): Tensor; protected convTranspose_impl(kernel: Tensor, dilations: number[], group: number, pads: number[], strides: number[]): Tensor; protected pad_impl(pads: number[], mode: PadMode, value: number): Tensor; protected averagePool_impl(kernelShape: number[], pads: number[], strides: number[], includePad: boolean): Tensor; protected transpose_impl(permutation: number[]): Tensor; protected slice_impl(starts: number[], ends: number[], axes: number[], steps: number[]): Tensor; }