diff options
author | TianxingHe <htx_2006@hotmail.com> | 2016-01-19 20:13:49 -0800 |
---|---|---|
committer | TianxingHe <htx_2006@hotmail.com> | 2016-01-19 20:13:49 -0800 |
commit | dcad8a3f80fc55ca93984d981f9b829d2e4ea728 (patch) | |
tree | 61b9bc1d043883bb5d85dcb86cfb621396d75c41 /nerv/lib/matrix/generic/cumatrix.c | |
parent | 7449dd19c4d1669b483693f61add9d574e46f0b2 (diff) | |
parent | 37dec2610c92d03813c4e91ed58791ab60da6646 (diff) |
Merge pull request #21 from cloudygoose/txh18/rnnlm
Txh18/rnnlm new changes to lm side
Diffstat (limited to 'nerv/lib/matrix/generic/cumatrix.c')
-rw-r--r-- | nerv/lib/matrix/generic/cumatrix.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/nerv/lib/matrix/generic/cumatrix.c b/nerv/lib/matrix/generic/cumatrix.c index 65e0788..7582725 100644 --- a/nerv/lib/matrix/generic/cumatrix.c +++ b/nerv/lib/matrix/generic/cumatrix.c @@ -349,7 +349,7 @@ void nerv_matrix_(copy_rows_fromh_by_idx)(Matrix *a, const Matrix *b, long nrow = a->nrow; if (!(0 <= b_begin && b_begin + nrow <= idx->ncol)) NERV_EXIT_STATUS(status, MAT_INVALID_COPY_INTERVAL, 0); - float *idx_ptr = idx->data.f; + float *idx_ptr = MATRIX_ELEM_PTR_F(idx); int i; if (idx->nrow != 1) NERV_EXIT_STATUS(status, MAT_IDX_VECTOR_EXP, 0); @@ -393,15 +393,45 @@ void nerv_matrix_(copy_rows_fromd_by_idx)(Matrix *a, const Matrix *b, NERV_SET_STATUS(status, NERV_NORMAL, 0); } +void nerv_matrix_(copy_rows_fromd_by_colidx)(Matrix *a, const Matrix *b, + const Matrix *idx, int b_begin, Status *status) { + long nrow = a->nrow; + if (!(0 <= b_begin && b_begin + nrow <= idx->nrow)) + NERV_EXIT_STATUS(status, MAT_INVALID_COPY_INTERVAL, 0); + if (idx->ncol != 1) + NERV_EXIT_STATUS(status, MAT_IDX_VECTOR_EXP, 0); + if (a->ncol != b->ncol) { + printf("%d %d\n", a->ncol, b->ncol); + NERV_EXIT_STATUS(status, MAT_MISMATCH_DIM, 0); + } + PROFILE_START + cudak_(cuda_copy_rows_by_colidx)(b, a, idx, b_begin); + PROFILE_STOP + NERV_SET_STATUS(status, NERV_NORMAL, 0); +} + + #ifdef __NERV_FUTURE_CUDA_7 -void nerv_matrix_(update_select_rows)(Matrix *c, const Matrix *a, const Matrix *idx, double alpha, double beta, Status *status) { +void nerv_matrix_(update_select_rows_by_rowidx)(Matrix *c, const Matrix *a, const Matrix *idx, double alpha, double beta, Status *status) { long nrow = a->nrow; - if (idx->nrow != 1) + if (idx->nrow != 1 || idx->ncol != a->nrow) + NERV_EXIT_STATUS(status, MAT_IDX_VECTOR_EXP, 0); + if (a->ncol != c->ncol) + NERV_EXIT_STATUS(status, MAT_MISMATCH_DIM, 0); + PROFILE_START + cudak_(cuda_update_select_rows_by_rowidx)(c, a, idx, alpha, beta); + PROFILE_STOP + NERV_SET_STATUS(status, NERV_NORMAL, 0); +} + +void nerv_matrix_(update_select_rows_by_colidx)(Matrix *c, const Matrix *a, const Matrix *idx, double alpha, double beta, Status *status) { + long nrow = a->nrow; + if (idx->ncol != 1 || idx->nrow != a->nrow) NERV_EXIT_STATUS(status, MAT_IDX_VECTOR_EXP, 0); if (a->ncol != c->ncol) NERV_EXIT_STATUS(status, MAT_MISMATCH_DIM, 0); PROFILE_START - cudak_(cuda_update_select_rows)(c, a, idx, alpha, beta); + cudak_(cuda_update_select_rows_by_colidx)(c, a, idx, alpha, beta); PROFILE_STOP NERV_SET_STATUS(status, NERV_NORMAL, 0); } |