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 TestCross extends RSBaseCompute {
     26 
     27     private ScriptC_TestCross script;
     28     private ScriptC_TestCrossRelaxed scriptRelaxed;
     29 
     30     @Override
     31     protected void setUp() throws Exception {
     32         super.setUp();
     33         script = new ScriptC_TestCross(mRS);
     34         scriptRelaxed = new ScriptC_TestCrossRelaxed(mRS);
     35     }
     36 
     37     public class ArgumentsFloatNFloatNFloatN {
     38         public float[] inLhs;
     39         public float[] inRhs;
     40         public Target.Floaty[] out;
     41     }
     42 
     43     private void checkCrossFloat3Float3Float3() {
     44         Allocation inLhs = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xdec3726a2995edb5l, false);
     45         Allocation inRhs = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xdec3726a2996190bl, false);
     46         try {
     47             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
     48             script.set_gAllocInRhs(inRhs);
     49             script.forEach_testCrossFloat3Float3Float3(inLhs, out);
     50             verifyResultsCrossFloat3Float3Float3(inLhs, inRhs, out, false);
     51         } catch (Exception e) {
     52             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat3Float3Float3: " + e.toString());
     53         }
     54         try {
     55             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
     56             scriptRelaxed.set_gAllocInRhs(inRhs);
     57             scriptRelaxed.forEach_testCrossFloat3Float3Float3(inLhs, out);
     58             verifyResultsCrossFloat3Float3Float3(inLhs, inRhs, out, true);
     59         } catch (Exception e) {
     60             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat3Float3Float3: " + e.toString());
     61         }
     62     }
     63 
     64     private void verifyResultsCrossFloat3Float3Float3(Allocation inLhs, Allocation inRhs, Allocation out, boolean relaxed) {
     65         float[] arrayInLhs = new float[INPUTSIZE * 4];
     66         inLhs.copyTo(arrayInLhs);
     67         float[] arrayInRhs = new float[INPUTSIZE * 4];
     68         inRhs.copyTo(arrayInRhs);
     69         float[] arrayOut = new float[INPUTSIZE * 4];
     70         out.copyTo(arrayOut);
     71         for (int i = 0; i < INPUTSIZE; i++) {
     72             ArgumentsFloatNFloatNFloatN args = new ArgumentsFloatNFloatNFloatN();
     73             // Create the appropriate sized arrays in args
     74             args.inLhs = new float[3];
     75             args.inRhs = new float[3];
     76             args.out = new Target.Floaty[3];
     77             // Fill args with the input values
     78             for (int j = 0; j < 3 ; j++) {
     79                 args.inLhs[j] = arrayInLhs[i * 4 + j];
     80             }
     81             for (int j = 0; j < 3 ; j++) {
     82                 args.inRhs[j] = arrayInRhs[i * 4 + j];
     83             }
     84             Target target = new Target(relaxed);
     85             CoreMathVerifier.computeCross(args, target);
     86 
     87             // Compare the expected outputs to the actual values returned by RS.
     88             boolean valid = true;
     89             for (int j = 0; j < 3 ; j++) {
     90                 if (!args.out[j].couldBe(arrayOut[i * 4 + j])) {
     91                     valid = false;
     92                 }
     93             }
     94             if (!valid) {
     95                 StringBuilder message = new StringBuilder();
     96                 for (int j = 0; j < 3 ; j++) {
     97                     message.append("Input inLhs: ");
     98                     message.append(String.format("%14.8g {%8x} %15a",
     99                             arrayInLhs[i * 4 + j], Float.floatToRawIntBits(arrayInLhs[i * 4 + j]), arrayInLhs[i * 4 + j]));
    100                     message.append("\n");
    101                 }
    102                 for (int j = 0; j < 3 ; j++) {
    103                     message.append("Input inRhs: ");
    104                     message.append(String.format("%14.8g {%8x} %15a",
    105                             arrayInRhs[i * 4 + j], Float.floatToRawIntBits(arrayInRhs[i * 4 + j]), arrayInRhs[i * 4 + j]));
    106                     message.append("\n");
    107                 }
    108                 for (int j = 0; j < 3 ; j++) {
    109                     message.append("Expected output out: ");
    110                     message.append(args.out[j].toString());
    111                     message.append("\n");
    112                     message.append("Actual   output out: ");
    113                     message.append(String.format("%14.8g {%8x} %15a",
    114                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    115                     if (!args.out[j].couldBe(arrayOut[i * 4 + j])) {
    116                         message.append(" FAIL");
    117                     }
    118                     message.append("\n");
    119                 }
    120                 assertTrue("Incorrect output for checkCrossFloat3Float3Float3" +
    121                         (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    122             }
    123         }
    124     }
    125 
    126     private void checkCrossFloat4Float4Float4() {
    127         Allocation inLhs = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x6b4bc797a60fb18el, false);
    128         Allocation inRhs = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x6b4bc797a60fdce4l, false);
    129         try {
    130             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    131             script.set_gAllocInRhs(inRhs);
    132             script.forEach_testCrossFloat4Float4Float4(inLhs, out);
    133             verifyResultsCrossFloat4Float4Float4(inLhs, inRhs, out, false);
    134         } catch (Exception e) {
    135             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat4Float4Float4: " + e.toString());
    136         }
    137         try {
    138             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    139             scriptRelaxed.set_gAllocInRhs(inRhs);
    140             scriptRelaxed.forEach_testCrossFloat4Float4Float4(inLhs, out);
    141             verifyResultsCrossFloat4Float4Float4(inLhs, inRhs, out, true);
    142         } catch (Exception e) {
    143             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat4Float4Float4: " + e.toString());
    144         }
    145     }
    146 
    147     private void verifyResultsCrossFloat4Float4Float4(Allocation inLhs, Allocation inRhs, Allocation out, boolean relaxed) {
    148         float[] arrayInLhs = new float[INPUTSIZE * 4];
    149         inLhs.copyTo(arrayInLhs);
    150         float[] arrayInRhs = new float[INPUTSIZE * 4];
    151         inRhs.copyTo(arrayInRhs);
    152         float[] arrayOut = new float[INPUTSIZE * 4];
    153         out.copyTo(arrayOut);
    154         for (int i = 0; i < INPUTSIZE; i++) {
    155             ArgumentsFloatNFloatNFloatN args = new ArgumentsFloatNFloatNFloatN();
    156             // Create the appropriate sized arrays in args
    157             args.inLhs = new float[4];
    158             args.inRhs = new float[4];
    159             args.out = new Target.Floaty[4];
    160             // Fill args with the input values
    161             for (int j = 0; j < 4 ; j++) {
    162                 args.inLhs[j] = arrayInLhs[i * 4 + j];
    163             }
    164             for (int j = 0; j < 4 ; j++) {
    165                 args.inRhs[j] = arrayInRhs[i * 4 + j];
    166             }
    167             Target target = new Target(relaxed);
    168             CoreMathVerifier.computeCross(args, target);
    169 
    170             // Compare the expected outputs to the actual values returned by RS.
    171             boolean valid = true;
    172             for (int j = 0; j < 4 ; j++) {
    173                 if (!args.out[j].couldBe(arrayOut[i * 4 + j])) {
    174                     valid = false;
    175                 }
    176             }
    177             if (!valid) {
    178                 StringBuilder message = new StringBuilder();
    179                 for (int j = 0; j < 4 ; j++) {
    180                     message.append("Input inLhs: ");
    181                     message.append(String.format("%14.8g {%8x} %15a",
    182                             arrayInLhs[i * 4 + j], Float.floatToRawIntBits(arrayInLhs[i * 4 + j]), arrayInLhs[i * 4 + j]));
    183                     message.append("\n");
    184                 }
    185                 for (int j = 0; j < 4 ; j++) {
    186                     message.append("Input inRhs: ");
    187                     message.append(String.format("%14.8g {%8x} %15a",
    188                             arrayInRhs[i * 4 + j], Float.floatToRawIntBits(arrayInRhs[i * 4 + j]), arrayInRhs[i * 4 + j]));
    189                     message.append("\n");
    190                 }
    191                 for (int j = 0; j < 4 ; j++) {
    192                     message.append("Expected output out: ");
    193                     message.append(args.out[j].toString());
    194                     message.append("\n");
    195                     message.append("Actual   output out: ");
    196                     message.append(String.format("%14.8g {%8x} %15a",
    197                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    198                     if (!args.out[j].couldBe(arrayOut[i * 4 + j])) {
    199                         message.append(" FAIL");
    200                     }
    201                     message.append("\n");
    202                 }
    203                 assertTrue("Incorrect output for checkCrossFloat4Float4Float4" +
    204                         (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    205             }
    206         }
    207     }
    208 
    209     public void testCross() {
    210         checkCrossFloat3Float3Float3();
    211         checkCrossFloat4Float4Float4();
    212     }
    213 }
    214