Skip to content

Commit ae70362

Browse files
committed
Write private method for padding dims to dim4
1 parent cf6bb8b commit ae70362

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

com/arrayfire/Array.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,39 +76,43 @@ public Array() {
7676
ref = 0;
7777
}
7878

79-
// Below version of constructor
80-
// allocates space on device and initializes
81-
// all elemets to zero
82-
public Array(int[] dims) throws Exception {
79+
private int[] dim4(int[] dims) throws Exception {
80+
8381
if( dims == null ) {
8482
throw new Exception("Null dimensions object provided");
85-
} else if ( dims.length > 3 ) {
86-
throw new Exception("Upto 3 dimensions only supported for now.");
83+
} else if ( dims.length > 4 ) {
84+
throw new Exception("ArrayFire supports up to 4 dimensions only");
8785
}
86+
8887
int[] adims;
8988
adims = new int[] {1, 1, 1, 1};
9089
for (int i = 0; i < dims.length; i++) adims[i] = dims[i];
9190

91+
return adims;
92+
}
93+
94+
// Below version of constructor
95+
// allocates space on device and initializes
96+
// all elemets to zero
97+
public Array(int[] dims) throws Exception {
98+
int[] adims = dim4(dims);
9299
this.ref = createArray(adims);
93100
}
94101

95102
public Array(int[] dims, float[] elems) throws Exception {
96-
if( dims == null || elems == null ) {
97-
throw new Exception("Null object provided");
98-
} else if ( dims.length > 3 ) {
99-
throw new Exception("Upto 3 dimensions only supported for now.");
100-
}
103+
int[] adims = dim4(dims);
104+
101105
int total_size = 1;
102-
for (int i = 0; i < dims.length; i++) total_size *= dims[i];
106+
for (int i = 0; i < adims.length; i++) total_size *= adims[i];
107+
108+
if(elems == null) {
109+
throw new Exception("Null elems object provided");
110+
}
103111

104112
if( elems.length > total_size || elems.length < total_size ) {
105113
throw new Exception("Mismatching dims and array size");
106114
}
107115

108-
int[] adims;
109-
adims = new int[] {1, 1, 1, 1};
110-
for (int i = 0; i < dims.length; i++) adims[i] = dims[i];
111-
112116
this.ref = createArrayElems(adims, elems);
113117
}
114118

0 commit comments

Comments
 (0)