Next: , Previous: concatenate-grids, Up: Composition functions


4.3.4.4 diagonal

— Function: grid:diagonal grid &key offset indices destination start

Select a subgrid where the two indices are equal or differ by the offset, e.g. the diagonal affi for the matrix. The offset specifies sub- (offset<0) or super- (offset>0) diagonals.

— Function: (setf grid:diagonal)

Set a subgrid where the two indices are equal or differ by the offset, e.g. the diagonal affi for the matrix. The offset specifies sub- (offset<0) or super- (offset>0) diagonals. If grid is not supplied, a grid of one higher dimension than diagonal with default element 0 is used.

— Function: grid:set-diagonal grid function-or-value &optional offset value

Set the diagonal of the grid by calling the function on the indices. If value is non-nil, then set it to function-or-value, ignoring the indices.

The functions diagonal, (setf diagonal) (or set-diagonal) get or set the part of the grid where two indices are equal or differ by a constant to another grid; that is, either the diagonal or a sub- or super-diagonal. The diagonal of a grid can be set to a fixed value or to a function of its indices.

The diagonal is the collection of elements where there are two indices equal, or differ by a fixed amount. For a matrix (two dimensional grid), this would be for example:

     ANTIK-USER> (grid::test-grid-double-float 'array '(3 4))
     #2A((0.0 1.0 2.0 3.0) (10.0 11.0 12.0 13.0) (20.0 21.0 22.0 23.0))
     ANTIK-USER> (diagonal @)
     #(0.0 11.0 22.0)

The superdiagonal is accessible with the same function,

     ANTIK-USER> (diagonal (grid::test-grid-double-float 'array '(3 4)) :offset 1)
     #(1.0 12.0 23.0)

as is the subdiagonal,

     ANTIK-USER> (diagonal (grid::test-grid-double-float 'array '(3 4)) :offset -1)
     #(10.0 21.0)