40 ivec
find(
const bvec &invector)
42 it_assert(invector.size() > 0,
"find(): vector cannot be empty");
43 ivec temp(invector.size());
45 for (
int i = 0;i < invector.size();i++) {
46 if (invector(i) ==
bin(1)) {
51 temp.set_size(pos,
true);
57 #define CREATE_SET_FUNS(typef,typem,name,value) \
58 typef name(int size) \
65 typem name(int rows, int cols) \
67 typem t(rows, cols); \
72 #define CREATE_EYE_FUN(type,name,zero,one) \
73 type name(int size) { \
76 for (int i=0; i<size; i++) \
81 CREATE_SET_FUNS(vec, mat,
ones, 1.0)
83 CREATE_SET_FUNS(ivec, imat,
ones_i, 1)
84 CREATE_SET_FUNS(cvec, cmat,
ones_c, std::complex<
double>(1.0))
86 CREATE_SET_FUNS(vec, mat,
zeros, 0.0)
87 CREATE_SET_FUNS(bvec, bmat,
zeros_b, bin(0))
88 CREATE_SET_FUNS(ivec, imat,
zeros_i, 0)
89 CREATE_SET_FUNS(cvec, cmat,
zeros_c, std::complex<
double>(0.0))
91 CREATE_EYE_FUN(mat,
eye, 0.0, 1.0)
92 CREATE_EYE_FUN(bmat,
eye_b, bin(0), bin(1))
93 CREATE_EYE_FUN(imat,
eye_i, 0, 1)
94 CREATE_EYE_FUN(cmat,
eye_c, std::complex<
double>(0.0), std::complex<
double>(1.0))
116 double step = (to - from) /
double(points - 1);
118 for (i = 0; i < (points-1); i++)
119 output(i) = from + i * step;
127 it_assert(K > 0,
"zigzag_space:() K must be positive");
131 for (
int k = 0; k < K; k++) {
133 for (
int i = 1; i <
length(Nn); i += 2) {
142 for (
int i = 0; i < n; i++) {
151 it_assert(size > 0,
"hadamard(): size is not a power of 2");
152 int logsize =
ceil_i(::
log2(static_cast<double>(size)));
153 it_assert(
pow2i(logsize) == size,
"hadamard(): size is not a power of 2");
158 for (
int i = 0; i < logsize; ++i) {
160 for (
int k = 0; k <
pow2; ++k) {
161 for (
int l = 0; l <
pow2; ++l) {
163 H(k + pow2, l) = H(k, l);
164 H(k, l + pow2) = H(k, l);
165 H(k + pow2, l + pow2) = (-1) * H(k, l);
174 int quadratic_residue;
181 for (i = 0; i < (p - 1) / 2; i++) {
182 quadratic_residue = ((i + 1) * (i + 1)) % p;
184 for (j = 0; j < p; j++) {
185 out(j, (j + quadratic_residue) % p) = 1;
190 for (i = 0; i < p; i++) {
203 out.set_submatrix(0, 0, 1, n - 1, 1);
204 out.set_submatrix(1, n - 1, 0, 0, 1);
214 cvec c_conj =
conj(c);
215 for (
int i = 1; i < s; ++i) {
216 for (
int j = 0; j < s - i; ++j) {
217 output(i + j, j) = c_conj(i);
221 for (
int j = 0; j < s; ++j) {
222 for (
int i = 0; i < s - j; ++i) {
223 output(i, i + j) = c(j);
235 plane1 < dim && plane2 < dim && plane1 != plane2,
236 "Invalid arguments to rotation_matrix()");
238 m.set_size(dim, dim,
false);
240 for (
int i = 0; i < dim; i++)
243 m(plane1, plane1) = c;
244 m(plane1, plane2) = -s;
245 m(plane2, plane1) = s;
246 m(plane2, plane2) = c;
251 void house(
const vec &x, vec &v,
double &beta)
262 sigma =
sum(
sqr(x(1, n - 1)));
271 v(0) = -sigma / (x(0) + mu);
272 beta = 2 *
sqr(v(0)) / (sigma +
sqr(v(0)));
277 void givens(
double a,
double b,
double &c,
double &s)
286 if (fabs(b) > fabs(a)) {
312 if (fabs(b) > fabs(a)) {
349 if (fabs(b) > fabs(a)) {
374 template void eye(
int, mat &);
376 template void eye(
int,
bmat &);
378 template void eye(
int, imat &);
380 template void eye(
int, cmat &);