34#include <itpp/itexports.h>
54 for (
int i = 0; i < v.
length(); ++i) {
55 temp(i) =
static_cast<bin>(v(i));
68 for (
int i = 0; i < v.
length(); ++i) {
69 temp(i) =
static_cast<short>(v(i));
82 for (
int i = 0; i < v.
length(); ++i) {
83 temp(i) =
static_cast<int>(v(i));
96 for (
int i = 0; i < v.
length(); ++i) {
97 temp(i) =
static_cast<double>(v(i));
110 for (
int i = 0; i < v.
length(); ++i) {
111 temp(i) = std::complex<double>(
static_cast<double>(v(i)), 0.0);
132 "to_cvec(): real and imaginary parts must have the same length");
134 for (
int i = 0; i <
real.length(); ++i) {
135 temp(i) = std::complex<double>(
static_cast<double>(
real(i)),
136 static_cast<double>(
imag(i)));
171 for (
int i = 0; i < temp.rows(); ++i) {
172 for (
int j = 0; j < temp.cols(); ++j) {
173 temp(i, j) =
static_cast<bin>(m(i, j));
187 for (
int i = 0; i < temp.
rows(); ++i) {
188 for (
int j = 0; j < temp.
cols(); ++j) {
189 temp(i, j) =
static_cast<short>(m(i, j));
203 for (
int i = 0; i < temp.
rows(); ++i) {
204 for (
int j = 0; j < temp.
cols(); ++j) {
205 temp(i, j) =
static_cast<int>(m(i, j));
219 for (
int i = 0; i < temp.rows(); ++i) {
220 for (
int j = 0; j < temp.cols(); ++j) {
221 temp(i, j) =
static_cast<double>(m(i, j));
235 for (
int i = 0; i < temp.
rows(); ++i) {
236 for (
int j = 0; j < temp.
cols(); ++j) {
237 temp(i, j) = std::complex<double>(
static_cast<double>(m(i, j)), 0.0);
260 "to_cmat(): real and imag part sizes does not match");
262 for (
int i = 0; i < temp.
rows(); ++i) {
263 for (
int j = 0; j < temp.
cols(); ++j) {
264 temp(i, j) = std::complex<double>(
static_cast<double>(
real(i, j)),
265 static_cast<double>(
imag(i, j)));
285ITPP_EXPORT bvec
dec2bin(
int index,
bool msb_first =
true);
290ITPP_EXPORT
int bin2dec(
const bvec &inbvec,
bool msb_first =
true);
299ITPP_EXPORT bvec
oct2bin(
const ivec &octalindex,
short keepzeros = 0);
339inline int ceil_i(
double x) {
return static_cast<int>(std::ceil(x)); }
350inline int floor_i(
double x) {
return static_cast<int>(std::floor(x)); }
360 return ((std::fabs(x) < threshold) ? 0.0 : x);
365 double threshold = 1e-14)
367 return std::complex<double>(
round_to_zero(x.real(), threshold),
392 return (std::fabs(in)>threshold)?
itpp::round(in):in;
396inline std::complex<double>
round_to_infty(
const std::complex<double> &in,
const double threshold = 1e9)
430std::string
to_str(
const T &i);
439ITPP_EXPORT std::string
to_str(
const double &i,
const int precision);
446 std::ostringstream ss;
448 ss.setf(std::ostringstream::scientific, std::ostringstream::floatfield);
459ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT bvec
to_bvec(
const svec &v);
460ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT bvec
to_bvec(
const ivec &v);
462ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec
to_svec(
const bvec &v);
463ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec
to_svec(
const ivec &v);
464ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec
to_svec(
const vec &v);
466ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec
to_ivec(
const bvec &v);
467ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec
to_ivec(
const svec &v);
468ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec
to_ivec(
const vec &v);
470ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec
to_vec(
const bvec &v);
471ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec
to_vec(
const svec &v);
472ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec
to_vec(
const ivec &v);
474ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const bvec &v);
475ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const svec &v);
476ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const ivec &v);
477ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const vec &v);
479ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const bvec &
real,
const bvec &
imag);
480ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const svec &
real,
const svec &
imag);
481ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const ivec &
real,
const ivec &
imag);
482ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const vec &
real,
const vec &
imag);
484ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
bmat to_bmat(
const smat &m);
485ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
bmat to_bmat(
const imat &m);
487ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
to_smat(
const bmat &m);
488ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
to_smat(
const imat &m);
489ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
to_smat(
const mat &m);
491ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
to_imat(
const bmat &m);
492ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
to_imat(
const smat &m);
493ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
to_imat(
const mat &m);
495ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
to_mat(
const bmat &m);
496ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
to_mat(
const smat &m);
497ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
to_mat(
const imat &m);
499ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const bmat &m);
500ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const smat &m);
501ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const imat &m);
502ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const mat &m);
505ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const smat &
real,
const smat &
imag);
506ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const imat &
real,
const imat &
imag);
507ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const mat &
real,
const mat &
imag);
Mat(const Factory &f=DEFAULT_FACTORY)
cmat to_cmat(const Mat< T > &real, const Mat< T > &imag)
Converts real and imaginary Mat<T> to cmat.
cmat to_cmat(const Mat< T > &m)
Converts a Mat<T> to cmat.
bmat to_bmat(const Mat< T > &m)
Converts a Mat<T> to bmat.
Mat< std::complex< double > > cmat
int rows() const
The number of rows.
mat to_mat(const Mat< T > &m)
Converts a Mat<T> to mat.
int cols() const
The number of columns.
imat to_imat(const Mat< T > &m)
Converts a Mat<T> to imat.
smat to_smat(const Mat< T > &m)
Converts a Mat<T> to smat.
cvec to_cvec(const Vec< T > &v)
Converts a Vec<T> to cvec.
svec to_svec(const Vec< T > &v)
Converts a Vec<T> to svec.
cvec to_cvec(double real, double imag)
Converts real and imaginary double to cvec.
vec to_vec(const Vec< T > &v)
Converts a Vec<T> to vec.
cvec to_cvec(const Vec< T > &real, const Vec< T > &imag)
Converts real and imaginary Vec<T> to cvec.
ivec to_ivec(int s)
Converts an int to ivec.
vec to_vec(double s)
Converts an double to vec.
ivec to_ivec(const Vec< T > &v)
Converts a Vec<T> to ivec.
Vec(const Factory &f=DEFAULT_FACTORY)
Vec< std::complex< double > > cvec
int length() const
The size of the vector.
bvec to_bvec(const Vec< T > &v)
Converts a Vec<T> to bvec.
Binary arithmetic (boolean) class.
#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.
int length(const Vec< T > &v)
Length of vector.
vec imag(const cvec &data)
Imaginary part of complex values.
Vec< T > apply_function(T(*f)(T), const Vec< T > &v)
Help function to call for a function: Vec<T> function(Vec<T>)
vec real(const cvec &data)
Real part of complex values.
Help functions to make functions with vec and mat as arguments.
Mat< bin > bmat
bin matrix
Miscellaneous functions - header file.
double round_to_infty(const double in, const double threshold=1e9)
Remove trailing digits, found after the decimal point, for numbers greater than threshold.
cvec to_cvec(const Vec< T > &v)
Converts a Vec<T> to cvec.
double round_to_zero(double x, double threshold=1e-14)
Round x to zero if abs(x) is smaller than threshold.
ITPP_EXPORT ivec bin2oct(const bvec &inbits)
Convert bvec to octal ivec.
svec to_svec(const Vec< T > &v)
Converts a Vec<T> to svec.
ITPP_EXPORT int round_i(double x)
Round to nearest integer.
vec floor(const vec &x)
Round to nearest lower integer.
vec ceil(const vec &x)
Round to nearest upper integer.
double rad_to_deg(double x)
Convert radians to degrees.
ITPP_EXPORT bvec pol2bin(const ivec &inpol)
Convert binary polar ivec to bvec.
ITPP_EXPORT bvec oct2bin(const ivec &octalindex, short keepzeros=0)
Convert ivec of octal form to bvec.
cmat to_cmat(const Mat< T > &m)
Converts a Mat<T> to cmat.
ITPP_EXPORT ivec bin2pol(const bvec &inbvec)
Convert bvec to polar binary representation as ivec.
ITPP_EXPORT int bin2dec(const bvec &inbvec, bool msb_first=true)
Convert a bvec to decimal int with the first bit as MSB if msb_first == true.
bmat to_bmat(const Mat< T > &m)
Converts a Mat<T> to bmat.
int gray_code(int x)
Convert to Gray Code.
vec to_vec(const Vec< T > &v)
Converts a Vec<T> to vec.
std::string to_str(const T &i)
Convert anything to string.
ITPP_EXPORT bvec dec2bin(int length, int index)
Convert a decimal int index to bvec using length bits in the representation.
const double pi
Constant Pi.
mat to_mat(const Mat< T > &m)
Converts a Mat<T> to mat.
ITPP_EXPORT double round(double x)
Round to nearest integer, return result in double.
int ceil_i(double x)
The nearest larger integer.
imat to_imat(const Mat< T > &m)
Converts a Mat<T> to imat.
double deg_to_rad(double x)
Convert degrees to radians.
smat to_smat(const Mat< T > &m)
Converts a Mat<T> to smat.
int floor_i(double x)
The nearest smaller integer.
ivec to_ivec(const Vec< T > &v)
Converts a Vec<T> to ivec.
bvec to_bvec(const Vec< T > &v)
Converts a Vec<T> to bvec.