23 #ifndef CPPR_CONSTRUCTION_H //make sure this only gets included once
24 #define CPPR_CONSTRUCTION_H
39 template <
typename T >
42 ublas::vector<T> ret(m.size1()* m.size2());
44 for(
unsigned int i=0; i<m.size1(); i++)
46 for(
unsigned int j=0; j<m.size2(); j++)
47 ret(count++) = m(i,j);
60 template <
typename T >
63 ublas::vector<T> ret(size);
64 for(
int i=0; i<size; i++)
89 template <
typename T >
92 int rows,
int cols,
bool byrow=
false)
94 int size = vec.size();
95 if(rows <= 0 && cols > 0)
97 else if(cols <= 0 && rows > 0)
99 else if(rows <= 0 && cols <=0)
105 ublas::matrix<T> new_matrix(rows,cols);
106 for(
int i=0; i<rows; i++)
108 for(
int j=0; j<cols; j++)
112 new_matrix(i,j) = vec[(i*rows + j) % size];
116 new_matrix(i,j) = vec[(j*rows + i) % size];
131 template <
typename T >
133 createMatrix(
const std::vector<T> &vec,
int rows,
int cols,
bool byrow=
false)
136 v.resize(vec.size());
137 std::copy(vec.begin(), vec.end(), v.begin());
149 template <
typename T >
154 if(rows <= 0 && cols > 0)
156 else if(cols <= 0 && rows > 0)
158 else if(rows <= 0 && cols <=0)
163 ublas::matrix<T> new_matrix(rows,cols);
164 for(
int i=0; i<rows; i++)
166 for(
int j=0; j<cols; j++)
168 new_matrix(i,j) = value;
181 template <
typename T >
182 ublas::vector<T>
bind(ublas::vector<T> v1, ublas::vector<T> v2)
184 ublas::vector<T> ret = v1;
185 ret.resize(v1.size()+v2.size());
186 for(
unsigned int i = v1.size(); i < v2.size(); i++)
188 ret[i] = v2[i-v1.size()];
201 template <
typename T >
203 rep(
const ublas::vector<T> &vec,
int n)
205 unsigned int size = vec.size();
206 ublas::vector<T> new_vector(size * n);
207 for(
int i=0; i<n; i++)
209 for(
unsigned int j=0; j < size; j++)
211 new_vector[i*size+j] = vec[j];
224 template <
typename T >
226 rep(
const T &value,
int n)
228 ublas::vector<T> new_vector(n);
229 for(
int i=0; i<n; i++)
231 new_vector[i] = value;
244 template <
typename T >
245 ublas::vector<T>
diag(
const ublas::matrix<T> &m)
247 ublas::vector<T> ret(m.size1());
248 for(
unsigned int i=0; i<m.size1(); i++)
263 template <
typename T >
264 ublas::matrix<T>
diag(
const ublas::vector<T> &v)
267 rep(static_cast<T>(0),
268 v.size() * v.size()),
272 for(
unsigned int i=0; i<v.size(); i++)
286 template <
typename T >
287 ublas::matrix<T>
diag(
const T &value,
int size)
290 rep(static_cast<T>(0), size * size),
294 for(
int i=0; i<size; i++)
310 template <
typename T >
314 cppR_assert(max > min,
"Max must be greater than min in vecRange.");
316 ublas::vector<int> ret;
317 int size = max - min + 1;
320 for(
int i=0;i<size;i++)