BigDecimals in core.matrix?

36 views
Skip to first unread message

Mars0i

unread,
May 7, 2014, 12:47:45 PM5/7/14
to numerica...@googlegroups.com
In order to debug a numeric discrepancy between a new Clojure version and an old Common Lisp versions of a program, I thought I'd see what happened if I switched to BigDecimals in the Clojure version.  I've been using the vectorz-cl implementation of core.matrix, which only allows Doubles, but it's trival to switch the entire program over to ndarray (I love that!).  It looked as if ndarray allowed BigDecimals, but they get lost during computations:

user=> (class (mget (matrix [[1 2][3 4]]) 0 0))
java.lang.Long
user=> (class (mget (matrix [[1.0 2.0][3.0 4.0]]) 0 0))
java.lang.Double
user=> (class (mget (matrix [[1.0M 2.0M][3.0M 4.0M]]) 0 0))
java.math.BigDecimal
user=> (class (mget (mmul (matrix [[1.0M 2.0M][3.0M 4.0M]]) (matrix [1.0M 1.0M]))))
java.lang.Double

user=> (class (mget (mmul (matrix [[1M 2M][3 4]]) (matrix [1 1]))))
java.lang.Double


Is that a policy, or does it have to do with the current implementation of operations such as addition?  Might ndarray eventually support allowing a non-Double numeric type to be used everywhere?  So far I haven't found anything that answers this question in this group or in core.matrix, but I might have missed something.  Thanks-

Marshall

Mike Anderson

unread,
May 7, 2014, 1:10:04 PM5/7/14
to numerica...@googlegroups.com
NDArray should (in theory) be able to support BigDecimal maths throughout.

However I suspect that something in the NDArray mmul code is forcing conversion to doubles. Ideally it should retain the BigDecimal type. It is also possible that the cause is in the behaviour of the Clojure maths functions (which core.matrix uses for general number handling).

Could you file an issue against core.matrix NDArray so we don't lose track of this?

Mars0i

unread,
May 7, 2014, 1:33:32 PM5/7/14
to numerica...@googlegroups.com


On Wednesday, May 7, 2014 12:10:04 PM UTC-5, Mike Anderson wrote:
NDArray should (in theory) be able to support BigDecimal maths throughout.

However I suspect that something in the NDArray mmul code is forcing conversion to doubles. Ideally it should retain the BigDecimal type. It is also possible that the cause is in the behaviour of the Clojure maths functions (which core.matrix uses for general number handling).

Could you file an issue against core.matrix NDArray so we don't lose track of this?

Yes, will do.  I wasn't sure whether it would count as an issue.
Reply all
Reply to author
Forward
0 new messages