| /* |
| * Copyright (C) 2014 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 GeneratedTestNativeDivide extends RSBaseCompute { |
| |
| private ScriptC_GeneratedTestNativeDivide script; |
| private ScriptC_GeneratedTestNativeDivideRelaxed scriptRelaxed; |
| |
| @Override |
| protected void setUp() throws Exception { |
| super.setUp(); |
| script = new ScriptC_GeneratedTestNativeDivide(mRS); |
| scriptRelaxed = new ScriptC_GeneratedTestNativeDivideRelaxed(mRS); |
| } |
| |
| public class ArgumentsFloatFloatFloat { |
| public float inLeftVector; |
| public float inRightVector; |
| public Target.Floaty out; |
| } |
| |
| private void checkNativeDivideFloatFloatFloat() { |
| Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x73477387751754efl, false); |
| Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x5ed4412e19040daal, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); |
| script.set_gAllocInRightVector(inRightVector); |
| script.forEach_testNativeDivideFloatFloatFloat(inLeftVector, out); |
| verifyResultsNativeDivideFloatFloatFloat(inLeftVector, inRightVector, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeDivideFloatFloatFloat: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); |
| scriptRelaxed.set_gAllocInRightVector(inRightVector); |
| scriptRelaxed.forEach_testNativeDivideFloatFloatFloat(inLeftVector, out); |
| verifyResultsNativeDivideFloatFloatFloat(inLeftVector, inRightVector, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeDivideFloatFloatFloat: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsNativeDivideFloatFloatFloat(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { |
| float[] arrayInLeftVector = new float[INPUTSIZE * 1]; |
| inLeftVector.copyTo(arrayInLeftVector); |
| float[] arrayInRightVector = new float[INPUTSIZE * 1]; |
| inRightVector.copyTo(arrayInRightVector); |
| 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. |
| ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); |
| args.inLeftVector = arrayInLeftVector[i]; |
| args.inRightVector = arrayInRightVector[i]; |
| // Figure out what the outputs should have been. |
| Target target = new Target(relaxed); |
| CoreMathVerifier.computeNativeDivide(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 inLeftVector: "); |
| message.append(String.format("%14.8g {%8x} %15a", |
| args.inLeftVector, Float.floatToRawIntBits(args.inLeftVector), args.inLeftVector)); |
| message.append("\n"); |
| message.append("Input inRightVector: "); |
| message.append(String.format("%14.8g {%8x} %15a", |
| args.inRightVector, Float.floatToRawIntBits(args.inRightVector), args.inRightVector)); |
| 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 checkNativeDivideFloatFloatFloat" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkNativeDivideFloat2Float2Float2() { |
| Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x752d5a1207785d6dl, false); |
| Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xb071fa74af507ad4l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); |
| script.set_gAllocInRightVector(inRightVector); |
| script.forEach_testNativeDivideFloat2Float2Float2(inLeftVector, out); |
| verifyResultsNativeDivideFloat2Float2Float2(inLeftVector, inRightVector, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeDivideFloat2Float2Float2: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); |
| scriptRelaxed.set_gAllocInRightVector(inRightVector); |
| scriptRelaxed.forEach_testNativeDivideFloat2Float2Float2(inLeftVector, out); |
| verifyResultsNativeDivideFloat2Float2Float2(inLeftVector, inRightVector, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeDivideFloat2Float2Float2: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsNativeDivideFloat2Float2Float2(Allocation inLeftVector, Allocation inRightVector, Allocation out, boolean relaxed) { |
| float[] arrayInLeftVector = new float[INPUTSIZE * 2]; |
| inLeftVector.copyTo(arrayInLeftVector); |
| float[] arrayInRightVector = new float[INPUTSIZE * 2]; |
| inRightVector.copyTo(arrayInRightVector); |
| 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. |
| ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); |
| args.inLeftVector = arrayInLeftVector[i * 2 + j]; |
| args.inRightVector = arrayInRightVector[i * 2 + j]; |
| // Figure out what the outputs should have been. |
| Target target = new Target(relaxed); |
| CoreMathVerifier.computeNativeDivide(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 inLeftVector: "); |
| message.append(String.format("%14.8g {%8x} %15a", |
| args.inLeftVector, Float.floatToRawIntBits(args.inLeftVector), args.inLeftVector)); |
| message.append("\n"); |
| message.append("Input inRightVector: "); |
| message.append(String.format("%14.8g {%8x} %15a", |
| args.inRightVector, Float.floatToRawIntBits(args.inRightVector), args.inRightVector)); |
| 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 checkNativeDivideFloat2Float2Float2" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkNativeDivideFloat3Float3Float3() { |
| Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x5623c6c05fb90198l, false); |
| Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x79d63bbd822c0e0dl, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); |
| script.set_gAllocInRightVector(inRightVector); |
| script.forEach_testNativeDivideFloat3Float3Float3(inLeftVector, out); |
| verifyResultsNativeDivideFloat3Float3Float3(inLeftVector, inRightVector, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeDivideFloat3Float3Float3: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); |
| scriptRelaxed.set_gAllocInRightVector(inRightVector); |
| scriptRelaxed.forEach_testNativeDivideFloat3Float3Float3(inLeftVector, out); |
| verifyResultsNativeDivideFloat3Float3Float3(inLeftVector, inRightVector, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeDivideFloat3Float3Float3: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsNativeDivideFloat3Float3Float3(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++) { |
| for (int j = 0; j < 3 ; j++) { |
| // Extract the inputs. |
| ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); |
| args.inLeftVector = arrayInLeftVector[i * 4 + j]; |
| args.inRightVector = arrayInRightVector[i * 4 + j]; |
| // Figure out what the outputs should have been. |
| Target target = new Target(relaxed); |
| CoreMathVerifier.computeNativeDivide(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 inLeftVector: "); |
| message.append(String.format("%14.8g {%8x} %15a", |
| args.inLeftVector, Float.floatToRawIntBits(args.inLeftVector), args.inLeftVector)); |
| message.append("\n"); |
| message.append("Input inRightVector: "); |
| message.append(String.format("%14.8g {%8x} %15a", |
| args.inRightVector, Float.floatToRawIntBits(args.inRightVector), args.inRightVector)); |
| 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 checkNativeDivideFloat3Float3Float3" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkNativeDivideFloat4Float4Float4() { |
| Allocation inLeftVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x371a336eb7f9a5c3l, false); |
| Allocation inRightVector = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x433a7d065507a146l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); |
| script.set_gAllocInRightVector(inRightVector); |
| script.forEach_testNativeDivideFloat4Float4Float4(inLeftVector, out); |
| verifyResultsNativeDivideFloat4Float4Float4(inLeftVector, inRightVector, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeDivideFloat4Float4Float4: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); |
| scriptRelaxed.set_gAllocInRightVector(inRightVector); |
| scriptRelaxed.forEach_testNativeDivideFloat4Float4Float4(inLeftVector, out); |
| verifyResultsNativeDivideFloat4Float4Float4(inLeftVector, inRightVector, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeDivideFloat4Float4Float4: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsNativeDivideFloat4Float4Float4(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++) { |
| for (int j = 0; j < 4 ; j++) { |
| // Extract the inputs. |
| ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); |
| args.inLeftVector = arrayInLeftVector[i * 4 + j]; |
| args.inRightVector = arrayInRightVector[i * 4 + j]; |
| // Figure out what the outputs should have been. |
| Target target = new Target(relaxed); |
| CoreMathVerifier.computeNativeDivide(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 inLeftVector: "); |
| message.append(String.format("%14.8g {%8x} %15a", |
| args.inLeftVector, Float.floatToRawIntBits(args.inLeftVector), args.inLeftVector)); |
| message.append("\n"); |
| message.append("Input inRightVector: "); |
| message.append(String.format("%14.8g {%8x} %15a", |
| args.inRightVector, Float.floatToRawIntBits(args.inRightVector), args.inRightVector)); |
| 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 checkNativeDivideFloat4Float4Float4" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| public void testNativeDivide() { |
| checkNativeDivideFloatFloatFloat(); |
| checkNativeDivideFloat2Float2Float2(); |
| checkNativeDivideFloat3Float3Float3(); |
| checkNativeDivideFloat4Float4Float4(); |
| } |
| } |