[math] Matrix resize
This commit is contained in:
17
src/matrix.c
17
src/matrix.c
@@ -20,6 +20,23 @@ matrix_t *matrix_new(size_t m, size_t n) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool matrix_resize(matrix_t *self, size_t m, size_t n) {
|
||||||
|
if (self == NULL) return false;
|
||||||
|
|
||||||
|
matrix->values = realloc(sizeof(double) * m * n);
|
||||||
|
if (matrix->values == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->m = m;
|
||||||
|
self->n = n;
|
||||||
|
|
||||||
|
// Set all values to 0
|
||||||
|
matrix_zero(self);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
matrix_t *matrix_copy(matrix_t *self) {
|
matrix_t *matrix_copy(matrix_t *self) {
|
||||||
matrix_t *cpy = matrix_new(self->m, self->n);
|
matrix_t *cpy = matrix_new(self->m, self->n);
|
||||||
size_t num_values = self->m * self->n;
|
size_t num_values = self->m * self->n;
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ matrix_t *matrix_new_values(size_t m, size_t n, double *values);
|
|||||||
matrix_t *matrix_new_zeros(size_t m, size_t n);
|
matrix_t *matrix_new_zeros(size_t m, size_t n);
|
||||||
matrix_t *matrix_new_ones(size_t m, size_t n);
|
matrix_t *matrix_new_ones(size_t m, size_t n);
|
||||||
|
|
||||||
|
bool matrix_resize(matrix_t *self, size_t m, size_t n);
|
||||||
|
|
||||||
matrix_t *matrix_copy(matrix_t *self);
|
matrix_t *matrix_copy(matrix_t *self);
|
||||||
|
|
||||||
void matrix_init_values(matrix_t *self, double *values);
|
void matrix_init_values(matrix_t *self, double *values);
|
||||||
|
|||||||
Reference in New Issue
Block a user