]> gitweb.factorcode.org Git - factor.git/commitdiff
math: using ``v.`` instead of ``v* sum`` in a few places.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 24 Oct 2017 19:26:39 +0000 (12:26 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 24 Oct 2017 19:26:39 +0000 (12:26 -0700)
basis/math/polynomials/polynomials.factor
extra/arrays/shaped/shaped.factor
extra/euler/modeling/modeling.factor
extra/gml/coremath/coremath.factor
extra/math/distances/distances.factor
extra/math/similarity/similarity.factor

index 5312804ff2ac65272e629a696f312e47e8bcb2c3..b5d074e9549be5f47d4f25c76b52e85b0a2d3b50 100644 (file)
@@ -36,7 +36,7 @@ ALIAS: n*p n*v
     [ drop length [ <iota> ] keep ]
     [ nip <reversed> ]
     [ drop ] 2tri
-    '[ _ _ <slice> _ v* sum ] map reverse! ;
+    '[ _ _ <slice> _ v. ] map reverse! ;
 
 : p-sq ( p -- p^2 ) dup p* ; inline
 
index e02ef76edd9e6ab46b42bb9a3084dab1f33b6719..81c2a48fe2f7bef54c23e4c3369080bdf08ab506 100644 (file)
@@ -208,10 +208,10 @@ ERROR: shaped-bounds-error seq shape ;
 
 ! Inefficient
 : calculate-row-major-index ( seq shape -- i )
-    1 [ * ] accumulate nip reverse v* sum ;
+    1 [ * ] accumulate nip reverse v. ;
 
 : calculate-column-major-index ( seq shape -- i )
-    1 [ * ] accumulate nip v* sum ;
+    1 [ * ] accumulate nip v. ;
 
 : set-shaped-row-major ( obj seq shaped -- )
     shaped-bounds-check [ shape calculate-row-major-index ] [ underlying>> ] bi set-nth ;
index 21c69742831351ca3f3b2ed6c02a9392d9dfd127..b72112e952538b166e14f9471fd32ca67ae26b7e 100644 (file)
@@ -65,7 +65,7 @@ sharp-continue ;
 
 :: project-pt-line ( p p0 p1 -- q )
     p1 p0 v- :> vt
-    p p0 v- vt v* sum
+    p p0 v- vt v.
     vt norm-sq /
     vt n*v p0 v+ ; inline
 
index bfb6a1b4624395dfa59fccaab85e1c7d04fc9021..3a4d72d1531f5bed2faea74544ef8c9bcb448963 100644 (file)
@@ -191,7 +191,7 @@ GML: aNormal ( x -- y )
     } cond ;
 
 : det2 ( x y -- z )
-    { 1 0 } vshuffle double-2{ 1 -1 } v* v* sum ; inline
+    { 1 0 } vshuffle double-2{ 1 -1 } v* v. ; inline
 
 : det3 ( x y z -- w )
     [ cross ] dip v. ; inline
index e59fbad5d04ba01011966011c3c0045c834bb0da..7f56d6da19bfd7f1c244ae4e933ea8a3438c01e5 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2012 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: kernel math math.functions math.statistics math.vectors
-sequences sequences.extras ;
+USING: kernel math math.functions math.similarity
+math.statistics math.vectors sequences sequences.extras ;
 
 IN: math.distances
 
@@ -22,7 +22,7 @@ IN: math.distances
     v- vabs supremum ;
 
 : cosine-distance ( a b -- n )
-    [ v* sum ] [ [ norm ] bi@ * ] 2bi / 1 swap - ;
+    cosine-similarity 1 swap - ;
 
 : canberra-distance ( a b -- n )
     [ v- vabs ] [ [ vabs ] bi@ v+ ] 2bi v/ sum ;
@@ -31,4 +31,4 @@ IN: math.distances
     [ v- ] [ v+ ] 2bi [ vabs sum ] bi@ / ;
 
 : correlation-distance ( a b -- n )
-    [ demean ] bi@ [ v* sum ] [ [ norm ] bi@ * ] 2bi / 1 swap - ;
+    [ demean ] bi@ cosine-distance ;
index 1fdc82cfdb449aecb3b8200c58ed1e2bed8e77f1..6f4cfa89356af290ff425655b9c05505f3049747 100644 (file)
@@ -12,4 +12,4 @@ IN: math.similarity
     over length 3 < [ 2drop 1.0 ] [ population-corr 0.5 * 0.5 + ] if ;
 
 : cosine-similarity ( a b -- n )
-    [ v* sum ] [ [ norm ] bi@ * ] 2bi / ;
+    [ v. ] [ [ norm ] bi@ * ] 2bi / ;