30 #ifndef FIX_FUNCTIONS_H
31 #define FIX_FUNCTIONS_H
38 #include <itpp/itexports.h>
48 template<
class T>
inline bool is_fix(
const T &) {
return false;}
50 template<>
inline bool is_fix(
const Fix &) {
return true;}
56 template<>
inline bool is_fix(
const CFix &) {
return true;}
72 for (
int i = 0; i < y.
size(); i++) y(i).
set(x(i), n);
78 for (
int i = 0; i < y.
size(); i++) y(i).
set(x(i), n, q);
84 for (
int i = 0; i < y.
size(); i++) y(i).
set(x(i), n);
90 for (
int i = 0; i < y.
size(); i++) y(i).
set(x(i), n, q);
93 inline void set_fix(
double &y,
double x,
int) {y = x;}
97 inline void set_fix(vec &y,
const vec &x,
int) {y = x;}
101 inline void set_fix(mat &y,
const mat &x,
int) {y = x;}
117 for (
int i = 0; i < y.
size(); i++) y(i).
set(x(i), n);
122 it_assert_debug(real.length() == imag.length(),
"set_fix: real and imag should have the same size");
130 for (
int i = 0; i < y.
size(); i++) y(i).
set(x(i), n, q);
135 it_assert_debug(real.length() == imag.length(),
"set_fix: real and imag should have the same size");
143 for (
int i = 0; i < y.
size(); i++) y(i).
set(x(i), n);
148 it_assert_debug(real.rows() == imag.rows() && real.cols() == imag.cols(),
"set_fix: real and imag should have the same size");
149 y.
set_size(real.rows(), real.cols());
156 for (
int i = 0; i < y.
size(); i++) y(i).
set(x(i), n, q);
161 it_assert_debug(real.rows() == imag.rows() && real.cols() == imag.cols(),
"set_fix: real and imag should have the same size");
162 y.
set_size(real.rows(), real.cols());
166 inline void set_fix(std::complex<double> &y,
const std::complex<double> &x,
int) {y = x;}
170 inline void set_fix(std::complex<double> &y,
const std::complex<double> &x,
int,
q_mode) {y = x;}
174 inline void set_fix(cvec &y,
const cvec &x,
int) {y = x;}
182 inline void set_fix(cmat &y,
const cmat &x,
int) {y = x;}
194 for (
int i = 0; i < y.
size(); i++)
set_fix(y(i), x(i), n);
207 for (
int i = 0; i < y.
size(); i++)
set_fix(y(i), x(i), n, q);
225 {
for(
int i = 0; i < y.
size(); i++) y(i).lshift(n);}
228 {
for(
int i = 0; i < y.
size(); i++) y(i).rshift(n);}
231 {
for(
int i = 0; i < y.
size(); i++) y(i).rshift(n, q);}
234 {
for(
int i = 0; i < y.
size(); i++) y(i).lshift(n);}
237 {
for(
int i = 0; i < y.
size(); i++) y(i).rshift(n);}
240 {
for(
int i = 0; i < y.
size(); i++) y(i).rshift(n, q);}
267 {
for(
int i = 0; i < y.size(); i++) y(i).lshift(n);}
270 {
for(
int i = 0; i < y.size(); i++) y(i).rshift(n);}
273 {
for(
int i = 0; i < y.size(); i++) y(i).rshift(n, q);}
276 {
for(
int i = 0; i < y.size(); i++) y(i).lshift(n);}
279 {
for(
int i = 0; i < y.size(); i++) y(i).rshift(n);}
282 {
for(
int i = 0; i < y.size(); i++) y(i).rshift(n, q);}
334 template<
class T,
class U>
341 template<
class T,
class U>
342 class ConvertU2T<T, Array<U> >
345 typedef Array<typename ConvertU2T<T, U>::result> result;
348 template<
class T,
class U>
349 class ConvertU2T<T, Vec<U> >
352 typedef Vec<T> result;
355 template<
class T,
class U>
356 class ConvertU2T<T, Mat<U> >
359 typedef Mat<T> result;
365 template<
class T>
inline T
to(
double x) {
return T(x);}
367 template<
class T>
inline T
to(
const Fix &x) {
return T(x);}
369 template<
class T>
inline T
to(
const std::complex<double> &x) {
return T(x);}
371 template<
class T>
inline T
to(
const CFix &x) {
return T(x);}
373 template<
class T>
inline T
to(
double real,
double imag) {
return T(real, imag);}
381 for (
int i = 0; i < x.
length(); i++) {
389 template<>
inline cvec to<std::complex<double> >(
const cvec &x) {
return x;}
400 for (
int i = 0; i < real.
length(); i++) {
410 for (
int i = 0; i < x.
rows(); i++) {
411 for (
int j = 0; j < x.
cols(); j++) {
412 y(i, j) = T(x(i, j));
420 template<>
inline cmat to<std::complex<double> >(
const cmat &x) {
return x;}
431 for (
int i = 0; i < real.
rows(); i++) {
432 for (
int j = 0; j < real.
cols(); j++) {
433 y(i, j) = T(
real(i, j),
imag(i, j));
440 template<
class T,
class U>
444 for (
int i = 0; i < x.
size(); i++) {
451 template<
class T,
class U>
456 for (
int i = 0; i < real.
size(); i++) {
476 inline double unfix(
double x) {
return x;}
478 inline std::complex<double>
unfix(
const std::complex<double> &x) {
return x;}
480 inline vec
unfix(
const vec &x) {
return x;}
482 inline cvec
unfix(
const cvec &x) {
return x;}
484 inline mat
unfix(
const mat &x) {
return x;}
486 inline cmat
unfix(
const cmat &x) {
return x;}
495 typedef double to_double;
502 typedef std::complex<double> to_double;
506 class Convert<std::complex<T> >
509 typedef std::complex<double> to_double;
513 class Convert<Array<T> >
516 typedef Array<typename Convert<T>::to_double> to_double;
520 class Convert<Vec<T> >
523 typedef Vec<typename Convert<T>::to_double> to_double;
527 class Convert<Mat<T> >
530 typedef Mat<typename Convert<T>::to_double> to_double;
540 for (
int i = 0; i < x.
size(); i++) {
547 ITPP_EXPORT Fix
abs(
const Fix &x);
549 ITPP_EXPORT Fix
real(
const CFix &x);
551 ITPP_EXPORT Fix
imag(
const CFix &x);
553 ITPP_EXPORT CFix
conj(
const CFix &x);
559 #endif // #ifndef FIX_FUNCTIONS_H