max value calculation across a given dimension on 3d array

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

Moderator: pavanky

max value calculation across a given dimension on 3d array

Postby GBenito » Mon Dec 02, 2013 7:59 pm

Hi,

So pretty much as post topic claims, I'm trying to calculate the maximum values across a specific dimension on a 3D array.

The thing is that I have a certain number of matrices of the same size (m x n), so I pile them up together in an 'm x n x k' array (k being the number of matrices).

Then i'd like to get the maximum value of all these matrices for a given element[i,j], along with the index of such max value (which would be the number of the matrix it belongs to).

So if I have an 'm x n x k' sample array, I'd like to get 2 arrays: 1 m x n array with the max value of each element [i,j], and 1 m x n array with the index of each max value [i,j]...

This is the code i wrote for such task, but when i run it, i get an m x n array with the max values, but only a 3 x 1 array with what should be the indexes...

MatRes(af::span,af::span,indice) = Promedio;

//'MatRes' is the m x n x k array created with the k calcule iterations of array 'Promedio', located one after another using 'indice' as index...

af::array Avg = af::mean(MatRes,MatRes.dims(2));

af::array Maxi(image_H,image_W);
af::array MatAng(image_H,image_W);
max(Maxi, MatAng, MatRes,MatRes.dims(2));


Could anyone tell me which is the problem with such code, and how to fix it?

As you can see, i also calculate the mean values of each element[i,j] (so i use dimension(2) as argument), or at least that's what i intend it to do...

Thanks in advance...
GBenito
 
Posts: 32
Joined: Sun Nov 10, 2013 3:58 pm

Re: max value calculation across a given dimension on 3d arr

Postby shehzan » Tue Dec 03, 2013 10:59 am

Hi

The last parameter should be the dimension number, not the size of that particular dimension. i.e. use 2 instead of MatRes.dims(2).
Here is something quick I coded up and you can use.

Code: Select all
array test = randu(5, 4, 3);
print(test);
array max; array idx;
af::max(max, idx, test, 2);
print(max);
print(idx);


This will output:

Code: Select all
test [5 4 3] =
        0.7402     0.4464     0.7762     0.2920
        0.9210     0.6673     0.2948     0.3194
        0.0390     0.1099     0.7140     0.8109
        0.9690     0.4702     0.3585     0.1541
        0.9251     0.5132     0.6814     0.4452

        0.2080     0.8793     0.3557     0.3750
        0.6110     0.6462     0.7229     0.2405
        0.3073     0.9264     0.2783     0.4148
        0.4156     0.5786     0.6192     0.0937
        0.2343     0.5538     0.5876     0.6326

        0.2849     0.5360     0.9200     0.0421
        0.7793     0.7214     0.1872     0.7305
        0.2133     0.3546     0.1820     0.9400
        0.4131     0.2527     0.5984     0.8432
        0.0328     0.9847     0.7082     0.6116

max [5 4] =
        0.7402     0.8793     0.9200     0.3750
        0.9210     0.7214     0.7229     0.7305
        0.3073     0.9264     0.7140     0.9400
        0.9690     0.5786     0.6192     0.8432
        0.9251     0.9847     0.7082     0.6326

idx [5 4] =
        0     1     2     1
        0     2     1     2
        1     1     0     2
        0     1     1     2
        0     2     2     1


The used function is documented at: http://www.accelereyes.com/arrayfire/c/group__utility__func__cpp__max.htm#gac3cfb52f12166173de2ac1dabcaa6bb9

Let me know if this works for you.
----
Shehzan
Developer
AccelerEyes
User avatar
shehzan
 
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm

Re: max value calculation across a given dimension on 3d arr

Postby GBenito » Wed Dec 04, 2013 5:45 pm

I got to figure it out through trying some variants hehe....but thanks for the quick reply anyways!!!
GBenito
 
Posts: 32
Joined: Sun Nov 10, 2013 3:58 pm


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

cron