[Scilab-users] Overloading "inv" and/or "p" does not seem to work with Scilab 6.1.0

classic Classic list List threaded Threaded
3 messages Options
Denis Gérard Crété Denis Gérard Crété
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Overloading "inv" and/or "p" does not seem to work with Scilab 6.1.0

Hello,

I redefined a few functions in Scilab 6.1.0 to extend them to arrays with 3 dimensions (formerly called hypermatrix). Overloading works with "clean", "multiply", "left division" and "element by element division" (after defining functions %s_clean, %s_m_s, %s_l_s and %s_d_s).

I tried to overload function "inv" with the following code:

function y=%s_inv(x),
    if ndims(x)>2 then
        for k=1:size(x,3),
            y(:,:,k)=inv(x(:,:,k));
        end;
    else
        y=inv(x);
    end;
endfunction

expecting that each layer of y is the reciprocal of corresponding layer of x. Instead,
inv(ones(1,1,2).*.rand(2,2)) returns the reciprocal of x layer 1 in y layer 1 AND x LAYER n IN y LAYER n, WHEN n>1. I use "layer" to designate the matrix obtain for a fixed value the index along the 3rd dimension.

Code to reproduce the problem:

n=4; m=3;
M=ones(1,1,n).*.rand(m,m);
inv(M)

Attempts to circumvent this problem by using M^(-1) instead of inv(M) run into the same problem (after redefining function %s_p). Is this a bug or did I miss something ?

In the mean time, I avoided overloading the function "inv" and renamed "%s_inv" to "inverse" to do successfully call "inverse(M)"...

Best regards
Denis


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Overloading "inv" and/or "p" does not seem to work with Scilab 6.1.0

Hi,

Le 07/05/2020 à 14:58, CRETE Denis a écrit :
Hello,

I redefined a few functions in Scilab 6.1.0 to extend them to arrays with 3 dimensions (formerly called hypermatrix). Overloading works with "clean", "multiply", "left division" and "element by element division" (after defining functions %s_clean, %s_m_s, %s_l_s and %s_d_s).

clean and element by element division do not need overloading:

--> clean(ones(2,2,2))
 ans  =

(:,:,1)

   1.   1.
   1.   1.
(:,:,2)

   1.   1.
   1.   1.

--> ones(2,2,2)./ones(2,2,2)
 ans  =

(:,:,1)

   1.   1.
   1.   1.
(:,:,2)

   1.   1.
   1.   1.

S.


I tried to overload function "inv" with the following code:

function y=%s_inv(x),
    if ndims(x)>2 then
        for k=1:size(x,3),
            y(:,:,k)=inv(x(:,:,k));
        end;
    else
        y=inv(x);
    end;
endfunction

expecting that each layer of y is the reciprocal of corresponding layer of x. Instead,
inv(ones(1,1,2).*.rand(2,2)) returns the reciprocal of x layer 1 in y layer 1 AND x LAYER n IN y LAYER n, WHEN n>1. I use "layer" to designate the matrix obtain for a fixed value the index along the 3rd dimension.

Code to reproduce the problem:

n=4; m=3;
M=ones(1,1,n).*.rand(m,m);
inv(M)

Attempts to circumvent this problem by using M^(-1) instead of inv(M) run into the same problem (after redefining function %s_p). Is this a bug or did I miss something ?

In the mean time, I avoided overloading the function "inv" and renamed "%s_inv" to "inverse" to do successfully call "inverse(M)"...

Best regards
Denis


_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Overloading "inv" and/or "p" does not seem to work with Scilab 6.1.0

In reply to this post by Denis Gérard Crété
Hello Denis,

Le 07/05/2020 à 14:58, CRETE Denis a écrit :
Hello,

I redefined a few functions in Scilab 6.1.0 to extend them to arrays with 3 dimensions (formerly called hypermatrix). Overloading works with "clean", "multiply", "left division" and "element by element division" (after defining functions %s_clean, %s_m_s, %s_l_s and %s_d_s).

I tried to overload function "inv" with the following code:

function y=%s_inv(x),
    if ndims(x)>2 then
        for k=1:size(x,3),
            y(:,:,k)=inv(x(:,:,k));
        end;
    else
        y=inv(x);
    end;
endfunction

expecting that each layer of y is the reciprocal of corresponding layer of x. Instead,
inv(ones(1,1,2).*.rand(2,2)) returns the reciprocal of x layer 1 in y layer 1 AND x LAYER n IN y LAYER n, WHEN n>1. I use "layer" to designate the matrix obtain for a fixed value the index along the 3rd dimension.

Code to reproduce the problem:

n=4; m=3;
M=ones(1,1,n).*.rand(m,m);
inv(M)

Attempts to circumvent this problem by using M^(-1) instead of inv(M) run into the same problem (after redefining function %s_p). Is this a bug or did I miss something ?


It's a bug. inv() should display an error message inviting to define %s_inv(), or use %s_inv().
By the way, the hook to the overload existed in Scilab 5.5.2. Hence, this issue is a regression.
Could you please report it?
Thanks

Samuel



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users