list as output in function call

classic Classic list List threaded Threaded
8 messages Options
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

list as output in function call

Hello all,

After seeing this question on stackoverflow

https://stackoverflow.com/questions/55757856/ndgrid-input-and-output-from-cell-array

I realized that the current features of Scilab are quite asymmetric
w.r.t. the use of an "expanded" list as input, which is supported, as in

x = list(1:2,1:2,1:2)
ndgrid(x(:))

and as output, which is not supported, as in

X = list(,,)
X(:) = ndgrid(x(:))

Would it be complicated to implement the above ?

S.

_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Antoine ELIAS-2 Antoine ELIAS-2
Reply | Threaded
Open this post in threaded view
|

Re: list as output in function call

Hello Stéphane,

Just to be sure, you want that we fill the X-list with all outputs of
ngdrid.
Following witch information, size(X) or size(outputs) ?
In your cas I suppose that the size is the same.
What append if X is not a list or does not have the good size ?

Some functions that returns multiple arguments, "look" how many as
expected by caller
a = size(x) vs [a,b] = size(x) for example.
Does we must provide size(X) to ngrid ?

Just a question, specific to ndgrid, why do not update the function to
return a list in case of nargout == 1 ?

Regards,
Antoine
Le 23/04/2019 à 22:14, Stéphane Mottelet a écrit :

> Hello all,
>
> After seeing this question on stackoverflow
>
> https://stackoverflow.com/questions/55757856/ndgrid-input-and-output-from-cell-array 
>
>
> I realized that the current features of Scilab are quite asymmetric
> w.r.t. the use of an "expanded" list as input, which is supported, as in
>
> x = list(1:2,1:2,1:2)
> ndgrid(x(:))
>
> and as output, which is not supported, as in
>
> X = list(,,)
> X(:) = ndgrid(x(:))
>
> Would it be complicated to implement the above ?
>
> S.
>
> _______________________________________________
> dev mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/dev

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

Re: list as output in function call

Le 23/04/2019 à 22:28, Antoine ELIAS a écrit :

> Hello Stéphane,
>
> Just to be sure, you want that we fill the X-list with all outputs of
> ngdrid.
> Following witch information, size(X) or size(outputs) ?
> In your cas I suppose that the size is the same.
> What append if X is not a list or does not have the good size ?
the same thing that happens if in ngrid(x(:)) x is not a list or has not
the good size :-D
>
> Some functions that returns multiple arguments, "look" how many as
> expected by caller
> a = size(x) vs [a,b] = size(x) for example.
> Does we must provide size(X) to ngrid ?

After messing around the ast module I know it is not simple. But seeing
this naïvely, it seems as simple as giving the number of outputs when
running

[X(1),X(2),X(3)] = ndgrid(x(:))

>
> Just a question, specific to ndgrid, why do not update the function to
> return a list in case of nargout == 1 ?

This kind of behaviour is the default in Julia, for all functions. But
we don't need this in Scilab...

S.

>
> Regards,
> Antoine
> Le 23/04/2019 à 22:14, Stéphane Mottelet a écrit :
>> Hello all,
>>
>> After seeing this question on stackoverflow
>>
>> https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/stackoverflow.com/questions/55757856/ndgrid-input-and-output-from-cell-array 
>>
>>
>> I realized that the current features of Scilab are quite asymmetric
>> w.r.t. the use of an "expanded" list as input, which is supported, as in
>>
>> x = list(1:2,1:2,1:2)
>> ndgrid(x(:))
>>
>> and as output, which is not supported, as in
>>
>> X = list(,,)
>> X(:) = ndgrid(x(:))
>>
>> Would it be complicated to implement the above ?
>>
>> S.
>>
>> _______________________________________________
>> dev mailing list
>> [hidden email]
>> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/dev 
>>
>
> _______________________________________________
> dev mailing list
> [hidden email]
> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/dev 
>
_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: list as output in function call

In reply to this post by Antoine ELIAS-2
Hello,

Le 23/04/2019 à 22:28, Antoine ELIAS a écrit :

> Hello Stéphane,
>
> Just to be sure, you want that we fill the X-list with all outputs of
> ngdrid.
> Following witch information, size(X) or size(outputs) ?
> In your cas I suppose that the size is the same.
> What append if X is not a list or does not have the good size ?
>
> Some functions that returns multiple arguments, "look" how many as
> expected by caller
> a = size(x) vs [a,b] = size(x) for example.
> Does we must provide size(X) to ngrid ?

I am not sure that this would be enough.
This topic is discussed in the report http://bugzilla.scilab.org/14372 
and its comments

>
> Just a question, specific to ndgrid, why do not update the function to
> return a list in case of nargout == 1 ?

You likely mean as a unique explicit argout, instead of the varargout
"implicit" list.
Wrapping the result in a list would break a lot of code, and would make
addressing the results more complicated for most frequent cases.

Regards
Samuel

_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Antoine ELIAS-2 Antoine ELIAS-2
Reply | Threaded
Open this post in threaded view
|

Re: list as output in function call

In reply to this post by mottelet
Le 23/04/2019 à 22:46, Stéphane Mottelet a écrit :

> Le 23/04/2019 à 22:28, Antoine ELIAS a écrit :
>
>> Hello Stéphane,
>>
>> Just to be sure, you want that we fill the X-list with all outputs of
>> ngdrid.
>> Following witch information, size(X) or size(outputs) ?
>> In your cas I suppose that the size is the same.
>> What append if X is not a list or does not have the good size ?
> the same thing that happens if in ngrid(x(:)) x is not a list or has
> not the good size :-D
I'm not sure that we speak about the same things ( there are 2 X/x in
your example ).
I speak about number of outputs from the function and size of container
that "receive" data.
>>
>> Some functions that returns multiple arguments, "look" how many as
>> expected by caller
>> a = size(x) vs [a,b] = size(x) for example.
>> Does we must provide size(X) to ngrid ?
>
> After messing around the ast module I know it is not simple. But
> seeing this naïvely, it seems as simple as giving the number of
> outputs when running
I think it would not be very difficult to do. But my questions are most
about goals and implications of this kind of features.
I'm not really ready to break code or/and compatibility for very
situational features to avoid typing few characters ;)
I understand that will be useful but sometimes is not easy to imagine
implications ( like a + [], we learn from our mistakes :p )

>
> [X(1),X(2),X(3)] = ndgrid(x(:))
>
>>
>> Just a question, specific to ndgrid, why do not update the function
>> to return a list in case of nargout == 1 ?
>
> This kind of behaviour is the default in Julia, for all functions. But
> we don't need this in Scilab...
It was the same in very first versions of Scilab 6 ( before alphas I
think ) but for compatibility with familly 5, we change that ;)

>
> S.
>
>>
>> Regards,
>> Antoine
>> Le 23/04/2019 à 22:14, Stéphane Mottelet a écrit :
>>> Hello all,
>>>
>>> After seeing this question on stackoverflow
>>>
>>> https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/stackoverflow.com/questions/55757856/ndgrid-input-and-output-from-cell-array 
>>>
>>>
>>> I realized that the current features of Scilab are quite asymmetric
>>> w.r.t. the use of an "expanded" list as input, which is supported,
>>> as in
>>>
>>> x = list(1:2,1:2,1:2)
>>> ndgrid(x(:))
>>>
>>> and as output, which is not supported, as in
>>>
>>> X = list(,,)
>>> X(:) = ndgrid(x(:))
>>>
>>> Would it be complicated to implement the above ?
>>>
>>> S.
>>>
>>> _______________________________________________
>>> dev mailing list
>>> [hidden email]
>>> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/dev 
>>>
>>
>> _______________________________________________
>> dev mailing list
>> [hidden email]
>> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/dev 
>>
> _______________________________________________
> dev mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/dev

_______________________________________________
dev mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/dev
Antoine ELIAS-2 Antoine ELIAS-2
Reply | Threaded
Open this post in threaded view
|

Re: list as output in function call

In reply to this post by Samuel GOUGEON
Le 23/04/2019 à 22:50, Samuel Gougeon a écrit :

> Hello,
>
> Le 23/04/2019 à 22:28, Antoine ELIAS a écrit :
>> Hello Stéphane,
>>
>> Just to be sure, you want that we fill the X-list with all outputs of
>> ngdrid.
>> Following witch information, size(X) or size(outputs) ?
>> In your cas I suppose that the size is the same.
>> What append if X is not a list or does not have the good size ?
>>
>> Some functions that returns multiple arguments, "look" how many as
>> expected by caller
>> a = size(x) vs [a,b] = size(x) for example.
>> Does we must provide size(X) to ngrid ?
>
> I am not sure that this would be enough.
> This topic is discussed in the report http://bugzilla.scilab.org/14372 
> and its comments
>
>>
>> Just a question, specific to ndgrid, why do not update the function
>> to return a list in case of nargout == 1 ?
>
> You likely mean as a unique explicit argout, instead of the varargout
> "implicit" list.
> Wrapping the result in a list would break a lot of code, and would
> make addressing the results more complicated for most frequent cases.
>
Absolutely not ;)
I said that only for this specific case "ndgrid". I think that only
break non-working code.
and varargout is a real list ! ( Do not discriminate ^^ )

> Regards
> Samuel
>
> _______________________________________________
> dev mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/dev

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

Re: list as output in function call

Le 24/04/2019 à 09:25, Antoine ELIAS a écrit :
Le 23/04/2019 à 22:50, Samuel Gougeon a écrit :
Hello,

Le 23/04/2019 à 22:28, Antoine ELIAS a écrit :
.../...

Just a question, specific to ndgrid, why do not update the function to return a list in case of nargout == 1 ?

You likely mean as a unique explicit argout, instead of the varargout "implicit" list.
Wrapping the result in a list would break a lot of code, and would make addressing the results more complicated for most frequent cases.

Absolutely not ;)
I said that only for this specific case "ndgrid".

Yes, this is what i understood.

I think that only break non-working code.

With the current implementation, the following works, with argn(1)==1:

--> X = ndgrid(1:4)
 X  =
   1.   1.   1.   1.
   2.   2.   2.   2.
   3.   3.   3.   3.
   4.   4.   4.   4.


and varargout is a real list ! ( Do not discriminate ^^ )
Yes, it is build as a real list to feed the return. But is not processed as a classic list when returning, since it is assigned in a distributive way, while it's not the case for a simple list.
So yes we have to discriminate both, as the test below shows it:
--> function varargout = test()
  >  varargout = list("a","b","c")
  > endfunction

--> [a,b,c] = test()
 c  =
 c

 b  =
 b

 a  =
 a

--> function L = test()
  >  L = list("a","b","c")
  > endfunction

--> [a,b,c] = test()
Wrong number of output arguments.

And, alone, returning a list as the first element in or out of varargout would not fix the issue:

--> function varargout = test()
  >  varargout = list(list("a","b","c"))
  > endfunction

--> a = list(,,);
--> a(:) = test()
Unable to insert multiple item in a list.


--> function [r,varargout] = test()
  >     if argn(1)==1
  >         r = list("a","b","c")
  >         varargout = list()
  >     end
  > endfunction
--> a = list(,,);
--> a(:) = test()
Unable to insert multiple item in a list.


For the general discussion, i think that, from a user's point a view, when using a container as LHS argument, a distributive assignment would be often very useful. It might be either through a new .= "operator", or through the classic "=" one but only when for instance the RHS is a container as well,
  • either a list with the right number of elements at depth = 0
  • or a cell or struct array with the same sizes as the cell or struct (or struct or cell) on the LHS

AFAIR, this kind of feature is already reported as a wish.

Best regards
Samuel


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

Re: list as output in function call

Le 24/04/2019 à 10:07, Samuel Gougeon a écrit :
.../...

For the general discussion, i think that, from a user's point a view, when using a container as LHS argument, a distributive assignment would be often very useful. It might be either through a new .= "operator", or through the classic "=" one but only when for instance the RHS is a container as well,
  • either a list with the right number of elements at depth = 0
  • or a cell or struct array with the same sizes as the cell or struct (or struct or cell) on the LHS

AFAIR, this kind of feature is already reported as a wish.


By the way, while it was possible in Scilab 5.5.2 to assign the elements of a list to all elements of the field of an array of structures, it is no longer the case in Scilab 6.0:

--> clear s
--> s.a = %pi;
--> s.b = "a";
--> s(2).a = %e;
--> s(2).b = "b"
 s  =
2x1 struct array with fields:
   a
   b

--> setfield("a", list(%i, 3.1), s)
setfield:  Wrong type for input argument #3: List expected.

In Scilab 5, we get the right assignment:

-->setfield("a",list(%i,3.1),s)
-->s.a
 ans  =
       ans(1)
    i   
       ans(2)
    3.1 
-->s(2).a
 ans  =
    3.1 

This Scilab 6 restriction weakens the usage of arrays of structures.

Samuel


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