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> >
348 template<
class T,
class U>
349 class ConvertU2T<T, Vec<U> >
355 template<
class T,
class U>
356 class ConvertU2T<T, Mat<U> >
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> >
520 class Convert<Vec<T> >
527 class Convert<Mat<T> >
540 for (
int i = 0; i < x.
size(); i++) {
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 int size() const
The size of the vector.
cfixvec to< CFix >(const cfixvec &x)
Convert cfixvec to cfixvec.
void set_size(int rows, int cols, bool copy=false)
Set size of matrix. If copy = true then keep the data before resizing.
int size() const
Returns the number of data elements in the array object.
void rshift_fix(Fix &y, int n)
Right shift n bits using the quantization mode of y.
void rshift(int n)
Right shift n bits using quantization mode qmode (constructor argument)
vec imag(const cvec &data)
Imaginary part of complex values.
bool is_fix(const T &)
Return true only if argument is of type Fix or CFix (or an Array/Vec/Mat of Fix or CFix) ...
void set(const char *str)
Set the vector equal to the values in the str string.
cvec conj(const cvec &x)
Conjugate of complex value.
void set(double x, int n)
Set to x * pow2(n) using quantization mode qmode (constructor argument)
std::string to_str(const T &i)
Convert anything to string.
void set(const std::string &str)
Set matrix equal to values in the string str.
cmat to_cmat(const Mat< T > &m)
Converts a Mat<T> to cmat.
double unfix(const Fix &x)
Convert Fix to double by multiplying the bit representation with pow2(-shift)
void set_size(int size, bool copy=false)
Set length of vector. if copy = true then keeping the old values.
double unfix() const
Conversion to double.
mat to_mat(const Mat< T > &m)
Converts a Mat<T> to mat.
vec to< double >(const vec &x)
Convert vec to vec.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
Definition of Array class (container)
std::complex< double > unfix() const
Conversion to std::complex<double>
void set_size(int n, bool copy=false)
Resizing an Array<T>.
void assert_fixshift(double, int)
If x is a fixed-point variable, assert that x has the specified shift value, otherwise do nothing...
void lshift(int n)
Left shift n bits.
Definitions of converters between different vector and matrix types.
int cols() const
The number of columns.
fixvec to< Fix >(const fixvec &x)
Convert fixvec to fixvec.
Complex fixed-point data type.
void lshift_fix(Fix &y, int n)
Left shift n bits.
Matrix Class Definitions.
void rshift(int n)
Right shift n bits using quantization mode qmode (constructor argument)
void set_fix(Fix &y, double x, int n)
Set y = x * pow2(n) using the quantization mode of y.
vec to_vec(const Vec< T > &v)
Converts a Vec<T> to vec.
void lshift(int n)
Left shift n bits.
void set(double real, double imag, int n)
Set to (real + i*imag) * pow2(n) using quantization mode qmode (constructor argument) ...
int length() const
The size of the vector.
int size() const
The number of elements.
int rows() const
The number of rows.
cvec to_cvec(const Vec< T > &v)
Converts a Vec<T> to cvec.
T to(double x)
Convert double to T.
bin abs(const bin &inbin)
absolute value of bin
vec real(const cvec &data)
Real part of complex values.
q_mode
Quantization modes (aligned with SystemC)
int get_shift() const
Get shift.
Definitions of a complex fixed-point data type CFix.
Templated Vector Class Definitions.