How to solve a large sparse linear system from Sca

2019-05-25 03:28发布

问题:

There have been a few questions inquiring about general math/stats frameworks for Scala.

I am interested in only one specific problem, that of solving a large sparse linear system. Essentially I am looking for an equivalent of scipy.sparse.linalg.spsolve.

Currently I am looking into breeze-math of ScalaNLP Breeze, which looks like it would do the job, except that the focus of this library collection is natural language processing, so it feels a bit strange to use that.

Saddle also looks promising, but not very mature yet, and looking at its dependencies, EJML doesn't seem to have sparse functionality, while Apache commons math did, but it was flaky.

Has anyone got a reasonably simple and efficient solution that is currently available?

回答1:

Although ScalaNLP Breeze says it's for NLP, it's linear algebra library is fairly general and not specialized to NLP. With that said, you could easily do something like this:

  val A = new CSCMatrix[Int]()
  val B = new CSCMatrix[Int]()

  val x = A \ B