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)
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++) {
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 &);
Various functions on vectors and matrices - header file.
ITPP_EXPORT ivec zeros_i(int size)
A Int vector of zeros.
ITPP_EXPORT bvec ones_b(int size)
A Binary vector of ones.
ITPP_EXPORT ivec ones_i(int size)
A Int vector of ones.
ITPP_EXPORT cmat eye_c(int size)
A Double Complex (size,size) unit matrix.
int ceil_i(double x)
The nearest larger integer.
vec impulse(int size)
Impulse vector.
void givens_t(double a, double b, mat &m)
Calculate the transposed Givens rotation matrix.
ivec find(const bvec &invector)
Return a integer vector with indicies where bvec == 1.
cvec conj(const cvec &x)
Conjugate of complex value.
ITPP_EXPORT bvec zeros_b(int size)
A Binary vector of zeros.
template void eye(int, mat &)
Template instantiation of eye.
T sum(const Vec< T > &v)
Sum of all elements in the vector.
#define it_assert(t, s)
Abort if t is not true.
Logarithmic and exponenential functions - header file.
int length(const Vec< T > &v)
Length of vector.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
ITPP_EXPORT cvec zeros_c(int size)
A Double Complex vector of zeros.
const cmat toeplitz(const cvec &c)
Generate symmetric Toeplitz matrix from vector c (complex valued)
vec sin(const vec &x)
Sine function.
ITPP_EXPORT vec zeros(int size)
A Double vector of zeros.
vec angle(const cvec &x)
Angle.
vec log2(const vec &x)
log-2 of the elements
int pow2i(int x)
Calculate two to the power of x (2^x); x is integer.
double pow2(double x)
Calculate two to the power of x (2^x)
int size(const Vec< T > &v)
Length of vector.
imat conference(int n)
Conference matrix.
imat jacobsthal(int p)
Jacobsthal matrix.
ITPP_EXPORT vec ones(int size)
A float vector of ones.
mat rotation_matrix(int dim, int plane1, int plane2, double angle)
Create a rotation matrix that rotates the given plane angle radians. Note that the order of the plane...
void house(const vec &x, vec &v, double &beta)
Calcualte the Householder vector.
IT++ compatibility types and functions.
vec sqr(const cvec &data)
Absolute square of elements.
Definitions of special vectors and matrices.
template vec linspace_fixed_step(double, double, double)
Template instantiation of linspace_fixed_step.
vec linspace(double from, double to, int points)
linspace (works in the same way as the MATLAB version)
Binary arithmetic (boolean) class.
vec sqrt(const vec &x)
Square root of the elements.
T to(double x)
Convert double to T.
vec zigzag_space(double t0, double t1, int K)
Zig-zag space function (variation on linspace)
ITPP_EXPORT bmat eye_b(int size)
A Binary (size,size) unit matrix.
vec cos(const vec &x)
Cosine function.
ITPP_EXPORT cvec ones_c(int size)
A float Complex vector of ones.
ITPP_EXPORT imat eye_i(int size)
A Int (size,size) unit matrix.
Elementary mathematical functions - header file.
void givens(double a, double b, double &c, double &s)
Calculate the Givens rotation values.
imat hadamard(int size)
Hadamard matrix.
Mat< bin > bmat
bin matrix
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.