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 TestMax extends RSBaseCompute {
29 
30     private ScriptC_TestMax script;
31     private ScriptC_TestMaxRelaxed scriptRelaxed;
32 
33     @Override
setUp()34     protected void setUp() throws Exception {
35         super.setUp();
36         script = new ScriptC_TestMax(mRS);
37         scriptRelaxed = new ScriptC_TestMaxRelaxed(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 ArgumentsFloatFloatFloat {
48         public float inA;
49         public float inB;
50         public Target.Floaty out;
51     }
52 
checkMaxFloatFloatFloat()53     private void checkMaxFloatFloatFloat() {
54         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x2952d868c2162460l, false);
55         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x2952d868c2162461l, false);
56         try {
57             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
58             script.set_gAllocInB(inB);
59             script.forEach_testMaxFloatFloatFloat(inA, out);
60             verifyResultsMaxFloatFloatFloat(inA, inB, out, false);
61             out.destroy();
62         } catch (Exception e) {
63             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloatFloatFloat: " + e.toString());
64         }
65         try {
66             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
67             scriptRelaxed.set_gAllocInB(inB);
68             scriptRelaxed.forEach_testMaxFloatFloatFloat(inA, out);
69             verifyResultsMaxFloatFloatFloat(inA, inB, out, true);
70             out.destroy();
71         } catch (Exception e) {
72             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloatFloatFloat: " + e.toString());
73         }
74         inA.destroy();
75         inB.destroy();
76     }
77 
verifyResultsMaxFloatFloatFloat(Allocation inA, Allocation inB, Allocation out, boolean relaxed)78     private void verifyResultsMaxFloatFloatFloat(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
79         float[] arrayInA = new float[INPUTSIZE * 1];
80         Arrays.fill(arrayInA, (float) 42);
81         inA.copyTo(arrayInA);
82         float[] arrayInB = new float[INPUTSIZE * 1];
83         Arrays.fill(arrayInB, (float) 42);
84         inB.copyTo(arrayInB);
85         float[] arrayOut = new float[INPUTSIZE * 1];
86         Arrays.fill(arrayOut, (float) 42);
87         out.copyTo(arrayOut);
88         StringBuilder message = new StringBuilder();
89         boolean errorFound = false;
90         for (int i = 0; i < INPUTSIZE; i++) {
91             for (int j = 0; j < 1 ; j++) {
92                 // Extract the inputs.
93                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
94                 args.inA = arrayInA[i];
95                 args.inB = arrayInB[i];
96                 // Figure out what the outputs should have been.
97                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
98                 CoreMathVerifier.computeMax(args, target);
99                 // Validate the outputs.
100                 boolean valid = true;
101                 if (!args.out.couldBe(arrayOut[i * 1 + j])) {
102                     valid = false;
103                 }
104                 if (!valid) {
105                     if (!errorFound) {
106                         errorFound = true;
107                         message.append("Input inA: ");
108                         appendVariableToMessage(message, args.inA);
109                         message.append("\n");
110                         message.append("Input inB: ");
111                         appendVariableToMessage(message, args.inB);
112                         message.append("\n");
113                         message.append("Expected output out: ");
114                         appendVariableToMessage(message, args.out);
115                         message.append("\n");
116                         message.append("Actual   output out: ");
117                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
118                         if (!args.out.couldBe(arrayOut[i * 1 + j])) {
119                             message.append(" FAIL");
120                         }
121                         message.append("\n");
122                         message.append("Errors at");
123                     }
124                     message.append(" [");
125                     message.append(Integer.toString(i));
126                     message.append(", ");
127                     message.append(Integer.toString(j));
128                     message.append("]");
129                 }
130             }
131         }
132         assertFalse("Incorrect output for checkMaxFloatFloatFloat" +
133                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
134     }
135 
checkMaxFloat2Float2Float2()136     private void checkMaxFloat2Float2Float2() {
137         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xc6031e7536addadal, false);
138         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xc6031e7536addadbl, false);
139         try {
140             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
141             script.set_gAllocInB(inB);
142             script.forEach_testMaxFloat2Float2Float2(inA, out);
143             verifyResultsMaxFloat2Float2Float2(inA, inB, out, false);
144             out.destroy();
145         } catch (Exception e) {
146             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat2Float2Float2: " + e.toString());
147         }
148         try {
149             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
150             scriptRelaxed.set_gAllocInB(inB);
151             scriptRelaxed.forEach_testMaxFloat2Float2Float2(inA, out);
152             verifyResultsMaxFloat2Float2Float2(inA, inB, out, true);
153             out.destroy();
154         } catch (Exception e) {
155             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat2Float2Float2: " + e.toString());
156         }
157         inA.destroy();
158         inB.destroy();
159     }
160 
verifyResultsMaxFloat2Float2Float2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)161     private void verifyResultsMaxFloat2Float2Float2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
162         float[] arrayInA = new float[INPUTSIZE * 2];
163         Arrays.fill(arrayInA, (float) 42);
164         inA.copyTo(arrayInA);
165         float[] arrayInB = new float[INPUTSIZE * 2];
166         Arrays.fill(arrayInB, (float) 42);
167         inB.copyTo(arrayInB);
168         float[] arrayOut = new float[INPUTSIZE * 2];
169         Arrays.fill(arrayOut, (float) 42);
170         out.copyTo(arrayOut);
171         StringBuilder message = new StringBuilder();
172         boolean errorFound = false;
173         for (int i = 0; i < INPUTSIZE; i++) {
174             for (int j = 0; j < 2 ; j++) {
175                 // Extract the inputs.
176                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
177                 args.inA = arrayInA[i * 2 + j];
178                 args.inB = arrayInB[i * 2 + j];
179                 // Figure out what the outputs should have been.
180                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
181                 CoreMathVerifier.computeMax(args, target);
182                 // Validate the outputs.
183                 boolean valid = true;
184                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
185                     valid = false;
186                 }
187                 if (!valid) {
188                     if (!errorFound) {
189                         errorFound = true;
190                         message.append("Input inA: ");
191                         appendVariableToMessage(message, args.inA);
192                         message.append("\n");
193                         message.append("Input inB: ");
194                         appendVariableToMessage(message, args.inB);
195                         message.append("\n");
196                         message.append("Expected output out: ");
197                         appendVariableToMessage(message, args.out);
198                         message.append("\n");
199                         message.append("Actual   output out: ");
200                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
201                         if (!args.out.couldBe(arrayOut[i * 2 + j])) {
202                             message.append(" FAIL");
203                         }
204                         message.append("\n");
205                         message.append("Errors at");
206                     }
207                     message.append(" [");
208                     message.append(Integer.toString(i));
209                     message.append(", ");
210                     message.append(Integer.toString(j));
211                     message.append("]");
212                 }
213             }
214         }
215         assertFalse("Incorrect output for checkMaxFloat2Float2Float2" +
216                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
217     }
218 
checkMaxFloat3Float3Float3()219     private void checkMaxFloat3Float3Float3() {
220         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x1a67fc95388bdc7bl, false);
221         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x1a67fc95388bdc7cl, false);
222         try {
223             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
224             script.set_gAllocInB(inB);
225             script.forEach_testMaxFloat3Float3Float3(inA, out);
226             verifyResultsMaxFloat3Float3Float3(inA, inB, out, false);
227             out.destroy();
228         } catch (Exception e) {
229             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat3Float3Float3: " + e.toString());
230         }
231         try {
232             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
233             scriptRelaxed.set_gAllocInB(inB);
234             scriptRelaxed.forEach_testMaxFloat3Float3Float3(inA, out);
235             verifyResultsMaxFloat3Float3Float3(inA, inB, out, true);
236             out.destroy();
237         } catch (Exception e) {
238             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat3Float3Float3: " + e.toString());
239         }
240         inA.destroy();
241         inB.destroy();
242     }
243 
verifyResultsMaxFloat3Float3Float3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)244     private void verifyResultsMaxFloat3Float3Float3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
245         float[] arrayInA = new float[INPUTSIZE * 4];
246         Arrays.fill(arrayInA, (float) 42);
247         inA.copyTo(arrayInA);
248         float[] arrayInB = new float[INPUTSIZE * 4];
249         Arrays.fill(arrayInB, (float) 42);
250         inB.copyTo(arrayInB);
251         float[] arrayOut = new float[INPUTSIZE * 4];
252         Arrays.fill(arrayOut, (float) 42);
253         out.copyTo(arrayOut);
254         StringBuilder message = new StringBuilder();
255         boolean errorFound = false;
256         for (int i = 0; i < INPUTSIZE; i++) {
257             for (int j = 0; j < 3 ; j++) {
258                 // Extract the inputs.
259                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
260                 args.inA = arrayInA[i * 4 + j];
261                 args.inB = arrayInB[i * 4 + j];
262                 // Figure out what the outputs should have been.
263                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
264                 CoreMathVerifier.computeMax(args, target);
265                 // Validate the outputs.
266                 boolean valid = true;
267                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
268                     valid = false;
269                 }
270                 if (!valid) {
271                     if (!errorFound) {
272                         errorFound = true;
273                         message.append("Input inA: ");
274                         appendVariableToMessage(message, args.inA);
275                         message.append("\n");
276                         message.append("Input inB: ");
277                         appendVariableToMessage(message, args.inB);
278                         message.append("\n");
279                         message.append("Expected output out: ");
280                         appendVariableToMessage(message, args.out);
281                         message.append("\n");
282                         message.append("Actual   output out: ");
283                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
284                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
285                             message.append(" FAIL");
286                         }
287                         message.append("\n");
288                         message.append("Errors at");
289                     }
290                     message.append(" [");
291                     message.append(Integer.toString(i));
292                     message.append(", ");
293                     message.append(Integer.toString(j));
294                     message.append("]");
295                 }
296             }
297         }
298         assertFalse("Incorrect output for checkMaxFloat3Float3Float3" +
299                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
300     }
301 
checkMaxFloat4Float4Float4()302     private void checkMaxFloat4Float4Float4() {
303         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x6eccdab53a69de1cl, false);
304         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x6eccdab53a69de1dl, false);
305         try {
306             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
307             script.set_gAllocInB(inB);
308             script.forEach_testMaxFloat4Float4Float4(inA, out);
309             verifyResultsMaxFloat4Float4Float4(inA, inB, out, false);
310             out.destroy();
311         } catch (Exception e) {
312             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat4Float4Float4: " + e.toString());
313         }
314         try {
315             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
316             scriptRelaxed.set_gAllocInB(inB);
317             scriptRelaxed.forEach_testMaxFloat4Float4Float4(inA, out);
318             verifyResultsMaxFloat4Float4Float4(inA, inB, out, true);
319             out.destroy();
320         } catch (Exception e) {
321             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat4Float4Float4: " + e.toString());
322         }
323         inA.destroy();
324         inB.destroy();
325     }
326 
verifyResultsMaxFloat4Float4Float4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)327     private void verifyResultsMaxFloat4Float4Float4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
328         float[] arrayInA = new float[INPUTSIZE * 4];
329         Arrays.fill(arrayInA, (float) 42);
330         inA.copyTo(arrayInA);
331         float[] arrayInB = new float[INPUTSIZE * 4];
332         Arrays.fill(arrayInB, (float) 42);
333         inB.copyTo(arrayInB);
334         float[] arrayOut = new float[INPUTSIZE * 4];
335         Arrays.fill(arrayOut, (float) 42);
336         out.copyTo(arrayOut);
337         StringBuilder message = new StringBuilder();
338         boolean errorFound = false;
339         for (int i = 0; i < INPUTSIZE; i++) {
340             for (int j = 0; j < 4 ; j++) {
341                 // Extract the inputs.
342                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
343                 args.inA = arrayInA[i * 4 + j];
344                 args.inB = arrayInB[i * 4 + j];
345                 // Figure out what the outputs should have been.
346                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
347                 CoreMathVerifier.computeMax(args, target);
348                 // Validate the outputs.
349                 boolean valid = true;
350                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
351                     valid = false;
352                 }
353                 if (!valid) {
354                     if (!errorFound) {
355                         errorFound = true;
356                         message.append("Input inA: ");
357                         appendVariableToMessage(message, args.inA);
358                         message.append("\n");
359                         message.append("Input inB: ");
360                         appendVariableToMessage(message, args.inB);
361                         message.append("\n");
362                         message.append("Expected output out: ");
363                         appendVariableToMessage(message, args.out);
364                         message.append("\n");
365                         message.append("Actual   output out: ");
366                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
367                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
368                             message.append(" FAIL");
369                         }
370                         message.append("\n");
371                         message.append("Errors at");
372                     }
373                     message.append(" [");
374                     message.append(Integer.toString(i));
375                     message.append(", ");
376                     message.append(Integer.toString(j));
377                     message.append("]");
378                 }
379             }
380         }
381         assertFalse("Incorrect output for checkMaxFloat4Float4Float4" +
382                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
383     }
384 
385     public class ArgumentsHalfHalfHalf {
386         public short inA;
387         public double inADouble;
388         public short inB;
389         public double inBDouble;
390         public Target.Floaty out;
391     }
392 
checkMaxHalfHalfHalf()393     private void checkMaxHalfHalfHalf() {
394         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x3cd92a4ab6e25ddbl, false);
395         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x3cd92a4ab6e25ddcl, false);
396         try {
397             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
398             script.set_gAllocInB(inB);
399             script.forEach_testMaxHalfHalfHalf(inA, out);
400             verifyResultsMaxHalfHalfHalf(inA, inB, out, false);
401             out.destroy();
402         } catch (Exception e) {
403             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalfHalfHalf: " + e.toString());
404         }
405         try {
406             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
407             scriptRelaxed.set_gAllocInB(inB);
408             scriptRelaxed.forEach_testMaxHalfHalfHalf(inA, out);
409             verifyResultsMaxHalfHalfHalf(inA, inB, out, true);
410             out.destroy();
411         } catch (Exception e) {
412             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalfHalfHalf: " + e.toString());
413         }
414         inA.destroy();
415         inB.destroy();
416     }
417 
verifyResultsMaxHalfHalfHalf(Allocation inA, Allocation inB, Allocation out, boolean relaxed)418     private void verifyResultsMaxHalfHalfHalf(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
419         short[] arrayInA = new short[INPUTSIZE * 1];
420         Arrays.fill(arrayInA, (short) 42);
421         inA.copyTo(arrayInA);
422         short[] arrayInB = new short[INPUTSIZE * 1];
423         Arrays.fill(arrayInB, (short) 42);
424         inB.copyTo(arrayInB);
425         short[] arrayOut = new short[INPUTSIZE * 1];
426         Arrays.fill(arrayOut, (short) 42);
427         out.copyTo(arrayOut);
428         StringBuilder message = new StringBuilder();
429         boolean errorFound = false;
430         for (int i = 0; i < INPUTSIZE; i++) {
431             for (int j = 0; j < 1 ; j++) {
432                 // Extract the inputs.
433                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
434                 args.inA = arrayInA[i];
435                 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA);
436                 args.inB = arrayInB[i];
437                 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB);
438                 // Figure out what the outputs should have been.
439                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
440                 CoreMathVerifier.computeMax(args, target);
441                 // Validate the outputs.
442                 boolean valid = true;
443                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
444                     valid = false;
445                 }
446                 if (!valid) {
447                     if (!errorFound) {
448                         errorFound = true;
449                         message.append("Input inA: ");
450                         appendVariableToMessage(message, args.inA);
451                         message.append("\n");
452                         message.append("Input inB: ");
453                         appendVariableToMessage(message, args.inB);
454                         message.append("\n");
455                         message.append("Expected output out: ");
456                         appendVariableToMessage(message, args.out);
457                         message.append("\n");
458                         message.append("Actual   output out: ");
459                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
460                         message.append("\n");
461                         message.append("Actual   output out (in double): ");
462                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]));
463                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
464                             message.append(" FAIL");
465                         }
466                         message.append("\n");
467                         message.append("Errors at");
468                     }
469                     message.append(" [");
470                     message.append(Integer.toString(i));
471                     message.append(", ");
472                     message.append(Integer.toString(j));
473                     message.append("]");
474                 }
475             }
476         }
477         assertFalse("Incorrect output for checkMaxHalfHalfHalf" +
478                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
479     }
480 
checkMaxHalf2Half2Half2()481     private void checkMaxHalf2Half2Half2() {
482         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xf8c31a85f8fc6855l, false);
483         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xf8c31a85f8fc6856l, false);
484         try {
485             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
486             script.set_gAllocInB(inB);
487             script.forEach_testMaxHalf2Half2Half2(inA, out);
488             verifyResultsMaxHalf2Half2Half2(inA, inB, out, false);
489             out.destroy();
490         } catch (Exception e) {
491             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf2Half2Half2: " + e.toString());
492         }
493         try {
494             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
495             scriptRelaxed.set_gAllocInB(inB);
496             scriptRelaxed.forEach_testMaxHalf2Half2Half2(inA, out);
497             verifyResultsMaxHalf2Half2Half2(inA, inB, out, true);
498             out.destroy();
499         } catch (Exception e) {
500             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf2Half2Half2: " + e.toString());
501         }
502         inA.destroy();
503         inB.destroy();
504     }
505 
verifyResultsMaxHalf2Half2Half2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)506     private void verifyResultsMaxHalf2Half2Half2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
507         short[] arrayInA = new short[INPUTSIZE * 2];
508         Arrays.fill(arrayInA, (short) 42);
509         inA.copyTo(arrayInA);
510         short[] arrayInB = new short[INPUTSIZE * 2];
511         Arrays.fill(arrayInB, (short) 42);
512         inB.copyTo(arrayInB);
513         short[] arrayOut = new short[INPUTSIZE * 2];
514         Arrays.fill(arrayOut, (short) 42);
515         out.copyTo(arrayOut);
516         StringBuilder message = new StringBuilder();
517         boolean errorFound = false;
518         for (int i = 0; i < INPUTSIZE; i++) {
519             for (int j = 0; j < 2 ; j++) {
520                 // Extract the inputs.
521                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
522                 args.inA = arrayInA[i * 2 + j];
523                 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA);
524                 args.inB = arrayInB[i * 2 + j];
525                 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB);
526                 // Figure out what the outputs should have been.
527                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
528                 CoreMathVerifier.computeMax(args, target);
529                 // Validate the outputs.
530                 boolean valid = true;
531                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
532                     valid = false;
533                 }
534                 if (!valid) {
535                     if (!errorFound) {
536                         errorFound = true;
537                         message.append("Input inA: ");
538                         appendVariableToMessage(message, args.inA);
539                         message.append("\n");
540                         message.append("Input inB: ");
541                         appendVariableToMessage(message, args.inB);
542                         message.append("\n");
543                         message.append("Expected output out: ");
544                         appendVariableToMessage(message, args.out);
545                         message.append("\n");
546                         message.append("Actual   output out: ");
547                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
548                         message.append("\n");
549                         message.append("Actual   output out (in double): ");
550                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]));
551                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
552                             message.append(" FAIL");
553                         }
554                         message.append("\n");
555                         message.append("Errors at");
556                     }
557                     message.append(" [");
558                     message.append(Integer.toString(i));
559                     message.append(", ");
560                     message.append(Integer.toString(j));
561                     message.append("]");
562                 }
563             }
564         }
565         assertFalse("Incorrect output for checkMaxHalf2Half2Half2" +
566                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
567     }
568 
checkMaxHalf3Half3Half3()569     private void checkMaxHalf3Half3Half3() {
570         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x1e779a6f579b7924l, false);
571         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x1e779a6f579b7925l, false);
572         try {
573             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
574             script.set_gAllocInB(inB);
575             script.forEach_testMaxHalf3Half3Half3(inA, out);
576             verifyResultsMaxHalf3Half3Half3(inA, inB, out, false);
577             out.destroy();
578         } catch (Exception e) {
579             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf3Half3Half3: " + e.toString());
580         }
581         try {
582             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
583             scriptRelaxed.set_gAllocInB(inB);
584             scriptRelaxed.forEach_testMaxHalf3Half3Half3(inA, out);
585             verifyResultsMaxHalf3Half3Half3(inA, inB, out, true);
586             out.destroy();
587         } catch (Exception e) {
588             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf3Half3Half3: " + e.toString());
589         }
590         inA.destroy();
591         inB.destroy();
592     }
593 
verifyResultsMaxHalf3Half3Half3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)594     private void verifyResultsMaxHalf3Half3Half3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
595         short[] arrayInA = new short[INPUTSIZE * 4];
596         Arrays.fill(arrayInA, (short) 42);
597         inA.copyTo(arrayInA);
598         short[] arrayInB = new short[INPUTSIZE * 4];
599         Arrays.fill(arrayInB, (short) 42);
600         inB.copyTo(arrayInB);
601         short[] arrayOut = new short[INPUTSIZE * 4];
602         Arrays.fill(arrayOut, (short) 42);
603         out.copyTo(arrayOut);
604         StringBuilder message = new StringBuilder();
605         boolean errorFound = false;
606         for (int i = 0; i < INPUTSIZE; i++) {
607             for (int j = 0; j < 3 ; j++) {
608                 // Extract the inputs.
609                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
610                 args.inA = arrayInA[i * 4 + j];
611                 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA);
612                 args.inB = arrayInB[i * 4 + j];
613                 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB);
614                 // Figure out what the outputs should have been.
615                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
616                 CoreMathVerifier.computeMax(args, target);
617                 // Validate the outputs.
618                 boolean valid = true;
619                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
620                     valid = false;
621                 }
622                 if (!valid) {
623                     if (!errorFound) {
624                         errorFound = true;
625                         message.append("Input inA: ");
626                         appendVariableToMessage(message, args.inA);
627                         message.append("\n");
628                         message.append("Input inB: ");
629                         appendVariableToMessage(message, args.inB);
630                         message.append("\n");
631                         message.append("Expected output out: ");
632                         appendVariableToMessage(message, args.out);
633                         message.append("\n");
634                         message.append("Actual   output out: ");
635                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
636                         message.append("\n");
637                         message.append("Actual   output out (in double): ");
638                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
639                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
640                             message.append(" FAIL");
641                         }
642                         message.append("\n");
643                         message.append("Errors at");
644                     }
645                     message.append(" [");
646                     message.append(Integer.toString(i));
647                     message.append(", ");
648                     message.append(Integer.toString(j));
649                     message.append("]");
650                 }
651             }
652         }
653         assertFalse("Incorrect output for checkMaxHalf3Half3Half3" +
654                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
655     }
656 
checkMaxHalf4Half4Half4()657     private void checkMaxHalf4Half4Half4() {
658         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x442c1a58b63a89f3l, false);
659         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x442c1a58b63a89f4l, false);
660         try {
661             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
662             script.set_gAllocInB(inB);
663             script.forEach_testMaxHalf4Half4Half4(inA, out);
664             verifyResultsMaxHalf4Half4Half4(inA, inB, out, false);
665             out.destroy();
666         } catch (Exception e) {
667             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf4Half4Half4: " + e.toString());
668         }
669         try {
670             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
671             scriptRelaxed.set_gAllocInB(inB);
672             scriptRelaxed.forEach_testMaxHalf4Half4Half4(inA, out);
673             verifyResultsMaxHalf4Half4Half4(inA, inB, out, true);
674             out.destroy();
675         } catch (Exception e) {
676             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf4Half4Half4: " + e.toString());
677         }
678         inA.destroy();
679         inB.destroy();
680     }
681 
verifyResultsMaxHalf4Half4Half4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)682     private void verifyResultsMaxHalf4Half4Half4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
683         short[] arrayInA = new short[INPUTSIZE * 4];
684         Arrays.fill(arrayInA, (short) 42);
685         inA.copyTo(arrayInA);
686         short[] arrayInB = new short[INPUTSIZE * 4];
687         Arrays.fill(arrayInB, (short) 42);
688         inB.copyTo(arrayInB);
689         short[] arrayOut = new short[INPUTSIZE * 4];
690         Arrays.fill(arrayOut, (short) 42);
691         out.copyTo(arrayOut);
692         StringBuilder message = new StringBuilder();
693         boolean errorFound = false;
694         for (int i = 0; i < INPUTSIZE; i++) {
695             for (int j = 0; j < 4 ; j++) {
696                 // Extract the inputs.
697                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
698                 args.inA = arrayInA[i * 4 + j];
699                 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA);
700                 args.inB = arrayInB[i * 4 + j];
701                 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB);
702                 // Figure out what the outputs should have been.
703                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
704                 CoreMathVerifier.computeMax(args, target);
705                 // Validate the outputs.
706                 boolean valid = true;
707                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
708                     valid = false;
709                 }
710                 if (!valid) {
711                     if (!errorFound) {
712                         errorFound = true;
713                         message.append("Input inA: ");
714                         appendVariableToMessage(message, args.inA);
715                         message.append("\n");
716                         message.append("Input inB: ");
717                         appendVariableToMessage(message, args.inB);
718                         message.append("\n");
719                         message.append("Expected output out: ");
720                         appendVariableToMessage(message, args.out);
721                         message.append("\n");
722                         message.append("Actual   output out: ");
723                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
724                         message.append("\n");
725                         message.append("Actual   output out (in double): ");
726                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
727                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
728                             message.append(" FAIL");
729                         }
730                         message.append("\n");
731                         message.append("Errors at");
732                     }
733                     message.append(" [");
734                     message.append(Integer.toString(i));
735                     message.append(", ");
736                     message.append(Integer.toString(j));
737                     message.append("]");
738                 }
739             }
740         }
741         assertFalse("Incorrect output for checkMaxHalf4Half4Half4" +
742                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
743     }
744 
checkMaxFloat2FloatFloat2()745     private void checkMaxFloat2FloatFloat2() {
746         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x63dd380708592438l, false);
747         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x63dd380708592439l, false);
748         try {
749             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
750             script.set_gAllocInB(inB);
751             script.forEach_testMaxFloat2FloatFloat2(inA, out);
752             verifyResultsMaxFloat2FloatFloat2(inA, inB, out, false);
753             out.destroy();
754         } catch (Exception e) {
755             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat2FloatFloat2: " + e.toString());
756         }
757         try {
758             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
759             scriptRelaxed.set_gAllocInB(inB);
760             scriptRelaxed.forEach_testMaxFloat2FloatFloat2(inA, out);
761             verifyResultsMaxFloat2FloatFloat2(inA, inB, out, true);
762             out.destroy();
763         } catch (Exception e) {
764             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat2FloatFloat2: " + e.toString());
765         }
766         inA.destroy();
767         inB.destroy();
768     }
769 
verifyResultsMaxFloat2FloatFloat2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)770     private void verifyResultsMaxFloat2FloatFloat2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
771         float[] arrayInA = new float[INPUTSIZE * 2];
772         Arrays.fill(arrayInA, (float) 42);
773         inA.copyTo(arrayInA);
774         float[] arrayInB = new float[INPUTSIZE * 1];
775         Arrays.fill(arrayInB, (float) 42);
776         inB.copyTo(arrayInB);
777         float[] arrayOut = new float[INPUTSIZE * 2];
778         Arrays.fill(arrayOut, (float) 42);
779         out.copyTo(arrayOut);
780         StringBuilder message = new StringBuilder();
781         boolean errorFound = false;
782         for (int i = 0; i < INPUTSIZE; i++) {
783             for (int j = 0; j < 2 ; j++) {
784                 // Extract the inputs.
785                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
786                 args.inA = arrayInA[i * 2 + j];
787                 args.inB = arrayInB[i];
788                 // Figure out what the outputs should have been.
789                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
790                 CoreMathVerifier.computeMax(args, target);
791                 // Validate the outputs.
792                 boolean valid = true;
793                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
794                     valid = false;
795                 }
796                 if (!valid) {
797                     if (!errorFound) {
798                         errorFound = true;
799                         message.append("Input inA: ");
800                         appendVariableToMessage(message, args.inA);
801                         message.append("\n");
802                         message.append("Input inB: ");
803                         appendVariableToMessage(message, args.inB);
804                         message.append("\n");
805                         message.append("Expected output out: ");
806                         appendVariableToMessage(message, args.out);
807                         message.append("\n");
808                         message.append("Actual   output out: ");
809                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
810                         if (!args.out.couldBe(arrayOut[i * 2 + j])) {
811                             message.append(" FAIL");
812                         }
813                         message.append("\n");
814                         message.append("Errors at");
815                     }
816                     message.append(" [");
817                     message.append(Integer.toString(i));
818                     message.append(", ");
819                     message.append(Integer.toString(j));
820                     message.append("]");
821                 }
822             }
823         }
824         assertFalse("Incorrect output for checkMaxFloat2FloatFloat2" +
825                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
826     }
827 
checkMaxFloat3FloatFloat3()828     private void checkMaxFloat3FloatFloat3() {
829         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xb92ceb1ef6c41894l, false);
830         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xb92ceb1ef6c41895l, false);
831         try {
832             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
833             script.set_gAllocInB(inB);
834             script.forEach_testMaxFloat3FloatFloat3(inA, out);
835             verifyResultsMaxFloat3FloatFloat3(inA, inB, out, false);
836             out.destroy();
837         } catch (Exception e) {
838             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat3FloatFloat3: " + e.toString());
839         }
840         try {
841             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
842             scriptRelaxed.set_gAllocInB(inB);
843             scriptRelaxed.forEach_testMaxFloat3FloatFloat3(inA, out);
844             verifyResultsMaxFloat3FloatFloat3(inA, inB, out, true);
845             out.destroy();
846         } catch (Exception e) {
847             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat3FloatFloat3: " + e.toString());
848         }
849         inA.destroy();
850         inB.destroy();
851     }
852 
verifyResultsMaxFloat3FloatFloat3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)853     private void verifyResultsMaxFloat3FloatFloat3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
854         float[] arrayInA = new float[INPUTSIZE * 4];
855         Arrays.fill(arrayInA, (float) 42);
856         inA.copyTo(arrayInA);
857         float[] arrayInB = new float[INPUTSIZE * 1];
858         Arrays.fill(arrayInB, (float) 42);
859         inB.copyTo(arrayInB);
860         float[] arrayOut = new float[INPUTSIZE * 4];
861         Arrays.fill(arrayOut, (float) 42);
862         out.copyTo(arrayOut);
863         StringBuilder message = new StringBuilder();
864         boolean errorFound = false;
865         for (int i = 0; i < INPUTSIZE; i++) {
866             for (int j = 0; j < 3 ; j++) {
867                 // Extract the inputs.
868                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
869                 args.inA = arrayInA[i * 4 + j];
870                 args.inB = arrayInB[i];
871                 // Figure out what the outputs should have been.
872                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
873                 CoreMathVerifier.computeMax(args, target);
874                 // Validate the outputs.
875                 boolean valid = true;
876                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
877                     valid = false;
878                 }
879                 if (!valid) {
880                     if (!errorFound) {
881                         errorFound = true;
882                         message.append("Input inA: ");
883                         appendVariableToMessage(message, args.inA);
884                         message.append("\n");
885                         message.append("Input inB: ");
886                         appendVariableToMessage(message, args.inB);
887                         message.append("\n");
888                         message.append("Expected output out: ");
889                         appendVariableToMessage(message, args.out);
890                         message.append("\n");
891                         message.append("Actual   output out: ");
892                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
893                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
894                             message.append(" FAIL");
895                         }
896                         message.append("\n");
897                         message.append("Errors at");
898                     }
899                     message.append(" [");
900                     message.append(Integer.toString(i));
901                     message.append(", ");
902                     message.append(Integer.toString(j));
903                     message.append("]");
904                 }
905             }
906         }
907         assertFalse("Incorrect output for checkMaxFloat3FloatFloat3" +
908                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
909     }
910 
checkMaxFloat4FloatFloat4()911     private void checkMaxFloat4FloatFloat4() {
912         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xe7c9e36e52f0cf0l, false);
913         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xe7c9e36e52f0cf1l, false);
914         try {
915             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
916             script.set_gAllocInB(inB);
917             script.forEach_testMaxFloat4FloatFloat4(inA, out);
918             verifyResultsMaxFloat4FloatFloat4(inA, inB, out, false);
919             out.destroy();
920         } catch (Exception e) {
921             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat4FloatFloat4: " + e.toString());
922         }
923         try {
924             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
925             scriptRelaxed.set_gAllocInB(inB);
926             scriptRelaxed.forEach_testMaxFloat4FloatFloat4(inA, out);
927             verifyResultsMaxFloat4FloatFloat4(inA, inB, out, true);
928             out.destroy();
929         } catch (Exception e) {
930             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxFloat4FloatFloat4: " + e.toString());
931         }
932         inA.destroy();
933         inB.destroy();
934     }
935 
verifyResultsMaxFloat4FloatFloat4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)936     private void verifyResultsMaxFloat4FloatFloat4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
937         float[] arrayInA = new float[INPUTSIZE * 4];
938         Arrays.fill(arrayInA, (float) 42);
939         inA.copyTo(arrayInA);
940         float[] arrayInB = new float[INPUTSIZE * 1];
941         Arrays.fill(arrayInB, (float) 42);
942         inB.copyTo(arrayInB);
943         float[] arrayOut = new float[INPUTSIZE * 4];
944         Arrays.fill(arrayOut, (float) 42);
945         out.copyTo(arrayOut);
946         StringBuilder message = new StringBuilder();
947         boolean errorFound = false;
948         for (int i = 0; i < INPUTSIZE; i++) {
949             for (int j = 0; j < 4 ; j++) {
950                 // Extract the inputs.
951                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
952                 args.inA = arrayInA[i * 4 + j];
953                 args.inB = arrayInB[i];
954                 // Figure out what the outputs should have been.
955                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
956                 CoreMathVerifier.computeMax(args, target);
957                 // Validate the outputs.
958                 boolean valid = true;
959                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
960                     valid = false;
961                 }
962                 if (!valid) {
963                     if (!errorFound) {
964                         errorFound = true;
965                         message.append("Input inA: ");
966                         appendVariableToMessage(message, args.inA);
967                         message.append("\n");
968                         message.append("Input inB: ");
969                         appendVariableToMessage(message, args.inB);
970                         message.append("\n");
971                         message.append("Expected output out: ");
972                         appendVariableToMessage(message, args.out);
973                         message.append("\n");
974                         message.append("Actual   output out: ");
975                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
976                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
977                             message.append(" FAIL");
978                         }
979                         message.append("\n");
980                         message.append("Errors at");
981                     }
982                     message.append(" [");
983                     message.append(Integer.toString(i));
984                     message.append(", ");
985                     message.append(Integer.toString(j));
986                     message.append("]");
987                 }
988             }
989         }
990         assertFalse("Incorrect output for checkMaxFloat4FloatFloat4" +
991                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
992     }
993 
checkMaxHalf2HalfHalf2()994     private void checkMaxHalf2HalfHalf2() {
995         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x8eb729ebf5bbc96fl, false);
996         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x8eb729ebf5bbc970l, false);
997         try {
998             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
999             script.set_gAllocInB(inB);
1000             script.forEach_testMaxHalf2HalfHalf2(inA, out);
1001             verifyResultsMaxHalf2HalfHalf2(inA, inB, out, false);
1002             out.destroy();
1003         } catch (Exception e) {
1004             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf2HalfHalf2: " + e.toString());
1005         }
1006         try {
1007             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
1008             scriptRelaxed.set_gAllocInB(inB);
1009             scriptRelaxed.forEach_testMaxHalf2HalfHalf2(inA, out);
1010             verifyResultsMaxHalf2HalfHalf2(inA, inB, out, true);
1011             out.destroy();
1012         } catch (Exception e) {
1013             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf2HalfHalf2: " + e.toString());
1014         }
1015         inA.destroy();
1016         inB.destroy();
1017     }
1018 
verifyResultsMaxHalf2HalfHalf2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1019     private void verifyResultsMaxHalf2HalfHalf2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1020         short[] arrayInA = new short[INPUTSIZE * 2];
1021         Arrays.fill(arrayInA, (short) 42);
1022         inA.copyTo(arrayInA);
1023         short[] arrayInB = new short[INPUTSIZE * 1];
1024         Arrays.fill(arrayInB, (short) 42);
1025         inB.copyTo(arrayInB);
1026         short[] arrayOut = new short[INPUTSIZE * 2];
1027         Arrays.fill(arrayOut, (short) 42);
1028         out.copyTo(arrayOut);
1029         StringBuilder message = new StringBuilder();
1030         boolean errorFound = false;
1031         for (int i = 0; i < INPUTSIZE; i++) {
1032             for (int j = 0; j < 2 ; j++) {
1033                 // Extract the inputs.
1034                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
1035                 args.inA = arrayInA[i * 2 + j];
1036                 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA);
1037                 args.inB = arrayInB[i];
1038                 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB);
1039                 // Figure out what the outputs should have been.
1040                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
1041                 CoreMathVerifier.computeMax(args, target);
1042                 // Validate the outputs.
1043                 boolean valid = true;
1044                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
1045                     valid = false;
1046                 }
1047                 if (!valid) {
1048                     if (!errorFound) {
1049                         errorFound = true;
1050                         message.append("Input inA: ");
1051                         appendVariableToMessage(message, args.inA);
1052                         message.append("\n");
1053                         message.append("Input inB: ");
1054                         appendVariableToMessage(message, args.inB);
1055                         message.append("\n");
1056                         message.append("Expected output out: ");
1057                         appendVariableToMessage(message, args.out);
1058                         message.append("\n");
1059                         message.append("Actual   output out: ");
1060                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
1061                         message.append("\n");
1062                         message.append("Actual   output out (in double): ");
1063                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]));
1064                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
1065                             message.append(" FAIL");
1066                         }
1067                         message.append("\n");
1068                         message.append("Errors at");
1069                     }
1070                     message.append(" [");
1071                     message.append(Integer.toString(i));
1072                     message.append(", ");
1073                     message.append(Integer.toString(j));
1074                     message.append("]");
1075                 }
1076             }
1077         }
1078         assertFalse("Incorrect output for checkMaxHalf2HalfHalf2" +
1079                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1080     }
1081 
checkMaxHalf3HalfHalf3()1082     private void checkMaxHalf3HalfHalf3() {
1083         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xb9444a6aa8555b13l, false);
1084         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xb9444a6aa8555b14l, false);
1085         try {
1086             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
1087             script.set_gAllocInB(inB);
1088             script.forEach_testMaxHalf3HalfHalf3(inA, out);
1089             verifyResultsMaxHalf3HalfHalf3(inA, inB, out, false);
1090             out.destroy();
1091         } catch (Exception e) {
1092             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf3HalfHalf3: " + e.toString());
1093         }
1094         try {
1095             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
1096             scriptRelaxed.set_gAllocInB(inB);
1097             scriptRelaxed.forEach_testMaxHalf3HalfHalf3(inA, out);
1098             verifyResultsMaxHalf3HalfHalf3(inA, inB, out, true);
1099             out.destroy();
1100         } catch (Exception e) {
1101             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf3HalfHalf3: " + e.toString());
1102         }
1103         inA.destroy();
1104         inB.destroy();
1105     }
1106 
verifyResultsMaxHalf3HalfHalf3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1107     private void verifyResultsMaxHalf3HalfHalf3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1108         short[] arrayInA = new short[INPUTSIZE * 4];
1109         Arrays.fill(arrayInA, (short) 42);
1110         inA.copyTo(arrayInA);
1111         short[] arrayInB = new short[INPUTSIZE * 1];
1112         Arrays.fill(arrayInB, (short) 42);
1113         inB.copyTo(arrayInB);
1114         short[] arrayOut = new short[INPUTSIZE * 4];
1115         Arrays.fill(arrayOut, (short) 42);
1116         out.copyTo(arrayOut);
1117         StringBuilder message = new StringBuilder();
1118         boolean errorFound = false;
1119         for (int i = 0; i < INPUTSIZE; i++) {
1120             for (int j = 0; j < 3 ; j++) {
1121                 // Extract the inputs.
1122                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
1123                 args.inA = arrayInA[i * 4 + j];
1124                 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA);
1125                 args.inB = arrayInB[i];
1126                 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB);
1127                 // Figure out what the outputs should have been.
1128                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
1129                 CoreMathVerifier.computeMax(args, target);
1130                 // Validate the outputs.
1131                 boolean valid = true;
1132                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
1133                     valid = false;
1134                 }
1135                 if (!valid) {
1136                     if (!errorFound) {
1137                         errorFound = true;
1138                         message.append("Input inA: ");
1139                         appendVariableToMessage(message, args.inA);
1140                         message.append("\n");
1141                         message.append("Input inB: ");
1142                         appendVariableToMessage(message, args.inB);
1143                         message.append("\n");
1144                         message.append("Expected output out: ");
1145                         appendVariableToMessage(message, args.out);
1146                         message.append("\n");
1147                         message.append("Actual   output out: ");
1148                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1149                         message.append("\n");
1150                         message.append("Actual   output out (in double): ");
1151                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
1152                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
1153                             message.append(" FAIL");
1154                         }
1155                         message.append("\n");
1156                         message.append("Errors at");
1157                     }
1158                     message.append(" [");
1159                     message.append(Integer.toString(i));
1160                     message.append(", ");
1161                     message.append(Integer.toString(j));
1162                     message.append("]");
1163                 }
1164             }
1165         }
1166         assertFalse("Incorrect output for checkMaxHalf3HalfHalf3" +
1167                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1168     }
1169 
checkMaxHalf4HalfHalf4()1170     private void checkMaxHalf4HalfHalf4() {
1171         Allocation inA = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xe3d16ae95aeeecb7l, false);
1172         Allocation inB = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xe3d16ae95aeeecb8l, false);
1173         try {
1174             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
1175             script.set_gAllocInB(inB);
1176             script.forEach_testMaxHalf4HalfHalf4(inA, out);
1177             verifyResultsMaxHalf4HalfHalf4(inA, inB, out, false);
1178             out.destroy();
1179         } catch (Exception e) {
1180             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf4HalfHalf4: " + e.toString());
1181         }
1182         try {
1183             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
1184             scriptRelaxed.set_gAllocInB(inB);
1185             scriptRelaxed.forEach_testMaxHalf4HalfHalf4(inA, out);
1186             verifyResultsMaxHalf4HalfHalf4(inA, inB, out, true);
1187             out.destroy();
1188         } catch (Exception e) {
1189             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxHalf4HalfHalf4: " + e.toString());
1190         }
1191         inA.destroy();
1192         inB.destroy();
1193     }
1194 
verifyResultsMaxHalf4HalfHalf4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1195     private void verifyResultsMaxHalf4HalfHalf4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1196         short[] arrayInA = new short[INPUTSIZE * 4];
1197         Arrays.fill(arrayInA, (short) 42);
1198         inA.copyTo(arrayInA);
1199         short[] arrayInB = new short[INPUTSIZE * 1];
1200         Arrays.fill(arrayInB, (short) 42);
1201         inB.copyTo(arrayInB);
1202         short[] arrayOut = new short[INPUTSIZE * 4];
1203         Arrays.fill(arrayOut, (short) 42);
1204         out.copyTo(arrayOut);
1205         StringBuilder message = new StringBuilder();
1206         boolean errorFound = false;
1207         for (int i = 0; i < INPUTSIZE; i++) {
1208             for (int j = 0; j < 4 ; j++) {
1209                 // Extract the inputs.
1210                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
1211                 args.inA = arrayInA[i * 4 + j];
1212                 args.inADouble = Float16Utils.convertFloat16ToDouble(args.inA);
1213                 args.inB = arrayInB[i];
1214                 args.inBDouble = Float16Utils.convertFloat16ToDouble(args.inB);
1215                 // Figure out what the outputs should have been.
1216                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
1217                 CoreMathVerifier.computeMax(args, target);
1218                 // Validate the outputs.
1219                 boolean valid = true;
1220                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
1221                     valid = false;
1222                 }
1223                 if (!valid) {
1224                     if (!errorFound) {
1225                         errorFound = true;
1226                         message.append("Input inA: ");
1227                         appendVariableToMessage(message, args.inA);
1228                         message.append("\n");
1229                         message.append("Input inB: ");
1230                         appendVariableToMessage(message, args.inB);
1231                         message.append("\n");
1232                         message.append("Expected output out: ");
1233                         appendVariableToMessage(message, args.out);
1234                         message.append("\n");
1235                         message.append("Actual   output out: ");
1236                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1237                         message.append("\n");
1238                         message.append("Actual   output out (in double): ");
1239                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
1240                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
1241                             message.append(" FAIL");
1242                         }
1243                         message.append("\n");
1244                         message.append("Errors at");
1245                     }
1246                     message.append(" [");
1247                     message.append(Integer.toString(i));
1248                     message.append(", ");
1249                     message.append(Integer.toString(j));
1250                     message.append("]");
1251                 }
1252             }
1253         }
1254         assertFalse("Incorrect output for checkMaxHalf4HalfHalf4" +
1255                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1256     }
1257 
1258     public class ArgumentsCharCharChar {
1259         public byte inA;
1260         public byte inB;
1261         public byte out;
1262     }
1263 
checkMaxCharCharChar()1264     private void checkMaxCharCharChar() {
1265         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0x5f77cf3cb6405876l, false);
1266         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0x5f77cf3cb6405877l, false);
1267         try {
1268             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 1), INPUTSIZE);
1269             script.set_gAllocInB(inB);
1270             script.forEach_testMaxCharCharChar(inA, out);
1271             verifyResultsMaxCharCharChar(inA, inB, out, false);
1272             out.destroy();
1273         } catch (Exception e) {
1274             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxCharCharChar: " + e.toString());
1275         }
1276         try {
1277             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 1), INPUTSIZE);
1278             scriptRelaxed.set_gAllocInB(inB);
1279             scriptRelaxed.forEach_testMaxCharCharChar(inA, out);
1280             verifyResultsMaxCharCharChar(inA, inB, out, true);
1281             out.destroy();
1282         } catch (Exception e) {
1283             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxCharCharChar: " + e.toString());
1284         }
1285         inA.destroy();
1286         inB.destroy();
1287     }
1288 
verifyResultsMaxCharCharChar(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1289     private void verifyResultsMaxCharCharChar(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1290         byte[] arrayInA = new byte[INPUTSIZE * 1];
1291         Arrays.fill(arrayInA, (byte) 42);
1292         inA.copyTo(arrayInA);
1293         byte[] arrayInB = new byte[INPUTSIZE * 1];
1294         Arrays.fill(arrayInB, (byte) 42);
1295         inB.copyTo(arrayInB);
1296         byte[] arrayOut = new byte[INPUTSIZE * 1];
1297         Arrays.fill(arrayOut, (byte) 42);
1298         out.copyTo(arrayOut);
1299         StringBuilder message = new StringBuilder();
1300         boolean errorFound = false;
1301         for (int i = 0; i < INPUTSIZE; i++) {
1302             for (int j = 0; j < 1 ; j++) {
1303                 // Extract the inputs.
1304                 ArgumentsCharCharChar args = new ArgumentsCharCharChar();
1305                 args.inA = arrayInA[i];
1306                 args.inB = arrayInB[i];
1307                 // Figure out what the outputs should have been.
1308                 CoreMathVerifier.computeMax(args);
1309                 // Validate the outputs.
1310                 boolean valid = true;
1311                 if (args.out != arrayOut[i * 1 + j]) {
1312                     valid = false;
1313                 }
1314                 if (!valid) {
1315                     if (!errorFound) {
1316                         errorFound = true;
1317                         message.append("Input inA: ");
1318                         appendVariableToMessage(message, args.inA);
1319                         message.append("\n");
1320                         message.append("Input inB: ");
1321                         appendVariableToMessage(message, args.inB);
1322                         message.append("\n");
1323                         message.append("Expected output out: ");
1324                         appendVariableToMessage(message, args.out);
1325                         message.append("\n");
1326                         message.append("Actual   output out: ");
1327                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
1328                         if (args.out != arrayOut[i * 1 + j]) {
1329                             message.append(" FAIL");
1330                         }
1331                         message.append("\n");
1332                         message.append("Errors at");
1333                     }
1334                     message.append(" [");
1335                     message.append(Integer.toString(i));
1336                     message.append(", ");
1337                     message.append(Integer.toString(j));
1338                     message.append("]");
1339                 }
1340             }
1341         }
1342         assertFalse("Incorrect output for checkMaxCharCharChar" +
1343                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1344     }
1345 
checkMaxChar2Char2Char2()1346     private void checkMaxChar2Char2Char2() {
1347         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 2, 0x94dd090a19e42804l, false);
1348         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 2, 0x94dd090a19e42805l, false);
1349         try {
1350             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
1351             script.set_gAllocInB(inB);
1352             script.forEach_testMaxChar2Char2Char2(inA, out);
1353             verifyResultsMaxChar2Char2Char2(inA, inB, out, false);
1354             out.destroy();
1355         } catch (Exception e) {
1356             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxChar2Char2Char2: " + e.toString());
1357         }
1358         try {
1359             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
1360             scriptRelaxed.set_gAllocInB(inB);
1361             scriptRelaxed.forEach_testMaxChar2Char2Char2(inA, out);
1362             verifyResultsMaxChar2Char2Char2(inA, inB, out, true);
1363             out.destroy();
1364         } catch (Exception e) {
1365             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxChar2Char2Char2: " + e.toString());
1366         }
1367         inA.destroy();
1368         inB.destroy();
1369     }
1370 
verifyResultsMaxChar2Char2Char2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1371     private void verifyResultsMaxChar2Char2Char2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1372         byte[] arrayInA = new byte[INPUTSIZE * 2];
1373         Arrays.fill(arrayInA, (byte) 42);
1374         inA.copyTo(arrayInA);
1375         byte[] arrayInB = new byte[INPUTSIZE * 2];
1376         Arrays.fill(arrayInB, (byte) 42);
1377         inB.copyTo(arrayInB);
1378         byte[] arrayOut = new byte[INPUTSIZE * 2];
1379         Arrays.fill(arrayOut, (byte) 42);
1380         out.copyTo(arrayOut);
1381         StringBuilder message = new StringBuilder();
1382         boolean errorFound = false;
1383         for (int i = 0; i < INPUTSIZE; i++) {
1384             for (int j = 0; j < 2 ; j++) {
1385                 // Extract the inputs.
1386                 ArgumentsCharCharChar args = new ArgumentsCharCharChar();
1387                 args.inA = arrayInA[i * 2 + j];
1388                 args.inB = arrayInB[i * 2 + j];
1389                 // Figure out what the outputs should have been.
1390                 CoreMathVerifier.computeMax(args);
1391                 // Validate the outputs.
1392                 boolean valid = true;
1393                 if (args.out != arrayOut[i * 2 + j]) {
1394                     valid = false;
1395                 }
1396                 if (!valid) {
1397                     if (!errorFound) {
1398                         errorFound = true;
1399                         message.append("Input inA: ");
1400                         appendVariableToMessage(message, args.inA);
1401                         message.append("\n");
1402                         message.append("Input inB: ");
1403                         appendVariableToMessage(message, args.inB);
1404                         message.append("\n");
1405                         message.append("Expected output out: ");
1406                         appendVariableToMessage(message, args.out);
1407                         message.append("\n");
1408                         message.append("Actual   output out: ");
1409                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
1410                         if (args.out != arrayOut[i * 2 + j]) {
1411                             message.append(" FAIL");
1412                         }
1413                         message.append("\n");
1414                         message.append("Errors at");
1415                     }
1416                     message.append(" [");
1417                     message.append(Integer.toString(i));
1418                     message.append(", ");
1419                     message.append(Integer.toString(j));
1420                     message.append("]");
1421                 }
1422             }
1423         }
1424         assertFalse("Incorrect output for checkMaxChar2Char2Char2" +
1425                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1426     }
1427 
checkMaxChar3Char3Char3()1428     private void checkMaxChar3Char3Char3() {
1429         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 3, 0xba9188f3788338d3l, false);
1430         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 3, 0xba9188f3788338d4l, false);
1431         try {
1432             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
1433             script.set_gAllocInB(inB);
1434             script.forEach_testMaxChar3Char3Char3(inA, out);
1435             verifyResultsMaxChar3Char3Char3(inA, inB, out, false);
1436             out.destroy();
1437         } catch (Exception e) {
1438             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxChar3Char3Char3: " + e.toString());
1439         }
1440         try {
1441             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
1442             scriptRelaxed.set_gAllocInB(inB);
1443             scriptRelaxed.forEach_testMaxChar3Char3Char3(inA, out);
1444             verifyResultsMaxChar3Char3Char3(inA, inB, out, true);
1445             out.destroy();
1446         } catch (Exception e) {
1447             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxChar3Char3Char3: " + e.toString());
1448         }
1449         inA.destroy();
1450         inB.destroy();
1451     }
1452 
verifyResultsMaxChar3Char3Char3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1453     private void verifyResultsMaxChar3Char3Char3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1454         byte[] arrayInA = new byte[INPUTSIZE * 4];
1455         Arrays.fill(arrayInA, (byte) 42);
1456         inA.copyTo(arrayInA);
1457         byte[] arrayInB = new byte[INPUTSIZE * 4];
1458         Arrays.fill(arrayInB, (byte) 42);
1459         inB.copyTo(arrayInB);
1460         byte[] arrayOut = new byte[INPUTSIZE * 4];
1461         Arrays.fill(arrayOut, (byte) 42);
1462         out.copyTo(arrayOut);
1463         StringBuilder message = new StringBuilder();
1464         boolean errorFound = false;
1465         for (int i = 0; i < INPUTSIZE; i++) {
1466             for (int j = 0; j < 3 ; j++) {
1467                 // Extract the inputs.
1468                 ArgumentsCharCharChar args = new ArgumentsCharCharChar();
1469                 args.inA = arrayInA[i * 4 + j];
1470                 args.inB = arrayInB[i * 4 + j];
1471                 // Figure out what the outputs should have been.
1472                 CoreMathVerifier.computeMax(args);
1473                 // Validate the outputs.
1474                 boolean valid = true;
1475                 if (args.out != arrayOut[i * 4 + j]) {
1476                     valid = false;
1477                 }
1478                 if (!valid) {
1479                     if (!errorFound) {
1480                         errorFound = true;
1481                         message.append("Input inA: ");
1482                         appendVariableToMessage(message, args.inA);
1483                         message.append("\n");
1484                         message.append("Input inB: ");
1485                         appendVariableToMessage(message, args.inB);
1486                         message.append("\n");
1487                         message.append("Expected output out: ");
1488                         appendVariableToMessage(message, args.out);
1489                         message.append("\n");
1490                         message.append("Actual   output out: ");
1491                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1492                         if (args.out != arrayOut[i * 4 + j]) {
1493                             message.append(" FAIL");
1494                         }
1495                         message.append("\n");
1496                         message.append("Errors at");
1497                     }
1498                     message.append(" [");
1499                     message.append(Integer.toString(i));
1500                     message.append(", ");
1501                     message.append(Integer.toString(j));
1502                     message.append("]");
1503                 }
1504             }
1505         }
1506         assertFalse("Incorrect output for checkMaxChar3Char3Char3" +
1507                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1508     }
1509 
checkMaxChar4Char4Char4()1510     private void checkMaxChar4Char4Char4() {
1511         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 4, 0xe04608dcd72249a2l, false);
1512         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 4, 0xe04608dcd72249a3l, false);
1513         try {
1514             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
1515             script.set_gAllocInB(inB);
1516             script.forEach_testMaxChar4Char4Char4(inA, out);
1517             verifyResultsMaxChar4Char4Char4(inA, inB, out, false);
1518             out.destroy();
1519         } catch (Exception e) {
1520             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxChar4Char4Char4: " + e.toString());
1521         }
1522         try {
1523             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
1524             scriptRelaxed.set_gAllocInB(inB);
1525             scriptRelaxed.forEach_testMaxChar4Char4Char4(inA, out);
1526             verifyResultsMaxChar4Char4Char4(inA, inB, out, true);
1527             out.destroy();
1528         } catch (Exception e) {
1529             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxChar4Char4Char4: " + e.toString());
1530         }
1531         inA.destroy();
1532         inB.destroy();
1533     }
1534 
verifyResultsMaxChar4Char4Char4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1535     private void verifyResultsMaxChar4Char4Char4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1536         byte[] arrayInA = new byte[INPUTSIZE * 4];
1537         Arrays.fill(arrayInA, (byte) 42);
1538         inA.copyTo(arrayInA);
1539         byte[] arrayInB = new byte[INPUTSIZE * 4];
1540         Arrays.fill(arrayInB, (byte) 42);
1541         inB.copyTo(arrayInB);
1542         byte[] arrayOut = new byte[INPUTSIZE * 4];
1543         Arrays.fill(arrayOut, (byte) 42);
1544         out.copyTo(arrayOut);
1545         StringBuilder message = new StringBuilder();
1546         boolean errorFound = false;
1547         for (int i = 0; i < INPUTSIZE; i++) {
1548             for (int j = 0; j < 4 ; j++) {
1549                 // Extract the inputs.
1550                 ArgumentsCharCharChar args = new ArgumentsCharCharChar();
1551                 args.inA = arrayInA[i * 4 + j];
1552                 args.inB = arrayInB[i * 4 + j];
1553                 // Figure out what the outputs should have been.
1554                 CoreMathVerifier.computeMax(args);
1555                 // Validate the outputs.
1556                 boolean valid = true;
1557                 if (args.out != arrayOut[i * 4 + j]) {
1558                     valid = false;
1559                 }
1560                 if (!valid) {
1561                     if (!errorFound) {
1562                         errorFound = true;
1563                         message.append("Input inA: ");
1564                         appendVariableToMessage(message, args.inA);
1565                         message.append("\n");
1566                         message.append("Input inB: ");
1567                         appendVariableToMessage(message, args.inB);
1568                         message.append("\n");
1569                         message.append("Expected output out: ");
1570                         appendVariableToMessage(message, args.out);
1571                         message.append("\n");
1572                         message.append("Actual   output out: ");
1573                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1574                         if (args.out != arrayOut[i * 4 + j]) {
1575                             message.append(" FAIL");
1576                         }
1577                         message.append("\n");
1578                         message.append("Errors at");
1579                     }
1580                     message.append(" [");
1581                     message.append(Integer.toString(i));
1582                     message.append(", ");
1583                     message.append(Integer.toString(j));
1584                     message.append("]");
1585                 }
1586             }
1587         }
1588         assertFalse("Incorrect output for checkMaxChar4Char4Char4" +
1589                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1590     }
1591 
1592     public class ArgumentsUcharUcharUchar {
1593         public byte inA;
1594         public byte inB;
1595         public byte out;
1596     }
1597 
checkMaxUcharUcharUchar()1598     private void checkMaxUcharUcharUchar() {
1599         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0x800f9948853a162dl, false);
1600         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0x800f9948853a162el, false);
1601         try {
1602             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE);
1603             script.set_gAllocInB(inB);
1604             script.forEach_testMaxUcharUcharUchar(inA, out);
1605             verifyResultsMaxUcharUcharUchar(inA, inB, out, false);
1606             out.destroy();
1607         } catch (Exception e) {
1608             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUcharUcharUchar: " + e.toString());
1609         }
1610         try {
1611             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE);
1612             scriptRelaxed.set_gAllocInB(inB);
1613             scriptRelaxed.forEach_testMaxUcharUcharUchar(inA, out);
1614             verifyResultsMaxUcharUcharUchar(inA, inB, out, true);
1615             out.destroy();
1616         } catch (Exception e) {
1617             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUcharUcharUchar: " + e.toString());
1618         }
1619         inA.destroy();
1620         inB.destroy();
1621     }
1622 
verifyResultsMaxUcharUcharUchar(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1623     private void verifyResultsMaxUcharUcharUchar(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1624         byte[] arrayInA = new byte[INPUTSIZE * 1];
1625         Arrays.fill(arrayInA, (byte) 42);
1626         inA.copyTo(arrayInA);
1627         byte[] arrayInB = new byte[INPUTSIZE * 1];
1628         Arrays.fill(arrayInB, (byte) 42);
1629         inB.copyTo(arrayInB);
1630         byte[] arrayOut = new byte[INPUTSIZE * 1];
1631         Arrays.fill(arrayOut, (byte) 42);
1632         out.copyTo(arrayOut);
1633         StringBuilder message = new StringBuilder();
1634         boolean errorFound = false;
1635         for (int i = 0; i < INPUTSIZE; i++) {
1636             for (int j = 0; j < 1 ; j++) {
1637                 // Extract the inputs.
1638                 ArgumentsUcharUcharUchar args = new ArgumentsUcharUcharUchar();
1639                 args.inA = arrayInA[i];
1640                 args.inB = arrayInB[i];
1641                 // Figure out what the outputs should have been.
1642                 CoreMathVerifier.computeMax(args);
1643                 // Validate the outputs.
1644                 boolean valid = true;
1645                 if (args.out != arrayOut[i * 1 + j]) {
1646                     valid = false;
1647                 }
1648                 if (!valid) {
1649                     if (!errorFound) {
1650                         errorFound = true;
1651                         message.append("Input inA: ");
1652                         appendVariableToMessage(message, args.inA);
1653                         message.append("\n");
1654                         message.append("Input inB: ");
1655                         appendVariableToMessage(message, args.inB);
1656                         message.append("\n");
1657                         message.append("Expected output out: ");
1658                         appendVariableToMessage(message, args.out);
1659                         message.append("\n");
1660                         message.append("Actual   output out: ");
1661                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
1662                         if (args.out != arrayOut[i * 1 + j]) {
1663                             message.append(" FAIL");
1664                         }
1665                         message.append("\n");
1666                         message.append("Errors at");
1667                     }
1668                     message.append(" [");
1669                     message.append(Integer.toString(i));
1670                     message.append(", ");
1671                     message.append(Integer.toString(j));
1672                     message.append("]");
1673                 }
1674             }
1675         }
1676         assertFalse("Incorrect output for checkMaxUcharUcharUchar" +
1677                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1678     }
1679 
checkMaxUchar2Uchar2Uchar2()1680     private void checkMaxUchar2Uchar2Uchar2() {
1681         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0xd31d5735b7e9a9dbl, false);
1682         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0xd31d5735b7e9a9dcl, false);
1683         try {
1684             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
1685             script.set_gAllocInB(inB);
1686             script.forEach_testMaxUchar2Uchar2Uchar2(inA, out);
1687             verifyResultsMaxUchar2Uchar2Uchar2(inA, inB, out, false);
1688             out.destroy();
1689         } catch (Exception e) {
1690             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUchar2Uchar2Uchar2: " + e.toString());
1691         }
1692         try {
1693             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
1694             scriptRelaxed.set_gAllocInB(inB);
1695             scriptRelaxed.forEach_testMaxUchar2Uchar2Uchar2(inA, out);
1696             verifyResultsMaxUchar2Uchar2Uchar2(inA, inB, out, true);
1697             out.destroy();
1698         } catch (Exception e) {
1699             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUchar2Uchar2Uchar2: " + e.toString());
1700         }
1701         inA.destroy();
1702         inB.destroy();
1703     }
1704 
verifyResultsMaxUchar2Uchar2Uchar2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1705     private void verifyResultsMaxUchar2Uchar2Uchar2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1706         byte[] arrayInA = new byte[INPUTSIZE * 2];
1707         Arrays.fill(arrayInA, (byte) 42);
1708         inA.copyTo(arrayInA);
1709         byte[] arrayInB = new byte[INPUTSIZE * 2];
1710         Arrays.fill(arrayInB, (byte) 42);
1711         inB.copyTo(arrayInB);
1712         byte[] arrayOut = new byte[INPUTSIZE * 2];
1713         Arrays.fill(arrayOut, (byte) 42);
1714         out.copyTo(arrayOut);
1715         StringBuilder message = new StringBuilder();
1716         boolean errorFound = false;
1717         for (int i = 0; i < INPUTSIZE; i++) {
1718             for (int j = 0; j < 2 ; j++) {
1719                 // Extract the inputs.
1720                 ArgumentsUcharUcharUchar args = new ArgumentsUcharUcharUchar();
1721                 args.inA = arrayInA[i * 2 + j];
1722                 args.inB = arrayInB[i * 2 + j];
1723                 // Figure out what the outputs should have been.
1724                 CoreMathVerifier.computeMax(args);
1725                 // Validate the outputs.
1726                 boolean valid = true;
1727                 if (args.out != arrayOut[i * 2 + j]) {
1728                     valid = false;
1729                 }
1730                 if (!valid) {
1731                     if (!errorFound) {
1732                         errorFound = true;
1733                         message.append("Input inA: ");
1734                         appendVariableToMessage(message, args.inA);
1735                         message.append("\n");
1736                         message.append("Input inB: ");
1737                         appendVariableToMessage(message, args.inB);
1738                         message.append("\n");
1739                         message.append("Expected output out: ");
1740                         appendVariableToMessage(message, args.out);
1741                         message.append("\n");
1742                         message.append("Actual   output out: ");
1743                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
1744                         if (args.out != arrayOut[i * 2 + j]) {
1745                             message.append(" FAIL");
1746                         }
1747                         message.append("\n");
1748                         message.append("Errors at");
1749                     }
1750                     message.append(" [");
1751                     message.append(Integer.toString(i));
1752                     message.append(", ");
1753                     message.append(Integer.toString(j));
1754                     message.append("]");
1755                 }
1756             }
1757         }
1758         assertFalse("Incorrect output for checkMaxUchar2Uchar2Uchar2" +
1759                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1760     }
1761 
checkMaxUchar3Uchar3Uchar3()1762     private void checkMaxUchar3Uchar3Uchar3() {
1763         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x27823555b9c7ab7cl, false);
1764         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x27823555b9c7ab7dl, false);
1765         try {
1766             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
1767             script.set_gAllocInB(inB);
1768             script.forEach_testMaxUchar3Uchar3Uchar3(inA, out);
1769             verifyResultsMaxUchar3Uchar3Uchar3(inA, inB, out, false);
1770             out.destroy();
1771         } catch (Exception e) {
1772             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUchar3Uchar3Uchar3: " + e.toString());
1773         }
1774         try {
1775             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
1776             scriptRelaxed.set_gAllocInB(inB);
1777             scriptRelaxed.forEach_testMaxUchar3Uchar3Uchar3(inA, out);
1778             verifyResultsMaxUchar3Uchar3Uchar3(inA, inB, out, true);
1779             out.destroy();
1780         } catch (Exception e) {
1781             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUchar3Uchar3Uchar3: " + e.toString());
1782         }
1783         inA.destroy();
1784         inB.destroy();
1785     }
1786 
verifyResultsMaxUchar3Uchar3Uchar3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1787     private void verifyResultsMaxUchar3Uchar3Uchar3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1788         byte[] arrayInA = new byte[INPUTSIZE * 4];
1789         Arrays.fill(arrayInA, (byte) 42);
1790         inA.copyTo(arrayInA);
1791         byte[] arrayInB = new byte[INPUTSIZE * 4];
1792         Arrays.fill(arrayInB, (byte) 42);
1793         inB.copyTo(arrayInB);
1794         byte[] arrayOut = new byte[INPUTSIZE * 4];
1795         Arrays.fill(arrayOut, (byte) 42);
1796         out.copyTo(arrayOut);
1797         StringBuilder message = new StringBuilder();
1798         boolean errorFound = false;
1799         for (int i = 0; i < INPUTSIZE; i++) {
1800             for (int j = 0; j < 3 ; j++) {
1801                 // Extract the inputs.
1802                 ArgumentsUcharUcharUchar args = new ArgumentsUcharUcharUchar();
1803                 args.inA = arrayInA[i * 4 + j];
1804                 args.inB = arrayInB[i * 4 + j];
1805                 // Figure out what the outputs should have been.
1806                 CoreMathVerifier.computeMax(args);
1807                 // Validate the outputs.
1808                 boolean valid = true;
1809                 if (args.out != arrayOut[i * 4 + j]) {
1810                     valid = false;
1811                 }
1812                 if (!valid) {
1813                     if (!errorFound) {
1814                         errorFound = true;
1815                         message.append("Input inA: ");
1816                         appendVariableToMessage(message, args.inA);
1817                         message.append("\n");
1818                         message.append("Input inB: ");
1819                         appendVariableToMessage(message, args.inB);
1820                         message.append("\n");
1821                         message.append("Expected output out: ");
1822                         appendVariableToMessage(message, args.out);
1823                         message.append("\n");
1824                         message.append("Actual   output out: ");
1825                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1826                         if (args.out != arrayOut[i * 4 + j]) {
1827                             message.append(" FAIL");
1828                         }
1829                         message.append("\n");
1830                         message.append("Errors at");
1831                     }
1832                     message.append(" [");
1833                     message.append(Integer.toString(i));
1834                     message.append(", ");
1835                     message.append(Integer.toString(j));
1836                     message.append("]");
1837                 }
1838             }
1839         }
1840         assertFalse("Incorrect output for checkMaxUchar3Uchar3Uchar3" +
1841                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1842     }
1843 
checkMaxUchar4Uchar4Uchar4()1844     private void checkMaxUchar4Uchar4Uchar4() {
1845         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x7be71375bba5ad1dl, false);
1846         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x7be71375bba5ad1el, false);
1847         try {
1848             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
1849             script.set_gAllocInB(inB);
1850             script.forEach_testMaxUchar4Uchar4Uchar4(inA, out);
1851             verifyResultsMaxUchar4Uchar4Uchar4(inA, inB, out, false);
1852             out.destroy();
1853         } catch (Exception e) {
1854             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUchar4Uchar4Uchar4: " + e.toString());
1855         }
1856         try {
1857             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
1858             scriptRelaxed.set_gAllocInB(inB);
1859             scriptRelaxed.forEach_testMaxUchar4Uchar4Uchar4(inA, out);
1860             verifyResultsMaxUchar4Uchar4Uchar4(inA, inB, out, true);
1861             out.destroy();
1862         } catch (Exception e) {
1863             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUchar4Uchar4Uchar4: " + e.toString());
1864         }
1865         inA.destroy();
1866         inB.destroy();
1867     }
1868 
verifyResultsMaxUchar4Uchar4Uchar4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1869     private void verifyResultsMaxUchar4Uchar4Uchar4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1870         byte[] arrayInA = new byte[INPUTSIZE * 4];
1871         Arrays.fill(arrayInA, (byte) 42);
1872         inA.copyTo(arrayInA);
1873         byte[] arrayInB = new byte[INPUTSIZE * 4];
1874         Arrays.fill(arrayInB, (byte) 42);
1875         inB.copyTo(arrayInB);
1876         byte[] arrayOut = new byte[INPUTSIZE * 4];
1877         Arrays.fill(arrayOut, (byte) 42);
1878         out.copyTo(arrayOut);
1879         StringBuilder message = new StringBuilder();
1880         boolean errorFound = false;
1881         for (int i = 0; i < INPUTSIZE; i++) {
1882             for (int j = 0; j < 4 ; j++) {
1883                 // Extract the inputs.
1884                 ArgumentsUcharUcharUchar args = new ArgumentsUcharUcharUchar();
1885                 args.inA = arrayInA[i * 4 + j];
1886                 args.inB = arrayInB[i * 4 + j];
1887                 // Figure out what the outputs should have been.
1888                 CoreMathVerifier.computeMax(args);
1889                 // Validate the outputs.
1890                 boolean valid = true;
1891                 if (args.out != arrayOut[i * 4 + j]) {
1892                     valid = false;
1893                 }
1894                 if (!valid) {
1895                     if (!errorFound) {
1896                         errorFound = true;
1897                         message.append("Input inA: ");
1898                         appendVariableToMessage(message, args.inA);
1899                         message.append("\n");
1900                         message.append("Input inB: ");
1901                         appendVariableToMessage(message, args.inB);
1902                         message.append("\n");
1903                         message.append("Expected output out: ");
1904                         appendVariableToMessage(message, args.out);
1905                         message.append("\n");
1906                         message.append("Actual   output out: ");
1907                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1908                         if (args.out != arrayOut[i * 4 + j]) {
1909                             message.append(" FAIL");
1910                         }
1911                         message.append("\n");
1912                         message.append("Errors at");
1913                     }
1914                     message.append(" [");
1915                     message.append(Integer.toString(i));
1916                     message.append(", ");
1917                     message.append(Integer.toString(j));
1918                     message.append("]");
1919                 }
1920             }
1921         }
1922         assertFalse("Incorrect output for checkMaxUchar4Uchar4Uchar4" +
1923                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1924     }
1925 
1926     public class ArgumentsShortShortShort {
1927         public short inA;
1928         public short inB;
1929         public short out;
1930     }
1931 
checkMaxShortShortShort()1932     private void checkMaxShortShortShort() {
1933         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0x920335e143b57294l, false);
1934         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0x920335e143b57295l, false);
1935         try {
1936             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 1), INPUTSIZE);
1937             script.set_gAllocInB(inB);
1938             script.forEach_testMaxShortShortShort(inA, out);
1939             verifyResultsMaxShortShortShort(inA, inB, out, false);
1940             out.destroy();
1941         } catch (Exception e) {
1942             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxShortShortShort: " + e.toString());
1943         }
1944         try {
1945             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 1), INPUTSIZE);
1946             scriptRelaxed.set_gAllocInB(inB);
1947             scriptRelaxed.forEach_testMaxShortShortShort(inA, out);
1948             verifyResultsMaxShortShortShort(inA, inB, out, true);
1949             out.destroy();
1950         } catch (Exception e) {
1951             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxShortShortShort: " + e.toString());
1952         }
1953         inA.destroy();
1954         inB.destroy();
1955     }
1956 
verifyResultsMaxShortShortShort(Allocation inA, Allocation inB, Allocation out, boolean relaxed)1957     private void verifyResultsMaxShortShortShort(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
1958         short[] arrayInA = new short[INPUTSIZE * 1];
1959         Arrays.fill(arrayInA, (short) 42);
1960         inA.copyTo(arrayInA);
1961         short[] arrayInB = new short[INPUTSIZE * 1];
1962         Arrays.fill(arrayInB, (short) 42);
1963         inB.copyTo(arrayInB);
1964         short[] arrayOut = new short[INPUTSIZE * 1];
1965         Arrays.fill(arrayOut, (short) 42);
1966         out.copyTo(arrayOut);
1967         StringBuilder message = new StringBuilder();
1968         boolean errorFound = false;
1969         for (int i = 0; i < INPUTSIZE; i++) {
1970             for (int j = 0; j < 1 ; j++) {
1971                 // Extract the inputs.
1972                 ArgumentsShortShortShort args = new ArgumentsShortShortShort();
1973                 args.inA = arrayInA[i];
1974                 args.inB = arrayInB[i];
1975                 // Figure out what the outputs should have been.
1976                 CoreMathVerifier.computeMax(args);
1977                 // Validate the outputs.
1978                 boolean valid = true;
1979                 if (args.out != arrayOut[i * 1 + j]) {
1980                     valid = false;
1981                 }
1982                 if (!valid) {
1983                     if (!errorFound) {
1984                         errorFound = true;
1985                         message.append("Input inA: ");
1986                         appendVariableToMessage(message, args.inA);
1987                         message.append("\n");
1988                         message.append("Input inB: ");
1989                         appendVariableToMessage(message, args.inB);
1990                         message.append("\n");
1991                         message.append("Expected output out: ");
1992                         appendVariableToMessage(message, args.out);
1993                         message.append("\n");
1994                         message.append("Actual   output out: ");
1995                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
1996                         if (args.out != arrayOut[i * 1 + j]) {
1997                             message.append(" FAIL");
1998                         }
1999                         message.append("\n");
2000                         message.append("Errors at");
2001                     }
2002                     message.append(" [");
2003                     message.append(Integer.toString(i));
2004                     message.append(", ");
2005                     message.append(Integer.toString(j));
2006                     message.append("]");
2007                 }
2008             }
2009         }
2010         assertFalse("Incorrect output for checkMaxShortShortShort" +
2011                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2012     }
2013 
checkMaxShort2Short2Short2()2014     private void checkMaxShort2Short2Short2() {
2015         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x42e9d46b56ecb9del, false);
2016         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x42e9d46b56ecb9dfl, false);
2017         try {
2018             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
2019             script.set_gAllocInB(inB);
2020             script.forEach_testMaxShort2Short2Short2(inA, out);
2021             verifyResultsMaxShort2Short2Short2(inA, inB, out, false);
2022             out.destroy();
2023         } catch (Exception e) {
2024             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxShort2Short2Short2: " + e.toString());
2025         }
2026         try {
2027             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
2028             scriptRelaxed.set_gAllocInB(inB);
2029             scriptRelaxed.forEach_testMaxShort2Short2Short2(inA, out);
2030             verifyResultsMaxShort2Short2Short2(inA, inB, out, true);
2031             out.destroy();
2032         } catch (Exception e) {
2033             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxShort2Short2Short2: " + e.toString());
2034         }
2035         inA.destroy();
2036         inB.destroy();
2037     }
2038 
verifyResultsMaxShort2Short2Short2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2039     private void verifyResultsMaxShort2Short2Short2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2040         short[] arrayInA = new short[INPUTSIZE * 2];
2041         Arrays.fill(arrayInA, (short) 42);
2042         inA.copyTo(arrayInA);
2043         short[] arrayInB = new short[INPUTSIZE * 2];
2044         Arrays.fill(arrayInB, (short) 42);
2045         inB.copyTo(arrayInB);
2046         short[] arrayOut = new short[INPUTSIZE * 2];
2047         Arrays.fill(arrayOut, (short) 42);
2048         out.copyTo(arrayOut);
2049         StringBuilder message = new StringBuilder();
2050         boolean errorFound = false;
2051         for (int i = 0; i < INPUTSIZE; i++) {
2052             for (int j = 0; j < 2 ; j++) {
2053                 // Extract the inputs.
2054                 ArgumentsShortShortShort args = new ArgumentsShortShortShort();
2055                 args.inA = arrayInA[i * 2 + j];
2056                 args.inB = arrayInB[i * 2 + j];
2057                 // Figure out what the outputs should have been.
2058                 CoreMathVerifier.computeMax(args);
2059                 // Validate the outputs.
2060                 boolean valid = true;
2061                 if (args.out != arrayOut[i * 2 + j]) {
2062                     valid = false;
2063                 }
2064                 if (!valid) {
2065                     if (!errorFound) {
2066                         errorFound = true;
2067                         message.append("Input inA: ");
2068                         appendVariableToMessage(message, args.inA);
2069                         message.append("\n");
2070                         message.append("Input inB: ");
2071                         appendVariableToMessage(message, args.inB);
2072                         message.append("\n");
2073                         message.append("Expected output out: ");
2074                         appendVariableToMessage(message, args.out);
2075                         message.append("\n");
2076                         message.append("Actual   output out: ");
2077                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
2078                         if (args.out != arrayOut[i * 2 + j]) {
2079                             message.append(" FAIL");
2080                         }
2081                         message.append("\n");
2082                         message.append("Errors at");
2083                     }
2084                     message.append(" [");
2085                     message.append(Integer.toString(i));
2086                     message.append(", ");
2087                     message.append(Integer.toString(j));
2088                     message.append("]");
2089                 }
2090             }
2091         }
2092         assertFalse("Incorrect output for checkMaxShort2Short2Short2" +
2093                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2094     }
2095 
checkMaxShort3Short3Short3()2096     private void checkMaxShort3Short3Short3() {
2097         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x974eb28b58cabb7fl, false);
2098         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x974eb28b58cabb80l, false);
2099         try {
2100             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
2101             script.set_gAllocInB(inB);
2102             script.forEach_testMaxShort3Short3Short3(inA, out);
2103             verifyResultsMaxShort3Short3Short3(inA, inB, out, false);
2104             out.destroy();
2105         } catch (Exception e) {
2106             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxShort3Short3Short3: " + e.toString());
2107         }
2108         try {
2109             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
2110             scriptRelaxed.set_gAllocInB(inB);
2111             scriptRelaxed.forEach_testMaxShort3Short3Short3(inA, out);
2112             verifyResultsMaxShort3Short3Short3(inA, inB, out, true);
2113             out.destroy();
2114         } catch (Exception e) {
2115             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxShort3Short3Short3: " + e.toString());
2116         }
2117         inA.destroy();
2118         inB.destroy();
2119     }
2120 
verifyResultsMaxShort3Short3Short3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2121     private void verifyResultsMaxShort3Short3Short3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2122         short[] arrayInA = new short[INPUTSIZE * 4];
2123         Arrays.fill(arrayInA, (short) 42);
2124         inA.copyTo(arrayInA);
2125         short[] arrayInB = new short[INPUTSIZE * 4];
2126         Arrays.fill(arrayInB, (short) 42);
2127         inB.copyTo(arrayInB);
2128         short[] arrayOut = new short[INPUTSIZE * 4];
2129         Arrays.fill(arrayOut, (short) 42);
2130         out.copyTo(arrayOut);
2131         StringBuilder message = new StringBuilder();
2132         boolean errorFound = false;
2133         for (int i = 0; i < INPUTSIZE; i++) {
2134             for (int j = 0; j < 3 ; j++) {
2135                 // Extract the inputs.
2136                 ArgumentsShortShortShort args = new ArgumentsShortShortShort();
2137                 args.inA = arrayInA[i * 4 + j];
2138                 args.inB = arrayInB[i * 4 + j];
2139                 // Figure out what the outputs should have been.
2140                 CoreMathVerifier.computeMax(args);
2141                 // Validate the outputs.
2142                 boolean valid = true;
2143                 if (args.out != arrayOut[i * 4 + j]) {
2144                     valid = false;
2145                 }
2146                 if (!valid) {
2147                     if (!errorFound) {
2148                         errorFound = true;
2149                         message.append("Input inA: ");
2150                         appendVariableToMessage(message, args.inA);
2151                         message.append("\n");
2152                         message.append("Input inB: ");
2153                         appendVariableToMessage(message, args.inB);
2154                         message.append("\n");
2155                         message.append("Expected output out: ");
2156                         appendVariableToMessage(message, args.out);
2157                         message.append("\n");
2158                         message.append("Actual   output out: ");
2159                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
2160                         if (args.out != arrayOut[i * 4 + j]) {
2161                             message.append(" FAIL");
2162                         }
2163                         message.append("\n");
2164                         message.append("Errors at");
2165                     }
2166                     message.append(" [");
2167                     message.append(Integer.toString(i));
2168                     message.append(", ");
2169                     message.append(Integer.toString(j));
2170                     message.append("]");
2171                 }
2172             }
2173         }
2174         assertFalse("Incorrect output for checkMaxShort3Short3Short3" +
2175                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2176     }
2177 
checkMaxShort4Short4Short4()2178     private void checkMaxShort4Short4Short4() {
2179         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 4, 0xebb390ab5aa8bd20l, false);
2180         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 4, 0xebb390ab5aa8bd21l, false);
2181         try {
2182             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
2183             script.set_gAllocInB(inB);
2184             script.forEach_testMaxShort4Short4Short4(inA, out);
2185             verifyResultsMaxShort4Short4Short4(inA, inB, out, false);
2186             out.destroy();
2187         } catch (Exception e) {
2188             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxShort4Short4Short4: " + e.toString());
2189         }
2190         try {
2191             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
2192             scriptRelaxed.set_gAllocInB(inB);
2193             scriptRelaxed.forEach_testMaxShort4Short4Short4(inA, out);
2194             verifyResultsMaxShort4Short4Short4(inA, inB, out, true);
2195             out.destroy();
2196         } catch (Exception e) {
2197             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxShort4Short4Short4: " + e.toString());
2198         }
2199         inA.destroy();
2200         inB.destroy();
2201     }
2202 
verifyResultsMaxShort4Short4Short4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2203     private void verifyResultsMaxShort4Short4Short4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2204         short[] arrayInA = new short[INPUTSIZE * 4];
2205         Arrays.fill(arrayInA, (short) 42);
2206         inA.copyTo(arrayInA);
2207         short[] arrayInB = new short[INPUTSIZE * 4];
2208         Arrays.fill(arrayInB, (short) 42);
2209         inB.copyTo(arrayInB);
2210         short[] arrayOut = new short[INPUTSIZE * 4];
2211         Arrays.fill(arrayOut, (short) 42);
2212         out.copyTo(arrayOut);
2213         StringBuilder message = new StringBuilder();
2214         boolean errorFound = false;
2215         for (int i = 0; i < INPUTSIZE; i++) {
2216             for (int j = 0; j < 4 ; j++) {
2217                 // Extract the inputs.
2218                 ArgumentsShortShortShort args = new ArgumentsShortShortShort();
2219                 args.inA = arrayInA[i * 4 + j];
2220                 args.inB = arrayInB[i * 4 + j];
2221                 // Figure out what the outputs should have been.
2222                 CoreMathVerifier.computeMax(args);
2223                 // Validate the outputs.
2224                 boolean valid = true;
2225                 if (args.out != arrayOut[i * 4 + j]) {
2226                     valid = false;
2227                 }
2228                 if (!valid) {
2229                     if (!errorFound) {
2230                         errorFound = true;
2231                         message.append("Input inA: ");
2232                         appendVariableToMessage(message, args.inA);
2233                         message.append("\n");
2234                         message.append("Input inB: ");
2235                         appendVariableToMessage(message, args.inB);
2236                         message.append("\n");
2237                         message.append("Expected output out: ");
2238                         appendVariableToMessage(message, args.out);
2239                         message.append("\n");
2240                         message.append("Actual   output out: ");
2241                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
2242                         if (args.out != arrayOut[i * 4 + j]) {
2243                             message.append(" FAIL");
2244                         }
2245                         message.append("\n");
2246                         message.append("Errors at");
2247                     }
2248                     message.append(" [");
2249                     message.append(Integer.toString(i));
2250                     message.append(", ");
2251                     message.append(Integer.toString(j));
2252                     message.append("]");
2253                 }
2254             }
2255         }
2256         assertFalse("Incorrect output for checkMaxShort4Short4Short4" +
2257                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2258     }
2259 
2260     public class ArgumentsUshortUshortUshort {
2261         public short inA;
2262         public short inB;
2263         public short out;
2264     }
2265 
checkMaxUshortUshortUshort()2266     private void checkMaxUshortUshortUshort() {
2267         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0x8f869c73b947704bl, false);
2268         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0x8f869c73b947704cl, false);
2269         try {
2270             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE);
2271             script.set_gAllocInB(inB);
2272             script.forEach_testMaxUshortUshortUshort(inA, out);
2273             verifyResultsMaxUshortUshortUshort(inA, inB, out, false);
2274             out.destroy();
2275         } catch (Exception e) {
2276             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUshortUshortUshort: " + e.toString());
2277         }
2278         try {
2279             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE);
2280             scriptRelaxed.set_gAllocInB(inB);
2281             scriptRelaxed.forEach_testMaxUshortUshortUshort(inA, out);
2282             verifyResultsMaxUshortUshortUshort(inA, inB, out, true);
2283             out.destroy();
2284         } catch (Exception e) {
2285             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUshortUshortUshort: " + e.toString());
2286         }
2287         inA.destroy();
2288         inB.destroy();
2289     }
2290 
verifyResultsMaxUshortUshortUshort(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2291     private void verifyResultsMaxUshortUshortUshort(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2292         short[] arrayInA = new short[INPUTSIZE * 1];
2293         Arrays.fill(arrayInA, (short) 42);
2294         inA.copyTo(arrayInA);
2295         short[] arrayInB = new short[INPUTSIZE * 1];
2296         Arrays.fill(arrayInB, (short) 42);
2297         inB.copyTo(arrayInB);
2298         short[] arrayOut = new short[INPUTSIZE * 1];
2299         Arrays.fill(arrayOut, (short) 42);
2300         out.copyTo(arrayOut);
2301         StringBuilder message = new StringBuilder();
2302         boolean errorFound = false;
2303         for (int i = 0; i < INPUTSIZE; i++) {
2304             for (int j = 0; j < 1 ; j++) {
2305                 // Extract the inputs.
2306                 ArgumentsUshortUshortUshort args = new ArgumentsUshortUshortUshort();
2307                 args.inA = arrayInA[i];
2308                 args.inB = arrayInB[i];
2309                 // Figure out what the outputs should have been.
2310                 CoreMathVerifier.computeMax(args);
2311                 // Validate the outputs.
2312                 boolean valid = true;
2313                 if (args.out != arrayOut[i * 1 + j]) {
2314                     valid = false;
2315                 }
2316                 if (!valid) {
2317                     if (!errorFound) {
2318                         errorFound = true;
2319                         message.append("Input inA: ");
2320                         appendVariableToMessage(message, args.inA);
2321                         message.append("\n");
2322                         message.append("Input inB: ");
2323                         appendVariableToMessage(message, args.inB);
2324                         message.append("\n");
2325                         message.append("Expected output out: ");
2326                         appendVariableToMessage(message, args.out);
2327                         message.append("\n");
2328                         message.append("Actual   output out: ");
2329                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
2330                         if (args.out != arrayOut[i * 1 + j]) {
2331                             message.append(" FAIL");
2332                         }
2333                         message.append("\n");
2334                         message.append("Errors at");
2335                     }
2336                     message.append(" [");
2337                     message.append(Integer.toString(i));
2338                     message.append(", ");
2339                     message.append(Integer.toString(j));
2340                     message.append("]");
2341                 }
2342             }
2343         }
2344         assertFalse("Incorrect output for checkMaxUshortUshortUshort" +
2345                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2346     }
2347 
checkMaxUshort2Ushort2Ushort2()2348     private void checkMaxUshort2Ushort2Ushort2() {
2349         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0xbe3c50e6150b1f95l, false);
2350         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0xbe3c50e6150b1f96l, false);
2351         try {
2352             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
2353             script.set_gAllocInB(inB);
2354             script.forEach_testMaxUshort2Ushort2Ushort2(inA, out);
2355             verifyResultsMaxUshort2Ushort2Ushort2(inA, inB, out, false);
2356             out.destroy();
2357         } catch (Exception e) {
2358             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUshort2Ushort2Ushort2: " + e.toString());
2359         }
2360         try {
2361             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
2362             scriptRelaxed.set_gAllocInB(inB);
2363             scriptRelaxed.forEach_testMaxUshort2Ushort2Ushort2(inA, out);
2364             verifyResultsMaxUshort2Ushort2Ushort2(inA, inB, out, true);
2365             out.destroy();
2366         } catch (Exception e) {
2367             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUshort2Ushort2Ushort2: " + e.toString());
2368         }
2369         inA.destroy();
2370         inB.destroy();
2371     }
2372 
verifyResultsMaxUshort2Ushort2Ushort2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2373     private void verifyResultsMaxUshort2Ushort2Ushort2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2374         short[] arrayInA = new short[INPUTSIZE * 2];
2375         Arrays.fill(arrayInA, (short) 42);
2376         inA.copyTo(arrayInA);
2377         short[] arrayInB = new short[INPUTSIZE * 2];
2378         Arrays.fill(arrayInB, (short) 42);
2379         inB.copyTo(arrayInB);
2380         short[] arrayOut = new short[INPUTSIZE * 2];
2381         Arrays.fill(arrayOut, (short) 42);
2382         out.copyTo(arrayOut);
2383         StringBuilder message = new StringBuilder();
2384         boolean errorFound = false;
2385         for (int i = 0; i < INPUTSIZE; i++) {
2386             for (int j = 0; j < 2 ; j++) {
2387                 // Extract the inputs.
2388                 ArgumentsUshortUshortUshort args = new ArgumentsUshortUshortUshort();
2389                 args.inA = arrayInA[i * 2 + j];
2390                 args.inB = arrayInB[i * 2 + j];
2391                 // Figure out what the outputs should have been.
2392                 CoreMathVerifier.computeMax(args);
2393                 // Validate the outputs.
2394                 boolean valid = true;
2395                 if (args.out != arrayOut[i * 2 + j]) {
2396                     valid = false;
2397                 }
2398                 if (!valid) {
2399                     if (!errorFound) {
2400                         errorFound = true;
2401                         message.append("Input inA: ");
2402                         appendVariableToMessage(message, args.inA);
2403                         message.append("\n");
2404                         message.append("Input inB: ");
2405                         appendVariableToMessage(message, args.inB);
2406                         message.append("\n");
2407                         message.append("Expected output out: ");
2408                         appendVariableToMessage(message, args.out);
2409                         message.append("\n");
2410                         message.append("Actual   output out: ");
2411                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
2412                         if (args.out != arrayOut[i * 2 + j]) {
2413                             message.append(" FAIL");
2414                         }
2415                         message.append("\n");
2416                         message.append("Errors at");
2417                     }
2418                     message.append(" [");
2419                     message.append(Integer.toString(i));
2420                     message.append(", ");
2421                     message.append(Integer.toString(j));
2422                     message.append("]");
2423                 }
2424             }
2425         }
2426         assertFalse("Incorrect output for checkMaxUshort2Ushort2Ushort2" +
2427                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2428     }
2429 
checkMaxUshort3Ushort3Ushort3()2430     private void checkMaxUshort3Ushort3Ushort3() {
2431         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0x3e2be9df5df0112cl, false);
2432         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0x3e2be9df5df0112dl, false);
2433         try {
2434             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
2435             script.set_gAllocInB(inB);
2436             script.forEach_testMaxUshort3Ushort3Ushort3(inA, out);
2437             verifyResultsMaxUshort3Ushort3Ushort3(inA, inB, out, false);
2438             out.destroy();
2439         } catch (Exception e) {
2440             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUshort3Ushort3Ushort3: " + e.toString());
2441         }
2442         try {
2443             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
2444             scriptRelaxed.set_gAllocInB(inB);
2445             scriptRelaxed.forEach_testMaxUshort3Ushort3Ushort3(inA, out);
2446             verifyResultsMaxUshort3Ushort3Ushort3(inA, inB, out, true);
2447             out.destroy();
2448         } catch (Exception e) {
2449             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUshort3Ushort3Ushort3: " + e.toString());
2450         }
2451         inA.destroy();
2452         inB.destroy();
2453     }
2454 
verifyResultsMaxUshort3Ushort3Ushort3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2455     private void verifyResultsMaxUshort3Ushort3Ushort3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2456         short[] arrayInA = new short[INPUTSIZE * 4];
2457         Arrays.fill(arrayInA, (short) 42);
2458         inA.copyTo(arrayInA);
2459         short[] arrayInB = new short[INPUTSIZE * 4];
2460         Arrays.fill(arrayInB, (short) 42);
2461         inB.copyTo(arrayInB);
2462         short[] arrayOut = new short[INPUTSIZE * 4];
2463         Arrays.fill(arrayOut, (short) 42);
2464         out.copyTo(arrayOut);
2465         StringBuilder message = new StringBuilder();
2466         boolean errorFound = false;
2467         for (int i = 0; i < INPUTSIZE; i++) {
2468             for (int j = 0; j < 3 ; j++) {
2469                 // Extract the inputs.
2470                 ArgumentsUshortUshortUshort args = new ArgumentsUshortUshortUshort();
2471                 args.inA = arrayInA[i * 4 + j];
2472                 args.inB = arrayInB[i * 4 + j];
2473                 // Figure out what the outputs should have been.
2474                 CoreMathVerifier.computeMax(args);
2475                 // Validate the outputs.
2476                 boolean valid = true;
2477                 if (args.out != arrayOut[i * 4 + j]) {
2478                     valid = false;
2479                 }
2480                 if (!valid) {
2481                     if (!errorFound) {
2482                         errorFound = true;
2483                         message.append("Input inA: ");
2484                         appendVariableToMessage(message, args.inA);
2485                         message.append("\n");
2486                         message.append("Input inB: ");
2487                         appendVariableToMessage(message, args.inB);
2488                         message.append("\n");
2489                         message.append("Expected output out: ");
2490                         appendVariableToMessage(message, args.out);
2491                         message.append("\n");
2492                         message.append("Actual   output out: ");
2493                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
2494                         if (args.out != arrayOut[i * 4 + j]) {
2495                             message.append(" FAIL");
2496                         }
2497                         message.append("\n");
2498                         message.append("Errors at");
2499                     }
2500                     message.append(" [");
2501                     message.append(Integer.toString(i));
2502                     message.append(", ");
2503                     message.append(Integer.toString(j));
2504                     message.append("]");
2505                 }
2506             }
2507         }
2508         assertFalse("Incorrect output for checkMaxUshort3Ushort3Ushort3" +
2509                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2510     }
2511 
checkMaxUshort4Ushort4Ushort4()2512     private void checkMaxUshort4Ushort4Ushort4() {
2513         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0xbe1b82d8a6d502c3l, false);
2514         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0xbe1b82d8a6d502c4l, false);
2515         try {
2516             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
2517             script.set_gAllocInB(inB);
2518             script.forEach_testMaxUshort4Ushort4Ushort4(inA, out);
2519             verifyResultsMaxUshort4Ushort4Ushort4(inA, inB, out, false);
2520             out.destroy();
2521         } catch (Exception e) {
2522             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUshort4Ushort4Ushort4: " + e.toString());
2523         }
2524         try {
2525             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
2526             scriptRelaxed.set_gAllocInB(inB);
2527             scriptRelaxed.forEach_testMaxUshort4Ushort4Ushort4(inA, out);
2528             verifyResultsMaxUshort4Ushort4Ushort4(inA, inB, out, true);
2529             out.destroy();
2530         } catch (Exception e) {
2531             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUshort4Ushort4Ushort4: " + e.toString());
2532         }
2533         inA.destroy();
2534         inB.destroy();
2535     }
2536 
verifyResultsMaxUshort4Ushort4Ushort4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2537     private void verifyResultsMaxUshort4Ushort4Ushort4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2538         short[] arrayInA = new short[INPUTSIZE * 4];
2539         Arrays.fill(arrayInA, (short) 42);
2540         inA.copyTo(arrayInA);
2541         short[] arrayInB = new short[INPUTSIZE * 4];
2542         Arrays.fill(arrayInB, (short) 42);
2543         inB.copyTo(arrayInB);
2544         short[] arrayOut = new short[INPUTSIZE * 4];
2545         Arrays.fill(arrayOut, (short) 42);
2546         out.copyTo(arrayOut);
2547         StringBuilder message = new StringBuilder();
2548         boolean errorFound = false;
2549         for (int i = 0; i < INPUTSIZE; i++) {
2550             for (int j = 0; j < 4 ; j++) {
2551                 // Extract the inputs.
2552                 ArgumentsUshortUshortUshort args = new ArgumentsUshortUshortUshort();
2553                 args.inA = arrayInA[i * 4 + j];
2554                 args.inB = arrayInB[i * 4 + j];
2555                 // Figure out what the outputs should have been.
2556                 CoreMathVerifier.computeMax(args);
2557                 // Validate the outputs.
2558                 boolean valid = true;
2559                 if (args.out != arrayOut[i * 4 + j]) {
2560                     valid = false;
2561                 }
2562                 if (!valid) {
2563                     if (!errorFound) {
2564                         errorFound = true;
2565                         message.append("Input inA: ");
2566                         appendVariableToMessage(message, args.inA);
2567                         message.append("\n");
2568                         message.append("Input inB: ");
2569                         appendVariableToMessage(message, args.inB);
2570                         message.append("\n");
2571                         message.append("Expected output out: ");
2572                         appendVariableToMessage(message, args.out);
2573                         message.append("\n");
2574                         message.append("Actual   output out: ");
2575                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
2576                         if (args.out != arrayOut[i * 4 + j]) {
2577                             message.append(" FAIL");
2578                         }
2579                         message.append("\n");
2580                         message.append("Errors at");
2581                     }
2582                     message.append(" [");
2583                     message.append(Integer.toString(i));
2584                     message.append(", ");
2585                     message.append(Integer.toString(j));
2586                     message.append("]");
2587                 }
2588             }
2589         }
2590         assertFalse("Incorrect output for checkMaxUshort4Ushort4Ushort4" +
2591                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2592     }
2593 
2594     public class ArgumentsIntIntInt {
2595         public int inA;
2596         public int inB;
2597         public int out;
2598     }
2599 
checkMaxIntIntInt()2600     private void checkMaxIntIntInt() {
2601         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0x773d0d60e43d0fa9l, false);
2602         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0x773d0d60e43d0faal, false);
2603         try {
2604             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE);
2605             script.set_gAllocInB(inB);
2606             script.forEach_testMaxIntIntInt(inA, out);
2607             verifyResultsMaxIntIntInt(inA, inB, out, false);
2608             out.destroy();
2609         } catch (Exception e) {
2610             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxIntIntInt: " + e.toString());
2611         }
2612         try {
2613             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE);
2614             scriptRelaxed.set_gAllocInB(inB);
2615             scriptRelaxed.forEach_testMaxIntIntInt(inA, out);
2616             verifyResultsMaxIntIntInt(inA, inB, out, true);
2617             out.destroy();
2618         } catch (Exception e) {
2619             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxIntIntInt: " + e.toString());
2620         }
2621         inA.destroy();
2622         inB.destroy();
2623     }
2624 
verifyResultsMaxIntIntInt(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2625     private void verifyResultsMaxIntIntInt(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2626         int[] arrayInA = new int[INPUTSIZE * 1];
2627         Arrays.fill(arrayInA, (int) 42);
2628         inA.copyTo(arrayInA);
2629         int[] arrayInB = new int[INPUTSIZE * 1];
2630         Arrays.fill(arrayInB, (int) 42);
2631         inB.copyTo(arrayInB);
2632         int[] arrayOut = new int[INPUTSIZE * 1];
2633         Arrays.fill(arrayOut, (int) 42);
2634         out.copyTo(arrayOut);
2635         StringBuilder message = new StringBuilder();
2636         boolean errorFound = false;
2637         for (int i = 0; i < INPUTSIZE; i++) {
2638             for (int j = 0; j < 1 ; j++) {
2639                 // Extract the inputs.
2640                 ArgumentsIntIntInt args = new ArgumentsIntIntInt();
2641                 args.inA = arrayInA[i];
2642                 args.inB = arrayInB[i];
2643                 // Figure out what the outputs should have been.
2644                 CoreMathVerifier.computeMax(args);
2645                 // Validate the outputs.
2646                 boolean valid = true;
2647                 if (args.out != arrayOut[i * 1 + j]) {
2648                     valid = false;
2649                 }
2650                 if (!valid) {
2651                     if (!errorFound) {
2652                         errorFound = true;
2653                         message.append("Input inA: ");
2654                         appendVariableToMessage(message, args.inA);
2655                         message.append("\n");
2656                         message.append("Input inB: ");
2657                         appendVariableToMessage(message, args.inB);
2658                         message.append("\n");
2659                         message.append("Expected output out: ");
2660                         appendVariableToMessage(message, args.out);
2661                         message.append("\n");
2662                         message.append("Actual   output out: ");
2663                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
2664                         if (args.out != arrayOut[i * 1 + j]) {
2665                             message.append(" FAIL");
2666                         }
2667                         message.append("\n");
2668                         message.append("Errors at");
2669                     }
2670                     message.append(" [");
2671                     message.append(Integer.toString(i));
2672                     message.append(", ");
2673                     message.append(Integer.toString(j));
2674                     message.append("]");
2675                 }
2676             }
2677         }
2678         assertFalse("Incorrect output for checkMaxIntIntInt" +
2679                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2680     }
2681 
checkMaxInt2Int2Int2()2682     private void checkMaxInt2Int2Int2() {
2683         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x32815a01bb9dccd7l, false);
2684         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x32815a01bb9dccd8l, false);
2685         try {
2686             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
2687             script.set_gAllocInB(inB);
2688             script.forEach_testMaxInt2Int2Int2(inA, out);
2689             verifyResultsMaxInt2Int2Int2(inA, inB, out, false);
2690             out.destroy();
2691         } catch (Exception e) {
2692             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxInt2Int2Int2: " + e.toString());
2693         }
2694         try {
2695             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
2696             scriptRelaxed.set_gAllocInB(inB);
2697             scriptRelaxed.forEach_testMaxInt2Int2Int2(inA, out);
2698             verifyResultsMaxInt2Int2Int2(inA, inB, out, true);
2699             out.destroy();
2700         } catch (Exception e) {
2701             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxInt2Int2Int2: " + e.toString());
2702         }
2703         inA.destroy();
2704         inB.destroy();
2705     }
2706 
verifyResultsMaxInt2Int2Int2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2707     private void verifyResultsMaxInt2Int2Int2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2708         int[] arrayInA = new int[INPUTSIZE * 2];
2709         Arrays.fill(arrayInA, (int) 42);
2710         inA.copyTo(arrayInA);
2711         int[] arrayInB = new int[INPUTSIZE * 2];
2712         Arrays.fill(arrayInB, (int) 42);
2713         inB.copyTo(arrayInB);
2714         int[] arrayOut = new int[INPUTSIZE * 2];
2715         Arrays.fill(arrayOut, (int) 42);
2716         out.copyTo(arrayOut);
2717         StringBuilder message = new StringBuilder();
2718         boolean errorFound = false;
2719         for (int i = 0; i < INPUTSIZE; i++) {
2720             for (int j = 0; j < 2 ; j++) {
2721                 // Extract the inputs.
2722                 ArgumentsIntIntInt args = new ArgumentsIntIntInt();
2723                 args.inA = arrayInA[i * 2 + j];
2724                 args.inB = arrayInB[i * 2 + j];
2725                 // Figure out what the outputs should have been.
2726                 CoreMathVerifier.computeMax(args);
2727                 // Validate the outputs.
2728                 boolean valid = true;
2729                 if (args.out != arrayOut[i * 2 + j]) {
2730                     valid = false;
2731                 }
2732                 if (!valid) {
2733                     if (!errorFound) {
2734                         errorFound = true;
2735                         message.append("Input inA: ");
2736                         appendVariableToMessage(message, args.inA);
2737                         message.append("\n");
2738                         message.append("Input inB: ");
2739                         appendVariableToMessage(message, args.inB);
2740                         message.append("\n");
2741                         message.append("Expected output out: ");
2742                         appendVariableToMessage(message, args.out);
2743                         message.append("\n");
2744                         message.append("Actual   output out: ");
2745                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
2746                         if (args.out != arrayOut[i * 2 + j]) {
2747                             message.append(" FAIL");
2748                         }
2749                         message.append("\n");
2750                         message.append("Errors at");
2751                     }
2752                     message.append(" [");
2753                     message.append(Integer.toString(i));
2754                     message.append(", ");
2755                     message.append(Integer.toString(j));
2756                     message.append("]");
2757                 }
2758             }
2759         }
2760         assertFalse("Incorrect output for checkMaxInt2Int2Int2" +
2761                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2762     }
2763 
checkMaxInt3Int3Int3()2764     private void checkMaxInt3Int3Int3() {
2765         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x3f66ddfc867314c0l, false);
2766         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x3f66ddfc867314c1l, false);
2767         try {
2768             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
2769             script.set_gAllocInB(inB);
2770             script.forEach_testMaxInt3Int3Int3(inA, out);
2771             verifyResultsMaxInt3Int3Int3(inA, inB, out, false);
2772             out.destroy();
2773         } catch (Exception e) {
2774             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxInt3Int3Int3: " + e.toString());
2775         }
2776         try {
2777             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
2778             scriptRelaxed.set_gAllocInB(inB);
2779             scriptRelaxed.forEach_testMaxInt3Int3Int3(inA, out);
2780             verifyResultsMaxInt3Int3Int3(inA, inB, out, true);
2781             out.destroy();
2782         } catch (Exception e) {
2783             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxInt3Int3Int3: " + e.toString());
2784         }
2785         inA.destroy();
2786         inB.destroy();
2787     }
2788 
verifyResultsMaxInt3Int3Int3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2789     private void verifyResultsMaxInt3Int3Int3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2790         int[] arrayInA = new int[INPUTSIZE * 4];
2791         Arrays.fill(arrayInA, (int) 42);
2792         inA.copyTo(arrayInA);
2793         int[] arrayInB = new int[INPUTSIZE * 4];
2794         Arrays.fill(arrayInB, (int) 42);
2795         inB.copyTo(arrayInB);
2796         int[] arrayOut = new int[INPUTSIZE * 4];
2797         Arrays.fill(arrayOut, (int) 42);
2798         out.copyTo(arrayOut);
2799         StringBuilder message = new StringBuilder();
2800         boolean errorFound = false;
2801         for (int i = 0; i < INPUTSIZE; i++) {
2802             for (int j = 0; j < 3 ; j++) {
2803                 // Extract the inputs.
2804                 ArgumentsIntIntInt args = new ArgumentsIntIntInt();
2805                 args.inA = arrayInA[i * 4 + j];
2806                 args.inB = arrayInB[i * 4 + j];
2807                 // Figure out what the outputs should have been.
2808                 CoreMathVerifier.computeMax(args);
2809                 // Validate the outputs.
2810                 boolean valid = true;
2811                 if (args.out != arrayOut[i * 4 + j]) {
2812                     valid = false;
2813                 }
2814                 if (!valid) {
2815                     if (!errorFound) {
2816                         errorFound = true;
2817                         message.append("Input inA: ");
2818                         appendVariableToMessage(message, args.inA);
2819                         message.append("\n");
2820                         message.append("Input inB: ");
2821                         appendVariableToMessage(message, args.inB);
2822                         message.append("\n");
2823                         message.append("Expected output out: ");
2824                         appendVariableToMessage(message, args.out);
2825                         message.append("\n");
2826                         message.append("Actual   output out: ");
2827                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
2828                         if (args.out != arrayOut[i * 4 + j]) {
2829                             message.append(" FAIL");
2830                         }
2831                         message.append("\n");
2832                         message.append("Errors at");
2833                     }
2834                     message.append(" [");
2835                     message.append(Integer.toString(i));
2836                     message.append(", ");
2837                     message.append(Integer.toString(j));
2838                     message.append("]");
2839                 }
2840             }
2841         }
2842         assertFalse("Incorrect output for checkMaxInt3Int3Int3" +
2843                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2844     }
2845 
checkMaxInt4Int4Int4()2846     private void checkMaxInt4Int4Int4() {
2847         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x4c4c61f751485ca9l, false);
2848         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x4c4c61f751485caal, false);
2849         try {
2850             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
2851             script.set_gAllocInB(inB);
2852             script.forEach_testMaxInt4Int4Int4(inA, out);
2853             verifyResultsMaxInt4Int4Int4(inA, inB, out, false);
2854             out.destroy();
2855         } catch (Exception e) {
2856             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxInt4Int4Int4: " + e.toString());
2857         }
2858         try {
2859             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
2860             scriptRelaxed.set_gAllocInB(inB);
2861             scriptRelaxed.forEach_testMaxInt4Int4Int4(inA, out);
2862             verifyResultsMaxInt4Int4Int4(inA, inB, out, true);
2863             out.destroy();
2864         } catch (Exception e) {
2865             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxInt4Int4Int4: " + e.toString());
2866         }
2867         inA.destroy();
2868         inB.destroy();
2869     }
2870 
verifyResultsMaxInt4Int4Int4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2871     private void verifyResultsMaxInt4Int4Int4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2872         int[] arrayInA = new int[INPUTSIZE * 4];
2873         Arrays.fill(arrayInA, (int) 42);
2874         inA.copyTo(arrayInA);
2875         int[] arrayInB = new int[INPUTSIZE * 4];
2876         Arrays.fill(arrayInB, (int) 42);
2877         inB.copyTo(arrayInB);
2878         int[] arrayOut = new int[INPUTSIZE * 4];
2879         Arrays.fill(arrayOut, (int) 42);
2880         out.copyTo(arrayOut);
2881         StringBuilder message = new StringBuilder();
2882         boolean errorFound = false;
2883         for (int i = 0; i < INPUTSIZE; i++) {
2884             for (int j = 0; j < 4 ; j++) {
2885                 // Extract the inputs.
2886                 ArgumentsIntIntInt args = new ArgumentsIntIntInt();
2887                 args.inA = arrayInA[i * 4 + j];
2888                 args.inB = arrayInB[i * 4 + j];
2889                 // Figure out what the outputs should have been.
2890                 CoreMathVerifier.computeMax(args);
2891                 // Validate the outputs.
2892                 boolean valid = true;
2893                 if (args.out != arrayOut[i * 4 + j]) {
2894                     valid = false;
2895                 }
2896                 if (!valid) {
2897                     if (!errorFound) {
2898                         errorFound = true;
2899                         message.append("Input inA: ");
2900                         appendVariableToMessage(message, args.inA);
2901                         message.append("\n");
2902                         message.append("Input inB: ");
2903                         appendVariableToMessage(message, args.inB);
2904                         message.append("\n");
2905                         message.append("Expected output out: ");
2906                         appendVariableToMessage(message, args.out);
2907                         message.append("\n");
2908                         message.append("Actual   output out: ");
2909                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
2910                         if (args.out != arrayOut[i * 4 + j]) {
2911                             message.append(" FAIL");
2912                         }
2913                         message.append("\n");
2914                         message.append("Errors at");
2915                     }
2916                     message.append(" [");
2917                     message.append(Integer.toString(i));
2918                     message.append(", ");
2919                     message.append(Integer.toString(j));
2920                     message.append("]");
2921                 }
2922             }
2923         }
2924         assertFalse("Incorrect output for checkMaxInt4Int4Int4" +
2925                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
2926     }
2927 
2928     public class ArgumentsUintUintUint {
2929         public int inA;
2930         public int inB;
2931         public int out;
2932     }
2933 
checkMaxUintUintUint()2934     private void checkMaxUintUintUint() {
2935         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0xcd24e58385f73e36l, false);
2936         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0xcd24e58385f73e37l, false);
2937         try {
2938             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE);
2939             script.set_gAllocInB(inB);
2940             script.forEach_testMaxUintUintUint(inA, out);
2941             verifyResultsMaxUintUintUint(inA, inB, out, false);
2942             out.destroy();
2943         } catch (Exception e) {
2944             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUintUintUint: " + e.toString());
2945         }
2946         try {
2947             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE);
2948             scriptRelaxed.set_gAllocInB(inB);
2949             scriptRelaxed.forEach_testMaxUintUintUint(inA, out);
2950             verifyResultsMaxUintUintUint(inA, inB, out, true);
2951             out.destroy();
2952         } catch (Exception e) {
2953             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUintUintUint: " + e.toString());
2954         }
2955         inA.destroy();
2956         inB.destroy();
2957     }
2958 
verifyResultsMaxUintUintUint(Allocation inA, Allocation inB, Allocation out, boolean relaxed)2959     private void verifyResultsMaxUintUintUint(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
2960         int[] arrayInA = new int[INPUTSIZE * 1];
2961         Arrays.fill(arrayInA, (int) 42);
2962         inA.copyTo(arrayInA);
2963         int[] arrayInB = new int[INPUTSIZE * 1];
2964         Arrays.fill(arrayInB, (int) 42);
2965         inB.copyTo(arrayInB);
2966         int[] arrayOut = new int[INPUTSIZE * 1];
2967         Arrays.fill(arrayOut, (int) 42);
2968         out.copyTo(arrayOut);
2969         StringBuilder message = new StringBuilder();
2970         boolean errorFound = false;
2971         for (int i = 0; i < INPUTSIZE; i++) {
2972             for (int j = 0; j < 1 ; j++) {
2973                 // Extract the inputs.
2974                 ArgumentsUintUintUint args = new ArgumentsUintUintUint();
2975                 args.inA = arrayInA[i];
2976                 args.inB = arrayInB[i];
2977                 // Figure out what the outputs should have been.
2978                 CoreMathVerifier.computeMax(args);
2979                 // Validate the outputs.
2980                 boolean valid = true;
2981                 if (args.out != arrayOut[i * 1 + j]) {
2982                     valid = false;
2983                 }
2984                 if (!valid) {
2985                     if (!errorFound) {
2986                         errorFound = true;
2987                         message.append("Input inA: ");
2988                         appendVariableToMessage(message, args.inA);
2989                         message.append("\n");
2990                         message.append("Input inB: ");
2991                         appendVariableToMessage(message, args.inB);
2992                         message.append("\n");
2993                         message.append("Expected output out: ");
2994                         appendVariableToMessage(message, args.out);
2995                         message.append("\n");
2996                         message.append("Actual   output out: ");
2997                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
2998                         if (args.out != arrayOut[i * 1 + j]) {
2999                             message.append(" FAIL");
3000                         }
3001                         message.append("\n");
3002                         message.append("Errors at");
3003                     }
3004                     message.append(" [");
3005                     message.append(Integer.toString(i));
3006                     message.append(", ");
3007                     message.append(Integer.toString(j));
3008                     message.append("]");
3009                 }
3010             }
3011         }
3012         assertFalse("Incorrect output for checkMaxUintUintUint" +
3013                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3014     }
3015 
checkMaxUint2Uint2Uint2()3016     private void checkMaxUint2Uint2Uint2() {
3017         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0xbd5747860e84d6c4l, false);
3018         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0xbd5747860e84d6c5l, false);
3019         try {
3020             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
3021             script.set_gAllocInB(inB);
3022             script.forEach_testMaxUint2Uint2Uint2(inA, out);
3023             verifyResultsMaxUint2Uint2Uint2(inA, inB, out, false);
3024             out.destroy();
3025         } catch (Exception e) {
3026             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUint2Uint2Uint2: " + e.toString());
3027         }
3028         try {
3029             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
3030             scriptRelaxed.set_gAllocInB(inB);
3031             scriptRelaxed.forEach_testMaxUint2Uint2Uint2(inA, out);
3032             verifyResultsMaxUint2Uint2Uint2(inA, inB, out, true);
3033             out.destroy();
3034         } catch (Exception e) {
3035             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUint2Uint2Uint2: " + e.toString());
3036         }
3037         inA.destroy();
3038         inB.destroy();
3039     }
3040 
verifyResultsMaxUint2Uint2Uint2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)3041     private void verifyResultsMaxUint2Uint2Uint2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
3042         int[] arrayInA = new int[INPUTSIZE * 2];
3043         Arrays.fill(arrayInA, (int) 42);
3044         inA.copyTo(arrayInA);
3045         int[] arrayInB = new int[INPUTSIZE * 2];
3046         Arrays.fill(arrayInB, (int) 42);
3047         inB.copyTo(arrayInB);
3048         int[] arrayOut = new int[INPUTSIZE * 2];
3049         Arrays.fill(arrayOut, (int) 42);
3050         out.copyTo(arrayOut);
3051         StringBuilder message = new StringBuilder();
3052         boolean errorFound = false;
3053         for (int i = 0; i < INPUTSIZE; i++) {
3054             for (int j = 0; j < 2 ; j++) {
3055                 // Extract the inputs.
3056                 ArgumentsUintUintUint args = new ArgumentsUintUintUint();
3057                 args.inA = arrayInA[i * 2 + j];
3058                 args.inB = arrayInB[i * 2 + j];
3059                 // Figure out what the outputs should have been.
3060                 CoreMathVerifier.computeMax(args);
3061                 // Validate the outputs.
3062                 boolean valid = true;
3063                 if (args.out != arrayOut[i * 2 + j]) {
3064                     valid = false;
3065                 }
3066                 if (!valid) {
3067                     if (!errorFound) {
3068                         errorFound = true;
3069                         message.append("Input inA: ");
3070                         appendVariableToMessage(message, args.inA);
3071                         message.append("\n");
3072                         message.append("Input inB: ");
3073                         appendVariableToMessage(message, args.inB);
3074                         message.append("\n");
3075                         message.append("Expected output out: ");
3076                         appendVariableToMessage(message, args.out);
3077                         message.append("\n");
3078                         message.append("Actual   output out: ");
3079                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
3080                         if (args.out != arrayOut[i * 2 + j]) {
3081                             message.append(" FAIL");
3082                         }
3083                         message.append("\n");
3084                         message.append("Errors at");
3085                     }
3086                     message.append(" [");
3087                     message.append(Integer.toString(i));
3088                     message.append(", ");
3089                     message.append(Integer.toString(j));
3090                     message.append("]");
3091                 }
3092             }
3093         }
3094         assertFalse("Incorrect output for checkMaxUint2Uint2Uint2" +
3095                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3096     }
3097 
checkMaxUint3Uint3Uint3()3098     private void checkMaxUint3Uint3Uint3() {
3099         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0xe30bc76f6d23e793l, false);
3100         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0xe30bc76f6d23e794l, false);
3101         try {
3102             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
3103             script.set_gAllocInB(inB);
3104             script.forEach_testMaxUint3Uint3Uint3(inA, out);
3105             verifyResultsMaxUint3Uint3Uint3(inA, inB, out, false);
3106             out.destroy();
3107         } catch (Exception e) {
3108             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUint3Uint3Uint3: " + e.toString());
3109         }
3110         try {
3111             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
3112             scriptRelaxed.set_gAllocInB(inB);
3113             scriptRelaxed.forEach_testMaxUint3Uint3Uint3(inA, out);
3114             verifyResultsMaxUint3Uint3Uint3(inA, inB, out, true);
3115             out.destroy();
3116         } catch (Exception e) {
3117             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUint3Uint3Uint3: " + e.toString());
3118         }
3119         inA.destroy();
3120         inB.destroy();
3121     }
3122 
verifyResultsMaxUint3Uint3Uint3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)3123     private void verifyResultsMaxUint3Uint3Uint3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
3124         int[] arrayInA = new int[INPUTSIZE * 4];
3125         Arrays.fill(arrayInA, (int) 42);
3126         inA.copyTo(arrayInA);
3127         int[] arrayInB = new int[INPUTSIZE * 4];
3128         Arrays.fill(arrayInB, (int) 42);
3129         inB.copyTo(arrayInB);
3130         int[] arrayOut = new int[INPUTSIZE * 4];
3131         Arrays.fill(arrayOut, (int) 42);
3132         out.copyTo(arrayOut);
3133         StringBuilder message = new StringBuilder();
3134         boolean errorFound = false;
3135         for (int i = 0; i < INPUTSIZE; i++) {
3136             for (int j = 0; j < 3 ; j++) {
3137                 // Extract the inputs.
3138                 ArgumentsUintUintUint args = new ArgumentsUintUintUint();
3139                 args.inA = arrayInA[i * 4 + j];
3140                 args.inB = arrayInB[i * 4 + j];
3141                 // Figure out what the outputs should have been.
3142                 CoreMathVerifier.computeMax(args);
3143                 // Validate the outputs.
3144                 boolean valid = true;
3145                 if (args.out != arrayOut[i * 4 + j]) {
3146                     valid = false;
3147                 }
3148                 if (!valid) {
3149                     if (!errorFound) {
3150                         errorFound = true;
3151                         message.append("Input inA: ");
3152                         appendVariableToMessage(message, args.inA);
3153                         message.append("\n");
3154                         message.append("Input inB: ");
3155                         appendVariableToMessage(message, args.inB);
3156                         message.append("\n");
3157                         message.append("Expected output out: ");
3158                         appendVariableToMessage(message, args.out);
3159                         message.append("\n");
3160                         message.append("Actual   output out: ");
3161                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
3162                         if (args.out != arrayOut[i * 4 + j]) {
3163                             message.append(" FAIL");
3164                         }
3165                         message.append("\n");
3166                         message.append("Errors at");
3167                     }
3168                     message.append(" [");
3169                     message.append(Integer.toString(i));
3170                     message.append(", ");
3171                     message.append(Integer.toString(j));
3172                     message.append("]");
3173                 }
3174             }
3175         }
3176         assertFalse("Incorrect output for checkMaxUint3Uint3Uint3" +
3177                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3178     }
3179 
checkMaxUint4Uint4Uint4()3180     private void checkMaxUint4Uint4Uint4() {
3181         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0x8c04758cbc2f862l, false);
3182         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0x8c04758cbc2f863l, false);
3183         try {
3184             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
3185             script.set_gAllocInB(inB);
3186             script.forEach_testMaxUint4Uint4Uint4(inA, out);
3187             verifyResultsMaxUint4Uint4Uint4(inA, inB, out, false);
3188             out.destroy();
3189         } catch (Exception e) {
3190             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUint4Uint4Uint4: " + e.toString());
3191         }
3192         try {
3193             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
3194             scriptRelaxed.set_gAllocInB(inB);
3195             scriptRelaxed.forEach_testMaxUint4Uint4Uint4(inA, out);
3196             verifyResultsMaxUint4Uint4Uint4(inA, inB, out, true);
3197             out.destroy();
3198         } catch (Exception e) {
3199             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUint4Uint4Uint4: " + e.toString());
3200         }
3201         inA.destroy();
3202         inB.destroy();
3203     }
3204 
verifyResultsMaxUint4Uint4Uint4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)3205     private void verifyResultsMaxUint4Uint4Uint4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
3206         int[] arrayInA = new int[INPUTSIZE * 4];
3207         Arrays.fill(arrayInA, (int) 42);
3208         inA.copyTo(arrayInA);
3209         int[] arrayInB = new int[INPUTSIZE * 4];
3210         Arrays.fill(arrayInB, (int) 42);
3211         inB.copyTo(arrayInB);
3212         int[] arrayOut = new int[INPUTSIZE * 4];
3213         Arrays.fill(arrayOut, (int) 42);
3214         out.copyTo(arrayOut);
3215         StringBuilder message = new StringBuilder();
3216         boolean errorFound = false;
3217         for (int i = 0; i < INPUTSIZE; i++) {
3218             for (int j = 0; j < 4 ; j++) {
3219                 // Extract the inputs.
3220                 ArgumentsUintUintUint args = new ArgumentsUintUintUint();
3221                 args.inA = arrayInA[i * 4 + j];
3222                 args.inB = arrayInB[i * 4 + j];
3223                 // Figure out what the outputs should have been.
3224                 CoreMathVerifier.computeMax(args);
3225                 // Validate the outputs.
3226                 boolean valid = true;
3227                 if (args.out != arrayOut[i * 4 + j]) {
3228                     valid = false;
3229                 }
3230                 if (!valid) {
3231                     if (!errorFound) {
3232                         errorFound = true;
3233                         message.append("Input inA: ");
3234                         appendVariableToMessage(message, args.inA);
3235                         message.append("\n");
3236                         message.append("Input inB: ");
3237                         appendVariableToMessage(message, args.inB);
3238                         message.append("\n");
3239                         message.append("Expected output out: ");
3240                         appendVariableToMessage(message, args.out);
3241                         message.append("\n");
3242                         message.append("Actual   output out: ");
3243                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
3244                         if (args.out != arrayOut[i * 4 + j]) {
3245                             message.append(" FAIL");
3246                         }
3247                         message.append("\n");
3248                         message.append("Errors at");
3249                     }
3250                     message.append(" [");
3251                     message.append(Integer.toString(i));
3252                     message.append(", ");
3253                     message.append(Integer.toString(j));
3254                     message.append("]");
3255                 }
3256             }
3257         }
3258         assertFalse("Incorrect output for checkMaxUint4Uint4Uint4" +
3259                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3260     }
3261 
3262     public class ArgumentsLongLongLong {
3263         public long inA;
3264         public long inB;
3265         public long out;
3266     }
3267 
checkMaxLongLongLong()3268     private void checkMaxLongLongLong() {
3269         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 1, 0x542587285eceb84l, false);
3270         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 1, 0x542587285eceb85l, false);
3271         try {
3272             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 1), INPUTSIZE);
3273             script.set_gAllocInB(inB);
3274             script.forEach_testMaxLongLongLong(inA, out);
3275             verifyResultsMaxLongLongLong(inA, inB, out, false);
3276             out.destroy();
3277         } catch (Exception e) {
3278             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxLongLongLong: " + e.toString());
3279         }
3280         try {
3281             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 1), INPUTSIZE);
3282             scriptRelaxed.set_gAllocInB(inB);
3283             scriptRelaxed.forEach_testMaxLongLongLong(inA, out);
3284             verifyResultsMaxLongLongLong(inA, inB, out, true);
3285             out.destroy();
3286         } catch (Exception e) {
3287             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxLongLongLong: " + e.toString());
3288         }
3289         inA.destroy();
3290         inB.destroy();
3291     }
3292 
verifyResultsMaxLongLongLong(Allocation inA, Allocation inB, Allocation out, boolean relaxed)3293     private void verifyResultsMaxLongLongLong(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
3294         long[] arrayInA = new long[INPUTSIZE * 1];
3295         Arrays.fill(arrayInA, (long) 42);
3296         inA.copyTo(arrayInA);
3297         long[] arrayInB = new long[INPUTSIZE * 1];
3298         Arrays.fill(arrayInB, (long) 42);
3299         inB.copyTo(arrayInB);
3300         long[] arrayOut = new long[INPUTSIZE * 1];
3301         Arrays.fill(arrayOut, (long) 42);
3302         out.copyTo(arrayOut);
3303         StringBuilder message = new StringBuilder();
3304         boolean errorFound = false;
3305         for (int i = 0; i < INPUTSIZE; i++) {
3306             for (int j = 0; j < 1 ; j++) {
3307                 // Extract the inputs.
3308                 ArgumentsLongLongLong args = new ArgumentsLongLongLong();
3309                 args.inA = arrayInA[i];
3310                 args.inB = arrayInB[i];
3311                 // Figure out what the outputs should have been.
3312                 CoreMathVerifier.computeMax(args);
3313                 // Validate the outputs.
3314                 boolean valid = true;
3315                 if (args.out != arrayOut[i * 1 + j]) {
3316                     valid = false;
3317                 }
3318                 if (!valid) {
3319                     if (!errorFound) {
3320                         errorFound = true;
3321                         message.append("Input inA: ");
3322                         appendVariableToMessage(message, args.inA);
3323                         message.append("\n");
3324                         message.append("Input inB: ");
3325                         appendVariableToMessage(message, args.inB);
3326                         message.append("\n");
3327                         message.append("Expected output out: ");
3328                         appendVariableToMessage(message, args.out);
3329                         message.append("\n");
3330                         message.append("Actual   output out: ");
3331                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
3332                         if (args.out != arrayOut[i * 1 + j]) {
3333                             message.append(" FAIL");
3334                         }
3335                         message.append("\n");
3336                         message.append("Errors at");
3337                     }
3338                     message.append(" [");
3339                     message.append(Integer.toString(i));
3340                     message.append(", ");
3341                     message.append(Integer.toString(j));
3342                     message.append("]");
3343                 }
3344             }
3345         }
3346         assertFalse("Incorrect output for checkMaxLongLongLong" +
3347                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3348     }
3349 
checkMaxLong2Long2Long2()3350     private void checkMaxLong2Long2Long2() {
3351         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 2, 0xc5c0bac4c249c9dal, false);
3352         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 2, 0xc5c0bac4c249c9dbl, false);
3353         try {
3354             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
3355             script.set_gAllocInB(inB);
3356             script.forEach_testMaxLong2Long2Long2(inA, out);
3357             verifyResultsMaxLong2Long2Long2(inA, inB, out, false);
3358             out.destroy();
3359         } catch (Exception e) {
3360             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxLong2Long2Long2: " + e.toString());
3361         }
3362         try {
3363             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
3364             scriptRelaxed.set_gAllocInB(inB);
3365             scriptRelaxed.forEach_testMaxLong2Long2Long2(inA, out);
3366             verifyResultsMaxLong2Long2Long2(inA, inB, out, true);
3367             out.destroy();
3368         } catch (Exception e) {
3369             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxLong2Long2Long2: " + e.toString());
3370         }
3371         inA.destroy();
3372         inB.destroy();
3373     }
3374 
verifyResultsMaxLong2Long2Long2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)3375     private void verifyResultsMaxLong2Long2Long2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
3376         long[] arrayInA = new long[INPUTSIZE * 2];
3377         Arrays.fill(arrayInA, (long) 42);
3378         inA.copyTo(arrayInA);
3379         long[] arrayInB = new long[INPUTSIZE * 2];
3380         Arrays.fill(arrayInB, (long) 42);
3381         inB.copyTo(arrayInB);
3382         long[] arrayOut = new long[INPUTSIZE * 2];
3383         Arrays.fill(arrayOut, (long) 42);
3384         out.copyTo(arrayOut);
3385         StringBuilder message = new StringBuilder();
3386         boolean errorFound = false;
3387         for (int i = 0; i < INPUTSIZE; i++) {
3388             for (int j = 0; j < 2 ; j++) {
3389                 // Extract the inputs.
3390                 ArgumentsLongLongLong args = new ArgumentsLongLongLong();
3391                 args.inA = arrayInA[i * 2 + j];
3392                 args.inB = arrayInB[i * 2 + j];
3393                 // Figure out what the outputs should have been.
3394                 CoreMathVerifier.computeMax(args);
3395                 // Validate the outputs.
3396                 boolean valid = true;
3397                 if (args.out != arrayOut[i * 2 + j]) {
3398                     valid = false;
3399                 }
3400                 if (!valid) {
3401                     if (!errorFound) {
3402                         errorFound = true;
3403                         message.append("Input inA: ");
3404                         appendVariableToMessage(message, args.inA);
3405                         message.append("\n");
3406                         message.append("Input inB: ");
3407                         appendVariableToMessage(message, args.inB);
3408                         message.append("\n");
3409                         message.append("Expected output out: ");
3410                         appendVariableToMessage(message, args.out);
3411                         message.append("\n");
3412                         message.append("Actual   output out: ");
3413                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
3414                         if (args.out != arrayOut[i * 2 + j]) {
3415                             message.append(" FAIL");
3416                         }
3417                         message.append("\n");
3418                         message.append("Errors at");
3419                     }
3420                     message.append(" [");
3421                     message.append(Integer.toString(i));
3422                     message.append(", ");
3423                     message.append(Integer.toString(j));
3424                     message.append("]");
3425                 }
3426             }
3427         }
3428         assertFalse("Incorrect output for checkMaxLong2Long2Long2" +
3429                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3430     }
3431 
checkMaxLong3Long3Long3()3432     private void checkMaxLong3Long3Long3() {
3433         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 3, 0xeb753aae20e8daa9l, false);
3434         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 3, 0xeb753aae20e8daaal, false);
3435         try {
3436             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
3437             script.set_gAllocInB(inB);
3438             script.forEach_testMaxLong3Long3Long3(inA, out);
3439             verifyResultsMaxLong3Long3Long3(inA, inB, out, false);
3440             out.destroy();
3441         } catch (Exception e) {
3442             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxLong3Long3Long3: " + e.toString());
3443         }
3444         try {
3445             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
3446             scriptRelaxed.set_gAllocInB(inB);
3447             scriptRelaxed.forEach_testMaxLong3Long3Long3(inA, out);
3448             verifyResultsMaxLong3Long3Long3(inA, inB, out, true);
3449             out.destroy();
3450         } catch (Exception e) {
3451             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxLong3Long3Long3: " + e.toString());
3452         }
3453         inA.destroy();
3454         inB.destroy();
3455     }
3456 
verifyResultsMaxLong3Long3Long3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)3457     private void verifyResultsMaxLong3Long3Long3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
3458         long[] arrayInA = new long[INPUTSIZE * 4];
3459         Arrays.fill(arrayInA, (long) 42);
3460         inA.copyTo(arrayInA);
3461         long[] arrayInB = new long[INPUTSIZE * 4];
3462         Arrays.fill(arrayInB, (long) 42);
3463         inB.copyTo(arrayInB);
3464         long[] arrayOut = new long[INPUTSIZE * 4];
3465         Arrays.fill(arrayOut, (long) 42);
3466         out.copyTo(arrayOut);
3467         StringBuilder message = new StringBuilder();
3468         boolean errorFound = false;
3469         for (int i = 0; i < INPUTSIZE; i++) {
3470             for (int j = 0; j < 3 ; j++) {
3471                 // Extract the inputs.
3472                 ArgumentsLongLongLong args = new ArgumentsLongLongLong();
3473                 args.inA = arrayInA[i * 4 + j];
3474                 args.inB = arrayInB[i * 4 + j];
3475                 // Figure out what the outputs should have been.
3476                 CoreMathVerifier.computeMax(args);
3477                 // Validate the outputs.
3478                 boolean valid = true;
3479                 if (args.out != arrayOut[i * 4 + j]) {
3480                     valid = false;
3481                 }
3482                 if (!valid) {
3483                     if (!errorFound) {
3484                         errorFound = true;
3485                         message.append("Input inA: ");
3486                         appendVariableToMessage(message, args.inA);
3487                         message.append("\n");
3488                         message.append("Input inB: ");
3489                         appendVariableToMessage(message, args.inB);
3490                         message.append("\n");
3491                         message.append("Expected output out: ");
3492                         appendVariableToMessage(message, args.out);
3493                         message.append("\n");
3494                         message.append("Actual   output out: ");
3495                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
3496                         if (args.out != arrayOut[i * 4 + j]) {
3497                             message.append(" FAIL");
3498                         }
3499                         message.append("\n");
3500                         message.append("Errors at");
3501                     }
3502                     message.append(" [");
3503                     message.append(Integer.toString(i));
3504                     message.append(", ");
3505                     message.append(Integer.toString(j));
3506                     message.append("]");
3507                 }
3508             }
3509         }
3510         assertFalse("Incorrect output for checkMaxLong3Long3Long3" +
3511                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3512     }
3513 
checkMaxLong4Long4Long4()3514     private void checkMaxLong4Long4Long4() {
3515         Allocation inA = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 4, 0x1129ba977f87eb78l, false);
3516         Allocation inB = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 4, 0x1129ba977f87eb79l, false);
3517         try {
3518             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
3519             script.set_gAllocInB(inB);
3520             script.forEach_testMaxLong4Long4Long4(inA, out);
3521             verifyResultsMaxLong4Long4Long4(inA, inB, out, false);
3522             out.destroy();
3523         } catch (Exception e) {
3524             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxLong4Long4Long4: " + e.toString());
3525         }
3526         try {
3527             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
3528             scriptRelaxed.set_gAllocInB(inB);
3529             scriptRelaxed.forEach_testMaxLong4Long4Long4(inA, out);
3530             verifyResultsMaxLong4Long4Long4(inA, inB, out, true);
3531             out.destroy();
3532         } catch (Exception e) {
3533             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxLong4Long4Long4: " + e.toString());
3534         }
3535         inA.destroy();
3536         inB.destroy();
3537     }
3538 
verifyResultsMaxLong4Long4Long4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)3539     private void verifyResultsMaxLong4Long4Long4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
3540         long[] arrayInA = new long[INPUTSIZE * 4];
3541         Arrays.fill(arrayInA, (long) 42);
3542         inA.copyTo(arrayInA);
3543         long[] arrayInB = new long[INPUTSIZE * 4];
3544         Arrays.fill(arrayInB, (long) 42);
3545         inB.copyTo(arrayInB);
3546         long[] arrayOut = new long[INPUTSIZE * 4];
3547         Arrays.fill(arrayOut, (long) 42);
3548         out.copyTo(arrayOut);
3549         StringBuilder message = new StringBuilder();
3550         boolean errorFound = false;
3551         for (int i = 0; i < INPUTSIZE; i++) {
3552             for (int j = 0; j < 4 ; j++) {
3553                 // Extract the inputs.
3554                 ArgumentsLongLongLong args = new ArgumentsLongLongLong();
3555                 args.inA = arrayInA[i * 4 + j];
3556                 args.inB = arrayInB[i * 4 + j];
3557                 // Figure out what the outputs should have been.
3558                 CoreMathVerifier.computeMax(args);
3559                 // Validate the outputs.
3560                 boolean valid = true;
3561                 if (args.out != arrayOut[i * 4 + j]) {
3562                     valid = false;
3563                 }
3564                 if (!valid) {
3565                     if (!errorFound) {
3566                         errorFound = true;
3567                         message.append("Input inA: ");
3568                         appendVariableToMessage(message, args.inA);
3569                         message.append("\n");
3570                         message.append("Input inB: ");
3571                         appendVariableToMessage(message, args.inB);
3572                         message.append("\n");
3573                         message.append("Expected output out: ");
3574                         appendVariableToMessage(message, args.out);
3575                         message.append("\n");
3576                         message.append("Actual   output out: ");
3577                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
3578                         if (args.out != arrayOut[i * 4 + j]) {
3579                             message.append(" FAIL");
3580                         }
3581                         message.append("\n");
3582                         message.append("Errors at");
3583                     }
3584                     message.append(" [");
3585                     message.append(Integer.toString(i));
3586                     message.append(", ");
3587                     message.append(Integer.toString(j));
3588                     message.append("]");
3589                 }
3590             }
3591         }
3592         assertFalse("Incorrect output for checkMaxLong4Long4Long4" +
3593                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3594     }
3595 
3596     public class ArgumentsUlongUlongUlong {
3597         public long inA;
3598         public long inB;
3599         public long out;
3600     }
3601 
checkMaxUlongUlongUlong()3602     private void checkMaxUlongUlongUlong() {
3603         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 1, 0x8d1ad8f38f18baafl, false);
3604         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 1, 0x8d1ad8f38f18bab0l, false);
3605         try {
3606             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 1), INPUTSIZE);
3607             script.set_gAllocInB(inB);
3608             script.forEach_testMaxUlongUlongUlong(inA, out);
3609             verifyResultsMaxUlongUlongUlong(inA, inB, out, false);
3610             out.destroy();
3611         } catch (Exception e) {
3612             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUlongUlongUlong: " + e.toString());
3613         }
3614         try {
3615             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 1), INPUTSIZE);
3616             scriptRelaxed.set_gAllocInB(inB);
3617             scriptRelaxed.forEach_testMaxUlongUlongUlong(inA, out);
3618             verifyResultsMaxUlongUlongUlong(inA, inB, out, true);
3619             out.destroy();
3620         } catch (Exception e) {
3621             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUlongUlongUlong: " + e.toString());
3622         }
3623         inA.destroy();
3624         inB.destroy();
3625     }
3626 
verifyResultsMaxUlongUlongUlong(Allocation inA, Allocation inB, Allocation out, boolean relaxed)3627     private void verifyResultsMaxUlongUlongUlong(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
3628         long[] arrayInA = new long[INPUTSIZE * 1];
3629         Arrays.fill(arrayInA, (long) 42);
3630         inA.copyTo(arrayInA);
3631         long[] arrayInB = new long[INPUTSIZE * 1];
3632         Arrays.fill(arrayInB, (long) 42);
3633         inB.copyTo(arrayInB);
3634         long[] arrayOut = new long[INPUTSIZE * 1];
3635         Arrays.fill(arrayOut, (long) 42);
3636         out.copyTo(arrayOut);
3637         StringBuilder message = new StringBuilder();
3638         boolean errorFound = false;
3639         for (int i = 0; i < INPUTSIZE; i++) {
3640             for (int j = 0; j < 1 ; j++) {
3641                 // Extract the inputs.
3642                 ArgumentsUlongUlongUlong args = new ArgumentsUlongUlongUlong();
3643                 args.inA = arrayInA[i];
3644                 args.inB = arrayInB[i];
3645                 // Figure out what the outputs should have been.
3646                 CoreMathVerifier.computeMax(args);
3647                 // Validate the outputs.
3648                 boolean valid = true;
3649                 if (args.out != arrayOut[i * 1 + j]) {
3650                     valid = false;
3651                 }
3652                 if (!valid) {
3653                     if (!errorFound) {
3654                         errorFound = true;
3655                         message.append("Input inA: ");
3656                         appendVariableToMessage(message, args.inA);
3657                         message.append("\n");
3658                         message.append("Input inB: ");
3659                         appendVariableToMessage(message, args.inB);
3660                         message.append("\n");
3661                         message.append("Expected output out: ");
3662                         appendVariableToMessage(message, args.out);
3663                         message.append("\n");
3664                         message.append("Actual   output out: ");
3665                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
3666                         if (args.out != arrayOut[i * 1 + j]) {
3667                             message.append(" FAIL");
3668                         }
3669                         message.append("\n");
3670                         message.append("Errors at");
3671                     }
3672                     message.append(" [");
3673                     message.append(Integer.toString(i));
3674                     message.append(", ");
3675                     message.append(Integer.toString(j));
3676                     message.append("]");
3677                 }
3678             }
3679         }
3680         assertFalse("Incorrect output for checkMaxUlongUlongUlong" +
3681                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3682     }
3683 
checkMaxUlong2Ulong2Ulong2()3684     private void checkMaxUlong2Ulong2Ulong2() {
3685         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0x6e2049a55946bc65l, false);
3686         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0x6e2049a55946bc66l, false);
3687         try {
3688             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
3689             script.set_gAllocInB(inB);
3690             script.forEach_testMaxUlong2Ulong2Ulong2(inA, out);
3691             verifyResultsMaxUlong2Ulong2Ulong2(inA, inB, out, false);
3692             out.destroy();
3693         } catch (Exception e) {
3694             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUlong2Ulong2Ulong2: " + e.toString());
3695         }
3696         try {
3697             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
3698             scriptRelaxed.set_gAllocInB(inB);
3699             scriptRelaxed.forEach_testMaxUlong2Ulong2Ulong2(inA, out);
3700             verifyResultsMaxUlong2Ulong2Ulong2(inA, inB, out, true);
3701             out.destroy();
3702         } catch (Exception e) {
3703             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUlong2Ulong2Ulong2: " + e.toString());
3704         }
3705         inA.destroy();
3706         inB.destroy();
3707     }
3708 
verifyResultsMaxUlong2Ulong2Ulong2(Allocation inA, Allocation inB, Allocation out, boolean relaxed)3709     private void verifyResultsMaxUlong2Ulong2Ulong2(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
3710         long[] arrayInA = new long[INPUTSIZE * 2];
3711         Arrays.fill(arrayInA, (long) 42);
3712         inA.copyTo(arrayInA);
3713         long[] arrayInB = new long[INPUTSIZE * 2];
3714         Arrays.fill(arrayInB, (long) 42);
3715         inB.copyTo(arrayInB);
3716         long[] arrayOut = new long[INPUTSIZE * 2];
3717         Arrays.fill(arrayOut, (long) 42);
3718         out.copyTo(arrayOut);
3719         StringBuilder message = new StringBuilder();
3720         boolean errorFound = false;
3721         for (int i = 0; i < INPUTSIZE; i++) {
3722             for (int j = 0; j < 2 ; j++) {
3723                 // Extract the inputs.
3724                 ArgumentsUlongUlongUlong args = new ArgumentsUlongUlongUlong();
3725                 args.inA = arrayInA[i * 2 + j];
3726                 args.inB = arrayInB[i * 2 + j];
3727                 // Figure out what the outputs should have been.
3728                 CoreMathVerifier.computeMax(args);
3729                 // Validate the outputs.
3730                 boolean valid = true;
3731                 if (args.out != arrayOut[i * 2 + j]) {
3732                     valid = false;
3733                 }
3734                 if (!valid) {
3735                     if (!errorFound) {
3736                         errorFound = true;
3737                         message.append("Input inA: ");
3738                         appendVariableToMessage(message, args.inA);
3739                         message.append("\n");
3740                         message.append("Input inB: ");
3741                         appendVariableToMessage(message, args.inB);
3742                         message.append("\n");
3743                         message.append("Expected output out: ");
3744                         appendVariableToMessage(message, args.out);
3745                         message.append("\n");
3746                         message.append("Actual   output out: ");
3747                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
3748                         if (args.out != arrayOut[i * 2 + j]) {
3749                             message.append(" FAIL");
3750                         }
3751                         message.append("\n");
3752                         message.append("Errors at");
3753                     }
3754                     message.append(" [");
3755                     message.append(Integer.toString(i));
3756                     message.append(", ");
3757                     message.append(Integer.toString(j));
3758                     message.append("]");
3759                 }
3760             }
3761         }
3762         assertFalse("Incorrect output for checkMaxUlong2Ulong2Ulong2" +
3763                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3764     }
3765 
checkMaxUlong3Ulong3Ulong3()3766     private void checkMaxUlong3Ulong3Ulong3() {
3767         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0xc28527c55b24be06l, false);
3768         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0xc28527c55b24be07l, false);
3769         try {
3770             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
3771             script.set_gAllocInB(inB);
3772             script.forEach_testMaxUlong3Ulong3Ulong3(inA, out);
3773             verifyResultsMaxUlong3Ulong3Ulong3(inA, inB, out, false);
3774             out.destroy();
3775         } catch (Exception e) {
3776             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUlong3Ulong3Ulong3: " + e.toString());
3777         }
3778         try {
3779             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
3780             scriptRelaxed.set_gAllocInB(inB);
3781             scriptRelaxed.forEach_testMaxUlong3Ulong3Ulong3(inA, out);
3782             verifyResultsMaxUlong3Ulong3Ulong3(inA, inB, out, true);
3783             out.destroy();
3784         } catch (Exception e) {
3785             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUlong3Ulong3Ulong3: " + e.toString());
3786         }
3787         inA.destroy();
3788         inB.destroy();
3789     }
3790 
verifyResultsMaxUlong3Ulong3Ulong3(Allocation inA, Allocation inB, Allocation out, boolean relaxed)3791     private void verifyResultsMaxUlong3Ulong3Ulong3(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
3792         long[] arrayInA = new long[INPUTSIZE * 4];
3793         Arrays.fill(arrayInA, (long) 42);
3794         inA.copyTo(arrayInA);
3795         long[] arrayInB = new long[INPUTSIZE * 4];
3796         Arrays.fill(arrayInB, (long) 42);
3797         inB.copyTo(arrayInB);
3798         long[] arrayOut = new long[INPUTSIZE * 4];
3799         Arrays.fill(arrayOut, (long) 42);
3800         out.copyTo(arrayOut);
3801         StringBuilder message = new StringBuilder();
3802         boolean errorFound = false;
3803         for (int i = 0; i < INPUTSIZE; i++) {
3804             for (int j = 0; j < 3 ; j++) {
3805                 // Extract the inputs.
3806                 ArgumentsUlongUlongUlong args = new ArgumentsUlongUlongUlong();
3807                 args.inA = arrayInA[i * 4 + j];
3808                 args.inB = arrayInB[i * 4 + j];
3809                 // Figure out what the outputs should have been.
3810                 CoreMathVerifier.computeMax(args);
3811                 // Validate the outputs.
3812                 boolean valid = true;
3813                 if (args.out != arrayOut[i * 4 + j]) {
3814                     valid = false;
3815                 }
3816                 if (!valid) {
3817                     if (!errorFound) {
3818                         errorFound = true;
3819                         message.append("Input inA: ");
3820                         appendVariableToMessage(message, args.inA);
3821                         message.append("\n");
3822                         message.append("Input inB: ");
3823                         appendVariableToMessage(message, args.inB);
3824                         message.append("\n");
3825                         message.append("Expected output out: ");
3826                         appendVariableToMessage(message, args.out);
3827                         message.append("\n");
3828                         message.append("Actual   output out: ");
3829                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
3830                         if (args.out != arrayOut[i * 4 + j]) {
3831                             message.append(" FAIL");
3832                         }
3833                         message.append("\n");
3834                         message.append("Errors at");
3835                     }
3836                     message.append(" [");
3837                     message.append(Integer.toString(i));
3838                     message.append(", ");
3839                     message.append(Integer.toString(j));
3840                     message.append("]");
3841                 }
3842             }
3843         }
3844         assertFalse("Incorrect output for checkMaxUlong3Ulong3Ulong3" +
3845                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3846     }
3847 
checkMaxUlong4Ulong4Ulong4()3848     private void checkMaxUlong4Ulong4Ulong4() {
3849         Allocation inA = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x16ea05e55d02bfa7l, false);
3850         Allocation inB = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x16ea05e55d02bfa8l, false);
3851         try {
3852             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
3853             script.set_gAllocInB(inB);
3854             script.forEach_testMaxUlong4Ulong4Ulong4(inA, out);
3855             verifyResultsMaxUlong4Ulong4Ulong4(inA, inB, out, false);
3856             out.destroy();
3857         } catch (Exception e) {
3858             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUlong4Ulong4Ulong4: " + e.toString());
3859         }
3860         try {
3861             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
3862             scriptRelaxed.set_gAllocInB(inB);
3863             scriptRelaxed.forEach_testMaxUlong4Ulong4Ulong4(inA, out);
3864             verifyResultsMaxUlong4Ulong4Ulong4(inA, inB, out, true);
3865             out.destroy();
3866         } catch (Exception e) {
3867             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMaxUlong4Ulong4Ulong4: " + e.toString());
3868         }
3869         inA.destroy();
3870         inB.destroy();
3871     }
3872 
verifyResultsMaxUlong4Ulong4Ulong4(Allocation inA, Allocation inB, Allocation out, boolean relaxed)3873     private void verifyResultsMaxUlong4Ulong4Ulong4(Allocation inA, Allocation inB, Allocation out, boolean relaxed) {
3874         long[] arrayInA = new long[INPUTSIZE * 4];
3875         Arrays.fill(arrayInA, (long) 42);
3876         inA.copyTo(arrayInA);
3877         long[] arrayInB = new long[INPUTSIZE * 4];
3878         Arrays.fill(arrayInB, (long) 42);
3879         inB.copyTo(arrayInB);
3880         long[] arrayOut = new long[INPUTSIZE * 4];
3881         Arrays.fill(arrayOut, (long) 42);
3882         out.copyTo(arrayOut);
3883         StringBuilder message = new StringBuilder();
3884         boolean errorFound = false;
3885         for (int i = 0; i < INPUTSIZE; i++) {
3886             for (int j = 0; j < 4 ; j++) {
3887                 // Extract the inputs.
3888                 ArgumentsUlongUlongUlong args = new ArgumentsUlongUlongUlong();
3889                 args.inA = arrayInA[i * 4 + j];
3890                 args.inB = arrayInB[i * 4 + j];
3891                 // Figure out what the outputs should have been.
3892                 CoreMathVerifier.computeMax(args);
3893                 // Validate the outputs.
3894                 boolean valid = true;
3895                 if (args.out != arrayOut[i * 4 + j]) {
3896                     valid = false;
3897                 }
3898                 if (!valid) {
3899                     if (!errorFound) {
3900                         errorFound = true;
3901                         message.append("Input inA: ");
3902                         appendVariableToMessage(message, args.inA);
3903                         message.append("\n");
3904                         message.append("Input inB: ");
3905                         appendVariableToMessage(message, args.inB);
3906                         message.append("\n");
3907                         message.append("Expected output out: ");
3908                         appendVariableToMessage(message, args.out);
3909                         message.append("\n");
3910                         message.append("Actual   output out: ");
3911                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
3912                         if (args.out != arrayOut[i * 4 + j]) {
3913                             message.append(" FAIL");
3914                         }
3915                         message.append("\n");
3916                         message.append("Errors at");
3917                     }
3918                     message.append(" [");
3919                     message.append(Integer.toString(i));
3920                     message.append(", ");
3921                     message.append(Integer.toString(j));
3922                     message.append("]");
3923                 }
3924             }
3925         }
3926         assertFalse("Incorrect output for checkMaxUlong4Ulong4Ulong4" +
3927                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
3928     }
3929 
testMax()3930     public void testMax() {
3931         checkMaxFloatFloatFloat();
3932         checkMaxFloat2Float2Float2();
3933         checkMaxFloat3Float3Float3();
3934         checkMaxFloat4Float4Float4();
3935         checkMaxHalfHalfHalf();
3936         checkMaxHalf2Half2Half2();
3937         checkMaxHalf3Half3Half3();
3938         checkMaxHalf4Half4Half4();
3939         checkMaxFloat2FloatFloat2();
3940         checkMaxFloat3FloatFloat3();
3941         checkMaxFloat4FloatFloat4();
3942         checkMaxHalf2HalfHalf2();
3943         checkMaxHalf3HalfHalf3();
3944         checkMaxHalf4HalfHalf4();
3945         checkMaxCharCharChar();
3946         checkMaxChar2Char2Char2();
3947         checkMaxChar3Char3Char3();
3948         checkMaxChar4Char4Char4();
3949         checkMaxUcharUcharUchar();
3950         checkMaxUchar2Uchar2Uchar2();
3951         checkMaxUchar3Uchar3Uchar3();
3952         checkMaxUchar4Uchar4Uchar4();
3953         checkMaxShortShortShort();
3954         checkMaxShort2Short2Short2();
3955         checkMaxShort3Short3Short3();
3956         checkMaxShort4Short4Short4();
3957         checkMaxUshortUshortUshort();
3958         checkMaxUshort2Ushort2Ushort2();
3959         checkMaxUshort3Ushort3Ushort3();
3960         checkMaxUshort4Ushort4Ushort4();
3961         checkMaxIntIntInt();
3962         checkMaxInt2Int2Int2();
3963         checkMaxInt3Int3Int3();
3964         checkMaxInt4Int4Int4();
3965         checkMaxUintUintUint();
3966         checkMaxUint2Uint2Uint2();
3967         checkMaxUint3Uint3Uint3();
3968         checkMaxUint4Uint4Uint4();
3969         checkMaxLongLongLong();
3970         checkMaxLong2Long2Long2();
3971         checkMaxLong3Long3Long3();
3972         checkMaxLong4Long4Long4();
3973         checkMaxUlongUlongUlong();
3974         checkMaxUlong2Ulong2Ulong2();
3975         checkMaxUlong3Ulong3Ulong3();
3976         checkMaxUlong4Ulong4Ulong4();
3977     }
3978 }
3979