If functions are not vectorized already, a common approach is to use a map function (e.g.
In the meantime you could work around this by defining your own using sequences:
then you can write:
Christoph
Vector.map
from the Math.NET Numerics F# extensions). Unfortunately in your case you'd need a map2 function accepting two vectors, which is not yet available. We should add them!In the meantime you could work around this by defining your own using sequences:
let map2 f u v = Seq.map2 f (Vector.toSeq u) (Vector.toSeq v) |> DenseVector.ofSeq
which has the signature f:('a -> 'b -> 'c) -> u:Vector<'a> -> v:Vector<'b> -> Vector<'c>
then you can write:
let u = vector [1.0; 2.0; 0.0; 3.0]
let v = vector [2.0; 1.0; 3.0; 0.0]
(u, v) ||> map2 (fun p q -> if p = 0.0 || q = 0.0 then 0.0 else log(p / q) * p)
or by defining a function:let f2 p q = map2 (fun p q -> if p = 0.0 || q = 0.0 then 0.0 else log(p / q) * p) p q
// or in terms of f1:
let f2 p q = map2 f1 p q
// use on vectors u and v:
f2 u v
Thanks,Christoph