30#ifndef FIX_FUNCTIONS_H
31#define FIX_FUNCTIONS_H
38#include <itpp/itexports.h>
48template<
class T>
inline bool is_fix(
const T &) {
return false;}
50template<>
inline bool is_fix(
const Fix &) {
return true;}
56template<>
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);
93inline void set_fix(
double &y,
double x,
int) {y = x;}
97inline void set_fix(vec &y,
const vec &x,
int) {y = x;}
101inline 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);
130 for (
int i = 0; i < y.
size(); i++) y(i).
set(x(i), n, q);
143 for (
int i = 0; i < y.
size(); i++) y(i).
set(x(i), n);
156 for (
int i = 0; i < y.
size(); i++) y(i).
set(x(i), n, q);
166inline void set_fix(std::complex<double> &y,
const std::complex<double> &x,
int) {y = x;}
170inline void set_fix(std::complex<double> &y,
const std::complex<double> &x,
int,
q_mode) {y = x;}
174inline void set_fix(cvec &y,
const cvec &x,
int) {y = x;}
182inline 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);}
334template<
class T,
class U>
341template<
class T,
class U>
342class ConvertU2T<T,
Array<U> >
345 typedef Array<typename ConvertU2T<T, U>::result> result;
348template<
class T,
class U>
349class ConvertU2T<T,
Vec<U> >
352 typedef Vec<T> result;
355template<
class T,
class U>
356class ConvertU2T<T,
Mat<U> >
359 typedef Mat<T> result;
365template<
class T>
inline T
to(
double x) {
return T(x);}
367template<
class T>
inline T
to(
const Fix &x) {
return T(x);}
369template<
class T>
inline T
to(
const std::complex<double> &x) {
return T(x);}
371template<
class T>
inline T
to(
const CFix &x) {
return T(x);}
381 for (
int i = 0; i < x.
length(); i++) {
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));
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));
440template<
class T,
class U>
444 for (
int i = 0; i < x.
size(); i++) {
451template<
class T,
class U>
456 for (
int i = 0; i <
real.size(); i++) {
476inline double unfix(
double x) {
return x;}
478inline std::complex<double>
unfix(
const std::complex<double> &x) {
return x;}
480inline vec
unfix(
const vec &x) {
return x;}
482inline cvec
unfix(
const cvec &x) {
return x;}
484inline mat
unfix(
const mat &x) {
return x;}
486inline cmat
unfix(
const cmat &x) {
return x;}
495 typedef double to_double;
502 typedef std::complex<double> to_double;
506class Convert<std::complex<T> >
509 typedef std::complex<double> to_double;
513class Convert<
Array<T> >
516 typedef Array<typename Convert<T>::to_double> to_double;
520class Convert<
Vec<T> >
523 typedef Vec<typename Convert<T>::to_double> to_double;
527class Convert<
Mat<T> >
530 typedef Mat<typename Convert<T>::to_double> to_double;
540 for (
int i = 0; i < x.
size(); i++) {
547ITPP_EXPORT Fix
abs(
const Fix &x);
549ITPP_EXPORT Fix
real(
const CFix &x);
551ITPP_EXPORT Fix
imag(
const CFix &x);
553ITPP_EXPORT CFix
conj(
const CFix &x);
Definition of Array class (container)
Definitions of a complex fixed-point data type CFix.
int size() const
Returns the number of data elements in the array object.
void set_size(int n, bool copy=false)
Resizing an Array<T>.
Complex fixed-point data type.
void lshift(int n)
Left shift n bits.
void rshift(int n)
Right shift n bits using quantization mode qmode (constructor argument)
std::complex< double > unfix() const
Conversion to std::complex<double>
void set(double real, double imag, int n)
Set to (real + i*imag) * pow2(n) using quantization mode qmode (constructor argument)
int get_shift() const
Get shift.
void lshift(int n)
Left shift n bits.
void rshift(int n)
Right shift n bits using quantization mode qmode (constructor argument)
void set(double x, int n)
Set to x * pow2(n) using quantization mode qmode (constructor argument)
double unfix() const
Conversion to double.
void set_size(int rows, int cols, bool copy=false)
Set size of matrix. If copy = true then keep the data before resizing.
void set(const std::string &str)
Set matrix equal to values in the string str.
int rows() const
The number of rows.
int cols() const
The number of columns.
int size() const
The number of elements.
void set(const char *str)
Set the vector equal to the values in the str string.
int size() const
The size of the vector.
void set_size(int size, bool copy=false)
Set length of vector. if copy = true then keeping the old values.
int length() const
The size of the vector.
Definitions of converters between different vector and matrix types.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
Vec< CFix > cfixvec
Typedef for complex fixed-point vector type.
void set_fix(Fix &y, double x, int n)
Set y = x * pow2(n) using the quantization mode of y.
void rshift_fix(Fix &y, int n)
Right shift n bits using the quantization mode of y.
vec to< double >(const vec &x)
Convert vec to vec.
double unfix(const Fix &x)
Convert Fix to double by multiplying the bit representation with pow2(-shift)
void lshift_fix(Fix &y, int n)
Left shift n bits.
Mat< CFix > cfixmat
Typedef for complex fixed-point matrix type.
T to(double x)
Convert double to T.
cfixvec to< CFix >(const cfixvec &x)
Convert cfixvec to cfixvec.
q_mode
Quantization modes (aligned with SystemC)
Mat< Fix > fixmat
Typedef for fixed-point matrix type.
void assert_fixshift(double, int)
If x is a fixed-point variable, assert that x has the specified shift value, otherwise do nothing.
fixvec to< Fix >(const fixvec &x)
Convert fixvec to fixvec.
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)
Vec< Fix > fixvec
Typedef for fixed-point vector type.
vec imag(const cvec &data)
Imaginary part of complex values.
vec real(const cvec &data)
Real part of complex values.
cvec conj(const cvec &x)
Conjugate of complex value.
Matrix Class Definitions.
cvec to_cvec(const Vec< T > &v)
Converts a Vec<T> to cvec.
cmat to_cmat(const Mat< T > &m)
Converts a Mat<T> to cmat.
vec to_vec(const Vec< T > &v)
Converts a Vec<T> to vec.
std::string to_str(const T &i)
Convert anything to string.
mat to_mat(const Mat< T > &m)
Converts a Mat<T> to mat.
bin abs(const bin &inbin)
absolute value of bin
Templated Vector Class Definitions.