Rename variables in some stack declarations for consistency.

It doesn't look great when a word is called "v/n", but the declared
parameters are "u" and "n". Better to have the parameters "v" and "n".
Also for consistency all input parameters are named "v" for "vector" (or
"u" and "v" in the alphabetical order), and the result vector is always
"w".
db4
Alexander Iljin 2015-09-29 17:48:10 +03:00 committed by John Benediktsson
parent d904fae5b5
commit fc7b70a17e
2 changed files with 57 additions and 57 deletions

View File

@ -190,53 +190,53 @@ ARTICLE: "math-vectors" "Vector operations"
ABOUT: "math-vectors" ABOUT: "math-vectors"
HELP: vneg HELP: vneg
{ $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } } { $values { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
{ $description "Negates each element of " { $snippet "u" } "." } ; { $description "Negates each element of " { $snippet "v" } "." } ;
HELP: vabs HELP: vabs
{ $values { "u" "a sequence of numbers" } { "v" "a sequence of non-negative real numbers" } } { $values { "v" "a sequence of numbers" } { "w" "a sequence of non-negative real numbers" } }
{ $description "Takes the absolute value of each element of " { $snippet "u" } "." } ; { $description "Takes the absolute value of each element of " { $snippet "v" } "." } ;
HELP: vsqrt HELP: vsqrt
{ $values { "u" "a sequence of non-negative real numbers" } { "v" "a sequence of non-negative real numbers" } } { $values { "v" "a sequence of non-negative real numbers" } { "w" "a sequence of non-negative real numbers" } }
{ $description "Takes the square root of each element of " { $snippet "u" } "." } { $description "Takes the square root of each element of " { $snippet "v" } "." }
{ $warning "For performance reasons, this does not work with negative inputs, unlike " { $link sqrt } "." } ; { $warning "For performance reasons, this does not work with negative inputs, unlike " { $link sqrt } "." } ;
HELP: vfloor HELP: vfloor
{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } } { $values { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
{ $description "Takes the " { $link floor } " of each element of " { $snippet "u" } "." } ; { $description "Takes the " { $link floor } " of each element of " { $snippet "v" } "." } ;
HELP: vceiling HELP: vceiling
{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } } { $values { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
{ $description "Takes the " { $link ceiling } " of each element of " { $snippet "u" } "." } ; { $description "Takes the " { $link ceiling } " of each element of " { $snippet "v" } "." } ;
HELP: vtruncate HELP: vtruncate
{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } } { $values { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
{ $description "Truncates each element of " { $snippet "u" } "." } ; { $description "Truncates each element of " { $snippet "v" } "." } ;
HELP: n+v HELP: n+v
{ $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } } { $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
{ $description "Adds " { $snippet "n" } " to each element of " { $snippet "v" } "." } ; { $description "Adds " { $snippet "n" } " to each element of " { $snippet "v" } "." } ;
HELP: v+n HELP: v+n
{ $values { "u" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } } { $values { "v" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
{ $description "Adds " { $snippet "n" } " to each element of " { $snippet "u" } "." } ; { $description "Adds " { $snippet "n" } " to each element of " { $snippet "v" } "." } ;
HELP: n-v HELP: n-v
{ $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } } { $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
{ $description "Subtracts each element of " { $snippet "v" } " from " { $snippet "n" } "." } ; { $description "Subtracts each element of " { $snippet "v" } " from " { $snippet "n" } "." } ;
HELP: v-n HELP: v-n
{ $values { "u" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } } { $values { "v" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
{ $description "Subtracts " { $snippet "n" } " from each element of " { $snippet "u" } "." } ; { $description "Subtracts " { $snippet "n" } " from each element of " { $snippet "v" } "." } ;
HELP: n*v HELP: n*v
{ $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } } { $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
{ $description "Multiplies each element of " { $snippet "v" } " by " { $snippet "n" } "." } ; { $description "Multiplies each element of " { $snippet "v" } " by " { $snippet "n" } "." } ;
HELP: v*n HELP: v*n
{ $values { "u" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } } { $values { "v" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
{ $description "Multiplies each element of " { $snippet "u" } " by " { $snippet "n" } "." } ; { $description "Multiplies each element of " { $snippet "v" } " by " { $snippet "n" } "." } ;
HELP: n/v HELP: n/v
{ $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } } { $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
@ -244,8 +244,8 @@ HELP: n/v
{ $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ; { $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
HELP: v/n HELP: v/n
{ $values { "u" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } } { $values { "v" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
{ $description "Divides each element of " { $snippet "u" } " by " { $snippet "n" } "." } { $description "Divides each element of " { $snippet "v" } " by " { $snippet "n" } "." }
{ $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ; { $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
HELP: n^v HELP: n^v
@ -253,8 +253,8 @@ HELP: n^v
{ $description "Raises " { $snippet "n" } " to the power of each element of " { $snippet "v" } "." } ; { $description "Raises " { $snippet "n" } " to the power of each element of " { $snippet "v" } "." } ;
HELP: v^n HELP: v^n
{ $values { "u" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } } { $values { "v" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
{ $description "Raises each element of " { $snippet "u" } " to the power of " { $snippet "n" } "." } ; { $description "Raises each element of " { $snippet "u" } " to the power of " { $snippet "v" } "." } ;
HELP: v+ HELP: v+
{ $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } } { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
@ -359,21 +359,21 @@ HELP: vbitxor
{ $notes "Unlike " { $link bitxor } ", this word may be used on a specialized array of floats or doubles, in which case the bitwise representation of the floating point numbers is operated upon." } ; { $notes "Unlike " { $link bitxor } ", this word may be used on a specialized array of floats or doubles, in which case the bitwise representation of the floating point numbers is operated upon." } ;
HELP: vlshift HELP: vlshift
{ $values { "u" "a sequence of integers" } { "n" "a non-negative integer" } { "w" "a sequence of integers" } } { $values { "v" "a sequence of integers" } { "n" "a non-negative integer" } { "w" "a sequence of integers" } }
{ $description "Shifts each element of " { $snippet "u" } " to the left by " { $snippet "n" } " bits." } { $description "Shifts each element of " { $snippet "v" } " to the left by " { $snippet "n" } " bits." }
{ $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ; { $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ;
HELP: vrshift HELP: vrshift
{ $values { "u" "a sequence of integers" } { "n" "a non-negative integer" } { "w" "a sequence of integers" } } { $values { "v" "a sequence of integers" } { "n" "a non-negative integer" } { "w" "a sequence of integers" } }
{ $description "Shifts each element of " { $snippet "u" } " to the right by " { $snippet "n" } " bits." } { $description "Shifts each element of " { $snippet "v" } " to the right by " { $snippet "n" } " bits." }
{ $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ; { $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ;
HELP: hlshift HELP: hlshift
{ $values { "u" "a SIMD array" } { "n" "a non-negative integer" } { "w" "a SIMD array" } } { $values { "v" "a SIMD array" } { "n" "a non-negative integer" } { "w" "a SIMD array" } }
{ $description "Shifts the entire SIMD array to the left by " { $snippet "n" } " bytes, filling the vacated right-hand bits with zeroes. This word may only be used in a context where the compiler can statically infer that the input is a SIMD array." } ; { $description "Shifts the entire SIMD array to the left by " { $snippet "n" } " bytes, filling the vacated right-hand bits with zeroes. This word may only be used in a context where the compiler can statically infer that the input is a SIMD array." } ;
HELP: hrshift HELP: hrshift
{ $values { "u" "a SIMD array" } { "n" "a non-negative integer" } { "w" "a SIMD array" } } { $values { "v" "a SIMD array" } { "n" "a non-negative integer" } { "w" "a SIMD array" } }
{ $description "Shifts the entire SIMD array to the right by " { $snippet "n" } " bytes, filling the vacated left-hand bits with zeroes. This word may only be used in a context where the compiler can statically infer that the input is a SIMD array." } ; { $description "Shifts the entire SIMD array to the right by " { $snippet "n" } " bytes, filling the vacated left-hand bits with zeroes. This word may only be used in a context where the compiler can statically infer that the input is a SIMD array." } ;
HELP: vmerge HELP: vmerge
@ -434,7 +434,7 @@ HELP: vbroadcast
} ; } ;
HELP: vshuffle HELP: vshuffle
{ $values { "u" "a SIMD array" } { "perm" "an array of integers, or a byte-array" } { "v" "a SIMD array" } } { $values { "v" "a SIMD array" } { "perm" "an array of integers, or a byte-array" } { "w" "a SIMD array" } }
{ $description "Permutes the elements of a SIMD array. Duplicate entries are allowed in the permutation. The " { $snippet "perm" } " argument can have one of two forms:" { $description "Permutes the elements of a SIMD array. Duplicate entries are allowed in the permutation. The " { $snippet "perm" } " argument can have one of two forms:"
{ $list { $list
{ "A literal array of integers of the same length as the vector. This will perform a static, elementwise shuffle." } { "A literal array of integers of the same length as the vector. This will perform a static, elementwise shuffle." }
@ -478,8 +478,8 @@ HELP: p-norm
{ $description "Computes the length of a mathematical vector in " { $snippet "L^p" } " space." } ; { $description "Computes the length of a mathematical vector in " { $snippet "L^p" } " space." } ;
HELP: normalize HELP: normalize
{ $values { "u" "a sequence of numbers, not all zero" } { "v" "a sequence of numbers" } } { $values { "v" "a sequence of numbers, not all zero" } { "w" "a sequence of numbers" } }
{ $description "Outputs a vector with the same direction as " { $snippet "u" } " but length 1." } ; { $description "Outputs a vector with the same direction as " { $snippet "v" } " but length 1." } ;
HELP: distance HELP: distance
{ $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "x" "a non-negative real number" } } { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "x" "a non-negative real number" } }
@ -541,8 +541,8 @@ HELP: vxor
{ $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ; { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
HELP: vnot HELP: vnot
{ $values { "u" "a sequence of booleans" } { "w" "a sequence of booleans" } } { $values { "v" "a sequence of booleans" } { "w" "a sequence of booleans" } }
{ $description "Takes the logical NOT of each element of " { $snippet "u" } "." } { $description "Takes the logical NOT of each element of " { $snippet "v" } "." }
{ $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ; { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
HELP: v? HELP: v?

View File

@ -6,28 +6,28 @@ fry combinators byte-arrays accessors locals ;
QUALIFIED-WITH: alien.c-types c QUALIFIED-WITH: alien.c-types c
IN: math.vectors IN: math.vectors
GENERIC: vneg ( u -- v ) GENERIC: vneg ( v -- w )
M: object vneg [ neg ] map ; inline M: object vneg [ neg ] map ; inline
GENERIC# v+n 1 ( u n -- w ) GENERIC# v+n 1 ( v n -- w )
M: object v+n [ + ] curry map ; inline M: object v+n [ + ] curry map ; inline
GENERIC: n+v ( n v -- w ) GENERIC: n+v ( n v -- w )
M: object n+v [ + ] with map ; inline M: object n+v [ + ] with map ; inline
GENERIC# v-n 1 ( u n -- w ) GENERIC# v-n 1 ( v n -- w )
M: object v-n [ - ] curry map ; inline M: object v-n [ - ] curry map ; inline
GENERIC: n-v ( n v -- w ) GENERIC: n-v ( n v -- w )
M: object n-v [ - ] with map ; inline M: object n-v [ - ] with map ; inline
GENERIC# v*n 1 ( u n -- w ) GENERIC# v*n 1 ( v n -- w )
M: object v*n [ * ] curry map ; inline M: object v*n [ * ] curry map ; inline
GENERIC: n*v ( n v -- w ) GENERIC: n*v ( n v -- w )
M: object n*v [ * ] with map ; inline M: object n*v [ * ] with map ; inline
GENERIC# v/n 1 ( u n -- w ) GENERIC# v/n 1 ( v n -- w )
M: object v/n [ / ] curry map ; inline M: object v/n [ / ] curry map ; inline
GENERIC: n/v ( n v -- w ) GENERIC: n/v ( n v -- w )
@ -48,7 +48,7 @@ M: object v* [ * ] 2map ; inline
GENERIC: v*high ( u v -- w ) GENERIC: v*high ( u v -- w )
<PRIVATE <PRIVATE
: (h+) ( u -- w ) 2 <groups> [ first2 + ] map ; : (h+) ( v -- w ) 2 <groups> [ first2 + ] map ;
PRIVATE> PRIVATE>
GENERIC: v*hs+ ( u v -- w ) GENERIC: v*hs+ ( u v -- w )
@ -60,7 +60,7 @@ M: object v/ [ / ] 2map ; inline
GENERIC: v^ ( u v -- w ) GENERIC: v^ ( u v -- w )
M: object v^ [ ^ ] 2map ; inline M: object v^ [ ^ ] 2map ; inline
GENERIC: v^n ( u n -- w ) GENERIC: v^n ( v n -- w )
M: object v^n [ ^ ] curry map ; inline M: object v^n [ ^ ] curry map ; inline
GENERIC: n^v ( n v -- w ) GENERIC: n^v ( n v -- w )
@ -90,10 +90,10 @@ M: object vs- [ - ] 2map ; inline
GENERIC: vs* ( u v -- w ) GENERIC: vs* ( u v -- w )
M: object vs* [ * ] 2map ; inline M: object vs* [ * ] 2map ; inline
GENERIC: vabs ( u -- v ) GENERIC: vabs ( v -- w )
M: object vabs [ abs ] map ; inline M: object vabs [ abs ] map ; inline
GENERIC: vsqrt ( u -- v ) GENERIC: vsqrt ( v -- w )
M: object vsqrt [ >float fsqrt ] map ; inline M: object vsqrt [ >float fsqrt ] map ; inline
GENERIC: vsad ( u v -- n ) GENERIC: vsad ( u v -- n )
@ -113,13 +113,13 @@ GENERIC: vbitor ( u v -- w )
M: object vbitor [ bitor ] 2map ; inline M: object vbitor [ bitor ] 2map ; inline
GENERIC: vbitxor ( u v -- w ) GENERIC: vbitxor ( u v -- w )
M: object vbitxor [ bitxor ] 2map ; inline M: object vbitxor [ bitxor ] 2map ; inline
GENERIC: vbitnot ( u -- w ) GENERIC: vbitnot ( v -- w )
M: object vbitnot [ bitnot ] map ; inline M: object vbitnot [ bitnot ] map ; inline
GENERIC# vbroadcast 1 ( u n -- v ) GENERIC# vbroadcast 1 ( u n -- v )
M:: object vbroadcast ( u n -- v ) u length n u nth <repetition> u like ; inline M:: object vbroadcast ( u n -- v ) u length n u nth <repetition> u like ; inline
GENERIC# vshuffle-elements 1 ( u perm -- v ) GENERIC# vshuffle-elements 1 ( v perm -- w )
M: object vshuffle-elements M: object vshuffle-elements
over length 0 pad-tail over length 0 pad-tail
swap [ '[ _ nth ] ] keep map-as ; inline swap [ '[ _ nth ] ] keep map-as ; inline
@ -128,19 +128,19 @@ GENERIC# vshuffle2-elements 1 ( u v perm -- w )
M: object vshuffle2-elements M: object vshuffle2-elements
[ append ] dip vshuffle-elements ; inline [ append ] dip vshuffle-elements ; inline
GENERIC# vshuffle-bytes 1 ( u perm -- v ) GENERIC# vshuffle-bytes 1 ( v perm -- w )
GENERIC: vshuffle ( u perm -- v ) GENERIC: vshuffle ( v perm -- w )
M: array vshuffle ( u perm -- v ) M: array vshuffle ( v perm -- w )
vshuffle-elements ; inline vshuffle-elements ; inline
GENERIC# vlshift 1 ( u n -- w ) GENERIC# vlshift 1 ( v n -- w )
M: object vlshift '[ _ shift ] map ; inline M: object vlshift '[ _ shift ] map ; inline
GENERIC# vrshift 1 ( u n -- w ) GENERIC# vrshift 1 ( v n -- w )
M: object vrshift neg '[ _ shift ] map ; inline M: object vrshift neg '[ _ shift ] map ; inline
GENERIC# hlshift 1 ( u n -- w ) GENERIC# hlshift 1 ( v n -- w )
GENERIC# hrshift 1 ( u n -- w ) GENERIC# hrshift 1 ( v n -- w )
GENERIC: (vmerge-head) ( u v -- h ) GENERIC: (vmerge-head) ( u v -- h )
M: object (vmerge-head) over length 2 /i '[ _ head-slice ] bi@ [ zip ] keep concat-as ; inline M: object (vmerge-head) over length 2 /i '[ _ head-slice ] bi@ [ zip ] keep concat-as ; inline
@ -165,7 +165,7 @@ M: object vor [ or ] 2map ; inline
GENERIC: vxor ( u v -- w ) GENERIC: vxor ( u v -- w )
M: object vxor [ xor ] 2map ; inline M: object vxor [ xor ] 2map ; inline
GENERIC: vnot ( u -- w ) GENERIC: vnot ( v -- w )
M: object vnot [ not ] map ; inline M: object vnot [ not ] map ; inline
GENERIC: vall? ( v -- ? ) GENERIC: vall? ( v -- ? )
@ -209,10 +209,10 @@ M: object v?
[ [ call ] dip call v? ] [ [ call ] dip call v? ]
} cond ; inline } cond ; inline
: v>integer ( u -- v ) [ >integer ] map ; : v>integer ( v -- w ) [ >integer ] map ;
: vfloor ( u -- v ) [ floor ] map ; : vfloor ( v -- w ) [ floor ] map ;
: vceiling ( u -- v ) [ ceiling ] map ; : vceiling ( v -- w ) [ ceiling ] map ;
: vtruncate ( u -- v ) [ truncate ] map ; : vtruncate ( v -- w ) [ truncate ] map ;
: vsupremum ( seq -- vmax ) [ ] [ vmax ] map-reduce ; inline : vsupremum ( seq -- vmax ) [ ] [ vmax ] map-reduce ; inline
: vinfimum ( seq -- vmin ) [ ] [ vmin ] map-reduce ; inline : vinfimum ( seq -- vmin ) [ ] [ vmin ] map-reduce ; inline
@ -241,7 +241,7 @@ M: object norm-sq [ absq ] [ + ] map-reduce ; inline
[ p-norm-default ] [ p-norm-default ]
} cond ; } cond ;
: normalize ( u -- v ) dup norm v/n ; inline : normalize ( v -- w ) dup norm v/n ; inline
GENERIC: distance ( u v -- x ) GENERIC: distance ( u v -- x )
M: object distance [ - absq ] [ + ] 2map-reduce sqrt ; inline M: object distance [ - absq ] [ + ] 2map-reduce sqrt ; inline