Skip to content
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
27 changes: 20 additions & 7 deletions src/TiledArray/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ namespace TiledArray {
* @{
*/

/// An N-dimensional shallow-copy wrapper for Tensor-like types that, unlike
/// Tensor, have deep-copy semantics. Like Tensor, Tile is
/// default-constructible. The default constructor produced a Tile in
/// null state (not referring to any tensor object). The name refers to its
/// intended use as a tile of DistArray.
/// A shallow-copy wrapper for deep-copy Tensor-like types. The name
/// refers to its intended use as a tile of DistArray.
/// Like Tensor, Tile is default-constructible. The default constructor
/// produces a Tile in null state (not referring to any tensor object);
/// calling reset() on a Tile also produces a null Tile.
/// Most operations on a null Tile will produce a failing TA_ASSERT
/// (see Tile::tensor()), even in cases where valid semantics could be defined
/// (such as add_to).
///
/// \tparam T a tensor type. It may provide a subset of the full operation
/// set of Tensor, since only those operations that are actually used
Expand Down Expand Up @@ -196,9 +199,19 @@ class Tile {

// Tile accessor -----------------------------------------------------------

tensor_type& tensor() { return *pimpl_; }
/// \return reference to the referred-to value
/// \pre TA_ASSERT that this is not in a null state
tensor_type& tensor() {
TA_ASSERT(pimpl_);
return *pimpl_;
}

const tensor_type& tensor() const { return *pimpl_; }
/// \return const reference to the referred-to value
/// \pre TA_ASSERT that this is not in a null state
const tensor_type& tensor() const {
TA_ASSERT(pimpl_);
return *pimpl_;
}

// Iterator accessor -------------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ set(ta_test_src_files ta_test.cpp
btas_zb_inner_tile.cpp
tensor_tensor_view.cpp
tensor_shift_wrapper.cpp
tile.cpp
tiled_range1.cpp
tiled_range.cpp
blocked_pmap.cpp
Expand Down
49 changes: 49 additions & 0 deletions tests/tile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is a part of TiledArray.
* Copyright (C) 2026 Virginia Tech
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* tile.cpp
* September 24, 2026
*
*/

#include <TiledArray/config.h>

#ifdef TILEDARRAY_HAS_BTAS

#include <TiledArray/external/btas.h>
#include <TiledArray/tile.h>
#include "tiledarray.h"
#include "unit_test_config.h"

BOOST_AUTO_TEST_SUITE(tile_suite, TA_UT_LABEL_SERIAL)

// TA::Tile is meant to wrap deep-copy tensor types, such as btas::Tensor
using tile_type = TiledArray::Tile<btas::Tensor<double, TiledArray::Range>>;

BOOST_AUTO_TEST_CASE(null_tile) {
tile_type null_tile;
const tile_type& const_null_tile = null_tile;
BOOST_CHECK(null_tile.empty());
BOOST_CHECK_EQUAL(null_tile.use_count(), 0);
// tensor() on a null tile must trigger TA_ASSERT
BOOST_CHECK_TA_ASSERT(null_tile.tensor(), TiledArray::Exception);
BOOST_CHECK_TA_ASSERT(const_null_tile.tensor(), TiledArray::Exception);
}

BOOST_AUTO_TEST_SUITE_END()

#endif // TILEDARRAY_HAS_BTAS
Loading