13 #ifndef __SGMATRIX_H__ 14 #define __SGMATRIX_H__ 17 #include <shogun/lib/config.h> 26 template <
class,
int,
int,
int,
int,
int>
class Matrix;
28 template <
class,
int,
class>
class Map;
33 template<
class T>
class SGVector;
81 return gpu_ptr != NULL;
84 #ifndef SWIG // SWIG should skip this part 85 #if defined(HAVE_CXX0X) || defined(HAVE_CXX11) 88 template <
typename ST>
using container_type =
SGMatrix<ST>;
90 #endif // define (HAVE_CXX0X) || defined(HAVE_CXX11) 123 operator EigenMatrixXtMap()
const;
135 #ifndef SWIG // SWIG should skip this part 143 const int64_t c = col;
144 return &matrix[c*num_rows];
167 const int64_t c = i_col;
168 return matrix[c*num_rows + i_row];
177 return matrix[index];
187 const int64_t c = i_col;
188 return matrix[c*num_rows + i_row];
197 return matrix[index];
200 #endif // SWIG should skip this part 210 return (*
this)(row, col);
221 (*this)(row, col)=el;
224 #ifndef SWIG // SWIG should skip this part 245 const uint64_t c=num_cols;
263 if (matrix != other.
matrix)
293 bool is_symmetric()
const;
296 T max_single()
const;
302 static T* clone_matrix(
const T* matrix, int32_t nrows, int32_t ncols);
305 static void transpose_matrix(
306 T*& matrix, int32_t& num_feat, int32_t& num_vec);
309 static void create_diagonal_matrix(T* matrix, T* v,int32_t size);
337 static double* compute_eigenvectors(
double* matrix,
int n,
int m);
349 void compute_few_eigenvectors(
double* matrix_,
double*& eigenvalues,
double*& eigenvectors,
350 int n,
int il,
int iu);
362 bool transpose_A=
false,
bool transpose_B=
false,
372 float64_t* matrix, int32_t rows, int32_t cols,
379 float64_t* mat, int32_t cols, int32_t rows);
382 static T* get_row_sum(T* matrix, int32_t m, int32_t n);
385 static T* get_column_sum(T* matrix, int32_t m, int32_t n);
391 static void center_matrix(T* matrix, int32_t m, int32_t n);
394 void remove_column_mean();
397 void display_matrix(
const char* name=
"matrix")
const;
400 static void display_matrix(
401 const T* matrix, int32_t rows, int32_t cols,
402 const char* name=
"matrix",
const char* prefix=
"");
405 static void display_matrix(
406 const SGMatrix<T> matrix,
const char* name=
"matrix",
407 const char* prefix=
"");
427 void load(
CFile* loader);
433 void save(
CFile* saver);
434 #endif // #ifndef SWIG // SWIG should skip this part 441 virtual void init_data();
444 virtual void free_data();
448 std::atomic<bool> m_on_gpu;
453 void assert_on_cpu()
const 456 SG_SERROR(
"Direct memory access not possible when data is in GPU memory.\n");
470 #endif // __SGMATRIX_H__ T & operator[](index_t index)
const T & operator[](index_t index) const
const T & operator()(index_t i_row, index_t i_col) const
const T & get_element(index_t row, index_t col)
Eigen::Map< EigenMatrixXt, 0, Eigen::Stride< 0, 0 > > EigenMatrixXtMap
void scale(SGVector< T > &a, SGVector< T > &result, T alpha=1)
void set_element(const T &el, index_t row, index_t col)
Eigen::Matrix< T,-1,-1, 0,-1,-1 > EigenMatrixXt
void set_const(Container< T > &a, T value)
SG_FORCED_INLINE bool operator==(const SGMatrix< T > &other) const
T * get_column_vector(index_t col) const
std::shared_ptr< GPUMemoryBase< T > > gpu_ptr
shogun reference count managed data
A File access base class.
all of classes and functions are contained in the shogun namespace
Interface for GPU memory libraries.
Linalg methods with Eigen3 backend.
T & operator()(index_t i_row, index_t i_col)