pnmatrix 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/ext/nmatrix/binary_format.txt +53 -0
  3. data/ext/nmatrix/data/complex.h +388 -0
  4. data/ext/nmatrix/data/data.cpp +274 -0
  5. data/ext/nmatrix/data/data.h +651 -0
  6. data/ext/nmatrix/data/meta.h +64 -0
  7. data/ext/nmatrix/data/ruby_object.h +386 -0
  8. data/ext/nmatrix/extconf.rb +70 -0
  9. data/ext/nmatrix/math/asum.h +99 -0
  10. data/ext/nmatrix/math/cblas_enums.h +36 -0
  11. data/ext/nmatrix/math/cblas_templates_core.h +507 -0
  12. data/ext/nmatrix/math/gemm.h +241 -0
  13. data/ext/nmatrix/math/gemv.h +178 -0
  14. data/ext/nmatrix/math/getrf.h +255 -0
  15. data/ext/nmatrix/math/getrs.h +121 -0
  16. data/ext/nmatrix/math/imax.h +82 -0
  17. data/ext/nmatrix/math/laswp.h +165 -0
  18. data/ext/nmatrix/math/long_dtype.h +62 -0
  19. data/ext/nmatrix/math/magnitude.h +54 -0
  20. data/ext/nmatrix/math/math.h +751 -0
  21. data/ext/nmatrix/math/nrm2.h +165 -0
  22. data/ext/nmatrix/math/rot.h +117 -0
  23. data/ext/nmatrix/math/rotg.h +106 -0
  24. data/ext/nmatrix/math/scal.h +71 -0
  25. data/ext/nmatrix/math/trsm.h +336 -0
  26. data/ext/nmatrix/math/util.h +162 -0
  27. data/ext/nmatrix/math.cpp +1368 -0
  28. data/ext/nmatrix/nm_memory.h +60 -0
  29. data/ext/nmatrix/nmatrix.cpp +285 -0
  30. data/ext/nmatrix/nmatrix.h +476 -0
  31. data/ext/nmatrix/ruby_constants.cpp +151 -0
  32. data/ext/nmatrix/ruby_constants.h +106 -0
  33. data/ext/nmatrix/ruby_nmatrix.c +3130 -0
  34. data/ext/nmatrix/storage/common.cpp +77 -0
  35. data/ext/nmatrix/storage/common.h +183 -0
  36. data/ext/nmatrix/storage/dense/dense.cpp +1096 -0
  37. data/ext/nmatrix/storage/dense/dense.h +129 -0
  38. data/ext/nmatrix/storage/list/list.cpp +1628 -0
  39. data/ext/nmatrix/storage/list/list.h +138 -0
  40. data/ext/nmatrix/storage/storage.cpp +730 -0
  41. data/ext/nmatrix/storage/storage.h +99 -0
  42. data/ext/nmatrix/storage/yale/class.h +1139 -0
  43. data/ext/nmatrix/storage/yale/iterators/base.h +143 -0
  44. data/ext/nmatrix/storage/yale/iterators/iterator.h +131 -0
  45. data/ext/nmatrix/storage/yale/iterators/row.h +450 -0
  46. data/ext/nmatrix/storage/yale/iterators/row_stored.h +140 -0
  47. data/ext/nmatrix/storage/yale/iterators/row_stored_nd.h +169 -0
  48. data/ext/nmatrix/storage/yale/iterators/stored_diagonal.h +124 -0
  49. data/ext/nmatrix/storage/yale/math/transpose.h +110 -0
  50. data/ext/nmatrix/storage/yale/yale.cpp +2074 -0
  51. data/ext/nmatrix/storage/yale/yale.h +203 -0
  52. data/ext/nmatrix/types.h +55 -0
  53. data/ext/nmatrix/util/io.cpp +279 -0
  54. data/ext/nmatrix/util/io.h +115 -0
  55. data/ext/nmatrix/util/sl_list.cpp +627 -0
  56. data/ext/nmatrix/util/sl_list.h +144 -0
  57. data/ext/nmatrix/util/util.h +78 -0
  58. data/lib/nmatrix/blas.rb +378 -0
  59. data/lib/nmatrix/cruby/math.rb +744 -0
  60. data/lib/nmatrix/enumerate.rb +253 -0
  61. data/lib/nmatrix/homogeneous.rb +241 -0
  62. data/lib/nmatrix/io/fortran_format.rb +138 -0
  63. data/lib/nmatrix/io/harwell_boeing.rb +221 -0
  64. data/lib/nmatrix/io/market.rb +263 -0
  65. data/lib/nmatrix/io/point_cloud.rb +189 -0
  66. data/lib/nmatrix/jruby/decomposition.rb +24 -0
  67. data/lib/nmatrix/jruby/enumerable.rb +13 -0
  68. data/lib/nmatrix/jruby/error.rb +4 -0
  69. data/lib/nmatrix/jruby/math.rb +501 -0
  70. data/lib/nmatrix/jruby/nmatrix_java.rb +840 -0
  71. data/lib/nmatrix/jruby/operators.rb +283 -0
  72. data/lib/nmatrix/jruby/slice.rb +264 -0
  73. data/lib/nmatrix/lapack_core.rb +181 -0
  74. data/lib/nmatrix/lapack_plugin.rb +44 -0
  75. data/lib/nmatrix/math.rb +953 -0
  76. data/lib/nmatrix/mkmf.rb +100 -0
  77. data/lib/nmatrix/monkeys.rb +137 -0
  78. data/lib/nmatrix/nmatrix.rb +1172 -0
  79. data/lib/nmatrix/rspec.rb +75 -0
  80. data/lib/nmatrix/shortcuts.rb +1163 -0
  81. data/lib/nmatrix/version.rb +39 -0
  82. data/lib/nmatrix/yale_functions.rb +118 -0
  83. data/lib/nmatrix.rb +28 -0
  84. data/spec/00_nmatrix_spec.rb +892 -0
  85. data/spec/01_enum_spec.rb +196 -0
  86. data/spec/02_slice_spec.rb +407 -0
  87. data/spec/03_nmatrix_monkeys_spec.rb +80 -0
  88. data/spec/2x2_dense_double.mat +0 -0
  89. data/spec/4x4_sparse.mat +0 -0
  90. data/spec/4x5_dense.mat +0 -0
  91. data/spec/blas_spec.rb +215 -0
  92. data/spec/elementwise_spec.rb +311 -0
  93. data/spec/homogeneous_spec.rb +100 -0
  94. data/spec/io/fortran_format_spec.rb +88 -0
  95. data/spec/io/harwell_boeing_spec.rb +98 -0
  96. data/spec/io/test.rua +9 -0
  97. data/spec/io_spec.rb +159 -0
  98. data/spec/lapack_core_spec.rb +482 -0
  99. data/spec/leakcheck.rb +16 -0
  100. data/spec/math_spec.rb +1363 -0
  101. data/spec/nmatrix_yale_resize_test_associations.yaml +2802 -0
  102. data/spec/nmatrix_yale_spec.rb +286 -0
  103. data/spec/rspec_monkeys.rb +56 -0
  104. data/spec/rspec_spec.rb +35 -0
  105. data/spec/shortcuts_spec.rb +474 -0
  106. data/spec/slice_set_spec.rb +162 -0
  107. data/spec/spec_helper.rb +172 -0
  108. data/spec/stat_spec.rb +214 -0
  109. data/spec/test.pcd +20 -0
  110. data/spec/utm5940.mtx +83844 -0
  111. metadata +295 -0
@@ -0,0 +1,181 @@
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
+ # == lapack_core.rb
25
+ #
26
+ # This file contains friendlier interfaces to LAPACK functions
27
+ # implemented in C.
28
+ # This file is only for functions available with the core nmatrix gem
29
+ # (no external libraries needed).
30
+ #
31
+ # Note: most of these functions are borrowed from ATLAS, which is available under a BSD-
32
+ # style license.
33
+ #++
34
+
35
+ class NMatrix
36
+
37
+ module LAPACK
38
+
39
+ #Add functions from C extension to main LAPACK module
40
+ class << self
41
+ NMatrix::Internal::LAPACK.singleton_methods.each do |m|
42
+ define_method m, NMatrix::Internal::LAPACK.method(m).to_proc
43
+ end
44
+ end
45
+
46
+ class << self
47
+ # Solve the matrix equation AX = B, where A is a symmetric (or Hermitian)
48
+ # positive-definite matrix. If A is a nxn matrix, B must be mxn.
49
+ # Depending on the value of uplo, only the upper or lower half of +a+
50
+ # is read.
51
+ # This uses the Cholesky decomposition so it should be faster than
52
+ # the generic NMatrix#solve method.
53
+ # Doesn't modify inputs.
54
+ # Requires either the nmatrix-atlas or nmatrix-lapacke gem.
55
+ # * *Arguments* :
56
+ # - +uplo+ -> Either +:upper+ or +:lower+. Specifies which half of +a+ to read.
57
+ # - +a+ -> The matrix A.
58
+ # - +b+ -> The right-hand side B.
59
+ # * *Returns* :
60
+ # - The solution X
61
+ def posv(uplo, a, b)
62
+ raise(NotImplementedError, "Either the nmatrix-atlas or nmatrix-lapacke gem must be installed to use posv")
63
+ end
64
+
65
+ # laswp(matrix, ipiv) -> NMatrix
66
+ #
67
+ # Permute the columns of a matrix (in-place) according to the Array +ipiv+.
68
+ #
69
+ def laswp(matrix, ipiv)
70
+ raise(ArgumentError, "expected NMatrix for argument 0") unless matrix.is_a?(NMatrix)
71
+ raise(StorageTypeError, "LAPACK functions only work on :dense NMatrix instances") unless matrix.stype == :dense
72
+ raise(ArgumentError, "expected Array ipiv to have no more entries than NMatrix a has columns") if ipiv.size > matrix.shape[1]
73
+
74
+ clapack_laswp(matrix.shape[0], matrix, matrix.shape[1], 0, ipiv.size-1, ipiv, 1)
75
+ end
76
+
77
+ def alloc_svd_result(matrix)
78
+ [
79
+ NMatrix.new(matrix.shape[0], dtype: matrix.dtype),
80
+ NMatrix.new([[matrix.shape[0],matrix.shape[1]].min,1], dtype: matrix.abs_dtype),
81
+ NMatrix.new(matrix.shape[1], dtype: matrix.dtype)
82
+ ]
83
+ end
84
+
85
+
86
+ #
87
+ # call-seq:
88
+ # gesvd(matrix) -> [u, sigma, v_transpose]
89
+ # gesvd(matrix) -> [u, sigma, v_conjugate_transpose] # complex
90
+ #
91
+ # Compute the singular value decomposition of a matrix using LAPACK's GESVD function.
92
+ #
93
+ # Optionally accepts a +workspace_size+ parameter, which will be honored only if it is larger than what LAPACK
94
+ # requires.
95
+ #
96
+ # Requires either the nmatrix-lapacke or nmatrix-atlas gem.
97
+ #
98
+ def gesvd(matrix, workspace_size=1)
99
+ raise(NotImplementedError,"gesvd requires either the nmatrix-atlas or nmatrix-lapacke gem")
100
+ end
101
+
102
+ #
103
+ # call-seq:
104
+ # gesdd(matrix) -> [u, sigma, v_transpose]
105
+ # gesdd(matrix) -> [u, sigma, v_conjugate_transpose] # complex
106
+ #
107
+ # Compute the singular value decomposition of a matrix using LAPACK's GESDD function. This uses a divide-and-conquer
108
+ # strategy. See also #gesvd.
109
+ #
110
+ # Optionally accepts a +workspace_size+ parameter, which will be honored only if it is larger than what LAPACK
111
+ # requires.
112
+ #
113
+ # Requires either the nmatrix-lapacke or nmatrix-atlas gem.
114
+ #
115
+ def gesdd(matrix, workspace_size=nil)
116
+ raise(NotImplementedError,"gesvd requires either the nmatrix-atlas or nmatrix-lapacke gem")
117
+ end
118
+
119
+ #
120
+ # call-seq:
121
+ # geev(matrix) -> [eigenvalues, left_eigenvectors, right_eigenvectors]
122
+ # geev(matrix, :left) -> [eigenvalues, left_eigenvectors]
123
+ # geev(matrix, :right) -> [eigenvalues, right_eigenvectors]
124
+ #
125
+ # Perform eigenvalue decomposition on a matrix using LAPACK's xGEEV function.
126
+ #
127
+ # +eigenvalues+ is a n-by-1 NMatrix containing the eigenvalues.
128
+ #
129
+ # +right_eigenvalues+ is a n-by-n matrix such that its j'th column
130
+ # contains the (right) eigenvalue of +matrix+ corresponding
131
+ # to the j'th eigenvalue.
132
+ # This means that +matrix+ = RDR^(-1),
133
+ # where R is +right_eigenvalues+ and D is the diagonal matrix formed
134
+ # from +eigenvalues+.
135
+ #
136
+ # +left_eigenvalues+ is n-by-n and its columns are the left
137
+ # eigenvalues of +matrix+, using the {definition of left eigenvalue
138
+ # from LAPACK}[https://software.intel.com/en-us/node/521147].
139
+ #
140
+ # For real dtypes, +eigenvalues+ and the eigenvector matrices
141
+ # will be complex if and only if +matrix+ has complex eigenvalues.
142
+ #
143
+ # Only available if nmatrix-lapack or nmatrix-atlas is installed.
144
+ #
145
+ def geev(matrix, which=:both)
146
+ raise(NotImplementedError, "geev requires either the nmatrix-atlas or nmatrix-lapack gem")
147
+ end
148
+
149
+ # The following are functions that used to be implemented in C, but
150
+ # now require nmatrix-atlas to run properly, so we can just
151
+ # implemented their stubs in Ruby.
152
+ def lapack_gesvd(jobu, jobvt, m, n, a, lda, s, u, ldu, vt, ldvt, lwork)
153
+ raise(NotImplementedError,"lapack_gesvd requires the nmatrix-atlas gem")
154
+ end
155
+
156
+ def lapack_gesdd(jobz, m, n, a, lda, s, u, ldu, vt, ldvt, lwork)
157
+ raise(NotImplementedError,"lapack_gesdd requires the nmatrix-atlas gem")
158
+ end
159
+
160
+ def lapack_geev(jobvl, jobvr, n, a, lda, w, wi, vl, ldvl, vr, ldvr, lwork)
161
+ raise(NotImplementedError,"lapack_geev requires the nmatrix-atlas gem")
162
+ end
163
+
164
+ def clapack_potrf(order, uplo, n, a, lda)
165
+ raise(NotImplementedError,"clapack_potrf requires the nmatrix-atlas gem")
166
+ end
167
+
168
+ def clapack_potri(order, uplo, n, a, lda)
169
+ raise(NotImplementedError,"clapack_potri requires the nmatrix-atlas gem")
170
+ end
171
+
172
+ def clapack_potrs(order, uplo, n, nrhs, a, lda, b, ldb)
173
+ raise(NotImplementedError,"clapack_potrs requires the nmatrix-atlas gem")
174
+ end
175
+
176
+ def clapack_getri(order, n, a, lda, ipiv)
177
+ raise(NotImplementedError,"clapack_getri requires the nmatrix-atlas gem")
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,44 @@
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
+ # == lapack_plugin.rb
25
+ #
26
+ # This file `require`s either nmatrix-atlas or nmatrix-lapacke depending on which
27
+ # is available.
28
+ #
29
+ # The idea is that if a developer wants to use a LAPACK feature which is provided
30
+ # by both of these gems (e.g. NMatrix#potrf! or NMatrix::LAPACK.geev),
31
+ # but doesn't care which one is installed, they can
32
+ # just `require 'nmatrix/lapack_plugin'` rather than having to choose between
33
+ # `require 'nmatrix/lapacke'` or `require 'nmatrix/lapacke'`
34
+ #++
35
+
36
+ begin
37
+ require 'nmatrix/atlas'
38
+ rescue LoadError
39
+ begin
40
+ require 'nmatrix/lapacke'
41
+ rescue LoadError
42
+ raise(LoadError,"Either nmatrix-atlas or nmatrix-lapacke must be installed")
43
+ end
44
+ end