]> gitweb.factorcode.org Git - factor.git/blob - basis/math/vectors/vectors-docs.factor
remove SIMDS:
[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     vif
105 }
106 "Entire vector tests:"
107 { $subsections
108     vall?
109     vany?
110     vnone?
111 }
112 "Element shuffling:"
113 { $subsections vshuffle } ;
114
115 ARTICLE: "math-vectors-misc" "Miscellaneous vector functions"
116 { $subsections
117     trilerp
118     bilerp
119     vlerp
120     vnlerp
121     vbilerp
122 } ;
123
124 ARTICLE: "math-vectors-simd-logic" "Componentwise logic with SIMD vectors"
125 "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:"
126 { $example
127 """USING: math.vectors math.vectors.simd prettyprint ;
128 FROM: alien.c-types => float ;
129 SIMD: float
130
131 float-4{ 1.0 2.0 3.0 0/0. } float-4{ 1.0 -2.0 3.0 0/0. } v= ."""
132 """float-4{ NAN: fffffe0000000 0.0 NAN: fffffe0000000 0.0 }"""
133 }
134 "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):"
135 { $example
136 """USING: math.vectors math.vectors.simd prettyprint alien.c-types ;
137 SIMD: int
138 SIMD: uchar
139
140 int-4{ 1 2 3 0 } int-4{ 1 -2 3 4 } v=
141 uchar-16{  0  1  2  3  4  5 6 7 8 9 10 11 12 13 14 15 }
142 uchar-16{ 15 14 13 12 11 10 9 8 7 6  5  4  3  2  1  0 } v<
143 [ . ] bi@"""
144 """int-4{ -1 0 -1 0 }
145 uchar-16{ 255 255 255 255 255 255 255 255 0 0 0 0 0 0 0 0 }"""
146 }
147 "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:"
148 { $example
149 """USING: math.vectors math.vectors.simd prettyprint alien.c-types ;
150 SIMD: int
151
152 int-4{ f f t f } ."""
153 """int-4{ 0 0 -1 0 }""" }
154 "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."
155 $nl
156 "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."
157 $nl
158 "This applies to the output of the following element comparison words: "
159 { $list
160 { $link v< }
161 { $link v<= }
162 { $link v= }
163 { $link v>= }
164 { $link v> }
165 { $link vunordered? }
166 }
167 "This likewise applies to the " { $snippet "mask" } " argument of " { $link v? } " and to the inputs and outputs of the following element logic words:"
168 { $list
169 { $link vand }
170 { $link vandn }
171 { $link vor }
172 { $link vxor }
173 { $link vnot }
174 }
175 "Finally, this applies to the inputs of these vector test words:"
176 { $list
177 { $link vall? }
178 { $link vany? }
179 { $link vnone? }
180 } ;
181
182 ARTICLE: "math-vectors" "Vector operations"
183 "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."
184 { $subsections
185     "math-vectors-arithmetic"
186     "math-vectors-logic"
187     "math-vectors-shuffle"
188     "math-vectors-misc"
189 } ;
190
191 ABOUT: "math-vectors"
192
193 HELP: vneg
194 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } }
195 { $description "Negates each element of " { $snippet "u" } "." } ;
196
197 HELP: vabs
198 { $values { "u" "a sequence of numbers" } { "v" "a sequence of non-negative real numbers" } }
199 { $description "Takes the absolute value of each element of " { $snippet "u" } "." } ;
200
201 HELP: vsqrt
202 { $values { "u" "a sequence of non-negative real numbers" } { "v" "a sequence of non-negative real numbers" } }
203 { $description "Takes the square root of each element of " { $snippet "u" } "." }
204 { $warning "For performance reasons, this does not work with negative inputs, unlike " { $link sqrt } "." } ;
205
206 HELP: vfloor
207 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } }
208 { $description "Takes the " { $link floor } " of each element of " { $snippet "u" } "." } ;
209
210 HELP: vceiling
211 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } }
212 { $description "Takes the " { $link ceiling } " of each element of " { $snippet "u" } "." } ;
213
214 HELP: vtruncate
215 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } }
216 { $description "Truncates each element of " { $snippet "u" } "." } ;
217
218 HELP: n+v
219 { $values { "n" "a number" } { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } }
220 { $description "Adds " { $snippet "n" } " to each element of " { $snippet "u" } "." } ;
221
222 HELP: v+n
223 { $values { "u" "a sequence of numbers" } { "n" "a number" } { "v" "a sequence of numbers" } }
224 { $description "Adds " { $snippet "n" } " to each element of " { $snippet "u" } "." } ;
225
226 HELP: n-v
227 { $values { "n" "a number" } { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } }
228 { $description "Subtracts each element of " { $snippet "u" } " from " { $snippet "n" } "." } ;
229
230 HELP: v-n
231 { $values { "u" "a sequence of numbers" } { "n" "a number" } { "v" "a sequence of numbers" } }
232 { $description "Subtracts " { $snippet "n" } " from each element of " { $snippet "u" } "." } ;
233
234 HELP: n*v
235 { $values { "n" "a number" } { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } }
236 { $description "Multiplies each element of " { $snippet "u" } " by " { $snippet "n" } "." } ;
237
238 HELP: v*n
239 { $values { "u" "a sequence of numbers" } { "n" "a number" } { "v" "a sequence of numbers" } }
240 { $description "Multiplies each element of " { $snippet "u" } " by " { $snippet "n" } "." } ;
241
242 HELP: n/v
243 { $values { "n" "a number" } { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } }
244 { $description "Divides " { $snippet "n" } " by each element of " { $snippet "u" } "." }
245 { $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
246
247 HELP: v/n
248 { $values { "u" "a sequence of numbers" } { "n" "a number" } { "v" "a sequence of numbers" } }
249 { $description "Divides each element of " { $snippet "u" } " by " { $snippet "n" } "." }
250 { $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
251
252 HELP: v+
253 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
254 { $description "Adds " { $snippet "u" } " and " { $snippet "v" } " component-wise." } ;
255
256 HELP: v-
257 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
258 { $description "Subtracts " { $snippet "v" } " from " { $snippet "u" } " component-wise." } ;
259
260 HELP: v+-
261 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
262 { $description "Adds and subtracts alternate elements of " { $snippet "v" } " and " { $snippet "u" } " component-wise." }
263 { $examples
264     { $example
265         "USING: math.vectors prettyprint ;"
266         "{ 1 2 3 } { 2 3 2 } v+- ."
267         "{ -1 5 1 }"
268     }
269 } ;
270
271 HELP: [v-]
272 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
273 { $description "Subtracts " { $snippet "v" } " from " { $snippet "u" } " component-wise; any components which become negative are set to zero." } ;
274
275 HELP: v*
276 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
277 { $description "Multiplies " { $snippet "u" } " and " { $snippet "v" } " component-wise." } ;
278
279 HELP: v/
280 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
281 { $description "Divides " { $snippet "u" } " by " { $snippet "v" } " component-wise." }
282 { $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
283
284 HELP: vmax
285 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
286 { $description "Creates a sequence where each element is the maximum of the corresponding elements from " { $snippet "u" } " and " { $snippet "v" } "." }
287 { $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 5 } { -7 6 3 } vmax ." "{ 1 6 5 }" } } ;
288
289 HELP: vmin
290 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
291 { $description "Creates a sequence where each element is the minimum of the corresponding elements from " { $snippet "u" } " and " { $snippet "v" } "." }
292 { $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 5 } { -7 6 3 } vmin ." "{ -7 2 3 }" } } ;
293
294 HELP: v.
295 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "x" "a real number" } }
296 { $description "Computes the dot product of two vectors." } ;
297
298 HELP: vs+
299 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
300 { $description "Adds " { $snippet "u" } " and " { $snippet "v" } " component-wise with saturation." }
301 { $examples
302     "With saturation:"
303     { $example
304         "USING: alien.c-types math.vectors prettyprint specialized-arrays ;"
305         "SPECIALIZED-ARRAY: uchar"
306         "uchar-array{ 100 200 150 } uchar-array{ 70 70 70 } vs+ ."
307         "uchar-array{ 170 255 220 }"
308     }
309     "Without saturation:"
310     { $example
311         "USING: alien.c-types math.vectors prettyprint specialized-arrays ;"
312         "SPECIALIZED-ARRAY: uchar"
313         "uchar-array{ 100 200 150 } uchar-array{ 70 70 70 } v+ ."
314         "uchar-array{ 170 14 220 }"
315     }
316 } ;
317
318 HELP: vs-
319 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
320 { $description "Subtracts " { $snippet "v" } " from " { $snippet "u" } " component-wise with saturation." } ;
321
322 HELP: vs*
323 { $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
324 { $description "Multiplies " { $snippet "u" } " and " { $snippet "v" } " component-wise with saturation." } ;
325
326 HELP: vbitand
327 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
328 { $description "Takes the bitwise and of " { $snippet "u" } " and " { $snippet "v" } " component-wise." }
329 { $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." } ;
330
331 HELP: vbitandn
332 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
333 { $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" } "." }
334 { $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." } ;
335
336 HELP: vbitor
337 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
338 { $description "Takes the bitwise or of " { $snippet "u" } " and " { $snippet "v" } " component-wise." }
339 { $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." } ;
340
341 HELP: vbitxor
342 { $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "w" "a sequence of real numbers" } }
343 { $description "Takes the bitwise exclusive or of " { $snippet "u" } " and " { $snippet "v" } " component-wise." }
344 { $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." } ;
345
346 HELP: vlshift
347 { $values { "u" "a sequence of integers" } { "n" "a non-negative integer" } { "w" "a sequence of integers" } }
348 { $description "Shifts each element of " { $snippet "u" } " to the left by " { $snippet "n" } " bits." }
349 { $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ;
350
351 HELP: vrshift
352 { $values { "u" "a sequence of integers" } { "n" "a non-negative integer" } { "w" "a sequence of integers" } }
353 { $description "Shifts each element of " { $snippet "u" } " to the right by " { $snippet "n" } " bits." }
354 { $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ;
355
356 HELP: hlshift
357 { $values { "u" "a SIMD array" } { "n" "a non-negative integer" } { "w" "a SIMD array" } }
358 { $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." } ;
359
360 HELP: hrshift
361 { $values { "u" "a SIMD array" } { "n" "a non-negative integer" } { "w" "a SIMD array" } }
362 { $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." } ;
363
364 HELP: vmerge
365 { $values { "u" "a sequence" } { "v" "a sequence" } { "w" "a sequence" } }
366 { $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" } "." }
367 { $examples
368 { $example """USING: kernel math.vectors prettyprint ;
369
370 { "A" "B" "C" "D" } { "1" "2" "3" "4" } vmerge ."""
371 """{ "A" "1" "B" "2" "C" "3" "D" "4" }"""
372 } } ;
373
374 HELP: (vmerge)
375 { $values { "u" "a sequence" } { "v" "a sequence" } { "h" "a sequence" } { "t" "a sequence" } }
376 { $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" } "." }
377 { $notes "For hardware-supported SIMD vector types this word compiles to a single instruction per output value." }
378 { $examples
379 { $example """USING: kernel math.vectors prettyprint ;
380
381 { "A" "B" "C" "D" } { "1" "2" "3" "4" } (vmerge) [ . ] bi@"""
382 """{ "A" "1" "B" "2" }
383 { "C" "3" "D" "4" }"""
384 } } ;
385
386 HELP: (vmerge-head)
387 { $values { "u" "a sequence" } { "v" "a sequence" } { "h" "a sequence" } }
388 { $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" } "." }
389 { $notes "For hardware-supported SIMD vector types this word compiles to a single instruction." }
390 { $examples
391 { $example """USING: kernel math.vectors prettyprint ;
392
393 { "A" "B" "C" "D" } { "1" "2" "3" "4" } (vmerge-head) ."""
394 """{ "A" "1" "B" "2" }"""
395 } } ;
396
397 HELP: (vmerge-tail)
398 { $values { "u" "a sequence" } { "v" "a sequence" } { "t" "a sequence" } }
399 { $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" } "." }
400 { $notes "For hardware-supported SIMD vector types this word compiles to a single instruction." }
401 { $examples
402 { $example """USING: kernel math.vectors prettyprint ;
403
404 { "A" "B" "C" "D" } { "1" "2" "3" "4" } (vmerge-tail) ."""
405 """{ "C" "3" "D" "4" }"""
406 } } ;
407
408 { vmerge (vmerge) (vmerge-head) (vmerge-tail) } related-words
409
410 HELP: vbroadcast
411 { $values { "u" "a SIMD array" } { "n" "a non-negative integer" } { "v" "a SIMD array" } }
412 { $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" } "." }
413 { $examples
414     { $example
415         "USING: alien.c-types math.vectors math.vectors.simd" "prettyprint ;"
416         "SIMD: int"
417         "int-4{ 69 42 911 13 } 2 vbroadcast ."
418         "int-4{ 911 911 911 911 }"
419     }
420 } ;
421
422 HELP: vshuffle
423 { $values { "u" "a SIMD array" } { "perm" "an array of integers, or a byte-array" } { "v" "a SIMD array" } }
424 { $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:"
425 { $list
426 { "A literal array of integers of the same length as the vector. This will perform a static, elementwise shuffle." }
427 { "A byte array or SIMD vector of the same byte length as the vector. This will perform a variable bytewise shuffle." }
428 } }
429 { $examples
430     { $example
431         "USING: alien.c-types math.vectors math.vectors.simd" "prettyprint ;"
432         "SIMD: int"
433         "int-4{ 69 42 911 13 } { 1 3 2 3 } vshuffle ."
434         "int-4{ 42 13 911 13 }"
435     }
436     { $example
437         "USING: alien.c-types combinators math.vectors math.vectors.simd"
438         "namespaces prettyprint prettyprint.config ;"
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" } { "result" "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: vif
542 { $values { "mask" "a sequence of booleans" } { "true-quot" { $quotation "( -- vector )" } } { "false-quot" { $quotation "( -- vector )" } } { "result" "a sequence" } }
543 { $description "If all of the elements of " { $snippet "mask" } " are true, " { $snippet "true-quot" } " is called and its output value returned. If all of the elements of " { $snippet "mask" } " are false, " { $snippet "false-quot" } " is called and its output value returned. Otherwise, both quotations are called and " { $snippet "mask" } " is used to select elements from each output as with " { $link v? } "." }
544 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types."
545 $nl
546 "For most conditional SIMD code, unless a case is exceptionally expensive to compute, it is usually most efficient to just compute all cases and blend them with " { $link v? } " instead of using " { $snippet "vif" } "." } ;
547
548 { v? vif } related-words
549
550 HELP: vany?
551 { $values { "v" "a sequence of booleans" } { "?" "a boolean" } }
552 { $description "Returns true if any element of " { $snippet "v" } " is true." }
553 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs when using SIMD types." } ;
554
555 HELP: vall?
556 { $values { "v" "a sequence of booleans" } { "?" "a boolean" } }
557 { $description "Returns true if every element of " { $snippet "v" } " is true." }
558 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs when using SIMD types." } ;
559
560 HELP: vnone?
561 { $values { "v" "a sequence of booleans" } { "?" "a boolean" } }
562 { $description "Returns true if every element of " { $snippet "v" } " is false." }
563 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs when using SIMD types." } ;
564
565 { 2map v+ v- v* v/ } related-words
566
567 { 2reduce v. } related-words
568
569 { vs+ vs- vs* } related-words
570
571 { v< v<= v= v> v>= vunordered? vand vor vxor vnot vany? vall? vnone? v? } related-words
572
573 { vbitand vbitandn vbitor vbitxor vbitnot } related-words