• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // Don't edit this file!  It is auto-generated by frameworks/rs/api/generate.sh.
18 
19 package android.renderscript.cts;
20 
21 import android.renderscript.Allocation;
22 import android.renderscript.RSRuntimeException;
23 import android.renderscript.Element;
24 import android.renderscript.cts.Target;
25 
26 import java.util.Arrays;
27 
28 public class TestIlogb extends RSBaseCompute {
29 
30     private ScriptC_TestIlogb script;
31     private ScriptC_TestIlogbRelaxed scriptRelaxed;
32 
33     @Override
setUp()34     protected void setUp() throws Exception {
35         super.setUp();
36         script = new ScriptC_TestIlogb(mRS);
37         scriptRelaxed = new ScriptC_TestIlogbRelaxed(mRS);
38     }
39 
40     public class ArgumentsFloatInt {
41         public float inV;
42         public int out;
43     }
44 
checkIlogbFloatInt()45     private void checkIlogbFloatInt() {
46         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x5664967bl, false);
47         try {
48             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE);
49             script.forEach_testIlogbFloatInt(inV, out);
50             verifyResultsIlogbFloatInt(inV, out, false);
51         } catch (Exception e) {
52             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testIlogbFloatInt: " + e.toString());
53         }
54         try {
55             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE);
56             scriptRelaxed.forEach_testIlogbFloatInt(inV, out);
57             verifyResultsIlogbFloatInt(inV, out, true);
58         } catch (Exception e) {
59             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testIlogbFloatInt: " + e.toString());
60         }
61     }
62 
verifyResultsIlogbFloatInt(Allocation inV, Allocation out, boolean relaxed)63     private void verifyResultsIlogbFloatInt(Allocation inV, Allocation out, boolean relaxed) {
64         float[] arrayInV = new float[INPUTSIZE * 1];
65         Arrays.fill(arrayInV, (float) 42);
66         inV.copyTo(arrayInV);
67         int[] arrayOut = new int[INPUTSIZE * 1];
68         Arrays.fill(arrayOut, (int) 42);
69         out.copyTo(arrayOut);
70         StringBuilder message = new StringBuilder();
71         boolean errorFound = false;
72         for (int i = 0; i < INPUTSIZE; i++) {
73             for (int j = 0; j < 1 ; j++) {
74                 // Extract the inputs.
75                 ArgumentsFloatInt args = new ArgumentsFloatInt();
76                 args.inV = arrayInV[i];
77                 // Extract the outputs.
78                 args.out = arrayOut[i * 1 + j];
79                 // Ask the CoreMathVerifier to validate.
80                 String errorMessage = CoreMathVerifier.verifyIlogb(args);
81                 boolean valid = errorMessage == null;
82                 if (!valid) {
83                     if (!errorFound) {
84                         errorFound = true;
85                         message.append("Input inV: ");
86                         appendVariableToMessage(message, args.inV);
87                         message.append("\n");
88                         message.append("Output out: ");
89                         appendVariableToMessage(message, args.out);
90                         message.append("\n");
91                         message.append(errorMessage);
92                         message.append("Errors at");
93                     }
94                     message.append(" [");
95                     message.append(Integer.toString(i));
96                     message.append(", ");
97                     message.append(Integer.toString(j));
98                     message.append("]");
99                 }
100             }
101         }
102         assertFalse("Incorrect output for checkIlogbFloatInt" +
103                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
104     }
105 
checkIlogbFloat2Int2()106     private void checkIlogbFloat2Int2() {
107         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xb6f32a61l, false);
108         try {
109             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
110             script.forEach_testIlogbFloat2Int2(inV, out);
111             verifyResultsIlogbFloat2Int2(inV, out, false);
112         } catch (Exception e) {
113             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testIlogbFloat2Int2: " + e.toString());
114         }
115         try {
116             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
117             scriptRelaxed.forEach_testIlogbFloat2Int2(inV, out);
118             verifyResultsIlogbFloat2Int2(inV, out, true);
119         } catch (Exception e) {
120             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testIlogbFloat2Int2: " + e.toString());
121         }
122     }
123 
verifyResultsIlogbFloat2Int2(Allocation inV, Allocation out, boolean relaxed)124     private void verifyResultsIlogbFloat2Int2(Allocation inV, Allocation out, boolean relaxed) {
125         float[] arrayInV = new float[INPUTSIZE * 2];
126         Arrays.fill(arrayInV, (float) 42);
127         inV.copyTo(arrayInV);
128         int[] arrayOut = new int[INPUTSIZE * 2];
129         Arrays.fill(arrayOut, (int) 42);
130         out.copyTo(arrayOut);
131         StringBuilder message = new StringBuilder();
132         boolean errorFound = false;
133         for (int i = 0; i < INPUTSIZE; i++) {
134             for (int j = 0; j < 2 ; j++) {
135                 // Extract the inputs.
136                 ArgumentsFloatInt args = new ArgumentsFloatInt();
137                 args.inV = arrayInV[i * 2 + j];
138                 // Extract the outputs.
139                 args.out = arrayOut[i * 2 + j];
140                 // Ask the CoreMathVerifier to validate.
141                 String errorMessage = CoreMathVerifier.verifyIlogb(args);
142                 boolean valid = errorMessage == null;
143                 if (!valid) {
144                     if (!errorFound) {
145                         errorFound = true;
146                         message.append("Input inV: ");
147                         appendVariableToMessage(message, args.inV);
148                         message.append("\n");
149                         message.append("Output out: ");
150                         appendVariableToMessage(message, args.out);
151                         message.append("\n");
152                         message.append(errorMessage);
153                         message.append("Errors at");
154                     }
155                     message.append(" [");
156                     message.append(Integer.toString(i));
157                     message.append(", ");
158                     message.append(Integer.toString(j));
159                     message.append("]");
160                 }
161             }
162         }
163         assertFalse("Incorrect output for checkIlogbFloat2Int2" +
164                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
165     }
166 
checkIlogbFloat3Int3()167     private void checkIlogbFloat3Int3() {
168         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x9b3a97l, false);
169         try {
170             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
171             script.forEach_testIlogbFloat3Int3(inV, out);
172             verifyResultsIlogbFloat3Int3(inV, out, false);
173         } catch (Exception e) {
174             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testIlogbFloat3Int3: " + e.toString());
175         }
176         try {
177             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
178             scriptRelaxed.forEach_testIlogbFloat3Int3(inV, out);
179             verifyResultsIlogbFloat3Int3(inV, out, true);
180         } catch (Exception e) {
181             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testIlogbFloat3Int3: " + e.toString());
182         }
183     }
184 
verifyResultsIlogbFloat3Int3(Allocation inV, Allocation out, boolean relaxed)185     private void verifyResultsIlogbFloat3Int3(Allocation inV, Allocation out, boolean relaxed) {
186         float[] arrayInV = new float[INPUTSIZE * 4];
187         Arrays.fill(arrayInV, (float) 42);
188         inV.copyTo(arrayInV);
189         int[] arrayOut = new int[INPUTSIZE * 4];
190         Arrays.fill(arrayOut, (int) 42);
191         out.copyTo(arrayOut);
192         StringBuilder message = new StringBuilder();
193         boolean errorFound = false;
194         for (int i = 0; i < INPUTSIZE; i++) {
195             for (int j = 0; j < 3 ; j++) {
196                 // Extract the inputs.
197                 ArgumentsFloatInt args = new ArgumentsFloatInt();
198                 args.inV = arrayInV[i * 4 + j];
199                 // Extract the outputs.
200                 args.out = arrayOut[i * 4 + j];
201                 // Ask the CoreMathVerifier to validate.
202                 String errorMessage = CoreMathVerifier.verifyIlogb(args);
203                 boolean valid = errorMessage == null;
204                 if (!valid) {
205                     if (!errorFound) {
206                         errorFound = true;
207                         message.append("Input inV: ");
208                         appendVariableToMessage(message, args.inV);
209                         message.append("\n");
210                         message.append("Output out: ");
211                         appendVariableToMessage(message, args.out);
212                         message.append("\n");
213                         message.append(errorMessage);
214                         message.append("Errors at");
215                     }
216                     message.append(" [");
217                     message.append(Integer.toString(i));
218                     message.append(", ");
219                     message.append(Integer.toString(j));
220                     message.append("]");
221                 }
222             }
223         }
224         assertFalse("Incorrect output for checkIlogbFloat3Int3" +
225                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
226     }
227 
checkIlogbFloat4Int4()228     private void checkIlogbFloat4Int4() {
229         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x4a434acdl, false);
230         try {
231             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
232             script.forEach_testIlogbFloat4Int4(inV, out);
233             verifyResultsIlogbFloat4Int4(inV, out, false);
234         } catch (Exception e) {
235             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testIlogbFloat4Int4: " + e.toString());
236         }
237         try {
238             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
239             scriptRelaxed.forEach_testIlogbFloat4Int4(inV, out);
240             verifyResultsIlogbFloat4Int4(inV, out, true);
241         } catch (Exception e) {
242             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testIlogbFloat4Int4: " + e.toString());
243         }
244     }
245 
verifyResultsIlogbFloat4Int4(Allocation inV, Allocation out, boolean relaxed)246     private void verifyResultsIlogbFloat4Int4(Allocation inV, Allocation out, boolean relaxed) {
247         float[] arrayInV = new float[INPUTSIZE * 4];
248         Arrays.fill(arrayInV, (float) 42);
249         inV.copyTo(arrayInV);
250         int[] arrayOut = new int[INPUTSIZE * 4];
251         Arrays.fill(arrayOut, (int) 42);
252         out.copyTo(arrayOut);
253         StringBuilder message = new StringBuilder();
254         boolean errorFound = false;
255         for (int i = 0; i < INPUTSIZE; i++) {
256             for (int j = 0; j < 4 ; j++) {
257                 // Extract the inputs.
258                 ArgumentsFloatInt args = new ArgumentsFloatInt();
259                 args.inV = arrayInV[i * 4 + j];
260                 // Extract the outputs.
261                 args.out = arrayOut[i * 4 + j];
262                 // Ask the CoreMathVerifier to validate.
263                 String errorMessage = CoreMathVerifier.verifyIlogb(args);
264                 boolean valid = errorMessage == null;
265                 if (!valid) {
266                     if (!errorFound) {
267                         errorFound = true;
268                         message.append("Input inV: ");
269                         appendVariableToMessage(message, args.inV);
270                         message.append("\n");
271                         message.append("Output out: ");
272                         appendVariableToMessage(message, args.out);
273                         message.append("\n");
274                         message.append(errorMessage);
275                         message.append("Errors at");
276                     }
277                     message.append(" [");
278                     message.append(Integer.toString(i));
279                     message.append(", ");
280                     message.append(Integer.toString(j));
281                     message.append("]");
282                 }
283             }
284         }
285         assertFalse("Incorrect output for checkIlogbFloat4Int4" +
286                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
287     }
288 
testIlogb()289     public void testIlogb() {
290         checkIlogbFloatInt();
291         checkIlogbFloat2Int2();
292         checkIlogbFloat3Int3();
293         checkIlogbFloat4Int4();
294     }
295 }
296