[Haskell-cafe] Matlab Style Logic Operations ala V1.*(V2>0) on Vectors and Matrices with HMatrix ??

Henning Thielemann lemming at henning-thielemann.de
Tue Dec 21 14:04:21 CET 2010

On Tue, 21 Dec 2010, Alberto Ruiz wrote:

> Vectorized boolean operations are not yet implemented but I hope to get them 
> ready soon, including a "find" function. In the meantime you can use 
> zipVectorWith, as mentioned by Henning.

I would not find it a great idea to support the MatLab style of handling 
booleans by 0 and 1. It's the whole point of Haskell's type safety to 
distinguish between numbers and booleans. MatLab even weakly distinguishs 
between numbers and booleans. If you use a vector of logical values 
(MatLab.logical corresponds to Haskell.Bool) as index, then it works like 
'filter', e.g.
  logical indices:  [1 2 3 4 5 6]([0 0 1 1 0 0]) = [3 4]
  number indices:   [1 2 3 4 5 6]([0 0 1 1 0 0]) -> zero index not allowed

  Writing v2>0 in Haskell would mean to compare a matrix with a scalar. You 
would need a custom '>' operator and new type hacks in order to support 
all combinations of matrix and scalar operands. I think a Matrix.zipWith 
function would be the cleanest and most efficient way we can have!

More information about the Haskell-Cafe mailing list