Merge branch 'master' of git://factorcode.org/git/factor
commit
9b5690a8ad
|
@ -44,6 +44,9 @@ M: word test-cfg
|
|||
nl
|
||||
] each ;
|
||||
|
||||
: test-mr. ( quot -- )
|
||||
test-mr mr. ; inline
|
||||
|
||||
! Prettyprinting
|
||||
: 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 ]
|
||||
bi [ suffix ] when*
|
||||
] map concat
|
||||
] map concat >hashtable representations set ;
|
||||
] map concat >hashtable representations set ;
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
USING: help.markup help.syntax math math.functions sequences ;
|
||||
IN: math.vectors
|
||||
|
||||
ARTICLE: "math-vectors" "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."
|
||||
$nl
|
||||
"Acting on vectors by a scalar:"
|
||||
ARTICLE: "math-vectors-arithmetic" "Vector arithmetic"
|
||||
"Vector/vector binary operations:"
|
||||
{ $subsection v+ }
|
||||
{ $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 v*n }
|
||||
{ $subsection n*v }
|
||||
|
@ -14,24 +25,21 @@ $nl
|
|||
{ $subsection n+v }
|
||||
{ $subsection v-n }
|
||||
{ $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" } "):"
|
||||
{ $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= }
|
||||
|
@ -40,6 +48,8 @@ $nl
|
|||
{ $subsection vunordered? }
|
||||
{ $subsection vmax }
|
||||
{ $subsection vmin }
|
||||
{ $subsection vsupremum }
|
||||
{ $subsection vinfimum }
|
||||
"Bitwise operations:"
|
||||
{ $subsection vbitand }
|
||||
{ $subsection vbitandn }
|
||||
|
@ -47,31 +57,29 @@ $nl
|
|||
{ $subsection vbitxor }
|
||||
{ $subsection vlshift }
|
||||
{ $subsection vrshift }
|
||||
"Componentwise logical operations:"
|
||||
"Element logical operations:"
|
||||
{ $subsection vand }
|
||||
{ $subsection vor }
|
||||
{ $subsection vxor }
|
||||
{ $subsection vmask }
|
||||
{ $subsection v? }
|
||||
"Shuffling:"
|
||||
{ $subsection vshuffle }
|
||||
"Inner product and norm:"
|
||||
{ $subsection v. }
|
||||
{ $subsection norm }
|
||||
{ $subsection norm-sq }
|
||||
{ $subsection normalize }
|
||||
"Comparing entire vectors:"
|
||||
{ $subsection distance }
|
||||
{ $subsection v~ }
|
||||
"Other functions:"
|
||||
{ $subsection vsupremum }
|
||||
{ $subsection vinfimum }
|
||||
"Element shuffling:"
|
||||
{ $subsection vshuffle } ;
|
||||
|
||||
ARTICLE: "math-vectors-misc" "Miscellaneous vector functions"
|
||||
{ $subsection trilerp }
|
||||
{ $subsection bilerp }
|
||||
{ $subsection vlerp }
|
||||
{ $subsection vnlerp }
|
||||
{ $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"
|
||||
|
||||
HELP: vneg
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -1,6 +1,6 @@
|
|||
! (c)Joe Groff bsd license
|
||||
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
|
||||
typed ;
|
||||
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 )
|
||||
matrix4 (struct) :> c
|
||||
|
||||
|
|
|
@ -4,5 +4,7 @@ IN: typed.debugger
|
|||
|
||||
: typed-test-mr ( word -- mrs )
|
||||
"typed-word" word-prop test-mr ; inline
|
||||
: typed-test-mr. ( word -- )
|
||||
"typed-word" word-prop test-mr mr. ; inline
|
||||
: typed-optimized. ( word -- )
|
||||
"typed-word" word-prop optimized. ; inline
|
||||
|
|
Loading…
Reference in New Issue