简体   繁体   中英

Matrix multiplication in java

I wanted to do matrix multiplication in Java, and the speed needs to be very good.

I was thinking of calling R through java to achieve this.

I had a couple of Qs though:

  1. Is calling R using Java a good idea? If yes, are there any code samples that can be shared?

  2. What are the other ways that can be considered to do matrix multiplication in Java?

Update:

My colleague who quit the firm was a C# programmer, who was forced to write Java code that involved matrix multiplication.

-- He has written his own DataTable class in Java, in order to be able to

a) create indexes to sort and join with other DataTables

b) matrix multiplication.

So, I want to essentially clean up the code, and thought using something like R within Java will help me focus on business logic rather than sorting, joining, matrix multiplication, etc.

您可以使用矩阵包,例如JAMA

There are several stackoverflow questions on using R with Java. This is simple with JRI . See this question for an example: R from within Java . Once you have integrated your code, doing the matrix multiplication in R is trivial. If you have two matrices, a and b , you would simply call: a %*% b .

If you want to stay in pure Java and work with a mathematics library, you can also look into using Colt (which is adapted from JAMA ), although you could be better off just using JAMA directly .

Another option would be to use Incanter from Clojure (which provides a wrapper around Parallel Colt , amongst other things), and then call it as a Jar from Java. It's trivial to integrate Clojure into Java, and if all you want is matrix multiplication, that will be easier for you than using R.

Another vote for jblas . all the methods are like you'd expect them to be.

EJML seems to be a promising new one for fast multiplication. They have benchmarks on their site to show what they claim to be fast times for matrix multiplication.

Parallel colt is an effective library to perform matrix operations .

Other good matrix libraries would include jblas and ujmp

All of these packages are effective. jblas is my personal favourite . It has good documentation and straight forward unlike ujmp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM