-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils.cpp
More file actions
122 lines (112 loc) · 3.53 KB
/
test_utils.cpp
File metadata and controls
122 lines (112 loc) · 3.53 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* test_utils.cpp
*
* Created on: Feb 2, 2013
* Author: igkiou
*/
#include <iostream>
#include "mex_utils.h"
//#include "mat_utils.h"
mex::MxString test() {
return mex::MxString("gkiou");
}
mex::MxString test2() {
mex::MxString ret("gkiou");
mex::MxString ret2(ret);
return ret2;
}
std::string test3() {
return std::string("gkiou");
}
template < class T >
inline std::ostream& operator << (std::ostream& os, const std::vector<T>& v)
{
os << "[";
for (typename std::vector<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
{
os << " " << *ii;
}
os << " ]";
return os;
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
int height = 10;
int width = 10;
// const int dims[3] = {height, width, 3};
// plhs[0] = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL); /* x */
mex::MxNumeric<float> temp(height, width);
// plhs[0] = temp.get_array();
temp = mex::MxNumeric<float>(height, width);
mex::MxNumeric<float> temp2(temp);
// mex::MxString tempg(mex::MxArray(temp.get_array()));
// tempg[0] = 0;
plhs[2] = temp.get_array();
temp[1] = 5.0;
std::vector<float> vec;
vec.push_back(10);
vec.push_back(20);
vec.push_back(30);
plhs[3] = mex::MxNumeric<float>(vec).get_array();
mex::MxNumeric<int> foo(height, width);
foo.getData()[0] = 10;
plhs[4] = foo.get_array();
std::vector<int> veci = foo.vectorize();
std::cout << "length " << veci.size() << std::endl;
for (int iter = 0, end = veci.size(); iter < end; ++iter) {
std::cout << "iter " << iter << " value "<< veci[iter] << std::endl;
}
std::array<bool, 10> dummy;
plhs[5] = mex::MxNumeric<bool>(dummy).get_array();
// mexPrintf("M %d N %d size %d numel %d.\n", foo.M(), foo.N(), foo.size(), foo.numel());
plhs[6] = mex::MxString(std::string("gkiou")).get_array();
plhs[7] = mex::MxString("gkiou").get_array();
std::string gkiou("gkiou");
plhs[8] = mex::MxString(gkiou).get_array();
mex::MxString gkiou2("gkiou");
plhs[9] = mex::MxString(gkiou2).get_array();
plhs[10] = test().get_array();
plhs[11] = test2().get_array();
std::vector<std::string> names;
std::vector<mex::MxArray*> vars;
names.push_back("field1");
names.push_back("field2");
names.push_back("field3");
mex::MxArray* tempp = new mex::MxNumeric<float>(height,width);
vars.push_back(tempp);
tempp = new mex::MxNumeric<bool>(height,width);
vars.push_back(tempp);
tempp = new mex::MxString("field");
vars.push_back(tempp);
plhs[12] = mex::MxStruct(names, vars).get_array();
delete vars[0];
delete vars[1];
delete vars[2];
std::vector<int> dims;
dims.push_back(10);
dims.push_back(5);
dims.push_back(2);
temp = mex::MxNumeric<float>(int(dims.size()), &dims[0]);
for (int iter = 0; iter < temp.getNumberOfElements(); ++iter) {
temp[iter] = iter;
}
std::vector<int> perm;
perm.push_back(2);
perm.push_back(1);
perm.push_back(3);
plhs[0] = temp.permute(perm).get_array();
plhs[1] = temp.get_array();
double* a = (double*) malloc(100 * sizeof(double));
double* b = (double*) malloc(100 * sizeof(double));
memcpy(a, b, 100 * sizeof(double));
// mex::MatFile file("test.mat", "r");
// std::vector<std::string> varnames = file.getVariableNames();
// std::cout << "number of variables: " << varnames.size() << std::endl;
// for (int iter = 0, end = varnames.size(); iter < end; ++iter) {
// std::cout << "variable " << iter << " name: " << varnames[iter] << std::endl;
// }
// file.write(temp, "temp1");
// plhs[1] = file.read(varnames[0]).get_array();
// file.clear(varnames[0]);
// mex::MatInputFile matfile("igkiou.mat");
// matfile.readNextVariable();
}