From d262c689731e4d49b28968206f21a60ba9d8022d Mon Sep 17 00:00:00 2001 From: Samuel GOUGEON Date: Tue, 10 Mar 2020 04:35:29 +0100 Subject: [PATCH] ./. .\. extended to sparses after fced8250 * ./. and .\. undocumented implementations introduced in 6.0.0 - always yielded errors for sparse inputs, due to divisions by zero - did not match proper definitions - are canceled here. * Proper definitions introduced in 6.1.0 are extended to sparse here Change-Id: Iedb2a6f95268abeaf161d35d486bee655c60618e --- scilab/modules/ast/tests/unit_tests/krondivide.tst | 18 +++++++++++++++- .../modules/elementary_functions/macros/%s_y_s.sci | 6 +++++- scilab/modules/overloading/macros/%sp_y_sp.sci | 22 ++++---------------- scilab/modules/overloading/macros/%sp_z_sp.sci | 22 ++++---------------- 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/scilab/modules/ast/tests/unit_tests/krondivide.tst b/scilab/modules/ast/tests/unit_tests/krondivide.tst index 1b4582a..b4ad660 100644 --- a/scilab/modules/ast/tests/unit_tests/krondivide.tst +++ b/scilab/modules/ast/tests/unit_tests/krondivide.tst @@ -1,7 +1,7 @@ // ============================================================================ // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab // -// Copyright (C) 2019 - Samuel GOUGEON +// Copyright (C) 2019-2020 - Samuel GOUGEON // // This file is distributed under the same license as the Scilab package. // ============================================================================ @@ -76,3 +76,19 @@ for i = 1:n assert_checkalmostequal(o2 .\. b, o, rtol) end end + +// Between sparse matrices +// ======================= +rtol = 10*%eps; +objects = list(sprand(10,1,0.5), sprand(1,8,0.5), sprand(5,5,0.5)); +n = length(objects); + +for i = 1:n + o = objects(i); + for j = 1:n + o2 = objects(j); + b = o .*. o2; + assert_checkalmostequal(b ./. o2, o, rtol) + assert_checkalmostequal(o .\. b, o2, rtol) + end +end diff --git a/scilab/modules/elementary_functions/macros/%s_y_s.sci b/scilab/modules/elementary_functions/macros/%s_y_s.sci index 9ca530e..ccbd0f6 100644 --- a/scilab/modules/elementary_functions/macros/%s_y_s.sci +++ b/scilab/modules/elementary_functions/macros/%s_y_s.sci @@ -36,7 +36,11 @@ function x = %s_y_s(b, a) b = matrix(b(k), prod(sx), prod(sa)) // Least square Processing - x = b / a(:).' + if issparse(a) then // call by %sp_y_sp + x = (a(:) \ b.').' + else + x = b / a(:).' + end // Reshaping the raw result x = matrix(x, sx) diff --git a/scilab/modules/overloading/macros/%sp_y_sp.sci b/scilab/modules/overloading/macros/%sp_y_sp.sci index df6d6b3..29ba7d0 100644 --- a/scilab/modules/overloading/macros/%sp_y_sp.sci +++ b/scilab/modules/overloading/macros/%sp_y_sp.sci @@ -1,7 +1,7 @@ // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab // Copyright (C) INRIA // -// Copyright (C) 2012 - 2016 - Scilab Enterprises +// Copyright (C) 2020 - Samuel GOUGEON // // This file is hereby licensed under the terms of the GNU GPL v2.0, // pursuant to article 5.3.4 of the CeCILL v.2.1. @@ -10,21 +10,7 @@ // For more information, see the COPYING file which you should have received // along with this program. -function r = %sp_y_sp(a,b) - // a./.b with a and b sparse - - [ija,va,mna] = spget(a) - [ijb,vb,mnb] = spget(b) - if size(ijb,1)<>prod(mnb)|or(vb==0) then - msg = _("%s: Division by 0...\n") - error(msprintf(msg, "%sp_y_sp")) - end - ia = ija(:,1); - ja = ija(:,2) - ib = ijb(:,1); - jb = ijb(:,2) - - ij = [((ia-ones(ia))*mnb(1)).*.ones(ib)+ones(ia).*.ib,.. - ((ja-ones(ja))*mnb(2)).*.ones(jb)+ones(ia).*.jb] - r = sparse(ij,va./.vb,mna.*mnb) +function r = %sp_y_sp(a, b) + // a ./. b with a and b sparse + r = %s_y_s(a, b) endfunction diff --git a/scilab/modules/overloading/macros/%sp_z_sp.sci b/scilab/modules/overloading/macros/%sp_z_sp.sci index 82d01a9..2441b19 100644 --- a/scilab/modules/overloading/macros/%sp_z_sp.sci +++ b/scilab/modules/overloading/macros/%sp_z_sp.sci @@ -1,7 +1,6 @@ // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab -// Copyright (C) INRIA // -// Copyright (C) 2012 - 2016 - Scilab Enterprises +// Copyright (C) 2020 - Samuel GOUGEON // // This file is hereby licensed under the terms of the GNU GPL v2.0, // pursuant to article 5.3.4 of the CeCILL v.2.1. @@ -10,21 +9,8 @@ // For more information, see the COPYING file which you should have received // along with this program. -function r = %sp_z_sp(a,b) - // a.\.b with a and b sparse +function r = %sp_z_sp(a, b) + // a .\. b with a and b sparse - [ija,va,mna] = spget(a) - [ijb,vb,mnb] = spget(b) - if size(ija,1)<>prod(mna) | or(va==0) then - msg = _("%s: Division by 0...\n") - error(msprintf(msg, "%sp_z_sp")) - end - ia = ija(:,1); - ja = ija(:,2) - ib = ijb(:,1); - jb = ijb(:,2) - - ij = [((ia-ones(ia))*mnb(1)).*.ones(ib)+ones(ia).*.ib,.. - ((ja-ones(ja))*mnb(2)).*.ones(jb)+ones(ia).*.jb] - r = sparse(ij, va.\.vb, mna.*mnb) + r = %s_z_s(a, b) endfunction -- 1.7.9.5