kron with a single sparse matrix- another corner case
David Bateman
David.Bateman at motorola.com
Fri Jan 4 09:50:23 CST 2008
augustm wrote:
> Octave-3.0.0. on linux 64 bit.
>
>
> I like to build finite difference operators (with several fields) from sparse
> representations of derivative operators, which are then replicated with the
> "kron" function.
>
> It is perhaps natural that
> kron(full, sparse) gives a sparse result.
>
> However kron promotes to full by defaults. A trivial example creates
> an empty sparse matrix and replicates twice using kron.
>
>
> octave:1> j=sparse( [], [] , [], 10,10) ;
> octave:2> whos j
>
> *** local user variables:
>
> Prot Name Size Bytes Class
> ==== ==== ==== ===== =====
> rwd j 10x10 44 double
>
> Total is 0 elements using 44 bytes
>
> octave:3> jj=kron ( [1 0], j );
> octave:4> whos jj
>
> *** local user variables:
>
> Prot Name Size Bytes Class
> ==== ==== ==== ===== =====
> rwd jj 10x20 1600 double
>
> Total is 200 elements using 1600 bytes
>
>
> The work around is to use
> jj=kron ( sparse([1 0]), j );
>
>
> Note Matlab uses the suggested behaviour. This was found on porting over
> a code previously run under matlab.
>
> TM, Paris.
>
Ok, this is hard to do still, as the sparse kron function is in fact
spkron and dispatch is used so that the first argument to the kron
function picks whether the sparse or full version is used.
What we need to do to fix this is to use the newly introduced object
classes (ie the "@" directories in this case) and the superiorto
function to force mixed sparse/full function to be treated by the sparse
versions of the functions. As we are still missing the superiorto
function this isn't yet possible and so even converting to object
classes won't help here yet... I think this is one that will have to
wait at the moment.
The workaround in Octave is just to call directly the spkron function.
D.
--
David Bateman David.Bateman at motorola.com
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
More information about the Bug-octave
mailing list