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 TestMix extends RSBaseCompute {
29 
30     private ScriptC_TestMix script;
31     private ScriptC_TestMixRelaxed scriptRelaxed;
32 
33     @Override
setUp()34     protected void setUp() throws Exception {
35         super.setUp();
36         script = new ScriptC_TestMix(mRS);
37         scriptRelaxed = new ScriptC_TestMixRelaxed(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 ArgumentsFloatFloatFloatFloat {
48         public float inStart;
49         public float inStop;
50         public float inFraction;
51         public Target.Floaty out;
52     }
53 
checkMixFloatFloatFloatFloat()54     private void checkMixFloatFloatFloatFloat() {
55         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x9f4beff6471d6db1l, false);
56         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x6ede0b88b4422e8fl, false);
57         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x6d2f014ec6a51d9fl, false);
58         try {
59             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
60             script.set_gAllocInStop(inStop);
61             script.set_gAllocInFraction(inFraction);
62             script.forEach_testMixFloatFloatFloatFloat(inStart, out);
63             verifyResultsMixFloatFloatFloatFloat(inStart, inStop, inFraction, out, false);
64             out.destroy();
65         } catch (Exception e) {
66             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloatFloatFloatFloat: " + e.toString());
67         }
68         try {
69             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
70             scriptRelaxed.set_gAllocInStop(inStop);
71             scriptRelaxed.set_gAllocInFraction(inFraction);
72             scriptRelaxed.forEach_testMixFloatFloatFloatFloat(inStart, out);
73             verifyResultsMixFloatFloatFloatFloat(inStart, inStop, inFraction, out, true);
74             out.destroy();
75         } catch (Exception e) {
76             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloatFloatFloatFloat: " + e.toString());
77         }
78         inStart.destroy();
79         inStop.destroy();
80         inFraction.destroy();
81     }
82 
verifyResultsMixFloatFloatFloatFloat(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)83     private void verifyResultsMixFloatFloatFloatFloat(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
84         float[] arrayInStart = new float[INPUTSIZE * 1];
85         Arrays.fill(arrayInStart, (float) 42);
86         inStart.copyTo(arrayInStart);
87         float[] arrayInStop = new float[INPUTSIZE * 1];
88         Arrays.fill(arrayInStop, (float) 42);
89         inStop.copyTo(arrayInStop);
90         float[] arrayInFraction = new float[INPUTSIZE * 1];
91         Arrays.fill(arrayInFraction, (float) 42);
92         inFraction.copyTo(arrayInFraction);
93         float[] arrayOut = new float[INPUTSIZE * 1];
94         Arrays.fill(arrayOut, (float) 42);
95         out.copyTo(arrayOut);
96         StringBuilder message = new StringBuilder();
97         boolean errorFound = false;
98         for (int i = 0; i < INPUTSIZE; i++) {
99             for (int j = 0; j < 1 ; j++) {
100                 // Extract the inputs.
101                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
102                 args.inStart = arrayInStart[i];
103                 args.inStop = arrayInStop[i];
104                 args.inFraction = arrayInFraction[i];
105                 // Figure out what the outputs should have been.
106                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
107                 CoreMathVerifier.computeMix(args, target);
108                 // Validate the outputs.
109                 boolean valid = true;
110                 if (!args.out.couldBe(arrayOut[i * 1 + j])) {
111                     valid = false;
112                 }
113                 if (!valid) {
114                     if (!errorFound) {
115                         errorFound = true;
116                         message.append("Input inStart: ");
117                         appendVariableToMessage(message, args.inStart);
118                         message.append("\n");
119                         message.append("Input inStop: ");
120                         appendVariableToMessage(message, args.inStop);
121                         message.append("\n");
122                         message.append("Input inFraction: ");
123                         appendVariableToMessage(message, args.inFraction);
124                         message.append("\n");
125                         message.append("Expected output out: ");
126                         appendVariableToMessage(message, args.out);
127                         message.append("\n");
128                         message.append("Actual   output out: ");
129                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
130                         if (!args.out.couldBe(arrayOut[i * 1 + j])) {
131                             message.append(" FAIL");
132                         }
133                         message.append("\n");
134                         message.append("Errors at");
135                     }
136                     message.append(" [");
137                     message.append(Integer.toString(i));
138                     message.append(", ");
139                     message.append(Integer.toString(j));
140                     message.append("]");
141                 }
142             }
143         }
144         assertFalse("Incorrect output for checkMixFloatFloatFloatFloat" +
145                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
146     }
147 
checkMixFloat2Float2Float2Float2()148     private void checkMixFloat2Float2Float2Float2() {
149         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x45502e8f0a2d9ce9l, false);
150         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xba2b8a035395e837l, false);
151         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xe56bef3c621e0ac7l, false);
152         try {
153             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
154             script.set_gAllocInStop(inStop);
155             script.set_gAllocInFraction(inFraction);
156             script.forEach_testMixFloat2Float2Float2Float2(inStart, out);
157             verifyResultsMixFloat2Float2Float2Float2(inStart, inStop, inFraction, out, false);
158             out.destroy();
159         } catch (Exception e) {
160             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2Float2Float2: " + e.toString());
161         }
162         try {
163             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
164             scriptRelaxed.set_gAllocInStop(inStop);
165             scriptRelaxed.set_gAllocInFraction(inFraction);
166             scriptRelaxed.forEach_testMixFloat2Float2Float2Float2(inStart, out);
167             verifyResultsMixFloat2Float2Float2Float2(inStart, inStop, inFraction, out, true);
168             out.destroy();
169         } catch (Exception e) {
170             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2Float2Float2: " + e.toString());
171         }
172         inStart.destroy();
173         inStop.destroy();
174         inFraction.destroy();
175     }
176 
verifyResultsMixFloat2Float2Float2Float2(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)177     private void verifyResultsMixFloat2Float2Float2Float2(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
178         float[] arrayInStart = new float[INPUTSIZE * 2];
179         Arrays.fill(arrayInStart, (float) 42);
180         inStart.copyTo(arrayInStart);
181         float[] arrayInStop = new float[INPUTSIZE * 2];
182         Arrays.fill(arrayInStop, (float) 42);
183         inStop.copyTo(arrayInStop);
184         float[] arrayInFraction = new float[INPUTSIZE * 2];
185         Arrays.fill(arrayInFraction, (float) 42);
186         inFraction.copyTo(arrayInFraction);
187         float[] arrayOut = new float[INPUTSIZE * 2];
188         Arrays.fill(arrayOut, (float) 42);
189         out.copyTo(arrayOut);
190         StringBuilder message = new StringBuilder();
191         boolean errorFound = false;
192         for (int i = 0; i < INPUTSIZE; i++) {
193             for (int j = 0; j < 2 ; j++) {
194                 // Extract the inputs.
195                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
196                 args.inStart = arrayInStart[i * 2 + j];
197                 args.inStop = arrayInStop[i * 2 + j];
198                 args.inFraction = arrayInFraction[i * 2 + j];
199                 // Figure out what the outputs should have been.
200                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
201                 CoreMathVerifier.computeMix(args, target);
202                 // Validate the outputs.
203                 boolean valid = true;
204                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
205                     valid = false;
206                 }
207                 if (!valid) {
208                     if (!errorFound) {
209                         errorFound = true;
210                         message.append("Input inStart: ");
211                         appendVariableToMessage(message, args.inStart);
212                         message.append("\n");
213                         message.append("Input inStop: ");
214                         appendVariableToMessage(message, args.inStop);
215                         message.append("\n");
216                         message.append("Input inFraction: ");
217                         appendVariableToMessage(message, args.inFraction);
218                         message.append("\n");
219                         message.append("Expected output out: ");
220                         appendVariableToMessage(message, args.out);
221                         message.append("\n");
222                         message.append("Actual   output out: ");
223                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
224                         if (!args.out.couldBe(arrayOut[i * 2 + j])) {
225                             message.append(" FAIL");
226                         }
227                         message.append("\n");
228                         message.append("Errors at");
229                     }
230                     message.append(" [");
231                     message.append(Integer.toString(i));
232                     message.append(", ");
233                     message.append(Integer.toString(j));
234                     message.append("]");
235                 }
236             }
237         }
238         assertFalse("Incorrect output for checkMixFloat2Float2Float2Float2" +
239                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
240     }
241 
checkMixFloat3Float3Float3Float3()242     private void checkMixFloat3Float3Float3Float3() {
243         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xeb4701726b009c5l, false);
244         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x9b21f6b3249ee4cbl, false);
245         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xf15862eab0d4f51bl, false);
246         try {
247             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
248             script.set_gAllocInStop(inStop);
249             script.set_gAllocInFraction(inFraction);
250             script.forEach_testMixFloat3Float3Float3Float3(inStart, out);
251             verifyResultsMixFloat3Float3Float3Float3(inStart, inStop, inFraction, out, false);
252             out.destroy();
253         } catch (Exception e) {
254             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3Float3Float3: " + e.toString());
255         }
256         try {
257             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
258             scriptRelaxed.set_gAllocInStop(inStop);
259             scriptRelaxed.set_gAllocInFraction(inFraction);
260             scriptRelaxed.forEach_testMixFloat3Float3Float3Float3(inStart, out);
261             verifyResultsMixFloat3Float3Float3Float3(inStart, inStop, inFraction, out, true);
262             out.destroy();
263         } catch (Exception e) {
264             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3Float3Float3: " + e.toString());
265         }
266         inStart.destroy();
267         inStop.destroy();
268         inFraction.destroy();
269     }
270 
verifyResultsMixFloat3Float3Float3Float3(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)271     private void verifyResultsMixFloat3Float3Float3Float3(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
272         float[] arrayInStart = new float[INPUTSIZE * 4];
273         Arrays.fill(arrayInStart, (float) 42);
274         inStart.copyTo(arrayInStart);
275         float[] arrayInStop = new float[INPUTSIZE * 4];
276         Arrays.fill(arrayInStop, (float) 42);
277         inStop.copyTo(arrayInStop);
278         float[] arrayInFraction = new float[INPUTSIZE * 4];
279         Arrays.fill(arrayInFraction, (float) 42);
280         inFraction.copyTo(arrayInFraction);
281         float[] arrayOut = new float[INPUTSIZE * 4];
282         Arrays.fill(arrayOut, (float) 42);
283         out.copyTo(arrayOut);
284         StringBuilder message = new StringBuilder();
285         boolean errorFound = false;
286         for (int i = 0; i < INPUTSIZE; i++) {
287             for (int j = 0; j < 3 ; j++) {
288                 // Extract the inputs.
289                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
290                 args.inStart = arrayInStart[i * 4 + j];
291                 args.inStop = arrayInStop[i * 4 + j];
292                 args.inFraction = arrayInFraction[i * 4 + j];
293                 // Figure out what the outputs should have been.
294                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
295                 CoreMathVerifier.computeMix(args, target);
296                 // Validate the outputs.
297                 boolean valid = true;
298                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
299                     valid = false;
300                 }
301                 if (!valid) {
302                     if (!errorFound) {
303                         errorFound = true;
304                         message.append("Input inStart: ");
305                         appendVariableToMessage(message, args.inStart);
306                         message.append("\n");
307                         message.append("Input inStop: ");
308                         appendVariableToMessage(message, args.inStop);
309                         message.append("\n");
310                         message.append("Input inFraction: ");
311                         appendVariableToMessage(message, args.inFraction);
312                         message.append("\n");
313                         message.append("Expected output out: ");
314                         appendVariableToMessage(message, args.out);
315                         message.append("\n");
316                         message.append("Actual   output out: ");
317                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
318                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
319                             message.append(" FAIL");
320                         }
321                         message.append("\n");
322                         message.append("Errors at");
323                     }
324                     message.append(" [");
325                     message.append(Integer.toString(i));
326                     message.append(", ");
327                     message.append(Integer.toString(j));
328                     message.append("]");
329                 }
330             }
331         }
332         assertFalse("Incorrect output for checkMixFloat3Float3Float3Float3" +
333                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
334     }
335 
checkMixFloat4Float4Float4Float4()336     private void checkMixFloat4Float4Float4Float4() {
337         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xd818b19f433276a1l, false);
338         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x7c186362f5a7e15fl, false);
339         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xfd44d698ff8bdf6fl, false);
340         try {
341             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
342             script.set_gAllocInStop(inStop);
343             script.set_gAllocInFraction(inFraction);
344             script.forEach_testMixFloat4Float4Float4Float4(inStart, out);
345             verifyResultsMixFloat4Float4Float4Float4(inStart, inStop, inFraction, out, false);
346             out.destroy();
347         } catch (Exception e) {
348             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4Float4Float4: " + e.toString());
349         }
350         try {
351             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
352             scriptRelaxed.set_gAllocInStop(inStop);
353             scriptRelaxed.set_gAllocInFraction(inFraction);
354             scriptRelaxed.forEach_testMixFloat4Float4Float4Float4(inStart, out);
355             verifyResultsMixFloat4Float4Float4Float4(inStart, inStop, inFraction, out, true);
356             out.destroy();
357         } catch (Exception e) {
358             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4Float4Float4: " + e.toString());
359         }
360         inStart.destroy();
361         inStop.destroy();
362         inFraction.destroy();
363     }
364 
verifyResultsMixFloat4Float4Float4Float4(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)365     private void verifyResultsMixFloat4Float4Float4Float4(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
366         float[] arrayInStart = new float[INPUTSIZE * 4];
367         Arrays.fill(arrayInStart, (float) 42);
368         inStart.copyTo(arrayInStart);
369         float[] arrayInStop = new float[INPUTSIZE * 4];
370         Arrays.fill(arrayInStop, (float) 42);
371         inStop.copyTo(arrayInStop);
372         float[] arrayInFraction = new float[INPUTSIZE * 4];
373         Arrays.fill(arrayInFraction, (float) 42);
374         inFraction.copyTo(arrayInFraction);
375         float[] arrayOut = new float[INPUTSIZE * 4];
376         Arrays.fill(arrayOut, (float) 42);
377         out.copyTo(arrayOut);
378         StringBuilder message = new StringBuilder();
379         boolean errorFound = false;
380         for (int i = 0; i < INPUTSIZE; i++) {
381             for (int j = 0; j < 4 ; j++) {
382                 // Extract the inputs.
383                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
384                 args.inStart = arrayInStart[i * 4 + j];
385                 args.inStop = arrayInStop[i * 4 + j];
386                 args.inFraction = arrayInFraction[i * 4 + j];
387                 // Figure out what the outputs should have been.
388                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
389                 CoreMathVerifier.computeMix(args, target);
390                 // Validate the outputs.
391                 boolean valid = true;
392                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
393                     valid = false;
394                 }
395                 if (!valid) {
396                     if (!errorFound) {
397                         errorFound = true;
398                         message.append("Input inStart: ");
399                         appendVariableToMessage(message, args.inStart);
400                         message.append("\n");
401                         message.append("Input inStop: ");
402                         appendVariableToMessage(message, args.inStop);
403                         message.append("\n");
404                         message.append("Input inFraction: ");
405                         appendVariableToMessage(message, args.inFraction);
406                         message.append("\n");
407                         message.append("Expected output out: ");
408                         appendVariableToMessage(message, args.out);
409                         message.append("\n");
410                         message.append("Actual   output out: ");
411                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
412                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
413                             message.append(" FAIL");
414                         }
415                         message.append("\n");
416                         message.append("Errors at");
417                     }
418                     message.append(" [");
419                     message.append(Integer.toString(i));
420                     message.append(", ");
421                     message.append(Integer.toString(j));
422                     message.append("]");
423                 }
424             }
425         }
426         assertFalse("Incorrect output for checkMixFloat4Float4Float4Float4" +
427                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
428     }
429 
430     public class ArgumentsHalfHalfHalfHalf {
431         public short inStart;
432         public double inStartDouble;
433         public short inStop;
434         public double inStopDouble;
435         public short inFraction;
436         public double inFractionDouble;
437         public Target.Floaty out;
438     }
439 
checkMixHalfHalfHalfHalf()440     private void checkMixHalfHalfHalfHalf() {
441         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x3dea3b1da5c04055l, false);
442         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x764b3fabc69b07bl, false);
443         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x3115d5834936a9cbl, false);
444         try {
445             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
446             script.set_gAllocInStop(inStop);
447             script.set_gAllocInFraction(inFraction);
448             script.forEach_testMixHalfHalfHalfHalf(inStart, out);
449             verifyResultsMixHalfHalfHalfHalf(inStart, inStop, inFraction, out, false);
450             out.destroy();
451         } catch (Exception e) {
452             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalfHalfHalfHalf: " + e.toString());
453         }
454         try {
455             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
456             scriptRelaxed.set_gAllocInStop(inStop);
457             scriptRelaxed.set_gAllocInFraction(inFraction);
458             scriptRelaxed.forEach_testMixHalfHalfHalfHalf(inStart, out);
459             verifyResultsMixHalfHalfHalfHalf(inStart, inStop, inFraction, out, true);
460             out.destroy();
461         } catch (Exception e) {
462             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalfHalfHalfHalf: " + e.toString());
463         }
464         inStart.destroy();
465         inStop.destroy();
466         inFraction.destroy();
467     }
468 
verifyResultsMixHalfHalfHalfHalf(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)469     private void verifyResultsMixHalfHalfHalfHalf(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
470         short[] arrayInStart = new short[INPUTSIZE * 1];
471         Arrays.fill(arrayInStart, (short) 42);
472         inStart.copyTo(arrayInStart);
473         short[] arrayInStop = new short[INPUTSIZE * 1];
474         Arrays.fill(arrayInStop, (short) 42);
475         inStop.copyTo(arrayInStop);
476         short[] arrayInFraction = new short[INPUTSIZE * 1];
477         Arrays.fill(arrayInFraction, (short) 42);
478         inFraction.copyTo(arrayInFraction);
479         short[] arrayOut = new short[INPUTSIZE * 1];
480         Arrays.fill(arrayOut, (short) 42);
481         out.copyTo(arrayOut);
482         StringBuilder message = new StringBuilder();
483         boolean errorFound = false;
484         for (int i = 0; i < INPUTSIZE; i++) {
485             for (int j = 0; j < 1 ; j++) {
486                 // Extract the inputs.
487                 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf();
488                 args.inStart = arrayInStart[i];
489                 args.inStartDouble = Float16Utils.convertFloat16ToDouble(args.inStart);
490                 args.inStop = arrayInStop[i];
491                 args.inStopDouble = Float16Utils.convertFloat16ToDouble(args.inStop);
492                 args.inFraction = arrayInFraction[i];
493                 args.inFractionDouble = Float16Utils.convertFloat16ToDouble(args.inFraction);
494                 // Figure out what the outputs should have been.
495                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
496                 CoreMathVerifier.computeMix(args, target);
497                 // Validate the outputs.
498                 boolean valid = true;
499                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
500                     valid = false;
501                 }
502                 if (!valid) {
503                     if (!errorFound) {
504                         errorFound = true;
505                         message.append("Input inStart: ");
506                         appendVariableToMessage(message, args.inStart);
507                         message.append("\n");
508                         message.append("Input inStop: ");
509                         appendVariableToMessage(message, args.inStop);
510                         message.append("\n");
511                         message.append("Input inFraction: ");
512                         appendVariableToMessage(message, args.inFraction);
513                         message.append("\n");
514                         message.append("Expected output out: ");
515                         appendVariableToMessage(message, args.out);
516                         message.append("\n");
517                         message.append("Actual   output out: ");
518                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
519                         message.append("\n");
520                         message.append("Actual   output out (in double): ");
521                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]));
522                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
523                             message.append(" FAIL");
524                         }
525                         message.append("\n");
526                         message.append("Errors at");
527                     }
528                     message.append(" [");
529                     message.append(Integer.toString(i));
530                     message.append(", ");
531                     message.append(Integer.toString(j));
532                     message.append("]");
533                 }
534             }
535         }
536         assertFalse("Incorrect output for checkMixHalfHalfHalfHalf" +
537                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
538     }
539 
checkMixHalf2Half2Half2Half2()540     private void checkMixHalf2Half2Half2Half2() {
541         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x4266268b2fe5c049l, false);
542         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x3720249e07114257l, false);
543         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xd354aab305b09ae7l, false);
544         try {
545             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
546             script.set_gAllocInStop(inStop);
547             script.set_gAllocInFraction(inFraction);
548             script.forEach_testMixHalf2Half2Half2Half2(inStart, out);
549             verifyResultsMixHalf2Half2Half2Half2(inStart, inStop, inFraction, out, false);
550             out.destroy();
551         } catch (Exception e) {
552             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf2Half2Half2Half2: " + e.toString());
553         }
554         try {
555             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
556             scriptRelaxed.set_gAllocInStop(inStop);
557             scriptRelaxed.set_gAllocInFraction(inFraction);
558             scriptRelaxed.forEach_testMixHalf2Half2Half2Half2(inStart, out);
559             verifyResultsMixHalf2Half2Half2Half2(inStart, inStop, inFraction, out, true);
560             out.destroy();
561         } catch (Exception e) {
562             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf2Half2Half2Half2: " + e.toString());
563         }
564         inStart.destroy();
565         inStop.destroy();
566         inFraction.destroy();
567     }
568 
verifyResultsMixHalf2Half2Half2Half2(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)569     private void verifyResultsMixHalf2Half2Half2Half2(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
570         short[] arrayInStart = new short[INPUTSIZE * 2];
571         Arrays.fill(arrayInStart, (short) 42);
572         inStart.copyTo(arrayInStart);
573         short[] arrayInStop = new short[INPUTSIZE * 2];
574         Arrays.fill(arrayInStop, (short) 42);
575         inStop.copyTo(arrayInStop);
576         short[] arrayInFraction = new short[INPUTSIZE * 2];
577         Arrays.fill(arrayInFraction, (short) 42);
578         inFraction.copyTo(arrayInFraction);
579         short[] arrayOut = new short[INPUTSIZE * 2];
580         Arrays.fill(arrayOut, (short) 42);
581         out.copyTo(arrayOut);
582         StringBuilder message = new StringBuilder();
583         boolean errorFound = false;
584         for (int i = 0; i < INPUTSIZE; i++) {
585             for (int j = 0; j < 2 ; j++) {
586                 // Extract the inputs.
587                 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf();
588                 args.inStart = arrayInStart[i * 2 + j];
589                 args.inStartDouble = Float16Utils.convertFloat16ToDouble(args.inStart);
590                 args.inStop = arrayInStop[i * 2 + j];
591                 args.inStopDouble = Float16Utils.convertFloat16ToDouble(args.inStop);
592                 args.inFraction = arrayInFraction[i * 2 + j];
593                 args.inFractionDouble = Float16Utils.convertFloat16ToDouble(args.inFraction);
594                 // Figure out what the outputs should have been.
595                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
596                 CoreMathVerifier.computeMix(args, target);
597                 // Validate the outputs.
598                 boolean valid = true;
599                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
600                     valid = false;
601                 }
602                 if (!valid) {
603                     if (!errorFound) {
604                         errorFound = true;
605                         message.append("Input inStart: ");
606                         appendVariableToMessage(message, args.inStart);
607                         message.append("\n");
608                         message.append("Input inStop: ");
609                         appendVariableToMessage(message, args.inStop);
610                         message.append("\n");
611                         message.append("Input inFraction: ");
612                         appendVariableToMessage(message, args.inFraction);
613                         message.append("\n");
614                         message.append("Expected output out: ");
615                         appendVariableToMessage(message, args.out);
616                         message.append("\n");
617                         message.append("Actual   output out: ");
618                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
619                         message.append("\n");
620                         message.append("Actual   output out (in double): ");
621                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]));
622                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
623                             message.append(" FAIL");
624                         }
625                         message.append("\n");
626                         message.append("Errors at");
627                     }
628                     message.append(" [");
629                     message.append(Integer.toString(i));
630                     message.append(", ");
631                     message.append(Integer.toString(j));
632                     message.append("]");
633                 }
634             }
635         }
636         assertFalse("Incorrect output for checkMixHalf2Half2Half2Half2" +
637                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
638     }
639 
checkMixHalf3Half3Half3Half3()640     private void checkMixHalf3Half3Half3Half3() {
641         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x9b13445c25babc91l, false);
642         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xf1bef5aecb4bcb2fl, false);
643         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x60d7d360187ca83fl, false);
644         try {
645             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
646             script.set_gAllocInStop(inStop);
647             script.set_gAllocInFraction(inFraction);
648             script.forEach_testMixHalf3Half3Half3Half3(inStart, out);
649             verifyResultsMixHalf3Half3Half3Half3(inStart, inStop, inFraction, out, false);
650             out.destroy();
651         } catch (Exception e) {
652             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf3Half3Half3Half3: " + e.toString());
653         }
654         try {
655             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
656             scriptRelaxed.set_gAllocInStop(inStop);
657             scriptRelaxed.set_gAllocInFraction(inFraction);
658             scriptRelaxed.forEach_testMixHalf3Half3Half3Half3(inStart, out);
659             verifyResultsMixHalf3Half3Half3Half3(inStart, inStop, inFraction, out, true);
660             out.destroy();
661         } catch (Exception e) {
662             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf3Half3Half3Half3: " + e.toString());
663         }
664         inStart.destroy();
665         inStop.destroy();
666         inFraction.destroy();
667     }
668 
verifyResultsMixHalf3Half3Half3Half3(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)669     private void verifyResultsMixHalf3Half3Half3Half3(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
670         short[] arrayInStart = new short[INPUTSIZE * 4];
671         Arrays.fill(arrayInStart, (short) 42);
672         inStart.copyTo(arrayInStart);
673         short[] arrayInStop = new short[INPUTSIZE * 4];
674         Arrays.fill(arrayInStop, (short) 42);
675         inStop.copyTo(arrayInStop);
676         short[] arrayInFraction = new short[INPUTSIZE * 4];
677         Arrays.fill(arrayInFraction, (short) 42);
678         inFraction.copyTo(arrayInFraction);
679         short[] arrayOut = new short[INPUTSIZE * 4];
680         Arrays.fill(arrayOut, (short) 42);
681         out.copyTo(arrayOut);
682         StringBuilder message = new StringBuilder();
683         boolean errorFound = false;
684         for (int i = 0; i < INPUTSIZE; i++) {
685             for (int j = 0; j < 3 ; j++) {
686                 // Extract the inputs.
687                 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf();
688                 args.inStart = arrayInStart[i * 4 + j];
689                 args.inStartDouble = Float16Utils.convertFloat16ToDouble(args.inStart);
690                 args.inStop = arrayInStop[i * 4 + j];
691                 args.inStopDouble = Float16Utils.convertFloat16ToDouble(args.inStop);
692                 args.inFraction = arrayInFraction[i * 4 + j];
693                 args.inFractionDouble = Float16Utils.convertFloat16ToDouble(args.inFraction);
694                 // Figure out what the outputs should have been.
695                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
696                 CoreMathVerifier.computeMix(args, target);
697                 // Validate the outputs.
698                 boolean valid = true;
699                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
700                     valid = false;
701                 }
702                 if (!valid) {
703                     if (!errorFound) {
704                         errorFound = true;
705                         message.append("Input inStart: ");
706                         appendVariableToMessage(message, args.inStart);
707                         message.append("\n");
708                         message.append("Input inStop: ");
709                         appendVariableToMessage(message, args.inStop);
710                         message.append("\n");
711                         message.append("Input inFraction: ");
712                         appendVariableToMessage(message, args.inFraction);
713                         message.append("\n");
714                         message.append("Expected output out: ");
715                         appendVariableToMessage(message, args.out);
716                         message.append("\n");
717                         message.append("Actual   output out: ");
718                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
719                         message.append("\n");
720                         message.append("Actual   output out (in double): ");
721                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
722                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
723                             message.append(" FAIL");
724                         }
725                         message.append("\n");
726                         message.append("Errors at");
727                     }
728                     message.append(" [");
729                     message.append(Integer.toString(i));
730                     message.append(", ");
731                     message.append(Integer.toString(j));
732                     message.append("]");
733                 }
734             }
735         }
736         assertFalse("Incorrect output for checkMixHalf3Half3Half3Half3" +
737                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
738     }
739 
checkMixHalf4Half4Half4Half4()740     private void checkMixHalf4Half4Half4Half4() {
741         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xf3c0622d1b8fb8d9l, false);
742         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xac5dc6bf8f865407l, false);
743         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xee5afc0d2b48b597l, false);
744         try {
745             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
746             script.set_gAllocInStop(inStop);
747             script.set_gAllocInFraction(inFraction);
748             script.forEach_testMixHalf4Half4Half4Half4(inStart, out);
749             verifyResultsMixHalf4Half4Half4Half4(inStart, inStop, inFraction, out, false);
750             out.destroy();
751         } catch (Exception e) {
752             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf4Half4Half4Half4: " + e.toString());
753         }
754         try {
755             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
756             scriptRelaxed.set_gAllocInStop(inStop);
757             scriptRelaxed.set_gAllocInFraction(inFraction);
758             scriptRelaxed.forEach_testMixHalf4Half4Half4Half4(inStart, out);
759             verifyResultsMixHalf4Half4Half4Half4(inStart, inStop, inFraction, out, true);
760             out.destroy();
761         } catch (Exception e) {
762             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf4Half4Half4Half4: " + e.toString());
763         }
764         inStart.destroy();
765         inStop.destroy();
766         inFraction.destroy();
767     }
768 
verifyResultsMixHalf4Half4Half4Half4(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)769     private void verifyResultsMixHalf4Half4Half4Half4(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
770         short[] arrayInStart = new short[INPUTSIZE * 4];
771         Arrays.fill(arrayInStart, (short) 42);
772         inStart.copyTo(arrayInStart);
773         short[] arrayInStop = new short[INPUTSIZE * 4];
774         Arrays.fill(arrayInStop, (short) 42);
775         inStop.copyTo(arrayInStop);
776         short[] arrayInFraction = new short[INPUTSIZE * 4];
777         Arrays.fill(arrayInFraction, (short) 42);
778         inFraction.copyTo(arrayInFraction);
779         short[] arrayOut = new short[INPUTSIZE * 4];
780         Arrays.fill(arrayOut, (short) 42);
781         out.copyTo(arrayOut);
782         StringBuilder message = new StringBuilder();
783         boolean errorFound = false;
784         for (int i = 0; i < INPUTSIZE; i++) {
785             for (int j = 0; j < 4 ; j++) {
786                 // Extract the inputs.
787                 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf();
788                 args.inStart = arrayInStart[i * 4 + j];
789                 args.inStartDouble = Float16Utils.convertFloat16ToDouble(args.inStart);
790                 args.inStop = arrayInStop[i * 4 + j];
791                 args.inStopDouble = Float16Utils.convertFloat16ToDouble(args.inStop);
792                 args.inFraction = arrayInFraction[i * 4 + j];
793                 args.inFractionDouble = Float16Utils.convertFloat16ToDouble(args.inFraction);
794                 // Figure out what the outputs should have been.
795                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
796                 CoreMathVerifier.computeMix(args, target);
797                 // Validate the outputs.
798                 boolean valid = true;
799                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
800                     valid = false;
801                 }
802                 if (!valid) {
803                     if (!errorFound) {
804                         errorFound = true;
805                         message.append("Input inStart: ");
806                         appendVariableToMessage(message, args.inStart);
807                         message.append("\n");
808                         message.append("Input inStop: ");
809                         appendVariableToMessage(message, args.inStop);
810                         message.append("\n");
811                         message.append("Input inFraction: ");
812                         appendVariableToMessage(message, args.inFraction);
813                         message.append("\n");
814                         message.append("Expected output out: ");
815                         appendVariableToMessage(message, args.out);
816                         message.append("\n");
817                         message.append("Actual   output out: ");
818                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
819                         message.append("\n");
820                         message.append("Actual   output out (in double): ");
821                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
822                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
823                             message.append(" FAIL");
824                         }
825                         message.append("\n");
826                         message.append("Errors at");
827                     }
828                     message.append(" [");
829                     message.append(Integer.toString(i));
830                     message.append(", ");
831                     message.append(Integer.toString(j));
832                     message.append("]");
833                 }
834             }
835         }
836         assertFalse("Incorrect output for checkMixHalf4Half4Half4Half4" +
837                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
838     }
839 
checkMixFloat2Float2FloatFloat2()840     private void checkMixFloat2Float2FloatFloat2() {
841         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xf811b2d52bd1d7c3l, false);
842         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x17a127e13c8dd1c5l, false);
843         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xe0b7d03e92afd1f5l, false);
844         try {
845             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
846             script.set_gAllocInStop(inStop);
847             script.set_gAllocInFraction(inFraction);
848             script.forEach_testMixFloat2Float2FloatFloat2(inStart, out);
849             verifyResultsMixFloat2Float2FloatFloat2(inStart, inStop, inFraction, out, false);
850             out.destroy();
851         } catch (Exception e) {
852             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2FloatFloat2: " + e.toString());
853         }
854         try {
855             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
856             scriptRelaxed.set_gAllocInStop(inStop);
857             scriptRelaxed.set_gAllocInFraction(inFraction);
858             scriptRelaxed.forEach_testMixFloat2Float2FloatFloat2(inStart, out);
859             verifyResultsMixFloat2Float2FloatFloat2(inStart, inStop, inFraction, out, true);
860             out.destroy();
861         } catch (Exception e) {
862             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2FloatFloat2: " + e.toString());
863         }
864         inStart.destroy();
865         inStop.destroy();
866         inFraction.destroy();
867     }
868 
verifyResultsMixFloat2Float2FloatFloat2(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)869     private void verifyResultsMixFloat2Float2FloatFloat2(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
870         float[] arrayInStart = new float[INPUTSIZE * 2];
871         Arrays.fill(arrayInStart, (float) 42);
872         inStart.copyTo(arrayInStart);
873         float[] arrayInStop = new float[INPUTSIZE * 2];
874         Arrays.fill(arrayInStop, (float) 42);
875         inStop.copyTo(arrayInStop);
876         float[] arrayInFraction = new float[INPUTSIZE * 1];
877         Arrays.fill(arrayInFraction, (float) 42);
878         inFraction.copyTo(arrayInFraction);
879         float[] arrayOut = new float[INPUTSIZE * 2];
880         Arrays.fill(arrayOut, (float) 42);
881         out.copyTo(arrayOut);
882         StringBuilder message = new StringBuilder();
883         boolean errorFound = false;
884         for (int i = 0; i < INPUTSIZE; i++) {
885             for (int j = 0; j < 2 ; j++) {
886                 // Extract the inputs.
887                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
888                 args.inStart = arrayInStart[i * 2 + j];
889                 args.inStop = arrayInStop[i * 2 + j];
890                 args.inFraction = arrayInFraction[i];
891                 // Figure out what the outputs should have been.
892                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
893                 CoreMathVerifier.computeMix(args, target);
894                 // Validate the outputs.
895                 boolean valid = true;
896                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
897                     valid = false;
898                 }
899                 if (!valid) {
900                     if (!errorFound) {
901                         errorFound = true;
902                         message.append("Input inStart: ");
903                         appendVariableToMessage(message, args.inStart);
904                         message.append("\n");
905                         message.append("Input inStop: ");
906                         appendVariableToMessage(message, args.inStop);
907                         message.append("\n");
908                         message.append("Input inFraction: ");
909                         appendVariableToMessage(message, args.inFraction);
910                         message.append("\n");
911                         message.append("Expected output out: ");
912                         appendVariableToMessage(message, args.out);
913                         message.append("\n");
914                         message.append("Actual   output out: ");
915                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
916                         if (!args.out.couldBe(arrayOut[i * 2 + j])) {
917                             message.append(" FAIL");
918                         }
919                         message.append("\n");
920                         message.append("Errors at");
921                     }
922                     message.append(" [");
923                     message.append(Integer.toString(i));
924                     message.append(", ");
925                     message.append(Integer.toString(j));
926                     message.append("]");
927                 }
928             }
929         }
930         assertFalse("Incorrect output for checkMixFloat2Float2FloatFloat2" +
931                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
932     }
933 
checkMixFloat3Float3FloatFloat3()934     private void checkMixFloat3Float3FloatFloat3() {
935         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xae7aff441b20fa80l, false);
936         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe64a4d60d6f4de7cl, false);
937         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x21bd09bbd131a27cl, false);
938         try {
939             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
940             script.set_gAllocInStop(inStop);
941             script.set_gAllocInFraction(inFraction);
942             script.forEach_testMixFloat3Float3FloatFloat3(inStart, out);
943             verifyResultsMixFloat3Float3FloatFloat3(inStart, inStop, inFraction, out, false);
944             out.destroy();
945         } catch (Exception e) {
946             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3FloatFloat3: " + e.toString());
947         }
948         try {
949             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
950             scriptRelaxed.set_gAllocInStop(inStop);
951             scriptRelaxed.set_gAllocInFraction(inFraction);
952             scriptRelaxed.forEach_testMixFloat3Float3FloatFloat3(inStart, out);
953             verifyResultsMixFloat3Float3FloatFloat3(inStart, inStop, inFraction, out, true);
954             out.destroy();
955         } catch (Exception e) {
956             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3FloatFloat3: " + e.toString());
957         }
958         inStart.destroy();
959         inStop.destroy();
960         inFraction.destroy();
961     }
962 
verifyResultsMixFloat3Float3FloatFloat3(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)963     private void verifyResultsMixFloat3Float3FloatFloat3(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
964         float[] arrayInStart = new float[INPUTSIZE * 4];
965         Arrays.fill(arrayInStart, (float) 42);
966         inStart.copyTo(arrayInStart);
967         float[] arrayInStop = new float[INPUTSIZE * 4];
968         Arrays.fill(arrayInStop, (float) 42);
969         inStop.copyTo(arrayInStop);
970         float[] arrayInFraction = new float[INPUTSIZE * 1];
971         Arrays.fill(arrayInFraction, (float) 42);
972         inFraction.copyTo(arrayInFraction);
973         float[] arrayOut = new float[INPUTSIZE * 4];
974         Arrays.fill(arrayOut, (float) 42);
975         out.copyTo(arrayOut);
976         StringBuilder message = new StringBuilder();
977         boolean errorFound = false;
978         for (int i = 0; i < INPUTSIZE; i++) {
979             for (int j = 0; j < 3 ; j++) {
980                 // Extract the inputs.
981                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
982                 args.inStart = arrayInStart[i * 4 + j];
983                 args.inStop = arrayInStop[i * 4 + j];
984                 args.inFraction = arrayInFraction[i];
985                 // Figure out what the outputs should have been.
986                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
987                 CoreMathVerifier.computeMix(args, target);
988                 // Validate the outputs.
989                 boolean valid = true;
990                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
991                     valid = false;
992                 }
993                 if (!valid) {
994                     if (!errorFound) {
995                         errorFound = true;
996                         message.append("Input inStart: ");
997                         appendVariableToMessage(message, args.inStart);
998                         message.append("\n");
999                         message.append("Input inStop: ");
1000                         appendVariableToMessage(message, args.inStop);
1001                         message.append("\n");
1002                         message.append("Input inFraction: ");
1003                         appendVariableToMessage(message, args.inFraction);
1004                         message.append("\n");
1005                         message.append("Expected output out: ");
1006                         appendVariableToMessage(message, args.out);
1007                         message.append("\n");
1008                         message.append("Actual   output out: ");
1009                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1010                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
1011                             message.append(" FAIL");
1012                         }
1013                         message.append("\n");
1014                         message.append("Errors at");
1015                     }
1016                     message.append(" [");
1017                     message.append(Integer.toString(i));
1018                     message.append(", ");
1019                     message.append(Integer.toString(j));
1020                     message.append("]");
1021                 }
1022             }
1023         }
1024         assertFalse("Incorrect output for checkMixFloat3Float3FloatFloat3" +
1025                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1026     }
1027 
checkMixFloat4Float4FloatFloat4()1028     private void checkMixFloat4Float4FloatFloat4() {
1029         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x64e44bb30a701d3dl, false);
1030         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xb4f372e0715beb33l, false);
1031         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x62c243390fb37303l, false);
1032         try {
1033             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
1034             script.set_gAllocInStop(inStop);
1035             script.set_gAllocInFraction(inFraction);
1036             script.forEach_testMixFloat4Float4FloatFloat4(inStart, out);
1037             verifyResultsMixFloat4Float4FloatFloat4(inStart, inStop, inFraction, out, false);
1038             out.destroy();
1039         } catch (Exception e) {
1040             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4FloatFloat4: " + e.toString());
1041         }
1042         try {
1043             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
1044             scriptRelaxed.set_gAllocInStop(inStop);
1045             scriptRelaxed.set_gAllocInFraction(inFraction);
1046             scriptRelaxed.forEach_testMixFloat4Float4FloatFloat4(inStart, out);
1047             verifyResultsMixFloat4Float4FloatFloat4(inStart, inStop, inFraction, out, true);
1048             out.destroy();
1049         } catch (Exception e) {
1050             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4FloatFloat4: " + e.toString());
1051         }
1052         inStart.destroy();
1053         inStop.destroy();
1054         inFraction.destroy();
1055     }
1056 
verifyResultsMixFloat4Float4FloatFloat4(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)1057     private void verifyResultsMixFloat4Float4FloatFloat4(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
1058         float[] arrayInStart = new float[INPUTSIZE * 4];
1059         Arrays.fill(arrayInStart, (float) 42);
1060         inStart.copyTo(arrayInStart);
1061         float[] arrayInStop = new float[INPUTSIZE * 4];
1062         Arrays.fill(arrayInStop, (float) 42);
1063         inStop.copyTo(arrayInStop);
1064         float[] arrayInFraction = new float[INPUTSIZE * 1];
1065         Arrays.fill(arrayInFraction, (float) 42);
1066         inFraction.copyTo(arrayInFraction);
1067         float[] arrayOut = new float[INPUTSIZE * 4];
1068         Arrays.fill(arrayOut, (float) 42);
1069         out.copyTo(arrayOut);
1070         StringBuilder message = new StringBuilder();
1071         boolean errorFound = false;
1072         for (int i = 0; i < INPUTSIZE; i++) {
1073             for (int j = 0; j < 4 ; j++) {
1074                 // Extract the inputs.
1075                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
1076                 args.inStart = arrayInStart[i * 4 + j];
1077                 args.inStop = arrayInStop[i * 4 + j];
1078                 args.inFraction = arrayInFraction[i];
1079                 // Figure out what the outputs should have been.
1080                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
1081                 CoreMathVerifier.computeMix(args, target);
1082                 // Validate the outputs.
1083                 boolean valid = true;
1084                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
1085                     valid = false;
1086                 }
1087                 if (!valid) {
1088                     if (!errorFound) {
1089                         errorFound = true;
1090                         message.append("Input inStart: ");
1091                         appendVariableToMessage(message, args.inStart);
1092                         message.append("\n");
1093                         message.append("Input inStop: ");
1094                         appendVariableToMessage(message, args.inStop);
1095                         message.append("\n");
1096                         message.append("Input inFraction: ");
1097                         appendVariableToMessage(message, args.inFraction);
1098                         message.append("\n");
1099                         message.append("Expected output out: ");
1100                         appendVariableToMessage(message, args.out);
1101                         message.append("\n");
1102                         message.append("Actual   output out: ");
1103                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1104                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
1105                             message.append(" FAIL");
1106                         }
1107                         message.append("\n");
1108                         message.append("Errors at");
1109                     }
1110                     message.append(" [");
1111                     message.append(Integer.toString(i));
1112                     message.append(", ");
1113                     message.append(Integer.toString(j));
1114                     message.append("]");
1115                 }
1116             }
1117         }
1118         assertFalse("Incorrect output for checkMixFloat4Float4FloatFloat4" +
1119                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1120     }
1121 
checkMixHalf2Half2HalfHalf2()1122     private void checkMixHalf2Half2HalfHalf2() {
1123         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x5a6c4ac90c5a4349l, false);
1124         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xcc857ec32fea4b57l, false);
1125         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xebe632db339d3e7l, false);
1126         try {
1127             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
1128             script.set_gAllocInStop(inStop);
1129             script.set_gAllocInFraction(inFraction);
1130             script.forEach_testMixHalf2Half2HalfHalf2(inStart, out);
1131             verifyResultsMixHalf2Half2HalfHalf2(inStart, inStop, inFraction, out, false);
1132             out.destroy();
1133         } catch (Exception e) {
1134             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf2Half2HalfHalf2: " + e.toString());
1135         }
1136         try {
1137             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
1138             scriptRelaxed.set_gAllocInStop(inStop);
1139             scriptRelaxed.set_gAllocInFraction(inFraction);
1140             scriptRelaxed.forEach_testMixHalf2Half2HalfHalf2(inStart, out);
1141             verifyResultsMixHalf2Half2HalfHalf2(inStart, inStop, inFraction, out, true);
1142             out.destroy();
1143         } catch (Exception e) {
1144             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf2Half2HalfHalf2: " + e.toString());
1145         }
1146         inStart.destroy();
1147         inStop.destroy();
1148         inFraction.destroy();
1149     }
1150 
verifyResultsMixHalf2Half2HalfHalf2(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)1151     private void verifyResultsMixHalf2Half2HalfHalf2(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
1152         short[] arrayInStart = new short[INPUTSIZE * 2];
1153         Arrays.fill(arrayInStart, (short) 42);
1154         inStart.copyTo(arrayInStart);
1155         short[] arrayInStop = new short[INPUTSIZE * 2];
1156         Arrays.fill(arrayInStop, (short) 42);
1157         inStop.copyTo(arrayInStop);
1158         short[] arrayInFraction = new short[INPUTSIZE * 1];
1159         Arrays.fill(arrayInFraction, (short) 42);
1160         inFraction.copyTo(arrayInFraction);
1161         short[] arrayOut = new short[INPUTSIZE * 2];
1162         Arrays.fill(arrayOut, (short) 42);
1163         out.copyTo(arrayOut);
1164         StringBuilder message = new StringBuilder();
1165         boolean errorFound = false;
1166         for (int i = 0; i < INPUTSIZE; i++) {
1167             for (int j = 0; j < 2 ; j++) {
1168                 // Extract the inputs.
1169                 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf();
1170                 args.inStart = arrayInStart[i * 2 + j];
1171                 args.inStartDouble = Float16Utils.convertFloat16ToDouble(args.inStart);
1172                 args.inStop = arrayInStop[i * 2 + j];
1173                 args.inStopDouble = Float16Utils.convertFloat16ToDouble(args.inStop);
1174                 args.inFraction = arrayInFraction[i];
1175                 args.inFractionDouble = Float16Utils.convertFloat16ToDouble(args.inFraction);
1176                 // Figure out what the outputs should have been.
1177                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
1178                 CoreMathVerifier.computeMix(args, target);
1179                 // Validate the outputs.
1180                 boolean valid = true;
1181                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
1182                     valid = false;
1183                 }
1184                 if (!valid) {
1185                     if (!errorFound) {
1186                         errorFound = true;
1187                         message.append("Input inStart: ");
1188                         appendVariableToMessage(message, args.inStart);
1189                         message.append("\n");
1190                         message.append("Input inStop: ");
1191                         appendVariableToMessage(message, args.inStop);
1192                         message.append("\n");
1193                         message.append("Input inFraction: ");
1194                         appendVariableToMessage(message, args.inFraction);
1195                         message.append("\n");
1196                         message.append("Expected output out: ");
1197                         appendVariableToMessage(message, args.out);
1198                         message.append("\n");
1199                         message.append("Actual   output out: ");
1200                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
1201                         message.append("\n");
1202                         message.append("Actual   output out (in double): ");
1203                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]));
1204                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
1205                             message.append(" FAIL");
1206                         }
1207                         message.append("\n");
1208                         message.append("Errors at");
1209                     }
1210                     message.append(" [");
1211                     message.append(Integer.toString(i));
1212                     message.append(", ");
1213                     message.append(Integer.toString(j));
1214                     message.append("]");
1215                 }
1216             }
1217         }
1218         assertFalse("Incorrect output for checkMixHalf2Half2HalfHalf2" +
1219                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1220     }
1221 
checkMixHalf3Half3HalfHalf3()1222     private void checkMixHalf3Half3HalfHalf3() {
1223         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x825985c204615a8l, false);
1224         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x9506d3ea541973f4l, false);
1225         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x341608c1b462aa74l, false);
1226         try {
1227             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
1228             script.set_gAllocInStop(inStop);
1229             script.set_gAllocInFraction(inFraction);
1230             script.forEach_testMixHalf3Half3HalfHalf3(inStart, out);
1231             verifyResultsMixHalf3Half3HalfHalf3(inStart, inStop, inFraction, out, false);
1232             out.destroy();
1233         } catch (Exception e) {
1234             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf3Half3HalfHalf3: " + e.toString());
1235         }
1236         try {
1237             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
1238             scriptRelaxed.set_gAllocInStop(inStop);
1239             scriptRelaxed.set_gAllocInFraction(inFraction);
1240             scriptRelaxed.forEach_testMixHalf3Half3HalfHalf3(inStart, out);
1241             verifyResultsMixHalf3Half3HalfHalf3(inStart, inStop, inFraction, out, true);
1242             out.destroy();
1243         } catch (Exception e) {
1244             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf3Half3HalfHalf3: " + e.toString());
1245         }
1246         inStart.destroy();
1247         inStop.destroy();
1248         inFraction.destroy();
1249     }
1250 
verifyResultsMixHalf3Half3HalfHalf3(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)1251     private void verifyResultsMixHalf3Half3HalfHalf3(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
1252         short[] arrayInStart = new short[INPUTSIZE * 4];
1253         Arrays.fill(arrayInStart, (short) 42);
1254         inStart.copyTo(arrayInStart);
1255         short[] arrayInStop = new short[INPUTSIZE * 4];
1256         Arrays.fill(arrayInStop, (short) 42);
1257         inStop.copyTo(arrayInStop);
1258         short[] arrayInFraction = new short[INPUTSIZE * 1];
1259         Arrays.fill(arrayInFraction, (short) 42);
1260         inFraction.copyTo(arrayInFraction);
1261         short[] arrayOut = new short[INPUTSIZE * 4];
1262         Arrays.fill(arrayOut, (short) 42);
1263         out.copyTo(arrayOut);
1264         StringBuilder message = new StringBuilder();
1265         boolean errorFound = false;
1266         for (int i = 0; i < INPUTSIZE; i++) {
1267             for (int j = 0; j < 3 ; j++) {
1268                 // Extract the inputs.
1269                 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf();
1270                 args.inStart = arrayInStart[i * 4 + j];
1271                 args.inStartDouble = Float16Utils.convertFloat16ToDouble(args.inStart);
1272                 args.inStop = arrayInStop[i * 4 + j];
1273                 args.inStopDouble = Float16Utils.convertFloat16ToDouble(args.inStop);
1274                 args.inFraction = arrayInFraction[i];
1275                 args.inFractionDouble = Float16Utils.convertFloat16ToDouble(args.inFraction);
1276                 // Figure out what the outputs should have been.
1277                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
1278                 CoreMathVerifier.computeMix(args, target);
1279                 // Validate the outputs.
1280                 boolean valid = true;
1281                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
1282                     valid = false;
1283                 }
1284                 if (!valid) {
1285                     if (!errorFound) {
1286                         errorFound = true;
1287                         message.append("Input inStart: ");
1288                         appendVariableToMessage(message, args.inStart);
1289                         message.append("\n");
1290                         message.append("Input inStop: ");
1291                         appendVariableToMessage(message, args.inStop);
1292                         message.append("\n");
1293                         message.append("Input inFraction: ");
1294                         appendVariableToMessage(message, args.inFraction);
1295                         message.append("\n");
1296                         message.append("Expected output out: ");
1297                         appendVariableToMessage(message, args.out);
1298                         message.append("\n");
1299                         message.append("Actual   output out: ");
1300                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1301                         message.append("\n");
1302                         message.append("Actual   output out (in double): ");
1303                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
1304                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
1305                             message.append(" FAIL");
1306                         }
1307                         message.append("\n");
1308                         message.append("Errors at");
1309                     }
1310                     message.append(" [");
1311                     message.append(Integer.toString(i));
1312                     message.append(", ");
1313                     message.append(Integer.toString(j));
1314                     message.append("]");
1315                 }
1316             }
1317         }
1318         assertFalse("Incorrect output for checkMixHalf3Half3HalfHalf3" +
1319                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1320     }
1321 
checkMixHalf4Half4HalfHalf4()1322     private void checkMixHalf4Half4HalfHalf4() {
1323         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xb5dee5ef3431e807l, false);
1324         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x5d88291178489c91l, false);
1325         Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x596dae55b58b8101l, false);
1326         try {
1327             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
1328             script.set_gAllocInStop(inStop);
1329             script.set_gAllocInFraction(inFraction);
1330             script.forEach_testMixHalf4Half4HalfHalf4(inStart, out);
1331             verifyResultsMixHalf4Half4HalfHalf4(inStart, inStop, inFraction, out, false);
1332             out.destroy();
1333         } catch (Exception e) {
1334             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf4Half4HalfHalf4: " + e.toString());
1335         }
1336         try {
1337             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
1338             scriptRelaxed.set_gAllocInStop(inStop);
1339             scriptRelaxed.set_gAllocInFraction(inFraction);
1340             scriptRelaxed.forEach_testMixHalf4Half4HalfHalf4(inStart, out);
1341             verifyResultsMixHalf4Half4HalfHalf4(inStart, inStop, inFraction, out, true);
1342             out.destroy();
1343         } catch (Exception e) {
1344             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixHalf4Half4HalfHalf4: " + e.toString());
1345         }
1346         inStart.destroy();
1347         inStop.destroy();
1348         inFraction.destroy();
1349     }
1350 
verifyResultsMixHalf4Half4HalfHalf4(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed)1351     private void verifyResultsMixHalf4Half4HalfHalf4(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
1352         short[] arrayInStart = new short[INPUTSIZE * 4];
1353         Arrays.fill(arrayInStart, (short) 42);
1354         inStart.copyTo(arrayInStart);
1355         short[] arrayInStop = new short[INPUTSIZE * 4];
1356         Arrays.fill(arrayInStop, (short) 42);
1357         inStop.copyTo(arrayInStop);
1358         short[] arrayInFraction = new short[INPUTSIZE * 1];
1359         Arrays.fill(arrayInFraction, (short) 42);
1360         inFraction.copyTo(arrayInFraction);
1361         short[] arrayOut = new short[INPUTSIZE * 4];
1362         Arrays.fill(arrayOut, (short) 42);
1363         out.copyTo(arrayOut);
1364         StringBuilder message = new StringBuilder();
1365         boolean errorFound = false;
1366         for (int i = 0; i < INPUTSIZE; i++) {
1367             for (int j = 0; j < 4 ; j++) {
1368                 // Extract the inputs.
1369                 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf();
1370                 args.inStart = arrayInStart[i * 4 + j];
1371                 args.inStartDouble = Float16Utils.convertFloat16ToDouble(args.inStart);
1372                 args.inStop = arrayInStop[i * 4 + j];
1373                 args.inStopDouble = Float16Utils.convertFloat16ToDouble(args.inStop);
1374                 args.inFraction = arrayInFraction[i];
1375                 args.inFractionDouble = Float16Utils.convertFloat16ToDouble(args.inFraction);
1376                 // Figure out what the outputs should have been.
1377                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
1378                 CoreMathVerifier.computeMix(args, target);
1379                 // Validate the outputs.
1380                 boolean valid = true;
1381                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
1382                     valid = false;
1383                 }
1384                 if (!valid) {
1385                     if (!errorFound) {
1386                         errorFound = true;
1387                         message.append("Input inStart: ");
1388                         appendVariableToMessage(message, args.inStart);
1389                         message.append("\n");
1390                         message.append("Input inStop: ");
1391                         appendVariableToMessage(message, args.inStop);
1392                         message.append("\n");
1393                         message.append("Input inFraction: ");
1394                         appendVariableToMessage(message, args.inFraction);
1395                         message.append("\n");
1396                         message.append("Expected output out: ");
1397                         appendVariableToMessage(message, args.out);
1398                         message.append("\n");
1399                         message.append("Actual   output out: ");
1400                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1401                         message.append("\n");
1402                         message.append("Actual   output out (in double): ");
1403                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
1404                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
1405                             message.append(" FAIL");
1406                         }
1407                         message.append("\n");
1408                         message.append("Errors at");
1409                     }
1410                     message.append(" [");
1411                     message.append(Integer.toString(i));
1412                     message.append(", ");
1413                     message.append(Integer.toString(j));
1414                     message.append("]");
1415                 }
1416             }
1417         }
1418         assertFalse("Incorrect output for checkMixHalf4Half4HalfHalf4" +
1419                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1420     }
1421 
testMix()1422     public void testMix() {
1423         checkMixFloatFloatFloatFloat();
1424         checkMixFloat2Float2Float2Float2();
1425         checkMixFloat3Float3Float3Float3();
1426         checkMixFloat4Float4Float4Float4();
1427         checkMixHalfHalfHalfHalf();
1428         checkMixHalf2Half2Half2Half2();
1429         checkMixHalf3Half3Half3Half3();
1430         checkMixHalf4Half4Half4Half4();
1431         checkMixFloat2Float2FloatFloat2();
1432         checkMixFloat3Float3FloatFloat3();
1433         checkMixFloat4Float4FloatFloat4();
1434         checkMixHalf2Half2HalfHalf2();
1435         checkMixHalf3Half3HalfHalf3();
1436         checkMixHalf4Half4HalfHalf4();
1437     }
1438 }
1439