help-octave
[Top][All Lists]
Advanced

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

Re: [Chanegset]: Re: cat does not convert sparse matrices?


From: David Bateman
Subject: Re: [Chanegset]: Re: cat does not convert sparse matrices?
Date: Thu, 18 Sep 2008 16:51:11 +0200
User-agent: Thunderbird 2.0.0.16 (X11/20080725)

Jaroslav Hajek wrote:
On Sat, Sep 13, 2008 at 10:44 PM, David Bateman <address@hidden> wrote:
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  double
  rwd 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   1

Trailing 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 1

The 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

_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave



David, this does not apply cleanly to release-3-0-x. The do_cat
function seems to have non-trivially diverged between the branches. I
tracked the previous changes to changeset 7997 in John's repo (by you)
that deals mainly with single prec - apparently you fixed something
"along the way". I can't transplant 7997 and at this moment I'm not
100% sure how to adapt the patch. If you wish this bug to be fixed in
3.0.x, please adapt the patch specially for 3.0.x.

regards

Ok, will do..

D.

--
David Bateman                                address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary



reply via email to

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