Coder Social home page Coder Social logo

jblas-project / jblas Goto Github PK

View Code? Open in Web Editor NEW
589.0 40.0 149.0 69.83 MB

Linear Algebra for Java

Home Page: http://jblas.org

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.86% Java 70.38% C 17.39% Ruby 11.05% Dockerfile 0.32%
java lapack linear-algebra machine-learning matrix-library

jblas's Introduction

jblas is a matrix library for Java which uses existing high performance BLAS and LAPACK libraries like ATLAS.

  • Version 1.2.5, August 22, 2020
  • Version 1.2.4, May 11, 2015
  • Version 1.2.3, February 13, 2013
  • Version 1.2.2, December 17, 2012
  • Version 1.2.1
  • Version 1.2.0, January 7, 2011
  • Version 1.1.1
  • Version 1.1, August 16, 2010
  • Version 1.0.2, February 26, 2010
  • Version 1.0.1, January 14, 2010
  • Version 1.0, December 22, 2009
  • Version 0.3, September 17, 2009
  • Version 0.2, May 8, 2009
  • Version 0.1, March 28, 2009

see also the file RELEASE_NOTES

Homepage: http://jblas.org

INSTALL

In principle, all you need is the jblas-1.2.5.jar in your classpath. jblas-1.2.5.jar will then automagically extract your platform dependent native library to a tempfile and load it from there. You can also put that file somewhere in your load path ($LD_LIBRARY_PATH for Linux, %PATH for Windows).

Or, use the following dependency in maven

  <dependency>
    <groupId>org.jblas</groupId>
    <artifactId>jblas</artifactId>
    <version>1.2.5</version>
  </dependency>

BUILDING

If you only work on the java part, you can use maven to recompile from the sources. In addition to that you need an installation of ruby for some scripts which automaticall generate code. Then, you just type "mvn package" on the command line.

If you want to build jblas from the sources including the native part, you need to set up quite a few things:

You will need some implementation of blas and lapack. jblas is tested with either plain lapack, or ATLAS (http://math-atlas.sourceforge.net/). You also need the Fortran sources for BLAS and LAPACK, available, for example from http://www.netlib.org/lapack/lapack-lite-3.1.1.tgz.

If you still want to build the source your own, see INSTALL for further details.

HOW TO GET STARTED

Have a look at javadoc/index.html and javadoc/org/jblas/DoubleMatrix.html

If you want to validate your installation and get some performance numbers, try "java -jar jblas-1.2.5.jar".

LICENSE

jblas is distributed under a BSD-style license. See the file COPYING for more information.

BUGS

If you encounter any bugs, feel free to go to http://jblas.org and register a ticket for them. Make sure to include as much information as possible. For configuration problems it would also be helpful to include the file "configure.log".

CONTRIBUTORS

see file AUTHORS

jblas's People

Contributors

azenkov avatar chmp avatar dependabot[bot] avatar etrain avatar farahhariri avatar fauxfaux avatar huitseeker avatar jey avatar keszybz avatar landesfeind avatar lifeiteng avatar lipiji avatar lynaghk avatar mikiobraun avatar mrsampson avatar mtbrandy avatar mudge avatar nicolasoury avatar quantisan avatar robbymckilliam avatar sehlstrom avatar srowen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jblas's Issues

configure script unable to cope with spaces in JDK-path on Windows

On my Windows Vista 64 bit box, I get the following error when invoking ./configure on the most recent sources:

codinghero@codinghero-PC /cygdrive/d/tmp/jblas/jblas
$ ./configure
checking for java, javac... ok
checking for nm... ok
determining operating system... checking for cygpath... ok
Windows
determining architecture... x86
locating the Java Development Kit... sh: -c: line 0: syntax error near unexpected token (' sh: -c: line 0:cygpath -u C:\Program Files (x86)\Java'
failed
Configuration failed!
Reason: couldn't find /include/jni.h

I believe this has something to do with spaces in the JDK path....

get(Range rs, Range cs)

First, thanks for sharing this code. Second, a bug report:

I think this is essentially the same as issue #10. There appears to be a bug in FloatMatrix.get(Range rs, Range cs) (FloatMatrix.class:642) which currently looks like this:

    public FloatMatrix get(Range rs, Range cs) {
        rs.init(0, rows);
        cs.init(0, columns);
        FloatMatrix result = new FloatMatrix(rs.length(), cs.length());

        for (; rs.hasMore(); rs.next()) {
            for (; cs.hasMore(); cs.next()) {
                result.put(rs.index(), cs.index(), get(rs.value(), cs.value()));
            }
        }
        return result;
    }

The problem is that only first row is actually "got". I think this is because cs needs to be reset for each row. For instance:

    public FloatMatrix get(Range rs, Range cs) {
        rs.init(0, rows);
        cs.init(0, columns);
        FloatMatrix result = new FloatMatrix(rs.length(), cs.length());

        for (; rs.hasMore(); rs.next()) {
            for (; cs.hasMore(); cs.next()) {
                cs.init(0,columns) //<--------------- NOTE CHANGE -----
                result.put(rs.index(), cs.index(), get(rs.value(), cs.value()));
            }
        }

        return result;
    }

I didn't bother to check if the same is present in DoubleMatrix

Use slf4j instead of home-grown logging framework

Using a standard library for logging such as slf4j or even java.util.logging would help with capturing the logs in the expected/configured places rather than just System.err which might be redirected into unexpected places or even be completely ignored.

Thank you.

Win64 mmul() fuction UnsatisfiedLinkError

It happens when I call x.mmul(y)

-- org.jblas ERROR Couldn't load copied link file: java.lang.UnsatisfiedLinkError: C:\Users\MarkNV\AppData\Local\Temp\jblas7739628082596798714jblas.dll: Can't find dependent libraries.

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.jblas.NativeBlas.dgemm(CCIIID[DII[DIID[DII)V
at org.jblas.NativeBlas.dgemm(Native Method)
at org.jblas.SimpleBlas.gemm(SimpleBlas.java:245)
at org.jblas.DoubleMatrix.mmuli(DoubleMatrix.java:1673)
at mobios.index.algorithms.JLLE.main(JLLE.java:42)

unfortunately, i've got no idea about it. it's just a simple matrix-matrix multiplication, so pls help~

SVD produces incorrect V and U*

Summary: At the moment, svd function produces incorrect V and U matrice for both sparse and full. Singular value seems to be OK.

I was using clatrix, a clojure library interface with jblas, in my project, I needed all V, S and U (and I was looking for a matlab alternative). The svd function there was a direct call to jblas' svd, and The matrix I was using was a 434x32 matrix, the smallest data set comparing with others.
By comparing with matlab result, a lot of the elements in V has different signs. And the norm of the result of (V_S_U - original_matrix) is almost a 1000, which is really really bad. Singular values, S, seems to be ok on that data set, but I didn't check with bigger data set.

Since clatrix calls jblas directly, so I figure I should report it here.

"Too many open files"

Hello!

I just stumbled on a 'too many open files' error when saving a large amount of DoubleMatrix to disk. It is looking like the output and input streams are never closed.

public void save(String filename) throws IOException {
    DataOutputStream dos = new DataOutputStream(new FileOutputStream(filename, false));
    this.out(dos);
}

public void load(String filename) throws IOException {
    DataInputStream dis = new DataInputStream(new FileInputStream(filename));
    this.in(dis);
}

Best,
Yves

strange native call failure under JAX-RS container (jersey-grizzly2), win7-x64

It all was quite perfect, until I finally tried to assemble my web-app that uses jblas at the backend. Unable to find a solution, and even debug, I'm asking for your help guys.

That's a dummy example that goes very ugly:

@Path("/myservice")
public class DummyService {
 @GET

    @GET
    @Path("test1")
    public String test1() 
    {
        final DoubleMatrix X=new DoubleMatrix(5,2,new double[]{1,2,3,4,5,6,7,8,9,10});
        final DoubleMatrix Q= X.dup();
       return Q.toString();
    }

    @Path("test2")
    public String test2()
    {
        final DoubleMatrix X=new DoubleMatrix(5,2,new double[]{1,2,3,4,5,6,7,8,9,10});

        try{

            final DoubleMatrix Q= Decompose.qr(X).q;

            // this line is never reacher

            return Q.toString();

            }catch(Throwable e){
                 // exception is never thrown
                 return "oops";
          }
    }
}

So, first, I do GET http://myhost/myservice/test1, and it works just as expected (I could see "[1,5;2,6;...]" in my browser.
Than I do GET http://myhost/myservice/test2 and just nothing happens. No response (browser is eternally waiting), no error in Java console, no exception - nada.

Than I tried to debug, and found out that everything just literally goes away at the native call to dgeqrf here:

public static void geqrf(DoubleMatrix A, DoubleMatrix tau) {
    int info = NativeBlas.dgeqrf(A.rows, A.columns, A.data, 0, A.rows, tau.data, 0);
    checkInfo("GEQRF", info);
  }

I mean, literally dies - control point never reaches the statement "checkInfo("GEQRF", info)", no exceptions thrown. JVM stays up, since other services work fine, including calls to test1 work fine.

Of course, I tried to run the same test "off-line" (not within the server context) and it all works just fine.

In this example I used a very light-weighted standalone jersey-grizzly2 server, that is launched directly via "void main()", just as any other command-line java app.

Since test1() is able to perform a native call to JavaBlas.rcopy with success, I suspect that the problem with calling dgeqrf in test2() has something to do with a threading context. Since I'm unable even get an error code, I could only guess what it is (something like "MTA vs STA"?).

Any clues are appreciated!

Later I'll try to create a maven project with a running example.

Make all Matrices, ComplexDouble and ComplexFloat serializable

I am going to create a JPPF-style library permitting a user to specify algorithms to be executed on remote computing / data nodes. For matrix operations, I'd like to choose jblas. An absolute prerequisite, however, is for all Matrices, ComplexDouble and ComplexFloat to be serializable. I can do it, if you want, and issue a pull request.

Configure fails on AArch64: Could not locate libraries for the following symbols: daxpy_, dgemm_

Trying to configure on Linux/AArch64 fails as follows:

$ ./configure --lapack=../lapack --static-libs --lapack-build --built-type=lapack --libpath=../lapack
checking for java, javac... ok
determining operating system... ok (Linux)
determining architecture... ok (aarch64)
determining architecture flavor... ok
looking for nm... ok
locating the Java Development Kit... ok (/usr/lib/jvm/java-8-openjdk-arm64)
Setting up gcc and flags... ok (gcc)
deciding whether to use g77 or gfortran... ok (gfortran)
looking for version of make... ok (make)
search for lapack sources (configure by --lapack=dir)... ok (../lapack)
determining build type... ok (static)
getting library path...... ok (["../lapack"])
determining whether to build for lapack or atlas... ok (lapack)
looking for libraries...... *failed*

Configuration failed!

Reason: Could not locate libraries for the following symbols: daxpy_, dgemm_.

Note that the lapack directory above is as downloaded from http://www.netlib.org/lapack

Trying to configure using the download option $ ./configure --static-libs --download-lapack also fails:

determining whether to build for lapack or atlas... ok (atlas)
looking for libraries...... *failed*

Configuration failed!

Reason: Could not locate libraries for the following symbols: dsyev_, ATL_dgemm, dgemm_, daxpy_, cblas_daxpy, ATL_caxpy.

Same is the case with specifying --lapack-build:

determining whether to build for lapack or atlas... ok (lapack)
looking for libraries...... *failed*

Configuration failed!

Reason: Could not locate libraries for the following symbols: dsyev_, daxpy_, dgemm_.

jblas 1.0 crashes under Windows 2000

dleskov got:

E:\TEMP>java -server -jar jblas-1.0.jar
Simple benchmark for jblas

Running sanity benchmarks.

checking vector addition... ok

#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ILLEGAL_INSTRUCTION (0xc000001d) at pc=0x1026826a, pid=560, tid=2152
#
# Java VM: Java HotSpot(TM) Server VM (1.6.0_03-b05 mixed mode)
# Problematic frame:
# C [jblas.dll+0x26826a]
#
# An error report file with more information is saved as hs_err_pid560.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#

broken equals / hashCode contract

Hi,
this is realy great lib. I like it so much, especially for almost-"matlab" comfort. But there is one annoying thing: bad implementation of .equals().
Thing is, that current equals() has several potential problems:
a) a comparison with a hard-coded tolerance (hey, what if 1e-6 is the NOT a precision I seek?)
b) NaNs are just ignored ( [1 2 3] equals [1 NaN 3])
c) equal matrices according to such implementation, will have different hashCodes - and this is a realy bad news for those who is going to use jblas objects in complex systems with caching, hashmaps. Things may go really bad for them.

AFIK, from A.equals(B) in Java we expect A.hashCode()==B.hashCode(), while opposite is not necessarily true.

Since jblas does not provide interfaces or abstract classes (for performance reasons, I guess) there is no elegant way to fix .equals() by simple overriding. So, my proposal is the following:

  1. refactor current implementation of equals(Object o) into e.g.
    compare(SomeMatrix other, double tol)

  2. implement equals(Object o) based on exact value (=byte level) comparison (e.g, using Arrays.equals(this.data,other.data).

Thanks!

Running jblas from multiple processes

I have a case where I need to run more than 1 instance of jblass at a time, for example, 1st is continuesly calculating big matrix, while in 2nd I occasionally experimenting with intermediate results of the 1st.
the problem is with mechanism of extracting native libraries into temp dir and loading it from there, even if I put 2 required dll in source dir, so they are copied into bin during compilation, the second case started and worked, but in the log it shows the error:
-- org.jblas ERROR Could not create the temp file: java.io.FileNotFoundException: C:\Users\xxx\AppData\Local\Temp\libgcc_s_dw2-1.dll (The process can not access the file because the file is in use by another process). // translated back from Russian

-- org.jblas ERROR Could not create the temp file: java.io.FileNotFoundException: C:\Users\xxx\AppData\Local\Temp\libgfortran-3.dll (The process can not access the file because the file is in use by another process).

I use with same manner JNA jar, and it also depends on native dll, but with it I am able to put this dll's into some source folder (then copied to bin) and just point JNA during startup this folder (actually, since I use a default location for WIN32x86, I even don't point anything specially)

so I think it would be useful to every one to redesign dll load pattern into something more usable, without need on specifying environment variables, which is in my opinion a bit hard operation, having in mind you have everything in several separate development environments (eclipse in my case) running in parallel.
again, I think the load pattern from JNA could be used as an example here.
btw, JNA, of course, uses JNI for that, so they develop some C wrapper around library loading, and I believe this could be done for jblas as well.

Unable to run configure: Could not locate libraries for the following symbols: dsyev_.

Hi, I keep getting this error on x86_64 Ubuntu when I try to build jblas from source. I looked at the config file located in config/config_libs.rb to see why dsyev_ is needed, but the part dsyev_ is a required symbol, but not yet included in ATLAS/LAPACK confuses me:

ATLAS_REQUIRED_SYMBOLS = [
    'dsyev_', # eigenvalue function not yet included in ATLAS/LAPACK
    'ATL_dgemm',
    'dgemm_', # matrix-matrix multiplication
    'daxpy_', # blas-related function
    'cblas_daxpy', # atlas itself often uses cblas
    'ATL_caxpy'
]

I downloaded ATLAS 3.10.2 from http://downloads.sourceforge.net/project/math-atlas/Stable/3.10.2/atlas3.10.2.tar.bz2 then compiled it using the default build parameters.

In the jblas working directory, I run ./configure --libpath=$HOME/jblas/dep/ATLAS/build/lib --static-libs

In my $HOME/jblas/dep/ATLAS/build/lib, it contains the following libraries:
libatlas.a libcblas.a libf77blas.a libf77refblas.a liblapack.a libptcblas.a libptf77blas.a libptlapack.a libtstatlas.a

I checked all the *.a files there with nm:

nm $HOME/jblas/dep/ATLAS/build/lib/*.a | grep "dsyev_"

Found nothing in those libraries that has this symbol.

Please clarify if this is an intended requirement for the build.

Environment: Ubuntu 14.04, Kernel=3.16.0-41-generic x86_64

Static libs on MacOS X

Hi,

using master as of ab621e9 (Quick fix to set SMLSIZ=25 to get around Mac OS X bug.), the build fails:


~jblas (master)> ./configure --lapack=../lapack-3.4.2 --libpath=$HOME/atlas/lib --static-libs
....
looking for libraries...... {"lapack"=>"/Users/luc/atlas/lib", "f77blas"=>"/Users/luc/atlas/lib", "cblas"=>"/Users/luc/atlas/lib", "atlas"=>"/Users/luc/atlas/lib"}
x86_64
Looking for where libgfortran.a is... (/opt/local/lib/gcc47/gcc/x86_64-apple-darwin11/4.7.3/../../../libgfortran.a)
ok

Configuration succesfull, writing out results to configure.out
~jblas (master)> make
gcc -shared -o target/c/NativeBlas.jnilib target/c/NativeBlas.o /Users/luc/atlas/lib/liblapack.a /Users/luc/atlas/lib/libf77blas.a /Users/luc/atlas/lib/libcblas.a /Users/luc/atlas/lib/libatlas.a /opt/local/lib/gcc47/gcc/x86_64-apple-darwin11/4.7.3/../../../libgfortran.a
Undefined symbols for architecture x86_64:
  "_quadmath_snprintf", referenced from:
      _write_float in libgfortran.a(write.o)
  "_strtoflt128", referenced from:
      __gfortrani_convert_real in libgfortran.a(read.o)
      __gfortrani_convert_infnan in libgfortran.a(read.o)
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [target/c/NativeBlas.jnilib] Error 1

Now if I apply the following patch:

diff --git a/config/config_libs.rb b/config/config_libs.rb
index 2055a49..19b9fca 100644
--- a/config/config_libs.rb
+++ b/config/config_libs.rb
@@ -157,10 +157,7 @@ because it's usually not compiled with -fPIC. This means that you need to
 have libgfortran.so installed on your target system. Sorry for the inconvenience!
 EOS
       elsif CONFIG['OS_NAME'] == 'Mac\ OS\ X'
-        print "Looking for where libgfortran.a is... "
-        libgfortran_path = %x(gfortran -print-file-name=libgfortran.a).strip
-             puts "(#{libgfortran_path})"
-             CONFIG['LOADLIBES'] += [libgfortran_path]
+             CONFIG['LOADLIBES'] += ['-lgfortran']
       else
         CONFIG['LOADLIBES'] += ['-l:libgfortran.a']
       end

It all works and the sanity check passes with flying colours. What was the reason for not using -lgfortran on MacOS X?

Couldn't find the resource libjblas.jnilib.

Hi,
I'm attempting to implement jblas on MacOSX using Eclipse. I've run into several errors. The first was:

    "Exception in thread "main" java.lang.UnsatisfiedLinkError: org.jblas.util.ArchFlavor.SSELevel()I"

I was able to get around that using:
ArchFlavor.overrideArchFlavor("SSE3");

Now I have run into the error:
"Exception in thread "main" java.lang.UnsatisfiedLinkError: Couldn't find the resource libjblas.jnilib."
I have worked with it for a while but don't seem to be getting anywhere. I looked at the source LibraryLoader and see at it is using "/lib/" when searching for the native libraries while the folder that is in the tar.gz is called "native-libs". I also tried changing that in LibraryLoader.java but same error.

My bit of code is:

    System.out.println("Starting jBLAS EigenvalueDecomposition");

    ArchFlavor.overrideArchFlavor("SSE3");
    SanityChecks.checkVectorAddition();
    SanityChecks.checkEigenvalues();

and the full error message is...

    Starting jBLAS EigenvalueDecomposition
    -- org.jblas ERROR Couldn't load copied link file: java.lang.UnsatisfiedLinkError: /private/var/folders/dy/dyBwkLfgEIC3mw-aTd3uj++++Tc/-Tmp-/jblas1067812095146790936libjblas_arch_flavor.jnilib:  no suitable image found.  Did find:  /private/var/folders/dy/dyBwkLfgEIC3mw-aTd3uj++++Tc/-Tmp-/jblas1067812095146790936libjblas_arch_flavor.jnilib: unknown required load command 0x80000022.

    checking vector addition... ok
    Exception in thread "main" java.lang.UnsatisfiedLinkError: Couldn't find the resource libjblas.jnilib.
at org.jblas.util.LibraryLoader.loadLibrary(LibraryLoader.java:119)
at org.jblas.NativeBlas.<clinit>(NativeBlas.java:84)
at org.jblas.util.SanityChecks.checkEigenvalues(SanityChecks.java:122)
at gs.rrEmma.EigenTester.main(EigenTester.java:81)

Thanks!

After downloading libs: "Couldn't locate LAPACK and BLAS libraries."

[...]
lapack-lite-3.1.1/TESTING/sgbak.in
lapack-lite-3.1.1/TESTING/zbak.in
lapack-lite-3.1.1/TESTING/dec.in
lapack-lite-3.1.1/TESTING/ced.in
lapack-lite-3.1.1/TESTING/ssg.in
lapack-lite-3.1.1/TESTING/cgd.in
lapack-lite-3.1.1/TESTING/zsb.in
lapack-lite-3.1.1/TESTING/cbal.in
lapack-lite-3.1.1/TESTING/dgg.in
lapack-lite-3.1.1/TESTING/dstest.in
lapack-lite-3.1.1/TESTING/dbal.in
lapack-lite-3.1.1/TESTING/dgbak.in
lapack-lite-3.1.1/TESTING/sbb.in
lapack-lite-3.1.1/TESTING/csb.in
lapack-lite-3.1.1/TESTING/cgbal.in
lapack-lite-3.1.1/TESTING/ztest.in
lapack-lite-3.1.1/Makefile
lapack-lite-3.1.1/README
./lapack-lite-3.1.1
locating lapack and blas libraries... failed
failed

Configuration failed!

Reason: Couldn't locate LAPACK and BLAS libraries.

Reason: couldn't find library 'lapack' in
path /usr/lib:/lib:/usr/lib/sse2

You can try to pass the location via --libpath=...
or build your own LAPACK and BLAS libraries (see INSTALL)

codinghero@codinghero-PC /cygdrive/d/tmp/jblas/jblas
$

./configure script option --download-lapack doesnt work

codinghero@codinghero-PC /cygdrive/d/tmp/jblas/jblas
$ ./configure --download-lapack
checking for java, javac... ok
checking for nm... ok
determining operating system... checking for cygpath... ok
Windows
determining architecture... amd64
locating the Java Development Kit... ok
deciding whether to use g77 or gfortran... g77
Setting up gcc and flags... ok
looking for version of make... ok
locating lapack sources... failed
trying to download lapack (about 5M)
tar (child): lapack-lite-3.1.1.tgz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Exiting with failure status due to previous errors
failed

Configuration failed!

Reason: couldn't find ./lapack-lite-3.1.1/BLAS/SRC/dgemm.f

arg() function for complex numbers is wrong

Both ComplexFloat and ComplexDouble classes contain wrong implementation of arg().

E.g.

    public float arg() {
        return (float) Math.atan2(r, i);
    }

must be replaced with

    public float arg() {
        return (float) Math.atan2(i, r);
    }

exp(ix) = cos(x) + i*sin(x). atan2(y, x) = arctan(y/x) for non-zero x. So to get x = arg(exp(ix)), you need to take atan2(im(exp(ix)), re(exp(ix))) = atan2(sin(x), cos(x)) = arctan(tan(x)) = x (for x in proper range).

java.lang.OutOfMemoryError: Java heap space

Hi

Splendid tool!

But I have a problem with a possible memory leakage when I am running my code. There is a good chance the problem is related to jblas since it started to occur when I changed from the apache.commons.math3 linear algebra package to jblas.

I perform an iteration in a method similar to the code below:

void doStep(DoubleMatrix f) {
    DoubleMatrix k = assembler.getStiffness();
    this.u = Solve.solvePositive(k, f);
}

The memory error occurs inside the Solve.Solve.solvePositive()-method after about 7 iterations when the size of k is about 1400x1400 and 2 iterations when k is about 2050x2050.

Is there a way to "clear" the memory that the jblas uses?

Exception statement (trunkated):

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    at org.jblas.DoubleMatrix.<init>(DoubleMatrix.java:323)
    at org.jblas.DoubleMatrix.dup(DoubleMatrix.java:1191)
    at org.jblas.Solve.solvePositive(Solve.java:66)

possible bug in DoubleMatrix.put

Just exploring DoubleMatrix,put:

    /** Set elements in linear ordering in the specified indices. */
    public DoubleMatrix put(int[] indices, DoubleMatrix x) {
        if (x.isScalar()) {
            return put(indices, x.scalar());
        }
        x.checkLength(indices.length);

        for (int i = 0; i < indices.length; i++) {
            put(indices[i], x.get(i));
        }

        return this;
    }

String

x.checkLength(indices.length);

seems unnecessary. Cause, if someone call something like this:

DoubleMatrix m = DoubleMatrix.ones(3);
m.put(new int[]{2}, DoubleMatrix.zeros(3));

it will be an exception

internal representation of DoubleMatrix fundamentally contradict with documentation

from the documentation I expected that internally DoubleMatrix represented as single array of row after row, i.e. row0:column0, column2..column5; row1..., row2... etc

follow this logic, if I need to took DoubleMatrix[row1][column4], it would be length of 1 row + 4, i.e.
"rowIndex * columns + columnIndex"
"1 * 5+ 4"

but after week of fighting, I decided to look into code of DoubleMatrix.index method.
/** Get index of an element */
public int index(int rowIndex, int columnIndex) {
return rowIndex + rows * columnIndex;
}

it is completely opposite! so the internal representation of DoubleMatrix is NOT row after row.
it is column, after column, because of this index method.

I am really surprised to find such fundamental difference. it took me more that 3 days of debug and test to understand that it was not my fault, because of my belief in documentation.

Small typo in DoubleMatrix javadoc

On the javadoc page for DoubleMatrix, in the table following
"Alternatively, you can construct (column) vectors, if you just supply the length using the following constructors and static methods."

The descriptions for the initial values of zeros() and ones() have been transposed (ones() has 0.0, zeros() has 1.0).

getRows with IntervalRange problems

The method "public DoubleMatrix getRows(Range indices, DoubleMatrix result)" uses the indices.index() instead of the values. Resulting in problems when try to get some rows in the middle.

e.g.:
DoubleMatrix m = new DoubleMatrix(new double[][]{{1,1,1},{2,2,2},{3,3,3},{4,4,4}});
DoubleMatrix m1 = m.getRows(new IntervalRange(0, 2));
DoubleMatrix m2 = m.getRows(new IntervalRange(2, m.getRows()));

m1 and m2 have the same values.

Fatal error in Solve.pinv

The following code:

import org.jblas.DoubleMatrix;
import org.jblas.Solve;

public class Problem
{
  public static void main(String [] args)
  {
    double [][] test = new double[][]{{1,0.5},{0.5,1}};
    for (int i = 0; i < 1000; i++)
      Solve.pinv(new DoubleMatrix(test));
  }
}

crashes with the error:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fff8a1e8b56, pid=70017, tid=6659
#
# JRE version: Java(TM) SE Runtime Environment (8.0_20-b26) (build 1.8.0_20-b26)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.20-b23 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C  [libsystem_c.dylib+0x1b56]  memmove$VARIANT$sse42+0x16e
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# [ANONYMIZED]/hs_err_pid70017.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Platform: mac ox 10.8.5

Matrix put with ranges

These checks assume sizes of ranges to have exactly the same size as the matrix has. This way it is impossible to fill some part of the matrix with the other one (say a vector), you can only fill the whole matrix with the other one of the same size.

public DoubleMatrix put(Range rs, Range cs, DoubleMatrix x) {
        rs.init(0, rows);
        cs.init(0, columns);

        x.checkRows(rs.length());
        x.checkColumns(cs.length());

        for (; rs.hasMore(); rs.next()) {
            cs.init(0, columns);
            for (; cs.hasMore(); cs.next()) {
                put(rs.value(), cs.value(), x.get(rs.index(), cs.index()));
            }
        }

        return this;
    }

Power Linux (ppc64le) support?

What is the process for adding support for additional platforms?

Running Spark on RHEL/Ubuntu (ppc64le) currently requires a manually build of libjblas.so to enable some of the Machine learning library functionality.

I can assist in obtaining access to Power hardware to ease the process.

Inverted rows/columns in matrix representation

Not a big deal, but a bit confusing bug, either in a code or in docs.

According to your javadoc, we got the following API:

DoubleMatrix(int newRows, int newColumns, double... newData)
saying:
"DoubleMatrix(m,n, [value1, value2, value3...]) Values are filled in row by row."

So, I expected the following test to pass, but it didn't:

    final DoubleMatrix x1=new DoubleMatrix(2,3,new double[]{1,2,3,4,5,6});
    final DoubleMatrix x2=new DoubleMatrix(new double[][]{{1,2,3},{4,5,6}});

    System.out.println(x1);
    System.out.println(x2);

    assertTrue(x1.equals(x2));

The output is:

[1,000000, 3,000000, 5,000000; 2,000000, 4,000000, 6,000000]
[1,000000, 2,000000, 3,000000; 4,000000, 5,000000, 6,000000]

It looks like DoubleMatrix(m,n, [value1, value2, value3...]) is filled "column by column" instead. "Column by column" may also make some sense, since for example, Matlab does so in memory, but I didn't expect such behavior here ;)

Thanx!

P.S: I uses jblass-1.2.3 from maven.

CONFIG BLAS native library not found in path.

uname -a
SunOS opensolaris.2009.06 5.11 snv_134b i86pc i386 i86pc Solaris

java -version
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Server VM (build 16.0-b13, mixed mode)

java -server -jar jblas-1.2.3.jar
-- org.jblas INFO jblas version is 1.2.3
Simple benchmark for jblas

Running sanity benchmarks.

checking vector addition... ok
-- org.jblas CONFIG BLAS native library not found in path. Copying native library from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH).
-- org.jblas CONFIG ArchFlavor native library not found in path. Copying native library libjblas_arch_flavor from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH).
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.jblas.NativeBlas.dgemm(CCIIID[DII[DIID[DII)V
at org.jblas.NativeBlas.dgemm(Native Method)
at org.jblas.SimpleBlas.gemm(SimpleBlas.java:251)
at org.jblas.DoubleMatrix.mmuli(DoubleMatrix.java:1697)
at org.jblas.DoubleMatrix.mmul(DoubleMatrix.java:3054)
at org.jblas.util.SanityChecks.checkMatrixMultiplication(SanityChecks.java:91)
at org.jblas.util.SanityChecks.main(SanityChecks.java:182)
at org.jblas.benchmark.Main.main(Main.java:114)
[email protected]:/The-Hill-cipher2$
[email protected]:
/The-Hill-cipher2$
[email protected]:~/The-Hill-cipher2$ java -jar jblas-1.2.3.jar
-- org.jblas INFO jblas version is 1.2.3
Simple benchmark for jblas

Running sanity benchmarks.

checking vector addition... ok
-- org.jblas CONFIG BLAS native library not found in path. Copying native library from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH).
-- org.jblas CONFIG ArchFlavor native library not found in path. Copying native library libjblas_arch_flavor from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH).
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.jblas.NativeBlas.dgemm(CCIIID[DII[DIID[DII)V
at org.jblas.NativeBlas.dgemm(Native Method)
at org.jblas.SimpleBlas.gemm(SimpleBlas.java:251)
at org.jblas.DoubleMatrix.mmuli(DoubleMatrix.java:1697)
at org.jblas.DoubleMatrix.mmul(DoubleMatrix.java:3054)
at org.jblas.util.SanityChecks.checkMatrixMultiplication(SanityChecks.java:91)
at org.jblas.util.SanityChecks.main(SanityChecks.java:182)
at org.jblas.benchmark.Main.main(Main.java:114)
[email protected]:~/The-Hill-cipher2$

Ability to set random seed

It would be nice if the results of DoubleMatrix.rand() were reproducable. We need a way to set the seed used by the java.util.Random object DoubleMatrix.rand() is using.

Release?

Think you could release the next version of jblas? Or do you have any blockers? Just curious on the status of the project. Thanks!

put Ranges

Hello mikkiobraun

Your API is a great work. thank you.
By making some data imports with the put function and ranges I found some bug. If I understood the function put(Range rs, Range cs, DoubleMatrix x) correctly they should in the first loop something like โ€žcs.reset();โ€œ otherwise only the first row would be inserted.

/** Put a matrix into specified indices. */
public DoubleMatrix put(Range rs, Range cs, DoubleMatrix x) {
rs.init(0, rows);
cs.init(0, columns);

    x.checkRows(rs.length());
    x.checkColumns(cs.length());

    for (; rs.hasMore(); rs.next()) {
        for (; cs.hasMore(); cs.next()) {
            put(rs.value(), cs.value(), x.get(rs.index(), cs.index()));
        }
        cs.reset();
    }

    return this;
}

jblas on multiple jvm instances

Given that there is already a jvm process running jblas, if a second jvm process is run (windows 64bit in my tests), I get the error
-- org.jblas ERROR Couldn't load copied link file: java.lang.UnsatisfiedLinkError: C:\Windows\Temp\libgcc_s_dw2-1.dll: The process cannot access the file because it is being used by another process.

-- org.jblas ERROR Couldn't load copied link file: java.lang.UnsatisfiedLinkError: C:\Windows\Temp\jblas2376714726013803026jblas_arch_flavor.dll: Can't find dependent libraries.

Problem with mmuli

Hi everyone
I have a problem with the function mmulti of DoubleMatrix class
it doesn't return the result, and netbeans throws me a nullpointer exception

unoD.mmuli(unoT, unoP);

I want to multiply unoD with unoT and I want to assign the result into unoP
but that line throws me a nullpoint excepcion...
plz tell me what I'm doing wrong or what's wrong hahaha
greetings :D

Windows 64 Library Missing Dependencies?

When I try to run JBlas in 64-bit Windows, I get an unsatisfied link exception which actually looks to be a missing dependency:

-- org.jblas ERROR Couldn't load copied link file: java.lang.UnsatisfiedLinkError: C:\Users\chris\AppData\Local\Temp\jblas6440552492698981567jblas.dll: Can't find dependent libraries

If I run JBlas with 32-bit java on the same machine it runs with no problems. Unfortunately I don't have any idea how to dig around the dll to see what dependencies I'm missing.

Error configuring jBlas to use OpenBlas

Hi,

I am trying to configure jBlas in a way that will enable me to use OpenBlas with it. I have followed the instructions given in #51. When I try executing the configure command, an error prompts indicating some libraries could not be found:

./configure --static-libs --libpath=$HOME/openblas/lib --download-lapack --lapack-build

Where HOME/openblas/lib indicates my custom installation location. The followings are the error and the log generated in the file configure.log

checking for java, javac... ok
determining operating system... ok (Linux)
determining architecture... ok (amd64)
determining architecture flavor... ok (sse3)
looking for nm... ok
locating the Java Development Kit... ok (/usr/lib/jvm/java-7-openjdk-amd64)
Setting up gcc and flags... ok (gcc)
deciding whether to use g77 or gfortran... ok (gfortran)
looking for version of make... ok (make)
search for lapack sources (configure by --lapack=dir)... ok (./lapack-lite-3.1.1)
determining build type... ok (static)
getting library path...... ok (["/home/ubuntu/openblas/lib"])
determining whether to build for lapack or atlas... ok (lapack)
looking for libraries...... *failed*

Configuration failed!

Reason: Could not locate libraries for the following symbols: dsyev_, daxpy_, dgemm_.

configure.log:

Searching for command java
Searching for command javac
Setting FOUND_JAVA to true
Setting OS_NAME to Linux
Setting OS_ARCH to amd64
Searching for command gcc
Setting OS_ARCH_WITH_FLAVOR to amd64/sse3
Searching for command nm
Setting NM to nm
Setting FOUND_NM to true
Searching for file /usr/lib/jvm/java-7-openjdk-amd64/include/jni.h
Setting JAVA_HOME to /usr/lib/jvm/java-7-openjdk-amd64
Searching for command gcc
Searching for command make
Searching for command ld
Setting CC to gcc
Setting CFLAGS to -fPIC
Setting INCDIRS to ["-Iinclude -I/usr/lib/jvm/java-7-openjdk-amd64/include -I/usr/lib/jvm/java-7-openjdk-amd64/include/linux"]
Setting SO to so
Setting LIB to lib
Setting RUBY to ruby
Setting LDFLAGS to ["-shared"]
Setting F77 to gfortran
Setting LD to gcc
Setting CCC to c99
Setting MAKE to make
Searching for file ./lapack-lite-3.1.1/BLAS/SRC/dgemm.f
Searching for file ./lapack-lite-3.1.1/SRC/dsyev.f
Setting LAPACK_HOME to ./lapack-lite-3.1.1
Setting LINKAGE_TYPE to static
Setting libpath to ["/home/ubuntu/openblas/lib"]
Setting BUILD_TYPE to lapack

I wonder what the problem could be. It seems a rather straightforward process, and I fail to identify what mistake I am doing. Any help would be appreciated.

org.jblas.FloatMatrix.loadCSVFile() prints to System.out

Hello,

The loadCSVFile() method in the FloatMatrix class contains the following line:

System.out.println("Done reading file");

(Line 2085 in org.jblas.FloatMatrix.java in the jblas-1.2.3.jar available via Maven.)

imho - making applications which use JBlas print messages they did not intend to seems like a bad idea. It would be nicer if this was either
a. removed, or
b. made optional via some verbosity flag.

Maven support would be nice

so that people (like me) can add it more easily to their repository. But that's just my 2 cents, it really just nice to have, not crucial....

Missing libraries even when libgfortran.x86_64 is installed

Hi,

I was trying to do the following,

java -server -jar jblas-1.2.4.jar

and I get the following error. I've already installed libgfortran.x86_64 using yum. Any thoughts?

-- org.jblas INFO jblas version is 1.2.4
Simple benchmark for jblas

Running sanity benchmarks.

checking vector addition... ok
-- org.jblas CONFIG BLAS native library not found in path. Copying native library from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH).
-- org.jblas CONFIG ArchFlavor native library not found in path. Copying native library libjblas_arch_flavor from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH).
-- org.jblas CONFIG Loading libjblas_arch_flavor.so from /lib/static/Linux/amd64/, copying to libjblas_arch_flavor.so.
-- org.jblas ERROR Couldn't load copied link file: java.lang.UnsatisfiedLinkError: /tmp/jblas29209775120479040/libjblas_arch_flavor.so: libgfortran.so.3: cannot open shared object file: No such file or directory.

On Linux 64bit, you need additional support libraries.
You need to install libgfortran3.

For example for debian or Ubuntu, type "sudo apt-get install libgfortran3"

For more information, see https://github.com/mikiobraun/jblas/wiki/Missing-Libraries
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.jblas.NativeBlas.dgemm(CCIIID[DII[DIID[DII)V
at org.jblas.NativeBlas.dgemm(Native Method)
at org.jblas.SimpleBlas.gemm(SimpleBlas.java:247)
at org.jblas.DoubleMatrix.mmuli(DoubleMatrix.java:1781)
at org.jblas.DoubleMatrix.mmul(DoubleMatrix.java:3138)
at org.jblas.util.SanityChecks.checkMatrixMultiplication(SanityChecks.java:91)
at org.jblas.util.SanityChecks.main(SanityChecks.java:182)
at org.jblas.benchmark.Main.main(Main.java:114)
-- org.jblas INFO Deleting /tmp/jblas29209775120479040/libjblas_arch_flavor.so
-- org.jblas INFO Deleting /tmp/jblas29209775120479040

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.