GitHub
deepbox/ndarray

Sparse, FFT & Advanced Ops

Sparse matrices, Einstein summation, FFTs, convolution utilities, stochastic masks, and other advanced ndarray features.
Sparse
FFT
einsum
type atleast1d
export declare const atleast1d: typeof atleast_1d;
atleast1d is a public const in deepbox/ndarray.
type atleast2d
export declare const atleast2d: typeof atleast_2d;
atleast2d is a public const in deepbox/ndarray.
type broadcastTo
export declare const broadcastTo: typeof broadcast_to;
broadcastTo is a public const in deepbox/ndarray.
type emptyLike
export declare const emptyLike: typeof empty_like;
emptyLike is a public const in deepbox/ndarray.
type FFTResult
export interface FFTResult { … }
Result of an FFT operation: real and imaginary parts as separate tensors.
type flipLr
export declare const flipLr: typeof fliplr;
flipLr is a public const in deepbox/ndarray.
type flipUd
export declare const flipUd: typeof flipud;
flipUd is a public const in deepbox/ndarray.
type fullLike
export declare const fullLike: typeof full_like;
fullLike is a public const in deepbox/ndarray.
type indexSelect
export declare const indexSelect: typeof index_select;
indexSelect is a public const in deepbox/ndarray.
type onesLike
export declare const onesLike: typeof ones_like;
onesLike is a public const in deepbox/ndarray.
type zerosLike
export declare const zerosLike: typeof zeros_like;
zerosLike is a public const in deepbox/ndarray.
type CSRMatrixInit
export type CSRMatrixInit = { readonly data: Float64Array; readonly indices: Int32Array; readonly indptr: Int32Array; readonly shape: Shape; };
Initialization data for constructing a .

CSRMatrix

Compressed Sparse Row (CSR) matrix representation.

col2im
export declare function col2im(cols: Tensor, inputShape: Shape, kernelSize: [number, number], stride: [number, number], padding: [number, number]): Tensor;

Column to Image operation (col2im).

im2col
export declare function im2col(input: Tensor, kernelSize: [number, number], stride: [number, number], padding: [number, number]): Tensor;

Image to Column operation (im2col).

einsum
export declare function einsum(subscripts: string, ...tensors: Tensor[]): Tensor;

Einstein summation convention.

atleast_1d
export declare function atleast_1d(t: Tensor): Tensor;

Ensure the input is at least 1-D.

atleast_2d
export declare function atleast_2d(t: Tensor): Tensor;

Ensure the input is at least 2-D.

bartlettWindow
export declare function bartlettWindow(n: number): Tensor;

bartlettWindow is exported by deepbox/ndarray.

bincount
export declare function bincount(t: Tensor, minlength?: number): Tensor;

Count number of occurrences of each value in a non-negative integer tensor.

blackmanWindow
export declare function blackmanWindow(n: number): Tensor;

blackmanWindow is exported by deepbox/ndarray.

booleanIndex
export declare function booleanIndex(t: Tensor, mask: Tensor): Tensor;

Select elements from a tensor using a boolean mask.

broadcast_to
export declare function broadcast_to(t: Tensor, shape: Shape): Tensor;

Broadcast a tensor to a target shape.

clone
export declare function clone(t: Tensor): Tensor;

Create a deep copy of a tensor with its own data buffer.

contiguous
export declare function contiguous(t: Tensor): Tensor;

Return a contiguous tensor.

convolve
export declare function convolve(a: Tensor, v: Tensor, mode?: "full" | "same" | "valid"): Tensor;

convolve is exported by deepbox/ndarray.

copy
export declare function copy(t: Tensor): Tensor;

Create an explicit deep copy of a tensor (alias for clone).

correlate
export declare function correlate(a: Tensor, v: Tensor, mode?: "full" | "same" | "valid"): Tensor;

correlate is exported by deepbox/ndarray.

cross
export declare function cross(a: Tensor, b: Tensor): Tensor;

Compute the cross product of two 3-element vectors.

detach
export declare function detach(t: Tensor): Tensor;

Create a copy of a tensor detached from any computation graph.

diag
export declare function diag(t: Tensor, k?: number): Tensor;

Extract a diagonal or construct a diagonal matrix.

diagonal
export declare function diagonal(t: Tensor, k?: number): Tensor;

Extract the k-th diagonal from a 2-D tensor.

empty_like
export declare function empty_like(t: Tensor): Tensor;

Create an uninitialized tensor with the same shape and dtype as the input tensor.

fancyIndex
export declare function fancyIndex(t: Tensor, indices: Tensor, axis?: Axis): Tensor;

Select elements from a tensor using integer index arrays.

fft
export declare function fft(t: Tensor, n?: number): FFTResult;

Compute the one-dimensional discrete Fourier Transform.

fft2
export declare function fft2(t: Tensor): FFTResult;

Compute the 2-dimensional discrete Fourier Transform.

fftn
export declare function fftn(t: Tensor, axes?: number[]): FFTResult;

Compute the n-dimensional discrete Fourier Transform.

flip
export declare function flip(t: Tensor, axes?: number[]): Tensor;

Reverse the order of elements along the given axes.

fliplr
export declare function fliplr(t: Tensor): Tensor;

Flip a 2-D tensor left-right (reverse columns).

flipud
export declare function flipud(t: Tensor): Tensor;

Flip a 2-D tensor up-down (reverse rows).

full_like
export declare function full_like(t: Tensor, fillValue: number | bigint): Tensor;

Create a tensor filled with a specified value, matching the shape and dtype of the input.

hammingWindow
export declare function hammingWindow(n: number): Tensor;

hammingWindow is exported by deepbox/ndarray.

hannWindow
export declare function hannWindow(n: number): Tensor;

hannWindow is exported by deepbox/ndarray.

histogram
export declare function histogram(t: Tensor, bins?: number, range?: readonly [number, number]): { counts: Tensor; binEdges: Tensor; };

Compute the histogram of a 1-D tensor.

ifft
export declare function ifft(real: Tensor, imag: Tensor, n?: number): FFTResult;

Compute the one-dimensional inverse discrete Fourier Transform.

ifft2
export declare function ifft2(real: Tensor, imag: Tensor): FFTResult;

Compute the 2-dimensional inverse discrete Fourier Transform.

ifftn
export declare function ifftn(real: Tensor, imag: Tensor, axes?: number[]): FFTResult;

Compute the n-dimensional inverse discrete Fourier Transform.

index_select
export declare function index_select(input: Tensor, dim: number, index: Tensor): Tensor;

Select elements along a dimension using an index tensor.

irfft
export declare function irfft(real: Tensor, imag: Tensor, n?: number): FFTResult;

Compute the inverse FFT for rfft output (Hermitian-symmetric).

isin
export declare function isin(a: Tensor, values: Tensor | number[]): Tensor;

Test whether each element of `a` is in `values`.

kaiserWindow
export declare function kaiserWindow(n: number, beta?: number): Tensor;

kaiserWindow is exported by deepbox/ndarray.

meshgrid
export declare function meshgrid(...args: [...Tensor[], ...[{ readonly indexing?: "xy" | "ij"; }]] | Tensor[]): Tensor[];

Return coordinate matrices from coordinate vectors.

moveaxis
export declare function moveaxis(t: Tensor, source: number | number[], destination: number | number[]): Tensor;

Move axes of a tensor to new positions.

nanmax
export declare function nanmax(t: Tensor, axis?: Axis): Tensor;

Maximum of elements, ignoring NaN values.

nanmean
export declare function nanmean(t: Tensor, axis?: Axis): Tensor;

Mean of elements, ignoring NaN values.

nanmin
export declare function nanmin(t: Tensor, axis?: Axis): Tensor;

Minimum of elements, ignoring NaN values.

nanstd
export declare function nanstd(t: Tensor, axis?: Axis): Tensor;

Standard deviation of elements, ignoring NaN values.

nansum
export declare function nansum(t: Tensor, axis?: Axis): Tensor;

Sum of elements, ignoring NaN values.

ones_like
export declare function ones_like(t: Tensor): Tensor;

Create a tensor of ones with the same shape and dtype as the input tensor.

pad
export declare function pad(t: Tensor, padWidth: ReadonlyArray<readonly [number, number]>, mode?: PadMode, constantValue?: number): Tensor;

Pad a tensor with values.

rfft
export declare function rfft(t: Tensor, n?: number): FFTResult;

Compute the one-dimensional FFT for real input.

roll
export declare function roll(t: Tensor, shift: number, axis?: Axis): Tensor;

Roll tensor elements along the given axis.

rot90
export declare function rot90(t: Tensor, k?: number): Tensor;

Rotate a 2-D tensor by 90 degrees counter-clockwise.

scatter
export declare function scatter(t: Tensor, dim: number, index: Tensor, src: Tensor): Tensor;

Scatter values into a tensor at specified indices along an axis.

searchsorted
export declare function searchsorted(sortedArr: Tensor, values: Tensor, side?: "left" | "right"): Tensor;

Find indices where elements should be inserted to maintain order.

swapaxes
export declare function swapaxes(t: Tensor, axis1: number, axis2: number): Tensor;

Swap two axes of a tensor.

tril
export declare function tril(t: Tensor, k?: number): Tensor;

Return the lower triangular part of a 2-D tensor, with elements above the k-th diagonal zeroed.

triu
export declare function triu(t: Tensor, k?: number): Tensor;

Return the upper triangular part of a 2-D tensor, with elements below the k-th diagonal zeroed.

unique
export declare function unique(t: Tensor, returnCounts?: boolean): { values: Tensor; counts?: Tensor; };

Return the unique elements of a tensor, sorted in ascending order.

where
export declare function where(condition: Tensor, x: Tensor, y: Tensor): Tensor;

Conditional element selection: returns elements from `x` where `condition` is true, and from `y` where `condition` is false.

zeros_like
export declare function zeros_like(t: Tensor): Tensor;

Create a tensor of zeros with the same shape and dtype as the input tensor.

dropoutMask
export declare function dropoutMask(shape: Shape, p: number, scale: number, dtype: NumericDType, device: Device): Tensor;

Generate a tensor of Bernoulli samples scaled by a constant.

ndarray-sparse.ts
import { CSRMatrix, dropoutMask, einsum, fft, ifft, rfft, tensor } from "deepbox/ndarray";const dense = tensor([  [1, 0, 0],  [0, 2, 3],]);const sparse = CSRMatrix.fromCOO({  rows: 2,  cols: 3,  rowIndices: new Int32Array([0, 1, 1]),  colIndices: new Int32Array([0, 1, 2]),  values: new Float64Array([1, 2, 3]),});const signal = tensor([1, 2, 3, 4]);const spectrum = fft(signal);console.log(dense.toString());console.log(sparse.toDense().toString());console.log(einsum("ij,jk->ik", dense, tensor([[1], [2], [3]])).toString());console.log(spectrum.real.toString());console.log(rfft(signal).real.toString());console.log(ifft(spectrum.real, spectrum.imag).real.toString());console.log(dropoutMask(signal.shape, 0.25, 1 / (1 - 0.25), "float32", "cpu").toString());