From: Samuel GOUGEON Date: Wed, 23 Jan 2019 19:11:09 +0000 (+0100) Subject: fix regression of min(sparseScalar) max(sparseScalar) X-Git-Tag: 6.0.2~93 X-Git-Url: http://gitweb.scilab.org/?p=scilab.git;a=commitdiff_plain;h=f4ad1001149d31545700c61b96b5c37eca269ec3 fix regression of min(sparseScalar) max(sparseScalar) faisait échouer test_run ast dotdivide (en fait assert_checkalmostequal()) Follow-up of https://codereview.scilab.org/#/c/20499/ test_run elementary_functions max test_run ast dotdivide Désormais, on peut mélanger des sparse input arrays et scalaires. Par sécurité, pour max(), les scalaires acceptés en cas de mélange devaient être <=0 (argumentaire http://bugzilla.scilab.org/15755). Cette restriction n'est pas compatible avec le seul usage possible pré-existant : max(sparse(-5), 3, 0..) avec uniquement des scalaires, mais possiblement > 0. Dans ce patch, on relache complètement la contrainte "doit être <=0" (=> BC totale). Idem pour min() Change-Id: I962d034c108e1c44a6b540ffe60ade3137f2abb6 --- diff --git a/scilab/modules/elementary_functions/help/en_US/matrixoperations/max.xml b/scilab/modules/elementary_functions/help/en_US/matrixoperations/max.xml index 6dea44d..33291f1 100644 --- a/scilab/modules/elementary_functions/help/en_US/matrixoperations/max.xml +++ b/scilab/modules/elementary_functions/help/en_US/matrixoperations/max.xml @@ -42,8 +42,7 @@ scalars, vectors, matrices or hypermatrices of encoded integers or of real numbers, in dense or sparse format. They must have the same sizes, or be mixed with scalars (scalars are then implicitly expanded to the arrays sizes). - Sparse arrays can't be mixed with dense ones, except with dense - negative scalars. + Sparse arrays can't be mixed with dense ones, except with dense scalars. @@ -163,6 +162,11 @@ + + If max(A1, A2,..., An) is used with a huge input sparse matrix of + low density, together with a strictly positive scalar input, the sparse result will no longer + have any 0 value: It will be a sparse array with density=1, that may lead to a memory failure. + Examples @@ -238,7 +242,7 @@ A = grand(4,6,"uin",0,30); A(3,4) = %nan 3. 2. 6. - ]]> +]]> With sparse inputs: @@ -318,7 +322,7 @@ K 1. 2. 2. 1. 1. 1. 1. 1. 1. 2. 1. 2. -]]> +]]> See also diff --git a/scilab/modules/elementary_functions/help/en_US/matrixoperations/min.xml b/scilab/modules/elementary_functions/help/en_US/matrixoperations/min.xml index da933b6..55ef18b 100644 --- a/scilab/modules/elementary_functions/help/en_US/matrixoperations/min.xml +++ b/scilab/modules/elementary_functions/help/en_US/matrixoperations/min.xml @@ -42,8 +42,7 @@ scalars, vectors, matrices or hypermatrices of encoded integers or of real numbers, in dense or sparse format. They must have the same sizes, or be mixed with scalars (scalars are then implicitly expanded to the arrays sizes). - Sparse arrays can't be mixed with dense ones, except with dense - positive scalars. + Sparse arrays can't be mixed with dense ones, except with dense scalars. @@ -163,6 +162,11 @@ + + If min(A1, A2,..., An) is used with a huge input sparse matrix of + low density, together with a strictly negative scalar input, the sparse result will no longer + have any 0 value: It will be a sparse array with density=1, that may lead to a memory failure. + Examples @@ -238,7 +242,7 @@ A = grand(4,6,"uin",0,30); A(3,4) = %nan 6. 2. 6. - ]]> +]]> With sparse inputs: @@ -318,7 +322,7 @@ K 2. 1. 2. 2. 1. 1. 1. 1. 1. 1. 2. 1. -]]> +]]> See also diff --git a/scilab/modules/elementary_functions/help/ru_RU/matrixoperations/max.xml b/scilab/modules/elementary_functions/help/ru_RU/matrixoperations/max.xml index 625838a..48eff17 100644 --- a/scilab/modules/elementary_functions/help/ru_RU/matrixoperations/max.xml +++ b/scilab/modules/elementary_functions/help/ru_RU/matrixoperations/max.xml @@ -44,7 +44,7 @@ одинаковые размеры или быть смешанными со скалярами (скаляры, следовательно, неявно расширяются до размеров массивов). Разрежённые массивы не могут смешиваться с полными массивами, за - исключением отрицательных скаляров. + исключением скаляров. @@ -169,6 +169,11 @@ + + If max(A1, A2,..., An) is used with a huge input sparse matrix of + low density, together with a strictly positive scalar input, the sparse result will no longer + have any 0 value: It will be a sparse array with density=1, that may lead to a memory failure. + Примеры @@ -185,11 +190,13 @@ [] k = [] + --> [m, k] = max([1 5 ; 3 %nan]) m = 5. k = 1. 2. + --> [m, k] = max([1 5 ; 3 %nan], 2.5) m = 2.5 5. @@ -197,6 +204,7 @@ k = 2. 1. 1. 2. + --> [m, k] = max([5 -1 1], [1 0 3], [2 1 3]) m = 5. 1. 3. @@ -218,11 +226,13 @@ A = grand(4,6,"uin",0,30); A(3,4) = %nan 16. 20. 25. 6. 10. 1. 25. 26. 20. Nan 2. 21. 5. 9. 16. 15. 24. 25. + --> [Row, K] = max(A, "r") Row = 25. 26. 25. 15. 24. 28. K = 3. 3. 2. 4. 4. 1. + --> [Col, K] = max(A, "c") Col = 28. @@ -234,7 +244,7 @@ A = grand(4,6,"uin",0,30); A(3,4) = %nan 3. 2. 6. - ]]> +]]> С разрежёнными входными данными: @@ -268,6 +278,7 @@ K 0. -2. -4. 0. 0. 4. 0. 2. 0. -5. 5. -4. + --> [Row, K] = max(s, "r") Row = ( 1, 4) sparse matrix @@ -276,6 +287,7 @@ K ( 1, 4) 3. K = 1. 4. 5. 1. + --> [Col, K] = max(s, "c") Col = ( 5, 1) sparse matrix @@ -289,6 +301,7 @@ K 1. 2. 3. + --> [M, K] = max(s, -1); [full(s) ones(s(:,1))*%nan full(M)] ans = 0. -2. -4. 3. Nan 0. -1. -1. 3. @@ -296,9 +309,11 @@ K 0. -2. -4. 0. Nan 0. -1. -1. 0. 0. 4. 0. 2. Nan 0. 4. 0. 2. 0. -5. 5. -4. Nan 0. -1. 5. -1. + --> issparse(M) ans = 1. + --> K K = 1. 2. 2. 1. @@ -306,7 +321,7 @@ K 1. 2. 2. 1. 1. 1. 1. 1. 1. 2. 1. 2. -]]> +]]> Смотрите также diff --git a/scilab/modules/elementary_functions/help/ru_RU/matrixoperations/min.xml b/scilab/modules/elementary_functions/help/ru_RU/matrixoperations/min.xml index 266ac26..06a92ef 100644 --- a/scilab/modules/elementary_functions/help/ru_RU/matrixoperations/min.xml +++ b/scilab/modules/elementary_functions/help/ru_RU/matrixoperations/min.xml @@ -44,7 +44,7 @@ одинаковые размеры или быть смешанными со скалярами (скаляры, следовательно, неявно расширяются до размеров массивов). Разрежённые массивы не могут смешиваться с полными массивами, за - исключением положительных скаляров. + исключением скаляров. @@ -169,6 +169,11 @@ + + If min(A1, A2,..., An) is used with a huge input sparse matrix of + low density, together with a strictly negative scalar input, the sparse result will no longer + have any 0 value: It will be a sparse array with density=1, that may lead to a memory failure. + Примеры @@ -185,11 +190,13 @@ [] k = [] + --> [m, k] = min([5 3 ; 2 %nan]) m = 2. k = 2. 1. + --> [m, k] = min([5 3 ; 2 %nan], 4) m = 4. 3. @@ -197,6 +204,7 @@ k = 2. 1. 1. 2. + --> [m, k] = min([5 -1 2], [1 5 1], [0 1 3]) m = 0. -1. 1. @@ -218,11 +226,13 @@ A = grand(4,6,"uin",0,30); A(3,4) = %nan 23. 25. 29. 6. 19. 5. 30. 2. 20. Nan 6. 6. 20. 8. 13. 14. 16. 3. + --> [Row, K] = min(A, "r") Row = 20. 2. 13. 4. 6. 3. K = 4. 3. 4. 1. 1. 4. + --> [Col, K] = min(A, "c") Col = 4. @@ -234,7 +244,7 @@ A = grand(4,6,"uin",0,30); A(3,4) = %nan 6. 2. 6. - ]]> +]]> С разрежёнными входными данными: @@ -266,6 +276,7 @@ K 3. -1. 3. 4. 0. 0. 0. 0. 0. 0. 4. -5. + --> [Row, K] = min(s, "r") Row = ( 1, 4) sparse matrix @@ -275,6 +286,7 @@ K ( 1, 4) -5. K = 2. 3. 2. 5. + --> [Col, K] = min(s, "c") Col = ( 5, 1) sparse matrix @@ -288,6 +300,7 @@ K 2. 1. 4. + --> [M, K] = min(s,1); [full(s) ones(s(:,1))*%nan full(M)] ans = 0. 0. 5. -2. Nan 0. 0. 1. -2. @@ -295,6 +308,7 @@ K 3. -1. 3. 4. Nan 1. -1. 1. 1. 0. 0. 0. 0. Nan 0. 0. 0. 0. 0. 0. 4. -5. Nan 0. 0. 1. -5. + --> issparse(M) ans = 1. @@ -305,7 +319,7 @@ K 2. 1. 2. 2. 1. 1. 1. 1. 1. 1. 2. 1. -]]> +]]> Смотрите также diff --git a/scilab/modules/elementary_functions/macros/%sp_max.sci b/scilab/modules/elementary_functions/macros/%sp_max.sci index f543cd5..fec885e 100644 --- a/scilab/modules/elementary_functions/macros/%sp_max.sci +++ b/scilab/modules/elementary_functions/macros/%sp_max.sci @@ -127,6 +127,7 @@ function [m, k] = %sp_max(varargin) k = ones(m) end [m1, n1] = size(m) + // Loop on the number of input arguments for i = 2:rhs An = elements(i) @@ -146,11 +147,6 @@ function [m, k] = %sp_max(varargin) msg = _("%s: Wrong size of input argument #%d%s: Same size as input argument #%d expected.\n") error(msprintf(msg, "%sp_max", i, error_list, 1)) end - // If An is a scalar: check that it is negative - if and([m2 n2]==[1 1]) & An>0 then - msg = _("%s: Argument #%d: the scalar must be negative.\n") - error(msprintf(msg, "%sp_max", i)) - end // Processing: mNan = isnan(m); diff --git a/scilab/modules/elementary_functions/macros/%sp_min.sci b/scilab/modules/elementary_functions/macros/%sp_min.sci index 63a19c9..0926601 100644 --- a/scilab/modules/elementary_functions/macros/%sp_min.sci +++ b/scilab/modules/elementary_functions/macros/%sp_min.sci @@ -126,6 +126,7 @@ function [m, k] = %sp_min(varargin) k = ones(m) end [m1, n1] = size(m) + // Loop on the number of input arguments for i = 2:rhs An = elements(i) @@ -145,11 +146,7 @@ function [m, k] = %sp_min(varargin) msg = _("%s: Wrong size of input argument #%d%s: Same size as input argument #%d expected.\n") error(msprintf(msg, "%sp_min", i, error_list, 1)) end - // If An is a scalar: check that it is positive - if and([m2 n2]==[1 1]) & An<0 then - msg = _("%s: Argument #%d: the scalar must be positive.\n") - error(msprintf(msg, "%sp_max", i)) - end + // Processing: mNan = isnan(m); newNan = isnan(An);