mdarray 0.5.4-java → 0.5.5-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,4 +22,4 @@
22
22
  require_relative 'test_statistics'
23
23
  require_relative 'test_stat_list'
24
24
  require_relative 'test_math'
25
- require_relative 'test_matrix'
25
+ require_relative 'matrix/test_complete'
@@ -21,14 +21,19 @@
21
21
 
22
22
  require 'env.rb'
23
23
 
24
- require 'mdarray/test_complete'
25
- require 'colt/test_complete'
26
- require 'netcdf/test_complete'
24
+ require 'mdarray/test_complete'
25
+ require 'colt/test_complete'
26
+ require 'netcdf/test_complete'
27
27
 
28
28
 
29
29
  # Temporary tests. Remove before shipping!
30
30
 
31
- # require 'colt/test_matrix'
32
- # require 'netcdf/test_netcdf'
33
- # require 'mdarray/test_sections'
34
- # require 'netcdf/netcdfwriter'
31
+ # require 'colt/matrix/test_complete'
32
+
33
+ # require 'colt/matrix/test_matrix2d_floatingalgebra'
34
+ # require 'colt/matrix/test_matrix2d_fixpointalgebra'
35
+
36
+ # require 'colt/matrix/test_matrix1d_floatingalgebra'
37
+ # require 'colt/matrix/test_matrix1d_fixpointalgebra'
38
+
39
+ # require 'colt/matrix/test_properties'
@@ -179,6 +179,61 @@ class MDArrayTest < Test::Unit::TestCase
179
179
 
180
180
  end
181
181
 
182
+ #-------------------------------------------------------------------------------------
183
+ # Regions and sections are the same functionality with a different interface
184
+ #-------------------------------------------------------------------------------------
185
+
186
+ should "get array regions" do
187
+
188
+ # 1 -> first year (only 1 year)
189
+ # 20 -> 20 days
190
+ # 10 -> number os secs
191
+ # 7 - > number of values
192
+
193
+ # b is a section of @a, starting at position (0) and taking only the first two
194
+ # elements of the first dimension. Getting all values, for all secs for the first
195
+ # 2 days
196
+ # b = @a.section([0, 0, 0, 0], [1, 2, 10, 7])
197
+ b = @a.region(:spec => "0:0, 0:1, 0:9, 0:6")
198
+ assert_equal(true, b.section?)
199
+ assert_equal([1, 2, 10, 7], b.shape)
200
+ ind = b.get_index
201
+ ind.each do |elmt|
202
+ assert_equal(@a.get(elmt), b.get(elmt))
203
+ end
204
+
205
+
206
+ # getting "open" for the first 2 days of the 2nd sec. Values are organized
207
+ # as follows:
208
+ # (open, close, high, low, volume, e1, e2).
209
+ # Start at: [0, 0, 3, 0] =>
210
+ # 0 -> first year, 0 -> first day, 3 -> 2nd sec, 0 -> first value
211
+ # Specification: [1, 2, 1, 1] =>
212
+ # 1 -> get only first year, 2 -> take 2 days from day 0 to day 1,
213
+ # 1 -> take one security, already selected the 2nd one, 1 -> only one value
214
+ # in this case the first one was selected.
215
+ # b = @a.section([0, 0, 3, 0], [1, 2, 1, 1])
216
+ b = @a.region(:spec => "0:0, 0:1, 3:3, 0:0")
217
+ assert_equal(40.00, b[0, 0, 0, 0])
218
+ assert_equal(41.00, b[0, 1, 0, 0])
219
+
220
+
221
+ # getting "close" (2nd) value of the 3rd sec for the second day with
222
+ # shape reduction. Note that in this case, with shape reduction, b is a
223
+ # number and not an array any more
224
+ # b = @a.section([0, 1, 2, 1], [1, 1, 1, 1], true)
225
+ b = @a.region(:origin => [0, 1, 2, 1], :shape => [1, 1, 1, 1], :reduce => true)
226
+ assert_equal(@a[0, 1, 2, 1], b)
227
+
228
+ # getting the "close" (2nd) value of the 3rd sec for the second day without
229
+ # shape reduction
230
+ # b = @a.section([0, 1, 2, 1], [1, 1, 1, 1])
231
+ b = @a.region(:origin => [0, 1, 2, 1], :size => [1, 1, 1, 1], :stride => [1, 1, 1, 1])
232
+ assert_equal([1, 1, 1, 1], b.shape)
233
+ assert_equal(@a[0, 1, 2, 1], b[0, 0, 0, 0])
234
+
235
+ end
236
+
182
237
  #-------------------------------------------------------------------------------------
183
238
  # each_along_axes returns sub-arrays (sections) of the original array. Each section
184
239
  # is taken by walking along the given axis and getting all elements of the
data/version.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  $gem_name = "mdarray"
2
- $version="0.5.4"
2
+ $version="0.5.5"
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: mdarray
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.4
5
+ version: 0.5.5
6
6
  platform: java
7
7
  authors:
8
8
  - Rodrigo Botafogo
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-07 00:00:00.000000000 Z
12
+ date: 2013-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: map
@@ -42,7 +42,7 @@ dependencies:
42
42
  version: '0'
43
43
  none: false
44
44
  prerelease: false
45
- type: :runtime
45
+ type: :development
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: simplecov
48
48
  version_requirements: !ruby/object:Gem::Requirement
@@ -94,10 +94,11 @@ dependencies:
94
94
  description: "\"MDArray is a multi dimensional array implemented for JRuby inspired\
95
95
  \ by NumPy (www.numpy.org) and \nMasahiro Tanaka´s Narray (narray.rubyforge.org).\
96
96
  \ MDArray stands on the shoulders of Java-NetCDF \nand Parallel Colt. At this\
97
- \ point MDArray has libraries for mathematical, trigonometric and \ndescriptive\
98
- \ statistics methods.\n\nNetCDF-Java Library is a Java interface to NetCDF files,\
99
- \ as well as to many other types of \nscientific data formats. It is developed\
100
- \ and distributed by Unidata (http://www.unidata.ucar.edu). \n\nParallel Colt (http://grepcode.com/snapshot/repo1.maven.org/maven2/net.sourceforge.parallelcolt/\n\
97
+ \ point MDArray has libraries for linear algebra, mathematical, \ntrigonometric\
98
+ \ and descriptive statistics methods.\n\nNetCDF-Java Library is a Java interface\
99
+ \ to NetCDF files, as well as to many other types of \nscientific data formats.\
100
+ \ It is developed and distributed by Unidata (http://www.unidata.ucar.edu). \n\n\
101
+ Parallel Colt (http://grepcode.com/snapshot/repo1.maven.org/maven2/net.sourceforge.parallelcolt/\n\
101
102
  parallelcolt/0.10.0/) is a multithreaded version of Colt (http://acs.lbl.gov/software/colt/).\
102
103
  \ \nColt provides a set of Open Source Libraries for High Performance Scientific\
103
104
  \ and Technical \nComputing in Java. Scientific and technical computing is characterized\
@@ -122,9 +123,11 @@ files:
122
123
  - lib/colt/double_descriptive.rb
123
124
  - lib/colt/probability.rb
124
125
  - lib/colt/stat_list.rb
126
+ - lib/colt/matrix/algebra.rb
125
127
  - lib/colt/matrix/colt_matrix.rb
126
- - lib/colt/matrix/matrix2D_floating_algebra.rb
127
- - lib/colt/matrix/matrix_hierarchy.rb
128
+ - lib/colt/matrix/creation.rb
129
+ - lib/colt/matrix/hierarchy.rb
130
+ - lib/colt/matrix/property.rb
128
131
  - lib/mdarray/access.rb
129
132
  - lib/mdarray/counter.rb
130
133
  - lib/mdarray/creation.rb
@@ -158,12 +161,16 @@ files:
158
161
  - test/complete.rb
159
162
  - test/env.rb
160
163
  - test/colt/test_complete.rb
161
- - test/colt/test_double_matrix2d.rb
162
- - test/colt/test_float_matrix2d.rb
163
164
  - test/colt/test_math.rb
164
- - test/colt/test_matrix.rb
165
165
  - test/colt/test_statistics.rb
166
166
  - test/colt/test_stat_list.rb
167
+ - test/colt/matrix/test_complete.rb
168
+ - test/colt/matrix/test_matrix1d_floatingalgebra.rb
169
+ - test/colt/matrix/test_matrix2d_fixpointalgebra.rb
170
+ - test/colt/matrix/test_matrix2d_floatingalgebra.rb
171
+ - test/colt/matrix/test_operations.rb
172
+ - test/colt/matrix/test_properties.rb
173
+ - test/colt/matrix/test_creation.rb
167
174
  - test/mdarray/arithmetic_casting.rb
168
175
  - test/mdarray/test_access.rb
169
176
  - test/mdarray/test_boolean.rb
@@ -255,16 +262,15 @@ files:
255
262
  - doc/MDArray/IteratorFastInt.html
256
263
  - doc/MDArray/IteratorFastLong.html
257
264
  - doc/MDArray/IteratorFastShort.html
258
- - vendor/commons-compiler.jar
259
- - vendor/incanter.jar
260
- - vendor/janino.jar
261
265
  - vendor/netcdfAll-4.3.18.jar
266
+ - vendor/mdarray.jar
262
267
  - target/helper.jar
263
268
  - README.md
264
269
  - LICENSE.txt
265
270
  - LICENSE.txt~
266
271
  homepage: http://github.com/rbotafogo/mdarray/wiki
267
- licenses: []
272
+ licenses:
273
+ - BSD 2-clause
268
274
  post_install_message:
269
275
  rdoc_options: []
270
276
  require_paths:
@@ -1,325 +0,0 @@
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 for educational, research, and
6
- # not-for-profit purposes, without fee and without a signed licensing agreement, is hereby
7
- # granted, provided that the above copyright notice, this paragraph and the following two
8
- # paragraphs appear in all copies, modifications, and distributions. Contact Rodrigo
9
- # Botafogo - rodrigo.a.botafogo@gmail.com for commercial licensing opportunities.
10
- #
11
- # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
12
- # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
13
- # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
14
- # POSSIBILITY OF SUCH DAMAGE.
15
- #
16
- # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
- # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
18
- # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
19
- # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
20
- # OR MODIFICATIONS.
21
- ##########################################################################################
22
-
23
- # require 'jruby/core_ext'
24
-
25
- require 'java'
26
-
27
- ##########################################################################################
28
- #
29
- ##########################################################################################
30
-
31
- module Matrix2DFloatingAlgebra
32
- include_package "cern.colt.matrix.tdouble.algo"
33
- include_package "cern.colt.matrix.tfloat.algo"
34
-
35
- #------------------------------------------------------------------------------------
36
- # Solves the upper triangular system U*x=b;
37
- #------------------------------------------------------------------------------------
38
-
39
- def backward_solve(matrix1D)
40
- result = @algebra.backwardSolve(@colt_matrix, matrix1D.colt_matrix)
41
- MDMatrix.from_colt_matrix(result)
42
- end
43
-
44
- #------------------------------------------------------------------------------------
45
- # Constructs and returns the cholesky-decomposition of the given matrix. For a
46
- # symmetric, positive definite matrix A, the Cholesky decomposition is a lower
47
- # triangular matrix L so that A = L*L'; If the matrix is not symmetric positive
48
- # definite, the IllegalArgumentException is thrown.
49
- #------------------------------------------------------------------------------------
50
-
51
- def chol
52
- result = @algebra.chol(@colt_matrix).getL()
53
- MDMatrix.from_colt_matrix(result)
54
- end
55
-
56
- #------------------------------------------------------------------------------------
57
- # Returns the condition of matrix A, which is the ratio of largest to smallest
58
- # singular value.
59
- #------------------------------------------------------------------------------------
60
-
61
- def cond
62
- @algebra.cond(@colt_matrix)
63
- end
64
-
65
- #------------------------------------------------------------------------------------
66
- # Returns the determinant of matrix A.
67
- #------------------------------------------------------------------------------------
68
-
69
- def det
70
- @algebra.det(@colt_matrix)
71
- end
72
-
73
- #------------------------------------------------------------------------------------
74
- #
75
- #------------------------------------------------------------------------------------
76
-
77
- def eig
78
- eig = @algebra.eig(@colt_matrix)
79
- [MDMatrix.from_colt_matrix(eig.getD),
80
- MDMatrix.from_colt_matrix(eig.getImagEigenvalues),
81
- MDMatrix.from_colt_matrix(eig.getRealEigenvalues),
82
- MDMatrix.from_colt_matrix(eig.getV)]
83
- end
84
-
85
- #------------------------------------------------------------------------------------
86
- # Solves the lower triangular system L*x=b;
87
- #------------------------------------------------------------------------------------
88
-
89
- def forward_solve(matrix1D)
90
- result = @algebra.forwardSolve(@colt_matrix, matrix1D.colt_matrix)
91
- MDMatrix.from_colt_matrix(result)
92
- end
93
-
94
- #------------------------------------------------------------------------------------
95
- # Returns the inverse or pseudo-inverse of matrix A.
96
- #------------------------------------------------------------------------------------
97
-
98
- def inverse
99
- result = @algebra.inverse(@colt_matrix)
100
- MDMatrix.from_colt_matrix(result)
101
- end
102
-
103
- #------------------------------------------------------------------------------------
104
- # Computes the Kronecker product of two real matrices.
105
- #------------------------------------------------------------------------------------
106
-
107
- def kron(matrix)
108
-
109
- if (matrix.rank != 2)
110
- raise "Rank should be 2"
111
- end
112
- result = @algebra.kron(@colt_matrix, matrix.colt_matrix)
113
- MDMatrix.from_colt_matrix(result)
114
-
115
- end
116
-
117
- #------------------------------------------------------------------------------------
118
- # Constructs and returns the LU-decomposition of the given matrix.
119
- #------------------------------------------------------------------------------------
120
-
121
- def lu
122
- result = @algebra.lu(@colt_matrix)
123
- [result.isNonsingular(), result.det(), result.getPivot.to_a(),
124
- MDMatrix.from_colt_matrix(result.getL()),
125
- MDMatrix.from_colt_matrix(result.getU())]
126
- end
127
-
128
- #------------------------------------------------------------------------------------
129
- # Multiplies this matrix by another matrix
130
- #------------------------------------------------------------------------------------
131
-
132
- def mult(matrix)
133
-
134
- if (matrix.rank > 2)
135
- raise "Rank should be 1 or 2"
136
- end
137
-
138
- result = @colt_matrix.like
139
- @colt_matrix.zMult(matrix.colt_matrix, result)
140
- MDMatrix.from_colt_matrix(result)
141
-
142
- end
143
-
144
- alias :* :mult
145
-
146
- #------------------------------------------------------------------------------------
147
- # Returns the one-norm of vector x, which is Sum(abs(x[i])).
148
- #------------------------------------------------------------------------------------
149
-
150
- def norm1
151
- @algebra.norm1(@colt_matrix)
152
- end
153
-
154
- #------------------------------------------------------------------------------------
155
- # Returns the two-norm of matrix A, which is the maximum singular value; obtained
156
- # from SVD.
157
- #------------------------------------------------------------------------------------
158
-
159
- def norm2
160
- @algebra.norm2(@colt_matrix)
161
- end
162
-
163
- #------------------------------------------------------------------------------------
164
- # Returns the Frobenius norm of matrix A, which is Sqrt(Sum(A[i,j]^2))
165
- #------------------------------------------------------------------------------------
166
-
167
- def normF
168
- @algebra.normF(@colt_matrix)
169
- end
170
-
171
- #------------------------------------------------------------------------------------
172
- # Returns the infinity norm of matrix A, which is the maximum absolute row sum.
173
- #------------------------------------------------------------------------------------
174
-
175
- def norm_infinity
176
- @algebra.normInfinity(@colt_matrix)
177
- end
178
-
179
- #------------------------------------------------------------------------------------
180
- # Linear algebraic matrix power; B = A^k <==> B = A*A*...
181
- #------------------------------------------------------------------------------------
182
-
183
- def power(val)
184
- result = @algebra.pow(@colt_matrix, val)
185
- MDMatrix.from_colt_matrix(result)
186
- end
187
-
188
- alias :** :power
189
-
190
- #------------------------------------------------------------------------------------
191
- # Returns the effective numerical rank of matrix A, obtained from Singular Value
192
- # Decomposition.
193
- #------------------------------------------------------------------------------------
194
-
195
- def numerical_rank
196
- @algebra.rank(@colt_matrix)
197
- end
198
-
199
- #------------------------------------------------------------------------------------
200
- # Solves A*X = B
201
- #------------------------------------------------------------------------------------
202
-
203
- def solve(matrix)
204
- result = @algebra.solve(@colt_matrix, matrix.colt_matrix)
205
- MDMatris.from_colt_matrix(resul)
206
- end
207
-
208
- #------------------------------------------------------------------------------------
209
- # Solves X*A = B, which is also A'*X' = B'.
210
- #------------------------------------------------------------------------------------
211
-
212
- def solve_transpose(matrix)
213
- result = @algebra.solveTranspose(@colt_matrix, matrix.colt_matrix)
214
- MDMatris.from_colt_matrix(resul)
215
- end
216
-
217
- #------------------------------------------------------------------------------------
218
- # Constructs and returns the SingularValue-decomposition of the given matrix.
219
- #------------------------------------------------------------------------------------
220
-
221
- def svd
222
- result = @algebra.svd(@colt_matrix)
223
- [result.getInfo().val, result.cond(), result.norm2(), result.rank(),
224
- result.getSingularValues().to_a(),
225
- MDMatrix.from_colt_matrix(result.getS()),
226
- MDMatrix.from_colt_matrix(result.getU()),
227
- MDMatrix.from_colt_matrix(result.getV())]
228
- end
229
-
230
- #------------------------------------------------------------------------------------
231
- # Returns the sum of the diagonal elements of matrix A; Sum(A[i,i]).
232
- #------------------------------------------------------------------------------------
233
-
234
- def trace
235
- @algebra.trace(@colt_matrix)
236
- end
237
-
238
- #------------------------------------------------------------------------------------
239
- # Modifies the matrix to be a lower trapezoidal matrix.
240
- #------------------------------------------------------------------------------------
241
-
242
- def trapezoidal_lower
243
- result = @algebra.trapezoidalLower(@colt_matrix)
244
- MDMatrix.from_colt_matrix(result)
245
- end
246
-
247
- #------------------------------------------------------------------------------------
248
- # Returns the two-norm (aka euclidean norm) of vector X.vectorize();
249
- #------------------------------------------------------------------------------------
250
-
251
- def vector_norm2
252
- @algebra.vectorNorm2(@colt_matrix)
253
- end
254
-
255
- end #
256
-
257
- ##########################################################################################
258
- #
259
- ##########################################################################################
260
-
261
- module Matrix2DDoubleAlgebra
262
- include_package "cern.colt.matrix.tdouble.algo"
263
-
264
- #------------------------------------------------------------------------------------
265
- # Constructs and returns the QR-decomposition of the given matrix.
266
- #------------------------------------------------------------------------------------
267
-
268
- def qr(economy_size = true)
269
- result = @algebra.qr(@colt_matrix)
270
- [result.hasFullRank(), MDMatrix.from_colt_matrix(result.getQ(economy_size)),
271
- MDMatrix.from_colt_matrix(result.getR(economy_size))]
272
- end
273
-
274
- end
275
-
276
- ##########################################################################################
277
- #
278
- ##########################################################################################
279
-
280
- module Matrix2DFloatAlgebra
281
- include_package "cern.colt.matrix.tfloat.algo"
282
-
283
- #------------------------------------------------------------------------------------
284
- # Constructs and returns the QR-decomposition of the given matrix.
285
- #------------------------------------------------------------------------------------
286
-
287
- def qr
288
- result = @algebra.qr(@colt_matrix)
289
- [result.hasFullRank(),
290
- MDMatrix.from_colt_matrix(result.getH()),
291
- MDMatrix.from_colt_matrix(result.getQ()),
292
- MDMatrix.from_colt_matrix(result.getR())]
293
- end
294
-
295
- end
296
-
297
- ##########################################################################################
298
- #
299
- ##########################################################################################
300
-
301
- class FloatingMDMatrix2D
302
-
303
- include Matrix2DFloatingAlgebra
304
-
305
- end # MDMatrix
306
-
307
- ##########################################################################################
308
- #
309
- ##########################################################################################
310
-
311
- class DoubleMDMatrix2D
312
-
313
- include Matrix2DDoubleAlgebra
314
-
315
- end
316
-
317
- ##########################################################################################
318
- #
319
- ##########################################################################################
320
-
321
- class FloatMDMatrix2D
322
-
323
- include Matrix2DFloatAlgebra
324
-
325
- end