nmatrix 0.0.9 → 0.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/History.txt +95 -1
- data/LICENSE.txt +2 -2
- data/README.rdoc +24 -26
- data/Rakefile +32 -16
- data/ext/nmatrix/data/complex.h +2 -2
- data/ext/nmatrix/data/data.cpp +27 -51
- data/ext/nmatrix/data/data.h +92 -4
- data/ext/nmatrix/data/meta.h +2 -2
- data/ext/nmatrix/data/rational.h +2 -2
- data/ext/nmatrix/data/ruby_object.h +2 -2
- data/ext/nmatrix/extconf.rb +87 -86
- data/ext/nmatrix/math.cpp +45 -40
- data/ext/nmatrix/math/asum.h +3 -3
- data/ext/nmatrix/math/geev.h +2 -2
- data/ext/nmatrix/math/gemm.h +6 -2
- data/ext/nmatrix/math/gemv.h +6 -2
- data/ext/nmatrix/math/ger.h +2 -2
- data/ext/nmatrix/math/gesdd.h +2 -2
- data/ext/nmatrix/math/gesvd.h +2 -2
- data/ext/nmatrix/math/getf2.h +2 -2
- data/ext/nmatrix/math/getrf.h +2 -2
- data/ext/nmatrix/math/getri.h +2 -2
- data/ext/nmatrix/math/getrs.h +7 -3
- data/ext/nmatrix/math/idamax.h +2 -2
- data/ext/nmatrix/math/inc.h +12 -6
- data/ext/nmatrix/math/laswp.h +2 -2
- data/ext/nmatrix/math/long_dtype.h +2 -2
- data/ext/nmatrix/math/math.h +16 -10
- data/ext/nmatrix/math/nrm2.h +3 -3
- data/ext/nmatrix/math/potrs.h +7 -3
- data/ext/nmatrix/math/rot.h +2 -2
- data/ext/nmatrix/math/rotg.h +2 -2
- data/ext/nmatrix/math/scal.h +2 -2
- data/ext/nmatrix/math/swap.h +2 -2
- data/ext/nmatrix/math/trsm.h +7 -3
- data/ext/nmatrix/nm_memory.h +60 -0
- data/ext/nmatrix/nmatrix.cpp +13 -47
- data/ext/nmatrix/nmatrix.h +37 -12
- data/ext/nmatrix/ruby_constants.cpp +4 -2
- data/ext/nmatrix/ruby_constants.h +4 -2
- data/ext/nmatrix/ruby_nmatrix.c +937 -170
- data/ext/nmatrix/storage/common.cpp +2 -2
- data/ext/nmatrix/storage/common.h +2 -2
- data/ext/nmatrix/storage/{dense.cpp → dense/dense.cpp} +253 -100
- data/ext/nmatrix/storage/{dense.h → dense/dense.h} +6 -5
- data/ext/nmatrix/storage/{list.cpp → list/list.cpp} +517 -98
- data/ext/nmatrix/storage/{list.h → list/list.h} +13 -6
- data/ext/nmatrix/storage/storage.cpp +48 -19
- data/ext/nmatrix/storage/storage.h +4 -4
- data/ext/nmatrix/storage/yale/class.h +112 -43
- data/ext/nmatrix/storage/yale/iterators/base.h +2 -2
- data/ext/nmatrix/storage/yale/iterators/iterator.h +2 -2
- data/ext/nmatrix/storage/yale/iterators/row.h +2 -2
- data/ext/nmatrix/storage/yale/iterators/row_stored.h +2 -2
- data/ext/nmatrix/storage/yale/iterators/row_stored_nd.h +4 -3
- data/ext/nmatrix/storage/yale/iterators/stored_diagonal.h +2 -2
- data/ext/nmatrix/storage/yale/math/transpose.h +2 -2
- data/ext/nmatrix/storage/yale/yale.cpp +343 -52
- data/ext/nmatrix/storage/yale/yale.h +7 -3
- data/ext/nmatrix/types.h +2 -2
- data/ext/nmatrix/util/io.cpp +5 -5
- data/ext/nmatrix/util/io.h +2 -2
- data/ext/nmatrix/util/sl_list.cpp +40 -27
- data/ext/nmatrix/util/sl_list.h +3 -3
- data/ext/nmatrix/util/util.h +2 -2
- data/lib/nmatrix.rb +2 -2
- data/lib/nmatrix/blas.rb +2 -2
- data/lib/nmatrix/enumerate.rb +17 -6
- data/lib/nmatrix/io/market.rb +2 -3
- data/lib/nmatrix/io/mat5_reader.rb +2 -2
- data/lib/nmatrix/io/mat_reader.rb +2 -2
- data/lib/nmatrix/lapack.rb +46 -46
- data/lib/nmatrix/math.rb +213 -20
- data/lib/nmatrix/monkeys.rb +24 -2
- data/lib/nmatrix/nmatrix.rb +394 -9
- data/lib/nmatrix/nvector.rb +2 -64
- data/lib/nmatrix/rspec.rb +2 -2
- data/lib/nmatrix/shortcuts.rb +14 -61
- data/lib/nmatrix/version.rb +11 -3
- data/lib/nmatrix/yale_functions.rb +4 -4
- data/nmatrix.gemspec +2 -7
- data/scripts/mac-brew-gcc.sh +11 -8
- data/scripts/mac-mavericks-brew-gcc.sh +22 -0
- data/spec/00_nmatrix_spec.rb +116 -7
- data/spec/01_enum_spec.rb +17 -3
- data/spec/02_slice_spec.rb +11 -3
- data/spec/blas_spec.rb +5 -2
- data/spec/elementwise_spec.rb +5 -2
- data/spec/io_spec.rb +27 -17
- data/spec/lapack_spec.rb +157 -9
- data/spec/math_spec.rb +95 -4
- data/spec/nmatrix_yale_spec.rb +21 -26
- data/spec/rspec_monkeys.rb +27 -0
- data/spec/rspec_spec.rb +2 -2
- data/spec/shortcuts_spec.rb +5 -10
- data/spec/slice_set_spec.rb +6 -2
- data/spec/spec_helper.rb +3 -2
- data/spec/stat_spec.rb +174 -158
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbe2c20e1a86c29f525cda90fd74b6e916b8e406
|
4
|
+
data.tar.gz: 0f50913f5df2579d6d7acb8986f5c5321bdf3bec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aa8a2a396a4c88b0ed73a7674d95ccafd63fe8394cad06319531e0465a12628851dfb796454c6c41b52d102d5688b413f114b4b3a8560de566ea69089da32e7
|
7
|
+
data.tar.gz: 44ec7c62e47ccd107e584500124019a0847ab67a8f88495d376416e491745d7f8550f0aba10d9f5dea6bc90ecd3e8adc23eba5a28fea42b05c22d061a1e103a2
|
data/Gemfile
CHANGED
data/History.txt
CHANGED
@@ -426,4 +426,98 @@
|
|
426
426
|
* nil values in matrices are now pretty printed as "nil"
|
427
427
|
|
428
428
|
* Casting from dense to Yale now properly accepts the default
|
429
|
-
|
429
|
+
value option
|
430
|
+
|
431
|
+
=== 0.1.0.rc1 / 2014-12-28
|
432
|
+
|
433
|
+
* 4 major enhancements:
|
434
|
+
|
435
|
+
* Improved garbage collection strategy for partial object creation
|
436
|
+
(i.e., when VALUEs are allocated but not registered right away),
|
437
|
+
which in addition to fixing numerous bugs should prevent some new
|
438
|
+
bugs from arising in the future (by @cjfuller)
|
439
|
+
|
440
|
+
* Implemented list storage transpose
|
441
|
+
|
442
|
+
* Implemented generic n-dimensional transpose
|
443
|
+
|
444
|
+
* Implemented == comparison between differing matrix stypes
|
445
|
+
|
446
|
+
* 9 minor enhancements:
|
447
|
+
|
448
|
+
* User-friendly #gesvd and #gesdd updates (by @ryanmt)
|
449
|
+
|
450
|
+
* Added experimental #yale_row_key_intersection function for expert
|
451
|
+
recommendation problems
|
452
|
+
|
453
|
+
* Added additional *indgen shortcuts and changed behavior for some;
|
454
|
+
now, #cindgen for :complex64, #zindgen for :complex128, #findgen
|
455
|
+
for :float32, #dindgen for :float64, #rindgen for :rational128,
|
456
|
+
and #rbindgen for Ruby objects (which contain integers); also,
|
457
|
+
removed code repetition
|
458
|
+
|
459
|
+
* Changed #stddev to use elementwise #sqrt instead of a manual map
|
460
|
+
block (by @cjfuller)
|
461
|
+
|
462
|
+
* Added alias from MATLAB `load_mat` method to `load` for
|
463
|
+
consistency with the MatrixMarket loader
|
464
|
+
|
465
|
+
* Improved organization by moving list and yale code into storage/
|
466
|
+
subdirectories
|
467
|
+
|
468
|
+
* Added NMatrix#potrf! and NMatrix#getrf, which are instance methods
|
469
|
+
for calling CLAPACK functions (NMatrix#getrf! already existed)
|
470
|
+
|
471
|
+
* Added GCC installation instructions for Mac OS X Mavericks, and
|
472
|
+
updated the old installation instructions for Mac OS X (both
|
473
|
+
found in scripts/)
|
474
|
+
|
475
|
+
* Switched NMatrix::VERSION to work more like Rails::VERSION, with
|
476
|
+
support for MAJOR, MINOR, TINY, and PRE
|
477
|
+
|
478
|
+
* Added #concat, #hconcat, #vconcat, and #dconcat for joining
|
479
|
+
matrices together
|
480
|
+
|
481
|
+
* 16 bug fixes:
|
482
|
+
|
483
|
+
* Spec revisions for lapack_gesdd and lapack_gesvd (by @ryanmt)
|
484
|
+
|
485
|
+
* Fixed two double-free problems (by @cjfuller and @mohawkjohn)
|
486
|
+
|
487
|
+
* Fixed contiguous array marking fencepost error
|
488
|
+
|
489
|
+
* Fixed C/C++ API compatibility problem preventing rb/gsl linking
|
490
|
+
|
491
|
+
* Resolved a number of compiler warnings, including one return-type
|
492
|
+
problem that would likely have become a garbage collection error
|
493
|
+
(if it wasn't already)
|
494
|
+
|
495
|
+
* Fixed -O3 optimization problems
|
496
|
+
|
497
|
+
* Restored NMatrix#asum, #nrm2, #binned_sorted_indices,
|
498
|
+
#sorted_indices which were inadvertantly removed by NVector
|
499
|
+
deprecation; have not tested
|
500
|
+
|
501
|
+
* Experimental #yale_nd_row and functions which call it now checks
|
502
|
+
range of argument to prevent segfault
|
503
|
+
|
504
|
+
* Fixed :* shortcut for a full list dimension (by @cjfuller)
|
505
|
+
|
506
|
+
* Fixed list construction problem which occurred when an initial
|
507
|
+
value array was provided (by @cjfuller)
|
508
|
+
|
509
|
+
* Fixed #inject issue with list and yale matrices of two dimensions
|
510
|
+
(by @cjfuller)
|
511
|
+
|
512
|
+
* Fixed several garbage collection problems (also listed under
|
513
|
+
enhancements) (by @cjfuller)
|
514
|
+
|
515
|
+
* Updated object cleaning target in extconf.rb
|
516
|
+
|
517
|
+
* Fixed possible compilation problem on Mavericks with Xcode 5.02
|
518
|
+
|
519
|
+
* Fixed errors involving undefined symbols, unresolved symbols, and
|
520
|
+
lazy symbol binding
|
521
|
+
|
522
|
+
* Improved LAPACK and BLAS header selection for Ubuntu/Debian
|
523
|
+
systems with ATLAS (by @mvz)
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
This version of
|
1
|
+
This version of NMatrix is licensed under the BSD 2-clause license.
|
2
2
|
|
3
3
|
* http://sciruby.com
|
4
4
|
* http://github.com/sciruby/sciruby/wiki/License
|
@@ -9,7 +9,7 @@ You *must* read the Contributor Agreement before contributing code to the SciRub
|
|
9
9
|
|
10
10
|
-----
|
11
11
|
|
12
|
-
Copyright (c) 2010 -
|
12
|
+
Copyright (c) 2010 - 2014, Ruby Science Foundation
|
13
13
|
All rights reserved.
|
14
14
|
|
15
15
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
data/README.rdoc
CHANGED
@@ -7,6 +7,8 @@ Fast Numerical Linear Algebra Library for Ruby
|
|
7
7
|
* {NMatrix Installation wiki}[https://github.com/SciRuby/nmatrix/wiki/Installation]
|
8
8
|
* {SciRuby Installation guide}[http://sciruby.com/docs#installation]
|
9
9
|
|
10
|
+
{<img src=https://travis-ci.org/SciRuby/nmatrix.png>}[https://travis-ci.org/SciRuby/nmatrix]
|
11
|
+
|
10
12
|
== Description
|
11
13
|
|
12
14
|
NMatrix is a fast numerical linear algebra library for Ruby, with dense and sparse matrices, written mostly in C and
|
@@ -24,8 +26,7 @@ However, you will need to install {ATLAS}[http://math-atlas.sourceforge.net/] wi
|
|
24
26
|
{BLAS}[http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms]) first. Detailed directions can be found
|
25
27
|
{here}[https://github.com/SciRuby/nmatrix/wiki/Installation]. The requirements for NMatrix are:
|
26
28
|
|
27
|
-
* ATLAS
|
28
|
-
* LAPACK, probably ({see here for details}[https://github.com/SciRuby/nmatrix/wiki/Installation])
|
29
|
+
* ATLAS, preferably with CLAPACK ({see here for details}[https://github.com/SciRuby/nmatrix/wiki/Installation])
|
29
30
|
* a version of GCC or clang which supports C++0x or C++11
|
30
31
|
* Ruby 1.9.3+
|
31
32
|
* {packable}[http://github.com/marcandre/packable] 1.3.5 (used for I/O)
|
@@ -37,9 +38,11 @@ If you want to obtain the latest (development) code, you should generally do:
|
|
37
38
|
bundle install
|
38
39
|
bundle exec rake compile
|
39
40
|
bundle exec rake repackage
|
40
|
-
gem install pkg/nmatrix-0.1.0.gem
|
41
|
+
gem install pkg/nmatrix-0.1.0-rc1.gem
|
41
42
|
|
42
43
|
Detailed instructions are available for {Mac}[https://github.com/SciRuby/nmatrix/wiki/Installation#mac-os-x] and {Linux}[https://github.com/SciRuby/nmatrix/wiki/Installation#linux].
|
44
|
+
We are currently working on Mavericks (Mac OS X) installation instructions, but in general, you'll need Homebrew and should
|
45
|
+
probably use +brew install gcc48+ instead of using the install script.
|
43
46
|
|
44
47
|
== Documentation
|
45
48
|
|
@@ -52,21 +55,27 @@ You can find the complete API documentation {on our website}[http://sciruby.com/
|
|
52
55
|
|
53
56
|
== Examples
|
54
57
|
|
55
|
-
Create a new NMatrix from a ruby
|
58
|
+
Create a new NMatrix from a ruby Array:
|
56
59
|
|
57
60
|
>> require 'nmatrix'
|
58
|
-
>> NMatrix.new([2, 3], [0, 1, 2, 3, 4, 5], dtype: :int64)
|
59
|
-
|
60
|
-
|
61
|
-
|
61
|
+
>> NMatrix.new([2, 3], [0, 1, 2, 3, 4, 5], dtype: :int64)
|
62
|
+
=> [
|
63
|
+
[0, 1, 2],
|
64
|
+
[3, 4, 5]
|
65
|
+
]
|
62
66
|
|
63
67
|
Create a new NMatrix using the +N+ shortcut:
|
64
68
|
|
65
69
|
>> m = N[ [2, 3, 4], [7, 8, 9] ]
|
70
|
+
=> [
|
71
|
+
[2, 3, 4],
|
72
|
+
[7, 8, 9]
|
73
|
+
]
|
74
|
+
>> m.inspect
|
66
75
|
=> #<NMatrix:0x007f8e121b6cf8shape:[2,3] dtype:int32 stype:dense>
|
67
|
-
|
68
|
-
|
69
|
-
|
76
|
+
|
77
|
+
The above output requires that you have a pretty-print-enabled console such as Pry; otherwise, you'll
|
78
|
+
see the output given by +inspect+.
|
70
79
|
|
71
80
|
If you want to learn more about how to create a
|
72
81
|
matrix, {read the guide in our wiki}[https://github.com/SciRuby/nmatrix/wiki/How-to-create-a-NMatrix].
|
@@ -79,7 +88,7 @@ Read the instructions in +CONTRIBUTING.md+ if you want to help NMatrix.
|
|
79
88
|
|
80
89
|
== Features
|
81
90
|
|
82
|
-
The following features exist in the current version of NMatrix (0.0.
|
91
|
+
The following features exist in the current version of NMatrix (0.1.0.rc1):
|
83
92
|
|
84
93
|
* Matrix and vector storage containers: dense, yale, list (more to come)
|
85
94
|
* Data types: byte (uint8), int8, int16, int32, int64, float32, float64, complex64, complex128, rational64, rational128,
|
@@ -114,6 +123,8 @@ The following features exist in the current version of NMatrix (0.0.8):
|
|
114
123
|
* Determinant calculation for BLAS dtypes
|
115
124
|
* Vector 2-norms
|
116
125
|
* Ruby/GSL interoperability (requires {SciRuby's fork of rb-gsl}(http://github.com/SciRuby/rb-gsl))
|
126
|
+
* slice assignments, e.g.,
|
127
|
+
x[1..3,0..4] = some_other_matrix
|
117
128
|
|
118
129
|
=== Planned Features (Short-to-Medium Term)
|
119
130
|
|
@@ -121,29 +132,16 @@ We are nearly the release of NMatrix 0.1.0, our first beta.
|
|
121
132
|
|
122
133
|
These are features planned for NMatrix 0.2.0:
|
123
134
|
|
124
|
-
* slice assignments, e.g.,
|
125
|
-
x[1..3,0..4] = some_other_matrix
|
126
135
|
* LAPACK-free calculation of determinant, trace, and eigenvalues (characteristic polynomial)
|
127
136
|
* LAPACK-free matrix inversions
|
128
137
|
* tensor products
|
129
|
-
* principal component analysis (PCA)
|
130
138
|
* improved file I/O
|
131
139
|
* compression of yale symmetries in I/O
|
132
140
|
* optimization of non-BLAS data types on BLAS-like operations (e.g., matrix multiplication for rational numbers)
|
133
141
|
|
134
|
-
=== Warning
|
135
|
-
|
136
|
-
Please be aware that SciRuby and NMatrix are *alpha* status. If you're thinking of using SciRuby/NMatrix to write
|
137
|
-
mission-critical code, such as for driving a car or flying a space shuttle, you may wish to choose other software for
|
138
|
-
now.
|
139
|
-
|
140
|
-
You should also be aware that NMatrix and NArray are incompatible with one another; you should not try to require both
|
141
|
-
at the same time. Unfortunately, that causes problems with Ruby/GSL, which currently depends upon NArray. As such, we
|
142
|
-
have a {fork of Ruby/GSL}[https://github.com/SciRuby/rb-gsl].
|
143
|
-
|
144
142
|
== License
|
145
143
|
|
146
|
-
Copyright (c)
|
144
|
+
Copyright (c) 2012--14, John Woods and the Ruby Science Foundation.
|
147
145
|
|
148
146
|
All rights reserved.
|
149
147
|
|
data/Rakefile
CHANGED
@@ -41,18 +41,26 @@ BASEDIR = Pathname( __FILE__ ).dirname.relative_path_from( Pathname.pwd )
|
|
41
41
|
SPECDIR = BASEDIR + 'spec'
|
42
42
|
|
43
43
|
VALGRIND_OPTIONS = [
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
"--tool=memcheck",
|
45
|
+
#"--leak-check=yes",
|
46
|
+
"--num-callers=15",
|
47
|
+
#"--error-limit=no",
|
48
|
+
"--partial-loads-ok=yes",
|
49
|
+
"--undef-value-errors=no" #,
|
50
|
+
#"--dsymutil=yes"
|
51
51
|
]
|
52
|
+
|
53
|
+
CALLGRIND_OPTIONS = [
|
54
|
+
"--tool=callgrind",
|
55
|
+
"--dump-instr=yes",
|
56
|
+
"--simulate-cache=yes",
|
57
|
+
"--collect-jumps=yes"
|
58
|
+
]
|
59
|
+
|
52
60
|
VALGRIND_MEMORYFILL_OPTIONS = [
|
53
|
-
|
54
|
-
|
55
|
-
|
61
|
+
"--freelist-vol=100000000",
|
62
|
+
"--malloc-fill=6D",
|
63
|
+
"--free-fill=66 ",
|
56
64
|
]
|
57
65
|
|
58
66
|
GDB_OPTIONS = []
|
@@ -125,17 +133,25 @@ namespace :spec do
|
|
125
133
|
desc "Run specs under cgdb."
|
126
134
|
task :cgdb => [ :compile ] do |task|
|
127
135
|
cmd = [ 'cgdb' ] + GDB_OPTIONS
|
128
|
-
|
129
|
-
|
130
|
-
|
136
|
+
cmd += [ '--args' ]
|
137
|
+
cmd += RSPEC_CMD
|
138
|
+
run( *cmd )
|
131
139
|
end
|
132
140
|
|
133
141
|
desc "Run specs under Valgrind."
|
134
142
|
task :valgrind => [ :compile ] do |task|
|
135
|
-
|
136
|
-
|
137
|
-
|
143
|
+
cmd = [ 'valgrind' ] + VALGRIND_OPTIONS
|
144
|
+
cmd += RSPEC_CMD
|
145
|
+
run( *cmd )
|
146
|
+
end
|
147
|
+
|
148
|
+
desc "Run specs under Callgrind."
|
149
|
+
task :callgrind => [ :compile ] do |task|
|
150
|
+
cmd = [ 'valgrind' ] + CALLGRIND_OPTIONS
|
151
|
+
cmd += RSPEC_CMD
|
152
|
+
run( *cmd )
|
138
153
|
end
|
154
|
+
|
139
155
|
end
|
140
156
|
|
141
157
|
|
data/ext/nmatrix/data/complex.h
CHANGED
@@ -9,8 +9,8 @@
|
|
9
9
|
//
|
10
10
|
// == Copyright Information
|
11
11
|
//
|
12
|
-
// SciRuby is Copyright (c) 2010 -
|
13
|
-
// NMatrix is Copyright (c)
|
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
14
|
//
|
15
15
|
// Please see LICENSE.txt for additional copyright notices.
|
16
16
|
//
|
data/ext/nmatrix/data/data.cpp
CHANGED
@@ -9,8 +9,8 @@
|
|
9
9
|
//
|
10
10
|
// == Copyright Information
|
11
11
|
//
|
12
|
-
// SciRuby is Copyright (c) 2010 -
|
13
|
-
// NMatrix is Copyright (c)
|
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
14
|
//
|
15
15
|
// Please see LICENSE.txt for additional copyright notices.
|
16
16
|
//
|
@@ -73,50 +73,24 @@ namespace nm {
|
|
73
73
|
"geq"
|
74
74
|
};
|
75
75
|
|
76
|
+
const std::string NONCOM_EWOP_NAMES[nm::NUM_NONCOM_EWOPS] = {
|
77
|
+
"atan2",
|
78
|
+
"ldexp",
|
79
|
+
"hypot"
|
80
|
+
};
|
76
81
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
case T_FIXNUM:
|
87
|
-
case T_BIGNUM:
|
88
|
-
r = NUM2DBL(other.rval);
|
89
|
-
i = 0.0;
|
90
|
-
break;
|
91
|
-
default:
|
92
|
-
rb_raise(rb_eTypeError, "not sure how to convert this type of VALUE to a complex");
|
93
|
-
}
|
94
|
-
}
|
95
|
-
|
96
|
-
|
97
|
-
template <typename Type>
|
98
|
-
Rational<Type>::Rational(const RubyObject& other) {
|
99
|
-
switch (TYPE(other.rval)) {
|
100
|
-
case T_RATIONAL:
|
101
|
-
n = NUM2LONG(rb_funcall(other.rval, rb_intern("numerator"), 0));
|
102
|
-
d = NUM2LONG(rb_funcall(other.rval, rb_intern("denominator"), 0));
|
103
|
-
break;
|
104
|
-
case T_FIXNUM:
|
105
|
-
case T_BIGNUM:
|
106
|
-
n = NUM2LONG(other.rval);
|
107
|
-
d = 1;
|
108
|
-
break;
|
109
|
-
case T_COMPLEX:
|
110
|
-
case T_FLOAT:
|
111
|
-
rb_raise(rb_eTypeError, "cannot convert float to a rational");
|
112
|
-
break;
|
113
|
-
default:
|
114
|
-
rb_raise(rb_eTypeError, "not sure how to convert this type of VALUE to a rational");
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
82
|
+
const std::string UNARYOPS[nm::NUM_UNARYOPS] = {
|
83
|
+
"sin", "cos", "tan",
|
84
|
+
"asin", "acos", "atan",
|
85
|
+
"sinh", "cosh", "tanh",
|
86
|
+
"asinh", "acosh", "atanh",
|
87
|
+
"exp", "log2",
|
88
|
+
"log10", "sqrt", "erf",
|
89
|
+
"erfc", "cbrt", "gamma"
|
90
|
+
};
|
118
91
|
|
119
92
|
} // end of namespace nm
|
93
|
+
|
120
94
|
extern "C" {
|
121
95
|
|
122
96
|
const char* const DTYPE_NAMES[nm::NUM_DTYPES] = {
|
@@ -301,21 +275,23 @@ nm::RubyObject rubyobj_from_cval(void* val, nm::dtype_t dtype) {
|
|
301
275
|
*/
|
302
276
|
void* rubyobj_to_cval(VALUE val, nm::dtype_t dtype) {
|
303
277
|
size_t size = DTYPE_SIZES[dtype];
|
304
|
-
|
278
|
+
NM_CONSERVATIVE(nm_register_value(val));
|
279
|
+
void* ret_val = NM_ALLOC_N(char, size);
|
305
280
|
|
306
281
|
rubyval_to_cval(val, dtype, ret_val);
|
307
|
-
|
282
|
+
NM_CONSERVATIVE(nm_unregister_value(val));
|
308
283
|
return ret_val;
|
309
284
|
}
|
310
285
|
|
311
286
|
|
312
287
|
void nm_init_data() {
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
288
|
+
volatile VALUE t = INT2FIX(1);
|
289
|
+
volatile nm::RubyObject obj(t);
|
290
|
+
volatile nm::Rational32 x(const_cast<nm::RubyObject&>(obj));
|
291
|
+
volatile nm::Rational64 y(const_cast<nm::RubyObject&>(obj));
|
292
|
+
volatile nm::Rational128 z(const_cast<nm::RubyObject&>(obj));
|
293
|
+
volatile nm::Complex64 a(const_cast<nm::RubyObject&>(obj));
|
294
|
+
volatile nm::Complex128 b(const_cast<nm::RubyObject&>(obj));
|
319
295
|
}
|
320
296
|
|
321
297
|
|
data/ext/nmatrix/data/data.h
CHANGED
@@ -9,8 +9,8 @@
|
|
9
9
|
//
|
10
10
|
// == Copyright Information
|
11
11
|
//
|
12
|
-
// SciRuby is Copyright (c) 2010 -
|
13
|
-
// NMatrix is Copyright (c)
|
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
14
|
//
|
15
15
|
// Please see LICENSE.txt for additional copyright notices.
|
16
16
|
//
|
@@ -55,7 +55,8 @@ namespace nm {
|
|
55
55
|
const int NUM_DTYPES = 13;
|
56
56
|
const int NUM_ITYPES = 4;
|
57
57
|
const int NUM_EWOPS = 12;
|
58
|
-
const int
|
58
|
+
const int NUM_UNARYOPS = 21;
|
59
|
+
const int NUM_NONCOM_EWOPS = 3;
|
59
60
|
|
60
61
|
enum ewop_t {
|
61
62
|
EW_ADD,
|
@@ -69,12 +70,85 @@ namespace nm {
|
|
69
70
|
EW_LT,
|
70
71
|
EW_GT,
|
71
72
|
EW_LEQ,
|
72
|
-
EW_GEQ
|
73
|
+
EW_GEQ,
|
74
|
+
};
|
75
|
+
|
76
|
+
enum noncom_ewop_t {
|
77
|
+
NONCOM_EW_ATAN2,
|
78
|
+
NONCOM_EW_LDEXP,
|
79
|
+
NONCOM_EW_HYPOT
|
80
|
+
};
|
81
|
+
|
82
|
+
enum unaryop_t {
|
83
|
+
UNARY_SIN,
|
84
|
+
UNARY_COS,
|
85
|
+
UNARY_TAN,
|
86
|
+
UNARY_ASIN,
|
87
|
+
UNARY_ACOS,
|
88
|
+
UNARY_ATAN,
|
89
|
+
UNARY_SINH,
|
90
|
+
UNARY_COSH,
|
91
|
+
UNARY_TANH,
|
92
|
+
UNARY_ASINH,
|
93
|
+
UNARY_ACOSH,
|
94
|
+
UNARY_ATANH,
|
95
|
+
UNARY_EXP,
|
96
|
+
UNARY_LOG2,
|
97
|
+
UNARY_LOG10,
|
98
|
+
UNARY_SQRT,
|
99
|
+
UNARY_ERF,
|
100
|
+
UNARY_ERFC,
|
101
|
+
UNARY_CBRT,
|
102
|
+
UNARY_GAMMA
|
73
103
|
};
|
74
104
|
|
75
105
|
// element-wise and scalar operators
|
76
106
|
extern const char* const EWOP_OPS[nm::NUM_EWOPS];
|
77
107
|
extern const std::string EWOP_NAMES[nm::NUM_EWOPS];
|
108
|
+
extern const std::string UNARYOPS[nm::NUM_UNARYOPS];
|
109
|
+
extern const std::string NONCOM_EWOP_NAMES[nm::NUM_NONCOM_EWOPS];
|
110
|
+
|
111
|
+
|
112
|
+
template <typename Type>
|
113
|
+
Complex<Type>::Complex(const RubyObject& other) {
|
114
|
+
switch(TYPE(other.rval)) {
|
115
|
+
case T_COMPLEX:
|
116
|
+
r = NUM2DBL(rb_funcall(other.rval, rb_intern("real"), 0));
|
117
|
+
i = NUM2DBL(rb_funcall(other.rval, rb_intern("imag"), 0));
|
118
|
+
break;
|
119
|
+
case T_FLOAT:
|
120
|
+
case T_RATIONAL:
|
121
|
+
case T_FIXNUM:
|
122
|
+
case T_BIGNUM:
|
123
|
+
r = NUM2DBL(other.rval);
|
124
|
+
i = 0.0;
|
125
|
+
break;
|
126
|
+
default:
|
127
|
+
rb_raise(rb_eTypeError, "not sure how to convert this type of VALUE to a complex");
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
template <typename Type>
|
133
|
+
Rational<Type>::Rational(const RubyObject& other) {
|
134
|
+
switch (TYPE(other.rval)) {
|
135
|
+
case T_RATIONAL:
|
136
|
+
n = NUM2LONG(rb_funcall(other.rval, rb_intern("numerator"), 0));
|
137
|
+
d = NUM2LONG(rb_funcall(other.rval, rb_intern("denominator"), 0));
|
138
|
+
break;
|
139
|
+
case T_FIXNUM:
|
140
|
+
case T_BIGNUM:
|
141
|
+
n = NUM2LONG(other.rval);
|
142
|
+
d = 1;
|
143
|
+
break;
|
144
|
+
case T_COMPLEX:
|
145
|
+
case T_FLOAT:
|
146
|
+
rb_raise(rb_eTypeError, "cannot convert float to a rational");
|
147
|
+
break;
|
148
|
+
default:
|
149
|
+
rb_raise(rb_eTypeError, "not sure how to convert this type of VALUE to a rational");
|
150
|
+
}
|
151
|
+
}
|
78
152
|
|
79
153
|
|
80
154
|
} // end of namespace nm
|
@@ -90,6 +164,20 @@ namespace nm {
|
|
90
164
|
nm_yale_storage_mark \
|
91
165
|
};
|
92
166
|
|
167
|
+
#define STYPE_REGISTER_TABLE(name) \
|
168
|
+
static void (*(name)[nm::NUM_STYPES])(const STORAGE*) = { \
|
169
|
+
nm_dense_storage_register, \
|
170
|
+
nm_list_storage_register, \
|
171
|
+
nm_yale_storage_register \
|
172
|
+
};
|
173
|
+
|
174
|
+
#define STYPE_UNREGISTER_TABLE(name) \
|
175
|
+
static void (*(name)[nm::NUM_STYPES])(const STORAGE*) = { \
|
176
|
+
nm_dense_storage_unregister, \
|
177
|
+
nm_list_storage_unregister, \
|
178
|
+
nm_yale_storage_unregister \
|
179
|
+
};
|
180
|
+
|
93
181
|
#define CAST_TABLE(name) \
|
94
182
|
static STORAGE* (*(name)[nm::NUM_STYPES][nm::NUM_STYPES])(const STORAGE*, nm::dtype_t, void*) = { \
|
95
183
|
{ nm_dense_storage_cast_copy, nm_dense_storage_from_list, nm_dense_storage_from_yale }, \
|