summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStéphane MOTTELET <stephane.mottelet@utc.fr>2019-07-10 13:50:18 +0200
committerClément DAVID <clement.david@esi-group.com>2019-07-23 09:55:57 +0200
commitedaf386bc36a4c6efee23dfe1f5a28f9d053272f (patch)
treedb04a5055914df7c78557807c200e75e316f7eae
parent7b3e99789c6346aaf0ca2794a3dcff9ae672a121 (diff)
downloadscilab-edaf386bc36a4c6efee23dfe1f5a28f9d053272f.zip
scilab-edaf386bc36a4c6efee23dfe1f5a28f9d053272f.tar.gz
* Bug 16144 fixed: addition of sparse matrices gave incorrect results
http://bugzilla.scilab.org/show_bug.cgi?id=16144 Change-Id: I45b06e55ccae711d1add233e9d0692b36f82c76d
-rw-r--r--scilab/CHANGES.md1
-rw-r--r--scilab/modules/ast/src/cpp/operations/types_addition.cpp75
-rw-r--r--scilab/modules/ast/tests/nonreg_tests/bug_16144.tst22
3 files changed, 39 insertions, 59 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index c62fbec..0b2f115 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -181,5 +181,6 @@ Bug Fixes
181* [#16085](http://bugzilla.scilab.org/show_bug.cgi?id=16085): insertion in an empty struct was broken. 181* [#16085](http://bugzilla.scilab.org/show_bug.cgi?id=16085): insertion in an empty struct was broken.
182* [#16087](http://bugzilla.scilab.org/show_bug.cgi?id=16087): Insertion of struct() in a non-empty struct crashed Scilab. 182* [#16087](http://bugzilla.scilab.org/show_bug.cgi?id=16087): Insertion of struct() in a non-empty struct crashed Scilab.
183* [#16111](http://bugzilla.scilab.org/show_bug.cgi?id=16111): `isglobal` was not supporting non-scalar array of strings as input. 183* [#16111](http://bugzilla.scilab.org/show_bug.cgi?id=16111): `isglobal` was not supporting non-scalar array of strings as input.
184* [#16144](http://bugzilla.scilab.org/show_bug.cgi?id=16144): Addition of sparse matrices gave incorrect results.
184 185
185 186
diff --git a/scilab/modules/ast/src/cpp/operations/types_addition.cpp b/scilab/modules/ast/src/cpp/operations/types_addition.cpp
index a9846c7..2efe2c2 100644
--- a/scilab/modules/ast/src/cpp/operations/types_addition.cpp
+++ b/scilab/modules/ast/src/cpp/operations/types_addition.cpp
@@ -2427,66 +2427,23 @@ template<> InternalType* add_I_M<Double, Polynom, Polynom>(Double* _pL, Polynom*
2427//sp + sp 2427//sp + sp
2428template<> InternalType* add_M_M<Sparse, Sparse, Sparse>(Sparse* _pL, Sparse* _pR) 2428template<> InternalType* add_M_M<Sparse, Sparse, Sparse>(Sparse* _pL, Sparse* _pR)
2429{ 2429{
2430 Sparse* pOut = NULL;
2431
2432 //check scalar hidden in a sparse ;) 2430 //check scalar hidden in a sparse ;)
2433 /* if (_pL->getRows() == 1 && _pL->getCols() == 1) 2431 if (_pL->isScalar() || _pR->isScalar())
2434 { 2432 {
2435 //do scalar + sp 2433 // scalar + sp or sp + scalar
2436 Double* pDbl = NULL; 2434 // call Overload
2437 if (_pL->isComplex()) 2435 return NULL;
2438 { 2436 }
2439 std::complex<double> dbl = _pL->getImg(0, 0); 2437
2440 pDbl = new Double(dbl.real(), dbl.imag()); 2438 if (_pL->getRows() != _pR->getRows() || _pL->getCols() != _pR->getCols())
2441 } 2439 {
2442 else 2440 //dimensions not match
2443 { 2441 throw ast::InternalError(_W("Inconsistent row/column dimensions.\n"));
2444 pDbl = new Double(_pL->get(0, 0)); 2442 }
2445 } 2443
2446 2444 types::Sparse* pOut = _pL->add(*_pR);
2447 AddSparseToDouble(_pR, pDbl, (GenericType**)pOut); 2445 pOut->finalize();
2448 delete pDbl; 2446 return pOut;
2449 return pOut;
2450 }
2451
2452 if (_pR->getRows() == 1 && _pR->getCols() == 1)
2453 {
2454 //do sp + scalar
2455 Double* pDbl = NULL;
2456 if (_pR->isComplex())
2457 {
2458 std::complex<double> dbl = _pR->getImg(0, 0);
2459 pDbl = new Double(dbl.real(), dbl.imag());
2460 }
2461 else
2462 {
2463 pDbl = new Double(_pR->get(0, 0));
2464 }
2465
2466 AddSparseToDouble(_pL, pDbl, (GenericType**)pOut);
2467 delete pDbl;
2468 return 0;
2469 }
2470
2471 if (_pL->getRows() != _pR->getRows() || _pL->getCols() != _pR->getCols())
2472 {
2473 //dimensions not match
2474 throw ast::InternalError(_W("Inconsistent row/column dimensions.\n"));
2475 }
2476
2477 if (_pL->nonZeros() == 0)
2478 {
2479 //sp([]) + sp
2480 return _pR;
2481 }
2482
2483 if (_pR->nonZeros() == 0)
2484 {
2485 //sp + sp([])
2486 return _pL;
2487 }*/
2488
2489 return _pL->add(*_pR);
2490} 2447}
2491 2448
2492//d + sp 2449//d + sp
diff --git a/scilab/modules/ast/tests/nonreg_tests/bug_16144.tst b/scilab/modules/ast/tests/nonreg_tests/bug_16144.tst
new file mode 100644
index 0000000..59ba5d9
--- /dev/null
+++ b/scilab/modules/ast/tests/nonreg_tests/bug_16144.tst
@@ -0,0 +1,22 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2019 - Stéphane MOTTELET
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7//
8// <-- CLI SHELL MODE -->
9// <-- NO CHECK REF -->
10//
11// <-- Non-regression test for bug 16144 -->
12//
13// <-- Bugzilla URL -->
14// http://bugzilla.scilab.org/16144
15//
16// <-- Short Description -->
17// Addition of sparse matrices gives incorrect results
18
19message = msprintf(_("Inconsistent row/column dimensions.\n"));
20assert_checkerror("sparse([3,4],9) + sparse([1,2],5)",message);
21assert_checkequal(sparse([3,4],9,[4 4]) + sparse([1,2],5,[4,4]), sparse([3,4;1,2],[9,5],[4 4]))
22