• 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 TestNativeExpm1 extends RSBaseCompute {
29 
30     private ScriptC_TestNativeExpm1 script;
31     private ScriptC_TestNativeExpm1Relaxed scriptRelaxed;
32 
33     @Override
setUp()34     protected void setUp() throws Exception {
35         super.setUp();
36         script = new ScriptC_TestNativeExpm1(mRS);
37         scriptRelaxed = new ScriptC_TestNativeExpm1Relaxed(mRS);
38     }
39 
40     public class ArgumentsFloatFloat {
41         public float inV;
42         public Target.Floaty out;
43     }
44 
checkNativeExpm1FloatFloat()45     private void checkNativeExpm1FloatFloat() {
46         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x7094f34bl, false);
47         try {
48             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
49             script.forEach_testNativeExpm1FloatFloat(inV, out);
50             verifyResultsNativeExpm1FloatFloat(inV, out, false);
51         } catch (Exception e) {
52             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1FloatFloat: " + e.toString());
53         }
54         try {
55             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
56             scriptRelaxed.forEach_testNativeExpm1FloatFloat(inV, out);
57             verifyResultsNativeExpm1FloatFloat(inV, out, true);
58         } catch (Exception e) {
59             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1FloatFloat: " + e.toString());
60         }
61     }
62 
verifyResultsNativeExpm1FloatFloat(Allocation inV, Allocation out, boolean relaxed)63     private void verifyResultsNativeExpm1FloatFloat(Allocation inV, Allocation out, boolean relaxed) {
64         float[] arrayInV = new float[INPUTSIZE * 1];
65         Arrays.fill(arrayInV, (float) 42);
66         inV.copyTo(arrayInV);
67         float[] arrayOut = new float[INPUTSIZE * 1];
68         Arrays.fill(arrayOut, (float) 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                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
76                 args.inV = arrayInV[i];
77                 // Figure out what the outputs should have been.
78                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
79                 CoreMathVerifier.computeNativeExpm1(args, target);
80                 // Validate the outputs.
81                 boolean valid = true;
82                 if (!args.out.couldBe(arrayOut[i * 1 + j])) {
83                     valid = false;
84                 }
85                 if (!valid) {
86                     if (!errorFound) {
87                         errorFound = true;
88                         message.append("Input inV: ");
89                         appendVariableToMessage(message, args.inV);
90                         message.append("\n");
91                         message.append("Expected output out: ");
92                         appendVariableToMessage(message, args.out);
93                         message.append("\n");
94                         message.append("Actual   output out: ");
95                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
96                         if (!args.out.couldBe(arrayOut[i * 1 + j])) {
97                             message.append(" FAIL");
98                         }
99                         message.append("\n");
100                         message.append("Errors at");
101                     }
102                     message.append(" [");
103                     message.append(Integer.toString(i));
104                     message.append(", ");
105                     message.append(Integer.toString(j));
106                     message.append("]");
107                 }
108             }
109         }
110         assertFalse("Incorrect output for checkNativeExpm1FloatFloat" +
111                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
112     }
113 
checkNativeExpm1Float2Float2()114     private void checkNativeExpm1Float2Float2() {
115         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xe84b7997l, false);
116         try {
117             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
118             script.forEach_testNativeExpm1Float2Float2(inV, out);
119             verifyResultsNativeExpm1Float2Float2(inV, out, false);
120         } catch (Exception e) {
121             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Float2Float2: " + e.toString());
122         }
123         try {
124             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
125             scriptRelaxed.forEach_testNativeExpm1Float2Float2(inV, out);
126             verifyResultsNativeExpm1Float2Float2(inV, out, true);
127         } catch (Exception e) {
128             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Float2Float2: " + e.toString());
129         }
130     }
131 
verifyResultsNativeExpm1Float2Float2(Allocation inV, Allocation out, boolean relaxed)132     private void verifyResultsNativeExpm1Float2Float2(Allocation inV, Allocation out, boolean relaxed) {
133         float[] arrayInV = new float[INPUTSIZE * 2];
134         Arrays.fill(arrayInV, (float) 42);
135         inV.copyTo(arrayInV);
136         float[] arrayOut = new float[INPUTSIZE * 2];
137         Arrays.fill(arrayOut, (float) 42);
138         out.copyTo(arrayOut);
139         StringBuilder message = new StringBuilder();
140         boolean errorFound = false;
141         for (int i = 0; i < INPUTSIZE; i++) {
142             for (int j = 0; j < 2 ; j++) {
143                 // Extract the inputs.
144                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
145                 args.inV = arrayInV[i * 2 + j];
146                 // Figure out what the outputs should have been.
147                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
148                 CoreMathVerifier.computeNativeExpm1(args, target);
149                 // Validate the outputs.
150                 boolean valid = true;
151                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
152                     valid = false;
153                 }
154                 if (!valid) {
155                     if (!errorFound) {
156                         errorFound = true;
157                         message.append("Input inV: ");
158                         appendVariableToMessage(message, args.inV);
159                         message.append("\n");
160                         message.append("Expected output out: ");
161                         appendVariableToMessage(message, args.out);
162                         message.append("\n");
163                         message.append("Actual   output out: ");
164                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
165                         if (!args.out.couldBe(arrayOut[i * 2 + j])) {
166                             message.append(" FAIL");
167                         }
168                         message.append("\n");
169                         message.append("Errors at");
170                     }
171                     message.append(" [");
172                     message.append(Integer.toString(i));
173                     message.append(", ");
174                     message.append(Integer.toString(j));
175                     message.append("]");
176                 }
177             }
178         }
179         assertFalse("Incorrect output for checkNativeExpm1Float2Float2" +
180                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
181     }
182 
checkNativeExpm1Float3Float3()183     private void checkNativeExpm1Float3Float3() {
184         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xde669a75l, false);
185         try {
186             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
187             script.forEach_testNativeExpm1Float3Float3(inV, out);
188             verifyResultsNativeExpm1Float3Float3(inV, out, false);
189         } catch (Exception e) {
190             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Float3Float3: " + e.toString());
191         }
192         try {
193             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
194             scriptRelaxed.forEach_testNativeExpm1Float3Float3(inV, out);
195             verifyResultsNativeExpm1Float3Float3(inV, out, true);
196         } catch (Exception e) {
197             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Float3Float3: " + e.toString());
198         }
199     }
200 
verifyResultsNativeExpm1Float3Float3(Allocation inV, Allocation out, boolean relaxed)201     private void verifyResultsNativeExpm1Float3Float3(Allocation inV, Allocation out, boolean relaxed) {
202         float[] arrayInV = new float[INPUTSIZE * 4];
203         Arrays.fill(arrayInV, (float) 42);
204         inV.copyTo(arrayInV);
205         float[] arrayOut = new float[INPUTSIZE * 4];
206         Arrays.fill(arrayOut, (float) 42);
207         out.copyTo(arrayOut);
208         StringBuilder message = new StringBuilder();
209         boolean errorFound = false;
210         for (int i = 0; i < INPUTSIZE; i++) {
211             for (int j = 0; j < 3 ; j++) {
212                 // Extract the inputs.
213                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
214                 args.inV = arrayInV[i * 4 + j];
215                 // Figure out what the outputs should have been.
216                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
217                 CoreMathVerifier.computeNativeExpm1(args, target);
218                 // Validate the outputs.
219                 boolean valid = true;
220                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
221                     valid = false;
222                 }
223                 if (!valid) {
224                     if (!errorFound) {
225                         errorFound = true;
226                         message.append("Input inV: ");
227                         appendVariableToMessage(message, args.inV);
228                         message.append("\n");
229                         message.append("Expected output out: ");
230                         appendVariableToMessage(message, args.out);
231                         message.append("\n");
232                         message.append("Actual   output out: ");
233                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
234                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
235                             message.append(" FAIL");
236                         }
237                         message.append("\n");
238                         message.append("Errors at");
239                     }
240                     message.append(" [");
241                     message.append(Integer.toString(i));
242                     message.append(", ");
243                     message.append(Integer.toString(j));
244                     message.append("]");
245                 }
246             }
247         }
248         assertFalse("Incorrect output for checkNativeExpm1Float3Float3" +
249                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
250     }
251 
checkNativeExpm1Float4Float4()252     private void checkNativeExpm1Float4Float4() {
253         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xd481bb53l, false);
254         try {
255             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
256             script.forEach_testNativeExpm1Float4Float4(inV, out);
257             verifyResultsNativeExpm1Float4Float4(inV, out, false);
258         } catch (Exception e) {
259             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Float4Float4: " + e.toString());
260         }
261         try {
262             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
263             scriptRelaxed.forEach_testNativeExpm1Float4Float4(inV, out);
264             verifyResultsNativeExpm1Float4Float4(inV, out, true);
265         } catch (Exception e) {
266             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Float4Float4: " + e.toString());
267         }
268     }
269 
verifyResultsNativeExpm1Float4Float4(Allocation inV, Allocation out, boolean relaxed)270     private void verifyResultsNativeExpm1Float4Float4(Allocation inV, Allocation out, boolean relaxed) {
271         float[] arrayInV = new float[INPUTSIZE * 4];
272         Arrays.fill(arrayInV, (float) 42);
273         inV.copyTo(arrayInV);
274         float[] arrayOut = new float[INPUTSIZE * 4];
275         Arrays.fill(arrayOut, (float) 42);
276         out.copyTo(arrayOut);
277         StringBuilder message = new StringBuilder();
278         boolean errorFound = false;
279         for (int i = 0; i < INPUTSIZE; i++) {
280             for (int j = 0; j < 4 ; j++) {
281                 // Extract the inputs.
282                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
283                 args.inV = arrayInV[i * 4 + j];
284                 // Figure out what the outputs should have been.
285                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
286                 CoreMathVerifier.computeNativeExpm1(args, target);
287                 // Validate the outputs.
288                 boolean valid = true;
289                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
290                     valid = false;
291                 }
292                 if (!valid) {
293                     if (!errorFound) {
294                         errorFound = true;
295                         message.append("Input inV: ");
296                         appendVariableToMessage(message, args.inV);
297                         message.append("\n");
298                         message.append("Expected output out: ");
299                         appendVariableToMessage(message, args.out);
300                         message.append("\n");
301                         message.append("Actual   output out: ");
302                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
303                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
304                             message.append(" FAIL");
305                         }
306                         message.append("\n");
307                         message.append("Errors at");
308                     }
309                     message.append(" [");
310                     message.append(Integer.toString(i));
311                     message.append(", ");
312                     message.append(Integer.toString(j));
313                     message.append("]");
314                 }
315             }
316         }
317         assertFalse("Incorrect output for checkNativeExpm1Float4Float4" +
318                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
319     }
320 
321     public class ArgumentsHalfHalf {
322         public short inV;
323         public double inVDouble;
324         public short out;
325         public double outDouble;
326     }
327 
checkNativeExpm1HalfHalf()328     private void checkNativeExpm1HalfHalf() {
329         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x1f7c28dl, false);
330         try {
331             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
332             script.forEach_testNativeExpm1HalfHalf(inV, out);
333             verifyResultsNativeExpm1HalfHalf(inV, out, false);
334         } catch (Exception e) {
335             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1HalfHalf: " + e.toString());
336         }
337         try {
338             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
339             scriptRelaxed.forEach_testNativeExpm1HalfHalf(inV, out);
340             verifyResultsNativeExpm1HalfHalf(inV, out, true);
341         } catch (Exception e) {
342             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1HalfHalf: " + e.toString());
343         }
344     }
345 
verifyResultsNativeExpm1HalfHalf(Allocation inV, Allocation out, boolean relaxed)346     private void verifyResultsNativeExpm1HalfHalf(Allocation inV, Allocation out, boolean relaxed) {
347         short[] arrayInV = new short[INPUTSIZE * 1];
348         Arrays.fill(arrayInV, (short) 42);
349         inV.copyTo(arrayInV);
350         short[] arrayOut = new short[INPUTSIZE * 1];
351         Arrays.fill(arrayOut, (short) 42);
352         out.copyTo(arrayOut);
353         StringBuilder message = new StringBuilder();
354         boolean errorFound = false;
355         for (int i = 0; i < INPUTSIZE; i++) {
356             for (int j = 0; j < 1 ; j++) {
357                 // Extract the inputs.
358                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
359                 args.inV = arrayInV[i];
360                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
361                 // Extract the outputs.
362                 args.out = arrayOut[i * 1 + j];
363                 args.outDouble = Float16Utils.convertFloat16ToDouble(args.out);
364                 // Ask the CoreMathVerifier to validate.
365                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
366                 String errorMessage = CoreMathVerifier.verifyNativeExpm1(args, target);
367                 boolean valid = errorMessage == null;
368                 if (!valid) {
369                     if (!errorFound) {
370                         errorFound = true;
371                         message.append("Input inV: ");
372                         appendVariableToMessage(message, args.inV);
373                         message.append("\n");
374                         message.append("Output out: ");
375                         appendVariableToMessage(message, args.out);
376                         message.append("\n");
377                         message.append("\n");
378                         message.append("Output out (in double): ");
379                         appendVariableToMessage(message, args.outDouble);
380                         message.append("\n");
381                         message.append(errorMessage);
382                         message.append("Errors at");
383                     }
384                     message.append(" [");
385                     message.append(Integer.toString(i));
386                     message.append(", ");
387                     message.append(Integer.toString(j));
388                     message.append("]");
389                 }
390             }
391         }
392         assertFalse("Incorrect output for checkNativeExpm1HalfHalf" +
393                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
394     }
395 
checkNativeExpm1Half2Half2()396     private void checkNativeExpm1Half2Half2() {
397         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xddb33a87l, false);
398         try {
399             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
400             script.forEach_testNativeExpm1Half2Half2(inV, out);
401             verifyResultsNativeExpm1Half2Half2(inV, out, false);
402         } catch (Exception e) {
403             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Half2Half2: " + e.toString());
404         }
405         try {
406             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
407             scriptRelaxed.forEach_testNativeExpm1Half2Half2(inV, out);
408             verifyResultsNativeExpm1Half2Half2(inV, out, true);
409         } catch (Exception e) {
410             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Half2Half2: " + e.toString());
411         }
412     }
413 
verifyResultsNativeExpm1Half2Half2(Allocation inV, Allocation out, boolean relaxed)414     private void verifyResultsNativeExpm1Half2Half2(Allocation inV, Allocation out, boolean relaxed) {
415         short[] arrayInV = new short[INPUTSIZE * 2];
416         Arrays.fill(arrayInV, (short) 42);
417         inV.copyTo(arrayInV);
418         short[] arrayOut = new short[INPUTSIZE * 2];
419         Arrays.fill(arrayOut, (short) 42);
420         out.copyTo(arrayOut);
421         StringBuilder message = new StringBuilder();
422         boolean errorFound = false;
423         for (int i = 0; i < INPUTSIZE; i++) {
424             for (int j = 0; j < 2 ; j++) {
425                 // Extract the inputs.
426                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
427                 args.inV = arrayInV[i * 2 + j];
428                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
429                 // Extract the outputs.
430                 args.out = arrayOut[i * 2 + j];
431                 args.outDouble = Float16Utils.convertFloat16ToDouble(args.out);
432                 // Ask the CoreMathVerifier to validate.
433                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
434                 String errorMessage = CoreMathVerifier.verifyNativeExpm1(args, target);
435                 boolean valid = errorMessage == null;
436                 if (!valid) {
437                     if (!errorFound) {
438                         errorFound = true;
439                         message.append("Input inV: ");
440                         appendVariableToMessage(message, args.inV);
441                         message.append("\n");
442                         message.append("Output out: ");
443                         appendVariableToMessage(message, args.out);
444                         message.append("\n");
445                         message.append("\n");
446                         message.append("Output out (in double): ");
447                         appendVariableToMessage(message, args.outDouble);
448                         message.append("\n");
449                         message.append(errorMessage);
450                         message.append("Errors at");
451                     }
452                     message.append(" [");
453                     message.append(Integer.toString(i));
454                     message.append(", ");
455                     message.append(Integer.toString(j));
456                     message.append("]");
457                 }
458             }
459         }
460         assertFalse("Incorrect output for checkNativeExpm1Half2Half2" +
461                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
462     }
463 
checkNativeExpm1Half3Half3()464     private void checkNativeExpm1Half3Half3() {
465         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x3cbaff7bl, false);
466         try {
467             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
468             script.forEach_testNativeExpm1Half3Half3(inV, out);
469             verifyResultsNativeExpm1Half3Half3(inV, out, false);
470         } catch (Exception e) {
471             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Half3Half3: " + e.toString());
472         }
473         try {
474             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
475             scriptRelaxed.forEach_testNativeExpm1Half3Half3(inV, out);
476             verifyResultsNativeExpm1Half3Half3(inV, out, true);
477         } catch (Exception e) {
478             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Half3Half3: " + e.toString());
479         }
480     }
481 
verifyResultsNativeExpm1Half3Half3(Allocation inV, Allocation out, boolean relaxed)482     private void verifyResultsNativeExpm1Half3Half3(Allocation inV, Allocation out, boolean relaxed) {
483         short[] arrayInV = new short[INPUTSIZE * 4];
484         Arrays.fill(arrayInV, (short) 42);
485         inV.copyTo(arrayInV);
486         short[] arrayOut = new short[INPUTSIZE * 4];
487         Arrays.fill(arrayOut, (short) 42);
488         out.copyTo(arrayOut);
489         StringBuilder message = new StringBuilder();
490         boolean errorFound = false;
491         for (int i = 0; i < INPUTSIZE; i++) {
492             for (int j = 0; j < 3 ; j++) {
493                 // Extract the inputs.
494                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
495                 args.inV = arrayInV[i * 4 + j];
496                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
497                 // Extract the outputs.
498                 args.out = arrayOut[i * 4 + j];
499                 args.outDouble = Float16Utils.convertFloat16ToDouble(args.out);
500                 // Ask the CoreMathVerifier to validate.
501                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
502                 String errorMessage = CoreMathVerifier.verifyNativeExpm1(args, target);
503                 boolean valid = errorMessage == null;
504                 if (!valid) {
505                     if (!errorFound) {
506                         errorFound = true;
507                         message.append("Input inV: ");
508                         appendVariableToMessage(message, args.inV);
509                         message.append("\n");
510                         message.append("Output out: ");
511                         appendVariableToMessage(message, args.out);
512                         message.append("\n");
513                         message.append("\n");
514                         message.append("Output out (in double): ");
515                         appendVariableToMessage(message, args.outDouble);
516                         message.append("\n");
517                         message.append(errorMessage);
518                         message.append("Errors at");
519                     }
520                     message.append(" [");
521                     message.append(Integer.toString(i));
522                     message.append(", ");
523                     message.append(Integer.toString(j));
524                     message.append("]");
525                 }
526             }
527         }
528         assertFalse("Incorrect output for checkNativeExpm1Half3Half3" +
529                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
530     }
531 
checkNativeExpm1Half4Half4()532     private void checkNativeExpm1Half4Half4() {
533         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x9bc2c46fl, false);
534         try {
535             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
536             script.forEach_testNativeExpm1Half4Half4(inV, out);
537             verifyResultsNativeExpm1Half4Half4(inV, out, false);
538         } catch (Exception e) {
539             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Half4Half4: " + e.toString());
540         }
541         try {
542             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
543             scriptRelaxed.forEach_testNativeExpm1Half4Half4(inV, out);
544             verifyResultsNativeExpm1Half4Half4(inV, out, true);
545         } catch (Exception e) {
546             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExpm1Half4Half4: " + e.toString());
547         }
548     }
549 
verifyResultsNativeExpm1Half4Half4(Allocation inV, Allocation out, boolean relaxed)550     private void verifyResultsNativeExpm1Half4Half4(Allocation inV, Allocation out, boolean relaxed) {
551         short[] arrayInV = new short[INPUTSIZE * 4];
552         Arrays.fill(arrayInV, (short) 42);
553         inV.copyTo(arrayInV);
554         short[] arrayOut = new short[INPUTSIZE * 4];
555         Arrays.fill(arrayOut, (short) 42);
556         out.copyTo(arrayOut);
557         StringBuilder message = new StringBuilder();
558         boolean errorFound = false;
559         for (int i = 0; i < INPUTSIZE; i++) {
560             for (int j = 0; j < 4 ; j++) {
561                 // Extract the inputs.
562                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
563                 args.inV = arrayInV[i * 4 + j];
564                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
565                 // Extract the outputs.
566                 args.out = arrayOut[i * 4 + j];
567                 args.outDouble = Float16Utils.convertFloat16ToDouble(args.out);
568                 // Ask the CoreMathVerifier to validate.
569                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
570                 String errorMessage = CoreMathVerifier.verifyNativeExpm1(args, target);
571                 boolean valid = errorMessage == null;
572                 if (!valid) {
573                     if (!errorFound) {
574                         errorFound = true;
575                         message.append("Input inV: ");
576                         appendVariableToMessage(message, args.inV);
577                         message.append("\n");
578                         message.append("Output out: ");
579                         appendVariableToMessage(message, args.out);
580                         message.append("\n");
581                         message.append("\n");
582                         message.append("Output out (in double): ");
583                         appendVariableToMessage(message, args.outDouble);
584                         message.append("\n");
585                         message.append(errorMessage);
586                         message.append("Errors at");
587                     }
588                     message.append(" [");
589                     message.append(Integer.toString(i));
590                     message.append(", ");
591                     message.append(Integer.toString(j));
592                     message.append("]");
593                 }
594             }
595         }
596         assertFalse("Incorrect output for checkNativeExpm1Half4Half4" +
597                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
598     }
599 
testNativeExpm1()600     public void testNativeExpm1() {
601         checkNativeExpm1FloatFloat();
602         checkNativeExpm1Float2Float2();
603         checkNativeExpm1Float3Float3();
604         checkNativeExpm1Float4Float4();
605         checkNativeExpm1HalfHalf();
606         checkNativeExpm1Half2Half2();
607         checkNativeExpm1Half3Half3();
608         checkNativeExpm1Half4Half4();
609     }
610 }
611