Guest User

Untitled

a guest
Jun 6th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1.   namespace mlpack
  2.   {
  3.   namespace ind_sub
  4.   {
  5.   #if (true)
  6.   inline
  7.   uvec
  8.   ind3sub(const SizeMat& s, const uword i)
  9.     {
  10.     arma_extra_debug_sigprint();
  11.  
  12.     arma_debug_check( (i >= (s.n_rows * s.n_cols) ), "ind2sub(): index out of range" );
  13.  
  14.     uvec out(2);
  15.  
  16.     out[0] = i % s.n_rows;
  17.     out[1] = i / s.n_rows;
  18.  
  19.     return out;
  20.     }
  21.  
  22.   uvec
  23.   ind2sub(const SizeCube& s, const uword i)
  24.     {
  25.     arma_extra_debug_sigprint();
  26.  
  27.     arma_debug_check( (i >= (s.n_rows * s.n_cols * s.n_slices) ), "ind2sub(): index out of range" );
  28.  
  29.     const uword n_elem_slice = s.n_rows * s.n_cols;
  30.  
  31.     const uword slice  = i / n_elem_slice;
  32.     const uword j      = i - (slice * n_elem_slice);
  33.     const uword row    = j % s.n_rows;
  34.     const uword col    = j / s.n_rows;
  35.  
  36.     uvec out(3);
  37.  
  38.     out[0] = row;
  39.     out[1] = col;
  40.     out[2] = slice;
  41.  
  42.     return out;
  43.     }
  44.  
  45.  
  46.   arma_inline
  47.   uword
  48.   sub2ind(const SizeMat& s, const uword row, const uword col)
  49.     {
  50.     arma_extra_debug_sigprint();
  51.  
  52.     arma_debug_check( ((row >= s.n_rows) || (col >= s.n_cols)), "sub2ind(): subscript out of range" );
  53.  
  54.     return uword(row + col*s.n_rows);
  55.     }
  56.  
  57.  
  58.   arma_inline
  59.   uword
  60.   sub2ind(const SizeCube& s, const uword row, const uword col, const uword slice)
  61.     {
  62.     arma_extra_debug_sigprint();
  63.  
  64.     arma_debug_check( ((row >= s.n_rows) || (col >= s.n_cols) || (slice >= s.n_slices)), "sub2ind(): subscript out of range" );
  65.  
  66.     return uword( (slice * s.n_rows * s.n_cols) + (col * s.n_rows) + row );
  67.     }
  68. #endif
  69.  } // end namespace ind_sub
  70.  } // end namespace mlpack
Add Comment
Please, Sign In to add comment