Thread Subject: reshaping cost

Subject: reshaping cost

From: Jay

Date: 24 Apr, 2008 18:50:04

Message: 1 of 4

What is the time and memory cost of reshaping a matrix?

Given a matrix M with N elements, and I reshape to any other
size having N elements, I would hope I'm only changing the
matrix shape parameters rather than *any* memcpy at all.

However I see no post or doc on this. Anyone know?

Thanks

Subject: reshaping cost

From: Peter Boettcher

Date: 24 Apr, 2008 18:54:53

Message: 2 of 4

"Jay " <jay.damask@mlp.com> writes:

> What is the time and memory cost of reshaping a matrix?
>
> Given a matrix M with N elements, and I reshape to any other
> size having N elements, I would hope I'm only changing the
> matrix shape parameters rather than *any* memcpy at all.
>
> However I see no post or doc on this. Anyone know?

Run the following:

format debug
a=1:10
b=reshape(a,2,5)

pr has the same value, which means both share the same data block.

-Peter

Subject: reshaping cost

From: Jay

Date: 24 Apr, 2008 19:09:01

Message: 3 of 4

Peter Boettcher <boettcher@ll.mit.edu> wrote in message
<muyve27m6bm.fsf@G99-Boettcher.llan.ll.mit.edu>...
> "Jay " <jay.damask@mlp.com> writes:
>
> > What is the time and memory cost of reshaping a matrix?
> >
> > Given a matrix M with N elements, and I reshape to any other
> > size having N elements, I would hope I'm only changing the
> > matrix shape parameters rather than *any* memcpy at all.
> >
> > However I see no post or doc on this. Anyone know?
>
> Run the following:
>
> format debug
> a=1:10
> b=reshape(a,2,5)
>
> pr has the same value, which means both share the same
data block.
>
> -Peter

okay, super. I didn't know about the format debug. Thanks
for the help.

Subject: reshaping cost

From: Bruno Luong

Date: 24 Apr, 2008 21:06:02

Message: 4 of 4

Peter Boettcher <boettcher@ll.mit.edu> wrote in message
<muyve27m6bm.fsf@G99-Boettcher.llan.ll.mit.edu>...
>
> format debug

Really cool!!! Thanks Peter.

Is it an undocumented option?

Bruno

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
undocumented Yair Altman 30 Apr, 2008 17:47:40
reshaping cost Jay 24 Apr, 2008 14:55:04
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com