From cba2cb15cb85b245a57e4b99ea3b30b4fb1dd955 Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Sat, 2 May 2026 03:18:02 +0800 Subject: [PATCH 1/3] code cleanup ensures that operator<< writes to the correct ostream fixes python bindings removes comments of the form // cout << ... fixes and orders includes --- include/Accessor.hpp | 5 +- include/Bond.hpp | 14 +- include/Device.hpp | 8 +- include/Gncon.hpp | 31 ++- include/LinOp.hpp | 17 +- include/Network.hpp | 31 ++- include/Symmetry.hpp | 23 +- include/Tensor.hpp | 5 - include/UniTensor.hpp | 80 +++--- include/backend/Scalar.hpp | 31 ++- include/backend/Storage.hpp | 22 +- include/backend/Tensor_impl.hpp | 1 - include/stat.hpp | 12 +- include/utils/dynamic_arg_resolver.hpp | 4 - include/utils/print.hpp | 13 +- pybind/network_py.cpp | 4 +- pybind/scalar_py.cpp | 4 +- pybind/storage_py.cpp | 6 +- pybind/unitensor_py.cpp | 12 +- src/Accessor.cpp | 22 +- src/BlockFermionicUniTensor.cpp | 236 +++--------------- src/BlockUniTensor.cpp | 88 +++---- src/Bond.cpp | 4 +- src/DenseUniTensor.cpp | 86 +++---- src/Device.cpp | 33 ++- src/FermionNetwork.cpp | 1 - src/Generator.cpp | 7 +- src/Gncon.cpp | 2 +- src/Gncon_base.cpp | 7 +- src/LinOp.cpp | 17 +- src/Network.cpp | 4 +- src/Network_base.cpp | 6 +- src/Physics.cpp | 1 - src/RegularGncon.cpp | 66 ++--- src/RegularNetwork.cpp | 119 ++++----- src/SparseUniTensor.cpp | 78 +++--- src/Symmetry.cpp | 78 +++--- src/Tensor.cpp | 2 +- src/UniTensor.cpp | 5 +- src/UniTensor_base.cpp | 16 +- src/backend/Scalar.cpp | 10 +- src/backend/Storage.cpp | 5 +- src/backend/StorageImplementation.cpp | 55 ++-- src/backend/Storage_base.cpp | 134 +++++----- src/backend/Tensor_impl.cpp | 62 +---- .../algo_internal_cpu/Concate_internal.cpp | 2 - .../algo_internal_cpu/Concate_internal.hpp | 1 - .../algo_internal_cpu/Split_internal.cpp | 1 - .../algo_internal_cpu/Split_internal.hpp | 1 - .../algo_internal_gpu/cuConcate_internal.cu | 1 - .../algo_internal_gpu/cuConcate_internal.hpp | 1 - .../algo_internal_gpu/cuSplit_internal.hpp | 1 - .../linalg_internal_cpu/Abs_internal.hpp | 1 - .../linalg_internal_cpu/Axpy_internal.hpp | 1 - .../Batch_matmul_internal.hpp | 1 - .../Conj_inplace_internal.hpp | 1 - .../linalg_internal_cpu/Det_internal.hpp | 1 - .../linalg_internal_cpu/Diag_internal.hpp | 1 - .../linalg_internal_cpu/Eig_internal.hpp | 1 - .../linalg_internal_cpu/Eigh_internal.hpp | 1 - .../linalg_internal_cpu/Exp_internal.hpp | 1 - .../Gemm_Batch_internal.hpp | 1 - .../linalg_internal_cpu/Gemm_internal.hpp | 1 - .../linalg_internal_cpu/Ger_internal.hpp | 1 - .../linalg_internal_cpu/Gesvd_internal.hpp | 1 - .../InvM_inplace_internal.hpp | 2 +- .../Inv_inplace_internal.hpp | 2 +- .../linalg_internal_cpu/Kron_internal.hpp | 2 +- .../linalg_internal_cpu/Lstsq_internal.hpp | 2 +- .../Matmul_dg_internal.hpp | 2 +- .../linalg_internal_cpu/Matmul_internal.cpp | 1 - .../linalg_internal_cpu/Matmul_internal.hpp | 2 +- .../linalg_internal_cpu/Matvec_internal.cpp | 1 - .../linalg_internal_cpu/Matvec_internal.hpp | 1 - .../linalg_internal_cpu/MaxMin_internal.hpp | 1 - .../linalg_internal_cpu/Norm_internal.hpp | 1 - .../linalg_internal_cpu/Outer_internal.hpp | 1 - .../linalg_internal_cpu/Pow_internal.hpp | 1 - .../linalg_internal_cpu/QR_internal.hpp | 1 - .../linalg_internal_cpu/Sdd_internal.hpp | 1 - .../linalg_internal_cpu/Trace_internal.hpp | 1 - .../linalg_internal_cpu/Tridiag_internal.cpp | 4 - .../linalg_internal_cpu/Tridiag_internal.hpp | 1 - .../Vectordot_internal.cpp | 2 +- .../Vectordot_internal.hpp | 1 - .../linalg_internal_cpu/iAdd_internal.cpp | 2 +- .../linalg_internal_cpu/iAdd_internal.hpp | 2 +- .../linalg_internal_cpu/iDiv_internal.cpp | 1 - .../linalg_internal_cpu/iDiv_internal.hpp | 2 +- .../linalg_internal_cpu/iMul_internal.cpp | 2 +- .../linalg_internal_cpu/iMul_internal.hpp | 2 +- .../linalg_internal_cpu/iSub_internal.cpp | 2 +- .../linalg_internal_cpu/iSub_internal.hpp | 2 +- .../linalg_internal_cpu/memcpyTruncation.hpp | 1 - .../linalg_internal_gpu/cuAbs_internal.hpp | 1 - .../linalg_internal_gpu/cuAdd_internal.hpp | 1 - .../cuConj_inplace_internal.hpp | 1 - .../linalg_internal_gpu/cuCpr_internal.hpp | 1 - .../linalg_internal_gpu/cuDet_internal.hpp | 1 - .../linalg_internal_gpu/cuDiag_internal.hpp | 1 - .../linalg_internal_gpu/cuDiv_internal.hpp | 1 - .../linalg_internal_gpu/cuEig_internal.hpp | 1 - .../linalg_internal_gpu/cuEigh_internal.hpp | 1 - .../linalg_internal_gpu/cuExp_internal.hpp | 1 - .../linalg_internal_gpu/cuGeSvd_internal.hpp | 1 - .../cuGemm_Batch_internal.hpp | 1 - .../linalg_internal_gpu/cuGemm_internal.hpp | 1 - .../linalg_internal_gpu/cuGer_internal.hpp | 1 - .../cuInvM_inplace_internal.hpp | 1 - .../cuInv_inplace_internal.hpp | 1 - .../linalg_internal_gpu/cuKron_internal.cuh | 1 - .../cuMatmul_dg_internal.cu | 2 - .../cuMatmul_dg_internal.hpp | 1 - .../linalg_internal_gpu/cuMatmul_internal.hpp | 1 - .../linalg_internal_gpu/cuMatvec_internal.hpp | 1 - .../linalg_internal_gpu/cuMaxMin_internal.cu | 2 - .../linalg_internal_gpu/cuMaxMin_internal.hpp | 1 - .../linalg_internal_gpu/cuMod_internal.hpp | 1 - .../linalg_internal_gpu/cuMul_internal.hpp | 1 - .../linalg_internal_gpu/cuNorm_internal.hpp | 1 - .../linalg_internal_gpu/cuOuter_internal.hpp | 1 - .../linalg_internal_gpu/cuPow_internal.hpp | 1 - .../cuQuantumGeSvd_internal.cu | 1 + .../cuQuantumGeSvd_internal.hpp | 1 - .../cuQuantumQr_internal.hpp | 1 - .../linalg_internal_gpu/cuSub_internal.hpp | 1 - .../linalg_internal_gpu/cuSum_internal.hpp | 1 - .../linalg_internal_gpu/cuSvd_internal.hpp | 1 - .../cuTensordot_internal.hpp | 1 - .../linalg_internal_gpu/cuTrace_internal.hpp | 1 - .../cuVectordot_internal.cu | 18 +- .../cuVectordot_internal.hpp | 1 - .../cudaMemcpyTruncation.hpp | 1 - src/backend/linalg_internal_interface.hpp | 1 - .../GetElems_contiguous_cpu.cpp | 1 - src/contraction_tree.cpp | 15 -- src/linalg/Conj.cpp | 1 - src/linalg/Conj_.cpp | 1 - src/linalg/Cpr.cpp | 2 - src/linalg/Det.cpp | 1 - src/linalg/Div.cpp | 1 - src/linalg/Dot.cpp | 2 - src/linalg/Eig.cpp | 19 -- src/linalg/Eigh.cpp | 18 -- src/linalg/ExpH.cpp | 9 - src/linalg/ExpM.cpp | 9 - src/linalg/Gemm.cpp | 4 - src/linalg/Gemm_Batch.cpp | 1 - src/linalg/Gesvd.cpp | 25 -- src/linalg/Hosvd.cpp | 1 - src/linalg/Kron.cpp | 1 - src/linalg/Lanczos.cpp | 6 +- src/linalg/Lanczos_ER.cpp | 9 - src/linalg/Lanczos_Exp.cpp | 23 +- src/linalg/Lanczos_Gnd.cpp | 29 +-- src/linalg/Lanczos_Gnd_Ut.cpp | 17 +- src/linalg/Lstsq.cpp | 1 - src/linalg/Matmul.cpp | 8 - src/linalg/Matmul_dg.cpp | 7 - src/linalg/Mul.cpp | 1 - src/linalg/Norm.cpp | 1 - src/linalg/Outer.cpp | 1 - src/linalg/Qdr.cpp | 3 - src/linalg/Qr.cpp | 10 - src/linalg/Rand_isometry.cpp | 1 - src/linalg/Rsvd.cpp | 4 - src/linalg/Svd.cpp | 30 --- src/linalg/Trace.cpp | 1 - src/linalg/Tridiag.cpp | 4 - src/linalg/iAdd.cpp | 2 - src/ncon.cpp | 1 - src/search_tree.cpp | 2 + src/stat/histogram.cpp | 37 ++- src/tn_algo/DMRG.cpp | 39 +-- src/tn_algo/MPS.cpp | 2 +- src/tn_algo/RegularMPS.cpp | 5 - src/utils/complex_arithmetic.cpp | 1 - src/utils/cutensornet.cu | 12 +- src/utils/utils.cpp | 1 - 179 files changed, 686 insertions(+), 1276 deletions(-) diff --git a/include/Accessor.hpp b/include/Accessor.hpp index cca852628..7e263065e 100644 --- a/include/Accessor.hpp +++ b/include/Accessor.hpp @@ -6,8 +6,8 @@ #include #include #include -#include #include +#include namespace cytnx { @@ -63,7 +63,6 @@ namespace cytnx { std::vector tmp = list; this->_type = this->list; this->idx_list = std::vector(tmp.begin(), tmp.end()); - // std::cout << "VV" << this->idx_list.size() << std::endl; }; // construct from vector/list, should be 1d with dtype integer. template @@ -184,10 +183,8 @@ namespace cytnx { template std::vector Indices_resolver(const T &a, const Ts &...args) { - // std::cout << a << std::endl;; std::vector idxs; _resolve_elems(idxs, a, args...); - // cout << idxs << endl; return idxs; } ///@endcond diff --git a/include/Bond.hpp b/include/Bond.hpp index 4e2417901..3de7ae725 100644 --- a/include/Bond.hpp +++ b/include/Bond.hpp @@ -1,14 +1,16 @@ #ifndef CYTNX_BOND_H_ #define CYTNX_BOND_H_ -#include "Type.hpp" -#include "cytnx_error.hpp" -#include "Symmetry.hpp" -#include -#include +#include #include +#include #include -#include +#include +#include + +#include "Symmetry.hpp" +#include "Type.hpp" +#include "cytnx_error.hpp" #include "intrusive_ptr_base.hpp" #include "utils/vec_clone.hpp" diff --git a/include/Device.hpp b/include/Device.hpp index 99747e107..418a5e2d0 100644 --- a/include/Device.hpp +++ b/include/Device.hpp @@ -1,8 +1,9 @@ #ifndef CYTNX_DEVICE_H_ #define CYTNX_DEVICE_H_ -#include +#include #include +#include namespace cytnx { @@ -18,7 +19,10 @@ namespace cytnx { int Ncpus; std::vector> CanAccessPeer; Device_class(); - void Print_Property(); + void Print_Property() { this->Print_Property(std::cout); } + /// @cond + void Print_Property(std::ostream &os); + /// @endcond std::string getname(const int &device_id); ~Device_class(); // void cudaDeviceSynchronize(); diff --git a/include/Gncon.hpp b/include/Gncon.hpp index d83c1c14f..1e4aff14b 100644 --- a/include/Gncon.hpp +++ b/include/Gncon.hpp @@ -1,16 +1,18 @@ #ifndef CYTNX_GNCON_H_ #define CYTNX_GNCON_H_ -#include "Type.hpp" -#include "cytnx_error.hpp" +#include #include -#include +#include #include -#include -#include "intrusive_ptr_base.hpp" -#include "utils/utils.hpp" +#include + +#include "Type.hpp" #include "UniTensor.hpp" #include "contraction_tree.hpp" +#include "cytnx_error.hpp" +#include "intrusive_ptr_base.hpp" +#include "utils/utils.hpp" #ifdef BACKEND_TORCH #else @@ -69,7 +71,7 @@ namespace cytnx { return true; } - // void print_Gncon() const; + // void print_Gncon(std::ostream &os = std::cout) const; // void PreConstruct(bool force = true); @@ -93,7 +95,7 @@ namespace cytnx { virtual void clear(); virtual std::string getOptimalOrder(); virtual UniTensor Launch(const bool &optimal = false, const std::string &contract_order = ""); - virtual void PrintNet(std::ostream &os); + virtual void PrintNet(std::ostream &os) const; virtual boost::intrusive_ptr clone(); virtual void Savefile(const std::string &fname); virtual ~Gncon_base(){}; @@ -137,7 +139,7 @@ namespace cytnx { boost::intrusive_ptr out(tmp); return out; } - void PrintNet(std::ostream &os); + void PrintNet(std::ostream &os) const; void Savefile(const std::string &fname); ~RegularGncon(){}; }; @@ -182,9 +184,9 @@ namespace cytnx { boost::intrusive_ptr out(tmp); return out; } - void PrintNet(std::ostream &os){}; - void Savefile(const std::string &fname){}; - ~FermionGncon(){}; + void PrintNet(std::ostream &os) const; + void Savefile(const std::string &fname); + ~FermionGncon(); }; ///@endcond @@ -352,7 +354,10 @@ namespace cytnx { out._impl = this->_impl->clone(); return out; } - void PrintNet() { this->_impl->PrintNet(std::cout); } + void PrintNet() const { this->_impl->PrintNet(std::cout); } + /// @cond + void PrintNet(std::ostream &os) const { this->_impl->PrintNet(os); } + /// @endcond void Savefile(const std::string &fname) { this->_impl->Savefile(fname); } }; diff --git a/include/LinOp.hpp b/include/LinOp.hpp index 1ed60f8b6..a09d9c297 100644 --- a/include/LinOp.hpp +++ b/include/LinOp.hpp @@ -1,17 +1,19 @@ #ifndef CYTNX_LINOP_H_ #define CYTNX_LINOP_H_ -#include "Type.hpp" -#include "cytnx_error.hpp" -#include +#include #include #include +#include #include #include -#include -#include "intrusive_ptr_base.hpp" +#include + #include "Tensor.hpp" +#include "Type.hpp" #include "UniTensor.hpp" +#include "cytnx_error.hpp" +#include "intrusive_ptr_base.hpp" #ifdef BACKEND_TORCH #else @@ -156,7 +158,10 @@ namespace cytnx { int dtype() const { return this->_dtype; }; cytnx_uint64 nx() const { return this->_nx; }; - void _print(); + void _print() { this->_print(std::cout); }; + /// @cond + void _print(std::ostream &os); + /// @endcond /// @cond // this expose to interitance: diff --git a/include/Network.hpp b/include/Network.hpp index 75aa82db1..dae9f68c1 100644 --- a/include/Network.hpp +++ b/include/Network.hpp @@ -1,16 +1,18 @@ #ifndef CYTNX_NETWORK_H_ #define CYTNX_NETWORK_H_ -#include "Type.hpp" -#include "cytnx_error.hpp" +#include #include -#include +#include #include -#include -#include "intrusive_ptr_base.hpp" -#include "utils/utils.hpp" +#include + +#include "Type.hpp" #include "UniTensor.hpp" #include "contraction_tree.hpp" +#include "cytnx_error.hpp" +#include "intrusive_ptr_base.hpp" +#include "utils/utils.hpp" #ifdef BACKEND_TORCH #else @@ -95,7 +97,7 @@ namespace cytnx { return true; } - // void print_network() const; + // void print_network(std::ostream &os = std::cout) const; // void PreConstruct(bool force = true); @@ -135,7 +137,7 @@ namespace cytnx { const std::vector> &labels, const std::vector &outlabel, const cytnx_int64 &outrk, const std::string &order, const bool optim); - virtual void PrintNet(std::ostream &os); + virtual void PrintNet(std::ostream &os = std::cout) const; virtual boost::intrusive_ptr clone(); virtual void Savefile(const std::string &fname); virtual ~Network_base(){}; @@ -194,7 +196,7 @@ namespace cytnx { boost::intrusive_ptr out(tmp); return out; } - void PrintNet(std::ostream &os); + void PrintNet(std::ostream &os = std::cout) const; void Savefile(const std::string &fname); ~RegularNetwork(){}; }; @@ -245,9 +247,9 @@ namespace cytnx { boost::intrusive_ptr out(tmp); return out; } - void PrintNet(std::ostream &os){}; - void Savefile(const std::string &fname){}; - ~FermionNetwork(){}; + void PrintNet(std::ostream &os = std::cout) const; + void Savefile(const std::string &fname); + ~FermionNetwork(); }; ///@endcond @@ -450,7 +452,10 @@ namespace cytnx { out._impl = this->_impl->clone(); return out; } - void PrintNet() { this->_impl->PrintNet(std::cout); } + void PrintNet() const { this->_impl->PrintNet(std::cout); } + /// @cond + void PrintNet(std::ostream &os) const { this->_impl->PrintNet(os); } + /// @endcond void Savefile(const std::string &fname) { this->_impl->Savefile(fname); } }; diff --git a/include/Symmetry.hpp b/include/Symmetry.hpp index 46b02e5a1..3c1a1972d 100644 --- a/include/Symmetry.hpp +++ b/include/Symmetry.hpp @@ -2,7 +2,7 @@ #define CYTNX_SYMMETRY_H_ #include -#include +#include #include #include @@ -90,7 +90,7 @@ namespace cytnx { virtual fermionParity get_fermion_parity(const cytnx_int64 &in_qnum) const; virtual bool is_fermionic() const { return false; }; - virtual void print_info() const; + virtual void print_info(std::ostream &os = std::cout) const; virtual std::string stype_str() const; // virtual std::vector& combine_rule(const std::vector &inL, const // std::vector &inR); @@ -105,7 +105,7 @@ namespace cytnx { void Init(const int &n) { this->stype_id = SymmetryType::U; this->n = n; - if (n != 1) cytnx_error_msg(1, "%s", "[ERROR] U1Symmetry should set n = 1"); + if (n != 1) cytnx_error_msg(true, "%s", "[ERROR] U1Symmetry should set n = 1"); } boost::intrusive_ptr clone() { boost::intrusive_ptr out(new U1Symmetry(this->n)); @@ -118,7 +118,7 @@ namespace cytnx { void combine_rule_(cytnx_int64 &out, const cytnx_int64 &inL, const cytnx_int64 &inR, const bool &is_reverse); void reverse_rule_(cytnx_int64 &out, const cytnx_int64 &in); - void print_info() const; + void print_info(std::ostream &os = std::cout) const; std::string stype_str() const override { return "U1"; }; }; ///@endcond @@ -131,7 +131,7 @@ namespace cytnx { void Init(const int &n) { this->stype_id = SymmetryType::Z; this->n = n; - if (n <= 1) cytnx_error_msg(1, "%s", "[ERROR] ZnSymmetry can only have n > 1"); + if (n <= 1) cytnx_error_msg(true, "%s", "[ERROR] ZnSymmetry can only have n > 1"); } boost::intrusive_ptr clone() { boost::intrusive_ptr out(new ZnSymmetry(this->n)); @@ -144,7 +144,7 @@ namespace cytnx { void combine_rule_(cytnx_int64 &out, const cytnx_int64 &inL, const cytnx_int64 &inR, const bool &is_reverse); void reverse_rule_(cytnx_int64 &out, const cytnx_int64 &in); - void print_info() const; + void print_info(std::ostream &os = std::cout) const; std::string stype_str() const override { return "Z" + std::to_string(this->n); }; }; ///@endcond @@ -169,7 +169,7 @@ namespace cytnx { void reverse_rule_(cytnx_int64 &out, const cytnx_int64 &in); fermionParity get_fermion_parity(const cytnx_int64 &in_qnum) const override; bool is_fermionic() const override { return true; }; - void print_info() const; + void print_info(std::ostream &os = std::cout) const; std::string stype_str() const override { return "fP"; } }; ///@endcond @@ -194,7 +194,7 @@ namespace cytnx { void reverse_rule_(cytnx_int64 &out, const cytnx_int64 &in); fermionParity get_fermion_parity(const cytnx_int64 &in_qnum) const override; bool is_fermionic() const override { return true; }; - void print_info() const; + void print_info(std::ostream &os = std::cout) const; std::string stype_str() const override { return "f#"; } }; ///@endcond @@ -226,7 +226,7 @@ namespace cytnx { boost::intrusive_ptr tmp(new FermionNumberSymmetry()); this->_impl = tmp; } else { - cytnx_error_msg(1, "%s", "[ERROR] invalid symmetry type."); + cytnx_error_msg(true, "%s", "[ERROR] invalid symmetry type."); } } Symmetry &operator=(const Symmetry &rhs) { @@ -524,7 +524,10 @@ namespace cytnx { /** * @brief Print the information of current Symmetry object. */ - void print_info() const { this->_impl->print_info(); } + void print_info() const { this->_impl->print_info(std::cout); } + /// @cond + void print_info(std::ostream &os) const { this->_impl->print_info(os); } + /// @endcond /** * @brief the equality operator of the Symmetry object. diff --git a/include/Tensor.hpp b/include/Tensor.hpp index e7645c419..11fd45bf7 100644 --- a/include/Tensor.hpp +++ b/include/Tensor.hpp @@ -232,25 +232,21 @@ namespace cytnx { //---------------------------------------- template Tproxy operator()(const std::string &e1, const Ts &...elems) { - // std::cout << e1 << std::endl; std::vector tmp = Indices_resolver(e1, elems...); return (*this)[tmp]; } template Tproxy operator()(const cytnx_int64 &e1, const Ts &...elems) { - // std::cout << e1<< std::endl; std::vector tmp = Indices_resolver(e1, elems...); return (*this)[tmp]; } template Tproxy operator()(const cytnx::Accessor &e1, const Ts &...elems) { - // std::cout << e1 << std::endl; std::vector tmp = Indices_resolver(e1, elems...); return (*this)[tmp]; } template const Tproxy operator()(const std::string &e1, const Ts &...elems) const { - // std::cout << e1 << std::endl; std::vector tmp = Indices_resolver(e1, elems...); return (*this)[tmp]; } @@ -805,7 +801,6 @@ namespace cytnx { template Tensor &reshape_(const cytnx_int64 &e1, const Ts... elems) { std::vector shape = dynamic_arg_int64_resolver(e1, elems...); - // std::cout << shape << std::endl; this->_impl->reshape_(shape); return *this; } diff --git a/include/UniTensor.hpp b/include/UniTensor.hpp index 68afa5d9b..6873d656d 100644 --- a/include/UniTensor.hpp +++ b/include/UniTensor.hpp @@ -1,23 +1,24 @@ #ifndef CYTNX_UNITENSOR_H_ #define CYTNX_UNITENSOR_H_ -#include "Type.hpp" -#include "cytnx_error.hpp" -#include "Device.hpp" -#include "Tensor.hpp" -#include "utils/utils.hpp" -#include "intrusive_ptr_base.hpp" +#include +#include +#include #include -#include #include +#include #include -#include -#include -#include -#include "Symmetry.hpp" +#include + #include "Bond.hpp" +#include "Device.hpp" #include "Generator.hpp" -#include +#include "Symmetry.hpp" +#include "Tensor.hpp" +#include "Type.hpp" +#include "cytnx_error.hpp" +#include "intrusive_ptr_base.hpp" +#include "utils/utils.hpp" #ifdef BACKEND_TORCH #else @@ -273,9 +274,10 @@ namespace cytnx { virtual boost::intrusive_ptr contiguous(); virtual boost::intrusive_ptr apply_(); virtual boost::intrusive_ptr apply(); - virtual void print_diagram(const bool &bond_info = false) const; - virtual void print_blocks(const bool &full_info = true) const; - virtual void print_block(const cytnx_int64 &idx, const bool &full_info = true) const; + virtual void print_diagram(std::ostream &os, const bool &bond_info = false) const; + virtual void print_blocks(std::ostream &os, const bool &full_info = true) const; + virtual void print_block(std::ostream &os, const cytnx_int64 &idx, + const bool &full_info = true) const; virtual boost::intrusive_ptr astype(const unsigned int &dtype) const; @@ -638,9 +640,9 @@ namespace cytnx { return out; } - void print_diagram(const bool &bond_info = false) const; - void print_blocks(const bool &full_info = true) const; - void print_block(const cytnx_int64 &idx, const bool &full_info = true) const; + void print_diagram(std::ostream &os, const bool &bond_info = false) const; + void print_blocks(std::ostream &os, const bool &full_info = true) const; + void print_block(std::ostream &os, const cytnx_int64 &idx, const bool &full_info = true) const; Tensor get_block() const { return this->_block.clone(); } Tensor get_block(const cytnx_uint64 &idx) const { cytnx_error_msg(idx != 0, @@ -1460,9 +1462,9 @@ namespace cytnx { return out; } - void print_diagram(const bool &bond_info = false) const; - void print_blocks(const bool &full_info = true) const; - void print_block(const cytnx_int64 &idx, const bool &full_info = true) const; + void print_diagram(std::ostream &os, const bool &bond_info = false) const; + void print_blocks(std::ostream &os, const bool &full_info = true) const; + void print_block(std::ostream &os, const cytnx_int64 &idx, const bool &full_info = true) const; boost::intrusive_ptr contract(const boost::intrusive_ptr &rhs, const bool &mv_elem_self = false, @@ -2234,9 +2236,9 @@ namespace cytnx { boost::intrusive_ptr apply_(); boost::intrusive_ptr apply(); - void print_diagram(const bool &bond_info = false) const; - void print_blocks(const bool &full_info = true) const; - void print_block(const cytnx_int64 &idx, const bool &full_info = true) const; + void print_diagram(std::ostream &os, const bool &bond_info = false) const; + void print_blocks(std::ostream &os, const bool &full_info = true) const; + void print_block(std::ostream &os, const cytnx_int64 &idx, const bool &full_info = true) const; boost::intrusive_ptr contract(const boost::intrusive_ptr &rhs, const bool &mv_elem_self = false, @@ -2750,7 +2752,6 @@ namespace cytnx { */ void Init(const Tensor &in_tensor, const bool &is_diag = false, const cytnx_int64 &rowrank = -1, const std::vector &in_labels = {}, const std::string &name = "") { - // std::cout << "[entry!]" << std::endl; boost::intrusive_ptr out(new DenseUniTensor()); out->Init_by_Tensor(in_tensor, is_diag, rowrank, name); this->_impl = out; @@ -2843,8 +2844,6 @@ namespace cytnx { if (sym_fver == -1) sym_fver = bonds[i]._impl->_degs.size(); else { - // std::cout << sym_fver << " " << - // bonds[i]._impl->_degs.size() << std::endl; cytnx_error_msg((bool(sym_fver) ^ bool(bonds[i]._impl->_degs.size())), "[ERROR] When initializing a UniTensor with symmetries, all Bonds must " "be in the same format!%s", @@ -3881,18 +3880,30 @@ namespace cytnx { } /** - @brief Plot the diagram of the UniTensor. + @brief Print the diagram of the UniTensor. @param[in] bond_info whether need to print the information of the bonds of the UniTensor. */ void print_diagram(const bool &bond_info = false) const { - this->_impl->print_diagram(bond_info); + this->_impl->print_diagram(std::cout, bond_info); + } + /// @cond + void print_diagram(std::ostream &os, const bool &bond_info = false) const { + this->_impl->print_diagram(os, bond_info); } + /// @endcond /** @brief Print all blocks of the UniTensor. @param[in] full_info whether need to print the full information of the blocks */ - void print_blocks(const bool &full_info = true) const { this->_impl->print_blocks(full_info); } + void print_blocks(const bool &full_info = true) const { + this->_impl->print_blocks(std::cout, full_info); + } + /// @cond + void print_blocks(std::ostream &os, const bool &full_info = true) const { + this->_impl->print_blocks(os, full_info); + } + /// @endcond /** @brief Print out the block of the UniTensor with a given block index number. @@ -3900,8 +3911,13 @@ namespace cytnx { @param[in] full_info whether need to print the full information of the block */ void print_block(const cytnx_int64 &idx, const bool &full_info = true) const { - this->_impl->print_block(idx, full_info); + this->_impl->print_block(std::cout, idx, full_info); + } + /// @cond + void print_block(std::ostream &os, const cytnx_int64 &idx, const bool &full_info = true) const { + this->_impl->print_block(os, idx, full_info); } + /// @endcond /** @brief Group the same quantum number basis together. @@ -3930,7 +3946,6 @@ namespace cytnx { */ template T &at(const std::vector &locator) { - // std::cout << "at " << this->is_blockform() << std::endl; if (this->uten_type() == UTenType.Block || this->uten_type() == UTenType.BlockFermionic) { // [NEW] this will not check if it exists, if it is not then error will throw! T aux; @@ -3959,7 +3974,6 @@ namespace cytnx { */ template const T &at(const std::vector &locator) const { - // std::cout << "at " << this->is_blockform() << std::endl; if (this->uten_type() == UTenType.Block || this->uten_type() == UTenType.BlockFermionic) { // [NEW] this will not check if it exists, if it is not then error will throw! T aux; diff --git a/include/backend/Scalar.hpp b/include/backend/Scalar.hpp index e6d1e7a94..19959b25d 100644 --- a/include/backend/Scalar.hpp +++ b/include/backend/Scalar.hpp @@ -2,16 +2,19 @@ #define CYTNX_BACKEND_SCALAR_H_ #ifndef BACKEND_TORCH - #include "Type.hpp" - #include "cytnx_error.hpp" - #include "intrusive_ptr_base.hpp" - #include + + #include #include - #include #include - #include - #include #include + #include + #include + #include + + #include "Type.hpp" + #include "cytnx_error.hpp" + #include "intrusive_ptr_base.hpp" + namespace cytnx { ///@cond @@ -2845,15 +2848,17 @@ namespace cytnx { */ int dtype() const { return this->_impl->_dtype; } - // print() /** - * @brief Print the Scalar to the standard output. + * @brief Print the Scalar */ - void print() const { - this->_impl->print(std::cout); - std::cout << std::string(" Scalar dtype: [") << Type.getname(this->_impl->_dtype) - << std::string("]") << std::endl; + void print() const { this->print(std::cout); } + /// @cond + void print(std::ostream &os) const { + this->_impl->print(os); + os << std::string(" Scalar dtype: [") << Type.getname(this->_impl->_dtype) << std::string("]") + << std::endl; } + /// @endcond // casting /// @brief The explicit casting operator of the Scalar class to cytnx::cytnx_double. diff --git a/include/backend/Storage.hpp b/include/backend/Storage.hpp index 4c693a280..458295e99 100644 --- a/include/backend/Storage.hpp +++ b/include/backend/Storage.hpp @@ -63,8 +63,9 @@ namespace cytnx { void _cpy_bool(void *ptr, const std::vector &vin); - void print(); - void print_info(); + void print(std::ostream &os = std::cout) const; + void print_info(std::ostream &os = std::cout) const; + /* This function is design to check the type mismatch. Handy for developer to exclude the assign of double @@ -121,7 +122,7 @@ namespace cytnx { cytnx_error_msg(typeid(T) != typeid(cytnx_bool), "%s", "[ERROR _Init_byptr_safe type not match]"); } else { - cytnx_error_msg(1, "[FATAL] ERROR%s", "\n"); + cytnx_error_msg(true, "[FATAL] ERROR%s", "\n"); } this->_Init_byptr((void *)rawptr, len_in); @@ -186,7 +187,7 @@ namespace cytnx { const std::vector &invmapper); virtual void PrintElem_byShape(std::ostream &os, const std::vector &shape, const std::vector &mapper = {}); - virtual void print_elems(); + virtual void print_elems(std::ostream &os = std::cout) const; virtual boost::intrusive_ptr real(); virtual boost::intrusive_ptr imag(); @@ -258,7 +259,11 @@ namespace cytnx { boost::intrusive_ptr to(const int &device); void PrintElem_byShape(std::ostream &os, const std::vector &shape, const std::vector &mapper = {}); - void print_elems(); + + void print_elems() const { this->print(std::cout); } + /// @cond + void print_elems(std::ostream &os = std::cout) const; + /// @endcond ~StorageImplementation(); @@ -768,10 +773,11 @@ namespace cytnx { @brief print the info of the Storage, including the device, dtype and size. */ - void print_info() const { this->_impl->print_info(); } + void print_info() const { this->_impl->print(std::cout); } /// @cond + void print_info(std::ostream &os) const { this->_impl->print(os); } // this is a redundant function - void print() const { this->_impl->print(); } + void print(std::ostream &os = std::cout) const { this->_impl->print(os); } /// @endcond /** @@ -870,7 +876,7 @@ namespace cytnx { void _from_vector(const std::vector &vin, const int device = -1) { // auto dispatch: // check: - cytnx_error_msg(1, "[FATAL] ERROR unsupport type%s", "\n"); + cytnx_error_msg(true, "[FATAL] ERROR unsupport type%s", "\n"); // this->_impl->Init(vin.size(),device); // memcpy(this->_impl->data(),&vin[0],sizeof(T)*vin.size()); } diff --git a/include/backend/Tensor_impl.hpp b/include/backend/Tensor_impl.hpp index a497e9751..524a62ffa 100644 --- a/include/backend/Tensor_impl.hpp +++ b/include/backend/Tensor_impl.hpp @@ -226,7 +226,6 @@ namespace cytnx { this->_storage._impl->Move_memory(oldshape, this->_mapper, this->_invmapper); // this->_storage._impl->Move_memory_(oldshape, this->_mapper, this->_invmapper); // out->_storage._impl = this->_storage._impl; - // std::cout << out->_storage << std::endl; out->_invmapper = vec_range(this->_invmapper.size()); out->_mapper = out->_invmapper; out->_shape = this->_shape; diff --git a/include/stat.hpp b/include/stat.hpp index 142bec071..0c2163586 100644 --- a/include/stat.hpp +++ b/include/stat.hpp @@ -1,13 +1,13 @@ #ifndef CYTNX_STAT_H_ #define CYTNX_STAT_H_ -#include "Type.hpp" -#include "cytnx_error.hpp" - -#include "Tensor.hpp" #include #include +#include "Tensor.hpp" +#include "Type.hpp" +#include "cytnx_error.hpp" + #ifdef BACKEND_TORCH #else @@ -86,7 +86,7 @@ namespace cytnx { } void normalize(); - void print() const; + void print(std::ostream &os = std::cout) const; const Storage &get_x() const { // get x @@ -179,7 +179,7 @@ namespace cytnx { } void normalize(); - void print() const; + void print(std::ostream &os = std::cout) const; const Storage &get_x() const { // get x diff --git a/include/utils/dynamic_arg_resolver.hpp b/include/utils/dynamic_arg_resolver.hpp index 2e52703dc..abe851313 100644 --- a/include/utils/dynamic_arg_resolver.hpp +++ b/include/utils/dynamic_arg_resolver.hpp @@ -22,10 +22,8 @@ namespace cytnx { template std::vector dynamic_arg_int64_resolver(const cytnx_int64 &a, const Ts &...args) { - // std::cout << a << std::endl; std::vector idxs; _resolve_int64(idxs, a, args...); - // cout << idxs << endl; return idxs; } @@ -46,10 +44,8 @@ namespace cytnx { template std::vector dynamic_arg_uint64_resolver(const cytnx_uint64 &a, const Ts &...args) { - // std::cout << a << std::endl;; std::vector idxs; _resolve_uint64(idxs, a, args...); - // cout << idxs << endl; return idxs; } diff --git a/include/utils/print.hpp b/include/utils/print.hpp index a765da634..c8021d992 100644 --- a/include/utils/print.hpp +++ b/include/utils/print.hpp @@ -1,14 +1,14 @@ #ifndef CYTNX_UTILS_PRINT_H_ #define CYTNX_UTILS_PRINT_H_ -#include "Type.hpp" -#include "Tensor.hpp" +#include #include "Bond.hpp" +#include "Network.hpp" #include "Symmetry.hpp" +#include "Tensor.hpp" +#include "Type.hpp" #include "UniTensor.hpp" -#include "Network.hpp" -#include #ifdef BACKEND_TORCH #else @@ -23,6 +23,11 @@ namespace cytnx { std::cout << ipt << std::endl; } + template + void print(std::ostream &os, const T &ipt) { + os << ipt << std::endl; + } + } // namespace cytnx #endif // CYTNX_UTILS_PRINT_H_ diff --git a/pybind/network_py.cpp b/pybind/network_py.cpp index 5f442d19f..fbecafa37 100644 --- a/pybind/network_py.cpp +++ b/pybind/network_py.cpp @@ -114,7 +114,9 @@ void network_binding(py::module &m) { return std::string(""); }, py::call_guard()) - .def("PrintNet", &Network::PrintNet) + .def( + "PrintNet", [](Network &self) { self.PrintNet(); }, + py::call_guard()) .def_static( "Contract", [](const std::vector &utensors, const std::string &Tout, diff --git a/pybind/scalar_py.cpp b/pybind/scalar_py.cpp index 6cd648864..005cdc0e6 100644 --- a/pybind/scalar_py.cpp +++ b/pybind/scalar_py.cpp @@ -116,7 +116,9 @@ void scalar_binding(py::module &m) { .def("iabs", &Scalar::iabs) .def("isqrt", &Scalar::isqrt) .def("dtype", &Scalar::dtype) - .def("print", &Scalar::print) + .def( + "print", [](const Scalar &self) { self.print(); }, + py::call_guard()) // ---- Arithmetic in-place ---- .def("__iadd__", diff --git a/pybind/storage_py.cpp b/pybind/storage_py.cpp index 2808b6672..631dc83c6 100644 --- a/pybind/storage_py.cpp +++ b/pybind/storage_py.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -194,8 +195,9 @@ void storage_binding(py::module &m) { .def("__deepcopy__", &cytnx::Storage::clone) .def("size", &cytnx::Storage::size) .def("__len__", [](cytnx::Storage &self) { return self.size(); }) - .def("print_info", &cytnx::Storage::print_info, - py::call_guard()) + .def( + "print_info", [](cytnx::Storage &self) { self.print_info(); }, + py::call_guard()) .def("set_zeros", &cytnx::Storage::set_zeros) .def("__eq__", [](cytnx::Storage &self, const cytnx::Storage &rhs) -> bool { return self == rhs; }) diff --git a/pybind/unitensor_py.cpp b/pybind/unitensor_py.cpp index 50bd02280..7d6e41efc 100644 --- a/pybind/unitensor_py.cpp +++ b/pybind/unitensor_py.cpp @@ -588,12 +588,12 @@ void unitensor_binding(py::module &m) { .def("apply_", &UniTensor::apply_, "Apply fermionic signflips inplacely. Subsequently, signflip() returns False for all " "elements. Non-fermionic tensors are left unchanged. See also: apply()") - .def("print_diagram", &UniTensor::print_diagram, py::arg("bond_info") = false, - py::call_guard()) - .def("print_blocks", &UniTensor::print_blocks, py::arg("full_info") = true, - py::call_guard()) - .def("print_block", &UniTensor::print_block, py::arg("idx"), py::arg("full_info") = true, - py::call_guard()) + .def("print_diagram", [](UniTensor &self, const bool &bond_info){ self.print_diagram(bond_info); }, + py::call_guard(), py::arg("bond_info") = false) + .def("print_block", [](UniTensor &self, const cytnx_int64 &idx, const bool &full_info){ self.print_block(idx, full_info); }, + py::call_guard(), py::arg("idx"), py::arg("full_info") = true) + .def("print_blocks", [](UniTensor &self, const bool &full_info){ self.print_blocks(full_info); }, + py::call_guard(), py::arg("full_info") = true) .def("group_basis_", &UniTensor::group_basis_) .def("group_basis", &UniTensor::group_basis) diff --git a/src/Accessor.cpp b/src/Accessor.cpp index 932b12f7e..681698efc 100644 --- a/src/Accessor.cpp +++ b/src/Accessor.cpp @@ -1,8 +1,10 @@ #include "Accessor.hpp" -#include "utils/str_utils.hpp" -#include + #include +#include #include + +#include "utils/str_utils.hpp" #include "utils/vec_print.hpp" using namespace std; @@ -40,7 +42,6 @@ namespace cytnx { Accessor::Accessor(const std::string &str) { // this->_axis_len = 0; - // std::cout << str << "|" << std::endl; if ((str == "all") || (str == ":")) this->_type = Accessor::All; else { @@ -76,11 +77,6 @@ namespace cytnx { } else { this->_step = 1; } - - // cout << this->min; - // cout << this->max; - // cout << this->step << endl; - // std::cout << token << std::endl; } } @@ -145,20 +141,17 @@ namespace cytnx { "a null Tensor."); // len = (r_max-r_min)/this->step; - // std::cout << len << " " << dim << std::endl; // if((r_max-r_min)%this->step) len+=1; len = 0; if (this->_step < 0) { for (cytnx_int64 i = r_min; i > r_max; i += this->_step) { pos.push_back(i); - // std::cout << pos.back() << std::endl; len++; } } else { for (cytnx_int64 i = r_min; i < r_max; i += this->_step) { pos.push_back(i); - // std::cout << pos.back() << std::endl; len++; } } @@ -179,20 +172,16 @@ namespace cytnx { if (this->_step < 0) { for (cytnx_int64 i = r_min; i >= r_max; i += this->_step) { pos.push_back(i); - // std::cout << pos.back() << std::endl; - len++; } } else { for (cytnx_int64 i = r_min; i <= r_max; i += this->_step) { pos.push_back(i); - // std::cout << pos.back() << std::endl; len++; } } } else if (this->_type == Accessor::Singl) { // check: - // std::cout << this->loc << " " << dim << std::endl; cytnx_error_msg(std::abs(this->loc) >= dim, "[ERROR] index is out of bound%s", "\n"); len = 1; if (this->loc < 0) @@ -215,13 +204,11 @@ namespace cytnx { if (this->_step < 0) { for (cytnx_int64 i = r_min; i >= r_max; i += this->_step) { pos.push_back(i); - // std::cout << pos.back() << std::endl; len++; } } else { for (cytnx_int64 i = r_min; i <= r_max; i += this->_step) { pos.push_back(i); - // std::cout << pos.back() << std::endl; len++; } } @@ -230,7 +217,6 @@ namespace cytnx { pos.clear(); pos.resize(this->idx_list.size()); len = pos.size(); - // cout << "list in accessor len:" <idx_list.size(); i++) { // checking: if (this->idx_list[i] < 0) { diff --git a/src/BlockFermionicUniTensor.cpp b/src/BlockFermionicUniTensor.cpp index 0ca22202b..b4a0322f0 100644 --- a/src/BlockFermionicUniTensor.cpp +++ b/src/BlockFermionicUniTensor.cpp @@ -1,15 +1,20 @@ #include "UniTensor.hpp" + +#include +#include +#include +#include + +#include + #include "Accessor.hpp" -#include "utils/utils.hpp" -#include "linalg.hpp" #include "Generator.hpp" -#include +#include "linalg.hpp" +#include "utils/utils.hpp" #include "utils/vec_clone.hpp" -#include "utils/vec_print.hpp" #include "utils/vec_concatenate.hpp" -#include -#include -#include +#include "utils/vec_print.hpp" + using namespace std; #ifdef BACKEND_TORCH @@ -153,15 +158,8 @@ namespace cytnx { bool fin = false; while (1) { // get elem - // cout << "start!" << endl; - // cytnx::vec_print_simple(std::cout , Loc); this->_fx_get_total_fluxs(Loc, this->_bonds[0].syms(), tot_qns); - // std::cout << "Loc: "; - // cytnx::vec_print_simple(std::cout, Loc); - // std::cout << "tot_flx: "; - // cytnx::vec_print_simple(std::cout, tot_qns); - // if exists: if (std::all_of(tot_qns.begin(), tot_qns.end(), [](const int &i) { return i == 0; })) { // get size & init block! @@ -191,7 +189,6 @@ namespace cytnx { continue; } else { Loc.back() += 1; - // cout << "+1 at loc:" << Loc.size()-1 <_bonds.size()) { Loc.push_back(0); } @@ -322,15 +319,14 @@ namespace cytnx { os << (std::string(" ") * (3 + Lmax + 5)) << std::string("-") * (4 + mL + mR + 5) << endl; } - void BlockFermionicUniTensor::print_block(const cytnx_int64 &idx, const bool &full_info) const { + void BlockFermionicUniTensor::print_block(std::ostream &os, const cytnx_int64 &idx, + const bool &full_info) const { //[21 Aug 2024] This is a copy from BlockUniTensor; sign structure is printed additionally cytnx_error_msg( (idx < 0) || (idx >= this->_blocks.size()), "[ERROR] index [%d] out of bound. should be >0 and < number of available blocks %d\n", idx, this->_blocks.size()); - std::ostream &os = std::cout; - os << "========================\n"; if (this->_is_diag) os << " *is_diag: True\n"; os << "BLOCK [#" << idx << "]\n"; @@ -372,10 +368,8 @@ namespace cytnx { } } - void BlockFermionicUniTensor::print_blocks(const bool &full_info) const { + void BlockFermionicUniTensor::print_blocks(std::ostream &os, const bool &full_info) const { //[21 Aug 2024] This is a copy from BlockUniTensor; sign structure is printed additionally - std::ostream &os = std::cout; - os << "-------- start of print ---------\n"; char *buffer = (char *)malloc(sizeof(char) * 10240); sprintf(buffer, "Tensor name: %s\n", this->_name.c_str()); @@ -407,7 +401,7 @@ namespace cytnx { // print each blocks with its qnum! for (int b = 0; b < this->_blocks.size(); b++) { - this->print_block(b, full_info); + this->print_block(os, b, full_info); } /* @@ -434,34 +428,34 @@ namespace cytnx { free(buffer); } - void BlockFermionicUniTensor::print_diagram(const bool &bond_info) const { + void BlockFermionicUniTensor::print_diagram(std::ostream &os, const bool &bond_info) const { //[21 Aug 2024] This is a copy from BlockUniTensor; additionally, 'f' symbols in the corners of // the diagram are shown, and the sign structure is printed char *buffer = (char *)malloc(10240 * sizeof(char)); unsigned int BUFFsize = 100; sprintf(buffer, "--fermionic UniTensor---%s", "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "tensor Name : %s\n", this->_name.c_str()); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "tensor Rank : %d\n", this->_labels.size()); - std::cout << std::string(buffer); + os << std::string(buffer); // sprintf(buffer, "block_form : true%s", "\n"); - // std::cout << std::string(buffer); + // os << std::string(buffer); sprintf(buffer, "contiguous : %s\n", this->is_contiguous() ? "True" : "False"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "valid blocks: %d\n", this->_blocks.size()); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "is diag : %s\n", this->is_diag() ? "True" : "False"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "on device : %s\n", this->device_str().c_str()); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "fermion sign:"); for (int i = 0; i < this->_signflip.size(); i++) { sprintf(buffer + strlen(buffer), this->_signflip[i] ? " -1" : " +1"); } sprintf(buffer + strlen(buffer), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); cytnx_uint64 Nin = this->_rowrank; cytnx_uint64 Nout = this->_labels.size() - this->_rowrank; @@ -497,12 +491,12 @@ namespace cytnx { std::string tmpss; sprintf(buffer, "%s row %s col %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s f%sf %s", LallSpace.c_str(), M_dashes.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); for (cytnx_uint64 i = 0; i < vl; i++) { sprintf(buffer, "%s |%s| %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); if (i < Nin) { if (this->_bonds[i].type() == bondType::BD_KET) @@ -546,21 +540,21 @@ namespace cytnx { sprintf(rlbl, "%s", tmpss.c_str()); } sprintf(buffer, " %s| %s %s |%s\n", l, llbl, rlbl, r); - std::cout << std::string(buffer); + os << std::string(buffer); } sprintf(buffer, "%s |%s| %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s f%sf %s", LallSpace.c_str(), M_dashes.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s", "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); if (bond_info) { for (cytnx_uint64 i = 0; i < this->_bonds.size(); i++) { // sprintf(buffer, "lbl:%d ", this->_labels[i]); sprintf(buffer, "lbl:%s ", this->_labels[i].c_str()); - std::cout << std::string(buffer); - std::cout << this->_bonds[i] << std::endl; + os << std::string(buffer); + os << this->_bonds[i] << std::endl; } } @@ -890,15 +884,11 @@ namespace cytnx { // get the parities std::vector qindices = this->_inner_to_outer_idx[b]; // quantum indices for each block - // std::cout << "[DEBUG] Block " << b << " qnums: " << qindices << std::endl; // find the fermion parity for each quantum index std::vector parities(qindices.size()); for (cytnx_int64 qnum = 0; qnum < qindices.size(); qnum++) { parities[qnum] = this->_bonds[qnum]._impl->get_fermion_parity( this->_bonds[qnum]._impl->_qnums[qindices[qnum]]); - // std::cout << "[DEBUG] Block " << b << ", Qindex[" << qnum << "] = " << qindices[qnum] - // << " Qnums = " << this->_bonds[qnum]._impl->_qnums[qindices[qnum]] << endl; - // std::cout << "[DEBUG] Parity: " << parities[qnum] << endl; } // permute; the goal is to permute until we arrive at an ordered list [0,1,2,3,4] @@ -918,7 +908,6 @@ namespace cytnx { fermionParity actparity; // permute; we exchange i with permutation[i], until permutation[i] == i for (cytnx_int64 qnum = 0; qnum < qindices.size(); qnum++) { - // cout << "[DEBUG] permutation[" << qnum << "] = " << permutation[qnum] << endl; while (permutation[qnum] != qnum) { // exchange until the correct qindex is here actind = permutation[qnum]; // want to exchange qnum <-> actind; // then, permutation[actind] == actind @@ -927,19 +916,10 @@ namespace cytnx { if (actparity == ODD) { if (parities[actind] == ODD) { // both fermionic, one sign flip signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] - // << " because parities[permutation[actind=" << actind - // << "]=" << permutation[actind] << "] and parities[actind=" << actind - // << "] are both ODD" << endl; } else { // one fermionic, sign flip for each intermediate fermion for (cytnx_int64 intqnum = qnum + 1; intqnum < actind; intqnum++) { if (parities[permutation[intqnum]] == ODD) { signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] - // << " because parities[permutation[actind=" << actind - // << "]=" << permutation[actind] - // << "] and parities[permutation[intqnum=" << intqnum - // << "]=" << permutation[intqnum] << "] are both ODD" << endl; } } } @@ -949,28 +929,15 @@ namespace cytnx { for (cytnx_int64 intqnum = qnum + 1; intqnum < actind; intqnum++) { if (parities[permutation[intqnum]] == ODD) { signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] - // << " because parities[actind=" << actind - // << "] and parities[permutation[intqnum=" << intqnum - // << "]=" << permutation[intqnum] << "] are both ODD" << endl; } } } // else{ //both bosonic, do nothing // } } - // cout << "[DEBUG] permutation before permute: " << endl - // << permutation << "; signs before permute: " << endl - // << parities << endl; - // cout << "[DEBUG] qnum = " << qnum << "; actind = " << actind - // << "; permutation[actind] = " << permutation[actind] << endl; // exchange the sites permutation[qnum] = permutation[actind]; permutation[actind] = actind; - // cout << "[DEBUG] permutation after permute: " << endl - // << permutation << "; signs after permute:" << endl - // << parities << endl; - // cout << "[DEBUG] signflip = " << signs[b] << endl; } } // this->_signflip[b] = signflip; @@ -988,47 +955,29 @@ namespace cytnx { // find parities std::vector qindices = this->_inner_to_outer_idx[b]; // quantum indices for each block - // std::cout << "[DEBUG] Block " << b << " qnums: " << qindices << std::endl; // find the fermion parity for each quantum index std::vector parities(qindices.size()); for (cytnx_uint64 qnum = 0; qnum < qindices.size(); qnum++) { parities[qnum] = this->_bonds[qnum]._impl->get_fermion_parity( this->_bonds[qnum]._impl->_qnums[qindices[qnum]]); - // std::cout << "[DEBUG] Block " << b << ", Qindex[" << qnum << "] = " << qindices[qnum] << - // " Qnums = " << this->_bonds[qnum]._impl->_qnums[qindices[qnum]] << endl; cout << "Parity: - // " << parities[qnum] << endl; } std::vector permutation = std::vector(mapper.begin(), mapper.end()); cytnx_uint64 actind; fermionParity actparity; - // cout << "[DEBUG] permutation = " << permutation << endl; - // cout << "[DEBUG] parities = " << parities << endl; // permute; we exchange i with permutation[i], until permutation[i] == i for (cytnx_uint64 qnum = 0; qnum < qindices.size(); qnum++) { - // cout << "[DEBUG] permutation[" << qnum << "] = " << permutation[qnum] << endl; - // cout << "[DEBUG] parity[" << qnum << "] = " << parities[qnum] << endl; while (permutation[qnum] != qnum) { // exchange until the correct qindex is here actind = permutation[qnum]; actparity = parities[permutation[actind]]; - // cout << "[DEBUG] parities[" << permutation[actind] << "] = " << actparity << "; - // parities[" << actind << "] = " << parities[actind] << endl; // find the sign flips of the exchange, depending on the statistics of qnum and actind if (actparity == ODD) { if (parities[actind] == ODD) { // both fermionic, one sign flip signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] << " because - // parities[" << permutation[actind] << "] = ODD and parities[" << actind << "] = ODD" - // << endl; } else { // one fermionic, sign flip for each intermediate fermion for (cytnx_uint64 intqnum = qnum + 1; intqnum < actind; intqnum++) { - // cout << "[DEBUG] intqnum = " << intqnum << "; permutation[intqnum] = " << - // permutation[intqnum] << "; parity = " << parities[permutation[intqnum]] << endl; if (parities[permutation[intqnum]] == ODD) { signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] << " because - // parities[" << permutation[actind] << "] = ODD and parities[" << - // permutation[intqnum] << "] = ODD" << endl; } } } @@ -1036,29 +985,19 @@ namespace cytnx { if (parities[actind] == ODD) { // one fermionic, sign flip for each intermediate fermion for (cytnx_uint64 intqnum = qnum + 1; intqnum < actind; intqnum++) { - // cout << "[DEBUG] intqnum = " << intqnum << "; permutation[intqnum] = " << - // permutation[intqnum] << "; parity = " << parities[permutation[intqnum]] << endl; if (parities[permutation[intqnum]] == ODD) { signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] << " because - // parities[" << permutation[actind] << "] = ODD and parities[" << - // permutation[intqnum] << "] = ODD" << endl; } } } // else{ //both bosonic, do nothing // } } - // cout << "[DEBUG] permutation before permute: " << endl << permutation << "; signs - // before permute: " << endl << parities << endl; cout << "qnum = " << qnum << "; actind = - // " << actind << "; permutation[actind] = " << permutation[actind] << endl; // exchange the sites permutation[qnum] = permutation[actind]; permutation[actind] = actind; // parities[qnum] = parities[actind]; // parities[actind] = actparity; - // cout << "[DEBUG] permutation after permute: " << endl << permutation << "; signs after - // permute: " << endl << parities << endl; cout << "signflip = " << signs[b] << endl; } } // this->_signflip[b] = signflip; @@ -1079,7 +1018,6 @@ namespace cytnx { "cannot be larger than the number of bonds.%s", "\n"); cytnx_uint64 firstcontr = this->_bonds.size() - contrno; - // cout << "[DEBUG] contrno = " << contrno << "; firstcontr = " << firstcontr << endl; std::vector signs = this->_signflip; @@ -1087,58 +1025,36 @@ namespace cytnx { // find parities std::vector qindices = this->_inner_to_outer_idx[b]; // quantum indices for each block - // std::cout << "[DEBUG] Block " << b << " qnums: " << qindices << std::endl; // find the fermion parity for each quantum index std::vector parities(qindices.size()); for (cytnx_int64 qnum = 0; qnum < qindices.size(); qnum++) { parities[qnum] = this->_bonds[qnum]._impl->get_fermion_parity( this->_bonds[qnum]._impl->_qnums[qindices[qnum]]); - // std::cout << "[DEBUG] Block " << b << ", Qindex[" << qnum << "] = " << qindices[qnum] << - // " Qnums = " << this->_bonds[qnum]._impl->_qnums[qindices[qnum]] << endl; cout << "Parity: - // " << parities[qnum] << endl; } std::vector permutation = std::vector(mapper.begin(), mapper.end()); cytnx_int64 actind; fermionParity actparity; - // cout << "[DEBUG] permutation = " << permutation << endl; - // cout << "[DEBUG] parities = " << parities << endl; // sign flips for reversed order for (cytnx_int64 qnum = firstcontr; qnum < qindices.size(); qnum++) { actind = permutation[qnum]; if (parities[actind] == ODD && this->_bonds[actind]._impl->_type == BD_KET) { signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] << endl; - // cout << "[DEBUG] Block " << b << " has a sign flip because a bond is of type BD_KET; - // previous index = " << qnum << "; permuted index = " << actind << endl; cout << "[DEBUG] - // parities[" << actind << "] = " << parities[actind] << endl; } } // permute; we exchange i with permutation[i], until permutation[i] == i for (cytnx_int64 qnum = 0; qnum < qindices.size(); qnum++) { - // cout << "[DEBUG] permutation[" << qnum << "] = " << permutation[qnum] << endl; - // cout << "[DEBUG] parity[" << qnum << "] = " << parities[qnum] << endl; while (permutation[qnum] != qnum) { // exchange until the correct qindex is here actind = permutation[qnum]; actparity = parities[permutation[actind]]; - // cout << "[DEBUG] parities[" << permutation[actind] << "] = " << actparity << "; - // parities[" << actind << "] = " << parities[actind] << endl; find the sign flips of the - // exchange, depending on the statistics of qnum and actind + // find the sign flips of the exchange, depending on the statistics of qnum and actind if (actparity == ODD) { if (parities[actind] == ODD) { // both fermionic, one sign flip signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] << " because - // parities[" << permutation[actind] << "] = ODD and parities[" << actind << "] = ODD" - // << endl; } else { // one fermionic, sign flip for each intermediate fermion for (cytnx_int64 intqnum = qnum + 1; intqnum < actind; intqnum++) { - // cout << "[DEBUG] intqnum = " << intqnum << "; permutation[intqnum] = " << - // permutation[intqnum] << "; parity = " << parities[permutation[intqnum]] << endl; if (parities[permutation[intqnum]] == ODD) { signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] << " because - // parities[" << permutation[actind] << "] = ODD and parities[" << - // permutation[intqnum] << "] = ODD" << endl; } } } @@ -1146,29 +1062,19 @@ namespace cytnx { if (parities[actind] == ODD) { // one fermionic, sign flip for each intermediate fermion for (cytnx_int64 intqnum = qnum + 1; intqnum < actind; intqnum++) { - // cout << "[DEBUG] intqnum = " << intqnum << "; permutation[intqnum] = " << - // permutation[intqnum] << "; parity = " << parities[permutation[intqnum]] << endl; if (parities[permutation[intqnum]] == ODD) { signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] << " because - // parities[" << permutation[actind] << "] = ODD and parities[" << - // permutation[intqnum] << "] = ODD" << endl; } } } // else{ //both bosonic, do nothing // } } - // cout << "[DEBUG] permutation before permute: " << endl << permutation << "; signs - // before permute: " << endl << parities << endl; cout << "qnum = " << qnum << "; actind = - // " << actind << "; permutation[actind] = " << permutation[actind] << endl; exchange the - // sites + // exchange the sites permutation[qnum] = permutation[actind]; permutation[actind] = actind; // parities[qnum] = parities[actind]; // parities[actind] = actparity; - // cout << "[DEBUG] permutation after permute: " << endl << permutation << "; signs after - // permute: " << endl << parities << endl; cout << "signflip = " << signs[b] << endl; } } // this->_signflip[b] = signflip; @@ -1189,7 +1095,6 @@ namespace cytnx { "cannot be larger than the number of bonds.%s", "\n"); cytnx_uint64 firstcontr = this->_bonds.size() - contrno; - // cout << "[DEBUG] contrno = " << contrno << "; firstcontr = " << firstcontr << endl; std::vector signs = this->_signflip; @@ -1197,58 +1102,36 @@ namespace cytnx { // find parities std::vector qindices = this->_inner_to_outer_idx[b]; // quantum indices for each block - // std::cout << "[DEBUG] Block " << b << " qnums: " << qindices << std::endl; // find the fermion parity for each quantum index std::vector parities(qindices.size()); for (cytnx_uint64 qnum = 0; qnum < qindices.size(); qnum++) { parities[qnum] = this->_bonds[qnum]._impl->get_fermion_parity( this->_bonds[qnum]._impl->_qnums[qindices[qnum]]); - // std::cout << "[DEBUG] Block " << b << ", Qindex[" << qnum << "] = " << qindices[qnum] << - // " Qnums = " << this->_bonds[qnum]._impl->_qnums[qindices[qnum]] << endl; cout << "Parity: - // " << parities[qnum] << endl; } std::vector permutation = std::vector(mapper.begin(), mapper.end()); cytnx_uint64 actind; fermionParity actparity; - // cout << "[DEBUG] permutation = " << permutation << endl; - // cout << "[DEBUG] parities = " << parities << endl; // sign flips for reversed order for (cytnx_uint64 qnum = firstcontr; qnum < qindices.size(); qnum++) { actind = permutation[qnum]; if (parities[actind] == ODD && this->_bonds[actind]._impl->_type == BD_KET) { signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] << endl; - // cout << "[DEBUG] Block " << b << " has a sign flip because a bond is of type BD_KET; - // previous index = " << qnum << "; permuted index = " << actind << endl; cout << "[DEBUG] - // parities[" << actind << "] = " << parities[actind] << endl; } } // permute; we exchange i with permutation[i], until permutation[i] == i for (cytnx_uint64 qnum = 0; qnum < qindices.size(); qnum++) { - // cout << "[DEBUG] permutation[" << qnum << "] = " << permutation[qnum] << endl; - // cout << "[DEBUG] parity[" << qnum << "] = " << parities[qnum] << endl; while (permutation[qnum] != qnum) { // exchange until the correct qindex is here actind = permutation[qnum]; actparity = parities[permutation[actind]]; - // cout << "[DEBUG] parities[" << permutation[actind] << "] = " << actparity << "; - // parities[" << actind << "] = " << parities[actind] << endl; find the sign flips of the - // exchange, depending on the statistics of qnum and actind + // find the sign flips of the exchange, depending on the statistics of qnum and actind if (actparity == ODD) { if (parities[actind] == ODD) { // both fermionic, one sign flip signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] << " because - // parities[" << permutation[actind] << "] = ODD and parities[" << actind << "] = ODD" - // << endl; } else { // one fermionic, sign flip for each intermediate fermion for (cytnx_uint64 intqnum = qnum + 1; intqnum < actind; intqnum++) { - // cout << "[DEBUG] intqnum = " << intqnum << "; permutation[intqnum] = " << - // permutation[intqnum] << "; parity = " << parities[permutation[intqnum]] << endl; if (parities[permutation[intqnum]] == ODD) { signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] << " because - // parities[" << permutation[actind] << "] = ODD and parities[" << - // permutation[intqnum] << "] = ODD" << endl; } } } @@ -1256,29 +1139,19 @@ namespace cytnx { if (parities[actind] == ODD) { // one fermionic, sign flip for each intermediate fermion for (cytnx_uint64 intqnum = qnum + 1; intqnum < actind; intqnum++) { - // cout << "[DEBUG] intqnum = " << intqnum << "; permutation[intqnum] = " << - // permutation[intqnum] << "; parity = " << parities[permutation[intqnum]] << endl; if (parities[permutation[intqnum]] == ODD) { signs[b] = !signs[b]; - // cout << "[DEBUG] signs[" << b << "] flipped to " << signs[b] << " because - // parities[" << permutation[actind] << "] = ODD and parities[" << - // permutation[intqnum] << "] = ODD" << endl; } } } // else{ //both bosonic, do nothing // } } - // cout << "[DEBUG] permutation before permute: " << endl << permutation << "; signs - // before permute: " << endl << parities << endl; cout << "qnum = " << qnum << "; actind = - // " << actind << "; permutation[actind] = " << permutation[actind] << endl; exchange the - // sites + // exchange the sites permutation[qnum] = permutation[actind]; permutation[actind] = actind; // parities[qnum] = parities[actind]; // parities[actind] = actparity; - // cout << "[DEBUG] permutation after permute: " << endl << permutation << "; signs after - // permute: " << endl << parities << endl; cout << "signflip = " << signs[b] << endl; } } // this->_signflip[b] = signflip; @@ -1427,7 +1300,6 @@ namespace cytnx { out_rowrank = this->rowrank() + rhs->rowrank(); vec_concatenate_(out_labels, this->_labels, rhs->_labels); - // cout << out_bonds; tmp->Init(out_bonds, out_labels, out_rowrank, this->dtype(), this->device(), false); // tmp->_name = this->_name + "+" + rhs->_name; @@ -2022,8 +1894,6 @@ namespace cytnx { ida--; } this->permute_(perm); - // cout << "[DEBUG] ida=" << ida << "; idb=" << idb << "; permutation=" << perm << endl; - // this->print_diagram(); // 1) remove the bond, labels: this->_bonds.erase(this->_bonds.begin() + idb); @@ -2060,7 +1930,6 @@ namespace cytnx { std::map, cytnx_uint64> tmap; std::map, cytnx_uint64>::iterator itr; for (cytnx_int64 i = 0; i < this->_blocks.size(); i++) { - // std::cout << "blk: " << i << std::endl; if (this->_inner_to_outer_idx[i][ida] == this->_inner_to_outer_idx[i][idb]) { auto s = this->_inner_to_outer_idx[i]; s.erase(s.begin() + idb); @@ -2665,8 +2534,6 @@ namespace cytnx { // process one by one: for (cytnx_int64 bn = 0; bn < dup_bond_idxs.size(); bn++) { - // cout << "BOND:" << dup_bond_idxs[bn] << endl; - // cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; tmp_inner_to_outer_idx = this->_inner_to_outer_idx; for (cytnx_int64 i = 0; i < this->_inner_to_outer_idx.size(); i++) { @@ -2696,21 +2563,6 @@ namespace cytnx { // need to combine two! // checking which bonds do not need to be combined! mask[a] = 1; - /* - std::cout << "CALL DS:\n"; - std::cout << no_combine << std::endl; - std::cout << "targ: old/new itoi:\n"; - std::cout << this->_inner_to_outer_idx[b] << std::endl; - std::cout << tmp_inner_to_outer_idx[b] << std::endl; - std::cout << "----------\n" << std::endl; - std::cout << "src: old/new itoi:\n"; - std::cout << this->_inner_to_outer_idx[a] << std::endl; - std::cout << tmp_inner_to_outer_idx[a] << std::endl; - std::cout << "----------\n" << std::endl; - std::cout << new_blocks.back().shape() << std::endl; - std::cout << this->_blocks[a].shape() << std::endl; - std::cout << "=============\n" << std::endl; - */ if (new_signs.back() == this->_signflip[a]) { new_blocks.back() = linalg::Directsum(new_blocks.back(), this->_blocks[a], no_combine); @@ -2803,8 +2655,6 @@ namespace cytnx { } } } - // std::cout << idx_mapper << std::endl; - // std::cout << new_shape_aft_perm << std::endl; this->permute_(idx_mapper); this->contiguous_(); @@ -2812,8 +2662,6 @@ namespace cytnx { // group bonds: std::vector new_bonds; std::vector cb_stride(indicators.size()); - // std::cout << "idor" << idor << std::endl; - // std::cout << "rank" << this->rank() << std::endl; for (int i = 0; i < this->rank(); i++) { if (i == idor) { Bond tmp = this->_bonds[i]; @@ -2864,9 +2712,6 @@ namespace cytnx { this->_blocks[b].reshape_(new_shape); } - // cout<<"AAAAAAAAAAAAAAAAAAAAAAA"<get_qindices(2)<bonds()<_blocks.size(); b++) { this->_inner_to_outer_idx[b][idor] *= cb_stride[0]; for (int i = idor + 1; i < idor + indicators.size(); i++) { @@ -2880,15 +2725,12 @@ namespace cytnx { } this->_inner_to_outer_idx[b].resize(this->rank()); } - // std::cout << this->_inner_to_outer_idx << std::endl; // change rowrank: this->_rowrank = newrowrank; this->_is_braket_form = this->_update_braket(); - // cout<<"BBBBBBBBBBBBBBBBBBBBBBB"<get_qindices(2)<bonds()<group_basis_(); } diff --git a/src/BlockUniTensor.cpp b/src/BlockUniTensor.cpp index 8aea56690..adfe52955 100644 --- a/src/BlockUniTensor.cpp +++ b/src/BlockUniTensor.cpp @@ -1,15 +1,20 @@ #include "UniTensor.hpp" + +#include +#include +#include +#include + +#include + #include "Accessor.hpp" -#include "utils/utils.hpp" -#include "linalg.hpp" #include "Generator.hpp" -#include +#include "linalg.hpp" +#include "utils/utils.hpp" #include "utils/vec_clone.hpp" -#include "utils/vec_print.hpp" #include "utils/vec_concatenate.hpp" -#include -#include -#include +#include "utils/vec_print.hpp" + using namespace std; #ifdef BACKEND_TORCH @@ -142,15 +147,8 @@ namespace cytnx { bool fin = false; while (1) { // get elem - // cout << "start!" << endl; - // cytnx::vec_print_simple(std::cout , Loc); this->_fx_get_total_fluxs(Loc, this->_bonds[0].syms(), tot_qns); - // std::cout << "Loc: "; - // cytnx::vec_print_simple(std::cout, Loc); - // std::cout << "tot_flx: "; - // cytnx::vec_print_simple(std::cout, tot_qns); - // if exists: if (std::all_of(tot_qns.begin(), tot_qns.end(), [](const int &i) { return i == 0; })) { // get size & init block! @@ -180,7 +178,6 @@ namespace cytnx { continue; } else { Loc.back() += 1; - // cout << "+1 at loc:" << Loc.size()-1 <_bonds.size()) { Loc.push_back(0); } @@ -303,14 +300,13 @@ namespace cytnx { os << (std::string(" ") * (3 + Lmax + 5)) << std::string("-") * (4 + mL + mR + 5) << endl; } - void BlockUniTensor::print_block(const cytnx_int64 &idx, const bool &full_info) const { + void BlockUniTensor::print_block(std::ostream &os, const cytnx_int64 &idx, + const bool &full_info) const { cytnx_error_msg( (idx < 0) || (idx >= this->_blocks.size()), "[ERROR] index [%d] out of bound. should be >0 and < number of available blocks %d\n", idx, this->_blocks.size()); - std::ostream &os = std::cout; - os << "========================\n"; if (this->_is_diag) os << " *is_diag: True\n"; os << "BLOCK [#" << idx << "]\n"; @@ -351,9 +347,7 @@ namespace cytnx { } } - void BlockUniTensor::print_blocks(const bool &full_info) const { - std::ostream &os = std::cout; - + void BlockUniTensor::print_blocks(std::ostream &os, const bool &full_info) const { os << "-------- start of print ---------\n"; char *buffer = (char *)malloc(sizeof(char) * 10240); sprintf(buffer, "Tensor name: %s\n", this->_name.c_str()); @@ -377,7 +371,7 @@ namespace cytnx { // print each blocks with its qnum! for (int b = 0; b < this->_blocks.size(); b++) { - this->print_block(b, full_info); + this->print_block(os, b, full_info); } /* @@ -404,26 +398,26 @@ namespace cytnx { free(buffer); } - void BlockUniTensor::print_diagram(const bool &bond_info) const { + void BlockUniTensor::print_diagram(std::ostream &os, const bool &bond_info) const { char *buffer = (char *)malloc(10240 * sizeof(char)); unsigned int BUFFsize = 100; sprintf(buffer, "-----------------------%s", "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "tensor Name : %s\n", this->_name.c_str()); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "tensor Rank : %d\n", this->_labels.size()); - std::cout << std::string(buffer); + os << std::string(buffer); // sprintf(buffer, "block_form : true%s", "\n"); - // std::cout << std::string(buffer); + // os << std::string(buffer); sprintf(buffer, "contiguous : %s\n", this->is_contiguous() ? "True" : "False"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "valid blocks: %d\n", this->_blocks.size()); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "is diag : %s\n", this->is_diag() ? "True" : "False"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "on device : %s\n", this->device_str().c_str()); - std::cout << std::string(buffer); + os << std::string(buffer); cytnx_uint64 Nin = this->_rowrank; cytnx_uint64 Nout = this->_labels.size() - this->_rowrank; @@ -459,12 +453,12 @@ namespace cytnx { std::string tmpss; sprintf(buffer, "%s row %s col %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s -%s- %s", LallSpace.c_str(), M_dashes.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); for (cytnx_uint64 i = 0; i < vl; i++) { sprintf(buffer, "%s |%s| %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); if (i < Nin) { if (this->_bonds[i].type() == bondType::BD_KET) @@ -508,21 +502,21 @@ namespace cytnx { sprintf(rlbl, "%s", tmpss.c_str()); } sprintf(buffer, " %s| %s %s |%s\n", l, llbl, rlbl, r); - std::cout << std::string(buffer); + os << std::string(buffer); } sprintf(buffer, "%s |%s| %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s -%s- %s", LallSpace.c_str(), M_dashes.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s", "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); if (bond_info) { for (cytnx_uint64 i = 0; i < this->_bonds.size(); i++) { // sprintf(buffer, "lbl:%d ", this->_labels[i]); sprintf(buffer, "lbl:%s ", this->_labels[i].c_str()); - std::cout << std::string(buffer); - std::cout << this->_bonds[i] << std::endl; + os << std::string(buffer); + os << this->_bonds[i] << std::endl; } } @@ -767,7 +761,6 @@ namespace cytnx { out_rowrank = this->rowrank() + rhs->rowrank(); vec_concatenate_(out_labels, this->_labels, rhs->_labels); - // cout << out_bonds; tmp->Init(out_bonds, out_labels, out_rowrank, this->dtype(), this->device(), false); // tmp->_name = this->_name + "+" + rhs->_name; @@ -1308,7 +1301,6 @@ namespace cytnx { std::map, cytnx_uint64> tmap; std::map, cytnx_uint64>::iterator itr; for (cytnx_int64 i = 0; i < this->_blocks.size(); i++) { - // std::cout << "blk: " << i << std::endl; if (this->_inner_to_outer_idx[i][ida] == this->_inner_to_outer_idx[i][idb]) { auto s = this->_inner_to_outer_idx[i]; s.erase(s.begin() + idb); @@ -1815,8 +1807,6 @@ namespace cytnx { // process one by one: for (cytnx_int64 bn = 0; bn < dup_bond_idxs.size(); bn++) { - // cout << "BOND:" << dup_bond_idxs[bn] << endl; - // cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; tmp_inner_to_outer_idx = this->_inner_to_outer_idx; for (cytnx_int64 i = 0; i < this->_inner_to_outer_idx.size(); i++) { @@ -1916,8 +1906,6 @@ namespace cytnx { } } } - // std::cout << idx_mapper << std::endl; - // std::cout << new_shape_aft_perm << std::endl; this->permute_(idx_mapper); this->contiguous_(); @@ -1925,8 +1913,6 @@ namespace cytnx { // group bonds: std::vector new_bonds; std::vector cb_stride(indicators.size()); - // std::cout << "idor" << idor << std::endl; - // std::cout << "rank" << this->rank() << std::endl; for (int i = 0; i < this->rank(); i++) { if (i == idor) { Bond tmp = this->_bonds[i]; @@ -1977,9 +1963,6 @@ namespace cytnx { this->_blocks[b].reshape_(new_shape); } - // cout<<"AAAAAAAAAAAAAAAAAAAAAAA"<get_qindices(2)<bonds()<_blocks.size(); b++) { this->_inner_to_outer_idx[b][idor] *= cb_stride[0]; for (int i = idor + 1; i < idor + indicators.size(); i++) { @@ -1993,15 +1976,12 @@ namespace cytnx { } this->_inner_to_outer_idx[b].resize(this->rank()); } - // std::cout << this->_inner_to_outer_idx << std::endl; // change rowrank: this->_rowrank = newrowrank; this->_is_braket_form = this->_update_braket(); - // cout<<"BBBBBBBBBBBBBBBBBBBBBBB"<get_qindices(2)<bonds()<group_basis_(); } diff --git a/src/Bond.cpp b/src/Bond.cpp index e5b76c0e8..42ea7a781 100644 --- a/src/Bond.cpp +++ b/src/Bond.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "utils/utils.hpp" @@ -329,7 +330,6 @@ namespace cytnx { } else { idx_erase.push_back(q); tmp_degs[loc] += tmp_degs[q]; - // std::cout << "add from loc" << q << " to " << cnt << std::endl; } return_order[mapper[q]] = cnt; } @@ -620,7 +620,7 @@ namespace cytnx { } else if (bin.type() == bondType::BD_KET) { os << "type: | IN (KET)> " << std::endl; } else { - cytnx_error_msg(1, "%s", "[ERROR] internal error."); + cytnx_error_msg(true, "%s", "[ERROR] internal error."); } // os << bin.get_syms().size() << endl; diff --git a/src/DenseUniTensor.cpp b/src/DenseUniTensor.cpp index 82a008b95..53f20cfbe 100644 --- a/src/DenseUniTensor.cpp +++ b/src/DenseUniTensor.cpp @@ -1,11 +1,14 @@ #include "UniTensor.hpp" -#include "utils/utils.hpp" -#include "Generator.hpp" -#include "linalg.hpp" #include +#include #include #include + +#include "Generator.hpp" +#include "linalg.hpp" +#include "utils/utils.hpp" + typedef cytnx::Accessor ac; using namespace std; @@ -41,14 +44,10 @@ namespace cytnx { } cytnx_error_msg(bonds[i].dim() == 0, "%s", "[ERROR] All bonds must have dimension >=1"); } - // cout << N_ket << endl; - // cout << is_diag << endl; - // cout << this->_is_tag << endl; // check rowrank if (this->_is_tag) { if (is_diag) { - // cout << "NKET = " << N_ket << endl; cytnx_error_msg(N_ket != 1, "[ERROR][DenseUniTensor] is_diag = true with tagged UniTensor must have " "one IN (KET) bond and one OUT (BRA) bond.%s", @@ -148,7 +147,6 @@ namespace cytnx { cytnx_int64 i_rowrank = rowrank; if (is_diag) { - // std::cout << in_tensor.shape() << std::endl; cytnx_error_msg(in_tensor.shape().size() != 1, "[ERROR][Init_by_tensor] setting is_diag=True should have input Tensor to be " "rank-1 with diagonal elements.%s", @@ -193,7 +191,6 @@ namespace cytnx { for (cytnx_uint64 i = 0; i < in_tensor.shape().size(); i++) { bds.push_back(Bond(in_tensor.shape()[i])); } - // std::cout << bds.size() << std::endl; this->_bonds = bds; this->_block = in_tensor; std::vector tmp = vec_range(in_tensor.shape().size()); @@ -422,8 +419,8 @@ namespace cytnx { } } - void DenseUniTensor::print_block(const cytnx_int64 &idx, const bool &full_info) const { - std::ostream &os = std::cout; + void DenseUniTensor::print_block(std::ostream &os, const cytnx_int64 &idx, + const bool &full_info) const { os << "-------- start of print ---------\n"; char *buffer = (char *)malloc(sizeof(char) * 10240); sprintf(buffer, "Tensor name: %s\n", this->_name.c_str()); @@ -449,26 +446,26 @@ namespace cytnx { } free(buffer); } - void DenseUniTensor::print_blocks(const bool &full_info) const { - this->print_block(0, full_info); + void DenseUniTensor::print_blocks(std::ostream &os, const bool &full_info) const { + this->print_block(os, 0, full_info); } - void DenseUniTensor::print_diagram(const bool &bond_info) const { + void DenseUniTensor::print_diagram(std::ostream &os, const bool &bond_info) const { char *buffer = (char *)malloc(10240 * sizeof(char)); unsigned int BUFFsize = 100; sprintf(buffer, "-----------------------%s", "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "tensor Name : %s\n", this->_name.c_str()); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "tensor Rank : %ld\n", this->_labels.size()); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "block_form : False%s", "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "is_diag : %s\n", this->_is_diag ? "True" : "False"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "on device : %s\n", this->device_str().c_str()); - std::cout << std::string(buffer); + os << std::string(buffer); cytnx_uint64 Nin = this->_rowrank; cytnx_uint64 Nout = this->_labels.size() - this->_rowrank; @@ -505,15 +502,15 @@ namespace cytnx { if (this->is_tag()) { sprintf(buffer, "braket_form : %s\n", this->_is_braket_form ? "True" : "False"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s row %s col %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s -%s- %s", LallSpace.c_str(), M_dashes.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); for (cytnx_uint64 i = 0; i < vl; i++) { sprintf(buffer, "%s |%s| %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); if (i < Nin) { if (this->_bonds[i].type() == bondType::BD_KET) @@ -559,25 +556,25 @@ namespace cytnx { sprintf(rlbl, "%s", tmpss.c_str()); } sprintf(buffer, " %s| %s %s |%s\n", l, llbl, rlbl, r); - std::cout << std::string(buffer); + os << std::string(buffer); } sprintf(buffer, "%s |%s| %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s -%s- %s", LallSpace.c_str(), M_dashes.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); // sprintf(buffer, "%s", "\n"); - // std::cout << std::string(buffer); + // os << std::string(buffer); } else { sprintf(buffer, "%s %s %s", LallSpace.c_str(), M_dashes.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); for (cytnx_uint64 i = 0; i < vl; i++) { if (i == 0) { sprintf(buffer, "%s /%s\\ %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); } else { sprintf(buffer, "%s |%s| %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); } if (i < Nin) { @@ -620,20 +617,20 @@ namespace cytnx { sprintf(rlbl, "%s", tmpss.c_str()); } sprintf(buffer, " %s| %s %s |%s\n", l, llbl, rlbl, r); - std::cout << std::string(buffer); + os << std::string(buffer); } sprintf(buffer, "%s \\%s/ %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s %s %s", LallSpace.c_str(), M_dashes.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); } if (bond_info) { for (cytnx_uint64 i = 0; i < this->_bonds.size(); i++) { // sprintf(buffer, "lbl:%ld ", this->_labels[i]); sprintf(buffer, "lbl:%s ", this->_labels[i].c_str()); - std::cout << std::string(buffer); - std::cout << this->_bonds[i] << std::endl; + os << std::string(buffer); + os << this->_bonds[i] << std::endl; } } @@ -721,9 +718,7 @@ namespace cytnx { if (this->is_diag()) { // if(new_shape.size()!=2){ this->_block = cytnx::linalg::Diag(this->_block); - // std::cout << this->_block << std::endl; this->_block.reshape_(new_shape); - // std::cout << this->_block << std::endl; this->Init_by_Tensor(this->_block, false, rowrank, this->_name); //}else{ // cytnx_error_msg(new_shape[0]!=new_shape[1],"[ERROR] invalid shape. The total elements @@ -819,8 +814,6 @@ namespace cytnx { // group bonds: std::vector new_bonds; - // std::cout << "idor" << idor << std::endl; - // std::cout << "rank" << this->rank() << std::endl; for (int i = 0; i < this->rank(); i++) { if (i == idor) { Bond tmp = this->_bonds[i]; @@ -1036,8 +1029,6 @@ namespace cytnx { std::vector comm_labels; std::vector comm_idx1, comm_idx2; vec_intersect_(comm_labels, this->labels(), rhs->labels(), comm_idx1, comm_idx2); - // std::cout << comm_idx1 << std::endl; - // std::cout << comm_idx2 << std::endl; // output instance: DenseUniTensor *tmp = new DenseUniTensor(); @@ -1106,7 +1097,6 @@ namespace cytnx { } // process meta - // std::cout << this->rank() << " " << rhs->rank() << std::endl; std::vector non_comm_idx1 = vec_erase(vec_range(this->rank()), comm_idx1); std::vector non_comm_idx2 = vec_erase(vec_range(rhs->rank()), comm_idx2); @@ -1150,9 +1140,6 @@ namespace cytnx { // Tensor tmpL,tmpR; // tmpL = this->_block; // tmpR = rhs->get_block_(); // share view!! - // std::cout << "dkd" << std::endl; - // std::cout << this->_block.shape() << std::endl; - // std::cout << rhs->get_block_().shape() << std::endl; tmp->_block = linalg::Tensordot(this->_block, rhs->get_block_(), comm_idx1, comm_idx2, mv_elem_self, mv_elem_rhs); } @@ -1404,12 +1391,7 @@ namespace cytnx { } } } - void DenseUniTensor::Add_(const Scalar &rhs) { - // cout << rhs << endl; - // cytnx_error_msg(this->is_tag(),"[ERROR] Cannot perform arithmetic on tagged unitensor - // L.%s","\n"); - this->_block += rhs; - } + void DenseUniTensor::Add_(const Scalar &rhs) { this->_block += rhs; } void DenseUniTensor::Sub_(const boost::intrusive_ptr &rhs) { // checking if Bond have same direction: diff --git a/src/Device.cpp b/src/Device.cpp index 0bded499c..304251170 100644 --- a/src/Device.cpp +++ b/src/Device.cpp @@ -1,5 +1,6 @@ #include "Device.hpp" +#include #include #include "cytnx_error.hpp" @@ -8,7 +9,6 @@ using namespace std; namespace cytnx { Device_class::Device_class() : Ngpus(0), Ncpus(std::thread::hardware_concurrency()) { - // cout << "init_device class!" << endl; #ifdef UNI_GPU // get all available gpus @@ -49,7 +49,6 @@ namespace cytnx { if (device_id == this->cpu) { return string("cytnx device: CPU"); } else if (device_id >= 0) { - // cout << device_id << Ngpus << endl; if (device_id >= Ngpus) { cytnx_error_msg(true, "%s", "[ERROR] invalid device_id, gpuid exceed limit"); return string(""); @@ -61,42 +60,42 @@ namespace cytnx { return string(""); } } - void Device_class::Print_Property() { + void Device_class::Print_Property(std::ostream& os) { char* buffer = (char*)malloc(sizeof(char) * 256); #ifdef UNI_GPU - cout << "=== CUDA support ===" << endl; - cout << ": Peer PCIE Access:" << endl; - cout << " "; + os << "=== CUDA support ===" << std::endl; + os << ": Peer PCIE Access:" << std::endl; + os << " "; for (int i = 0; i < this->Ngpus; i++) { sprintf(buffer, " %2d", i); - cout << string(buffer); + os << string(buffer); } - cout << endl; + os << std::endl; - cout << " "; + os << " "; for (int i = 0; i < this->Ngpus; i++) { sprintf(buffer, "%s", "---"); - cout << string(buffer); + os << string(buffer); } - cout << endl; + os << std::endl; for (int i = 0; i < this->Ngpus; i++) { sprintf(buffer, "%2d|", i); - cout << string(buffer); + os << string(buffer); for (int j = 0; j < this->Ngpus; j++) { if (j == i) { sprintf(buffer, "%s", " x"); - cout << string(buffer); + os << string(buffer); } else { sprintf(buffer, " %d", int(CanAccessPeer[i][j])); - cout << string(buffer); + os << string(buffer); } } - cout << endl; + os << std::endl; } - cout << "--------------------" << endl; + os << "--------------------" << std::endl; #else - cout << "=== No CUDA support ===" << endl; + os << "=== No CUDA support ===" << std::endl; #endif free(buffer); diff --git a/src/FermionNetwork.cpp b/src/FermionNetwork.cpp index fe919a8d8..57dbc67b4 100644 --- a/src/FermionNetwork.cpp +++ b/src/FermionNetwork.cpp @@ -2,7 +2,6 @@ #include "Network.hpp" #include #include -#include using namespace std; diff --git a/src/Generator.cpp b/src/Generator.cpp index 90c4bccfa..16afb0638 100644 --- a/src/Generator.cpp +++ b/src/Generator.cpp @@ -1,10 +1,9 @@ #include "Generator.hpp" -#include "utils/utils.hpp" +#include #include "linalg.hpp" -#include -#include +#include "utils/utils.hpp" #ifdef BACKEND_TORCH #else @@ -21,8 +20,6 @@ namespace cytnx { } Tensor zeros(const std::vector &Nelem, const unsigned int &dtype, const int &device) { - // std::cout << "OK" << std::endl; - // std::cout << Nelem << std::endl; Tensor out(Nelem, dtype, device, true); // out._impl->storage().set_zeros(); return out; diff --git a/src/Gncon.cpp b/src/Gncon.cpp index eb1823919..9d5569953 100644 --- a/src/Gncon.cpp +++ b/src/Gncon.cpp @@ -20,7 +20,7 @@ namespace cytnx { GnconType_class NtType; - std::ostream& operator<<(std::ostream& os, const Gncon& in) { + std::ostream& operator<<(std::ostream& os, const Gncon& in) const { in._impl->PrintNet(os); return os; } diff --git a/src/Gncon_base.cpp b/src/Gncon_base.cpp index 334783a0b..85de88b2d 100644 --- a/src/Gncon_base.cpp +++ b/src/Gncon_base.cpp @@ -1,6 +1,9 @@ -#include + #include "Gncon.hpp" +#include +#include + #include "linalg.hpp" using namespace std; @@ -48,7 +51,7 @@ namespace cytnx { cytnx_error_msg(true, "[ERROR][Gncon][clone] call from uninitialize Gncon. %s", "\n"); return nullptr; } - void Gncon_base::PrintNet(std::ostream &os) { + void Gncon_base::PrintNet(std::ostream &os) const { os << " [Empty Gncon]" << endl; os << "--- Please Load Gncon file ---\n"; os << endl; diff --git a/src/LinOp.cpp b/src/LinOp.cpp index 9f58e87f4..3747db407 100644 --- a/src/LinOp.cpp +++ b/src/LinOp.cpp @@ -1,4 +1,7 @@ #include "LinOp.hpp" + +#include + #include "Tensor.hpp" #include "utils/vec_print.hpp" @@ -7,16 +10,16 @@ namespace cytnx { - void LinOp::_print() { + void LinOp::_print(std::ostream &os) { if (this->_type == "mv_elem") { - std::cout << "elements :" << std::endl; + os << "elements :" << std::endl; for (auto it = this->_elems.begin(); it != this->_elems.end(); it++) { - std::cout << "row:" << it->first << std::endl; + os << "row:" << it->first << std::endl; // Tensor e_i = it->second.second; - std::cout << "col idx:" << std::endl; - std::cout << it->second.first << std::endl; - std::cout << "elem:" << std::endl; - std::cout << it->second.second << std::endl; + os << "col idx:" << std::endl; + os << it->second.first << std::endl; + os << "elem:" << std::endl; + os << it->second.second << std::endl; } } } diff --git a/src/Network.cpp b/src/Network.cpp index 4d852a8db..e0ac6f172 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -1,6 +1,8 @@ -#include #include "Network.hpp" +#include +#include + #include "linalg.hpp" using namespace std; diff --git a/src/Network_base.cpp b/src/Network_base.cpp index 6877fc8c7..1a54d6422 100644 --- a/src/Network_base.cpp +++ b/src/Network_base.cpp @@ -1,6 +1,8 @@ -#include #include "Network.hpp" +#include +#include + #include "linalg.hpp" using namespace std; @@ -81,7 +83,7 @@ namespace cytnx { cytnx_error_msg(true, "[ERROR][Network][clone] call from uninitialized network. %s", "\n"); return nullptr; } - void Network_base::PrintNet(std::ostream &os) { + void Network_base::PrintNet(std::ostream &os) const { os << " [Empty Network]" << endl; os << "--- Please Load Network file ---\n"; os << endl; diff --git a/src/Physics.cpp b/src/Physics.cpp index d0fd6687c..553e57baf 100644 --- a/src/Physics.cpp +++ b/src/Physics.cpp @@ -5,7 +5,6 @@ #include "linalg.hpp" #include -#include #include using namespace std; diff --git a/src/RegularGncon.cpp b/src/RegularGncon.cpp index bf23de315..bf12ae7fe 100644 --- a/src/RegularGncon.cpp +++ b/src/RegularGncon.cpp @@ -1,10 +1,11 @@ -#include #include "Gncon.hpp" -#include "search_tree.hpp" -#include #include #include +#include +#include + +#include "search_tree.hpp" using namespace std; @@ -49,8 +50,6 @@ namespace cytnx { // rep_labels.push_back(vector>()); name2pos[tmpvs_[0]] = names.size() - 1; // register } - // std::cout<<"table size : "< ptmp(tmpvs_[1], "/" + to_string(i)); // table[i] = i-th tensor's leg names to be contracted, and its target labels. table[name2pos[tmpvs_[0]]].push_back(ptmp); @@ -90,8 +89,6 @@ namespace cytnx { vector tmp_ = str_split(tmp[i], false, "/"); string name = str_strip(tmp_[0]); string content = str_strip(tmp_[1]); - // std::cout<<"name = "< tmp(ls[0], ls[1]); - // std::cout<<"ls[0] = "<>> &table, vector &names, - map &name2pos) { - std::cout << "### table ###" << std::endl; + map &name2pos, std::ostream &os = std::cout) { + os << "### table ###" << std::endl; for (int i = 0; i < table.size(); i++) { for (int j = 0; j < table[i].size(); j++) { - std::cout << "original lbl, replaced lbl = " << table[i][j].first << " ," - << table[i][j].second << std::endl; + os << "original lbl, replaced lbl = " << table[i][j].first << " ," << table[i][j].second + << std::endl; } } - std::cout << "### tensor names ###" << std::endl; + os << "### tensor names ###" << std::endl; for (int i = 0; i < names.size(); i++) { - std::cout << names[i] << " pos : " << name2pos[names[i]] << std::endl; + os << names[i] << " pos : " << name2pos[names[i]] << std::endl; } } @@ -220,7 +216,6 @@ namespace cytnx { // } // this->name2pos[name] = names.size() - 1; // register - // // cout << name << "|" << names.size() - 1 << endl; // this->label_arr.push_back(vector()); // cytnx_uint64 tmp_iBN; // // this is an internal function that is defined in this cpp file. @@ -332,7 +327,6 @@ namespace cytnx { // remove any comment at eol : line = str_split(line, true, "#")[0]; // remove comment on end. - // std::cout<table, this->names, this->name2pos); @@ -539,12 +534,6 @@ namespace cytnx { void RegularGncon::PutUniTensor(const std::string &name, const UniTensor &utensor) { cytnx_uint64 idx; - /* - std::cout << "|" << name <<"|" << std::endl; - for(auto it=this->name2pos.begin();it!=this->name2pos.end();it++){ - std::cout << "|"<first<<"|"<second<<"|" << std::endl; - } - */ try { idx = this->name2pos.at(name); } catch (std::out_of_range) { @@ -557,7 +546,7 @@ namespace cytnx { this->PutUniTensor(idx, utensor); } - void RegularGncon::PrintNet(std::ostream &os) { + void RegularGncon::PrintNet(std::ostream &os) const { string status; os << "==== Gncon ====" << endl; if (this->tensors.size() == 0) { @@ -640,21 +629,12 @@ namespace cytnx { // transion save old labels: // old_labels.push_back(this->tensors[idx].labels()); - // std::cout<<"idx: "<label_arr[idx].size(); j++){ - // std::cout<label_arr[idx][j]<<","; - // } - // std::cout<tensors[idx].relabel_(this->label_arr[idx]);//this conflict this->CtTree.base_nodes[idx]->utensor = this->tensors[idx].relabel(this->label_arr[idx]); // this conflict // this->CtTree.base_nodes[idx].name = this->tensors[idx].name(); this->CtTree.base_nodes[idx]->is_assigned = true; - - // cout << this->tensors[idx].name() << " " << idx << "from dict:" << - // this->name2pos[this->tensors[idx].name()] << endl; } // 1.5 contraction order: @@ -678,7 +658,6 @@ namespace cytnx { } // 2. contract using postorder traversal: - // cout << this->CtTree.nodes_container.size() << endl; stack> stk; std::shared_ptr root = this->CtTree.nodes_container.back(); int ly = 0; @@ -707,34 +686,19 @@ namespace cytnx { if (ict) { // process! - // cout << "OK" << endl; if ((root->right != nullptr) && (root->left != nullptr)) { - // cout << "L,R::\n"; - // root->left->utensor.print_diagram(1); - // root->right->utensor.print_diagram(1); root->utensor = Contract(root->left->utensor, root->right->utensor); - // cout << "Contract:" << root->left->utensor.name() << " " << root->right->utensor.name() - // << endl; root->left->utensor.print_diagram(); root->right->utensor.print_diagram(); - // root->utensor.print_diagram(); root->utensor.set_name(root->left->utensor.name() + - // root->right->utensor.name()); root->left->clear_utensor(); // remove intermediate unitensor to save heap space root->right->clear_utensor(); // remove intermediate unitensor to save heap space root->is_assigned = true; - // cout << "contract!" << endl; } root = nullptr; } - - // cout.flush(); - // break; - } while (!stk.empty()); // 3. get result: UniTensor out = this->CtTree.nodes_container.back()->utensor; - // std::cout << out << std::endl; - // out.print_diagram(); // 4. reset nodes: this->CtTree.reset_nodes(); diff --git a/src/RegularNetwork.cpp b/src/RegularNetwork.cpp index 0d5a1d111..606386942 100644 --- a/src/RegularNetwork.cpp +++ b/src/RegularNetwork.cpp @@ -1,10 +1,11 @@ +#include "Network.hpp" + #include #include #include #include #include "Generator.hpp" -#include "Network.hpp" #include "search_tree.hpp" using namespace std; @@ -167,8 +168,6 @@ namespace cytnx { // // tri(tmp.c_str()); - // // cout << tmp.size() << endl; - // // cout << tmp.find_first_not_of("0123456789-") << endl; // cytnx_error_msg((tmp.find_first_not_of("0123456789-") != string::npos), // "[ERROR][Network][Fromfile] line:%d %s\n", line_num, // "Invalid TN line. label contain non integer."); @@ -269,9 +268,6 @@ namespace cytnx { root = nullptr; } } while (!stk.empty()); - // for (int i = 0; i < path.size(); i++) { - // std::cout << path[i].first << ", " << path[i].second << std::endl; - // } return path; } @@ -362,7 +358,6 @@ namespace cytnx { } this->name2pos[name] = names.size() - 1; // register - // cout << name << "|" << names.size() - 1 << endl; this->label_arr.push_back(vector()); cytnx_uint64 tmp_iBN; // this is an internal function that is defined in this cpp file. @@ -394,11 +389,12 @@ namespace cytnx { TN_names.erase(it); } if (TN_names.size() != 0) { - cout << "[ERROR] Following TNs appeared in ORDER line, but is not defined." << endl; + std::cout << "[ERROR] The following TNs appeared in ORDER line, but are not defined." + << std::endl; for (int i = 0; i < TN_names.size(); i++) { - cout << " " << TN_names[i] << endl; + std::cout << " " << TN_names[i] << std::endl; } - cytnx_error_msg(true, "%s", "\n"); + cytnx_error_msg(true, "[ERROR] TNs appeared in ORDER line, but are not defined.%s", "\n"); } } // check all RN. @@ -419,7 +415,7 @@ namespace cytnx { } bool err = false; if (expected_TOUT.size() != TOUT_labels.size()) { - cout << expected_TOUT.size() << endl; + std::cout << expected_TOUT.size() << std::endl; err = true; } vector itrsct = vec_intersect(expected_TOUT, this->TOUT_labels); @@ -428,15 +424,19 @@ namespace cytnx { } if (err) { - cout << "[ERROR][Network][Contract--planning] The TOUT contains labels that does not match " - "with the delcartion from TNs.\n"; - cout << " > The reduced labels [rank:" << expected_TOUT.size() << "] should be:"; - for (int i = 0; i < expected_TOUT.size(); i++) cout << expected_TOUT[i] << " "; - cout << endl; - cout << " > The TOUT [rank" << TOUT_labels.size() << "] specified is:"; - for (int i = 0; i < TOUT_labels.size(); i++) cout << TOUT_labels[i] << " "; - cout << endl; - cytnx_error_msg(true, "%s", "\n"); + std::cout + << "[ERROR][Network][Contract--planning] The TOUT contains labels that does not match " + "with the delcartion from TNs.\n"; + std::cout << " > The reduced labels [rank:" << expected_TOUT.size() << "] should be:"; + for (int i = 0; i < expected_TOUT.size(); i++) std::cout << expected_TOUT[i] << " "; + std::cout << std::endl; + std::cout << " > The TOUT [rank" << TOUT_labels.size() << "] specified is:"; + for (int i = 0; i < TOUT_labels.size(); i++) std::cout << TOUT_labels[i] << " "; + std::cout << std::endl; + cytnx_error_msg(true, + "[ERROR][Network][Contract--planning] The TOUT contains labels that does not " + "match with the delcartion from TNs%s", + "\n"); } // put tensor: @@ -516,7 +516,6 @@ namespace cytnx { i); this->name2pos[name] = names.size() - 1; // register - // cout << name << "|" << names.size() - 1 << endl; this->label_arr.push_back(vector()); cytnx_uint64 tmp_iBN; // this is an internal function that is defined in this cpp file. @@ -558,11 +557,12 @@ namespace cytnx { TN_names.erase(it); } if (TN_names.size() != 0) { - cout << "[ERROR] Following TNs appeared in ORDER line, but is not defined." << endl; + std::cout << "[ERROR] The following TNs appeared in ORDER line, but are not defined." + << std::endl; for (int i = 0; i < TN_names.size(); i++) { - cout << " " << TN_names[i] << endl; + std::cout << " " << TN_names[i] << std::endl; } - cytnx_error_msg(true, "%s", "\n"); + cytnx_error_msg(true, "[ERROR] TNs appeared in ORDER line, but are not defined.%s", "\n"); } } // check all RN. @@ -590,15 +590,18 @@ namespace cytnx { } if (err) { - cout << "[ERROR][Network][Fromfile] The TOUT contains labels that does not match with the " - "delcartion from TNs.\n"; - cout << " > The reduced labels [rank:" << expected_TOUT.size() << "] should be:"; - for (int i = 0; i < expected_TOUT.size(); i++) cout << expected_TOUT[i] << " "; - cout << endl; - cout << " > The TOUT [rank" << TOUT_labels.size() << "] specified is:"; - for (int i = 0; i < TOUT_labels.size(); i++) cout << TOUT_labels[i] << " "; - cout << endl; - cytnx_error_msg(true, "%s", "\n"); + std::cout << "[ERROR][Network][Fromfile] The TOUT contains labels that does not match with " + "the delcartion from TNs.\n"; + std::cout << " > The reduced labels [rank:" << expected_TOUT.size() << "] should be:"; + for (int i = 0; i < expected_TOUT.size(); i++) std::cout << expected_TOUT[i] << " "; + std::cout << std::endl; + std::cout << " > The TOUT [rank" << TOUT_labels.size() << "] specified is:"; + for (int i = 0; i < TOUT_labels.size(); i++) std::cout << TOUT_labels[i] << " "; + std::cout << std::endl; + cytnx_error_msg(true, + "[ERROR][Network][Fromfile] The TOUT contains labels that does not match " + "with the delcartion from TNs.%s", + "\n"); } // maintain TOUT leg position @@ -786,7 +789,7 @@ namespace cytnx { for (int i = 0; i < ORDER_tokens.size(); i++) { fo << ORDER_tokens[i]; } - fo << endl; + fo << std::endl; } fo.close(); @@ -806,11 +809,11 @@ namespace cytnx { this->PutUniTensor(idx, utensor); } - void RegularNetwork::PrintNet(ostream &os) { + void RegularNetwork::PrintNet(ostream &os) const { string status; - os << "==== Network ====" << endl; + os << "==== Network ====" << std::endl; if (this->tensors.size() == 0) { - os << " Empty " << endl; + os << " Empty " << std::endl; } else { for (cytnx_uint64 i = 0; i < this->tensors.size(); i++) { if (this->tensors[i].uten_type() != UTenType.Void) @@ -830,7 +833,7 @@ namespace cytnx { os << this->label_arr[i][j] << " "; // printf("%d ",this->label_arr[i][j]); } - os << endl; + os << std::endl; } os << "TOUT : "; @@ -844,13 +847,13 @@ namespace cytnx { os << this->TOUT_labels[j] << " "; // printf("%d ",this->TOUT_labels[j]); } - os << endl; + os << std::endl; os << "ORDER : "; for (cytnx_int64 i = 0; i < this->ORDER_tokens.size(); i++) { os << this->ORDER_tokens[i]; } - os << endl; - os << "=================" << endl; + os << std::endl; + os << "=================" << std::endl; } } @@ -976,7 +979,6 @@ namespace cytnx { } // 2. contract using postorder traversal: - // cout << this->CtTree.nodes_container.size() << endl; stack> stk; std::shared_ptr root = this->CtTree.nodes_container.back(); root->set_root_ptrs(); // Add this line @@ -1017,8 +1019,6 @@ namespace cytnx { // 3. get result: UniTensor out = this->CtTree.nodes_container.back()->utensor; - // cout << out << endl; - // out.print_diagram(); // 4. reset nodes: this->CtTree.reset_nodes(); @@ -1094,7 +1094,6 @@ namespace cytnx { CtTree.build_default_contraction_tree(); } // 2. contract using postorder traversal: - // cout << this->CtTree.nodes_container.size() << endl; stack> stk; std::shared_ptr root = this->CtTree.nodes_container.back(); root->set_root_ptrs(); // Add this line @@ -1181,11 +1180,12 @@ namespace cytnx { TN_names.erase(it); } if (TN_names.size() != 0) { - cout << "[ERROR] Following TNs appeared in ORDER line, but is not defined." << endl; + std::cout << "[ERROR] The following TNs appeared in ORDER line, but are not defined." + << std::endl; for (int i = 0; i < TN_names.size(); i++) { - cout << " " << TN_names[i] << endl; + std::cout << " " << TN_names[i] << std::endl; } - cytnx_error_msg(true, "%s", "\n"); + cytnx_error_msg(true, "[ERROR] TNs appeared in ORDER line, but are not defined.%s", "\n"); } } // check all RN. @@ -1219,7 +1219,6 @@ namespace cytnx { for (map::iterator it = labelcnt.begin(); it != labelcnt.end(); ++it) { if (it->second == 1) expected_TOUT.push_back(it->first); } - // cout<TOUT_labels.size(); if (this->TOUT_labels.size() == 0) { this->TOUT_labels = expected_TOUT; } else { @@ -1232,15 +1231,19 @@ namespace cytnx { err = true; } if (err) { - cout << "[ERROR][Network][Fromfile] The TOUT contains labels that does not match with the " - "delcartion from TNs.\n"; - cout << " > The reduced labels [rank:" << expected_TOUT.size() << "] should be:"; - for (int i = 0; i < expected_TOUT.size(); i++) cout << expected_TOUT[i] << " "; - cout << endl; - cout << " > The TOUT [rank" << TOUT_labels.size() << "] specified is:"; - for (int i = 0; i < TOUT_labels.size(); i++) cout << TOUT_labels[i] << " "; - cout << endl; - cytnx_error_msg(true, "%s", "\n"); + std::cout + << "[ERROR][Network][Fromfile] The TOUT contains labels that does not match with the " + "delcartion from TNs.\n"; + std::cout << " > The reduced labels [rank:" << expected_TOUT.size() << "] should be:"; + for (int i = 0; i < expected_TOUT.size(); i++) std::cout << expected_TOUT[i] << " "; + std::cout << std::endl; + std::cout << " > The TOUT [rank" << TOUT_labels.size() << "] specified is:"; + for (int i = 0; i < TOUT_labels.size(); i++) std::cout << TOUT_labels[i] << " "; + std::cout << std::endl; + cytnx_error_msg(true, + "[ERROR][Network][Fromfile] The TOUT contains labels that does not match " + "with the delcartion from TNs.%s", + "\n"); } } diff --git a/src/SparseUniTensor.cpp b/src/SparseUniTensor.cpp index de87a153e..e1ff237e9 100644 --- a/src/SparseUniTensor.cpp +++ b/src/SparseUniTensor.cpp @@ -1,13 +1,17 @@ #include "UniTensor.hpp" + +#include +#include +#include + #include "Accessor.hpp" +#include "Generator.hpp" +#include "UniTensor.hpp" +#include "linalg.hpp" #include "utils/utils.hpp" #include "utils/utils_internal_interface.hpp" -#include "linalg.hpp" -#include "Generator.hpp" -#include -#include "utils/vec_print.hpp" #include "utils/vec_concatenate.hpp" -#include +#include "utils/vec_print.hpp" using namespace std; namespace cytnx { @@ -96,12 +100,6 @@ namespace cytnx { vector degenerates; vector> uniq_bonds_row = tot_bonds[0].getUniqueQnums(); vector> uniq_bonds_col = tot_bonds[1].getUniqueQnums(); - // vec_print(std::cout,uniq_bonds_row);// << endl; - // vec_print(std::cout,uniq_bonds_col);// << endl; - // exit(1); - // vec_print(std::cout,tot_bonds[0].qnums()); - // vec_print(std::cout,tot_bonds[1].qnums()); - //[DDK] // get common qnum set of row-col (bra-ket) space. this->_blockqnums = vec2d_intersect(uniq_bonds_row, uniq_bonds_col, false, false); @@ -110,8 +108,6 @@ namespace cytnx { this->_blockqnums.size() == 0, "[ERROR][SparseUniTensor] invalid qnums. no common block (qnum) in this setup.%s", "\n"); - // vec_print(std::cout,this->_blockqnums); - // calculate&init the No. of blocks and their sizes. this->_blocks.resize(this->_blockqnums.size()); cytnx_uint64 rowdim, coldim; @@ -233,7 +229,7 @@ namespace cytnx { for (cytnx_uint32 i = 0; i < mapper_u64.size(); i++) { if (mapper_u64[i] >= mapper_u64.size()) { - cytnx_error_msg(1, "%s", "invalid rank index.\n"); + cytnx_error_msg(true, "%s", "invalid rank index.\n"); } // std::cout << this->_mapper[rnks[i]] << " " << i << std::endl; new_idxmap[out_raw->_mapper[mapper_u64[i]]] = i; @@ -300,7 +296,7 @@ namespace cytnx { for (cytnx_uint32 i = 0; i < mapper_u64.size(); i++) { if (mapper_u64[i] >= mapper_u64.size()) { - cytnx_error_msg(1, "%s", "invalid rank index.\n"); + cytnx_error_msg(true, "%s", "invalid rank index.\n"); } // std::cout << this->_mapper[rnks[i]] << " " << i << std::endl; new_idxmap[out_raw->_mapper[mapper_u64[i]]] = i; @@ -361,7 +357,7 @@ namespace cytnx { for (cytnx_uint32 i = 0; i < mapper_u64.size(); i++) { if (mapper_u64[i] >= mapper_u64.size()) { - cytnx_error_msg(1, "%s", "invalid rank index.\n"); + cytnx_error_msg(true, "%s", "invalid rank index.\n"); } // std::cout << this->_mapper[rnks[i]] << " " << i << std::endl; new_idxmap[out_raw->_mapper[mapper_u64[i]]] = i; @@ -427,7 +423,7 @@ namespace cytnx { for (cytnx_uint32 i = 0; i < mapper_u64.size(); i++) { if (mapper_u64[i] >= mapper_u64.size()) { - cytnx_error_msg(1, "%s", "invalid rank index.\n"); + cytnx_error_msg(true, "%s", "invalid rank index.\n"); } // std::cout << this->_mapper[rnks[i]] << " " << i << std::endl; new_idxmap[this->_mapper[mapper_u64[i]]] = i; @@ -485,7 +481,7 @@ namespace cytnx { for (cytnx_uint32 i = 0; i < mapper_u64.size(); i++) { if (mapper_u64[i] >= mapper_u64.size()) { - cytnx_error_msg(1, "%s", "invalid rank index.\n"); + cytnx_error_msg(true, "%s", "invalid rank index.\n"); } // std::cout << this->_mapper[rnks[i]] << " " << i << std::endl; new_idxmap[this->_mapper[mapper_u64[i]]] = i; @@ -538,7 +534,7 @@ namespace cytnx { for (cytnx_uint32 i = 0; i < mapper_u64.size(); i++) { if (mapper_u64[i] >= mapper_u64.size()) { - cytnx_error_msg(1, "%s", "invalid rank index.\n"); + cytnx_error_msg(true, "%s", "invalid rank index.\n"); } // std::cout << this->_mapper[rnks[i]] << " " << i << std::endl; new_idxmap[this->_mapper[mapper_u64[i]]] = i; @@ -652,12 +648,12 @@ namespace cytnx { std::vector SparseUniTensor::syms() const { return this->_bonds[0].syms(); } - void SparseUniTensor::print_block(const cytnx_int64 &idx, const bool &full_info) const { + void SparseUniTensor::print_block(std::ostream &os, const cytnx_int64 &idx, + const bool &full_info) const { cytnx_error_msg(true, "[ERROR] SpareUniTensor does not support individual printing.%s", "\n"); } - void SparseUniTensor::print_blocks(const bool &full_info) const { - std::ostream &os = std::cout; + void SparseUniTensor::print_blocks(std::ostream &os, const bool &full_info) const { os << "-------- start of print ---------\n"; char *buffer = (char *)malloc(sizeof(char) * 1024); sprintf(buffer, "Tensor name: %s\n", this->_name.c_str()); @@ -700,26 +696,26 @@ namespace cytnx { free(buffer); } - void SparseUniTensor::print_diagram(const bool &bond_info) const { + void SparseUniTensor::print_diagram(std::ostream &os, const bool &bond_info) const { char *buffer = (char *)malloc(1024 * sizeof(char)); unsigned int BUFFsize = 100; sprintf(buffer, "-----------------------%s", "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "tensor Name : %s\n", this->_name.c_str()); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "tensor Rank : %d\n", this->_labels.size()); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "block_form : true%s", "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "contiguous : %s\n", this->is_contiguous() ? "True" : "False"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "valid bocks : %d\n", this->_blocks.size()); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "is diag : %s\n", this->is_diag() ? "True" : "False"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "on device : %s\n", this->device_str().c_str()); - std::cout << std::string(buffer); + os << std::string(buffer); cytnx_uint64 Nin = this->_rowrank; cytnx_uint64 Nout = this->_labels.size() - this->_rowrank; cytnx_uint64 vl; @@ -753,16 +749,16 @@ namespace cytnx { string M_dashes = string("-") * (1 + Space_Ldim_max + 5 + Space_Rdim_max + 1); sprintf(buffer, "braket_form : %s\n", this->_is_braket_form ? "True" : "False"); - std::cout << std::string(buffer); + os << std::string(buffer); std::string tmpss; sprintf(buffer, "%s row %s col %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s -%s- %s", LallSpace.c_str(), M_dashes.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); for (cytnx_uint64 i = 0; i < vl; i++) { sprintf(buffer, "%s |%s| %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); if (i < Nin) { if (this->_bonds[i].type() == bondType::BD_KET) @@ -806,21 +802,21 @@ namespace cytnx { sprintf(rlbl, "%s", tmpss.c_str()); } sprintf(buffer, " %s| %s %s |%s\n", l, llbl, rlbl, r); - std::cout << std::string(buffer); + os << std::string(buffer); } sprintf(buffer, "%s |%s| %s", LallSpace.c_str(), MallSpace.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s -%s- %s", LallSpace.c_str(), M_dashes.c_str(), "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); sprintf(buffer, "%s", "\n"); - std::cout << std::string(buffer); + os << std::string(buffer); if (bond_info) { for (cytnx_uint64 i = 0; i < this->_bonds.size(); i++) { // sprintf(buffer, "lbl:%d ", this->_labels[i]); sprintf(buffer, "lbl:%s ", this->_labels[i].c_str()); - std::cout << std::string(buffer); - std::cout << this->_bonds[i] << std::endl; + os << std::string(buffer); + os << this->_bonds[i] << std::endl; } } diff --git a/src/Symmetry.cpp b/src/Symmetry.cpp index 3b65ff162..4156bfa84 100644 --- a/src/Symmetry.cpp +++ b/src/Symmetry.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -36,36 +36,36 @@ namespace cytnx { } bool cytnx::Symmetry_base::check_qnum(const cytnx_int64 &qnum) { - cytnx_error_msg(1, "%s", "[ERROR][Internal] should not call Symmerty base!"); + cytnx_error_msg(true, "%s", "[ERROR][Internal] should not call Symmerty base!"); return false; } bool cytnx::Symmetry_base::check_qnums(const std::vector &qnums) { - cytnx_error_msg(1, "%s", "[ERROR][Internal] should not call Symmerty base!"); + cytnx_error_msg(true, "%s", "[ERROR][Internal] should not call Symmerty base!"); return false; } void cytnx::Symmetry_base::combine_rule_(std::vector &out, const std::vector &inL, const std::vector &inR) { - cytnx_error_msg(1, "%s", "[ERROR][Internal] should not call Symmerty base!"); + cytnx_error_msg(true, "%s", "[ERROR][Internal] should not call Symmerty base!"); } void cytnx::Symmetry_base::combine_rule_(cytnx_int64 &out, const cytnx_int64 &inL, const cytnx_int64 &inR, const bool &is_reverse) { - cytnx_error_msg(1, "%s", "[ERROR][Internal] should not call Symmerty base!"); + cytnx_error_msg(true, "%s", "[ERROR][Internal] should not call Symmerty base!"); } void cytnx::Symmetry_base::reverse_rule_(cytnx_int64 &out, const cytnx_int64 &in) { - cytnx_error_msg(1, "%s", "[ERROR][Internal] should not call Symmerty base!"); + cytnx_error_msg(true, "%s", "[ERROR][Internal] should not call Symmerty base!"); } fermionParity cytnx::Symmetry_base::get_fermion_parity(const cytnx_int64 &in_qnum) const { return EVEN; } - void cytnx::Symmetry_base::print_info() const { - cytnx_error_msg(1, "%s", "[ERROR][Internal] should not call Symmerty base!"); + void cytnx::Symmetry_base::print_info(std::ostream &os) const { + cytnx_error_msg(true, "%s", "[ERROR][Internal] should not call Symmerty base!"); } std::string cytnx::Symmetry_base::stype_str() const { - cytnx_error_msg(1, "%s", "[ERROR][Internal] should not call Symmerty base!"); + cytnx_error_msg(true, "%s", "[ERROR][Internal] should not call Symmerty base!"); } ///========================= @@ -89,13 +89,13 @@ namespace cytnx { } void cytnx::U1Symmetry::reverse_rule_(cytnx_int64 &out, const cytnx_int64 &in) { out = in * -1; } - void cytnx::U1Symmetry::print_info() const { - cout << "--------------------\n"; - cout << "[Symmetry]" << endl; - cout << "type : Abelian, U1" << endl; - cout << "combine rule : Q1 + Q2" << endl; - cout << "reverse rule : Q*(-1) " << endl; - cout << "--------------------\n"; + void cytnx::U1Symmetry::print_info(std::ostream &os) const { + os << "--------------------\n"; + os << "[Symmetry]" << std::endl; + os << "type : Abelian, U1" << std::endl; + os << "combine rule : Q1 + Q2" << std::endl; + os << "reverse rule : Q*(-1) " << std::endl; + os << "--------------------\n"; } ///======================== @@ -132,13 +132,13 @@ namespace cytnx { out = -in + this->n; } - void cytnx::ZnSymmetry::print_info() const { - cout << "--------------------\n"; - cout << "[Symmetry]" << endl; - cout << "type : Abelian, Z(" << this->n << ")" << endl; - cout << "combine rule : (Q1 + Q2)\%" << this->n << endl; - cout << "reverse rule : Q*(-1) " << endl; - cout << "--------------------\n"; + void cytnx::ZnSymmetry::print_info(std::ostream &os) const { + os << "--------------------\n"; + os << "[Symmetry]" << std::endl; + os << "type : Abelian, Z(" << this->n << ")" << std::endl; + os << "combine rule : (Q1 + Q2)\%" << this->n << std::endl; + os << "reverse rule : Q*(-1) " << std::endl; + os << "--------------------\n"; } ///======================== @@ -186,13 +186,13 @@ namespace cytnx { "\n"); } - void cytnx::FermionParitySymmetry::print_info() const { - cout << "--------------------\n"; - cout << "[Symmetry]" << endl; - cout << "type : fermionic, FermionParity" << endl; - cout << "combine rule : (Q1 + Q2)\2" << endl; - cout << "reverse rule : Q*(-1) " << endl; - cout << "--------------------\n"; + void cytnx::FermionParitySymmetry::print_info(std::ostream &os) const { + os << "--------------------\n"; + os << "[Symmetry]" << std::endl; + os << "type : fermionic, FermionParity" << std::endl; + os << "combine rule : (Q1 + Q2)\2" << std::endl; + os << "reverse rule : Q*(-1) " << std::endl; + os << "--------------------\n"; } ///========================= @@ -228,13 +228,13 @@ namespace cytnx { return ODD; } - void cytnx::FermionNumberSymmetry::print_info() const { - cout << "--------------------\n"; - cout << "[Symmetry]" << endl; - cout << "type : fermionic, FermionNumber" << endl; - cout << "combine rule : Q1 + Q2" << endl; - cout << "reverse rule : Q*(-1) " << endl; - cout << "--------------------\n"; + void cytnx::FermionNumberSymmetry::print_info(std::ostream &os) const { + os << "--------------------\n"; + os << "[Symmetry]" << std::endl; + os << "type : fermionic, FermionNumber" << std::endl; + os << "combine rule : Q1 + Q2" << std::endl; + os << "reverse rule : Q*(-1) " << std::endl; + os << "--------------------\n"; } //================================================== @@ -295,8 +295,8 @@ namespace cytnx { this->Init(stype_in, n_in); } - ostream &operator<<(ostream &os, const Symmetry &in) { - in.print_info(); + std::ostream &operator<<(std::ostream &os, const Symmetry &in) { + in.print_info(os); return os; } }; // namespace cytnx diff --git a/src/Tensor.cpp b/src/Tensor.cpp index 35dd12da8..d9fda4150 100644 --- a/src/Tensor.cpp +++ b/src/Tensor.cpp @@ -1,6 +1,7 @@ #include "Tensor.hpp" #include +#include #include #include "linalg.hpp" @@ -817,7 +818,6 @@ namespace cytnx { } template <> Tensor &Tensor::operator/=(const cytnx_int32 &rc) { - // std::cout << "entry /= int32" << std::endl; this->_impl->storage() = cytnx::linalg::Div(*this, rc)._impl->storage(); return *this; } diff --git a/src/UniTensor.cpp b/src/UniTensor.cpp index 836e8e124..f37071e6f 100644 --- a/src/UniTensor.cpp +++ b/src/UniTensor.cpp @@ -27,10 +27,7 @@ namespace cytnx { } UniTensor UniTensor::Add(const UniTensor &rhs) const { return cytnx::linalg::Add(*this, rhs); } - UniTensor UniTensor::Add(const Scalar &rhs) const { - // cout << "lyer1: " << rhs << endl; - return cytnx::linalg::Add(*this, rhs); - } + UniTensor UniTensor::Add(const Scalar &rhs) const { return cytnx::linalg::Add(*this, rhs); } UniTensor UniTensor::Sub(const UniTensor &rhs) const { return cytnx::linalg::Sub(*this, rhs); } UniTensor UniTensor::Sub(const Scalar &rhs) const { return cytnx::linalg::Sub(*this, rhs); } diff --git a/src/UniTensor_base.cpp b/src/UniTensor_base.cpp index 1cb1e9beb..2a44d4706 100644 --- a/src/UniTensor_base.cpp +++ b/src/UniTensor_base.cpp @@ -1,8 +1,11 @@ #include "UniTensor.hpp" + +#include +#include + +#include "Network.hpp" #include "Tensor.hpp" #include "linalg.hpp" -#include "Network.hpp" -#include #ifdef BACKEND_TORCH #else @@ -236,15 +239,16 @@ namespace cytnx { return out; } - void UniTensor_base::print_diagram(const bool &bond_info) const { + void UniTensor_base::print_diagram(std::ostream &os, const bool &bond_info) const { cytnx_error_msg( true, "[ERROR] fatal internal, cannot call on an un-initialized UniTensor_base%s", "\n"); } - void UniTensor_base::print_blocks(const bool &full_info) const { + void UniTensor_base::print_blocks(std::ostream &os, const bool &full_info) const { cytnx_error_msg( true, "[ERROR] fatal internal, cannot call on an un-initialized UniTensor_base%s", "\n"); } - void UniTensor_base::print_block(const cytnx_int64 &idx, const bool &full_info) const { + void UniTensor_base::print_block(std::ostream &os, const cytnx_int64 &idx, + const bool &full_info) const { cytnx_error_msg( true, "[ERROR] fatal internal, cannot call on an un-initialized UniTensor_base%s", "\n"); } @@ -713,7 +717,7 @@ namespace cytnx { //----------------------------------------- std::ostream &operator<<(std::ostream &os, const UniTensor &in) { - in.print_blocks(); + in.print_blocks(os); return os; } diff --git a/src/backend/Scalar.cpp b/src/backend/Scalar.cpp index ec060b863..d9f180eaa 100644 --- a/src/backend/Scalar.cpp +++ b/src/backend/Scalar.cpp @@ -1,4 +1,7 @@ #include "backend/Scalar.hpp" + +#include + #include "backend/Storage.hpp" namespace cytnx { @@ -53,22 +56,15 @@ namespace cytnx { // Scalar proxy: // Sproxy Scalar::Sproxy& Scalar::Sproxy::operator=(const Scalar::Sproxy& rc) { - // std::cout << "entry !!" << std::endl; if (this->_insimpl.get() == 0) { - // std::cout << "entry cpcon, not init!!" << std::endl; - // std::cout << std::flush; // not init: this->_insimpl = rc._insimpl; this->_loc = rc._loc; return *this; } else { if ((rc._insimpl == this->_insimpl) && (rc._loc == this->_loc)) { - // std::cout << "entry same!!" << std::endl; - std::cout << std::flush; return *this; } else { - // std::cout << "entry wrn !!" << std::endl; - std::cout << std::flush; Scalar tmp = rc._insimpl->get_item(rc._loc); this->_insimpl->set_item(this->_loc, tmp); return *this; diff --git a/src/backend/Storage.cpp b/src/backend/Storage.cpp index c14f35928..c7305dadc 100644 --- a/src/backend/Storage.cpp +++ b/src/backend/Storage.cpp @@ -1,7 +1,7 @@ #include "backend/Storage.hpp" #include -#include +#include using namespace std; @@ -10,7 +10,7 @@ namespace cytnx { Storage_init_interface __SII; std::ostream &operator<<(std::ostream &os, const Storage &in) { - in.print(); + in.print(os); return os; } @@ -199,7 +199,6 @@ namespace cytnx { // check size: ifstream jf; - // std::cout << fname << std::endl; jf.open(fname, ios::ate | ios::binary); if (!jf.is_open()) { cytnx_error_msg(true, "[ERROR] Cannot open file '%s'.\n", fname.c_str()); diff --git a/src/backend/StorageImplementation.cpp b/src/backend/StorageImplementation.cpp index b41b4a3c2..899cb5588 100644 --- a/src/backend/StorageImplementation.cpp +++ b/src/backend/StorageImplementation.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -89,7 +89,7 @@ namespace cytnx { this->start_ = utils_internal::cuCalloc_gpu(this->capacity_, sizeof(DType)); #else - cytnx_error_msg(1, "%s", "[ERROR] Cannot init a Storage on gpu without CUDA support."); + cytnx_error_msg(true, "%s", "[ERROR] Cannot init a Storage on gpu without CUDA support."); #endif } this->device_ = device; @@ -140,7 +140,7 @@ namespace cytnx { checkCudaErrors(cudaMemcpy(out->data(), this->start_, sizeof(DType) * this->size_, cudaMemcpyDeviceToDevice)); #else - cytnx_error_msg(1, "%s", "[ERROR] Cannot clone a Storage on gpu without CUDA support."); + cytnx_error_msg(true, "%s", "[ERROR] Cannot clone a Storage on gpu without CUDA support."); #endif } return out; @@ -158,7 +158,7 @@ namespace cytnx { checkCudaErrors(cudaSetDevice(this->device_)); utils_internal::MoveMemoryGpu(tmp, old_shape, mapper, invmapper, 1); #else - cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support"); + cytnx_error_msg(true, "%s", "[ERROR][Internal] try to call GPU section without CUDA support"); #endif } } @@ -175,7 +175,7 @@ namespace cytnx { checkCudaErrors(cudaSetDevice(this->device_)); return utils_internal::MoveMemoryGpu(tmp, old_shape, mapper, invmapper, 0); #else - cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support"); + cytnx_error_msg(true, "%s", "[ERROR][Internal] try to call GPU section without CUDA support"); return nullptr; #endif } @@ -196,7 +196,8 @@ namespace cytnx { this->start_ = dtmp; this->device_ = device; #else - cytnx_error_msg(1, "%s", "[ERROR] try to move from cpu(Host) to gpu without CUDA support."); + cytnx_error_msg(true, "%s", + "[ERROR] try to move from cpu(Host) to gpu without CUDA support."); #endif } else { #ifdef UNI_GPU @@ -222,8 +223,8 @@ namespace cytnx { } #else cytnx_error_msg( - 1, "%s", - "[ERROR][Internal] Storage.to_. the Storage is as GPU but without CUDA support."); + true, "[ERROR][Internal][Storage.to_] The Storage is on GPU but without CUDA support.%s", + "n"); #endif } } @@ -247,7 +248,8 @@ namespace cytnx { out->_Init_byptr(dtmp, this->size_, device, true, this->capacity_); return out; #else - cytnx_error_msg(1, "%s", "[ERROR] try to move from cpu(Host) to gpu without CUDA support."); + cytnx_error_msg(true, "%s", + "[ERROR] try to move from cpu(Host) to gpu without CUDA support."); return nullptr; #endif } else { @@ -274,8 +276,8 @@ namespace cytnx { } #else cytnx_error_msg( - 1, "%s", - "[ERROR][Internal] Storage.to_. the Storage is as GPU but without CUDA support."); + true, "[ERROR][Internal][Storage.to_] The Storage is on GPU but without CUDA support.%s", + "n"); return nullptr; #endif } @@ -293,7 +295,7 @@ namespace cytnx { Ne *= shape[i]; } if (Ne != this->size_) { - cytnx_error_msg(1, "%s", + cytnx_error_msg(true, "%s", "PrintElem_byShape, the number of shape not match with the No. of elements."); } @@ -373,7 +375,7 @@ namespace cytnx { } else { /// This is for non-contiguous Tensor printing; - // cytnx_error_msg(1,"%s","print for a non-contiguous Storage is under developing"); + // cytnx_error_msg(true,"%s","print for a non-contiguous Storage is under developing"); // cytnx_uint64 cnt=0; std::vector c_offj(shape.size()); std::vector c_shape(shape.size()); @@ -445,13 +447,13 @@ namespace cytnx { } template - void StorageImplementation::print_elems() { + void StorageImplementation::print_elems(std::ostream &os) const { DType *elem_ptr_ = reinterpret_cast(this->start_); - cout << "[ "; + os << "[ "; for (unsigned long long cnt = 0; cnt < this->size_; cnt++) { - PrintValueAndSpace(std::cout, elem_ptr_[cnt]); + PrintValueAndSpace(os, elem_ptr_[cnt]); } - std::cout << "]" << std::endl; + os << "]" << std::endl; } template @@ -508,8 +510,8 @@ namespace cytnx { checkCudaErrors(cudaSetDevice(this->device_)); utils_internal::cuSetZeros(this->start_, sizeof(DType) * this->size_); #else - cytnx_error_msg(1, "[ERROR][set_zeros] fatal, the storage is on gpu without CUDA support.%s", - "\n"); + cytnx_error_msg( + true, "[ERROR][set_zeros] fatal, the storage is on gpu without CUDA support.%s", "\n"); #endif } } @@ -540,8 +542,8 @@ namespace cytnx { this->start_ = dtmp; #else cytnx_error_msg( - 1, "%s", - "[ERROR][Internal] Storage.resize. the Storage is as GPU but without CUDA support."); + true, "[ERROR][Internal][Storage.to_] The Storage is on GPU but without CUDA support.%s", + "n"); #endif } } @@ -630,8 +632,8 @@ namespace cytnx { return out; #else cytnx_error_msg( - 1, "%s", - "[ERROR][Internal] Storage.to_. the Storage is as GPU but without CUDA support."); + true, "[ERROR][Internal][Storage.to_] The Storage is on GPU but without CUDA support.%s", + "n"); return nullptr; #endif } @@ -671,8 +673,8 @@ namespace cytnx { return out; #else cytnx_error_msg( - 1, "%s", - "[ERROR][Internal] Storage.to_. the Storage is as GPU but without CUDA support."); + true, "[ERROR][Internal][Storage.to_] The Storage is on GPU but without CUDA support.%s", + "n"); return nullptr; #endif } @@ -816,7 +818,6 @@ namespace cytnx { template StorageImplementation::~StorageImplementation() { - // std::cout << "delet" << endl; if (this->data() != NULL) { if (this->device() == Device.cpu) { free(this->data()); @@ -824,7 +825,7 @@ namespace cytnx { #ifdef UNI_GPU checkCudaErrors(cudaFree(this->data())); #else - cytnx_error_msg(1, "%s", "[ERROR] trying to free an GPU memory without CUDA install"); + cytnx_error_msg(true, "%s", "[ERROR] trying to free an GPU memory without CUDA install"); #endif } } diff --git a/src/backend/Storage_base.cpp b/src/backend/Storage_base.cpp index be44112af..a6c8fb5b8 100644 --- a/src/backend/Storage_base.cpp +++ b/src/backend/Storage_base.cpp @@ -1,4 +1,7 @@ #include "backend/Storage.hpp" + +#include + #include "utils_internal_interface.hpp" #include "utils/vec_print.hpp" @@ -70,9 +73,7 @@ namespace cytnx { //========================== void Storage_base::Init(const unsigned long long &len_in, const int &device, - const bool &init_zero) { - // cout << "Base.init" << endl; - } + const bool &init_zero) {} Storage_base::Storage_base(const unsigned long long &len_in, const int &device, const bool &init_zero) { @@ -80,14 +81,16 @@ namespace cytnx { } Storage_base &Storage_base::operator=(Storage_base &Rhs) { - cout << "dev" << endl; + cytnx_error_msg(true, "[ERROR] Not implemented.%s", "\n"); return *this; } - Storage_base::Storage_base(Storage_base &Rhs) { cout << "dev" << endl; } + Storage_base::Storage_base(Storage_base &Rhs) { + cytnx_error_msg(true, "[ERROR] Not implemented.%s", "\n"); + } void Storage_base::resize(const cytnx_uint64 &newsize) { - cytnx_error_msg(1, "[ERROR][internal] resize should not be called by base%s", "\n"); + cytnx_error_msg(true, "[ERROR][internal] resize should not be called by base%s", "\n"); } boost::intrusive_ptr Storage_base::astype(const unsigned int &dtype) { @@ -96,22 +99,21 @@ namespace cytnx { if (this->device() == Device.cpu) { if (utils_internal::uii.ElemCast[this->dtype()][dtype] == NULL) { - cytnx_error_msg(1, "[ERROR] not support type with dtype=%d", dtype); + cytnx_error_msg(true, "[ERROR] not support type with dtype=%d", dtype); } else { utils_internal::uii.ElemCast[this->dtype()][dtype](this, out, this->size(), 1); } } else { #ifdef UNI_GPU if (utils_internal::uii.cuElemCast[this->dtype()][dtype] == NULL) { - cytnx_error_msg(1, "[ERROR] not support type with dtype=%d", dtype); + cytnx_error_msg(true, "[ERROR] not support type with dtype=%d", dtype); } else { - // std::cout << this->device() << std::endl; utils_internal::uii.cuElemCast[this->dtype()][dtype](this, out, this->size(), this->device()); } #else cytnx_error_msg( - 1, "%s", + true, "%s", "[ERROR][Internal Error] enter GPU section without CUDA support @ Storage.astype()"); #endif } @@ -119,7 +121,7 @@ namespace cytnx { } boost::intrusive_ptr Storage_base::_create_new_sametype() { - cytnx_error_msg(1, "%s", "[ERROR] call _create_new_sametype in base"); + cytnx_error_msg(true, "%s", "[ERROR] call _create_new_sametype in base"); return nullptr; } @@ -132,7 +134,7 @@ namespace cytnx { string Storage_base::device_str() const { return Device.getname(this->device()); } void Storage_base::_Init_byptr(void *rawptr, const unsigned long long &len_in, const int &device, const bool &iscap, const unsigned long long &cap_in) { - cytnx_error_msg(1, "%s", "[ERROR] call _Init_byptr in base"); + cytnx_error_msg(true, "%s", "[ERROR] call _Init_byptr in base"); } Storage_base::~Storage_base() {} @@ -140,41 +142,41 @@ namespace cytnx { void Storage_base::Move_memory_(const std::vector &old_shape, const std::vector &mapper, const std::vector &invmapper) { - cytnx_error_msg(1, "%s", "[ERROR] call Move_memory_ directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call Move_memory_ directly on Void Storage."); } boost::intrusive_ptr Storage_base::Move_memory( const std::vector &old_shape, const std::vector &mapper, const std::vector &invmapper) { - cytnx_error_msg(1, "%s", "[ERROR] call Move_memory_ directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call Move_memory_ directly on Void Storage."); return nullptr; } void Storage_base::to_(const int &device) { - cytnx_error_msg(1, "%s", "[ERROR] call to_ directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call to_ directly on Void Storage."); } boost::intrusive_ptr Storage_base::to(const int &device) { - cytnx_error_msg(1, "%s", "[ERROR] call to directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call to directly on Void Storage."); return nullptr; } void Storage_base::PrintElem_byShape(std::ostream &os, const std::vector &shape, const std::vector &mapper) { - cytnx_error_msg(1, "%s", "[ERROR] call PrintElem_byShape directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call PrintElem_byShape directly on Void Storage."); } - void Storage_base::print_info() { - cout << "dtype : " << this->dtype_str() << endl; - cout << "device: " << Device.getname(this->device()) << endl; - cout << "size : " << this->size() << endl; + void Storage_base::print_info(std::ostream &os) const { + os << "dtype : " << this->dtype_str() << std::endl; + os << "device: " << Device.getname(this->device()) << std::endl; + os << "size : " << this->size() << std::endl; } - void Storage_base::print_elems() { - cytnx_error_msg(1, "%s", "[ERROR] call print_elems directly on Void Storage."); + void Storage_base::print_elems(std::ostream &os) const { + cytnx_error_msg(true, "%s", "[ERROR] call print_elems directly on Void Storage."); } - void Storage_base::print() { - this->print_info(); - this->print_elems(); + void Storage_base::print(std::ostream &os) const { + this->print_info(os); + this->print_elems(os); } // shadow new: @@ -217,9 +219,6 @@ namespace cytnx { else new_accu *= shape[i]; } - // std::cout << c_offj << std::endl; - // std::cout << new_offj << std::endl; - // std::cout << TotalElem << std::endl; if (this->device() == Device.cpu) { utils_internal::uii.GetElems_conti_ii[this->dtype()](out->data(), this->data(), c_offj, new_offj, locators, TotalElem, Nunit); @@ -252,8 +251,6 @@ namespace cytnx { } cytnx_error_msg(this->device() != out->device(), "[ERROR] Cannot GetElem_byShape between different device.%s", "\n"); - - // std::cout <<"=====" << len.size() << " " << locators.size() << std::endl; // create new instance: cytnx_uint64 TotalElem = 1; for (cytnx_uint32 i = 0; i < len.size(); i++) TotalElem *= len[i]; @@ -309,7 +306,6 @@ namespace cytnx { cytnx_error_msg(this->device() != in->device(), "[ERROR] Cannot SetElem_byShape between different device.%s", "\n"); - // std::cout <<"=====" << len.size() << " " << locators.size() << std::endl; // create new instance: cytnx_uint64 TotalElem = 1; for (cytnx_uint32 i = 0; i < len.size(); i++) TotalElem *= len[i]; @@ -367,12 +363,8 @@ namespace cytnx { const std::vector> &locators, const cytnx_uint64 &Nunit, const bool &is_scalar) { // plan: we assume in is contiguous for now! - // - cytnx_error_msg(this->device() != in->device(), "[ERROR] Cannot SetElem_byShape_v2 between different device.%s", "\n"); - - // std::cout <<"=====" << len.size() << " " << locators.size() << std::endl; // create new instance: cytnx_uint64 TotalElem = 1; for (cytnx_uint32 i = 0; i < locators.size(); i++) { @@ -428,77 +420,77 @@ namespace cytnx { // generators: void Storage_base::fill(const cytnx_complex128 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call fill directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call fill directly on Void Storage."); } void Storage_base::fill(const cytnx_complex64 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call fill directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call fill directly on Void Storage."); } void Storage_base::fill(const cytnx_double &val) { - cytnx_error_msg(1, "%s", "[ERROR] call fill directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call fill directly on Void Storage."); } void Storage_base::fill(const cytnx_float &val) { - cytnx_error_msg(1, "%s", "[ERROR] call fill directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call fill directly on Void Storage."); } void Storage_base::fill(const cytnx_int64 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call fill directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call fill directly on Void Storage."); } void Storage_base::fill(const cytnx_uint64 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call fill directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call fill directly on Void Storage."); } void Storage_base::fill(const cytnx_int32 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call fill directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call fill directly on Void Storage."); } void Storage_base::fill(const cytnx_uint32 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call fill directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call fill directly on Void Storage."); } void Storage_base::fill(const cytnx_int16 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call fill directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call fill directly on Void Storage."); } void Storage_base::fill(const cytnx_uint16 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call fill directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call fill directly on Void Storage."); } void Storage_base::fill(const cytnx_bool &val) { - cytnx_error_msg(1, "%s", "[ERROR] call fill directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call fill directly on Void Storage."); } void Storage_base::set_zeros() { - cytnx_error_msg(1, "%s", "[ERROR] call set_zeros directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call set_zeros directly on Void Storage."); } void Storage_base::append(const Scalar &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } void Storage_base::append(const cytnx_complex128 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } void Storage_base::append(const cytnx_complex64 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } void Storage_base::append(const cytnx_double &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } void Storage_base::append(const cytnx_float &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } void Storage_base::append(const cytnx_int64 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } void Storage_base::append(const cytnx_uint64 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } void Storage_base::append(const cytnx_int32 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } void Storage_base::append(const cytnx_uint32 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } void Storage_base::append(const cytnx_int16 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } void Storage_base::append(const cytnx_uint16 &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } void Storage_base::append(const cytnx_bool &val) { - cytnx_error_msg(1, "%s", "[ERROR] call append directly on Void Storage."); + cytnx_error_msg(true, "%s", "[ERROR] call append directly on Void Storage."); } // instantiation: @@ -664,7 +656,7 @@ namespace cytnx { Type.getname(this->dtype()).c_str()); } if (idx >= this->size()) - cytnx_error_msg(1, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); + cytnx_error_msg(true, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); #ifdef UNI_GPU cudaDeviceSynchronize(); @@ -680,7 +672,7 @@ namespace cytnx { Type.getname(this->dtype()).c_str()); } if (idx >= this->size()) - cytnx_error_msg(1, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); + cytnx_error_msg(true, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); #ifdef UNI_GPU cudaDeviceSynchronize(); @@ -696,7 +688,7 @@ namespace cytnx { "[ERROR] type mismatch. try to get < complex > type from raw data of type %s", Type.getname(this->dtype()).c_str()); if (idx >= this->size()) - cytnx_error_msg(1, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); + cytnx_error_msg(true, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); #ifdef UNI_GPU cudaDeviceSynchronize(); @@ -712,7 +704,7 @@ namespace cytnx { "[ERROR] type mismatch. try to get < complex > type from raw data of type %s", Type.getname(this->dtype()).c_str()); if (idx >= this->size()) - cytnx_error_msg(1, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); + cytnx_error_msg(true, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); #ifdef UNI_GPU cudaDeviceSynchronize(); @@ -727,7 +719,7 @@ namespace cytnx { "[ERROR] type mismatch. try to get type from raw data of type %s", Type.getname(this->dtype()).c_str()); if (idx >= this->size()) - cytnx_error_msg(1, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); + cytnx_error_msg(true, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); #ifdef UNI_GPU cudaDeviceSynchronize(); @@ -742,7 +734,7 @@ namespace cytnx { "[ERROR] type mismatch. try to get type from raw data of type %s", Type.getname(this->dtype()).c_str()); if (idx >= this->size()) - cytnx_error_msg(1, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); + cytnx_error_msg(true, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); #ifdef UNI_GPU cudaDeviceSynchronize(); @@ -757,7 +749,7 @@ namespace cytnx { "[ERROR] type mismatch. try to get type from raw data of type %s", Type.getname(this->dtype()).c_str()); if (idx >= this->size()) - cytnx_error_msg(1, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); + cytnx_error_msg(true, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); #ifdef UNI_GPU cudaDeviceSynchronize(); @@ -772,7 +764,7 @@ namespace cytnx { "[ERROR] type mismatch. try to get type from raw data of type %s", Type.getname(this->dtype()).c_str()); if (idx >= this->size()) - cytnx_error_msg(1, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); + cytnx_error_msg(true, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); #ifdef UNI_GPU cudaDeviceSynchronize(); @@ -788,7 +780,7 @@ namespace cytnx { Type.getname(this->dtype()).c_str()); if (idx >= this->size()) - cytnx_error_msg(1, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); + cytnx_error_msg(true, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); #ifdef UNI_GPU cudaDeviceSynchronize(); @@ -803,7 +795,7 @@ namespace cytnx { "[ERROR] type mismatch. try to get type from raw data of type %s", Type.getname(this->dtype()).c_str()); if (idx >= this->size()) - cytnx_error_msg(1, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); + cytnx_error_msg(true, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); #ifdef UNI_GPU cudaDeviceSynchronize(); @@ -819,7 +811,7 @@ namespace cytnx { Type.getname(this->dtype()).c_str()); if (idx >= this->size()) - cytnx_error_msg(1, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); + cytnx_error_msg(true, "[ERROR] index [%d] out of bound [%d]\n", idx, this->size()); #ifdef UNI_GPU cudaDeviceSynchronize(); diff --git a/src/backend/Tensor_impl.cpp b/src/backend/Tensor_impl.cpp index a47ccddd3..ed251ef9d 100644 --- a/src/backend/Tensor_impl.cpp +++ b/src/backend/Tensor_impl.cpp @@ -26,7 +26,6 @@ namespace cytnx { this->_mapper = vec_range(shape.size()); this->_invmapper = this->_mapper; this->_contiguous = true; - // cout << shape << endl; } void Tensor_impl::Init(const Storage &in) { cytnx_error_msg(in.dtype() == Type.Void, @@ -56,16 +55,12 @@ namespace cytnx { std::vector new_shape(this->_shape.size()); std::vector new_idxmap(this->_shape.size()); - // for(int i=0;i_shape.size();i++) - // std::cout << this->_mapper[i] << " " << this->_invmapper[i] << std::endl; - boost::intrusive_ptr out(new Tensor_impl()); for (cytnx_uint32 i = 0; i < rnks.size(); i++) { if (rnks[i] >= rnks.size()) { - cytnx_error_msg(1, "%s", "reshape a tensor with invalid rank index."); + cytnx_error_msg(true, "%s", "reshape a tensor with invalid rank index."); } - // std::cout << this->_mapper[rnks[i]] << " " << i << std::endl; new_idxmap[this->_mapper[rnks[i]]] = i; new_fwdmap[i] = this->_mapper[rnks[i]]; new_shape[i] = this->_shape[rnks[i]]; @@ -117,14 +112,10 @@ namespace cytnx { std::vector new_shape(this->_shape.size()); std::vector new_idxmap(this->_shape.size()); - // for(int i=0;i_shape.size();i++) - // std::cout << this->_mapper[i] << " " << this->_invmapper[i] << std::endl; - for (cytnx_uint32 i = 0; i < rnks.size(); i++) { if (rnks[i] >= rnks.size()) { - cytnx_error_msg(1, "%s", "reshape a tensor with invalid rank index."); + cytnx_error_msg(true, "%s", "reshape a tensor with invalid rank index."); } - // std::cout << this->_mapper[rnks[i]] << " " << i << std::endl; // new_idxmap[this->_mapper[rnks[i]]] = i; this->_invmapper[this->_mapper[rnks[i]]] = i; new_fwdmap[i] = this->_mapper[rnks[i]]; @@ -168,24 +159,10 @@ namespace cytnx { acc.push_back(Accessor::all()); } - /* - cout << "acc type bef" << endl; - for(int i=0;i_invmapper); // contiguous. - /* - cout << "acc type aft" << endl; - for(int i=0;i_shape, this->_invmapper); - // cout << "curr_shape" << endl; - // cout << curr_shape << endl; //[2] from back to front, check until last all: cytnx_uint64 Nunit = 1; @@ -199,12 +176,8 @@ namespace cytnx { break; } } - // cout << "tmpidx" << tmpidx << endl; - // cout << "Nunit" << Nunit << endl; - // cout << acc.size() << endl; // acc-> locators - std::vector get_shape(acc.size()); std::vector> locators(acc.size()); for (cytnx_uint32 i = 0; i < acc.size(); i++) { @@ -212,8 +185,6 @@ namespace cytnx { "[ERROR] Tensor cannot accept accessor with qnum list.%s", "\n"); acc[i].get_len_pos(curr_shape[i], get_shape[i], locators[i]); } - // cout << "get_shape" << endl; - // cout << get_shape << endl; // create Tensor: for (cytnx_uint64 i = 0; i < tmpidx; i++) { @@ -221,7 +192,6 @@ namespace cytnx { } boost::intrusive_ptr out(new Tensor_impl()); out->Init(get_shape, this->dtype(), this->device()); - // cout << get_shape << endl; if (locators.size() == 0) { locators.resize(1); @@ -242,19 +212,6 @@ namespace cytnx { new_shape.push_back(out->shape()[i]); } - // cout << "mapper" << endl; - // cout << new_mapper << endl; - // cout << "inv_mapper" << endl; - // cout << this->_invmapper << endl; - - // cout << "removed" << endl; - // cout << removed << endl; - // cout << "out shape raw" << endl; - // cout << out->shape() << endl; - - // cout << "perm" << endl; - // cout << perm << endl; - // cout << new_shape << endl; if (new_shape.size()) { // exclude the case where only single element exists! out->reshape_(new_shape); // remove size-1 axis @@ -295,9 +252,6 @@ namespace cytnx { std::vector> locators(this->_shape.size()); for (cytnx_uint32 i = 0; i < acc.size(); i++) { acc[i].get_len_pos(this->_shape[i], get_shape[i], locators[i]); - // std::cout << this->_shape[i] << " " << get_shape[i] << "|"; - // for(int j=0;j out(new Tensor_impl()); @@ -319,7 +273,6 @@ namespace cytnx { void Tensor_impl::set(const std::vector &accessors, const boost::intrusive_ptr &rhs) { - // cout << "calling set" << endl; cytnx_error_msg(accessors.size() > this->_shape.size(), "%s", "The input indexes rank is out of range! (>Tensor's rank)."); @@ -359,15 +312,11 @@ namespace cytnx { if (rhs->storage().size() == 1) { this->storage()._impl->SetElem_byShape_v2(rhs->storage()._impl, curr_shape, locators, Nunit, true); - // std::cout << "Scalar" << endl; - } else { for (cytnx_uint64 i = 0; i < tmpidx; i++) { get_shape.push_back(curr_shape[acc.size() + i]); } - // std::cout << get_shape << endl; - // permute input to currect pos std::vector new_mapper(this->_mapper.begin(), this->_mapper.end()); std::vector new_shape; @@ -399,9 +348,7 @@ namespace cytnx { std::vector iperm(perm.size()); for (unsigned int i = 0; i < iperm.size(); i++) iperm[perm[i]] = i; - // std::cout << new_shape << endl; boost::intrusive_ptr tmp; - // std::cout << iperm << std::endl; tmp = rhs->permute(iperm)->contiguous(); cytnx_error_msg(new_shape != tmp->shape(), "[ERROR][Tensor.set_elems]%s", "inconsistent shape"); @@ -437,9 +384,6 @@ namespace cytnx { break; } } - // cout << "tmpidx" << tmpidx << endl; - // cout << "Nunit" << Nunit << endl; - // cout << acc.size() << endl; // acc-> locators @@ -450,8 +394,6 @@ namespace cytnx { "[ERROR] Tensor cannot accept accessor with qnum list.%s", "\n"); acc[i].get_len_pos(curr_shape[i], get_shape[i], locators[i]); } - // cout << "get_shape" << endl; - // cout << get_shape << endl; // call storage Scalar c = rc; diff --git a/src/backend/algo_internal_cpu/Concate_internal.cpp b/src/backend/algo_internal_cpu/Concate_internal.cpp index 885bdfef6..b7c11a465 100644 --- a/src/backend/algo_internal_cpu/Concate_internal.cpp +++ b/src/backend/algo_internal_cpu/Concate_internal.cpp @@ -1,5 +1,4 @@ #include "Concate_internal.hpp" -#include #include namespace cytnx { @@ -20,7 +19,6 @@ namespace cytnx { for (cytnx_int32 i = 0; i < ins.size(); i++) { memcpy(out_ptr + offs, ins[i], ElemSize * lens[i]); offs += ElemSize * lens[i]; - // std::cout << ElemSize*lens[i] << std::endl; } } diff --git a/src/backend/algo_internal_cpu/Concate_internal.hpp b/src/backend/algo_internal_cpu/Concate_internal.hpp index 9f585e74c..1b7799d07 100644 --- a/src/backend/algo_internal_cpu/Concate_internal.hpp +++ b/src/backend/algo_internal_cpu/Concate_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_ALGO_INTERNAL_CPU_CONCATE_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/algo_internal_cpu/Split_internal.cpp b/src/backend/algo_internal_cpu/Split_internal.cpp index 18e2bfc6c..72aaac767 100644 --- a/src/backend/algo_internal_cpu/Split_internal.cpp +++ b/src/backend/algo_internal_cpu/Split_internal.cpp @@ -1,5 +1,4 @@ #include "Split_internal.hpp" -#include #include namespace cytnx { diff --git a/src/backend/algo_internal_cpu/Split_internal.hpp b/src/backend/algo_internal_cpu/Split_internal.hpp index 02247d2b8..c05cc24d9 100644 --- a/src/backend/algo_internal_cpu/Split_internal.hpp +++ b/src/backend/algo_internal_cpu/Split_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_ALGO_INTERNAL_CPU_SPLIT_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/algo_internal_gpu/cuConcate_internal.cu b/src/backend/algo_internal_gpu/cuConcate_internal.cu index 6b076a1f2..e91fee356 100644 --- a/src/backend/algo_internal_gpu/cuConcate_internal.cu +++ b/src/backend/algo_internal_gpu/cuConcate_internal.cu @@ -19,7 +19,6 @@ namespace cytnx { checkCudaErrors( cudaMemcpy(out_ptr + offs, ins[i], ElemSize * lens[i], cudaMemcpyDeviceToDevice)); offs += ElemSize * lens[i]; - // std::cout << ElemSize*lens[i] << std::endl; } } diff --git a/src/backend/algo_internal_gpu/cuConcate_internal.hpp b/src/backend/algo_internal_gpu/cuConcate_internal.hpp index c1b3a83a0..3ec681786 100644 --- a/src/backend/algo_internal_gpu/cuConcate_internal.hpp +++ b/src/backend/algo_internal_gpu/cuConcate_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_ALGO_INTERNAL_GPU_CUCONCATE_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/algo_internal_gpu/cuSplit_internal.hpp b/src/backend/algo_internal_gpu/cuSplit_internal.hpp index dd2f8e62c..f8389618c 100644 --- a/src/backend/algo_internal_gpu/cuSplit_internal.hpp +++ b/src/backend/algo_internal_gpu/cuSplit_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_ALGO_INTERNAL_GPU_CUSPLIT_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Abs_internal.hpp b/src/backend/linalg_internal_cpu/Abs_internal.hpp index f76708819..5dbe7e049 100644 --- a/src/backend/linalg_internal_cpu/Abs_internal.hpp +++ b/src/backend/linalg_internal_cpu/Abs_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_ABS_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Axpy_internal.hpp b/src/backend/linalg_internal_cpu/Axpy_internal.hpp index 2d404ff3e..fa7e5777a 100644 --- a/src/backend/linalg_internal_cpu/Axpy_internal.hpp +++ b/src/backend/linalg_internal_cpu/Axpy_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_AXPY_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Batch_matmul_internal.hpp b/src/backend/linalg_internal_cpu/Batch_matmul_internal.hpp index 4fc225169..99d4b448d 100644 --- a/src/backend/linalg_internal_cpu/Batch_matmul_internal.hpp +++ b/src/backend/linalg_internal_cpu/Batch_matmul_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_BATCH_MATMUL_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Conj_inplace_internal.hpp b/src/backend/linalg_internal_cpu/Conj_inplace_internal.hpp index 371c6e33e..bc0c86d89 100644 --- a/src/backend/linalg_internal_cpu/Conj_inplace_internal.hpp +++ b/src/backend/linalg_internal_cpu/Conj_inplace_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_CONJ_INPLACE_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Det_internal.hpp b/src/backend/linalg_internal_cpu/Det_internal.hpp index d56435f5e..d713cf3ed 100644 --- a/src/backend/linalg_internal_cpu/Det_internal.hpp +++ b/src/backend/linalg_internal_cpu/Det_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_DET_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Diag_internal.hpp b/src/backend/linalg_internal_cpu/Diag_internal.hpp index c227840c6..2be4c9fee 100644 --- a/src/backend/linalg_internal_cpu/Diag_internal.hpp +++ b/src/backend/linalg_internal_cpu/Diag_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_DIAG_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Eig_internal.hpp b/src/backend/linalg_internal_cpu/Eig_internal.hpp index 1feb84fc4..12ca810a1 100644 --- a/src/backend/linalg_internal_cpu/Eig_internal.hpp +++ b/src/backend/linalg_internal_cpu/Eig_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_EIG_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Eigh_internal.hpp b/src/backend/linalg_internal_cpu/Eigh_internal.hpp index ec421f44d..f3be91a07 100644 --- a/src/backend/linalg_internal_cpu/Eigh_internal.hpp +++ b/src/backend/linalg_internal_cpu/Eigh_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_EIGH_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Exp_internal.hpp b/src/backend/linalg_internal_cpu/Exp_internal.hpp index 0ec02eb07..b65c6c041 100644 --- a/src/backend/linalg_internal_cpu/Exp_internal.hpp +++ b/src/backend/linalg_internal_cpu/Exp_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_EXP_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Gemm_Batch_internal.hpp b/src/backend/linalg_internal_cpu/Gemm_Batch_internal.hpp index 1c99281bf..1fe51ea45 100644 --- a/src/backend/linalg_internal_cpu/Gemm_Batch_internal.hpp +++ b/src/backend/linalg_internal_cpu/Gemm_Batch_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_GEMM_BATCH_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Gemm_internal.hpp b/src/backend/linalg_internal_cpu/Gemm_internal.hpp index 57690bc8c..397fba0f4 100644 --- a/src/backend/linalg_internal_cpu/Gemm_internal.hpp +++ b/src/backend/linalg_internal_cpu/Gemm_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_GEMM_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Ger_internal.hpp b/src/backend/linalg_internal_cpu/Ger_internal.hpp index 258153e44..3ccfe5411 100644 --- a/src/backend/linalg_internal_cpu/Ger_internal.hpp +++ b/src/backend/linalg_internal_cpu/Ger_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_GER_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Gesvd_internal.hpp b/src/backend/linalg_internal_cpu/Gesvd_internal.hpp index 2c304056c..3f931e6a9 100644 --- a/src/backend/linalg_internal_cpu/Gesvd_internal.hpp +++ b/src/backend/linalg_internal_cpu/Gesvd_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_GESVD_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/InvM_inplace_internal.hpp b/src/backend/linalg_internal_cpu/InvM_inplace_internal.hpp index 3c697ee35..634aad842 100644 --- a/src/backend/linalg_internal_cpu/InvM_inplace_internal.hpp +++ b/src/backend/linalg_internal_cpu/InvM_inplace_internal.hpp @@ -2,9 +2,9 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_INVM_INPLACE_INTERNAL_H_ #include -#include #include #include + #include "backend/Storage.hpp" #include "Type.hpp" diff --git a/src/backend/linalg_internal_cpu/Inv_inplace_internal.hpp b/src/backend/linalg_internal_cpu/Inv_inplace_internal.hpp index 97a92b226..fc8f79e69 100644 --- a/src/backend/linalg_internal_cpu/Inv_inplace_internal.hpp +++ b/src/backend/linalg_internal_cpu/Inv_inplace_internal.hpp @@ -2,9 +2,9 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_INV_INPLACE_INTERNAL_H_ #include -#include #include #include + #include "backend/Storage.hpp" #include "Type.hpp" diff --git a/src/backend/linalg_internal_cpu/Kron_internal.hpp b/src/backend/linalg_internal_cpu/Kron_internal.hpp index 886724d41..071a36548 100644 --- a/src/backend/linalg_internal_cpu/Kron_internal.hpp +++ b/src/backend/linalg_internal_cpu/Kron_internal.hpp @@ -2,9 +2,9 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_KRON_INTERNAL_H_ #include -#include #include #include + #include "backend/Storage.hpp" #include "Type.hpp" diff --git a/src/backend/linalg_internal_cpu/Lstsq_internal.hpp b/src/backend/linalg_internal_cpu/Lstsq_internal.hpp index 5c93d0192..8791b1409 100644 --- a/src/backend/linalg_internal_cpu/Lstsq_internal.hpp +++ b/src/backend/linalg_internal_cpu/Lstsq_internal.hpp @@ -2,9 +2,9 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_LSTSQ_INTERNAL_H_ #include -#include #include #include + #include "backend/Storage.hpp" #include "Type.hpp" diff --git a/src/backend/linalg_internal_cpu/Matmul_dg_internal.hpp b/src/backend/linalg_internal_cpu/Matmul_dg_internal.hpp index 21c8c12ba..1627b9875 100644 --- a/src/backend/linalg_internal_cpu/Matmul_dg_internal.hpp +++ b/src/backend/linalg_internal_cpu/Matmul_dg_internal.hpp @@ -2,9 +2,9 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_MATMUL_DG_INTERNAL_H_ #include -#include #include #include + #include "backend/Storage.hpp" #include "Type.hpp" diff --git a/src/backend/linalg_internal_cpu/Matmul_internal.cpp b/src/backend/linalg_internal_cpu/Matmul_internal.cpp index 4a5e686d6..9de1348ae 100644 --- a/src/backend/linalg_internal_cpu/Matmul_internal.cpp +++ b/src/backend/linalg_internal_cpu/Matmul_internal.cpp @@ -13,7 +13,6 @@ namespace cytnx { cytnx_int64 j = n / Nr; out[j * Nr + i] = 0; for (cytnx_int64 c = 0; c < Comm; c++) { - // std::cout << inl[j*Comm+c] << " " << inr[c*Nr+i] << std::endl; out[j * Nr + i] += inl[j * Comm + c] * inr[c * Nr + i]; } } diff --git a/src/backend/linalg_internal_cpu/Matmul_internal.hpp b/src/backend/linalg_internal_cpu/Matmul_internal.hpp index b29486024..07dca30dd 100644 --- a/src/backend/linalg_internal_cpu/Matmul_internal.hpp +++ b/src/backend/linalg_internal_cpu/Matmul_internal.hpp @@ -2,9 +2,9 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_MATMUL_INTERNAL_H_ #include -#include #include #include + #include "backend/Storage.hpp" #include "Type.hpp" diff --git a/src/backend/linalg_internal_cpu/Matvec_internal.cpp b/src/backend/linalg_internal_cpu/Matvec_internal.cpp index 5d72c749a..9f0544549 100644 --- a/src/backend/linalg_internal_cpu/Matvec_internal.cpp +++ b/src/backend/linalg_internal_cpu/Matvec_internal.cpp @@ -11,7 +11,6 @@ namespace cytnx { for (cytnx_uint64 n = 0; n < cytnx_uint64(Ml); n++) { out[n] = 0; for (cytnx_int64 c = 0; c < Nr; c++) { - // std::cout << inl[j*Comm+c] << " " << inr[c*Nr+i] << std::endl; out[n] += inl[n * Nr + c] * inr[c]; } } diff --git a/src/backend/linalg_internal_cpu/Matvec_internal.hpp b/src/backend/linalg_internal_cpu/Matvec_internal.hpp index 53d95bb80..a81506468 100644 --- a/src/backend/linalg_internal_cpu/Matvec_internal.hpp +++ b/src/backend/linalg_internal_cpu/Matvec_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_MATVEC_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/MaxMin_internal.hpp b/src/backend/linalg_internal_cpu/MaxMin_internal.hpp index 7f5a402bc..3a3dcbf2d 100644 --- a/src/backend/linalg_internal_cpu/MaxMin_internal.hpp +++ b/src/backend/linalg_internal_cpu/MaxMin_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_MAXMIN_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Norm_internal.hpp b/src/backend/linalg_internal_cpu/Norm_internal.hpp index 2fce1dc35..cac0004b3 100644 --- a/src/backend/linalg_internal_cpu/Norm_internal.hpp +++ b/src/backend/linalg_internal_cpu/Norm_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_NORM_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Outer_internal.hpp b/src/backend/linalg_internal_cpu/Outer_internal.hpp index d3d403eef..55910e4c0 100644 --- a/src/backend/linalg_internal_cpu/Outer_internal.hpp +++ b/src/backend/linalg_internal_cpu/Outer_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_OUTER_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Pow_internal.hpp b/src/backend/linalg_internal_cpu/Pow_internal.hpp index a4a08de20..3abf6577d 100644 --- a/src/backend/linalg_internal_cpu/Pow_internal.hpp +++ b/src/backend/linalg_internal_cpu/Pow_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_POW_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/QR_internal.hpp b/src/backend/linalg_internal_cpu/QR_internal.hpp index cca40d9b3..0be7115cf 100644 --- a/src/backend/linalg_internal_cpu/QR_internal.hpp +++ b/src/backend/linalg_internal_cpu/QR_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_QR_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Sdd_internal.hpp b/src/backend/linalg_internal_cpu/Sdd_internal.hpp index 5e5f3151e..7312e3646 100644 --- a/src/backend/linalg_internal_cpu/Sdd_internal.hpp +++ b/src/backend/linalg_internal_cpu/Sdd_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_SDD_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Trace_internal.hpp b/src/backend/linalg_internal_cpu/Trace_internal.hpp index 64375a423..c518ab381 100644 --- a/src/backend/linalg_internal_cpu/Trace_internal.hpp +++ b/src/backend/linalg_internal_cpu/Trace_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_TRACE_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Tridiag_internal.cpp b/src/backend/linalg_internal_cpu/Tridiag_internal.cpp index ac7d4bc9b..d910748e7 100644 --- a/src/backend/linalg_internal_cpu/Tridiag_internal.cpp +++ b/src/backend/linalg_internal_cpu/Tridiag_internal.cpp @@ -1,7 +1,6 @@ #include "Tridiag_internal.hpp" #include "cytnx_error.hpp" #include "backend/lapack_wrapper.hpp" -#include namespace cytnx { namespace linalg_internal { @@ -13,7 +12,6 @@ namespace cytnx { bool throw_excp /*= false*/) { char job; job = (U->dtype() == Type.Void) ? 'N' : 'V'; - // std::cout << L << std::endl; // copy from in to S[out] memcpy(S->data(), diag->data(), L * sizeof(cytnx_double)); @@ -31,7 +29,6 @@ namespace cytnx { info = LAPACKE_dstev(LAPACK_COL_MAJOR, job, L, (cytnx_double *)S->data(), Dsv, (cytnx_double *)U->data(), ldz); - // std::cout << L << std::endl; if (!throw_excp and info != 0) { cytnx_error_msg(info != 0, "%s %d", "Error in Lapack function 'dstev': Lapack INFO = ", info); @@ -49,7 +46,6 @@ namespace cytnx { bool throw_excp /*= false*/) { char job; job = (U->dtype() == Type.Void) ? 'N' : 'V'; - // std::cout << L << std::endl; // copy from in to S[out] memcpy(S->data(), diag->data(), L * sizeof(cytnx_float)); diff --git a/src/backend/linalg_internal_cpu/Tridiag_internal.hpp b/src/backend/linalg_internal_cpu/Tridiag_internal.hpp index e7494a21d..ea162431f 100644 --- a/src/backend/linalg_internal_cpu/Tridiag_internal.hpp +++ b/src/backend/linalg_internal_cpu/Tridiag_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_TRIDIAG_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/Vectordot_internal.cpp b/src/backend/linalg_internal_cpu/Vectordot_internal.cpp index 32886a4dd..7bd052446 100644 --- a/src/backend/linalg_internal_cpu/Vectordot_internal.cpp +++ b/src/backend/linalg_internal_cpu/Vectordot_internal.cpp @@ -232,7 +232,7 @@ namespace cytnx { const boost::intrusive_ptr &Lin, const boost::intrusive_ptr &Rin, const unsigned long long &len, const bool &is_conj) { - cytnx_error_msg(1, + cytnx_error_msg(true, "[ERROR][Vectordot_internal_b][FATAL Invalid internal call.] No internal " "function for vectordot of bool type.%s", "\n"); diff --git a/src/backend/linalg_internal_cpu/Vectordot_internal.hpp b/src/backend/linalg_internal_cpu/Vectordot_internal.hpp index 55d2b253b..6a81731ac 100644 --- a/src/backend/linalg_internal_cpu/Vectordot_internal.hpp +++ b/src/backend/linalg_internal_cpu/Vectordot_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_VECTORDOT_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_cpu/iAdd_internal.cpp b/src/backend/linalg_internal_cpu/iAdd_internal.cpp index 2a6bc708a..a69a0d1ce 100644 --- a/src/backend/linalg_internal_cpu/iAdd_internal.cpp +++ b/src/backend/linalg_internal_cpu/iAdd_internal.cpp @@ -1,7 +1,7 @@ #include "iAdd_internal.hpp" + #include "backend/utils_internal_interface.hpp" #include "utils/utils.hpp" -#include namespace cytnx { diff --git a/src/backend/linalg_internal_cpu/iAdd_internal.hpp b/src/backend/linalg_internal_cpu/iAdd_internal.hpp index ce9a30ddd..63d302524 100644 --- a/src/backend/linalg_internal_cpu/iAdd_internal.hpp +++ b/src/backend/linalg_internal_cpu/iAdd_internal.hpp @@ -2,9 +2,9 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_IADD_INTERNAL_H_ #include -#include #include #include + #include "backend/Storage.hpp" #include "Type.hpp" diff --git a/src/backend/linalg_internal_cpu/iDiv_internal.cpp b/src/backend/linalg_internal_cpu/iDiv_internal.cpp index b82c95a96..282abbe49 100644 --- a/src/backend/linalg_internal_cpu/iDiv_internal.cpp +++ b/src/backend/linalg_internal_cpu/iDiv_internal.cpp @@ -1,7 +1,6 @@ #include "iDiv_internal.hpp" #include "backend/utils_internal_interface.hpp" #include "utils/utils.hpp" -#include namespace cytnx { diff --git a/src/backend/linalg_internal_cpu/iDiv_internal.hpp b/src/backend/linalg_internal_cpu/iDiv_internal.hpp index e28aaa93c..ec3d3afe7 100644 --- a/src/backend/linalg_internal_cpu/iDiv_internal.hpp +++ b/src/backend/linalg_internal_cpu/iDiv_internal.hpp @@ -2,9 +2,9 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_IDIV_INTERNAL_H_ #include -#include #include #include + #include "backend/Storage.hpp" #include "Type.hpp" diff --git a/src/backend/linalg_internal_cpu/iMul_internal.cpp b/src/backend/linalg_internal_cpu/iMul_internal.cpp index 14e3f4f4c..603d613e2 100644 --- a/src/backend/linalg_internal_cpu/iMul_internal.cpp +++ b/src/backend/linalg_internal_cpu/iMul_internal.cpp @@ -1,7 +1,7 @@ #include "iMul_internal.hpp" + #include "backend/utils_internal_interface.hpp" #include "utils/utils.hpp" -#include namespace cytnx { diff --git a/src/backend/linalg_internal_cpu/iMul_internal.hpp b/src/backend/linalg_internal_cpu/iMul_internal.hpp index 8f2914728..9a62b5a7f 100644 --- a/src/backend/linalg_internal_cpu/iMul_internal.hpp +++ b/src/backend/linalg_internal_cpu/iMul_internal.hpp @@ -2,9 +2,9 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_IMUL_INTERNAL_H_ #include -#include #include #include + #include "backend/Storage.hpp" #include "Type.hpp" diff --git a/src/backend/linalg_internal_cpu/iSub_internal.cpp b/src/backend/linalg_internal_cpu/iSub_internal.cpp index 14aa56c8f..262cd480a 100644 --- a/src/backend/linalg_internal_cpu/iSub_internal.cpp +++ b/src/backend/linalg_internal_cpu/iSub_internal.cpp @@ -1,7 +1,7 @@ #include "iSub_internal.hpp" + #include "backend/utils_internal_interface.hpp" #include "utils/utils.hpp" -#include namespace cytnx { diff --git a/src/backend/linalg_internal_cpu/iSub_internal.hpp b/src/backend/linalg_internal_cpu/iSub_internal.hpp index 8bed0af53..4ae154326 100644 --- a/src/backend/linalg_internal_cpu/iSub_internal.hpp +++ b/src/backend/linalg_internal_cpu/iSub_internal.hpp @@ -2,9 +2,9 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_ISUB_INTERNAL_H_ #include -#include #include #include + #include "backend/Storage.hpp" #include "Type.hpp" diff --git a/src/backend/linalg_internal_cpu/memcpyTruncation.hpp b/src/backend/linalg_internal_cpu/memcpyTruncation.hpp index 4378d0a19..cd136238e 100644 --- a/src/backend/linalg_internal_cpu/memcpyTruncation.hpp +++ b/src/backend/linalg_internal_cpu/memcpyTruncation.hpp @@ -1,7 +1,6 @@ #ifndef CYTNX_BACKEND_LINALG_INTERNAL_CPU_MEMCPYTRUNCATION_H_ #define CYTNX_BACKEND_LINALG_INTERNAL_CPU_MEMCPYTRUNCATION_H_ -#include #include #include "Tensor.hpp" diff --git a/src/backend/linalg_internal_gpu/cuAbs_internal.hpp b/src/backend/linalg_internal_gpu/cuAbs_internal.hpp index 566ce96e6..f14552ceb 100644 --- a/src/backend/linalg_internal_gpu/cuAbs_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuAbs_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUABS_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuAdd_internal.hpp b/src/backend/linalg_internal_gpu/cuAdd_internal.hpp index ca8997145..87f553fd7 100644 --- a/src/backend/linalg_internal_gpu/cuAdd_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuAdd_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUADD_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuConj_inplace_internal.hpp b/src/backend/linalg_internal_gpu/cuConj_inplace_internal.hpp index eaeabee02..7f025394b 100644 --- a/src/backend/linalg_internal_gpu/cuConj_inplace_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuConj_inplace_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUCONJ_INPLACE_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuCpr_internal.hpp b/src/backend/linalg_internal_gpu/cuCpr_internal.hpp index b9f79aae4..69b48a5cc 100644 --- a/src/backend/linalg_internal_gpu/cuCpr_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuCpr_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUCPR_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuDet_internal.hpp b/src/backend/linalg_internal_gpu/cuDet_internal.hpp index 2ba94e67f..33cad328e 100644 --- a/src/backend/linalg_internal_gpu/cuDet_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuDet_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUDET_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuDiag_internal.hpp b/src/backend/linalg_internal_gpu/cuDiag_internal.hpp index 4dd8786fe..de6327184 100644 --- a/src/backend/linalg_internal_gpu/cuDiag_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuDiag_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUDIAG_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuDiv_internal.hpp b/src/backend/linalg_internal_gpu/cuDiv_internal.hpp index 2b6c220b3..6286c9fa4 100644 --- a/src/backend/linalg_internal_gpu/cuDiv_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuDiv_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUDIV_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuEig_internal.hpp b/src/backend/linalg_internal_gpu/cuEig_internal.hpp index 9532199c9..162560ce4 100644 --- a/src/backend/linalg_internal_gpu/cuEig_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuEig_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUEIG_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuEigh_internal.hpp b/src/backend/linalg_internal_gpu/cuEigh_internal.hpp index a242427fc..a2371265c 100644 --- a/src/backend/linalg_internal_gpu/cuEigh_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuEigh_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUEIGH_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuExp_internal.hpp b/src/backend/linalg_internal_gpu/cuExp_internal.hpp index cf0c7677f..3219f9e1d 100644 --- a/src/backend/linalg_internal_gpu/cuExp_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuExp_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUEXP_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuGeSvd_internal.hpp b/src/backend/linalg_internal_gpu/cuGeSvd_internal.hpp index 453d9436e..b7dc71b9b 100644 --- a/src/backend/linalg_internal_gpu/cuGeSvd_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuGeSvd_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUGESVD_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuGemm_Batch_internal.hpp b/src/backend/linalg_internal_gpu/cuGemm_Batch_internal.hpp index 09bce0c19..fb5e7a869 100644 --- a/src/backend/linalg_internal_gpu/cuGemm_Batch_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuGemm_Batch_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUGEMM_BATCH_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuGemm_internal.hpp b/src/backend/linalg_internal_gpu/cuGemm_internal.hpp index 5dc66ebb4..c20a10166 100644 --- a/src/backend/linalg_internal_gpu/cuGemm_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuGemm_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUGEMM_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuGer_internal.hpp b/src/backend/linalg_internal_gpu/cuGer_internal.hpp index e8fe3ef10..112d86a60 100644 --- a/src/backend/linalg_internal_gpu/cuGer_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuGer_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUGER_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuInvM_inplace_internal.hpp b/src/backend/linalg_internal_gpu/cuInvM_inplace_internal.hpp index 014af906f..430f68e6e 100644 --- a/src/backend/linalg_internal_gpu/cuInvM_inplace_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuInvM_inplace_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUINVM_INPLACE_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuInv_inplace_internal.hpp b/src/backend/linalg_internal_gpu/cuInv_inplace_internal.hpp index 01b1820de..dcdcd7d88 100644 --- a/src/backend/linalg_internal_gpu/cuInv_inplace_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuInv_inplace_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUINV_INPLACE_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuKron_internal.cuh b/src/backend/linalg_internal_gpu/cuKron_internal.cuh index af7956587..8ee1575b8 100644 --- a/src/backend/linalg_internal_gpu/cuKron_internal.cuh +++ b/src/backend/linalg_internal_gpu/cuKron_internal.cuh @@ -9,7 +9,6 @@ #include "cytnx_error.hpp" #include "Type.hpp" #include "backend/lapack_wrapper.hpp" -#include #ifndef __CUDACC__ #error This file requires a CUDA compiler diff --git a/src/backend/linalg_internal_gpu/cuMatmul_dg_internal.cu b/src/backend/linalg_internal_gpu/cuMatmul_dg_internal.cu index 85c682dc9..0bfa0a0ae 100644 --- a/src/backend/linalg_internal_gpu/cuMatmul_dg_internal.cu +++ b/src/backend/linalg_internal_gpu/cuMatmul_dg_internal.cu @@ -97,8 +97,6 @@ namespace cytnx { // query working space : cytnx_int32 blsMl = Ml, blsNr = Nr; //, blsComm=Comm; - // std::cout << blsMl << " " << blsNr << " " << blsComm << std::endl; - // std::cout << diag_L << std::endl; if (diag_L) checkCudaErrors( diff --git a/src/backend/linalg_internal_gpu/cuMatmul_dg_internal.hpp b/src/backend/linalg_internal_gpu/cuMatmul_dg_internal.hpp index a3387456d..6616fb4c4 100644 --- a/src/backend/linalg_internal_gpu/cuMatmul_dg_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuMatmul_dg_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUMATMUL_DG_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuMatmul_internal.hpp b/src/backend/linalg_internal_gpu/cuMatmul_internal.hpp index 104ce35c7..8749c35fa 100644 --- a/src/backend/linalg_internal_gpu/cuMatmul_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuMatmul_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUMATMUL_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuMatvec_internal.hpp b/src/backend/linalg_internal_gpu/cuMatvec_internal.hpp index 5a442df01..80f233e60 100644 --- a/src/backend/linalg_internal_gpu/cuMatvec_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuMatvec_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUMATVEC_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuMaxMin_internal.cu b/src/backend/linalg_internal_gpu/cuMaxMin_internal.cu index dab5d014e..c8320641d 100644 --- a/src/backend/linalg_internal_gpu/cuMaxMin_internal.cu +++ b/src/backend/linalg_internal_gpu/cuMaxMin_internal.cu @@ -427,7 +427,6 @@ namespace cytnx { // alloc mem for each block: T *dblk; - // std::cout << NBlocks*sizeof(cytnx_double) << std::endl; cudaMalloc((void **)&dblk, NBlocks * sizeof(T)); if (NBlocks == 1) { @@ -466,7 +465,6 @@ namespace cytnx { // alloc mem for each block: T *dblk; - // std::cout << NBlocks*sizeof(cytnx_double) << std::endl; cudaMalloc((void **)&dblk, NBlocks * sizeof(T)); if (NBlocks == 1) { diff --git a/src/backend/linalg_internal_gpu/cuMaxMin_internal.hpp b/src/backend/linalg_internal_gpu/cuMaxMin_internal.hpp index 70db5e60b..4eb164013 100644 --- a/src/backend/linalg_internal_gpu/cuMaxMin_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuMaxMin_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUMAXMIN_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuMod_internal.hpp b/src/backend/linalg_internal_gpu/cuMod_internal.hpp index 7f5cbe5eb..d7e8999ad 100644 --- a/src/backend/linalg_internal_gpu/cuMod_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuMod_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUMOD_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuMul_internal.hpp b/src/backend/linalg_internal_gpu/cuMul_internal.hpp index 6837e6f43..0c5a38ea0 100644 --- a/src/backend/linalg_internal_gpu/cuMul_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuMul_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUMUL_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuNorm_internal.hpp b/src/backend/linalg_internal_gpu/cuNorm_internal.hpp index 2ee6639a8..e9dcf4027 100644 --- a/src/backend/linalg_internal_gpu/cuNorm_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuNorm_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUNORM_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuOuter_internal.hpp b/src/backend/linalg_internal_gpu/cuOuter_internal.hpp index d1e1d7bfe..e833727d3 100644 --- a/src/backend/linalg_internal_gpu/cuOuter_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuOuter_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUOUTER_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuPow_internal.hpp b/src/backend/linalg_internal_gpu/cuPow_internal.hpp index 993e20776..db95fb425 100644 --- a/src/backend/linalg_internal_gpu/cuPow_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuPow_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUPOW_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuQuantumGeSvd_internal.cu b/src/backend/linalg_internal_gpu/cuQuantumGeSvd_internal.cu index 794521096..a1e63d596 100644 --- a/src/backend/linalg_internal_gpu/cuQuantumGeSvd_internal.cu +++ b/src/backend/linalg_internal_gpu/cuQuantumGeSvd_internal.cu @@ -1,6 +1,7 @@ #include #include +#include #include #include #include diff --git a/src/backend/linalg_internal_gpu/cuQuantumGeSvd_internal.hpp b/src/backend/linalg_internal_gpu/cuQuantumGeSvd_internal.hpp index d90c6dc5a..ee2470ec6 100644 --- a/src/backend/linalg_internal_gpu/cuQuantumGeSvd_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuQuantumGeSvd_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUQUANTUMGESVD_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuQuantumQr_internal.hpp b/src/backend/linalg_internal_gpu/cuQuantumQr_internal.hpp index c2d6eaaf8..db43c63df 100644 --- a/src/backend/linalg_internal_gpu/cuQuantumQr_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuQuantumQr_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUQUANTUMQR_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuSub_internal.hpp b/src/backend/linalg_internal_gpu/cuSub_internal.hpp index 5073e3ea6..e6cfb8e07 100644 --- a/src/backend/linalg_internal_gpu/cuSub_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuSub_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUSUB_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuSum_internal.hpp b/src/backend/linalg_internal_gpu/cuSum_internal.hpp index dbe009b38..30bb0a722 100644 --- a/src/backend/linalg_internal_gpu/cuSum_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuSum_internal.hpp @@ -4,7 +4,6 @@ #include "boost/smart_ptr/intrusive_ptr.hpp" #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuSvd_internal.hpp b/src/backend/linalg_internal_gpu/cuSvd_internal.hpp index 2fae72edf..748d3e97e 100644 --- a/src/backend/linalg_internal_gpu/cuSvd_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuSvd_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUSVD_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuTensordot_internal.hpp b/src/backend/linalg_internal_gpu/cuTensordot_internal.hpp index 7fa1176d9..56a41bc3f 100644 --- a/src/backend/linalg_internal_gpu/cuTensordot_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuTensordot_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUTENSORDOT_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuTrace_internal.hpp b/src/backend/linalg_internal_gpu/cuTrace_internal.hpp index 300aee615..e700fe33e 100644 --- a/src/backend/linalg_internal_gpu/cuTrace_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuTrace_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUTRACE_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cuVectordot_internal.cu b/src/backend/linalg_internal_gpu/cuVectordot_internal.cu index 53dd2f7c5..6f0f9d127 100644 --- a/src/backend/linalg_internal_gpu/cuVectordot_internal.cu +++ b/src/backend/linalg_internal_gpu/cuVectordot_internal.cu @@ -31,7 +31,6 @@ namespace cytnx { cudaMemset(dacres, 0, sizeof(cuDoubleComplex) * TotSeg); while (remain != 0) { - cout << "cnt" << endl; if (remain >= INT_MAX) MAXX = INT_MAX; else @@ -155,10 +154,8 @@ namespace cytnx { MAXX = INT_MAX; else MAXX = remain; - // std::cout << cnt << std::endl; checkCudaErrors( cublasDdot(cublasH, MAXX, _Lin + bias, ONE, _Rin + bias, ONE, dacres + cnt)); - // std::cout << cnt << std::endl; cnt++; //_out[0] += acres[0]; remain -= MAXX; @@ -170,7 +167,6 @@ namespace cytnx { } else { utils_internal::cuReduce_gpu(_out, dacres, TotSeg); } - // std::cout << "done" << std::endl; /* cytnx_double *hacres = (cytnx_double*)malloc(sizeof(cytnx_double)*TotSeg); cudaMemcpy((cytnx_double*)hacres,dacres,sizeof(cytnx_double)*TotSeg,cudaMemcpyDeviceToHost); @@ -242,7 +238,7 @@ namespace cytnx { const boost::intrusive_ptr &Lin, const boost::intrusive_ptr &Rin, const unsigned long long &len, const bool &is_conj) { - cytnx_error_msg(1, + cytnx_error_msg(true, "[ERROR][cuVectordot_internal_i64][FATAL Invalid internal call.] No internal " "function for vectordot of int64 type.%s", "\n"); @@ -251,7 +247,7 @@ namespace cytnx { const boost::intrusive_ptr &Lin, const boost::intrusive_ptr &Rin, const unsigned long long &len, const bool &is_conj) { - cytnx_error_msg(1, + cytnx_error_msg(true, "[ERROR][cuVectordot_internal_u64][FATAL Invalid internal call.] No internal " "function for vectordot of uint64 type.%s", "\n"); @@ -260,7 +256,7 @@ namespace cytnx { const boost::intrusive_ptr &Lin, const boost::intrusive_ptr &Rin, const unsigned long long &len, const bool &is_conj) { - cytnx_error_msg(1, + cytnx_error_msg(true, "[ERROR][cuVectordot_internal_i32][FATAL Invalid internal call.] No internal " "function for vectordot of int32 type.%s", "\n"); @@ -269,7 +265,7 @@ namespace cytnx { const boost::intrusive_ptr &Lin, const boost::intrusive_ptr &Rin, const unsigned long long &len, const bool &is_conj) { - cytnx_error_msg(1, + cytnx_error_msg(true, "[ERROR][cuVectordot_internal_u32][FATAL Invalid internal call.] No internal " "function for vectordot of uint32 type.%s", "\n"); @@ -278,7 +274,7 @@ namespace cytnx { const boost::intrusive_ptr &Lin, const boost::intrusive_ptr &Rin, const unsigned long long &len, const bool &is_conj) { - cytnx_error_msg(1, + cytnx_error_msg(true, "[ERROR][cuVectordot_internal_i16][FATAL Invalid internal call.] No internal " "function for vectordot of int16 type.%s", "\n"); @@ -287,7 +283,7 @@ namespace cytnx { const boost::intrusive_ptr &Lin, const boost::intrusive_ptr &Rin, const unsigned long long &len, const bool &is_conj) { - cytnx_error_msg(1, + cytnx_error_msg(true, "[ERROR][cuVectordot_internal_u16][FATAL Invalid internal call.] No internal " "function for vectordot of uint16 type.%s", "\n"); @@ -296,7 +292,7 @@ namespace cytnx { const boost::intrusive_ptr &Lin, const boost::intrusive_ptr &Rin, const unsigned long long &len, const bool &is_conj) { - cytnx_error_msg(1, + cytnx_error_msg(true, "[ERROR][cuVectordot_internal_b][FATAL Invalid internal call.] No internal " "function for vectordot of bool type.%s", "\n"); diff --git a/src/backend/linalg_internal_gpu/cuVectordot_internal.hpp b/src/backend/linalg_internal_gpu/cuVectordot_internal.hpp index 70726eb28..7421775c9 100644 --- a/src/backend/linalg_internal_gpu/cuVectordot_internal.hpp +++ b/src/backend/linalg_internal_gpu/cuVectordot_internal.hpp @@ -2,7 +2,6 @@ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUVECTORDOT_INTERNAL_H_ #include -#include #include #include #include "backend/Storage.hpp" diff --git a/src/backend/linalg_internal_gpu/cudaMemcpyTruncation.hpp b/src/backend/linalg_internal_gpu/cudaMemcpyTruncation.hpp index d46d8d2a2..a718a461c 100644 --- a/src/backend/linalg_internal_gpu/cudaMemcpyTruncation.hpp +++ b/src/backend/linalg_internal_gpu/cudaMemcpyTruncation.hpp @@ -1,7 +1,6 @@ #ifndef CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUDAMEMCPYTRUNCATION_H_ #define CYTNX_BACKEND_LINALG_INTERNAL_GPU_CUDAMEMCPYTRUNCATION_H_ -#include #include #include "Tensor.hpp" diff --git a/src/backend/linalg_internal_interface.hpp b/src/backend/linalg_internal_interface.hpp index 5835a7ecb..e3dcb8fc7 100644 --- a/src/backend/linalg_internal_interface.hpp +++ b/src/backend/linalg_internal_interface.hpp @@ -1,7 +1,6 @@ #ifndef CYTNX_BACKEND_LINALG_INTERNAL_INTERFACE_H_ #define CYTNX_BACKEND_LINALG_INTERNAL_INTERFACE_H_ -#include #include #include "Type.hpp" diff --git a/src/backend/utils_internal_cpu/GetElems_contiguous_cpu.cpp b/src/backend/utils_internal_cpu/GetElems_contiguous_cpu.cpp index 4e5b9d054..80115262e 100644 --- a/src/backend/utils_internal_cpu/GetElems_contiguous_cpu.cpp +++ b/src/backend/utils_internal_cpu/GetElems_contiguous_cpu.cpp @@ -70,7 +70,6 @@ namespace cytnx { Loc += cytnx_uint64(tmpn / new_offj[r]) * offj[r]; tmpn %= new_offj[r]; } - // std::cout << n << " " << Loc << std::endl; memcpy(new_elem_ptr_ + n * Nelem_grp, elem_ptr_ + Loc * Nelem_grp, sizeof(cytnx_double) * Nelem_grp); // new_elem_ptr_[n] = elem_ptr_[Loc]; diff --git a/src/contraction_tree.cpp b/src/contraction_tree.cpp index 43e1521fa..09e7189d2 100644 --- a/src/contraction_tree.cpp +++ b/src/contraction_tree.cpp @@ -30,7 +30,6 @@ namespace cytnx { if (!nodes_container.empty()) { auto root = nodes_container.back(); - // std::cout << "Setting root pointers from " << root->name << std::endl; root->set_root_ptrs(); } } @@ -60,14 +59,10 @@ namespace cytnx { // change address. for (cytnx_uint64 i = 0; i < tokens.size(); i++) { tok = str_strip(tokens[i]); // remove space. - // cout << tokens[i] << "|" << tok << "|" << endl; if (tok.length() == 0) continue; - // cout << tok << "|"; if (tok == "(") { operators.push(tok.c_str()[0]); - // cout << "put(" << endl; } else if (tok == ")") { - // cout << "put)-->"; if (!operators.empty()) { topc = operators.top(); while ((topc != '(')) { @@ -85,10 +80,8 @@ namespace cytnx { break; } } - // cout << endl; operators.pop(); // discard the '(' } else if (tok == ",") { - // cout << "put,-->"; if (!operators.empty()) { topc = operators.top(); while ((topc != '(') && (topc != ')')) { @@ -106,7 +99,6 @@ namespace cytnx { break; } } - // cout << endl; operators.push(','); } else { cytnx_uint64 idx; @@ -134,13 +126,6 @@ namespace cytnx { this->nodes_container.push_back(new_node); stk.push(this->nodes_container.back()); } - /* - cout << "============" << endl; - for(int i=0;inodes_container.size();i++){ - cout << this->nodes_container[i].name << endl; - } - cout << "============" << endl; - */ } } // namespace cytnx diff --git a/src/linalg/Conj.cpp b/src/linalg/Conj.cpp index 504be5b73..53eced9c1 100644 --- a/src/linalg/Conj.cpp +++ b/src/linalg/Conj.cpp @@ -1,5 +1,4 @@ #include "linalg.hpp" -#include #include "Tensor.hpp" #include "UniTensor.hpp" diff --git a/src/linalg/Conj_.cpp b/src/linalg/Conj_.cpp index c0edca8e9..e2352e46c 100644 --- a/src/linalg/Conj_.cpp +++ b/src/linalg/Conj_.cpp @@ -1,6 +1,5 @@ #include "linalg.hpp" #include "Tensor.hpp" -#include #ifdef BACKEND_TORCH diff --git a/src/linalg/Cpr.cpp b/src/linalg/Cpr.cpp index e6214b3a6..b0300a73e 100644 --- a/src/linalg/Cpr.cpp +++ b/src/linalg/Cpr.cpp @@ -1,6 +1,5 @@ #include "linalg.hpp" -#include #include "Tensor.hpp" #ifdef BACKEND_TORCH @@ -15,7 +14,6 @@ namespace cytnx { "[Cpr] error, the two tensor does not have the same shape.%s", "\n"); cytnx_error_msg(Lt.device() != Rt.device(), "[Cpr] error, two tensor cannot on different devices.%s", "\n"); - // std::cout << "g1 Cpr" << std::endl; Tensor out(Lt.shape(), Type.Bool, Lt.device()); // if contiguous, then no need to calculate the mappers diff --git a/src/linalg/Det.cpp b/src/linalg/Det.cpp index ae796c508..9373e8d8c 100644 --- a/src/linalg/Det.cpp +++ b/src/linalg/Det.cpp @@ -1,6 +1,5 @@ #include "linalg.hpp" -#include #include "Tensor.hpp" #ifdef BACKEND_TORCH diff --git a/src/linalg/Div.cpp b/src/linalg/Div.cpp index 1208cd89b..1b96fa128 100644 --- a/src/linalg/Div.cpp +++ b/src/linalg/Div.cpp @@ -609,7 +609,6 @@ namespace cytnx { // Tensor out(Lt.shape(),Type.Int32 < Lt.dtype()?Type.Int32:Lt.dtype(),Lt.device()); if (Lt.device() == Device.cpu) { - // std::cout << "chk" << std::endl; cytnx::linalg_internal::lii.Ari_ii[Lt.dtype()][Type.Int32]( out._impl->storage()._impl, Lt._impl->storage()._impl, Cnst._impl, Lt._impl->storage()._impl->size(), {}, {}, {}, 3); diff --git a/src/linalg/Dot.cpp b/src/linalg/Dot.cpp index b25ed54a5..666e05480 100644 --- a/src/linalg/Dot.cpp +++ b/src/linalg/Dot.cpp @@ -1,5 +1,4 @@ #include "linalg.hpp" -#include #include #include "Tensor.hpp" @@ -42,7 +41,6 @@ namespace cytnx { // check type: Tensor _tl = Tl.contiguous(); Tensor _tr = Tr.contiguous(); - // std::cout << "MV" << std::endl; Tensor out; std::vector newshape = Tl.shape(); newshape.pop_back(); diff --git a/src/linalg/Eig.cpp b/src/linalg/Eig.cpp index fe994e9d2..ac1f4d395 100644 --- a/src/linalg/Eig.cpp +++ b/src/linalg/Eig.cpp @@ -1,6 +1,5 @@ #include "linalg.hpp" #include "algo.hpp" -#include #include "Tensor.hpp" using namespace std; @@ -44,18 +43,13 @@ namespace cytnx { std::vector out; out.push_back(S); - // std::cout << "[Eig][V]" << std::endl; - // std::cout << V << std::endl; if (is_V) { out.push_back(V); if (!row_v) { if (out.back().dtype() == Type.ComplexFloat || out.back().dtype() == Type.ComplexDouble) { out.back().permute_({1, 0}).contiguous_(); - // std::cout << out.back(); out.back().Conj_(); - // std::cout << out.back(); - // std::cout << "ok" << std::endl; } else out.back().permute_({1, 0}).contiguous_(); } @@ -96,8 +90,6 @@ namespace cytnx { //[Note] outCyT must be empty! // DenseUniTensor: - // cout << "entry Dense UT" << endl; - Tensor tmp; if (Tin.is_contiguous()) tmp = Tin.get_block_(); @@ -153,7 +145,6 @@ namespace cytnx { strides.push_back(Tin.bonds()[i].qnums().size()); BdLeft._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } - // std::cout << BdLeft << std::endl; strides.push_back(1); auto BdRight = Tin.bonds()[Tin.rowrank()].clone(); for (int i = Tin.rowrank() + 1; i < Tin.rank(); i++) { @@ -161,8 +152,6 @@ namespace cytnx { BdRight._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } strides.push_back(1); - // std::cout << BdRight << std::endl; - // std::cout << strides << std::endl; // 2) making new inner_to_outer_idx lists for each block: // -> a. get stride: @@ -172,7 +161,6 @@ namespace cytnx { for (int i = Tin.rank() - 2; i >= Tin.rowrank(); i--) { strides[i] *= strides[i + 1]; } - // std::cout << strides << std::endl; // ->b. calc new inner_to_outer_idx! vec2d new_itoi(Tin.Nblocks(), std::vector(2)); @@ -186,7 +174,6 @@ namespace cytnx { new_itoi[b][1] += tmpv[cnt] * strides[cnt]; } } - // std::cout << new_itoi << std::endl; // 3) categorize: // key = qnum, val = list of block locations: @@ -209,10 +196,8 @@ namespace cytnx { for (auto const &x : mgrp) { vec2d itoi_indicators(x.second.size()); - // cout << x.second.size() << "-------" << endl; // for (int i = 0; i < x.second.size(); i++) { itoi_indicators[i] = new_itoi[x.second[i]]; - // std::cout << new_itoi[x.second[i]] << std::endl; // } auto order = vec_sort(itoi_indicators, true); std::vector Tlist(itoi_indicators.size()); @@ -234,7 +219,6 @@ namespace cytnx { // BTen is the big block!! cytnx_uint64 Cblk_dim = Tlist.size() / Rblk_dim; Tensor BTen = algo::_fx_Matric_combine(Tlist, Rblk_dim, Cblk_dim); - // std::cout << BTen; // Now we can perform linalg! aux_qnums.push_back(x.first); auto out = linalg::Eig(BTen, is_V, row_v); @@ -242,14 +226,11 @@ namespace cytnx { e_blocks.push_back(out[0]); if (is_V) { - // std::cout << row_szs << std::endl; - // std::cout << out[tr].shape() << std::endl; std::vector split_dims; for (int i = 0; i < Rblk_dim; i++) { split_dims.push_back(row_szs[i * Cblk_dim]); } std::vector blks; - // std::cout< new_shape(Tin.rowrank() + 1); diff --git a/src/linalg/Eigh.cpp b/src/linalg/Eigh.cpp index 1d518f3a3..4c3bf990d 100644 --- a/src/linalg/Eigh.cpp +++ b/src/linalg/Eigh.cpp @@ -1,6 +1,5 @@ #include "linalg.hpp" #include "algo.hpp" -#include #include "Tensor.hpp" using namespace std; @@ -18,8 +17,6 @@ namespace cytnx { cytnx_error_msg(Tin.shape()[0] != Tin.shape()[1], "[Eigh] error, Eigh should accept a square matrix.%s", "\n"); - - // std::cout << Tin << std::endl; Tensor in = Tin.contiguous(); if (Tin.dtype() > Type.Float) in = in.astype(Type.Double); @@ -44,7 +41,6 @@ namespace cytnx { out.back().dtype() == Type.ComplexDouble) { out.back().permute_({1, 0}).contiguous_(); out.back().Conj_(); - // std::cout << "ok"; } else out.back().permute_({1, 0}).contiguous_(); } @@ -68,7 +64,6 @@ namespace cytnx { out.back().dtype() == Type.ComplexDouble) { out.back().permute_({1, 0}).contiguous_(); out.back().Conj_(); - // std::cout << "ok"; } else out.back().permute_({1, 0}).contiguous_(); } @@ -89,8 +84,6 @@ namespace cytnx { //[Note] outCyT must be empty! // DenseUniTensor: - // cout << "entry Dense UT" << endl; - Tensor tmp; if (Tin.is_contiguous()) tmp = Tin.get_block_(); @@ -146,7 +139,6 @@ namespace cytnx { strides.push_back(Tin.bonds()[i].qnums().size()); BdLeft._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } - // std::cout << BdLeft << std::endl; strides.push_back(1); auto BdRight = Tin.bonds()[Tin.rowrank()].clone(); for (int i = Tin.rowrank() + 1; i < Tin.rank(); i++) { @@ -154,8 +146,6 @@ namespace cytnx { BdRight._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } strides.push_back(1); - // std::cout << BdRight << std::endl; - // std::cout << strides << std::endl; // 2) making new inner_to_outer_idx lists for each block: // -> a. get stride: @@ -165,7 +155,6 @@ namespace cytnx { for (int i = Tin.rank() - 2; i >= Tin.rowrank(); i--) { strides[i] *= strides[i + 1]; } - // std::cout << strides << std::endl; // ->b. calc new inner_to_outer_idx! vec2d new_itoi(Tin.Nblocks(), std::vector(2)); @@ -179,7 +168,6 @@ namespace cytnx { new_itoi[b][1] += tmpv[cnt] * strides[cnt]; } } - // std::cout << new_itoi << std::endl; // 3) categorize: // key = qnum, val = list of block locations: @@ -202,10 +190,8 @@ namespace cytnx { for (auto const &x : mgrp) { vec2d itoi_indicators(x.second.size()); - // cout << x.second.size() << "-------" << endl; // for (int i = 0; i < x.second.size(); i++) { itoi_indicators[i] = new_itoi[x.second[i]]; - // std::cout << new_itoi[x.second[i]] << std::endl; // } auto order = vec_sort(itoi_indicators, true); std::vector Tlist(itoi_indicators.size()); @@ -227,7 +213,6 @@ namespace cytnx { // BTen is the big block!! cytnx_uint64 Cblk_dim = Tlist.size() / Rblk_dim; Tensor BTen = algo::_fx_Matric_combine(Tlist, Rblk_dim, Cblk_dim); - // std::cout << BTen; // Now we can perform linalg! aux_qnums.push_back(x.first); auto out = linalg::Eigh(BTen, is_V, row_v); @@ -235,14 +220,11 @@ namespace cytnx { e_blocks.push_back(out[0]); if (is_V) { - // std::cout << row_szs << std::endl; - // std::cout << out[tr].shape() << std::endl; std::vector split_dims; for (int i = 0; i < Rblk_dim; i++) { split_dims.push_back(row_szs[i * Cblk_dim]); } std::vector blks; - // std::cout< new_shape(Tin.rowrank() + 1); diff --git a/src/linalg/ExpH.cpp b/src/linalg/ExpH.cpp index 22d61bd20..8878566a4 100644 --- a/src/linalg/ExpH.cpp +++ b/src/linalg/ExpH.cpp @@ -3,7 +3,6 @@ #include "Tensor.hpp" #include "UniTensor.hpp" #include "algo.hpp" -#include #include #ifdef BACKEND_TORCH @@ -42,10 +41,7 @@ namespace cytnx { u = su[1]; //[Optim required] - // cout << s << endl; s = cytnx::linalg::Diag(s); - // cout << s << endl; - // cout << u; ut = su[1].clone(); if (Type.is_complex(ut.dtype())) { ut.permute_({1, 0}).Conj_(); @@ -53,7 +49,6 @@ namespace cytnx { ut.permute_({1, 0}); } ut.contiguous_(); - // cout << ut; ut = cytnx::linalg::Matmul(s, ut); ut = cytnx::linalg::Matmul(u, ut); @@ -123,7 +118,6 @@ namespace cytnx { strides.push_back(Tin.bonds()[i].qnums().size()); BdLeft._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } - // std::cout << BdLeft << std::endl; strides.push_back(1); auto BdRight = Tin.bonds()[Tin.rowrank()].clone(); for (int i = Tin.rowrank() + 1; i < Tin.rank(); i++) { @@ -140,7 +134,6 @@ namespace cytnx { for (int i = Tin.rank() - 2; i >= Tin.rowrank(); i--) { strides[i] *= strides[i + 1]; } - // std::cout << strides << std::endl; // ->b. calc new inner_to_outer_idx! vec2d new_itoi(Tin.Nblocks(), std::vector(2)); @@ -167,10 +160,8 @@ namespace cytnx { std::vector &out_blocks_ = ((BlockUniTensor *)out._impl.get())->_blocks; for (auto const &x : mgrp) { vec2d itoi_indicators(x.second.size()); - // cout << x.second.size() << "-------" << endl; for (int i = 0; i < x.second.size(); i++) { itoi_indicators[i] = new_itoi[x.second[i]]; - // std::cout << new_itoi[x.second[i]] << std::endl; } auto order = vec_sort(itoi_indicators, true); std::vector Tlist(itoi_indicators.size()); diff --git a/src/linalg/ExpM.cpp b/src/linalg/ExpM.cpp index 1e776c5e2..dae232f9c 100644 --- a/src/linalg/ExpM.cpp +++ b/src/linalg/ExpM.cpp @@ -3,7 +3,6 @@ #include "Tensor.hpp" #include "UniTensor.hpp" #include "algo.hpp" -#include #include #ifdef BACKEND_TORCH @@ -25,7 +24,6 @@ namespace cytnx { "[ExpH] error, ExpM can only operator on square Tensor (#row = #col%s", "\n"); vector su = cytnx::linalg::Eig(Tin, true); - // cout << su[0] << su[1] << endl; Tensor s, u, ut; if (a == 0) return cytnx::linalg::Diag(cytnx::ones(Tin.shape()[0])); @@ -37,10 +35,7 @@ namespace cytnx { u = su[1]; //[Optim required] - // cout << s << endl; s = cytnx::linalg::Diag(s); - // cout << s << endl; - // cout << u; ut = InvM(su[1]); ut = cytnx::linalg::Matmul(s, ut); @@ -109,7 +104,6 @@ namespace cytnx { strides.push_back(Tin.bonds()[i].qnums().size()); BdLeft._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } - // std::cout << BdLeft << std::endl; strides.push_back(1); auto BdRight = Tin.bonds()[Tin.rowrank()].clone(); for (int i = Tin.rowrank() + 1; i < Tin.rank(); i++) { @@ -126,7 +120,6 @@ namespace cytnx { for (int i = Tin.rank() - 2; i >= Tin.rowrank(); i--) { strides[i] *= strides[i + 1]; } - // std::cout << strides << std::endl; // ->b. calc new inner_to_outer_idx! vec2d new_itoi(Tin.Nblocks(), std::vector(2)); @@ -153,10 +146,8 @@ namespace cytnx { std::vector &out_blocks_ = ((BlockUniTensor *)out._impl.get())->_blocks; for (auto const &x : mgrp) { vec2d itoi_indicators(x.second.size()); - // cout << x.second.size() << "-------" << endl; for (int i = 0; i < x.second.size(); i++) { itoi_indicators[i] = new_itoi[x.second[i]]; - // std::cout << new_itoi[x.second[i]] << std::endl; } auto order = vec_sort(itoi_indicators, true); std::vector Tlist(itoi_indicators.size()); diff --git a/src/linalg/Gemm.cpp b/src/linalg/Gemm.cpp index 4245b1ee4..a62f64d17 100644 --- a/src/linalg/Gemm.cpp +++ b/src/linalg/Gemm.cpp @@ -1,6 +1,5 @@ #include "linalg.hpp" -#include #include "Tensor.hpp" #include "Generator.hpp" @@ -110,9 +109,6 @@ namespace cytnx { Tensor Gemm(const Scalar &a, const Tensor &x, const Tensor &y) { // ax*y -> out - // std::cout << "matmul" << std::endl; - // std::cout << Tl << Tr << std::endl; - cytnx_error_msg(x.shape().size() != 2, "[Gemm_] error, tensor x , Gemm can only operate on rank-2 Tensor.%s", "\n"); cytnx_error_msg(y.shape().size() != 2, diff --git a/src/linalg/Gemm_Batch.cpp b/src/linalg/Gemm_Batch.cpp index a2f060cc4..0813ceaa4 100644 --- a/src/linalg/Gemm_Batch.cpp +++ b/src/linalg/Gemm_Batch.cpp @@ -1,5 +1,4 @@ #include "linalg.hpp" -#include #include "Tensor.hpp" #include "Generator.hpp" diff --git a/src/linalg/Gesvd.cpp b/src/linalg/Gesvd.cpp index a48157ccb..f6e0d007e 100644 --- a/src/linalg/Gesvd.cpp +++ b/src/linalg/Gesvd.cpp @@ -1,4 +1,3 @@ -#include #include #include @@ -26,8 +25,6 @@ namespace cytnx { Tensor in = Tin.contiguous(); if (Tin.dtype() > Type.Float) in = in.astype(Type.Double); - // std::cout << n_singlu << std::endl; - Tensor U, S, vT; S.Init({n_singlu}, in.dtype() <= 2 ? in.dtype() + 2 : in.dtype(), in.device()); // if type is complex, S should be real @@ -90,8 +87,6 @@ namespace cytnx { //[Note] outCyT must be empty! // DenseUniTensor: - // cout << "entry Dense UT" << endl; - Tensor tmp; if (Tin.is_contiguous()) tmp = Tin.get_block_(); @@ -123,7 +118,6 @@ namespace cytnx { Cy_S.Init({newBond, newBond}, {std::string("_aux_L"), std::string("_aux_R")}, 1, Type.Double, Tin.device(), true); // it is just reference so no hurt to alias ^^ - // cout << "[AFTER INIT]" << endl; Cy_S.put_block_(outT[t]); t++; @@ -150,7 +144,6 @@ namespace cytnx { outT[t].reshape_(shapevT); Cy_vT.Init(outT[t], false, 1); - // cout << shapevT.size() << endl; vector labelvT(shapevT.size()); labelvT[0] = Cy_S.labels()[1]; // memcpy(&labelvT[1], &oldlabel[Tin.rowrank()], sizeof(cytnx_int64) * (labelvT.size() - @@ -202,7 +195,6 @@ namespace cytnx { strides.push_back(Tin.bonds()[i].qnums().size()); BdLeft._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } - // std::cout << BdLeft << std::endl; strides.push_back(1); auto BdRight = Tin.bonds()[Tin.rowrank()].clone(); for (int i = Tin.rowrank() + 1; i < Tin.rank(); i++) { @@ -210,8 +202,6 @@ namespace cytnx { BdRight._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } strides.push_back(1); - // std::cout << BdRight << std::endl; - // std::cout << strides << std::endl; // 2) making new inner_to_outer_idx lists for each block: // -> a. get stride: @@ -221,7 +211,6 @@ namespace cytnx { for (int i = Tin.rank() - 2; i >= Tin.rowrank(); i--) { strides[i] *= strides[i + 1]; } - // std::cout << strides << std::endl; // ->b. calc new inner_to_outer_idx! vec2d new_itoi(Tin.Nblocks(), std::vector(2)); @@ -235,7 +224,6 @@ namespace cytnx { new_itoi[b][1] += tmpv[cnt] * strides[cnt]; } } - // std::cout << new_itoi << std::endl; // 3) categorize: // key = qnum, val = list of block locations: @@ -259,10 +247,8 @@ namespace cytnx { int tr; for (auto const &x : mgrp) { vec2d itoi_indicators(x.second.size()); - // cout << x.second.size() << "-------" << endl; for (int i = 0; i < x.second.size(); i++) { itoi_indicators[i] = new_itoi[x.second[i]]; - // std::cout << new_itoi[x.second[i]] << std::endl; } auto order = vec_sort(itoi_indicators, true); std::vector Tlist(itoi_indicators.size()); @@ -293,8 +279,6 @@ namespace cytnx { tr = 1; if (is_U) { - // std::cout << row_szs << std::endl; - // std::cout << out[tr].shape() << std::endl; std::vector split_dims; for (int i = 0; i < Rblk_dim; i++) { split_dims.push_back(row_szs[i * Cblk_dim]); @@ -422,7 +406,6 @@ namespace cytnx { strides.push_back(Tin.bonds()[i].qnums().size()); BdLeft._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } - // std::cout << BdLeft << std::endl; strides.push_back(1); auto BdRight = Tin.bonds()[Tin.rowrank()].clone(); for (int i = Tin.rowrank() + 1; i < Tin.rank(); i++) { @@ -430,8 +413,6 @@ namespace cytnx { BdRight._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } strides.push_back(1); - // std::cout << BdRight << std::endl; - // std::cout << strides << std::endl; // 2) making new inner_to_outer_idx lists for each block: // -> a. get stride: @@ -441,7 +422,6 @@ namespace cytnx { for (int i = Tin.rank() - 2; i >= Tin.rowrank(); i--) { strides[i] *= strides[i + 1]; } - // std::cout << strides << std::endl; // ->b. calc new inner_to_outer_idx! vec2d new_itoi(Tin.Nblocks(), std::vector(2)); @@ -455,7 +435,6 @@ namespace cytnx { new_itoi[b][1] += tmpv[cnt] * strides[cnt]; } } - // std::cout << new_itoi << std::endl; // 3) categorize: // key = qnum, val = list of block locations: @@ -479,10 +458,8 @@ namespace cytnx { int tr; for (auto const &x : mgrp) { vec2d itoi_indicators(x.second.size()); - // cout << x.second.size() << "-------" << endl; for (int i = 0; i < x.second.size(); i++) { itoi_indicators[i] = new_itoi[x.second[i]]; - // std::cout << new_itoi[x.second[i]] << std::endl; } auto order = vec_sort(itoi_indicators, true); std::vector Tlist(itoi_indicators.size()); @@ -520,8 +497,6 @@ namespace cytnx { tr = 1; if (is_U) { - // std::cout << row_szs << std::endl; - // std::cout << out[tr].shape() << std::endl; std::vector split_dims; for (int i = 0; i < Rblk_dim; i++) { split_dims.push_back(row_szs[i * Cblk_dim]); diff --git a/src/linalg/Hosvd.cpp b/src/linalg/Hosvd.cpp index f6eb1ef3a..d52c7ae1b 100644 --- a/src/linalg/Hosvd.cpp +++ b/src/linalg/Hosvd.cpp @@ -2,7 +2,6 @@ #include "Tensor.hpp" #include "UniTensor.hpp" -#include #include #ifdef BACKEND_TORCH diff --git a/src/linalg/Kron.cpp b/src/linalg/Kron.cpp index 71b38d39e..293fc462c 100644 --- a/src/linalg/Kron.cpp +++ b/src/linalg/Kron.cpp @@ -1,7 +1,6 @@ #include "linalg.hpp" #include "utils/utils.hpp" #include "Device.hpp" -#include #include "Tensor.hpp" #ifdef BACKEND_TORCH diff --git a/src/linalg/Lanczos.cpp b/src/linalg/Lanczos.cpp index 70b54a029..d27fb5cce 100644 --- a/src/linalg/Lanczos.cpp +++ b/src/linalg/Lanczos.cpp @@ -131,7 +131,7 @@ namespace cytnx { // return Lanczos(Hop, Tin, "SA", Maxiter, CvgCrit, 1, is_V, 0, verbose); } else { cytnx_error_msg( - 1, "[ERROR][Lanczos] Invalid Lanczos method, should be either 'ER' or 'Gnd'.%s", "\n"); + true, "[ERROR][Lanczos] Invalid Lanczos method, should be either 'ER' or 'Gnd'.%s", "\n"); return std::vector(); } } // Lanczos @@ -142,7 +142,7 @@ namespace cytnx { const cytnx_uint32 &max_krydim, const bool &verbose) { if (method == "ER") { cytnx_error_msg( - 1, "[ERROR][Lanczos] Lanczos method 'ER' for UniTensor is under developing!.%s", "\n"); + true, "[ERROR][Lanczos] Lanczos method 'ER' for UniTensor is under developing!.%s", "\n"); return std::vector(); } else if (method == "Gnd") { cytnx_error_msg(k > 1, "[ERROR][Lanczos] Only k = 1 is supported for 'Gnd' method.%s", @@ -154,7 +154,7 @@ namespace cytnx { // return Lanczos(Hop, Tin, "SA", Maxiter, CvgCrit, 1, is_V, 0, verbose); } else { cytnx_error_msg( - 1, "[ERROR][Lanczos] Invalid Lanczos method, should be either 'ER' or 'Gnd'.%s", "\n"); + true, "[ERROR][Lanczos] Invalid Lanczos method, should be either 'ER' or 'Gnd'.%s", "\n"); return std::vector(); } } // Lanczos diff --git a/src/linalg/Lanczos_ER.cpp b/src/linalg/Lanczos_ER.cpp index bdfb7a305..7da9d49a4 100644 --- a/src/linalg/Lanczos_ER.cpp +++ b/src/linalg/Lanczos_ER.cpp @@ -18,7 +18,6 @@ namespace cytnx { const cytnx_uint32 &max_krydim, const cytnx_uint64 &maxiter, const double &CvgCrit, const bool &verbose) { std::vector converged_ev; - // std::cout << max_krydim << std::endl; for (cytnx_int32 ik = 0; ik < k; ik++) { cytnx_uint64 krydim = max_krydim; // initialize @@ -116,7 +115,6 @@ namespace cytnx { const double &CvgCrit, const bool &verbose){ std::vector converged_ev; - //std::cout << max_krydim << std::endl; for(cytnx_int32 ik=0;ikdevice()); @@ -226,7 +224,6 @@ namespace cytnx { const double &CvgCrit, const bool &verbose){ std::vector converged_ev; - //std::cout << max_krydim << std::endl; for(cytnx_int32 ik=0;ikdevice()); @@ -324,7 +321,6 @@ namespace cytnx { const double &CvgCrit, const bool &verbose){ std::vector converged_ev; - //std::cout << max_krydim << std::endl; for(cytnx_int32 ik=0;ikdevice()); @@ -423,11 +419,9 @@ namespace cytnx { const double &CvgCrit, const bool &verbose){ std::vector converged_ev; - //std::cout << max_krydim << std::endl; for(cytnx_int32 ik=0;ikdevice()); - //std::cout << "cool" << std::endl; double Elast = DBL_MAX; // this is temporary, so let's put it on CPU. bool cvg = false; @@ -554,8 +548,6 @@ namespace cytnx { buffer[0] = Tin.astype(Hop->dtype()); } - // std::cout << "[entry] LER" << std::endl; - std::vector out; if (is_V) out.resize(2); @@ -564,7 +556,6 @@ namespace cytnx { out[0] = zeros({k}, Type.is_complex(Hop->dtype()) ? Hop->dtype() + 2 : Hop->dtype(), Hop->device()); - // std::cout << "[entry] LER 2" << std::endl; double _cvgcrit = CvgCrit; if (Hop->dtype() == Type.Float || Hop->dtype() == Type.ComplexFloat) { diff --git a/src/linalg/Lanczos_Exp.cpp b/src/linalg/Lanczos_Exp.cpp index fd77db46c..299c43a6a 100644 --- a/src/linalg/Lanczos_Exp.cpp +++ b/src/linalg/Lanczos_Exp.cpp @@ -1,15 +1,16 @@ -#include "linalg.hpp" -#include "Generator.hpp" -#include "random.hpp" -#include "Tensor.hpp" -#include "LinOp.hpp" - #include -#include #include +#include +#include +#include + +#include "Generator.hpp" +#include "LinOp.hpp" +#include "Tensor.hpp" #include "UniTensor.hpp" +#include "linalg.hpp" +#include "random.hpp" #include "utils/vec_print.hpp" -#include #ifdef BACKEND_TORCH #else @@ -218,11 +219,6 @@ namespace cytnx { VkDag_labels.push_back(label_kr); VkDag_ut.relabel_(VkDag_labels); - // Vk_ut.print_diagram(); - // VkDag_ut.print_diagram(); - // v0.print_diagram(); - // B.print_diagram(); - out = Contracts({v0, VkDag_ut, B}, "", true); out = Contract(out, Vk_ut); out.set_rowrank_(v0.rowrank()); @@ -309,7 +305,6 @@ namespace cytnx { break; } } - // std::cout << B_mat; // Let V_k be the n × (k + 1) matrix whose columns are v[0],...,v[k] respectively. UniTensor Vk_ut(Vk); diff --git a/src/linalg/Lanczos_Gnd.cpp b/src/linalg/Lanczos_Gnd.cpp index 882670d0a..c796257a7 100644 --- a/src/linalg/Lanczos_Gnd.cpp +++ b/src/linalg/Lanczos_Gnd.cpp @@ -1,13 +1,13 @@ -#include "linalg.hpp" -#include "Generator.hpp" -#include "random.hpp" -#include "Tensor.hpp" -#include "LinOp.hpp" - #include +#include +#include #include + +#include "Generator.hpp" +#include "LinOp.hpp" #include "Tensor.hpp" -#include +#include "linalg.hpp" +#include "random.hpp" #ifdef BACKEND_TORCH #else @@ -43,10 +43,7 @@ namespace cytnx { new_psi = Hop->matvec(psi_1); As(0) = linalg::Vectordot(new_psi, psi_1, true).item(); - // cout << (new_psi); new_psi -= As(0) * psi_1; - // cout << (new_psi); - // exit(1); Bs(0) = new_psi.Norm(); @@ -62,9 +59,7 @@ namespace cytnx { // iteration LZ: for (unsigned int i = 1; i < Maxiter; i++) { - // cout << "iter:" << i << "print Hv" << endl; new_psi = Hop->matvec(psi_1); //- Bs(i-1)*psi_0; - // cout << new_psi << endl; As.append(linalg::Vectordot(new_psi, psi_1, true).item()); @@ -107,8 +102,6 @@ namespace cytnx { } // iteration - // cout << As << endl; - if (cvg_fin == false) { cytnx_warning_msg(true, "[WARNING] iteration not converge after Maxiter!.\n :: Note :: ignore if " @@ -170,10 +163,7 @@ namespace cytnx { //------------------------------------------------- new_psi = Hop->matvec(psi_1); As(0) = linalg::Vectordot(new_psi,psi_1).item(); - //cout << (new_psi); new_psi -= As(0)*psi_1; - //cout << (new_psi); - //exit(1); Bs(0) = new_psi.Norm(); psi_0 = psi_1; @@ -282,12 +272,8 @@ namespace cytnx { // i=0 //------------------------------------------------- new_psi = Hop->matvec(psi_1).astype(Type.Float); - //cout << Scalar(linalg::Vectordot(new_psi,psi_1).item()) << endl; As(0) = linalg::Vectordot(new_psi,psi_1).item(); - //cout << (new_psi); new_psi -= As(0)*psi_1; - //cout << (new_psi); - //exit(1); Bs(0) = new_psi.Norm(); psi_0 = psi_1; @@ -391,7 +377,6 @@ namespace cytnx { // check criteria and maxiter: cytnx_error_msg(CvgCrit <= 0, "[ERROR][Lanczos] converge criteria must >0%s", "\n"); cytnx_error_msg(Maxiter < 2, "[ERROR][Lanczos] Maxiter must >1%s", "\n"); - // cout << Tin << endl; // check Tin should be rank-1: Tensor v0; diff --git a/src/linalg/Lanczos_Gnd_Ut.cpp b/src/linalg/Lanczos_Gnd_Ut.cpp index 4d1cf3f02..9d23e9c91 100644 --- a/src/linalg/Lanczos_Gnd_Ut.cpp +++ b/src/linalg/Lanczos_Gnd_Ut.cpp @@ -1,15 +1,16 @@ -#include "linalg.hpp" -#include "Generator.hpp" -#include "random.hpp" -#include "Tensor.hpp" -#include "LinOp.hpp" - #include -#include #include +#include +#include +#include + +#include "Generator.hpp" +#include "LinOp.hpp" +#include "Tensor.hpp" #include "UniTensor.hpp" +#include "linalg.hpp" +#include "random.hpp" #include "utils/vec_print.hpp" -#include #ifdef BACKEND_TORCH #else diff --git a/src/linalg/Lstsq.cpp b/src/linalg/Lstsq.cpp index aa08b3182..41f6d6335 100644 --- a/src/linalg/Lstsq.cpp +++ b/src/linalg/Lstsq.cpp @@ -1,5 +1,4 @@ #include "linalg.hpp" -#include #include "Tensor.hpp" #include "Generator.hpp" diff --git a/src/linalg/Matmul.cpp b/src/linalg/Matmul.cpp index e9617f09c..b95f04416 100644 --- a/src/linalg/Matmul.cpp +++ b/src/linalg/Matmul.cpp @@ -1,6 +1,5 @@ #include "linalg.hpp" -#include #include "Tensor.hpp" #ifdef BACKEND_TORCH @@ -10,9 +9,6 @@ namespace cytnx { namespace linalg { Tensor Matmul(const Tensor &Tl, const Tensor &Tr) { - // std::cout << "matmul" << std::endl; - // std::cout << Tl << Tr << std::endl; - cytnx_error_msg(Tl.shape().size() != 2, "[Matmul] error, tensor Tl ,Matmul can only operate on rank-2 Tensor.%s", "\n"); @@ -64,10 +60,6 @@ namespace cytnx { cytnx::linalg_internal::lii.cuMatmul_ii[_tl.dtype()]( out._impl->storage()._impl, _tl._impl->storage()._impl, _tr._impl->storage()._impl, _tl.shape()[0], _tl.shape()[1], _tr.shape()[1]); - - // std::cout << "GPU Matmul OUT" << std::endl; - // std::cout << out < #ifdef BACKEND_TORCH #else @@ -64,15 +63,9 @@ namespace cytnx { } else { #ifdef UNI_GPU checkCudaErrors(cudaSetDevice(Tl.device())); - // std::cout << _tl << std::endl; - // std::cout << _tr << std::endl; cytnx::linalg_internal::lii.cuMatmul_dg_ii[_tl.dtype()]( out._impl->storage()._impl, _tl._impl->storage()._impl, _tr._impl->storage()._impl, _tl.shape()[0], _tl.shape().back(), _tr.shape().back(), diag_L); - - // std::cout << "GPU Matmul OUT" << std::endl; - // std::cout << out < Tensor Mul(const cytnx_complex128 &lc, const Tensor &Rt) { - // std::cout << "entroy" << std::endl; Storage Cnst(1, Type.ComplexDouble, Rt.device()); Cnst.at(0) = lc; Tensor out; diff --git a/src/linalg/Norm.cpp b/src/linalg/Norm.cpp index 10e85d0f7..5daa47b6a 100644 --- a/src/linalg/Norm.cpp +++ b/src/linalg/Norm.cpp @@ -1,5 +1,4 @@ #include "linalg.hpp" -#include #include "Tensor.hpp" #include "cytnx.hpp" #ifdef BACKEND_TORCH diff --git a/src/linalg/Outer.cpp b/src/linalg/Outer.cpp index 08667390a..f13aa2761 100644 --- a/src/linalg/Outer.cpp +++ b/src/linalg/Outer.cpp @@ -2,7 +2,6 @@ #include "utils/utils.hpp" #include "Device.hpp" #include "Tensor.hpp" -#include #ifdef BACKEND_TORCH #else diff --git a/src/linalg/Qdr.cpp b/src/linalg/Qdr.cpp index aff2d23bd..011bc9ffe 100644 --- a/src/linalg/Qdr.cpp +++ b/src/linalg/Qdr.cpp @@ -1,6 +1,5 @@ #include "linalg.hpp" #include "Tensor.hpp" -#include #include #include "UniTensor.hpp" #include "algo.hpp" @@ -25,8 +24,6 @@ namespace cytnx { Tensor in = Tin.contiguous(); if (Tin.dtype() > Type.Float) in = in.astype(Type.Double); - // std::cout << n_singlu << std::endl; - Tensor tau, Q, R, D; // D is not used here. tau.Init({n_tau}, in.dtype(), in.device()); tau.storage().set_zeros(); diff --git a/src/linalg/Qr.cpp b/src/linalg/Qr.cpp index 10b0c00a6..c622a8960 100644 --- a/src/linalg/Qr.cpp +++ b/src/linalg/Qr.cpp @@ -2,7 +2,6 @@ #include "Tensor.hpp" #include "UniTensor.hpp" #include "algo.hpp" -#include #include using namespace std; typedef cytnx::Accessor ac; @@ -25,8 +24,6 @@ namespace cytnx { Tensor in = Tin.contiguous(); if (Tin.dtype() > Type.Float) in = in.astype(Type.Double); - // std::cout << n_singlu << std::endl; - Tensor tau, Q, R, D; // D is not used here. tau.Init({n_tau}, in.dtype(), in.device()); tau.storage().set_zeros(); // if type is complex, S should be real @@ -183,7 +180,6 @@ namespace cytnx { strides.push_back(Tin.bonds()[i].qnums().size()); BdLeft._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } - // std::cout << BdLeft << std::endl; strides.push_back(1); auto BdRight = Tin.bonds()[Tin.rowrank()].clone(); for (int i = Tin.rowrank() + 1; i < Tin.rank(); i++) { @@ -191,8 +187,6 @@ namespace cytnx { BdRight._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } strides.push_back(1); - // std::cout << BdRight << std::endl; - // std::cout << strides << std::endl; // 2) making new inner_to_outer_idx lists for each block: // -> a. get stride: @@ -202,7 +196,6 @@ namespace cytnx { for (int i = Tin.rank() - 2; i >= Tin.rowrank(); i--) { strides[i] *= strides[i + 1]; } - // std::cout << strides << std::endl; // ->b. calc new inner_to_outer_idx! vec2d new_itoi(Tin.Nblocks(), std::vector(2)); @@ -216,7 +209,6 @@ namespace cytnx { new_itoi[b][1] += tmpv[cnt] * strides[cnt]; } } - // std::cout << new_itoi << std::endl; // 3) categorize: // key = qnum, val = list of block locations: @@ -241,10 +233,8 @@ namespace cytnx { cytnx_uint64 trcntr = 0; for (auto const &x : mgrp) { vec2d itoi_indicators(x.second.size()); - // cout << x.second.size() << "-------" << endl; for (int i = 0; i < x.second.size(); i++) { itoi_indicators[i] = new_itoi[x.second[i]]; - // std::cout << new_itoi[x.second[i]] << std::endl; } auto order = vec_sort(itoi_indicators, true); std::vector Tlist(itoi_indicators.size()); diff --git a/src/linalg/Rand_isometry.cpp b/src/linalg/Rand_isometry.cpp index f844a0ea9..9a85e36f9 100644 --- a/src/linalg/Rand_isometry.cpp +++ b/src/linalg/Rand_isometry.cpp @@ -1,4 +1,3 @@ -#include #include #include diff --git a/src/linalg/Rsvd.cpp b/src/linalg/Rsvd.cpp index 98a4f0d67..3aea4e389 100644 --- a/src/linalg/Rsvd.cpp +++ b/src/linalg/Rsvd.cpp @@ -102,8 +102,6 @@ namespace cytnx { //[Note] outCyT must be empty! // DenseUniTensor: - // cout << "entry Dense UT" << endl; - Tensor tmp; if (Tin.is_contiguous()) tmp = Tin.get_block_(); @@ -136,7 +134,6 @@ namespace cytnx { Cy_S.Init({newBond, newBond}, {std::string("_aux_L"), std::string("_aux_R")}, 1, Type.Double, Tin.device(), true); // it is just reference so no hurt to alias ^^ - // cout << "[AFTER INIT]" << endl; Cy_S.put_block_(outT[t]); t++; @@ -163,7 +160,6 @@ namespace cytnx { outT[t].reshape_(shapevT); Cy_vT.Init(outT[t], false, 1); - // cout << shapevT.size() << endl; std::vector labelvT(shapevT.size()); labelvT[0] = Cy_S.labels()[1]; // memcpy(&labelvT[1], &oldlabel[Tin.rowrank()], sizeof(cytnx_int64) * (labelvT.size() - diff --git a/src/linalg/Svd.cpp b/src/linalg/Svd.cpp index c819cab96..ee1f4fcf7 100644 --- a/src/linalg/Svd.cpp +++ b/src/linalg/Svd.cpp @@ -1,4 +1,3 @@ -#include #include #include @@ -26,8 +25,6 @@ namespace cytnx { Tensor in = Tin.contiguous(); if (Tin.dtype() > Type.Float) in = in.astype(Type.Double); - // std::cout << n_singlu << std::endl; - Tensor U, S, vT; S.Init({n_singlu}, in.dtype() <= 2 ? in.dtype() + 2 : in.dtype(), in.device()); // if type is complex, S should be real @@ -68,11 +65,6 @@ namespace cytnx { std::vector out; out.push_back(S); if (is_UvT) { - // cout << "Original:\n" << in << endl; - // cout << "S:\n" << S << endl; - // cout << "Recompose1!:\n" << Matmul(Matmul(U, Diag(S)), vT) << endl; - // cout << "Recompose2!:\n" - // << Tensordot(Tensordot(U, Diag(S), {1}, {0}), vT, {1}, {0}) << endl; out.push_back(U); out.push_back(vT); } @@ -99,8 +91,6 @@ namespace cytnx { //[Note] outCyT must be empty! // DenseUniTensor: - // cout << "entry Dense UT" << endl; - Tensor tmp; if (Tin.is_contiguous()) tmp = Tin.get_block_(); @@ -132,7 +122,6 @@ namespace cytnx { Cy_S.Init({newBond, newBond}, {std::string("_aux_L"), std::string("_aux_R")}, 1, Type.Double, Tin.device(), true); // it is just reference so no hurt to alias ^^ - // cout << "[AFTER INIT]" << endl; Cy_S.put_block_(outT[t]); t++; @@ -159,7 +148,6 @@ namespace cytnx { outT[t].reshape_(shapevT); Cy_vT.Init(outT[t], false, 1); - // cout << shapevT.size() << endl; vector labelvT(shapevT.size()); labelvT[0] = Cy_S.labels()[1]; // memcpy(&labelvT[1], &oldlabel[Tin.rowrank()], sizeof(cytnx_int64) * (labelvT.size() - @@ -211,7 +199,6 @@ namespace cytnx { strides.push_back(Tin.bonds()[i].qnums().size()); BdLeft._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } - // std::cout << BdLeft << std::endl; strides.push_back(1); auto BdRight = Tin.bonds()[Tin.rowrank()].clone(); for (int i = Tin.rowrank() + 1; i < Tin.rank(); i++) { @@ -219,8 +206,6 @@ namespace cytnx { BdRight._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } strides.push_back(1); - // std::cout << BdRight << std::endl; - // std::cout << strides << std::endl; // 2) making new inner_to_outer_idx lists for each block: // -> a. get stride: @@ -230,7 +215,6 @@ namespace cytnx { for (int i = Tin.rank() - 2; i >= Tin.rowrank(); i--) { strides[i] *= strides[i + 1]; } - // std::cout << strides << std::endl; // ->b. calc new inner_to_outer_idx! vec2d new_itoi(Tin.Nblocks(), std::vector(2)); @@ -244,7 +228,6 @@ namespace cytnx { new_itoi[b][1] += tmpv[cnt] * strides[cnt]; } } - // std::cout << new_itoi << std::endl; // 3) categorize: // key = qnum, val = list of block locations: @@ -268,10 +251,8 @@ namespace cytnx { int tr; for (auto const &x : mgrp) { vec2d itoi_indicators(x.second.size()); - // cout << x.second.size() << "-------" << endl; for (int i = 0; i < x.second.size(); i++) { itoi_indicators[i] = new_itoi[x.second[i]]; - // std::cout << new_itoi[x.second[i]] << std::endl; } auto order = vec_sort(itoi_indicators, true); std::vector Tlist(itoi_indicators.size()); @@ -302,8 +283,6 @@ namespace cytnx { tr = 1; if (compute_uv) { - // std::cout << row_szs << std::endl; - // std::cout << out[tr].shape() << std::endl; std::vector split_dims; for (int i = 0; i < Rblk_dim; i++) { split_dims.push_back(row_szs[i * Cblk_dim]); @@ -430,7 +409,6 @@ namespace cytnx { strides.push_back(Tin.bonds()[i].qnums().size()); BdLeft._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } - // std::cout << BdLeft << std::endl; strides.push_back(1); auto BdRight = Tin.bonds()[Tin.rowrank()].clone(); for (int i = Tin.rowrank() + 1; i < Tin.rank(); i++) { @@ -438,8 +416,6 @@ namespace cytnx { BdRight._impl->force_combineBond_(Tin.bonds()[i]._impl, false); // no grouping } strides.push_back(1); - // std::cout << BdRight << std::endl; - // std::cout << strides << std::endl; // 2) making new inner_to_outer_idx lists for each block: // -> a. get stride: @@ -449,7 +425,6 @@ namespace cytnx { for (int i = Tin.rank() - 2; i >= Tin.rowrank(); i--) { strides[i] *= strides[i + 1]; } - // std::cout << strides << std::endl; // ->b. calc new inner_to_outer_idx! vec2d new_itoi(Tin.Nblocks(), std::vector(2)); @@ -463,7 +438,6 @@ namespace cytnx { new_itoi[b][1] += tmpv[cnt] * strides[cnt]; } } - // std::cout << new_itoi << std::endl; // 3) categorize: // key = qnum, val = list of block locations: @@ -487,10 +461,8 @@ namespace cytnx { int tr; for (auto const &x : mgrp) { vec2d itoi_indicators(x.second.size()); - // cout << x.second.size() << "-------" << endl; for (int i = 0; i < x.second.size(); i++) { itoi_indicators[i] = new_itoi[x.second[i]]; - // std::cout << new_itoi[x.second[i]] << std::endl; } auto order = vec_sort(itoi_indicators, true); std::vector Tlist(itoi_indicators.size()); @@ -528,8 +500,6 @@ namespace cytnx { tr = 1; if (compute_uv) { - // std::cout << row_szs << std::endl; - // std::cout << out[tr].shape() << std::endl; std::vector split_dims; for (int i = 0; i < Rblk_dim; i++) { split_dims.push_back(row_szs[i * Cblk_dim]); diff --git a/src/linalg/Trace.cpp b/src/linalg/Trace.cpp index dae84b266..185ee0a1a 100644 --- a/src/linalg/Trace.cpp +++ b/src/linalg/Trace.cpp @@ -83,7 +83,6 @@ namespace cytnx { for (cytnx_uint64 i = 0; i < Tn.shape().size(); i++) { if (i != ax1 && i != ax2) remain_rank_id.push_back(i); } - // std::cout << "entry Trace" << std::endl; if (Tn.device() == Device.cpu) linalg_internal::lii.Trace_ii[Tn.dtype()](false, out, Tn, Ndiag, Nelem, Device.Ncpus, accu, remain_rank_id, shape, ax1, ax2); diff --git a/src/linalg/Tridiag.cpp b/src/linalg/Tridiag.cpp index 1e81de244..d643b5f6e 100644 --- a/src/linalg/Tridiag.cpp +++ b/src/linalg/Tridiag.cpp @@ -1,6 +1,5 @@ #include "linalg.hpp" -#include #include "Tensor.hpp" #ifdef BACKEND_TORCH @@ -45,9 +44,6 @@ namespace cytnx { else s_diag = Sub_diag; - // std::cout << s_diag.shape() << std::endl; - // std::cout << in_diag << std::endl; - // std::cout << s_diag << std::endl; Tensor vT, S; S.Init({Diag.shape()[0]}, cType <= 2 ? cType + 2 : cType, Device.cpu); // if type is complex, S should be real diff --git a/src/linalg/iAdd.cpp b/src/linalg/iAdd.cpp index ab062fcbb..a6f371cdc 100644 --- a/src/linalg/iAdd.cpp +++ b/src/linalg/iAdd.cpp @@ -18,8 +18,6 @@ namespace cytnx { "Rt rank: [%d] %s", Lt.shape().size(), Rt.shape().size(), "\n"); } - - // std::cout << "iadd entry" << std::endl; Storage nulls; Tensor R; diff --git a/src/ncon.cpp b/src/ncon.cpp index acd8b44f9..f5d27563a 100644 --- a/src/ncon.cpp +++ b/src/ncon.cpp @@ -82,7 +82,6 @@ namespace cytnx { } } str_order = string(needed_parentheses, '(').append(str_order); - // std::cout << str_order << std::endl; UniTensor out; Network N; N.construct(alias, labels, out_labels, 1, str_order, optimize); diff --git a/src/search_tree.cpp b/src/search_tree.cpp index c0e156753..f5909e309 100644 --- a/src/search_tree.cpp +++ b/src/search_tree.cpp @@ -1,4 +1,6 @@ #include "search_tree.hpp" + +#include #include using namespace std; diff --git a/src/stat/histogram.cpp b/src/stat/histogram.cpp index 1e5fc1b98..d1b83b382 100644 --- a/src/stat/histogram.cpp +++ b/src/stat/histogram.cpp @@ -9,10 +9,7 @@ namespace cytnx { Histogram::Histogram(const unsigned long long &Nbins, const double &min_val, const double &max_val) { - if (min_val >= max_val) { - std::cout << "[ERROR] Cannot have min >= max" << std::endl; - exit(1); - } + cytnx_error_msg(min_val >= max_val, "[ERROR] Cannot have min >= max%s", "\n"); this->min = min_val; this->max = max_val; this->bins = Nbins; @@ -38,25 +35,19 @@ namespace cytnx { this->vars = tmp.storage(); } - void Histogram::print() const { - std::cout << "[Histogram 1D] Real" << std::endl; - std::cout << "Nbins: " << this->bins << std::endl; - std::cout << "bound: [ " << this->min << " , " << this->max << " ]\n"; - std::cout << "current count: " << this->total_count << std::endl; + void Histogram::print(std::ostream &os) const { + os << "[Histogram 1D] Real" << std::endl; + os << "Nbins: " << this->bins << std::endl; + os << "bound: [ " << this->min << " , " << this->max << " ]\n"; + os << "current count: " << this->total_count << std::endl; } //-----------[2d] Histogram2d::Histogram2d(const unsigned long long &Nbinx, const unsigned long long &Nbiny, const double &min_x, const double &max_x, const double &min_y, const double &max_y) { - if (min_x >= max_x) { - std::cout << "[ERROR] Cannot have min >= max [x axis]" << std::endl; - exit(1); - } - if (min_y >= max_y) { - std::cout << "[ERROR] Cannot have min >= max [y axis]" << std::endl; - exit(1); - } + cytnx_error_msg(min_x >= max_x, "[ERROR] Cannot have min >= max [x axis]%s", "\n"); + cytnx_error_msg(min_y >= max_y, "[ERROR] Cannot have min >= max [y axis]%s", "\n"); this->minx = min_x; this->maxx = max_x; this->miny = min_y; @@ -92,12 +83,12 @@ namespace cytnx { this->vars = tmp.storage(); } - void Histogram2d::print() const { - std::cout << "[Histogram 2D] Real" << std::endl; - std::cout << "Nbins: [x= " << this->binx << " , y= " << this->biny << " ]\n"; - std::cout << "bound,x: [ " << this->minx << " , " << this->maxx << " ]\n"; - std::cout << "bound,y: [ " << this->miny << " , " << this->maxy << " ]\n"; - std::cout << "current count: " << this->total_count << std::endl; + void Histogram2d::print(std::ostream &os) const { + os << "[Histogram 2D] Real" << std::endl; + os << "Nbins: [x= " << this->binx << " , y= " << this->biny << " ]\n"; + os << "bound,x: [ " << this->minx << " , " << this->maxx << " ]\n"; + os << "bound,y: [ " << this->miny << " , " << this->maxy << " ]\n"; + os << "current count: " << this->total_count << std::endl; } } // namespace stat diff --git a/src/tn_algo/DMRG.cpp b/src/tn_algo/DMRG.cpp index 4f2c99cfa..678e25c7b 100644 --- a/src/tn_algo/DMRG.cpp +++ b/src/tn_algo/DMRG.cpp @@ -1,12 +1,14 @@ -#include "tn_algo/DMRG.hpp" +#include +#include +#include + #include "Generator.hpp" -#include "Network.hpp" #include "LinOp.hpp" +#include "Network.hpp" #include "linalg.hpp" -#include -#include -#include +#include "tn_algo/DMRG.hpp" #include "utils/vec_print.hpp" + using namespace std; #ifdef BACKEND_TORCH @@ -33,8 +35,6 @@ namespace cytnx { UniTensor &M2 = functArgs[2]; UniTensor &R = functArgs[3]; - // std::vector pshape = - // {L.shape()[1],M1.shape()[2],M2.shape()[2],R.shape()[1]}; vec_print(std::cout,pshape); this->anet.FromString({"psi: -1,-2;-3,-4", "L: ;-5,-1,0", "R: ;-7,-4,3", "M1: ;-5,-6,-2,1", "M2: ;-6,-7,-3,2", "TOUT: 0,1;2,3"}); this->anet.PutUniTensor("M2", M2); @@ -82,7 +82,6 @@ namespace cytnx { std::vector pshape = vec_cast( {L.shape()[1], M1.shape()[2], M2.shape()[2], R.shape()[1]}); - // vec_print(std::cout,pshape); this->anet.FromString({"psi: ;-1,-2,-3,-4", "L: ;-5,-1,0", "R: ;-7,-4,3", "M1: ;-5,-6,-2,1", "M2: ;-6,-7,-3,2", "TOUT: ;0,1,2,3"}); this->anet.PutUniTensor("M2", M2); @@ -110,8 +109,6 @@ namespace cytnx { auto c = linalg::Dot(r, v).item(); out += this->weight * c * r; } - // cout << counter << endl; counter++; - // cout << out << endl; return out; } }; @@ -270,7 +267,6 @@ namespace cytnx { min(min(dim_l * this->mps.phys_dim(p), dim_r * this->mps.phys_dim(p + 1)), this->mps.virt_dim()); - // cout << "bkpt1\n"; // calculate local ortho_mps: // omps = [] std::vector omps; @@ -292,13 +288,11 @@ namespace cytnx { omps.back().flatten_(); } - // cout << psi_T << endl; auto out = optimize_psi( psi_T, {this->LR[p], this->mpo.get_op(p), this->mpo.get_op(p + 1), this->LR[p + 2]}, maxit, krydim, omps, this->weight); psi_T = out[1]; Entemp = out[0].item(); - // cout << psi_T << endl; psi_T.reshape_(dim_l, this->mps.phys_dim(p), this->mps.phys_dim(p + 1), dim_r); // convert psi back to 4-leg form @@ -318,9 +312,6 @@ namespace cytnx { this->mps.data()[p] = Contract(this->mps.data()[p], s); // absorb s into next neighbor this->mps.S_loc() = p; - // A[p].print_diagram() - // A[p+1].print_diagram() - // update LR from right to left: // anet = cytnx.Network("R_AMAH.net") anet.FromString( @@ -511,7 +502,6 @@ namespace cytnx { min(min(dim_l * this->mps.phys_dim(p), dim_r * this->mps.phys_dim(p + 1)), this->mps.virt_dim()); - // cout << "bkpt1\n"; // calculate local ortho_mps: // omps = [] std::vector omps; @@ -534,18 +524,16 @@ namespace cytnx { } psi.set_rowrank(2); - // psi.print_diagram(); - // cout << psi << endl; auto out = optimize_psi_new( psi, {this->LR[p], this->mpo.get_op(p), this->mpo.get_op(p + 1), this->LR[p + 2]}, maxit, krydim, omps, this->weight); psi = out[1]; - // cout << psi << endl; Entemp = out[0].item(); - // psi.print_diagram(); - // exit(1); - // psi_T.reshape_(dim_l, this->mps.phys_dim(p), this->mps.phys_dim(p+1), dim_r); //convert - // psi back to 4-leg form psi = UniTensor(psi_T,2); psi.relabel_(lbl); + + // psi_T.reshape_(dim_l, this->mps.phys_dim(p), this->mps.phys_dim(p+1), dim_r); + // convert psi back to 4-leg form + // psi = UniTensor(psi_T,2); + // psi.relabel_(lbl); // self.Ekeep.append(Entemp); @@ -561,9 +549,6 @@ namespace cytnx { this->mps.data()[p] = Contract(this->mps.data()[p], s); // absorb s into next neighbor this->mps.S_loc() = p; - // A[p].print_diagram() - // A[p+1].print_diagram() - // update LR from right to left: // anet = cytnx.Network("R_AMAH.net") anet.FromString( diff --git a/src/tn_algo/MPS.cpp b/src/tn_algo/MPS.cpp index e94e360c6..5c627e905 100644 --- a/src/tn_algo/MPS.cpp +++ b/src/tn_algo/MPS.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include using namespace std; diff --git a/src/tn_algo/RegularMPS.cpp b/src/tn_algo/RegularMPS.cpp index ec49ce014..1459fe253 100644 --- a/src/tn_algo/RegularMPS.cpp +++ b/src/tn_algo/RegularMPS.cpp @@ -94,9 +94,7 @@ namespace cytnx { k_ov = 0; } - // vec_print(std::cout,vphys_dim); for (cytnx_int64 k = 1; k < N; k++) { - // cout << k << endl; dim1 = this->_TNs[k - 1].shape()[2]; dim2 = vphys_dim[k]; @@ -108,7 +106,6 @@ namespace cytnx { } this->_TNs[k] = UniTensor(random::normal({dim1, dim2, dim3}, 0., 1., -1), false, 2); this->_TNs[k].relabel_({to_string(2 * k), to_string(2 * k + 1), to_string(2 * k + 2)}); - // vec_print(std::cout,this->_TNs[k].shape());// << endl; } this->S_loc = -1; this->Into_Lortho(); @@ -143,7 +140,6 @@ namespace cytnx { cytnx_uint64 DR = 1; cytnx_int64 k_ov = -1; for (cytnx_int64 k = N - 1; k >= 0; k--) { - // cout << k << endl; if (std::numeric_limits::max() / vphys_dim[k] <= DR) { k_ov = k; break; @@ -166,7 +162,6 @@ namespace cytnx { DR /= vphys_dim[k]; dim3 = std::min(std::min(chi, cytnx_uint64(dim1 * dim2)), DR); } - // cout << dim1 << dim2 << dim3 << endl; this->_TNs[k] = UniTensor(zeros({dim1, dim2, dim3}), false, 2); this->_TNs[k].get_block_()(":", select[k]) = random::normal({dim1, dim3}, 0., 1.); diff --git a/src/utils/complex_arithmetic.cpp b/src/utils/complex_arithmetic.cpp index c5b8bbe76..aef59a65f 100644 --- a/src/utils/complex_arithmetic.cpp +++ b/src/utils/complex_arithmetic.cpp @@ -393,7 +393,6 @@ namespace cytnx { return ln / cytnx_complex128(rn); } cytnx_complex128 operator/(const cytnx_complex128 &ln, const cytnx_double &rn) { - // std::cout << "[arithmetic call] cd/d" << std::endl; return cytnx_complex128(ln.real() / rn, ln.imag() / rn); } cytnx_complex128 operator/(const cytnx_complex128 &ln, const cytnx_float &rn) { diff --git a/src/utils/cutensornet.cu b/src/utils/cutensornet.cu index ac641eaed..a3b0bd45d 100644 --- a/src/utils/cutensornet.cu +++ b/src/utils/cutensornet.cu @@ -1,9 +1,13 @@ -#include #include +#include + +#include +#include #include #include -#include + #include + #include "cutensornet.hpp" #ifdef UNI_GPU @@ -69,7 +73,6 @@ namespace cytnx { // type_mapper[Type.ComplexFloat] = CUDA_C_32F; // type_mapper[Type.Double] = CUDA_R_64F; // type_mapper[Type.Float] = CUDA_R_32F; - // std::cout<<"hdiewhdoiwehdiwehdiuwehdiweu"<(); // stridesIn = std::vector(); // tns = std::vector(); @@ -92,7 +95,6 @@ namespace cytnx { // // type_mapper[Type.ComplexFloat] = CUDA_C_32F; // // type_mapper[Type.Double] = CUDA_R_64F; // // type_mapper[Type.Float] = CUDA_R_32F; - // // std::cout<<"hdiewhdoiwehdiwehdiuwehdiweu"<> einsum_path; - // std::cout << "Number of contractions : " << path.numContractions << std::endl; for (int i = 0; i < path.numContractions; i++) { einsum_path.push_back( std::pair((int64_t)path.data[i].first, (int64_t)path.data[i].second)); - // std::cout << path.data[i].first << ", " << path.data[i].second << std::endl; } HANDLE_ERROR(cutensornetContractionOptimizerInfoGetAttribute( handle, optimizerInfo, CUTENSORNET_CONTRACTION_OPTIMIZER_INFO_NUM_SLICES, &numSlices, diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 4d5258b28..d7696eee0 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -1,6 +1,5 @@ #include "utils/utils.hpp" #include -#include #include namespace cytnx { From 25d3917c836842db0cf9b000f3e98b487529ebc7 Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Tue, 5 May 2026 13:43:24 +0800 Subject: [PATCH 2/3] fixed issues --- include/Gncon.hpp | 6 +++--- include/Network.hpp | 6 +++--- include/backend/Storage.hpp | 4 ++-- src/Accessor.cpp | 1 + src/Gncon.cpp | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/Gncon.hpp b/include/Gncon.hpp index 1e4aff14b..3b7cf0032 100644 --- a/include/Gncon.hpp +++ b/include/Gncon.hpp @@ -184,9 +184,9 @@ namespace cytnx { boost::intrusive_ptr out(tmp); return out; } - void PrintNet(std::ostream &os) const; - void Savefile(const std::string &fname); - ~FermionGncon(); + void PrintNet(std::ostream &os) const {}; + void Savefile(const std::string &fname){}; + ~FermionGncon(){}; }; ///@endcond diff --git a/include/Network.hpp b/include/Network.hpp index dae9f68c1..1f9491eeb 100644 --- a/include/Network.hpp +++ b/include/Network.hpp @@ -247,9 +247,9 @@ namespace cytnx { boost::intrusive_ptr out(tmp); return out; } - void PrintNet(std::ostream &os = std::cout) const; - void Savefile(const std::string &fname); - ~FermionNetwork(); + void PrintNet(std::ostream &os = std::cout) const {}; + void Savefile(const std::string &fname){}; + ~FermionNetwork(){}; }; ///@endcond diff --git a/include/backend/Storage.hpp b/include/backend/Storage.hpp index 458295e99..fda19824c 100644 --- a/include/backend/Storage.hpp +++ b/include/backend/Storage.hpp @@ -262,7 +262,7 @@ namespace cytnx { void print_elems() const { this->print(std::cout); } /// @cond - void print_elems(std::ostream &os = std::cout) const; + void print_elems(std::ostream &os) const; /// @endcond ~StorageImplementation(); @@ -773,7 +773,7 @@ namespace cytnx { @brief print the info of the Storage, including the device, dtype and size. */ - void print_info() const { this->_impl->print(std::cout); } + void print_info() const { this->_impl->print_info(std::cout); } /// @cond void print_info(std::ostream &os) const { this->_impl->print(os); } // this is a redundant function diff --git a/src/Accessor.cpp b/src/Accessor.cpp index 681698efc..4d9b30f7d 100644 --- a/src/Accessor.cpp +++ b/src/Accessor.cpp @@ -172,6 +172,7 @@ namespace cytnx { if (this->_step < 0) { for (cytnx_int64 i = r_min; i >= r_max; i += this->_step) { pos.push_back(i); + len++; } } else { for (cytnx_int64 i = r_min; i <= r_max; i += this->_step) { diff --git a/src/Gncon.cpp b/src/Gncon.cpp index 9d5569953..eb1823919 100644 --- a/src/Gncon.cpp +++ b/src/Gncon.cpp @@ -20,7 +20,7 @@ namespace cytnx { GnconType_class NtType; - std::ostream& operator<<(std::ostream& os, const Gncon& in) const { + std::ostream& operator<<(std::ostream& os, const Gncon& in) { in._impl->PrintNet(os); return os; } From 2bee797592db859394f49766c17d251a87feab82 Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Tue, 5 May 2026 17:01:04 +0800 Subject: [PATCH 3/3] fixed issue --- include/backend/Storage.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/backend/Storage.hpp b/include/backend/Storage.hpp index fda19824c..97fa69c3c 100644 --- a/include/backend/Storage.hpp +++ b/include/backend/Storage.hpp @@ -260,7 +260,7 @@ namespace cytnx { void PrintElem_byShape(std::ostream &os, const std::vector &shape, const std::vector &mapper = {}); - void print_elems() const { this->print(std::cout); } + void print_elems() const { this->print_elems(std::cout); } /// @cond void print_elems(std::ostream &os) const; /// @endcond