From: Andreas Lobinger on
Aloha,

in the SW i'm working on, there are some operations which
f.e. build a 'cross' difference, so from all elements from
one vector to all elements in the second vector.

d = repmat(a,1,size(b,2)) - repmat(b,size(a,1),1);

As my a changes over the runtime and the b is constant, i
store the possible repmat(b...) and build the repmat(a,...)
in runtime.

Recently i learned, that bsxfun(@minus, ...) would be an
option not to do the repmat and have the difference calculated
in place.

However, the profiler tells me, that using bsxfun is slower
than the initial solution (?).

So if the initial solution needs something like 1.0 (time) for the
difference (-) and around 0.6 for the repmat(b...) the
bsxfun is 2.0, so slower then the sum of the operations.

What i'm doing wrong?

Wishing a happy day,
LOBI
From: Walter Roberson on
Andreas Lobinger wrote:

> Recently i learned, that bsxfun(@minus, ...) would be an
> option not to do the repmat and have the difference calculated
> in place.
>
> However, the profiler tells me, that using bsxfun is slower
> than the initial solution (?).

Instead of @minus there, try 'minus' (the string 'minus') as bsxfun has
built-in logic to handle that if I recall.
From: Oliver Woodford on
Walter Roberson wrote:
> Instead of @minus there, try 'minus' (the string 'minus') as bsxfun has
> built-in logic to handle that if I recall.

Apparently not:
>> bsxfun('minus', [1; 2], [0 1])
??? Error using ==> bsxfun
First Argument must be a function handle.

A pity. It's a good idea.
From: Peter Perkins on
On 6/10/2010 2:33 AM, Andreas Lobinger wrote:
> in the SW i'm working on, there are some operations which
> f.e. build a 'cross' difference, so from all elements from
> one vector to all elements in the second vector.
>
> d = repmat(a,1,size(b,2)) - repmat(b,size(a,1),1);

> However, the profiler tells me, that using bsxfun is slower
> than the initial solution (?).

LOBI, how big are a and b?
From: Matt Fig on
Walter Roberson <roberson(a)hushmail.com> wrote in message <6N%Pn.72624$HG1.14036(a)newsfe21.iad>...
> Andreas Lobinger wrote:
>
> > Recently i learned, that bsxfun(@minus, ...) would be an
> > option not to do the repmat and have the difference calculated
> > in place.
> >
> > However, the profiler tells me, that using bsxfun is slower
> > than the initial solution (?).
>
> Instead of @minus there, try 'minus' (the string 'minus') as bsxfun has
> built-in logic to handle that if I recall.

You might be thinking of the limited string inputs to CELLFUN, which are indeed much faster than using equivalent function handles. I wish TMW would increase the number of these for CELLFUN and add some for BSXFUN.
 |  Next  |  Last
Pages: 1 2 3
Prev: Finding max of simple function
Next: Filter Design