[Scilab-users] undocumented behavior of sum(), prod() and type()

6 messages
Open this post in threaded view
|

[Scilab-users] undocumented behavior of sum(), prod() and type()

 Dear all, I note that sum([]) yields 0 instead of []. This is somewhat contradictory with the documented behavior that [] + n yields [] regardless of the type of n I allso find that prod([]) yields 1. This is even stranger. The common feature is that both are the respective neutral element of the operations. Interestingly, cumsum and cumprod applied to [] yield the expected result, [] Besides, type([]) is 1 (constant). Somehow it is asuming an empty matrix is by default a container for constants, even in csses such as the following: a = %s b = a(1:\$-1)  where b is an empty sub-vector of a polynomial vector. None of these behaviors seem to be documented. If intentional, they should be documented. Regards, Federico Miyara _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: undocumented behavior of sum(), prod() and type()

 Hello federico, The empty page is improved in 6.1.0. Please have a look to http://bugzilla.scilab.org/15431 http://bugzilla.scilab.org/attachment.cgi?id=4929 Thanks Samuel Le 09/02/2020 à 04:27, Federico Miyara a écrit : Dear all, I note that sum([]) yields 0 instead of []. This is somewhat contradictory with the documented behavior that [] + n yields [] regardless of the type of n I allso find that prod([]) yields 1. This is even stranger. The common feature is that both are the respective neutral element of the operations. Interestingly, cumsum and cumprod applied to [] yield the expected result, [] Besides, type([]) is 1 (constant). Somehow it is asuming an empty matrix is by default a container for constants, even in csses such as the following: a = %s b = a(1:\$-1)  where b is an empty sub-vector of a polynomial vector. None of these behaviors seem to be documented. If intentional, they should be documented. Regards, Federico Miyara ```_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: undocumented behavior of sum(), prod() and type()

 Thanks, Samuel. This certainly clarifies how [] behaves. But is there a rationale for sum([])==0 and yet cumsum([])==[]? By the way, it would be useful to include cumsum and cumprod among the examples, or at least ensure the respective help pages include that information. Regards, Federico   On 09/02/2020 00:40, Samuel Gougeon wrote: Hello federico, The empty page is improved in 6.1.0. Please have a look to http://bugzilla.scilab.org/15431 http://bugzilla.scilab.org/attachment.cgi?id=4929 Thanks Samuel Le 09/02/2020 à 04:27, Federico Miyara a écrit : Dear all, I note that sum([]) yields 0 instead of []. This is somewhat contradictory with the documented behavior that [] + n yields [] regardless of the type of n I allso find that prod([]) yields 1. This is even stranger. The common feature is that both are the respective neutral element of the operations. Interestingly, cumsum and cumprod applied to [] yield the expected result, [] Besides, type([]) is 1 (constant). Somehow it is asuming an empty matrix is by default a container for constants, even in csses such as the following: a = %s b = a(1:\$-1)  where b is an empty sub-vector of a polynomial vector. None of these behaviors seem to be documented. If intentional, they should be documented. Regards, Federico Miyara ```_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` ```_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: undocumented behavior of sum(), prod() and type()

 Le 11/02/2020 à 02:37, Federico Miyara a écrit : Thanks, Samuel. This certainly clarifies how [] behaves. But is there a rationale for sum([])==0 and yet cumsum([])==[]? For sum([])==0 : IMO this is OK. Personnaly, i expect from sum(A) + sum(B) + .. sum(Z) not to be killed just because one of the arguments is []. So, to me, this case is somewhat distinct from the  A +[]. A + [] works element-wise. Because a vector is expected from sum([],"r"), that then would be added in an element-wise way, --> sum([],"r")  ans  =     [] is also OK. I would give the same rationale for prod([])==1. By the way, it would be useful to include cumsum and cumprod among the examples, Right Regards Samuel _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
 Samuel: Sounds reasonable! Thanks, Federico On 11/02/2020 07:13, Samuel Gougeon wrote: Le 11/02/2020 à 02:37, Federico Miyara a écrit : .../... But is there a rationale for sum([])==0 and yet cumsum([])==[]? We expect a scalar from sum([]), while from cumsum([]) we expect an array with the same size than the input array. ```_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users