[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Permuted matrix is not a matrix?

From: Julien Bect
Subject: Re: Permuted matrix is not a matrix?
Date: Sun, 28 Aug 2016 08:35:28 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.1.0

Le 13/08/2016 à 16:45, Maynard Wright a écrit :
On Saturday, August 13, 2016 06:54:28 AM James Sherman Jr. wrote:
On Sat, Aug 13, 2016 at 6:06 AM, Vallet García José

<address@hidden> wrote:
Hello all.

Is this inconsistent?
A=permute([1,2],[1 3 2]);
ans = 0
ans = matrix
Why ismatrix returns 0 while typeinfo returns "matrix" as type? Am I
missing something?


Help-octave mailing list
The naming of "matrix" is a bit inconsistent, but as for why ismatrix
returns a 0, from the help file:

  -- Built-in Function:  ismatrix (A)
      Return true if A is a 2-D array.

And how you did the permute returns a matrix in 3 dimensions (not 2),
thus ismatrix returns 0.  I would say that typeinfo (to be a bit more
precise) should return "array", but I imagine that would break a lot
of functions that use typeinfo to do checks on inputs.

Hope this helps,

James Sherman Jr.

Help-octave mailing list
In my installation of 3.8.1, ismatrix(A) returns ans = 1 and typeinfo(A)
returns ans = matrix.

Maynard Wright

@Maynard : yes, ismatrix has been modified in Octave 4.x for the sake of Matlab compatibilty.

What you observe is the result of the old ismatrix function, which was not Matlab-compatible.

ismatrix (A) now returns 0 in Octave 4.x (and in Matlab) since the result of A=permute([1,2],[1 3 2]); is a 3-dimensional array, as observed earlier by James.


@José : to answer your initial question, there is indeed an "inconsistency", but it is only an inconsistent choice of type and function names (not an actual bug).

To understand why it is so, you have to look at the history of Octave and Matlab...  I will try to explain, please forgive me if I fail at being clear...

First, you have to know that Octave aims at being compatible with Matlab, but also has specific features that do not exist in Matlab. Sometimes, this becomes is little messy.

One example of such an Octave-specific feature is the notion of "type" that is returned by typeinfo.  This notion does not exist in Matlab, and neither does the associated typeinfo function.

ismatrix has been present in Octave since around 2002, and in the case of your array A=permute([1,2],[1 3 2]); the result was 1 in Octave 3.8.x and earlier, as reported by Maynard (which was consistent with the type returned by typeinfo).

At this time, ismatrix was an Octave-specific function (there was no ismatrix function in Matlab).  But at some point around 2010, TMW also introduced an "ismatrix" function in Matlab, which was not compatible with Octave's.  Then, Octave's ismatrix function was modified to be compatible with Matlab's (if you want to know everything, here is the corresponding changeset: but the result of typeinfo was not modified.

This is why you now have a function "ismatrix" that returns 1 for 2D arrays only (i.e., arrays for which size (A) is of the form [m n]) while typeinfo returns "matrix" when the underlying C++ object is of class octave_matrix.


I agree that this is annoying, but I don't think it is likely to change any time soon...

The lightest option would be to improve the documentation of ismatrix and typeinfo to warn users about this, I think.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]