Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JRuby port of NMatrix #558

Merged
merged 168 commits into from Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
168 commits
Select commit Hold shift + click to select a range
b11df50
created nmatrix_java directory structure and added rake tasks
prasunanand May 30, 2016
c96a0e7
dense and storage type of nmatrix
prasunanand May 30, 2016
f0dca82
NMatrix for arbitrary dimension double dtype using Apache CommonsMath
prasunanand May 30, 2016
086472d
test init
prasunanand May 30, 2016
b1a45ef
gitignore classes and jars
prasunanand May 31, 2016
163e393
jruby: frontend tasks running
prasunanand Oct 17, 2016
a5e0812
imported nmatrix.jar and 2 tests succeded
prasunanand May 31, 2016
ab51565
2Dnmatrix.jar and elementwise operations
prasunanand Jun 1, 2016
2de91f8
jruby: refactoring the code. nmatrix_java.rb is not in lib/nnatrix di…
prasunanand Jun 2, 2016
3876d1e
jruby: change java? method to jruby? and loading jars using nmatrix_j…
prasunanand Oct 17, 2016
6533e61
jruby: modified jnmatrix.java to store shape as an array and worked o…
prasunanand Jun 2, 2016
ffc392a
jruby: run tests and require_relative
prasunanand Oct 13, 2016
ff0af2f
jruby: modified initialize parameters for nmatrix shortcuts
prasunanand Oct 13, 2016
3ad7e0e
jruby: == operator implemented that checks whether two nmatrices are …
prasunanand Oct 13, 2016
b60390a
jruby: implemented add(+) operator for nmatrix
prasunanand Oct 13, 2016
3c75d97
jruby: implemented sin() unary operator using Univariate function
prasunanand Oct 13, 2016
504b0b5
jruby: elementwise operators functionality implemented except binary …
prasunanand Oct 13, 2016
3701e94
jruby: nmatrix indexing implemented for a single element position
prasunanand Oct 13, 2016
124ed72
jruby: [] for range slicing
prasunanand Oct 13, 2016
2c13eb5
jruby: Implemented [] for range
prasunanand Oct 13, 2016
c70da69
jruby: implemented []= operator
prasunanand Oct 13, 2016
8b02667
jruby: require_relative for tests
prasunanand Oct 13, 2016
8c50dd3
jruby: is_Symmetric implemented and twoDMatrix initialized when shape==2
prasunanand Jun 7, 2016
3a661a3
jruby: implemented det_exact and inverse of a matrix
prasunanand Oct 13, 2016
f371830
jruby: implemented matrix multiplication or dot()
prasunanand Oct 13, 2016
3e92110
jruby: all elementwise inequality operators implemented; return as ru…
prasunanand Oct 13, 2016
9421496
jruby: Block matrix for matrix multiplication and loop correction
prasunanand Jun 9, 2016
9a9e183
jruby: shape compatibility correction
prasunanand Jun 9, 2016
b318842
jruby:initialise of nmatrix changed to improve performance; addition,…
prasunanand Jun 14, 2016
e1b4406
jruby: performance=> inequality operators modified
prasunanand Jun 15, 2016
f6d772f
jruby: performance=> unary operators modified
prasunanand Jun 15, 2016
47b83c5
jruby: performance=> [] and []= implemented, range not supported
prasunanand Jun 15, 2016
041af32
jruby: performace => implemented dot for matrix and is_symmetric
prasunanand Jun 15, 2016
7cf35be
jruby: getting modular
prasunanand Jun 15, 2016
3cb4fc6
jruby: nrm2 and scale operator implemented
prasunanand Oct 13, 2016
917a689
jruby: correction of dense_each
prasunanand Oct 13, 2016
c9b92ab
jruby: dot dimension correction
prasunanand Jun 18, 2016
8394a4e
jruby: preety print implemented => shape initialisation for xslice re…
prasunanand Jun 18, 2016
4809d19
jruby: implemented factorize_lu, factorize_qr, potrf, ipiv and alias …
prasunanand Oct 13, 2016
ffcdc17
jruby: implemented factorize_cholesky and hermitian?
prasunanand Jun 19, 2016
676be2c
jruby: scale and scale! implemented
prasunanand Jun 19, 2016
bc23587
jruby: det_exact alias to det
prasunanand Jun 19, 2016
b0a0e78
jruby: inverse,invert and invert! implemented
prasunanand Jun 20, 2016
3858fdc
jruby: implemented each_stored_with_indices and adjugate/adjoint of a…
prasunanand Jun 20, 2016
6041be1
jruby: solve options
prasunanand Jun 20, 2016
b6e2cad
jruby: initialization when element is not an array
prasunanand Jun 20, 2016
c027279
jruby: entries of a nmatrix
prasunanand Oct 13, 2016
36e8e24
jruby: initialise dtype and stype
prasunanand Jun 21, 2016
ffb19e7
jruby: correct exception message
prasunanand Jun 21, 2016
9824951
jruby: test modify for jruby for [] method
prasunanand Oct 13, 2016
8575172
jruby: shape correction
prasunanand Jun 21, 2016
1b3ab41
jruby: __dense_each__ yields value
prasunanand Jun 21, 2016
49776a7
jruby: [] implemented for negative indeces
prasunanand Jun 21, 2016
bfb766c
jruby: diagonal operator implemented
prasunanand Jun 21, 2016
9036d91
jruby: block for __dense_each__ and transpose of a matrix
prasunanand Jun 21, 2016
9a92e6d
jruby: casting for jruby
prasunanand Jun 21, 2016
fbe0da9
jruby: []= implemented for range
prasunanand Jun 23, 2016
8e3df90
jruby: get_twoDArray helper
prasunanand Jun 24, 2016
cfeeb81
jruby: shape correction
prasunanand Jun 24, 2016
d4e2a13
jruby: return row as nmatrix
prasunanand Jun 24, 2016
21ab7f1
jruby: slice when :* as arg
prasunanand Jun 24, 2016
e712819
jruby: implemented cast full
prasunanand Jun 27, 2016
add3330
jruby: implemented supershape and offset
prasunanand Jun 27, 2016
75d5324
jruby: implemented reshape_bang and interpret_shape
prasunanand Jun 27, 2016
0695c04
jruby: enums=> yield if block_given?
prasunanand Jun 27, 2016
9542433
jruby: slices=> dense storage access by reference and get
prasunanand Jun 27, 2016
232faff
jruby: modularize slicing methods
prasunanand Jun 27, 2016
8b33fb1
jruby: return rows, cols and layers as nmatrix
prasunanand Jun 27, 2016
2d7052d
jruby: slice set when right arg is a nmatrix
prasunanand Jun 27, 2016
11684bd
jruby: singleton method guess dtype for nmatrix shortcuts
prasunanand Jun 27, 2016
e315006
jruby: elements array length bug
prasunanand Jun 27, 2016
a5f33ee
jruby: pretty print completely functional
prasunanand Jun 28, 2016
8fa9012
jruby: modularizing linear and binary math operators
prasunanand Jun 28, 2016
5ef7f7b
jruby: inject_rank shape duplication and add dimension for + operator
prasunanand Jun 28, 2016
90183da
jruby: add dimension for allmath operators
prasunanand Jun 28, 2016
2ab1a5b
jruby: implemented solve using LUDecomposition
prasunanand Jun 29, 2016
4dd57f7
jruby: implemented solve using CholeskyDecomposition
prasunanand Jun 29, 2016
079f3b9
jruby: solve when the rhs is of type n * p
prasunanand Jun 30, 2016
e99b161
jruby: correct NMatrix#solve
prasunanand Jul 25, 2016
a1ffe24
jruby: NMatrix#initialize for dtype = object
prasunanand Jul 25, 2016
71d1391
jruby: [], slice and xslice implemented for ruby objects
prasunanand Jul 25, 2016
6ea4b95
jruby: pretty print implemented for ruby objects
prasunanand Jul 25, 2016
f8bee86
jruby: #each_with_indices and #each_stored_with_indices implemented f…
prasunanand Jul 25, 2016
751d042
jruby: #elementwise_inequlity matrices return NMatrix
prasunanand Jul 25, 2016
b051372
jruby: #== implemented for ruby objects
prasunanand Jul 25, 2016
821754c
jruby: slicing by reference
prasunanand Jul 25, 2016
40b4e62
jruby: elementwise binary and unary operators don't modify the origin…
prasunanand Jul 25, 2016
3d7a1f2
jruby: Exponentiation NMatrix#** operator implemented
prasunanand Jul 26, 2016
893a817
jruby: NMatrix#clone implemented as @s.clone is private
prasunanand Jul 26, 2016
02b40d7
jruby: NMatrix equality method correction
prasunanand Jul 26, 2016
e59e1d3
jruby: implemented NMatrix#[]= for ruby objects
prasunanand Jul 26, 2016
84a2f4a
jruby: added ArrayGenerator and MatrixGenerator class for fast conver…
prasunanand Aug 3, 2016
e7a0b6d
jruby: covertArrayFloatFromDouble correction
prasunanand Aug 3, 2016
1867f9d
jruby: get Matrix from java method
prasunanand Aug 8, 2016
1972007
jruby: correct NMatrix#scale method
prasunanand Aug 8, 2016
66df67d
jruby: NMatrx#cast returns self
prasunanand Aug 8, 2016
09bcfa5
jruby: NMatrix#create_dummy_nmatrix, protected method
prasunanand Aug 8, 2016
9f2c138
jruby: NMatrix#atan2 implemented which takes two arguments
prasunanand Aug 8, 2016
def71a4
jruby: implemented log with arbitrary base
prasunanand Aug 9, 2016
32ac3a4
jruby: corrected matrix transpose and used java_method to store flat_…
prasunanand Aug 9, 2016
43775ea
jruby: stype accessor added
prasunanand Aug 9, 2016
1d208b8
jruby: check equality with delta = 1e-3
prasunanand Aug 9, 2016
0f28632
jruby: implemented erf and erfc operators
prasunanand Aug 9, 2016
3d32200
jruby: NMatrix#-@, elementwise negation and NMatrix#gamma implemented
prasunanand Aug 9, 2016
2b64e2d
jruby: round determinant to 3 decimal places
prasunanand Aug 9, 2016
1fdd310
jruby: potrf correction
prasunanand Aug 9, 2016
8ea115f
jruby: cholesky_factorization correction
prasunanand Aug 9, 2016
592c7e7
jruby: NMatrix#round implemented for double matrices
prasunanand Aug 9, 2016
edef600
jruby: implemented NMatrix#ldexp
prasunanand Aug 9, 2016
7399104
jruby: implemented NMatrix#hypot
prasunanand Aug 9, 2016
f8e20d6
jruby: hypot for scalar implemented
prasunanand Aug 10, 2016
3e1c5c6
jruby: NMatrix#hypot for scalar implemented
prasunanand Aug 10, 2016
af86ca8
jruby: NMatrix#hypot detects nmatrix or scalar when second argument n…
prasunanand Aug 10, 2016
570bd1d
jruby: NMatrix#ldexp detects nmatrix or scalar when second argument n…
prasunanand Aug 10, 2016
42cbed5
jruby: NMatrix#log default is natural log
prasunanand Aug 10, 2016
9d05e74
jruby: NMatrix#atan2 implemented
prasunanand Aug 10, 2016
c7fb093
jruby: NMatrix#atan2 implemented for scalar
prasunanand Aug 10, 2016
a4d14cc
jruby: dtype set to integer type when using Floor, ceil and round
prasunanand Aug 10, 2016
4f8f7f9
jruby: NMatrix#__dense_map__ implemented and qr_factorization set up …
prasunanand Aug 11, 2016
b04482d
jruby: Hessenberg Transformer not implemented currently
prasunanand Aug 11, 2016
3a8f502
jruby: cast in abs
prasunanand Aug 11, 2016
fce6d93
jruby: DataTypeError initialized
prasunanand Aug 11, 2016
7fe6d54
jruby: singleton methods min_dtype and upcast added
prasunanand Aug 11, 2016
091c594
NMatrix #solve correction for different options
prasunanand Aug 11, 2016
7d52167
jruby: move nmatrix_java.rb to lib/jruby/
prasunanand Aug 14, 2016
9822c2c
jruby: Remove java files which are not required
prasunanand Aug 14, 2016
d88fe1f
jruby: single-line format for class definitions with no body
prasunanand Aug 14, 2016
9cac5a9
jruby: rename lib/jruby/math.rb to operators.rb
prasunanand Aug 14, 2016
bb0cfda
jruby: separate jruby math logic from MRI
prasunanand Aug 14, 2016
911cb9c
jruby: load math.rb form nmatrix.rb instead of monkeys.rb
prasunanand Aug 14, 2016
9e38ad4
jruby: restore lib/nmatrix/math.rb to its original state
prasunanand Aug 14, 2016
b8321aa
jruby: change if-else to one-liner
prasunanand Aug 14, 2016
c04ba3c
jruby: Improve NMatrix#matrix_solve method
prasunanand Aug 15, 2016
8dfcab4
jruby: make exeception checking as one-liners
prasunanand Aug 15, 2016
1f13bf7
jruby: correct indentation
prasunanand Aug 15, 2016
717ce19
jruby: remove commented out code
prasunanand Aug 15, 2016
4b9d5a5
jruby: why create_dummy_matrix
prasunanand Aug 15, 2016
ed17445
jruby: create_dummy_matrix for NMatrix#methods
prasunanand Aug 17, 2016
128e0a4
jruby: chain dot result to java_method
prasunanand Aug 17, 2016
e9efaec
jruby: chain NMatrix#inverse result to java_method
prasunanand Aug 17, 2016
c0bddfb
jruby: chain NMatrix#qr_factorization and NMatrix#lu_factorization to…
prasunanand Aug 17, 2016
41da577
jruby: remove #get_oneDArray and #twoDArray
prasunanand Aug 17, 2016
c7698bf
jruby: rename twoDMat2 to twoDMat and change attribute accessor to me…
prasunanand Aug 17, 2016
766e1e5
jruby: correct exceptions to be raised
prasunanand Aug 17, 2016
f00d28f
jruby: remove unnecessary comments in nmatrix_jruby.rb
prasunanand Aug 18, 2016
215548d
jruby: comments in nmatrix_jruby and clean code
prasunanand Aug 18, 2016
b553f36
jruby: add Enumerable#sum supported by backports gem for MRI
prasunanand Aug 19, 2016
dc088a0
jruby_port: Add Readme
prasunanand Sep 14, 2016
871e060
Cleaned up JRuby instructions in README a bit
Sep 27, 2016
7780d0e
jruby_port: run rake tasks from project root directory
prasunanand Oct 13, 2016
787e74c
Merge remote-tracking branch 'upstream/master' into jruby_test_rebase
prasunanand Nov 21, 2016
803075f
jruby_port: make tests pending for 00_nmatrix_spec.rb
prasunanand Dec 13, 2016
291f293
jruby_port: make tests pending for 01_enum'_spec.rb
prasunanand Dec 13, 2016
455a975
jruby_port: make tests pending for 02_slice_spec.rb
prasunanand Dec 13, 2016
84e50e8
jruby_port: make tests pending for 03_nmatrix_monkeys_spec.rb
prasunanand Dec 13, 2016
eec5f23
jruby_port: make tests pending for elementwise_spec.rb
prasunanand Dec 13, 2016
f326962
jruby_port: make tests pending for homogeneous_spec.rb
prasunanand Dec 13, 2016
a674aac
jruby_port: make tests pending for io_spec.rb
prasunanand Dec 13, 2016
7324442
jruby_port: make tests pending for stat_spec.rb
prasunanand Dec 13, 2016
a3e0a81
jruby_port: make tests pending for slice_set_spec.rb
prasunanand Dec 13, 2016
cfd6c41
jruby_port: make tests pending for shortcuts_spec.rb
prasunanand Dec 13, 2016
f1ab4c9
jruby_port: make tests pending for rspec_spec.rb
prasunanand Dec 13, 2016
3f53f51
jruby_port: improve tests pending for math_spec.rb
prasunanand Dec 16, 2016
f446674
jruby_port: rake tests for jruby
prasunanand Dec 16, 2016
2e26cfc
jruby_port: correct math_spec
prasunanand Dec 16, 2016
78a3472
jruby_port: travis task for jruby
prasunanand Dec 17, 2016
4997f3c
jruby_port: travis script for jruby
prasunanand Dec 17, 2016
36a1cf5
jruby_port: test only for no external libs in JRuby
prasunanand Dec 24, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -27,3 +27,9 @@ doc/
docs/
pkg/
.autotest
ext/nmatrix_java/vendor/
ext/nmatrix_java/target/
ext/nmatrix_java/build/
ext/nmatrix_java/target/
*.class
*.jar
15 changes: 7 additions & 8 deletions .travis.yml
Expand Up @@ -20,7 +20,7 @@ rvm:
- 2.3.0-clang
- ruby-head-clang
# JRuby versions --- experimental, pending merging Prasun's GSoC project.
# - jruby-9.0.0.0 # earliest supported version (uncomment when jruby-head is passing)
- jruby-9.0.5.0 # earliest supported version (uncomment when jruby-head is passing)
- jruby-head # latest supported JRuby
# Make sure to add exclude lines for new JRuby versions below.

Expand All @@ -42,11 +42,12 @@ matrix:
env: USE_OPENBLAS=1
- rvm: jruby-head
env: USE_REF=1
#- rvm: jruby-9.0.0.0
# env:
# - USE_ATLAS=1
# - USE_OPENBLAS=1
# - USE_REF=1
- rvm: jruby-9.0.5.0
env: USE_ATLAS=1
- rvm: jruby-9.0.5.0
env: USE_OPENBLAS=1
- rvm: jruby-9.0.5.0
env: USE_REF=1
# NOTE: The following two ruby versions on OSX are currently unavailable
- os: osx
rvm: 2.0.0-p648
Expand Down Expand Up @@ -106,8 +107,6 @@ matrix:
- ruby_version=2.1.8 USE_OPENBLAS=1
allow_failures:
# trunk
- rvm: jruby-head
#- rvm: jruby-9.0.0.0
- rvm: ruby-head
- rvm: ruby-head-clang
- os: osx
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -62,6 +62,16 @@ $ rake spec
This will install all dependencies, compile the extension and run the
specs.

For **JRuby**

```bash
$ mkdir ext/nmatrix_java/vendor
Download commons_math.3.6.1 jar and place it in ext/nmatrix_java/vendor directory
$ mkdir -p ext/nmatrix_java/build/class
$ mkdir ext/nmatrix_java/target
$ rake jruby
```

If everything's fine until now, you can create a new branch to work on
your feature:

Expand Down
22 changes: 22 additions & 0 deletions README.rdoc
Expand Up @@ -67,6 +67,28 @@ To install:

bundle exec rake install

=== JRuby

First, you need to download Apache Commons Math 3.6.1 (the JAR, which
you can find in the binary package). For example, in the NMatrix
directory, do:

wget https://www.apache.org/dist/commons/math/binaries/commons-math3-3.6.1-bin.tar.gz
tar zxvf commons-math3-3.6.1-bin.tar.gz
mkdir ext/nmatrix_java/vendor/
cp commons-math3-3.6.1/commons-math3-3.6.1.jar ext/nmatrix_java/vendor/

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all these steps still required? It seems like this is already done by the rake task.

Also is this the standard way of dealing with Java libraries (just downloading them and sticking the jar in a random directory)? It seems a little unfortunate.

Are you planning to get this to work with a simple gem install?

Also, you should probably add a small note to the README, noting the limited features of the JRuby version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all these steps still required? It seems like this is already done by the rake task.
=> These steps are not done by rake task. And, a rake task can be added to achieve this.

Also is this the standard way of dealing with Java libraries (just downloading them and sticking the jar in a random directory)? It seems a little unfortunate.
=> AFAIK, this is the only way.

Are you planning to get this to work with a simple gem install?
=>Yes, It works with gem install

Also, you should probably add a small note to the README, noting the limited features of the JRuby version.
=>Sure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some error with json-version. I will correct it. I left it earlier, because there was no error with travis tests. So, I thought that the error was limited to my machine only.

Next, create build directories:

mkdir -p ext/nmatrix_java/build/class
mkdir ext/nmatrix_java/target

Finally, compile and package as jar.

rake jruby

=== Plugins

The commands above build and install only the core +nmatrix+ gem. If
you want to build one or more of the plugin gems (+nmatrix-atlas+,
+nmatrix-lapacke+) in addition to the core nmatrix gem, use the
Expand Down
91 changes: 74 additions & 17 deletions Rakefile
Expand Up @@ -73,6 +73,7 @@ namespace :spec do
gemspecs.each do |gemspec|
test_files = gemspec.test_files
test_files.keep_if { |file| file =~ /_spec\.rb$/ }
test_files -= ['spec/nmatrix_yale_spec.rb', 'spec/blas_spec.rb', 'spec/lapack_core_spec.rb'] if /java/ === RUBY_PLATFORM
next if test_files.empty?
spec_tasks << gemspec.name
RSpec::Core::RakeTask.new(gemspec.name) do |spec|
Expand Down Expand Up @@ -273,27 +274,83 @@ RDoc::Task.new do |rdoc|
rdoc.options << "--exclude=lib/nmatrix/rspec.rb"
end

namespace :travis do
task :env do
puts "\n# Build environment:"
%w[
CC CXX
USE_ATLAS USE_OPENBLAS USE_REF NO_EXTERNAL_LIB
TRAVIS_OS_NAME TRAVIS_BRANCH TRAVIS_COMMIT TRAVIS_PULL_REQUEST
].each do |name|
puts "- #{name}: #{ENV[name]}"
# jruby tasks

namespace :jruby do

PROJECT_DIR = File.expand_path(".",Dir.pwd)

BUILD_DIR = "build"
CLASSES_DIR = "../build/classes"
TEST_CLASSES_DIR = "build/testClasses"

JRUBY_DIR = "#{PROJECT_DIR}/ext/nmatrix_java"
VENDOR_DIR = "#{JRUBY_DIR}/vendor"
TARGET_DIR = "#{JRUBY_DIR}/target"

jars = Dir["#{VENDOR_DIR}/*.jar"]

desc 'Compile java classes'
task :javac do
unless RUBY_PLATFORM == 'java'
abort 'Please run with JRuby'
end
sh "mkdir -p #{JRUBY_DIR}/build/classes"
Dir.chdir("#{JRUBY_DIR}/nmatrix")
classes = Dir['**/*.java']
sh "javac -classpath #{jars.join(':')} -d #{CLASSES_DIR} #{classes.join(' ')}"
end

require 'rbconfig'
puts "\n# RbConfig::MAKEFILE_CONFIG values:"
%w[
CC CXX CPPFLAGS CFLAGS CXXFLAGS
].each do |name|
puts "- #{name}: #{RbConfig::MAKEFILE_CONFIG[name]}"
desc 'Package java classes in a jar file'
task :jar do
unless RUBY_PLATFORM == 'java'
abort 'Please run with JRuby'
end
sh "mkdir -p #{TARGET_DIR}"
Dir.chdir("#{JRUBY_DIR}/build/classes")
classes = Dir['**/*.class']
sh "jar -cf #{TARGET_DIR}/nmatrix.jar #{classes.join(' ')}"
end

cc = RbConfig::MAKEFILE_CONFIG['CC']
puts "\n$ #{cc} -v\n#{`#{cc} -v 2>&1`}"
task :all => [:javac, :jar]
end

desc "Compile java classes and Package them in a jar file"
task :jruby => 'jruby:all'

namespace :travis do
task :env do
if /java/ === RUBY_PLATFORM
puts "Building for jruby"
sh "mkdir ext/nmatrix_java/vendor"
puts "Downloading tar file."
sh "wget http://www-eu.apache.org/dist//commons/math/binaries/commons-math3-3.6.1-bin.tar.gz"
puts "Unzipping tar file."
sh "tar -zxf commons-math3-3.6.1-bin.tar.gz"
puts "Deleting tar file."
sh "rm commons-math3-3.6.1-bin.tar.gz"
sh "cp -r commons-math3-3.6.1/commons-math3-3.6.1.jar ext/nmatrix_java/vendor"
else
puts "\n# Build environment:"
%w[
CC CXX
USE_ATLAS USE_OPENBLAS USE_REF NO_EXTERNAL_LIB
TRAVIS_OS_NAME TRAVIS_BRANCH TRAVIS_COMMIT TRAVIS_PULL_REQUEST
].each do |name|
puts "- #{name}: #{ENV[name]}"
end

require 'rbconfig'
puts "\n# RbConfig::MAKEFILE_CONFIG values:"
%w[
CC CXX CPPFLAGS CFLAGS CXXFLAGS
].each do |name|
puts "- #{name}: #{RbConfig::MAKEFILE_CONFIG[name]}"
end

cc = RbConfig::MAKEFILE_CONFIG['CC']
puts "\n$ #{cc} -v\n#{`#{cc} -v 2>&1`}"
end
end
end

Expand Down
Empty file added ext/nmatrix_java/README.md
Empty file.
68 changes: 68 additions & 0 deletions ext/nmatrix_java/Rakefile
@@ -0,0 +1,68 @@
PROJECT_DIR = File.expand_path(".",Dir.pwd)
# puts PROJECT_DIR

BUILD_DIR = "build"
CLASSES_DIR = "../build/classes"
TEST_CLASSES_DIR = "build/testClasses"

VENDOR_DIR = "#{PROJECT_DIR}/vendor"
TARGET_DIR = "#{PROJECT_DIR}/target"
# puts VENDOR_DIR

jars = Dir["#{VENDOR_DIR}/*.jar"]
# puts jars

unless RUBY_PLATFORM == 'java'
abort 'Please run with JRuby'
end

#-----------------------------------------------------------------------------------------

desc 'Compile java classes'
task :javac do

Dir.chdir("nmatrix")
classes = Dir['**/*.java']
sh "javac -classpath #{jars.join(':')} -d #{CLASSES_DIR} #{classes.join(' ')}"
# sh "javac -d #{CLASSES_DIR} #{classes.join(' ')}"

end

#-----------------------------------------------------------------------------------------
desc 'Make jar file'
task :jar do

Dir.chdir("build/classes")
classes = Dir['**/*.class']
# p classes
sh "jar -cf #{TARGET_DIR}/nmatrix.jar #{classes.join(' ')}"

end

#-----------------------------------------------------------------------------------------


desc 'Compile test classes'
task :compileTest do

classes = Dir['**/*.java']
sh "javac -classpath #{jars.join(':')} -d #{TEST_CLASSES_DIR} #{classes.join(' ')}"
# sh "javac -d #{CLASSES_DIR} #{classes.join(' ')}"

end

#-----------------------------------------------------------------------------------------

desc 'Run junit tests'
task :test do

Dir.chdir("build/classes")
classes = Dir['**/*.class']
# p classes
sh "javac -classpath #{TARGET_DIR}/nmatrix.jar -d #{classes.join(' ')}"

end

#-----------------------------------------------------------------------------------------

task :default => :javac
Empty file.
111 changes: 111 additions & 0 deletions ext/nmatrix_java/nmatrix/math/MathHelper.java
@@ -0,0 +1,111 @@
import org.apache.commons.math3.util.FastMath;
import org.apache.commons.math3.special.Erf;
import org.apache.commons.math3.special.Gamma;

public class MathHelper{

public static double[] log(double base, double[] arr){
double[] result = new double[arr.length];
for(int i = 0; i< arr.length; i++){
result[i] = FastMath.log(base, arr[i]);
}
return result;
}

public static double[] erf(double[] arr){
double[] result = new double[arr.length];
for(int i = 0; i< arr.length; i++){
result[i] = Erf.erf(arr[i]);
}
return result;
}

public static double[] erfc(double[] arr){
double[] result = new double[arr.length];
for(int i = 0; i< arr.length; i++){
result[i] = Erf.erfc(arr[i]);
}
return result;
}

public static double[] gamma(double[] arr){
double[] result = new double[arr.length];
for(int i = 0; i< arr.length; i++){
result[i] = Gamma.gamma(arr[i]);
}
return result;
}

public static double[] round(double[] arr){
double[] result = new double[arr.length];
for(int i = 0; i< arr.length; i++){
result[i] = Math.round(arr[i]);
}
return result;
}

public static double[] ldexp(double[] arr1, double[] arr){
double[] result = new double[arr1.length];
for(int i = 0; i< arr1.length; i++){
result[i] = arr1[i] * Math.pow(2, arr[i]);
}
return result;
}

public static double[] ldexpScalar(double val, double[] arr){
double[] result = new double[arr.length];
for(int i = 0; i< arr.length; i++){
result[i] = val * Math.pow(2, arr[i]);
}
return result;
}

public static double[] ldexpScalar2(double val, double[] arr){
double[] result = new double[arr.length];
for(int i = 0; i< arr.length; i++){
result[i] = arr[i] * Math.pow(2, val);
}
return result;
}

public static double[] hypot(double[] arr1, double[] arr2){
double[] result = new double[arr1.length];
for(int i = 0; i< arr1.length; i++){
result[i] = Math.sqrt(arr2[i] * arr2[i] + arr1[i] * arr1[i]);
}
return result;
}

public static double[] hypotScalar(double val, double[] arr){
double[] result = new double[arr.length];
for(int i = 0; i< arr.length; i++){
result[i] = Math.sqrt(arr[i] * arr[i] + val * val);
}
return result;
}

public static double[] atan2(double[] arr1, double[] arr2){
double[] result = new double[arr1.length];
for(int i = 0; i< arr1.length; i++){
result[i] = Math.atan2(arr2[i], arr1[i]);
}
return result;
}

public static double[] atan2Scalar(double val, double[] arr){
double[] result = new double[arr.length];
for(int i = 0; i< arr.length; i++){
result[i] = Math.atan2(val, arr[i]);
}
return result;
}

public static double[] atan2Scalar2(double val, double[] arr){
double[] result = new double[arr.length];
for(int i = 0; i< arr.length; i++){
result[i] = Math.atan2(arr[i], val);
}
return result;
}

}