Re: Adding fast many polynomials of varying degrees
- From: "John D'Errico" <woodchips@xxxxxxxxxxxxxxxx>
- Date: Thu, 13 Apr 2006 16:14:28 -0400
jeicke wrote:
Maybe somehow converting it into a regular MATLAB matrix first,
using
the function cell2mat, then using the function 'sum', would be
faster.
You also might look at using sparse matrices for P instead of a
cell
array. Are you using a cell array to do something similar as a
sparse
matrix?
That's my guess- and, although I've not used benchmarked cell
arrays
myself, I'd be shocked if they weren't much slower than non-cell
arrays.
Much depends upon what else you are doing with
these polynomials, and how you generate them.
A sparse form would make this sum much faster,
but other operations might be less fast.
If many of your polynomials are very short
and of the same length, then you might be able
to gain by
Lp = cellfun('length',P);
Now, use unique on the lengths Lp, separating
out all polynomials with the same lengths.
Use a cat operation to concatenate all of the
identified same length polynomials together,
then sum them, and accumulate into a total
summed polynomial.
Would this be more efficient than a brute
force sum? I have no way to tell without
knowing the distribution of lengths.
Another trick is to use sparse to directly
sum the polynomials. This might be fast.
Something like this:
P = {1:3 1 1:3 2:5};
S = sparse(1,cell2mat(cellfun(@(c) ...
length(c):-1:1,P,'UniformOutput',false)),cell2mat(P));
S = fliplr(full(S));
This code can surely be cleaned up.
HTH,
John D'Errico
.
- Follow-Ups:
- Re: Adding fast many polynomials of varying degree
- From: Pierre Grinspan
- Re: Adding fast many polynomials of varying degree
- References:
- Adding fast many polynomials of varying degrees
- From: Pierre Grinspan
- Re: Adding fast many polynomials of varying degrees
- From: jeicke
- Adding fast many polynomials of varying degrees
- Prev by Date: Re: now that was interesting
- Next by Date: Re: now that was interesting
- Previous by thread: Re: Adding fast many polynomials of varying degrees
- Next by thread: Re: Adding fast many polynomials of varying degree
- Index(es):
Relevant Pages
|
Loading