40ivec
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++) \
81CREATE_SET_FUNS(vec, mat,
ones, 1.0)
83CREATE_SET_FUNS(ivec, imat,
ones_i, 1)
84CREATE_SET_FUNS(cvec, cmat,
ones_c,
std::complex<
double>(1.0))
86CREATE_SET_FUNS(vec, mat,
zeros, 0.0)
88CREATE_SET_FUNS(ivec, imat,
zeros_i, 0)
89CREATE_SET_FUNS(cvec, cmat,
zeros_c,
std::complex<
double>(0.0))
91CREATE_EYE_FUN(mat,
eye, 0.0, 1.0)
92CREATE_EYE_FUN(
bmat,
eye_b, bin(0), bin(1))
93CREATE_EYE_FUN(imat,
eye_i, 0, 1)
94CREATE_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);
232 double c = std::cos(
angle), s = std::sin(
angle);
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;
251void house(
const vec &x, vec &v,
double &beta)
262 sigma =
sum(
sqr(x(1, n - 1)));
267 mu = std::sqrt(
sqr(x(0)) + sigma);
271 v(0) = -sigma / (x(0) + mu);
272 beta = 2 *
sqr(v(0)) / (sigma +
sqr(v(0)));
277void givens(
double a,
double b,
double &c,
double &s)
286 if (fabs(b) > fabs(a)) {
288 s = -1.0 / std::sqrt(1 + t * t);
293 c = 1.0 / std::sqrt(1 + t * t);
312 if (fabs(b) > fabs(a)) {
314 s = -1.0 / std::sqrt(1 + t * t);
319 c = 1.0 / std::sqrt(1 + t * t);
349 if (fabs(b) > fabs(a)) {
351 s = -1.0 / std::sqrt(1 + t * t);
356 c = 1.0 / std::sqrt(1 + t * t);
374template void eye(
int, mat &);
378template void eye(
int, imat &);
380template void eye(
int, cmat &);
Binary arithmetic (boolean) class.
Elementary mathematical functions - header file.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
#define it_assert(t, s)
Abort if t is not true.
T to(double x)
Convert double to T.
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)
vec log2(const vec &x)
log-2 of the elements
int size(const Vec< T > &v)
Length of vector.
T sum(const Vec< T > &v)
Sum of all elements in the vector.
int length(const Vec< T > &v)
Length of vector.
vec angle(const cvec &x)
Angle.
void givens_t(double a, double b, mat &m)
Calculate the transposed Givens rotation matrix.
void house(const vec &x, vec &v, double &beta)
Calcualte the Householder vector.
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...
ivec find(const bvec &invector)
Return a integer vector with indicies where bvec == 1.
vec sqr(const cvec &data)
Absolute square of elements.
cvec conj(const cvec &x)
Conjugate of complex value.
void givens(double a, double b, double &c, double &s)
Calculate the Givens rotation values.
vec linspace(double from, double to, int points)
linspace (works in the same way as the MATLAB version)
ITPP_EXPORT vec zeros(int size)
A Double vector of zeros.
const cmat toeplitz(const cvec &c)
Generate symmetric Toeplitz matrix from vector c (complex valued)
ITPP_EXPORT cvec zeros_c(int size)
A Double Complex vector of zeros.
ITPP_EXPORT cmat eye_c(int size)
A Double Complex (size,size) unit matrix.
imat hadamard(int size)
Hadamard matrix.
ITPP_EXPORT ivec ones_i(int size)
A Int vector of ones.
ITPP_EXPORT imat eye_i(int size)
A Int (size,size) unit matrix.
vec impulse(int size)
Impulse vector.
ITPP_EXPORT bmat eye_b(int size)
A Binary (size,size) unit matrix.
imat conference(int n)
Conference matrix.
ITPP_EXPORT cvec ones_c(int size)
A float Complex vector of ones.
ITPP_EXPORT bvec ones_b(int size)
A Binary vector of ones.
ITPP_EXPORT bvec zeros_b(int size)
A Binary vector of zeros.
ITPP_EXPORT vec ones(int size)
A float vector of ones.
imat jacobsthal(int p)
Jacobsthal matrix.
vec zigzag_space(double t0, double t1, int K)
Zig-zag space function (variation on linspace)
ITPP_EXPORT ivec zeros_i(int size)
A Int vector of zeros.
IT++ compatibility types and functions.
Logarithmic and exponenential functions - header file.
Mat< bin > bmat
bin matrix
Various functions on vectors and matrices - header file.
template vec linspace_fixed_step(double, double, double)
Template instantiation of linspace_fixed_step.
template void eye(int, mat &)
Template instantiation of eye.
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.
int ceil_i(double x)
The nearest larger integer.
Definitions of special vectors and matrices.