Discussion:
[fricas-devel] [PATCH] optimize 'removeDuplicates!' in ListAggregate
oldk1331
2018-06-11 12:48:50 UTC
Permalink
optimize 'removeDuplicates!' in ListAggregate


diff --git a/src/algebra/aggcat.spad b/src/algebra/aggcat.spad
index 58c48445..64fae13e 100644
--- a/src/algebra/aggcat.spad
+++ b/src/algebra/aggcat.spad
@@ -2380,8 +2380,7 @@
removeDuplicates! l ==
p := l
while not empty? p repeat
- p := setrest!(p, remove!((x : S) : Boolean +-> x = first p,
- rest p))
+ p := setrest!(p, remove!(first p, rest p))
l

if S has OrderedSet then
--
You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+***@googlegroups.com.
To post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
oldk1331
2018-06-11 12:55:12 UTC
Permalink
A similar optimization in vector.spad:

optimize 'same?' in DirectProduct


diff --git a/src/algebra/vector.spad b/src/algebra/vector.spad
index a166f394..a18de376 100644
--- a/src/algebra/vector.spad
+++ b/src/algebra/vector.spad
@@ -386,7 +386,7 @@

if R has BasicType then
same? : % -> Boolean
- same? z == every?(x +-> x = z(minIndex z), z)
+ same? z == (z1 := z(minIndex z); every?(x +-> x = z1, z))

if R is NonNegativeInteger or R is Integer or R is PositiveInteger then
-- This is a hack to gain speed. Direct product is used
--
You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+***@googlegroups.com.
To post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
Waldek Hebisch
2018-06-11 13:30:56 UTC
Permalink
OK for the 3 'optimize' patches.
Post by oldk1331
optimize 'same?' in DirectProduct
diff --git a/src/algebra/vector.spad b/src/algebra/vector.spad
index a166f394..a18de376 100644
--- a/src/algebra/vector.spad
+++ b/src/algebra/vector.spad
@@ -386,7 +386,7 @@
if R has BasicType then
same? : % -> Boolean
- same? z == every?(x +-> x = z(minIndex z), z)
+ same? z == (z1 := z(minIndex z); every?(x +-> x = z1, z))
if R is NonNegativeInteger or R is Integer or R is PositiveInteger then
-- This is a hack to gain speed. Direct product is used
--
You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
--
Waldek Hebisch
--
You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+***@googlegroups.com.
To post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
Loading...