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.
@@ -42,7 +42,7 @@ class SciComTest < Test::Unit::TestCase
42
42
  #--------------------------------------------------------------------------------------
43
43
  #
44
44
  #--------------------------------------------------------------------------------------
45
- =begin
45
+
46
46
  should "create data-frame from a single vector" do
47
47
 
48
48
  vec = R.seq(20)
@@ -142,7 +142,6 @@ class SciComTest < Test::Unit::TestCase
142
142
  mtcars[R.c("mpg", "hp")].pp
143
143
 
144
144
  end
145
- =end
146
145
 
147
146
  #--------------------------------------------------------------------------------------
148
147
  #
@@ -195,7 +194,6 @@ class SciComTest < Test::Unit::TestCase
195
194
  #--------------------------------------------------------------------------------------
196
195
 
197
196
  should "create data-frame from multiple vectors" do
198
- =begin
199
197
 
200
198
  # name age hgt wgt race year SAT
201
199
  # Bob 21 70 180 Cauc Jr 1080
@@ -229,7 +227,7 @@ class SciComTest < Test::Unit::TestCase
229
227
  # variable rbvec.
230
228
  rbvec.print
231
229
 
232
-
230
+ =begin
233
231
  # R.colnames(df) = R.c("name", "age", "height", "weigth", "race", "SAT")
234
232
  df.print
235
233
  summ = R.summary(df.r)
@@ -240,7 +238,6 @@ class SciComTest < Test::Unit::TestCase
240
238
  col = R.colnames(:df)
241
239
  col.print
242
240
  =end
243
-
244
241
  end
245
242
 
246
243
  end
@@ -36,10 +36,6 @@ class SciComTest < Test::Unit::TestCase
36
36
 
37
37
  setup do
38
38
 
39
- # creating two distinct instances of SciCom
40
- @r1 = R.new
41
- @r2 = R.new
42
-
43
39
  end
44
40
 
45
41
  #--------------------------------------------------------------------------------------
@@ -48,14 +48,14 @@ class SciComTest < Test::Unit::TestCase
48
48
  baseball = R.read__csv("baseball.csv")
49
49
  # Lets look at the data available for Momeyball.
50
50
  # (baseball.Year < R.d(2002)).pp
51
- moneyball = R.subset(baseball, baseball.Year < 2002)
51
+ moneyball = baseball.subset(baseball.Year < 2002)
52
52
 
53
53
  # Let's see if we can predict the number of wins, by looking at
54
54
  # runs allowed (RA) and runs scored (RS). RD is the runs difference.
55
55
  # We are making a linear model for predicting wins (W) based on RD
56
56
  moneyball.RD = moneyball.RS - moneyball.RA
57
57
  wins_reg = R.lm("W ~ RD", data: moneyball)
58
- R.summary(wins_reg).pp
58
+ wins_reg.summary.pp
59
59
 
60
60
  end
61
61
 
data/test/test_matrix.rb CHANGED
@@ -96,11 +96,11 @@ class SciComTest < Test::Unit::TestCase
96
96
  # from the digits 0-9. For the purpose of this demonstration, we will set the random
97
97
  # number seed to a memorable number so that it will yield the same answer each time.
98
98
  R.set__seed(42)
99
- xij = R.matrix(R.sample(R.seq(0, 9), 40, replace: TRUE), ncol: 4)
100
-
101
- xij.fassign(:rownames, R.paste("S", R.seq(1, xij.attr.dim[1]), sep: ""))
102
- xij.fassign(:colnames, R.paste("V", R.seq(1, xij.attr.dim[2]), sep: ""))
103
- xij.pp
99
+ xij = R.seq(0,9).sample(40, replace: TRUE).matrix(ncol: 4)
100
+ xij
101
+ .fassign(:rownames, R.paste("S", R.seq(1, xij.attr.dim[1]), sep: ""))
102
+ .fassign(:colnames, R.paste("V", R.seq(1, xij.attr.dim[2]), sep: ""))
103
+ .pp
104
104
 
105
105
  # Just as we could with vectors, we can add, subtract, muliply or divide the matrix
106
106
  # by a scaler (a number with out a dimension)
@@ -183,17 +183,13 @@ class SciComTest < Test::Unit::TestCase
183
183
  x_cov.diag.round(2).pp
184
184
 
185
185
  sdi = (1 / x_cov.diag.sqrt).diag
186
- sdi.fassign(:rownames, x_cov.rownames)
187
- sdi.fassign(:colnames, x_cov.colnames)
188
- sdi.round(2).pp
186
+ .fassign(:rownames, x_cov.rownames)
187
+ .fassign(:colnames, x_cov.colnames)
188
+ .pp
189
189
 
190
190
  x_cor = (sdi._ :*, x_cov)._ :*, sdi
191
- x_cor.fassign(:rownames, x_cov.rownames)
192
- x_cor.fassign(:colnames, x_cov.colnames)
193
- x_cor.round(2).pp
194
-
195
- # use the cor function to find the correlation
196
- xij.cor.round(2).pp
191
+ .fassign(:rownames, x_cov.rownames)
192
+ .fassign(:colnames, x_cov.colnames)
197
193
 
198
194
  assert_equal(true, (x_cor.round(2) == xij.cor.round(2)).all.gt)
199
195
 
data/version.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  $gem_name = "scicom"
2
- $version="0.2.2"
2
+ $version="0.2.3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scicom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: java
6
6
  authors:
7
7
  - Rodrigo Botafogo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2014-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -113,23 +113,20 @@ files:
113
113
  - lib/JRubyR/list.rb
114
114
  - lib/JRubyR/vector.rb
115
115
  - lib/JRubyR/attributes.rb
116
- - lib/JRubyR/as_mdarray.rb
117
116
  - lib/JRubyR/logical_value.rb
118
- - lib/JRubyR/sequence.rb
119
117
  - lib/JRubyR/environment.rb
120
- - lib/JRubyR/list_orig.rb
121
118
  - lib/JRubyR/ruby_classes.rb
122
119
  - lib/JRubyR/function.rb
123
- - lib/JRubyR/index.rb
124
120
  - lib/JRubyR/rbsexp.rb
125
121
  - lib/JRubyR/renjin.rb
126
122
  - lib/JRubyR/dataframe.rb
127
123
  - test/env.rb
128
124
  - test/test_tmp.rb
125
+ - test/test_assign_mdarray_2d.rb
129
126
  - test/test_attributes.rb
130
127
  - test/test_complete.rb
131
128
  - test/test_column-major.rb
132
- - test/test_double_assign.rb
129
+ - test/test_assign_mdarray.rb
133
130
  - test/test_double_receive.rb
134
131
  - test/test_distribution.rb
135
132
  - test/test_creation.rb
@@ -146,6 +143,8 @@ files:
146
143
  - test/test_operators.rb
147
144
  - test/test_linear_model.rb
148
145
  - test/test_matrix.rb
146
+ - test/test_assign_mdarray_3d.rb
147
+ - test/test_assign_mdarray_4d.rb
149
148
  - test/test_dataframe.rb
150
149
  - test/test_list.rb
151
150
  - test/baseball.csv
@@ -185,10 +184,11 @@ summary: Scientific Computing for Ruby
185
184
  test_files:
186
185
  - test/env.rb
187
186
  - test/test_tmp.rb
187
+ - test/test_assign_mdarray_2d.rb
188
188
  - test/test_attributes.rb
189
189
  - test/test_complete.rb
190
190
  - test/test_column-major.rb
191
- - test/test_double_assign.rb
191
+ - test/test_assign_mdarray.rb
192
192
  - test/test_double_receive.rb
193
193
  - test/test_distribution.rb
194
194
  - test/test_creation.rb
@@ -205,5 +205,7 @@ test_files:
205
205
  - test/test_operators.rb
206
206
  - test/test_linear_model.rb
207
207
  - test/test_matrix.rb
208
+ - test/test_assign_mdarray_3d.rb
209
+ - test/test_assign_mdarray_4d.rb
208
210
  - test/test_dataframe.rb
209
211
  - test/test_list.rb
@@ -1,60 +0,0 @@
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
data/lib/JRubyR/index.rb DELETED
@@ -1,278 +0,0 @@
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