Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rows = NM_SHAPE0($input);
- cols = NM_SHAPE1($input);
- int32_t dtype = NM_DTYPE($input);
- // only dense is supported
- if (NM_STYPE($input) != 0)
- SWIG_fail;
- DENSE_STORAGE* s = (DENSE_STORAGE*)NM_STORAGE($input);
- array = SG_MALLOC(SGTYPE, rows * cols);
- for (i = 0; i < rows; i++) {
- for (j = 0; j < cols; j++) {
- switch(dtype) {
- case 0:
- array[i * cols + j] = ((unsigned char*)s->elements)[i * cols + j];
- break;
- case 1:
- array[i * cols + j] = ((char*)s->elements)[i * cols + j];
- break;
- case 2:
- array[i * cols + j] = ((short*)s->elements)[i * cols + j];
- break;
- case 3:
- array[i * cols + j] = ((int*)s->elements)[i * cols + j];
- break;
- case 4:
- array[i * cols + j] = ((long*)s->elements)[i * cols + j];
- break;
- case 5:
- array[i * cols + j] = ((float*)s->elements)[i * cols + j];
- break;
- case 6:
- array[i * cols + j] = ((double*)s->elements)[i * cols + j];
- break;
- default:
- SWIG_fail;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment