Is transpose costless?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Is transpose costless?

Rik-4
jwe,

I had a question about optimization in the parser.  If I write

x = x.';

is that effectively a costless operation that simply swaps the first two
values of the dimension vector?  Or does Octave first create a temporary
intermediate (which is costless because of COW), but then the transpose
operator forces a deep copy to the intermediate, and then the final
assignment takes place (also potentially another deep copy).

--Rik


Reply | Threaded
Open this post in threaded view
|

Re: Is transpose costless?

John W. Eaton
Administrator
On 7/15/19 11:47 AM, Rik wrote:

> I had a question about optimization in the parser.  If I write
>
> x = x.';
>
> is that effectively a costless operation that simply swaps the first two
> values of the dimension vector?  Or does Octave first create a temporary
> intermediate (which is costless because of COW), but then the transpose
> operator forces a deep copy to the intermediate, and then the final
> assignment takes place (also potentially another deep copy).

Transpose for Array<T> objects, which includes numeric arrays, cell
arrays, and values of the fields of struct arrays (because they are
stored as cell arrays) is handled in liboctave/array/Array.cc.
Transpose only works for 2-dimensional arrays and there is a special
case for empty arrays and vectors that just swaps the dimensions and
shares the data array.  Otherwise, if the number of rows and columns are
both greater than 1, we have to copy data.

jwe