]> gitweb.factorcode.org Git - factor.git/blob - basis/math/vectors/vectors-docs.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / math / vectors / vectors-docs.factor
1 USING: help.markup help.syntax math math.functions sequences ;
2 IN: math.vectors
3
4 ARTICLE: "math-vectors-arithmetic" "Vector arithmetic"
5 "Vector/vector binary operations:"
6 { $subsections
7     v+
8     v-
9     v+-
10     v*
11     v/
12 }
13 "Vector unary operations:"
14 { $subsections
15     vneg
16     vabs
17     vsqrt
18     vfloor
19     vceiling
20     vtruncate
21 }
22 "Vector/scalar and scalar/vector binary operations:"
23 { $subsections
24     vneg
25     v*n
26     n*v
27     v/n
28     n/v
29     v+n
30     n+v
31     v-n
32     n-v
33 }
34 "Saturated arithmetic (only on " { $link "specialized-arrays" } "):"
35 { $subsections
36     vs+
37     vs-
38     vs*
39 }
40 "Inner product and norm:"
41 { $subsections
42     v.
43     norm
44     norm-sq
45     normalize
46 }
47 "Comparing entire vectors:"
48 { $subsections
49     distance
50     v~
51 } ;
52
53 ARTICLE: "math-vectors-shuffle" "Vector shuffling, packing, and unpacking"
54 { $notes
55 "These operations are primarily meant to be used with " { $vocab-link "math.vectors.simd" } " types. The software fallbacks for types not supported by hardware will not perform well."
56 }
57 $nl
58 { $subsections
59     vshuffle
60     vbroadcast
61     hlshift
62     hrshift
63     vmerge
64     (vmerge)
65 }
66 "See the " { $vocab-link "math.vectors.conversion" } " vocabulary for packing, unpacking, and converting vectors." ;
67
68 ARTICLE: "math-vectors-logic" "Vector component- and bit-wise logic"
69 { $notes
70 "See " { $link "math-vectors-simd-logic" } " for notes about using comparison and logical operations with SIMD vector types."
71 }
72 $nl
73 "Element comparisons:"
74 { $subsections
75     v<
76     v<=
77     v=
78     v>=
79     v>
80     vunordered?
81     vmax
82     vmin
83     vsupremum
84     vinfimum
85 }
86 "Bitwise operations:"
87 { $subsections
88     vbitand
89     vbitandn
90     vbitor
91     vbitxor
92     vbitnot
93     vlshift
94     vrshift
95 }
96 "Element logical operations:"
97 { $subsections
98     vand
99     vandn
100     vor
101     vxor
102     vnot
103     v?
104 }
105 "Entire vector tests:"
106 { $subsections
107     vall?
108     vany?
109     vnone?
110 }
111 "Element shuffling:"
112 { $subsections vshuffle } ;
113
114 ARTICLE: "math-vectors-misc" "Miscellaneous vector functions"
115 { $subsections
116     trilerp
117     bilerp
118     vlerp
119     vnlerp
120     vbilerp
121 } ;
122
123 ARTICLE: "math-vectors-simd-logic" "Componentwise logic with SIMD vectors"
124 "Processor SIMD units supported by the " { $vocab-link "math.vectors.simd" } " vocabulary represent boolean values as bitmasks, where a true result's binary representation is all ones and a false representation is all zeroes. This is the format in which results from comparison words such as " { $link v= } " return their results and in which logic and test words such as " { $link vand } " and " { $link vall? } " take their inputs when working with SIMD types. For a float vector, false will manifest itself as " { $snippet "0.0" } " and true as a " { $link POSTPONE: NAN: } " literal with a string of set bits in its payload:"
125 { $example
126 """USING: math.vectors math.vectors.simd prettyprint ;
127 FROM: alien.c-types => float ;
128 SIMD: float
129
130 float-4{ 1.0 2.0 3.0 0/0. } float-4{ 1.0 -2.0 3.0 0/0. } v= ."""
131 """float-4{ NAN: fffffe0000000 0.0 NAN: fffffe0000000 0.0 }"""
132 }
133 "For an integer vector, false will manifest as " { $snippet "0" } " and true as " { $snippet "-1" } " (for signed vectors) or the largest representable value of the element type (for unsigned vectors):"
134 { $example
135 """USING: math.vectors math.vectors.simd prettyprint alien.c-types ;
136 SIMD: int
137 SIMD: uchar
138
139 int-4{ 1 2 3 0 } int-4{ 1 -2 3 4 } v=
140 uchar-16{  0  1  2  3  4  5 6 7 8 9 10 11 12 13 14 15 }
141 uchar-16{ 15 14 13 12 11 10 9 8 7 6  5  4  3  2  1  0 } v<
142 [ . ] bi@"""
143 """int-4{ -1 0 -1 0 }
144 uchar-16{ 255 255 255 255 255 255 255 255 0 0 0 0 0 0 0 0 }"""
145 }
146 "This differs from Factor's native representation of boolean values, where " { $link f } " is false and every other value (including " { $snippet "0" } " and " { $snippet "0.0" } ") is true. To make it easy to construct literal SIMD masks, " { $link t } " and " { $link f } " are accepted inside SIMD literal syntax and expand to the proper true or false representation for the underlying type:"
147 { $example
148 """USING: math.vectors math.vectors.simd prettyprint alien.c-types ;
149 SIMD: int
150
151 int-4{ f f t f } ."""
152 """int-4{ 0 0 -1 0 }""" }
153 "However, extracting an element from a boolean SIMD vector with " { $link nth } " will not yield a valid Factor boolean. This is not generally a problem, since the results of vector comparisons are meant to be consumed by subsequent vector logical and test operations, which will accept SIMD values in the native boolean format."
154 $nl
155 "Providing a SIMD boolean vector with element values other than the proper true and false representations as an input to the vector logical or test operations is undefined. Do not count on operations such as " { $link vall? } " or " { $link v? } " using bitwise operations to construct their results."
156 $nl
157 "This applies to the output of the following element comparison words: "
158 { $list
159 { $link v< }
160 { $link v<= }
161 { $link v= }
162 { $link v>= }
163 { $link v> }
164 { $link vunordered? }
165 }
166 "This likewise applies to the " { $snippet "mask" } " argument of " { $link v? } " and to the inputs and outputs of the following element logic words:"
167 { $list
168 { $link vand }
169 { $link vandn }
170 { $link vor }
171 { $link vxor }
172 { $link vnot }
173 }
174 "Finally, this applies to the inputs of these vector test words:"
175 { $list
176 { $link vall? }
177 { $link vany? }
178 { $link vnone? }
179 } ;
180
181 ARTICLE: "math-vectors" "Vector operations"
182 "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."
183 { $subsections
184     "math-vectors-arithmetic"
185     "math-vectors-logic"
186     "math-vectors-shuffle"
187     "math-vectors-misc"
188 } ;
189
190 ABOUT: "math-vectors"
191
192 HELP: vneg
193 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } }
194 { $description "Negates each element of " { $snippet "u" } "." } ;
195
196 HELP: vabs
197 { $values { "u" "a sequence of numbers" } { "v" "a sequence of non-negative real numbers" } }
198 { $description "Takes the absolute value of each element of " { $snippet "u" } "." } ;
199
200 HELP: vsqrt
201 { $values { "u" "a sequence of non-negative real numbers" } { "v" "a sequence of non-negative real numbers" } }
202 { $description "Takes the square root of each element of " { $snippet "u" } "." }
203 { $warning "For performance reasons, this does not work with negative inputs, unlike " { $link sqrt } "." } ;
204
205 HELP: vfloor
206 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } }
207 { $description "Takes the " { $link floor } " of each element of " { $snippet "u" } "." } ;
208
209 HELP: vceiling
210 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } }
211 { $description "Takes the " { $link ceiling } " of each element of " { $snippet "u" } "." } ;
212
213 HELP: vtruncate
214 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } }
215 { $description "Truncates each element of " { $snippet "u" } "." } ;
216
217 HELP: n+v
218 { $values { "n" "a number" } { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } }
219 { $description "Adds " { $snippet "n" } " to each element of " { $snippet "u" } "." } ;
220
221 HELP: v+n
222 { $values { "u" "a sequence of numbers" } { "n" "a number" } { "v" "a sequence of numbers" } }
223 { $description "Adds " { $snippet "n" } " to each element of " { $snippet "u" } "." } ;
224
225 HELP: n-v
226 { $values { "n" "a number" } { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } }
227 { $description "Subtracts each element of " { $snippet "u" } " from " { $snippet "n" } "." } ;
228
229 HELP: v-n
230 { $values { "u" "a sequence of numbers" } { "n" "a number" } { "v" "a sequence of numbers" } }
231 { $description "Subtracts " { $snippet "n" } " from each element of " { $snippet "u" } "." } ;
232
233 HELP: n*v
234 { $values { "n" "a number" } { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } }
235 { $description "Multiplies each element of " { $snippet "u" } " by " { $snippet "n" } "." } ;
236
237 HELP: v*n
238 { $values { "u" "a sequence of numbers" } { "n" "a number" } { "v" "a sequence of numbers" } }
239 { $description "Multiplies each element of " { $snippet "u" } " by " { $snippet "n" } "." } ;
240
241 HELP: n/v
242 { $values { "n" "a number" } { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } }
243 { $description "Divides " { $snippet "n" } " by each element of " { $snippet "u" } "." }
244 { $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
245
246 HELP: v/n
247 { $values { "u" "a sequence of numbers" } { "n" "a number" } { "v" "a sequence of numbers" } }
248 { $description "Divides each element of " { $snippet "u" } " by " { $snippet "n" } "." }
249 { $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
250
251 HELP: v+
252 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
253 { $description "Adds " { $snippet "u" } " and " { $snippet "v" } " component-wise." } ;
254
255 HELP: v-
256 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
257 { $description "Subtracts " { $snippet "v" } " from " { $snippet "u" } " component-wise." } ;
258
259 HELP: v+-
260 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
261 { $description "Adds and subtracts alternate elements of " { $snippet "v" } " and " { $snippet "u" } " component-wise." }
262 { $examples
263     { $example
264         "USING: math.vectors prettyprint ;"
265         "{ 1 2 3 } { 2 3 2 } v+- ."
266         "{ -1 5 1 }"
267     }
268 } ;
269
270 HELP: [v-]
271 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
272 { $description "Subtracts " { $snippet "v" } " from " { $snippet "u" } " component-wise; any components which become negative are set to zero." } ;
273
274 HELP: v*
275 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
276 { $description "Multiplies " { $snippet "u" } " and " { $snippet "v" } " component-wise." } ;
277
278 HELP: v/
279 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
280 { $description "Divides " { $snippet "u" } " by " { $snippet "v" } " component-wise." }
281 { $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
282
283 HELP: vmax
284 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
285 { $description "Creates a sequence where each element is the maximum of the corresponding elements from " { $snippet "u" } " and " { $snippet "v" } "." }
286 { $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 5 } { -7 6 3 } vmax ." "{ 1 6 5 }" } } ;
287
288 HELP: vmin
289 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
290 { $description "Creates a sequence where each element is the minimum of the corresponding elements from " { $snippet "u" } " and " { $snippet "v" } "." }
291 { $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 5 } { -7 6 3 } vmin ." "{ -7 2 3 }" } } ;
292
293 HELP: v.
294 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "x" "a real number" } }
295 { $description "Computes the dot product of two vectors." } ;
296
297 HELP: vs+
298 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
299 { $description "Adds " { $snippet "u" } " and " { $snippet "v" } " component-wise with saturation." }
300 { $examples
301     "With saturation:"
302     { $example
303         "USING: alien.c-types math.vectors prettyprint specialized-arrays ;"
304         "SPECIALIZED-ARRAY: uchar"
305         "uchar-array{ 100 200 150 } uchar-array{ 70 70 70 } vs+ ."
306         "uchar-array{ 170 255 220 }"
307     }
308     "Without saturation:"
309     { $example
310         "USING: alien.c-types math.vectors prettyprint specialized-arrays ;"
311         "SPECIALIZED-ARRAY: uchar"
312         "uchar-array{ 100 200 150 } uchar-array{ 70 70 70 } v+ ."
313         "uchar-array{ 170 14 220 }"
314     }
315 } ;
316
317 HELP: vs-
318 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
319 { $description "Subtracts " { $snippet "v" } " from " { $snippet "u" } " component-wise with saturation." } ;
320
321 HELP: vs*
322 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
323 { $description "Multiplies " { $snippet "u" } " and " { $snippet "v" } " component-wise with saturation." } ;
324
325 HELP: vbitand
326 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
327 { $description "Takes the bitwise and of " { $snippet "u" } " and " { $snippet "v" } " component-wise." }
328 { $notes "Unlike " { $link bitand } ", 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." } ;
329
330 HELP: vbitandn
331 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
332 { $description "Takes the bitwise and-not of " { $snippet "u" } " and " { $snippet "v" } " component-wise, where " { $snippet "x and-not y" } " is defined as " { $snippet "not(x) and y" } "." }
333 { $notes "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." } ;
334
335 HELP: vbitor
336 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
337 { $description "Takes the bitwise or of " { $snippet "u" } " and " { $snippet "v" } " component-wise." }
338 { $notes "Unlike " { $link bitor } ", 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." } ;
339
340 HELP: vbitxor
341 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
342 { $description "Takes the bitwise exclusive or of " { $snippet "u" } " and " { $snippet "v" } " component-wise." }
343 { $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." } ;
344
345 HELP: vlshift
346 { $values { "u" "a sequence of integers" } { "n" "a non-negative integer" } { "w" "a sequence of integers" } }
347 { $description "Shifts each element of " { $snippet "u" } " to the left by " { $snippet "n" } " bits." }
348 { $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ;
349
350 HELP: vrshift
351 { $values { "u" "a sequence of integers" } { "n" "a non-negative integer" } { "w" "a sequence of integers" } }
352 { $description "Shifts each element of " { $snippet "u" } " to the right by " { $snippet "n" } " bits." }
353 { $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ;
354
355 HELP: hlshift
356 { $values { "u" "a SIMD array" } { "n" "a non-negative integer" } { "w" "a SIMD array" } }
357 { $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." } ;
358
359 HELP: hrshift
360 { $values { "u" "a SIMD array" } { "n" "a non-negative integer" } { "w" "a SIMD array" } }
361 { $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." } ;
362
363 HELP: vmerge
364 { $values { "u" "a sequence" } { "v" "a sequence" } { "w" "a sequence" } }
365 { $description "Creates a new sequence of the same type as and twice the length of " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements of " { $snippet "u" } " and " { $snippet "v" } "." }
366 { $examples
367 { $example """USING: kernel math.vectors prettyprint ;
368
369 { "A" "B" "C" "D" } { "1" "2" "3" "4" } vmerge ."""
370 """{ "A" "1" "B" "2" "C" "3" "D" "4" }"""
371 } } ;
372
373 HELP: (vmerge)
374 { $values { "u" "a sequence" } { "v" "a sequence" } { "h" "a sequence" } { "t" "a sequence" } }
375 { $description "Creates two new sequences of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements of " { $snippet "u" } " and " { $snippet "v" } "." }
376 { $notes "For hardware-supported SIMD vector types this word compiles to a single instruction per output value." }
377 { $examples
378 { $example """USING: kernel math.vectors prettyprint ;
379
380 { "A" "B" "C" "D" } { "1" "2" "3" "4" } (vmerge) [ . ] bi@"""
381 """{ "A" "1" "B" "2" }
382 { "C" "3" "D" "4" }"""
383 } } ;
384
385 HELP: (vmerge-head)
386 { $values { "u" "a sequence" } { "v" "a sequence" } { "h" "a sequence" } }
387 { $description "Creates a new sequence of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements from the first half of " { $snippet "u" } " and " { $snippet "v" } "." }
388 { $notes "For hardware-supported SIMD vector types this word compiles to a single instruction." }
389 { $examples
390 { $example """USING: kernel math.vectors prettyprint ;
391
392 { "A" "B" "C" "D" } { "1" "2" "3" "4" } (vmerge-head) ."""
393 """{ "A" "1" "B" "2" }"""
394 } } ;
395
396 HELP: (vmerge-tail)
397 { $values { "u" "a sequence" } { "v" "a sequence" } { "t" "a sequence" } }
398 { $description "Creates a new sequence of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements from the tail half of " { $snippet "u" } " and " { $snippet "v" } "." }
399 { $notes "For hardware-supported SIMD vector types this word compiles to a single instruction." }
400 { $examples
401 { $example """USING: kernel math.vectors prettyprint ;
402
403 { "A" "B" "C" "D" } { "1" "2" "3" "4" } (vmerge-tail) ."""
404 """{ "C" "3" "D" "4" }"""
405 } } ;
406
407 { vmerge (vmerge) (vmerge-head) (vmerge-tail) } related-words
408
409 HELP: vbroadcast
410 { $values { "u" "a SIMD array" } { "n" "a non-negative integer" } { "v" "a SIMD array" } }
411 { $description "Outputs a new SIMD array of the same type as " { $snippet "u" } " where every element is equal to the " { $snippet "n" } "th element of " { $snippet "u" } "." }
412 { $examples
413     { $example
414         "USING: alien.c-types math.vectors math.vectors.simd" "prettyprint ;"
415         "SIMD: int"
416         "int-4{ 69 42 911 13 } 2 vbroadcast ."
417         "int-4{ 911 911 911 911 }"
418     }
419 } ;
420
421 HELP: vshuffle
422 { $values { "u" "a SIMD array" } { "perm" "an array of integers, or a byte-array" } { "v" "a SIMD array" } }
423 { $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:"
424 { $list
425 { "A literal array of integers of the same length as the vector. This will perform a static, elementwise shuffle." }
426 { "A byte array or SIMD vector of the same byte length as the vector. This will perform a variable bytewise shuffle." }
427 } }
428 { $examples
429     { $example
430         "USING: alien.c-types math.vectors math.vectors.simd" "prettyprint ;"
431         "SIMD: int"
432         "int-4{ 69 42 911 13 } { 1 3 2 3 } vshuffle ."
433         "int-4{ 42 13 911 13 }"
434     }
435     { $example
436         "USING: alien.c-types combinators math.vectors math.vectors.simd"
437         "namespaces prettyprint prettyprint.config ;"
438         "SIMDS: int uchar ;"
439         "IN: scratchpad"
440         ""
441         ": endian-swap ( size -- vector )"
442         "    {"
443         "        { 1 [ uchar-16{ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 } ] }"
444         "        { 2 [ uchar-16{ 1 0 3 2 5 4 7 6 9 8 11 10 13 12 15 14 } ] }"
445         "        { 4 [ uchar-16{ 3 2 1 0 7 6 5 4 11 10 9 8 15 14 13 12 } ] }"
446         "    } case ;"
447         ""
448         "int-4{ HEX: 11223344 HEX: 11223344 HEX: 11223344 HEX: 11223344 }"
449         "4 endian-swap vshuffle"
450         "16 number-base [ . ] with-variable"
451         """int-4{
452     HEX: 44332211
453     HEX: 44332211
454     HEX: 44332211
455     HEX: 44332211
456 }"""
457     }
458 } ;
459
460 HELP: norm-sq
461 { $values { "v" "a sequence of numbers" } { "x" "a non-negative real number" } }
462 { $description "Computes the squared length of a mathematical vector." } ;
463
464 HELP: norm
465 { $values { "v" "a sequence of numbers" } { "x" "a non-negative real number" } }
466 { $description "Computes the length of a mathematical vector." } ;
467
468 HELP: normalize
469 { $values { "u" "a sequence of numbers, not all zero" } { "v" "a sequence of numbers" } }
470 { $description "Outputs a vector with the same direction as " { $snippet "u" } " but length 1." } ;
471
472 HELP: distance
473 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "x" "a non-negative real number" } }
474 { $description "Outputs the Euclidean distance between two vectors." } ;
475
476 HELP: set-axis
477 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "axis" "a sequence of 0/1" } { "w" "a sequence of numbers" } }
478 { $description "Using " { $snippet "w" } " as a template, creates a new sequence containing corresponding elements from " { $snippet "u" } " in place of 0, and corresponding elements from " { $snippet "v" } " in place of 1." }
479 { $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 3 } { 4 5 6 } { 0 1 0 } set-axis ." "{ 1 5 3 }" } } ;
480
481 HELP: v<
482 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of booleans" } }
483 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when the former is less than the latter or " { $link f } " otherwise." }
484 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
485
486 HELP: v<=
487 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of booleans" } }
488 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when the former is less than or equal to the latter or " { $link f } " otherwise." }
489 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
490
491 HELP: v=
492 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of booleans" } }
493 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when they are equal or " { $link f } " otherwise." }
494 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
495
496 HELP: v>
497 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of booleans" } }
498 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when the former is greater than the latter or " { $link f } " otherwise." }
499 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
500
501 HELP: v>=
502 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of booleans" } }
503 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when the former is greater than or equal to the latter or " { $link f } " otherwise." }
504 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
505
506 HELP: vunordered?
507 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of booleans" } }
508 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when either value is Not-a-Number or " { $link f } " otherwise." }
509 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
510
511 HELP: vand
512 { $values { "u" "a sequence of booleans" } { "v" "a sequence of booleans" } { "w" "a sequence of booleans" } }
513 { $description "Takes the logical AND of each corresponding element of " { $snippet "u" } " and " { $snippet "v" } "." }
514 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
515
516 HELP: vandn
517 { $values { "u" "a sequence of booleans" } { "v" "a sequence of booleans" } { "w" "a sequence of booleans" } }
518 { $description "Takes the logical AND-NOT of each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", where " { $snippet "x AND-NOT y" } " is defined as " { $snippet "NOT(x) AND y" } "." }
519 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
520
521 HELP: vor
522 { $values { "u" "a sequence of booleans" } { "v" "a sequence of booleans" } { "w" "a sequence of booleans" } }
523 { $description "Takes the logical OR of each corresponding element of " { $snippet "u" } " and " { $snippet "v" } "." }
524 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
525
526 HELP: vxor
527 { $values { "u" "a sequence of booleans" } { "v" "a sequence of booleans" } { "w" "a sequence of booleans" } }
528 { $description "Takes the logical XOR of each corresponding element of " { $snippet "u" } " and " { $snippet "v" } "." }
529 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
530
531 HELP: vnot
532 { $values { "u" "a sequence of booleans" } { "w" "a sequence of booleans" } }
533 { $description "Takes the logical NOT of each element of " { $snippet "u" } "." }
534 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
535
536 HELP: v?
537 { $values { "mask" "a sequence of booleans" } { "true" "a sequence of numbers" } { "false" "a sequence of numbers" } { "w" "a sequence of numbers" } }
538 { $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." }
539 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
540
541 HELP: vany?
542 { $values { "v" "a sequence of booleans" } { "?" "a boolean" } }
543 { $description "Returns true if any element of " { $snippet "v" } " is true." }
544 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs when using SIMD types." } ;
545
546 HELP: vall?
547 { $values { "v" "a sequence of booleans" } { "?" "a boolean" } }
548 { $description "Returns true if every element of " { $snippet "v" } " is true." }
549 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs when using SIMD types." } ;
550
551 HELP: vnone?
552 { $values { "v" "a sequence of booleans" } { "?" "a boolean" } }
553 { $description "Returns true if every element of " { $snippet "v" } " is false." }
554 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs when using SIMD types." } ;
555
556 { 2map v+ v- v* v/ } related-words
557
558 { 2reduce v. } related-words
559
560 { vs+ vs- vs* } related-words
561
562 { v< v<= v= v> v>= vunordered? vand vor vxor vnot vany? vall? vnone? v? } related-words
563
564 { vbitand vbitandn vbitor vbitxor vbitnot } related-words