Matrix

API

#include <ds/mat.h>

Handle

struct mat

View into memory representing a matrix.

Utilities to manipulate a row-major matrix stored on a contiguous block of memory.

Public Members

size_t _ino

Number of columns.

size_t _jno

Number of rows.

size_t _el_size

Size of each element in bytes.

byte *_data

Pointer to the underlying array.

Functions

void mat_make(struct mat *p, size_t el_size, size_t ino, size_t jno)

Initializes a matrix and allocates its memory.

Every call to mat_make must have a matching call to mat_del to release the managed memory.

Parameters:
  • p – Handle to the slice.

  • el_size – Size of each element.

  • ino – Number of columns.

  • jno – Number of rows.

void mat_del(struct mat *p)

Deallocates the memory backing a matrix created by mat_make.

Parameters:
  • p – Handle to the matrix.

size_t mat_idxof(struct mat *p, size_t i, size_t j)

Returns the byte offset to the ij-th element on the underlying array.

Parameters:
  • p – Handle to the matrix.

  • i

  • j

void mat_set(struct mat *p, size_t i, size_t j, void *el)

Sets the value of the ij-th element of the matrix.

Copies the element stored at el to the position of the ij-th element of the matrix.

Parameters:
  • p – Handle to the matrix.

  • i

  • j

  • el – Pointer to the element to append.

void *mat_at(struct mat *p, size_t i, size_t j)

Returns a pointer to the element at the ij-th index.

Returns a view into the underlying memory.

Parameters:
  • p – Handle to the matrix.

  • i

  • j

  • el – Pointer to the element to append.