Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1656a0d

Browse filesBrowse files
myluszczakisuruf
authored andcommitted
efficiency upgrade for translate function
1 parent 45bdff9 commit 1656a0d
Copy full SHA for 1656a0d

8 files changed

+520-454Lines changed: 520 additions & 454 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎symengine/derivative.cpp‎

Copy file name to clipboardExpand all lines: symengine/derivative.cpp
+155-155Lines changed: 155 additions & 155 deletions
Large diffs are not rendered by default.
Collapse file

‎symengine/dict.cpp‎

Copy file name to clipboardExpand all lines: symengine/dict.cpp
+20-20Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ bool vec_basic_eq_perm(const vec_basic &a, const vec_basic &b)
105105
// Find the element a[i] in "b"
106106
bool found = false;
107107
for (size_t j = 0; j < a.size(); j++) {
108-
if (eq(*a[i], *b[j])) {
109-
found = true;
110-
break;
111-
}
108+
if (eq(*a[i], *b[j])) {
109+
found = true;
110+
break;
111+
}
112112
}
113113
// If not found, then a != b
114114
if (not found) return false;
@@ -132,7 +132,7 @@ int vec_basic_compare(const vec_basic &A, const vec_basic &B)
132132
}
133133

134134
bool map_uint_mpz_eq(const map_uint_mpz &a,
135-
const map_uint_mpz &b)
135+
const map_uint_mpz &b)
136136
{
137137
// Can't be equal if # of entries differ:
138138
if (a.size() != b.size()) return false;
@@ -153,9 +153,9 @@ int map_uint_mpz_compare(const map_uint_mpz &A, const map_uint_mpz &B)
153153
auto b = B.begin();
154154
for (; a != A.end(); ++a, ++b) {
155155
if (a->first != b->first)
156-
return (a->first < b->first) ? -1 : 1;
156+
return (a->first < b->first) ? -1 : 1;
157157
if (a->second != b->second)
158-
return (a->second < b->second) ? -1 : 1;
158+
return (a->second < b->second) ? -1 : 1;
159159
}
160160
return 0;
161161
}
@@ -210,27 +210,27 @@ int umap_uvec_mpz_compare(const umap_uvec_mpz &a, const umap_uvec_mpz &b) {
210210

211211
if (va.empty())
212212
if (!vb.empty())
213-
return -1;
213+
return -1;
214214
if (vb.empty())
215215
if (!va.empty())
216-
return 1;
216+
return 1;
217217
if (va.empty() && vb.empty())
218218
return 0;
219219

220220
for (unsigned int i = 0; i < va.size() && i < vb.size(); i++) {
221221
if (vec_uint_compare()(va[i], vb[i])) {
222-
return -1;
222+
return -1;
223223
} else if (!vec_uint_compare()(va[i], vb[i]) && va[i] != vb[i]) {
224-
return 1;
224+
return 1;
225225
} else {
226-
if (a.find(va[i])->second != b.find(vb[i])->second) {
227-
if(a.find(va[i])->second < b.find(vb[i])->second) {
228-
return -1;
229-
} else {
230-
return 1;
231-
}
232-
}
233-
}
226+
if (a.find(va[i])->second != b.find(vb[i])->second) {
227+
if (a.find(va[i])->second < b.find(vb[i])->second) {
228+
return -1;
229+
} else {
230+
return 1;
231+
}
232+
}
233+
}
234234
}
235235
if (va.size() < vb.size())
236236
return -1;
@@ -239,7 +239,7 @@ int umap_uvec_mpz_compare(const umap_uvec_mpz &a, const umap_uvec_mpz &b) {
239239
return 0;
240240
}
241241

242-
//coppied from umap_eq, with derefrencing of image in map removed.
242+
//Copied from umap_eq, with derefrencing of image in map removed.
243243
bool umap_uvec_mpz_eq(const umap_uvec_mpz &a, const umap_uvec_mpz &b){
244244
// This follows the same algorithm as Python's dictionary comparison
245245
// (a==b), which is implemented by "dict_equal" function in
Collapse file

‎symengine/dict.h‎

Copy file name to clipboardExpand all lines: symengine/dict.h
+30-29Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ typedef std::map<int, Expression> map_int_Expr;
5252
//! `insert(m, first, second)` is equivalent to `m[first] = second`, just faster,
5353
//! because no default constructor is called on the `second` type.
5454
template<typename T1, typename T2, typename T3> inline
55-
void insert(T1 &m, const T2 &first, const T3 &second) {
55+
void insert(T1 &m, const T2 &first, const T3 &second) {
5656
m.insert(std::pair<T2, T3>(first, second));
5757
}
5858

@@ -68,10 +68,10 @@ bool umap_eq(const T &a, const T &b)
6868
if (a.size() != b.size()) return false;
6969
// Loop over keys in "a":
7070
for (const auto &p: a) {
71-
// O(1) lookup of the key in "b":
72-
auto f = b.find(p.first);
73-
if (f == b.end()) return false; // no such element in "b"
74-
if (neq(*p.second, *f->second)) return false; // values not equal
71+
// O(1) lookup of the key in "b":
72+
auto f = b.find(p.first);
73+
if (f == b.end()) return false; // no such element in "b"
74+
if (neq(*p.second, *f->second)) return false; // values not equal
7575
}
7676
return true;
7777
}
@@ -86,8 +86,8 @@ bool map_eq(const T &A, const T &B)
8686
auto a = A.begin();
8787
auto b = B.begin();
8888
for (; a != A.end(); ++a, ++b) {
89-
if (neq(*a->first, *b->first)) return false; // keys not equal
90-
if (neq(*a->second, *b->second)) return false; // values not equal
89+
if (neq(*a->first, *b->first)) return false; // keys not equal
90+
if (neq(*a->second, *b->second)) return false; // values not equal
9191
}
9292
return true;
9393
}
@@ -112,10 +112,10 @@ int map_compare(const T &A, const T &B)
112112
auto b = B.begin();
113113
int cmp;
114114
for (; a != A.end(); ++a, ++b) {
115-
cmp = a->first->__cmp__(*b->first);
116-
if (cmp != 0) return cmp;
115+
cmp = a->first->__cmp__(*b->first);
116+
if (cmp != 0) return cmp;
117117
cmp = a->second->__cmp__(*b->second);
118-
if (cmp != 0) return cmp;
118+
if (cmp != 0) return cmp;
119119
}
120120
return 0;
121121
}
@@ -132,11 +132,11 @@ int map_int_Expr_compare(const map_int_Expr &a, const map_int_Expr &b);
132132
typedef struct
133133
{
134134
inline std::size_t operator() (const vec_int &k) const {
135-
std::size_t h = 0;
136-
for (const auto &p: k) {
137-
h = (h << 4) + p;
138-
}
139-
return h;
135+
std::size_t h = 0;
136+
for (const auto &p: k) {
137+
h = (h << 4) + p;
138+
}
139+
return h;
140140
}
141141
} vec_int_hash;
142142

@@ -153,7 +153,7 @@ class vec_uint_hash{
153153
std::size_t operator()(const vec_uint &v) const {
154154
std::size_t h = 0;
155155
for (unsigned int i : v) {
156-
h ^= i + 0x9e3779b + (h << 6) + (h >> 2);
156+
h ^= i + 0x9e3779b + (h << 6) + (h >> 2);
157157
}
158158
return h;
159159
}
@@ -163,10 +163,10 @@ class vec_uint_eq{
163163
public:
164164
bool operator()(const vec_uint &a, const vec_uint &b) const{
165165
if (a.size() != b.size())
166-
return false;
166+
return false;
167167
for (unsigned int i = 0; i < a.size(); i++) {
168-
if(a[i] != b[i])
169-
return false;
168+
if(a[i] != b[i])
169+
return false;
170170
}
171171
return true;
172172
}
@@ -176,33 +176,34 @@ class vec_uint_compare{
176176
public:
177177
bool operator()(const vec_uint &a, const vec_uint &b) const{
178178
if (a.size() != b.size())
179-
return a.size() < b.size();
179+
return a.size() < b.size();
180180
unsigned int sum1 = 0;
181181
unsigned int sum2 = 0;
182182
for (unsigned int x : a) {
183-
sum1 += x;
183+
sum1 += x;
184184
}
185185
for (unsigned int x : b) {
186-
sum2 += x;
186+
sum2 += x;
187187
}
188188
if (sum1 != sum2)
189-
return sum1 < sum2;
189+
return sum1 < sum2;
190190
return a < b;
191191
}
192192
};
193193

194194
typedef std::set< RCP<const Symbol>, RCPSymbolCompare> set_sym;
195-
typedef std::unordered_map<RCP<const Symbol>, unsigned int, RCPSymbolHash, RCPSymbolEq> umap_sym_uint;
195+
typedef std::unordered_map<RCP<const Symbol>, unsigned int, RCPSymbolHash, RCPSymbolEq>
196+
umap_sym_uint;
196197
typedef std::unordered_map<vec_uint, integer_class, vec_uint_hash, vec_uint_eq> umap_uvec_mpz;
197198

198199
//Takes an unordered map of type M with key type K and returns a vector of K ordered by C.
199200
template<class K, class M, class C>
200-
std::vector<K> order_umap(const M &d){
201+
std::vector<K> order_umap(const M &d) {
201202
std::vector<K> v;
202203
for (auto bucket : d) {
203204
auto iter = v.begin();
204205
while(iter != v.end() && C()(bucket.first,*iter)){
205-
iter++;
206+
iter++;
206207
}
207208
v.insert(iter, bucket.first);
208209
}
@@ -232,13 +233,13 @@ template<class T>
232233
int set_compare(const T &A, const T &B)
233234
{
234235
if (A.size() != B.size())
235-
return (A.size() < B.size()) ? -1 : 1;
236+
return (A.size() < B.size()) ? -1 : 1;
236237
auto a = A.begin();
237238
auto b = B.begin();
238239
int cmp;
239240
for (; a != A.end(); ++a, ++b) {
240-
cmp = (*a)->__cmp__(**b);
241-
if (cmp != 0) return cmp;
241+
cmp = (*a)->__cmp__(**b);
242+
if (cmp != 0) return cmp;
242243
}
243244
return 0;
244245
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.