From 09bb258c96e90631353dc2219ff67e0ba89c6f35 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Tue, 27 Aug 2024 15:12:49 -0400 Subject: [PATCH] introduced Tile::total_size() to mirror Tensor::total_size --- src/TiledArray/tile.h | 14 +++++++++++++- src/TiledArray/type_traits.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/TiledArray/tile.h b/src/TiledArray/tile.h index 1091362287..7d568f7200 100644 --- a/src/TiledArray/tile.h +++ b/src/TiledArray/tile.h @@ -215,11 +215,23 @@ class Tile { // Dimension information accessors ----------------------------------------- - /// Size accessors + /// Size accessor /// \return The number of elements in the tensor decltype(auto) size() const { return tensor().size(); } + /// Total size accessor + + /// \return The number of elements in the tensor, tallied across batches (if + /// any) + decltype(auto) total_size() const { + if constexpr (detail::has_member_function_total_size_anyreturn_v< + tensor_type>) { + return tensor().total_size(); + } else + return size(); + } + /// Range accessor /// \return An object describes the upper and lower bounds of the tensor data diff --git a/src/TiledArray/type_traits.h b/src/TiledArray/type_traits.h index 5c3d066e9c..80c6bd924f 100644 --- a/src/TiledArray/type_traits.h +++ b/src/TiledArray/type_traits.h @@ -322,6 +322,8 @@ GENERATE_HAS_MEMBER_TYPE(mapped_type) GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(size) GENERATE_HAS_MEMBER_FUNCTION(size) +GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(total_size) +GENERATE_HAS_MEMBER_FUNCTION(total_size) GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(data) GENERATE_HAS_MEMBER_FUNCTION(data) GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(empty)