|
From: | David Bateman |
Subject: | [Chanegset]: Re: cat does not convert sparse matrices? |
Date: | Sat, 13 Sep 2008 22:44:28 +0200 |
User-agent: | Thunderbird 2.0.0.16 (X11/20080725) |
dbateman wrote:
In fact I think I see two bugs here Francesco Potorti`-2 wrote:In Octave 3.0.1, I cannot catenate a full double matrix with a sparse logical matrix. Is this normal or a bug? octave> a=zeros(3,3,0); octave> b1=zeros(3,3); octave> b2=sparse(1,1,true,3,3); octave> whos a b1 b2 *** local user variables: Prot Name Size Bytes Class==== ==== ==== ===== ===== rwd a 3x3x0 0 doublerwd b1 3x3 72 double rwd b2 3x3 21 logical Total is 10 elements using 93 bytes octave> size(cat(3,a,b1)) ans = 3 3 1Trailing singleton dimensions should be dropped, So I suspect there is a function call missing in the cat function that should do this.
The attached patch addresses this, but
octave> size(cat(3,a,b2)) error: invalid conversion of NDArray to Matrix error: range error for insert error: evaluating argument list element number 1The sparse logical matrix should be promoted to a sparse matrix and the concatenation allowed. Ok, I'll look at this wen I'm on a development machine.
It seems I missed the point you made by this one.. Sparse logical matrices are promoted to sparse double matrices before concatenation with another double matrix. The issue above is that a 3x3x0 is an NDArray and the Sparse matrix type only supports 2D arrays and so the conversion of the 3x3x0 array to a sparse matrices prior to the concatenation fails. It would be interesting to know what matlab does in this case, as I suspect it fails as well. If it doesn't then I suppose we need to special case for this.
In fact we used to special case for all empty matrices in data.cc (do_cat) and just drop them from the concatenation. However, something like "cat(1,[],single([]))" must return a single precision empty matrix and so even empty matrices play their part in selecting the type of the returned matrix. So care would have to be taken if we did allow this not to cause other issues.
Cheers David
D.
# HG changeset patch # User David Bateman <address@hidden> # Date 1221338610 -7200 # Node ID 71f97e500f63e0a93e9cbe7f3cd5318827d3b3f9 # Parent 9fe441ffcbaa7b5e2f2c41d3e83b1769f92235da cut trailing singeltons in cat function diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ 2008-09-09 David Bateman <address@hidden +2008-09-13 David Bateman <address@hidden> + + * data.cc (do_cat): Chopping trailing singleton dimensions. + 2008-09-09 David Bateman <address@hidden> * DLD-FUNCTIONS/regexp.cc (octregexp_list): Distinguish between diff --git a/src/data.cc b/src/data.cc --- a/src/data.cc +++ b/src/data.cc @@ -1802,6 +1802,10 @@ do_cat (const octave_value_list& args, s dv_tmp (dim) : 1); } + // Reshape, chopping trailing singleton dimensions + dv.chop_trailing_singletons (); + tmp = tmp.reshape (dv); + retval = tmp; } else
[Prev in Thread] | Current Thread | [Next in Thread] |