[math] matrix scalar arithmetic
This commit is contained in:
21
src/matrix.c
21
src/matrix.c
@@ -74,10 +74,27 @@ matrix_t *matrix_new_values(size_t m, size_t n, double *values) {
|
|||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void matrix_scale(matrix_t *self, double value) {
|
|
||||||
double_array_mul(self->values, self->m * self->n, value);
|
inline void matrix_div(matrix_t *self, double value) {
|
||||||
|
double_array_div(self->values, value, self->m * self->n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void matrix_mul(matrix_t *self, double value) {
|
||||||
|
double_array_mul(self->values, value, self->m * self->n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void matrix_add(matrix_t *self, double value) {
|
||||||
|
double_array_add(self->values, self->m * self->n, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void matrix_sub(matrix_t *self, double value) {
|
||||||
|
double_array_sub(self->values, value, self->m * self->n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void matrix_dot_vector(matrix_t *self, double *vec, double *result) {
|
void matrix_dot_vector(matrix_t *self, double *vec, double *result) {
|
||||||
double *values = self->values;
|
double *values = self->values;
|
||||||
size_t n = self->n;
|
size_t n = self->n;
|
||||||
|
|||||||
@@ -27,7 +27,10 @@ void matrix_set_scalar(matrix_t *self, size_t row_index, size_t col_index, doubl
|
|||||||
|
|
||||||
double matrix_get(matrix_t *self, size_t row_index, size_t col_index);
|
double matrix_get(matrix_t *self, size_t row_index, size_t col_index);
|
||||||
|
|
||||||
void matrix_scale(matrix_t *self, double value);
|
void matrix_add(matrix_t *self, double value);
|
||||||
|
void matrix_sub(matrix_t *self, double value);
|
||||||
|
void matrix_mul(matrix_t *self, double value);
|
||||||
|
void matrix_div(matrix_t *self, double value);
|
||||||
void matrix_dot_vector(matrix_t *self, double *vec, double *result);
|
void matrix_dot_vector(matrix_t *self, double *vec, double *result);
|
||||||
int matrix_dot_matrix(matrix_t *m1, matrix_t *m2, matrix_t *result);
|
int matrix_dot_matrix(matrix_t *m1, matrix_t *m2, matrix_t *result);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user