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 TestNativeAtan2 extends RSBaseCompute {
     29 
     30     private ScriptC_TestNativeAtan2 script;
     31     private ScriptC_TestNativeAtan2Relaxed scriptRelaxed;
     32 
     33     @Override
     34     protected void setUp() throws Exception {
     35         super.setUp();
     36         script = new ScriptC_TestNativeAtan2(mRS);
     37         scriptRelaxed = new ScriptC_TestNativeAtan2Relaxed(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 inNumerator;
     49         public float inDenominator;
     50         public Target.Floaty out;
     51     }
     52 
     53     private void checkNativeAtan2FloatFloatFloat() {
     54         Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x2139aa61fb6dcb4fl, false);
     55         Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xf6634dcb634c16d0l, false);
     56         try {
     57             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     58             script.set_gAllocInDenominator(inDenominator);
     59             script.forEach_testNativeAtan2FloatFloatFloat(inNumerator, out);
     60             verifyResultsNativeAtan2FloatFloatFloat(inNumerator, inDenominator, out, false);
     61             out.destroy();
     62         } catch (Exception e) {
     63             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2FloatFloatFloat: " + e.toString());
     64         }
     65         try {
     66             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     67             scriptRelaxed.set_gAllocInDenominator(inDenominator);
     68             scriptRelaxed.forEach_testNativeAtan2FloatFloatFloat(inNumerator, out);
     69             verifyResultsNativeAtan2FloatFloatFloat(inNumerator, inDenominator, out, true);
     70             out.destroy();
     71         } catch (Exception e) {
     72             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2FloatFloatFloat: " + e.toString());
     73         }
     74         inNumerator.destroy();
     75         inDenominator.destroy();
     76     }
     77 
     78     private void verifyResultsNativeAtan2FloatFloatFloat(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
     79         float[] arrayInNumerator = new float[INPUTSIZE * 1];
     80         Arrays.fill(arrayInNumerator, (float) 42);
     81         inNumerator.copyTo(arrayInNumerator);
     82         float[] arrayInDenominator = new float[INPUTSIZE * 1];
     83         Arrays.fill(arrayInDenominator, (float) 42);
     84         inDenominator.copyTo(arrayInDenominator);
     85         float[] arrayOut = new float[INPUTSIZE * 1];
     86         Arrays.fill(arrayOut, (float) 42);
     87         out.copyTo(arrayOut);
     88         StringBuilder message = new StringBuilder();
     89         boolean errorFound = false;
     90         for (int i = 0; i < INPUTSIZE; i++) {
     91             for (int j = 0; j < 1 ; j++) {
     92                 // Extract the inputs.
     93                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
     94                 args.inNumerator = arrayInNumerator[i];
     95                 args.inDenominator = arrayInDenominator[i];
     96                 // Figure out what the outputs should have been.
     97                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
     98                 CoreMathVerifier.computeNativeAtan2(args, target);
     99                 // Validate the outputs.
    100                 boolean valid = true;
    101                 if (!args.out.couldBe(arrayOut[i * 1 + j], 0.0005)) {
    102                     valid = false;
    103                 }
    104                 if (!valid) {
    105                     if (!errorFound) {
    106                         errorFound = true;
    107                         message.append("Input inNumerator: ");
    108                         appendVariableToMessage(message, args.inNumerator);
    109                         message.append("\n");
    110                         message.append("Input inDenominator: ");
    111                         appendVariableToMessage(message, args.inDenominator);
    112                         message.append("\n");
    113                         message.append("Expected output out: ");
    114                         appendVariableToMessage(message, args.out);
    115                         message.append("\n");
    116                         message.append("Actual   output out: ");
    117                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
    118                         if (!args.out.couldBe(arrayOut[i * 1 + j], 0.0005)) {
    119                             message.append(" FAIL");
    120                         }
    121                         message.append("\n");
    122                         message.append("Errors at");
    123                     }
    124                     message.append(" [");
    125                     message.append(Integer.toString(i));
    126                     message.append(", ");
    127                     message.append(Integer.toString(j));
    128                     message.append("]");
    129                 }
    130             }
    131         }
    132         assertFalse("Incorrect output for checkNativeAtan2FloatFloatFloat" +
    133                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    134     }
    135 
    136     private void checkNativeAtan2Float2Float2Float2() {
    137         Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x989e0b0cd0059da7l, false);
    138         Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x4a617fa4dfda5468l, false);
    139         try {
    140             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    141             script.set_gAllocInDenominator(inDenominator);
    142             script.forEach_testNativeAtan2Float2Float2Float2(inNumerator, out);
    143             verifyResultsNativeAtan2Float2Float2Float2(inNumerator, inDenominator, out, false);
    144             out.destroy();
    145         } catch (Exception e) {
    146             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Float2Float2Float2: " + e.toString());
    147         }
    148         try {
    149             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    150             scriptRelaxed.set_gAllocInDenominator(inDenominator);
    151             scriptRelaxed.forEach_testNativeAtan2Float2Float2Float2(inNumerator, out);
    152             verifyResultsNativeAtan2Float2Float2Float2(inNumerator, inDenominator, out, true);
    153             out.destroy();
    154         } catch (Exception e) {
    155             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Float2Float2Float2: " + e.toString());
    156         }
    157         inNumerator.destroy();
    158         inDenominator.destroy();
    159     }
    160 
    161     private void verifyResultsNativeAtan2Float2Float2Float2(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
    162         float[] arrayInNumerator = new float[INPUTSIZE * 2];
    163         Arrays.fill(arrayInNumerator, (float) 42);
    164         inNumerator.copyTo(arrayInNumerator);
    165         float[] arrayInDenominator = new float[INPUTSIZE * 2];
    166         Arrays.fill(arrayInDenominator, (float) 42);
    167         inDenominator.copyTo(arrayInDenominator);
    168         float[] arrayOut = new float[INPUTSIZE * 2];
    169         Arrays.fill(arrayOut, (float) 42);
    170         out.copyTo(arrayOut);
    171         StringBuilder message = new StringBuilder();
    172         boolean errorFound = false;
    173         for (int i = 0; i < INPUTSIZE; i++) {
    174             for (int j = 0; j < 2 ; j++) {
    175                 // Extract the inputs.
    176                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
    177                 args.inNumerator = arrayInNumerator[i * 2 + j];
    178                 args.inDenominator = arrayInDenominator[i * 2 + j];
    179                 // Figure out what the outputs should have been.
    180                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
    181                 CoreMathVerifier.computeNativeAtan2(args, target);
    182                 // Validate the outputs.
    183                 boolean valid = true;
    184                 if (!args.out.couldBe(arrayOut[i * 2 + j], 0.0005)) {
    185                     valid = false;
    186                 }
    187                 if (!valid) {
    188                     if (!errorFound) {
    189                         errorFound = true;
    190                         message.append("Input inNumerator: ");
    191                         appendVariableToMessage(message, args.inNumerator);
    192                         message.append("\n");
    193                         message.append("Input inDenominator: ");
    194                         appendVariableToMessage(message, args.inDenominator);
    195                         message.append("\n");
    196                         message.append("Expected output out: ");
    197                         appendVariableToMessage(message, args.out);
    198                         message.append("\n");
    199                         message.append("Actual   output out: ");
    200                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
    201                         if (!args.out.couldBe(arrayOut[i * 2 + j], 0.0005)) {
    202                             message.append(" FAIL");
    203                         }
    204                         message.append("\n");
    205                         message.append("Errors at");
    206                     }
    207                     message.append(" [");
    208                     message.append(Integer.toString(i));
    209                     message.append(", ");
    210                     message.append(Integer.toString(j));
    211                     message.append("]");
    212                 }
    213             }
    214         }
    215         assertFalse("Incorrect output for checkNativeAtan2Float2Float2Float2" +
    216                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    217     }
    218 
    219     private void checkNativeAtan2Float3Float3Float3() {
    220         Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x742cb44672d189a8l, false);
    221         Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x13c5c0edb2b5e7a1l, false);
    222         try {
    223             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    224             script.set_gAllocInDenominator(inDenominator);
    225             script.forEach_testNativeAtan2Float3Float3Float3(inNumerator, out);
    226             verifyResultsNativeAtan2Float3Float3Float3(inNumerator, inDenominator, out, false);
    227             out.destroy();
    228         } catch (Exception e) {
    229             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Float3Float3Float3: " + e.toString());
    230         }
    231         try {
    232             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    233             scriptRelaxed.set_gAllocInDenominator(inDenominator);
    234             scriptRelaxed.forEach_testNativeAtan2Float3Float3Float3(inNumerator, out);
    235             verifyResultsNativeAtan2Float3Float3Float3(inNumerator, inDenominator, out, true);
    236             out.destroy();
    237         } catch (Exception e) {
    238             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Float3Float3Float3: " + e.toString());
    239         }
    240         inNumerator.destroy();
    241         inDenominator.destroy();
    242     }
    243 
    244     private void verifyResultsNativeAtan2Float3Float3Float3(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
    245         float[] arrayInNumerator = new float[INPUTSIZE * 4];
    246         Arrays.fill(arrayInNumerator, (float) 42);
    247         inNumerator.copyTo(arrayInNumerator);
    248         float[] arrayInDenominator = new float[INPUTSIZE * 4];
    249         Arrays.fill(arrayInDenominator, (float) 42);
    250         inDenominator.copyTo(arrayInDenominator);
    251         float[] arrayOut = new float[INPUTSIZE * 4];
    252         Arrays.fill(arrayOut, (float) 42);
    253         out.copyTo(arrayOut);
    254         StringBuilder message = new StringBuilder();
    255         boolean errorFound = false;
    256         for (int i = 0; i < INPUTSIZE; i++) {
    257             for (int j = 0; j < 3 ; j++) {
    258                 // Extract the inputs.
    259                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
    260                 args.inNumerator = arrayInNumerator[i * 4 + j];
    261                 args.inDenominator = arrayInDenominator[i * 4 + j];
    262                 // Figure out what the outputs should have been.
    263                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
    264                 CoreMathVerifier.computeNativeAtan2(args, target);
    265                 // Validate the outputs.
    266                 boolean valid = true;
    267                 if (!args.out.couldBe(arrayOut[i * 4 + j], 0.0005)) {
    268                     valid = false;
    269                 }
    270                 if (!valid) {
    271                     if (!errorFound) {
    272                         errorFound = true;
    273                         message.append("Input inNumerator: ");
    274                         appendVariableToMessage(message, args.inNumerator);
    275                         message.append("\n");
    276                         message.append("Input inDenominator: ");
    277                         appendVariableToMessage(message, args.inDenominator);
    278                         message.append("\n");
    279                         message.append("Expected output out: ");
    280                         appendVariableToMessage(message, args.out);
    281                         message.append("\n");
    282                         message.append("Actual   output out: ");
    283                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
    284                         if (!args.out.couldBe(arrayOut[i * 4 + j], 0.0005)) {
    285                             message.append(" FAIL");
    286                         }
    287                         message.append("\n");
    288                         message.append("Errors at");
    289                     }
    290                     message.append(" [");
    291                     message.append(Integer.toString(i));
    292                     message.append(", ");
    293                     message.append(Integer.toString(j));
    294                     message.append("]");
    295                 }
    296             }
    297         }
    298         assertFalse("Incorrect output for checkNativeAtan2Float3Float3Float3" +
    299                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    300     }
    301 
    302     private void checkNativeAtan2Float4Float4Float4() {
    303         Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x4fbb5d80159d75a9l, false);
    304         Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xdd2a023685917adal, false);
    305         try {
    306             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    307             script.set_gAllocInDenominator(inDenominator);
    308             script.forEach_testNativeAtan2Float4Float4Float4(inNumerator, out);
    309             verifyResultsNativeAtan2Float4Float4Float4(inNumerator, inDenominator, out, false);
    310             out.destroy();
    311         } catch (Exception e) {
    312             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Float4Float4Float4: " + e.toString());
    313         }
    314         try {
    315             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    316             scriptRelaxed.set_gAllocInDenominator(inDenominator);
    317             scriptRelaxed.forEach_testNativeAtan2Float4Float4Float4(inNumerator, out);
    318             verifyResultsNativeAtan2Float4Float4Float4(inNumerator, inDenominator, out, true);
    319             out.destroy();
    320         } catch (Exception e) {
    321             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Float4Float4Float4: " + e.toString());
    322         }
    323         inNumerator.destroy();
    324         inDenominator.destroy();
    325     }
    326 
    327     private void verifyResultsNativeAtan2Float4Float4Float4(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
    328         float[] arrayInNumerator = new float[INPUTSIZE * 4];
    329         Arrays.fill(arrayInNumerator, (float) 42);
    330         inNumerator.copyTo(arrayInNumerator);
    331         float[] arrayInDenominator = new float[INPUTSIZE * 4];
    332         Arrays.fill(arrayInDenominator, (float) 42);
    333         inDenominator.copyTo(arrayInDenominator);
    334         float[] arrayOut = new float[INPUTSIZE * 4];
    335         Arrays.fill(arrayOut, (float) 42);
    336         out.copyTo(arrayOut);
    337         StringBuilder message = new StringBuilder();
    338         boolean errorFound = false;
    339         for (int i = 0; i < INPUTSIZE; i++) {
    340             for (int j = 0; j < 4 ; j++) {
    341                 // Extract the inputs.
    342                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
    343                 args.inNumerator = arrayInNumerator[i * 4 + j];
    344                 args.inDenominator = arrayInDenominator[i * 4 + j];
    345                 // Figure out what the outputs should have been.
    346                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.FLOAT, relaxed);
    347                 CoreMathVerifier.computeNativeAtan2(args, target);
    348                 // Validate the outputs.
    349                 boolean valid = true;
    350                 if (!args.out.couldBe(arrayOut[i * 4 + j], 0.0005)) {
    351                     valid = false;
    352                 }
    353                 if (!valid) {
    354                     if (!errorFound) {
    355                         errorFound = true;
    356                         message.append("Input inNumerator: ");
    357                         appendVariableToMessage(message, args.inNumerator);
    358                         message.append("\n");
    359                         message.append("Input inDenominator: ");
    360                         appendVariableToMessage(message, args.inDenominator);
    361                         message.append("\n");
    362                         message.append("Expected output out: ");
    363                         appendVariableToMessage(message, args.out);
    364                         message.append("\n");
    365                         message.append("Actual   output out: ");
    366                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
    367                         if (!args.out.couldBe(arrayOut[i * 4 + j], 0.0005)) {
    368                             message.append(" FAIL");
    369                         }
    370                         message.append("\n");
    371                         message.append("Errors at");
    372                     }
    373                     message.append(" [");
    374                     message.append(Integer.toString(i));
    375                     message.append(", ");
    376                     message.append(Integer.toString(j));
    377                     message.append("]");
    378                 }
    379             }
    380         }
    381         assertFalse("Incorrect output for checkNativeAtan2Float4Float4Float4" +
    382                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    383     }
    384 
    385     public class ArgumentsHalfHalfHalf {
    386         public short inNumerator;
    387         public double inNumeratorDouble;
    388         public short inDenominator;
    389         public double inDenominatorDouble;
    390         public Target.Floaty out;
    391     }
    392 
    393     private void checkNativeAtan2HalfHalfHalf() {
    394         Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x8c9f12b4e3d252c0l, false);
    395         Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xa5d1cc9be16255f9l, false);
    396         try {
    397             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
    398             script.set_gAllocInDenominator(inDenominator);
    399             script.forEach_testNativeAtan2HalfHalfHalf(inNumerator, out);
    400             verifyResultsNativeAtan2HalfHalfHalf(inNumerator, inDenominator, out, false);
    401             out.destroy();
    402         } catch (Exception e) {
    403             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2HalfHalfHalf: " + e.toString());
    404         }
    405         try {
    406             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
    407             scriptRelaxed.set_gAllocInDenominator(inDenominator);
    408             scriptRelaxed.forEach_testNativeAtan2HalfHalfHalf(inNumerator, out);
    409             verifyResultsNativeAtan2HalfHalfHalf(inNumerator, inDenominator, out, true);
    410             out.destroy();
    411         } catch (Exception e) {
    412             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2HalfHalfHalf: " + e.toString());
    413         }
    414         inNumerator.destroy();
    415         inDenominator.destroy();
    416     }
    417 
    418     private void verifyResultsNativeAtan2HalfHalfHalf(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
    419         short[] arrayInNumerator = new short[INPUTSIZE * 1];
    420         Arrays.fill(arrayInNumerator, (short) 42);
    421         inNumerator.copyTo(arrayInNumerator);
    422         short[] arrayInDenominator = new short[INPUTSIZE * 1];
    423         Arrays.fill(arrayInDenominator, (short) 42);
    424         inDenominator.copyTo(arrayInDenominator);
    425         short[] arrayOut = new short[INPUTSIZE * 1];
    426         Arrays.fill(arrayOut, (short) 42);
    427         out.copyTo(arrayOut);
    428         StringBuilder message = new StringBuilder();
    429         boolean errorFound = false;
    430         for (int i = 0; i < INPUTSIZE; i++) {
    431             for (int j = 0; j < 1 ; j++) {
    432                 // Extract the inputs.
    433                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
    434                 args.inNumerator = arrayInNumerator[i];
    435                 args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator);
    436                 args.inDenominator = arrayInDenominator[i];
    437                 args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator);
    438                 // Figure out what the outputs should have been.
    439                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
    440                 CoreMathVerifier.computeNativeAtan2(args, target);
    441                 // Validate the outputs.
    442                 boolean valid = true;
    443                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
    444                     valid = false;
    445                 }
    446                 if (!valid) {
    447                     if (!errorFound) {
    448                         errorFound = true;
    449                         message.append("Input inNumerator: ");
    450                         appendVariableToMessage(message, args.inNumerator);
    451                         message.append("\n");
    452                         message.append("Input inDenominator: ");
    453                         appendVariableToMessage(message, args.inDenominator);
    454                         message.append("\n");
    455                         message.append("Expected output out: ");
    456                         appendVariableToMessage(message, args.out);
    457                         message.append("\n");
    458                         message.append("Actual   output out: ");
    459                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
    460                         message.append("\n");
    461                         message.append("Actual   output out (in double): ");
    462                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]));
    463                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
    464                             message.append(" FAIL");
    465                         }
    466                         message.append("\n");
    467                         message.append("Errors at");
    468                     }
    469                     message.append(" [");
    470                     message.append(Integer.toString(i));
    471                     message.append(", ");
    472                     message.append(Integer.toString(j));
    473                     message.append("]");
    474                 }
    475             }
    476         }
    477         assertFalse("Incorrect output for checkNativeAtan2HalfHalfHalf" +
    478                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    479     }
    480 
    481     private void checkNativeAtan2Half2Half2Half2() {
    482         Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xe8f5f79a051d7124l, false);
    483         Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x956d078958f0d63dl, false);
    484         try {
    485             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
    486             script.set_gAllocInDenominator(inDenominator);
    487             script.forEach_testNativeAtan2Half2Half2Half2(inNumerator, out);
    488             verifyResultsNativeAtan2Half2Half2Half2(inNumerator, inDenominator, out, false);
    489             out.destroy();
    490         } catch (Exception e) {
    491             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Half2Half2Half2: " + e.toString());
    492         }
    493         try {
    494             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE);
    495             scriptRelaxed.set_gAllocInDenominator(inDenominator);
    496             scriptRelaxed.forEach_testNativeAtan2Half2Half2Half2(inNumerator, out);
    497             verifyResultsNativeAtan2Half2Half2Half2(inNumerator, inDenominator, out, true);
    498             out.destroy();
    499         } catch (Exception e) {
    500             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Half2Half2Half2: " + e.toString());
    501         }
    502         inNumerator.destroy();
    503         inDenominator.destroy();
    504     }
    505 
    506     private void verifyResultsNativeAtan2Half2Half2Half2(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
    507         short[] arrayInNumerator = new short[INPUTSIZE * 2];
    508         Arrays.fill(arrayInNumerator, (short) 42);
    509         inNumerator.copyTo(arrayInNumerator);
    510         short[] arrayInDenominator = new short[INPUTSIZE * 2];
    511         Arrays.fill(arrayInDenominator, (short) 42);
    512         inDenominator.copyTo(arrayInDenominator);
    513         short[] arrayOut = new short[INPUTSIZE * 2];
    514         Arrays.fill(arrayOut, (short) 42);
    515         out.copyTo(arrayOut);
    516         StringBuilder message = new StringBuilder();
    517         boolean errorFound = false;
    518         for (int i = 0; i < INPUTSIZE; i++) {
    519             for (int j = 0; j < 2 ; j++) {
    520                 // Extract the inputs.
    521                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
    522                 args.inNumerator = arrayInNumerator[i * 2 + j];
    523                 args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator);
    524                 args.inDenominator = arrayInDenominator[i * 2 + j];
    525                 args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator);
    526                 // Figure out what the outputs should have been.
    527                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
    528                 CoreMathVerifier.computeNativeAtan2(args, target);
    529                 // Validate the outputs.
    530                 boolean valid = true;
    531                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
    532                     valid = false;
    533                 }
    534                 if (!valid) {
    535                     if (!errorFound) {
    536                         errorFound = true;
    537                         message.append("Input inNumerator: ");
    538                         appendVariableToMessage(message, args.inNumerator);
    539                         message.append("\n");
    540                         message.append("Input inDenominator: ");
    541                         appendVariableToMessage(message, args.inDenominator);
    542                         message.append("\n");
    543                         message.append("Expected output out: ");
    544                         appendVariableToMessage(message, args.out);
    545                         message.append("\n");
    546                         message.append("Actual   output out: ");
    547                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
    548                         message.append("\n");
    549                         message.append("Actual   output out (in double): ");
    550                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]));
    551                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) {
    552                             message.append(" FAIL");
    553                         }
    554                         message.append("\n");
    555                         message.append("Errors at");
    556                     }
    557                     message.append(" [");
    558                     message.append(Integer.toString(i));
    559                     message.append(", ");
    560                     message.append(Integer.toString(j));
    561                     message.append("]");
    562                 }
    563             }
    564         }
    565         assertFalse("Incorrect output for checkNativeAtan2Half2Half2Half2" +
    566                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    567     }
    568 
    569     private void checkNativeAtan2Half3Half3Half3() {
    570         Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xa394c8a9508fa193l, false);
    571         Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x7a80ff0144b0a7f4l, false);
    572         try {
    573             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
    574             script.set_gAllocInDenominator(inDenominator);
    575             script.forEach_testNativeAtan2Half3Half3Half3(inNumerator, out);
    576             verifyResultsNativeAtan2Half3Half3Half3(inNumerator, inDenominator, out, false);
    577             out.destroy();
    578         } catch (Exception e) {
    579             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Half3Half3Half3: " + e.toString());
    580         }
    581         try {
    582             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE);
    583             scriptRelaxed.set_gAllocInDenominator(inDenominator);
    584             scriptRelaxed.forEach_testNativeAtan2Half3Half3Half3(inNumerator, out);
    585             verifyResultsNativeAtan2Half3Half3Half3(inNumerator, inDenominator, out, true);
    586             out.destroy();
    587         } catch (Exception e) {
    588             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Half3Half3Half3: " + e.toString());
    589         }
    590         inNumerator.destroy();
    591         inDenominator.destroy();
    592     }
    593 
    594     private void verifyResultsNativeAtan2Half3Half3Half3(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
    595         short[] arrayInNumerator = new short[INPUTSIZE * 4];
    596         Arrays.fill(arrayInNumerator, (short) 42);
    597         inNumerator.copyTo(arrayInNumerator);
    598         short[] arrayInDenominator = new short[INPUTSIZE * 4];
    599         Arrays.fill(arrayInDenominator, (short) 42);
    600         inDenominator.copyTo(arrayInDenominator);
    601         short[] arrayOut = new short[INPUTSIZE * 4];
    602         Arrays.fill(arrayOut, (short) 42);
    603         out.copyTo(arrayOut);
    604         StringBuilder message = new StringBuilder();
    605         boolean errorFound = false;
    606         for (int i = 0; i < INPUTSIZE; i++) {
    607             for (int j = 0; j < 3 ; j++) {
    608                 // Extract the inputs.
    609                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
    610                 args.inNumerator = arrayInNumerator[i * 4 + j];
    611                 args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator);
    612                 args.inDenominator = arrayInDenominator[i * 4 + j];
    613                 args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator);
    614                 // Figure out what the outputs should have been.
    615                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
    616                 CoreMathVerifier.computeNativeAtan2(args, target);
    617                 // Validate the outputs.
    618                 boolean valid = true;
    619                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
    620                     valid = false;
    621                 }
    622                 if (!valid) {
    623                     if (!errorFound) {
    624                         errorFound = true;
    625                         message.append("Input inNumerator: ");
    626                         appendVariableToMessage(message, args.inNumerator);
    627                         message.append("\n");
    628                         message.append("Input inDenominator: ");
    629                         appendVariableToMessage(message, args.inDenominator);
    630                         message.append("\n");
    631                         message.append("Expected output out: ");
    632                         appendVariableToMessage(message, args.out);
    633                         message.append("\n");
    634                         message.append("Actual   output out: ");
    635                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
    636                         message.append("\n");
    637                         message.append("Actual   output out (in double): ");
    638                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
    639                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
    640                             message.append(" FAIL");
    641                         }
    642                         message.append("\n");
    643                         message.append("Errors at");
    644                     }
    645                     message.append(" [");
    646                     message.append(Integer.toString(i));
    647                     message.append(", ");
    648                     message.append(Integer.toString(j));
    649                     message.append("]");
    650                 }
    651             }
    652         }
    653         assertFalse("Incorrect output for checkNativeAtan2Half3Half3Half3" +
    654                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    655     }
    656 
    657     private void checkNativeAtan2Half4Half4Half4() {
    658         Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x5e3399b89c01d202l, false);
    659         Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x5f94f679307079abl, false);
    660         try {
    661             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
    662             script.set_gAllocInDenominator(inDenominator);
    663             script.forEach_testNativeAtan2Half4Half4Half4(inNumerator, out);
    664             verifyResultsNativeAtan2Half4Half4Half4(inNumerator, inDenominator, out, false);
    665             out.destroy();
    666         } catch (Exception e) {
    667             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Half4Half4Half4: " + e.toString());
    668         }
    669         try {
    670             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE);
    671             scriptRelaxed.set_gAllocInDenominator(inDenominator);
    672             scriptRelaxed.forEach_testNativeAtan2Half4Half4Half4(inNumerator, out);
    673             verifyResultsNativeAtan2Half4Half4Half4(inNumerator, inDenominator, out, true);
    674             out.destroy();
    675         } catch (Exception e) {
    676             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeAtan2Half4Half4Half4: " + e.toString());
    677         }
    678         inNumerator.destroy();
    679         inDenominator.destroy();
    680     }
    681 
    682     private void verifyResultsNativeAtan2Half4Half4Half4(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) {
    683         short[] arrayInNumerator = new short[INPUTSIZE * 4];
    684         Arrays.fill(arrayInNumerator, (short) 42);
    685         inNumerator.copyTo(arrayInNumerator);
    686         short[] arrayInDenominator = new short[INPUTSIZE * 4];
    687         Arrays.fill(arrayInDenominator, (short) 42);
    688         inDenominator.copyTo(arrayInDenominator);
    689         short[] arrayOut = new short[INPUTSIZE * 4];
    690         Arrays.fill(arrayOut, (short) 42);
    691         out.copyTo(arrayOut);
    692         StringBuilder message = new StringBuilder();
    693         boolean errorFound = false;
    694         for (int i = 0; i < INPUTSIZE; i++) {
    695             for (int j = 0; j < 4 ; j++) {
    696                 // Extract the inputs.
    697                 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
    698                 args.inNumerator = arrayInNumerator[i * 4 + j];
    699                 args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator);
    700                 args.inDenominator = arrayInDenominator[i * 4 + j];
    701                 args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator);
    702                 // Figure out what the outputs should have been.
    703                 Target target = new Target(Target.FunctionType.NATIVE, Target.ReturnType.HALF, relaxed);
    704                 CoreMathVerifier.computeNativeAtan2(args, target);
    705                 // Validate the outputs.
    706                 boolean valid = true;
    707                 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
    708                     valid = false;
    709                 }
    710                 if (!valid) {
    711                     if (!errorFound) {
    712                         errorFound = true;
    713                         message.append("Input inNumerator: ");
    714                         appendVariableToMessage(message, args.inNumerator);
    715                         message.append("\n");
    716                         message.append("Input inDenominator: ");
    717                         appendVariableToMessage(message, args.inDenominator);
    718                         message.append("\n");
    719                         message.append("Expected output out: ");
    720                         appendVariableToMessage(message, args.out);
    721                         message.append("\n");
    722                         message.append("Actual   output out: ");
    723                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
    724                         message.append("\n");
    725                         message.append("Actual   output out (in double): ");
    726                         appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]));
    727                         if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) {
    728                             message.append(" FAIL");
    729                         }
    730                         message.append("\n");
    731                         message.append("Errors at");
    732                     }
    733                     message.append(" [");
    734                     message.append(Integer.toString(i));
    735                     message.append(", ");
    736                     message.append(Integer.toString(j));
    737                     message.append("]");
    738                 }
    739             }
    740         }
    741         assertFalse("Incorrect output for checkNativeAtan2Half4Half4Half4" +
    742                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
    743     }
    744 
    745     public void testNativeAtan2() {
    746         checkNativeAtan2FloatFloatFloat();
    747         checkNativeAtan2Float2Float2Float2();
    748         checkNativeAtan2Float3Float3Float3();
    749         checkNativeAtan2Float4Float4Float4();
    750         checkNativeAtan2HalfHalfHalf();
    751         checkNativeAtan2Half2Half2Half2();
    752         checkNativeAtan2Half3Half3Half3();
    753         checkNativeAtan2Half4Half4Half4();
    754     }
    755 }
    756