• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // Don't edit this file!  It is auto-generated by frameworks/rs/api/generate.sh.
18 
19 package android.renderscript.cts;
20 
21 import android.renderscript.Allocation;
22 import android.renderscript.RSRuntimeException;
23 import android.renderscript.Element;
24 import android.renderscript.cts.Target;
25 
26 import java.util.Arrays;
27 
28 public class TestLength extends RSBaseCompute {
29 
30     private ScriptC_TestLength script;
31     private ScriptC_TestLengthRelaxed scriptRelaxed;
32 
33     @Override
setUp()34     protected void setUp() throws Exception {
35         super.setUp();
36         script = new ScriptC_TestLength(mRS);
37         scriptRelaxed = new ScriptC_TestLengthRelaxed(mRS);
38     }
39 
40     public class ArgumentsFloatFloat {
41         public float inV;
42         public Target.Floaty out;
43     }
44 
checkLengthFloatFloat()45     private void checkLengthFloatFloat() {
46         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x9f7cc9fl, false);
47         try {
48             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
49             script.forEach_testLengthFloatFloat(inV, out);
50             verifyResultsLengthFloatFloat(inV, out, false);
51         } catch (Exception e) {
52             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthFloatFloat: " + e.toString());
53         }
54         try {
55             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
56             scriptRelaxed.forEach_testLengthFloatFloat(inV, out);
57             verifyResultsLengthFloatFloat(inV, out, true);
58         } catch (Exception e) {
59             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthFloatFloat: " + e.toString());
60         }
61     }
62 
verifyResultsLengthFloatFloat(Allocation inV, Allocation out, boolean relaxed)63     private void verifyResultsLengthFloatFloat(Allocation inV, Allocation out, boolean relaxed) {
64         float[] arrayInV = new float[INPUTSIZE * 1];
65         Arrays.fill(arrayInV, (float) 42);
66         inV.copyTo(arrayInV);
67         float[] arrayOut = new float[INPUTSIZE * 1];
68         Arrays.fill(arrayOut, (float) 42);
69         out.copyTo(arrayOut);
70         StringBuilder message = new StringBuilder();
71         boolean errorFound = false;
72         for (int i = 0; i < INPUTSIZE; i++) {
73             ArgumentsFloatFloat args = new ArgumentsFloatFloat();
74             // Create the appropriate sized arrays in args
75             // Fill args with the input values
76             args.inV = arrayInV[i];
77             Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
78             CoreMathVerifier.computeLength(args, target);
79 
80             // Compare the expected outputs to the actual values returned by RS.
81             boolean valid = true;
82             if (!args.out.couldBe(arrayOut[i])) {
83                 valid = false;
84             }
85             if (!valid) {
86                 if (!errorFound) {
87                     errorFound = true;
88                     message.append("Input inV: ");
89                     appendVariableToMessage(message, arrayInV[i]);
90                     message.append("\n");
91                     message.append("Expected output out: ");
92                     appendVariableToMessage(message, args.out);
93                     message.append("\n");
94                     message.append("Actual   output out: ");
95                     appendVariableToMessage(message, arrayOut[i]);
96                     if (!args.out.couldBe(arrayOut[i])) {
97                         message.append(" FAIL");
98                     }
99                     message.append("\n");
100                     message.append("Errors at");
101                 }
102                 message.append(" [");
103                 message.append(Integer.toString(i));
104                 message.append("]");
105             }
106         }
107         assertFalse("Incorrect output for checkLengthFloatFloat" +
108                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
109     }
110 
111     public class ArgumentsFloatNFloat {
112         public float[] inV;
113         public Target.Floaty out;
114     }
115 
checkLengthFloat2Float()116     private void checkLengthFloat2Float() {
117         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x5dd9595dl, false);
118         try {
119             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
120             script.forEach_testLengthFloat2Float(inV, out);
121             verifyResultsLengthFloat2Float(inV, out, false);
122         } catch (Exception e) {
123             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthFloat2Float: " + e.toString());
124         }
125         try {
126             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
127             scriptRelaxed.forEach_testLengthFloat2Float(inV, out);
128             verifyResultsLengthFloat2Float(inV, out, true);
129         } catch (Exception e) {
130             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthFloat2Float: " + e.toString());
131         }
132     }
133 
verifyResultsLengthFloat2Float(Allocation inV, Allocation out, boolean relaxed)134     private void verifyResultsLengthFloat2Float(Allocation inV, Allocation out, boolean relaxed) {
135         float[] arrayInV = new float[INPUTSIZE * 2];
136         Arrays.fill(arrayInV, (float) 42);
137         inV.copyTo(arrayInV);
138         float[] arrayOut = new float[INPUTSIZE * 1];
139         Arrays.fill(arrayOut, (float) 42);
140         out.copyTo(arrayOut);
141         StringBuilder message = new StringBuilder();
142         boolean errorFound = false;
143         for (int i = 0; i < INPUTSIZE; i++) {
144             ArgumentsFloatNFloat args = new ArgumentsFloatNFloat();
145             // Create the appropriate sized arrays in args
146             args.inV = new float[2];
147             // Fill args with the input values
148             for (int j = 0; j < 2 ; j++) {
149                 args.inV[j] = arrayInV[i * 2 + j];
150             }
151             Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
152             CoreMathVerifier.computeLength(args, target);
153 
154             // Compare the expected outputs to the actual values returned by RS.
155             boolean valid = true;
156             if (!args.out.couldBe(arrayOut[i])) {
157                 valid = false;
158             }
159             if (!valid) {
160                 if (!errorFound) {
161                     errorFound = true;
162                     for (int j = 0; j < 2 ; j++) {
163                         message.append("Input inV: ");
164                         appendVariableToMessage(message, arrayInV[i * 2 + j]);
165                         message.append("\n");
166                     }
167                     message.append("Expected output out: ");
168                     appendVariableToMessage(message, args.out);
169                     message.append("\n");
170                     message.append("Actual   output out: ");
171                     appendVariableToMessage(message, arrayOut[i]);
172                     if (!args.out.couldBe(arrayOut[i])) {
173                         message.append(" FAIL");
174                     }
175                     message.append("\n");
176                     message.append("Errors at");
177                 }
178                 message.append(" [");
179                 message.append(Integer.toString(i));
180                 message.append("]");
181             }
182         }
183         assertFalse("Incorrect output for checkLengthFloat2Float" +
184                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
185     }
186 
checkLengthFloat3Float()187     private void checkLengthFloat3Float() {
188         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xbcdfe7bel, false);
189         try {
190             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
191             script.forEach_testLengthFloat3Float(inV, out);
192             verifyResultsLengthFloat3Float(inV, out, false);
193         } catch (Exception e) {
194             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthFloat3Float: " + e.toString());
195         }
196         try {
197             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
198             scriptRelaxed.forEach_testLengthFloat3Float(inV, out);
199             verifyResultsLengthFloat3Float(inV, out, true);
200         } catch (Exception e) {
201             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthFloat3Float: " + e.toString());
202         }
203     }
204 
verifyResultsLengthFloat3Float(Allocation inV, Allocation out, boolean relaxed)205     private void verifyResultsLengthFloat3Float(Allocation inV, Allocation out, boolean relaxed) {
206         float[] arrayInV = new float[INPUTSIZE * 4];
207         Arrays.fill(arrayInV, (float) 42);
208         inV.copyTo(arrayInV);
209         float[] arrayOut = new float[INPUTSIZE * 1];
210         Arrays.fill(arrayOut, (float) 42);
211         out.copyTo(arrayOut);
212         StringBuilder message = new StringBuilder();
213         boolean errorFound = false;
214         for (int i = 0; i < INPUTSIZE; i++) {
215             ArgumentsFloatNFloat args = new ArgumentsFloatNFloat();
216             // Create the appropriate sized arrays in args
217             args.inV = new float[3];
218             // Fill args with the input values
219             for (int j = 0; j < 3 ; j++) {
220                 args.inV[j] = arrayInV[i * 4 + j];
221             }
222             Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
223             CoreMathVerifier.computeLength(args, target);
224 
225             // Compare the expected outputs to the actual values returned by RS.
226             boolean valid = true;
227             if (!args.out.couldBe(arrayOut[i])) {
228                 valid = false;
229             }
230             if (!valid) {
231                 if (!errorFound) {
232                     errorFound = true;
233                     for (int j = 0; j < 3 ; j++) {
234                         message.append("Input inV: ");
235                         appendVariableToMessage(message, arrayInV[i * 4 + j]);
236                         message.append("\n");
237                     }
238                     message.append("Expected output out: ");
239                     appendVariableToMessage(message, args.out);
240                     message.append("\n");
241                     message.append("Actual   output out: ");
242                     appendVariableToMessage(message, arrayOut[i]);
243                     if (!args.out.couldBe(arrayOut[i])) {
244                         message.append(" FAIL");
245                     }
246                     message.append("\n");
247                     message.append("Errors at");
248                 }
249                 message.append(" [");
250                 message.append(Integer.toString(i));
251                 message.append("]");
252             }
253         }
254         assertFalse("Incorrect output for checkLengthFloat3Float" +
255                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
256     }
257 
checkLengthFloat4Float()258     private void checkLengthFloat4Float() {
259         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x1be6761fl, false);
260         try {
261             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
262             script.forEach_testLengthFloat4Float(inV, out);
263             verifyResultsLengthFloat4Float(inV, out, false);
264         } catch (Exception e) {
265             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthFloat4Float: " + e.toString());
266         }
267         try {
268             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
269             scriptRelaxed.forEach_testLengthFloat4Float(inV, out);
270             verifyResultsLengthFloat4Float(inV, out, true);
271         } catch (Exception e) {
272             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthFloat4Float: " + e.toString());
273         }
274     }
275 
verifyResultsLengthFloat4Float(Allocation inV, Allocation out, boolean relaxed)276     private void verifyResultsLengthFloat4Float(Allocation inV, Allocation out, boolean relaxed) {
277         float[] arrayInV = new float[INPUTSIZE * 4];
278         Arrays.fill(arrayInV, (float) 42);
279         inV.copyTo(arrayInV);
280         float[] arrayOut = new float[INPUTSIZE * 1];
281         Arrays.fill(arrayOut, (float) 42);
282         out.copyTo(arrayOut);
283         StringBuilder message = new StringBuilder();
284         boolean errorFound = false;
285         for (int i = 0; i < INPUTSIZE; i++) {
286             ArgumentsFloatNFloat args = new ArgumentsFloatNFloat();
287             // Create the appropriate sized arrays in args
288             args.inV = new float[4];
289             // Fill args with the input values
290             for (int j = 0; j < 4 ; j++) {
291                 args.inV[j] = arrayInV[i * 4 + j];
292             }
293             Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
294             CoreMathVerifier.computeLength(args, target);
295 
296             // Compare the expected outputs to the actual values returned by RS.
297             boolean valid = true;
298             if (!args.out.couldBe(arrayOut[i])) {
299                 valid = false;
300             }
301             if (!valid) {
302                 if (!errorFound) {
303                     errorFound = true;
304                     for (int j = 0; j < 4 ; j++) {
305                         message.append("Input inV: ");
306                         appendVariableToMessage(message, arrayInV[i * 4 + j]);
307                         message.append("\n");
308                     }
309                     message.append("Expected output out: ");
310                     appendVariableToMessage(message, args.out);
311                     message.append("\n");
312                     message.append("Actual   output out: ");
313                     appendVariableToMessage(message, arrayOut[i]);
314                     if (!args.out.couldBe(arrayOut[i])) {
315                         message.append(" FAIL");
316                     }
317                     message.append("\n");
318                     message.append("Errors at");
319                 }
320                 message.append(" [");
321                 message.append(Integer.toString(i));
322                 message.append("]");
323             }
324         }
325         assertFalse("Incorrect output for checkLengthFloat4Float" +
326                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
327     }
328 
329     public class ArgumentsHalfHalf {
330         public short inV;
331         public double inVDouble;
332         public Target.Floaty out;
333     }
334 
checkLengthHalfHalf()335     private void checkLengthHalfHalf() {
336         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x6dc47281l, false);
337         try {
338             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
339             script.forEach_testLengthHalfHalf(inV, out);
340             verifyResultsLengthHalfHalf(inV, out, false);
341         } catch (Exception e) {
342             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthHalfHalf: " + e.toString());
343         }
344         try {
345             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
346             scriptRelaxed.forEach_testLengthHalfHalf(inV, out);
347             verifyResultsLengthHalfHalf(inV, out, true);
348         } catch (Exception e) {
349             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthHalfHalf: " + e.toString());
350         }
351     }
352 
verifyResultsLengthHalfHalf(Allocation inV, Allocation out, boolean relaxed)353     private void verifyResultsLengthHalfHalf(Allocation inV, Allocation out, boolean relaxed) {
354         short[] arrayInV = new short[INPUTSIZE * 1];
355         Arrays.fill(arrayInV, (short) 42);
356         inV.copyTo(arrayInV);
357         short[] arrayOut = new short[INPUTSIZE * 1];
358         Arrays.fill(arrayOut, (short) 42);
359         out.copyTo(arrayOut);
360         StringBuilder message = new StringBuilder();
361         boolean errorFound = false;
362         for (int i = 0; i < INPUTSIZE; i++) {
363             ArgumentsHalfHalf args = new ArgumentsHalfHalf();
364             // Create the appropriate sized arrays in args
365             // Fill args with the input values
366             args.inV = arrayInV[i];
367             args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
368             Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
369             CoreMathVerifier.computeLength(args, target);
370 
371             // Compare the expected outputs to the actual values returned by RS.
372             boolean valid = true;
373             if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
374                 valid = false;
375             }
376             if (!valid) {
377                 if (!errorFound) {
378                     errorFound = true;
379                     message.append("Input inV: ");
380                     appendVariableToMessage(message, arrayInV[i]);
381                     message.append("\n");
382                     message.append("Expected output out: ");
383                     appendVariableToMessage(message, args.out);
384                     message.append("\n");
385                     message.append("Actual   output out: ");
386                     appendVariableToMessage(message, arrayOut[i]);
387                     message.append("\n");
388                     message.append("Actual   output out (in double): ");
389                     appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i]));
390                     if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
391                         message.append(" FAIL");
392                     }
393                     message.append("\n");
394                     message.append("Errors at");
395                 }
396                 message.append(" [");
397                 message.append(Integer.toString(i));
398                 message.append("]");
399             }
400         }
401         assertFalse("Incorrect output for checkLengthHalfHalf" +
402                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
403     }
404 
405     public class ArgumentsHalfNHalf {
406         public short[] inV;
407         public double[] inVDouble;
408         public Target.Floaty out;
409     }
410 
checkLengthHalf2Half()411     private void checkLengthHalf2Half() {
412         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xf0ea410dl, false);
413         try {
414             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
415             script.forEach_testLengthHalf2Half(inV, out);
416             verifyResultsLengthHalf2Half(inV, out, false);
417         } catch (Exception e) {
418             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthHalf2Half: " + e.toString());
419         }
420         try {
421             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
422             scriptRelaxed.forEach_testLengthHalf2Half(inV, out);
423             verifyResultsLengthHalf2Half(inV, out, true);
424         } catch (Exception e) {
425             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthHalf2Half: " + e.toString());
426         }
427     }
428 
verifyResultsLengthHalf2Half(Allocation inV, Allocation out, boolean relaxed)429     private void verifyResultsLengthHalf2Half(Allocation inV, Allocation out, boolean relaxed) {
430         short[] arrayInV = new short[INPUTSIZE * 2];
431         Arrays.fill(arrayInV, (short) 42);
432         inV.copyTo(arrayInV);
433         short[] arrayOut = new short[INPUTSIZE * 1];
434         Arrays.fill(arrayOut, (short) 42);
435         out.copyTo(arrayOut);
436         StringBuilder message = new StringBuilder();
437         boolean errorFound = false;
438         for (int i = 0; i < INPUTSIZE; i++) {
439             ArgumentsHalfNHalf args = new ArgumentsHalfNHalf();
440             // Create the appropriate sized arrays in args
441             args.inV = new short[2];
442             args.inVDouble = new double[2];
443             // Fill args with the input values
444             for (int j = 0; j < 2 ; j++) {
445                 args.inV[j] = arrayInV[i * 2 + j];
446                 args.inVDouble[j] = Float16Utils.convertFloat16ToDouble(args.inV[j]);
447             }
448             Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
449             CoreMathVerifier.computeLength(args, target);
450 
451             // Compare the expected outputs to the actual values returned by RS.
452             boolean valid = true;
453             if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
454                 valid = false;
455             }
456             if (!valid) {
457                 if (!errorFound) {
458                     errorFound = true;
459                     for (int j = 0; j < 2 ; j++) {
460                         message.append("Input inV: ");
461                         appendVariableToMessage(message, arrayInV[i * 2 + j]);
462                         message.append("\n");
463                     }
464                     message.append("Expected output out: ");
465                     appendVariableToMessage(message, args.out);
466                     message.append("\n");
467                     message.append("Actual   output out: ");
468                     appendVariableToMessage(message, arrayOut[i]);
469                     message.append("\n");
470                     message.append("Actual   output out (in double): ");
471                     appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i]));
472                     if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
473                         message.append(" FAIL");
474                     }
475                     message.append("\n");
476                     message.append("Errors at");
477                 }
478                 message.append(" [");
479                 message.append(Integer.toString(i));
480                 message.append("]");
481             }
482         }
483         assertFalse("Incorrect output for checkLengthHalf2Half" +
484                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
485     }
486 
checkLengthHalf3Half()487     private void checkLengthHalf3Half() {
488         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x3a911ab0l, false);
489         try {
490             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
491             script.forEach_testLengthHalf3Half(inV, out);
492             verifyResultsLengthHalf3Half(inV, out, false);
493         } catch (Exception e) {
494             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthHalf3Half: " + e.toString());
495         }
496         try {
497             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
498             scriptRelaxed.forEach_testLengthHalf3Half(inV, out);
499             verifyResultsLengthHalf3Half(inV, out, true);
500         } catch (Exception e) {
501             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthHalf3Half: " + e.toString());
502         }
503     }
504 
verifyResultsLengthHalf3Half(Allocation inV, Allocation out, boolean relaxed)505     private void verifyResultsLengthHalf3Half(Allocation inV, Allocation out, boolean relaxed) {
506         short[] arrayInV = new short[INPUTSIZE * 4];
507         Arrays.fill(arrayInV, (short) 42);
508         inV.copyTo(arrayInV);
509         short[] arrayOut = new short[INPUTSIZE * 1];
510         Arrays.fill(arrayOut, (short) 42);
511         out.copyTo(arrayOut);
512         StringBuilder message = new StringBuilder();
513         boolean errorFound = false;
514         for (int i = 0; i < INPUTSIZE; i++) {
515             ArgumentsHalfNHalf args = new ArgumentsHalfNHalf();
516             // Create the appropriate sized arrays in args
517             args.inV = new short[3];
518             args.inVDouble = new double[3];
519             // Fill args with the input values
520             for (int j = 0; j < 3 ; j++) {
521                 args.inV[j] = arrayInV[i * 4 + j];
522                 args.inVDouble[j] = Float16Utils.convertFloat16ToDouble(args.inV[j]);
523             }
524             Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
525             CoreMathVerifier.computeLength(args, target);
526 
527             // Compare the expected outputs to the actual values returned by RS.
528             boolean valid = true;
529             if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
530                 valid = false;
531             }
532             if (!valid) {
533                 if (!errorFound) {
534                     errorFound = true;
535                     for (int j = 0; j < 3 ; j++) {
536                         message.append("Input inV: ");
537                         appendVariableToMessage(message, arrayInV[i * 4 + j]);
538                         message.append("\n");
539                     }
540                     message.append("Expected output out: ");
541                     appendVariableToMessage(message, args.out);
542                     message.append("\n");
543                     message.append("Actual   output out: ");
544                     appendVariableToMessage(message, arrayOut[i]);
545                     message.append("\n");
546                     message.append("Actual   output out (in double): ");
547                     appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i]));
548                     if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
549                         message.append(" FAIL");
550                     }
551                     message.append("\n");
552                     message.append("Errors at");
553                 }
554                 message.append(" [");
555                 message.append(Integer.toString(i));
556                 message.append("]");
557             }
558         }
559         assertFalse("Incorrect output for checkLengthHalf3Half" +
560                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
561     }
562 
checkLengthHalf4Half()563     private void checkLengthHalf4Half() {
564         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x8437f453l, false);
565         try {
566             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
567             script.forEach_testLengthHalf4Half(inV, out);
568             verifyResultsLengthHalf4Half(inV, out, false);
569         } catch (Exception e) {
570             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthHalf4Half: " + e.toString());
571         }
572         try {
573             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
574             scriptRelaxed.forEach_testLengthHalf4Half(inV, out);
575             verifyResultsLengthHalf4Half(inV, out, true);
576         } catch (Exception e) {
577             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLengthHalf4Half: " + e.toString());
578         }
579     }
580 
verifyResultsLengthHalf4Half(Allocation inV, Allocation out, boolean relaxed)581     private void verifyResultsLengthHalf4Half(Allocation inV, Allocation out, boolean relaxed) {
582         short[] arrayInV = new short[INPUTSIZE * 4];
583         Arrays.fill(arrayInV, (short) 42);
584         inV.copyTo(arrayInV);
585         short[] arrayOut = new short[INPUTSIZE * 1];
586         Arrays.fill(arrayOut, (short) 42);
587         out.copyTo(arrayOut);
588         StringBuilder message = new StringBuilder();
589         boolean errorFound = false;
590         for (int i = 0; i < INPUTSIZE; i++) {
591             ArgumentsHalfNHalf args = new ArgumentsHalfNHalf();
592             // Create the appropriate sized arrays in args
593             args.inV = new short[4];
594             args.inVDouble = new double[4];
595             // Fill args with the input values
596             for (int j = 0; j < 4 ; j++) {
597                 args.inV[j] = arrayInV[i * 4 + j];
598                 args.inVDouble[j] = Float16Utils.convertFloat16ToDouble(args.inV[j]);
599             }
600             Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
601             CoreMathVerifier.computeLength(args, target);
602 
603             // Compare the expected outputs to the actual values returned by RS.
604             boolean valid = true;
605             if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
606                 valid = false;
607             }
608             if (!valid) {
609                 if (!errorFound) {
610                     errorFound = true;
611                     for (int j = 0; j < 4 ; j++) {
612                         message.append("Input inV: ");
613                         appendVariableToMessage(message, arrayInV[i * 4 + j]);
614                         message.append("\n");
615                     }
616                     message.append("Expected output out: ");
617                     appendVariableToMessage(message, args.out);
618                     message.append("\n");
619                     message.append("Actual   output out: ");
620                     appendVariableToMessage(message, arrayOut[i]);
621                     message.append("\n");
622                     message.append("Actual   output out (in double): ");
623                     appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i]));
624                     if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
625                         message.append(" FAIL");
626                     }
627                     message.append("\n");
628                     message.append("Errors at");
629                 }
630                 message.append(" [");
631                 message.append(Integer.toString(i));
632                 message.append("]");
633             }
634         }
635         assertFalse("Incorrect output for checkLengthHalf4Half" +
636                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
637     }
638 
testLength()639     public void testLength() {
640         checkLengthFloatFloat();
641         checkLengthFloat2Float();
642         checkLengthFloat3Float();
643         checkLengthFloat4Float();
644         checkLengthHalfHalf();
645         checkLengthHalf2Half();
646         checkLengthHalf3Half();
647         checkLengthHalf4Half();
648     }
649 }
650