3 #include "../include/ctf.hpp" 11 typedef std::complex<float>
TYPE6;
12 typedef std::complex<double>
TYPE7;
16 template <
typename dtype>
19 for(
int i=0;i<A->
order;i++) {
25 template <
typename dtype>
32 template <
typename dtype>
38 B_bool->operator[](idx_B) =
CTF::Function<bool, bool>([](
bool a){
return a==
false ?
true :
false; })(B_bool->operator[](idx_B));
41 template <
typename dtype>
44 for(
int i=0;i<A->
order;i++) {
47 B->operator[](str) =
CTF::Function<std::complex<dtype>,std::complex<dtype>>([](std::complex<dtype>
a){
return std::complex<dtype>(a.real(), -a.imag()); })(A->operator[](str));
50 template <
typename dtype>
53 for(
int i=0;i<A->
order;i++) {
56 B->operator[](str) =
CTF::Function<std::complex<dtype>,
dtype>([](std::complex<dtype>
a){
return a.real(); })(A->operator[](str));
59 template <
typename dtype>
62 for(
int i=0;i<A->
order;i++) {
65 B->operator[](str) =
CTF::Function<std::complex<dtype>,
dtype>([](std::complex<dtype>
a){
return a.imag(); })(A->operator[](str));
69 template <
typename dtype>
72 for(
int i=0;i<A->
order;i++) {
78 template <
typename dtype>
81 for(
int i=0;i<A->
order;i++) {
87 template <
typename dtype>
95 for (
int i=0; i<A->
order; i++){
105 if (ret !=
CTF_int::SUCCESS){ printf(
"CTF ERROR: failed to execute function sparisfy\n");
IASSERT(0);
return; }
117 (*Q)[
"ij"] = mQ[
"ij"];
118 (*R)[
"ij"] = mR[
"ij"];
129 (*Q)[
"ij"] = mQ[
"ij"];
130 (*R)[
"ij"] = mR[
"ij"];
135 printf(
"CTF ERROR: SVD called on invalid tensor element type\n");
149 (*Q)[
"ij"] = mQ[
"ij"];
150 (*R)[
"ij"] = mR[
"ij"];
161 (*Q)[
"ij"] = mQ[
"ij"];
162 (*R)[
"ij"] = mR[
"ij"];
167 printf(
"CTF ERROR: SVD called on invalid tensor element type\n");
183 mA.
svd(mU, vS, mVT, rank);
185 (*U)[
"ij"] = mU[
"ij"];
187 (*VT)[
"ij"] = mVT[
"ij"];
198 mA.
svd(mU, vS, mVT, rank);
200 (*U)[
"ij"] = mU[
"ij"];
202 (*VT)[
"ij"] = mVT[
"ij"];
207 printf(
"CTF ERROR: SVD called on invalid tensor element type\n");
221 mA.
svd(mU, vS, mVT, rank);
223 (*U)[
"ij"] = mU[
"ij"];
225 (*VT)[
"ij"] = mVT[
"ij"];
236 mA.
svd(mU, vS, mVT, rank);
238 (*U)[
"ij"] = mU[
"ij"];
240 (*VT)[
"ij"] = mVT[
"ij"];
245 printf(
"CTF ERROR: SVD called on invalid tensor element type\n");
263 #define CONV_FCOMPLEX_INST(ctype,otype) \ 265 void tensor::conv_type<std::complex<ctype>,otype>(tensor * B){ \ 266 char str[this->order]; \ 267 for (int i=0; i<this->order; i++){ \ 270 assert(this->order == B->order); \ 271 B->operator[](str) = CTF::Function<otype,std::complex<ctype>>([](otype a){ return std::complex<ctype>(a,0.); })(this->operator[](str)); \ 290 #define SWITCH_TYPE(T1, type_idx2, A, B) \ 291 switch (type_idx2){ \ 293 A->conv_type<TYPE##T1, TYPE1>(B); \ 296 A->conv_type<TYPE##T1, TYPE2>(B); \ 299 A->conv_type<TYPE##T1, TYPE3>(B); \ 302 A->conv_type<TYPE##T1, TYPE4>(B); \ 305 A->conv_type<TYPE##T1, TYPE5>(B); \ 308 A->conv_type<TYPE##T1, TYPE6>(B); \ 311 A->conv_type<TYPE##T1, TYPE7>(B); \ 315 A->conv_type<TYPE##T1, TYPE8>(B); \ 319 A->conv_type<TYPE##T1, TYPE9>(B); \ 401 template void tensor::compare_elementwise<float>(
tensor * A,
tensor * B);
402 template void tensor::compare_elementwise<double>(
tensor * A,
tensor * B);
403 template void tensor::compare_elementwise< std::complex<double> >(
tensor * A,
tensor * B);
404 template void tensor::compare_elementwise< std::complex<float> >(
tensor * A,
tensor * B);
405 template void tensor::compare_elementwise<bool>(
tensor * A,
tensor * B);
408 template void tensor::not_equals<double>(
tensor * A,
tensor * B);
409 template void tensor::not_equals<bool>(
tensor * A,
tensor * B);
412 template void tensor::smaller_than<double>(
tensor * A,
tensor * B);
413 template void tensor::smaller_than<bool>(
tensor * A,
tensor * B);
416 template void tensor::smaller_equal_than<double>(
tensor * A,
tensor * B);
417 template void tensor::smaller_equal_than<bool>(
tensor * A,
tensor * B);
420 template void tensor::larger_than<double>(
tensor * A,
tensor * B);
421 template void tensor::larger_than<bool>(
tensor * A,
tensor * B);
424 template void tensor::larger_equal_than<double>(
tensor * A,
tensor * B);
425 template void tensor::larger_equal_than<bool>(
tensor * A,
tensor * B);
429 template void tensor::exp_helper<int16_t, float>(
tensor* A);
430 template void tensor::exp_helper<int32_t, double>(
tensor* A);
431 template void tensor::exp_helper<int64_t, double>(
tensor* A);
432 template void tensor::exp_helper<float, float>(
tensor* A);
433 template void tensor::exp_helper<double, double>(
tensor* A);
434 template void tensor::exp_helper<long double, long double>(
tensor* A);
435 template void tensor::exp_helper<std::complex<double>, std::complex<double>>(
tensor* A);
437 template void tensor::exp_helper<int64_t, float>(
tensor* A);
438 template void tensor::exp_helper<int32_t, float>(
tensor* A);
441 template void abs_helper< std::complex<double> >(
tensor * A,
tensor * B);
442 template void abs_helper< std::complex<float> >(
tensor * A,
tensor * B);
453 template void pow_helper< std::complex<double> >(
tensor * A,
tensor * B,
tensor * C,
char const * idx_A,
char const * idx_B,
char const * idx_C);
454 template void pow_helper< std::complex<float> >(
tensor * A,
tensor * B,
tensor * C,
char const * idx_A,
char const * idx_B,
char const * idx_C);
465 template void all_helper< std::complex<double> >(
tensor * A,
tensor * B_bool,
char const * idx_A,
char const * idx_B);
466 template void all_helper< std::complex<float> >(
tensor * A,
tensor * B_bool,
char const * idx_A,
char const * idx_B);
476 template void any_helper< std::complex<double> >(
tensor * A,
tensor * B_bool,
char const * idx_A,
char const * idx_B);
477 template void any_helper< std::complex<float> >(
tensor * A,
tensor * B_bool,
char const * idx_A,
char const * idx_B);
486 template void tensor::true_divide<double>(
tensor* A);
487 template void tensor::true_divide<float>(
tensor* A);
488 template void tensor::true_divide<int64_t>(
tensor* A);
489 template void tensor::true_divide<int32_t>(
tensor* A);
490 template void tensor::true_divide<int16_t>(
tensor* A);
491 template void tensor::true_divide<int8_t>(
tensor* A);
492 template void tensor::true_divide<bool>(
tensor* A);
template void conj_helper< double >(tensor *A, tensor *B)
template void pow_helper< int64_t >(tensor *A, tensor *B, tensor *C, char const *idx_A, char const *idx_B, char const *idx_C)
template void any_helper< int16_t >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
template void get_real< double >(tensor *A, tensor *B)
template void abs_helper< int32_t >(tensor *A, tensor *B)
template void all_helper< int8_t >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
template void all_helper< float >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
template void all_helper< int32_t >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
void qr(Matrix< dtype > &Q, Matrix< dtype > &R)
template void set_real< float >(tensor *A, tensor *B)
template void any_helper< int32_t >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
Matrix class which encapsulates a 2D tensor.
template void pow_helper< int16_t >(tensor *A, tensor *B, tensor *C, char const *idx_A, char const *idx_B, char const *idx_C)
template void set_real< double >(tensor *A, tensor *B)
template void pow_helper< int32_t >(tensor *A, tensor *B, tensor *C, char const *idx_A, char const *idx_B, char const *idx_C)
int64_t sum_bool_tsr(tensor *A)
sum all 1 values in boolean tensor
void matrix_svd(tensor *A, tensor *U, tensor *S, tensor *VT, int rank)
double get_rand48()
returns new random number in [0,1)
int sparsify(char const *threshold=NULL, bool take_abs=true)
reduce tensor to sparse format, storing only nonzero data, or data above a specified threshold...
void conv_type(int type_idx1, int type_idx2, tensor *A, tensor *B)
convert tensor from one type to another
dtype get_val()
returns scalar value
template void any_helper< float >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
void get_real(tensor *A, tensor *B)
Vector class which encapsulates a 1D tensor.
template void abs_helper< int16_t >(tensor *A, tensor *B)
void abs_helper(tensor *A, tensor *B)
template void abs_helper< int64_t >(tensor *A, tensor *B)
template void any_helper< int8_t >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
int order
number of tensor dimensions
template void any_helper< bool >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
template void all_helper< int64_t >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
template void conj_helper< float >(tensor *A, tensor *B)
void all_helper(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
void matrix_qr_cmplx(tensor *A, tensor *Q, tensor *R)
CTF::World * wrld
distributed processor context on which tensor is defined
Scalar class which encapsulates a 0D tensor.
template void get_imag< float >(tensor *A, tensor *B)
template void pow_helper< double >(tensor *A, tensor *B, tensor *C, char const *idx_A, char const *idx_B, char const *idx_C)
void subsample(tensor *A, double probability)
extract a sample of the entries (if sparse of the current nonzeros)
void svd(Matrix< dtype > &U, Vector< dtype > &S, Matrix< dtype > &VT, int rank=0)
template void any_helper< int64_t >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
std::complex< float > TYPE6
template void get_real< float >(tensor *A, tensor *B)
void get_imag(tensor *A, tensor *B)
template void pow_helper< float >(tensor *A, tensor *B, tensor *C, char const *idx_A, char const *idx_B, char const *idx_C)
algstrct * sr
algstrct on which tensor elements and operations are defined
void set_real(tensor *A, tensor *B)
void conj_helper(tensor *A, tensor *B)
template void any_helper< double >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
void any_helper(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
template void abs_helper< double >(tensor *A, tensor *B)
void pow_helper(tensor *A, tensor *B, tensor *C, char const *idx_A, char const *idx_B, char const *idx_C)
template void pow_helper< bool >(tensor *A, tensor *B, tensor *C, char const *idx_A, char const *idx_B, char const *idx_C)
template void pow_helper< int8_t >(tensor *A, tensor *B, tensor *C, char const *idx_A, char const *idx_B, char const *idx_C)
template void all_helper< double >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
void matrix_qr(tensor *A, tensor *Q, tensor *R)
template void all_helper< bool >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
int el_size
size of each element of algstrct in bytes
template void abs_helper< float >(tensor *A, tensor *B)
internal distributed tensor class
template void get_imag< double >(tensor *A, tensor *B)
template void abs_helper< bool >(tensor *A, tensor *B)
void set_imag(tensor *A, tensor *B)
#define SWITCH_TYPE(T1, type_idx2, A, B)
template void set_imag< double >(tensor *A, tensor *B)
template void set_imag< float >(tensor *A, tensor *B)
std::complex< double > TYPE7
template void abs_helper< int8_t >(tensor *A, tensor *B)
#define CONV_FCOMPLEX_INST(ctype, otype)
template void all_helper< int16_t >(tensor *A, tensor *B_bool, char const *idx_A, char const *idx_B)
void matrix_svd_cmplx(tensor *A, tensor *U, tensor *S, tensor *VT, int rank)