scicom 0.2.0-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 +7 -0
- data/LICENSE.txt +674 -0
- data/README.md +66 -0
- data/README.md~ +290 -0
- data/Rakefile +51 -0
- data/config.rb +163 -0
- data/doc/PypeR.pdf +0 -0
- data/doc/Stat 133 Class Notes (Phil Spector).pdf +29905 -45
- data/doc/The R interface.docx +0 -0
- data/lib/JRubyR/as_mdarray.rb +60 -0
- data/lib/JRubyR/attributes.rb +74 -0
- data/lib/JRubyR/dataframe.rb +35 -0
- data/lib/JRubyR/environment.rb +60 -0
- data/lib/JRubyR/function.rb +61 -0
- data/lib/JRubyR/index.rb +278 -0
- data/lib/JRubyR/list.rb +56 -0
- data/lib/JRubyR/list_orig.rb +111 -0
- data/lib/JRubyR/logical_value.rb +56 -0
- data/lib/JRubyR/rbsexp.rb +386 -0
- data/lib/JRubyR/renjin.rb +431 -0
- data/lib/JRubyR/ruby_classes.rb +58 -0
- data/lib/JRubyR/sequence.rb +56 -0
- data/lib/JRubyR/vector.rb +493 -0
- data/lib/env.rb +12 -0
- data/lib/rinruby.rb +795 -0
- data/lib/scicom.rb +29 -0
- data/target/helper.jar +0 -0
- data/test/baseball.csv +1 -0
- data/test/env.rb +7 -0
- data/test/test_R_interface.rb +165 -0
- data/test/test_array.rb +191 -0
- data/test/test_attributes.rb +261 -0
- data/test/test_basic.rb +156 -0
- data/test/test_column-major.rb +114 -0
- data/test/test_complete.rb +49 -0
- data/test/test_creation.rb +299 -0
- data/test/test_dataframe.rb +248 -0
- data/test/test_distribution.rb +320 -0
- data/test/test_double_assign.rb +240 -0
- data/test/test_double_receive.rb +106 -0
- data/test/test_environment.rb +57 -0
- data/test/test_factor.rb +285 -0
- data/test/test_functions.rb +67 -0
- data/test/test_linear_model.rb +64 -0
- data/test/test_list.rb +220 -0
- data/test/test_matrix.rb +205 -0
- data/test/test_mdarray.rb +258 -0
- data/test/test_operators.rb +227 -0
- data/test/test_sequence.rb +63 -0
- data/test/test_subsetting.rb +67 -0
- data/test/test_tmp.rb +67 -0
- data/test/test_vector.rb +227 -0
- data/vendor/Renjin.pdf +0 -0
- data/vendor/renjin-script-engine-0.7.0-RC7-SNAPSHOT-jar-with-dependencies.jar +0 -0
- data/version.rb +2 -0
- metadata +196 -0
Binary file
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
##########################################################################################
|
4
|
+
# @author Rodrigo Botafogo
|
5
|
+
#
|
6
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
7
|
+
# and distribute this software and its documentation, without fee and without a signed
|
8
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
9
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
10
|
+
# distributions.
|
11
|
+
#
|
12
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
13
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
14
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
15
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
16
|
+
#
|
17
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
18
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
19
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
20
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
21
|
+
# OR MODIFICATIONS.
|
22
|
+
##########################################################################################
|
23
|
+
|
24
|
+
|
25
|
+
###########################################################################################
|
26
|
+
#
|
27
|
+
###########################################################################################
|
28
|
+
|
29
|
+
class MDArray
|
30
|
+
|
31
|
+
#----------------------------------------------------------------------------------------
|
32
|
+
#
|
33
|
+
#----------------------------------------------------------------------------------------
|
34
|
+
|
35
|
+
def z
|
36
|
+
self[0]
|
37
|
+
end
|
38
|
+
|
39
|
+
#----------------------------------------------------------------------------------------
|
40
|
+
#
|
41
|
+
#----------------------------------------------------------------------------------------
|
42
|
+
|
43
|
+
def pp
|
44
|
+
print
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
###########################################################################################
|
50
|
+
#
|
51
|
+
###########################################################################################
|
52
|
+
|
53
|
+
class Renjin
|
54
|
+
|
55
|
+
class Vector
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
##########################################################################################
|
4
|
+
# @author Rodrigo Botafogo
|
5
|
+
#
|
6
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
7
|
+
# and distribute this software and its documentation, without fee and without a signed
|
8
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
9
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
10
|
+
# distributions.
|
11
|
+
#
|
12
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
13
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
14
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
15
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
16
|
+
#
|
17
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
18
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
19
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
20
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
21
|
+
# OR MODIFICATIONS.
|
22
|
+
##########################################################################################
|
23
|
+
|
24
|
+
#==========================================================================================
|
25
|
+
#
|
26
|
+
#==========================================================================================
|
27
|
+
|
28
|
+
class Renjin
|
29
|
+
|
30
|
+
class Attributes
|
31
|
+
|
32
|
+
attr_reader :rbsexp
|
33
|
+
|
34
|
+
#----------------------------------------------------------------------------------------
|
35
|
+
#
|
36
|
+
#----------------------------------------------------------------------------------------
|
37
|
+
|
38
|
+
def initialize(rbsexp)
|
39
|
+
@rbsexp = rbsexp
|
40
|
+
end
|
41
|
+
|
42
|
+
#----------------------------------------------------------------------------------------
|
43
|
+
#
|
44
|
+
#----------------------------------------------------------------------------------------
|
45
|
+
|
46
|
+
def method_missing(symbol, *args)
|
47
|
+
|
48
|
+
name = symbol.id2name
|
49
|
+
name.sub!(/__/,".")
|
50
|
+
# Method 'rclass' is a substitute for R method 'class'. Needed, as 'class' is also
|
51
|
+
# a Ruby method on an object
|
52
|
+
name.gsub!("rclass", "class")
|
53
|
+
|
54
|
+
if name =~ /(.*)=$/
|
55
|
+
super if args.length != 1
|
56
|
+
args = R.parse(*args)
|
57
|
+
ret = R.eval("attr(#{@rbsexp.r}, \"#{name.delete!('=')}\") = #{args}")
|
58
|
+
else
|
59
|
+
if (args.length == 0)
|
60
|
+
# p "retrieving attribute: #{name}"
|
61
|
+
ret = R.eval("attr(#{@rbsexp.r}, \"#{name}\")")
|
62
|
+
ret.scope = ["attr", @rbsexp, name]
|
63
|
+
else
|
64
|
+
raise "An attribute cannot have parameters"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
ret
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
##########################################################################################
|
4
|
+
# @author Rodrigo Botafogo
|
5
|
+
#
|
6
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
7
|
+
# and distribute this software and its documentation, without fee and without a signed
|
8
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
9
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
10
|
+
# distributions.
|
11
|
+
#
|
12
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
13
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
14
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
15
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
16
|
+
#
|
17
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
18
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
19
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
20
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
21
|
+
# OR MODIFICATIONS.
|
22
|
+
##########################################################################################
|
23
|
+
|
24
|
+
class Renjin
|
25
|
+
|
26
|
+
class DataFrame < Renjin::List
|
27
|
+
|
28
|
+
def colnames(names)
|
29
|
+
R.eval("colnames(#{r}) = c(#{names})")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
##########################################################################################
|
4
|
+
# @author Rodrigo Botafogo
|
5
|
+
#
|
6
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
7
|
+
# and distribute this software and its documentation, without fee and without a signed
|
8
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
9
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
10
|
+
# distributions.
|
11
|
+
#
|
12
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
13
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
14
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
15
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
16
|
+
#
|
17
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
18
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
19
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
20
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
21
|
+
# OR MODIFICATIONS.
|
22
|
+
##########################################################################################
|
23
|
+
|
24
|
+
|
25
|
+
class Renjin
|
26
|
+
|
27
|
+
class Environment < Renjin::RubySexp
|
28
|
+
|
29
|
+
#----------------------------------------------------------------------------------------
|
30
|
+
#
|
31
|
+
#----------------------------------------------------------------------------------------
|
32
|
+
|
33
|
+
def method_missing(symbol, *args)
|
34
|
+
|
35
|
+
name = symbol.id2name
|
36
|
+
if name =~ /(.*)=$/
|
37
|
+
# should never reach this point. Parse error... but check
|
38
|
+
raise ArgumentError, "You shouldn't assign nil" if args==[nil]
|
39
|
+
super if args.length != 1
|
40
|
+
ret = R.assign($1,args[0])
|
41
|
+
else
|
42
|
+
name.gsub!(/__/,".")
|
43
|
+
# super if args.length != 0
|
44
|
+
if (args.length == 0)
|
45
|
+
# treat the argument as a named item of the list
|
46
|
+
ret = Renjin::RubySexp.build(@sexp.getVariable(name))
|
47
|
+
else
|
48
|
+
params = parse(*args)
|
49
|
+
ret = eval("#{name}(#{params})")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
ret
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
##########################################################################################
|
4
|
+
# @author Rodrigo Botafogo
|
5
|
+
#
|
6
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
7
|
+
# and distribute this software and its documentation, without fee and without a signed
|
8
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
9
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
10
|
+
# distributions.
|
11
|
+
#
|
12
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
13
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
14
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
15
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
16
|
+
#
|
17
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
18
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
19
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
20
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
21
|
+
# OR MODIFICATIONS.
|
22
|
+
##########################################################################################
|
23
|
+
|
24
|
+
require_relative "attributes"
|
25
|
+
|
26
|
+
#==========================================================================================
|
27
|
+
#
|
28
|
+
#==========================================================================================
|
29
|
+
|
30
|
+
class Renjin
|
31
|
+
|
32
|
+
#========================================================================================
|
33
|
+
#
|
34
|
+
#========================================================================================
|
35
|
+
|
36
|
+
class Function < Renjin::RubySexp
|
37
|
+
|
38
|
+
def call(*args)
|
39
|
+
args = R.parse(*args)
|
40
|
+
R.eval("#{r}(#{args})")
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
#========================================================================================
|
46
|
+
#
|
47
|
+
#========================================================================================
|
48
|
+
|
49
|
+
class Closure < Function
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
#========================================================================================
|
54
|
+
#
|
55
|
+
#========================================================================================
|
56
|
+
|
57
|
+
class Primitive < Function
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/lib/JRubyR/index.rb
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
##########################################################################################
|
4
|
+
# @author Rodrigo Botafogo
|
5
|
+
#
|
6
|
+
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
|
7
|
+
# and distribute this software and its documentation, without fee and without a signed
|
8
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
9
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
10
|
+
# distributions.
|
11
|
+
#
|
12
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
13
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
14
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
15
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
16
|
+
#
|
17
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
18
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
19
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
20
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
21
|
+
# OR MODIFICATIONS.
|
22
|
+
##########################################################################################
|
23
|
+
|
24
|
+
require 'java'
|
25
|
+
require 'set'
|
26
|
+
|
27
|
+
class Java::UcarMa2::Index
|
28
|
+
field_accessor :stride
|
29
|
+
|
30
|
+
def currentElement
|
31
|
+
getCurrentCounter()
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
#------------------------------------------------------------------------------------------
|
38
|
+
#
|
39
|
+
#------------------------------------------------------------------------------------------
|
40
|
+
|
41
|
+
class MDArray
|
42
|
+
|
43
|
+
@LAYOUT = Set.new [:row, :column, :r]
|
44
|
+
|
45
|
+
#------------------------------------------------------------------------------------
|
46
|
+
# Builds a new MDArray
|
47
|
+
# @param type the type of the new mdarray to build, could be boolean, byte, short,
|
48
|
+
# int, long, float, double, string, structure
|
49
|
+
# @param shape [Array] the shape of the mdarray as a ruby array
|
50
|
+
# @param storage [Array] a ruby array with the initialization data
|
51
|
+
#------------------------------------------------------------------------------------
|
52
|
+
|
53
|
+
def self.build(type, shape, storage = nil, layout = :row)
|
54
|
+
|
55
|
+
if !@LAYOUT.include?(layout)
|
56
|
+
raise "Unknown layout #{layout}"
|
57
|
+
end
|
58
|
+
|
59
|
+
if (shape.is_a? String)
|
60
|
+
# building from csv
|
61
|
+
# using shape as filename
|
62
|
+
# using storage as flag for headers
|
63
|
+
storage = (storage)? storage : false
|
64
|
+
parameters = Csv.read_numeric(shape, storage)
|
65
|
+
shape=[parameters[0], parameters[1]]
|
66
|
+
storage = parameters[2]
|
67
|
+
end
|
68
|
+
|
69
|
+
if (storage)
|
70
|
+
# nc_array = Java::UcarMa2.Array.factory(dtype, jshape, jstorage)
|
71
|
+
nc_array = make_nc_array(type, shape, storage, layout)
|
72
|
+
else
|
73
|
+
nc_array = Java::UcarMa2.Array
|
74
|
+
.factory(DataType.valueOf(type.upcase), shape.to_java(:int))
|
75
|
+
end
|
76
|
+
|
77
|
+
klass = Object.const_get("#{type.capitalize}MDArray")
|
78
|
+
return klass.new(type, nc_array)
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
#------------------------------------------------------------------------------------
|
83
|
+
# Creates new index with the given shape and column-major layout
|
84
|
+
#------------------------------------------------------------------------------------
|
85
|
+
|
86
|
+
def self.index_factory(shape)
|
87
|
+
|
88
|
+
stride = comp_stride(shape)
|
89
|
+
index = Java::UcarMa2.Index.factory(shape.to_java(:int))
|
90
|
+
index.stride = stride.to_java(:int)
|
91
|
+
index.precalc
|
92
|
+
index
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
#----------------------------------------------------------------------------------------
|
97
|
+
#
|
98
|
+
#----------------------------------------------------------------------------------------
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
#------------------------------------------------------------------------------------
|
103
|
+
# Computes the stride for the given shape and column-major layout
|
104
|
+
#------------------------------------------------------------------------------------
|
105
|
+
|
106
|
+
def self.comp_stride(shape)
|
107
|
+
|
108
|
+
stride = Array.new(shape.size)
|
109
|
+
stride[-1], stride[-2] = shape[-2], 1
|
110
|
+
product = shape[-1] * shape[-2]
|
111
|
+
|
112
|
+
if (shape.size > 2)
|
113
|
+
(shape.length - 3).downto(0).each do |i|
|
114
|
+
stride[i] = product
|
115
|
+
product *= shape[i]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
stride
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
#------------------------------------------------------------------------------------
|
124
|
+
# Makes a NetCDF Array with the given storage and layout.
|
125
|
+
#------------------------------------------------------------------------------------
|
126
|
+
|
127
|
+
def self.make_nc_array(type, shape, storage, layout)
|
128
|
+
|
129
|
+
dtype = DataType.valueOf(type.upcase)
|
130
|
+
jshape = shape.to_java :int
|
131
|
+
jstorage = storage.to_java type.downcase.to_sym
|
132
|
+
|
133
|
+
if (layout == :row || shape.size == 1)
|
134
|
+
nc_array = Java::UcarMa2.Array.factory(dtype, jshape, jstorage)
|
135
|
+
else
|
136
|
+
jclass = Java::UcarMa2::Array.java_class
|
137
|
+
nc_array = Java::RbScicom::PrivateCall
|
138
|
+
.factoryInvoke(jclass, type.capitalize, index_factory(shape), jstorage)
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
#------------------------------------------------------------------------------------
|
144
|
+
#
|
145
|
+
#------------------------------------------------------------------------------------
|
146
|
+
|
147
|
+
def self.from_jstorage(type, shape, jstorage, section = false, layout = :row)
|
148
|
+
|
149
|
+
if !@LAYOUT.include?(layout)
|
150
|
+
raise "Unknown layout #{layout}"
|
151
|
+
end
|
152
|
+
|
153
|
+
if (shape.size == 1 && shape[0] == 0)
|
154
|
+
return nil
|
155
|
+
end
|
156
|
+
|
157
|
+
dtype = DataType.valueOf(type.upcase)
|
158
|
+
jshape = shape.to_java :int
|
159
|
+
|
160
|
+
case layout
|
161
|
+
when :row
|
162
|
+
nc_array = Java::UcarMa2.Array.factory(dtype, jshape, jstorage)
|
163
|
+
klass = Object.const_get("#{type.capitalize}MDArray")
|
164
|
+
return klass.new(type, nc_array, section)
|
165
|
+
else
|
166
|
+
jclass = Java::UcarMa2::Array.java_class
|
167
|
+
jstorage = storage.to_java(type)
|
168
|
+
nc_array = Java::RbScicom::PrivateCall
|
169
|
+
.factoryInvoke(jclass, type.capitalize, index_factory(shape), jstorage)
|
170
|
+
MDArray.build_from_nc_array(type, nc_array)
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
=begin
|
183
|
+
|
184
|
+
#------------------------------------------------------------------------------------------
|
185
|
+
# Derived class from Index does not work as we need to create Index1D, Index2D, etc.
|
186
|
+
# classes, and this will only create the Index class
|
187
|
+
#------------------------------------------------------------------------------------------
|
188
|
+
|
189
|
+
class ColumnIndex < Java::UcarMa2::Index
|
190
|
+
|
191
|
+
field_reader :stride
|
192
|
+
field_reader :offset
|
193
|
+
field_reader :current
|
194
|
+
|
195
|
+
def initialize(shape)
|
196
|
+
|
197
|
+
stride = comp_stride(shape)
|
198
|
+
stride = stride.to_java(:int)
|
199
|
+
# index = Java::UcarMa2.Index.factory(shape.to_java(:int))
|
200
|
+
super(shape.to_java(:int), stride)
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
#------------------------------------------------------------------------------------
|
205
|
+
#
|
206
|
+
#------------------------------------------------------------------------------------
|
207
|
+
|
208
|
+
private
|
209
|
+
|
210
|
+
#------------------------------------------------------------------------------------
|
211
|
+
# Computes the stride for the given shape and a column-major layout
|
212
|
+
#------------------------------------------------------------------------------------
|
213
|
+
|
214
|
+
def comp_stride(shape)
|
215
|
+
|
216
|
+
stride = Array.new(shape.size)
|
217
|
+
stride[-1], stride[-2] = shape[-2], 1
|
218
|
+
product = shape[-1] * shape[-2]
|
219
|
+
|
220
|
+
if (shape.size > 2)
|
221
|
+
(shape.length - 3).downto(0).each do |i|
|
222
|
+
stride[i] = product
|
223
|
+
product *= shape[i]
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
stride
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
# jclass is a java class
|
237
|
+
jclass = Java::UcarMa2::Array.java_class
|
238
|
+
# p jclass.private_methods
|
239
|
+
# p jclass.methods
|
240
|
+
# p jclass.declared_method_smart(:factory)
|
241
|
+
|
242
|
+
new = Java::UcarMa2::ArrayDouble.java_class
|
243
|
+
|
244
|
+
# p jclass.declared_class_methods
|
245
|
+
# method = jclass.declared_class_methods[2]
|
246
|
+
# p method.inspect
|
247
|
+
|
248
|
+
method = jclass.declared_class_methods.each do |method|
|
249
|
+
p method if method.name == "factory" && method.arity == 3
|
250
|
+
end
|
251
|
+
|
252
|
+
p method
|
253
|
+
method.accessible = true
|
254
|
+
arr = method.invoke(self, new, index, jstorage.to_java)
|
255
|
+
p arr
|
256
|
+
p arr[0, 0, 0, 0, 0, 0, 0, 0, 0]
|
257
|
+
|
258
|
+
# p jclass.methods
|
259
|
+
# p jclass.java_class_methods
|
260
|
+
|
261
|
+
# jclass.declared_method (Java::UcarMa2::Array.factory, [java.lang.Class, Java::UcarMa2.Index])
|
262
|
+
# java_class = Java::UcarMa2.Array
|
263
|
+
# p java_class
|
264
|
+
# p java_class.methods
|
265
|
+
# p java_class.java_class_methods
|
266
|
+
# const = Java::UcarMa2::ArrayDouble.java_method :factory, [Java::UcarMa2.Index]
|
267
|
+
# const = Java::UcarMa2::Array.java_method :factory, [java.lang.Class, Java::int[]]
|
268
|
+
# p const
|
269
|
+
# constructor = java_class.declared_method (Java::UcarMa2.Array.factory)
|
270
|
+
end
|
271
|
+
|
272
|
+
# java_class = Java::JavaClass.for_name("ucar.ma2.Array")
|
273
|
+
# java_class.getCanonicalName()
|
274
|
+
|
275
|
+
# get a bound Method based on the add(int, Object) method from ArrayList
|
276
|
+
# add = list.java_method :add, [Java::int, java.lang.Object]
|
277
|
+
# add.call(0, 'foo')
|
278
|
+
=end
|