summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authorSamuel GOUGEON <sgougeon@free.fr>2021-05-10 19:59:21 +0200
committerClément David <clement.david@esi-group.com>2021-05-20 16:33:53 +0200
commitf8ff9927f796d2c03a03becb11a240a2f98242d2 (patch)
tree848b71e5080f8f9960bdfe4f7de53997d82c365a /scilab
parent18e9fd43fc2a5d034e5ff7a8f79e9c6a55e195cf (diff)
downloadscilab-f8ff9927f796d2c03a03becb11a240a2f98242d2.zip
scilab-f8ff9927f796d2c03a03becb11a240a2f98242d2.tar.gz
* Bug 16664 fixed: diag(spzeros(2,2)) warned for Operation - []
http://bugzilla.scilab.org/16664 Test: diag(spzeros(2,2)) // Must return without warning --> diag(spzeros(2,2)) ans = ( 2, 1)zero sparse matrix Change-Id: I3a55d6d2108b19e5f1cbadfcaaf46856760b20f8
Diffstat (limited to 'scilab')
-rw-r--r--scilab/CHANGES.md1
-rw-r--r--scilab/modules/elementary_functions/macros/%sp_diag.sci8
-rw-r--r--scilab/modules/elementary_functions/tests/unit_tests/diag.tst43
3 files changed, 50 insertions, 2 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index b5c3edd..636349a 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -466,6 +466,7 @@ Bug Fixes
466* [#16644](https://bugzilla.scilab.org/16644): `input("message:")` yielded a wrong error message about `mprintf` in case of non-interpretable input. 466* [#16644](https://bugzilla.scilab.org/16644): `input("message:")` yielded a wrong error message about `mprintf` in case of non-interpretable input.
467* [#16654](https://bugzilla.scilab.org/16654): `interp` was leaking memory. 467* [#16654](https://bugzilla.scilab.org/16654): `interp` was leaking memory.
468* [#16661](https://bugzilla.scilab.org/16661): `x=spzeros(1e10,1e10)` yielded an incorrect error message. 468* [#16661](https://bugzilla.scilab.org/16661): `x=spzeros(1e10,1e10)` yielded an incorrect error message.
469* [#16664](https://bugzilla.scilab.org/16664): `diag(spzeros(2,2))` yielded an `Operation -[]` warning.
469* [#16665](https://bugzilla.scilab.org/16665): `help echo` could not redirect to `help mode` when preferred, for new users coming from Octave. 470* [#16665](https://bugzilla.scilab.org/16665): `help echo` could not redirect to `help mode` when preferred, for new users coming from Octave.
470* [#16677](https://bugzilla.scilab.org/16677): In offline mode, `atomsInstall` was flashing many times the console. 471* [#16677](https://bugzilla.scilab.org/16677): In offline mode, `atomsInstall` was flashing many times the console.
471* [#16679](https://bugzilla.scilab.org/16679): `get_function_path("acosh")` yielded an error (regression from Scilab 6.0.0). 472* [#16679](https://bugzilla.scilab.org/16679): `get_function_path("acosh")` yielded an error (regression from Scilab 6.0.0).
diff --git a/scilab/modules/elementary_functions/macros/%sp_diag.sci b/scilab/modules/elementary_functions/macros/%sp_diag.sci
index 32a0878..d388c09 100644
--- a/scilab/modules/elementary_functions/macros/%sp_diag.sci
+++ b/scilab/modules/elementary_functions/macros/%sp_diag.sci
@@ -10,7 +10,7 @@
10// For more information, see the COPYING file which you should have received 10// For more information, see the COPYING file which you should have received
11// along with this program. 11// along with this program.
12 12
13function d=%sp_diag(a,k) 13function d = %sp_diag(a,k)
14 // %sp_diag - implement diag function for sparse matrix, rational matrix ,.. 14 // %sp_diag - implement diag function for sparse matrix, rational matrix ,..
15 15
16 [lhs,rhs]=argn(0) 16 [lhs,rhs]=argn(0)
@@ -19,7 +19,11 @@ function d=%sp_diag(a,k)
19 [ij,v,sz]=spget(a) 19 [ij,v,sz]=spget(a)
20 m=sz(1);n=sz(2) 20 m=sz(1);n=sz(2)
21 if m>1&n>1 then 21 if m>1&n>1 then
22 l=find(ij(:,1)==(ij(:,2)-k)) 22 if ij<>[]
23 l = find(ij(:,1)==(ij(:,2)-k))
24 else
25 l = []
26 end
23 if k<=0 then 27 if k<=0 then
24 mn=min(m+k,n) 28 mn=min(m+k,n)
25 i0=-k 29 i0=-k
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/diag.tst b/scilab/modules/elementary_functions/tests/unit_tests/diag.tst
new file mode 100644
index 0000000..9e302cc
--- /dev/null
+++ b/scilab/modules/elementary_functions/tests/unit_tests/diag.tst
@@ -0,0 +1,43 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) 2021 - ESI Group - Clement DAVID
3//
4// This file is hereby licensed under the terms of the GNU GPL v2.0,
5// pursuant to article 5.3.4 of the CeCILL v.2.1.
6// This file was originally licensed under the terms of the CeCILL v2.1,
7// and continues to be available under such terms.
8// For more information, see the COPYING file which you should have received
9// along with this program.
10// ----------------------------------------------------------------------------
11
12// <-- CLI SHELL MODE -->
13// <-- NO CHECK REF -->
14// <-- IMPOSED ENGLISH -->
15//
16// --------------------------
17// Unit tests for diag()
18// --------------------------
19
20// Double
21assert_checkequal(diag(1), 1);
22assert_checkequal(diag([1 ; 2]), [1 0 ; 0 2]);
23assert_checkequal(diag([1 ; 2 ; 3]), [1 0 0 ; 0 2 0 ; 0 0 3]);
24assert_checkequal(diag(diag([1 ; 2])), [1 ; 2]);
25assert_checkequal(diag(diag([1 ; 2 ; 3])), [1 ; 2 ; 3]);
26
27assert_checkequal(diag(1, 1), [0 1 ; 0 0]);
28assert_checkequal(diag([1 ; 2], 1), [0 1 0 ; 0 0 2 ; 0 0 0]);
29assert_checkequal(diag([1 ; 2 ; 3], 1), [0 1 0 0 ; 0 0 2 0 ; 0 0 0 3 ; 0 0 0 0]);
30
31// Sparse
32assert_checkequal(diag(sparse(1)), sparse(1));
33assert_checkequal(diag(sparse([1 ; 2])), sparse([1 0 ; 0 2]));
34assert_checkequal(diag(sparse([1 ; 2 ; 3])), sparse([1 0 0 ; 0 2 0 ; 0 0 3]));
35assert_checkequal(diag(sparse(diag([1 ; 2]))), sparse([1 ; 2]));
36assert_checkequal(diag(sparse(diag([1 ; 2 ; 3]))), sparse([1 ; 2 ; 3]));
37
38assert_checkequal(diag(sparse(1), 1), sparse([0 1 ; 0 0]));
39assert_checkequal(diag(sparse([1 ; 2]), 1), sparse([0 1 0 ; 0 0 2 ; 0 0 0]));
40assert_checkequal(diag(sparse([1 ; 2 ; 3]), 1), sparse([0 1 0 0 ; 0 0 2 0 ; 0 0 0 3 ; 0 0 0 0]));
41
42// http://bugzilla.scilab.org/16664
43diag(spzeros(2,2)) \ No newline at end of file