@@ -944,4 +944,63 @@ BOOST_AUTO_TEST_CASE(reduction) {
944944 BOOST_REQUIRE (array_norm = std::sqrt (TA::dot (array, array)));
945945}
946946
947+ BOOST_AUTO_TEST_CASE (size_of) {
948+ using Numeric = double ;
949+ using T = Tensor<Numeric>;
950+ using ToT = Tensor<T>;
951+ using Policy = SparsePolicy;
952+ using ArrayToT = DistArray<ToT, Policy>;
953+
954+ auto unit_T = [](Range const & rng) { return T (rng, Numeric{1 }); };
955+
956+ auto unit_ToT = [unit_T](Range const & rngo, Range const & rngi) {
957+ return ToT (rngo, unit_T (rngi));
958+ };
959+
960+ size_t constexpr nrows = 3 ;
961+ size_t constexpr ncols = 4 ;
962+ TiledRange const trange ({{0 , 2 , 5 , 7 }, {0 , 5 , 7 , 10 , 12 }});
963+ TA_ASSERT (trange.tiles_range ().extent ().at (0 ) == nrows &&
964+ trange.tiles_range ().extent ().at (1 ) == ncols,
965+ " Following code depends on this condition." );
966+
967+ // this Range is used to construct all inner tensors of the tile with
968+ // tile index @c tix.
969+ auto inner_dims = [nrows, ncols](Range::index_type const & tix) -> Range {
970+ static std::array<size_t , nrows> const rows{7 , 8 , 9 };
971+ static std::array<size_t , ncols> const cols{7 , 8 , 9 , 10 };
972+
973+ TA_ASSERT (tix.size () == 2 , " Only rank-2 tensor expected." );
974+ return Range ({rows[tix.at (0 ) % nrows], cols[tix.at (1 ) % ncols]});
975+ };
976+
977+ // let's make all 'diagonal' tiles zero
978+ auto zero_tile = [](Range::index_type const & tix) -> bool {
979+ return tix.at (0 ) == tix.at (1 );
980+ };
981+
982+ auto make_tile = [inner_dims, //
983+ zero_tile, //
984+ &trange, //
985+ unit_ToT](auto & tile, auto const & rng) {
986+ auto && tix = trange.element_to_tile (rng.lobound ());
987+ if (zero_tile (tix))
988+ return 0 .;
989+ else {
990+ tile = unit_ToT (rng, inner_dims (tix));
991+ return tile.norm ();
992+ }
993+ };
994+
995+ auto & world = get_default_world ();
996+
997+ // all non-zero inner tensors of this ToT array are unit (ie all
998+ // inner tensors' elements are 1.)
999+ auto array = make_array<ArrayToT>(world, trange, make_tile);
1000+
1001+ auto sz0 = TiledArray::size_of<MemorySpace::Host>(array);
1002+ world.gop .sum (sz0);
1003+ BOOST_REQUIRE (sz0 == 56688 );
1004+ }
1005+
9471006BOOST_AUTO_TEST_SUITE_END ()
0 commit comments