summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Bignier <paul.bignier@scilab-enterprises.com>2016-12-15 17:09:45 +0100
committerClément DAVID <clement.david@scilab-enterprises.com>2016-12-16 09:27:27 +0100
commitb90c8368858258f164eec501311988af9f135dd1 (patch)
tree78cd1e66ba7c5ee81719e9a437744e6967ebe0e9
parent0fcd811f8144d9bfac8f82c01a799399a5d7ba5a (diff)
downloadscilab-b90c8368858258f164eec501311988af9f135dd1.zip
scilab-b90c8368858258f164eec501311988af9f135dd1.tar.gz
AST: error out on wrong matrix multiplication
* matrix*hyper & hyper*hyper can still be overloaded but not matrix*matrix with wrong dimensions * numderivative.tst passes again Change-Id: I834a753ac30fcb2c5ec441d4b1af9339325c875f
-rw-r--r--scilab/modules/ast/src/cpp/operations/types_multiplication.cpp6
-rw-r--r--scilab/modules/ast/tests/unit_tests/multiplication.dia.ref3
-rw-r--r--scilab/modules/ast/tests/unit_tests/multiplication.tst4
3 files changed, 13 insertions, 0 deletions
diff --git a/scilab/modules/ast/src/cpp/operations/types_multiplication.cpp b/scilab/modules/ast/src/cpp/operations/types_multiplication.cpp
index 9641dcc..5778ea5 100644
--- a/scilab/modules/ast/src/cpp/operations/types_multiplication.cpp
+++ b/scilab/modules/ast/src/cpp/operations/types_multiplication.cpp
@@ -235,6 +235,12 @@ int MultiplyDoubleByDouble(Double* _pDouble1, Double* _pDouble2, Double** _pDoub
235 return 0; 235 return 0;
236 } 236 }
237 237
238 if (_pDouble1->getDims() == 2 && _pDouble1->getDims() == _pDouble2->getDims() && _pDouble1->getCols() != _pDouble2->getRows())
239 {
240 // Both matrices but with wrong dimensions: error out
241 return 1;
242 }
243
238 if (_pDouble1->getDims() > 2 || _pDouble2->getDims() > 2 || _pDouble1->getCols() != _pDouble2->getRows()) 244 if (_pDouble1->getDims() > 2 || _pDouble2->getDims() > 2 || _pDouble1->getCols() != _pDouble2->getRows())
239 { 245 {
240 //call overload 246 //call overload
diff --git a/scilab/modules/ast/tests/unit_tests/multiplication.dia.ref b/scilab/modules/ast/tests/unit_tests/multiplication.dia.ref
index e8759f4..633c330 100644
--- a/scilab/modules/ast/tests/unit_tests/multiplication.dia.ref
+++ b/scilab/modules/ast/tests/unit_tests/multiplication.dia.ref
@@ -73,3 +73,6 @@ assert_checkequal(R * C, [ 7+%i*14, 10+%i*20; 15+%i*30, 22+%i*44]);
73assert_checkequal(C * R, [ 7+%i*14, 10+%i*20; 15+%i*30, 22+%i*44]); 73assert_checkequal(C * R, [ 7+%i*14, 10+%i*20; 15+%i*30, 22+%i*44]);
74// C * C 74// C * C
75assert_checkequal(C * C, [-21+%i*28,-30+%i*40;-45+%i*60,-66+%i*88]); 75assert_checkequal(C * C, [-21+%i*28,-30+%i*40;-45+%i*60,-66+%i*88]);
76errmsg = gettext("Inconsistent row/column dimensions.");
77assert_checkerror("[1;1]*[1;1]", errmsg);
78assert_checkerror("[1 1]*[1 1]", errmsg);
diff --git a/scilab/modules/ast/tests/unit_tests/multiplication.tst b/scilab/modules/ast/tests/unit_tests/multiplication.tst
index 0f08494..452b43a 100644
--- a/scilab/modules/ast/tests/unit_tests/multiplication.tst
+++ b/scilab/modules/ast/tests/unit_tests/multiplication.tst
@@ -87,3 +87,7 @@ assert_checkequal(R * C, [ 7+%i*14, 10+%i*20; 15+%i*30, 22+%i*44]);
87assert_checkequal(C * R, [ 7+%i*14, 10+%i*20; 15+%i*30, 22+%i*44]); 87assert_checkequal(C * R, [ 7+%i*14, 10+%i*20; 15+%i*30, 22+%i*44]);
88// C * C 88// C * C
89assert_checkequal(C * C, [-21+%i*28,-30+%i*40;-45+%i*60,-66+%i*88]); 89assert_checkequal(C * C, [-21+%i*28,-30+%i*40;-45+%i*60,-66+%i*88]);
90
91errmsg = gettext("Inconsistent row/column dimensions.");
92assert_checkerror("[1;1]*[1;1]", errmsg);
93assert_checkerror("[1 1]*[1 1]", errmsg);