diff options
author | Determinant <ted.sybil@gmail.com> | 2015-06-24 22:48:24 +0800 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2015-06-24 22:48:24 +0800 |
commit | 5e407d74130accfbbf94d2cabcb03fc126a89410 (patch) | |
tree | 6d8998e904a31a95f85a6e64ac7f3940fb61af80 /nerv/lib/matrix/mmatrix.c | |
parent | 8f13607cba9d6cf4fc4a213ba5ae4bcd46f7e18d (diff) |
separate non-Lua part of matrix code to a dedicated dir
Diffstat (limited to 'nerv/lib/matrix/mmatrix.c')
-rw-r--r-- | nerv/lib/matrix/mmatrix.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/nerv/lib/matrix/mmatrix.c b/nerv/lib/matrix/mmatrix.c new file mode 100644 index 0000000..2f58e7f --- /dev/null +++ b/nerv/lib/matrix/mmatrix.c @@ -0,0 +1,53 @@ +#define NERV_GENERIC_MMATRIX +#include <stdlib.h> +#include "../../common.h" + +#define MATRIX_USE_FLOAT +#define host_matrix_(NAME) host_matrix_float_##NAME +#define nerv_matrix_(NAME) nerv_matrix_host_float_##NAME +#include "generic/matrix.h" +#include "generic/mmatrix.c" +#undef nerv_matrix_ +#undef host_matrix_ +#undef MATRIX_USE_FLOAT +#undef MATRIX_ELEM +#undef MATRIX_ELEM_PTR +#undef MATRIX_ELEM_FMT +#undef MATRIX_ELEM_WRITE_FMT + +#define NERV_GENERIC_MMATRIX +#define MATRIX_USE_DOUBLE +#define host_matrix_(NAME) host_matrix_double_##NAME +#define nerv_matrix_(NAME) nerv_matrix_host_double_##NAME +#include "generic/mmatrix.c" +#undef nerv_matrix_ +#undef host_matrix_ +#undef MATRIX_USE_DOUBLE +#undef MATRIX_ELEM +#undef MATRIX_ELEM_PTR +#undef MATRIX_ELEM_FMT +#undef MATRIX_ELEM_WRITE_FMT + +#define NERV_GENERIC_MMATRIX +#define MATRIX_USE_INT +#define host_matrix_(NAME) host_matrix_int_##NAME +#define nerv_matrix_(NAME) nerv_matrix_host_int_##NAME +#include "generic/mmatrix.c" + +Matrix *nerv_matrix_(perm_gen)(int ncol, Status *status) { + int i; + Matrix *self = nerv_matrix_(create)(1, ncol, status); + if (status->err_code != MAT_NORMAL) + return NULL; + long *prow = self->data.i; + for (i = 0; i < ncol; i++) + prow[i] = i; + for (i = ncol - 1; i >= 0; i--) + { + size_t j = rand() % (i + 1); + long tmp = prow[i]; + prow[i] = prow[j]; + prow[j] = tmp; + } + return self; +} |