nmatrix 0.1.0.rc3 → 0.1.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +22 -21
  3. data/History.txt +13 -0
  4. data/Manifest.txt +1 -2
  5. data/README.rdoc +8 -8
  6. data/ext/nmatrix/binary_format.txt +1 -1
  7. data/ext/nmatrix/data/complex.h +21 -21
  8. data/ext/nmatrix/data/data.cpp +9 -2
  9. data/ext/nmatrix/data/data.h +4 -2
  10. data/ext/nmatrix/math.cpp +69 -31
  11. data/ext/nmatrix/math/getf2.h +2 -2
  12. data/ext/nmatrix/math/getrf.h +2 -2
  13. data/ext/nmatrix/math/imax.h +101 -0
  14. data/ext/nmatrix/math/scal.h +30 -10
  15. data/ext/nmatrix/math/swap.h +1 -22
  16. data/ext/nmatrix/nm_memory.h +1 -1
  17. data/ext/nmatrix/nmatrix.h +2 -2
  18. data/ext/nmatrix/ruby_constants.cpp +1 -2
  19. data/ext/nmatrix/ruby_constants.h +6 -7
  20. data/ext/nmatrix/ruby_nmatrix.c +23 -18
  21. data/ext/nmatrix/storage/list/list.cpp +48 -47
  22. data/ext/nmatrix/util/io.cpp +2 -2
  23. data/lib/nmatrix.rb +0 -1
  24. data/lib/nmatrix/enumerate.rb +1 -1
  25. data/lib/nmatrix/io/market.rb +1 -1
  26. data/lib/nmatrix/io/mat_reader.rb +41 -41
  27. data/lib/nmatrix/lapack.rb +0 -1
  28. data/lib/nmatrix/math.rb +43 -0
  29. data/lib/nmatrix/nmatrix.rb +5 -1
  30. data/lib/nmatrix/version.rb +1 -1
  31. data/nmatrix.gemspec +3 -4
  32. data/spec/00_nmatrix_spec.rb +13 -6
  33. data/spec/01_enum_spec.rb +17 -25
  34. data/spec/02_slice_spec.rb +74 -82
  35. data/spec/blas_spec.rb +21 -6
  36. data/spec/elementwise_spec.rb +1 -6
  37. data/spec/io_spec.rb +15 -22
  38. data/spec/lapack_spec.rb +1 -6
  39. data/spec/leakcheck.rb +1 -1
  40. data/spec/math_spec.rb +43 -4
  41. data/spec/nmatrix_yale_spec.rb +1 -4
  42. data/spec/rspec_spec.rb +1 -1
  43. data/spec/shortcuts_spec.rb +1 -6
  44. data/spec/slice_set_spec.rb +1 -5
  45. data/spec/stat_spec.rb +46 -51
  46. metadata +32 -22
  47. data/Guardfile +0 -6
  48. data/ext/nmatrix/math/idamax.h +0 -86
  49. data/lib/nmatrix/nvector.rb +0 -184
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nmatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc3
4
+ version: 0.1.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Woods
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-03-27 00:00:00.000000000 Z
13
+ date: 2014-07-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdoc
@@ -58,30 +58,30 @@ dependencies:
58
58
  name: rspec
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - '>='
61
+ - - ~>
62
62
  - !ruby/object:Gem::Version
63
- version: '0'
63
+ version: 2.14.1
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - '>='
68
+ - - ~>
69
69
  - !ruby/object:Gem::Version
70
- version: '0'
70
+ version: 2.14.1
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec-longrun
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - '>='
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: 1.0.1
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - '>='
82
+ - - ~>
83
83
  - !ruby/object:Gem::Version
84
- version: '0'
84
+ version: 1.0.1
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: pry
87
87
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +124,6 @@ files:
124
124
  - .travis.yml
125
125
  - CONTRIBUTING.md
126
126
  - Gemfile
127
- - Guardfile
128
127
  - History.txt
129
128
  - LICENSE.txt
130
129
  - Manifest.txt
@@ -150,7 +149,7 @@ files:
150
149
  - ext/nmatrix/math/getrf.h
151
150
  - ext/nmatrix/math/getri.h
152
151
  - ext/nmatrix/math/getrs.h
153
- - ext/nmatrix/math/idamax.h
152
+ - ext/nmatrix/math/imax.h
154
153
  - ext/nmatrix/math/inc.h
155
154
  - ext/nmatrix/math/laswp.h
156
155
  - ext/nmatrix/math/long_dtype.h
@@ -204,7 +203,6 @@ files:
204
203
  - lib/nmatrix/math.rb
205
204
  - lib/nmatrix/monkeys.rb
206
205
  - lib/nmatrix/nmatrix.rb
207
- - lib/nmatrix/nvector.rb
208
206
  - lib/nmatrix/rspec.rb
209
207
  - lib/nmatrix/shortcuts.rb
210
208
  - lib/nmatrix/version.rb
@@ -238,15 +236,27 @@ homepage: http://sciruby.com
238
236
  licenses:
239
237
  - BSD 2-clause
240
238
  metadata: {}
241
- post_install_message: "***********************************************************\nWelcome
242
- to SciRuby: Tools for Scientific Computing in Ruby!\n\nNMatrix requires a C compiler,
243
- and has been tested only\nwith GCC 4.6+. We are happy to accept contributions\nwhich
244
- improve the portability of this project.\n\nAlso required is ATLAS. Most Linux distributions
245
- and Mac\nversions include ATLAS, but you may wish to compile it\nyourself. The Ubuntu/Debian
246
- apt package for ATLAS WILL \nNOT WORK with NMatrix if LAPACK is also installed.\n\nMore
247
- explicit instructions for NMatrix and SciRuby should\nbe available on the SciRuby
248
- website, sciruby.com, or\nthrough our mailing list (which can be found on our web-\nsite).\n\nThanks
249
- for trying out NMatrix! Happy coding!\n\n***********************************************************\n"
239
+ post_install_message: |
240
+ ***********************************************************
241
+ Welcome to SciRuby: Tools for Scientific Computing in Ruby!
242
+
243
+ NMatrix requires a C compiler, and has been tested only
244
+ with GCC 4.6+. We are happy to accept contributions
245
+ which improve the portability of this project.
246
+
247
+ Also required is ATLAS. Most Linux distributions and Mac
248
+ versions include ATLAS, but you may wish to compile it
249
+ yourself. The Ubuntu/Debian apt package for ATLAS WILL
250
+ NOT WORK with NMatrix if LAPACK is also installed.
251
+
252
+ More explicit instructions for NMatrix and SciRuby should
253
+ be available on the SciRuby website, sciruby.com, or
254
+ through our mailing list (which can be found on our web-
255
+ site).
256
+
257
+ Thanks for trying out NMatrix! Happy coding!
258
+
259
+ ***********************************************************
250
260
  rdoc_options: []
251
261
  require_paths:
252
262
  - lib
data/Guardfile DELETED
@@ -1,6 +0,0 @@
1
- guard 'rspec' do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { "spec" }
4
- watch(%r{^ext/nmatrix/(.+)\.(c|cpp|h|rb)$}) { `rake compile | rake spec` }
5
- watch('spec/spec_helper.rb') { "spec" }
6
- end
@@ -1,86 +0,0 @@
1
- /////////////////////////////////////////////////////////////////////
2
- // = NMatrix
3
- //
4
- // A linear algebra library for scientific computation in Ruby.
5
- // NMatrix is part of SciRuby.
6
- //
7
- // NMatrix was originally inspired by and derived from NArray, by
8
- // Masahiro Tanaka: http://narray.rubyforge.org
9
- //
10
- // == Copyright Information
11
- //
12
- // SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation
13
- // NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation
14
- //
15
- // Please see LICENSE.txt for additional copyright notices.
16
- //
17
- // == Contributing
18
- //
19
- // By contributing source code to SciRuby, you agree to be bound by
20
- // our Contributor Agreement:
21
- //
22
- // * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
23
- //
24
- // == idamax.h
25
- //
26
- // LAPACK idamax function in native C.
27
- //
28
-
29
- #ifndef IDAMAX_H
30
- #define IDAMAX_H
31
-
32
- namespace nm { namespace math {
33
-
34
- /* Purpose */
35
- /* ======= */
36
-
37
- /* IDAMAX finds the index of element having max. absolute value. */
38
-
39
- /* Further Details */
40
- /* =============== */
41
-
42
- /* jack dongarra, linpack, 3/11/78. */
43
- /* modified 3/93 to return if incx .le. 0. */
44
- /* modified 12/3/93, array(1) declarations changed to array(*) */
45
-
46
- /* ===================================================================== */
47
-
48
- template <typename DType>
49
- inline int idamax(size_t n, DType *dx, int incx) {
50
-
51
- /* Function Body */
52
- if (n < 1 || incx <= 0) return -1;
53
- if (n == 1) return 0;
54
-
55
- DType dmax;
56
- size_t imax = 0;
57
-
58
- if (incx == 1) { // if incrementing by 1
59
-
60
- dmax = abs(dx[0]);
61
-
62
- for (size_t i = 1; i < n; ++i) {
63
- if (std::abs(dx[i]) > dmax) {
64
- imax = i;
65
- dmax = std::abs(dx[i]);
66
- }
67
- }
68
-
69
- } else { // if incrementing by more than 1
70
-
71
- dmax = std::abs(dx[0]);
72
-
73
- for (size_t i = 1, ix = incx; i < n; ++i, ix += incx) {
74
- if (std::abs(dx[ix]) > dmax) {
75
- imax = i;
76
- dmax = std::abs(dx[ix]);
77
- }
78
- }
79
- }
80
- return imax;
81
- } /* idamax_ */
82
-
83
- }} // end of namespace nm::math
84
-
85
- #endif
86
-
@@ -1,184 +0,0 @@
1
- #--
2
- # = NMatrix
3
- #
4
- # A linear algebra library for scientific computation in Ruby.
5
- # NMatrix is part of SciRuby.
6
- #
7
- # NMatrix was originally inspired by and derived from NArray, by
8
- # Masahiro Tanaka: http://narray.rubyforge.org
9
- #
10
- # == Copyright Information
11
- #
12
- # SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation
13
- # NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation
14
- #
15
- # Please see LICENSE.txt for additional copyright notices.
16
- #
17
- # == Contributing
18
- #
19
- # By contributing source code to SciRuby, you agree to be bound by
20
- # our Contributor Agreement:
21
- #
22
- # * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
23
- #
24
- # == nmatrix.rb
25
- #
26
- # This file defines the NVector class.
27
- #++
28
-
29
- # This is a specific type of NMatrix in which only one dimension is not 1.
30
- # Although it is stored as a dim-2, n x 1, matrix, it acts as a dim-1 vector
31
- # of size n. If the @orientation flag is set to :column, it is stored as n x 1
32
- # instead of 1 x n.
33
- class NVector < NMatrix
34
- #
35
- # call-seq:
36
- # new(shape) -> NVector
37
- # new(stype, shape) -> NVector
38
- # new(shape, init) -> NVector
39
- # new(:dense, shape, init) -> NVector
40
- # new(:list, shape, init) -> NVector
41
- # new(shape, init, dtype) -> NVector
42
- # new(stype, shape, init, dtype) -> NVector
43
- # new(stype, shape, dtype) -> NVector
44
- #
45
- # Creates a new NVector. See also NMatrix#initialize for a more detailed explanation of
46
- # the arguments.
47
- #
48
- # * *Arguments* :
49
- # - +stype+ -> (optional) Storage type of the vector (:list, :dense, :yale). Defaults to :dense.
50
- # - +shape+ -> Shape of the vector. Accepts [n,1], [1,n], or n, where n is a Fixnum.
51
- # - +init+ -> (optional) Yale: capacity; List: default value (0); Dense: initial value or values (uninitialized by default).
52
- # - +dtype+ -> (optional if +init+ provided) Data type stored in the vector. For :dense and :list, can be inferred from +init+.
53
- # * *Returns* :
54
- # -
55
- #
56
- def initialize(*args)
57
- stype = args[0].is_a?(Symbol) ? args.shift : :dense
58
- shape = args[0].is_a?(Array) ? args.shift : [1,args.shift]
59
-
60
- if shape.size != 2 || !shape.include?(1) || shape == [1,1]
61
- raise(ArgumentError, "shape must be a Fixnum or an Array of positive Fixnums where exactly one value is 1")
62
- end
63
-
64
- warn "NVector is deprecated"
65
-
66
- super(stype, shape, *args)
67
- end
68
-
69
-
70
- #
71
- # call-seq:
72
- # orientation -> Symbol
73
- #
74
- # Orientation defaults to row (e.g., [1,3] is a row of length 3). It
75
- # may also be column, e.g., for [5,1].
76
- #
77
- def orientation
78
- shape[0] == 1 ? :row : :column
79
- end
80
-
81
- # Override NMatrix#each_row and #each_column
82
- def each_column(get_by=:reference, &block) #:nodoc:
83
- shape[0] == 1 ? self.each(&block) : (yield self)
84
- end
85
- def each_row(get_by=:reference, &block) #:nodoc:
86
- shape[0] == 1 ? (yield self) : self.each(&block)
87
- end
88
-
89
-
90
-
91
- #
92
- # call-seq:
93
- # vector[index] -> element
94
- # vector[range] -> NVector
95
- #
96
- # Retrieves an element or return a slice.
97
- #
98
- # Examples:
99
- #
100
- # u = NVector.new(3, [10, 20, 30])
101
- # u[0] # => 10
102
- # u[0] + u[1] # => 30
103
- # u[0 .. 1].shape # => [2, 1]
104
- #
105
- def [](i)
106
- shape[0] == 1 ? super(0, i) : super(i, 0)
107
- end
108
-
109
- #
110
- # call-seq:
111
- # vector[index] = obj -> obj
112
- #
113
- # Stores +value+ at position +index+.
114
- #
115
- def []=(i, val)
116
- shape[0] == 1 ? super(0, i, val) : super(i, 0, val)
117
- end
118
-
119
- #
120
- # call-seq:
121
- # dim -> 1
122
- #
123
- # Returns the dimension of a vector, which is 1.
124
- #
125
- def dim; 1; end
126
-
127
- #
128
- # call-seq:
129
- # size -> Fixnum
130
- #
131
- # Shorthand for the dominant shape component
132
- def size
133
- shape[0] > 1 ? shape[0] : shape[1]
134
- end
135
-
136
- #
137
- # call-seq:
138
- # max -> Numeric
139
- #
140
- # Return the maximum element.
141
- def max
142
- max_so_far = self[0]
143
- self.each do |x|
144
- max_so_far = x if x > max_so_far
145
- end
146
- max_so_far
147
- end
148
-
149
- #
150
- # call-seq:
151
- # min -> Numeric
152
- #
153
- # Return the minimum element.
154
- def min
155
- min_so_far = self[0]
156
- self.each do |x|
157
- min_so_far = x if x < min_so_far
158
- end
159
- min_so_far
160
- end
161
-
162
-
163
- # TODO: Make this actually pretty.
164
- def pretty_print(q = nil) #:nodoc:
165
- dimen = shape[0] == 1 ? 1 : 0
166
-
167
- arr = (0...shape[dimen]).inject(Array.new){ |a, i| a << self[i] }
168
-
169
- if q.nil?
170
- puts "[" + arr.join("\n") + "]"
171
- else
172
- q.group(1, "", "\n") do
173
- q.seplist(arr, lambda { q.text " " }, :each) { |v| q.text v.to_s }
174
- end
175
- end
176
- end
177
-
178
- def inspect #:nodoc:
179
- original_inspect = super()
180
- original_inspect = original_inspect[0...original_inspect.size-1]
181
- original_inspect += " orientation:#{self.orientation}>"
182
- end
183
-
184
- end