linalg 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +24 -0
  3. data/ext/g2c_typedefs.h +5 -0
  4. data/ext/lapack/extconf.rb +309 -0
  5. data/ext/lapack/include/BLAS.h +154 -0
  6. data/ext/lapack/include/LAPACK.h +1314 -0
  7. data/ext/lapack/main.c +49 -0
  8. data/ext/lapack/rb_lapack.h +36 -0
  9. data/ext/lapack/rb_lapack_c.c +11614 -0
  10. data/ext/lapack/rb_lapack_d.c +12663 -0
  11. data/ext/lapack/rb_lapack_s.c +12649 -0
  12. data/ext/lapack/rb_lapack_x.c +208 -0
  13. data/ext/lapack/rb_lapack_z.c +11614 -0
  14. data/ext/linalg/dcomplex.c +359 -0
  15. data/ext/linalg/dcomplex.h +40 -0
  16. data/ext/linalg/ddata.c +194 -0
  17. data/ext/linalg/extconf.rb +324 -0
  18. data/ext/linalg/linalg.c +55 -0
  19. data/ext/linalg/linalg.h +21 -0
  20. data/ext/linalg/xdata.c +21 -0
  21. data/ext/linalg/xdata.h +33 -0
  22. data/ext/linalg/xmatrix.c.tmpl +1630 -0
  23. data/ext/linalg/xmatrix.h.tmpl +77 -0
  24. data/ext/linalg/xmatrixc.c.tmpl +138 -0
  25. data/ext/linalg/xmatrixr.c.tmpl +130 -0
  26. data/lib/lapack.rb +87 -0
  27. data/lib/linalg.rb +9 -0
  28. data/lib/linalg/dcomplex.rb +17 -0
  29. data/lib/linalg/dmatrix.rb +29 -0
  30. data/lib/linalg/dmatrix/alias.rb +32 -0
  31. data/lib/linalg/dmatrix/cholesky.rb +52 -0
  32. data/lib/linalg/dmatrix/cond.rb +80 -0
  33. data/lib/linalg/dmatrix/det.rb +36 -0
  34. data/lib/linalg/dmatrix/eigen.rb +153 -0
  35. data/lib/linalg/dmatrix/fit.rb +281 -0
  36. data/lib/linalg/dmatrix/inverse.rb +78 -0
  37. data/lib/linalg/dmatrix/lu.rb +120 -0
  38. data/lib/linalg/dmatrix/main.rb +244 -0
  39. data/lib/linalg/dmatrix/norms.rb +88 -0
  40. data/lib/linalg/dmatrix/nullspace.rb +114 -0
  41. data/lib/linalg/dmatrix/qr.rb +129 -0
  42. data/lib/linalg/dmatrix/schur.rb +88 -0
  43. data/lib/linalg/dmatrix/solve.rb +78 -0
  44. data/lib/linalg/dmatrix/svd.rb +125 -0
  45. data/lib/linalg/exception.rb +32 -0
  46. data/lib/linalg/iterators.rb +221 -0
  47. data/lib/linalg/math.rb +23 -0
  48. data/lib/linalg/scomplex.rb +15 -0
  49. data/lib/linalg/version.rb +3 -0
  50. data/lib/linalg/xdata.rb +123 -0
  51. metadata +94 -0
@@ -0,0 +1,32 @@
1
+ #
2
+ # Copyright (c) 2004-2008 by James M. Lawrence
3
+ #
4
+ # See LICENSE
5
+ #
6
+
7
+ module Linalg
8
+ module Exception
9
+
10
+ #
11
+ # The algorithm failed to converge.
12
+ #
13
+ class Diverged < RuntimeError
14
+ end
15
+
16
+ #
17
+ # One or more parameters failed to meet the
18
+ # prerequisite dimensions.
19
+ #
20
+ class DimensionError < RuntimeError
21
+ end
22
+
23
+ #
24
+ # A singular matrix was encountered where a nonsingular one
25
+ # was expected.
26
+ #
27
+ class SingularMatrix < RuntimeError
28
+ end
29
+
30
+ end
31
+ end
32
+
@@ -0,0 +1,221 @@
1
+ #
2
+ # Copyright (c) 2004-2008 by James M. Lawrence
3
+ #
4
+ # See LICENSE
5
+ #
6
+
7
+
8
+ module Linalg
9
+
10
+ #
11
+ # <tt>Enumerable</tt>s and <tt>Enumerable</tt>-like
12
+ # methods for matrices.
13
+ #
14
+ # For blocks which yield <tt>i,j</tt> indexes, the visitation is
15
+ # always in column-major order -- that is, +i+ changes faster than +j+.
16
+ #
17
+ # To visit in row-major order, one would say
18
+ # m.rows.each_with_index { |row, i|
19
+ # row.elems.each_with_index { |e, j|
20
+ # # e == m[i,j]
21
+ # }
22
+ # }
23
+ #
24
+ module Iterators
25
+
26
+ #
27
+ # Common +Enumerable+ for matrices
28
+ #
29
+ class MatrixEnum
30
+ include Enumerable
31
+ def initialize(m)
32
+ @m = m
33
+ end
34
+ end
35
+
36
+ #
37
+ # This class doesn't do much except +yield+ matrix elements.
38
+ #
39
+ class DiagEnum < MatrixEnum
40
+ def each
41
+ min = @m.hsize < @m.vsize ? @m.hsize : @m.vsize
42
+ min.times { |i|
43
+ yield @m[i,i]
44
+ }
45
+ @m
46
+ end
47
+ end
48
+
49
+ #
50
+ # This class doesn't do much except +yield+ matrix elements.
51
+ #
52
+ class ElemEnum < MatrixEnum
53
+ def each
54
+ (0...@m.hsize).each { |j|
55
+ (0...@m.vsize).each { |i|
56
+ yield @m[i,j]
57
+ }
58
+ }
59
+ @m
60
+ end
61
+ end
62
+
63
+ #
64
+ # This class doesn't do much except +yield+ columns.
65
+ #
66
+ class ColumnEnum < MatrixEnum
67
+ def each
68
+ @m.hsize.times { |i|
69
+ yield @m.column(i)
70
+ }
71
+ @m
72
+ end
73
+ end
74
+
75
+ #
76
+ # This class doesn't do much except +yield+ rows.
77
+ #
78
+ class RowEnum < MatrixEnum
79
+ def each
80
+ @m.vsize.times { |i|
81
+ yield @m.row(i)
82
+ }
83
+ @m
84
+ end
85
+ end
86
+
87
+ #
88
+ # Returns an +Enumerable+ of the rows
89
+ #
90
+ def rows
91
+ RowEnum.new(self)
92
+ end
93
+
94
+ #
95
+ # Returns an +Enumerable+ of the columns
96
+ #
97
+ def columns
98
+ ColumnEnum.new(self)
99
+ end
100
+
101
+ #
102
+ # Returns an +Enumerable+ of the matrix elements
103
+ #
104
+ def elems
105
+ ElemEnum.new(self)
106
+ end
107
+
108
+ #
109
+ # Returns an +Enumerable+ of the diagonal elements
110
+ #
111
+ def diags
112
+ DiagEnum.new(self)
113
+ end
114
+
115
+ #
116
+ # Like <tt>Enumerable#each_with_index</tt>, but with an index pair
117
+ #
118
+ def each_with_index # :yields: e, i, j
119
+ (0...hsize).each { |j|
120
+ (0...vsize).each { |i|
121
+ yield self[i,j], i, j
122
+ }
123
+ }
124
+ self
125
+ end
126
+
127
+ #
128
+ # Like <tt>Array#each_index</tt>, but with an index pair
129
+ #
130
+ def each_index
131
+ (0...hsize).each { |j|
132
+ (0...vsize).each { |i|
133
+ yield i, j
134
+ }
135
+ }
136
+ self
137
+ end
138
+
139
+ #
140
+ # Like <tt>Enumerable#map</tt>, but the resultant is a another matrix
141
+ #
142
+ def map # :yields: e
143
+ m = self.class.reserve(self.vsize, self.hsize)
144
+ each_with_index { |e, i, j|
145
+ m[i,j] = yield e
146
+ }
147
+ m
148
+ end
149
+
150
+ #
151
+ # +map+ with an index pair
152
+ #
153
+ def map_with_index # :yields: e, i, j
154
+ m = self.class.reserve(self.vsize, self.hsize)
155
+ each_with_index { |e, i, j|
156
+ m[i,j] = yield e, i, j
157
+ }
158
+ m
159
+ end
160
+
161
+ #
162
+ # In-place +map+
163
+ #
164
+ def map! # :yields: e
165
+ each_with_index { |e, i, j|
166
+ self[i,j] = yield e
167
+ }
168
+ self
169
+ end
170
+
171
+ #
172
+ # In-place +map_with_index+
173
+ #
174
+ def map_with_index! # :yields: e, i, j
175
+ each_with_index { |e, i, j|
176
+ self[i,j] = yield e, i, j
177
+ }
178
+ self
179
+ end
180
+
181
+ #
182
+ # Visit below-diagonal elements, with index pair
183
+ #
184
+ def each_lower_with_index # :yields: e, i, j
185
+ (0...hsize).each { |j|
186
+ ((j+1)...vsize).each { |i|
187
+ yield self[i,j], i, j
188
+ }
189
+ }
190
+ self
191
+ end
192
+
193
+ #
194
+ # Visit above-diagonal elements, with index pair
195
+ #
196
+ def each_upper_with_index # :yields: e, i, j
197
+ (1...hsize).each { |j|
198
+ (0...(j > vsize ? vsize : j)).each { |i|
199
+ yield self[i,j], i, j
200
+ }
201
+ }
202
+ self
203
+ end
204
+
205
+ private
206
+
207
+ # this seems overkill.
208
+ #
209
+ # Like <tt>Enumerable#inject</tt>, but with an index pair
210
+ #
211
+ #def inject_with_index(initial) # :yields: memo, e, i, j
212
+ # res = initial
213
+ # each_with_index { |e, i, j|
214
+ # res = yield res, e, i, j
215
+ # }
216
+ # res
217
+ #end
218
+
219
+ end
220
+ end
221
+
@@ -0,0 +1,23 @@
1
+ #
2
+ # Copyright (c) 2004-2008 by James M. Lawrence
3
+ #
4
+ # See LICENSE
5
+ #
6
+
7
+ module Linalg
8
+ class Math
9
+ extend ::Math
10
+
11
+ def self.min(a, b)
12
+ a < b ? a : b
13
+ end
14
+
15
+ def self.max(a, b)
16
+ a > b ? a : b
17
+ end
18
+
19
+ def self.log2(x)
20
+ ::Math.log(x)/::Math.log(2.0)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ #
2
+ # Copyright (c) 2004-2008 by James M. Lawrence
3
+ #
4
+ # See LICENSE
5
+ #
6
+
7
+ require 'linalg'
8
+
9
+ module Linalg
10
+ class SComplex
11
+ def to_s
12
+ "#{real} + #{imag}i"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Linalg
2
+ VERSION = "1.0.2"
3
+ end
@@ -0,0 +1,123 @@
1
+ #
2
+ # Copyright (c) 2004-2008 by James M. Lawrence
3
+ #
4
+ # See LICENSE
5
+ #
6
+
7
+ require 'linalg'
8
+
9
+ module Linalg
10
+ module XData
11
+
12
+ class NullClass
13
+ def to_doublecomplex_ptr
14
+ 0
15
+ end
16
+
17
+ def to_complex_ptr
18
+ 0
19
+ end
20
+
21
+ def to_doublereal_ptr
22
+ 0
23
+ end
24
+
25
+ def to_real_ptr
26
+ 0
27
+ end
28
+
29
+ def to_integer_ptr
30
+ 0
31
+ end
32
+
33
+ def to_logical_ptr
34
+ 0
35
+ end
36
+
37
+ def to_char_ptr
38
+ 0
39
+ end
40
+
41
+ def to_L_fp
42
+ 0
43
+ end
44
+ end
45
+
46
+ NULL = NullClass.new
47
+
48
+ class DReal < DData
49
+ def initialize(value = 0.0)
50
+ super(1)
51
+ self[0] = value
52
+ end
53
+
54
+ def value
55
+ self[0]
56
+ end
57
+
58
+ def value=(a)
59
+ self[0] = a
60
+ end
61
+ end
62
+
63
+ class SReal < SData
64
+ def initialize(value = 0.0)
65
+ super(1)
66
+ self[0] = value
67
+ end
68
+
69
+ def value
70
+ self[0]
71
+ end
72
+
73
+ def value=(a)
74
+ self[0] = a
75
+ end
76
+ end
77
+
78
+ class XInteger < IData
79
+ def initialize(value = 0)
80
+ super(1)
81
+ self[0] = value
82
+ end
83
+
84
+ def value
85
+ self[0]
86
+ end
87
+
88
+ def value=(a)
89
+ self[0] = a
90
+ end
91
+ end
92
+
93
+ class Logical < LData
94
+ def initialize(value = 0)
95
+ super(1)
96
+ self[0] = value
97
+ end
98
+
99
+ def value
100
+ self[0]
101
+ end
102
+
103
+ def value=(a)
104
+ self[0] = a
105
+ end
106
+ end
107
+
108
+ class Char < CharData
109
+ def initialize(value = "\0")
110
+ super(1)
111
+ self[0] = value
112
+ end
113
+
114
+ def value
115
+ self[0]
116
+ end
117
+
118
+ def value=(a)
119
+ self[0] = a
120
+ end
121
+ end
122
+ end
123
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linalg
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - James M. Lawrence
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Fortran-based linear algebra package
14
+ email:
15
+ - quixoticsycophant@gmail.com
16
+ executables: []
17
+ extensions:
18
+ - ext/lapack/extconf.rb
19
+ - ext/linalg/extconf.rb
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE
23
+ - ext/g2c_typedefs.h
24
+ - ext/lapack/extconf.rb
25
+ - ext/lapack/include/BLAS.h
26
+ - ext/lapack/include/LAPACK.h
27
+ - ext/lapack/main.c
28
+ - ext/lapack/rb_lapack.h
29
+ - ext/lapack/rb_lapack_c.c
30
+ - ext/lapack/rb_lapack_d.c
31
+ - ext/lapack/rb_lapack_s.c
32
+ - ext/lapack/rb_lapack_x.c
33
+ - ext/lapack/rb_lapack_z.c
34
+ - ext/linalg/dcomplex.c
35
+ - ext/linalg/dcomplex.h
36
+ - ext/linalg/ddata.c
37
+ - ext/linalg/extconf.rb
38
+ - ext/linalg/linalg.c
39
+ - ext/linalg/linalg.h
40
+ - ext/linalg/xdata.c
41
+ - ext/linalg/xdata.h
42
+ - ext/linalg/xmatrix.c.tmpl
43
+ - ext/linalg/xmatrix.h.tmpl
44
+ - ext/linalg/xmatrixc.c.tmpl
45
+ - ext/linalg/xmatrixr.c.tmpl
46
+ - lib/lapack.rb
47
+ - lib/linalg.rb
48
+ - lib/linalg/dcomplex.rb
49
+ - lib/linalg/dmatrix.rb
50
+ - lib/linalg/dmatrix/alias.rb
51
+ - lib/linalg/dmatrix/cholesky.rb
52
+ - lib/linalg/dmatrix/cond.rb
53
+ - lib/linalg/dmatrix/det.rb
54
+ - lib/linalg/dmatrix/eigen.rb
55
+ - lib/linalg/dmatrix/fit.rb
56
+ - lib/linalg/dmatrix/inverse.rb
57
+ - lib/linalg/dmatrix/lu.rb
58
+ - lib/linalg/dmatrix/main.rb
59
+ - lib/linalg/dmatrix/norms.rb
60
+ - lib/linalg/dmatrix/nullspace.rb
61
+ - lib/linalg/dmatrix/qr.rb
62
+ - lib/linalg/dmatrix/schur.rb
63
+ - lib/linalg/dmatrix/solve.rb
64
+ - lib/linalg/dmatrix/svd.rb
65
+ - lib/linalg/exception.rb
66
+ - lib/linalg/iterators.rb
67
+ - lib/linalg/math.rb
68
+ - lib/linalg/scomplex.rb
69
+ - lib/linalg/version.rb
70
+ - lib/linalg/xdata.rb
71
+ homepage: http://github.com/quix/linalg
72
+ licenses: []
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 1.3.6
88
+ requirements: []
89
+ rubyforge_project: linalg
90
+ rubygems_version: 2.2.0
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Ruby Linear Algebra Library
94
+ test_files: []