summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authormottelet <stephane.mottelet@utc.fr>2020-10-20 14:19:02 +0200
committerClement DAVID <clement.david@esi-group.com>2020-12-22 15:29:10 +0100
commitde4658a44c879106b0629d66215f352f3a2431d8 (patch)
tree6625c23c75cc793e02f678c83d4dba1125e813d9 /scilab
parent04d8da5edae7eba142333d4b7b2834afbddf3d15 (diff)
downloadscilab-de4658a44c879106b0629d66215f352f3a2431d8.zip
scilab-de4658a44c879106b0629d66215f352f3a2431d8.tar.gz
* Bug 16559 fixed: size(A,'*') was 0 for A = speye(2^16,2^16)
http://bugzilla.scilab.org/show_bug.cgi?id=16559 The patch also improves the speed of colon extraction A(:,...,:) and A(:) when A is sparse. Change-Id: If7cde827079d6d4d16fb66859f8a6aed592289f1
Diffstat (limited to 'scilab')
-rw-r--r--scilab/CHANGES.md1
-rw-r--r--scilab/modules/ast/src/cpp/types/sparse.cpp57
-rw-r--r--scilab/modules/elementary_functions/sci_gateway/cpp/sci_size.cpp9
-rw-r--r--scilab/modules/elementary_functions/tests/nonreg_tests/bug_16559.tst22
4 files changed, 88 insertions, 1 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index e94a97e..cdeb69f 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -345,6 +345,7 @@ Bug Fixes
345* [#16551](https://bugzilla.scilab.org/16551): `num2cell` returned {} for any input array of empty strings. 345* [#16551](https://bugzilla.scilab.org/16551): `num2cell` returned {} for any input array of empty strings.
346* [#16553](https://bugzilla.scilab.org/16553): `unique(["" ""])` returned `["" ""]`. 346* [#16553](https://bugzilla.scilab.org/16553): `unique(["" ""])` returned `["" ""]`.
347* [#16557](https://bugzilla.scilab.org/16557): `macr2tree` + `tree2code` translated `e={2}` into `"e=1"` and `e={2,"ab"}` into `"e=[2,"ab"]"`. 347* [#16557](https://bugzilla.scilab.org/16557): `macr2tree` + `tree2code` translated `e={2}` into `"e=1"` and `e={2,"ab"}` into `"e=[2,"ab"]"`.
348* [#16559](https://bugzilla.scilab.org/16553): `isempty(A)` was true for sparse matrix of dimension 2^16 or larger.
348 349
349 350
350### Bugs fixed in 6.1.0: 351### Bugs fixed in 6.1.0:
diff --git a/scilab/modules/ast/src/cpp/types/sparse.cpp b/scilab/modules/ast/src/cpp/types/sparse.cpp
index 6882f77..b57bab9 100644
--- a/scilab/modules/ast/src/cpp/types/sparse.cpp
+++ b/scilab/modules/ast/src/cpp/types/sparse.cpp
@@ -2004,11 +2004,68 @@ GenericType* Sparse::extract(typed_list* _pArgs)
2004{ 2004{
2005 Sparse* pOut = NULL; 2005 Sparse* pOut = NULL;
2006 int iDims = (int)_pArgs->size(); 2006 int iDims = (int)_pArgs->size();
2007 bool bAllColonIndex = true;
2007 typed_list pArg; 2008 typed_list pArg;
2008 2009
2009 int* piMaxDim = new int[iDims]; 2010 int* piMaxDim = new int[iDims];
2010 int* piCountDim = new int[iDims]; 2011 int* piCountDim = new int[iDims];
2011 2012
2013 for (int i=0; i<iDims; i++)
2014 {
2015 bAllColonIndex &= (*_pArgs)[i]->isColon();
2016 }
2017
2018 if (bAllColonIndex)
2019 {
2020 if (iDims > 1) // a(:,...,:)
2021 {
2022 return this;
2023 }
2024 else // a(:)
2025 {
2026 if (isVector())
2027 {
2028 if (getCols() == 1)
2029 {
2030 return this;
2031 }
2032 else
2033 {
2034 this->transpose((types::InternalType *&)pOut);
2035 return pOut;
2036 }
2037 }
2038 pOut = new types::Sparse(getRows()*getCols(), 1, isComplex());
2039 if (isComplex())
2040 {
2041 CplxSparse_t *sp = pOut->matrixCplx;
2042 sp->reserve(nonZeros());
2043 int k=0;
2044 for (size_t i=0; i<getRows(); ++i)
2045 {
2046 for (Sparse::CplxSparse_t::InnerIterator it(*matrixCplx, i); it; ++it)
2047 {
2048 sp->insert(it.col()*getRows() + i, 0) = it.value();
2049 }
2050 }
2051 }
2052 else
2053 {
2054 RealSparse_t *sp = pOut->matrixReal;
2055 sp->reserve(nonZeros());
2056 int k=0;
2057 for (size_t i=0; i<getRows(); ++i)
2058 {
2059 for (Sparse::RealSparse_t::InnerIterator it(*matrixReal, i); it; ++it)
2060 {
2061 sp->insert(it.col()*getRows() + i, 0) = it.value();
2062 }
2063 }
2064 }
2065 }
2066 return pOut;
2067 }
2068
2012 //evaluate each argument and replace by appropriate value and compute the count of combinations 2069 //evaluate each argument and replace by appropriate value and compute the count of combinations
2013 int iSeqCount = checkIndexesArguments(this, _pArgs, &pArg, piMaxDim, piCountDim); 2070 int iSeqCount = checkIndexesArguments(this, _pArgs, &pArg, piMaxDim, piCountDim);
2014 if (iSeqCount == 0) 2071 if (iSeqCount == 0)
diff --git a/scilab/modules/elementary_functions/sci_gateway/cpp/sci_size.cpp b/scilab/modules/elementary_functions/sci_gateway/cpp/sci_size.cpp
index 85cdf0b..c7e74b4 100644
--- a/scilab/modules/elementary_functions/sci_gateway/cpp/sci_size.cpp
+++ b/scilab/modules/elementary_functions/sci_gateway/cpp/sci_size.cpp
@@ -135,7 +135,14 @@ types::Function::ReturnValue sci_size(types::typed_list &in, int _iRetCount, typ
135 } 135 }
136 break; 136 break;
137 case 0 : //"*" 137 case 0 : //"*"
138 pdbl[0] = in[0]->getAs<types::GenericType>()->getSize(); 138 if (in[0]->isSparse())
139 {
140 pdbl[0] = (double)piDims[0]*(double)piDims[1];
141 }
142 else
143 {
144 pdbl[0] = in[0]->getAs<types::GenericType>()->getSize();
145 }
139 break; 146 break;
140 default : //"r" 147 default : //"r"
141 if (iMode > iDims) 148 if (iMode > iDims)
diff --git a/scilab/modules/elementary_functions/tests/nonreg_tests/bug_16559.tst b/scilab/modules/elementary_functions/tests/nonreg_tests/bug_16559.tst
new file mode 100644
index 0000000..32ffaee
--- /dev/null
+++ b/scilab/modules/elementary_functions/tests/nonreg_tests/bug_16559.tst
@@ -0,0 +1,22 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2020 - 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 16559 -->
12//
13// <-- Bugzilla URL -->
14// http://bugzilla.scilab.org/16559
15//
16// <-- Short Description -->
17// A(:,:) is empty for sparse matrix of dimension 2^16 or larger
18
19n = 2^16;
20A = speye(n,n);
21assert_checkequal(size(A,"*"),n*n);
22assert_checkfalse(isempty(A)); \ No newline at end of file