blob: 702609088bb97b4c9c238a5f068e6eddba3b5fe5 [file] [log] [blame]
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Don't edit this file! It is auto-generated by frameworks/rs/api/gen_runtime.
package android.renderscript.cts;
import android.renderscript.Allocation;
import android.renderscript.RSRuntimeException;
import android.renderscript.Element;
public class TestMix extends RSBaseCompute {
private ScriptC_TestMix script;
private ScriptC_TestMixRelaxed scriptRelaxed;
@Override
protected void setUp() throws Exception {
super.setUp();
script = new ScriptC_TestMix(mRS);
scriptRelaxed = new ScriptC_TestMixRelaxed(mRS);
}
public class ArgumentsFloatFloatFloatFloat {
public float inStart;
public float inStop;
public float inFraction;
public Target.Floaty out;
}
private void checkMixFloatFloatFloatFloat() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x9f4beff6471d6db1l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x6ede0b88b4422e8fl, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x6d2f014ec6a51d9fl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
script.set_gAllocInStop(inStop);
script.set_gAllocInFraction(inFraction);
script.forEach_testMixFloatFloatFloatFloat(inStart, out);
verifyResultsMixFloatFloatFloatFloat(inStart, inStop, inFraction, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloatFloatFloatFloat: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
scriptRelaxed.set_gAllocInStop(inStop);
scriptRelaxed.set_gAllocInFraction(inFraction);
scriptRelaxed.forEach_testMixFloatFloatFloatFloat(inStart, out);
verifyResultsMixFloatFloatFloatFloat(inStart, inStop, inFraction, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloatFloatFloatFloat: " + e.toString());
}
}
private void verifyResultsMixFloatFloatFloatFloat(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
float[] arrayInStart = new float[INPUTSIZE * 1];
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 1];
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 1];
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 1];
out.copyTo(arrayOut);
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 1 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
args.inStart = arrayInStart[i];
args.inStop = arrayInStop[i];
args.inFraction = arrayInFraction[i];
// Figure out what the outputs should have been.
Target target = new Target(relaxed);
CoreMathVerifier.computeMix(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 1 + j])) {
valid = false;
}
if (!valid) {
StringBuilder message = new StringBuilder();
message.append("Input inStart: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
message.append("\n");
message.append("Input inStop: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
message.append("\n");
message.append("Input inFraction: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inFraction, Float.floatToRawIntBits(args.inFraction), args.inFraction));
message.append("\n");
message.append("Expected output out: ");
message.append(args.out.toString());
message.append("\n");
message.append("Actual output out: ");
message.append(String.format("%14.8g {%8x} %15a",
arrayOut[i * 1 + j], Float.floatToRawIntBits(arrayOut[i * 1 + j]), arrayOut[i * 1 + j]));
if (!args.out.couldBe(arrayOut[i * 1 + j])) {
message.append(" FAIL");
}
message.append("\n");
assertTrue("Incorrect output for checkMixFloatFloatFloatFloat" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
}
}
}
}
private void checkMixFloat2Float2Float2Float2() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x45502e8f0a2d9ce9l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xba2b8a035395e837l, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xe56bef3c621e0ac7l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
script.set_gAllocInStop(inStop);
script.set_gAllocInFraction(inFraction);
script.forEach_testMixFloat2Float2Float2Float2(inStart, out);
verifyResultsMixFloat2Float2Float2Float2(inStart, inStop, inFraction, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2Float2Float2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
scriptRelaxed.set_gAllocInStop(inStop);
scriptRelaxed.set_gAllocInFraction(inFraction);
scriptRelaxed.forEach_testMixFloat2Float2Float2Float2(inStart, out);
verifyResultsMixFloat2Float2Float2Float2(inStart, inStop, inFraction, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2Float2Float2: " + e.toString());
}
}
private void verifyResultsMixFloat2Float2Float2Float2(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
float[] arrayInStart = new float[INPUTSIZE * 2];
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 2];
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 2];
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 2];
out.copyTo(arrayOut);
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
args.inStart = arrayInStart[i * 2 + j];
args.inStop = arrayInStop[i * 2 + j];
args.inFraction = arrayInFraction[i * 2 + j];
// Figure out what the outputs should have been.
Target target = new Target(relaxed);
CoreMathVerifier.computeMix(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
valid = false;
}
if (!valid) {
StringBuilder message = new StringBuilder();
message.append("Input inStart: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
message.append("\n");
message.append("Input inStop: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
message.append("\n");
message.append("Input inFraction: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inFraction, Float.floatToRawIntBits(args.inFraction), args.inFraction));
message.append("\n");
message.append("Expected output out: ");
message.append(args.out.toString());
message.append("\n");
message.append("Actual output out: ");
message.append(String.format("%14.8g {%8x} %15a",
arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
message.append(" FAIL");
}
message.append("\n");
assertTrue("Incorrect output for checkMixFloat2Float2Float2Float2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
}
}
}
}
private void checkMixFloat3Float3Float3Float3() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xeb4701726b009c5l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x9b21f6b3249ee4cbl, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xf15862eab0d4f51bl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
script.set_gAllocInStop(inStop);
script.set_gAllocInFraction(inFraction);
script.forEach_testMixFloat3Float3Float3Float3(inStart, out);
verifyResultsMixFloat3Float3Float3Float3(inStart, inStop, inFraction, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3Float3Float3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
scriptRelaxed.set_gAllocInStop(inStop);
scriptRelaxed.set_gAllocInFraction(inFraction);
scriptRelaxed.forEach_testMixFloat3Float3Float3Float3(inStart, out);
verifyResultsMixFloat3Float3Float3Float3(inStart, inStop, inFraction, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3Float3Float3: " + e.toString());
}
}
private void verifyResultsMixFloat3Float3Float3Float3(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
float[] arrayInStart = new float[INPUTSIZE * 4];
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 4];
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 4];
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 4];
out.copyTo(arrayOut);
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
args.inStart = arrayInStart[i * 4 + j];
args.inStop = arrayInStop[i * 4 + j];
args.inFraction = arrayInFraction[i * 4 + j];
// Figure out what the outputs should have been.
Target target = new Target(relaxed);
CoreMathVerifier.computeMix(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
if (!valid) {
StringBuilder message = new StringBuilder();
message.append("Input inStart: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
message.append("\n");
message.append("Input inStop: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
message.append("\n");
message.append("Input inFraction: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inFraction, Float.floatToRawIntBits(args.inFraction), args.inFraction));
message.append("\n");
message.append("Expected output out: ");
message.append(args.out.toString());
message.append("\n");
message.append("Actual output out: ");
message.append(String.format("%14.8g {%8x} %15a",
arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
assertTrue("Incorrect output for checkMixFloat3Float3Float3Float3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
}
}
}
}
private void checkMixFloat4Float4Float4Float4() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xd818b19f433276a1l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x7c186362f5a7e15fl, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xfd44d698ff8bdf6fl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
script.set_gAllocInStop(inStop);
script.set_gAllocInFraction(inFraction);
script.forEach_testMixFloat4Float4Float4Float4(inStart, out);
verifyResultsMixFloat4Float4Float4Float4(inStart, inStop, inFraction, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4Float4Float4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
scriptRelaxed.set_gAllocInStop(inStop);
scriptRelaxed.set_gAllocInFraction(inFraction);
scriptRelaxed.forEach_testMixFloat4Float4Float4Float4(inStart, out);
verifyResultsMixFloat4Float4Float4Float4(inStart, inStop, inFraction, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4Float4Float4: " + e.toString());
}
}
private void verifyResultsMixFloat4Float4Float4Float4(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
float[] arrayInStart = new float[INPUTSIZE * 4];
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 4];
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 4];
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 4];
out.copyTo(arrayOut);
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
args.inStart = arrayInStart[i * 4 + j];
args.inStop = arrayInStop[i * 4 + j];
args.inFraction = arrayInFraction[i * 4 + j];
// Figure out what the outputs should have been.
Target target = new Target(relaxed);
CoreMathVerifier.computeMix(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
if (!valid) {
StringBuilder message = new StringBuilder();
message.append("Input inStart: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
message.append("\n");
message.append("Input inStop: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
message.append("\n");
message.append("Input inFraction: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inFraction, Float.floatToRawIntBits(args.inFraction), args.inFraction));
message.append("\n");
message.append("Expected output out: ");
message.append(args.out.toString());
message.append("\n");
message.append("Actual output out: ");
message.append(String.format("%14.8g {%8x} %15a",
arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
assertTrue("Incorrect output for checkMixFloat4Float4Float4Float4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
}
}
}
}
private void checkMixFloat2Float2FloatFloat2() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xf811b2d52bd1d7c3l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x17a127e13c8dd1c5l, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xe0b7d03e92afd1f5l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
script.set_gAllocInStop(inStop);
script.set_gAllocInFraction(inFraction);
script.forEach_testMixFloat2Float2FloatFloat2(inStart, out);
verifyResultsMixFloat2Float2FloatFloat2(inStart, inStop, inFraction, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2FloatFloat2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
scriptRelaxed.set_gAllocInStop(inStop);
scriptRelaxed.set_gAllocInFraction(inFraction);
scriptRelaxed.forEach_testMixFloat2Float2FloatFloat2(inStart, out);
verifyResultsMixFloat2Float2FloatFloat2(inStart, inStop, inFraction, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2FloatFloat2: " + e.toString());
}
}
private void verifyResultsMixFloat2Float2FloatFloat2(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
float[] arrayInStart = new float[INPUTSIZE * 2];
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 2];
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 1];
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 2];
out.copyTo(arrayOut);
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
args.inStart = arrayInStart[i * 2 + j];
args.inStop = arrayInStop[i * 2 + j];
args.inFraction = arrayInFraction[i];
// Figure out what the outputs should have been.
Target target = new Target(relaxed);
CoreMathVerifier.computeMix(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
valid = false;
}
if (!valid) {
StringBuilder message = new StringBuilder();
message.append("Input inStart: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
message.append("\n");
message.append("Input inStop: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
message.append("\n");
message.append("Input inFraction: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inFraction, Float.floatToRawIntBits(args.inFraction), args.inFraction));
message.append("\n");
message.append("Expected output out: ");
message.append(args.out.toString());
message.append("\n");
message.append("Actual output out: ");
message.append(String.format("%14.8g {%8x} %15a",
arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
message.append(" FAIL");
}
message.append("\n");
assertTrue("Incorrect output for checkMixFloat2Float2FloatFloat2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
}
}
}
}
private void checkMixFloat3Float3FloatFloat3() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xae7aff441b20fa80l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe64a4d60d6f4de7cl, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x21bd09bbd131a27cl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
script.set_gAllocInStop(inStop);
script.set_gAllocInFraction(inFraction);
script.forEach_testMixFloat3Float3FloatFloat3(inStart, out);
verifyResultsMixFloat3Float3FloatFloat3(inStart, inStop, inFraction, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3FloatFloat3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
scriptRelaxed.set_gAllocInStop(inStop);
scriptRelaxed.set_gAllocInFraction(inFraction);
scriptRelaxed.forEach_testMixFloat3Float3FloatFloat3(inStart, out);
verifyResultsMixFloat3Float3FloatFloat3(inStart, inStop, inFraction, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3FloatFloat3: " + e.toString());
}
}
private void verifyResultsMixFloat3Float3FloatFloat3(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
float[] arrayInStart = new float[INPUTSIZE * 4];
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 4];
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 1];
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 4];
out.copyTo(arrayOut);
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
args.inStart = arrayInStart[i * 4 + j];
args.inStop = arrayInStop[i * 4 + j];
args.inFraction = arrayInFraction[i];
// Figure out what the outputs should have been.
Target target = new Target(relaxed);
CoreMathVerifier.computeMix(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
if (!valid) {
StringBuilder message = new StringBuilder();
message.append("Input inStart: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
message.append("\n");
message.append("Input inStop: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
message.append("\n");
message.append("Input inFraction: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inFraction, Float.floatToRawIntBits(args.inFraction), args.inFraction));
message.append("\n");
message.append("Expected output out: ");
message.append(args.out.toString());
message.append("\n");
message.append("Actual output out: ");
message.append(String.format("%14.8g {%8x} %15a",
arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
assertTrue("Incorrect output for checkMixFloat3Float3FloatFloat3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
}
}
}
}
private void checkMixFloat4Float4FloatFloat4() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x64e44bb30a701d3dl, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xb4f372e0715beb33l, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x62c243390fb37303l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
script.set_gAllocInStop(inStop);
script.set_gAllocInFraction(inFraction);
script.forEach_testMixFloat4Float4FloatFloat4(inStart, out);
verifyResultsMixFloat4Float4FloatFloat4(inStart, inStop, inFraction, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4FloatFloat4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
scriptRelaxed.set_gAllocInStop(inStop);
scriptRelaxed.set_gAllocInFraction(inFraction);
scriptRelaxed.forEach_testMixFloat4Float4FloatFloat4(inStart, out);
verifyResultsMixFloat4Float4FloatFloat4(inStart, inStop, inFraction, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4FloatFloat4: " + e.toString());
}
}
private void verifyResultsMixFloat4Float4FloatFloat4(Allocation inStart, Allocation inStop, Allocation inFraction, Allocation out, boolean relaxed) {
float[] arrayInStart = new float[INPUTSIZE * 4];
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 4];
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 1];
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 4];
out.copyTo(arrayOut);
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat();
args.inStart = arrayInStart[i * 4 + j];
args.inStop = arrayInStop[i * 4 + j];
args.inFraction = arrayInFraction[i];
// Figure out what the outputs should have been.
Target target = new Target(relaxed);
CoreMathVerifier.computeMix(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
if (!valid) {
StringBuilder message = new StringBuilder();
message.append("Input inStart: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStart, Float.floatToRawIntBits(args.inStart), args.inStart));
message.append("\n");
message.append("Input inStop: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inStop, Float.floatToRawIntBits(args.inStop), args.inStop));
message.append("\n");
message.append("Input inFraction: ");
message.append(String.format("%14.8g {%8x} %15a",
args.inFraction, Float.floatToRawIntBits(args.inFraction), args.inFraction));
message.append("\n");
message.append("Expected output out: ");
message.append(args.out.toString());
message.append("\n");
message.append("Actual output out: ");
message.append(String.format("%14.8g {%8x} %15a",
arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
assertTrue("Incorrect output for checkMixFloat4Float4FloatFloat4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
}
}
}
}
public void testMix() {
checkMixFloatFloatFloatFloat();
checkMixFloat2Float2Float2Float2();
checkMixFloat3Float3Float3Float3();
checkMixFloat4Float4Float4Float4();
checkMixFloat2Float2FloatFloat2();
checkMixFloat3Float3FloatFloat3();
checkMixFloat4Float4FloatFloat4();
}
}