fn
diagonal_op
→TensorImplPtrint diagonal_op(const int & a, int offset, int axis1, int axis2)Python wrappers
Public Python APIs implemented by this engine symbols.Extract a single diagonal as a final-axis vector.
Returns the elements of a lying on the diagonal of the
(axis1, axis2) plane offset by offset: positive offsets shift
the diagonal toward the upper-right, negative offsets toward the
lower-left. The two selected axes are removed and a new trailing axis
of length L is appended.
Parameters
aTensorImplPtrInput tensor of rank .
offsetintDiagonal offset (0 = main diagonal).
axis1intFirst axis defining the plane.
axis2intSecond axis defining the plane. Must differ from
axis1; the two are canonicalised to a1 < a2.Returns
TensorImplPtrTensor whose shape is a.shape with axes axis1 and axis2 removed and a trailing dimension of length appended, where are the sizes of the two selected axes and are the starting row / column for the given offset.
Notes
Backward scatters the diagonal gradient into a zero tensor of the original input shape, leaving off-diagonal positions zero.