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 TestNativeTanpi extends RSBaseCompute {
     29 
     30     private ScriptC_TestNativeTanpi script;
     31     private ScriptC_TestNativeTanpiRelaxed scriptRelaxed;
     32 
     33     @Override
     34     protected void setUp() throws Exception {
     35         super.setUp();
     36         script = new ScriptC_TestNativeTanpi(mRS);
     37         scriptRelaxed = new ScriptC_TestNativeTanpiRelaxed(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 ArgumentsFloatFloat {
     48         public float inV;
     49         public Target.Floaty out;
     50     }
     51 
     52     private void checkNativeTanpiFloatFloat() {
     53         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x88f565b6d39357f6l, false);
     54         try {
     55             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     56             script.forEach_testNativeTanpiFloatFloat(inV, out);
     57             verifyResultsNativeTanpiFloatFloat(inV, out, false);
     58             out.destroy();
     59         } catch (Exception e) {
     60             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiFloatFloat: " + e.toString());
     61         }
     62         try {
     63             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     64             scriptRelaxed.forEach_testNativeTanpiFloatFloat(inV, out);
     65             verifyResultsNativeTanpiFloatFloat(inV, out, true);
     66             out.destroy();
     67         } catch (Exception e) {
     68             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiFloatFloat: " + e.toString());
     69         }
     70         inV.destroy();
     71     }
     72 
     73     private void verifyResultsNativeTanpiFloatFloat(Allocation inV, Allocation out, boolean relaxed) {
     74         float[] arrayInV = new float[INPUTSIZE * 1];
     75         Arrays.fill(arrayInV, (float) 42);
     76         inV.copyTo(arrayInV);
     77         float[] arrayOut = new float[INPUTSIZE * 1];
     78         Arrays.fill(arrayOut, (float) 42);
     79         out.copyTo(arrayOut);
     80         StringBuilder message = new StringBuilder();
     81         boolean errorFound = false;
     82         for (int i = 0; i < INPUTSIZE; i++) {
     83             for (int j = 0; j < 1 ; j++) {
     84                 // Extract the inputs.
     85                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
     86                 args.inV = arrayInV[i];
     87                 // Figure out what the outputs should have been.
     88                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
     89                 CoreMathVerifier.computeNativeTanpi(args, target);
     90                 // Validate the outputs.
     91                 boolean valid = true;
     92                 if (!args.out.couldBe(arrayOut[i * 1 + j])) {
     93                     valid = false;
     94                 }
     95                 if (!valid) {
     96                     if (!errorFound) {
     97                         errorFound = true;
     98                         message.append("Input inV: ");
     99                         appendVariableToMessage(message, args.inV);
    100                         message.append("\n");
    101                         message.append("Expected output out: ");
    102                         appendVariableToMessage(message, args.out);
    103                         message.append("\n");
    104                         message.append("Actual   output out: ");
    105                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
    106                         if (!args.out.couldBe(arrayOut[i * 1 + j])) {
    107                             message.append(" FAIL");
    108                         }
    109                         message.append("\n");
    110                         message.append("Errors at");
    111                     }
    112                     message.append(" [");
    113                     message.append(Integer.toString(i));
    114                     message.append(", ");
    115                     message.append(Integer.toString(j));
    116                     message.append("]");
    117                 }
    118             }
    119         }
    120         assertFalse("Incorrect output for checkNativeTanpiFloatFloat" +
    121                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    122     }
    123 
    124     private void checkNativeTanpiFloat2Float2() {
    125         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x34465ac4e7b090aal, false);
    126         try {
    127             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    128             script.forEach_testNativeTanpiFloat2Float2(inV, out);
    129             verifyResultsNativeTanpiFloat2Float2(inV, out, false);
    130             out.destroy();
    131         } catch (Exception e) {
    132             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiFloat2Float2: " + e.toString());
    133         }
    134         try {
    135             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    136             scriptRelaxed.forEach_testNativeTanpiFloat2Float2(inV, out);
    137             verifyResultsNativeTanpiFloat2Float2(inV, out, true);
    138             out.destroy();
    139         } catch (Exception e) {
    140             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiFloat2Float2: " + e.toString());
    141         }
    142         inV.destroy();
    143     }
    144 
    145     private void verifyResultsNativeTanpiFloat2Float2(Allocation inV, Allocation out, boolean relaxed) {
    146         float[] arrayInV = new float[INPUTSIZE * 2];
    147         Arrays.fill(arrayInV, (float) 42);
    148         inV.copyTo(arrayInV);
    149         float[] arrayOut = new float[INPUTSIZE * 2];
    150         Arrays.fill(arrayOut, (float) 42);
    151         out.copyTo(arrayOut);
    152         StringBuilder message = new StringBuilder();
    153         boolean errorFound = false;
    154         for (int i = 0; i < INPUTSIZE; i++) {
    155             for (int j = 0; j < 2 ; j++) {
    156                 // Extract the inputs.
    157                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
    158                 args.inV = arrayInV[i * 2 + j];
    159                 // Figure out what the outputs should have been.
    160                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
    161                 CoreMathVerifier.computeNativeTanpi(args, target);
    162                 // Validate the outputs.
    163                 boolean valid = true;
    164                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    165                     valid = false;
    166                 }
    167                 if (!valid) {
    168                     if (!errorFound) {
    169                         errorFound = true;
    170                         message.append("Input inV: ");
    171                         appendVariableToMessage(message, args.inV);
    172                         message.append("\n");
    173                         message.append("Expected output out: ");
    174                         appendVariableToMessage(message, args.out);
    175                         message.append("\n");
    176                         message.append("Actual   output out: ");
    177                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
    178                         if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    179                             message.append(" FAIL");
    180                         }
    181                         message.append("\n");
    182                         message.append("Errors at");
    183                     }
    184                     message.append(" [");
    185                     message.append(Integer.toString(i));
    186                     message.append(", ");
    187                     message.append(Integer.toString(j));
    188                     message.append("]");
    189                 }
    190             }
    191         }
    192         assertFalse("Incorrect output for checkNativeTanpiFloat2Float2" +
    193                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    194     }
    195 
    196     private void checkNativeTanpiFloat3Float3() {
    197         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x344823dfddcbb188l, false);
    198         try {
    199             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    200             script.forEach_testNativeTanpiFloat3Float3(inV, out);
    201             verifyResultsNativeTanpiFloat3Float3(inV, out, false);
    202             out.destroy();
    203         } catch (Exception e) {
    204             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiFloat3Float3: " + e.toString());
    205         }
    206         try {
    207             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    208             scriptRelaxed.forEach_testNativeTanpiFloat3Float3(inV, out);
    209             verifyResultsNativeTanpiFloat3Float3(inV, out, true);
    210             out.destroy();
    211         } catch (Exception e) {
    212             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiFloat3Float3: " + e.toString());
    213         }
    214         inV.destroy();
    215     }
    216 
    217     private void verifyResultsNativeTanpiFloat3Float3(Allocation inV, Allocation out, boolean relaxed) {
    218         float[] arrayInV = new float[INPUTSIZE * 4];
    219         Arrays.fill(arrayInV, (float) 42);
    220         inV.copyTo(arrayInV);
    221         float[] arrayOut = new float[INPUTSIZE * 4];
    222         Arrays.fill(arrayOut, (float) 42);
    223         out.copyTo(arrayOut);
    224         StringBuilder message = new StringBuilder();
    225         boolean errorFound = false;
    226         for (int i = 0; i < INPUTSIZE; i++) {
    227             for (int j = 0; j < 3 ; j++) {
    228                 // Extract the inputs.
    229                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
    230                 args.inV = arrayInV[i * 4 + j];
    231                 // Figure out what the outputs should have been.
    232                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
    233                 CoreMathVerifier.computeNativeTanpi(args, target);
    234                 // Validate the outputs.
    235                 boolean valid = true;
    236                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    237                     valid = false;
    238                 }
    239                 if (!valid) {
    240                     if (!errorFound) {
    241                         errorFound = true;
    242                         message.append("Input inV: ");
    243                         appendVariableToMessage(message, args.inV);
    244                         message.append("\n");
    245                         message.append("Expected output out: ");
    246                         appendVariableToMessage(message, args.out);
    247                         message.append("\n");
    248                         message.append("Actual   output out: ");
    249                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
    250                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    251                             message.append(" FAIL");
    252                         }
    253                         message.append("\n");
    254                         message.append("Errors at");
    255                     }
    256                     message.append(" [");
    257                     message.append(Integer.toString(i));
    258                     message.append(", ");
    259                     message.append(Integer.toString(j));
    260                     message.append("]");
    261                 }
    262             }
    263         }
    264         assertFalse("Incorrect output for checkNativeTanpiFloat3Float3" +
    265                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    266     }
    267 
    268     private void checkNativeTanpiFloat4Float4() {
    269         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x3449ecfad3e6d266l, false);
    270         try {
    271             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    272             script.forEach_testNativeTanpiFloat4Float4(inV, out);
    273             verifyResultsNativeTanpiFloat4Float4(inV, out, false);
    274             out.destroy();
    275         } catch (Exception e) {
    276             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiFloat4Float4: " + e.toString());
    277         }
    278         try {
    279             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    280             scriptRelaxed.forEach_testNativeTanpiFloat4Float4(inV, out);
    281             verifyResultsNativeTanpiFloat4Float4(inV, out, true);
    282             out.destroy();
    283         } catch (Exception e) {
    284             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiFloat4Float4: " + e.toString());
    285         }
    286         inV.destroy();
    287     }
    288 
    289     private void verifyResultsNativeTanpiFloat4Float4(Allocation inV, Allocation out, boolean relaxed) {
    290         float[] arrayInV = new float[INPUTSIZE * 4];
    291         Arrays.fill(arrayInV, (float) 42);
    292         inV.copyTo(arrayInV);
    293         float[] arrayOut = new float[INPUTSIZE * 4];
    294         Arrays.fill(arrayOut, (float) 42);
    295         out.copyTo(arrayOut);
    296         StringBuilder message = new StringBuilder();
    297         boolean errorFound = false;
    298         for (int i = 0; i < INPUTSIZE; i++) {
    299             for (int j = 0; j < 4 ; j++) {
    300                 // Extract the inputs.
    301                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
    302                 args.inV = arrayInV[i * 4 + j];
    303                 // Figure out what the outputs should have been.
    304                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
    305                 CoreMathVerifier.computeNativeTanpi(args, target);
    306                 // Validate the outputs.
    307                 boolean valid = true;
    308                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    309                     valid = false;
    310                 }
    311                 if (!valid) {
    312                     if (!errorFound) {
    313                         errorFound = true;
    314                         message.append("Input inV: ");
    315                         appendVariableToMessage(message, args.inV);
    316                         message.append("\n");
    317                         message.append("Expected output out: ");
    318                         appendVariableToMessage(message, args.out);
    319                         message.append("\n");
    320                         message.append("Actual   output out: ");
    321                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
    322                         if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    323                             message.append(" FAIL");
    324                         }
    325                         message.append("\n");
    326                         message.append("Errors at");
    327                     }
    328                     message.append(" [");
    329                     message.append(Integer.toString(i));
    330                     message.append(", ");
    331                     message.append(Integer.toString(j));
    332                     message.append("]");
    333                 }
    334             }
    335         }
    336         assertFalse("Incorrect output for checkNativeTanpiFloat4Float4" +
    337                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    338     }
    339 
    340     public class ArgumentsHalfHalf {
    341         public short inV;
    342         public double inVDouble;
    343         public short out;
    344         public double outDouble;
    345     }
    346 
    347     private void checkNativeTanpiHalfHalf() {
    348         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x2ba7d9c1a1618990l, -100, 100);
    349         try {
    350             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
    351             script.forEach_testNativeTanpiHalfHalf(inV, out);
    352             verifyResultsNativeTanpiHalfHalf(inV, out, false);
    353             out.destroy();
    354         } catch (Exception e) {
    355             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiHalfHalf: " + e.toString());
    356         }
    357         try {
    358             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
    359             scriptRelaxed.forEach_testNativeTanpiHalfHalf(inV, out);
    360             verifyResultsNativeTanpiHalfHalf(inV, out, true);
    361             out.destroy();
    362         } catch (Exception e) {
    363             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiHalfHalf: " + e.toString());
    364         }
    365         inV.destroy();
    366     }
    367 
    368     private void verifyResultsNativeTanpiHalfHalf(Allocation inV, Allocation out, boolean relaxed) {
    369         short[] arrayInV = new short[INPUTSIZE * 1];
    370         Arrays.fill(arrayInV, (short) 42);
    371         inV.copyTo(arrayInV);
    372         short[] arrayOut = new short[INPUTSIZE * 1];
    373         Arrays.fill(arrayOut, (short) 42);
    374         out.copyTo(arrayOut);
    375         StringBuilder message = new StringBuilder();
    376         boolean errorFound = false;
    377         for (int i = 0; i < INPUTSIZE; i++) {
    378             for (int j = 0; j < 1 ; j++) {
    379                 // Extract the inputs.
    380                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
    381                 args.inV = arrayInV[i];
    382                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
    383                 // Extract the outputs.
    384                 args.out = arrayOut[i * 1 + j];
    385                 args.outDouble = Float16Utils.convertFloat16ToDouble(args.out);
    386                 // Ask the CoreMathVerifier to validate.
    387                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
    388                 String errorMessage = CoreMathVerifier.verifyNativeTanpi(args, target);
    389                 boolean valid = errorMessage == null;
    390                 if (!valid) {
    391                     if (!errorFound) {
    392                         errorFound = true;
    393                         message.append("Input inV: ");
    394                         appendVariableToMessage(message, args.inV);
    395                         message.append("\n");
    396                         message.append("Output out: ");
    397                         appendVariableToMessage(message, args.out);
    398                         message.append("\n");
    399                         message.append("\n");
    400                         message.append("Output out (in double): ");
    401                         appendVariableToMessage(message, args.outDouble);
    402                         message.append("\n");
    403                         message.append(errorMessage);
    404                         message.append("Errors at");
    405                     }
    406                     message.append(" [");
    407                     message.append(Integer.toString(i));
    408                     message.append(", ");
    409                     message.append(Integer.toString(j));
    410                     message.append("]");
    411                 }
    412             }
    413         }
    414         assertFalse("Incorrect output for checkNativeTanpiHalfHalf" +
    415                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    416     }
    417 
    418     private void checkNativeTanpiHalf2Half2() {
    419         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x4f52d76a40b19f32l, -100, 100);
    420         try {
    421             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
    422             script.forEach_testNativeTanpiHalf2Half2(inV, out);
    423             verifyResultsNativeTanpiHalf2Half2(inV, out, false);
    424             out.destroy();
    425         } catch (Exception e) {
    426             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiHalf2Half2: " + e.toString());
    427         }
    428         try {
    429             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
    430             scriptRelaxed.forEach_testNativeTanpiHalf2Half2(inV, out);
    431             verifyResultsNativeTanpiHalf2Half2(inV, out, true);
    432             out.destroy();
    433         } catch (Exception e) {
    434             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiHalf2Half2: " + e.toString());
    435         }
    436         inV.destroy();
    437     }
    438 
    439     private void verifyResultsNativeTanpiHalf2Half2(Allocation inV, Allocation out, boolean relaxed) {
    440         short[] arrayInV = new short[INPUTSIZE * 2];
    441         Arrays.fill(arrayInV, (short) 42);
    442         inV.copyTo(arrayInV);
    443         short[] arrayOut = new short[INPUTSIZE * 2];
    444         Arrays.fill(arrayOut, (short) 42);
    445         out.copyTo(arrayOut);
    446         StringBuilder message = new StringBuilder();
    447         boolean errorFound = false;
    448         for (int i = 0; i < INPUTSIZE; i++) {
    449             for (int j = 0; j < 2 ; j++) {
    450                 // Extract the inputs.
    451                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
    452                 args.inV = arrayInV[i * 2 + j];
    453                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
    454                 // Extract the outputs.
    455                 args.out = arrayOut[i * 2 + j];
    456                 args.outDouble = Float16Utils.convertFloat16ToDouble(args.out);
    457                 // Ask the CoreMathVerifier to validate.
    458                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
    459                 String errorMessage = CoreMathVerifier.verifyNativeTanpi(args, target);
    460                 boolean valid = errorMessage == null;
    461                 if (!valid) {
    462                     if (!errorFound) {
    463                         errorFound = true;
    464                         message.append("Input inV: ");
    465                         appendVariableToMessage(message, args.inV);
    466                         message.append("\n");
    467                         message.append("Output out: ");
    468                         appendVariableToMessage(message, args.out);
    469                         message.append("\n");
    470                         message.append("\n");
    471                         message.append("Output out (in double): ");
    472                         appendVariableToMessage(message, args.outDouble);
    473                         message.append("\n");
    474                         message.append(errorMessage);
    475                         message.append("Errors at");
    476                     }
    477                     message.append(" [");
    478                     message.append(Integer.toString(i));
    479                     message.append(", ");
    480                     message.append(Integer.toString(j));
    481                     message.append("]");
    482                 }
    483             }
    484         }
    485         assertFalse("Incorrect output for checkNativeTanpiHalf2Half2" +
    486                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    487     }
    488 
    489     private void checkNativeTanpiHalf3Half3() {
    490         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x4f52e20b9fb96426l, -100, 100);
    491         try {
    492             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
    493             script.forEach_testNativeTanpiHalf3Half3(inV, out);
    494             verifyResultsNativeTanpiHalf3Half3(inV, out, false);
    495             out.destroy();
    496         } catch (Exception e) {
    497             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiHalf3Half3: " + e.toString());
    498         }
    499         try {
    500             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
    501             scriptRelaxed.forEach_testNativeTanpiHalf3Half3(inV, out);
    502             verifyResultsNativeTanpiHalf3Half3(inV, out, true);
    503             out.destroy();
    504         } catch (Exception e) {
    505             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiHalf3Half3: " + e.toString());
    506         }
    507         inV.destroy();
    508     }
    509 
    510     private void verifyResultsNativeTanpiHalf3Half3(Allocation inV, Allocation out, boolean relaxed) {
    511         short[] arrayInV = new short[INPUTSIZE * 4];
    512         Arrays.fill(arrayInV, (short) 42);
    513         inV.copyTo(arrayInV);
    514         short[] arrayOut = new short[INPUTSIZE * 4];
    515         Arrays.fill(arrayOut, (short) 42);
    516         out.copyTo(arrayOut);
    517         StringBuilder message = new StringBuilder();
    518         boolean errorFound = false;
    519         for (int i = 0; i < INPUTSIZE; i++) {
    520             for (int j = 0; j < 3 ; j++) {
    521                 // Extract the inputs.
    522                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
    523                 args.inV = arrayInV[i * 4 + j];
    524                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
    525                 // Extract the outputs.
    526                 args.out = arrayOut[i * 4 + j];
    527                 args.outDouble = Float16Utils.convertFloat16ToDouble(args.out);
    528                 // Ask the CoreMathVerifier to validate.
    529                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
    530                 String errorMessage = CoreMathVerifier.verifyNativeTanpi(args, target);
    531                 boolean valid = errorMessage == null;
    532                 if (!valid) {
    533                     if (!errorFound) {
    534                         errorFound = true;
    535                         message.append("Input inV: ");
    536                         appendVariableToMessage(message, args.inV);
    537                         message.append("\n");
    538                         message.append("Output out: ");
    539                         appendVariableToMessage(message, args.out);
    540                         message.append("\n");
    541                         message.append("\n");
    542                         message.append("Output out (in double): ");
    543                         appendVariableToMessage(message, args.outDouble);
    544                         message.append("\n");
    545                         message.append(errorMessage);
    546                         message.append("Errors at");
    547                     }
    548                     message.append(" [");
    549                     message.append(Integer.toString(i));
    550                     message.append(", ");
    551                     message.append(Integer.toString(j));
    552                     message.append("]");
    553                 }
    554             }
    555         }
    556         assertFalse("Incorrect output for checkNativeTanpiHalf3Half3" +
    557                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    558     }
    559 
    560     private void checkNativeTanpiHalf4Half4() {
    561         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x4f52ecacfec1291al, -100, 100);
    562         try {
    563             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
    564             script.forEach_testNativeTanpiHalf4Half4(inV, out);
    565             verifyResultsNativeTanpiHalf4Half4(inV, out, false);
    566             out.destroy();
    567         } catch (Exception e) {
    568             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiHalf4Half4: " + e.toString());
    569         }
    570         try {
    571             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
    572             scriptRelaxed.forEach_testNativeTanpiHalf4Half4(inV, out);
    573             verifyResultsNativeTanpiHalf4Half4(inV, out, true);
    574             out.destroy();
    575         } catch (Exception e) {
    576             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeTanpiHalf4Half4: " + e.toString());
    577         }
    578         inV.destroy();
    579     }
    580 
    581     private void verifyResultsNativeTanpiHalf4Half4(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 * 4];
    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             for (int j = 0; j < 4 ; j++) {
    592                 // Extract the inputs.
    593                 ArgumentsHalfHalf args = new ArgumentsHalfHalf();
    594                 args.inV = arrayInV[i * 4 + j];
    595                 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV);
    596                 // Extract the outputs.
    597                 args.out = arrayOut[i * 4 + j];
    598                 args.outDouble = Float16Utils.convertFloat16ToDouble(args.out);
    599                 // Ask the CoreMathVerifier to validate.
    600                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
    601                 String errorMessage = CoreMathVerifier.verifyNativeTanpi(args, target);
    602                 boolean valid = errorMessage == null;
    603                 if (!valid) {
    604                     if (!errorFound) {
    605                         errorFound = true;
    606                         message.append("Input inV: ");
    607                         appendVariableToMessage(message, args.inV);
    608                         message.append("\n");
    609                         message.append("Output out: ");
    610                         appendVariableToMessage(message, args.out);
    611                         message.append("\n");
    612                         message.append("\n");
    613                         message.append("Output out (in double): ");
    614                         appendVariableToMessage(message, args.outDouble);
    615                         message.append("\n");
    616                         message.append(errorMessage);
    617                         message.append("Errors at");
    618                     }
    619                     message.append(" [");
    620                     message.append(Integer.toString(i));
    621                     message.append(", ");
    622                     message.append(Integer.toString(j));
    623                     message.append("]");
    624                 }
    625             }
    626         }
    627         assertFalse("Incorrect output for checkNativeTanpiHalf4Half4" +
    628                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    629     }
    630 
    631     public void testNativeTanpi() {
    632         checkNativeTanpiFloatFloat();
    633         checkNativeTanpiFloat2Float2();
    634         checkNativeTanpiFloat3Float3();
    635         checkNativeTanpiFloat4Float4();
    636         checkNativeTanpiHalfHalf();
    637         checkNativeTanpiHalf2Half2();
    638         checkNativeTanpiHalf3Half3();
    639         checkNativeTanpiHalf4Half4();
    640     }
    641 }
    642