Skip to content

Commit c987912

Browse files
committed
made force argument deprecated instead of breaking the API
1 parent ed8eac1 commit c987912

2 files changed

Lines changed: 133 additions & 36 deletions

File tree

include/UniTensor.hpp

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ namespace cytnx {
667667
}
668668

669669
void put_block(const Tensor &in, const cytnx_uint64 &idx = 0) {
670-
// We don't check the dtype for DenseUniTensor, since it'll be more convinent to change
670+
// We don't check the dtype for DenseUniTensor, since it'll be more convenient to change
671671
// DenseUniTensor's dtype
672672

673673
// cytnx_error_msg(in.dtype() != this->dtype(),
@@ -694,7 +694,7 @@ namespace cytnx {
694694
}
695695
// share view of the block
696696
void put_block_(Tensor &in, const cytnx_uint64 &idx = 0) {
697-
// We don't check the dtype for DenseUniTensor, since it'll be more convinent to change
697+
// We don't check the dtype for DenseUniTensor, since it'll be more convenient to change
698698
// DenseUniTensor's dtype
699699

700700
// cytnx_error_msg(in.dtype() != this->dtype(),
@@ -4176,6 +4176,20 @@ namespace cytnx {
41764176
return *this;
41774177
}
41784178

4179+
/**
4180+
* @deprecated This function is deprecated. Please use \n
4181+
* put_block(const Tensor &in, const cytnx_uint64 &idx) \n
4182+
* instead.
4183+
*/
4184+
[[deprecated(
4185+
"Please use "
4186+
"UniTensor &put_block(const Tensor &in, const cytnx_uint64 &idx) "
4187+
"instead.")]] UniTensor &
4188+
put_block(const Tensor &in, const cytnx_uint64 &idx, const bool &force) {
4189+
this->_impl->put_block(in, idx);
4190+
return *this;
4191+
}
4192+
41794193
/**
41804194
@brief Put the block into the UniTensor with given quantum number.
41814195
@param[in] in_tens the block you want to put into UniTensor
@@ -4187,6 +4201,20 @@ namespace cytnx {
41874201
return *this;
41884202
}
41894203

4204+
/**
4205+
* @deprecated This function is deprecated. Please use \n
4206+
* put_block(const Tensor &in_tens, const std::vector<cytnx_int64> &qidx) \n
4207+
* instead.
4208+
*/
4209+
[[deprecated(
4210+
"Please use "
4211+
"UniTensor &put_block(const Tensor &in_tens, const std::vector<cytnx_int64> &qidx) "
4212+
"instead.")]] UniTensor &
4213+
put_block(const Tensor &in_tens, const std::vector<cytnx_int64> &qidx, const bool &force) {
4214+
this->_impl->put_block(in_tens, qidx);
4215+
return *this;
4216+
}
4217+
41904218
/**
41914219
* @brief Put the block into the UniTensor with given quantum indices, will copy the input
41924220
* tensor.
@@ -4219,6 +4247,21 @@ namespace cytnx {
42194247
return *this;
42204248
}
42214249

4250+
/**
4251+
* @deprecated This function is deprecated. Please use \n
4252+
* put_block(Tensor &in, const std::vector<std::string> &lbls, const std::vector<cytnx_int64>
4253+
* &qidx) \n instead.
4254+
*/
4255+
[[deprecated(
4256+
"Please use "
4257+
"UniTensor &put_block(Tensor &in, const std::vector<std::string> &lbls, const "
4258+
"std::vector<cytnx_int64> &qidx) "
4259+
"instead.")]] UniTensor &
4260+
put_block(Tensor &in, const std::vector<std::string> &lbls,
4261+
const std::vector<cytnx_int64> &qidx, const bool &force) {
4262+
return put_block(in, lbls, qidx);
4263+
}
4264+
42224265
/**
42234266
@brief Put the block into the UniTensor with given index, inplacely.
42244267
@note the put block will have shared view with the internal block, i.e. non-clone.
@@ -4239,6 +4282,20 @@ namespace cytnx {
42394282
return *this;
42404283
}
42414284

4285+
/**
4286+
* @deprecated This function is deprecated. Please use \n
4287+
* put_block_(Tensor &in, const std::vector<cytnx_int64> &qidx) \n
4288+
* instead.
4289+
*/
4290+
[[deprecated(
4291+
"Please use "
4292+
"UniTensor &put_block_(Tensor &in, const std::vector<cytnx_int64> &qidx) "
4293+
"instead.")]] UniTensor &
4294+
put_block_(Tensor &in, const std::vector<cytnx_int64> &qidx, const bool &force) {
4295+
this->_impl->put_block_(in, qidx);
4296+
return *this;
4297+
}
4298+
42424299
/**
42434300
* @brief Put the block into the UniTensor with given quantum indices, inplacely.
42444301
* @note the put block will have shared view with the internal block, i.e. non-clone.
@@ -4273,6 +4330,22 @@ namespace cytnx {
42734330
in.permute_(new_order);
42744331
return *this;
42754332
}
4333+
4334+
/**
4335+
* @deprecated This function is deprecated. Please use \n
4336+
* put_block_(Tensor &in, const std::vector<std::string> &lbls, const std::vector<cytnx_int64>
4337+
* &qidx) \n instead.
4338+
*/
4339+
[[deprecated(
4340+
"Please use "
4341+
"UniTensor &put_block_(Tensor &in, const std::vector<std::string> &lbls, const "
4342+
"std::vector<cytnx_int64> &qidx) "
4343+
"instead.")]] UniTensor &
4344+
put_block_(Tensor &in, const std::vector<std::string> &lbls,
4345+
const std::vector<cytnx_int64> &qidx, const bool &force) {
4346+
return put_block_(in, lbls, qidx);
4347+
}
4348+
42764349
UniTensor get(const std::vector<Accessor> &accessors) const {
42774350
UniTensor out;
42784351
out._impl = this->_impl->get(accessors);

pybind/unitensor_py.cpp

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -665,90 +665,76 @@ void unitensor_binding(py::module &m) {
665665

666666
.def("group_basis_", &UniTensor::group_basis_)
667667
.def("group_basis", &UniTensor::group_basis)
668-
.def(
669-
"get_block",
668+
.def("get_block",
670669
[](const UniTensor &self, const cytnx_uint64 &idx) { return self.get_block(idx); },
671670
py::arg("idx") = (cytnx_uint64)(0))
672671

673-
.def(
674-
"get_block",
672+
.def("get_block",
675673
[](const UniTensor &self, const std::vector<cytnx_int64> &qnum, const bool &force) {
676674
return self.get_block(qnum, force);
677675
},
678676
py::arg("qnum"), py::arg("force") = false)
679-
.def(
680-
"get_block",
677+
.def("get_block",
681678
[](const UniTensor &self, const std::vector<cytnx_uint64> &qnum, const bool &force) {
682679
return self.get_block(qnum, force);
683680
},
684681
py::arg("qnum"), py::arg("force") = false)
685682

686-
.def(
687-
"get_block",
683+
.def("get_block",
688684
[](const UniTensor &self, const std::vector<std::string> &label, const std::vector<cytnx_int64> &qnum, const bool &force) {
689685
return self.get_block(label, qnum, force);
690686
},
691687
py::arg("labels"), py::arg("qnum"), py::arg("force") = false)
692-
.def(
693-
"get_block",
688+
.def("get_block",
694689
[](const UniTensor &self, const std::vector<std::string> &label, const std::vector<cytnx_uint64> &qnum, const bool &force) {
695690
return self.get_block(label,qnum, force);
696691
},
697692
py::arg("labels"), py::arg("qnum"), py::arg("force") = false)
698-
.def(
699-
"get_block_",
693+
.def("get_block_",
700694
[](UniTensor &self, const std::vector<cytnx_int64> &qnum, const bool &force) {
701695
return self.get_block_(qnum, force);
702696
},
703697
py::arg("qnum"), py::arg("force") = false)
704-
.def(
705-
"get_block_",
698+
.def("get_block_",
706699
[](UniTensor &self, const std::vector<cytnx_uint64> &qnum, const bool &force) {
707700
return self.get_block_(qnum, force);
708701
},
709702
py::arg("qnum"), py::arg("force") = false)
710703

711-
.def(
712-
"get_block_",
704+
.def("get_block_",
713705
[](UniTensor &self, const std::vector<std::string> &labels, const std::vector<cytnx_int64> &qnum, const bool &force) {
714706
return self.get_block_(labels, qnum, force);
715707
},
716708
py::arg("labels"), py::arg("qnum"), py::arg("force") = false)
717-
.def(
718-
"get_block_",
709+
.def("get_block_",
719710
[](UniTensor &self, const std::vector<std::string> &labels, const std::vector<cytnx_uint64> &qnum, const bool &force) {
720711
return self.get_block_(labels,qnum, force);
721712
},
722713
py::arg("labels"), py::arg("qnum"), py::arg("force") = false)
723714

724715

725-
.def(
726-
"get_block_", [](UniTensor &self, const cytnx_uint64 &idx) { return self.get_block_(idx); },
716+
.def("get_block_", [](UniTensor &self, const cytnx_uint64 &idx) { return self.get_block_(idx); },
727717
py::arg("idx") = (cytnx_uint64)(0))
728718
.def("get_blocks", [](const UniTensor &self) { return self.get_blocks(); })
729-
.def(
730-
"get_blocks_",
719+
.def("get_blocks_",
731720
[](const UniTensor& self, py::args args, py::kwargs kwargs) {
732721
return self.get_blocks_(parse_get_blocks_silent_arg(args, kwargs));
733722
}
734-
// ,py::arg("silent") = false // Uncmment this line after removing the deprecated argument.
723+
// ,py::arg("silent") = false // Uncomment this line after removing the deprecated argument.
735724
)
736-
.def(
737-
"get_blocks_",
725+
.def("get_blocks_",
738726
[](UniTensor &self, py::args args, py::kwargs kwargs) {
739727
return self.get_blocks_(parse_get_blocks_silent_arg(args, kwargs));
740728
}
741-
// ,py::arg("silent") = false // Uncmment this line after removing the deprecated argument.
729+
// ,py::arg("silent") = false // Uncomment this line after removing the deprecated argument.
742730
)
743-
.def(
744-
"put_block",
731+
.def("put_block",
745732
[](UniTensor &self, const cytnx::Tensor &in, const cytnx_uint64 &idx) {
746733
self.put_block(in, idx);
747734
},
748735
py::arg("in"), py::arg("idx") = (cytnx_uint64)(0))
749736

750-
.def(
751-
"put_block",
737+
.def("put_block",
752738
[](UniTensor &self, const cytnx::Tensor &in, const std::vector<cytnx_int64> &qnum) {
753739
self.put_block(in, qnum);
754740
},
@@ -758,8 +744,27 @@ void unitensor_binding(py::module &m) {
758744
self.put_block(in, lbls, qnum);
759745
},
760746
py::arg("in"), py::arg("labels"), py::arg("qidx"))
761-
.def(
762-
"put_block_",
747+
748+
// [Deprecated force argument!]
749+
.def("put_block",
750+
[](UniTensor &self, const cytnx::Tensor &in, const std::vector<cytnx_int64> &qnum,
751+
const bool &force) {
752+
py::warnings::warn("argument 'force' is deprecated and will be removed; use put_block(UniTensor &self, const cytnx::Tensor &in, const std::vector<cytnx_int64> &qnum) instead.",
753+
PyExc_FutureWarning, 2);
754+
self.put_block(in, qnum, force);
755+
},
756+
py::arg("in"), py::arg("qidx"), py::arg("force"))
757+
// [Deprecated force argument!]
758+
.def("put_block",
759+
[](UniTensor &self, cytnx::Tensor &in, const std::vector<std::string> &lbls, const std::vector<cytnx_int64> &qnum,
760+
const bool &force) {
761+
py::warnings::warn("argument 'force' is deprecated and will be removed; use put_block((UniTensor &self, cytnx::Tensor &in, const std::vector<std::string> &lbls, const std::vector<cytnx_int64> &qnum) instead",
762+
PyExc_FutureWarning, 2);
763+
self.put_block(in, lbls, qnum, force);
764+
},
765+
py::arg("in"), py::arg("labels"), py::arg("qidx"), py::arg("force"))
766+
767+
.def("put_block_",
763768
[](UniTensor &self, cytnx::Tensor &in, const cytnx_uint64 &idx) { self.put_block_(in, idx); },
764769
py::arg("in"), py::arg("idx") = (cytnx_uint64)(0))
765770

@@ -773,8 +778,27 @@ void unitensor_binding(py::module &m) {
773778
self.put_block_(in, lbls, qnum);
774779
},
775780
py::arg("in"), py::arg("labels"), py::arg("qidx"))
776-
.def(
777-
"__repr__",
781+
782+
// [Deprecated force argument!]
783+
.def("put_block_",
784+
[](UniTensor &self, cytnx::Tensor &in, const std::vector<cytnx_int64> &qnum,
785+
const bool &force) {
786+
py::warnings::warn("argument 'force' is deprecated and will be removed; use put_block_(UniTensor &self, cytnx::Tensor &in, const std::vector<cytnx_int64> &qnum) instead.",
787+
PyExc_FutureWarning, 2);
788+
self.put_block_(in, qnum, force);
789+
},
790+
py::arg("in"), py::arg("qidx"), py::arg("force"))
791+
// [Deprecated force argument!]
792+
.def("put_block_",
793+
[](UniTensor &self, cytnx::Tensor &in, const std::vector<std::string> &lbls, const std::vector<cytnx_int64> &qnum,
794+
const bool &force) {
795+
py::warnings::warn("argument 'force' is deprecated and will be removed; use put_block_(UniTensor &self, cytnx::Tensor &in, const std::vector<std::string> &lbls, const std::vector<cytnx_int64> &qnum) instead.",
796+
PyExc_FutureWarning, 2);
797+
self.put_block_(in, lbls, qnum, force);
798+
},
799+
py::arg("in"), py::arg("labels"), py::arg("qidx"), py::arg("force"))
800+
801+
.def("__repr__",
778802
[](UniTensor &self) -> std::string {
779803
std::cout << self << std::endl;
780804
return std::string("");

0 commit comments

Comments
 (0)