Skip to content

Commit

Permalink
random_tensor function returns the same TA::Tensor for the same TA:…
Browse files Browse the repository at this point in the history
…:Range. [debug]
  • Loading branch information
bimalgaudel committed Jan 16, 2024
1 parent d0ca818 commit 3b5d6b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
5 changes: 4 additions & 1 deletion tests/einsum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,10 @@ BOOST_AUTO_TEST_CASE(ij_mn_eq_ijk_mo_times_ijk_no) {

auto out = einsum(lhs("i,j,k;m,o"), rhs("i,j,k;n,o"), "i,j;m,n");
bool are_equal = ToTArrayFixture::are_equal<ShapeComp::False>(ref, out);
std::cout << "ref:\n" << ref << '\n' << "out:\n" << out << '\n';

std::cout << "LHS:\n" << lhs << "\nRHS:\n" << rhs << "\n";

// std::cout << "ref:\n" << ref << '\n' << "out:\n" << out << '\n';
BOOST_CHECK(are_equal);
}

Expand Down
29 changes: 22 additions & 7 deletions tests/tot_array_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,17 @@ enum class ShapeComp { True, False };
template <typename TensorT,
std::enable_if_t<TA::detail::is_tensor_v<TensorT>, bool> = true>
auto random_tensor(TA::Range const& rng) {
using Ix1 = typename TA::Range::index1_type;
using Num = typename TensorT::numeric_type;
TensorT result{rng};
using NumericT = typename TensorT::numeric_type;
std::generate(/*std::execution::par, */
result.begin(), result.end(),
TA::detail::MakeRandom<char>::generate_value);
for (auto const& ix : rng) {
result(ix) =
static_cast<Num>(std::accumulate(ix.begin(), ix.end(), Ix1{0}));
}
// std::generate(/*std::execution::par, */
// result.begin(), result.end(),
// TA::detail::MakeRandom<char>::generate_value);
return result;
}

Expand All @@ -112,12 +118,21 @@ template <
std::enable_if_t<TA::detail::is_tensor_of_tensor_v<TensorT>, bool> = true>
auto random_tensor(TA::Range const& outer_rng, TA::Range const& inner_rng) {
using InnerTensorT = typename TensorT::value_type;
using Num = typename TensorT::numeric_type;
using Ix1 = typename TA::Range::index1_type;
TensorT result{outer_rng};

std::generate(/*std::execution::par,*/
result.begin(), result.end(), [inner_rng]() {
return random_tensor<InnerTensorT>(inner_rng);
});
for (auto const& ix : outer_rng) {
auto inner = random_tensor<InnerTensorT>(inner_rng);
auto plus = std::accumulate(ix.begin(), ix.end(), Ix1{0});
inner.add_to(static_cast<Num>(plus));
result(ix) = inner;
}

// std::generate(/*std::execution::par,*/
// result.begin(), result.end(), [inner_rng]() {
// return random_tensor<InnerTensorT>(inner_rng);
// });

return result;
}
Expand Down

0 comments on commit 3b5d6b5

Please sign in to comment.