wvMatrixElt(3) USC Math Department
Back to wvlib matrix function index
wvMatrixElt(3)

Name

wvMatrixGetElt, wvMatrixSetElt, wvMatrixElt, wvMatrixEltPtr - matrix element functions

Synopsis

#include <wv/matrix.h>

WVdata wvMatrixGetElt(const WVmatrix *matrix, const WVindexVector *index);

WVdata wvMatrixSetElt(WVmatrix *matrix, const WVindexVector *index, WVdata value);

WVdata wvMatrixElt({const} WVmatrix *matrix, const WVindexVector *index);

WVdata *wvMatrixEltPtr(const WVmatrix *matrix, const WVindexVector *index);

Description

wvMatrixGetElt returns the value of the element of matrix at index.

wvMatrixSetElt sets the value of the element of matrix at index to value and returns that value.

wvMatrixElt provides a mechanism for accessing the element of matrix at index directly. This element can be written to (used as a r.h.s) if the matrix is not const. See the example.

wvMatrixEltPtr returns a pointer to the element of matrix at index.

When matrix is const, wvMatrixGetElt is preferred over wvMatrixElt. Otherwise, the programmer is free to use whichever function she chooses to access the elements of matrix.

Example

#include <wv/matrix.h>
  
    .
    .
    .
{
    WVindexVector *size;
    WVindexVector *index;
    WVmatrix *mat;
    WVdata val;

    size = wvVaNewIndexVector(2, 256, 512);
    mat  = wvNewMatrix(size);
    index = wvNewIndexVector(2);

    /* the following two statements are equivalent */
    wvMatrixSetElt(mat, index, 20);
    wvMatrixElt(mat, index) = 20;

    /* the following three statements are equivalent */
    val = wvMatrixGetElt(mat, index);
    val = wvMatrixElt(mat, index);
    val = *(wvMatrixEltPtr(mat, index));

    /* an example of the flexibility of wvMatrixElt() */
    wvMatrixElt(mat, index) += 5;

    .
    .
    .

    wvDestroyIndexVector(index);
    wvDestroyMatrix(mat);
    wvDestroyIndexVector(size);
}

See Also

wvMatrixForEachElt(3), wvMatrixSize(3), wvNewIndexVector(3), wvNewMatrix(3)

Caveat

Results are undefined if any of the elements of the index vector are greater than the corresponding size of the matrix.

Back to wvlib matrix function index Last Updated: 27 January 1998