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 TestSincos extends RSBaseCompute {
     26 
     27     private ScriptC_TestSincos script;
     28     private ScriptC_TestSincosRelaxed scriptRelaxed;
     29 
     30     @Override
     31     protected void setUp() throws Exception {
     32         super.setUp();
     33         script = new ScriptC_TestSincos(mRS);
     34         scriptRelaxed = new ScriptC_TestSincosRelaxed(mRS);
     35     }
     36 
     37     public class ArgumentsFloatFloatFloat {
     38         public float inV;
     39         public Target.Floaty outCosptr;
     40         public Target.Floaty out;
     41     }
     42 
     43     private void checkSincosFloatFloatFloat() {
     44         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xb8748e13e46c48d4l, false);
     45         try {
     46             Allocation outCosptr = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     47             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     48             script.set_gAllocOutCosptr(outCosptr);
     49             script.forEach_testSincosFloatFloatFloat(inV, out);
     50             verifyResultsSincosFloatFloatFloat(inV, outCosptr, out, false);
     51         } catch (Exception e) {
     52             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloatFloatFloat: " + e.toString());
     53         }
     54         try {
     55             Allocation outCosptr = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     56             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     57             scriptRelaxed.set_gAllocOutCosptr(outCosptr);
     58             scriptRelaxed.forEach_testSincosFloatFloatFloat(inV, out);
     59             verifyResultsSincosFloatFloatFloat(inV, outCosptr, out, true);
     60         } catch (Exception e) {
     61             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloatFloatFloat: " + e.toString());
     62         }
     63     }
     64 
     65     private void verifyResultsSincosFloatFloatFloat(Allocation inV, Allocation outCosptr, Allocation out, boolean relaxed) {
     66         float[] arrayInV = new float[INPUTSIZE * 1];
     67         inV.copyTo(arrayInV);
     68         float[] arrayOutCosptr = new float[INPUTSIZE * 1];
     69         outCosptr.copyTo(arrayOutCosptr);
     70         float[] arrayOut = new float[INPUTSIZE * 1];
     71         out.copyTo(arrayOut);
     72         for (int i = 0; i < INPUTSIZE; i++) {
     73             for (int j = 0; j < 1 ; j++) {
     74                 // Extract the inputs.
     75                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
     76                 args.inV = arrayInV[i];
     77                 // Figure out what the outputs should have been.
     78                 Target target = new Target(relaxed);
     79                 CoreMathVerifier.computeSincos(args, target);
     80                 // Validate the outputs.
     81                 boolean valid = true;
     82                 if (!args.outCosptr.couldBe(arrayOutCosptr[i * 1 + j])) {
     83                     valid = false;
     84                 }
     85                 if (!args.out.couldBe(arrayOut[i * 1 + j])) {
     86                     valid = false;
     87                 }
     88                 if (!valid) {
     89                     StringBuilder message = new StringBuilder();
     90                     message.append("Input inV: ");
     91                     message.append(String.format("%14.8g {%8x} %15a",
     92                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
     93                     message.append("\n");
     94                     message.append("Expected output outCosptr: ");
     95                     message.append(args.outCosptr.toString());
     96                     message.append("\n");
     97                     message.append("Actual   output outCosptr: ");
     98                     message.append(String.format("%14.8g {%8x} %15a",
     99                             arrayOutCosptr[i * 1 + j], Float.floatToRawIntBits(arrayOutCosptr[i * 1 + j]), arrayOutCosptr[i * 1 + j]));
    100                     if (!args.outCosptr.couldBe(arrayOutCosptr[i * 1 + j])) {
    101                         message.append(" FAIL");
    102                     }
    103                     message.append("\n");
    104                     message.append("Expected output out: ");
    105                     message.append(args.out.toString());
    106                     message.append("\n");
    107                     message.append("Actual   output out: ");
    108                     message.append(String.format("%14.8g {%8x} %15a",
    109                             arrayOut[i * 1 + j], Float.floatToRawIntBits(arrayOut[i * 1 + j]), arrayOut[i * 1 + j]));
    110                     if (!args.out.couldBe(arrayOut[i * 1 + j])) {
    111                         message.append(" FAIL");
    112                     }
    113                     message.append("\n");
    114                     assertTrue("Incorrect output for checkSincosFloatFloatFloat" +
    115                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    116                 }
    117             }
    118         }
    119     }
    120 
    121     private void checkSincosFloat2Float2Float2() {
    122         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xc85bab4e3e2fc77cl, false);
    123         try {
    124             Allocation outCosptr = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    125             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    126             script.set_gAllocOutCosptr(outCosptr);
    127             script.forEach_testSincosFloat2Float2Float2(inV, out);
    128             verifyResultsSincosFloat2Float2Float2(inV, outCosptr, out, false);
    129         } catch (Exception e) {
    130             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat2Float2Float2: " + e.toString());
    131         }
    132         try {
    133             Allocation outCosptr = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    134             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    135             scriptRelaxed.set_gAllocOutCosptr(outCosptr);
    136             scriptRelaxed.forEach_testSincosFloat2Float2Float2(inV, out);
    137             verifyResultsSincosFloat2Float2Float2(inV, outCosptr, out, true);
    138         } catch (Exception e) {
    139             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat2Float2Float2: " + e.toString());
    140         }
    141     }
    142 
    143     private void verifyResultsSincosFloat2Float2Float2(Allocation inV, Allocation outCosptr, Allocation out, boolean relaxed) {
    144         float[] arrayInV = new float[INPUTSIZE * 2];
    145         inV.copyTo(arrayInV);
    146         float[] arrayOutCosptr = new float[INPUTSIZE * 2];
    147         outCosptr.copyTo(arrayOutCosptr);
    148         float[] arrayOut = new float[INPUTSIZE * 2];
    149         out.copyTo(arrayOut);
    150         for (int i = 0; i < INPUTSIZE; i++) {
    151             for (int j = 0; j < 2 ; j++) {
    152                 // Extract the inputs.
    153                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
    154                 args.inV = arrayInV[i * 2 + j];
    155                 // Figure out what the outputs should have been.
    156                 Target target = new Target(relaxed);
    157                 CoreMathVerifier.computeSincos(args, target);
    158                 // Validate the outputs.
    159                 boolean valid = true;
    160                 if (!args.outCosptr.couldBe(arrayOutCosptr[i * 2 + j])) {
    161                     valid = false;
    162                 }
    163                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    164                     valid = false;
    165                 }
    166                 if (!valid) {
    167                     StringBuilder message = new StringBuilder();
    168                     message.append("Input inV: ");
    169                     message.append(String.format("%14.8g {%8x} %15a",
    170                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
    171                     message.append("\n");
    172                     message.append("Expected output outCosptr: ");
    173                     message.append(args.outCosptr.toString());
    174                     message.append("\n");
    175                     message.append("Actual   output outCosptr: ");
    176                     message.append(String.format("%14.8g {%8x} %15a",
    177                             arrayOutCosptr[i * 2 + j], Float.floatToRawIntBits(arrayOutCosptr[i * 2 + j]), arrayOutCosptr[i * 2 + j]));
    178                     if (!args.outCosptr.couldBe(arrayOutCosptr[i * 2 + j])) {
    179                         message.append(" FAIL");
    180                     }
    181                     message.append("\n");
    182                     message.append("Expected output out: ");
    183                     message.append(args.out.toString());
    184                     message.append("\n");
    185                     message.append("Actual   output out: ");
    186                     message.append(String.format("%14.8g {%8x} %15a",
    187                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
    188                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    189                         message.append(" FAIL");
    190                     }
    191                     message.append("\n");
    192                     assertTrue("Incorrect output for checkSincosFloat2Float2Float2" +
    193                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    194                 }
    195             }
    196         }
    197     }
    198 
    199     private void checkSincosFloat3Float3Float3() {
    200         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x1cc0896e400dc91dl, false);
    201         try {
    202             Allocation outCosptr = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    203             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    204             script.set_gAllocOutCosptr(outCosptr);
    205             script.forEach_testSincosFloat3Float3Float3(inV, out);
    206             verifyResultsSincosFloat3Float3Float3(inV, outCosptr, out, false);
    207         } catch (Exception e) {
    208             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat3Float3Float3: " + e.toString());
    209         }
    210         try {
    211             Allocation outCosptr = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    212             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    213             scriptRelaxed.set_gAllocOutCosptr(outCosptr);
    214             scriptRelaxed.forEach_testSincosFloat3Float3Float3(inV, out);
    215             verifyResultsSincosFloat3Float3Float3(inV, outCosptr, out, true);
    216         } catch (Exception e) {
    217             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat3Float3Float3: " + e.toString());
    218         }
    219     }
    220 
    221     private void verifyResultsSincosFloat3Float3Float3(Allocation inV, Allocation outCosptr, Allocation out, boolean relaxed) {
    222         float[] arrayInV = new float[INPUTSIZE * 4];
    223         inV.copyTo(arrayInV);
    224         float[] arrayOutCosptr = new float[INPUTSIZE * 4];
    225         outCosptr.copyTo(arrayOutCosptr);
    226         float[] arrayOut = new float[INPUTSIZE * 4];
    227         out.copyTo(arrayOut);
    228         for (int i = 0; i < INPUTSIZE; i++) {
    229             for (int j = 0; j < 3 ; j++) {
    230                 // Extract the inputs.
    231                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
    232                 args.inV = arrayInV[i * 4 + j];
    233                 // Figure out what the outputs should have been.
    234                 Target target = new Target(relaxed);
    235                 CoreMathVerifier.computeSincos(args, target);
    236                 // Validate the outputs.
    237                 boolean valid = true;
    238                 if (!args.outCosptr.couldBe(arrayOutCosptr[i * 4 + j])) {
    239                     valid = false;
    240                 }
    241                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    242                     valid = false;
    243                 }
    244                 if (!valid) {
    245                     StringBuilder message = new StringBuilder();
    246                     message.append("Input inV: ");
    247                     message.append(String.format("%14.8g {%8x} %15a",
    248                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
    249                     message.append("\n");
    250                     message.append("Expected output outCosptr: ");
    251                     message.append(args.outCosptr.toString());
    252                     message.append("\n");
    253                     message.append("Actual   output outCosptr: ");
    254                     message.append(String.format("%14.8g {%8x} %15a",
    255                             arrayOutCosptr[i * 4 + j], Float.floatToRawIntBits(arrayOutCosptr[i * 4 + j]), arrayOutCosptr[i * 4 + j]));
    256                     if (!args.outCosptr.couldBe(arrayOutCosptr[i * 4 + j])) {
    257                         message.append(" FAIL");
    258                     }
    259                     message.append("\n");
    260                     message.append("Expected output out: ");
    261                     message.append(args.out.toString());
    262                     message.append("\n");
    263                     message.append("Actual   output out: ");
    264                     message.append(String.format("%14.8g {%8x} %15a",
    265                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    266                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    267                         message.append(" FAIL");
    268                     }
    269                     message.append("\n");
    270                     assertTrue("Incorrect output for checkSincosFloat3Float3Float3" +
    271                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    272                 }
    273             }
    274         }
    275     }
    276 
    277     private void checkSincosFloat4Float4Float4() {
    278         Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x7125678e41ebcabel, false);
    279         try {
    280             Allocation outCosptr = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    281             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    282             script.set_gAllocOutCosptr(outCosptr);
    283             script.forEach_testSincosFloat4Float4Float4(inV, out);
    284             verifyResultsSincosFloat4Float4Float4(inV, outCosptr, out, false);
    285         } catch (Exception e) {
    286             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat4Float4Float4: " + e.toString());
    287         }
    288         try {
    289             Allocation outCosptr = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    290             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    291             scriptRelaxed.set_gAllocOutCosptr(outCosptr);
    292             scriptRelaxed.forEach_testSincosFloat4Float4Float4(inV, out);
    293             verifyResultsSincosFloat4Float4Float4(inV, outCosptr, out, true);
    294         } catch (Exception e) {
    295             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testSincosFloat4Float4Float4: " + e.toString());
    296         }
    297     }
    298 
    299     private void verifyResultsSincosFloat4Float4Float4(Allocation inV, Allocation outCosptr, Allocation out, boolean relaxed) {
    300         float[] arrayInV = new float[INPUTSIZE * 4];
    301         inV.copyTo(arrayInV);
    302         float[] arrayOutCosptr = new float[INPUTSIZE * 4];
    303         outCosptr.copyTo(arrayOutCosptr);
    304         float[] arrayOut = new float[INPUTSIZE * 4];
    305         out.copyTo(arrayOut);
    306         for (int i = 0; i < INPUTSIZE; i++) {
    307             for (int j = 0; j < 4 ; j++) {
    308                 // Extract the inputs.
    309                 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
    310                 args.inV = arrayInV[i * 4 + j];
    311                 // Figure out what the outputs should have been.
    312                 Target target = new Target(relaxed);
    313                 CoreMathVerifier.computeSincos(args, target);
    314                 // Validate the outputs.
    315                 boolean valid = true;
    316                 if (!args.outCosptr.couldBe(arrayOutCosptr[i * 4 + j])) {
    317                     valid = false;
    318                 }
    319                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    320                     valid = false;
    321                 }
    322                 if (!valid) {
    323                     StringBuilder message = new StringBuilder();
    324                     message.append("Input inV: ");
    325                     message.append(String.format("%14.8g {%8x} %15a",
    326                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
    327                     message.append("\n");
    328                     message.append("Expected output outCosptr: ");
    329                     message.append(args.outCosptr.toString());
    330                     message.append("\n");
    331                     message.append("Actual   output outCosptr: ");
    332                     message.append(String.format("%14.8g {%8x} %15a",
    333                             arrayOutCosptr[i * 4 + j], Float.floatToRawIntBits(arrayOutCosptr[i * 4 + j]), arrayOutCosptr[i * 4 + j]));
    334                     if (!args.outCosptr.couldBe(arrayOutCosptr[i * 4 + j])) {
    335                         message.append(" FAIL");
    336                     }
    337                     message.append("\n");
    338                     message.append("Expected output out: ");
    339                     message.append(args.out.toString());
    340                     message.append("\n");
    341                     message.append("Actual   output out: ");
    342                     message.append(String.format("%14.8g {%8x} %15a",
    343                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    344                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    345                         message.append(" FAIL");
    346                     }
    347                     message.append("\n");
    348                     assertTrue("Incorrect output for checkSincosFloat4Float4Float4" +
    349                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    350                 }
    351             }
    352         }
    353     }
    354 
    355     public void testSincos() {
    356         checkSincosFloatFloatFloat();
    357         checkSincosFloat2Float2Float2();
    358         checkSincosFloat3Float3Float3();
    359         checkSincosFloat4Float4Float4();
    360     }
    361 }
    362