Loading...
Searching...
No Matches
SymEngine::UDictWrapper< Vec, Value, Wrapper > Class Template Reference
+ Collaboration diagram for SymEngine::UDictWrapper< Vec, Value, Wrapper >:

Public Types

using Dict = std::unordered_map< Vec, Value, vec_hash< Vec > >
 
typedef Vec vec_type
 
typedef Value coef_type
 
typedef Dict dict_type
 

Public Member Functions

 UDictWrapper (unsigned int s) SYMENGINE_NOEXCEPT
 
 UDictWrapper (Dict &&p, unsigned int sz)
 
 UDictWrapper (const Dict &p, unsigned int sz)
 
Wrapper & operator= (Wrapper &&other)
 
Wrapper & operator+= (const Wrapper &other)
 
Wrapper operator- () const
 
Wrapper & operator-= (const Wrapper &other)
 
Wrapper & operator*= (const Wrapper &other)
 
bool operator== (const Wrapper &other) const
 
bool operator!= (const Wrapper &other) const
 
const Dictget_dict () const
 
bool empty () const
 
Value get_coeff (Vec &x) const
 
Wrapper translate (const vec_uint &translator, unsigned int size) const
 

Static Public Member Functions

static Wrapper mul (const Wrapper &a, const Wrapper &b)
 
static Wrapper pow (const Wrapper &a, unsigned int p)
 

Data Fields

Dict dict_
 
unsigned int vec_size
 

Friends

Wrapper operator+ (const Wrapper &a, const Wrapper &b)
 
Wrapper operator- (const Wrapper &a, const Wrapper &b)
 
Wrapper operator* (const Wrapper &a, const Wrapper &b)
 

Detailed Description

template<typename Vec, typename Value, typename Wrapper>
class SymEngine::UDictWrapper< Vec, Value, Wrapper >

Definition at line 14 of file msymenginepoly.h.

Member Typedef Documentation

◆ coef_type

template<typename Vec , typename Value , typename Wrapper >
typedef Value SymEngine::UDictWrapper< Vec, Value, Wrapper >::coef_type

Definition at line 22 of file msymenginepoly.h.

◆ Dict

template<typename Vec , typename Value , typename Wrapper >
using SymEngine::UDictWrapper< Vec, Value, Wrapper >::Dict = std::unordered_map<Vec, Value, vec_hash<Vec> >

Definition at line 17 of file msymenginepoly.h.

◆ dict_type

template<typename Vec , typename Value , typename Wrapper >
typedef Dict SymEngine::UDictWrapper< Vec, Value, Wrapper >::dict_type

Definition at line 23 of file msymenginepoly.h.

◆ vec_type

template<typename Vec , typename Value , typename Wrapper >
typedef Vec SymEngine::UDictWrapper< Vec, Value, Wrapper >::vec_type

Definition at line 21 of file msymenginepoly.h.

Constructor & Destructor Documentation

◆ UDictWrapper() [1/4]

template<typename Vec , typename Value , typename Wrapper >
SymEngine::UDictWrapper< Vec, Value, Wrapper >::UDictWrapper ( unsigned int  s)
inline

Definition at line 25 of file msymenginepoly.h.

26 {
27 vec_size = s;
28 }

◆ UDictWrapper() [2/4]

template<typename Vec , typename Value , typename Wrapper >
SymEngine::UDictWrapper< Vec, Value, Wrapper >::UDictWrapper ( )
inline

Definition at line 30 of file msymenginepoly.h.

30{}

◆ ~UDictWrapper()

template<typename Vec , typename Value , typename Wrapper >
SymEngine::UDictWrapper< Vec, Value, Wrapper >::~UDictWrapper ( )
inline

Definition at line 32 of file msymenginepoly.h.

32{}

◆ UDictWrapper() [3/4]

template<typename Vec , typename Value , typename Wrapper >
SymEngine::UDictWrapper< Vec, Value, Wrapper >::UDictWrapper ( Dict &&  p,
unsigned int  sz 
)
inline

Definition at line 34 of file msymenginepoly.h.

35 {
36 auto iter = p.begin();
37 while (iter != p.end()) {
38 if (iter->second == 0) {
39 auto toErase = iter;
40 iter++;
41 p.erase(toErase);
42 } else {
43 iter++;
44 }
45 }
46
47 dict_ = p;
48 vec_size = sz;
49 }

◆ UDictWrapper() [4/4]

template<typename Vec , typename Value , typename Wrapper >
SymEngine::UDictWrapper< Vec, Value, Wrapper >::UDictWrapper ( const Dict p,
unsigned int  sz 
)
inline

Definition at line 51 of file msymenginepoly.h.

52 {
53 for (auto &iter : p) {
54 if (iter.second != Value(0))
55 dict_[iter.first] = iter.second;
56 }
57 vec_size = sz;
58 }

Member Function Documentation

◆ empty()

template<typename Vec , typename Value , typename Wrapper >
bool SymEngine::UDictWrapper< Vec, Value, Wrapper >::empty ( ) const
inline

Definition at line 228 of file msymenginepoly.h.

229 {
230 return dict_.empty();
231 }
T empty(T... args)

◆ get_coeff()

template<typename Vec , typename Value , typename Wrapper >
Value SymEngine::UDictWrapper< Vec, Value, Wrapper >::get_coeff ( Vec &  x) const
inline

Definition at line 233 of file msymenginepoly.h.

234 {
235 auto ite = dict_.find(x);
236 if (ite != dict_.end())
237 return ite->second;
238 return Value(0);
239 }
T end(T... args)
T find(T... args)

◆ get_dict()

template<typename Vec , typename Value , typename Wrapper >
const Dict & SymEngine::UDictWrapper< Vec, Value, Wrapper >::get_dict ( ) const
inline

Definition at line 223 of file msymenginepoly.h.

224 {
225 return dict_;
226 }

◆ mul()

template<typename Vec , typename Value , typename Wrapper >
static Wrapper SymEngine::UDictWrapper< Vec, Value, Wrapper >::mul ( const Wrapper &  a,
const Wrapper &  b 
)
inlinestatic

Definition at line 130 of file msymenginepoly.h.

131 {
132 SYMENGINE_ASSERT(a.vec_size == b.vec_size)
133
134 Wrapper p(a.vec_size);
135 for (auto const &a_ : a.dict_) {
136 for (auto const &b_ : b.dict_) {
137
138 Vec target(a.vec_size, 0);
139 for (unsigned int i = 0; i < a.vec_size; i++)
140 target[i] = a_.first[i] + b_.first[i];
141
142 if (p.dict_.find(target) == p.dict_.end()) {
143 p.dict_.insert({target, a_.second * b_.second});
144 } else {
145 p.dict_.find(target)->second += a_.second * b_.second;
146 }
147 }
148 }
149
150 for (auto it = p.dict_.begin(); it != p.dict_.end();) {
151 if (it->second == 0) {
152 p.dict_.erase(it++);
153 } else {
154 ++it;
155 }
156 }
157 return p;
158 }

◆ operator!=()

template<typename Vec , typename Value , typename Wrapper >
bool SymEngine::UDictWrapper< Vec, Value, Wrapper >::operator!= ( const Wrapper &  other) const
inline

Definition at line 218 of file msymenginepoly.h.

219 {
220 return not(*this == other);
221 }

◆ operator*=()

template<typename Vec , typename Value , typename Wrapper >
Wrapper & SymEngine::UDictWrapper< Vec, Value, Wrapper >::operator*= ( const Wrapper &  other)
inline

Definition at line 186 of file msymenginepoly.h.

187 {
188 SYMENGINE_ASSERT(vec_size == other.vec_size)
189
190 if (dict_.empty())
191 return static_cast<Wrapper &>(*this);
192
193 if (other.dict_.empty()) {
194 dict_.clear();
195 return static_cast<Wrapper &>(*this);
196 }
197
198 Vec zero_v(vec_size, 0);
199 // ! other is a just constant term
200 if (other.dict_.size() == 1
201 and other.dict_.find(zero_v) != other.dict_.end()) {
202 auto t = other.dict_.begin();
203 for (auto &i1 : dict_)
204 i1.second *= t->second;
205 return static_cast<Wrapper &>(*this);
206 }
207
208 Wrapper res = Wrapper::mul(static_cast<Wrapper &>(*this), other);
209 res.dict_.swap(this->dict_);
210 return static_cast<Wrapper &>(*this);
211 }
T clear(T... args)

◆ operator+=()

template<typename Vec , typename Value , typename Wrapper >
Wrapper & SymEngine::UDictWrapper< Vec, Value, Wrapper >::operator+= ( const Wrapper &  other)
inline

Definition at line 77 of file msymenginepoly.h.

78 {
79 SYMENGINE_ASSERT(vec_size == other.vec_size)
80
81 for (auto &iter : other.dict_) {
82 auto t = dict_.find(iter.first);
83 if (t != dict_.end()) {
84 t->second += iter.second;
85 if (t->second == 0)
86 dict_.erase(t);
87 } else {
88 dict_.insert(t, {iter.first, iter.second});
89 }
90 }
91 return static_cast<Wrapper &>(*this);
92 }

◆ operator-()

template<typename Vec , typename Value , typename Wrapper >
Wrapper SymEngine::UDictWrapper< Vec, Value, Wrapper >::operator- ( ) const
inline

Definition at line 103 of file msymenginepoly.h.

104 {
105 auto c = *this;
106 for (auto &iter : c.dict_)
107 iter.second *= -1;
108 return static_cast<Wrapper &>(c);
109 }

◆ operator-=()

template<typename Vec , typename Value , typename Wrapper >
Wrapper & SymEngine::UDictWrapper< Vec, Value, Wrapper >::operator-= ( const Wrapper &  other)
inline

Definition at line 113 of file msymenginepoly.h.

114 {
115 SYMENGINE_ASSERT(vec_size == other.vec_size)
116
117 for (auto &iter : other.dict_) {
118 auto t = dict_.find(iter.first);
119 if (t != dict_.end()) {
120 t->second -= iter.second;
121 if (t->second == 0)
122 dict_.erase(t);
123 } else {
124 dict_.insert(t, {iter.first, -iter.second});
125 }
126 }
127 return static_cast<Wrapper &>(*this);
128 }

◆ operator=()

template<typename Vec , typename Value , typename Wrapper >
Wrapper & SymEngine::UDictWrapper< Vec, Value, Wrapper >::operator= ( Wrapper &&  other)
inline

Definition at line 60 of file msymenginepoly.h.

61 {
62 if (this != &other)
63 dict_ = std::move(other.dict_);
64 return static_cast<Wrapper &>(*this);
65 }
T move(T... args)

◆ operator==()

template<typename Vec , typename Value , typename Wrapper >
bool SymEngine::UDictWrapper< Vec, Value, Wrapper >::operator== ( const Wrapper &  other) const
inline

Definition at line 213 of file msymenginepoly.h.

214 {
215 return dict_ == other.dict_;
216 }

◆ pow()

template<typename Vec , typename Value , typename Wrapper >
static Wrapper SymEngine::UDictWrapper< Vec, Value, Wrapper >::pow ( const Wrapper &  a,
unsigned int  p 
)
inlinestatic

Definition at line 160 of file msymenginepoly.h.

161 {
162 Wrapper tmp = a, res(a.vec_size);
163
164 Vec zero_v(a.vec_size, 0);
165 res.dict_[zero_v] = 1_z;
166
167 while (p != 1) {
168 if (p % 2 == 0) {
169 tmp = tmp * tmp;
170 } else {
171 res = res * tmp;
172 tmp = tmp * tmp;
173 }
174 p >>= 1;
175 }
176
177 return (res * tmp);
178 }

◆ translate()

template<typename Vec , typename Value , typename Wrapper >
Wrapper SymEngine::UDictWrapper< Vec, Value, Wrapper >::translate ( const vec_uint translator,
unsigned int  size 
) const
inline

Definition at line 241 of file msymenginepoly.h.

242 {
243 SYMENGINE_ASSERT(translator.size() == vec_size)
244 SYMENGINE_ASSERT(size >= vec_size)
245
246 Dict d;
247
248 for (auto it : dict_) {
249 Vec changed;
250 changed.resize(size, 0);
251 for (unsigned int i = 0; i < vec_size; i++)
252 changed[translator[i]] = it.first[i];
253 d.insert({changed, it.second});
254 }
255
256 return Wrapper(std::move(d), size);
257 }
T insert(T... args)

Friends And Related Function Documentation

◆ operator*

template<typename Vec , typename Value , typename Wrapper >
Wrapper operator* ( const Wrapper &  a,
const Wrapper &  b 
)
friend

Definition at line 180 of file msymenginepoly.h.

181 {
182 SYMENGINE_ASSERT(a.vec_size == b.vec_size)
183 return Wrapper::mul(a, b);
184 }

◆ operator+

template<typename Vec , typename Value , typename Wrapper >
Wrapper operator+ ( const Wrapper &  a,
const Wrapper &  b 
)
friend

Definition at line 67 of file msymenginepoly.h.

68 {
69 SYMENGINE_ASSERT(a.vec_size == b.vec_size)
70 Wrapper c = a;
71 c += b;
72 return c;
73 }

◆ operator-

template<typename Vec , typename Value , typename Wrapper >
Wrapper operator- ( const Wrapper &  a,
const Wrapper &  b 
)
friend

Definition at line 94 of file msymenginepoly.h.

95 {
96 SYMENGINE_ASSERT(a.vec_size == b.vec_size)
97
98 Wrapper c = a;
99 c -= b;
100 return c;
101 }

Field Documentation

◆ dict_

template<typename Vec , typename Value , typename Wrapper >
Dict SymEngine::UDictWrapper< Vec, Value, Wrapper >::dict_

Definition at line 18 of file msymenginepoly.h.

◆ vec_size

template<typename Vec , typename Value , typename Wrapper >
unsigned int SymEngine::UDictWrapper< Vec, Value, Wrapper >::vec_size

Definition at line 19 of file msymenginepoly.h.


The documentation for this class was generated from the following file: