Daniel-Diaz / matrix

A Haskell native implementation of matrices and their operations.
BSD 3-Clause "New" or "Revised" License
35 stars 31 forks source link

Definition of (*) #7

Closed dalejordan closed 10 years ago

dalejordan commented 10 years ago

I think it was a mistake to define (*) as matrix multiplication. Pointwise multiplication would be better and consistent with the other Num functions. APL and others have separate operators for the other types of products, especially when you provide 3 implementations of matrix product. One can easily define an infix operator to be oen of them, but no easy way to get an efficient pointwise multiplication. I imagine in may be too late to change though.

Daniel-Diaz commented 10 years ago

The operations given to matrices are taken from the matrix ring operations wherever possible (this makes no sense for the absolute value of a matrix, for example). However, you are making a point: there is no direct way to implement element wise operations. I think this can be easily fixed by adding a function like the following (the name is provisional).

elementwise :: (a -> b -> c) -> Matrix a -> Matrix b -> Matrix c

With this in hand, elementwise multiplication would be just elementwise (*). And this can be probably extended for other use cases.

dalejordan commented 10 years ago

On 01/20/2014 02:03 PM, Daniel Díaz wrote:

The operations given to matrices are taken from the matrix ring operations wherever possible (this makes no sense for the absolute value of a matrix, for example). However, you are making a point: there is no direct way to implement element wise operations. I think this can be easily fixed by adding a function like the following (the name is provisional).

elementwise :: (a -> b -> c) -> Matrix a -> Matrix b -> Matrix c

With this in hand, elementwise multiplication would be just |elementwise (*)|. And this can be probably extended for other use cases.

"elementwise" or, perhaps, an Applicative instance would satisfy practical concerns. I can live the definition of (*) as matrix multiply, I'm just used to the elementwise definition.

Thanks, Dale

Daniel-Diaz commented 10 years ago

Function elementwise was added some time ago to HEAD (see commit https://github.com/Daniel-Diaz/matrix/commit/3ada77a24e543843361c4c04acc2482e0320534c). However, today it has reached Hackage, so I am closing this issue.