20 #ifndef JDFTX_ELECTRONIC_MATRIX_H 21 #define JDFTX_ELECTRONIC_MATRIX_H 23 #include <electronic/common.h> 24 #include <core/ManagedMemory.h> 25 #include <core/matrix3.h> 28 #include <gsl/gsl_cblas.h> 34 diagMatrix(
int N=0,
double d=0.) : std::vector<double>(N,d) {}
35 int nRows()
const {
return size(); }
36 int nCols()
const {
return size(); }
37 bool isScalar(
double absTol=1e-14,
double relTol=1e-14)
const;
39 diagMatrix& operator*=(
double s) {
for(
double& d: *
this) d*=s;
return *
this; }
42 diagMatrix operator()(
int iStart,
int iStop)
const;
43 diagMatrix operator()(
int iStart,
int iStep,
int iStop)
const;
44 void set(
int iStart,
int iStop,
const diagMatrix& m);
45 void set(
int iStart,
int iStep,
int iStop,
const diagMatrix& m);
48 void print(FILE* fp,
const char* fmt=
"%lg\t")
const;
51 void send(
int dest,
int tag=0)
const;
52 void recv(
int src,
int tag=0);
53 void bcast(
int root=0);
54 void allReduce(MPIUtil::ReduceOp op,
bool safeMode=
false);
64 int nRows()
const {
return nr; }
65 int nCols()
const {
return nc; }
66 int index(
int i,
int j)
const {
return nr*j+i; }
67 explicit operator bool()
const {
return nr*nc; }
69 void init(
int nrows,
int ncols,
bool onGpu=
false);
70 void reshape(
int nrows,
int ncols);
71 matrix(
int nrows=0,
int ncols=0,
bool onGpu=
false);
75 matrix(
const std::vector<complex>&);
82 complex operator()(
int i,
int j)
const;
85 matrix operator()(
int iStart,
int iStop,
int jStart,
int jStop)
const {
return (*
this)(iStart,1,iStop, jStart,1,jStop); }
88 matrix operator()(
int iStart,
int iStep,
int iStop,
int jStart,
int jStep,
int jStop)
const;
91 void set(
int i,
int j,
complex m);
94 void set(
int iStart,
int iStop,
int jStart,
int jStop,
const matrix& m) {
set(iStart,1,iStop, jStart,1,jStop, m); }
97 void set(
int iStart,
int iStep,
int iStop,
int jStart,
int jStep,
int jStop,
const matrix& m);
99 void scan(FILE* fp,
const char* fmt=
"%lg%+lgi");
100 void scan_real(FILE* fp);
101 void print(FILE* fp,
const char* fmt=
"%lg%+lgi\t")
const;
102 void print_real(FILE* fp,
const char* fmt=
"%lg\t")
const;
105 void diagonalize(
matrix& levecs, std::vector<complex>& eigs,
matrix& revecs)
const;
120 int nRows()
const {
return op==CblasNoTrans ? mat.nRows() : mat.nCols(); }
121 int nCols()
const {
return op==CblasNoTrans ? mat.nCols() : mat.nRows(); }
123 int index(
int i,
int j)
const {
return op==CblasNoTrans ? mat.
index(i,j) : mat.
index(j,i); }
127 : mat(mat), scale(scale), op(op) {}
131 : mat(smat.data), scale(smat.scale), op(op) {}
149 inline matrix& operator*=(
matrix& m,
double s) { scale(s, m);
return m; }
234 matrix zeroes(
int nRows,
int nCols);
241 const std::vector<complex>* phaseArr;
248 #endif // JDFTX_ELECTRONIC_MATRIX_H ScalarField pow(const ScalarField &, double alpha)
Elementwise power (preserve input)
CBLAS_TRANSPOSE op
pending operation (none, transpose or dagger)
Definition: matrix.h:118
Tptr operator*(const Tptr &in, double scaleFac)
Scalar multiply (preserve input)
Definition: Operators.h:116
void randomize(TptrCollection &x)
Initialize to normal random numbers:
Definition: ScalarFieldArray.h:154
Simulation grid descriptor.
Definition: GridInfo.h:45
Tptr conj(Tptr &&in)
Generic elementwise conjugate for complex data:
Definition: Operators.h:122
void scan(FILE *fp)
set submatrix to m at arbitrary increments
complex dot(const Tptr &X, const Tptr &Y)
Definition: Operators.h:196
double scale
pending scale factor
Definition: matrix.h:117
General complex matrix.
Definition: matrix.h:58
Template to avoid (delay) scaling operations on linear objects.
int index(int i, int j) const
Index into data()
Definition: matrix.h:66
Base class for managed-memory objects (that could potentially live on GPUs as well) ...
Definition: ManagedMemory.h:26
Real diagonal matrix.
Definition: matrix.h:31
Tptr & operator-=(Tptr &in, const Tptr &other)
Decrement.
Definition: Operators.h:170
int index(int i, int j) const
Index into data() with possible transpose.
Definition: matrix.h:123
const matrix & mat
matrix
Definition: matrix.h:116
Tptr clone(const Tptr &X)
Clone (NOTE: operator= is by reference for the ScalarField classes)
Definition: Operators.h:111
matrixScaledTransOp(const scaled< matrix > &smat, CBLAS_TRANSPOSE op=CblasNoTrans)
Create from a scaled matrix, with an optional op.
Definition: matrix.h:130
matrix operator()(int iStart, int iStop, int jStart, int jStop) const
get submatrix of elements (iStart <= i < iStop, jStart <= j < jStop)
Definition: matrix.h:85
matrixScaledTransOp(const matrix &mat, double scale=1.0, CBLAS_TRANSPOSE op=CblasNoTrans)
Create from a matrix with an optional scale and op:
Definition: matrix.h:126
bool isScalar(double absTol=1e-14, double relTol=1e-14) const
Check if all entries are identical within threshold.
Tptr operator+(const Tptr &in1, const Tptr &in2)
Add (preserve inputs)
Definition: Operators.h:171
ScalarField inv(const ScalarField &)
Elementwise reciprocal (preserve input)
Geometry of the simulation grid.
Matrix with a pending scale and transpose operation.
Definition: matrix.h:115
void print(FILE *fp, const char *fmt="%lg\t") const
print (ascii) to stream
Complex number (need to define our own because we need operators for gpu code as well) ...
Definition: scalar.h:49
void axpy(double alpha, const Tptr &X, Tptr &Y)
Generic axpy for complex data types (Note: null pointers are treated as zero)
Definition: Operators.h:158
complex conjOp(complex a) const
return conjugate if op requires it
Definition: matrix.h:122
A block matrix formed by repeating (tiling) a dense matrix along the diagonal.
Definition: matrix.h:237
Tptr & operator+=(Tptr &in, const Tptr &other)
Increment.
Definition: Operators.h:169
Tptr operator-(const Tptr &in1, const Tptr &in2)
Subtract (preserve inputs)
Definition: Operators.h:175
double nrm2(const Tptr &X)
Definition: Operators.h:199