Skip to content

Commit ed7ed35

Browse files
author
John Woods
committed
Merge branch 'master' of github.com:sciruby/nmatrix
2 parents 5a1fd1f + 212859b commit ed7ed35

File tree

7 files changed

+51
-17
lines changed

7 files changed

+51
-17
lines changed

README.rdoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The requirements for NMatrix are:
4444
To install +nmatrix-atlas+ or +nmatrix-lapacke+, an additional requirement is a
4545
compatible LAPACK library.
4646
Detailed directions for this step can be found
47-
{here}[https://github.com/wlevine/nmatrix/wiki/Installation].
47+
{here}[https://github.com/SciRuby/nmatrix/wiki/Installation].
4848

4949
If you want to obtain the latest (development) code, you should generally do:
5050

@@ -79,7 +79,7 @@ singular value decomposition, eigenvalues/eigenvectors, inverses of matrices
7979
bigger than 3-by-3), your code now depends on the +nmatrix-atlas+ gem. You
8080
will need to add this a dependency of your project and <tt>require 'nmatrix/atlas'</tt>
8181
in addition to <tt>require 'nmatrix'</tt>. In most cases, no further changes
82-
should be necessary, however there have been a few {API changes}[https://github.com/wlevine/nmatrix/wiki/API-Changes], please check
82+
should be necessary, however there have been a few {API changes}[https://github.com/SciRuby/nmatrix/wiki/API-Changes], please check
8383
to see if these affect you.
8484

8585
== Documentation

ext/nmatrix/extconf.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def gplusplus_version
158158
#$libs += " -lprofiler "
159159

160160
# For release, these next two should both be changed to -O3.
161-
$CFLAGS += " -O0 -g "
161+
$CFLAGS += " -O3 "
162162
#$CFLAGS += " -static -O0 -g "
163-
$CPPFLAGS += " -O0 -g -std=#{$CPP_STANDARD} " #-fmax-errors=10 -save-temps
163+
$CPPFLAGS += " -O3 -std=#{$CPP_STANDARD} " #-fmax-errors=10 -save-temps
164164
#$CPPFLAGS += " -static -O0 -g -std=#{$CPP_STANDARD} "
165165

166166
CONFIG['warnflags'].gsub!('-Wshorten-64-to-32', '') # doesn't work except in Mac-patched gcc (4.2)

ext/nmatrix/ruby_nmatrix.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,22 @@ static VALUE nm_eqeq(VALUE left, VALUE right) {
880880

881881
bool result = false;
882882

883+
// Check that the shapes match before going any further.
884+
if (l->storage->dim != r->storage->dim) {
885+
NM_CONSERVATIVE(nm_unregister_value(&left));
886+
NM_CONSERVATIVE(nm_unregister_value(&right));
887+
rb_raise(nm_eShapeError, "cannot compare matrices with different dimension");
888+
}
889+
890+
size_t dim = l->storage->dim;
891+
for (size_t i=0; i<dim; i++) {
892+
if (l->storage->shape[i] != r->storage->shape[i]) {
893+
NM_CONSERVATIVE(nm_unregister_value(&left));
894+
NM_CONSERVATIVE(nm_unregister_value(&right));
895+
rb_raise(nm_eShapeError, "cannot compare matrices with different shapes");
896+
}
897+
}
898+
883899
if (l->stype != r->stype) { // DIFFERENT STYPES
884900

885901
if (l->stype == nm::DENSE_STORE)

ext/nmatrix/storage/dense/dense.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -976,12 +976,6 @@ bool eqeq(const DENSE_STORAGE* left, const DENSE_STORAGE* right) {
976976
tmp1 = NULL; tmp2 = NULL;
977977
bool result = true;
978978
/* FIXME: Very strange behavior! The GC calls the method directly with non-initialized data. */
979-
if (left->dim != right->dim) {
980-
nm_dense_storage_unregister(right);
981-
nm_dense_storage_unregister(left);
982-
983-
return false;
984-
}
985979

986980
LDType* left_elements = (LDType*)left->elements;
987981
RDType* right_elements = (RDType*)right->elements;

lib/nmatrix/nmatrix.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,8 @@ def __sparse_initial_set__(ary) #:nodoc:
10771077
end
10781078

10791079

1080-
# Function assumes the dimensions and such have already been tested.
1080+
# This function assumes that the shapes of the two matrices have already
1081+
# been tested and are the same.
10811082
#
10821083
# Called from inside NMatrix: nm_eqeq
10831084
#

spec/00_nmatrix_spec.rb

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,36 @@
478478
context "#==" do
479479
[:dense, :list, :yale].each do |left|
480480
[:dense, :list, :yale].each do |right|
481-
next if left == right
482481
context ("#{left}?#{right}") do
483-
it "should compare two matrices of differing stypes" do
484-
n = NMatrix.new([3,4], [0,0,1,2,0,0,3,4,0,0,0,0,5,6,7,0], stype: left)
485-
m = NMatrix.new([3,4], [0,0,1,2,0,0,3,4,0,0,0,0,5,6,7,0], stype: right)
486-
expect(n).to eq(m)
482+
it "tests equality of two equal matrices" do
483+
n = NMatrix.new([3,4], [0,0,1,2,0,0,3,4,0,0,0,0], stype: left)
484+
m = NMatrix.new([3,4], [0,0,1,2,0,0,3,4,0,0,0,0], stype: right)
485+
486+
expect(n==m).to eq(true)
487487
end
488+
489+
it "tests equality of two unequal matrices" do
490+
n = NMatrix.new([3,4], [0,0,1,2,0,0,3,4,0,0,0,1], stype: left)
491+
m = NMatrix.new([3,4], [0,0,1,2,0,0,3,4,0,0,0,0], stype: right)
492+
493+
expect(n==m).to eq(false)
494+
end
495+
496+
it "tests equality of matrices with different shapes" do
497+
n = NMatrix.new([2,2], [1,2, 3,4], stype: left)
498+
m = NMatrix.new([2,3], [1,2, 3,4, 5,6], stype: right)
499+
x = NMatrix.new([1,4], [1,2, 3,4], stype: right)
500+
501+
expect{n==m}.to raise_error(ShapeError)
502+
expect{n==x}.to raise_error(ShapeError)
503+
end
504+
505+
it "tests equality of matrices with different dimension" do
506+
n = NMatrix.new([2,1], [1,2], stype: left)
507+
m = NMatrix.new([2], [1,2], stype: right)
508+
509+
expect{n==m}.to raise_error(ShapeError)
510+
end if left != :yale && right != :yale # yale must have dimension 2
488511
end
489512
end
490513
end

spec/03_nmatrix_monkeys_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
it "intuits shape of Array into multiple dimensions" do
6161
a = [[[0], [1]], [[2], [3]], [[4], [5]]]
62-
expect(a.to_nm).to eq(NMatrix.new([3,1,2], a.flatten))
62+
expect(a.to_nm).to eq(NMatrix.new([3,2,1], a.flatten))
6363
expect(a).to eq(a.to_nm.to_a)
6464
end
6565

0 commit comments

Comments
 (0)