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 TestCosh extends RSBaseCompute {
29 
30     private ScriptC_TestCosh script;
31     private ScriptC_TestCoshRelaxed scriptRelaxed;
32 
33     @Override
setUp()34     protected void setUp() throws Exception {
35         super.setUp();
36         script = new ScriptC_TestCosh(mRS);
37         scriptRelaxed = new ScriptC_TestCoshRelaxed(mRS);
38     }
39 
40     public class ArgumentsFloatFloat {
41         public float inV;
42         public Target.Floaty out;
43     }
44 
checkCoshFloatFloat()45     private void checkCoshFloatFloat() {
46         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x108cfb40l, false);
47         try {
48             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
49             script.forEach_testCoshFloatFloat(inV, out);
50             verifyResultsCoshFloatFloat(inV, out, false);
51         } catch (Exception e) {
52             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshFloatFloat: " + e.toString());
53         }
54         try {
55             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
56             scriptRelaxed.forEach_testCoshFloatFloat(inV, out);
57             verifyResultsCoshFloatFloat(inV, out, true);
58         } catch (Exception e) {
59             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshFloatFloat: " + e.toString());
60         }
61     }
62 
verifyResultsCoshFloatFloat(Allocation inV, Allocation out, boolean relaxed)63     private void verifyResultsCoshFloatFloat(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.NORMAL, Target.ReturnType.FLOAT, relaxed);
79                 CoreMathVerifier.computeCosh(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 checkCoshFloatFloat" +
111                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
112     }
113 
checkCoshFloat2Float2()114     private void checkCoshFloat2Float2() {
115         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x4ebcf224l, false);
116         try {
117             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
118             script.forEach_testCoshFloat2Float2(inV, out);
119             verifyResultsCoshFloat2Float2(inV, out, false);
120         } catch (Exception e) {
121             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshFloat2Float2: " + e.toString());
122         }
123         try {
124             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
125             scriptRelaxed.forEach_testCoshFloat2Float2(inV, out);
126             verifyResultsCoshFloat2Float2(inV, out, true);
127         } catch (Exception e) {
128             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshFloat2Float2: " + e.toString());
129         }
130     }
131 
verifyResultsCoshFloat2Float2(Allocation inV, Allocation out, boolean relaxed)132     private void verifyResultsCoshFloat2Float2(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.NORMAL, Target.ReturnType.FLOAT, relaxed);
148                 CoreMathVerifier.computeCosh(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 checkCoshFloat2Float2" +
180                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
181     }
182 
checkCoshFloat3Float3()183     private void checkCoshFloat3Float3() {
184         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x44d81302l, false);
185         try {
186             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
187             script.forEach_testCoshFloat3Float3(inV, out);
188             verifyResultsCoshFloat3Float3(inV, out, false);
189         } catch (Exception e) {
190             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshFloat3Float3: " + e.toString());
191         }
192         try {
193             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
194             scriptRelaxed.forEach_testCoshFloat3Float3(inV, out);
195             verifyResultsCoshFloat3Float3(inV, out, true);
196         } catch (Exception e) {
197             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshFloat3Float3: " + e.toString());
198         }
199     }
200 
verifyResultsCoshFloat3Float3(Allocation inV, Allocation out, boolean relaxed)201     private void verifyResultsCoshFloat3Float3(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.NORMAL, Target.ReturnType.FLOAT, relaxed);
217                 CoreMathVerifier.computeCosh(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 checkCoshFloat3Float3" +
249                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
250     }
251 
checkCoshFloat4Float4()252     private void checkCoshFloat4Float4() {
253         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x3af333e0l, false);
254         try {
255             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
256             script.forEach_testCoshFloat4Float4(inV, out);
257             verifyResultsCoshFloat4Float4(inV, out, false);
258         } catch (Exception e) {
259             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshFloat4Float4: " + e.toString());
260         }
261         try {
262             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
263             scriptRelaxed.forEach_testCoshFloat4Float4(inV, out);
264             verifyResultsCoshFloat4Float4(inV, out, true);
265         } catch (Exception e) {
266             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshFloat4Float4: " + e.toString());
267         }
268     }
269 
verifyResultsCoshFloat4Float4(Allocation inV, Allocation out, boolean relaxed)270     private void verifyResultsCoshFloat4Float4(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.NORMAL, Target.ReturnType.FLOAT, relaxed);
286                 CoreMathVerifier.computeCosh(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 checkCoshFloat4Float4" +
318                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
319     }
320 
321     public class ArgumentsHalfHalf {
322         public short inV;
323         public double inVDouble;
324         public Target.Floaty out;
325     }
326 
checkCoshHalfHalf()327     private void checkCoshHalfHalf() {
328         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x609e2d2al, false);
329         try {
330             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
331             script.forEach_testCoshHalfHalf(inV, out);
332             verifyResultsCoshHalfHalf(inV, out, false);
333         } catch (Exception e) {
334             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshHalfHalf: " + e.toString());
335         }
336         try {
337             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
338             scriptRelaxed.forEach_testCoshHalfHalf(inV, out);
339             verifyResultsCoshHalfHalf(inV, out, true);
340         } catch (Exception e) {
341             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshHalfHalf: " + e.toString());
342         }
343     }
344 
verifyResultsCoshHalfHalf(Allocation inV, Allocation out, boolean relaxed)345     private void verifyResultsCoshHalfHalf(Allocation inV, Allocation out, boolean relaxed) {
346         short[] arrayInV = new short[INPUTSIZE * 1];
347         Arrays.fill(arrayInV, (short) 42);
348         inV.copyTo(arrayInV);
349         short[] arrayOut = new short[INPUTSIZE * 1];
350         Arrays.fill(arrayOut, (short) 42);
351         out.copyTo(arrayOut);
352         StringBuilder message = new StringBuilder();
353         boolean errorFound = false;
354         for (int i = 0; i < INPUTSIZE; i++) {
355             for (int j = 0; j < 1 ; j++) {
356                 // Extract the inputs.
357                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
358                 args.inV = arrayInV[i];
359                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
360                 // Figure out what the outputs should have been.
361                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
362                 CoreMathVerifier.computeCosh(args, target);
363                 // Validate the outputs.
364                 boolean valid = true;
365                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
366                     valid = false;
367                 }
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("Expected output out: ");
375                         appendVariableToMessage(message, args.out);
376                         message.append("\n");
377                         message.append("Actual   output out: ");
378                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
379                         message.append("\n");
380                         message.append("Actual   output out (in double): ");
381                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]));
382                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
383                             message.append(" FAIL");
384                         }
385                         message.append("\n");
386                         message.append("Errors at");
387                     }
388                     message.append(" [");
389                     message.append(Integer.toString(i));
390                     message.append(", ");
391                     message.append(Integer.toString(j));
392                     message.append("]");
393                 }
394             }
395         }
396         assertFalse("Incorrect output for checkCoshHalfHalf" +
397                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
398     }
399 
checkCoshHalf2Half2()400     private void checkCoshHalf2Half2() {
401         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x7dab427cl, false);
402         try {
403             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
404             script.forEach_testCoshHalf2Half2(inV, out);
405             verifyResultsCoshHalf2Half2(inV, out, false);
406         } catch (Exception e) {
407             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshHalf2Half2: " + e.toString());
408         }
409         try {
410             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
411             scriptRelaxed.forEach_testCoshHalf2Half2(inV, out);
412             verifyResultsCoshHalf2Half2(inV, out, true);
413         } catch (Exception e) {
414             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshHalf2Half2: " + e.toString());
415         }
416     }
417 
verifyResultsCoshHalf2Half2(Allocation inV, Allocation out, boolean relaxed)418     private void verifyResultsCoshHalf2Half2(Allocation inV, Allocation out, boolean relaxed) {
419         short[] arrayInV = new short[INPUTSIZE * 2];
420         Arrays.fill(arrayInV, (short) 42);
421         inV.copyTo(arrayInV);
422         short[] arrayOut = new short[INPUTSIZE * 2];
423         Arrays.fill(arrayOut, (short) 42);
424         out.copyTo(arrayOut);
425         StringBuilder message = new StringBuilder();
426         boolean errorFound = false;
427         for (int i = 0; i < INPUTSIZE; i++) {
428             for (int j = 0; j < 2 ; j++) {
429                 // Extract the inputs.
430                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
431                 args.inV = arrayInV[i * 2 + j];
432                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
433                 // Figure out what the outputs should have been.
434                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
435                 CoreMathVerifier.computeCosh(args, target);
436                 // Validate the outputs.
437                 boolean valid = true;
438                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
439                     valid = false;
440                 }
441                 if (!valid) {
442                     if (!errorFound) {
443                         errorFound = true;
444                         message.append("Input inV: ");
445                         appendVariableToMessage(message, args.inV);
446                         message.append("\n");
447                         message.append("Expected output out: ");
448                         appendVariableToMessage(message, args.out);
449                         message.append("\n");
450                         message.append("Actual   output out: ");
451                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
452                         message.append("\n");
453                         message.append("Actual   output out (in double): ");
454                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]));
455                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
456                             message.append(" FAIL");
457                         }
458                         message.append("\n");
459                         message.append("Errors at");
460                     }
461                     message.append(" [");
462                     message.append(Integer.toString(i));
463                     message.append(", ");
464                     message.append(Integer.toString(j));
465                     message.append("]");
466                 }
467             }
468         }
469         assertFalse("Incorrect output for checkCoshHalf2Half2" +
470                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
471     }
472 
checkCoshHalf3Half3()473     private void checkCoshHalf3Half3() {
474         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xdcb30770l, false);
475         try {
476             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
477             script.forEach_testCoshHalf3Half3(inV, out);
478             verifyResultsCoshHalf3Half3(inV, out, false);
479         } catch (Exception e) {
480             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshHalf3Half3: " + e.toString());
481         }
482         try {
483             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
484             scriptRelaxed.forEach_testCoshHalf3Half3(inV, out);
485             verifyResultsCoshHalf3Half3(inV, out, true);
486         } catch (Exception e) {
487             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshHalf3Half3: " + e.toString());
488         }
489     }
490 
verifyResultsCoshHalf3Half3(Allocation inV, Allocation out, boolean relaxed)491     private void verifyResultsCoshHalf3Half3(Allocation inV, Allocation out, boolean relaxed) {
492         short[] arrayInV = new short[INPUTSIZE * 4];
493         Arrays.fill(arrayInV, (short) 42);
494         inV.copyTo(arrayInV);
495         short[] arrayOut = new short[INPUTSIZE * 4];
496         Arrays.fill(arrayOut, (short) 42);
497         out.copyTo(arrayOut);
498         StringBuilder message = new StringBuilder();
499         boolean errorFound = false;
500         for (int i = 0; i < INPUTSIZE; i++) {
501             for (int j = 0; j < 3 ; j++) {
502                 // Extract the inputs.
503                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
504                 args.inV = arrayInV[i * 4 + j];
505                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
506                 // Figure out what the outputs should have been.
507                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
508                 CoreMathVerifier.computeCosh(args, target);
509                 // Validate the outputs.
510                 boolean valid = true;
511                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
512                     valid = false;
513                 }
514                 if (!valid) {
515                     if (!errorFound) {
516                         errorFound = true;
517                         message.append("Input inV: ");
518                         appendVariableToMessage(message, args.inV);
519                         message.append("\n");
520                         message.append("Expected output out: ");
521                         appendVariableToMessage(message, args.out);
522                         message.append("\n");
523                         message.append("Actual   output out: ");
524                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
525                         message.append("\n");
526                         message.append("Actual   output out (in double): ");
527                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
528                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
529                             message.append(" FAIL");
530                         }
531                         message.append("\n");
532                         message.append("Errors at");
533                     }
534                     message.append(" [");
535                     message.append(Integer.toString(i));
536                     message.append(", ");
537                     message.append(Integer.toString(j));
538                     message.append("]");
539                 }
540             }
541         }
542         assertFalse("Incorrect output for checkCoshHalf3Half3" +
543                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
544     }
545 
checkCoshHalf4Half4()546     private void checkCoshHalf4Half4() {
547         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x3bbacc64l, false);
548         try {
549             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
550             script.forEach_testCoshHalf4Half4(inV, out);
551             verifyResultsCoshHalf4Half4(inV, out, false);
552         } catch (Exception e) {
553             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshHalf4Half4: " + e.toString());
554         }
555         try {
556             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
557             scriptRelaxed.forEach_testCoshHalf4Half4(inV, out);
558             verifyResultsCoshHalf4Half4(inV, out, true);
559         } catch (Exception e) {
560             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCoshHalf4Half4: " + e.toString());
561         }
562     }
563 
verifyResultsCoshHalf4Half4(Allocation inV, Allocation out, boolean relaxed)564     private void verifyResultsCoshHalf4Half4(Allocation inV, Allocation out, boolean relaxed) {
565         short[] arrayInV = new short[INPUTSIZE * 4];
566         Arrays.fill(arrayInV, (short) 42);
567         inV.copyTo(arrayInV);
568         short[] arrayOut = new short[INPUTSIZE * 4];
569         Arrays.fill(arrayOut, (short) 42);
570         out.copyTo(arrayOut);
571         StringBuilder message = new StringBuilder();
572         boolean errorFound = false;
573         for (int i = 0; i < INPUTSIZE; i++) {
574             for (int j = 0; j < 4 ; j++) {
575                 // Extract the inputs.
576                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
577                 args.inV = arrayInV[i * 4 + j];
578                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
579                 // Figure out what the outputs should have been.
580                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
581                 CoreMathVerifier.computeCosh(args, target);
582                 // Validate the outputs.
583                 boolean valid = true;
584                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
585                     valid = false;
586                 }
587                 if (!valid) {
588                     if (!errorFound) {
589                         errorFound = true;
590                         message.append("Input inV: ");
591                         appendVariableToMessage(message, args.inV);
592                         message.append("\n");
593                         message.append("Expected output out: ");
594                         appendVariableToMessage(message, args.out);
595                         message.append("\n");
596                         message.append("Actual   output out: ");
597                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
598                         message.append("\n");
599                         message.append("Actual   output out (in double): ");
600                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
601                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
602                             message.append(" FAIL");
603                         }
604                         message.append("\n");
605                         message.append("Errors at");
606                     }
607                     message.append(" [");
608                     message.append(Integer.toString(i));
609                     message.append(", ");
610                     message.append(Integer.toString(j));
611                     message.append("]");
612                 }
613             }
614         }
615         assertFalse("Incorrect output for checkCoshHalf4Half4" +
616                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
617     }
618 
testCosh()619     public void testCosh() {
620         checkCoshFloatFloat();
621         checkCoshFloat2Float2();
622         checkCoshFloat3Float3();
623         checkCoshFloat4Float4();
624         checkCoshHalfHalf();
625         checkCoshHalf2Half2();
626         checkCoshHalf3Half3();
627         checkCoshHalf4Half4();
628     }
629 }
630