36 vec
sqr(
const cvec &data)
38 vec temp(data.length());
39 for (
int i = 0; i < data.length(); i++)
40 temp(i) =
sqr(data(i));
44 mat
sqr(
const cmat &data)
46 mat temp(data.rows(), data.cols());
47 for (
int i = 0; i < temp.rows(); i++) {
48 for (
int j = 0; j < temp.cols(); j++) {
49 temp(i, j) =
sqr(data(i, j));
55 vec
abs(
const cvec &data)
57 vec temp(data.length());
59 for (
int i = 0;i < data.length();i++)
65 mat
abs(
const cmat &data)
67 mat temp(data.rows(), data.cols());
69 for (
int i = 0;i < temp.rows();i++) {
70 for (
int j = 0;j < temp.cols();j++) {
79 double gamma(
double x) {
return tgamma(x); }
80 vec
gamma(
const vec &x) {
return apply_function<double>(tgamma, x); }
81 mat
gamma(
const mat &x) {
return apply_function<double>(tgamma, x); }
86 it_error_if(index > 170,
"fact(int index): Function overflows if index > 170.");
87 it_error_if(index < 0,
"fact(int index): index must be non-negative integer");
89 for (
int i = 1; i <= index; i++)
90 prod *= static_cast<double>(i);
97 it_assert(k <= n,
"binom(n, k): k can not be larger than n");
98 it_assert((n >= 0) && (k >= 0),
"binom(n, k): n and k must be non-negative integers");
99 k = ((n - k) < k) ? n - k : k;
102 for (
int i = 1; i <= k; ++i) {
112 it_assert(k <= n,
"binom_i(n, k): k can not be larger than n");
113 it_assert((n >= 0) && (k >= 0),
"binom_i(n, k): n and k must be non-negative integers");
114 k = ((n - k) < k) ? n - k : k;
117 for (
int i = 1; i <= k; ++i) {
127 it_assert(k <= n,
"log_binom(n, k): k can not be larger than n");
128 it_assert((n >= 0) && (k >= 0),
"log_binom(n, k): n and k must be non-negative integers");
129 k = ((n - k) < k) ? n - k : k;
132 for (
int i = 1; i <= k; i++)
133 out +=
log10(static_cast<double>(i + n - k))
134 -
log10(static_cast<double>(i));
142 it_assert((a >= 0) && (b >= 0),
"gcd(a, b): a and b must be non-negative integers");
159 vec temp(data.length());
161 for (
int i = 0;i < data.length();i++)
162 temp[i] = data[i].
real();
169 mat temp(data.rows(), data.cols());
171 for (
int i = 0;i < temp.rows();i++) {
172 for (
int j = 0;j < temp.cols();j++) {
173 temp(i, j) = data(i, j).real();
182 vec temp(data.length());
184 for (
int i = 0;i < data.length();i++)
185 temp[i] = data[i].
imag();
191 mat temp(data.rows(), data.cols());
193 for (
int i = 0;i < temp.rows();i++) {
194 for (
int j = 0;j < temp.cols();j++) {
195 temp(i, j) = data(i, j).imag();
204 vec temp(data.length());
206 for (
int i = 0;i < data.length();i++)
214 mat temp(data.rows(), data.cols());
216 for (
int i = 0;i < temp.rows();i++) {
217 for (
int j = 0;j < temp.cols();j++) {
226 cvec
conj(
const cvec &x)
230 for (
int i = 0; i < x.size(); i++) {
237 cmat
conj(
const cmat &x)
239 cmat temp(x.rows(), x.cols());
241 for (
int i = 0; i < x.rows(); i++) {
242 for (
int j = 0; j < x.cols(); j++) {