36vec
sqr(
const cvec &data)
38 vec
temp(data.length());
44mat
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++) {
55vec
abs(
const cvec &data)
57 vec
temp(data.length());
60 temp[
i] = std::abs(data[
i]);
65mat
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++) {
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());
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++) {
182 vec
temp(data.length());
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++) {
204 vec
temp(data.length());
207 temp[
i] = std::arg(data[
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++) {
226cvec
conj(
const cvec &x)
230 for (
int i = 0; i < x.size(); i++) {
231 temp(i) = std::conj(x(i));
237cmat
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++) {
243 temp(i, j) = std::conj(x(i, j));
int length() const
Returns the number of data elements in the array object.
Elementary mathematical functions - header file.
#define it_error_if(t, s)
Abort if t is true.
#define it_assert(t, s)
Abort if t is not true.
vec log10(const vec &x)
log-10 of the elements
T prod(const Vec< T > &v)
The product of all elements in the vector.
double gamma(double x)
Deprecated gamma function - please use tgamma() instead.
double binom(int n, int k)
Compute the binomial coefficient "n over k".
double fact(int index)
Calculates factorial coefficient for index <= 170.
vec imag(const cvec &data)
Imaginary part of complex values.
vec arg(const cvec &data)
Argument (angle)
int binom_i(int n, int k)
Compute the binomial coefficient "n over k".
vec real(const cvec &data)
Real part of complex values.
vec sqr(const cvec &data)
Absolute square of elements.
int gcd(int a, int b)
Compute the greatest common divisor (GCD) g of the elements a and b.
cvec conj(const cvec &x)
Conjugate of complex value.
double log_binom(int n, int k)
Compute the base 10 logarithm of the binomial coefficient "n over k".
IT++ compatibility types and functions.
bin abs(const bin &inbin)
absolute value of bin