ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
matrix_wrapper_tianhe2.h
Go to the documentation of this file.
1//==========================================================
2// AUTHOR : Peize Lin
3// DATE : 2018-07-31
4//==========================================================
5
6#ifndef MATRIX_WRAPPER_H
7#define MATRIX_WRAPPER_H
8
9#include "matrix.h"
10#include <cstring>
11namespace ModuleBase
12{
13
14// !!! Attention: c is very dangerous, may point to somewhere deleted
15
16class Matrix_Wrapper
17{
18public:
19 double *c;
20 int nr;
21 int nc;
22
23 Matrix_Wrapper(): nr(0), nc(0), c(nullptr){}
24 Matrix_Wrapper( const matrix &m ): nr(m.nr), nc(m.nc), c(m.c){}
25 inline void create( const int nr_in, const int nc_in, const bool flag_zero );
26 inline matrix to_matrix();
27 Matrix_Wrapper( const Matrix_Wrapper &m ): nr(m.nr), nc(m.nc), c(m.c){}
28 Matrix_Wrapper( Matrix_Wrapper &m ): nr(m.nr), nc(m.nc), c(m.c){}
29 Matrix_Wrapper( Matrix_Wrapper &&m ): nr(m.nr), nc(m.nc), c(m.c){}
30 inline Matrix_Wrapper&operator=( const Matrix_Wrapper&m ){ nr=m.nr; nc=m.nc; c=m.c; return *this; };
31 inline Matrix_Wrapper&operator=( Matrix_Wrapper&m ){ nr=m.nr; nc=m.nc; c=m.c; return *this; };
32 inline Matrix_Wrapper&operator=( Matrix_Wrapper&&m ){ nr=m.nr; nc=m.nc; c=m.c; return *this; };
33};
34
35
36inline void Matrix_Wrapper::create( const int nr_in, const int nc_in, const bool flag_zero )
37{
38 nr = nr_in; nc = nc_in;
39 c = new double[nr*nc];
40 if(flag_zero)
41 memset( c, 0, sizeof(double)*nr*nc );
42}
43
44inline matrix Matrix_Wrapper::to_matrix()
45{
46 matrix m;
47 m.nr = nr; m.nc = nc;
48 m.c = c;
49 nr = nc = 0;
50 c = nullptr;
51 return m;
52}
53
54}
55#endif
Definition matrix_wrapper.h:20
Matrix_Wrapper & operator=(Matrix_Wrapper &m)
Definition matrix_wrapper_tianhe2.h:31
Matrix_Wrapper(Matrix_Wrapper &&m)
Definition matrix_wrapper_tianhe2.h:29
Matrix_Wrapper(Matrix_Wrapper &m)
Definition matrix_wrapper_tianhe2.h:28
Matrix_Wrapper()
Definition matrix_wrapper_tianhe2.h:23
Matrix_Wrapper & operator=(Matrix_Wrapper &&m)
Definition matrix_wrapper_tianhe2.h:32
Matrix_Wrapper & operator=(const Matrix_Wrapper &m)
Definition matrix_wrapper_tianhe2.h:30
int nr
Definition matrix_wrapper.h:22
double * c
Definition matrix_wrapper.h:24
Matrix_Wrapper(const matrix &m)
Definition matrix_wrapper_tianhe2.h:24
void create(const int nr_in, const int nc_in, const bool flag_zero)
int nc
Definition matrix_wrapper.h:23
Matrix_Wrapper(const Matrix_Wrapper &m)
Definition matrix_wrapper_tianhe2.h:27
Definition matrix.h:19
int nr
Definition matrix.h:23
Definition array_pool.h:6