#include "myvec.h"
#include <stdlib.h>
#include <math.h>
#include "stackmem.h"
#ifdef MEMDEBUG
#include "mnemosyne.h"
#endif
myvec *myvec_new(int i) {
myvec *this = (myvec *)claim(sizeof(myvec));
this->N = i; this->p = (double *)claim((sizeof(double) * i));
for (i = 0; i < this->N; i++) this->p[i] = 0.0;
return this;
}
mymatrix *mymatrix_new(int i, int j) {
mymatrix *this = claim(sizeof(mymatrix));
this->Nr = i; this->Nc = j; this->p = (double **)claim((sizeof(double *)) * this->Nr);
for (i = 0; i < this->Nr; i++) this->p[i] = (double *)claim((sizeof(double)) * this->Nc);
return this;
}
double myvec_crc(myvec *mv) {
int i;
double crc = 0.0;
for (i = 0; i < mv->N; i++) {
crc += mv->p[i];
}
return crc;
}
double mymatrix_crc(mymatrix *mm) {
int i, j;
double crc = 0.0;
for (i = 0; i < mm->Nr; i++) {
for (j = 0; j < mm->Nc; j++) {
crc += mm->p[i][j];
}
}
return crc;
}