Matrix Basics

This page covers the basics of the matrix struct in slap and several of the fundamental operations.

The Matrix struct

In slap, a matrix is a lightweight struct (and matching typedef) that holds the pointer to the start of the matrix, along with some additional meta for things like the size, stride, and type.

struct Matrix

Represents a matrix of sfloat-precision data.

Simple wrapper around an arbitrary pointer to the underlying data. The data is assumed to be stored in a contiguous block of memory. The data is interpreted column-wise, such that data[1] is element [1,0] of the matrix.

Public Members

uint16_t rows

number of rows

uint16_t cols

number of columns

uint16_t sy

column stride (distance between adjacent elements in the same row)

bool is_transposed

is transposed

sfloat *data

pointer to the start of the data

enum slap_MatrixType mattype

type of matrix

The underlying data pointer should be accessed via the getter:

static inline sfloat *slap_GetData(Matrix mat)

Return the raw pointer stored by the matrix.

Parameters:

mat – Any matrix

Warning

The fields of a Matrix should be considered private and are not meant to be directly altered. Please use the function API, as the internal representation of the API is subject to change in future versions.

Size Information

The following functions are useful for obtaining information about the size of a matrix. Please use these functions over directly accessing the fields of the Matrix type. All size information in slap is represented by the int type.

Name

Description

slap_NumRows()

Get the number of rows (\(m\))

slap_NumCols()

Get the number of columns (\(n\))

slap_NumElements()

Get the number of elements (\(m * n\))

slap_Stride()

Get the column stride of the matrix

slap_MinDim()

Get the number of elements (\(\text{min}(m, n)\))

slap_IsEmpty()

True if either dimension is zero

slap_IsSquare()

True if dimensions are equal

Note

In the future, the default type used for size information might be set by the user as a CMake variable.

Boolean Checks

Use the following functions to perform various checks on a matrix.

Name

Description

slap_IsTransposed()

Checks if the matrix is transposed.

slap_IsDense()

Checks if memory is contiguous (default stride)

slap_IsNull()

Checks if the matrix is a default-initialized Null matrix

slap_IsValid()

Checks if the data pointer for a matrix is valid