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.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +674 -0
  3. data/README.md +66 -0
  4. data/README.md~ +290 -0
  5. data/Rakefile +51 -0
  6. data/config.rb +163 -0
  7. data/doc/PypeR.pdf +0 -0
  8. data/doc/Stat 133 Class Notes (Phil Spector).pdf +29905 -45
  9. data/doc/The R interface.docx +0 -0
  10. data/lib/JRubyR/as_mdarray.rb +60 -0
  11. data/lib/JRubyR/attributes.rb +74 -0
  12. data/lib/JRubyR/dataframe.rb +35 -0
  13. data/lib/JRubyR/environment.rb +60 -0
  14. data/lib/JRubyR/function.rb +61 -0
  15. data/lib/JRubyR/index.rb +278 -0
  16. data/lib/JRubyR/list.rb +56 -0
  17. data/lib/JRubyR/list_orig.rb +111 -0
  18. data/lib/JRubyR/logical_value.rb +56 -0
  19. data/lib/JRubyR/rbsexp.rb +386 -0
  20. data/lib/JRubyR/renjin.rb +431 -0
  21. data/lib/JRubyR/ruby_classes.rb +58 -0
  22. data/lib/JRubyR/sequence.rb +56 -0
  23. data/lib/JRubyR/vector.rb +493 -0
  24. data/lib/env.rb +12 -0
  25. data/lib/rinruby.rb +795 -0
  26. data/lib/scicom.rb +29 -0
  27. data/target/helper.jar +0 -0
  28. data/test/baseball.csv +1 -0
  29. data/test/env.rb +7 -0
  30. data/test/test_R_interface.rb +165 -0
  31. data/test/test_array.rb +191 -0
  32. data/test/test_attributes.rb +261 -0
  33. data/test/test_basic.rb +156 -0
  34. data/test/test_column-major.rb +114 -0
  35. data/test/test_complete.rb +49 -0
  36. data/test/test_creation.rb +299 -0
  37. data/test/test_dataframe.rb +248 -0
  38. data/test/test_distribution.rb +320 -0
  39. data/test/test_double_assign.rb +240 -0
  40. data/test/test_double_receive.rb +106 -0
  41. data/test/test_environment.rb +57 -0
  42. data/test/test_factor.rb +285 -0
  43. data/test/test_functions.rb +67 -0
  44. data/test/test_linear_model.rb +64 -0
  45. data/test/test_list.rb +220 -0
  46. data/test/test_matrix.rb +205 -0
  47. data/test/test_mdarray.rb +258 -0
  48. data/test/test_operators.rb +227 -0
  49. data/test/test_sequence.rb +63 -0
  50. data/test/test_subsetting.rb +67 -0
  51. data/test/test_tmp.rb +67 -0
  52. data/test/test_vector.rb +227 -0
  53. data/vendor/Renjin.pdf +0 -0
  54. data/vendor/renjin-script-engine-0.7.0-RC7-SNAPSHOT-jar-with-dependencies.jar +0 -0
  55. data/version.rb +2 -0
  56. metadata +196 -0
@@ -0,0 +1,56 @@
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
+
26
+ class Renjin
27
+
28
+ class Sequence < Renjin::RubySexp
29
+ include Renjin::Index
30
+
31
+ end
32
+
33
+ end
34
+
35
+ =begin
36
+ #==========================================================================================
37
+ #
38
+ #==========================================================================================
39
+
40
+ class Renjin
41
+
42
+ class IntSequence < Renjin::Sequence
43
+ include_package "org.renjin.primitives.sequence"
44
+
45
+ #----------------------------------------------------------------------------------------
46
+ #
47
+ #----------------------------------------------------------------------------------------
48
+
49
+ def getElement(index)
50
+ @sexp.getElementAsInt(index)
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+ =end
@@ -0,0 +1,493 @@
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
+
26
+
27
+ #==========================================================================================
28
+ #
29
+ #==========================================================================================
30
+
31
+ class Java::OrgRenjinSexp::StringArrayVector
32
+ field_reader :values
33
+ end
34
+
35
+ class Java::OrgRenjinSexp::LogicalArrayVector
36
+ field_reader :values
37
+ end
38
+
39
+
40
+ #==========================================================================================
41
+ #
42
+ #==========================================================================================
43
+
44
+ class Renjin
45
+
46
+ class Vector < Renjin::RubySexp
47
+ include Enumerable
48
+ include Renjin::Index
49
+
50
+ attr_reader :mdarray
51
+
52
+ #----------------------------------------------------------------------------------------
53
+ #
54
+ #----------------------------------------------------------------------------------------
55
+
56
+ def initialize(sexp)
57
+ super(sexp)
58
+ @mdarray = nil
59
+ @iterator = @sexp.iterator()
60
+ end
61
+
62
+ #----------------------------------------------------------------------------------------
63
+ #
64
+ #----------------------------------------------------------------------------------------
65
+
66
+ def integer?
67
+ R.is__integer(R.eval("#{r}")).gt
68
+ end
69
+
70
+ #----------------------------------------------------------------------------------------
71
+ #
72
+ #----------------------------------------------------------------------------------------
73
+
74
+ def double?
75
+ R.is__double(R.eval("#{r}")).gt
76
+ end
77
+
78
+ #----------------------------------------------------------------------------------------
79
+ #
80
+ #----------------------------------------------------------------------------------------
81
+
82
+ def complex?
83
+ R.is__complex(R.eval("#{r}")).gt
84
+ end
85
+
86
+ #----------------------------------------------------------------------------------------
87
+ #
88
+ #----------------------------------------------------------------------------------------
89
+
90
+ def logical?
91
+ R.is__logical(R.eval("#{r}")).gt
92
+ end
93
+
94
+ #----------------------------------------------------------------------------------------
95
+ #
96
+ #----------------------------------------------------------------------------------------
97
+
98
+ def character?
99
+ R.is__character(R.eval("#{r}")).gt
100
+ end
101
+
102
+ #----------------------------------------------------------------------------------------
103
+ #
104
+ #----------------------------------------------------------------------------------------
105
+
106
+ def atomic?
107
+ R.is__atomic(R.eval("#{r}")).gt
108
+ end
109
+
110
+ #----------------------------------------------------------------------------------------
111
+ #
112
+ #----------------------------------------------------------------------------------------
113
+
114
+ def numeric?
115
+ R.is__numeric(R.eval("#{r}")).gt
116
+ end
117
+
118
+ #----------------------------------------------------------------------------------------
119
+ #
120
+ #----------------------------------------------------------------------------------------
121
+
122
+ def ==(other_val)
123
+ other_val = (other_val.is_a? Renjin::RubySexp)? other_val.r : other_val
124
+ (other_val == nil)? false : R.eval("#{r} == #{other_val}")
125
+ end
126
+
127
+ #----------------------------------------------------------------------------------------
128
+ #
129
+ #----------------------------------------------------------------------------------------
130
+
131
+ def eq(other_val)
132
+ (other_val == nil)? false : R.eval("identical(#{r},#{other_val.r})")
133
+ end
134
+
135
+ #----------------------------------------------------------------------------------------
136
+ #
137
+ #----------------------------------------------------------------------------------------
138
+
139
+ def as__integer
140
+ R.as__integer(self)
141
+ end
142
+
143
+ #----------------------------------------------------------------------------------------
144
+ #
145
+ #----------------------------------------------------------------------------------------
146
+
147
+ def as__double
148
+ R.as__double(self)
149
+ end
150
+
151
+ #----------------------------------------------------------------------------------------
152
+ #
153
+ #----------------------------------------------------------------------------------------
154
+
155
+ def as__complex
156
+ R.as__complex(self)
157
+ end
158
+
159
+ #----------------------------------------------------------------------------------------
160
+ #
161
+ #----------------------------------------------------------------------------------------
162
+
163
+ def as__character
164
+ R.as__character(self)
165
+ end
166
+
167
+ #----------------------------------------------------------------------------------------
168
+ #
169
+ #----------------------------------------------------------------------------------------
170
+
171
+ def as__mdarray
172
+
173
+ if (@mdarray)
174
+ elsif (@sexp.instance_of? Java::RbScicom::MDDoubleVector)
175
+ @mdarray = MDArray.build_from_nc_array(:double, @sexp.array)
176
+ elsif (@sexp.instance_of? Java::OrgRenjinSexp::DoubleArrayVector)
177
+ @mdarray = MDArray.from_jstorage("double", [@sexp.length()], @sexp.toDoubleArrayUnsafe())
178
+ elsif (@sexp.instance_of? Java::OrgRenjinSexp::IntArrayVector)
179
+ @mdarray = MDArray.from_jstorage("int", [@sexp.length()], @sexp.toIntArrayUnsafe())
180
+ elsif (@sexp.instance_of? Java::OrgRenjinSexp::StringArrayVector)
181
+ @mdarray = MDArray.from_jstorage("string", [@sexp.length()], @sexp.values)
182
+ elsif (@sexp.instance_of? Java::OrgRenjinSexp::LogicalArrayVector)
183
+ @mdarray = MDArray.from_jstorage("int", [@sexp.length()], @sexp.values)
184
+ else
185
+ p "sexp type needs to be specialized"
186
+ p @sexp
187
+ @mdarray = Renjin::RubySexp.new(@sexp)
188
+ end
189
+
190
+ raise "Cannot convert Vector to MDArray" if (!@mdarray)
191
+ return @mdarray
192
+
193
+ end
194
+
195
+ #----------------------------------------------------------------------------------------
196
+ #
197
+ #----------------------------------------------------------------------------------------
198
+
199
+ def get(index = nil)
200
+ (index)? as__mdarray[index] : as__mdarray
201
+ end
202
+
203
+ #----------------------------------------------------------------------------------------
204
+ #
205
+ #----------------------------------------------------------------------------------------
206
+
207
+ def gz
208
+ get(0)
209
+ end
210
+
211
+ #----------------------------------------------------------------------------------------
212
+ #
213
+ #----------------------------------------------------------------------------------------
214
+
215
+ def gt(index = 0)
216
+ (get(index) == 0)? false : true
217
+ end
218
+
219
+ #----------------------------------------------------------------------------------------
220
+ #
221
+ #----------------------------------------------------------------------------------------
222
+
223
+ def +@
224
+ R.eval("+#{r}")
225
+ end
226
+
227
+ #----------------------------------------------------------------------------------------
228
+ #
229
+ #----------------------------------------------------------------------------------------
230
+
231
+ def -@
232
+ R.eval("-#{r}")
233
+ end
234
+
235
+ #----------------------------------------------------------------------------------------
236
+ #
237
+ #----------------------------------------------------------------------------------------
238
+
239
+ def +(other_vec)
240
+ if (other_vec.is_a? Numeric)
241
+ other_vec = R.d(other_vec)
242
+ end
243
+ R.eval("#{r} + #{other_vec.r}")
244
+
245
+ end
246
+
247
+ #----------------------------------------------------------------------------------------
248
+ #
249
+ #----------------------------------------------------------------------------------------
250
+
251
+ def -(other_vec)
252
+ if (other_vec.is_a? Numeric)
253
+ other_vec = R.d(other_vec)
254
+ end
255
+ R.eval("#{r} - #{other_vec.r}")
256
+ end
257
+
258
+ #----------------------------------------------------------------------------------------
259
+ #
260
+ #----------------------------------------------------------------------------------------
261
+
262
+ def *(other_vec)
263
+ if (other_vec.is_a? Numeric)
264
+ other_vec = R.d(other_vec)
265
+ end
266
+ R.eval("#{r} * #{other_vec.r}")
267
+ end
268
+
269
+ #----------------------------------------------------------------------------------------
270
+ #
271
+ #----------------------------------------------------------------------------------------
272
+
273
+ def /(other_vec)
274
+ if (other_vec.is_a? Numeric)
275
+ other_vec = R.d(other_vec)
276
+ end
277
+ R.eval("#{r} / #{other_vec.r}")
278
+ end
279
+
280
+ #----------------------------------------------------------------------------------------
281
+ # modulus
282
+ #----------------------------------------------------------------------------------------
283
+
284
+ def %(other_vec)
285
+ if (other_vec.is_a? Numeric)
286
+ other_vec = R.d(other_vec)
287
+ end
288
+ R.eval("#{r} %% #{other_vec.r}")
289
+ end
290
+
291
+ #----------------------------------------------------------------------------------------
292
+ #
293
+ #----------------------------------------------------------------------------------------
294
+
295
+ def int_div(other_vec)
296
+ if (other_vec.is_a? Numeric)
297
+ other_vec = R.d(other_vec)
298
+ end
299
+ R.eval("#{r} %/% #{other_vec.r}")
300
+ end
301
+
302
+ #----------------------------------------------------------------------------------------
303
+ # exponentiation
304
+ #----------------------------------------------------------------------------------------
305
+
306
+ def **(other_vec)
307
+ if (other_vec.is_a? Numeric)
308
+ other_vec = R.d(other_vec)
309
+ end
310
+ R.eval("#{r} ** #{other_vec.r}")
311
+ end
312
+
313
+ #----------------------------------------------------------------------------------------
314
+ #
315
+ #----------------------------------------------------------------------------------------
316
+
317
+ def >(other_vec)
318
+ if (other_vec.is_a? Numeric)
319
+ other_vec = R.d(other_vec)
320
+ end
321
+ R.eval("#{r} > #{other_vec.r}")
322
+ end
323
+
324
+ #----------------------------------------------------------------------------------------
325
+ #
326
+ #----------------------------------------------------------------------------------------
327
+
328
+ def >=(other_vec)
329
+ if (other_vec.is_a? Numeric)
330
+ other_vec = R.d(other_vec)
331
+ end
332
+ R.eval("#{r} >= #{other_vec.r}")
333
+ end
334
+
335
+ #----------------------------------------------------------------------------------------
336
+ #
337
+ #----------------------------------------------------------------------------------------
338
+
339
+ def <(other_vec)
340
+ if (other_vec.is_a? Numeric)
341
+ other_vec = R.d(other_vec)
342
+ end
343
+ R.eval("#{r} < #{other_vec.r}")
344
+ end
345
+
346
+ #----------------------------------------------------------------------------------------
347
+ #
348
+ #----------------------------------------------------------------------------------------
349
+
350
+ def <=(other_vec)
351
+ if (other_vec.is_a? Numeric)
352
+ other_vec = R.d(other_vec)
353
+ end
354
+ R.eval("#{r} <= #{other_vec.r}")
355
+ end
356
+
357
+ #----------------------------------------------------------------------------------------
358
+ #
359
+ #----------------------------------------------------------------------------------------
360
+
361
+ def !=(other_vec)
362
+ if (other_vec.is_a? Numeric)
363
+ other_vec = R.d(other_vec)
364
+ end
365
+ R.eval("#{r} != #{other_vec.r}")
366
+ end
367
+
368
+ #----------------------------------------------------------------------------------------
369
+ #
370
+ #----------------------------------------------------------------------------------------
371
+
372
+ def !
373
+ R.eval("!#{r}")
374
+ end
375
+
376
+ #----------------------------------------------------------------------------------------
377
+ #
378
+ #----------------------------------------------------------------------------------------
379
+
380
+ def &(other_vec)
381
+ if (other_vec.is_a? Numeric)
382
+ other_vec = R.d(other_vec)
383
+ end
384
+ R.eval("#{r} & #{other_vec.r}")
385
+ end
386
+
387
+ #----------------------------------------------------------------------------------------
388
+ # l_and looks at only the first element of the vector
389
+ #----------------------------------------------------------------------------------------
390
+
391
+ def l_and(other_vec)
392
+ if (other_vec.is_a? Numeric)
393
+ other_vec = R.d(other_vec)
394
+ end
395
+ R.eval("#{r} && #{other_vec.r}")
396
+ end
397
+
398
+ #----------------------------------------------------------------------------------------
399
+ # or
400
+ #----------------------------------------------------------------------------------------
401
+
402
+ def |(other_vec)
403
+ if (other_vec.is_a? Numeric)
404
+ other_vec = R.d(other_vec)
405
+ end
406
+ R.eval("#{r} | #{other_vec.r}")
407
+ end
408
+
409
+ #----------------------------------------------------------------------------------------
410
+ #
411
+ #----------------------------------------------------------------------------------------
412
+
413
+ def l_or(other_vec)
414
+ if (other_vec.is_a? Numeric)
415
+ other_vec = R.d(other_vec)
416
+ end
417
+ R.eval("#{r} || #{other_vec.r}")
418
+ end
419
+
420
+ #----------------------------------------------------------------------------------------
421
+ #
422
+ #----------------------------------------------------------------------------------------
423
+
424
+ def xor(other_vec)
425
+ if (other_vec.is_a? Numeric)
426
+ other_vec = R.d(other_vec)
427
+ end
428
+ R.eval("#{r} xor #{other_vec.r}")
429
+ end
430
+
431
+ #----------------------------------------------------------------------------------------
432
+ #
433
+ #----------------------------------------------------------------------------------------
434
+
435
+ def coerce(scalar)
436
+ [R.d(scalar), self]
437
+ end
438
+
439
+ end
440
+
441
+ end
442
+
443
+ #==========================================================================================
444
+ #
445
+ #==========================================================================================
446
+
447
+ class Renjin
448
+
449
+ class ComplexVector < Renjin::Vector
450
+
451
+ #----------------------------------------------------------------------------------------
452
+ # Returns a vector with the real part of this vector
453
+ #----------------------------------------------------------------------------------------
454
+
455
+ def re
456
+ R.Re(self)
457
+ end
458
+
459
+ #----------------------------------------------------------------------------------------
460
+ # Returns a vector with the imaginary part of this vector
461
+ #----------------------------------------------------------------------------------------
462
+
463
+ def im
464
+ R.Im(self)
465
+ end
466
+
467
+ #----------------------------------------------------------------------------------------
468
+ # Returns a vector with the modulus of this vector
469
+ #----------------------------------------------------------------------------------------
470
+
471
+ def mod
472
+ R.Mod(self)
473
+ end
474
+
475
+ #----------------------------------------------------------------------------------------
476
+ # Returns a vector with the argument of this complex vector
477
+ #----------------------------------------------------------------------------------------
478
+
479
+ def arg
480
+ R.Arg(self)
481
+ end
482
+
483
+ #----------------------------------------------------------------------------------------
484
+ # Returns a vector with the conjugate of this complex vector
485
+ #----------------------------------------------------------------------------------------
486
+
487
+ def conj
488
+ R.Conj(self)
489
+ end
490
+
491
+ end
492
+
493
+ end