v+- ( u v -- w ) (original) (raw)
v+- ( u v -- w )
Factor handbook » The language » Numbers » Vector operations » Vector arithmetic
Prev: | v- ( u v -- w ) |
---|---|
Next: | v* ( u v -- w ) |
Inputs
u | a sequence of numbers |
---|---|
v | a sequence of numbers |
Outputs
w | a sequence of numbers |
---|
Word description
Adds and subtracts alternate elements of v and u component-wise. Elements at even indexes are subtracted, while elements at odd indexes are added.
Examples
USING: math.vectors prettyprint ; { 1 2 3 } { 2 3 2 } v+- .
{ -1 5 1 }
Definition
Methods
USING: generic math.vectors sequences.cords ;
M: cord v+-
[ v+- ] [ M\ cord v+- (call-next-method) ] cord-2map ;
inline
USING: kernel math math.vectors sequences ;
M: object v+-
[ t ] 2dip [ [ not ] 2dip pick [ + ] [ - ] if ] 2map nip ;
inline
USING: generic kernel math.vectors math.vectors.simd
math.vectors.simd.intrinsics math.vectors.simd.private ;
M: simd-128 v+-
dup simd-rep
[ (simd-v+-) ] [ M\ simd-128 v+- (call-next-method) ]
vv->v-op ; inline