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 TestNativeExp10 extends RSBaseCompute {
     26 
     27     private ScriptC_TestNativeExp10 script;
     28     private ScriptC_TestNativeExp10Relaxed scriptRelaxed;
     29 
     30     @Override
     31     protected void setUp() throws Exception {
     32         super.setUp();
     33         script = new ScriptC_TestNativeExp10(mRS);
     34         scriptRelaxed = new ScriptC_TestNativeExp10Relaxed(mRS);
     35     }
     36 
     37     public class ArgumentsFloatFloat {
     38         public float inV;
     39         public Target.Floaty out;
     40     }
     41 
     42     private void checkNativeExp10FloatFloat() {
     43         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x562e4ea690352c54l, -37, 37);
     44         try {
     45             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     46             script.forEach_testNativeExp10FloatFloat(inV, out);
     47             verifyResultsNativeExp10FloatFloat(inV, out, false);
     48         } catch (Exception e) {
     49             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExp10FloatFloat: " + e.toString());
     50         }
     51         try {
     52             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     53             scriptRelaxed.forEach_testNativeExp10FloatFloat(inV, out);
     54             verifyResultsNativeExp10FloatFloat(inV, out, true);
     55         } catch (Exception e) {
     56             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExp10FloatFloat: " + e.toString());
     57         }
     58     }
     59 
     60     private void verifyResultsNativeExp10FloatFloat(Allocation inV, Allocation out, boolean relaxed) {
     61         float[] arrayInV = new float[INPUTSIZE * 1];
     62         inV.copyTo(arrayInV);
     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.inV = arrayInV[i];
     70                 // Figure out what the outputs should have been.
     71                 Target target = new Target(relaxed);
     72                 CoreMathVerifier.computeNativeExp10(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 inV: ");
     81                     message.append(String.format("%14.8g {%8x} %15a",
     82                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
     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 checkNativeExp10FloatFloat" +
     95                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
     96                 }
     97             }
     98         }
     99     }
    100 
    101     private void checkNativeExp10Float2Float2() {
    102         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x7450c64e54876b98l, -37, 37);
    103         try {
    104             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    105             script.forEach_testNativeExp10Float2Float2(inV, out);
    106             verifyResultsNativeExp10Float2Float2(inV, out, false);
    107         } catch (Exception e) {
    108             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExp10Float2Float2: " + e.toString());
    109         }
    110         try {
    111             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    112             scriptRelaxed.forEach_testNativeExp10Float2Float2(inV, out);
    113             verifyResultsNativeExp10Float2Float2(inV, out, true);
    114         } catch (Exception e) {
    115             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExp10Float2Float2: " + e.toString());
    116         }
    117     }
    118 
    119     private void verifyResultsNativeExp10Float2Float2(Allocation inV, Allocation out, boolean relaxed) {
    120         float[] arrayInV = new float[INPUTSIZE * 2];
    121         inV.copyTo(arrayInV);
    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.inV = arrayInV[i * 2 + j];
    129                 // Figure out what the outputs should have been.
    130                 Target target = new Target(relaxed);
    131                 CoreMathVerifier.computeNativeExp10(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 inV: ");
    140                     message.append(String.format("%14.8g {%8x} %15a",
    141                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
    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 checkNativeExp10Float2Float2" +
    154                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    155                 }
    156             }
    157         }
    158     }
    159 
    160     private void checkNativeExp10Float3Float3() {
    161         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x74528f694aa28c76l, -37, 37);
    162         try {
    163             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    164             script.forEach_testNativeExp10Float3Float3(inV, out);
    165             verifyResultsNativeExp10Float3Float3(inV, out, false);
    166         } catch (Exception e) {
    167             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExp10Float3Float3: " + e.toString());
    168         }
    169         try {
    170             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    171             scriptRelaxed.forEach_testNativeExp10Float3Float3(inV, out);
    172             verifyResultsNativeExp10Float3Float3(inV, out, true);
    173         } catch (Exception e) {
    174             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExp10Float3Float3: " + e.toString());
    175         }
    176     }
    177 
    178     private void verifyResultsNativeExp10Float3Float3(Allocation inV, Allocation out, boolean relaxed) {
    179         float[] arrayInV = new float[INPUTSIZE * 4];
    180         inV.copyTo(arrayInV);
    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.inV = arrayInV[i * 4 + j];
    188                 // Figure out what the outputs should have been.
    189                 Target target = new Target(relaxed);
    190                 CoreMathVerifier.computeNativeExp10(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 inV: ");
    199                     message.append(String.format("%14.8g {%8x} %15a",
    200                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
    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 checkNativeExp10Float3Float3" +
    213                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    214                 }
    215             }
    216         }
    217     }
    218 
    219     private void checkNativeExp10Float4Float4() {
    220         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x7454588440bdad54l, -37, 37);
    221         try {
    222             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    223             script.forEach_testNativeExp10Float4Float4(inV, out);
    224             verifyResultsNativeExp10Float4Float4(inV, out, false);
    225         } catch (Exception e) {
    226             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExp10Float4Float4: " + e.toString());
    227         }
    228         try {
    229             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    230             scriptRelaxed.forEach_testNativeExp10Float4Float4(inV, out);
    231             verifyResultsNativeExp10Float4Float4(inV, out, true);
    232         } catch (Exception e) {
    233             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeExp10Float4Float4: " + e.toString());
    234         }
    235     }
    236 
    237     private void verifyResultsNativeExp10Float4Float4(Allocation inV, Allocation out, boolean relaxed) {
    238         float[] arrayInV = new float[INPUTSIZE * 4];
    239         inV.copyTo(arrayInV);
    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.inV = arrayInV[i * 4 + j];
    247                 // Figure out what the outputs should have been.
    248                 Target target = new Target(relaxed);
    249                 CoreMathVerifier.computeNativeExp10(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 inV: ");
    258                     message.append(String.format("%14.8g {%8x} %15a",
    259                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
    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 checkNativeExp10Float4Float4" +
    272                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    273                 }
    274             }
    275         }
    276     }
    277 
    278     public void testNativeExp10() {
    279         checkNativeExp10FloatFloat();
    280         checkNativeExp10Float2Float2();
    281         checkNativeExp10Float3Float3();
    282         checkNativeExp10Float4Float4();
    283     }
    284 }
    285