Skip to content

Commit eb08923

Browse files
FIX: fix the issue #111
This bug occured because the type extent_of_rank_one_array_v was bool instead of std::size_t, which in turn casting the std::size_t value into bool. If the size of the array was N, it would cast it into 1.
1 parent 9cf2e9b commit eb08923

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

examples/tensor/multiply_tensors_product_function.cpp

+18-17
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,14 @@ void multiply_tensors_with_static_order()
193193
using value_t = float; // std::complex<double>;
194194
using matrix_t = matrix<value_t,format_t>;
195195
using vector_t = vector<value_t>;
196+
using tensor_t = dynamic_tensor<value_t>;
196197
using tensor2_t = fixed_rank_tensor<value_t,2U>;
197198
using tensor3_t = fixed_rank_tensor<value_t,3U>;
198-
// using tensor4_t = fixed_rank_tensor<value_t,4>;
199-
// using shape_t = typename tensor_t::extents_type;
200-
// using shape2_t = typename tensor2_t::extents_type;
199+
using tensor4_t = fixed_rank_tensor<value_t,4>;
200+
using shape_t = typename tensor_t::extents_type;
201+
using shape2_t = typename tensor2_t::extents_type;
201202
using shape3_t = typename tensor3_t::extents_type;
202-
// using shape4_t = typename tensor4_t::extents_type;
203+
using shape4_t = typename tensor4_t::extents_type;
203204

204205
// Tensor-Vector-Multiplications - Including Transposition
205206
// dynamic_extents with static rank
@@ -296,41 +297,41 @@ void multiply_tensors_with_static_order()
296297
// dynamic_extents with static rank
297298
{
298299

299-
// using perm_t = std::array<std::size_t,2>;
300+
using perm_t = std::array<std::size_t,2>;
300301

301-
// auto na = shape3_t{3,4,5};
302-
// auto nb = shape4_t{4,6,3,2};
303-
// auto nc = shape2_t{5,5};
304-
// auto A = tensor3_t(na,2.0F);
305-
// auto B = tensor4_t(nb,3.0F);
306-
// auto C = tensor2_t(nc,2.0F);
302+
auto na = shape3_t{3,4,5};
303+
auto nb = shape4_t{4,6,3,2};
304+
auto nc = shape2_t{5,5};
305+
auto A = tensor3_t(na,2.0F);
306+
auto B = tensor4_t(nb,3.0F);
307+
auto C = tensor2_t(nc,2.0F);
307308

308309
// C1(j,l) = T(j,l) + A(i,j,k)*A(i,j,l) + 5;
309310
// Right now there exist no tensor other than dynamic_extents with
310311
// dynamic rank so every tensor times tensor operator automatically
311312
// to dynamic tensor
312-
// auto C1 = C + prod(A,A,perm_t{1,2}) + 5.0F;
313+
auto C1 = C + prod(A,A,perm_t{1,2}) + 5.0F;
313314
std::cout << "% --------------------------- " << std::endl;
314315
std::cout << "% --------------------------- " << std::endl << std::endl;
315316
std::cout << "% C1(k,l) = T(k,l) + A(i,j,k)*A(i,j,l) + 5;" << std::endl << std::endl;
316-
// std::cout << "C1=" << tensor_t(C1) << ";" << std::endl << std::endl;
317+
std::cout << "C1=" << tensor_t(C1) << ";" << std::endl << std::endl;
317318

318319

319320
// C2(k,l,m) = T(k,l,m) + A(i,j,k)*B(j,l,i,m) + 5;
320321
// Similar Problem as above
321-
// tensor_t C2 = tensor_t(shape_t{na[2],nb[1],nb[3]},2.0F) + prod(A,B,perm_t{1,2},perm_t{3,1}) + 5.0F;
322+
tensor_t C2 = tensor3_t(shape3_t{na[2],nb[1],nb[3]},2.0F) + prod(A,B,perm_t{1,2},perm_t{3,1}) + 5.0F;
322323
std::cout << "% --------------------------- " << std::endl;
323324
std::cout << "% --------------------------- " << std::endl << std::endl;
324325
std::cout << "% C2(k,l,m) = T(k,l,m) + A(i,j,k)*B(j,l,i,m) + 5;" << std::endl << std::endl;
325-
//std::cout << "C2=" << C2 << ";" << std::endl << std::endl;
326+
std::cout << "C2=" << C2 << ";" << std::endl << std::endl;
326327

327328
// C3(k,l,m) = T(k,l,m) + A(i,j,k)*trans(B(j,l,i,m),{2,3,1,4})+ 5;
328329
// Similar Problem as above
329-
// tensor_t C3 = tensor_t(shape_t{na[2],nb[1],nb[3]},2.0F) + prod(A,trans(B,{2,3,1,4}),perm_t{1,2}) + 5.0F;
330+
tensor_t C3 = tensor3_t(shape3_t{na[2],nb[1],nb[3]},2.0F) + prod(A,trans(B,{2,3,1,4}),perm_t{1,2}) + 5.0F;
330331
std::cout << "% --------------------------- " << std::endl;
331332
std::cout << "% --------------------------- " << std::endl << std::endl;
332333
std::cout << "% C3(k,l,m) = T(k,l,m) + A(i,j,k)*trans(B(j,l,i,m),{2,3,1,4})+ 5;" << std::endl << std::endl;
333-
// std::cout << "C3=" << C3 << ";" << std::endl << std::endl;
334+
std::cout << "C3=" << C3 << ";" << std::endl << std::endl;
334335

335336
}
336337
}

include/boost/numeric/ublas/tensor/functions.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace boost::numeric::ublas
6464
{};
6565

6666
template<typename T>
67-
inline static constexpr bool extent_of_rank_one_array_v = extent_of_rank_one_array<T>::value;
67+
inline static constexpr std::size_t extent_of_rank_one_array_v = extent_of_rank_one_array<T>::value;
6868

6969
} // namespace detail
7070

@@ -360,6 +360,9 @@ namespace boost::numeric::ublas
360360
using lextents_type = std::decay_t< decltype(e1) >;
361361
using rextents_type = std::decay_t< decltype(e2) >;
362362
using array_type = std::decay_t< decltype(a1) >;
363+
364+
[[maybe_unused]] extents_size_type const size = ( e1.size() + e2.size() ) - ( a1.size() + a2.size() );
365+
363366
if constexpr(
364367
detail::is_bounded_array_v<array_type> &&
365368
is_static_rank_v<lextents_type> &&
@@ -371,7 +374,6 @@ namespace boost::numeric::ublas
371374
res.fill(1u);
372375
return res;
373376
}else{
374-
extents_size_type const size = ( e1.size() + e2.size() ) - ( a1.size() + a2.size() );
375377
using extents_base_type = typename extents<>::base_type;
376378
auto arr = extents_base_type( std::max(size, extents_size_type(2)), 1u );
377379
return extents<>(std::move(arr));

0 commit comments

Comments
 (0)