-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmymex.h
More file actions
executable file
·92 lines (79 loc) · 2.46 KB
/
mymex.h
File metadata and controls
executable file
·92 lines (79 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef MYMEX_H
#define MYMEX_H
#include <vector>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <typedef.h>
using std::vector;
const int mxDOUBLE_CLASS = 1;
const int mxSINGLE_CLASS = 2;
const int mxREAL = 1;
typedef int mwSize;
int mx_real_type();
class mxArray {
public:
char *data;
int NDim;
int *Dims;
int classID;
int _nelem;
mxArray() {
data = NULL;
Dims = NULL;
}
mxArray(int ndim, const int * dims, int _classID, int fake)
: classID(_classID), NDim(ndim)
{
if (0 == ndim) {
std::cout << "TODO(haosu): ndim=0! fix that";
}
Dims = new int[ndim];
memcpy(Dims, dims, sizeof(int) * ndim);
_nelem = 1;
for (int i = 0; i < ndim; i++) {
_nelem *= dims[i];
}
classID = _classID;
if (classID == mxDOUBLE_CLASS) {
data = new char[_nelem * sizeof(double)];
memset(data, 0, _nelem * sizeof(double));
} else if (classID == mxSINGLE_CLASS) {
data = new char[_nelem * sizeof(float)];
memset(data, 0, _nelem * sizeof(float));
} else {
data = NULL;
}
}
~mxArray();
mxArray & operator+=(const mxArray & rhs);
mxArray & operator+=(const double & rhs);
const mxArray operator+(const mxArray & rhs);
const mxArray operator+(const double & rhs);
friend mxArray operator-(const mxArray & op);
double get(vector<int> &subscript, double & retval);
real get2D(int row, int col, real &retval) const;
real get3D(int subidx1, int subidx2, int subidx3, real &retval) const;
double * getPtr3D(int subidx1, int subidx2, int subidx3);
void set(vector<int> subscript, double val);
void set2D(int row, int col, double val);
void set3D(int subidx1, int subidx2, int subidx3, double val);
mxArray * clone();
void negative();
};
double mxGetScalar(const mxArray * mxarray);
void mxFree(mxArray ** mxarray);
void mxFree(double * array);
void mxFree(float * array);
mxArray * mxCreateNumericArray(const int ndim, int const * dims, const int type, const int fake);
mxArray * mxCreateDoubleScalar(double val);
void * mxGetPr(const mxArray * mxarray);
void * mxCalloc(int nelem, int typesize);
int * mxGetDimensions(const mxArray * mxarray);
int mxGetNumberOfDimensions(const mxArray * mxarray);
int mxGetClassID(const mxArray * mxarray);
void mexErrMsgTxt(const char * msg);
int size(const mxArray * mxarray, int k);
int WriteToDisk3D(vector<mxArray *> & vecMatrix, std::string szFileName);
#endif