math.vectors: separate "dot product" from "Hermitian inner product". Fixes #484.
parent
70f0b151fb
commit
4f046a2339
|
@ -124,7 +124,7 @@ IN: math.matrices
|
|||
dupd proj v- ;
|
||||
|
||||
: angle-between ( v u -- a )
|
||||
[ normalize ] bi@ v. acos ;
|
||||
[ normalize ] bi@ h. acos ;
|
||||
|
||||
: (gram-schmidt) ( v seq -- newseq )
|
||||
[ dupd proj v- ] each ;
|
||||
|
|
|
@ -289,6 +289,10 @@ HELP: v.
|
|||
{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "x" "a real number" } }
|
||||
{ $description "Computes the dot product of two vectors." } ;
|
||||
|
||||
HELP: h.
|
||||
{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "x" "a real number" } }
|
||||
{ $description "Computes the Hermitian inner product of two vectors." } ;
|
||||
|
||||
HELP: vs+
|
||||
{ $values { "u" "a sequence of numbers" } { "v" "a sequence of numbers" } { "w" "a sequence of numbers" } }
|
||||
{ $description "Adds " { $snippet "u" } " and " { $snippet "v" } " component-wise with saturation." }
|
||||
|
|
|
@ -23,4 +23,7 @@ SPECIALIZED-ARRAY: int
|
|||
|
||||
[ { 0 3 2 5 4 } ] [ { 1 2 3 4 5 } { 1 1 1 1 1 } v+- ] unit-test
|
||||
|
||||
[ 1 ] [ { C{ 0 1 } } dup v. ] unit-test
|
||||
[ 32 ] [ { 1 2 3 } { 4 5 6 } v. ] unit-test
|
||||
[ -1 ] [ { C{ 0 1 } } dup v. ] unit-test
|
||||
|
||||
[ 1 ] [ { C{ 0 1 } } dup h. ] unit-test
|
||||
|
|
|
@ -208,7 +208,10 @@ M: object v?
|
|||
: vinfimum ( seq -- vmin ) [ ] [ vmin ] map-reduce ; inline
|
||||
|
||||
GENERIC: v. ( u v -- x )
|
||||
M: object v. [ conjugate * ] [ + ] 2map-reduce ; inline
|
||||
M: object v. [ * ] [ + ] 2map-reduce ; inline
|
||||
|
||||
GENERIC: h. ( u v -- x )
|
||||
M: object h. [ conjugate * ] [ + ] 2map-reduce ; inline
|
||||
|
||||
GENERIC: norm-sq ( v -- x )
|
||||
M: object norm-sq [ absq ] [ + ] map-reduce ; inline
|
||||
|
|
Loading…
Reference in New Issue