ABOUT: "math-vectors"
HELP: vneg
-{ $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } }
-{ $description "Negates each element of " { $snippet "u" } "." } ;
+{ $values { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
+{ $description "Negates each element of " { $snippet "v" } "." } ;
HELP: vabs
-{ $values { "u" "a sequence of numbers" } { "v" "a sequence of non-negative real numbers" } }
-{ $description "Takes the absolute value of each element of " { $snippet "u" } "." } ;
+{ $values { "v" "a sequence of numbers" } { "w" "a sequence of non-negative real numbers" } }
+{ $description "Takes the absolute value of each element of " { $snippet "v" } "." } ;
HELP: vsqrt
-{ $values { "u" "a sequence of non-negative real numbers" } { "v" "a sequence of non-negative real numbers" } }
-{ $description "Takes the square root of each element of " { $snippet "u" } "." }
+{ $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 "v" } "." }
{ $warning "For performance reasons, this does not work with negative inputs, unlike " { $link sqrt } "." } ;
HELP: vfloor
-{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } }
-{ $description "Takes the " { $link floor } " of each element of " { $snippet "u" } "." } ;
+{ $values { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
+{ $description "Takes the " { $link floor } " of each element of " { $snippet "v" } "." } ;
HELP: vceiling
-{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } }
-{ $description "Takes the " { $link ceiling } " of each element of " { $snippet "u" } "." } ;
+{ $values { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
+{ $description "Takes the " { $link ceiling } " of each element of " { $snippet "v" } "." } ;
HELP: vtruncate
-{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } }
-{ $description "Truncates each element of " { $snippet "u" } "." } ;
+{ $values { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
+{ $description "Truncates each element of " { $snippet "v" } "." } ;
HELP: n+v
{ $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
{ $description "Adds " { $snippet "n" } " to each element of " { $snippet "v" } "." } ;
HELP: v+n
-{ $values { "u" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
-{ $description "Adds " { $snippet "n" } " to each element of " { $snippet "u" } "." } ;
+{ $values { "v" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
+{ $description "Adds " { $snippet "n" } " to each element of " { $snippet "v" } "." } ;
HELP: n-v
{ $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
{ $description "Subtracts each element of " { $snippet "v" } " from " { $snippet "n" } "." } ;
HELP: v-n
-{ $values { "u" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
-{ $description "Subtracts " { $snippet "n" } " from each element of " { $snippet "u" } "." } ;
+{ $values { "v" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
+{ $description "Subtracts " { $snippet "n" } " from each element of " { $snippet "v" } "." } ;
HELP: n*v
{ $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
{ $description "Multiplies each element of " { $snippet "v" } " by " { $snippet "n" } "." } ;
HELP: v*n
-{ $values { "u" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
-{ $description "Multiplies each element of " { $snippet "u" } " by " { $snippet "n" } "." } ;
+{ $values { "v" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
+{ $description "Multiplies each element of " { $snippet "v" } " by " { $snippet "n" } "." } ;
HELP: n/v
{ $values { "n" number } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
{ $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
HELP: v/n
-{ $values { "u" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
-{ $description "Divides each element of " { $snippet "u" } " by " { $snippet "n" } "." }
+{ $values { "v" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
+{ $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" } "." } ;
HELP: n^v
{ $description "Raises " { $snippet "n" } " to the power of each element of " { $snippet "v" } "." } ;
HELP: v^n
-{ $values { "u" "a sequence of numbers" } { "n" number } { "w" "a sequence of numbers" } }
-{ $description "Raises each element of " { $snippet "u" } " to the power of " { $snippet "n" } "." } ;
+{ $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 "v" } "." } ;
HELP: v+
{ $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
{ $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
-{ $values { "u" "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." }
+{ $values { "v" "a sequence of integers" } { "n" "a non-negative integer" } { "w" "a sequence of integers" } }
+{ $description "Shifts each element of " { $snippet "v" } " to the left by " { $snippet "n" } " bits." }
{ $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ;
HELP: vrshift
-{ $values { "u" "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." }
+{ $values { "v" "a sequence of integers" } { "n" "a non-negative integer" } { "w" "a sequence of integers" } }
+{ $description "Shifts each element of " { $snippet "v" } " to the right by " { $snippet "n" } " bits." }
{ $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ;
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." } ;
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." } ;
HELP: vmerge
} ;
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:"
{ $list
{ "A literal array of integers of the same length as the vector. This will perform a static, elementwise shuffle." }
{ $description "Computes the length of a mathematical vector in " { $snippet "L^p" } " space." } ;
HELP: normalize
-{ $values { "u" "a sequence of numbers, not all zero" } { "v" "a sequence of numbers" } }
-{ $description "Outputs a vector with the same direction as " { $snippet "u" } " but length 1." } ;
+{ $values { "v" "a sequence of numbers, not all zero" } { "w" "a sequence of numbers" } }
+{ $description "Outputs a vector with the same direction as " { $snippet "v" } " but length 1." } ;
HELP: distance
{ $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "x" "a non-negative real number" } }
{ $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
HELP: vnot
-{ $values { "u" "a sequence of booleans" } { "w" "a sequence of booleans" } }
-{ $description "Takes the logical NOT of each element of " { $snippet "u" } "." }
+{ $values { "v" "a sequence of booleans" } { "w" "a sequence of booleans" } }
+{ $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." } ;
HELP: v?
QUALIFIED-WITH: alien.c-types c
IN: math.vectors
-GENERIC: vneg ( u -- v )
+GENERIC: vneg ( v -- w )
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
GENERIC: n+v ( n v -- w )
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
GENERIC: n-v ( n v -- w )
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
GENERIC: n*v ( n v -- w )
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
GENERIC: n/v ( n v -- w )
GENERIC: v*high ( u v -- w )
<PRIVATE
-: (h+) ( u -- w ) 2 <groups> [ first2 + ] map ;
+: (h+) ( v -- w ) 2 <groups> [ first2 + ] map ;
PRIVATE>
GENERIC: v*hs+ ( u v -- w )
GENERIC: v^ ( u v -- w )
M: object v^ [ ^ ] 2map ; inline
-GENERIC: v^n ( u n -- w )
+GENERIC: v^n ( v n -- w )
M: object v^n [ ^ ] curry map ; inline
GENERIC: n^v ( n v -- w )
GENERIC: vs* ( u v -- w )
M: object vs* [ * ] 2map ; inline
-GENERIC: vabs ( u -- v )
+GENERIC: vabs ( v -- w )
M: object vabs [ abs ] map ; inline
-GENERIC: vsqrt ( u -- v )
+GENERIC: vsqrt ( v -- w )
M: object vsqrt [ >float fsqrt ] map ; inline
GENERIC: vsad ( u v -- n )
M: object vbitor [ bitor ] 2map ; inline
GENERIC: vbitxor ( u v -- w )
M: object vbitxor [ bitxor ] 2map ; inline
-GENERIC: vbitnot ( u -- w )
+GENERIC: vbitnot ( v -- w )
M: object vbitnot [ bitnot ] map ; inline
GENERIC# vbroadcast 1 ( u n -- v )
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
over length 0 pad-tail
swap [ '[ _ nth ] ] keep map-as ; inline
M: object vshuffle2-elements
[ append ] dip vshuffle-elements ; inline
-GENERIC# vshuffle-bytes 1 ( u perm -- v )
+GENERIC# vshuffle-bytes 1 ( v perm -- w )
-GENERIC: vshuffle ( u perm -- v )
-M: array vshuffle ( u perm -- v )
+GENERIC: vshuffle ( v perm -- w )
+M: array vshuffle ( v perm -- w )
vshuffle-elements ; inline
-GENERIC# vlshift 1 ( u n -- w )
+GENERIC# vlshift 1 ( v n -- w )
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
-GENERIC# hlshift 1 ( u n -- w )
-GENERIC# hrshift 1 ( u n -- w )
+GENERIC# hlshift 1 ( v n -- w )
+GENERIC# hrshift 1 ( v n -- w )
GENERIC: (vmerge-head) ( u v -- h )
M: object (vmerge-head) over length 2 /i '[ _ head-slice ] bi@ [ zip ] keep concat-as ; inline
GENERIC: vxor ( u v -- w )
M: object vxor [ xor ] 2map ; inline
-GENERIC: vnot ( u -- w )
+GENERIC: vnot ( v -- w )
M: object vnot [ not ] map ; inline
GENERIC: vall? ( v -- ? )
[ [ call ] dip call v? ]
} cond ; inline
-: v>integer ( u -- v ) [ >integer ] map ;
-: vfloor ( u -- v ) [ floor ] map ;
-: vceiling ( u -- v ) [ ceiling ] map ;
-: vtruncate ( u -- v ) [ truncate ] map ;
+: v>integer ( v -- w ) [ >integer ] map ;
+: vfloor ( v -- w ) [ floor ] map ;
+: vceiling ( v -- w ) [ ceiling ] map ;
+: vtruncate ( v -- w ) [ truncate ] map ;
: vsupremum ( seq -- vmax ) [ ] [ vmax ] map-reduce ; inline
: vinfimum ( seq -- vmin ) [ ] [ vmin ] map-reduce ; inline
[ p-norm-default ]
} cond ;
-: normalize ( u -- v ) dup norm v/n ; inline
+: normalize ( v -- w ) dup norm v/n ; inline
GENERIC: distance ( u v -- x )
M: object distance [ - absq ] [ + ] 2map-reduce sqrt ; inline