Mimetic Operators Library Enhanced 4.0
Loading...
Searching...
No Matches
Utils Class Reference

#include <utils.h>

Public Member Functions

void meshgrid (const vec &x, const vec &y, mat &X, mat &Y)
 
void meshgrid (const vec &x, const vec &y, const vec &z, cube &X, cube &Y, cube &Z)
 

Static Public Member Functions

static sp_mat spkron (const sp_mat &A, const sp_mat &B)
 
static sp_mat spjoin_rows (const sp_mat &A, const sp_mat &B)
 
static sp_mat spjoin_cols (const sp_mat &A, const sp_mat &B)
 
static vec spsolve_eigen (const sp_mat &A, const vec &b)
 

Detailed Description

Definition at line 11 of file utils.h.

Member Function Documentation

◆ meshgrid() [1/2]

void Utils::meshgrid ( const vec & x,
const vec & y,
const vec & z,
cube & X,
cube & Y,
cube & Z )

Definition at line 178 of file utils.cpp.

179{
180 int m = x.n_elem;
181 int n = y.n_elem;
182 int o = z.n_elem;
183
184 assert(m > 0);
185 assert(n > 0);
186 assert(o > 0);
187
188 // Temporary Holder of sheet of cube
189 mat sheet(m, n, fill::zeros);
190
191 // Build X
192 vec t(n, fill::ones);
193
194 X.zeros(m, n, o);
195 Y.zeros(m, n, o);
196 Z.zeros(m, n, o);
197
198 // Sheet that repeats each slice
199 for(int ii = 0; ii < m; ++ii) {
200 sheet.row(ii) = x(ii) * t.t();
201 t.ones();
202 }
203
204 for(int kk = 0; kk < o; ++kk)
205 X.slice(kk) = sheet;
206
207 // Y Cube, repeats same sheet as well
208 for(int ii = 0; ii < m; ++ii)
209 sheet.row(ii) = y.t();
210
211 for(int kk = 0; kk < o; ++kk)
212 Y.slice(kk) = sheet;
213
214 // Z cube goes by slices each with same value
215 for(int kk = 0; kk < o; ++kk)
216 Z.slice(kk).fill(z(kk));
217}

◆ meshgrid() [2/2]

void Utils::meshgrid ( const vec & x,
const vec & y,
mat & X,
mat & Y )

Definition at line 155 of file utils.cpp.

156{
157 int m = x.n_elem;
158 int n = y.n_elem;
159
160 assert (m > 0);
161 assert (n > 0);
162
163 // Build X
164 vec t(n, fill::ones);
165
166 X.zeros(n, m);
167 Y.zeros(n, m);
168
169 for(int ii = 0; ii < m; ++ii) {
170 X.col(ii) = x(ii) * t;
171 t.ones();
172 }
173
174 for(int ii = 0; ii < m; ++ii)
175 Y.col(ii) = y;
176}

◆ spjoin_cols()

sp_mat Utils::spjoin_cols ( const sp_mat & A,
const sp_mat & B )
static

Definition at line 120 of file utils.cpp.

121{
122 sp_mat::const_iterator itA = A.begin();
123 sp_mat::const_iterator endA = A.end();
124 sp_mat::const_iterator itB = B.begin();
125 sp_mat::const_iterator endB = B.end();
126 u32 j = 0;
127
128 vec a = nonzeros(A);
129 vec b = nonzeros(B);
130
131 umat locations(2, a.n_elem + b.n_elem);
132 vec values(a.n_elem + b.n_elem);
133
134 while(itA != endA) {
135 locations(0, j) = itA.row();
136 locations(1, j) = itA.col();
137 values(j) = (*itA);
138 ++itA;
139 ++j;
140 }
141
142 while(itB != endB) {
143 locations(0, j) = itB.row() + A.n_rows;
144 locations(1, j) = itB.col();
145 values(j) = (*itB);
146 ++itB;
147 ++j;
148 }
149
150 sp_mat result(locations, values, A.n_rows+B.n_rows, A.n_cols, true);
151
152 return result;
153}

◆ spjoin_rows()

sp_mat Utils::spjoin_rows ( const sp_mat & A,
const sp_mat & B )
static

Definition at line 85 of file utils.cpp.

86{
87 sp_mat::const_iterator itA = A.begin();
88 sp_mat::const_iterator endA = A.end();
89 sp_mat::const_iterator itB = B.begin();
90 sp_mat::const_iterator endB = B.end();
91 u32 j = 0;
92
93 vec a = nonzeros(A);
94 vec b = nonzeros(B);
95
96 umat locations(2, a.n_elem + b.n_elem);
97 vec values(a.n_elem + b.n_elem);
98
99 while(itA != endA) {
100 locations(0, j) = itA.row();
101 locations(1, j) = itA.col();
102 values(j) = (*itA);
103 ++itA;
104 ++j;
105 }
106
107 while(itB != endB) {
108 locations(0, j) = itB.row();
109 locations(1, j) = itB.col() + A.n_cols;
110 values(j) = (*itB);
111 ++itB;
112 ++j;
113 }
114
115 sp_mat result(locations, values, A.n_rows, A.n_cols+B.n_cols, true);
116
117 return result;
118}

◆ spkron()

sp_mat Utils::spkron ( const sp_mat & A,
const sp_mat & B )
static

Definition at line 53 of file utils.cpp.

54{
55 sp_mat::const_iterator itA = A.begin();
56 sp_mat::const_iterator endA = A.end();
57 sp_mat::const_iterator itB = B.begin();
58 sp_mat::const_iterator endB = B.end();
59 u32 j = 0;
60
61 vec a = nonzeros(A);
62 vec b = nonzeros(B);
63
64 umat locations(2, a.n_elem*b.n_elem);
65 vec values(a.n_elem*b.n_elem);
66
67 while(itA != endA) {
68 while(itB != endB) {
69 locations(0, j) = itA.row()*B.n_rows + itB.row();
70 locations(1, j) = itA.col()*B.n_cols + itB.col();
71 values(j) = (*itA)*(*itB);
72 ++j;
73 ++itB;
74 }
75
76 ++itA;
77 itB = B.begin();
78 }
79
80 sp_mat result(locations, values, A.n_rows*B.n_rows, A.n_cols*B.n_cols, true);
81
82 return result;
83}

◆ spsolve_eigen()

static vec Utils::spsolve_eigen ( const sp_mat & A,
const vec & b )
static

The documentation for this class was generated from the following files: