Hi,

A SEP 95 was recently submitted in CodeReview:
https://codereview.scilab.org/cat/11455%2C2%2CSEP/SEP_095_ismatrix_isrow_iscolumn_issquare.odt

Despite no input is expected since the SEP has not been posted here (as not
foreseen by the SEP#0), here are a few comments about the proposal, for issquare(). Other comments about other proposed functions will be posted in a separated thread.

The full rationale says:
/These functions are some elementary functions that exist in Matlab to check if a matrix or a //
//vector is a matrix, a row, a column or a square matrix /

I have already written about the weight of any Matlab-mania. It looks here the main and even single input argument for Scilab Enterprises. Then, i am wondering about what should be the output, and if there is some tacit agreement between both companies.

By the way, AFAIK, issquare() is not a native Matlab function. It is only proposed by a matlaber
in FileExchange.  IMO, the gain of introducing issquare() is very small.

The proposed implementation is also very restricted:
https://codereview.scilab.org/#/c/11455/2/scilab/modules/elementary_functions/macros/issquare.sci :

function  r=issquare(v)
   // (checking input parameters. Then:)
   if  size(size(v),'*')  ==  1  |  size(v,1)  ==1  then
        r  =  %f;
    elseif  size(v,1)  ==  size(v,2)
        r=%t;
else r=%f;
    end
endfunction


*Suggested definition*: issquare(v) should return %T as soon as all non-null dimensions of v
(that are not singleton) are equal.
For example, this means, for any type of data in matrix or hypermatrix, with dense or sparse encoding:

issquare([])            // => %F : this could be conventional
issquare(%pi)           // => %T: yes, a scalar is a square matrix
issquare(emptystr(2,2)) // => %T, as expected
issquare(rand(2,1,2)) // => %T, oriented along (x,z) instead of (x,y), but truly square.
issquare(rand(2,2,2))   // => %T: a straighforward extension to 3D.
// There is no reason to implement specific iscube(), ishypercube().. functions
issquare(rand(2,2,3))   // => %F : only cubes accepted
issquare(rand(2,2,2,2)) // => %T...

While the present implementation disagrees in the following cases:
-->issquare([])
 ans  =
  T

-->issquare(%pi)
 ans  =
  F

-->issquare(rand(2,1,2))
 ans  =
  F

-->issquare(rand(2,2,3))
 ans  =
  T

So, what do we do?

Here is an alternate implementation, if one is really required:

function  r  =issquare(v)
    s  =  size(squeeze(v))
    s  =  s(s>0)    // to reject [ ]
    r  =  length(unique(s))==1
endfunction

To be tested on sparse samples.
Since there are here likely hundreds of subscribers, other inputs would be welcome.
Designing Scilab should be the matter of all present and forthcoming users.

Regards
Samuel Gougeon

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

Reply via email to