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");
133 cvec temp(
real.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");
261 cmat temp(
real.rows(),
real.cols());
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)));
280 ITPP_EXPORT
void dec2bin(
int index, bvec &v);
285 ITPP_EXPORT bvec
dec2bin(
int index,
bool msb_first =
true);
290 ITPP_EXPORT
int bin2dec(
const bvec &inbvec,
bool msb_first =
true);
299 ITPP_EXPORT bvec
oct2bin(
const ivec &octalindex,
short keepzeros = 0);
308 ITPP_EXPORT ivec
bin2oct(
const bvec &inbits);
311 ITPP_EXPORT ivec
bin2pol(
const bvec &inbvec);
314 ITPP_EXPORT bvec
pol2bin(
const ivec &inpol);
322 ITPP_EXPORT
double round(
double x);
324 ITPP_EXPORT vec
round(
const vec &x);
326 ITPP_EXPORT mat
round(
const mat &x);
328 ITPP_EXPORT
int round_i(
double x);
330 ITPP_EXPORT ivec
round_i(
const vec &x);
332 ITPP_EXPORT imat
round_i(
const mat &x);
335 inline vec
ceil(
const vec &x) {
return apply_function<double>(
std::ceil, x); }
337 inline mat
ceil(
const mat &x) {
return apply_function<double>(
std::ceil, x); }
341 ITPP_EXPORT ivec
ceil_i(
const vec &x);
343 ITPP_EXPORT imat
ceil_i(
const mat &x);
352 ITPP_EXPORT ivec
floor_i(
const vec &x);
354 ITPP_EXPORT imat
floor_i(
const mat &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),
384 ITPP_EXPORT cvec
round_to_zero(
const cvec &x,
double threshold = 1e-14);
387 ITPP_EXPORT cmat
round_to_zero(
const cmat &x,
double threshold = 1e-14);
392 return (std::fabs(in)>threshold)?
itpp::round(in):in;
396 inline std::complex<double>
round_to_infty(
const std::complex<double> &in,
const double threshold = 1e9)
415 ITPP_EXPORT cvec
round_to_infty(
const cvec &in,
const double threshold = 1e9);
418 ITPP_EXPORT cmat
round_to_infty(
const cmat &in,
const double threshold = 1e9);
429 template <
typename T>
430 std::string
to_str(
const T &i);
439 ITPP_EXPORT std::string
to_str(
const double &i,
const int precision);
443 template <
typename T>
446 std::ostringstream ss;
448 ss.setf(std::ostringstream::scientific, std::ostringstream::floatfield);
459 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT bvec
to_bvec(
const svec &v);
460 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT bvec
to_bvec(
const ivec &v);
462 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec
to_svec(
const bvec &v);
463 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec
to_svec(
const ivec &v);
464 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec
to_svec(
const vec &v);
466 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec
to_ivec(
const bvec &v);
467 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec
to_ivec(
const svec &v);
468 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec
to_ivec(
const vec &v);
470 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec
to_vec(
const bvec &v);
471 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec
to_vec(
const svec &v);
472 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec
to_vec(
const ivec &v);
474 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const bvec &v);
475 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const svec &v);
476 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const ivec &v);
477 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const vec &v);
479 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const bvec &
real,
const bvec &
imag);
480 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const svec &
real,
const svec &
imag);
481 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const ivec &
real,
const ivec &
imag);
482 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec
to_cvec(
const vec &
real,
const vec &
imag);
484 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
bmat to_bmat(
const smat &m);
485 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
bmat to_bmat(
const imat &m);
487 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
to_smat(
const bmat &m);
488 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
to_smat(
const imat &m);
489 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
to_smat(
const mat &m);
491 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
to_imat(
const bmat &m);
492 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
to_imat(
const smat &m);
493 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
to_imat(
const mat &m);
495 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
to_mat(
const bmat &m);
496 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
to_mat(
const smat &m);
497 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
to_mat(
const imat &m);
499 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const bmat &m);
500 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const smat &m);
501 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const imat &m);
502 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const mat &m);
505 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const smat &
real,
const smat &
imag);
506 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const imat &
real,
const imat &
imag);
507 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
to_cmat(
const mat &
real,
const mat &
imag);
513 #endif // CONVERTERS_H double deg_to_rad(double x)
Convert degrees to radians.
ITPP_EXPORT int round_i(double x)
Round to nearest integer.
Miscellaneous functions - header file.
double rad_to_deg(double x)
Convert radians to degrees.
vec imag(const cvec &data)
Imaginary part of complex values.
Help functions to make functions with vec and mat as arguments.
int ceil_i(double x)
The nearest larger integer.
double round_to_infty(const double in, const double threshold=1e9)
Remove trailing digits, found after the decimal point, for numbers greater than threshold.
vec floor(const vec &x)
Round to nearest lower integer.
imat to_imat(const Mat< T > &m)
Converts a Mat<T> to imat.
std::string to_str(const T &i)
Convert anything to string.
cmat to_cmat(const Mat< T > &m)
Converts a Mat<T> to cmat.
#define it_assert(t, s)
Abort if t is not true.
int length(const Vec< T > &v)
Length of vector.
mat to_mat(const Mat< T > &m)
Converts a Mat<T> to mat.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
ITPP_EXPORT ivec bin2oct(const bvec &inbits)
Convert bvec to octal ivec.
int gray_code(int x)
Convert to Gray Code.
ITPP_EXPORT double round(double x)
Round to nearest integer, return result in double.
bvec to_bvec(const Vec< T > &v)
Converts a Vec<T> to bvec.
int cols() const
The number of columns.
svec to_svec(const Vec< T > &v)
Converts a Vec<T> to svec.
const double pi
Constant Pi.
vec to_vec(const Vec< T > &v)
Converts a Vec<T> to vec.
smat to_smat(const Mat< T > &m)
Converts a Mat<T> to smat.
int floor_i(double x)
The nearest smaller integer.
ITPP_EXPORT bvec dec2bin(int length, int index)
Convert a decimal int index to bvec using length bits in the representation.
int length() const
The size of the vector.
ivec to_ivec(const Vec< T > &v)
Converts a Vec<T> to ivec.
ITPP_EXPORT bvec pol2bin(const ivec &inpol)
Convert binary polar ivec to bvec.
Binary arithmetic (boolean) class.
int rows() const
The number of rows.
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.
bmat to_bmat(const Mat< T > &m)
Converts a Mat<T> to bmat.
ITPP_EXPORT bvec oct2bin(const ivec &octalindex, short keepzeros=0)
Convert ivec of octal form to bvec.
mat floor(const mat &x)
Round to nearest lower integer.
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.
vec real(const cvec &data)
Real part of complex values.
ITPP_EXPORT ivec bin2pol(const bvec &inbvec)
Convert bvec to polar binary representation as ivec.
vec ceil(const vec &x)
Round to nearest upper integer.
mat ceil(const mat &x)
Round to nearest upper integer.
Mat< bin > bmat
bin matrix