blob: 74e22a4b4884130d0c10171869c14755a8603e76 [file] [log] [blame]
/*
* Copyright (C) 2016 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 android.renderscript.cts.Target;
import java.util.Arrays;
public class TestDistance extends RSBaseCompute {
private ScriptC_TestDistance script;
private ScriptC_TestDistanceRelaxed scriptRelaxed;
@Override
protected void setUp() throws Exception {
super.setUp();
script = new ScriptC_TestDistance(mRS);
scriptRelaxed = new ScriptC_TestDistanceRelaxed(mRS);
}
@Override
protected void tearDown() throws Exception {
script.destroy();
scriptRelaxed.destroy();
super.tearDown();
}
public class ArgumentsFloatFloatFloat {
public float inLeftVector;
public float inRightVector;
public Target.Floaty out;
}
private void checkDistanceFloatFloatFloat() {
Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xa481527082ced52al, false);
Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xa38cb25366d69793l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
script.set_gAllocInRightVector(inRightVector);
script.forEach_testDistanceFloatFloatFloat(inLeftVector, out);
verifyResultsDistanceFloatFloatFloat(inLeftVector, inRightVector, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceFloatFloatFloat: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
scriptRelaxed.set_gAllocInRightVector(inRightVector);
scriptRelaxed.forEach_testDistanceFloatFloatFloat(inLeftVector, out);
verifyResultsDistanceFloatFloatFloat(inLeftVector, inRightVector, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceFloatFloatFloat: " + e.toString());
}
inLeftVector.destroy();
inRightVector.destroy();
}
private void verifyResultsDistanceFloatFloatFloat(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) {
float[] arrayInLeftVector = new float[INPUTSIZE * 1];
Arrays.fill(arrayInLeftVector, (float) 42);
inLeftVector.copyTo(arrayInLeftVector);
float[] arrayInRightVector = new float[INPUTSIZE * 1];
Arrays.fill(arrayInRightVector, (float) 42);
inRightVector.copyTo(arrayInRightVector);
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++) {
ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat();
// Create the appropriate sized arrays in args
// Fill args with the input values
args.inLeftVector = arrayInLeftVector[i];
args.inRightVector = arrayInRightVector[i];
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeDistance(args, target);
// Compare the expected outputs to the actual values returned by RS.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inLeftVector: ");
appendVariableToMessage(message, arrayInLeftVector[i]);
message.append("\n");
message.append("Input inRightVector: ");
appendVariableToMessage(message, arrayInRightVector[i]);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i]);
if (!args.out.couldBe(arrayOut[i])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append("]");
}
}
assertFalse("Incorrect output for checkDistanceFloatFloatFloat" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public class ArgumentsFloatNFloatNFloat {
public float[] inLeftVector;
public float[] inRightVector;
public Target.Floaty out;
}
private void checkDistanceFloat2Float2Float() {
Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xbf71d23b554dab2el, false);
Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x29f22964c2248a3fl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
script.set_gAllocInRightVector(inRightVector);
script.forEach_testDistanceFloat2Float2Float(inLeftVector, out);
verifyResultsDistanceFloat2Float2Float(inLeftVector, inRightVector, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceFloat2Float2Float: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
scriptRelaxed.set_gAllocInRightVector(inRightVector);
scriptRelaxed.forEach_testDistanceFloat2Float2Float(inLeftVector, out);
verifyResultsDistanceFloat2Float2Float(inLeftVector, inRightVector, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceFloat2Float2Float: " + e.toString());
}
inLeftVector.destroy();
inRightVector.destroy();
}
private void verifyResultsDistanceFloat2Float2Float(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) {
float[] arrayInLeftVector = new float[INPUTSIZE * 2];
Arrays.fill(arrayInLeftVector, (float) 42);
inLeftVector.copyTo(arrayInLeftVector);
float[] arrayInRightVector = new float[INPUTSIZE * 2];
Arrays.fill(arrayInRightVector, (float) 42);
inRightVector.copyTo(arrayInRightVector);
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++) {
ArgumentsFloatNFloatNFloat args = new ArgumentsFloatNFloatNFloat();
// Create the appropriate sized arrays in args
args.inLeftVector = new float[2];
args.inRightVector = new float[2];
// Fill args with the input values
for (int j = 0; j < 2 ; j++) {
args.inLeftVector[j] = arrayInLeftVector[i * 2 + j];
}
for (int j = 0; j < 2 ; j++) {
args.inRightVector[j] = arrayInRightVector[i * 2 + j];
}
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeDistance(args, target);
// Compare the expected outputs to the actual values returned by RS.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
for (int j = 0; j < 2 ; j++) {
message.append("Input inLeftVector: ");
appendVariableToMessage(message, arrayInLeftVector[i * 2 + j]);
message.append("\n");
}
for (int j = 0; j < 2 ; j++) {
message.append("Input inRightVector: ");
appendVariableToMessage(message, arrayInRightVector[i * 2 + j]);
message.append("\n");
}
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i]);
if (!args.out.couldBe(arrayOut[i])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append("]");
}
}
assertFalse("Incorrect output for checkDistanceFloat2Float2Float" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkDistanceFloat3Float3Float() {
Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x8e1af7b976ec5f7cl, false);
Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe05b759467ccd359l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
script.set_gAllocInRightVector(inRightVector);
script.forEach_testDistanceFloat3Float3Float(inLeftVector, out);
verifyResultsDistanceFloat3Float3Float(inLeftVector, inRightVector, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceFloat3Float3Float: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
scriptRelaxed.set_gAllocInRightVector(inRightVector);
scriptRelaxed.forEach_testDistanceFloat3Float3Float(inLeftVector, out);
verifyResultsDistanceFloat3Float3Float(inLeftVector, inRightVector, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceFloat3Float3Float: " + e.toString());
}
inLeftVector.destroy();
inRightVector.destroy();
}
private void verifyResultsDistanceFloat3Float3Float(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) {
float[] arrayInLeftVector = new float[INPUTSIZE * 4];
Arrays.fill(arrayInLeftVector, (float) 42);
inLeftVector.copyTo(arrayInLeftVector);
float[] arrayInRightVector = new float[INPUTSIZE * 4];
Arrays.fill(arrayInRightVector, (float) 42);
inRightVector.copyTo(arrayInRightVector);
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++) {
ArgumentsFloatNFloatNFloat args = new ArgumentsFloatNFloatNFloat();
// Create the appropriate sized arrays in args
args.inLeftVector = new float[3];
args.inRightVector = new float[3];
// Fill args with the input values
for (int j = 0; j < 3 ; j++) {
args.inLeftVector[j] = arrayInLeftVector[i * 4 + j];
}
for (int j = 0; j < 3 ; j++) {
args.inRightVector[j] = arrayInRightVector[i * 4 + j];
}
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeDistance(args, target);
// Compare the expected outputs to the actual values returned by RS.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
for (int j = 0; j < 3 ; j++) {
message.append("Input inLeftVector: ");
appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]);
message.append("\n");
}
for (int j = 0; j < 3 ; j++) {
message.append("Input inRightVector: ");
appendVariableToMessage(message, arrayInRightVector[i * 4 + j]);
message.append("\n");
}
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i]);
if (!args.out.couldBe(arrayOut[i])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append("]");
}
}
assertFalse("Incorrect output for checkDistanceFloat3Float3Float" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkDistanceFloat4Float4Float() {
Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x5cc41d37988b13cal, false);
Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x96c4c1c40d751c73l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
script.set_gAllocInRightVector(inRightVector);
script.forEach_testDistanceFloat4Float4Float(inLeftVector, out);
verifyResultsDistanceFloat4Float4Float(inLeftVector, inRightVector, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceFloat4Float4Float: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE);
scriptRelaxed.set_gAllocInRightVector(inRightVector);
scriptRelaxed.forEach_testDistanceFloat4Float4Float(inLeftVector, out);
verifyResultsDistanceFloat4Float4Float(inLeftVector, inRightVector, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceFloat4Float4Float: " + e.toString());
}
inLeftVector.destroy();
inRightVector.destroy();
}
private void verifyResultsDistanceFloat4Float4Float(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) {
float[] arrayInLeftVector = new float[INPUTSIZE * 4];
Arrays.fill(arrayInLeftVector, (float) 42);
inLeftVector.copyTo(arrayInLeftVector);
float[] arrayInRightVector = new float[INPUTSIZE * 4];
Arrays.fill(arrayInRightVector, (float) 42);
inRightVector.copyTo(arrayInRightVector);
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++) {
ArgumentsFloatNFloatNFloat args = new ArgumentsFloatNFloatNFloat();
// Create the appropriate sized arrays in args
args.inLeftVector = new float[4];
args.inRightVector = new float[4];
// Fill args with the input values
for (int j = 0; j < 4 ; j++) {
args.inLeftVector[j] = arrayInLeftVector[i * 4 + j];
}
for (int j = 0; j < 4 ; j++) {
args.inRightVector[j] = arrayInRightVector[i * 4 + j];
}
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed);
CoreMathVerifier.computeDistance(args, target);
// Compare the expected outputs to the actual values returned by RS.
boolean valid = true;
if (!args.out.couldBe(arrayOut[i])) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
for (int j = 0; j < 4 ; j++) {
message.append("Input inLeftVector: ");
appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]);
message.append("\n");
}
for (int j = 0; j < 4 ; j++) {
message.append("Input inRightVector: ");
appendVariableToMessage(message, arrayInRightVector[i * 4 + j]);
message.append("\n");
}
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i]);
if (!args.out.couldBe(arrayOut[i])) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append("]");
}
}
assertFalse("Incorrect output for checkDistanceFloat4Float4Float" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public class ArgumentsHalfHalfHalf {
public short inLeftVector;
public double inLeftVectorDouble;
public short inRightVector;
public double inRightVectorDouble;
public Target.Floaty out;
}
private void checkDistanceHalfHalfHalf() {
Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xc2d03f430b911c71l, false);
Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xbace79b05f789080l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
script.set_gAllocInRightVector(inRightVector);
script.forEach_testDistanceHalfHalfHalf(inLeftVector, out);
verifyResultsDistanceHalfHalfHalf(inLeftVector, inRightVector, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceHalfHalfHalf: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
scriptRelaxed.set_gAllocInRightVector(inRightVector);
scriptRelaxed.forEach_testDistanceHalfHalfHalf(inLeftVector, out);
verifyResultsDistanceHalfHalfHalf(inLeftVector, inRightVector, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceHalfHalfHalf: " + e.toString());
}
inLeftVector.destroy();
inRightVector.destroy();
}
private void verifyResultsDistanceHalfHalfHalf(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) {
short[] arrayInLeftVector = new short[INPUTSIZE * 1];
Arrays.fill(arrayInLeftVector, (short) 42);
inLeftVector.copyTo(arrayInLeftVector);
short[] arrayInRightVector = new short[INPUTSIZE * 1];
Arrays.fill(arrayInRightVector, (short) 42);
inRightVector.copyTo(arrayInRightVector);
short[] arrayOut = new short[INPUTSIZE * 1];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf();
// Create the appropriate sized arrays in args
// Fill args with the input values
args.inLeftVector = arrayInLeftVector[i];
args.inLeftVectorDouble = Float16Utils.convertFloat16ToDouble(args.inLeftVector);
args.inRightVector = arrayInRightVector[i];
args.inRightVectorDouble = Float16Utils.convertFloat16ToDouble(args.inRightVector);
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeDistance(args, target);
// Compare the expected outputs to the actual values returned by RS.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inLeftVector: ");
appendVariableToMessage(message, arrayInLeftVector[i]);
message.append("\n");
message.append("Input inRightVector: ");
appendVariableToMessage(message, arrayInRightVector[i]);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append("]");
}
}
assertFalse("Incorrect output for checkDistanceHalfHalfHalf" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public class ArgumentsHalfNHalfNHalf {
public short[] inLeftVector;
public double[] inLeftVectorDouble;
public short[] inRightVector;
public double[] inRightVectorDouble;
public Target.Floaty out;
}
private void checkDistanceHalf2Half2Half() {
Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x8046ee611fddb297l, false);
Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x8dbde3bdc855c8e2l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
script.set_gAllocInRightVector(inRightVector);
script.forEach_testDistanceHalf2Half2Half(inLeftVector, out);
verifyResultsDistanceHalf2Half2Half(inLeftVector, inRightVector, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceHalf2Half2Half: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
scriptRelaxed.set_gAllocInRightVector(inRightVector);
scriptRelaxed.forEach_testDistanceHalf2Half2Half(inLeftVector, out);
verifyResultsDistanceHalf2Half2Half(inLeftVector, inRightVector, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceHalf2Half2Half: " + e.toString());
}
inLeftVector.destroy();
inRightVector.destroy();
}
private void verifyResultsDistanceHalf2Half2Half(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) {
short[] arrayInLeftVector = new short[INPUTSIZE * 2];
Arrays.fill(arrayInLeftVector, (short) 42);
inLeftVector.copyTo(arrayInLeftVector);
short[] arrayInRightVector = new short[INPUTSIZE * 2];
Arrays.fill(arrayInRightVector, (short) 42);
inRightVector.copyTo(arrayInRightVector);
short[] arrayOut = new short[INPUTSIZE * 1];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
ArgumentsHalfNHalfNHalf args = new ArgumentsHalfNHalfNHalf();
// Create the appropriate sized arrays in args
args.inLeftVector = new short[2];
args.inLeftVectorDouble = new double[2];
args.inRightVector = new short[2];
args.inRightVectorDouble = new double[2];
// Fill args with the input values
for (int j = 0; j < 2 ; j++) {
args.inLeftVector[j] = arrayInLeftVector[i * 2 + j];
args.inLeftVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inLeftVector[j]);
}
for (int j = 0; j < 2 ; j++) {
args.inRightVector[j] = arrayInRightVector[i * 2 + j];
args.inRightVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inRightVector[j]);
}
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeDistance(args, target);
// Compare the expected outputs to the actual values returned by RS.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
for (int j = 0; j < 2 ; j++) {
message.append("Input inLeftVector: ");
appendVariableToMessage(message, arrayInLeftVector[i * 2 + j]);
message.append("\n");
}
for (int j = 0; j < 2 ; j++) {
message.append("Input inRightVector: ");
appendVariableToMessage(message, arrayInRightVector[i * 2 + j]);
message.append("\n");
}
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append("]");
}
}
assertFalse("Incorrect output for checkDistanceHalf2Half2Half" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkDistanceHalf3Half3Half() {
Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x2e003bb4ea22ab53l, false);
Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xbbdde0d0c1eb9076l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
script.set_gAllocInRightVector(inRightVector);
script.forEach_testDistanceHalf3Half3Half(inLeftVector, out);
verifyResultsDistanceHalf3Half3Half(inLeftVector, inRightVector, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceHalf3Half3Half: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
scriptRelaxed.set_gAllocInRightVector(inRightVector);
scriptRelaxed.forEach_testDistanceHalf3Half3Half(inLeftVector, out);
verifyResultsDistanceHalf3Half3Half(inLeftVector, inRightVector, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceHalf3Half3Half: " + e.toString());
}
inLeftVector.destroy();
inRightVector.destroy();
}
private void verifyResultsDistanceHalf3Half3Half(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) {
short[] arrayInLeftVector = new short[INPUTSIZE * 4];
Arrays.fill(arrayInLeftVector, (short) 42);
inLeftVector.copyTo(arrayInLeftVector);
short[] arrayInRightVector = new short[INPUTSIZE * 4];
Arrays.fill(arrayInRightVector, (short) 42);
inRightVector.copyTo(arrayInRightVector);
short[] arrayOut = new short[INPUTSIZE * 1];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
ArgumentsHalfNHalfNHalf args = new ArgumentsHalfNHalfNHalf();
// Create the appropriate sized arrays in args
args.inLeftVector = new short[3];
args.inLeftVectorDouble = new double[3];
args.inRightVector = new short[3];
args.inRightVectorDouble = new double[3];
// Fill args with the input values
for (int j = 0; j < 3 ; j++) {
args.inLeftVector[j] = arrayInLeftVector[i * 4 + j];
args.inLeftVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inLeftVector[j]);
}
for (int j = 0; j < 3 ; j++) {
args.inRightVector[j] = arrayInRightVector[i * 4 + j];
args.inRightVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inRightVector[j]);
}
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeDistance(args, target);
// Compare the expected outputs to the actual values returned by RS.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
for (int j = 0; j < 3 ; j++) {
message.append("Input inLeftVector: ");
appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]);
message.append("\n");
}
for (int j = 0; j < 3 ; j++) {
message.append("Input inRightVector: ");
appendVariableToMessage(message, arrayInRightVector[i * 4 + j]);
message.append("\n");
}
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append("]");
}
}
assertFalse("Incorrect output for checkDistanceHalf3Half3Half" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkDistanceHalf4Half4Half() {
Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xdbb98908b467a40fl, false);
Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xe9fddde3bb81580al, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
script.set_gAllocInRightVector(inRightVector);
script.forEach_testDistanceHalf4Half4Half(inLeftVector, out);
verifyResultsDistanceHalf4Half4Half(inLeftVector, inRightVector, out, false);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceHalf4Half4Half: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
scriptRelaxed.set_gAllocInRightVector(inRightVector);
scriptRelaxed.forEach_testDistanceHalf4Half4Half(inLeftVector, out);
verifyResultsDistanceHalf4Half4Half(inLeftVector, inRightVector, out, true);
out.destroy();
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testDistanceHalf4Half4Half: " + e.toString());
}
inLeftVector.destroy();
inRightVector.destroy();
}
private void verifyResultsDistanceHalf4Half4Half(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) {
short[] arrayInLeftVector = new short[INPUTSIZE * 4];
Arrays.fill(arrayInLeftVector, (short) 42);
inLeftVector.copyTo(arrayInLeftVector);
short[] arrayInRightVector = new short[INPUTSIZE * 4];
Arrays.fill(arrayInRightVector, (short) 42);
inRightVector.copyTo(arrayInRightVector);
short[] arrayOut = new short[INPUTSIZE * 1];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
ArgumentsHalfNHalfNHalf args = new ArgumentsHalfNHalfNHalf();
// Create the appropriate sized arrays in args
args.inLeftVector = new short[4];
args.inLeftVectorDouble = new double[4];
args.inRightVector = new short[4];
args.inRightVectorDouble = new double[4];
// Fill args with the input values
for (int j = 0; j < 4 ; j++) {
args.inLeftVector[j] = arrayInLeftVector[i * 4 + j];
args.inLeftVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inLeftVector[j]);
}
for (int j = 0; j < 4 ; j++) {
args.inRightVector[j] = arrayInRightVector[i * 4 + j];
args.inRightVectorDouble[j] = Float16Utils.convertFloat16ToDouble(args.inRightVector[j]);
}
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeDistance(args, target);
// Compare the expected outputs to the actual values returned by RS.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
for (int j = 0; j < 4 ; j++) {
message.append("Input inLeftVector: ");
appendVariableToMessage(message, arrayInLeftVector[i * 4 + j]);
message.append("\n");
}
for (int j = 0; j < 4 ; j++) {
message.append("Input inRightVector: ");
appendVariableToMessage(message, arrayInRightVector[i * 4 + j]);
message.append("\n");
}
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i]))) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append("]");
}
}
assertFalse("Incorrect output for checkDistanceHalf4Half4Half" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public void testDistance() {
checkDistanceFloatFloatFloat();
checkDistanceFloat2Float2Float();
checkDistanceFloat3Float3Float();
checkDistanceFloat4Float4Float();
checkDistanceHalfHalfHalf();
checkDistanceHalf2Half2Half();
checkDistanceHalf3Half3Half();
checkDistanceHalf4Half4Half();
}
}