blob: 8adfe996c0169eaf335fe4e7f15bb30905c95408 [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/generate.sh.
package android.renderscript.cts;
import android.renderscript.Allocation;
import android.renderscript.RSRuntimeException;
import android.renderscript.Element;
import java.util.Arrays;
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, 0x471d6db1l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xb4422e8fl, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xc6a51d9fl, 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];
Arrays.fill(arrayInStart, (float) 42);
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 1];
Arrays.fill(arrayInStop, (float) 42);
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 1];
Arrays.fill(arrayInFraction, (float) 42);
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 1];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
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) {
if (!errorFound) {
errorFound = true;
message.append("Input inStart: ");
appendVariableToMessage(message, args.inStart);
message.append("\n");
message.append("Input inStop: ");
appendVariableToMessage(message, args.inStop);
message.append("\n");
message.append("Input inFraction: ");
appendVariableToMessage(message, args.inFraction);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 1 + j]);
if (!args.out.couldBe(arrayOut[i * 1 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkMixFloatFloatFloatFloat" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkMixFloat2Float2Float2Float2() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xa2d9ce9l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x5395e837l, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x621e0ac7l, 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];
Arrays.fill(arrayInStart, (float) 42);
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 2];
Arrays.fill(arrayInStop, (float) 42);
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 2];
Arrays.fill(arrayInFraction, (float) 42);
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 2];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
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) {
if (!errorFound) {
errorFound = true;
message.append("Input inStart: ");
appendVariableToMessage(message, args.inStart);
message.append("\n");
message.append("Input inStop: ");
appendVariableToMessage(message, args.inStop);
message.append("\n");
message.append("Input inFraction: ");
appendVariableToMessage(message, args.inFraction);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkMixFloat2Float2Float2Float2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkMixFloat3Float3Float3Float3() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x26b009c5l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x249ee4cbl, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xb0d4f51bl, 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];
Arrays.fill(arrayInStart, (float) 42);
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 4];
Arrays.fill(arrayInStop, (float) 42);
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 4];
Arrays.fill(arrayInFraction, (float) 42);
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 4];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
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) {
if (!errorFound) {
errorFound = true;
message.append("Input inStart: ");
appendVariableToMessage(message, args.inStart);
message.append("\n");
message.append("Input inStop: ");
appendVariableToMessage(message, args.inStop);
message.append("\n");
message.append("Input inFraction: ");
appendVariableToMessage(message, args.inFraction);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkMixFloat3Float3Float3Float3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkMixFloat4Float4Float4Float4() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x433276a1l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xf5a7e15fl, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xff8bdf6fl, 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];
Arrays.fill(arrayInStart, (float) 42);
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 4];
Arrays.fill(arrayInStop, (float) 42);
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 4];
Arrays.fill(arrayInFraction, (float) 42);
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 4];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
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) {
if (!errorFound) {
errorFound = true;
message.append("Input inStart: ");
appendVariableToMessage(message, args.inStart);
message.append("\n");
message.append("Input inStop: ");
appendVariableToMessage(message, args.inStop);
message.append("\n");
message.append("Input inFraction: ");
appendVariableToMessage(message, args.inFraction);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkMixFloat4Float4Float4Float4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkMixFloat2Float2FloatFloat2() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x2bd1d7c3l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x3c8dd1c5l, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x92afd1f5l, 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];
Arrays.fill(arrayInStart, (float) 42);
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 2];
Arrays.fill(arrayInStop, (float) 42);
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 1];
Arrays.fill(arrayInFraction, (float) 42);
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 2];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
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) {
if (!errorFound) {
errorFound = true;
message.append("Input inStart: ");
appendVariableToMessage(message, args.inStart);
message.append("\n");
message.append("Input inStop: ");
appendVariableToMessage(message, args.inStop);
message.append("\n");
message.append("Input inFraction: ");
appendVariableToMessage(message, args.inFraction);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
if (!args.out.couldBe(arrayOut[i * 2 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkMixFloat2Float2FloatFloat2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkMixFloat3Float3FloatFloat3() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x1b20fa80l, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xd6f4de7cl, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xd131a27cl, 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];
Arrays.fill(arrayInStart, (float) 42);
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 4];
Arrays.fill(arrayInStop, (float) 42);
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 1];
Arrays.fill(arrayInFraction, (float) 42);
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 4];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
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) {
if (!errorFound) {
errorFound = true;
message.append("Input inStart: ");
appendVariableToMessage(message, args.inStart);
message.append("\n");
message.append("Input inStop: ");
appendVariableToMessage(message, args.inStop);
message.append("\n");
message.append("Input inFraction: ");
appendVariableToMessage(message, args.inFraction);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkMixFloat3Float3FloatFloat3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkMixFloat4Float4FloatFloat4() {
Allocation inStart = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xa701d3dl, false);
Allocation inStop = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x715beb33l, false);
Allocation inFraction = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xfb37303l, 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];
Arrays.fill(arrayInStart, (float) 42);
inStart.copyTo(arrayInStart);
float[] arrayInStop = new float[INPUTSIZE * 4];
Arrays.fill(arrayInStop, (float) 42);
inStop.copyTo(arrayInStop);
float[] arrayInFraction = new float[INPUTSIZE * 1];
Arrays.fill(arrayInFraction, (float) 42);
inFraction.copyTo(arrayInFraction);
float[] arrayOut = new float[INPUTSIZE * 4];
Arrays.fill(arrayOut, (float) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
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) {
if (!errorFound) {
errorFound = true;
message.append("Input inStart: ");
appendVariableToMessage(message, args.inStart);
message.append("\n");
message.append("Input inStop: ");
appendVariableToMessage(message, args.inStop);
message.append("\n");
message.append("Input inFraction: ");
appendVariableToMessage(message, args.inFraction);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (!args.out.couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkMixFloat4Float4FloatFloat4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public void testMix() {
checkMixFloatFloatFloatFloat();
checkMixFloat2Float2Float2Float2();
checkMixFloat3Float3Float3Float3();
checkMixFloat4Float4Float4Float4();
checkMixFloat2Float2FloatFloat2();
checkMixFloat3Float3FloatFloat3();
checkMixFloat4Float4FloatFloat4();
}
}