nmatrix 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/ext/nmatrix/data/data.cpp +9 -9
  3. data/ext/nmatrix/data/data.h +7 -8
  4. data/ext/nmatrix/data/ruby_object.h +1 -4
  5. data/ext/nmatrix/extconf.rb +9 -127
  6. data/ext/nmatrix/math.cpp +25 -25
  7. data/ext/nmatrix/math/asum.h +10 -31
  8. data/ext/nmatrix/math/cblas_templates_core.h +10 -10
  9. data/ext/nmatrix/math/getrf.h +2 -2
  10. data/ext/nmatrix/math/imax.h +12 -9
  11. data/ext/nmatrix/math/laswp.h +3 -3
  12. data/ext/nmatrix/math/long_dtype.h +16 -3
  13. data/ext/nmatrix/math/magnitude.h +54 -0
  14. data/ext/nmatrix/math/nrm2.h +19 -14
  15. data/ext/nmatrix/math/trsm.h +40 -36
  16. data/ext/nmatrix/math/util.h +14 -0
  17. data/ext/nmatrix/nmatrix.h +39 -1
  18. data/ext/nmatrix/ruby_nmatrix.c +45 -83
  19. data/ext/nmatrix/storage/common.h +9 -3
  20. data/ext/nmatrix/storage/dense/dense.cpp +4 -4
  21. data/ext/nmatrix/storage/list/list.cpp +2 -2
  22. data/ext/nmatrix/storage/yale/class.h +1 -1
  23. data/lib/nmatrix/blas.rb +103 -34
  24. data/lib/nmatrix/io/fortran_format.rb +8 -5
  25. data/lib/nmatrix/io/harwell_boeing.rb +11 -10
  26. data/lib/nmatrix/io/market.rb +9 -6
  27. data/lib/nmatrix/io/mat5_reader.rb +54 -29
  28. data/lib/nmatrix/io/mat_reader.rb +26 -14
  29. data/lib/nmatrix/io/point_cloud.rb +19 -11
  30. data/lib/nmatrix/math.rb +224 -5
  31. data/lib/nmatrix/mkmf.rb +103 -0
  32. data/lib/nmatrix/nmatrix.rb +20 -6
  33. data/lib/nmatrix/shortcuts.rb +415 -0
  34. data/lib/nmatrix/version.rb +1 -1
  35. data/spec/00_nmatrix_spec.rb +50 -1
  36. data/spec/02_slice_spec.rb +21 -21
  37. data/spec/blas_spec.rb +25 -3
  38. data/spec/math_spec.rb +233 -5
  39. data/spec/shortcuts_spec.rb +145 -5
  40. data/spec/spec_helper.rb +24 -1
  41. metadata +20 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 862e6785562317ff3ffe71dfa679ab58d3bfd219
4
- data.tar.gz: 428075f3287f76f862bda8dbf6efa837272e6db9
3
+ metadata.gz: 8dd60ade9441cfcdc2c70cd18a60571110c18145
4
+ data.tar.gz: 3ae0a112c051f510718a2d7afad97327bb6808c2
5
5
  SHA512:
6
- metadata.gz: 3d845e422a71670756115bb9a9c6eb6c448b89c08f471395a4ffec74b71bdb4052732df7e619aabc1f5a825b5e2c8f36cc215aaa4b1b20192c1575729a5698e2
7
- data.tar.gz: 8737125b9d9778afa68ee7ac195014f286d29bea4fc7d33081a14610995e6df312fd2767a56207352534b718ae1c361a4c9ff2a5ad289043c091e4687be0fec9
6
+ metadata.gz: 6d9fcb8e0ba7ebb62cd30fa7aba1aafe0bcf1dba7ce7e77a12f3e249280212c668313c94b3e80ce40528829061ef0a6e8b140eda8d8f66175023133712393f72
7
+ data.tar.gz: ba0a384a026c56c01595b7de0b3a3a741bbe021d2b44e358a14c8f5d665c020262d0b400f6eade6a20ee91d65f90e47d730cc015430db5a0539ad4d684ceb6eb
@@ -198,39 +198,39 @@ const nm::dtype_t Upcast[nm::NUM_DTYPES][nm::NUM_DTYPES] = {
198
198
  void rubyval_to_cval(VALUE val, nm::dtype_t dtype, void* loc) {
199
199
  using namespace nm;
200
200
  switch (dtype) {
201
- case BYTE:
201
+ case nm::BYTE:
202
202
  *reinterpret_cast<uint8_t*>(loc) = static_cast<uint8_t>(RubyObject(val));
203
203
  break;
204
204
 
205
- case INT8:
205
+ case nm::INT8:
206
206
  *reinterpret_cast<int8_t*>(loc) = static_cast<int8_t>(RubyObject(val));
207
207
  break;
208
208
 
209
- case INT16:
209
+ case nm::INT16:
210
210
  *reinterpret_cast<int16_t*>(loc) = static_cast<int16_t>(RubyObject(val));
211
211
  break;
212
212
 
213
- case INT32:
213
+ case nm::INT32:
214
214
  *reinterpret_cast<int32_t*>(loc) = static_cast<int32_t>(RubyObject(val));
215
215
  break;
216
216
 
217
- case INT64:
217
+ case nm::INT64:
218
218
  *reinterpret_cast<int64_t*>(loc) = static_cast<int64_t>(RubyObject(val));
219
219
  break;
220
220
 
221
- case FLOAT32:
221
+ case nm::FLOAT32:
222
222
  *reinterpret_cast<float32_t*>(loc) = static_cast<float32_t>(RubyObject(val));
223
223
  break;
224
224
 
225
- case FLOAT64:
225
+ case nm::FLOAT64:
226
226
  *reinterpret_cast<float64_t*>(loc) = static_cast<float64_t>(RubyObject(val));
227
227
  break;
228
228
 
229
- case COMPLEX64:
229
+ case nm::COMPLEX64:
230
230
  *reinterpret_cast<Complex64*>(loc) = RubyObject(val).to<Complex64>();
231
231
  break;
232
232
 
233
- case COMPLEX128:
233
+ case nm::COMPLEX128:
234
234
  *reinterpret_cast<Complex128*>(loc) = RubyObject(val).to<Complex128>();
235
235
  break;
236
236
 
@@ -121,18 +121,17 @@ namespace nm {
121
121
 
122
122
  template <typename Type>
123
123
  Complex<Type>& Complex<Type>::operator=(const RubyObject& other) {
124
- switch(TYPE(other.rval)) {
125
- case T_COMPLEX:
124
+ if (RB_TYPE_P(other.rval, T_COMPLEX)) {
126
125
  this->r = NUM2DBL(rb_funcall(other.rval, rb_intern("real"), 0));
127
126
  this->i = NUM2DBL(rb_funcall(other.rval, rb_intern("imag"), 0));
128
- break;
129
- case T_FLOAT:
130
- case T_FIXNUM:
131
- case T_BIGNUM:
127
+ }
128
+ else if (RB_TYPE_P(other.rval, T_FLOAT) ||
129
+ RB_TYPE_P(other.rval, T_FIXNUM) ||
130
+ RB_TYPE_P(other.rval, T_BIGNUM)) {
132
131
  this->r = NUM2DBL(other.rval);
133
132
  this->i = 0.0;
134
- break;
135
- default:
133
+ }
134
+ else {
136
135
  rb_raise(rb_eTypeError, "not sure how to convert this type of VALUE to a complex");
137
136
  }
138
137
  return *this;
@@ -45,10 +45,7 @@
45
45
  /*
46
46
  * Macros
47
47
  */
48
- #define NM_RUBYVAL_IS_NUMERIC(val) (FIXNUM_P(val) or (TYPE(val) == T_FLOAT) or (TYPE(val) == T_COMPLEX))
49
- #define NMATRIX_CHECK_TYPE(val) \
50
- if (TYPE(val) != T_DATA || (RDATA(val)->dfree != (RUBY_DATA_FUNC)nm_delete && RDATA(val)->dfree != (RUBY_DATA_FUNC)nm_delete_ref)) \
51
- rb_raise(rb_eTypeError, "Expected NMatrix on left-hand side of operation.");
48
+ #define NM_RUBYVAL_IS_NUMERIC(val) (FIXNUM_P(val) or RB_FLOAT_TYPE_P(val) or RB_TYPE_P(val, T_COMPLEX))
52
49
 
53
50
  /*
54
51
  * Classes and Functions
@@ -25,74 +25,18 @@
25
25
  # This file checks for ATLAS and other necessary headers, and
26
26
  # generates a Makefile for compiling NMatrix.
27
27
 
28
- require "mkmf"
28
+ require File.expand_path("../../../lib/nmatrix/mkmf", __FILE__)
29
29
 
30
-
31
- # Function derived from NArray's extconf.rb.
32
- def have_type(type, header=nil) #:nodoc:
33
- printf "checking for %s... ", type
34
- STDOUT.flush
35
-
36
- src = <<"SRC"
37
- #include <ruby.h>
38
- SRC
39
-
40
-
41
- src << <<"SRC" unless header.nil?
42
- #include <#{header}>
43
- SRC
44
-
45
- r = try_link(src + <<"SRC")
46
- int main() { return 0; }
47
- int t() { #{type} a; return 0; }
48
- SRC
49
-
50
- unless r
51
- print "no\n"
52
- return false
53
- end
54
-
55
- $defs.push(format("-DHAVE_%s", type.upcase))
56
-
57
- print "yes\n"
58
-
59
- return true
60
- end
61
-
62
- # Function derived from NArray's extconf.rb.
63
- def create_conf_h(file) #:nodoc:
64
- print "creating #{file}\n"
65
- File.open(file, 'w') do |hfile|
66
- header_guard = file.upcase.sub(/\s|\./, '_')
67
-
68
- hfile.puts "#ifndef #{header_guard}"
69
- hfile.puts "#define #{header_guard}"
70
- hfile.puts
71
-
72
- # FIXME: Find a better way to do this:
73
- hfile.puts "#define RUBY_2 1" if RUBY_VERSION >= '2.0'
74
-
75
- for line in $defs
76
- line =~ /^-D(.*)/
77
- hfile.printf "#define %s 1\n", $1
78
- end
79
-
80
- hfile.puts
81
- hfile.puts "#endif"
82
- end
83
- end
84
-
85
- if RUBY_VERSION < '1.9'
86
- raise(NotImplementedError, "Sorry, you need at least Ruby 1.9!")
87
- else
88
- $INSTALLFILES = [['nmatrix.h', '$(archdir)'], ['nmatrix.hpp', '$(archdir)'], ['nmatrix_config.h', '$(archdir)'], ['nm_memory.h', '$(archdir)']]
89
- if /cygwin|mingw/ =~ RUBY_PLATFORM
90
- $INSTALLFILES << ['libnmatrix.a', '$(archdir)']
91
- end
92
- end
30
+ $INSTALLFILES = [
31
+ ['nmatrix.h' , '$(archdir)'],
32
+ ['nmatrix.hpp' , '$(archdir)'],
33
+ ['nmatrix_config.h', '$(archdir)'],
34
+ ['nm_memory.h' , '$(archdir)'],
35
+ ['ruby_constants.h', '$(archdir)']
36
+ ]
93
37
 
94
38
  if /cygwin|mingw/ =~ RUBY_PLATFORM
95
- CONFIG["DLDFLAGS"] << " --output-lib libnmatrix.a"
39
+ $INSTALLFILES << ['libnmatrix.a', '$(archdir)']
96
40
  end
97
41
 
98
42
  $DEBUG = true
@@ -105,70 +49,8 @@ basenames = %w{nmatrix ruby_constants data/data util/io math util/sl_list storag
105
49
  $objs = basenames.map { |b| "#{b}.o" }
106
50
  $srcs = basenames.map { |b| "#{b}.cpp" }
107
51
 
108
- def find_newer_gplusplus #:nodoc:
109
- print "checking for apparent GNU g++ binary with C++0x/C++11 support... "
110
- [9,8,7,6,5,4,3].each do |minor|
111
- ver = "4.#{minor}"
112
- gpp = "g++-#{ver}"
113
- result = `which #{gpp}`
114
- next if result.empty?
115
- CONFIG['CXX'] = gpp
116
- puts ver
117
- return CONFIG['CXX']
118
- end
119
- false
120
- end
121
-
122
- def gplusplus_version
123
- cxxvar = proc { |n| `#{CONFIG['CXX']} -E -dM - </dev/null | grep #{n}`.chomp.split(' ')[2] }
124
- major = cxxvar.call('__GNUC__')
125
- minor = cxxvar.call('__GNUC_MINOR__')
126
- patch = cxxvar.call('__GNUC_PATCHLEVEL__')
127
-
128
- raise("unable to determine g++ version (match to get version was nil)") if major.nil? || minor.nil? || patch.nil?
129
-
130
- "#{major}.#{minor}.#{patch}"
131
- end
132
-
133
-
134
- if CONFIG['CXX'] == 'clang++'
135
- $CXX_STANDARD = 'c++11'
136
-
137
- else
138
- version = gplusplus_version
139
- if version < '4.3.0' && CONFIG['CXX'] == 'g++' # see if we can find a newer G++, unless it's been overridden by user
140
- if !find_newer_gplusplus
141
- 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++.")
142
- end
143
- version = gplusplus_version
144
- end
145
-
146
- if version < '4.7.0'
147
- $CXX_STANDARD = 'c++0x'
148
- else
149
- $CXX_STANDARD = 'c++11'
150
- end
151
- puts "using C++ standard... #{$CXX_STANDARD}"
152
- puts "g++ reports version... " + `#{CONFIG['CXX']} --version|head -n 1|cut -f 3 -d " "`
153
- end
154
-
155
52
  #$libs += " -lprofiler "
156
53
 
157
- # For release, these next two should both be changed to -O3.
158
- $CFLAGS += " -O3 "
159
- #$CFLAGS += " -static -O0 -g "
160
- $CXXFLAGS += " -O3 -std=#{$CXX_STANDARD} " #-fmax-errors=10 -save-temps
161
- #$CXXFLAGS += " -static -O0 -g -std=#{$CXX_STANDARD} "
162
-
163
- CONFIG['warnflags'].gsub!('-Wshorten-64-to-32', '') # doesn't work except in Mac-patched gcc (4.2)
164
- CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
165
- CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '')
166
-
167
- have_func("rb_array_const_ptr", "ruby.h")
168
- have_macro("FIX_CONST_VALUE_PTR", "ruby.h")
169
- have_macro("RARRAY_CONST_PTR", "ruby.h")
170
- have_macro("RARRAY_AREF", "ruby.h")
171
-
172
54
  create_conf_h("nmatrix_config.h")
173
55
  create_makefile("nmatrix")
174
56
 
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // == Copyright Information
11
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
12
+ // SciRuby is Copyright (c) 2010 - present, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2012 - present, John Woods and the Ruby Science Foundation
14
14
  //
15
15
  // Please see LICENSE.txt for additional copyright notices.
16
16
  //
@@ -134,6 +134,7 @@
134
134
  #include "math/cblas_enums.h"
135
135
 
136
136
  #include "data/data.h"
137
+ #include "math/magnitude.h"
137
138
  #include "math/imax.h"
138
139
  #include "math/scal.h"
139
140
  #include "math/laswp.h"
@@ -237,11 +238,14 @@ namespace nm {
237
238
  int col_index[M];
238
239
 
239
240
  for (int k = 0;k < M; ++k) {
240
- DType akk = std::abs( matrix[k * (M + 1)] ) ; // diagonal element
241
+ typename MagnitudeDType<DType>::type akk;
242
+ akk = magnitude( matrix[k * (M + 1)] ); // diagonal element
243
+
241
244
  int interchange = k;
242
245
 
243
246
  for (int row = k + 1; row < M; ++row) {
244
- DType big = std::abs( matrix[M*row + k] ); // element below the temp pivot
247
+ typename MagnitudeDType<DType>::type big;
248
+ big = magnitude( matrix[M*row + k] ); // element below the temp pivot
245
249
 
246
250
  if ( big > akk ) {
247
251
  interchange = row;
@@ -694,16 +698,12 @@ static VALUE nm_cblas_rot(VALUE self, VALUE n, VALUE x, VALUE incx, VALUE y, VAL
694
698
  static VALUE nm_cblas_nrm2(VALUE self, VALUE n, VALUE x, VALUE incx) {
695
699
 
696
700
  static void (*ttable[nm::NUM_DTYPES])(const int N, const void* X, const int incX, void* sum) = {
697
- /* nm::math::cblas_nrm2<uint8_t,uint8_t>,
698
- nm::math::cblas_nrm2<int8_t,int8_t>,
699
- nm::math::cblas_nrm2<int16_t,int16_t>,
700
- nm::math::cblas_nrm2<int32_t,int32_t>, */
701
701
  NULL, NULL, NULL, NULL, NULL, // no help for integers
702
- nm::math::cblas_nrm2<float32_t,float32_t>,
703
- nm::math::cblas_nrm2<float64_t,float64_t>,
704
- nm::math::cblas_nrm2<float32_t,nm::Complex64>,
705
- nm::math::cblas_nrm2<float64_t,nm::Complex128>,
706
- nm::math::cblas_nrm2<nm::RubyObject,nm::RubyObject>
702
+ nm::math::cblas_nrm2<float32_t>,
703
+ nm::math::cblas_nrm2<float64_t>,
704
+ nm::math::cblas_nrm2<nm::Complex64>,
705
+ nm::math::cblas_nrm2<nm::Complex128>,
706
+ nm::math::cblas_nrm2<nm::RubyObject>
707
707
  };
708
708
 
709
709
  nm::dtype_t dtype = NM_DTYPE(x);
@@ -748,16 +748,16 @@ static VALUE nm_cblas_nrm2(VALUE self, VALUE n, VALUE x, VALUE incx) {
748
748
  static VALUE nm_cblas_asum(VALUE self, VALUE n, VALUE x, VALUE incx) {
749
749
 
750
750
  static void (*ttable[nm::NUM_DTYPES])(const int N, const void* X, const int incX, void* sum) = {
751
- nm::math::cblas_asum<uint8_t,uint8_t>,
752
- nm::math::cblas_asum<int8_t,int8_t>,
753
- nm::math::cblas_asum<int16_t,int16_t>,
754
- nm::math::cblas_asum<int32_t,int32_t>,
755
- nm::math::cblas_asum<int64_t,int64_t>,
756
- nm::math::cblas_asum<float32_t,float32_t>,
757
- nm::math::cblas_asum<float64_t,float64_t>,
758
- nm::math::cblas_asum<float32_t,nm::Complex64>,
759
- nm::math::cblas_asum<float64_t,nm::Complex128>,
760
- nm::math::cblas_asum<nm::RubyObject,nm::RubyObject>
751
+ nm::math::cblas_asum<uint8_t>,
752
+ nm::math::cblas_asum<int8_t>,
753
+ nm::math::cblas_asum<int16_t>,
754
+ nm::math::cblas_asum<int32_t>,
755
+ nm::math::cblas_asum<int64_t>,
756
+ nm::math::cblas_asum<float32_t>,
757
+ nm::math::cblas_asum<float64_t>,
758
+ nm::math::cblas_asum<nm::Complex64>,
759
+ nm::math::cblas_asum<nm::Complex128>,
760
+ nm::math::cblas_asum<nm::RubyObject>
761
761
  };
762
762
 
763
763
  nm::dtype_t dtype = NM_DTYPE(x);
@@ -998,7 +998,7 @@ static VALUE nm_clapack_getrs(VALUE self, VALUE order, VALUE trans, VALUE n, VAL
998
998
 
999
999
  // Allocate the C version of the pivot index array
1000
1000
  int* ipiv_;
1001
- if (TYPE(ipiv) != T_ARRAY) {
1001
+ if (!RB_TYPE_P(ipiv, T_ARRAY)) {
1002
1002
  rb_raise(rb_eArgError, "ipiv must be of type Array");
1003
1003
  } else {
1004
1004
  ipiv_ = NM_ALLOCA_N(int, RARRAY_LEN(ipiv));
@@ -1050,7 +1050,7 @@ static VALUE nm_clapack_laswp(VALUE self, VALUE n, VALUE a, VALUE lda, VALUE k1,
1050
1050
 
1051
1051
  // Allocate the C version of the pivot index array
1052
1052
  int* ipiv_;
1053
- if (TYPE(ipiv) != T_ARRAY) {
1053
+ if (!RB_TYPE_P(ipiv, T_ARRAY)) {
1054
1054
  rb_raise(rb_eArgError, "ipiv must be of type Array");
1055
1055
  } else {
1056
1056
  ipiv_ = NM_ALLOCA_N(int, RARRAY_LEN(ipiv));
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // == Copyright Information
11
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
12
+ // SciRuby is Copyright (c) 2010 - present, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2012 - present, John Woods and the Ruby Science Foundation
14
14
  //
15
15
  // Please see LICENSE.txt for additional copyright notices.
16
16
  //
@@ -60,6 +60,8 @@
60
60
  #define ASUM_H
61
61
 
62
62
 
63
+ #include "math/magnitude.h"
64
+
63
65
  namespace nm { namespace math {
64
66
 
65
67
  /*
@@ -73,44 +75,21 @@ namespace nm { namespace math {
73
75
  * complex64 -> float or double
74
76
  * complex128 -> double
75
77
  */
76
- template <typename ReturnDType, typename DType>
77
- inline ReturnDType asum(const int N, const DType* X, const int incX) {
78
- ReturnDType sum = 0;
79
- if ((N > 0) && (incX > 0)) {
80
- for (int i = 0; i < N; ++i) {
81
- sum += std::abs(X[i*incX]);
82
- }
83
- }
84
- return sum;
85
- }
86
-
87
-
88
- template <>
89
- inline float asum(const int N, const Complex64* X, const int incX) {
90
- float sum = 0;
91
- if ((N > 0) && (incX > 0)) {
92
- for (int i = 0; i < N; ++i) {
93
- sum += std::abs(X[i*incX].r) + std::abs(X[i*incX].i);
94
- }
95
- }
96
- return sum;
97
- }
98
-
99
- template <>
100
- inline double asum(const int N, const Complex128* X, const int incX) {
101
- double sum = 0;
78
+ template <typename DType, typename MDType = typename MagnitudeDType<DType>::type>
79
+ inline MDType asum(const int N, const DType* X, const int incX) {
80
+ MDType sum = 0;
102
81
  if ((N > 0) && (incX > 0)) {
103
82
  for (int i = 0; i < N; ++i) {
104
- sum += std::abs(X[i*incX].r) + std::abs(X[i*incX].i);
83
+ sum += magnitude(X[i*incX]);
105
84
  }
106
85
  }
107
86
  return sum;
108
87
  }
109
88
 
110
89
 
111
- template <typename ReturnDType, typename DType>
90
+ template <typename DType, typename MDType = typename MagnitudeDType<DType>::type>
112
91
  inline void cblas_asum(const int N, const void* X, const int incX, void* sum) {
113
- *reinterpret_cast<ReturnDType*>( sum ) = asum<ReturnDType, DType>( N, reinterpret_cast<const DType*>(X), incX );
92
+ *reinterpret_cast<MDType*>( sum ) = asum<DType,MDType>( N, reinterpret_cast<const DType*>(X), incX );
114
93
  }
115
94
 
116
95
 
@@ -107,9 +107,9 @@ inline void cblas_rot(const int N, void* X, const int incX, void* Y, const int i
107
107
  * complex64 -> float or double
108
108
  * complex128 -> double
109
109
  */
110
- template <typename ReturnDType, typename DType>
111
- inline ReturnDType asum(const int N, const DType* X, const int incX) {
112
- return nm::math::asum<ReturnDType,DType>(N,X,incX);
110
+ template <typename DType, typename MDType = typename MagnitudeDType<DType>::type>
111
+ inline MDType asum(const int N, const DType* X, const int incX) {
112
+ return nm::math::asum<DType,MDType>(N,X,incX);
113
113
  }
114
114
 
115
115
 
@@ -134,9 +134,9 @@ inline double asum(const int N, const Complex128* X, const int incX) {
134
134
  }
135
135
 
136
136
 
137
- template <typename ReturnDType, typename DType>
137
+ template <typename DType, typename MDType = typename MagnitudeDType<DType>::type>
138
138
  inline void cblas_asum(const int N, const void* X, const int incX, void* sum) {
139
- *static_cast<ReturnDType*>( sum ) = asum<ReturnDType, DType>( N, static_cast<const DType*>(X), incX );
139
+ *static_cast<MDType*>( sum ) = asum<DType, MDType>( N, static_cast<const DType*>(X), incX );
140
140
  }
141
141
 
142
142
  /*
@@ -149,9 +149,9 @@ inline void cblas_asum(const int N, const void* X, const int incX, void* sum) {
149
149
  * complex64 -> float or double
150
150
  * complex128 -> double
151
151
  */
152
- template <typename ReturnDType, typename DType>
153
- inline ReturnDType nrm2(const int N, const DType* X, const int incX) {
154
- return nm::math::nrm2<ReturnDType,DType>(N, X, incX);
152
+ template <typename DType, typename MDType = typename MagnitudeDType<DType>::type>
153
+ inline MDType nrm2(const int N, const DType* X, const int incX) {
154
+ return nm::math::nrm2<DType,MDType>(N, X, incX);
155
155
  }
156
156
 
157
157
 
@@ -175,9 +175,9 @@ inline double nrm2(const int N, const Complex128* X, const int incX) {
175
175
  return cblas_dznrm2(N, X, incX);
176
176
  }
177
177
 
178
- template <typename ReturnDType, typename DType>
178
+ template <typename DType, typename MDType = typename MagnitudeDType<DType>::type>
179
179
  inline void cblas_nrm2(const int N, const void* X, const int incX, void* result) {
180
- *static_cast<ReturnDType*>( result ) = nrm2<ReturnDType, DType>( N, static_cast<const DType*>(X), incX );
180
+ *static_cast<MDType*>( result ) = nrm2<DType, MDType>( N, static_cast<const DType*>(X), incX );
181
181
  }
182
182
 
183
183
  //imax