Function tfetch

  • Similar to the Web standard fetch API, this function enables asynchronous transfer of remote tensors.


    The function can be used with the await keyword:

    // input and output at once
    const i = sm.randn([128])
    const t = await'localhost:3000', i)

    // no expected return value
    await'localhost:3000', i)

    // no input
    const t = await'localhost:3000')

    or with a chained callbacks:'localhost:3000', i).then((t) => {
    // t is a tensor or null
    if (t) {
    }).catch((err) => {
    console.log('hit an error retrieving this tensor...')


    A tensor from the remote location or null (if the response is empty)


    • url: string

      The location to either send or request the tensor from.

    • Optional tensor: Tensor

      An optional tensor that will be sent to the remote location.

    • Optional options: {
          grad_fn?: ((grad?: any) => Promise<void | Tensor>);
          id?: string;
      • Optional grad_fn?: ((grad?: any) => Promise<void | Tensor>)
          • (grad?: any): Promise<void | Tensor>
          • Parameters

            • Optional grad: any

            Returns Promise<void | Tensor>

      • Optional id?: string

    Returns Promise<Tensor>

Generated using TypeDoc