scicom 0.2.2-java → 0.2.3-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -5
- data/config.rb +1 -1
- data/lib/JRubyR/rbsexp.rb +3 -55
- data/lib/JRubyR/renjin.rb +55 -31
- data/lib/JRubyR/ruby_classes.rb +7 -0
- data/lib/JRubyR/vector.rb +17 -0
- data/target/helper.jar +0 -0
- data/test/env.rb +1 -6
- data/test/test_R_interface.rb +1 -0
- data/test/test_assign_mdarray.rb +128 -0
- data/test/test_assign_mdarray_2d.rb +162 -0
- data/test/test_assign_mdarray_3d.rb +201 -0
- data/{lib/JRubyR/sequence.rb → test/test_assign_mdarray_4d.rb} +38 -24
- data/test/test_complete.rb +4 -1
- data/test/test_dataframe.rb +2 -5
- data/test/test_double_receive.rb +0 -4
- data/test/test_linear_model.rb +2 -2
- data/test/test_matrix.rb +10 -14
- data/version.rb +1 -1
- metadata +10 -8
- data/lib/JRubyR/as_mdarray.rb +0 -60
- data/lib/JRubyR/index.rb +0 -278
- data/lib/JRubyR/list_orig.rb +0 -111
- data/test/test_double_assign.rb +0 -240
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aef59cac8c877c6ed3e85aba23bf0157f51212a
|
4
|
+
data.tar.gz: f319a45282a3ca6639a0af0ac5dd9d9166298a3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ebfea9adeb89cd56730b443f15698b7787877f9c5503354750f558e68fc3942701f385d3eb9d07b05e7fde9ec118451394c4cfb60b873260de091f8bd7f5aa6
|
7
|
+
data.tar.gz: f5596e54636c345a2d1d7f10abf6e7284d5923611d693f93d1fd808ee0c09e7320d8c8bf623936ff4bf3b9a1bb664aae7744d186dd69bf2b9f6e0beb7df34330
|
data/README.md
CHANGED
@@ -41,7 +41,12 @@ Renjin is in development and still has some limitations
|
|
41
41
|
hope that this limitation will be solved not by implementing those libraries but by the
|
42
42
|
use of Ruby libraries from SciRuby such as NyaPlot (https://github.com/domitry/nyaplot)
|
43
43
|
or daru (https://github.com/v0dro/daru).
|
44
|
-
|
44
|
+
|
45
|
+
What´s new:
|
46
|
+
===========
|
47
|
+
|
48
|
+
This version includes integration of MDArray and SciCom.
|
49
|
+
|
45
50
|
|
46
51
|
SciCom installation and download:
|
47
52
|
==================================
|
@@ -62,7 +67,8 @@ Contributors are welcome.
|
|
62
67
|
SciCom History:
|
63
68
|
================
|
64
69
|
|
65
|
-
+
|
66
|
-
+
|
67
|
-
+ 17/
|
68
|
-
+
|
70
|
+
+ 30/Dec/2014: Version 0.2.3 - Integration with MDArray
|
71
|
+
+ 19/Nov/2014: Version 0.2.2 - Printing in Jirb
|
72
|
+
+ 17/Nov/2014: Version 0.2.1 - Added MDArray dependency
|
73
|
+
+ 17/Nov/2014: Version 0.2.0 - Most R functionality available to SciCom
|
74
|
+
+ 21/Jul/2014: Version 0.0.1 - Initial release
|
data/config.rb
CHANGED
data/lib/JRubyR/rbsexp.rb
CHANGED
@@ -222,8 +222,8 @@ class Renjin
|
|
222
222
|
#----------------------------------------------------------------------------------------
|
223
223
|
|
224
224
|
def print
|
225
|
-
Kernel.print(Java::OrgRenjinPrimitives::Print.doPrint(sexp))
|
226
|
-
|
225
|
+
# Kernel.print(Java::OrgRenjinPrimitives::Print.doPrint(sexp))
|
226
|
+
R.eval("print(#{r})")
|
227
227
|
end
|
228
228
|
|
229
229
|
#----------------------------------------------------------------------------------------
|
@@ -254,14 +254,6 @@ class Renjin
|
|
254
254
|
|
255
255
|
end
|
256
256
|
|
257
|
-
#==========================================================================================
|
258
|
-
# Make a Ruby Array into a RBSexp
|
259
|
-
#==========================================================================================
|
260
|
-
|
261
|
-
class Array
|
262
|
-
include Renjin::RBSexp
|
263
|
-
end
|
264
|
-
|
265
257
|
#==========================================================================================
|
266
258
|
#
|
267
259
|
#==========================================================================================
|
@@ -305,9 +297,7 @@ class Renjin
|
|
305
297
|
|
306
298
|
def self.build(sexp)
|
307
299
|
|
308
|
-
if (sexp.instance_of? Java::
|
309
|
-
res = Renjin::Sequence.new(sexp)
|
310
|
-
elsif (sexp.instance_of? Java::OrgRenjinSexp::Null)
|
300
|
+
if (sexp.instance_of? Java::OrgRenjinSexp::Null)
|
311
301
|
res = nil
|
312
302
|
elsif (sexp.instance_of? Java::OrgRenjinSexp::ListVector)
|
313
303
|
res = Renjin::List.new(sexp)
|
@@ -339,49 +329,7 @@ end
|
|
339
329
|
|
340
330
|
require_relative 'ruby_classes'
|
341
331
|
require_relative 'vector'
|
342
|
-
require_relative 'sequence'
|
343
332
|
require_relative 'list'
|
344
333
|
require_relative 'function'
|
345
334
|
require_relative 'logical_value'
|
346
335
|
require_relative 'environment'
|
347
|
-
|
348
|
-
|
349
|
-
=begin
|
350
|
-
#----------------------------------------------------------------------------------------
|
351
|
-
#
|
352
|
-
#----------------------------------------------------------------------------------------
|
353
|
-
|
354
|
-
def set_sexp(sexp)
|
355
|
-
@sexp = sexp
|
356
|
-
end
|
357
|
-
|
358
|
-
#----------------------------------------------------------------------------------------
|
359
|
-
#
|
360
|
-
#----------------------------------------------------------------------------------------
|
361
|
-
|
362
|
-
def method_missing(symbol, *args)
|
363
|
-
|
364
|
-
name = symbol.id2name
|
365
|
-
name.gsub!(/__/,".")
|
366
|
-
|
367
|
-
# super if args.length != 0
|
368
|
-
if name =~ /(.*)=$/
|
369
|
-
super if args.length != 1
|
370
|
-
args = R.parse(*args)
|
371
|
-
ret = R.eval("#{r}[[\"#{name}\"]] = #{args}")
|
372
|
-
elsif (args.length == 0)
|
373
|
-
# treat name as a named item of the list
|
374
|
-
ret = R.eval("#{r}[[\"#{name}\"]]")
|
375
|
-
elsif (name == "_")
|
376
|
-
method = "%#{args.shift.to_s}%"
|
377
|
-
arg2 = R.parse(*args)
|
378
|
-
ret = R.eval("#{r} #{method} #{arg2}")
|
379
|
-
else
|
380
|
-
raise "Illegal argument for named list item #{name}"
|
381
|
-
end
|
382
|
-
|
383
|
-
ret
|
384
|
-
|
385
|
-
end
|
386
|
-
|
387
|
-
=end
|
data/lib/JRubyR/renjin.rb
CHANGED
@@ -25,7 +25,16 @@ require 'java'
|
|
25
25
|
require 'securerandom'
|
26
26
|
|
27
27
|
require_relative 'rbsexp'
|
28
|
-
require_relative 'index'
|
28
|
+
# require_relative 'index'
|
29
|
+
|
30
|
+
|
31
|
+
#==========================================================================================
|
32
|
+
#
|
33
|
+
#==========================================================================================
|
34
|
+
|
35
|
+
class Java::RbScicom::MDDoubleVector
|
36
|
+
field_reader :_array
|
37
|
+
end
|
29
38
|
|
30
39
|
|
31
40
|
#==========================================================================================
|
@@ -91,22 +100,6 @@ class Renjin
|
|
91
100
|
|
92
101
|
end
|
93
102
|
|
94
|
-
#----------------------------------------------------------------------------------------
|
95
|
-
# Converts an MDArray shape or index onto an equivalent R shape or index
|
96
|
-
#----------------------------------------------------------------------------------------
|
97
|
-
|
98
|
-
def ri(shape)
|
99
|
-
|
100
|
-
rshape = shape.clone
|
101
|
-
|
102
|
-
if (rshape.size > 2)
|
103
|
-
rshape.reverse!
|
104
|
-
rshape[0], rshape[1] = rshape[1], rshape[0]
|
105
|
-
end
|
106
|
-
rshape.map{ |val| (val + 1) }
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
103
|
#----------------------------------------------------------------------------------------
|
111
104
|
#
|
112
105
|
#----------------------------------------------------------------------------------------
|
@@ -171,33 +164,38 @@ class Renjin
|
|
171
164
|
#----------------------------------------------------------------------------------------
|
172
165
|
|
173
166
|
def pi
|
174
|
-
|
167
|
+
eval("pi")
|
175
168
|
end
|
176
169
|
|
177
170
|
def LETTERS
|
178
|
-
|
171
|
+
eval("LETTERS")
|
179
172
|
end
|
180
173
|
|
181
174
|
def letters
|
182
|
-
|
175
|
+
eval("letters")
|
183
176
|
end
|
184
177
|
|
185
178
|
def month__abb
|
186
|
-
|
179
|
+
eval("month.abb")
|
187
180
|
end
|
188
181
|
|
189
182
|
def month__name
|
190
|
-
|
183
|
+
eval("month.name")
|
191
184
|
end
|
192
185
|
|
193
186
|
def i(value)
|
194
|
-
|
187
|
+
eval("#{value}L")
|
195
188
|
end
|
196
189
|
|
197
190
|
def d(value)
|
198
|
-
|
191
|
+
eval("#{value}")
|
192
|
+
end
|
193
|
+
|
194
|
+
def md(value)
|
195
|
+
Renjin::Vector.new(build_vector(value))
|
199
196
|
end
|
200
197
|
|
198
|
+
|
201
199
|
#----------------------------------------------------------------------------------------
|
202
200
|
#
|
203
201
|
#----------------------------------------------------------------------------------------
|
@@ -385,23 +383,31 @@ class Renjin
|
|
385
383
|
params = function[:params]
|
386
384
|
function = function[:f]
|
387
385
|
if (index)
|
388
|
-
|
386
|
+
eval("#{function.to_s}(#{sexp.r})#{index} = #{value.r}")
|
389
387
|
else
|
390
388
|
end
|
391
389
|
else
|
392
|
-
|
390
|
+
eval("#{function.to_s}(#{sexp.r}) = #{value.r}")
|
393
391
|
end
|
394
392
|
|
393
|
+
sexp
|
394
|
+
|
395
395
|
end
|
396
396
|
|
397
|
+
#----------------------------------------------------------------------------------------
|
398
|
+
# Builds a Renjin vector from an MDArray. Should be private, but public for testing.
|
399
|
+
#----------------------------------------------------------------------------------------
|
400
|
+
|
401
|
+
# private
|
402
|
+
|
397
403
|
#----------------------------------------------------------------------------------------
|
398
404
|
# Builds a Renjin vector from an MDArray. Should be private, but public for testing.
|
399
405
|
#----------------------------------------------------------------------------------------
|
400
406
|
|
401
|
-
def build_vector(
|
407
|
+
def build_vector(mdarray)
|
402
408
|
|
403
|
-
shape =
|
404
|
-
index =
|
409
|
+
shape = mdarray.shape
|
410
|
+
# index = mdarray.nc_array.getIndex()
|
405
411
|
# index = MDArray.index_factory(shape)
|
406
412
|
# representation of shape in R is different from shape in MDArray. Convert MDArray
|
407
413
|
# shape to R shape.
|
@@ -409,12 +415,30 @@ class Renjin
|
|
409
415
|
shape.reverse!
|
410
416
|
shape[0], shape[1] = shape[1], shape[0]
|
411
417
|
end
|
418
|
+
|
412
419
|
# AttributeMap attributes = AttributeMap.builder().setDim(new IntVector(dim)).build();
|
413
420
|
attributes = Java::OrgRenjinSexp::AttributeMap.builder()
|
414
421
|
.setDim(Java::OrgRenjinSexp::IntArrayVector.new(*(shape))).build()
|
415
|
-
|
416
|
-
|
422
|
+
|
423
|
+
# vector = Java::RbScicom::MDDoubleVector.new(mdarray.nc_array, attributes, index,
|
424
|
+
# index.stride)
|
417
425
|
|
426
|
+
case mdarray.type
|
427
|
+
when "int"
|
428
|
+
vector = Java::RbScicom::MDIntVector.factory(mdarray.nc_array, attributes)
|
429
|
+
when "double"
|
430
|
+
vector = Java::RbScicom::MDDoubleVector.factory(mdarray.nc_array, attributes)
|
431
|
+
when "byte"
|
432
|
+
vector = Java::RbScicom::MDLogicalVector.factory(mdarray.nc_array, attributes)
|
433
|
+
when "string"
|
434
|
+
vector = Java::RbScicom::MDStringVector.factory(mdarray.nc_array, attributes)
|
435
|
+
when "boolean"
|
436
|
+
raise "Boolean vectors cannot be converted to R vectors. If you are trying to \
|
437
|
+
convert to an R Logical object, use a :byte MDArray"
|
438
|
+
else
|
439
|
+
raise "Cannot convert MDArray #{mdarray.type} to R vector"
|
440
|
+
end
|
441
|
+
|
418
442
|
end
|
419
443
|
|
420
444
|
|
data/lib/JRubyR/ruby_classes.rb
CHANGED
@@ -54,5 +54,12 @@ end
|
|
54
54
|
|
55
55
|
class Array
|
56
56
|
include Renjin::RBSexp
|
57
|
+
end
|
58
|
+
|
59
|
+
#==========================================================================================
|
60
|
+
#
|
61
|
+
#==========================================================================================
|
57
62
|
|
63
|
+
class MDArray
|
64
|
+
include Renjin::RBSexp
|
58
65
|
end
|
data/lib/JRubyR/vector.rb
CHANGED
@@ -192,6 +192,23 @@ class Renjin
|
|
192
192
|
|
193
193
|
end
|
194
194
|
|
195
|
+
#----------------------------------------------------------------------------------------
|
196
|
+
# Converts an MDArray shape or index onto an equivalent R shape or index
|
197
|
+
#----------------------------------------------------------------------------------------
|
198
|
+
|
199
|
+
def ri(*shape)
|
200
|
+
|
201
|
+
rshape = shape.clone
|
202
|
+
|
203
|
+
if (rshape.size > 2)
|
204
|
+
rshape.reverse!
|
205
|
+
rshape[0], rshape[1] = rshape[1], rshape[0]
|
206
|
+
end
|
207
|
+
rshape.map!{ |val| (val + 1) }
|
208
|
+
self[*rshape]
|
209
|
+
|
210
|
+
end
|
211
|
+
|
195
212
|
#----------------------------------------------------------------------------------------
|
196
213
|
#
|
197
214
|
#----------------------------------------------------------------------------------------
|
data/target/helper.jar
CHANGED
Binary file
|
data/test/env.rb
CHANGED
data/test/test_R_interface.rb
CHANGED
@@ -73,6 +73,7 @@ class SciComTest < Test::Unit::TestCase
|
|
73
73
|
# Using method assign, to assign NULL to variable 'null' in R namespace.
|
74
74
|
R.assign("null", nil)
|
75
75
|
assert_equal(nil, R.null)
|
76
|
+
R.eval("print(null)")
|
76
77
|
|
77
78
|
# Variable 'res' is available only in the Ruby namespace and not in the R namespace.
|
78
79
|
# a NULL object in R is converted to nil in Ruby.
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
##########################################################################################
|
4
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
5
|
+
# and distribute this software and its documentation, without fee and without a signed
|
6
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
7
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
8
|
+
# distributions.
|
9
|
+
#
|
10
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
11
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
12
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
13
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
#
|
15
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
16
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
17
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
18
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
19
|
+
# OR MODIFICATIONS.
|
20
|
+
##########################################################################################
|
21
|
+
|
22
|
+
require 'rubygems'
|
23
|
+
require 'test/unit'
|
24
|
+
require 'shoulda'
|
25
|
+
require 'benchmark'
|
26
|
+
|
27
|
+
require 'env'
|
28
|
+
require 'scicom'
|
29
|
+
|
30
|
+
class SciComTest < Test::Unit::TestCase
|
31
|
+
|
32
|
+
context "R environment" do
|
33
|
+
|
34
|
+
#--------------------------------------------------------------------------------------
|
35
|
+
#
|
36
|
+
#--------------------------------------------------------------------------------------
|
37
|
+
|
38
|
+
setup do
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
#--------------------------------------------------------------------------------------
|
43
|
+
#
|
44
|
+
#--------------------------------------------------------------------------------------
|
45
|
+
|
46
|
+
should "convert MDArrays to R arrays" do
|
47
|
+
|
48
|
+
#--------------------------------------------------------------------------------------
|
49
|
+
#
|
50
|
+
#--------------------------------------------------------------------------------------
|
51
|
+
|
52
|
+
def to_r(dim, type)
|
53
|
+
|
54
|
+
dims = Array.new
|
55
|
+
(0...dim).each do |s|
|
56
|
+
dims[s] = rand(1..8)
|
57
|
+
end
|
58
|
+
|
59
|
+
p "converting MDArray of shape #{dims} and type #{type} to R array"
|
60
|
+
|
61
|
+
case type
|
62
|
+
when :byte
|
63
|
+
arr1 = MDArray.byte(dims)
|
64
|
+
when :rstring
|
65
|
+
arr1 = MDArray.init_with("rstring", dims, "this is a string")
|
66
|
+
else
|
67
|
+
arr1 = MDArray.typed_arange(type.to_s, dims.inject(:*))
|
68
|
+
end
|
69
|
+
|
70
|
+
arr1.reshape!(dims)
|
71
|
+
|
72
|
+
# convert to an R matrix
|
73
|
+
r_matrix = R.md(arr1)
|
74
|
+
|
75
|
+
# only compare all elements if array size is less than 5. For larger arrays this will take
|
76
|
+
# too much time.
|
77
|
+
if (dims.size < 6)
|
78
|
+
# A byte MDArray is converted to a Logical vector in R. Boolean MDArrays cannot be
|
79
|
+
# converted to logical vectors efficiently in Renjin.
|
80
|
+
compare = MDArray.byte(dims)
|
81
|
+
|
82
|
+
# In order to simplify access to the R vector with different dimension specification
|
83
|
+
# SciCom implements method 'ri' (r-indexing), so that arr1[dim1, dim2, dim3] is
|
84
|
+
# equal to r_matrix.ri(dim1, dim2, dim3)
|
85
|
+
arr1.get_index.each do |ct|
|
86
|
+
compare[*ct] = (arr1[*ct] == (r_matrix.ri(*ct).gz))? 1 : 0
|
87
|
+
end
|
88
|
+
|
89
|
+
# Convert the byte MDArray to an R vector.
|
90
|
+
comp = R.md(compare)
|
91
|
+
# use the .all method from R to verify that all elements in the vector all TRUE
|
92
|
+
assert_equal(true, comp.all.gt)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
#--------------------------------------------------------------------------------------
|
98
|
+
# Check conversion of 5 different arrays for dimensions from 1 to 7 (which are
|
99
|
+
# optimized) and also for 8 to 10 dimensions (that are not optimized)
|
100
|
+
#--------------------------------------------------------------------------------------
|
101
|
+
|
102
|
+
|
103
|
+
[:char, :long, :float].each do |type|
|
104
|
+
# convert to an R matrix
|
105
|
+
arr1 = MDArray.build(type, [2])
|
106
|
+
assert_raise ( RuntimeError ) { r_matrix = R.md(arr1) }
|
107
|
+
end
|
108
|
+
|
109
|
+
#--------------------------------------------------------------------------------------
|
110
|
+
# Check conversion of 5 different arrays for dimensions from 1 to 7 (which are
|
111
|
+
# optimized) and also for 8 to 10 dimensions (that are not optimized)
|
112
|
+
#--------------------------------------------------------------------------------------
|
113
|
+
|
114
|
+
#
|
115
|
+
|
116
|
+
[:byte, :int, :double, :rstring].each do |type|
|
117
|
+
(1..9).each do |dim|
|
118
|
+
(0...2).each do
|
119
|
+
to_r(dim, type)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|