Class Tensor

Hierarchy

Constructors

Properties

_checkpoint_callback: (() => boolean)

Type declaration

    • (): boolean
    • Returns boolean

_checkpoint_file: string
_deps: Tensor[] = []
_ptr: number
_underlying: ArrayBuffer
grad: Tensor = null
grad_callback_async?: ((grad?: GradContext) => Promise<void | Tensor>)

Type declaration

    • (grad?: GradContext): Promise<void | Tensor>
    • Parameters

      • Optional grad: GradContext

      Returns Promise<void | Tensor>

op: string = 'constant'
provenance: any = null
requires_grad: boolean = false
requires_stats: boolean = false
stats: OpStats = null

Accessors

Methods

  • Parameters

    Returns Record<string, {
        grad: Tensor;
        tensor: Tensor;
    }> | Promise<Record<string, {
        grad: Tensor;
        tensor: Tensor;
    }>>

  • Parameters

    • Optional file: (() => any)
        • (): any
        • Returns any

    • Optional callback: (() => boolean)
        • (): boolean
        • Returns boolean

    Returns Tensor

  • Determine the indices of elements that are non-zero. There is a static function version of this method: nonzero.

    Remarks

    Indices correspond to a flattened version of the input tensor.

    Example

      const t = sm.randn([100])

    // equivalent calls
    const a = t.nonzero()
    const b = sm.nonzero(t)

    Returns

    • A new Tensor composed of the flattened indices of the non-zero elements in the input

    Returns Tensor

  • Reshape a Tensor without modifying the underlying data. There is a static function version of this method: reshape.

    Remarks

    The resultant shape must contain the same number of elements as the base Tensor.

    Example

      const t = sm.randn([64])

    // equivalent calls
    const a = t.reshape([8, 8])
    const b = sm.reshape(t, [8, 8])

    Parameters

    • shape: BigInt64Array | number[]

      The shape of the output Tensor

    Returns Tensor

  • Round each element in a tensor to the nearest integer. There is a static function version of this method: rint.

    $$ x = \begin{cases} \lfloor x \rfloor,& \text{if } x - \lfloor x \rfloor \leq \frac{1}{2}\\ \lceil x \rceil,& \text{otherwise} \end{cases} \forall x \in T $$

    Example

      const t = sm.randn([128, 128])

    // equivalent calls
    const a = t.rint()
    const b = sm.rint(t)

    Returns

    Returns Tensor

  • Replicate a Tensor about its axes. There is a static function version of this method: tile.

    Example

      const t = sm.identity(4)

    // equivalent calls
    const a = sm.tile(t, [2, 2])
    a.shape // [8, 8]
    const b = t.tile([2, 2])
    b.shape // [8, 8]

    // tiling by 1 on all dims does nothing
    const no_op = t.tile([1, 1])

    Returns

    A new Tensor

    Parameters

    • shape: BigInt64Array | number[]

      A shape describing the number of iterations to tile each axis.

    Returns Tensor

  • Re-arrange the layout of the values within a Tensor. There is a static function version of this method: transpose.

    Remarks

    The total number of elements of the tensor does not change.

    Example

      const t = sm.rand([128, 8])

    // equivalent calls
    const a = t.transpose([1, 0])
    a.shape // [8, 128]
    const b = sm.transpose(t, [1, 0])
    b.shape // [8, 128]

    Returns

    A new Tensor

    Parameters

    • axes: BigInt64Array | number[]

      The new order of the indices of the current axes after tranposing

    Returns Tensor

Generated using TypeDoc