Guest User

Untitled

a guest
Sep 2nd, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. rows = NM_SHAPE0($input);
  2. cols = NM_SHAPE1($input);
  3. int32_t dtype = NM_DTYPE($input);
  4.  
  5. // only dense is supported
  6. if (NM_STYPE($input) != 0)
  7. SWIG_fail;
  8.  
  9. DENSE_STORAGE* s = (DENSE_STORAGE*)NM_STORAGE($input);
  10.  
  11. array = SG_MALLOC(SGTYPE, rows * cols);
  12.  
  13. for (i = 0; i < rows; i++) {
  14. for (j = 0; j < cols; j++) {
  15. switch(dtype) {
  16. case 0:
  17. array[i * cols + j] = ((unsigned char*)s->elements)[i * cols + j];
  18. break;
  19. case 1:
  20. array[i * cols + j] = ((char*)s->elements)[i * cols + j];
  21. break;
  22. case 2:
  23. array[i * cols + j] = ((short*)s->elements)[i * cols + j];
  24. break;
  25. case 3:
  26. array[i * cols + j] = ((int*)s->elements)[i * cols + j];
  27. break;
  28. case 4:
  29. array[i * cols + j] = ((long*)s->elements)[i * cols + j];
  30. break;
  31. case 5:
  32. array[i * cols + j] = ((float*)s->elements)[i * cols + j];
  33. break;
  34. case 6:
  35. array[i * cols + j] = ((double*)s->elements)[i * cols + j];
  36. break;
  37. default:
  38. SWIG_fail;
  39. break;
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment