Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2014 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/gen_runtime.
     18 
     19 package android.renderscript.cts;
     20 
     21 import android.renderscript.Allocation;
     22 import android.renderscript.RSRuntimeException;
     23 import android.renderscript.Element;
     24 
     25 public class TestNativeCosh extends RSBaseCompute {
     26 
     27     private ScriptC_TestNativeCosh script;
     28     private ScriptC_TestNativeCoshRelaxed scriptRelaxed;
     29 
     30     @Override
     31     protected void setUp() throws Exception {
     32         super.setUp();
     33         script = new ScriptC_TestNativeCosh(mRS);
     34         scriptRelaxed = new ScriptC_TestNativeCoshRelaxed(mRS);
     35     }
     36 
     37     public class ArgumentsFloatFloat {
     38         public float in;
     39         public Target.Floaty out;
     40     }
     41 
     42     private void checkNativeCoshFloatFloat() {
     43         Allocation in = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xeb1020909e9c475dl, false);
     44         try {
     45             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     46             script.forEach_testNativeCoshFloatFloat(in, out);
     47             verifyResultsNativeCoshFloatFloat(in, out, false);
     48         } catch (Exception e) {
     49             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeCoshFloatFloat: " + e.toString());
     50         }
     51         try {
     52             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     53             scriptRelaxed.forEach_testNativeCoshFloatFloat(in, out);
     54             verifyResultsNativeCoshFloatFloat(in, out, true);
     55         } catch (Exception e) {
     56             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeCoshFloatFloat: " + e.toString());
     57         }
     58     }
     59 
     60     private void verifyResultsNativeCoshFloatFloat(Allocation in, Allocation out, boolean relaxed) {
     61         float[] arrayIn = new float[INPUTSIZE * 1];
     62         in.copyTo(arrayIn);
     63         float[] arrayOut = new float[INPUTSIZE * 1];
     64         out.copyTo(arrayOut);
     65         for (int i = 0; i < INPUTSIZE; i++) {
     66             for (int j = 0; j < 1 ; j++) {
     67                 // Extract the inputs.
     68                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
     69                 args.in = arrayIn[i];
     70                 // Figure out what the outputs should have been.
     71                 Target target = new Target(relaxed);
     72                 CoreMathVerifier.computeNativeCosh(args, target);
     73                 // Validate the outputs.
     74                 boolean valid = true;
     75                 if (!args.out.couldBe(arrayOut[i * 1 + j])) {
     76                     valid = false;
     77                 }
     78                 if (!valid) {
     79                     StringBuilder message = new StringBuilder();
     80                     message.append("Input in: ");
     81                     message.append(String.format("%14.8g {%8x} %15a",
     82                             args.in, Float.floatToRawIntBits(args.in), args.in));
     83                     message.append("\n");
     84                     message.append("Expected output out: ");
     85                     message.append(args.out.toString());
     86                     message.append("\n");
     87                     message.append("Actual   output out: ");
     88                     message.append(String.format("%14.8g {%8x} %15a",
     89                             arrayOut[i * 1 + j], Float.floatToRawIntBits(arrayOut[i * 1 + j]), arrayOut[i * 1 + j]));
     90                     if (!args.out.couldBe(arrayOut[i * 1 + j])) {
     91                         message.append(" FAIL");
     92                     }
     93                     message.append("\n");
     94                     assertTrue("Incorrect output for checkNativeCoshFloatFloat" +
     95                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
     96                 }
     97             }
     98         }
     99     }
    100 
    101     private void checkNativeCoshFloat2Float2() {
    102         Allocation in = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xc77a568547f7e9d1l, false);
    103         try {
    104             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    105             script.forEach_testNativeCoshFloat2Float2(in, out);
    106             verifyResultsNativeCoshFloat2Float2(in, out, false);
    107         } catch (Exception e) {
    108             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeCoshFloat2Float2: " + e.toString());
    109         }
    110         try {
    111             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    112             scriptRelaxed.forEach_testNativeCoshFloat2Float2(in, out);
    113             verifyResultsNativeCoshFloat2Float2(in, out, true);
    114         } catch (Exception e) {
    115             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeCoshFloat2Float2: " + e.toString());
    116         }
    117     }
    118 
    119     private void verifyResultsNativeCoshFloat2Float2(Allocation in, Allocation out, boolean relaxed) {
    120         float[] arrayIn = new float[INPUTSIZE * 2];
    121         in.copyTo(arrayIn);
    122         float[] arrayOut = new float[INPUTSIZE * 2];
    123         out.copyTo(arrayOut);
    124         for (int i = 0; i < INPUTSIZE; i++) {
    125             for (int j = 0; j < 2 ; j++) {
    126                 // Extract the inputs.
    127                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
    128                 args.in = arrayIn[i * 2 + j];
    129                 // Figure out what the outputs should have been.
    130                 Target target = new Target(relaxed);
    131                 CoreMathVerifier.computeNativeCosh(args, target);
    132                 // Validate the outputs.
    133                 boolean valid = true;
    134                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    135                     valid = false;
    136                 }
    137                 if (!valid) {
    138                     StringBuilder message = new StringBuilder();
    139                     message.append("Input in: ");
    140                     message.append(String.format("%14.8g {%8x} %15a",
    141                             args.in, Float.floatToRawIntBits(args.in), args.in));
    142                     message.append("\n");
    143                     message.append("Expected output out: ");
    144                     message.append(args.out.toString());
    145                     message.append("\n");
    146                     message.append("Actual   output out: ");
    147                     message.append(String.format("%14.8g {%8x} %15a",
    148                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
    149                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    150                         message.append(" FAIL");
    151                     }
    152                     message.append("\n");
    153                     assertTrue("Incorrect output for checkNativeCoshFloat2Float2" +
    154                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    155                 }
    156             }
    157         }
    158     }
    159 
    160     private void checkNativeCoshFloat3Float3() {
    161         Allocation in = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xc77a6126a6fe7f6bl, false);
    162         try {
    163             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    164             script.forEach_testNativeCoshFloat3Float3(in, out);
    165             verifyResultsNativeCoshFloat3Float3(in, out, false);
    166         } catch (Exception e) {
    167             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeCoshFloat3Float3: " + e.toString());
    168         }
    169         try {
    170             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    171             scriptRelaxed.forEach_testNativeCoshFloat3Float3(in, out);
    172             verifyResultsNativeCoshFloat3Float3(in, out, true);
    173         } catch (Exception e) {
    174             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeCoshFloat3Float3: " + e.toString());
    175         }
    176     }
    177 
    178     private void verifyResultsNativeCoshFloat3Float3(Allocation in, Allocation out, boolean relaxed) {
    179         float[] arrayIn = new float[INPUTSIZE * 4];
    180         in.copyTo(arrayIn);
    181         float[] arrayOut = new float[INPUTSIZE * 4];
    182         out.copyTo(arrayOut);
    183         for (int i = 0; i < INPUTSIZE; i++) {
    184             for (int j = 0; j < 3 ; j++) {
    185                 // Extract the inputs.
    186                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
    187                 args.in = arrayIn[i * 4 + j];
    188                 // Figure out what the outputs should have been.
    189                 Target target = new Target(relaxed);
    190                 CoreMathVerifier.computeNativeCosh(args, target);
    191                 // Validate the outputs.
    192                 boolean valid = true;
    193                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    194                     valid = false;
    195                 }
    196                 if (!valid) {
    197                     StringBuilder message = new StringBuilder();
    198                     message.append("Input in: ");
    199                     message.append(String.format("%14.8g {%8x} %15a",
    200                             args.in, Float.floatToRawIntBits(args.in), args.in));
    201                     message.append("\n");
    202                     message.append("Expected output out: ");
    203                     message.append(args.out.toString());
    204                     message.append("\n");
    205                     message.append("Actual   output out: ");
    206                     message.append(String.format("%14.8g {%8x} %15a",
    207                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    208                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    209                         message.append(" FAIL");
    210                     }
    211                     message.append("\n");
    212                     assertTrue("Incorrect output for checkNativeCoshFloat3Float3" +
    213                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    214                 }
    215             }
    216         }
    217     }
    218 
    219     private void checkNativeCoshFloat4Float4() {
    220         Allocation in = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xc77a6bc806051505l, false);
    221         try {
    222             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    223             script.forEach_testNativeCoshFloat4Float4(in, out);
    224             verifyResultsNativeCoshFloat4Float4(in, out, false);
    225         } catch (Exception e) {
    226             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeCoshFloat4Float4: " + e.toString());
    227         }
    228         try {
    229             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    230             scriptRelaxed.forEach_testNativeCoshFloat4Float4(in, out);
    231             verifyResultsNativeCoshFloat4Float4(in, out, true);
    232         } catch (Exception e) {
    233             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeCoshFloat4Float4: " + e.toString());
    234         }
    235     }
    236 
    237     private void verifyResultsNativeCoshFloat4Float4(Allocation in, Allocation out, boolean relaxed) {
    238         float[] arrayIn = new float[INPUTSIZE * 4];
    239         in.copyTo(arrayIn);
    240         float[] arrayOut = new float[INPUTSIZE * 4];
    241         out.copyTo(arrayOut);
    242         for (int i = 0; i < INPUTSIZE; i++) {
    243             for (int j = 0; j < 4 ; j++) {
    244                 // Extract the inputs.
    245                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
    246                 args.in = arrayIn[i * 4 + j];
    247                 // Figure out what the outputs should have been.
    248                 Target target = new Target(relaxed);
    249                 CoreMathVerifier.computeNativeCosh(args, target);
    250                 // Validate the outputs.
    251                 boolean valid = true;
    252                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    253                     valid = false;
    254                 }
    255                 if (!valid) {
    256                     StringBuilder message = new StringBuilder();
    257                     message.append("Input in: ");
    258                     message.append(String.format("%14.8g {%8x} %15a",
    259                             args.in, Float.floatToRawIntBits(args.in), args.in));
    260                     message.append("\n");
    261                     message.append("Expected output out: ");
    262                     message.append(args.out.toString());
    263                     message.append("\n");
    264                     message.append("Actual   output out: ");
    265                     message.append(String.format("%14.8g {%8x} %15a",
    266                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    267                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    268                         message.append(" FAIL");
    269                     }
    270                     message.append("\n");
    271                     assertTrue("Incorrect output for checkNativeCoshFloat4Float4" +
    272                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    273                 }
    274             }
    275         }
    276     }
    277 
    278     public void testNativeCosh() {
    279         checkNativeCoshFloatFloat();
    280         checkNativeCoshFloat2Float2();
    281         checkNativeCoshFloat3Float3();
    282         checkNativeCoshFloat4Float4();
    283     }
    284 }
    285