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

Public Types

typedef Key key_type
 

Public Member Functions

 ODictWrapper (const int &i)
 
 ODictWrapper (const std::map< Key, Value > &p)
 
 ODictWrapper (std::map< Key, Value > &&p)
 
 ODictWrapper (const Value &p)
 
 ODictWrapper (std::string s)
 
Wrapper & operator= (Wrapper &&other) SYMENGINE_NOEXCEPT
 
Wrapper & operator+= (const Wrapper &other)
 
Wrapper operator- () const
 
Wrapper & operator-= (const Wrapper &other)
 
Wrapper & operator*= (const Wrapper &other)
 
bool operator!= (const Wrapper &other) const
 
const std::map< Key, Value > & get_dict () const
 
size_t size () const
 
bool empty () const
 
Key degree () const
 
Value get_coeff (Key x) const
 
Value get_lc () const
 

Static Public Member Functions

static Wrapper from_vec (const std::vector< Value > &v)
 
static Wrapper mul (const Wrapper &a, const Wrapper &b)
 
static Wrapper pow (const Wrapper &a, unsigned int p)
 
template<typename FromPoly >
static Wrapper from_poly (const FromPoly &p)
 

Data Fields

std::map< Key, Value > dict_
 

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)
 
bool operator== (const Wrapper &a, const Wrapper &b)
 

Detailed Description

template<typename Key, typename Value, typename Wrapper>
class SymEngine::ODictWrapper< Key, Value, Wrapper >

Definition at line 104 of file upolybase.h.

Member Typedef Documentation

◆ key_type

template<typename Key , typename Value , typename Wrapper >
typedef Key SymEngine::ODictWrapper< Key, Value, Wrapper >::key_type

Definition at line 108 of file upolybase.h.

Constructor & Destructor Documentation

◆ ODictWrapper() [1/6]

template<typename Key , typename Value , typename Wrapper >
SymEngine::ODictWrapper< Key, Value, Wrapper >::ODictWrapper ( )
inline

Definition at line 111 of file upolybase.h.

111{}

◆ ~ODictWrapper()

template<typename Key , typename Value , typename Wrapper >
SymEngine::ODictWrapper< Key, Value, Wrapper >::~ODictWrapper ( )
inline

Definition at line 112 of file upolybase.h.

112{}

◆ ODictWrapper() [2/6]

template<typename Key , typename Value , typename Wrapper >
SymEngine::ODictWrapper< Key, Value, Wrapper >::ODictWrapper ( const int &  i)
inline

Definition at line 114 of file upolybase.h.

115 {
116 if (i != 0)
117 dict_ = {{0, Value(i)}};
118 }

◆ ODictWrapper() [3/6]

template<typename Key , typename Value , typename Wrapper >
SymEngine::ODictWrapper< Key, Value, Wrapper >::ODictWrapper ( const std::map< Key, Value > &  p)
inline

Definition at line 120 of file upolybase.h.

121 {
122 for (auto &iter : p) {
123 if (iter.second != Value(0))
124 dict_[iter.first] = iter.second;
125 }
126 }

◆ ODictWrapper() [4/6]

template<typename Key , typename Value , typename Wrapper >
SymEngine::ODictWrapper< Key, Value, Wrapper >::ODictWrapper ( std::map< Key, Value > &&  p)
inline

Definition at line 128 of file upolybase.h.

129 {
130 for (auto &iter : p) {
131 if (iter.second != Value(0)) {
132 auto erase = iter;
133 iter++;
134 p.erase(erase);
135 } else {
136 iter++;
137 }
138 }
139 dict_ = p;
140 }

◆ ODictWrapper() [5/6]

template<typename Key , typename Value , typename Wrapper >
SymEngine::ODictWrapper< Key, Value, Wrapper >::ODictWrapper ( const Value &  p)
inline

Definition at line 142 of file upolybase.h.

143 {
144 if (p != Value(0))
145 dict_[0] = p;
146 }

◆ ODictWrapper() [6/6]

template<typename Key , typename Value , typename Wrapper >
SymEngine::ODictWrapper< Key, Value, Wrapper >::ODictWrapper ( std::string  s)
inline

Definition at line 148 of file upolybase.h.

149 {
150 dict_[1] = Value(1);
151 }

Member Function Documentation

◆ degree()

template<typename Key , typename Value , typename Wrapper >
Key SymEngine::ODictWrapper< Key, Value, Wrapper >::degree ( ) const
inline

Definition at line 328 of file upolybase.h.

329 {
330 if (dict_.empty())
331 return Key(0);
332 return dict_.rbegin()->first;
333 }
T empty(T... args)
T rbegin(T... args)

◆ empty()

template<typename Key , typename Value , typename Wrapper >
bool SymEngine::ODictWrapper< Key, Value, Wrapper >::empty ( ) const
inline

Definition at line 323 of file upolybase.h.

324 {
325 return dict_.empty();
326 }

◆ from_poly()

template<typename Key , typename Value , typename Wrapper >
template<typename FromPoly >
static Wrapper SymEngine::ODictWrapper< Key, Value, Wrapper >::from_poly ( const FromPoly &  p)
inlinestatic

Definition at line 266 of file upolybase.h.

267 {
268 Wrapper t;
269 for (auto it = p.begin(); it != p.end(); ++it)
270 t.dict_[it->first] = it->second;
271 return t;
272 }

◆ from_vec()

template<typename Key , typename Value , typename Wrapper >
static Wrapper SymEngine::ODictWrapper< Key, Value, Wrapper >::from_vec ( const std::vector< Value > &  v)
inlinestatic

Definition at line 153 of file upolybase.h.

154 {
155 Wrapper x;
156 x.dict_ = {};
157 for (unsigned int i = 0; i < v.size(); i++) {
158 if (v[i] != Value(0)) {
159 x.dict_[i] = v[i];
160 }
161 }
162 return x;
163 }
T size(T... args)

◆ get_coeff()

template<typename Key , typename Value , typename Wrapper >
Value SymEngine::ODictWrapper< Key, Value, Wrapper >::get_coeff ( Key  x) const
inline

Definition at line 335 of file upolybase.h.

336 {
337 auto ite = dict_.find(x);
338 if (ite != dict_.end())
339 return ite->second;
340 return Value(0);
341 }
T end(T... args)
T find(T... args)

◆ get_dict()

template<typename Key , typename Value , typename Wrapper >
const std::map< Key, Value > & SymEngine::ODictWrapper< Key, Value, Wrapper >::get_dict ( ) const
inline

Definition at line 313 of file upolybase.h.

314 {
315 return dict_;
316 }

◆ get_lc()

template<typename Key , typename Value , typename Wrapper >
Value SymEngine::ODictWrapper< Key, Value, Wrapper >::get_lc ( ) const
inline

Definition at line 343 of file upolybase.h.

344 {
345 if (dict_.empty())
346 return Value(0);
347 return dict_.rbegin()->second;
348 }

◆ mul()

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

Definition at line 226 of file upolybase.h.

227 {
228 if (a.get_dict().empty())
229 return a;
230 if (b.get_dict().empty())
231 return b;
232
233 Wrapper p;
234 for (const auto &i1 : a.dict_)
235 for (const auto &i2 : b.dict_)
236 p.dict_[i1.first + i2.first] += i1.second * i2.second;
237
238 for (auto it = p.dict_.cbegin(); it != p.dict_.cend();) {
239 if (it->second == 0) {
240 p.dict_.erase(it++);
241 } else {
242 ++it;
243 }
244 }
245 return p;
246 }

◆ operator!=()

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

Definition at line 308 of file upolybase.h.

309 {
310 return not(*this == other);
311 }

◆ operator*=()

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

Definition at line 279 of file upolybase.h.

280 {
281 if (dict_.empty())
282 return static_cast<Wrapper &>(*this);
283
284 if (other.dict_.empty()) {
285 dict_.clear();
286 return static_cast<Wrapper &>(*this);
287 }
288
289 // ! other is a just constant term
290 if (other.dict_.size() == 1
291 and other.dict_.find(0) != other.dict_.end()) {
292 auto t = other.dict_.begin();
293 for (auto &i1 : dict_)
294 i1.second *= t->second;
295 return static_cast<Wrapper &>(*this);
296 }
297
298 Wrapper res = Wrapper::mul(static_cast<Wrapper &>(*this), other);
299 res.dict_.swap(this->dict_);
300 return static_cast<Wrapper &>(*this);
301 }
T clear(T... args)

◆ operator+=()

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

Definition at line 179 of file upolybase.h.

180 {
181 for (auto &iter : other.dict_) {
182 auto t = dict_.lower_bound(iter.first);
183 if (t != dict_.end() and t->first == iter.first) {
184 t->second += iter.second;
185 if (t->second == 0) {
186 dict_.erase(t);
187 }
188 } else {
189 dict_.insert(t, {iter.first, iter.second});
190 }
191 }
192 return static_cast<Wrapper &>(*this);
193 }
T erase(T... args)
T insert(T... args)
T lower_bound(T... args)

◆ operator-()

template<typename Key , typename Value , typename Wrapper >
Wrapper SymEngine::ODictWrapper< Key, Value, Wrapper >::operator- ( ) const
inline

Definition at line 202 of file upolybase.h.

203 {
204 ODictWrapper c = *this;
205 for (auto &iter : c.dict_)
206 iter.second *= -1;
207 return static_cast<Wrapper &>(c);
208 }

◆ operator-=()

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

Definition at line 210 of file upolybase.h.

211 {
212 for (auto &iter : other.dict_) {
213 auto t = dict_.lower_bound(iter.first);
214 if (t != dict_.end() and t->first == iter.first) {
215 t->second -= iter.second;
216 if (t->second == 0) {
217 dict_.erase(t);
218 }
219 } else {
220 dict_.insert(t, {iter.first, -iter.second});
221 }
222 }
223 return static_cast<Wrapper &>(*this);
224 }

◆ operator=()

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

Definition at line 165 of file upolybase.h.

166 {
167 if (this != &other)
168 dict_ = std::move(other.dict_);
169 return static_cast<Wrapper &>(*this);
170 }
T move(T... args)

◆ pow()

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

Definition at line 248 of file upolybase.h.

249 {
250 Wrapper tmp = a, res(1);
251
252 while (p != 1) {
253 if (p % 2 == 0) {
254 tmp = tmp * tmp;
255 } else {
256 res = res * tmp;
257 tmp = tmp * tmp;
258 }
259 p >>= 1;
260 }
261
262 return (res * tmp);
263 }

◆ size()

template<typename Key , typename Value , typename Wrapper >
size_t SymEngine::ODictWrapper< Key, Value, Wrapper >::size ( ) const
inline

Definition at line 318 of file upolybase.h.

319 {
320 return dict_.size();
321 }

Friends And Related Function Documentation

◆ operator*

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

Definition at line 274 of file upolybase.h.

275 {
276 return Wrapper::mul(a, b);
277 }

◆ operator+

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

Definition at line 172 of file upolybase.h.

173 {
174 Wrapper c = a;
175 c += b;
176 return c;
177 }

◆ operator-

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

Definition at line 195 of file upolybase.h.

196 {
197 Wrapper c = a;
198 c -= b;
199 return c;
200 }

◆ operator==

template<typename Key , typename Value , typename Wrapper >
bool operator== ( const Wrapper &  a,
const Wrapper &  b 
)
friend

Definition at line 303 of file upolybase.h.

304 {
305 return a.dict_ == b.dict_;
306 }

Field Documentation

◆ dict_

template<typename Key , typename Value , typename Wrapper >
std::map<Key, Value> SymEngine::ODictWrapper< Key, Value, Wrapper >::dict_

Definition at line 107 of file upolybase.h.


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