Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Temporary output when assigning into slices?
Replies: 10   Last Post: Jan 27, 2013 3:53 AM

 Messages: [ Previous | Next ]
 Matt J Posts: 4,997 Registered: 11/28/09
Re: Temporary output when assigning into slices?
Posted: Jan 23, 2013 4:05 PM

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kdpg30\$6gl\$1@newscl01ah.mathworks.com>...
>
> > A(:,1)=B*x;
> >
> > Is this equivalent to
> >
> > z=B*x; %memory allocated here
> > A(:,1)=z;
> >
> > Or, does the output of B*x get directly generated in the memory locations occupied by A(:,1)?

>
> On recent MATLAB versions (2010a?), MATLAB is smart and puts directly the output in-place.

================

OK. That's strangely inconsistent with things I'm seeing, but so be it.

> If the resulting is not in a contiguous memory, similar optimization on memory space will slow down the speed. I suspect that is the main reason why the optimization cannot be carried out in the later example.
===============

Don't you mean, that optimization cannot be carried out in the *latter* example? I can see for example why

A=B(1,idx)*C

might have to extract B(1,idx) to a continguous memory block when C is a matrix. In that case the elements in B(1,idx) will be accessed many times.

Date Subject Author
1/23/13 Matt J
1/23/13 Bruno Luong
1/23/13 Matt J
1/23/13 Bruno Luong
1/23/13 Matt J
1/23/13 Bruno Luong
1/23/13 Matt J
1/23/13 Bruno Luong
1/24/13 Matt J
1/24/13 Matt J
1/27/13 Bruno Luong