Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linalg.Conj(_) for UniTensor #207

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/UniTensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3305,7 +3305,7 @@ namespace cytnx {
@note Compare to Conj_(), this fucntion will create a new object UniTensor.
@see Conj_()
*/
UniTensor Conj() {
UniTensor Conj() const {
UniTensor out;
out._impl = this->_impl->Conj();
return out;
Expand Down
16 changes: 15 additions & 1 deletion include/linalg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ namespace cytnx {
2. If the object is UniTensor, then the result will depend on the UniTensor's
rowrank.
*/

namespace linalg {

// Add:
Expand Down Expand Up @@ -839,6 +838,21 @@ namespace cytnx {
*/
void Pow_(UniTensor &Tin, const double &p);

/**
* @brief Elementwise conjugate of the UniTensor
* @param[in] UT The input UniTensor.
* @return [UniTensor] The UniTensor with all element being conjugated
* @see See UniTensor.Conj() for further details
*/
cytnx::UniTensor Conj(const cytnx::UniTensor &UT);

/**
* @brief Inplace elementwise conjugate of the UniTensor
* @param[in] UT The input UniTensor.
* @see See UniTensor.Conj_() for further details
*/
void Conj_(cytnx::UniTensor &UT);

//====================================================================================
// [Tensor]
// ====================================================================================
Expand Down
15 changes: 13 additions & 2 deletions pybind/linalg_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,19 @@ void linalg_binding(py::module &m) {
m_linalg.def("InvM_", &cytnx::linalg::InvM_, py::arg("Tio"));
m_linalg.def("Inv_", &cytnx::linalg::Inv_, py::arg("Tio"), py::arg("clip"));
m_linalg.def("Inv", &cytnx::linalg::Inv, py::arg("Tio"), py::arg("clip"));
m_linalg.def("Conj", &cytnx::linalg::Conj, py::arg("Tin"));
m_linalg.def("Conj_", &cytnx::linalg::Conj_, py::arg("Tio"));

m_linalg.def(
"Conj", [](const cytnx::Tensor &Tin) { return cytnx::linalg::Conj(Tin); }, py::arg("Tin"));

m_linalg.def(
"Conj_", [](cytnx::Tensor &Tin) { cytnx::linalg::Conj_(Tin); }, py::arg("Tin"));

m_linalg.def(
"Conj", [](const cytnx::UniTensor &Tin) { return cytnx::linalg::Conj(Tin); }, py::arg("Tin"));

m_linalg.def(
"Conj_", [](cytnx::UniTensor &Tin) { cytnx::linalg::Conj_(Tin); }, py::arg("Tin"));

m_linalg.def("Matmul", &cytnx::linalg::Matmul, py::arg("T1"), py::arg("T2"));
m_linalg.def("Matmul_dg", &cytnx::linalg::Matmul_dg, py::arg("T1"), py::arg("T2"));
m_linalg.def("Diag", &cytnx::linalg::Diag, py::arg("Tin"));
Expand Down
4 changes: 4 additions & 0 deletions src/linalg/Conj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#include "linalg_internal_interface.hpp"
#include <iostream>
#include "Tensor.hpp"
#include "UniTensor.hpp"

namespace cytnx {

namespace linalg {
Tensor Conj(const Tensor &Tin) {
// cytnx_error_msg(Tin.shape().size() != 2,"[Inv] error, Inv can only operate on rank-2
Expand Down Expand Up @@ -38,5 +40,7 @@ namespace cytnx {
}
}

UniTensor Conj(const UniTensor &Tin) { return Tin.Conj(); }

} // namespace linalg
} // namespace cytnx
2 changes: 2 additions & 0 deletions src/linalg/Conj_.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ namespace cytnx {
}
}

void Conj_(UniTensor &UT) { UT.Conj_(); }

} // namespace linalg
} // namespace cytnx
9 changes: 8 additions & 1 deletion test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ pair<std::string, cytnx_int64> operator>>(const std::string &a, const cytnx_int6
return make_pair(a, qnidx);
}

// pair<std::string, cytnx_int64> operator>>(const char* a[], const cytnx_int64 &qnidx) {
// return make_pair(std::string(a), qnidx);
// }

int main(int argc, char *argv[]) {
auto ttss = lbl("a") >> 4;
auto ttss = "a"s >> 4;
// auto ttss2 = "a" >> 4

// auto ttss = lbl("a") >> 4;
return 0;

int size = 5;
Expand Down