reorder to last dimension of 1

[Old posts from the commercial version of ArrayFire] Discussion of ArrayFire using CUDA or OpenCL.

Moderator: pavanky

reorder to last dimension of 1

Postby rm9 » Mon Apr 28, 2014 8:34 am

Hi,

Sometimes I have matrix of size [A B C 1] and I would like to reorder it to [A 1 B C].
ArrayFire gives an error in this case because it seems like it handles a dimension of size 1 at the end by dropping it, or ignoring it.
As a workaround I create an array [A B C 2], reorder it to [A 2 B C] and then take out only (span, 0, span, span).

Is there a better way?
Thanks.
rm9
 
Posts: 54
Joined: Thu Jan 30, 2014 5:44 am

Re: reorder to last dimension of 1

Postby shehzan » Mon Apr 28, 2014 10:44 am

Hi

I have tested the scenario you presented and the error does exist.
I have already fixed this bug while replying to this post.
We will release a fix for this shortly.

Thanks for notifying us.
----
Shehzan
Developer
AccelerEyes
User avatar
shehzan
 
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm

Re: reorder to last dimension of 1

Postby rm9 » Mon Apr 28, 2014 12:06 pm

Thanks! I'm waiting for the fix...
rm9
 
Posts: 54
Joined: Thu Jan 30, 2014 5:44 am

Re: reorder to last dimension of 1

Postby shehzan » Mon Apr 28, 2014 12:56 pm

Hi

Can you please post sample code for the segment you are this on?
----
Shehzan
Developer
AccelerEyes
User avatar
shehzan
 
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm

Re: reorder to last dimension of 1

Postby rm9 » Mon Apr 28, 2014 1:00 pm

This is my code:

Code: Select all

// Create an array with 2 in the last dimension.
array d4(d.dims(0), p.dims(3), d.dims(2), 2);
// Copy data from another array.
d4(span,span,span, 0) = tile(d(span, f2, span), 1, p.dims(3), 1);
// Reorder array, move last dimension to second.
array d3 = reorder(d4, 0, 3, 2, 1);
// Take only first item in the second dimension.
d3 = d3(span, 0, span, span);

rm9
 
Posts: 54
Joined: Thu Jan 30, 2014 5:44 am

Re: reorder to last dimension of 1

Postby pavanky » Mon Apr 28, 2014 1:04 pm

You can use the combination of reorder and moddims.

Code: Select all
array d2 = reorder(d, 0, 2, 1);
array d3 = moddims(d2, d2.dims(0), 1, d2.dims(1), d2.dims(2));
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: reorder to last dimension of 1

Postby rm9 » Mon Apr 28, 2014 1:08 pm

pavanky wrote:You can use the combination of reorder and moddims.

Code: Select all
array d2 = reorder(d, 0, 2, 1);
array d3 = moddims(d2, d2.dims(0), 1, d2.dims(1), d2.dims(2));


Thanks, it worked!
Btw, is there an upcoming release planned?
rm9
 
Posts: 54
Joined: Thu Jan 30, 2014 5:44 am


Return to [archive-commercial] Programming & Development with ArrayFire

cron