octave-maintainers
[Top][All Lists]
Advanced

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

Re: Kronecker products as objects?


From: Søren Hauberg
Subject: Re: Kronecker products as objects?
Date: Wed, 24 Mar 2010 09:46:36 -0700

ons, 24 03 2010 kl. 09:38 +0100, skrev David Bateman:
> I'd suggest modifying the full function like
> 
> function retval = full (KP)
>   if (isempty (KP.full))
>     KP.full = kron (KP.A, KP.B);
>   endif
>   retval = full (KP.full);
> endfunction

The idea in this function was that the full matrix should be cached such
that we don't have to evaluate it more than once (it can get very
expensive). I just realised that the code doesn't actually do that, as
the 'full' function is modifying a copy of the object. So this idea of
caching the full matrix doesn't seem to be implementable with an m-file
class.

I guess it will be better to simple raise an error when the user does
something that requires the full matrix (informing the user to use
'full'). This is also what is done with sparse matrices, right?

> and adding the functions
> 
> function  retval = issparse (KP)
>     retval = issparse(KP.A) || issparse(KP.B);
> endfunction

I'll add this one. Thanks.

> function retval = sparse (KP)
>   if (isempty (KP.full))
>     KP.full = kron (KP.A, KP.B);
>   endif
>   retval = sparse (KP.full);
> endfunction

Ohh, I see 'kron' can deal with sparse matrices, so this won't be create
the full matrix if 'A' and 'B' are sparse. I'll add this function.

> function retval = double (KP)
>   if (isempty (KP.full))
>     KP.full = kron (KP.A, KP.B);
>   endif
>   retval = KP.full;
> endfunction
> 
> then use the double function in the places you used full in your code. 
> In that way your knonprod object can be pretty much agnostics whether 
> its treating full or sparse matrices internally.

But then I can't handle complex matrices, right? I am unsure about the
'double'. Is it supposed to convert back into either a sparse or a full
matrix or should it just ensure that that the matrices are double, i.e.

function retval = double (KP)
  retval = kronprod (double (KP.A), double (KP.B));
endfunction

?

Soren



reply via email to

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