aboutsummaryrefslogtreecommitdiff
path: root/matrix/mmatrix.c
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2015-06-05 10:58:57 +0800
committerDeterminant <[email protected]>2015-06-05 10:58:57 +0800
commitdf737041e4a9f3f55978cc74db9a9cea27fa9fa0 (patch)
treed656820be286550bc548f7c5ed4b1dcfecf3691c /matrix/mmatrix.c
parentea6f2990f99dd9ded6a0e74d75a3ec84900a2518 (diff)
add profiling; add ce accurarcy; several other changes
Diffstat (limited to 'matrix/mmatrix.c')
-rw-r--r--matrix/mmatrix.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/matrix/mmatrix.c b/matrix/mmatrix.c
index ab15197..81f8dfc 100644
--- a/matrix/mmatrix.c
+++ b/matrix/mmatrix.c
@@ -29,5 +29,34 @@ const char *nerv_matrix_(tname) = "nerv.MMatrixDouble";
#define host_matrix_(NAME) host_matrix_int_##NAME
#define nerv_matrix_(NAME) nerv_matrix_host_int_##NAME
const char *nerv_matrix_(tname) = "nerv.MMatrixInt";
+#define MMATRIX_INIT(L) host_matrix_(init_extra)(L)
+
+static const luaL_Reg nerv_matrix_(extra_methods_int)[];
+static void host_matrix_(init_extra)(lua_State *L) {
+ luaN_append_methods(L, nerv_matrix_(extra_methods_int));
+}
+
#include "generic/mmatrix.c"
+static int nerv_matrix_(perm_gen)(lua_State *L) {
+ int i, ncol = luaL_checkinteger(L, 1);
+ Matrix *self = nerv_matrix_(new_)(L, 1, ncol);
+ 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;
+ }
+ luaT_pushudata(L, self, nerv_matrix_(tname));
+ return 1;
+}
+
+static const luaL_Reg nerv_matrix_(extra_methods_int)[] = {
+ {"perm_gen", nerv_matrix_(perm_gen)},
+ {NULL, NULL}
+};
+