Loading...
Searching...
No Matches
matrix.h
Go to the documentation of this file.
1#pragma once
2
12
13#include <nut/debug.h>
14
15typedef struct{
16 int64_t rows, cols;
17 int64_t *buf;
19
20typedef struct{
21 uint64_t rows, cols, modulus;
22 uint64_t *buf;
24
32NUT_ATTR_ACCESS(write_only, 1)
33bool nut_i64_Matrix_init(nut_i64_Matrix *self, int64_t rows, int64_t cols);
34
37NUT_ATTR_ACCESS(read_write, 1)
38NUT_ATTR_ACCESS(read_only, 2)
39void nut_i64_Matrix_copy(nut_i64_Matrix *restrict dest, const nut_i64_Matrix *restrict src);
40
43NUT_ATTR_ACCESS(read_write, 1)
45
49NUT_ATTR_ACCESS(read_only, 1)
50NUT_ATTR_ACCESS(read_write, 2)
51void nut_i64_Matrix_fprint(const nut_i64_Matrix *restrict self, FILE *file);
52
56NUT_ATTR_ACCESS(read_write, 1)
58
69NUT_ATTR_NONNULL(1, 2, 3)
70NUT_ATTR_ACCESS(read_only, 1)
71NUT_ATTR_ACCESS(read_only, 2)
72NUT_ATTR_ACCESS(write_only, 3)
73void nut_i64_Matrix_mul_vec(const nut_i64_Matrix *restrict self, const int64_t vec[restrict static self->cols], int64_t out[restrict static self->rows]);
74
82
91NUT_ATTR_ACCESS(read_write, 1)
92NUT_ATTR_ACCESS(read_write, 2)
93int64_t nut_i64_Matrix_invert_ltr(nut_i64_Matrix *restrict self, nut_i64_Matrix *restrict out);
94
100void nut_i64_Matrix_fill_vandemond_vec(uint64_t x, uint64_t k, uint64_t m, int64_t out[static k + 1]);
101
110NUT_ATTR_ACCESS(write_only, 1)
111bool nut_u64_ModMatrix_init(nut_u64_ModMatrix *self, uint64_t rows, uint64_t cols, uint64_t modulus);
112
115NUT_ATTR_ACCESS(read_write, 1)
116NUT_ATTR_ACCESS(read_only, 2)
117void nut_u64_ModMatrix_copy(nut_u64_ModMatrix *restrict dest, const nut_u64_ModMatrix *restrict src);
118
121NUT_ATTR_ACCESS(read_write, 1)
123
127NUT_ATTR_ACCESS(read_only, 1)
128NUT_ATTR_ACCESS(read_write, 2)
129void nut_u64_ModMatrix_fprint(const nut_u64_ModMatrix *restrict self, FILE *file);
130
134NUT_ATTR_ACCESS(read_write, 1)
136
147NUT_ATTR_NONNULL(1, 2, 3)
148NUT_ATTR_ACCESS(read_only, 1)
149NUT_ATTR_ACCESS(read_only, 2)
150NUT_ATTR_ACCESS(write_only, 3)
151void nut_u64_ModMatrix_mul_vec(const nut_u64_ModMatrix *restrict self, const uint64_t vec[restrict static self->cols], uint64_t out[restrict static self->rows]);
152
160
169NUT_ATTR_ACCESS(read_write, 1)
170NUT_ATTR_ACCESS(read_write, 2)
172
178void nut_u64_Matrix_fill_vandemond_vec(uint64_t x, uint64_t k, uint64_t m, uint64_t out[static k + 1]);
179
void nut_u64_ModMatrix_fill_short_pascal(nut_u64_ModMatrix *self)
Fill a matrix with part of the Pascal Triangle This is mostly internally used together with nut_u64_M...
void nut_i64_Matrix_destroy(nut_i64_Matrix *self)
Deallocate internal buffers for a matrix table.
void nut_u64_ModMatrix_copy(nut_u64_ModMatrix *restrict dest, const nut_u64_ModMatrix *restrict src)
Copy the values from one matrix to another, which must be initialized.
bool nut_u64_ModMatrix_invert_ltr(nut_u64_ModMatrix *restrict self, nut_u64_ModMatrix *restrict out)
Invert a lower triangular matrix Since we are working on matrices mod some number,...
void nut_i64_Matrix_fill_short_pascal(nut_i64_Matrix *self)
Fill a matrix with part of the Pascal Triangle This is mostly internally used together with nut_i64_M...
void nut_i64_Matrix_fill_vandemond_vec(uint64_t x, uint64_t k, uint64_t m, int64_t out[static k+1])
Fill a vector with increasing powers of x.
bool nut_i64_Matrix_fill_I(nut_i64_Matrix *self)
Fill a matrix with zeros off the diagonal and ones on the diagonal The matrix must be squared.
void nut_i64_Matrix_fprint(const nut_i64_Matrix *restrict self, FILE *file)
Print a matrix to a given file.
void nut_i64_Matrix_mul_vec(const nut_i64_Matrix *restrict self, const int64_t vec[restrict static self->cols], int64_t out[restrict static self->rows])
Multiply a matrix by a vector, returning a vector The vectors are stored as one dimensional arrays Th...
bool nut_i64_Matrix_init(nut_i64_Matrix *self, int64_t rows, int64_t cols)
Allocate internal buffers for a matrix.
void nut_u64_ModMatrix_fprint(const nut_u64_ModMatrix *restrict self, FILE *file)
Print a matrix to a given file.
void nut_i64_Matrix_copy(nut_i64_Matrix *restrict dest, const nut_i64_Matrix *restrict src)
Copy the values from one matrix to another, which must be initialized.
bool nut_u64_ModMatrix_fill_I(nut_u64_ModMatrix *self)
Fill a matrix with zeros off the diagonal and ones on the diagonal The matrix must be squared.
void nut_u64_Matrix_fill_vandemond_vec(uint64_t x, uint64_t k, uint64_t m, uint64_t out[static k+1])
Fill a vector with increasing powers of x.
bool nut_u64_ModMatrix_init(nut_u64_ModMatrix *self, uint64_t rows, uint64_t cols, uint64_t modulus)
Allocate internal buffers for a matrix.
int64_t nut_i64_Matrix_invert_ltr(nut_i64_Matrix *restrict self, nut_i64_Matrix *restrict out)
Invert a lower triangular matrix Integer matrices in general are not invertable because the integers ...
void nut_u64_ModMatrix_destroy(nut_u64_ModMatrix *self)
Deallocate internal buffers for a matrix table.
void nut_u64_ModMatrix_mul_vec(const nut_u64_ModMatrix *restrict self, const uint64_t vec[restrict static self->cols], uint64_t out[restrict static self->rows])
Multiply a matrix by a vector, returning a vector The vectors are stored as one dimensional arrays Th...
#define NUT_ATTR_ACCESS(...)
Wrapper for gcc's access function annotation - no clang equivalent, and currently disabled because it...
#define NUT_ATTR_NONNULL(...)
Wrapper for gnu::nonnull attr.