Merge branch 'master' of git://factorcode.org/git/factor

db4
Doug Coleman 2009-09-30 14:13:03 -05:00
commit 9b5690a8ad
8 changed files with 153 additions and 34 deletions

View File

@ -44,6 +44,9 @@ M: word test-cfg
nl nl
] each ; ] each ;
: test-mr. ( quot -- )
test-mr mr. ; inline
! Prettyprinting ! Prettyprinting
: pprint-loc ( loc word -- ) <block pprint-word n>> pprint* block> ; : pprint-loc ( loc word -- ) <block pprint-word n>> pprint* block> ;
@ -79,4 +82,4 @@ M: rs-loc pprint* \ R pprint-loc ;
[ [ defs-vreg ] [ defs-vreg-rep ] bi 2dup and [ 2array ] [ 2drop f ] if ] [ [ defs-vreg ] [ defs-vreg-rep ] bi 2dup and [ 2array ] [ 2drop f ] if ]
bi [ suffix ] when* bi [ suffix ] when*
] map concat ] map concat
] map concat >hashtable representations set ; ] map concat >hashtable representations set ;

View File

@ -1,10 +1,21 @@
USING: help.markup help.syntax math math.functions sequences ; USING: help.markup help.syntax math math.functions sequences ;
IN: math.vectors IN: math.vectors
ARTICLE: "math-vectors" "Vector arithmetic" ARTICLE: "math-vectors-arithmetic" "Vector arithmetic"
"Any Factor sequence can be used to represent a mathematical vector, however for best performance, the sequences defined by the " { $vocab-link "specialized-arrays" } " and " { $vocab-link "math.vectors.simd" } " vocabularies should be used." "Vector/vector binary operations:"
$nl { $subsection v+ }
"Acting on vectors by a scalar:" { $subsection v- }
{ $subsection v+- }
{ $subsection v* }
{ $subsection v/ }
"Vector unary operations:"
{ $subsection vneg }
{ $subsection vabs }
{ $subsection vsqrt }
{ $subsection vfloor }
{ $subsection vceiling }
{ $subsection vtruncate }
"Vector/scalar and scalar/vector binary operations:"
{ $subsection vneg } { $subsection vneg }
{ $subsection v*n } { $subsection v*n }
{ $subsection n*v } { $subsection n*v }
@ -14,24 +25,21 @@ $nl
{ $subsection n+v } { $subsection n+v }
{ $subsection v-n } { $subsection v-n }
{ $subsection n-v } { $subsection n-v }
"Vector unary operations:"
{ $subsection vneg }
{ $subsection vabs }
{ $subsection vsqrt }
{ $subsection vfloor }
{ $subsection vceiling }
{ $subsection vtruncate }
"Vector/vector binary operations:"
{ $subsection v+ }
{ $subsection v- }
{ $subsection v+- }
{ $subsection v* }
{ $subsection v/ }
"Saturated arithmetic (only on " { $link "specialized-arrays" } "):" "Saturated arithmetic (only on " { $link "specialized-arrays" } "):"
{ $subsection vs+ } { $subsection vs+ }
{ $subsection vs- } { $subsection vs- }
{ $subsection vs* } { $subsection vs* }
"Componentwise vector operations:" "Inner product and norm:"
{ $subsection v. }
{ $subsection norm }
{ $subsection norm-sq }
{ $subsection normalize }
"Comparing entire vectors:"
{ $subsection distance }
{ $subsection v~ } ;
ARTICLE: "math-vectors-logic" "Vector componentwise logic"
"Element comparisons:"
{ $subsection v< } { $subsection v< }
{ $subsection v<= } { $subsection v<= }
{ $subsection v= } { $subsection v= }
@ -40,6 +48,8 @@ $nl
{ $subsection vunordered? } { $subsection vunordered? }
{ $subsection vmax } { $subsection vmax }
{ $subsection vmin } { $subsection vmin }
{ $subsection vsupremum }
{ $subsection vinfimum }
"Bitwise operations:" "Bitwise operations:"
{ $subsection vbitand } { $subsection vbitand }
{ $subsection vbitandn } { $subsection vbitandn }
@ -47,31 +57,29 @@ $nl
{ $subsection vbitxor } { $subsection vbitxor }
{ $subsection vlshift } { $subsection vlshift }
{ $subsection vrshift } { $subsection vrshift }
"Componentwise logical operations:" "Element logical operations:"
{ $subsection vand } { $subsection vand }
{ $subsection vor } { $subsection vor }
{ $subsection vxor } { $subsection vxor }
{ $subsection vmask } { $subsection vmask }
{ $subsection v? } { $subsection v? }
"Shuffling:" "Element shuffling:"
{ $subsection vshuffle } { $subsection vshuffle } ;
"Inner product and norm:"
{ $subsection v. } ARTICLE: "math-vectors-misc" "Miscellaneous vector functions"
{ $subsection norm }
{ $subsection norm-sq }
{ $subsection normalize }
"Comparing entire vectors:"
{ $subsection distance }
{ $subsection v~ }
"Other functions:"
{ $subsection vsupremum }
{ $subsection vinfimum }
{ $subsection trilerp } { $subsection trilerp }
{ $subsection bilerp } { $subsection bilerp }
{ $subsection vlerp } { $subsection vlerp }
{ $subsection vnlerp } { $subsection vnlerp }
{ $subsection vbilerp } ; { $subsection vbilerp } ;
ARTICLE: "math-vectors" "Vector operations"
"Any Factor sequence can be used to represent a mathematical vector, however for best performance, the sequences defined by the " { $vocab-link "specialized-arrays" } " and " { $vocab-link "math.vectors.simd" } " vocabularies should be used."
{ $subsection "math-vectors-arithmetic" }
{ $subsection "math-vectors-logic" }
{ $subsection "math-vectors-misc" } ;
ABOUT: "math-vectors" ABOUT: "math-vectors"
HELP: vneg HELP: vneg

View File

@ -0,0 +1,23 @@
USING: kernel locals math math.matrices math.order math.vectors
prettyprint sequences ;
IN: benchmark.3d-matrix-scalar
:: p-matrix ( dim fov near far -- matrix )
dim dup first2 min v/n fov v*n near v*n
near far frustum-matrix4 ;
:: mv-matrix ( pitch yaw location -- matrix )
{ 1.0 0.0 0.0 } pitch rotation-matrix4
{ 0.0 1.0 0.0 } yaw rotation-matrix4
location vneg translation-matrix4 m. m. ;
:: 3d-matrix ( -- )
f :> result!
100000 [
{ 1024.0 768.0 } 0.7 0.25 1024.0 p-matrix :> p
3.0 1.0 { 10.0 -0.0 2.0 } mv-matrix :> mv
mv p m. result!
] times
result . ;
MAIN: 3d-matrix

View File

@ -0,0 +1,28 @@
USING: kernel locals math math.matrices.simd math.order math.vectors
math.vectors.simd prettyprint sequences typed ;
QUALIFIED-WITH: alien.c-types c
SIMD: c:float
IN: benchmark.3d-matrix-vector
: v2min ( xy -- xx )
dup { 1 0 2 3 } vshuffle vmin ; inline
TYPED:: p-matrix ( dim: float-4 fov: float near: float far: float -- matrix: matrix4 )
dim dup v2min v/ fov v*n near v*n
near far frustum-matrix4 ;
TYPED:: mv-matrix ( pitch: float yaw: float location: float-4 -- matrix: matrix4 )
float-4{ 1.0 0.0 0.0 0.0 } pitch rotation-matrix4
float-4{ 0.0 1.0 0.0 0.0 } yaw rotation-matrix4
location vneg translation-matrix4 m4. m4. ;
:: 3d-matrix ( -- )
f :> result!
100000 [
float-4{ 1024.0 768.0 0.0 0.0 } 0.7 0.25 1024.0 p-matrix :> p
3.0 1.0 float-4{ 10.0 -0.0 2.0 0.0 } mv-matrix :> mv
mv p m4. result!
] times
result . ;
MAIN: 3d-matrix

View File

@ -0,0 +1,24 @@
USING: locals math math.combinatorics math.matrices
prettyprint sequences typed ;
IN: benchmark.matrix-exponential-scalar
:: e^m ( m iterations -- e^m )
{
{ 0.0 0.0 0.0 0.0 }
{ 0.0 0.0 0.0 0.0 }
{ 0.0 0.0 0.0 0.0 }
{ 0.0 0.0 0.0 0.0 }
}
iterations iota [| i |
m i m^n i factorial >float m/n m+
] each ;
:: matrix-e ( -- )
f :> result!
4 identity-matrix :> i4
10000 [
i4 20 e^m result!
] times
result . ;
MAIN: matrix-e

View File

@ -0,0 +1,18 @@
USING: locals math math.combinatorics math.matrices.simd
prettyprint sequences typed ;
IN: benchmark.matrix-exponential-simd
TYPED:: e^m4 ( m: matrix4 iterations: fixnum -- e^m: matrix4 )
zero-matrix4
iterations iota [| i |
m i m4^n i factorial >float m4/n m4+
] each ;
:: matrix-e ( -- )
f :> result!
10000 [
identity-matrix4 20 e^m4 result!
] times
result . ;
MAIN: matrix-e

View File

@ -1,6 +1,6 @@
! (c)Joe Groff bsd license ! (c)Joe Groff bsd license
USING: accessors classes.struct generalizations kernel locals USING: accessors classes.struct generalizations kernel locals
math math.functions math.matrices.simd math.vectors math math.combinatorics math.functions math.matrices.simd math.vectors
math.vectors.simd sequences sequences.private specialized-arrays math.vectors.simd sequences sequences.private specialized-arrays
typed ; typed ;
QUALIFIED-WITH: alien.c-types c QUALIFIED-WITH: alien.c-types c
@ -105,6 +105,19 @@ CONSTANT: identity-matrix4
} }
} }
CONSTANT: zero-matrix4
S{ matrix4 f
float-4-array{
float-4{ 0.0 0.0 0.0 0.0 }
float-4{ 0.0 0.0 0.0 0.0 }
float-4{ 0.0 0.0 0.0 0.0 }
float-4{ 0.0 0.0 0.0 0.0 }
}
}
TYPED:: m4^n ( m: matrix4 n: fixnum -- m^n: matrix4 )
identity-matrix4 n [ m m4. ] times ;
TYPED:: scale-matrix4 ( factors: float-4 -- matrix: matrix4 ) TYPED:: scale-matrix4 ( factors: float-4 -- matrix: matrix4 )
matrix4 (struct) :> c matrix4 (struct) :> c

View File

@ -4,5 +4,7 @@ IN: typed.debugger
: typed-test-mr ( word -- mrs ) : typed-test-mr ( word -- mrs )
"typed-word" word-prop test-mr ; inline "typed-word" word-prop test-mr ; inline
: typed-test-mr. ( word -- )
"typed-word" word-prop test-mr mr. ; inline
: typed-optimized. ( word -- ) : typed-optimized. ( word -- )
"typed-word" word-prop optimized. ; inline "typed-word" word-prop optimized. ; inline