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