Program Listing for File matrix.h
↰ Return to documentation for file (rcsw/ds/matrix.h
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include <math.h>
#include "rcsw/ds/ds.h"
#include "rcsw/common/fpc.h"
/*******************************************************************************
* Structure Definitions
******************************************************************************/
struct matrix_params {
void (*printe)(const void *e);
dptr_t *elements;
size_t elt_size;
uint32_t flags;
size_t n_rows;
size_t n_cols;
};
struct matrix {
size_t n_rows;
size_t n_cols;
dptr_t* elements;
uint32_t flags;
size_t elt_size;
void (*printe)(const void *const e);
};
/*******************************************************************************
* API Functions
******************************************************************************/
BEGIN_C_DECLS
static inline void* matrix_access(const struct matrix* const matrix,
size_t u,
size_t v) {
RCSW_FPC_NV(NULL,
NULL != matrix,
u < matrix->n_rows,
v < matrix->n_cols);
return (uint8_t*)matrix->elements + (matrix->n_cols * matrix->elt_size * u) +
(matrix->elt_size * v);
}
static inline size_t matrix_element_space(size_t n_rows,
size_t n_cols,
size_t elt_size) {
return ds_elt_space_simple(n_rows * n_cols, elt_size);
}
static inline status_t matrix_elt_clear(struct matrix* const matrix,
size_t u,
size_t v) {
RCSW_FPC_NV(ERROR, NULL != matrix, u < matrix->n_rows, v < matrix->n_cols);
ds_elt_clear(matrix_access(matrix, u, v), matrix->elt_size);
return OK;
}
static inline status_t matrix_set(struct matrix* const matrix,
size_t u,
size_t v,
const void *const w) {
RCSW_FPC_NV(ERROR, NULL != matrix, NULL != w, u < matrix->n_rows,
v < matrix->n_cols);
ds_elt_copy(matrix_access(matrix, u, v), w, matrix->elt_size);
return OK;
} /* matrix_set() */
static inline bool_t matrix_issquare(const struct matrix* const matrix) {
RCSW_FPC_NV(false, NULL != matrix);
return matrix->n_cols == matrix->n_rows;
}
RCSW_API struct matrix* matrix_init(struct matrix* matrix_in,
const struct matrix_params* params);
RCSW_API void matrix_destroy(struct matrix* matrix);
RCSW_API status_t matrix_transpose(struct matrix* matrix);
RCSW_API void matrix_print(const struct matrix* matrix);
END_C_DECLS