pnmatrix 1.2.4
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.
- checksums.yaml +7 -0
- data/ext/nmatrix/binary_format.txt +53 -0
- data/ext/nmatrix/data/complex.h +388 -0
- data/ext/nmatrix/data/data.cpp +274 -0
- data/ext/nmatrix/data/data.h +651 -0
- data/ext/nmatrix/data/meta.h +64 -0
- data/ext/nmatrix/data/ruby_object.h +386 -0
- data/ext/nmatrix/extconf.rb +70 -0
- data/ext/nmatrix/math/asum.h +99 -0
- data/ext/nmatrix/math/cblas_enums.h +36 -0
- data/ext/nmatrix/math/cblas_templates_core.h +507 -0
- data/ext/nmatrix/math/gemm.h +241 -0
- data/ext/nmatrix/math/gemv.h +178 -0
- data/ext/nmatrix/math/getrf.h +255 -0
- data/ext/nmatrix/math/getrs.h +121 -0
- data/ext/nmatrix/math/imax.h +82 -0
- data/ext/nmatrix/math/laswp.h +165 -0
- data/ext/nmatrix/math/long_dtype.h +62 -0
- data/ext/nmatrix/math/magnitude.h +54 -0
- data/ext/nmatrix/math/math.h +751 -0
- data/ext/nmatrix/math/nrm2.h +165 -0
- data/ext/nmatrix/math/rot.h +117 -0
- data/ext/nmatrix/math/rotg.h +106 -0
- data/ext/nmatrix/math/scal.h +71 -0
- data/ext/nmatrix/math/trsm.h +336 -0
- data/ext/nmatrix/math/util.h +162 -0
- data/ext/nmatrix/math.cpp +1368 -0
- data/ext/nmatrix/nm_memory.h +60 -0
- data/ext/nmatrix/nmatrix.cpp +285 -0
- data/ext/nmatrix/nmatrix.h +476 -0
- data/ext/nmatrix/ruby_constants.cpp +151 -0
- data/ext/nmatrix/ruby_constants.h +106 -0
- data/ext/nmatrix/ruby_nmatrix.c +3130 -0
- data/ext/nmatrix/storage/common.cpp +77 -0
- data/ext/nmatrix/storage/common.h +183 -0
- data/ext/nmatrix/storage/dense/dense.cpp +1096 -0
- data/ext/nmatrix/storage/dense/dense.h +129 -0
- data/ext/nmatrix/storage/list/list.cpp +1628 -0
- data/ext/nmatrix/storage/list/list.h +138 -0
- data/ext/nmatrix/storage/storage.cpp +730 -0
- data/ext/nmatrix/storage/storage.h +99 -0
- data/ext/nmatrix/storage/yale/class.h +1139 -0
- data/ext/nmatrix/storage/yale/iterators/base.h +143 -0
- data/ext/nmatrix/storage/yale/iterators/iterator.h +131 -0
- data/ext/nmatrix/storage/yale/iterators/row.h +450 -0
- data/ext/nmatrix/storage/yale/iterators/row_stored.h +140 -0
- data/ext/nmatrix/storage/yale/iterators/row_stored_nd.h +169 -0
- data/ext/nmatrix/storage/yale/iterators/stored_diagonal.h +124 -0
- data/ext/nmatrix/storage/yale/math/transpose.h +110 -0
- data/ext/nmatrix/storage/yale/yale.cpp +2074 -0
- data/ext/nmatrix/storage/yale/yale.h +203 -0
- data/ext/nmatrix/types.h +55 -0
- data/ext/nmatrix/util/io.cpp +279 -0
- data/ext/nmatrix/util/io.h +115 -0
- data/ext/nmatrix/util/sl_list.cpp +627 -0
- data/ext/nmatrix/util/sl_list.h +144 -0
- data/ext/nmatrix/util/util.h +78 -0
- data/lib/nmatrix/blas.rb +378 -0
- data/lib/nmatrix/cruby/math.rb +744 -0
- data/lib/nmatrix/enumerate.rb +253 -0
- data/lib/nmatrix/homogeneous.rb +241 -0
- data/lib/nmatrix/io/fortran_format.rb +138 -0
- data/lib/nmatrix/io/harwell_boeing.rb +221 -0
- data/lib/nmatrix/io/market.rb +263 -0
- data/lib/nmatrix/io/point_cloud.rb +189 -0
- data/lib/nmatrix/jruby/decomposition.rb +24 -0
- data/lib/nmatrix/jruby/enumerable.rb +13 -0
- data/lib/nmatrix/jruby/error.rb +4 -0
- data/lib/nmatrix/jruby/math.rb +501 -0
- data/lib/nmatrix/jruby/nmatrix_java.rb +840 -0
- data/lib/nmatrix/jruby/operators.rb +283 -0
- data/lib/nmatrix/jruby/slice.rb +264 -0
- data/lib/nmatrix/lapack_core.rb +181 -0
- data/lib/nmatrix/lapack_plugin.rb +44 -0
- data/lib/nmatrix/math.rb +953 -0
- data/lib/nmatrix/mkmf.rb +100 -0
- data/lib/nmatrix/monkeys.rb +137 -0
- data/lib/nmatrix/nmatrix.rb +1172 -0
- data/lib/nmatrix/rspec.rb +75 -0
- data/lib/nmatrix/shortcuts.rb +1163 -0
- data/lib/nmatrix/version.rb +39 -0
- data/lib/nmatrix/yale_functions.rb +118 -0
- data/lib/nmatrix.rb +28 -0
- data/spec/00_nmatrix_spec.rb +892 -0
- data/spec/01_enum_spec.rb +196 -0
- data/spec/02_slice_spec.rb +407 -0
- data/spec/03_nmatrix_monkeys_spec.rb +80 -0
- data/spec/2x2_dense_double.mat +0 -0
- data/spec/4x4_sparse.mat +0 -0
- data/spec/4x5_dense.mat +0 -0
- data/spec/blas_spec.rb +215 -0
- data/spec/elementwise_spec.rb +311 -0
- data/spec/homogeneous_spec.rb +100 -0
- data/spec/io/fortran_format_spec.rb +88 -0
- data/spec/io/harwell_boeing_spec.rb +98 -0
- data/spec/io/test.rua +9 -0
- data/spec/io_spec.rb +159 -0
- data/spec/lapack_core_spec.rb +482 -0
- data/spec/leakcheck.rb +16 -0
- data/spec/math_spec.rb +1363 -0
- data/spec/nmatrix_yale_resize_test_associations.yaml +2802 -0
- data/spec/nmatrix_yale_spec.rb +286 -0
- data/spec/rspec_monkeys.rb +56 -0
- data/spec/rspec_spec.rb +35 -0
- data/spec/shortcuts_spec.rb +474 -0
- data/spec/slice_set_spec.rb +162 -0
- data/spec/spec_helper.rb +172 -0
- data/spec/stat_spec.rb +214 -0
- data/spec/test.pcd +20 -0
- data/spec/utm5940.mtx +83844 -0
- metadata +295 -0
data/lib/nmatrix/mkmf.rb
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require "mkmf"
|
|
2
|
+
|
|
3
|
+
if RUBY_VERSION < '1.9'
|
|
4
|
+
raise NotImplementedError, "Sorry, you need at least Ruby 1.9!"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
# Function derived from NArray's extconf.rb.
|
|
8
|
+
def create_conf_h(file) #:nodoc:
|
|
9
|
+
print "creating #{file}\n"
|
|
10
|
+
File.open(file, 'w') do |hfile|
|
|
11
|
+
header_guard = file.upcase.sub(/\s|\./, '_')
|
|
12
|
+
|
|
13
|
+
hfile.puts "#ifndef #{header_guard}"
|
|
14
|
+
hfile.puts "#define #{header_guard}"
|
|
15
|
+
hfile.puts
|
|
16
|
+
|
|
17
|
+
# FIXME: Find a better way to do this:
|
|
18
|
+
hfile.puts "#define RUBY_2 1" if RUBY_VERSION >= '2.0'
|
|
19
|
+
|
|
20
|
+
for line in $defs
|
|
21
|
+
line =~ /^-D(.*)/
|
|
22
|
+
hfile.printf "#define %s 1\n", $1
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
hfile.puts
|
|
26
|
+
hfile.puts "#endif"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def find_newer_gplusplus #:nodoc:
|
|
31
|
+
print "checking for apparent GNU g++ binary with C++0x/C++11 support... "
|
|
32
|
+
[9,8,7,6,5,4,3].each do |minor|
|
|
33
|
+
ver = "4.#{minor}"
|
|
34
|
+
gpp = "g++-#{ver}"
|
|
35
|
+
result = `which #{gpp}`
|
|
36
|
+
next if result.empty?
|
|
37
|
+
CONFIG['CXX'] = gpp
|
|
38
|
+
puts ver
|
|
39
|
+
return CONFIG['CXX']
|
|
40
|
+
end
|
|
41
|
+
false
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def gplusplus_version
|
|
45
|
+
cxxvar = proc { |n| `#{CONFIG['CXX']} -E -dM - <#{File::NULL} | grep #{n}`.chomp.split(' ')[2] }
|
|
46
|
+
major = cxxvar.call('__GNUC__')
|
|
47
|
+
minor = cxxvar.call('__GNUC_MINOR__')
|
|
48
|
+
patch = cxxvar.call('__GNUC_PATCHLEVEL__')
|
|
49
|
+
|
|
50
|
+
raise("unable to determine g++ version (match to get version was nil)") if major.nil? || minor.nil? || patch.nil?
|
|
51
|
+
|
|
52
|
+
"#{major}.#{minor}.#{patch}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
if /cygwin|mingw/ =~ RUBY_PLATFORM
|
|
57
|
+
CONFIG["DLDFLAGS"] << " --output-lib libnmatrix.a"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Fix compiler pairing
|
|
61
|
+
if CONFIG['CC'] == 'clang' && CONFIG['CXX'] != 'clang++'
|
|
62
|
+
puts "WARNING: CONFIG['CXX'] is not 'clang++' even though CONFIG['CC'] is 'clang'.",
|
|
63
|
+
"WARNING: Force to use clang++ together with clang."
|
|
64
|
+
|
|
65
|
+
CONFIG['CXX'] = 'clang++'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
if CONFIG['CXX'] == 'clang++'
|
|
69
|
+
$CXX_STANDARD = 'c++11'
|
|
70
|
+
else
|
|
71
|
+
version = gplusplus_version
|
|
72
|
+
if version < '4.3.0' && CONFIG['CXX'] == 'g++' # see if we can find a newer G++, unless it's been overridden by user
|
|
73
|
+
if !find_newer_gplusplus
|
|
74
|
+
raise("You need a version of g++ which supports -std=c++0x or -std=c++11. If you're on a Mac and using Homebrew, we recommend using mac-brew-gcc.sh to install a more recent g++.")
|
|
75
|
+
end
|
|
76
|
+
version = gplusplus_version
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
if version < '4.7.0'
|
|
80
|
+
$CXX_STANDARD = 'c++0x'
|
|
81
|
+
else
|
|
82
|
+
$CXX_STANDARD = 'c++11'
|
|
83
|
+
end
|
|
84
|
+
puts "using C++ standard... #{$CXX_STANDARD}"
|
|
85
|
+
puts "g++ reports version... " + `#{CONFIG['CXX']} --version|head -n 1|cut -f 3 -d " "`
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# For release, these next two should both be changed to -O3.
|
|
89
|
+
$CFLAGS += " -O3 "
|
|
90
|
+
#$CFLAGS += " -static -O0 -g "
|
|
91
|
+
$CXXFLAGS += " -O3 -std=#{$CXX_STANDARD} " #-fmax-errors=10 -save-temps
|
|
92
|
+
#$CXXFLAGS += " -static -O0 -g -std=#{$CXX_STANDARD} "
|
|
93
|
+
|
|
94
|
+
if CONFIG.has_key?('warnflags')
|
|
95
|
+
CONFIG['warnflags'].gsub!('-Wshorten-64-to-32', '') # doesn't work except in Mac-patched gcc (4.2)
|
|
96
|
+
CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
|
|
97
|
+
CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '')
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
have_func("rb_array_const_ptr", "ruby.h")
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
# == monkeys.rb
|
|
25
|
+
#
|
|
26
|
+
# Ruby core extensions for NMatrix.
|
|
27
|
+
#++
|
|
28
|
+
|
|
29
|
+
#######################
|
|
30
|
+
# Classes and Modules #
|
|
31
|
+
#######################
|
|
32
|
+
|
|
33
|
+
class Array
|
|
34
|
+
# Convert a Ruby Array to an NMatrix.
|
|
35
|
+
#
|
|
36
|
+
# You must provide a shape for the matrix as the first argument.
|
|
37
|
+
#
|
|
38
|
+
# == Arguments:
|
|
39
|
+
# <tt>shape</tt> :: Array describing matrix dimensions (or Integer for square).
|
|
40
|
+
# If not provided, will be intuited through #shape.
|
|
41
|
+
# <tt>dtype</tt> :: Override data type (e.g., to store a Float as :float32
|
|
42
|
+
# instead of :float64) -- optional.
|
|
43
|
+
# <tt>stype</tt> :: Optional storage type (defaults to :dense)
|
|
44
|
+
def to_nm(shape = nil, dtype = nil, stype = :dense)
|
|
45
|
+
elements = self.dup
|
|
46
|
+
|
|
47
|
+
guess_dtype = ->(type) {
|
|
48
|
+
case type
|
|
49
|
+
when Integer then :int64
|
|
50
|
+
when Float then :float64
|
|
51
|
+
when Complex then :complex128
|
|
52
|
+
end
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
guess_shape = lambda { |shapey; shape|
|
|
56
|
+
# Get the size of the current dimension
|
|
57
|
+
shape = [shapey.size]
|
|
58
|
+
shape << shapey.map {|s|
|
|
59
|
+
if s.respond_to?(:size) && s.respond_to?(:map)
|
|
60
|
+
guess_shape.call(s)
|
|
61
|
+
else
|
|
62
|
+
nil
|
|
63
|
+
end
|
|
64
|
+
}
|
|
65
|
+
if shape.last.any? {|s| (s != shape.last.first) || s.nil?}
|
|
66
|
+
shape.pop
|
|
67
|
+
end
|
|
68
|
+
if (shape.first != shape.last) && shape.last.all? {|s| s == shape.last.first}
|
|
69
|
+
shape[-1] = shape.last.first
|
|
70
|
+
end
|
|
71
|
+
shape.flatten
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
unless shape
|
|
75
|
+
shape = guess_shape.call(elements)
|
|
76
|
+
elements.flatten!(shape.size - 1)
|
|
77
|
+
if elements.flatten != elements
|
|
78
|
+
dtype = :object
|
|
79
|
+
else
|
|
80
|
+
dtype ||= guess_dtype[elements[0]]
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
dtype ||= guess_dtype[self[0]]
|
|
85
|
+
|
|
86
|
+
matrix = NMatrix.new(:dense, shape, elements, dtype)
|
|
87
|
+
|
|
88
|
+
if stype != :dense then matrix.cast(stype, dtype) else matrix end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
class Object #:nodoc:
|
|
93
|
+
def returning(value)
|
|
94
|
+
yield(value)
|
|
95
|
+
value
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
module Math #:nodoc:
|
|
101
|
+
class << self
|
|
102
|
+
NMatrix::NMMath::METHODS_ARITY_2.each do |meth|
|
|
103
|
+
define_method "nm_#{meth}" do |arg0, arg1|
|
|
104
|
+
if arg0.is_a? NMatrix then
|
|
105
|
+
arg0.send(meth, arg1)
|
|
106
|
+
elsif arg1.is_a? NMatrix then
|
|
107
|
+
arg1.send(meth, arg0, true)
|
|
108
|
+
else
|
|
109
|
+
self.send("old_#{meth}".to_sym, arg0, arg1)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
alias_method "old_#{meth}".to_sym, meth
|
|
113
|
+
alias_method meth, "nm_#{meth}".to_sym
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
class String
|
|
119
|
+
def underscore
|
|
120
|
+
self.gsub(/::/, '/').
|
|
121
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
|
122
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
|
123
|
+
tr("-", "_").
|
|
124
|
+
downcase
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Since `autoload` will most likely be deprecated (due to multi-threading concerns),
|
|
129
|
+
# we'll use `const_missing`. See: https://www.ruby-forum.com/topic/3036681 for more info.
|
|
130
|
+
module AutoloadPatch #:nodoc
|
|
131
|
+
def const_missing(name)
|
|
132
|
+
file = name.to_s.underscore
|
|
133
|
+
require "nmatrix/io/#{file}"
|
|
134
|
+
klass = const_get(name)
|
|
135
|
+
return klass if klass
|
|
136
|
+
end
|
|
137
|
+
end
|