Function tfetch

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

    Example

    The function can be used with the await keyword:

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

    // no expected return value
    await sm.network.tfetch('localhost:3000', i)

    // no input
    const t = await sm.network.tfetch('localhost:3000')

    or with a chained callbacks:

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

    Returns

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

    Parameters

    • 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