Skip to content

Commit 2849086

Browse files
author
Cem Bassoy
committed
fixing tesor-vector multiplication for subtensor.
1 parent 4bbbcc4 commit 2849086

15 files changed

+547
-571
lines changed

IDEs/qtcreator/test/test_tensor.pro

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ CONFIG += staticlib depend_includepath console
55
CONFIG -= qt
66
CONFIG += c++20
77

8-
CONFIG += c++17
9-
108
#QMAKE_CXXFLAGS += -fno-inline
119
QMAKE_CXXFLAGS =-std=c++20
1210
QMAKE_CXXFLAGS +=-Wall -Wpedantic -Wextra
1311
QMAKE_CXXFLAGS +=-Wno-unknown-pragmas
14-
QMAKE_CXXFLAGS +=-Wno-unused-but-set-variable
12+
#QMAKE_CXXFLAGS +=-Wno-unused-but-set-variable
1513

1614

1715
gcc:QMAKE_CXXFLAGS_RELEASE =-O3 -march=native -fopenmp

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2018-2020, Cem Bassoy, [email protected]
2+
// Copyright (c) 2020, Cem Bassoy, [email protected]
33
//
44
// Distributed under the Boost Software License, Version 1.0. (See
55
// accompanying file LICENSE_1_0.txt or copy at
@@ -10,8 +10,8 @@
1010
//
1111

1212

13-
#ifndef _BOOST_UBLAS_TENSOR_ACCESS_HPP
14-
#define _BOOST_UBLAS_TENSOR_ACCESS_HPP
13+
#ifndef BOOST_UBLAS_TENSOR_ACCESS_HPP
14+
#define BOOST_UBLAS_TENSOR_ACCESS_HPP
1515

1616

1717
#include <algorithm>
@@ -26,7 +26,7 @@ namespace boost::numeric::ublas {
2626
using first_order = column_major;
2727
using last_order = row_major;
2828

29-
}
29+
} // namespace boost::numeric::ublas
3030

3131
namespace boost::numeric::ublas::detail{
3232

@@ -68,11 +68,21 @@ constexpr inline auto compute_single_index(InputIt1 i, InputIt1 /*ip*/, InputIt2
6868
* @param i begin output iterator to a container with tensor or subtensor indices length std::distance(begin,end) or greater
6969
*/
7070
template<typename InputIt1, typename OutputIt, typename LayoutType>
71-
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 wp, OutputIt i, LayoutType l);
71+
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 wp, OutputIt i, LayoutType /*unused*/);
72+
//{
73+
// if(w == wp)
74+
// return;
75+
76+
// auto wr = std::make_reverse_iterator( w );
77+
// auto wrp = std::make_reverse_iterator( wp );
78+
// auto ir = std::make_reverse_iterator( i+std::distance(w,wp) );
79+
80+
// std::transform(wrp,wr,ir, [&j](auto v) { auto k=j/v; j-=v*k; return k; } );
81+
//}
7282

7383

7484
template<typename InputIt1, typename OutputIt>
75-
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 wp, OutputIt i, first_order )
85+
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 wp, OutputIt i, first_order /*unused*/)
7686
{
7787
if(w == wp)
7888
return;
@@ -85,7 +95,7 @@ constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 wp
8595
}
8696

8797
template<typename InputIt1, typename OutputIt>
88-
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 wp, OutputIt i, last_order )
98+
constexpr inline void compute_multi_index(std::size_t j, InputIt1 w, InputIt1 wp, OutputIt i, last_order /*unused*/)
8999
{
90100
if(w == wp)
91101
return;
@@ -182,6 +192,6 @@ constexpr inline auto compute_single_index(std::size_t jv, InputIt1 w, InputIt1
182192
);
183193
}
184194

185-
} // namespace
195+
} // namespace boost::numeric::ublas::detail
186196

187197
#endif

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <type_traits>
1717

18+
1819
namespace boost::numeric::ublas{
1920

2021
template<typename T>

include/boost/numeric/ublas/tensor/extents/extents_functions.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,12 @@ template<integral T, class L>
153153
{
154154
auto s = typename extents_core<T>::base_type(e.size(),1ul);
155155

156-
if(empty(e) || is_vector(e) || is_scalar(e)){
156+
if(empty(e) || is_scalar(e)){
157157
return s;
158158
}
159+
160+
// || is_vector(e)
161+
159162
if constexpr(std::is_same_v<L,layout::first_order>){
160163
std::transform(begin (e), end (e) - 1, s.begin (), s.begin ()+1, std::multiplies<>{});
161164
} else {
@@ -170,9 +173,13 @@ template<integral T, T n, class L>
170173
auto s = typename extents_core<T,n>::base_type{};
171174
std::fill(s.begin(),s.end(),1ul);
172175

173-
if(empty(e) || is_vector(e) || is_scalar(e)){
176+
if(empty(e) || is_scalar(e)){
174177
return s;
175178
}
179+
180+
181+
// || is_vector(e)
182+
176183
if constexpr(std::is_same_v<L,layout::first_order>){
177184
std::transform(begin (e), end (e) - 1, s.begin (), s.begin ()+1, std::multiplies<>{});
178185
} else {

include/boost/numeric/ublas/tensor/function/tensor_times_vector.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ inline decltype(auto) prod( tensor_core< TE > const &a, vector<T, A> const &b, c
9494
nc_base[j++] = na.at(i);
9595

9696
auto nc = shape(nc_base);
97-
98-
9997
auto c = tensor( nc, value{} );
98+
10099
auto const* bb = &(b(0));
101100
ttv(m, p,
102101
c.data(), c.extents().data(), c.strides().data(),

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,23 @@
1010
//
1111

1212

13-
#ifndef _BOOST_UBLAS_TENSOR_SPAN_
14-
#define _BOOST_UBLAS_TENSOR_SPAN_
13+
#ifndef BOOST_UBLAS_TENSOR_SPAN
14+
#define BOOST_UBLAS_TENSOR_SPAN
1515

1616
#include <typeinfo>
1717
#include <limits>
1818
#include <stdexcept>
1919
#include <ostream>
2020

21-
namespace boost {
22-
namespace numeric {
23-
namespace ublas {
24-
namespace tag {
21+
22+
#include "concepts.hpp"
23+
24+
namespace boost::numeric::ublas::tag{
2525

2626
struct sliced {};
2727
struct strided {};
2828

29-
}
30-
}
31-
}
32-
}
29+
} // namespace boost::numeric::ublas::tag
3330

3431

3532
namespace boost::numeric::ublas {
@@ -53,7 +50,7 @@ template<class span_tag, class unsigned_type>
5350
class span;
5451

5552

56-
static constexpr inline std::size_t end = std::numeric_limits<std::size_t>::max();
53+
static constexpr inline std::size_t max = std::numeric_limits<std::size_t>::max();
5754

5855
template<>
5956
class span<tag::strided, std::size_t>
@@ -210,14 +207,14 @@ class span<tag::sliced, std::size_t> :
210207
using sliced_span = span<tag::sliced, std::size_t>;
211208

212209

213-
template<class unsigned_type>
214-
inline auto ran(unsigned_type f, unsigned_type l)
210+
template<integral unsigned_type_left, integral unsigned_type_right>
211+
inline auto ran(unsigned_type_left f, unsigned_type_right l)
215212
{
216213
return sliced_span(f,l);
217214
}
218215

219-
template<class unsigned_type>
220-
inline auto ran(unsigned_type f, unsigned_type s, unsigned_type l)
216+
template<integral unsigned_type_left, integral unsigned_type_middle, integral unsigned_type_right>
217+
inline auto ran(unsigned_type_left f, unsigned_type_middle s, unsigned_type_right l)
221218
{
222219
return strided_span(f,s,l);
223220
}

0 commit comments

Comments
 (0)