CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
index_mul.cc.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_index_mul_cc_h__
13#define __cxz_index_mul_cc_h__
14
15#include "index_mul.h"
16
17namespace CNORXZ
18{
19
20 /*===================+
21 | MIndexSptrMul |
22 +===================*/
23
24 template <class BlockT, class... Indices, class I, SizeT... Is>
26 const Sptr<I>& b, Isq<Is...> is)
27 {
28 static_assert(sizeof...(Is) == sizeof...(Indices), "inconsistent index sequence");
29 return std::make_shared<MIndex<Indices...,I>>( a->pack()[CSizeT<Is>{}]..., b );
30 }
31
32 template <class BlockT, class... Indices, class I, typename Meta, SizeT... Js>
33 decltype(auto) MIndexSptrMul::evalXM(const Sptr<I>& a,
36 {
37 static_assert(sizeof...(Js) == sizeof...(Indices), "inconsistent index sequence");
38 return std::make_shared<MIndex<I,Indices...>>( a, b->pack()[CSizeT<Js>{}]... );
39 }
40
41 template <class BlockT1, class... Indices1, class BlockT2, class... Indices2,
42 SizeT... Is, SizeT... Js>
46 {
47 static_assert(sizeof...(Is) == sizeof...(Indices1), "inconsistent index sequence");
48 static_assert(sizeof...(Js) == sizeof...(Indices2), "inconsistent index sequence");
49 return MIndex<Indices1...,Indices2...>( a->pack()[CSizeT<Is>{}]...,
50 b->pack()[CSizeT<Js>{}]... );
51 }
52
53
54 /*===============+
55 | operator* |
56 +===============*/
57
58 template <class I1, typename Meta1, class I2, typename Meta2>
59 inline decltype(auto) operator*(const IndexInterface<I1,Meta1>& a,
61 {
62 if constexpr(std::is_same<I1,YIndex>::value or std::is_same<I2,YIndex>::value or
63 std::is_same<I1,DIndex>::value or std::is_same<I2,DIndex>::value) {
64 return dpack(a.THIS(), b.THIS());
65 }
66 else {
67 return spack(a.THIS(), b.THIS());
68 }
69 }
70
71 template <class I1, typename Meta1, class... Indices>
72 inline decltype(auto) operator*(const IndexInterface<I1,Meta1>& a,
73 const SPack<Indices...>& b)
74 {
75 return b.lmul(std::make_shared<I1>(a.THIS()));
76 }
77
78 template <class I2, typename Meta2, class... Indices>
79 inline decltype(auto) operator*(const SPack<Indices...>& a,
81 {
82 return a.rmul(std::make_shared<I2>(b.THIS()));
83 }
84
85 template <class Index, class... Indices>
86 inline decltype(auto) operator*(const Sptr<Index>& a,
87 const SPack<Indices...>& b)
88 {
89 static_assert(is_index<Index>::value, "got non-index type");
90 return b.lmul(a);
91 }
92
93 template <class Index, class... Indices>
94 inline decltype(auto) operator*(const SPack<Indices...>& a,
95 const Sptr<Index>& b)
96 {
97 static_assert(is_index<Index>::value, "got non-index type");
98 return a.rmul(b);
99 }
100
101 template <class... Indices1, class... Indices2>
102 inline decltype(auto) operator*(const SPack<Indices1...>& a, const SPack<Indices2...>& b)
103 {
104 return a.mul(b);
105 }
106
107 template <class I1, typename Meta1>
108 inline decltype(auto) operator*(const IndexInterface<I1,Meta1>& a, const DPack& b)
109 {
110 return b.lmul(std::make_shared<I1>(a.THIS()));
111 }
112
113 template <class I2, typename Meta2>
114 inline decltype(auto) operator*(const DPack& a, const IndexInterface<I2,Meta2>& b)
115 {
116 return a.rmul(std::make_shared<I2>(b.THIS()));
117 }
118
119 inline decltype(auto) operator*(const DPack& a, const DPack& b)
120 {
121 return a.mul(b);
122 }
123
124 /*=============+
125 | iptrMul |
126 +=============*/
127
128 template <class I1, class I2>
129 decltype(auto) iptrMul(const Sptr<I1>& a, const Sptr<I2>& b)
130 {
131 static_assert(is_index<I1>::value and is_index<I2>::value, "got non-index type");
132 if constexpr(std::is_same<I1,YIndex>::value or std::is_same<I2,YIndex>::value or
133 std::is_same<I1,DIndex>::value or std::is_same<I2,DIndex>::value) {
134 return dpackp(a, b);
135 }
136 else {
137 return spackp(a, b);
138 }
139 }
140
141}
142
143#endif
DPack rmul(const Sptr< DIndex > &i) const
Definition index_pack.cc:44
DPack mul(const DPack &p) const
Definition index_pack.cc:60
constexpr decltype(auto) rmul(const Sptr< Index > &i) const
constexpr decltype(auto) mul(const SPack< Indices2... > &p) const
Index multiplication.
DPack dpack(const Indices &... inds)
DPack dpackp(const Sptr< Indices > &... inds)
uint64_t SizeT
Definition types.h:38
constexpr decltype(auto) spack(const Indices &... inds)
std::integral_constant< SizeT, N > CSizeT
Definition types.h:81
Sptr< Range > rangeCast(const RangePtr r)
std::index_sequence< Is... > Isq
Definition types.h:74
decltype(auto) iptrMul(const Sptr< I1 > &a, const Sptr< I2 > &b)
constexpr decltype(auto) spackp(const Sptr< Indices > &... inds)
std::shared_ptr< T > Sptr
Definition types.h:48
static decltype(auto) evalMX(const Sptr< GMIndex< BlockT, Indices... > > &a, const Sptr< I > &b, Isq< Is... > is)
static decltype(auto) evalXM(const Sptr< I > &a, const Sptr< GMIndex< BlockT, Indices... > > &b, Isq< Js... > js)
static decltype(auto) evalMM(const Sptr< GMIndex< BlockT1, Indices1... > > &a, const Sptr< GMIndex< BlockT2, Indices2... > > &b, Isq< Is... > is, Isq< Js... > js)