blob: 51f6fb7605b14266f0b6e9f06df0667bf17e763d [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 TestNanHalf extends RSBaseCompute {
private ScriptC_TestNanHalf script;
private ScriptC_TestNanHalfRelaxed scriptRelaxed;
@Override
protected void setUp() throws Exception {
super.setUp();
script = new ScriptC_TestNanHalf(mRS);
scriptRelaxed = new ScriptC_TestNanHalfRelaxed(mRS);
}
public class ArgumentsHalf {
public Target.Floaty out;
}
private void checkNanHalfHalf() {
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
script.forEach_testNanHalfHalf(out);
verifyResultsNanHalfHalf(out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNanHalfHalf: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE);
scriptRelaxed.forEach_testNanHalfHalf(out);
verifyResultsNanHalfHalf(out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNanHalfHalf: " + e.toString());
}
}
private void verifyResultsNanHalfHalf(Allocation out, boolean relaxed) {
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++) {
for (int j = 0; j < 1 ; j++) {
// Extract the inputs.
ArgumentsHalf args = new ArgumentsHalf();
// Figure out what the outputs should have been.
Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed);
CoreMathVerifier.computeNanHalf(args, target);
// Validate the outputs.
boolean valid = true;
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 1 + j]);
message.append("\n");
message.append("Actual output out (in double): ");
appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]));
if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(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 checkNanHalfHalf" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public void testNanHalf() {
checkNanHalfHalf();
}
}