]> gitweb.factorcode.org Git - factor.git/commitdiff
add software vall?, vany?, vnone? words
authorJoe Groff <arcata@gmail.com>
Thu, 1 Oct 2009 18:21:10 +0000 (13:21 -0500)
committerJoe Groff <arcata@gmail.com>
Thu, 1 Oct 2009 18:21:10 +0000 (13:21 -0500)
basis/math/vectors/vectors-docs.factor
basis/math/vectors/vectors.factor
extra/math/matrices/simd/simd.factor

index 9b6f0a04f196e5c050fcad6eb7a3eabfb8993e64..547021afdb4f7b0216f751719fa15ca7ae8ef844 100644 (file)
@@ -61,8 +61,11 @@ ARTICLE: "math-vectors-logic" "Vector componentwise logic"
 { $subsection vand }
 { $subsection vor }
 { $subsection vxor }
-{ $subsection vmask }
 { $subsection v? }
+"Entire vector tests:"
+{ $subsection vall? }
+{ $subsection vany? }
+{ $subsection vnone? }
 "Element shuffling:"
 { $subsection vshuffle } ;
 
@@ -338,20 +341,28 @@ HELP: vnot
 { $values { "u" "a sequence of booleans" } { "w" "a sequence of booleans" } }
 { $description "Takes the logical NOT of each element of " { $snippet "u" } "." } ;
 
-HELP: vmask
-{ $values { "u" "a sequence of numbers" } { "?" "a sequence of booleans" } { "u'" "a sequence of numbers" } }
-{ $description "Returns a copy of " { $snippet "u" } " with the elements for which the corresponding element of " { $snippet "?" } " is false replaced by zero." } ;
-
 HELP: v?
 { $values { "mask" "a sequence of booleans" } { "true" "a sequence of numbers" } { "false" "a sequence of numbers" } { "w" "a sequence of numbers" } }
 { $description "Creates a new sequence by selecting elements from the " { $snippet "true" } " and " { $snippet "false" } " sequences based on whether the corresponding bits of the " { $snippet "mask" } " sequence are set or not." } ;
 
+HELP: vany?
+{ $values { "v" "a sequence of booleans" } { "?" "a boolean" } }
+{ $description "Returns true if any element of " { $snippet "v" } " is true." } ;
+
+HELP: vall?
+{ $values { "v" "a sequence of booleans" } { "?" "a boolean" } }
+{ $description "Returns true if every element of " { $snippet "v" } " is true." } ;
+
+HELP: vnone?
+{ $values { "v" "a sequence of booleans" } { "?" "a boolean" } }
+{ $description "Returns true if every element of " { $snippet "v" } " is false." } ;
+
 { 2map v+ v- v* v/ } related-words
 
 { 2reduce v. } related-words
 
 { vs+ vs- vs* } related-words
 
-{ v< v<= v= v> v>= vunordered? vand vor vxor vnot vmask v? } related-words
+{ v< v<= v= v> v>= vunordered? vand vor vxor vnot vany? vall? vnone? v? } related-words
 
 { vbitand vbitandn vbitor vbitxor vbitnot } related-words
index ffb761c54357150af85243476a380fe0db64b974..c2bfb3f2957e7ac147ae9cfaca20b8634be170ce 100644 (file)
@@ -92,6 +92,10 @@ PRIVATE>
 : vxor ( u v -- w ) [ xor ] 2map ;
 : vnot ( u -- w )   [ not ] map ;
 
+: vall? ( v -- ? ) [ ] all? ;
+: vany? ( v -- ? ) [ ] any? ;
+: vnone? ( v -- ? ) [ not ] all? ;
+
 : v<  ( u v -- w ) [ <   ] { } 2map-as ;
 : v<= ( u v -- w ) [ <=  ] { } 2map-as ;
 : v>= ( u v -- w ) [ >=  ] { } 2map-as ;
@@ -102,8 +106,6 @@ PRIVATE>
 : v? ( mask true false -- w )
     [ vbitand ] [ vbitandn ] bi-curry* bi vbitor ; inline
 
-: vmask ( u ? -- u' ) vbitand ; inline
-
 : vfloor    ( u -- v ) [ floor ] map ;
 : vceiling  ( u -- v ) [ ceiling ] map ;
 : vtruncate ( u -- v ) [ truncate ] map ;
index fc6c2a03f8d9cabd49ba84030af0ee5345820e26..16960993b60243b5c0dd55e78d1739f96745e1a6 100644 (file)
@@ -132,7 +132,7 @@ TYPED:: m4^n ( m: matrix4 n: fixnum -- m^n: matrix4 )
 TYPED:: scale-matrix4 ( factors: float-4 -- matrix: matrix4 )
     matrix4 (struct) :> c
 
-    factors float-4{ t t t f } vmask :> factors'
+    factors float-4{ t t t f } vbitand :> factors'
 
     factors' { 0 3 3 3 } vshuffle
     factors' { 3 1 3 3 } vshuffle
@@ -150,9 +150,9 @@ TYPED:: translation-matrix4 ( offset: float-4 -- matrix: matrix4 )
     float-4{ 0.0 0.0 0.0 1.0 } :> c4
     float-4{ t t t f } offset c4 v? :> offset'
 
-    offset' { 3 3 3 0 } vshuffle float-4{ t f f t } vmask
-    offset' { 3 3 3 1 } vshuffle float-4{ f t f t } vmask
-    offset' { 3 3 3 2 } vshuffle float-4{ f f t t } vmask
+    offset' { 3 3 3 0 } vshuffle float-4{ t f f t } vbitand
+    offset' { 3 3 3 1 } vshuffle float-4{ f t f t } vbitand
+    offset' { 3 3 3 2 } vshuffle float-4{ f f t t } vbitand
     c4
 
     c set-rows ;
@@ -177,7 +177,7 @@ TYPED:: rotation-matrix4 ( axis: float-4 theta: float -- matrix: matrix4 )
     axis2 cc ones axis2 v- v* v+ :> diagonal
 
     axis { 1 0 0 3 } vshuffle axis { 2 2 1 3 } vshuffle v* 1-c v*
-    float-4{ t t t f } vmask :> triangle-a
+    float-4{ t t t f } vbitand :> triangle-a
     ss axis v* triangle-sign v* :> triangle-b
     triangle-a triangle-b v+ :> triangle-lo
     triangle-a triangle-b v- :> triangle-hi
@@ -200,9 +200,9 @@ TYPED:: frustum-matrix4 ( xy: float-4 near: float far: float -- matrix: matrix4
     float-4{ t t f f } xy near far - float-4-with v? :> denom
     num denom v/ :> fov
 
-    fov { 0 0 0 0 } vshuffle float-4{ t f f f } vmask
-    fov { 1 1 1 1 } vshuffle float-4{ f t f f } vmask
-    fov { 2 2 2 3 } vshuffle float-4{ f f t t } vmask
+    fov { 0 0 0 0 } vshuffle float-4{ t f f f } vbitand
+    fov { 1 1 1 1 } vshuffle float-4{ f t f f } vbitand
+    fov { 2 2 2 3 } vshuffle float-4{ f f t t } vbitand
     float-4{ 0.0 0.0 -1.0 0.0 }
 
     c set-rows ;