Skip to content
Open
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
39 changes: 34 additions & 5 deletions include/UniTensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,14 @@ namespace cytnx {
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;
Tensor get_block(const cytnx_uint64 &idx = 0) const { return this->_block.clone(); }
Tensor get_block() const { return this->_block.clone(); }
Tensor get_block(const cytnx_uint64 &idx) const {
cytnx_error_msg(idx != 0,
"[ERROR][DenseUniTensor] Dense tensor has only one block, block number %d "
"invalid. Use get_block(0).\n",
idx);
return this->_block.clone();
}

Tensor get_block(const std::vector<cytnx_int64> &qnum, const bool &force) const {
cytnx_error_msg(
Expand All @@ -631,9 +638,23 @@ namespace cytnx {
}

// return a share view of block, this only work for non-symm tensor.
Tensor &get_block_(const cytnx_uint64 &idx = 0) { return this->_block; }
Tensor &get_block_() { return this->_block; }
Tensor &get_block_(const cytnx_uint64 &idx) {
cytnx_error_msg(idx != 0,
"[ERROR][DenseUniTensor] Dense tensor has only one block, block number %d "
"invalid. Use get_block_(0).\n",
idx);
return this->_block;
}
// return a share view of block, this only work for non-symm tensor.
const Tensor &get_block_(const cytnx_uint64 &idx = 0) const { return this->_block; }
const Tensor &get_block_() const { return this->_block; }
const Tensor &get_block_(const cytnx_uint64 &idx) const {
cytnx_error_msg(idx != 0,
"[ERROR][DenseUniTensor] Dense tensor has only one block, block number %d "
"invalid. Use get_block_(0).\n",
idx);
return this->_block;
}

cytnx_uint64 Nblocks() const { return 1; };
std::vector<Tensor> get_blocks() const {
Expand All @@ -656,9 +677,13 @@ namespace cytnx {
}

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

cytnx_error_msg(idx != 0,
"[ERROR][DenseUniTensor] Dense tensor has only one block, block number %d "
"invalid. Use put_block(0).\n",
idx);
// cytnx_error_msg(in.dtype() != this->dtype(),
// "[ERROR][DenseUniTensor][put_block] The input tensor dtype does not
// match.%s",
Expand All @@ -683,8 +708,12 @@ namespace cytnx {
}
// share view of the block
void put_block_(Tensor &in, const cytnx_uint64 &idx = 0) {
// We don't check the dtype for DenseUniTensor, since it'll be more convinent to change
// We don't check the dtype for DenseUniTensor, since it'll be more convenient to change
// DenseUniTensor's dtype
cytnx_error_msg(idx != 0,
"[ERROR][DenseUniTensor] Dense tensor has only one block, block number %d "
"invalid. Use get_block_(0).\n",
idx);

// cytnx_error_msg(in.dtype() != this->dtype(),
// "[ERROR][DenseUniTensor][put_block] The input tensor dtype does not
Expand Down
8 changes: 0 additions & 8 deletions tests/DenseUniTensor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,11 +1266,9 @@ TEST_F(DenseUniTensorTest, get_block) {
/*=====test info=====
describe:test get_block out of range
====================*/
#if FAIL_CASE_OPEN
TEST_F(DenseUniTensorTest, get_block_out_of_range) {
EXPECT_THROW(utzero345.get_block(3), std::logic_error);
}
#endif

/*=====test info=====
describe:test get_block, diagonal
Expand Down Expand Up @@ -1386,11 +1384,9 @@ TEST_F(DenseUniTensorTest, get_block__uninit) {
/*=====test info=====
describe:test get_block out of range
====================*/
#if FAIL_CASE_OPEN
TEST_F(DenseUniTensorTest, get_block__out_of_range) {
EXPECT_THROW(utzero345.get_block_(3), std::logic_error);
}
#endif

TEST_F(DenseUniTensorTest, get_blocks) { EXPECT_THROW(utzero345.get_blocks(), std::logic_error); }

Expand Down Expand Up @@ -1496,7 +1492,6 @@ TEST_F(DenseUniTensorTest, put_block_rank_mismatch) {
/*=====test info=====
describe:test put_block_, out of index
====================*/
#if FAIL_CASE_OPEN
TEST_F(DenseUniTensorTest, put_block_out_of_idx) {
constexpr cytnx_uint64 dim1 = 2, dim2 = 3;
auto tens = zeros({dim1, dim2});
Expand All @@ -1507,7 +1502,6 @@ TEST_F(DenseUniTensorTest, put_block_out_of_idx) {
auto ut = UniTensor({Bond(dim1), Bond(dim2)});
EXPECT_THROW(ut.put_block(tens, 1), std::logic_error);
}
#endif

/*=====test info=====
describe:test put_block_
Expand Down Expand Up @@ -1592,7 +1586,6 @@ TEST_F(DenseUniTensorTest, put_block__rank_mismatch) {
/*=====test info=====
describe:test put_block_, out of index
====================*/
#if FAIL_CASE_OPEN
TEST_F(DenseUniTensorTest, put_block__out_of_idx) {
constexpr cytnx_uint64 dim1 = 2, dim2 = 3;
auto tens = zeros({dim1, dim2});
Expand All @@ -1603,7 +1596,6 @@ TEST_F(DenseUniTensorTest, put_block__out_of_idx) {
auto ut = UniTensor({Bond(dim1), Bond(dim2)});
EXPECT_THROW(ut.put_block_(tens, 1), std::logic_error);
}
#endif

/*=====test info=====
describe:test put_blocks, input uninitialized UniTensor
Expand Down
Loading