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