nmatrix-gemv 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +29 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +14 -0
  5. data/Gemfile +7 -0
  6. data/README.md +29 -0
  7. data/Rakefile +225 -0
  8. data/ext/nmatrix_gemv/binary_format.txt +53 -0
  9. data/ext/nmatrix_gemv/data/complex.h +399 -0
  10. data/ext/nmatrix_gemv/data/data.cpp +298 -0
  11. data/ext/nmatrix_gemv/data/data.h +771 -0
  12. data/ext/nmatrix_gemv/data/meta.h +70 -0
  13. data/ext/nmatrix_gemv/data/rational.h +436 -0
  14. data/ext/nmatrix_gemv/data/ruby_object.h +471 -0
  15. data/ext/nmatrix_gemv/extconf.rb +254 -0
  16. data/ext/nmatrix_gemv/math.cpp +1639 -0
  17. data/ext/nmatrix_gemv/math/asum.h +143 -0
  18. data/ext/nmatrix_gemv/math/geev.h +82 -0
  19. data/ext/nmatrix_gemv/math/gemm.h +271 -0
  20. data/ext/nmatrix_gemv/math/gemv.h +212 -0
  21. data/ext/nmatrix_gemv/math/ger.h +96 -0
  22. data/ext/nmatrix_gemv/math/gesdd.h +80 -0
  23. data/ext/nmatrix_gemv/math/gesvd.h +78 -0
  24. data/ext/nmatrix_gemv/math/getf2.h +86 -0
  25. data/ext/nmatrix_gemv/math/getrf.h +240 -0
  26. data/ext/nmatrix_gemv/math/getri.h +108 -0
  27. data/ext/nmatrix_gemv/math/getrs.h +129 -0
  28. data/ext/nmatrix_gemv/math/idamax.h +86 -0
  29. data/ext/nmatrix_gemv/math/inc.h +47 -0
  30. data/ext/nmatrix_gemv/math/laswp.h +165 -0
  31. data/ext/nmatrix_gemv/math/long_dtype.h +52 -0
  32. data/ext/nmatrix_gemv/math/math.h +1069 -0
  33. data/ext/nmatrix_gemv/math/nrm2.h +181 -0
  34. data/ext/nmatrix_gemv/math/potrs.h +129 -0
  35. data/ext/nmatrix_gemv/math/rot.h +141 -0
  36. data/ext/nmatrix_gemv/math/rotg.h +115 -0
  37. data/ext/nmatrix_gemv/math/scal.h +73 -0
  38. data/ext/nmatrix_gemv/math/swap.h +73 -0
  39. data/ext/nmatrix_gemv/math/trsm.h +387 -0
  40. data/ext/nmatrix_gemv/nm_memory.h +60 -0
  41. data/ext/nmatrix_gemv/nmatrix_gemv.cpp +90 -0
  42. data/ext/nmatrix_gemv/nmatrix_gemv.h +374 -0
  43. data/ext/nmatrix_gemv/ruby_constants.cpp +153 -0
  44. data/ext/nmatrix_gemv/ruby_constants.h +107 -0
  45. data/ext/nmatrix_gemv/ruby_nmatrix.c +84 -0
  46. data/ext/nmatrix_gemv/ttable_helper.rb +122 -0
  47. data/ext/nmatrix_gemv/types.h +54 -0
  48. data/ext/nmatrix_gemv/util/util.h +78 -0
  49. data/lib/nmatrix-gemv.rb +43 -0
  50. data/lib/nmatrix_gemv/blas.rb +85 -0
  51. data/lib/nmatrix_gemv/nmatrix_gemv.rb +35 -0
  52. data/lib/nmatrix_gemv/rspec.rb +75 -0
  53. data/nmatrix-gemv.gemspec +31 -0
  54. data/spec/blas_spec.rb +154 -0
  55. data/spec/spec_helper.rb +128 -0
  56. metadata +186 -0
@@ -0,0 +1,54 @@
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
+ // == types.h
25
+ //
26
+ // Definition of simple types used throughout NMatrix.
27
+
28
+ #ifndef NMATRIX_TYPES_H
29
+ #define NMATRIX_TYPES_H
30
+
31
+ /*
32
+ * Standard Includes
33
+ */
34
+
35
+ #include <cstdint>
36
+
37
+ /*
38
+ * Macros
39
+ */
40
+
41
+ #define EPSILON 1E-10
42
+ #define FP_IS_ZERO(n) (-EPSILON < n && n < EPSILON)
43
+ #define FP_EQUAL(a, b) FP_IS_ZERO((a - b))
44
+
45
+ /*
46
+ * Types
47
+ */
48
+
49
+ typedef float float32_t;
50
+ typedef double float64_t;
51
+
52
+ typedef size_t IType;
53
+
54
+ #endif
@@ -0,0 +1,78 @@
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
+ // == util.h
25
+ //
26
+ // Header file for utility functions and data.
27
+
28
+ #ifndef UTIL_H
29
+ #define UTIL_H
30
+
31
+ /*
32
+ * Standard Includes
33
+ */
34
+
35
+ /*
36
+ * Project Includes
37
+ */
38
+
39
+ #include "types.h"
40
+
41
+ /*
42
+ * Macros
43
+ */
44
+
45
+ /*
46
+ * Types
47
+ */
48
+
49
+ /*
50
+ * Data
51
+ */
52
+
53
+ /*
54
+ * Functions
55
+ */
56
+ namespace nm {
57
+ template <typename Type>
58
+ inline Type gcf(Type x, Type y) {
59
+ Type t;
60
+
61
+ if (x < 0) x = -x;
62
+ if (y < 0) y = -y;
63
+
64
+ if (x == 0) return y;
65
+ if (y == 0) return x;
66
+
67
+ while (x > 0) {
68
+ t = x;
69
+ x = y % x;
70
+ y = t;
71
+ }
72
+
73
+ return y;
74
+ }
75
+ } // end of namespace nm
76
+
77
+
78
+ #endif // UTIL_H
@@ -0,0 +1,43 @@
1
+ # = NMatrix
2
+ #
3
+ # A linear algebra library for scientific computation in Ruby.
4
+ # NMatrix is part of SciRuby.
5
+ #
6
+ # NMatrix was originally inspired by and derived from NArray, by
7
+ # Masahiro Tanaka: http://narray.rubyforge.org
8
+ #
9
+ # == Copyright Information
10
+ #
11
+ # SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation
12
+ # NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation
13
+ #
14
+ # Please see LICENSE.txt for additional copyright notices.
15
+ #
16
+ # == Contributing
17
+ #
18
+ # By contributing source code to SciRuby, you agree to be bound by
19
+ # our Contributor Agreement:
20
+ #
21
+ # * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
22
+ #
23
+ # == nmatrix.rb
24
+ #
25
+ # This file loads the C extension for NMatrix and all the ruby files.
26
+ #
27
+
28
+ # For some reason nmatrix.so ends up in a different place during gem build.
29
+ if File.exist?("lib/nmatrixr_gemv/nmatrix_gemv.so") #|| File.exist?("lib/nmatrix/nmatrix.bundle")
30
+ # Development
31
+ require "nmatrixr_gemv/nmatrix_gemv.so"
32
+ else
33
+ # Gem
34
+ require "nmatrix_gemv.so"
35
+ end
36
+
37
+ require 'nmatrix_gemv/nmatrix_gemv.rb'
38
+ require 'nmatrix_gemv/blas.rb'
39
+ # require 'nmatrix/version.rb'
40
+ #require 'nmatrix/nvector.rb'
41
+ # require 'nmatrix/blas.rb'
42
+ # require 'nmatrix/monkeys'
43
+ # require "nmatrix/shortcuts.rb"
@@ -0,0 +1,85 @@
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
+ # == blas.rb
25
+ #
26
+ # This file contains the safer accessors for the BLAS functions
27
+ # supported by NMatrix.
28
+ #++
29
+
30
+ module NMatrix::BLAS
31
+ class << self
32
+
33
+ #
34
+ # call-seq:
35
+ # gemv(a, x) -> NMatrix
36
+ # gemv(a, x, y) -> NMatrix
37
+ # gemv(a, x, y, alpha, beta) -> NMatrix
38
+ #
39
+ # Implements matrix-vector product via
40
+ # y = (alpha * A * x) + (beta * y)
41
+ # where +alpha+ and +beta+ are scalar values.
42
+ #
43
+ # * *Arguments* :
44
+ # - +a+ -> Matrix A.
45
+ # - +x+ -> Vector x.
46
+ # - +y+ -> Vector y.
47
+ # - +alpha+ -> A scalar value that multiplies A * x.
48
+ # - +beta+ -> A scalar value that multiplies y.
49
+ # - +transpose_a+ ->
50
+ # - +m+ ->
51
+ # - +n+ ->
52
+ # - +lda+ ->
53
+ # - +incx+ ->
54
+ # - +incy+ ->
55
+ # * *Returns* :
56
+ # -
57
+ # * *Raises* :
58
+ # - ++ ->
59
+ #
60
+ def gemv(a, x, y = nil, alpha = 1.0, beta = 0.0, transpose_a = false, m = nil, n = nil, lda = nil, incx = nil, incy = nil)
61
+ raise(ArgumentError, 'Expected dense NMatrices as first two arguments.') unless a.is_a?(NMatrix) and x.is_a?(NMatrix) and a.stype == :dense and x.stype == :dense
62
+ raise(ArgumentError, 'Expected nil or dense NMatrix as third argument.') unless y.nil? or (y.is_a?(NMatrix) and y.stype == :dense)
63
+ raise(ArgumentError, 'NMatrix dtype mismatch.') unless a.dtype == x.dtype and (y ? a.dtype == y.dtype : true)
64
+
65
+ m ||= transpose_a ? a.shape[1] : a.shape[0]
66
+ n ||= transpose_a ? a.shape[0] : a.shape[1]
67
+
68
+ lda ||= a.shape[1]
69
+ incx ||= 1
70
+ incy ||= 1
71
+
72
+ # NM_COMPLEX64 and NM_COMPLEX128 both require complex alpha and beta.
73
+ if a.dtype == :complex64 or a.dtype == :complex128
74
+ alpha = Complex(1.0, 0.0) if alpha == 1.0
75
+ beta = Complex(0.0, 0.0) if beta == 0.0
76
+ end
77
+
78
+ y ||= NMatrix.new([m, n], dtype: a.dtype)
79
+
80
+ NMatrix::BLAS.cblas_gemv(transpose_a, m, n, alpha, a, lda, x, incx, beta, y, incy)
81
+
82
+ return y
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,35 @@
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 contains those core functionalities which can be
27
+ # implemented efficiently (or much more easily) in Ruby (e.g.,
28
+ # inspect, pretty_print, element-wise operations).
29
+
30
+
31
+ # require_relative './blas.rb'
32
+ #
33
+ class NMatrix
34
+ end
35
+
@@ -0,0 +1,75 @@
1
+ # = NMatrix
2
+ #
3
+ # A linear algebra library for scientific computation in Ruby.
4
+ # NMatrix is part of SciRuby.
5
+ #
6
+ # NMatrix was originally inspired by and derived from NArray, by
7
+ # Masahiro Tanaka: http://narray.rubyforge.org
8
+ #
9
+ # == Copyright Information
10
+ #
11
+ # SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation
12
+ # NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation
13
+ #
14
+ # Please see LICENSE.txt for additional copyright notices.
15
+ #
16
+ # == Contributing
17
+ #
18
+ # By contributing source code to SciRuby, you agree to be bound by
19
+ # our Contributor Agreement:
20
+ #
21
+ # * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
22
+ #
23
+ # == rspec.rb
24
+ #
25
+ # Monkey patches for RSpec improving its ability to work well with
26
+ # NMatrix (particularly #be_within).
27
+ #
28
+
29
+ require 'rspec'
30
+
31
+ # Amend RSpec to allow #be_within for matrices.
32
+ module RSpec::Matchers::BuiltIn #:nodoc:
33
+ class BeWithin
34
+
35
+ def of(expected)
36
+ @expected = expected
37
+ @unit = ''
38
+ if expected.is_a?(NMatrix)
39
+ @tolerance = if @delta.is_a?(NMatrix)
40
+ @delta.abs
41
+ elsif @delta.is_a?(Array)
42
+ NMatrix.new(:dense, expected.shape, @delta, :object).abs.cast(:dtype => expected.abs_dtype)
43
+ else
44
+ (NMatrix.ones_like(expected) * @delta).abs
45
+ end
46
+ else
47
+ @tolerance = @delta
48
+ end
49
+
50
+ self
51
+ end
52
+
53
+ def percent_of(expected)
54
+ @expected = expected
55
+ @unit = '%'
56
+ @tolerance = @expected.abs * @delta / 100.0 # <- only change is to reverse abs and @delta
57
+ self
58
+ end
59
+
60
+ def matches?(actual)
61
+ @actual = actual
62
+ raise needs_expected unless defined? @expected
63
+ raise needs_subtractable unless @actual.respond_to? :-
64
+ res = (@actual - @expected).abs <= @tolerance
65
+
66
+ #if res.is_a?(NMatrix)
67
+ # require 'pry'
68
+ # binding.pry
69
+ #end
70
+
71
+ res.is_a?(NMatrix) ? !res.any? { |x| !x } : res
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path('../lib/', __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "nmatrix-gemv"
6
+ gem.version = '0.0.3'
7
+ gem.summary = "blas gemv function interface for NMatrix"
8
+ gem.description = "provide gemv function to NMatrix, just require 'nmatrix-gemv' in file to use."
9
+ gem.homepage = 'http://sciruby.com'
10
+ gem.authors = ['Terence Ng']
11
+ gem.email = ['pheotiman@gmail.com']
12
+ gem.license = 'BSD 2-clause'
13
+
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ gem.extensions = ['ext/nmatrix_gemv/extconf.rb']
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.required_ruby_version = '>= 1.9'
21
+
22
+ gem.add_dependency 'rdoc', '>=4.0.1'
23
+ #gem.add_dependency 'yard'
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'bundler'
26
+ gem.add_development_dependency 'rspec'
27
+ gem.add_development_dependency 'rspec-longrun'
28
+ #gem.add_development_dependency 'pry'
29
+ gem.add_development_dependency 'rake-compiler', '~>0.8.1'
30
+ end
31
+
@@ -0,0 +1,154 @@
1
+ # = NMatrix
2
+ #
3
+ # A linear algebra library for scientific computation in Ruby.
4
+ # NMatrix is part of SciRuby.
5
+ #
6
+ # NMatrix was originally inspired by and derived from NArray, by
7
+ # Masahiro Tanaka: http://narray.rubyforge.org
8
+ #
9
+ # == Copyright Information
10
+ #
11
+ # SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation
12
+ # NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation
13
+ #
14
+ # Please see LICENSE.txt for additional copyright notices.
15
+ #
16
+ # == Contributing
17
+ #
18
+ # By contributing source code to SciRuby, you agree to be bound by
19
+ # our Contributor Agreement:
20
+ #
21
+ # * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
22
+ #
23
+ # == blas_spec.rb
24
+ #
25
+ # Tests for properly exposed BLAS functions.
26
+ #
27
+
28
+ # Can we use require_relative here instead?
29
+ require File.join(File.dirname(__FILE__), "spec_helper.rb")
30
+
31
+
32
+ describe NMatrix::BLAS do
33
+ #after :each do
34
+ # GC.start
35
+ #end
36
+
37
+ =begin
38
+ [:rational32, :rational64, :rational128, :float32, :float64, :complex64, :complex128].each do |dtype|
39
+ context dtype do
40
+ # This is not the same as "exposes cblas trsm", which would be for a version defined in blas.rb (which
41
+ # would greatly simplify the calling of cblas_trsm in terms of arguments, and which would be accessible
42
+ # as NMatrix::BLAS::trsm)
43
+ it "exposes unfriendly cblas_trsm" do
44
+ a = NMatrix.new(3, [4,-1.quo(2), -3.quo(4), -2, 2, -1.quo(4), -4, -2, -1.quo(2)], dtype: dtype)
45
+ b = NMatrix.new([3,1], [-1, 17, -9], dtype: dtype)
46
+ NMatrix::BLAS::cblas_trsm(:row, :right, :lower, :transpose, :nonunit, 1, 3, 1.0, a, 3, b, 3)
47
+
48
+ # These test results all come from actually running a matrix through BLAS. We use them to ensure that NMatrix's
49
+ # version of these functions (for rationals) give similar results.
50
+
51
+ b[0].should == -1.quo(4)
52
+ b[1].should == 33.quo(4)
53
+ b[2].should == -13
54
+
55
+ NMatrix::BLAS::cblas_trsm(:row, :right, :upper, :transpose, :unit, 1, 3, 1.0, a, 3, b, 3)
56
+
57
+ b[0].should == -15.quo(2)
58
+ b[1].should == 5
59
+ b[2].should == -13
60
+ end
61
+ end
62
+ end
63
+
64
+ [:rational32,:rational64,:rational128].each do |dtype|
65
+ context dtype do
66
+ it "exposes cblas rot"
67
+ end
68
+
69
+ context dtype do
70
+ it "exposes cblas rotg"
71
+ end
72
+ end
73
+
74
+ [:float32, :float64, :complex64, :complex128, :object].each do |dtype|
75
+ context dtype do
76
+
77
+ it "exposes cblas rot" do
78
+ x = NMatrix.new([5,1], [1,2,3,4,5], dtype: dtype)
79
+ y = NMatrix.new([5,1], [-5,-4,-3,-2,-1], dtype: dtype)
80
+ x, y = NMatrix::BLAS::rot(x, y, 1.quo(2), Math.sqrt(3).quo(2), -1)
81
+
82
+ x.should be_within(1e-4).of(
83
+ NMatrix.new([5,1], [-0.3660254037844386, -0.7320508075688772, -1.098076211353316, -1.4641016151377544, -1.8301270189221928], dtype: dtype)
84
+ )
85
+
86
+ y.should be_within(1e-4).of(
87
+ NMatrix.new([5,1], [-6.830127018922193, -5.464101615137754, -4.098076211353316, -2.732050807568877, -1.3660254037844386], dtype: dtype)
88
+ )
89
+ end
90
+
91
+ end
92
+ end
93
+
94
+ =end
95
+
96
+ [:float32, :float64, :complex64, :complex128, :object].each do |dtype|
97
+ context dtype do
98
+
99
+ =begin
100
+ it "exposes cblas rotg" do
101
+ pending("broken for :object") if dtype == :object
102
+
103
+ ab = NMatrix.new([2,1], [6,-8], dtype: dtype)
104
+ c,s = NMatrix::BLAS::rotg(ab)
105
+
106
+ if [:float32, :float64].include?(dtype)
107
+ ab[0].should be_within(1e-6).of(-10)
108
+ ab[1].should be_within(1e-6).of(-5.quo(3))
109
+ c.should be_within(1e-6).of(-3.quo(5))
110
+ else
111
+ pending "need correct test cases"
112
+ ab[0].should be_within(1e-6).of(10)
113
+ ab[1].should be_within(1e-6).of(5.quo(3))
114
+ c.should be_within(1e-6).of(3.quo(5))
115
+ end
116
+ s.should be_within(1e-6).of(4.quo(5))
117
+ end
118
+
119
+ # Note: this exposes gemm, not cblas_gemm (which is the unfriendly CBLAS no-error-checking version)
120
+ it "exposes gemm" do
121
+ n = NMatrix.new([4,3], [14.0,9.0,3.0, 2.0,11.0,15.0, 0.0,12.0,17.0, 5.0,2.0,3.0], dtype: dtype)
122
+ m = NMatrix.new([3,2], [12.0,25.0, 9.0,10.0, 8.0,5.0], dtype: dtype)
123
+
124
+ #c = NMatrix.new([4,2], dtype)
125
+ r = NMatrix::BLAS.gemm(n, m) #, c)
126
+ #c.should equal(r) # check that both are same memory address
127
+
128
+ r.should == NMatrix.new([4,2], [273,455,243,235,244,205,102,160], dtype: dtype)
129
+ end
130
+ =end
131
+
132
+ it "exposes gemv" do
133
+ a = NMatrix.new([4,3], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0], dtype: :float64)
134
+ x = NMatrix.new([3,1], [2.0, 1.0, 0.0], dtype: :float64)
135
+
136
+ NMatrix::BLAS.gemv(a, x)
137
+ end
138
+
139
+ =begin
140
+ it "exposes asum" do
141
+ x = NMatrix.new([4,1], [1,2,3,4], dtype: :float64)
142
+ NMatrix::BLAS.asum(x).should == 10.0
143
+ end
144
+
145
+
146
+ it "exposes nrm2" do
147
+ x = NMatrix.new([4,1], [2,-4,3,5], dtype: :float64)
148
+ NMatrix::BLAS.nrm2(x, 1, 3).should be_within(1e-10).of(5.385164807134504)
149
+ end
150
+ =end
151
+ end
152
+ end
153
+ end
154
+