blob: 7fc50f7781998a093aa69a6e147e26c8b26be7e4 [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;
public class TestCross extends RSBaseCompute {
private ScriptC_TestCross script;
private ScriptC_TestCrossRelaxed scriptRelaxed;
@Override
protected void setUp() throws Exception {
super.setUp();
script = new ScriptC_TestCross(mRS);
scriptRelaxed = new ScriptC_TestCrossRelaxed(mRS);
}
public class ArgumentsFloatNFloatNFloatN {
public float[] inLeftVector;
public float[] inRightVector;
public Target.Floaty[] out;
}
private void checkCrossFloat3Float3Float3() {
Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x3505ebf7382f1ad4l, false);
Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe9d27bf3de024b21l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
script.set_gAllocInRightVector(inRightVector);
script.forEach_testCrossFloat3Float3Float3(inLeftVector, out);
verifyResultsCrossFloat3Float3Float3(inLeftVector, inRightVector, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat3Float3Float3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
scriptRelaxed.set_gAllocInRightVector(inRightVector);
scriptRelaxed.forEach_testCrossFloat3Float3Float3(inLeftVector, out);
verifyResultsCrossFloat3Float3Float3(inLeftVector, inRightVector, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat3Float3Float3: " + e.toString());
}
}
private void verifyResultsCrossFloat3Float3Float3(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) {
float[] arrayInLeftVector = new float[INPUTSIZE * 4];
inLeftVector.copyTo(arrayInLeftVector);
float[] arrayInRightVector = new float[INPUTSIZE * 4];
inRightVector.copyTo(arrayInRightVector);
float[] arrayOut = new float[INPUTSIZE * 4];
out.copyTo(arrayOut);
for (int i = 0; i < INPUTSIZE; i++) {
ArgumentsFloatNFloatNFloatN args = new ArgumentsFloatNFloatNFloatN();
// Create the appropriate sized arrays in args
args.inLeftVector = new float[3];
args.inRightVector = new float[3];
args.out = new Target.Floaty[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(relaxed);
CoreMathVerifier.computeCross(args, target);
// Compare the expected outputs to the actual values returned by RS.
boolean valid = true;
for (int j = 0; j < 3 ; j++) {
if (!args.out[j].couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
}
if (!valid) {
StringBuilder message = new StringBuilder();
for (int j = 0; j < 3 ; j++) {
message.append("Input inLeftVector: ");
message.append(String.format("%14.8g {%8x} %15a",
arrayInLeftVector[i * 4 + j], Float.floatToRawIntBits(arrayInLeftVector[i * 4 + j]), arrayInLeftVector[i * 4 + j]));
message.append("\n");
}
for (int j = 0; j < 3 ; j++) {
message.append("Input inRightVector: ");
message.append(String.format("%14.8g {%8x} %15a",
arrayInRightVector[i * 4 + j], Float.floatToRawIntBits(arrayInRightVector[i * 4 + j]), arrayInRightVector[i * 4 + j]));
message.append("\n");
}
for (int j = 0; j < 3 ; j++) {
message.append("Expected output out: ");
message.append(args.out[j].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[j].couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
}
assertTrue("Incorrect output for checkCrossFloat3Float3Float3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
}
}
}
private void checkCrossFloat4Float4Float4() {
Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x15fc58a5906fbeffl, false);
Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xb336bd3cb0ddde5al, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
script.set_gAllocInRightVector(inRightVector);
script.forEach_testCrossFloat4Float4Float4(inLeftVector, out);
verifyResultsCrossFloat4Float4Float4(inLeftVector, inRightVector, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat4Float4Float4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
scriptRelaxed.set_gAllocInRightVector(inRightVector);
scriptRelaxed.forEach_testCrossFloat4Float4Float4(inLeftVector, out);
verifyResultsCrossFloat4Float4Float4(inLeftVector, inRightVector, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testCrossFloat4Float4Float4: " + e.toString());
}
}
private void verifyResultsCrossFloat4Float4Float4(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) {
float[] arrayInLeftVector = new float[INPUTSIZE * 4];
inLeftVector.copyTo(arrayInLeftVector);
float[] arrayInRightVector = new float[INPUTSIZE * 4];
inRightVector.copyTo(arrayInRightVector);
float[] arrayOut = new float[INPUTSIZE * 4];
out.copyTo(arrayOut);
for (int i = 0; i < INPUTSIZE; i++) {
ArgumentsFloatNFloatNFloatN args = new ArgumentsFloatNFloatNFloatN();
// Create the appropriate sized arrays in args
args.inLeftVector = new float[4];
args.inRightVector = new float[4];
args.out = new Target.Floaty[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(relaxed);
CoreMathVerifier.computeCross(args, target);
// Compare the expected outputs to the actual values returned by RS.
boolean valid = true;
for (int j = 0; j < 4 ; j++) {
if (!args.out[j].couldBe(arrayOut[i * 4 + j])) {
valid = false;
}
}
if (!valid) {
StringBuilder message = new StringBuilder();
for (int j = 0; j < 4 ; j++) {
message.append("Input inLeftVector: ");
message.append(String.format("%14.8g {%8x} %15a",
arrayInLeftVector[i * 4 + j], Float.floatToRawIntBits(arrayInLeftVector[i * 4 + j]), arrayInLeftVector[i * 4 + j]));
message.append("\n");
}
for (int j = 0; j < 4 ; j++) {
message.append("Input inRightVector: ");
message.append(String.format("%14.8g {%8x} %15a",
arrayInRightVector[i * 4 + j], Float.floatToRawIntBits(arrayInRightVector[i * 4 + j]), arrayInRightVector[i * 4 + j]));
message.append("\n");
}
for (int j = 0; j < 4 ; j++) {
message.append("Expected output out: ");
message.append(args.out[j].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[j].couldBe(arrayOut[i * 4 + j])) {
message.append(" FAIL");
}
message.append("\n");
}
assertTrue("Incorrect output for checkCrossFloat4Float4Float4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
}
}
}
public void testCross() {
checkCrossFloat3Float3Float3();
checkCrossFloat4Float4Float4();
}
}