Home | History | Annotate | Download | only in generated
      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 TestSincos extends RSBaseCompute {
     29 
     30     private ScriptC_TestSincos script;
     31     private ScriptC_TestSincosRelaxed scriptRelaxed;
     32 
     33     @Override
     34     protected void setUp() throws Exception {
     35         super.setUp();
     36         script = new ScriptC_TestSincos(mRS);
     37         scriptRelaxed = new ScriptC_TestSincosRelaxed(mRS);
     38     }
     39 
     40     @Override
     41     protected void tearDown() throws Exception {
     42         script.destroy();
     43         scriptRelaxed.destroy();
     44         super.tearDown();
     45     }
     46 
     47     public class ArgumentsFloatFloatFloat {
     48         public float inV;
     49         public Target.Floaty outCos;
     50         public Target.Floaty out;
     51     }
     52 
     53     private void checkSincosFloatFloatFloat() {
     54         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xb8748e13e46c48d4l, false);
     55         try {
     56             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     57             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     58             script.set_gAllocOutCos(outCos);
     59             script.forEach_testSincosFloatFloatFloat(inV, out);
     60             verifyResultsSincosFloatFloatFloat(inV, outCos, out, false);
     61             outCos.destroy();
     62             out.destroy();
     63         } catch (Exception e) {
     64             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloatFloatFloat: " + e.toString());
     65         }
     66         try {
     67             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     68             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     69             scriptRelaxed.set_gAllocOutCos(outCos);
     70             scriptRelaxed.forEach_testSincosFloatFloatFloat(inV, out);
     71             verifyResultsSincosFloatFloatFloat(inV, outCos, out, true);
     72             outCos.destroy();
     73             out.destroy();
     74         } catch (Exception e) {
     75             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloatFloatFloat: " + e.toString());
     76         }
     77         inV.destroy();
     78     }
     79 
     80     private void verifyResultsSincosFloatFloatFloat(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) {
     81         float[] arrayInV = new float[INPUTSIZE * 1];
     82         Arrays.fill(arrayInV, (float) 42);
     83         inV.copyTo(arrayInV);
     84         float[] arrayOutCos = new float[INPUTSIZE * 1];
     85         Arrays.fill(arrayOutCos, (float) 42);
     86         outCos.copyTo(arrayOutCos);
     87         float[] arrayOut = new float[INPUTSIZE * 1];
     88         Arrays.fill(arrayOut, (float) 42);
     89         out.copyTo(arrayOut);
     90         StringBuilder message = new StringBuilder();
     91         boolean errorFound = false;
     92         for (int i = 0; i < INPUTSIZE; i++) {
     93             for (int j = 0; j < 1 ; j++) {
     94                 // Extract the inputs.
     95                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
     96                 args.inV = arrayInV[i];
     97                 // Figure out what the outputs should have been.
     98                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
     99                 CoreMathVerifier.computeSincos(args, target);
    100                 // Validate the outputs.
    101                 boolean valid = true;
    102                 if (!args.outCos.couldBe(arrayOutCos[i * 1 + j])) {
    103                     valid = false;
    104                 }
    105                 if (!args.out.couldBe(arrayOut[i * 1 + j])) {
    106                     valid = false;
    107                 }
    108                 if (!valid) {
    109                     if (!errorFound) {
    110                         errorFound = true;
    111                         message.append("Input inV: ");
    112                         appendVariableToMessage(message, args.inV);
    113                         message.append("\n");
    114                         message.append("Expected output outCos: ");
    115                         appendVariableToMessage(message, args.outCos);
    116                         message.append("\n");
    117                         message.append("Actual   output outCos: ");
    118                         appendVariableToMessage(message, arrayOutCos[i * 1 + j]);
    119                         if (!args.outCos.couldBe(arrayOutCos[i * 1 + j])) {
    120                             message.append(" FAIL");
    121                         }
    122                         message.append("\n");
    123                         message.append("Expected output out: ");
    124                         appendVariableToMessage(message, args.out);
    125                         message.append("\n");
    126                         message.append("Actual   output out: ");
    127                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
    128                         if (!args.out.couldBe(arrayOut[i * 1 + j])) {
    129                             message.append(" FAIL");
    130                         }
    131                         message.append("\n");
    132                         message.append("Errors at");
    133                     }
    134                     message.append(" [");
    135                     message.append(Integer.toString(i));
    136                     message.append(", ");
    137                     message.append(Integer.toString(j));
    138                     message.append("]");
    139                 }
    140             }
    141         }
    142         assertFalse("Incorrect output for checkSincosFloatFloatFloat" +
    143                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    144     }
    145 
    146     private void checkSincosFloat2Float2Float2() {
    147         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xc85bab4e3e2fc77cl, false);
    148         try {
    149             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    150             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    151             script.set_gAllocOutCos(outCos);
    152             script.forEach_testSincosFloat2Float2Float2(inV, out);
    153             verifyResultsSincosFloat2Float2Float2(inV, outCos, out, false);
    154             outCos.destroy();
    155             out.destroy();
    156         } catch (Exception e) {
    157             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat2Float2Float2: " + e.toString());
    158         }
    159         try {
    160             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    161             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    162             scriptRelaxed.set_gAllocOutCos(outCos);
    163             scriptRelaxed.forEach_testSincosFloat2Float2Float2(inV, out);
    164             verifyResultsSincosFloat2Float2Float2(inV, outCos, out, true);
    165             outCos.destroy();
    166             out.destroy();
    167         } catch (Exception e) {
    168             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat2Float2Float2: " + e.toString());
    169         }
    170         inV.destroy();
    171     }
    172 
    173     private void verifyResultsSincosFloat2Float2Float2(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) {
    174         float[] arrayInV = new float[INPUTSIZE * 2];
    175         Arrays.fill(arrayInV, (float) 42);
    176         inV.copyTo(arrayInV);
    177         float[] arrayOutCos = new float[INPUTSIZE * 2];
    178         Arrays.fill(arrayOutCos, (float) 42);
    179         outCos.copyTo(arrayOutCos);
    180         float[] arrayOut = new float[INPUTSIZE * 2];
    181         Arrays.fill(arrayOut, (float) 42);
    182         out.copyTo(arrayOut);
    183         StringBuilder message = new StringBuilder();
    184         boolean errorFound = false;
    185         for (int i = 0; i < INPUTSIZE; i++) {
    186             for (int j = 0; j < 2 ; j++) {
    187                 // Extract the inputs.
    188                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
    189                 args.inV = arrayInV[i * 2 + j];
    190                 // Figure out what the outputs should have been.
    191                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
    192                 CoreMathVerifier.computeSincos(args, target);
    193                 // Validate the outputs.
    194                 boolean valid = true;
    195                 if (!args.outCos.couldBe(arrayOutCos[i * 2 + j])) {
    196                     valid = false;
    197                 }
    198                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    199                     valid = false;
    200                 }
    201                 if (!valid) {
    202                     if (!errorFound) {
    203                         errorFound = true;
    204                         message.append("Input inV: ");
    205                         appendVariableToMessage(message, args.inV);
    206                         message.append("\n");
    207                         message.append("Expected output outCos: ");
    208                         appendVariableToMessage(message, args.outCos);
    209                         message.append("\n");
    210                         message.append("Actual   output outCos: ");
    211                         appendVariableToMessage(message, arrayOutCos[i * 2 + j]);
    212                         if (!args.outCos.couldBe(arrayOutCos[i * 2 + j])) {
    213                             message.append(" FAIL");
    214                         }
    215                         message.append("\n");
    216                         message.append("Expected output out: ");
    217                         appendVariableToMessage(message, args.out);
    218                         message.append("\n");
    219                         message.append("Actual   output out: ");
    220                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
    221                         if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    222                             message.append(" FAIL");
    223                         }
    224                         message.append("\n");
    225                         message.append("Errors at");
    226                     }
    227                     message.append(" [");
    228                     message.append(Integer.toString(i));
    229                     message.append(", ");
    230                     message.append(Integer.toString(j));
    231                     message.append("]");
    232                 }
    233             }
    234         }
    235         assertFalse("Incorrect output for checkSincosFloat2Float2Float2" +
    236                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    237     }
    238 
    239     private void checkSincosFloat3Float3Float3() {
    240         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x1cc0896e400dc91dl, false);
    241         try {
    242             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    243             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    244             script.set_gAllocOutCos(outCos);
    245             script.forEach_testSincosFloat3Float3Float3(inV, out);
    246             verifyResultsSincosFloat3Float3Float3(inV, outCos, out, false);
    247             outCos.destroy();
    248             out.destroy();
    249         } catch (Exception e) {
    250             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat3Float3Float3: " + e.toString());
    251         }
    252         try {
    253             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    254             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    255             scriptRelaxed.set_gAllocOutCos(outCos);
    256             scriptRelaxed.forEach_testSincosFloat3Float3Float3(inV, out);
    257             verifyResultsSincosFloat3Float3Float3(inV, outCos, out, true);
    258             outCos.destroy();
    259             out.destroy();
    260         } catch (Exception e) {
    261             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat3Float3Float3: " + e.toString());
    262         }
    263         inV.destroy();
    264     }
    265 
    266     private void verifyResultsSincosFloat3Float3Float3(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) {
    267         float[] arrayInV = new float[INPUTSIZE * 4];
    268         Arrays.fill(arrayInV, (float) 42);
    269         inV.copyTo(arrayInV);
    270         float[] arrayOutCos = new float[INPUTSIZE * 4];
    271         Arrays.fill(arrayOutCos, (float) 42);
    272         outCos.copyTo(arrayOutCos);
    273         float[] arrayOut = new float[INPUTSIZE * 4];
    274         Arrays.fill(arrayOut, (float) 42);
    275         out.copyTo(arrayOut);
    276         StringBuilder message = new StringBuilder();
    277         boolean errorFound = false;
    278         for (int i = 0; i < INPUTSIZE; i++) {
    279             for (int j = 0; j < 3 ; j++) {
    280                 // Extract the inputs.
    281                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
    282                 args.inV = arrayInV[i * 4 + j];
    283                 // Figure out what the outputs should have been.
    284                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
    285                 CoreMathVerifier.computeSincos(args, target);
    286                 // Validate the outputs.
    287                 boolean valid = true;
    288                 if (!args.outCos.couldBe(arrayOutCos[i * 4 + j])) {
    289                     valid = false;
    290                 }
    291                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    292                     valid = false;
    293                 }
    294                 if (!valid) {
    295                     if (!errorFound) {
    296                         errorFound = true;
    297                         message.append("Input inV: ");
    298                         appendVariableToMessage(message, args.inV);
    299                         message.append("\n");
    300                         message.append("Expected output outCos: ");
    301                         appendVariableToMessage(message, args.outCos);
    302                         message.append("\n");
    303                         message.append("Actual   output outCos: ");
    304                         appendVariableToMessage(message, arrayOutCos[i * 4 + j]);
    305                         if (!args.outCos.couldBe(arrayOutCos[i * 4 + j])) {
    306                             message.append(" FAIL");
    307                         }
    308                         message.append("\n");
    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 * 4 + j]);
    314                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    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                     message.append(Integer.toString(j));
    324                     message.append("]");
    325                 }
    326             }
    327         }
    328         assertFalse("Incorrect output for checkSincosFloat3Float3Float3" +
    329                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    330     }
    331 
    332     private void checkSincosFloat4Float4Float4() {
    333         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x7125678e41ebcabel, false);
    334         try {
    335             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    336             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    337             script.set_gAllocOutCos(outCos);
    338             script.forEach_testSincosFloat4Float4Float4(inV, out);
    339             verifyResultsSincosFloat4Float4Float4(inV, outCos, out, false);
    340             outCos.destroy();
    341             out.destroy();
    342         } catch (Exception e) {
    343             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat4Float4Float4: " + e.toString());
    344         }
    345         try {
    346             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    347             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    348             scriptRelaxed.set_gAllocOutCos(outCos);
    349             scriptRelaxed.forEach_testSincosFloat4Float4Float4(inV, out);
    350             verifyResultsSincosFloat4Float4Float4(inV, outCos, out, true);
    351             outCos.destroy();
    352             out.destroy();
    353         } catch (Exception e) {
    354             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat4Float4Float4: " + e.toString());
    355         }
    356         inV.destroy();
    357     }
    358 
    359     private void verifyResultsSincosFloat4Float4Float4(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) {
    360         float[] arrayInV = new float[INPUTSIZE * 4];
    361         Arrays.fill(arrayInV, (float) 42);
    362         inV.copyTo(arrayInV);
    363         float[] arrayOutCos = new float[INPUTSIZE * 4];
    364         Arrays.fill(arrayOutCos, (float) 42);
    365         outCos.copyTo(arrayOutCos);
    366         float[] arrayOut = new float[INPUTSIZE * 4];
    367         Arrays.fill(arrayOut, (float) 42);
    368         out.copyTo(arrayOut);
    369         StringBuilder message = new StringBuilder();
    370         boolean errorFound = false;
    371         for (int i = 0; i < INPUTSIZE; i++) {
    372             for (int j = 0; j < 4 ; j++) {
    373                 // Extract the inputs.
    374                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
    375                 args.inV = arrayInV[i * 4 + j];
    376                 // Figure out what the outputs should have been.
    377                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
    378                 CoreMathVerifier.computeSincos(args, target);
    379                 // Validate the outputs.
    380                 boolean valid = true;
    381                 if (!args.outCos.couldBe(arrayOutCos[i * 4 + j])) {
    382                     valid = false;
    383                 }
    384                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    385                     valid = false;
    386                 }
    387                 if (!valid) {
    388                     if (!errorFound) {
    389                         errorFound = true;
    390                         message.append("Input inV: ");
    391                         appendVariableToMessage(message, args.inV);
    392                         message.append("\n");
    393                         message.append("Expected output outCos: ");
    394                         appendVariableToMessage(message, args.outCos);
    395                         message.append("\n");
    396                         message.append("Actual   output outCos: ");
    397                         appendVariableToMessage(message, arrayOutCos[i * 4 + j]);
    398                         if (!args.outCos.couldBe(arrayOutCos[i * 4 + j])) {
    399                             message.append(" FAIL");
    400                         }
    401                         message.append("\n");
    402                         message.append("Expected output out: ");
    403                         appendVariableToMessage(message, args.out);
    404                         message.append("\n");
    405                         message.append("Actual   output out: ");
    406                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
    407                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    408                             message.append(" FAIL");
    409                         }
    410                         message.append("\n");
    411                         message.append("Errors at");
    412                     }
    413                     message.append(" [");
    414                     message.append(Integer.toString(i));
    415                     message.append(", ");
    416                     message.append(Integer.toString(j));
    417                     message.append("]");
    418                 }
    419             }
    420         }
    421         assertFalse("Incorrect output for checkSincosFloat4Float4Float4" +
    422                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    423     }
    424 
    425     public class ArgumentsHalfHalfHalf {
    426         public short inV;
    427         public double inVDouble;
    428         public Target.Floaty outCos;
    429         public Target.Floaty out;
    430     }
    431 
    432     private void checkSincosHalfHalfHalf() {
    433         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x9a00091a9ffeac75l, false);
    434         try {
    435             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
    436             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
    437             script.set_gAllocOutCos(outCos);
    438             script.forEach_testSincosHalfHalfHalf(inV, out);
    439             verifyResultsSincosHalfHalfHalf(inV, outCos, out, false);
    440             outCos.destroy();
    441             out.destroy();
    442         } catch (Exception e) {
    443             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosHalfHalfHalf: " + e.toString());
    444         }
    445         try {
    446             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
    447             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
    448             scriptRelaxed.set_gAllocOutCos(outCos);
    449             scriptRelaxed.forEach_testSincosHalfHalfHalf(inV, out);
    450             verifyResultsSincosHalfHalfHalf(inV, outCos, out, true);
    451             outCos.destroy();
    452             out.destroy();
    453         } catch (Exception e) {
    454             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosHalfHalfHalf: " + e.toString());
    455         }
    456         inV.destroy();
    457     }
    458 
    459     private void verifyResultsSincosHalfHalfHalf(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) {
    460         short[] arrayInV = new short[INPUTSIZE * 1];
    461         Arrays.fill(arrayInV, (short) 42);
    462         inV.copyTo(arrayInV);
    463         short[] arrayOutCos = new short[INPUTSIZE * 1];
    464         Arrays.fill(arrayOutCos, (short) 42);
    465         outCos.copyTo(arrayOutCos);
    466         short[] arrayOut = new short[INPUTSIZE * 1];
    467         Arrays.fill(arrayOut, (short) 42);
    468         out.copyTo(arrayOut);
    469         StringBuilder message = new StringBuilder();
    470         boolean errorFound = false;
    471         for (int i = 0; i < INPUTSIZE; i++) {
    472             for (int j = 0; j < 1 ; j++) {
    473                 // Extract the inputs.
    474                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
    475                 args.inV = arrayInV[i];
    476                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
    477                 // Figure out what the outputs should have been.
    478                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
    479                 CoreMathVerifier.computeSincos(args, target);
    480                 // Validate the outputs.
    481                 boolean valid = true;
    482                 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 1 + j]))) {
    483                     valid = false;
    484                 }
    485                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
    486                     valid = false;
    487                 }
    488                 if (!valid) {
    489                     if (!errorFound) {
    490                         errorFound = true;
    491                         message.append("Input inV: ");
    492                         appendVariableToMessage(message, args.inV);
    493                         message.append("\n");
    494                         message.append("Expected output outCos: ");
    495                         appendVariableToMessage(message, args.outCos);
    496                         message.append("\n");
    497                         message.append("Actual   output outCos: ");
    498                         appendVariableToMessage(message, arrayOutCos[i * 1 + j]);
    499                         message.append("\n");
    500                         message.append("Actual   output outCos (in double): ");
    501                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 1 + j]));
    502                         if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 1 + j]))) {
    503                             message.append(" FAIL");
    504                         }
    505                         message.append("\n");
    506                         message.append("Expected output out: ");
    507                         appendVariableToMessage(message, args.out);
    508                         message.append("\n");
    509                         message.append("Actual   output out: ");
    510                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
    511                         message.append("\n");
    512                         message.append("Actual   output out (in double): ");
    513                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]));
    514                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
    515                             message.append(" FAIL");
    516                         }
    517                         message.append("\n");
    518                         message.append("Errors at");
    519                     }
    520                     message.append(" [");
    521                     message.append(Integer.toString(i));
    522                     message.append(", ");
    523                     message.append(Integer.toString(j));
    524                     message.append("]");
    525                 }
    526             }
    527         }
    528         assertFalse("Incorrect output for checkSincosHalfHalfHalf" +
    529                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    530     }
    531 
    532     private void checkSincosHalf2Half2Half2() {
    533         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x87e4d0311b528cc9l, false);
    534         try {
    535             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
    536             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
    537             script.set_gAllocOutCos(outCos);
    538             script.forEach_testSincosHalf2Half2Half2(inV, out);
    539             verifyResultsSincosHalf2Half2Half2(inV, outCos, out, false);
    540             outCos.destroy();
    541             out.destroy();
    542         } catch (Exception e) {
    543             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosHalf2Half2Half2: " + e.toString());
    544         }
    545         try {
    546             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
    547             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
    548             scriptRelaxed.set_gAllocOutCos(outCos);
    549             scriptRelaxed.forEach_testSincosHalf2Half2Half2(inV, out);
    550             verifyResultsSincosHalf2Half2Half2(inV, outCos, out, true);
    551             outCos.destroy();
    552             out.destroy();
    553         } catch (Exception e) {
    554             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosHalf2Half2Half2: " + e.toString());
    555         }
    556         inV.destroy();
    557     }
    558 
    559     private void verifyResultsSincosHalf2Half2Half2(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) {
    560         short[] arrayInV = new short[INPUTSIZE * 2];
    561         Arrays.fill(arrayInV, (short) 42);
    562         inV.copyTo(arrayInV);
    563         short[] arrayOutCos = new short[INPUTSIZE * 2];
    564         Arrays.fill(arrayOutCos, (short) 42);
    565         outCos.copyTo(arrayOutCos);
    566         short[] arrayOut = new short[INPUTSIZE * 2];
    567         Arrays.fill(arrayOut, (short) 42);
    568         out.copyTo(arrayOut);
    569         StringBuilder message = new StringBuilder();
    570         boolean errorFound = false;
    571         for (int i = 0; i < INPUTSIZE; i++) {
    572             for (int j = 0; j < 2 ; j++) {
    573                 // Extract the inputs.
    574                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
    575                 args.inV = arrayInV[i * 2 + j];
    576                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
    577                 // Figure out what the outputs should have been.
    578                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
    579                 CoreMathVerifier.computeSincos(args, target);
    580                 // Validate the outputs.
    581                 boolean valid = true;
    582                 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 2 + j]))) {
    583                     valid = false;
    584                 }
    585                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
    586                     valid = false;
    587                 }
    588                 if (!valid) {
    589                     if (!errorFound) {
    590                         errorFound = true;
    591                         message.append("Input inV: ");
    592                         appendVariableToMessage(message, args.inV);
    593                         message.append("\n");
    594                         message.append("Expected output outCos: ");
    595                         appendVariableToMessage(message, args.outCos);
    596                         message.append("\n");
    597                         message.append("Actual   output outCos: ");
    598                         appendVariableToMessage(message, arrayOutCos[i * 2 + j]);
    599                         message.append("\n");
    600                         message.append("Actual   output outCos (in double): ");
    601                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 2 + j]));
    602                         if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 2 + j]))) {
    603                             message.append(" FAIL");
    604                         }
    605                         message.append("\n");
    606                         message.append("Expected output out: ");
    607                         appendVariableToMessage(message, args.out);
    608                         message.append("\n");
    609                         message.append("Actual   output out: ");
    610                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
    611                         message.append("\n");
    612                         message.append("Actual   output out (in double): ");
    613                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]));
    614                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
    615                             message.append(" FAIL");
    616                         }
    617                         message.append("\n");
    618                         message.append("Errors at");
    619                     }
    620                     message.append(" [");
    621                     message.append(Integer.toString(i));
    622                     message.append(", ");
    623                     message.append(Integer.toString(j));
    624                     message.append("]");
    625                 }
    626             }
    627         }
    628         assertFalse("Incorrect output for checkSincosHalf2Half2Half2" +
    629                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    630     }
    631 
    632     private void checkSincosHalf3Half3Half3() {
    633         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xad99501a79f19d98l, false);
    634         try {
    635             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
    636             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
    637             script.set_gAllocOutCos(outCos);
    638             script.forEach_testSincosHalf3Half3Half3(inV, out);
    639             verifyResultsSincosHalf3Half3Half3(inV, outCos, out, false);
    640             outCos.destroy();
    641             out.destroy();
    642         } catch (Exception e) {
    643             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosHalf3Half3Half3: " + e.toString());
    644         }
    645         try {
    646             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
    647             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
    648             scriptRelaxed.set_gAllocOutCos(outCos);
    649             scriptRelaxed.forEach_testSincosHalf3Half3Half3(inV, out);
    650             verifyResultsSincosHalf3Half3Half3(inV, outCos, out, true);
    651             outCos.destroy();
    652             out.destroy();
    653         } catch (Exception e) {
    654             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosHalf3Half3Half3: " + e.toString());
    655         }
    656         inV.destroy();
    657     }
    658 
    659     private void verifyResultsSincosHalf3Half3Half3(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) {
    660         short[] arrayInV = new short[INPUTSIZE * 4];
    661         Arrays.fill(arrayInV, (short) 42);
    662         inV.copyTo(arrayInV);
    663         short[] arrayOutCos = new short[INPUTSIZE * 4];
    664         Arrays.fill(arrayOutCos, (short) 42);
    665         outCos.copyTo(arrayOutCos);
    666         short[] arrayOut = new short[INPUTSIZE * 4];
    667         Arrays.fill(arrayOut, (short) 42);
    668         out.copyTo(arrayOut);
    669         StringBuilder message = new StringBuilder();
    670         boolean errorFound = false;
    671         for (int i = 0; i < INPUTSIZE; i++) {
    672             for (int j = 0; j < 3 ; j++) {
    673                 // Extract the inputs.
    674                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
    675                 args.inV = arrayInV[i * 4 + j];
    676                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
    677                 // Figure out what the outputs should have been.
    678                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
    679                 CoreMathVerifier.computeSincos(args, target);
    680                 // Validate the outputs.
    681                 boolean valid = true;
    682                 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j]))) {
    683                     valid = false;
    684                 }
    685                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
    686                     valid = false;
    687                 }
    688                 if (!valid) {
    689                     if (!errorFound) {
    690                         errorFound = true;
    691                         message.append("Input inV: ");
    692                         appendVariableToMessage(message, args.inV);
    693                         message.append("\n");
    694                         message.append("Expected output outCos: ");
    695                         appendVariableToMessage(message, args.outCos);
    696                         message.append("\n");
    697                         message.append("Actual   output outCos: ");
    698                         appendVariableToMessage(message, arrayOutCos[i * 4 + j]);
    699                         message.append("\n");
    700                         message.append("Actual   output outCos (in double): ");
    701                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j]));
    702                         if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j]))) {
    703                             message.append(" FAIL");
    704                         }
    705                         message.append("\n");
    706                         message.append("Expected output out: ");
    707                         appendVariableToMessage(message, args.out);
    708                         message.append("\n");
    709                         message.append("Actual   output out: ");
    710                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
    711                         message.append("\n");
    712                         message.append("Actual   output out (in double): ");
    713                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
    714                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
    715                             message.append(" FAIL");
    716                         }
    717                         message.append("\n");
    718                         message.append("Errors at");
    719                     }
    720                     message.append(" [");
    721                     message.append(Integer.toString(i));
    722                     message.append(", ");
    723                     message.append(Integer.toString(j));
    724                     message.append("]");
    725                 }
    726             }
    727         }
    728         assertFalse("Incorrect output for checkSincosHalf3Half3Half3" +
    729                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    730     }
    731 
    732     private void checkSincosHalf4Half4Half4() {
    733         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xd34dd003d890ae67l, false);
    734         try {
    735             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
    736             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
    737             script.set_gAllocOutCos(outCos);
    738             script.forEach_testSincosHalf4Half4Half4(inV, out);
    739             verifyResultsSincosHalf4Half4Half4(inV, outCos, out, false);
    740             outCos.destroy();
    741             out.destroy();
    742         } catch (Exception e) {
    743             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosHalf4Half4Half4: " + e.toString());
    744         }
    745         try {
    746             Allocation outCos = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
    747             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
    748             scriptRelaxed.set_gAllocOutCos(outCos);
    749             scriptRelaxed.forEach_testSincosHalf4Half4Half4(inV, out);
    750             verifyResultsSincosHalf4Half4Half4(inV, outCos, out, true);
    751             outCos.destroy();
    752             out.destroy();
    753         } catch (Exception e) {
    754             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosHalf4Half4Half4: " + e.toString());
    755         }
    756         inV.destroy();
    757     }
    758 
    759     private void verifyResultsSincosHalf4Half4Half4(Allocation inV, Allocation outCos, Allocation out, boolean relaxed) {
    760         short[] arrayInV = new short[INPUTSIZE * 4];
    761         Arrays.fill(arrayInV, (short) 42);
    762         inV.copyTo(arrayInV);
    763         short[] arrayOutCos = new short[INPUTSIZE * 4];
    764         Arrays.fill(arrayOutCos, (short) 42);
    765         outCos.copyTo(arrayOutCos);
    766         short[] arrayOut = new short[INPUTSIZE * 4];
    767         Arrays.fill(arrayOut, (short) 42);
    768         out.copyTo(arrayOut);
    769         StringBuilder message = new StringBuilder();
    770         boolean errorFound = false;
    771         for (int i = 0; i < INPUTSIZE; i++) {
    772             for (int j = 0; j < 4 ; j++) {
    773                 // Extract the inputs.
    774                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
    775                 args.inV = arrayInV[i * 4 + j];
    776                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
    777                 // Figure out what the outputs should have been.
    778                 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
    779                 CoreMathVerifier.computeSincos(args, target);
    780                 // Validate the outputs.
    781                 boolean valid = true;
    782                 if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j]))) {
    783                     valid = false;
    784                 }
    785                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
    786                     valid = false;
    787                 }
    788                 if (!valid) {
    789                     if (!errorFound) {
    790                         errorFound = true;
    791                         message.append("Input inV: ");
    792                         appendVariableToMessage(message, args.inV);
    793                         message.append("\n");
    794                         message.append("Expected output outCos: ");
    795                         appendVariableToMessage(message, args.outCos);
    796                         message.append("\n");
    797                         message.append("Actual   output outCos: ");
    798                         appendVariableToMessage(message, arrayOutCos[i * 4 + j]);
    799                         message.append("\n");
    800                         message.append("Actual   output outCos (in double): ");
    801                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j]));
    802                         if (!args.outCos.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutCos[i * 4 + j]))) {
    803                             message.append(" FAIL");
    804                         }
    805                         message.append("\n");
    806                         message.append("Expected output out: ");
    807                         appendVariableToMessage(message, args.out);
    808                         message.append("\n");
    809                         message.append("Actual   output out: ");
    810                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
    811                         message.append("\n");
    812                         message.append("Actual   output out (in double): ");
    813                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
    814                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
    815                             message.append(" FAIL");
    816                         }
    817                         message.append("\n");
    818                         message.append("Errors at");
    819                     }
    820                     message.append(" [");
    821                     message.append(Integer.toString(i));
    822                     message.append(", ");
    823                     message.append(Integer.toString(j));
    824                     message.append("]");
    825                 }
    826             }
    827         }
    828         assertFalse("Incorrect output for checkSincosHalf4Half4Half4" +
    829                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    830     }
    831 
    832     public void testSincos() {
    833         checkSincosFloatFloatFloat();
    834         checkSincosFloat2Float2Float2();
    835         checkSincosFloat3Float3Float3();
    836         checkSincosFloat4Float4Float4();
    837         checkSincosHalfHalfHalf();
    838         checkSincosHalf2Half2Half2();
    839         checkSincosHalf3Half3Half3();
    840         checkSincosHalf4Half4Half4();
    841     }
    842 }
    843