deepbox/ndarray
Autograd
Automatic differentiation with GradTensor, parameter helpers, and gradient-safe activation variants.
GradTensor
type GradTensorOptions
export type GradTensorOptions = { readonly requiresGrad?: boolean; readonly dtype?: Exclude<DType, "string">; };
GradTensorOptions is a public type in deepbox/ndarray.
GradTensor
Tensor wrapper that records a computation graph for reverse-mode autodiff.
col2imGrad
export declare function col2imGrad(cols: GradTensor, outputShape: readonly number[], kernelSize: [number, number], stride: [number, number], padding: [number, number]): GradTensor;
Column to Image operation for GradTensor (transpose/adjoint of im2col).
concatGrad
export declare function concatGrad(parts: readonly GradTensor[], axis?: number): GradTensor;
Concatenate GradTensors along an existing axis.
customOp
export declare function customOp(output: Tensor, grads: ReadonlyArray<readonly [GradTensor, (outGrad: Tensor) => Tensor]>): GradTensor;
Wrap a precomputed output tensor with an explicit reverse-mode rule.
dropoutGrad
export declare function dropout(input: GradTensor, p?: number, training?: boolean): GradTensor;
dropoutGrad is exported by deepbox/ndarray.
im2colGrad
export declare function im2col(input: GradTensor, kernelSize: [number, number], stride: [number, number], padding: [number, number]): GradTensor;
Image to Column operation for GradTensor.
logSoftmaxGrad
export declare function logSoftmax(input: GradTensor, axis?: number): GradTensor;
logSoftmaxGrad is exported by deepbox/ndarray.
noGrad
export declare function noGrad<T>(fn: () => T): T;
Context manager to disable gradient calculation.
parameter
export declare function parameter(data: number | number[] | number[][] | number[][][] | Tensor, options?: GradTensorOptions): GradTensor;
Create a GradTensor with requiresGrad=true.
softmaxGrad
export declare function softmax(input: GradTensor, axis?: number): GradTensor;
softmaxGrad is exported by deepbox/ndarray.
stackGrad
export declare function stackGrad(parts: readonly GradTensor[]): GradTensor;
Stack a list of same-shape GradTensors along a new leading axis.
varianceGrad
export declare function variance(input: GradTensor, axis?: number, correction?: number): GradTensor;
varianceGrad is exported by deepbox/ndarray.
ndarray-autograd.ts
import { GradTensor, parameter } from "deepbox/ndarray";const x = parameter([[1, 2], [3, 4]]);const w = parameter([[0.5], [0.25]]);const y = x.matmul(w).sum();y.backward();console.log(x.grad?.toString());console.log(w.grad?.toString());console.log(x instanceof GradTensor);