44 static Treal
maxdiff(
const Treal* f1,
const Treal* f2,
int size) {
47 for(
int i = 0; i < size * size; i++) {
50 diff = (diff > tmpdiff ? diff : tmpdiff);
56 static Treal
maxdiff_tri(
const Treal* f1,
const Treal* f2,
int size) {
59 for (
int col = 0; col < size; col++)
60 for (
int row = 0; row < col + 1; row++) {
62 diff = (diff > tmpdiff ? diff : tmpdiff);
69 static Treal
frobdiff(
const Treal* f1,
const Treal* f2,
int size) {
72 for(
int i = 0; i < size * size; i++) {
81 static void fileread(T *ptr,
int size,FILE*) {
82 std::cout<<
"error reading file"<<std::endl;
85 void fileread<double>(
double *ptr,
int size,FILE* file) {
86 fread(ptr,
sizeof(
double),size*size,file);
89 void fileread<float>(
float *ptr,
int size,FILE* file) {
90 double* tmpptr=
new double [size*size];
91 fread(tmpptr,
sizeof(
double),size*size,file);
92 for (
int i=0;i<size*size;i++)
94 ptr[i]=(float)tmpptr[i];
99 template<
typename Treal,
typename Trealonfile>
100 static void fileread(Treal *ptr,
int size, FILE* file) {
101 if (
sizeof(Trealonfile) ==
sizeof(Treal))
102 fread(ptr,
sizeof(Treal),size,file);
104 Trealonfile* tmpptr=
new Trealonfile[size];
105 fread(tmpptr,
sizeof(Trealonfile),size,file);
106 for (
int i = 0; i < size; i++) {
107 ptr[i]=(Treal)tmpptr[i];
114 template<
typename Treal,
typename Tmatrix>
116 char const *
const matrixPath,
118 FILE* matrixfile=fopen(matrixPath,
"rb");
120 throw Failure(
"read_matrix: Cannot open inputfile");
122 Treal* matrixfull =
new Treal [size*size];
123 fileread<Treal, double>(matrixfull, size*size, matrixfile);
125 A.assign_from_full(matrixfull, size, size);
130 template<
typename Treal,
typename Trealonfile,
typename Tmatrix>
132 char const *
const rowPath,
133 char const *
const colPath,
134 char const *
const valPath,
136 FILE* rowfile=fopen(rowPath,
"rb");
138 throw Failure(
"read_matrix: Cannot open inputfile rowfile");
140 FILE* colfile=fopen(colPath,
"rb");
142 throw Failure(
"read_matrix: Cannot open inputfile colfile");
144 FILE* valfile=fopen(valPath,
"rb");
146 throw Failure(
"read_matrix: Cannot open inputfile valfile");
148 int* row =
new int[nval];
149 int* col =
new int[nval];
150 Treal* val =
new Treal[nval];
151 fileread<int, int>(row, nval, rowfile);
152 fileread<int, int>(col, nval, colfile);
153 fileread<Treal, Trealonfile>(val, nval, valfile);
156 A.assign_from_sparse(row, col, val, nval);
158 Treal* compval =
new Treal[nval];
159 A.get_values(row, col, compval, nval);
162 for (
int i = 0; i < nval; i++) {
166 std::cout<<
"Maxdiff: "<<
maxdiff<<std::endl;
174 template<
typename Treal>
179 char* atomfile(atomsPath);
180 std::ifstream input(atomfile);
182 throw Failure(
"read_xyz: Cannot open inputfile");
184 input >> std::setprecision(10);
185 Treal* xtmp =
new Treal[natoms];
186 Treal* ytmp =
new Treal[natoms];
187 Treal* ztmp =
new Treal[natoms];
188 int* atomstart =
new int[natoms+1];
189 for(
int i = 0 ; i < natoms ; i++) {
193 input >> atomstart[i];
195 atomstart[natoms] = size;
196 for (
int atom = 0; atom < natoms; atom++)
197 for (
int bf = atomstart[atom]; bf < atomstart[atom + 1]; bf++) {
Definition: allocate.cc:39
Treal template_blas_fabs(Treal x)
static Treal maxdiff_tri(const Treal *f1, const Treal *f2, int size)
Definition: general.h:56
static void read_sparse_matrix(Tmatrix &A, char const *const rowPath, char const *const colPath, char const *const valPath, int const nval)
Definition: general.h:131
static void read_xyz(Treal *x, Treal *y, Treal *z, char *atomsPath, int const natoms, int const size)
Definition: general.h:175
static void read_matrix(Tmatrix &A, char const *const matrixPath, int const size)
Definition: general.h:115
static Treal maxdiff(const Treal *f1, const Treal *f2, int size)
Definition: general.h:44
static Treal frobdiff(const Treal *f1, const Treal *f2, int size)
Definition: general.h:69
static void fileread(Treal *ptr, int size, FILE *file)
Definition: general.h:100
Treal template_blas_sqrt(Treal x)