123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945 |
- #ifndef BOOST_UBLAS_TENSOR_MULTIPLICATION
- #define BOOST_UBLAS_TENSOR_MULTIPLICATION
- #include <cassert>
- namespace boost {
- namespace numeric {
- namespace ublas {
- namespace detail {
- namespace recursive {
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void ttt(SizeType const k,
- SizeType const r, SizeType const s, SizeType const q,
- SizeType const*const phia, SizeType const*const phib,
- PointerOut c, SizeType const*const nc, SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
- if(k < r)
- {
- assert(nc[k] == na[phia[k]-1]);
- for(size_t ic = 0u; ic < nc[k]; a += wa[phia[k]-1], c += wc[k], ++ic)
- ttt(k+1, r, s, q, phia,phib, c, nc, wc, a, na, wa, b, nb, wb);
- }
- else if(k < r+s)
- {
- assert(nc[k] == nb[phib[k-r]-1]);
- for(size_t ic = 0u; ic < nc[k]; b += wb[phib[k-r]-1], c += wc[k], ++ic)
- ttt(k+1, r, s, q, phia, phib, c, nc, wc, a, na, wa, b, nb, wb);
- }
- else if(k < r+s+q-1)
- {
- assert(na[phia[k-s]-1] == nb[phib[k-r]-1]);
- for(size_t ia = 0u; ia < na[phia[k-s]-1]; a += wa[phia[k-s]-1], b += wb[phib[k-r]-1], ++ia)
- ttt(k+1, r, s, q, phia, phib, c, nc, wc, a, na, wa, b, nb, wb);
- }
- else
- {
- assert(na[phia[k-s]-1] == nb[phib[k-r]-1]);
- for(size_t ia = 0u; ia < na[phia[k-s]-1]; a += wa[phia[k-s]-1], b += wb[phib[k-r]-1], ++ia)
- *c += *a * *b;
- }
- }
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void ttt(SizeType const k,
- SizeType const r, SizeType const s, SizeType const q,
- PointerOut c, SizeType const*const nc, SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
- if(k < r)
- {
- assert(nc[k] == na[k]);
- for(size_t ic = 0u; ic < nc[k]; a += wa[k], c += wc[k], ++ic)
- ttt(k+1, r, s, q, c, nc, wc, a, na, wa, b, nb, wb);
- }
- else if(k < r+s)
- {
- assert(nc[k] == nb[k-r]);
- for(size_t ic = 0u; ic < nc[k]; b += wb[k-r], c += wc[k], ++ic)
- ttt(k+1, r, s, q, c, nc, wc, a, na, wa, b, nb, wb);
- }
- else if(k < r+s+q-1)
- {
- assert(na[k-s] == nb[k-r]);
- for(size_t ia = 0u; ia < na[k-s]; a += wa[k-s], b += wb[k-r], ++ia)
- ttt(k+1, r, s, q, c, nc, wc, a, na, wa, b, nb, wb);
- }
- else
- {
- assert(na[k-s] == nb[k-r]);
- for(size_t ia = 0u; ia < na[k-s]; a += wa[k-s], b += wb[k-r], ++ia)
- *c += *a * *b;
- }
- }
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void ttm(SizeType const m, SizeType const r,
- PointerOut c, SizeType const*const nc, SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
- if(r == m) {
- ttm(m, r-1, c, nc, wc, a, na, wa, b, nb, wb);
- }
- else if(r == 0){
- for(auto i0 = 0ul; i0 < nc[0]; c += wc[0], a += wa[0], ++i0) {
- auto cm = c;
- auto b0 = b;
- for(auto i0 = 0ul; i0 < nc[m]; cm += wc[m], b0 += wb[0], ++i0){
- auto am = a;
- auto b1 = b0;
- for(auto i1 = 0ul; i1 < nb[1]; am += wa[m], b1 += wb[1], ++i1)
- *cm += *am * *b1;
- }
- }
- }
- else{
- for(auto i = 0ul; i < na[r]; c += wc[r], a += wa[r], ++i)
- ttm(m, r-1, c, nc, wc, a, na, wa, b, nb, wb);
- }
- }
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void ttm0( SizeType const r,
- PointerOut c, SizeType const*const nc, SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
- if(r > 1){
- for(auto i = 0ul; i < na[r]; c += wc[r], a += wa[r], ++i)
- ttm0(r-1, c, nc, wc, a, na, wa, b, nb, wb);
- }
- else{
- for(auto i1 = 0ul; i1 < nc[1]; c += wc[1], a += wa[1], ++i1) {
- auto cm = c;
- auto b0 = b;
-
- for(auto i0 = 0ul; i0 < nc[0]; cm += wc[0], b0 += wb[0], ++i0){
- auto am = a;
- auto b1 = b0;
- for(auto i1 = 0u; i1 < nb[1]; am += wa[0], b1 += wb[1], ++i1){
- *cm += *am * *b1;
- }
- }
- }
- }
- }
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void ttv( SizeType const m, SizeType const r, SizeType const q,
- PointerOut c, SizeType const*const nc, SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b)
- {
- if(r == m) {
- ttv(m, r-1, q, c, nc, wc, a, na, wa, b);
- }
- else if(r == 0){
- for(auto i0 = 0u; i0 < na[0]; c += wc[0], a += wa[0], ++i0) {
- auto c1 = c; auto a1 = a; auto b1 = b;
- for(auto im = 0u; im < na[m]; a1 += wa[m], ++b1, ++im)
- *c1 += *a1 * *b1;
- }
- }
- else{
- for(auto i = 0u; i < na[r]; c += wc[q], a += wa[r], ++i)
- ttv(m, r-1, q-1, c, nc, wc, a, na, wa, b);
- }
- }
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void ttv0(SizeType const r,
- PointerOut c, SizeType const*const nc, SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b)
- {
- if(r > 1){
- for(auto i = 0u; i < na[r]; c += wc[r-1], a += wa[r], ++i)
- ttv0(r-1, c, nc, wc, a, na, wa, b);
- }
- else{
- for(auto i1 = 0u; i1 < na[1]; c += wc[0], a += wa[1], ++i1)
- {
- auto c1 = c; auto a1 = a; auto b1 = b;
- for(auto i0 = 0u; i0 < na[0]; a1 += wa[0], ++b1, ++i0)
- *c1 += *a1 * *b1;
- }
- }
- }
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void mtv(SizeType const m,
- PointerOut c, SizeType const*const , SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b)
- {
-
- const auto o = (m == 0) ? 1 : 0;
- for(auto io = 0u; io < na[o]; c += wc[o], a += wa[o], ++io) {
- auto c1 = c; auto a1 = a; auto b1 = b;
- for(auto im = 0u; im < na[m]; a1 += wa[m], ++b1, ++im)
- *c1 += *a1 * *b1;
- }
- }
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void mtm(PointerOut c, SizeType const*const nc, SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
-
- assert(nc[0] == na[0]);
- assert(nc[1] == nb[1]);
- assert(na[1] == nb[0]);
- auto cj = c; auto bj = b;
- for(auto j = 0u; j < nc[1]; cj += wc[1], bj += wb[1], ++j) {
- auto bk = bj; auto ak = a;
- for(auto k = 0u; k < na[1]; ak += wa[1], bk += wb[0], ++k) {
- auto ci = cj; auto ai = ak;
- for(auto i = 0u; i < na[0]; ai += wa[0], ci += wc[0], ++i){
- *ci += *ai * *bk;
- }
- }
- }
- }
- template <class PointerIn1, class PointerIn2, class value_t, class SizeType>
- value_t inner(SizeType const r, SizeType const*const n,
- PointerIn1 a, SizeType const*const wa,
- PointerIn2 b, SizeType const*const wb,
- value_t v)
- {
- if(r == 0)
- for(auto i0 = 0u; i0 < n[0]; a += wa[0], b += wb[0], ++i0)
- v += *a * *b;
- else
- for(auto ir = 0u; ir < n[r]; a += wa[r], b += wb[r], ++ir)
- v = inner(r-1, n, a, wa, b, wb, v);
- return v;
- }
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void outer_2x2(SizeType const pa,
- PointerOut c, SizeType const*const , SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
-
-
-
- for(auto ib1 = 0u; ib1 < nb[1]; b += wb[1], c += wc[pa+1], ++ib1) {
- auto c2 = c;
- auto b0 = b;
- for(auto ib0 = 0u; ib0 < nb[0]; b0 += wb[0], c2 += wc[pa], ++ib0) {
- const auto b = *b0;
- auto c1 = c2;
- auto a1 = a;
- for(auto ia1 = 0u; ia1 < na[1]; a1 += wa[1], c1 += wc[1], ++ia1) {
- auto a0 = a1;
- auto c0 = c1;
- for(SizeType ia0 = 0u; ia0 < na[0]; a0 += wa[0], c0 += wc[0], ++ia0)
- *c0 = *a0 * b;
- }
- }
- }
- }
- template<class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void outer(SizeType const pa,
- SizeType const rc, PointerOut c, SizeType const*const nc, SizeType const*const wc,
- SizeType const ra, PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- SizeType const rb, PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
- if(rb > 1)
- for(auto ib = 0u; ib < nb[rb]; b += wb[rb], c += wc[rc], ++ib)
- outer(pa, rc-1, c, nc, wc, ra, a, na, wa, rb-1, b, nb, wb);
- else if(ra > 1)
- for(auto ia = 0u; ia < na[ra]; a += wa[ra], c += wc[ra], ++ia)
- outer(pa, rc-1, c, nc, wc, ra-1, a, na, wa, rb, b, nb, wb);
- else
- outer_2x2(pa, c, nc, wc, a, na, wa, b, nb, wb);
- }
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void outer(SizeType const k,
- SizeType const r, SizeType const s,
- SizeType const*const phia, SizeType const*const phib,
- PointerOut c, SizeType const*const nc, SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
- if(k < r)
- {
- assert(nc[k] == na[phia[k]-1]);
- for(size_t ic = 0u; ic < nc[k]; a += wa[phia[k]-1], c += wc[k], ++ic)
- outer(k+1, r, s, phia,phib, c, nc, wc, a, na, wa, b, nb, wb);
- }
- else if(k < r+s-1)
- {
- assert(nc[k] == nb[phib[k-r]-1]);
- for(size_t ic = 0u; ic < nc[k]; b += wb[phib[k-r]-1], c += wc[k], ++ic)
- outer(k+1, r, s, phia, phib, c, nc, wc, a, na, wa, b, nb, wb);
- }
- else
- {
- assert(nc[k] == nb[phib[k-r]-1]);
- for(size_t ic = 0u; ic < nc[k]; b += wb[phib[k-r]-1], c += wc[k], ++ic)
- *c = *a * *b;
- }
- }
- }
- }
- }
- }
- }
- #include <stdexcept>
- namespace boost {
- namespace numeric {
- namespace ublas {
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void ttv(SizeType const m, SizeType const p,
- PointerOut c, SizeType const*const nc, SizeType const*const wc,
- const PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- const PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
- static_assert( std::is_pointer<PointerOut>::value & std::is_pointer<PointerIn1>::value & std::is_pointer<PointerIn2>::value,
- "Static error in boost::numeric::ublas::ttv: Argument types for pointers are not pointer types.");
- if( m == 0)
- throw std::length_error("Error in boost::numeric::ublas::ttv: Contraction mode must be greater than zero.");
- if( p < m )
- throw std::length_error("Error in boost::numeric::ublas::ttv: Rank must be greater equal the modus.");
- if( p == 0)
- throw std::length_error("Error in boost::numeric::ublas::ttv: Rank must be greater than zero.");
- if(c == nullptr || a == nullptr || b == nullptr)
- throw std::length_error("Error in boost::numeric::ublas::ttv: Pointers shall not be null pointers.");
- for(auto i = 0u; i < m-1; ++i)
- if(na[i] != nc[i])
- throw std::length_error("Error in boost::numeric::ublas::ttv: Extents (except of dimension mode) of A and C must be equal.");
- for(auto i = m; i < p; ++i)
- if(na[i] != nc[i-1])
- throw std::length_error("Error in boost::numeric::ublas::ttv: Extents (except of dimension mode) of A and C must be equal.");
- const auto max = std::max(nb[0], nb[1]);
- if( na[m-1] != max)
- throw std::length_error("Error in boost::numeric::ublas::ttv: Extent of dimension mode of A and b must be equal.");
- if((m != 1) && (p > 2))
- detail::recursive::ttv(m-1, p-1, p-2, c, nc, wc, a, na, wa, b);
- else if ((m == 1) && (p > 2))
- detail::recursive::ttv0(p-1, c, nc, wc, a, na, wa, b);
- else if( p == 2 )
- detail::recursive::mtv(m-1, c, nc, wc, a, na, wa, b);
- else {
- auto v = std::remove_pointer_t<std::remove_cv_t<PointerOut>>{};
- *c = detail::recursive::inner(SizeType(0), na, a, wa, b, wb, v);
- }
- }
- template <class PointerIn1, class PointerIn2, class PointerOut, class SizeType>
- void ttm(SizeType const m, SizeType const p,
- PointerOut c, SizeType const*const nc, SizeType const*const wc,
- const PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- const PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
- static_assert( std::is_pointer<PointerOut>::value & std::is_pointer<PointerIn1>::value & std::is_pointer<PointerIn2>::value,
- "Static error in boost::numeric::ublas::ttm: Argument types for pointers are not pointer types.");
- if( m == 0 )
- throw std::length_error("Error in boost::numeric::ublas::ttm: Contraction mode must be greater than zero.");
- if( p < m )
- throw std::length_error("Error in boost::numeric::ublas::ttm: Rank must be greater equal than the specified mode.");
- if( p == 0)
- throw std::length_error("Error in boost::numeric::ublas::ttm:Rank must be greater than zero.");
- if(c == nullptr || a == nullptr || b == nullptr)
- throw std::length_error("Error in boost::numeric::ublas::ttm: Pointers shall not be null pointers.");
- for(auto i = 0u; i < m-1; ++i)
- if(na[i] != nc[i])
- throw std::length_error("Error in boost::numeric::ublas::ttm: Extents (except of dimension mode) of A and C must be equal.");
- for(auto i = m; i < p; ++i)
- if(na[i] != nc[i])
- throw std::length_error("Error in boost::numeric::ublas::ttm: Extents (except of dimension mode) of A and C must be equal.");
- if(na[m-1] != nb[1])
- throw std::length_error("Error in boost::numeric::ublas::ttm: 2nd Extent of B and M-th Extent of A must be the equal.");
- if(nc[m-1] != nb[0])
- throw std::length_error("Error in boost::numeric::ublas::ttm: 1nd Extent of B and M-th Extent of C must be the equal.");
- if ( m != 1 )
- detail::recursive::ttm (m-1, p-1, c, nc, wc, a, na, wa, b, nb, wb);
- else
- detail::recursive::ttm0( p-1, c, nc, wc, a, na, wa, b, nb, wb);
- }
- template <class PointerIn1, class PointerIn2, class PointerOut, class SizeType>
- void ttt(SizeType const pa, SizeType const pb, SizeType const q,
- SizeType const*const phia, SizeType const*const phib,
- PointerOut c, SizeType const*const nc, SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
- static_assert( std::is_pointer<PointerOut>::value & std::is_pointer<PointerIn1>::value & std::is_pointer<PointerIn2>::value,
- "Static error in boost::numeric::ublas::ttm: Argument types for pointers are not pointer types.");
- if( pa == 0 || pb == 0)
- throw std::length_error("Error in boost::numeric::ublas::ttt: tensor order must be greater zero.");
- if( q > pa && q > pb)
- throw std::length_error("Error in boost::numeric::ublas::ttt: number of contraction must be smaller than or equal to the tensor order.");
- SizeType const r = pa - q;
- SizeType const s = pb - q;
- if(c == nullptr || a == nullptr || b == nullptr)
- throw std::length_error("Error in boost::numeric::ublas::ttm: Pointers shall not be null pointers.");
- for(auto i = 0ul; i < r; ++i)
- if( na[phia[i]-1] != nc[i] )
- throw std::length_error("Error in boost::numeric::ublas::ttt: dimensions of lhs and res tensor not correct.");
- for(auto i = 0ul; i < s; ++i)
- if( nb[phib[i]-1] != nc[r+i] )
- throw std::length_error("Error in boost::numeric::ublas::ttt: dimensions of rhs and res not correct.");
- for(auto i = 0ul; i < q; ++i)
- if( nb[phib[s+i]-1] != na[phia[r+i]-1] )
- throw std::length_error("Error in boost::numeric::ublas::ttt: dimensions of lhs and rhs not correct.");
- if(q == 0ul)
- detail::recursive::outer(SizeType{0},r,s, phia,phib, c,nc,wc, a,na,wa, b,nb,wb);
- else
- detail::recursive::ttt(SizeType{0},r,s,q, phia,phib, c,nc,wc, a,na,wa, b,nb,wb);
- }
- template <class PointerIn1, class PointerIn2, class PointerOut, class SizeType>
- void ttt(SizeType const pa, SizeType const pb, SizeType const q,
- PointerOut c, SizeType const*const nc, SizeType const*const wc,
- PointerIn1 a, SizeType const*const na, SizeType const*const wa,
- PointerIn2 b, SizeType const*const nb, SizeType const*const wb)
- {
- static_assert( std::is_pointer<PointerOut>::value & std::is_pointer<PointerIn1>::value & std::is_pointer<PointerIn2>::value,
- "Static error in boost::numeric::ublas::ttm: Argument types for pointers are not pointer types.");
- if( pa == 0 || pb == 0)
- throw std::length_error("Error in boost::numeric::ublas::ttt: tensor order must be greater zero.");
- if( q > pa && q > pb)
- throw std::length_error("Error in boost::numeric::ublas::ttt: number of contraction must be smaller than or equal to the tensor order.");
- SizeType const r = pa - q;
- SizeType const s = pb - q;
- SizeType const pc = r+s;
- if(c == nullptr || a == nullptr || b == nullptr)
- throw std::length_error("Error in boost::numeric::ublas::ttm: Pointers shall not be null pointers.");
- for(auto i = 0ul; i < r; ++i)
- if( na[i] != nc[i] )
- throw std::length_error("Error in boost::numeric::ublas::ttt: dimensions of lhs and res tensor not correct.");
- for(auto i = 0ul; i < s; ++i)
- if( nb[i] != nc[r+i] )
- throw std::length_error("Error in boost::numeric::ublas::ttt: dimensions of rhs and res not correct.");
- for(auto i = 0ul; i < q; ++i)
- if( nb[s+i] != na[r+i] )
- throw std::length_error("Error in boost::numeric::ublas::ttt: dimensions of lhs and rhs not correct.");
- using value_type = std::decay_t<decltype(*c)>;
- if(q == 0ul)
- detail::recursive::outer(pa, pc-1, c,nc,wc, pa-1, a,na,wa, pb-1, b,nb,wb);
- else if(r == 0ul && s == 0ul)
- *c = detail::recursive::inner(q-1, na, a,wa, b,wb, value_type(0) );
- else
- detail::recursive::ttt(SizeType{0},r,s,q, c,nc,wc, a,na,wa, b,nb,wb);
- }
- template <class PointerIn1, class PointerIn2, class value_t, class SizeType>
- auto inner(const SizeType p, SizeType const*const n,
- const PointerIn1 a, SizeType const*const wa,
- const PointerIn2 b, SizeType const*const wb,
- value_t v)
- {
- static_assert( std::is_pointer<PointerIn1>::value && std::is_pointer<PointerIn2>::value,
- "Static error in boost::numeric::ublas::inner: Argument types for pointers must be pointer types.");
- if(p<2)
- throw std::length_error("Error in boost::numeric::ublas::inner: Rank must be greater than zero.");
- if(a == nullptr || b == nullptr)
- throw std::length_error("Error in boost::numeric::ublas::inner: Pointers shall not be null pointers.");
- return detail::recursive::inner(p-1, n, a, wa, b, wb, v);
- }
- template <class PointerOut, class PointerIn1, class PointerIn2, class SizeType>
- void outer(PointerOut c, SizeType const pc, SizeType const*const nc, SizeType const*const wc,
- const PointerIn1 a, SizeType const pa, SizeType const*const na, SizeType const*const wa,
- const PointerIn2 b, SizeType const pb, SizeType const*const nb, SizeType const*const wb)
- {
- static_assert( std::is_pointer<PointerIn1>::value & std::is_pointer<PointerIn2>::value & std::is_pointer<PointerOut>::value,
- "Static error in boost::numeric::ublas::outer: argument types for pointers must be pointer types.");
- if(pa < 2u || pb < 2u)
- throw std::length_error("Error in boost::numeric::ublas::outer: number of extents of lhs and rhs tensor must be equal or greater than two.");
- if((pa + pb) != pc)
- throw std::length_error("Error in boost::numeric::ublas::outer: number of extents of lhs plus rhs tensor must be equal to the number of extents of C.");
- if(a == nullptr || b == nullptr || c == nullptr)
- throw std::length_error("Error in boost::numeric::ublas::outer: pointers shall not be null pointers.");
- detail::recursive::outer(pa, pc-1, c, nc, wc, pa-1, a, na, wa, pb-1, b, nb, wb);
- }
- }
- }
- }
- #endif
|