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 TestMix extends RSBaseCompute {
     26 
     27     private ScriptC_TestMix script;
     28     private ScriptC_TestMixRelaxed scriptRelaxed;
     29 
     30     @Override
     31     protected void setUp() throws Exception {
     32         super.setUp();
     33         script = new ScriptC_TestMix(mRS);
     34         scriptRelaxed = new ScriptC_TestMixRelaxed(mRS);
     35     }
     36 
     37     public class ArgumentsFloatFloatFloatFloat {
     38         public float inStart;
     39         public float inStop;
     40         public float inAmount;
     41         public Target.Floaty out;
     42     }
     43 
     44     private void checkMixFloatFloatFloatFloat() {
     45         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x9f4beff6471d6db1l, false);
     46         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x6ede0b88b4422e8fl, false);
     47         Allocation inAmount = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xc1c14e5d52dc3fe5l, false);
     48         try {
     49             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     50             script.set_gAllocInStop(inStop);
     51             script.set_gAllocInAmount(inAmount);
     52             script.forEach_testMixFloatFloatFloatFloat(inStart, out);
     53             verifyResultsMixFloatFloatFloatFloat(inStart, inStop, inAmount, out, false);
     54         } catch (Exception e) {
     55             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloatFloatFloatFloat: " + e.toString());
     56         }
     57         try {
     58             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
     59             scriptRelaxed.set_gAllocInStop(inStop);
     60             scriptRelaxed.set_gAllocInAmount(inAmount);
     61             scriptRelaxed.forEach_testMixFloatFloatFloatFloat(inStart, out);
     62             verifyResultsMixFloatFloatFloatFloat(inStart, inStop, inAmount, out, true);
     63         } catch (Exception e) {
     64             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloatFloatFloatFloat: " + e.toString());
     65         }
     66     }
     67 
     68     private void verifyResultsMixFloatFloatFloatFloat(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) {
     69         float[] arrayInStart = new float[INPUTSIZE * 1];
     70         inStart.copyTo(arrayInStart);
     71         float[] arrayInStop = new float[INPUTSIZE * 1];
     72         inStop.copyTo(arrayInStop);
     73         float[] arrayInAmount = new float[INPUTSIZE * 1];
     74         inAmount.copyTo(arrayInAmount);
     75         float[] arrayOut = new float[INPUTSIZE * 1];
     76         out.copyTo(arrayOut);
     77         for (int i = 0; i < INPUTSIZE; i++) {
     78             for (int j = 0; j < 1 ; j++) {
     79                 // Extract the inputs.
     80                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
     81                 args.inStart = arrayInStart[i];
     82                 args.inStop = arrayInStop[i];
     83                 args.inAmount = arrayInAmount[i];
     84                 // Figure out what the outputs should have been.
     85                 Target target = new Target(relaxed);
     86                 CoreMathVerifier.computeMix(args, target);
     87                 // Validate the outputs.
     88                 boolean valid = true;
     89                 if (!args.out.couldBe(arrayOut[i * 1 + j])) {
     90                     valid = false;
     91                 }
     92                 if (!valid) {
     93                     StringBuilder message = new StringBuilder();
     94                     message.append("Input inStart: ");
     95                     message.append(String.format("%14.8g {%8x} %15a",
     96                             args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
     97                     message.append("\n");
     98                     message.append("Input inStop: ");
     99                     message.append(String.format("%14.8g {%8x} %15a",
    100                             args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
    101                     message.append("\n");
    102                     message.append("Input inAmount: ");
    103                     message.append(String.format("%14.8g {%8x} %15a",
    104                             args.inAmount, Float.floatToRawIntBits(args.inAmount), args.inAmount));
    105                     message.append("\n");
    106                     message.append("Expected output out: ");
    107                     message.append(args.out.toString());
    108                     message.append("\n");
    109                     message.append("Actual   output out: ");
    110                     message.append(String.format("%14.8g {%8x} %15a",
    111                             arrayOut[i * 1 + j], Float.floatToRawIntBits(arrayOut[i * 1 + j]), arrayOut[i * 1 + j]));
    112                     if (!args.out.couldBe(arrayOut[i * 1 + j])) {
    113                         message.append(" FAIL");
    114                     }
    115                     message.append("\n");
    116                     assertTrue("Incorrect output for checkMixFloatFloatFloatFloat" +
    117                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    118                 }
    119             }
    120         }
    121     }
    122 
    123     private void checkMixFloat2Float2Float2Float2() {
    124         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x45502e8f0a2d9ce9l, false);
    125         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xba2b8a035395e837l, false);
    126         Allocation inAmount = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xa477d20616942e4dl, false);
    127         try {
    128             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    129             script.set_gAllocInStop(inStop);
    130             script.set_gAllocInAmount(inAmount);
    131             script.forEach_testMixFloat2Float2Float2Float2(inStart, out);
    132             verifyResultsMixFloat2Float2Float2Float2(inStart, inStop, inAmount, out, false);
    133         } catch (Exception e) {
    134             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2Float2Float2: " + e.toString());
    135         }
    136         try {
    137             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    138             scriptRelaxed.set_gAllocInStop(inStop);
    139             scriptRelaxed.set_gAllocInAmount(inAmount);
    140             scriptRelaxed.forEach_testMixFloat2Float2Float2Float2(inStart, out);
    141             verifyResultsMixFloat2Float2Float2Float2(inStart, inStop, inAmount, out, true);
    142         } catch (Exception e) {
    143             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2Float2Float2: " + e.toString());
    144         }
    145     }
    146 
    147     private void verifyResultsMixFloat2Float2Float2Float2(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) {
    148         float[] arrayInStart = new float[INPUTSIZE * 2];
    149         inStart.copyTo(arrayInStart);
    150         float[] arrayInStop = new float[INPUTSIZE * 2];
    151         inStop.copyTo(arrayInStop);
    152         float[] arrayInAmount = new float[INPUTSIZE * 2];
    153         inAmount.copyTo(arrayInAmount);
    154         float[] arrayOut = new float[INPUTSIZE * 2];
    155         out.copyTo(arrayOut);
    156         for (int i = 0; i < INPUTSIZE; i++) {
    157             for (int j = 0; j < 2 ; j++) {
    158                 // Extract the inputs.
    159                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
    160                 args.inStart = arrayInStart[i * 2 + j];
    161                 args.inStop = arrayInStop[i * 2 + j];
    162                 args.inAmount = arrayInAmount[i * 2 + j];
    163                 // Figure out what the outputs should have been.
    164                 Target target = new Target(relaxed);
    165                 CoreMathVerifier.computeMix(args, target);
    166                 // Validate the outputs.
    167                 boolean valid = true;
    168                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    169                     valid = false;
    170                 }
    171                 if (!valid) {
    172                     StringBuilder message = new StringBuilder();
    173                     message.append("Input inStart: ");
    174                     message.append(String.format("%14.8g {%8x} %15a",
    175                             args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
    176                     message.append("\n");
    177                     message.append("Input inStop: ");
    178                     message.append(String.format("%14.8g {%8x} %15a",
    179                             args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
    180                     message.append("\n");
    181                     message.append("Input inAmount: ");
    182                     message.append(String.format("%14.8g {%8x} %15a",
    183                             args.inAmount, Float.floatToRawIntBits(args.inAmount), args.inAmount));
    184                     message.append("\n");
    185                     message.append("Expected output out: ");
    186                     message.append(args.out.toString());
    187                     message.append("\n");
    188                     message.append("Actual   output out: ");
    189                     message.append(String.format("%14.8g {%8x} %15a",
    190                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
    191                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    192                         message.append(" FAIL");
    193                     }
    194                     message.append("\n");
    195                     assertTrue("Incorrect output for checkMixFloat2Float2Float2Float2" +
    196                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    197                 }
    198             }
    199         }
    200     }
    201 
    202     private void checkMixFloat3Float3Float3Float3() {
    203         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xeb4701726b009c5l, false);
    204         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x9b21f6b3249ee4cbl, false);
    205         Allocation inAmount = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x784ed3e2e07c7741l, false);
    206         try {
    207             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    208             script.set_gAllocInStop(inStop);
    209             script.set_gAllocInAmount(inAmount);
    210             script.forEach_testMixFloat3Float3Float3Float3(inStart, out);
    211             verifyResultsMixFloat3Float3Float3Float3(inStart, inStop, inAmount, out, false);
    212         } catch (Exception e) {
    213             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3Float3Float3: " + e.toString());
    214         }
    215         try {
    216             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    217             scriptRelaxed.set_gAllocInStop(inStop);
    218             scriptRelaxed.set_gAllocInAmount(inAmount);
    219             scriptRelaxed.forEach_testMixFloat3Float3Float3Float3(inStart, out);
    220             verifyResultsMixFloat3Float3Float3Float3(inStart, inStop, inAmount, out, true);
    221         } catch (Exception e) {
    222             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3Float3Float3: " + e.toString());
    223         }
    224     }
    225 
    226     private void verifyResultsMixFloat3Float3Float3Float3(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) {
    227         float[] arrayInStart = new float[INPUTSIZE * 4];
    228         inStart.copyTo(arrayInStart);
    229         float[] arrayInStop = new float[INPUTSIZE * 4];
    230         inStop.copyTo(arrayInStop);
    231         float[] arrayInAmount = new float[INPUTSIZE * 4];
    232         inAmount.copyTo(arrayInAmount);
    233         float[] arrayOut = new float[INPUTSIZE * 4];
    234         out.copyTo(arrayOut);
    235         for (int i = 0; i < INPUTSIZE; i++) {
    236             for (int j = 0; j < 3 ; j++) {
    237                 // Extract the inputs.
    238                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
    239                 args.inStart = arrayInStart[i * 4 + j];
    240                 args.inStop = arrayInStop[i * 4 + j];
    241                 args.inAmount = arrayInAmount[i * 4 + j];
    242                 // Figure out what the outputs should have been.
    243                 Target target = new Target(relaxed);
    244                 CoreMathVerifier.computeMix(args, target);
    245                 // Validate the outputs.
    246                 boolean valid = true;
    247                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    248                     valid = false;
    249                 }
    250                 if (!valid) {
    251                     StringBuilder message = new StringBuilder();
    252                     message.append("Input inStart: ");
    253                     message.append(String.format("%14.8g {%8x} %15a",
    254                             args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
    255                     message.append("\n");
    256                     message.append("Input inStop: ");
    257                     message.append(String.format("%14.8g {%8x} %15a",
    258                             args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
    259                     message.append("\n");
    260                     message.append("Input inAmount: ");
    261                     message.append(String.format("%14.8g {%8x} %15a",
    262                             args.inAmount, Float.floatToRawIntBits(args.inAmount), args.inAmount));
    263                     message.append("\n");
    264                     message.append("Expected output out: ");
    265                     message.append(args.out.toString());
    266                     message.append("\n");
    267                     message.append("Actual   output out: ");
    268                     message.append(String.format("%14.8g {%8x} %15a",
    269                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    270                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    271                         message.append(" FAIL");
    272                     }
    273                     message.append("\n");
    274                     assertTrue("Incorrect output for checkMixFloat3Float3Float3Float3" +
    275                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    276                 }
    277             }
    278         }
    279     }
    280 
    281     private void checkMixFloat4Float4Float4Float4() {
    282         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xd818b19f433276a1l, false);
    283         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x7c186362f5a7e15fl, false);
    284         Allocation inAmount = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x4c25d5bfaa64c035l, false);
    285         try {
    286             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    287             script.set_gAllocInStop(inStop);
    288             script.set_gAllocInAmount(inAmount);
    289             script.forEach_testMixFloat4Float4Float4Float4(inStart, out);
    290             verifyResultsMixFloat4Float4Float4Float4(inStart, inStop, inAmount, out, false);
    291         } catch (Exception e) {
    292             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4Float4Float4: " + e.toString());
    293         }
    294         try {
    295             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    296             scriptRelaxed.set_gAllocInStop(inStop);
    297             scriptRelaxed.set_gAllocInAmount(inAmount);
    298             scriptRelaxed.forEach_testMixFloat4Float4Float4Float4(inStart, out);
    299             verifyResultsMixFloat4Float4Float4Float4(inStart, inStop, inAmount, out, true);
    300         } catch (Exception e) {
    301             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4Float4Float4: " + e.toString());
    302         }
    303     }
    304 
    305     private void verifyResultsMixFloat4Float4Float4Float4(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) {
    306         float[] arrayInStart = new float[INPUTSIZE * 4];
    307         inStart.copyTo(arrayInStart);
    308         float[] arrayInStop = new float[INPUTSIZE * 4];
    309         inStop.copyTo(arrayInStop);
    310         float[] arrayInAmount = new float[INPUTSIZE * 4];
    311         inAmount.copyTo(arrayInAmount);
    312         float[] arrayOut = new float[INPUTSIZE * 4];
    313         out.copyTo(arrayOut);
    314         for (int i = 0; i < INPUTSIZE; i++) {
    315             for (int j = 0; j < 4 ; j++) {
    316                 // Extract the inputs.
    317                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
    318                 args.inStart = arrayInStart[i * 4 + j];
    319                 args.inStop = arrayInStop[i * 4 + j];
    320                 args.inAmount = arrayInAmount[i * 4 + j];
    321                 // Figure out what the outputs should have been.
    322                 Target target = new Target(relaxed);
    323                 CoreMathVerifier.computeMix(args, target);
    324                 // Validate the outputs.
    325                 boolean valid = true;
    326                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    327                     valid = false;
    328                 }
    329                 if (!valid) {
    330                     StringBuilder message = new StringBuilder();
    331                     message.append("Input inStart: ");
    332                     message.append(String.format("%14.8g {%8x} %15a",
    333                             args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
    334                     message.append("\n");
    335                     message.append("Input inStop: ");
    336                     message.append(String.format("%14.8g {%8x} %15a",
    337                             args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
    338                     message.append("\n");
    339                     message.append("Input inAmount: ");
    340                     message.append(String.format("%14.8g {%8x} %15a",
    341                             args.inAmount, Float.floatToRawIntBits(args.inAmount), args.inAmount));
    342                     message.append("\n");
    343                     message.append("Expected output out: ");
    344                     message.append(args.out.toString());
    345                     message.append("\n");
    346                     message.append("Actual   output out: ");
    347                     message.append(String.format("%14.8g {%8x} %15a",
    348                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    349                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    350                         message.append(" FAIL");
    351                     }
    352                     message.append("\n");
    353                     assertTrue("Incorrect output for checkMixFloat4Float4Float4Float4" +
    354                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    355                 }
    356             }
    357         }
    358     }
    359 
    360     private void checkMixFloat2Float2FloatFloat2() {
    361         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xf811b2d52bd1d7c3l, false);
    362         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x17a127e13c8dd1c5l, false);
    363         Allocation inAmount = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xaaf909cdbd2a10ebl, false);
    364         try {
    365             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    366             script.set_gAllocInStop(inStop);
    367             script.set_gAllocInAmount(inAmount);
    368             script.forEach_testMixFloat2Float2FloatFloat2(inStart, out);
    369             verifyResultsMixFloat2Float2FloatFloat2(inStart, inStop, inAmount, out, false);
    370         } catch (Exception e) {
    371             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2FloatFloat2: " + e.toString());
    372         }
    373         try {
    374             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    375             scriptRelaxed.set_gAllocInStop(inStop);
    376             scriptRelaxed.set_gAllocInAmount(inAmount);
    377             scriptRelaxed.forEach_testMixFloat2Float2FloatFloat2(inStart, out);
    378             verifyResultsMixFloat2Float2FloatFloat2(inStart, inStop, inAmount, out, true);
    379         } catch (Exception e) {
    380             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2FloatFloat2: " + e.toString());
    381         }
    382     }
    383 
    384     private void verifyResultsMixFloat2Float2FloatFloat2(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) {
    385         float[] arrayInStart = new float[INPUTSIZE * 2];
    386         inStart.copyTo(arrayInStart);
    387         float[] arrayInStop = new float[INPUTSIZE * 2];
    388         inStop.copyTo(arrayInStop);
    389         float[] arrayInAmount = new float[INPUTSIZE * 1];
    390         inAmount.copyTo(arrayInAmount);
    391         float[] arrayOut = new float[INPUTSIZE * 2];
    392         out.copyTo(arrayOut);
    393         for (int i = 0; i < INPUTSIZE; i++) {
    394             for (int j = 0; j < 2 ; j++) {
    395                 // Extract the inputs.
    396                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
    397                 args.inStart = arrayInStart[i * 2 + j];
    398                 args.inStop = arrayInStop[i * 2 + j];
    399                 args.inAmount = arrayInAmount[i];
    400                 // Figure out what the outputs should have been.
    401                 Target target = new Target(relaxed);
    402                 CoreMathVerifier.computeMix(args, target);
    403                 // Validate the outputs.
    404                 boolean valid = true;
    405                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    406                     valid = false;
    407                 }
    408                 if (!valid) {
    409                     StringBuilder message = new StringBuilder();
    410                     message.append("Input inStart: ");
    411                     message.append(String.format("%14.8g {%8x} %15a",
    412                             args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
    413                     message.append("\n");
    414                     message.append("Input inStop: ");
    415                     message.append(String.format("%14.8g {%8x} %15a",
    416                             args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
    417                     message.append("\n");
    418                     message.append("Input inAmount: ");
    419                     message.append(String.format("%14.8g {%8x} %15a",
    420                             args.inAmount, Float.floatToRawIntBits(args.inAmount), args.inAmount));
    421                     message.append("\n");
    422                     message.append("Expected output out: ");
    423                     message.append(args.out.toString());
    424                     message.append("\n");
    425                     message.append("Actual   output out: ");
    426                     message.append(String.format("%14.8g {%8x} %15a",
    427                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
    428                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    429                         message.append(" FAIL");
    430                     }
    431                     message.append("\n");
    432                     assertTrue("Incorrect output for checkMixFloat2Float2FloatFloat2" +
    433                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    434                 }
    435             }
    436         }
    437     }
    438 
    439     private void checkMixFloat3Float3FloatFloat3() {
    440         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xae7aff441b20fa80l, false);
    441         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe64a4d60d6f4de7cl, false);
    442         Allocation inAmount = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x4ea8e06fef74e6aal, false);
    443         try {
    444             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    445             script.set_gAllocInStop(inStop);
    446             script.set_gAllocInAmount(inAmount);
    447             script.forEach_testMixFloat3Float3FloatFloat3(inStart, out);
    448             verifyResultsMixFloat3Float3FloatFloat3(inStart, inStop, inAmount, out, false);
    449         } catch (Exception e) {
    450             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3FloatFloat3: " + e.toString());
    451         }
    452         try {
    453             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    454             scriptRelaxed.set_gAllocInStop(inStop);
    455             scriptRelaxed.set_gAllocInAmount(inAmount);
    456             scriptRelaxed.forEach_testMixFloat3Float3FloatFloat3(inStart, out);
    457             verifyResultsMixFloat3Float3FloatFloat3(inStart, inStop, inAmount, out, true);
    458         } catch (Exception e) {
    459             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3FloatFloat3: " + e.toString());
    460         }
    461     }
    462 
    463     private void verifyResultsMixFloat3Float3FloatFloat3(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) {
    464         float[] arrayInStart = new float[INPUTSIZE * 4];
    465         inStart.copyTo(arrayInStart);
    466         float[] arrayInStop = new float[INPUTSIZE * 4];
    467         inStop.copyTo(arrayInStop);
    468         float[] arrayInAmount = new float[INPUTSIZE * 1];
    469         inAmount.copyTo(arrayInAmount);
    470         float[] arrayOut = new float[INPUTSIZE * 4];
    471         out.copyTo(arrayOut);
    472         for (int i = 0; i < INPUTSIZE; i++) {
    473             for (int j = 0; j < 3 ; j++) {
    474                 // Extract the inputs.
    475                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
    476                 args.inStart = arrayInStart[i * 4 + j];
    477                 args.inStop = arrayInStop[i * 4 + j];
    478                 args.inAmount = arrayInAmount[i];
    479                 // Figure out what the outputs should have been.
    480                 Target target = new Target(relaxed);
    481                 CoreMathVerifier.computeMix(args, target);
    482                 // Validate the outputs.
    483                 boolean valid = true;
    484                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    485                     valid = false;
    486                 }
    487                 if (!valid) {
    488                     StringBuilder message = new StringBuilder();
    489                     message.append("Input inStart: ");
    490                     message.append(String.format("%14.8g {%8x} %15a",
    491                             args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
    492                     message.append("\n");
    493                     message.append("Input inStop: ");
    494                     message.append(String.format("%14.8g {%8x} %15a",
    495                             args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
    496                     message.append("\n");
    497                     message.append("Input inAmount: ");
    498                     message.append(String.format("%14.8g {%8x} %15a",
    499                             args.inAmount, Float.floatToRawIntBits(args.inAmount), args.inAmount));
    500                     message.append("\n");
    501                     message.append("Expected output out: ");
    502                     message.append(args.out.toString());
    503                     message.append("\n");
    504                     message.append("Actual   output out: ");
    505                     message.append(String.format("%14.8g {%8x} %15a",
    506                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    507                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    508                         message.append(" FAIL");
    509                     }
    510                     message.append("\n");
    511                     assertTrue("Incorrect output for checkMixFloat3Float3FloatFloat3" +
    512                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    513                 }
    514             }
    515         }
    516     }
    517 
    518     private void checkMixFloat4Float4FloatFloat4() {
    519         Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x64e44bb30a701d3dl, false);
    520         Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xb4f372e0715beb33l, false);
    521         Allocation inAmount = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xf258b71221bfbc69l, false);
    522         try {
    523             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    524             script.set_gAllocInStop(inStop);
    525             script.set_gAllocInAmount(inAmount);
    526             script.forEach_testMixFloat4Float4FloatFloat4(inStart, out);
    527             verifyResultsMixFloat4Float4FloatFloat4(inStart, inStop, inAmount, out, false);
    528         } catch (Exception e) {
    529             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4FloatFloat4: " + e.toString());
    530         }
    531         try {
    532             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    533             scriptRelaxed.set_gAllocInStop(inStop);
    534             scriptRelaxed.set_gAllocInAmount(inAmount);
    535             scriptRelaxed.forEach_testMixFloat4Float4FloatFloat4(inStart, out);
    536             verifyResultsMixFloat4Float4FloatFloat4(inStart, inStop, inAmount, out, true);
    537         } catch (Exception e) {
    538             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4FloatFloat4: " + e.toString());
    539         }
    540     }
    541 
    542     private void verifyResultsMixFloat4Float4FloatFloat4(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) {
    543         float[] arrayInStart = new float[INPUTSIZE * 4];
    544         inStart.copyTo(arrayInStart);
    545         float[] arrayInStop = new float[INPUTSIZE * 4];
    546         inStop.copyTo(arrayInStop);
    547         float[] arrayInAmount = new float[INPUTSIZE * 1];
    548         inAmount.copyTo(arrayInAmount);
    549         float[] arrayOut = new float[INPUTSIZE * 4];
    550         out.copyTo(arrayOut);
    551         for (int i = 0; i < INPUTSIZE; i++) {
    552             for (int j = 0; j < 4 ; j++) {
    553                 // Extract the inputs.
    554                 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
    555                 args.inStart = arrayInStart[i * 4 + j];
    556                 args.inStop = arrayInStop[i * 4 + j];
    557                 args.inAmount = arrayInAmount[i];
    558                 // Figure out what the outputs should have been.
    559                 Target target = new Target(relaxed);
    560                 CoreMathVerifier.computeMix(args, target);
    561                 // Validate the outputs.
    562                 boolean valid = true;
    563                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    564                     valid = false;
    565                 }
    566                 if (!valid) {
    567                     StringBuilder message = new StringBuilder();
    568                     message.append("Input inStart: ");
    569                     message.append(String.format("%14.8g {%8x} %15a",
    570                             args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
    571                     message.append("\n");
    572                     message.append("Input inStop: ");
    573                     message.append(String.format("%14.8g {%8x} %15a",
    574                             args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
    575                     message.append("\n");
    576                     message.append("Input inAmount: ");
    577                     message.append(String.format("%14.8g {%8x} %15a",
    578                             args.inAmount, Float.floatToRawIntBits(args.inAmount), args.inAmount));
    579                     message.append("\n");
    580                     message.append("Expected output out: ");
    581                     message.append(args.out.toString());
    582                     message.append("\n");
    583                     message.append("Actual   output out: ");
    584                     message.append(String.format("%14.8g {%8x} %15a",
    585                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    586                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    587                         message.append(" FAIL");
    588                     }
    589                     message.append("\n");
    590                     assertTrue("Incorrect output for checkMixFloat4Float4FloatFloat4" +
    591                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    592                 }
    593             }
    594         }
    595     }
    596 
    597     public void testMix() {
    598         checkMixFloatFloatFloatFloat();
    599         checkMixFloat2Float2Float2Float2();
    600         checkMixFloat3Float3Float3Float3();
    601         checkMixFloat4Float4Float4Float4();
    602         checkMixFloat2Float2FloatFloat2();
    603         checkMixFloat3Float3FloatFloat3();
    604         checkMixFloat4Float4FloatFloat4();
    605     }
    606 }
    607