@@ -11,59 +11,59 @@ using af::dim4;
1111namespace cpu
1212{
1313
14- static inline unsigned getIdx (const dim4 &strides,
15- int i, int j = 0 , int k = 0 , int l = 0 )
16- {
17- return (l * strides[3 ] +
18- k * strides[2 ] +
19- j * strides[1 ] +
20- i );
21- }
14+ static inline unsigned getIdx (const dim4 &strides,
15+ int i, int j = 0 , int k = 0 , int l = 0 )
16+ {
17+ return (l * strides[3 ] +
18+ k * strides[2 ] +
19+ j * strides[1 ] +
20+ i );
21+ }
2222
23- template <typename T>
24- Array<T> * transpose (const Array<T> &in)
25- {
26- const dim4 inDims = in.dims ();
23+ template <typename T>
24+ Array<T> * transpose (const Array<T> &in)
25+ {
26+ const dim4 inDims = in.dims ();
2727
28- dim4 outDims = dim4 (inDims[1 ],inDims[0 ],inDims[2 ],inDims[3 ]);
28+ dim4 outDims = dim4 (inDims[1 ],inDims[0 ],inDims[2 ],inDims[3 ]);
2929
30- // create an array with first two dimensions swapped
31- Array<T>* out = createEmptyArray<T>(outDims);
30+ // create an array with first two dimensions swapped
31+ Array<T>* out = createEmptyArray<T>(outDims);
3232
33- // get data pointers for input and output Arrays
34- T* outData = out->get ();
35- const T* inData = in.get ();
33+ // get data pointers for input and output Arrays
34+ T* outData = out->get ();
35+ const T* inData = in.get ();
3636
37- for (uint k=0 ; k<outDims[2 ]; ++k) {
38- // Outermost loop handles batch mode
39- // if input has no data along third dimension
40- // this loop runs only once
41- for (uint j=0 ; j<outDims[1 ]; ++j) {
42- for (uint i=0 ; i<outDims[0 ]; ++i) {
43- // calculate array indices based on offsets and strides
44- // the helper getIdx takes care of indices
45- int inIdx = getIdx (in.strides (),j,i,k);
46- int outIdx = getIdx (out->strides (),i,j,k);
47- outData[outIdx] = inData[inIdx];
48- }
37+ for (uint k=0 ; k<outDims[2 ]; ++k) {
38+ // Outermost loop handles batch mode
39+ // if input has no data along third dimension
40+ // this loop runs only once
41+ for (uint j=0 ; j<outDims[1 ]; ++j) {
42+ for (uint i=0 ; i<outDims[0 ]; ++i) {
43+ // calculate array indices based on offsets and strides
44+ // the helper getIdx takes care of indices
45+ int inIdx = getIdx (in.strides (),j,i,k);
46+ int outIdx = getIdx (out->strides (),i,j,k);
47+ outData[outIdx] = inData[inIdx];
4948 }
50- // outData and inData pointers doesn't need to be
51- // offset as the getIdx function is taking care
52- // of the batch parameter
5349 }
54- return out;
50+ // outData and inData pointers doesn't need to be
51+ // offset as the getIdx function is taking care
52+ // of the batch parameter
5553 }
54+ return out;
55+ }
5656
5757#define INSTANTIATE (T )\
5858 template Array<T> * transpose (const Array<T> &in);
5959
60- INSTANTIATE (float )
61- INSTANTIATE (cfloat)
62- INSTANTIATE (double )
63- INSTANTIATE (cdouble)
64- INSTANTIATE (char )
65- INSTANTIATE ( int )
66- INSTANTIATE (uint)
67- INSTANTIATE (uchar)
60+ INSTANTIATE (float )
61+ INSTANTIATE (cfloat )
62+ INSTANTIATE (double )
63+ INSTANTIATE (cdouble)
64+ INSTANTIATE (char )
65+ INSTANTIATE ( int )
66+ INSTANTIATE (uint )
67+ INSTANTIATE (uchar )
6868
6969}
0 commit comments