DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
utlSpams.h
Go to the documentation of this file.
1 
17 #ifndef __utlSpams_h
18 #define __utlSpams_h
19 
20 #include "linalg.h"
21 #include "utlNDArray.h"
22 
23 namespace spams
24 {
25 
26 template <class T>
27 void
28 UtlMatrixToMatrix ( const utl::NDArray<T,2>& matUtl, Matrix<T>& matSpams )
29 {
30  matSpams.resize(matUtl.Rows(), matUtl.Columns());
31  T const* matUtl_data = matUtl.GetData();
32  T* matSpams_data = matSpams.rawX();
33  if (matUtl.Rows() >= matUtl.Columns())
34  {
35  for ( int j = 0; j < matUtl.Columns(); j += 1 )
36  cblas_copy<T>(matUtl.Rows(), (T*)matUtl_data+j, matUtl.Columns(), matSpams_data+j*matUtl.Rows(),1);
37  }
38  else
39  {
40  for ( int i = 0; i < matUtl.Rows(); i += 1 )
41  cblas_copy<T>(matUtl.Columns(), (T*)matUtl_data+i*matUtl.Columns(), 1, matSpams_data+i,matUtl.Rows());
42  }
43 }
44 
45 template <class T>
46 void
47 MatrixToUtlMatrix ( const Matrix<T>& matSpams, utl::NDArray<T,2>& matUtl )
48 {
49  matUtl.ReSize(matSpams.m(), matSpams.n());
50  T* matUtl_data = matUtl.GetData();
51  const T * matSpams_data = matSpams.X();
52  if (matUtl.Rows() >= matUtl.Columns())
53  {
54  for ( int j = 0; j < matUtl.Columns(); j += 1 )
55  cblas_copy<T>(matUtl.Rows(), (T*)matSpams_data+j*matUtl.Rows(),1, matUtl_data+j, matUtl.Columns());
56  }
57  else
58  {
59  for ( int i = 0; i < matUtl.Rows(); i += 1 )
60  cblas_copy<T>(matUtl.Columns(), (T*)matSpams_data+i,matUtl.Rows(), matUtl_data+i*matUtl.Columns(), 1);
61  }
62 }
63 
64 template <class T>
65 void
67 {
68  vec.resize(v.size());
69  cblas_copy<T>(v.Size(), v.GetData(),1, vec.rawX(), 1);
70 }
71 
72 template <class T>
73 void
75 {
76  vec.ReSize(v.n());
77  cblas_copy<T>(vec.Size(), v.rawX(),1, vec.GetData(), 1);
78 }
79 
80 template <class T>
81 void
83 {
84  result.ReSize(mat.m(), mat.n());
85  result.Fill(0.0);
86  int* pB = mat.pB();
87  int* pE = mat.pE();
88  int* r = mat.r();
89  for ( int i = 0; i < mat.n(); i += 1 )
90  for (int j = pB[i]; j<pE[i]; ++j)
91  result(r[j], i) = mat.v(j);
92 }
93 
94 
95 }
96 
97 
98 #endif
Sparse Matrix class.
Definition: linalg.h:63
NDArray<T,1> is a vector class which uses blas mkl.
Definition: utlVector.h:36
Definition: dag.h:26
int pB(const int i) const
returns pB[i]
Definition: linalg.h:779
void VectorToUtlVector(const Vector< T > &v, utl::NDArray< T, 1 > &vec)
Definition: utlSpams.h:74
int * pE() const
Direct access to _pE.
Definition: linalg.h:806
T * rawX() const
returns a modifiable reference of the data, DANGEROUS
Definition: linalg.h:593
SizeType Columns() const
Definition: utlMatrix.h:137
SizeType Rows() const
Definition: utlMatrix.h:136
NDArray<T,2> is a row-major matrix.
Definition: utlMatrix.h:37
int m() const
Definition: linalg.h:222
int n() const
returns the size of the vector
Definition: linalg.h:591
T v(const int i) const
returns v[i]
Definition: linalg.h:783
Dense Vector class.
Definition: linalg.h:65
void Fill(const T &value)
Definition: utlNDArray.h:922
int m() const
returns the number of columns
Definition: linalg.h:789
int n() const
Number of columns.
Definition: linalg.h:224
void MatrixToUtlMatrix(const Matrix< T > &matSpams, utl::NDArray< T, 2 > &matUtl)
Definition: utlSpams.h:47
void resize(const int n)
resize the vector
Definition: linalg.h:2876
int r(const int i) const
returns r[i]
Definition: linalg.h:781
void SpMatrixToUtlMatrix(const SpMatrix< T > &mat, utl::NDArray< T, 2 > &result)
Definition: utlSpams.h:82
void UtlVectorToVector(const utl::NDArray< T, 1 > &v, Vector< T > &vec)
Definition: utlSpams.h:66
void UtlMatrixToMatrix(const utl::NDArray< T, 2 > &matUtl, Matrix< T > &matSpams)
Definition: utlSpams.h:28
int n() const
returns the number of rows
Definition: linalg.h:787
SizeType Size() const
Definition: utlNDArray.h:321
bool ReSize(const SizeType rows, const SizeType cols)
Definition: utlMatrix.h:140
void resize(int m, int n)
Resize the matrix.
Definition: linalg.h:1217
const T * X() const
return a non-modifiable reference to the data
Definition: linalg.h:256
bool ReSize(const SizeType size)
Definition: utlVector.h:167
Dense Matrix class.
Definition: linalg.h:61
T * rawX() const
reference a modifiable reference to the data, DANGEROUS
Definition: linalg.h:254