43 ivec
to_ivec(
int s) { ivec out(1); out(0) = s;
return out; }
45 vec
to_vec(
double s) { vec out(1); out(0) = s;
return out; }
50 out(0) = std::complex<double>(
real,
imag);
60 int i, bintemp = index;
63 for (i = length - 1; i >= 0; i--) {
64 temp(i) = bin(bintemp & 1);
65 bintemp = (bintemp >> 1);
70 bvec
dec2bin(
int index,
bool msb_first)
73 int i, bintemp = index;
76 for (i = length - 1; i >= 0; i--) {
77 temp(i) = bin(bintemp & 1);
78 bintemp = (bintemp >> 1);
88 void dec2bin(
int index, bvec &v)
90 int i, bintemp = index;
93 for (i = v.size() - 1; i >= 0; i--) {
94 v(i) = bin(bintemp & 1);
95 bintemp = (bintemp >> 1);
99 int bin2dec(
const bvec &inbvec,
bool msb_first)
102 int sizebvec = inbvec.length();
104 for (i = 0; i < sizebvec; i++) {
105 temp +=
pow2i(sizebvec - i - 1) * int(inbvec(i));
109 for (i = 0; i < sizebvec; i++) {
110 temp +=
pow2i(i) * int(inbvec(i));
116 bvec
oct2bin(
const ivec &octalindex,
short keepzeros)
118 int length = octalindex.length(), i;
120 for (i = 0; i <
length; i++) {
121 out.replace_mid(3*i,
dec2bin(3, octalindex(i)));
124 if (keepzeros == 0) {
125 for (i = 0; i < out.length(); i++) {
126 if ((
short)out(i) != 0) {
127 return out.right(out.length() - i);
138 ivec
bin2oct(
const bvec &inbits)
140 int start, Itterations =
ceil_i(inbits.length() / 3.0);
141 ivec out(Itterations);
142 for (
int i = Itterations - 1; i > 0; i--) {
143 start = 3 * i - (3 * Itterations - inbits.length());
144 out(i) =
bin2dec(inbits.mid(start, 3));
146 out(0) =
bin2dec(inbits.left(inbits.length() - ((Itterations - 1) * 3)));
150 ivec
bin2pol(
const bvec &inbvec)
155 bvec
pol2bin(
const ivec &inpol)
157 return to_bvec((1 -inpol) / 2);
162 double round(
double x) { return ::rint(x); }
164 vec
round(
const vec &x) {
return apply_function<double>(::rint, x); }
166 mat
round(
const mat &x) {
return apply_function<double>(::rint, x); }
168 int round_i(
double x) {
return static_cast<int>(::rint(x)); }
188 cvec temp(x.length());
190 for (
int i = 0; i < x.length(); i++)
198 cmat temp(x.rows(), x.cols());
200 for (
int i = 0; i < x.rows(); i++) {
201 for (
int j = 0; j < x.cols(); j++) {
211 cvec temp(in.length());
213 for (
int i = 0; i < in.length(); i++)
221 cmat temp(in.rows(), in.cols());
223 for (
int i = 0; i < in.rows(); i++) {
224 for (
int j = 0; j < in.cols(); j++) {
232 std::string
to_str(
const double &i,
const int precision)
234 std::ostringstream ss;
235 ss.precision(precision);
236 ss.setf(std::ostringstream::scientific, std::ostringstream::floatfield);
245 template ITPP_EXPORT bvec
to_bvec(
const svec &v);
246 template ITPP_EXPORT bvec
to_bvec(
const ivec &v);
248 template ITPP_EXPORT svec
to_svec(
const bvec &v);
249 template ITPP_EXPORT svec
to_svec(
const ivec &v);
250 template ITPP_EXPORT svec
to_svec(
const vec &v);
252 template ITPP_EXPORT ivec
to_ivec(
const bvec &v);
253 template ITPP_EXPORT ivec
to_ivec(
const svec &v);
254 template ITPP_EXPORT ivec
to_ivec(
const vec &v);
256 template ITPP_EXPORT vec
to_vec(
const bvec &v);
257 template ITPP_EXPORT vec
to_vec(
const svec &v);
258 template ITPP_EXPORT vec
to_vec(
const ivec &v);
260 template ITPP_EXPORT cvec
to_cvec(
const bvec &v);
261 template ITPP_EXPORT cvec
to_cvec(
const svec &v);
262 template ITPP_EXPORT cvec
to_cvec(
const ivec &v);
263 template ITPP_EXPORT cvec
to_cvec(
const vec &v);
274 template ITPP_EXPORT smat
to_smat(
const imat &m);
275 template ITPP_EXPORT smat
to_smat(
const mat &m);
278 template ITPP_EXPORT imat
to_imat(
const smat &m);
279 template ITPP_EXPORT imat
to_imat(
const mat &m);
281 template ITPP_EXPORT mat
to_mat(
const bmat &m);
282 template ITPP_EXPORT mat
to_mat(
const smat &m);
283 template ITPP_EXPORT mat
to_mat(
const imat &m);
286 template ITPP_EXPORT cmat
to_cmat(
const smat &m);
287 template ITPP_EXPORT cmat
to_cmat(
const imat &m);
288 template ITPP_EXPORT cmat
to_cmat(
const mat &m);