mikera / vectorz-clj

Fast matrix and vector maths library for Clojure - as a core.matrix implementation
202 stars 19 forks source link

Infinity norm is incorrect #67

Closed dmarjenburgh closed 6 years ago

dmarjenburgh commented 6 years ago

https://github.com/mikera/vectorz-clj/blob/81be477b05b940d6887e81f1ec08de05d9e8ad23/src/main/clojure/mikera/vectorz/matrix_api.clj#L366-L372

This takes the .elementMax while it should be the max of the absolute values. (atm, the inf-norm can even be negative). Unfortunately, .maxAbsElement this is not part of the INDArray interface. It's only implemented in AVector as far as I could tell. A correct way that would work for INDArrays would be (.maxElement (.absCopy m)), but requires 2 traversals.

I guess the norm protocol can be implemented for INDArray and AVector, so it would be fast for vectors.

What is the best way to deal with this?

mikera commented 6 years ago

Good spot!

I guess maxAbsElement should be available for INDArray. Nobody asked for it before but easy to support.

mikera commented 6 years ago

Fixed in 0.48.0 release :-)