Skip to content
fn

meshgrid_op

→vector<TensorImplPtr>
int meshgrid_op(const int & xs, bool indexing_xy)

Python wrappers

Public Python APIs implemented by this engine symbol.

Build N broadcast coordinate grids from N 1-D input tensors.

Given inputs x0,x1,…,xN−1x_0, x_1, \ldots, x_{N-1} with lengths L0,L1,…,LN−1L_0, L_1, \ldots, L_{N-1}, produces N output tensors all of the same rank-N shape; the ii-th output broadcasts xix_i across every axis except its "carry" axis, where it varies. This is the multi-dimensional analogue of NumPy's np.meshgrid.

Math

For ij indexing: outi[k0,k1,…,kN−1]=xi[ki]\mathrm{out}_i[k_0, k_1, \ldots, k_{N-1}] = x_i[k_i]

See Also

Concat : Stack the resulting grids along a new leading axis.

Parameters

xsvector<TensorImplPtr>
One or more 1-D input tensors. All must share the same dtype and device.
indexing_xybool
Axis convention for the first two inputs: * false — "ij" (matrix) indexing. Output i varies along axis i; output shape is (L_0, L_1, ..., L_{N-1}). * true — "xy" (Cartesian) indexing. Output 0 varies along axis 1 (x) and output 1 varies along axis 0 (y); outputs i >= 2 follow the ij convention. Output shape is (L_1, L_0, L_2, ..., L_{N-1}).

Returns

vector<TensorImplPtr>

N coordinate grids, one per input, each of rank N.

Notes

Backward sums each output gradient over every axis except the carry axis to recover the gradient w.r.t. the corresponding 1-D input. All inputs must be 1-D; mismatched ranks raise.

Examples

>>> X, Y = meshgrid([x, y], indexing_xy=true)  // 'xy' convention
>>> X.shape == (len(y), len(x))
True