Function meshgrid

pub fn meshgrid<B, const N: usize, K, O>(
    tensors: &[Tensor<B, 1, K>; N],
    options: O,
) -> [Tensor<B, N, K>; N]
where B: Backend, K: BasicOps<B>, O: Into<GridOptions>,
Expand description

Return a collection of coordinate matrices for coordinate vectors.

Takes N 1D tensors and returns N tensors where each tensor represents the coordinates in one dimension across an N-dimensional grid.

Based upon options.sparse, the generated coordinate tensors can either be Sparse or Dense:

  • In Sparse mode, output tensors will have shape 1 everywhere except their cardinal dimension.
  • In Dense mode, output tensors will be expanded to the full grid shape.

Based upon options.indexing, the generated coordinate tensors will use either:

  • Matrix indexing, where dimensions are in the same order as their cardinality.
  • Cartesian indexing; where the first two dimensions are swapped.

See:

  • https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html
  • https://pytorch.org/docs/stable/generated/torch.meshgrid.html

§Arguments

  • tensors - A slice of 1D tensors
  • options - the options.

§Returns

A vector of N N-dimensional tensors representing the grid coordinates.