Skip to content

Commit 84530ed

Browse files
committed
Review fix on #353: reject mixed-shape operands before the data cast
The dispatch derives Dim/Rank from the LHS; a mixed-rank node (constructible through the weak || precondition in dot_product, #360) reached a wrong-type static_cast and, with the new rank-1 branch, returned silent garbage where it previously threw. The wrapper now throws evaluation_error on operand rank/dim mismatch and on sequence sizes not covering the rank. Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
1 parent 37a99d4 commit 84530ed

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎include/numsim_cas/tensor/data/tensor_data_to_scalar_wrapper.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ class tensor_data_dcontract_wrapper final
6969
m_rhs_indices(rhs_indices) {}
7070

7171
template <std::size_t Dim, std::size_t Rank> ValueType evaluate_imp() {
72+
// The dispatch picks Dim/Rank from the LHS; a mixed-rank/dim node
73+
// (constructible through the weak dot_product precondition, #360)
74+
// would type-pun the RHS cast into silent garbage (review on #353).
75+
if (m_lhs.rank() != m_rhs.rank() || m_lhs.dim() != m_rhs.dim()) {
76+
throw evaluation_error(
77+
"tensor_data_dcontract_wrapper: operand rank/dim mismatch");
78+
}
79+
if (m_lhs_indices.size() != Rank || m_rhs_indices.size() != Rank) {
80+
throw evaluation_error(
81+
"tensor_data_dcontract_wrapper: sequence size != operand rank");
82+
}
7283
if constexpr (Rank == 2) {
7384
using Tensor = tensor_data<ValueType, Dim, Rank>;
7485
auto const &l = static_cast<const Tensor &>(m_lhs).data();

0 commit comments

Comments
 (0)