diff options
Diffstat (limited to 'nerv/matrix/generic/cumatrix.c')
-rw-r--r-- | nerv/matrix/generic/cumatrix.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/nerv/matrix/generic/cumatrix.c b/nerv/matrix/generic/cumatrix.c index 08cb4c2..e1519b0 100644 --- a/nerv/matrix/generic/cumatrix.c +++ b/nerv/matrix/generic/cumatrix.c @@ -247,8 +247,8 @@ static int nerv_matrix_(lua_copy_rows_fromd_by_idx)(lua_State *L) { const Matrix *b = luaT_checkudata(L, 2, nerv_matrix_(tname)); const Matrix *idx = luaT_checkudata(L, 3, nerv_matrix_(tname)); long nrow = a->nrow; - int b_begin = lua_gettop(L) > 3 ? luaL_checkinteger(L, 4) : 0; - nerv_matrix_(copy_rows_fromd_by_idx)(a, b, idx, b_begin, &status); + int idx_begin = lua_gettop(L) > 3 ? luaL_checkinteger(L, 4) : 0; + nerv_matrix_(copy_rows_fromd_by_idx)(a, b, idx, idx_begin, &status); NERV_LUA_CHECK_STATUS(L, status); return 0; } @@ -291,6 +291,22 @@ static int nerv_matrix_(lua_scale_rows_by_row)(lua_State *L) { return 0; } +#ifdef __NERV_FUTURE_CUDA_7 +static int nerv_matrix_(lua_update_select_rows)(lua_State *L) { + /* update c's select rows, + * i.e. c[idx[i]] = c[idx[i]] * (1 - beta * alpha) + a[i] * alpha */ + Status status; + Matrix *c = luaT_checkudata(L, 1, nerv_matrix_(tname)); + const Matrix *a = luaT_checkudata(L, 2, nerv_matrix_(tname)); + const Matrix *idx = luaT_checkudata(L, 3, nerv_matrix_(tname)); + MATRIX_ELEM alpha = luaL_checknumber(L, 4); + MATRIX_ELEM beta = luaL_checknumber(L, 5); + nerv_matrix_(update_select_rows)(c, a, idx, alpha, beta, &status); + NERV_LUA_CHECK_STATUS(L, status); + return 0; +} +#endif + static const luaL_Reg nerv_matrix_(extra_methods)[] = { {"colsum", nerv_matrix_(lua_colsum)}, {"colsame", nerv_matrix_(lua_colsame)}, @@ -321,6 +337,9 @@ static const luaL_Reg nerv_matrix_(extra_methods)[] = { {"rearrange_frm", nerv_matrix_(lua_rearrange_frm)}, {"scale_rows_by_row", nerv_matrix_(lua_scale_rows_by_row)}, {"scale_rows_by_col", nerv_matrix_(lua_scale_rows_by_col)}, +#ifdef __NERV_FUTURE_CUDA_7 + {"update_select_rows", nerv_matrix_(lua_update_select_rows)}, +#endif {NULL, NULL} }; |