nmatrix 0.0.1 → 0.0.2

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 (91) hide show
  1. data/.gitignore +27 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +3 -5
  4. data/Guardfile +6 -0
  5. data/History.txt +33 -0
  6. data/Manifest.txt +41 -38
  7. data/README.rdoc +88 -11
  8. data/Rakefile +35 -53
  9. data/ext/nmatrix/data/complex.h +372 -0
  10. data/ext/nmatrix/data/data.cpp +275 -0
  11. data/ext/nmatrix/data/data.h +707 -0
  12. data/ext/nmatrix/data/rational.h +421 -0
  13. data/ext/nmatrix/data/ruby_object.h +446 -0
  14. data/ext/nmatrix/extconf.rb +101 -51
  15. data/ext/nmatrix/new_extconf.rb +56 -0
  16. data/ext/nmatrix/nmatrix.cpp +1609 -0
  17. data/ext/nmatrix/nmatrix.h +265 -849
  18. data/ext/nmatrix/ruby_constants.cpp +134 -0
  19. data/ext/nmatrix/ruby_constants.h +103 -0
  20. data/ext/nmatrix/storage/common.cpp +70 -0
  21. data/ext/nmatrix/storage/common.h +170 -0
  22. data/ext/nmatrix/storage/dense.cpp +665 -0
  23. data/ext/nmatrix/storage/dense.h +116 -0
  24. data/ext/nmatrix/storage/list.cpp +1088 -0
  25. data/ext/nmatrix/storage/list.h +129 -0
  26. data/ext/nmatrix/storage/storage.cpp +658 -0
  27. data/ext/nmatrix/storage/storage.h +99 -0
  28. data/ext/nmatrix/storage/yale.cpp +1601 -0
  29. data/ext/nmatrix/storage/yale.h +208 -0
  30. data/ext/nmatrix/ttable_helper.rb +126 -0
  31. data/ext/nmatrix/{yale/smmp1_header.template.c → types.h} +36 -9
  32. data/ext/nmatrix/util/io.cpp +295 -0
  33. data/ext/nmatrix/util/io.h +117 -0
  34. data/ext/nmatrix/util/lapack.h +1175 -0
  35. data/ext/nmatrix/util/math.cpp +557 -0
  36. data/ext/nmatrix/util/math.h +1363 -0
  37. data/ext/nmatrix/util/sl_list.cpp +475 -0
  38. data/ext/nmatrix/util/sl_list.h +255 -0
  39. data/ext/nmatrix/util/util.h +78 -0
  40. data/lib/nmatrix/blas.rb +70 -0
  41. data/lib/nmatrix/io/mat5_reader.rb +567 -0
  42. data/lib/nmatrix/io/mat_reader.rb +162 -0
  43. data/lib/{string.rb → nmatrix/monkeys.rb} +49 -2
  44. data/lib/nmatrix/nmatrix.rb +199 -0
  45. data/lib/nmatrix/nvector.rb +103 -0
  46. data/lib/nmatrix/version.rb +27 -0
  47. data/lib/nmatrix.rb +22 -230
  48. data/nmatrix.gemspec +59 -0
  49. data/scripts/mac-brew-gcc.sh +47 -0
  50. data/spec/4x4_sparse.mat +0 -0
  51. data/spec/4x5_dense.mat +0 -0
  52. data/spec/blas_spec.rb +47 -0
  53. data/spec/elementwise_spec.rb +164 -0
  54. data/spec/io_spec.rb +60 -0
  55. data/spec/lapack_spec.rb +52 -0
  56. data/spec/math_spec.rb +96 -0
  57. data/spec/nmatrix_spec.rb +93 -89
  58. data/spec/nmatrix_yale_spec.rb +52 -36
  59. data/spec/nvector_spec.rb +1 -1
  60. data/spec/slice_spec.rb +257 -0
  61. data/spec/spec_helper.rb +51 -0
  62. data/spec/utm5940.mtx +83844 -0
  63. metadata +113 -71
  64. data/.autotest +0 -23
  65. data/.gemtest +0 -0
  66. data/ext/nmatrix/cblas.c +0 -150
  67. data/ext/nmatrix/dense/blas_header.template.c +0 -52
  68. data/ext/nmatrix/dense/elementwise.template.c +0 -107
  69. data/ext/nmatrix/dense/gemm.template.c +0 -159
  70. data/ext/nmatrix/dense/gemv.template.c +0 -130
  71. data/ext/nmatrix/dense/rationalmath.template.c +0 -68
  72. data/ext/nmatrix/dense.c +0 -307
  73. data/ext/nmatrix/depend +0 -18
  74. data/ext/nmatrix/generator/syntax_tree.rb +0 -481
  75. data/ext/nmatrix/generator.rb +0 -594
  76. data/ext/nmatrix/list.c +0 -774
  77. data/ext/nmatrix/nmatrix.c +0 -1977
  78. data/ext/nmatrix/rational.c +0 -98
  79. data/ext/nmatrix/yale/complexmath.template.c +0 -71
  80. data/ext/nmatrix/yale/elementwise.template.c +0 -46
  81. data/ext/nmatrix/yale/elementwise_op.template.c +0 -73
  82. data/ext/nmatrix/yale/numbmm.template.c +0 -94
  83. data/ext/nmatrix/yale/smmp1.template.c +0 -21
  84. data/ext/nmatrix/yale/smmp2.template.c +0 -43
  85. data/ext/nmatrix/yale/smmp2_header.template.c +0 -46
  86. data/ext/nmatrix/yale/sort_columns.template.c +0 -56
  87. data/ext/nmatrix/yale/symbmm.template.c +0 -54
  88. data/ext/nmatrix/yale/transp.template.c +0 -68
  89. data/ext/nmatrix/yale.c +0 -726
  90. data/lib/array.rb +0 -67
  91. data/spec/syntax_tree_spec.rb +0 -46
data/.gitignore ADDED
@@ -0,0 +1,27 @@
1
+ .idea
2
+ Gemfile.lock
3
+ ext/nmatrix/dense/daxpy.c
4
+ ext/nmatrix/dense/dgeco.c
5
+ ext/nmatrix/dense/dgefa.c
6
+ ext/nmatrix/dense/dgemm.c
7
+ ext/nmatrix/dense/dgemv.c
8
+ ext/nmatrix/dense/dscal.c
9
+ ext/nmatrix/dense/idamax.c
10
+ ext/nmatrix/dense/467.c
11
+ ext/nmatrix/dense/*.f
12
+ ext/nmatrix/dense/transpose.txt
13
+ ext/nmatrix/yale/aicm.tex
14
+ tmp/
15
+ test.c
16
+ spec/*.mtx
17
+ *.so
18
+ /tags
19
+ *.gem
20
+
21
+ ext/nmatrix/*.o
22
+ ext/nmatrix/*.so
23
+ ext/nmatrix/*.log
24
+ ext/nmatrix/**/*.o
25
+ ext/nmatrix/Makefile
26
+ ext/nmatrix/**/Makefile
27
+ ext/nmatrix/nmatrix_config.h
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  # Gemfile
2
+ source "http://rubygems.org"
3
+ gemspec
2
4
 
3
- gem "rake", "!= 0.9.0"
4
-
5
- group :development, :test do
6
- gem "rspec"
7
- end
5
+ gem 'packable' # for Matlab IO
data/Guardfile ADDED
@@ -0,0 +1,6 @@
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
data/History.txt CHANGED
@@ -4,3 +4,36 @@
4
4
 
5
5
  * Initial alpha release
6
6
 
7
+ === 0.0.2 / 2012-09-21
8
+
9
+ * Numerous major enhancements
10
+
11
+ * Second alpha release
12
+
13
+ * Rewrote NMatrix in C++0x and C++11 using templates, namespaces; removed Ruby generators and CAST parser
14
+
15
+ * Added preliminary C API
16
+
17
+ * Slicing and referencing support for dense and list matrices
18
+
19
+ * BLAS level-3 xTRSM algorithm added for rationals and BLAS types
20
+
21
+ * LAPACK support added, including partially working xGETRF subroutine
22
+
23
+ * Element-wise comparisons now return byte-matrices
24
+
25
+ * Element-wise operations on list matrices may alter the default value of the return matrix
26
+
27
+ * Element-wise division behaves like Ruby division
28
+
29
+ * Improved MATLAB .MAT v5 file reading
30
+
31
+ * clang support
32
+
33
+ * `==` operator now used for matrix equality, `=~` and `!~` for element-wise comparisons
34
+
35
+ * Dense `each` returns an Enumerator when called without a block
36
+
37
+ * Sped up list storage item deletion, fixed bugs
38
+
39
+ * Note: Element-wise list operations current disabled
data/Manifest.txt CHANGED
@@ -1,51 +1,54 @@
1
- .autotest
2
1
  History.txt
3
2
  Manifest.txt
4
3
  README.rdoc
5
4
  LICENSE.txt
6
5
  Rakefile
7
6
  Gemfile
7
+ Guardfile
8
+ spec/io_spec.rb
9
+ spec/math_spec.rb
8
10
  spec/nmatrix_spec.rb
9
11
  spec/nmatrix_yale_spec.rb
10
12
  spec/nvector_spec.rb
11
- spec/syntax_tree_spec.rb
12
- lib/array.rb
13
+ spec/slice_spec.rb
14
+ spec/elementwise_spec.rb
15
+ spec/blas_spec.rb
16
+ spec/lapack_spec.rb
17
+ spec/spec_helper.rb
13
18
  lib/nmatrix.rb
14
- lib/string.rb
15
- ext/nmatrix/cblas.c
16
- ext/nmatrix/dense.c
17
- ext/nmatrix/depend
18
- ext/nmatrix/extconf.rb
19
- ext/nmatrix/generator.rb
20
- ext/nmatrix/list.c
21
- ext/nmatrix/nmatrix.c
19
+ lib/nmatrix/io/mat5_reader.rb
20
+ lib/nmatrix/io/mat_reader.rb
21
+ lib/nmatrix/blas.rb
22
+ lib/nmatrix/monkeys.rb
23
+ lib/nmatrix/nmatrix.rb
24
+ lib/nmatrix/nvector.rb
25
+ lib/nmatrix/version.rb
26
+ ext/nmatrix/data/complex.h
27
+ ext/nmatrix/data/data.cpp
28
+ ext/nmatrix/data/data.h
29
+ ext/nmatrix/data/rational.h
30
+ ext/nmatrix/data/ruby_object.h
31
+ ext/nmatrix/storage/common.cpp
32
+ ext/nmatrix/storage/common.h
33
+ ext/nmatrix/storage/dense.cpp
34
+ ext/nmatrix/storage/dense.h
35
+ ext/nmatrix/storage/list.cpp
36
+ ext/nmatrix/storage/list.h
37
+ ext/nmatrix/storage/storage.cpp
38
+ ext/nmatrix/storage/storage.h
39
+ ext/nmatrix/storage/yale.cpp
40
+ ext/nmatrix/storage/yale.h
41
+ ext/nmatrix/util/math.cpp
42
+ ext/nmatrix/util/math.h
43
+ ext/nmatrix/util/sl_list.cpp
44
+ ext/nmatrix/util/sl_list.h
45
+ ext/nmatrix/util/util.h
46
+ ext/nmatrix/util/lapack.h
47
+ ext/nmatrix/nmatrix.cpp
22
48
  ext/nmatrix/nmatrix.h
23
- ext/nmatrix/rational.c
24
- ext/nmatrix/yale.c
25
- ext/nmatrix/generator/syntax_tree.rb
26
- ext/nmatrix/dense/blas_header.template.c
27
- ext/nmatrix/dense/elementwise.template.c
28
- ext/nmatrix/dense/gemm.template.c
29
- ext/nmatrix/dense/gemv.template.c
30
- ext/nmatrix/dense/rationalmath.template.c
31
- ext/nmatrix/yale/smmp1.template.c
32
- ext/nmatrix/yale/smmp2.template.c
33
- ext/nmatrix/yale/smmp1_header.template.c
34
- ext/nmatrix/yale/smmp2_header.template.c
35
- ext/nmatrix/yale/sort_columns.template.c
36
- ext/nmatrix/yale/symbmm.template.c
37
- ext/nmatrix/yale/numbmm.template.c
38
- ext/nmatrix/yale/transp.template.c
39
- ext/nmatrix/yale/complexmath.template.c
40
- ext/nmatrix/yale/elementwise.template.c
41
- ext/nmatrix/yale/elementwise_op.template.c
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
49
+ ext/nmatrix/ruby_constants.cpp
50
+ ext/nmatrix/ruby_constants.h
51
+ ext/nmatrix/types.h
52
+ ext/nmatrix/extconf.rb
50
53
 
51
54
 
data/README.rdoc CHANGED
@@ -8,7 +8,8 @@ http://sciruby.com
8
8
 
9
9
  == Description
10
10
 
11
- NMatrix is an experimental linear algebra library for Ruby, written mostly in C. It can be used with or without SciRuby, but is part of the SciRuby project.
11
+ NMatrix is an experimental linear algebra library for Ruby, written mostly in C and C++. It can be used with or without
12
+ SciRuby, but is part of the SciRuby project.
12
13
 
13
14
  NMatrix was inspired by and based heavily upon {NArray}[http://narray.rubyforge.org], by Masahiro Tanaka.
14
15
 
@@ -16,23 +17,90 @@ NMatrix was inspired by and based heavily upon {NArray}[http://narray.rubyforge.
16
17
 
17
18
  === WARNING:
18
19
 
19
- Please be aware that SciRuby and NMatrix are in *PRE-ALPHA* status. If you're thinking of using SciRuby/NMatrix to write mission critical code, such as for driving a car or flying a space shuttle, you may wish to choose other software (for now).
20
+ Please be aware that SciRuby and NMatrix are *ALPHA* status. If you're thinking of using SciRuby/NMatrix to write
21
+ mission-critical code, such as for driving a car or flying a space shuttle, you may wish to choose other software (for
22
+ now).
23
+
24
+ You should also be aware that NMatrix and NArray are incompatible with one another; you should not try to require both
25
+ at the same time. Unfortunately, that causes problems with Ruby/GSL, which currently depends upon NArray. As such, we
26
+ are working on a {patch for Ruby/GSL}[https://github.com/SciRuby/rb-gsl].
20
27
 
21
28
  == Features
22
29
 
30
+ The following features exist in the version of NMatrix (0.0.2) currently under development, and may or may not exist in
31
+ 0.0.1 (the current gem):
32
+
23
33
  * Matrix storage containers: dense, yale, list (more to come)
24
- * Data types: int8, int16, int32, int64, float32, float64, complex64, complex128, rational64, rational128 (incomplete)
25
- * Very basic algebra (more to come)
34
+ * Data types: uint8, int8, int16, int32, int64, float32, float64, complex64, complex128, rational64, rational128
35
+ (incomplete)
36
+ * Conversion between storage and data types (except from-complex, and from-float-to-rational)
37
+ * Element-wise operations and comparisons
38
+ * Matrix-matrix multiplication for dense (using ATLAS) and yale
39
+ * Matrix-vector multiplication for dense (using ATLAS)
40
+ * Dense and list matrix slicing and referencing
41
+ * Matlab .MAT v5 file input
42
+ * C and C++ API
43
+ * Level 3 BLAS internal implementations (no library) and ATLAS (with library) access:
44
+ * xGEMM
45
+ * xTRSM
46
+ * LAPACK ATLAS access:
47
+ * xGETRF (experimental)
48
+
49
+ === Planned Features (Very Short Term)
50
+
51
+ These features will exist in our second alpha release, 0.0.2 (incomplete, thus not yet available as a gem):
52
+
53
+ * Yale matrix slicing and referencing
54
+ * LU decomposition
55
+ * LAPACK internal implementations (no library needed):
56
+ * xGETRF
57
+
58
+ The estimated release date for 0.0.2 is the end of August 2012.
59
+
60
+ === Planned Features (Short-to-Medium Term)
61
+
62
+ These are features planned for NMatrix 0.1.0, our first beta.
63
+
64
+ * calculation of determinant, trace, and eigenvalues (characteristic polynomial) (0.1.0)
65
+ * Gaussian elimination
66
+ * exponentials and square roots
67
+ * matrix inversions
68
+ * matrix decomposition/factorization
69
+ * calculation of norms
70
+ * tensor products
71
+ * principal component analysis (PCA)
72
+ * improved file I/O
73
+ * operation scheduling
74
+ * parallelization of some types of operations
75
+ * optimization of non-BLAS data types on BLAS-like operations (e.g., matrix multiplication for rational numbers)
76
+ * Ruby/GSL interoperability
26
77
 
27
78
  == SYNOPSIS:
28
79
 
29
- From the command line,
80
+ For full instructions, please see sciruby.com/nmatrix. Generally, you should be able to do
81
+
82
+ gem install nmatrix
83
+
84
+ However, you will need to install ATLAS with CBLAS first. Those directions can be found at our website.
85
+
86
+ NOTE: The above command will not give you 0.0.2, which is not yet complete. To obtain 0.0.2, you should use the
87
+ following sequence of commands:
88
+
89
+ git clone https://github.com/SciRuby/nmatrix.git
90
+ cd nmatrix/
91
+ rake compile
92
+ rake repackage
93
+ gem install pkg/nmatrix-0.0.2.gem
30
94
 
31
- git clone git@github.com:mohawkjohn/nmatrix.git
32
- cd nmatrix
33
- rake console
95
+ If you get errors about clapack.h or cblas.h, figure out where your ATLAS headers are using:
34
96
 
35
- Gem coming later.
97
+ locate clapack.h
98
+
99
+ Then, tell your system:
100
+
101
+ export C_INCLUDE_PATH=/usr/local/atlas/include
102
+
103
+ Finally, try compiling again.
36
104
 
37
105
  == REQUIREMENTS:
38
106
 
@@ -48,7 +116,13 @@ More detailed installation instructions are available at {here}[http://sciruby.c
48
116
 
49
117
  == DEVELOPERS:
50
118
 
51
- Before commiting any code, you *MUST* read our {Contributor Agreement}[http://github.com/SciRuby/sciruby/wiki/Contributor-Agreement].
119
+ Code in the master branch of SciRuby/nmatrix on github should compile and link, but is not necessarily stable. You might
120
+ also check out the dev branch if master hasn't been updated in some time.
121
+
122
+ git clone https://github.com/mohawkjohn/nmatrix.git
123
+
124
+ Before commiting any code, you *MUST* read our
125
+ {Contributor Agreement}[http://github.com/SciRuby/sciruby/wiki/Contributor-Agreement].
52
126
 
53
127
  == LICENSE:
54
128
 
@@ -56,8 +130,11 @@ Copyright (c) 2012, The Ruby Science Foundation.
56
130
 
57
131
  All rights reserved.
58
132
 
59
- NMatrix, along with SciRuby, is licensed under the BSD 2-clause license. See {LICENSE.txt}[https://github.com/SciRuby/sciruby/wiki/License] for details.
133
+ NMatrix, along with SciRuby, is licensed under the BSD 2-clause license. See
134
+ {LICENSE.txt}[https://github.com/SciRuby/sciruby/wiki/License] for details.
60
135
 
61
136
  == DONATIONS:
62
137
 
138
+ Support a SciRuby Fellow:
139
+
63
140
  {<img src=https://www.pledgie.com/campaigns/15783.png?skin_name=chrome>}[http://www.pledgie.com/campaigns/15783]
data/Rakefile CHANGED
@@ -1,28 +1,40 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
4
12
 
5
- # Fix for problem described here: https://github.com/jbarnette/isolate/pull/39
6
- module Gem
7
- Deprecate = Module.new do
8
- include Deprecate
9
- end
13
+ require 'rake'
14
+ require "rake/extensiontask"
15
+ Rake::ExtensionTask.new do |ext|
16
+ ext.name = 'nmatrix'
17
+ ext.ext_dir = 'ext/nmatrix'
18
+ ext.lib_dir = 'lib/'
19
+ ext.source_pattern = "**/*.{c,cpp, h}"
10
20
  end
11
- require 'isolate/now'
12
- # End Fix
13
21
 
14
- require 'hoe'
15
- require 'pathname'
16
- require 'rspec/core/rake_task'
22
+ gemspec = eval(IO.read("nmatrix.gemspec"))
23
+
24
+ require "rake/gempackagetask"
25
+ Rake::GemPackageTask.new(gemspec).define
26
+
27
+ desc "install the gem locally"
28
+ task :install => [:package] do
29
+ sh %{gem install pkg/nmatrix-#{NMatrix::VERSION}}
30
+ end
17
31
 
18
- Hoe.plugin :compiler
19
- Hoe.plugin :bundler
20
- Hoe.plugin :git
21
- # Hoe.plugin :compiler
22
- # Hoe.plugin :gem_prelude_sucks
23
- # Hoe.plugin :inline
24
- # Hoe.plugin :racc
25
- # Hoe.plugin :rubyforge
32
+ require 'rspec/core/rake_task'
33
+ require 'rspec/core'
34
+ require 'rspec/core/rake_task'
35
+ RSpec::Core::RakeTask.new(:spec) do |spec|
36
+ spec.pattern = FileList['spec/**/*_spec.rb']
37
+ end
26
38
 
27
39
  BASEDIR = Pathname( __FILE__ ).dirname.relative_path_from( Pathname.pwd )
28
40
  SPECDIR = BASEDIR + 'spec'
@@ -42,41 +54,6 @@ VALGRIND_MEMORYFILL_OPTIONS = [
42
54
  GDB_OPTIONS = []
43
55
 
44
56
 
45
- h = Hoe.spec 'nmatrix' do
46
- self.require_ruby_version ">=1.9"
47
- self.developer('John Woods', 'john.o.woods@gmail.com')
48
- self.post_install_message = <<-EOF
49
- ***********************************************************
50
- Welcome to SciRuby: Tools for Scientific Computing in Ruby!
51
-
52
- *** WARNING ***
53
- Please be aware that NMatrix is in ALPHA status. If you're
54
- thinking of using NMatrix to write mission critical code,
55
- such as for driving a car or flying a space shuttle, you
56
- may wish to choose other software (for now).
57
-
58
- NMatrix requires a C compiler, and has been tested only
59
- with GCC 4.6.1. We are happy to accept contributions
60
- which improve the portability of this project.
61
-
62
- Also required is ATLAS. Most Linux distributions and Mac
63
- versions include ATLAS, but you may wish to compile it
64
- yourself.
65
-
66
- More explicit instructions for NMatrix and SciRuby should
67
- be available on the SciRuby website, sciruby.com, or
68
- through our mailing list (which can be found on our web-
69
- site).
70
-
71
- Thanks for trying out NMatrix! Happy coding!
72
-
73
- ***********************************************************
74
- EOF
75
- #self.need_rdoc = false
76
- self.readme_file = 'README.rdoc'
77
- # self.rubyforge_name = 'nmatrixx' # if different than 'nmatrix'
78
- end
79
-
80
57
  RSpec::Core::RakeTask.new(:spec)
81
58
 
82
59
  task :console do |task|
@@ -84,6 +61,11 @@ task :console do |task|
84
61
  run *cmd
85
62
  end
86
63
 
64
+ task :pry do |task|
65
+ cmd = [ 'pry', "-r './lib/nmatrix.rb'" ]
66
+ run *cmd
67
+ end
68
+
87
69
  #namespace :console do
88
70
  # CONSOLE_CMD = ['irb', "-r './lib/nmatrix.rb'"]
89
71
  # desc "Run console under GDB."