pangolin.interface.Interface.oindex#
- Interface.oindex(x, *indices)[source]#
Index an RV using fully orthogonal indexing.
Every nonscalar index contributes all of its dimensions independently to the output. Slices are treated as one-dimensional integer arrays. This is intentionally simpler than NumPy, JAX, or PyTorch indexing and resembles
oindexfrom NEP 21.Every dimension must be explicitly indexed, or covered by a single ellipsis. Missing trailing indices are not filled with full slices. For a matrix
x,x[0]raisesValueError; usex[0, :]orx[0, ...]instead. The same requirement applies to explicitoindexcalls.- Parameters:
x (RVLike) – Interface RV or array-like value to index.
*indices (Index) – One scalar, array-like value, interface RV, or slice per dimension of
x. A single ellipsis may stand for the required number of full slices.
- Returns:
indexed – Interface RV containing an
ir.IndexOp wrapped inir.VMapfor each index dimension. Its shape is the concatenation of the index shapes.- Raises:
ValueError – If the number of indices does not match the rank of
xor more than one ellipsis is supplied.- Return type:
Examples
>>> import pangolin.interface as pi >>> A = pi.constant([[3, 0, 2], [4, 4, 4]]) >>> pi.oindex(A, slice(None), [2, 2]) RV(VMap(VMap(Index(), [None, None, 0], 2), [None, 0, None], 2), RV(Constant([[3,0,2],[4,4,4]])), RV(Constant([0,1])), RV(Constant([2,2]))) >>> pi.oindex(A, 0, ...).shape (3,)
A scalar can be indexed with no indices:
>>> pi.oindex(pi.constant(12.0)).shape ()