| /* |
| * 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 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 inAmount; |
| public float out; |
| |
| public int ulf; |
| public int ulfRelaxed; |
| } |
| |
| private void checkMixFloatFloatFloatFloat() { |
| Allocation inStart = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x683b1cd71c16e1b4L); |
| Allocation inStop = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x683b1cd71c16e1b4L); |
| Allocation inAmount = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x683b1cd71c16e1b4L); |
| try { |
| Allocation out = Allocation.createSized(mRS, GetElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); |
| script.set_gAllocInStop(inStop); |
| script.set_gAllocInAmount(inAmount); |
| script.forEach_testMixFloatFloatFloatFloat(inStart, out); |
| verifyResultsMixFloatFloatFloatFloat(inStart, inStop, inAmount, 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_gAllocInAmount(inAmount); |
| scriptRelaxed.forEach_testMixFloatFloatFloatFloat(inStart, out); |
| verifyResultsMixFloatFloatFloatFloat(inStart, inStop, inAmount, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloatFloatFloatFloat: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsMixFloatFloatFloatFloat(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) { |
| float[] arrayInStart = new float[INPUTSIZE * 1]; |
| inStart.copyTo(arrayInStart); |
| float[] arrayInStop = new float[INPUTSIZE * 1]; |
| inStop.copyTo(arrayInStop); |
| float[] arrayInAmount = new float[INPUTSIZE * 1]; |
| inAmount.copyTo(arrayInAmount); |
| 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. |
| ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); |
| args.inStart = arrayInStart[i]; |
| args.inStop = arrayInStop[i]; |
| args.inAmount = arrayInAmount[i]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeMix(args); |
| int ulf = relaxed ? args.ulfRelaxed : args.ulf; |
| // Figure out what the outputs should have been. |
| boolean valid = true; |
| int neededUlf = 0; |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 1 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append(String.format("Input inStart: %x %.16f", Float.floatToRawIntBits(args.inStart), args.inStart)); |
| message.append("\n"); |
| message.append(String.format("Input inStop: %x %.16f", Float.floatToRawIntBits(args.inStop), args.inStop)); |
| message.append("\n"); |
| message.append(String.format("Input inAmount: %x %.16f", Float.floatToRawIntBits(args.inAmount), args.inAmount)); |
| message.append("\n"); |
| message.append(String.format("Expected output out: %x %.16f", Float.floatToRawIntBits(args.out), args.out)); |
| message.append("\n"); |
| message.append(String.format("Actual output out: %x %.16f", Float.floatToRawIntBits(arrayOut[i * 1 + j]), arrayOut[i * 1 + j])); |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 1 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| message.append(String.format(" FAILED, ulf needed %d, specified %d", neededUlf, ulf)); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkMixFloatFloatFloatFloat" + (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkMixFloat2Float2Float2Float2() { |
| Allocation inStart = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xc1902b42a420626cL); |
| Allocation inStop = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xc1902b42a420626cL); |
| Allocation inAmount = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xc1902b42a420626cL); |
| try { |
| Allocation out = Allocation.createSized(mRS, GetElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); |
| script.set_gAllocInStop(inStop); |
| script.set_gAllocInAmount(inAmount); |
| script.forEach_testMixFloat2Float2Float2Float2(inStart, out); |
| verifyResultsMixFloat2Float2Float2Float2(inStart, inStop, inAmount, 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_gAllocInAmount(inAmount); |
| scriptRelaxed.forEach_testMixFloat2Float2Float2Float2(inStart, out); |
| verifyResultsMixFloat2Float2Float2Float2(inStart, inStop, inAmount, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2Float2Float2: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsMixFloat2Float2Float2Float2(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) { |
| float[] arrayInStart = new float[INPUTSIZE * 2]; |
| inStart.copyTo(arrayInStart); |
| float[] arrayInStop = new float[INPUTSIZE * 2]; |
| inStop.copyTo(arrayInStop); |
| float[] arrayInAmount = new float[INPUTSIZE * 2]; |
| inAmount.copyTo(arrayInAmount); |
| 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. |
| ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); |
| args.inStart = arrayInStart[i * 2 + j]; |
| args.inStop = arrayInStop[i * 2 + j]; |
| args.inAmount = arrayInAmount[i * 2 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeMix(args); |
| int ulf = relaxed ? args.ulfRelaxed : args.ulf; |
| // Figure out what the outputs should have been. |
| boolean valid = true; |
| int neededUlf = 0; |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 2 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append(String.format("Input inStart: %x %.16f", Float.floatToRawIntBits(args.inStart), args.inStart)); |
| message.append("\n"); |
| message.append(String.format("Input inStop: %x %.16f", Float.floatToRawIntBits(args.inStop), args.inStop)); |
| message.append("\n"); |
| message.append(String.format("Input inAmount: %x %.16f", Float.floatToRawIntBits(args.inAmount), args.inAmount)); |
| message.append("\n"); |
| message.append(String.format("Expected output out: %x %.16f", Float.floatToRawIntBits(args.out), args.out)); |
| message.append("\n"); |
| message.append(String.format("Actual output out: %x %.16f", Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j])); |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 2 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| message.append(String.format(" FAILED, ulf needed %d, specified %d", neededUlf, ulf)); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkMixFloat2Float2Float2Float2" + (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkMixFloat3Float3Float3Float3() { |
| Allocation inStart = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x9709cedd76879c08L); |
| Allocation inStop = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x9709cedd76879c08L); |
| Allocation inAmount = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x9709cedd76879c08L); |
| try { |
| Allocation out = Allocation.createSized(mRS, GetElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); |
| script.set_gAllocInStop(inStop); |
| script.set_gAllocInAmount(inAmount); |
| script.forEach_testMixFloat3Float3Float3Float3(inStart, out); |
| verifyResultsMixFloat3Float3Float3Float3(inStart, inStop, inAmount, 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_gAllocInAmount(inAmount); |
| scriptRelaxed.forEach_testMixFloat3Float3Float3Float3(inStart, out); |
| verifyResultsMixFloat3Float3Float3Float3(inStart, inStop, inAmount, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3Float3Float3: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsMixFloat3Float3Float3Float3(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) { |
| float[] arrayInStart = new float[INPUTSIZE * 4]; |
| inStart.copyTo(arrayInStart); |
| float[] arrayInStop = new float[INPUTSIZE * 4]; |
| inStop.copyTo(arrayInStop); |
| float[] arrayInAmount = new float[INPUTSIZE * 4]; |
| inAmount.copyTo(arrayInAmount); |
| 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. |
| ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); |
| args.inStart = arrayInStart[i * 4 + j]; |
| args.inStop = arrayInStop[i * 4 + j]; |
| args.inAmount = arrayInAmount[i * 4 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeMix(args); |
| int ulf = relaxed ? args.ulfRelaxed : args.ulf; |
| // Figure out what the outputs should have been. |
| boolean valid = true; |
| int neededUlf = 0; |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 4 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append(String.format("Input inStart: %x %.16f", Float.floatToRawIntBits(args.inStart), args.inStart)); |
| message.append("\n"); |
| message.append(String.format("Input inStop: %x %.16f", Float.floatToRawIntBits(args.inStop), args.inStop)); |
| message.append("\n"); |
| message.append(String.format("Input inAmount: %x %.16f", Float.floatToRawIntBits(args.inAmount), args.inAmount)); |
| message.append("\n"); |
| message.append(String.format("Expected output out: %x %.16f", Float.floatToRawIntBits(args.out), args.out)); |
| message.append("\n"); |
| message.append(String.format("Actual output out: %x %.16f", Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 4 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| message.append(String.format(" FAILED, ulf needed %d, specified %d", neededUlf, ulf)); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkMixFloat3Float3Float3Float3" + (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkMixFloat4Float4Float4Float4() { |
| Allocation inStart = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x6c83727848eed5a4L); |
| Allocation inStop = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x6c83727848eed5a4L); |
| Allocation inAmount = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x6c83727848eed5a4L); |
| try { |
| Allocation out = Allocation.createSized(mRS, GetElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); |
| script.set_gAllocInStop(inStop); |
| script.set_gAllocInAmount(inAmount); |
| script.forEach_testMixFloat4Float4Float4Float4(inStart, out); |
| verifyResultsMixFloat4Float4Float4Float4(inStart, inStop, inAmount, 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_gAllocInAmount(inAmount); |
| scriptRelaxed.forEach_testMixFloat4Float4Float4Float4(inStart, out); |
| verifyResultsMixFloat4Float4Float4Float4(inStart, inStop, inAmount, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4Float4Float4: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsMixFloat4Float4Float4Float4(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) { |
| float[] arrayInStart = new float[INPUTSIZE * 4]; |
| inStart.copyTo(arrayInStart); |
| float[] arrayInStop = new float[INPUTSIZE * 4]; |
| inStop.copyTo(arrayInStop); |
| float[] arrayInAmount = new float[INPUTSIZE * 4]; |
| inAmount.copyTo(arrayInAmount); |
| 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. |
| ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); |
| args.inStart = arrayInStart[i * 4 + j]; |
| args.inStop = arrayInStop[i * 4 + j]; |
| args.inAmount = arrayInAmount[i * 4 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeMix(args); |
| int ulf = relaxed ? args.ulfRelaxed : args.ulf; |
| // Figure out what the outputs should have been. |
| boolean valid = true; |
| int neededUlf = 0; |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 4 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append(String.format("Input inStart: %x %.16f", Float.floatToRawIntBits(args.inStart), args.inStart)); |
| message.append("\n"); |
| message.append(String.format("Input inStop: %x %.16f", Float.floatToRawIntBits(args.inStop), args.inStop)); |
| message.append("\n"); |
| message.append(String.format("Input inAmount: %x %.16f", Float.floatToRawIntBits(args.inAmount), args.inAmount)); |
| message.append("\n"); |
| message.append(String.format("Expected output out: %x %.16f", Float.floatToRawIntBits(args.out), args.out)); |
| message.append("\n"); |
| message.append(String.format("Actual output out: %x %.16f", Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 4 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| message.append(String.format(" FAILED, ulf needed %d, specified %d", neededUlf, ulf)); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkMixFloat4Float4Float4Float4" + (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkMixFloat2Float2FloatFloat2() { |
| Allocation inStart = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x4813e47584a0d66L); |
| Allocation inStop = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x4813e47584a0d66L); |
| Allocation inAmount = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x4813e47584a0d66L); |
| try { |
| Allocation out = Allocation.createSized(mRS, GetElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); |
| script.set_gAllocInStop(inStop); |
| script.set_gAllocInAmount(inAmount); |
| script.forEach_testMixFloat2Float2FloatFloat2(inStart, out); |
| verifyResultsMixFloat2Float2FloatFloat2(inStart, inStop, inAmount, 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_gAllocInAmount(inAmount); |
| scriptRelaxed.forEach_testMixFloat2Float2FloatFloat2(inStart, out); |
| verifyResultsMixFloat2Float2FloatFloat2(inStart, inStop, inAmount, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat2Float2FloatFloat2: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsMixFloat2Float2FloatFloat2(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) { |
| float[] arrayInStart = new float[INPUTSIZE * 2]; |
| inStart.copyTo(arrayInStart); |
| float[] arrayInStop = new float[INPUTSIZE * 2]; |
| inStop.copyTo(arrayInStop); |
| float[] arrayInAmount = new float[INPUTSIZE * 1]; |
| inAmount.copyTo(arrayInAmount); |
| 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. |
| ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); |
| args.inStart = arrayInStart[i * 2 + j]; |
| args.inStop = arrayInStop[i * 2 + j]; |
| args.inAmount = arrayInAmount[i]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeMix(args); |
| int ulf = relaxed ? args.ulfRelaxed : args.ulf; |
| // Figure out what the outputs should have been. |
| boolean valid = true; |
| int neededUlf = 0; |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 2 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append(String.format("Input inStart: %x %.16f", Float.floatToRawIntBits(args.inStart), args.inStart)); |
| message.append("\n"); |
| message.append(String.format("Input inStop: %x %.16f", Float.floatToRawIntBits(args.inStop), args.inStop)); |
| message.append("\n"); |
| message.append(String.format("Input inAmount: %x %.16f", Float.floatToRawIntBits(args.inAmount), args.inAmount)); |
| message.append("\n"); |
| message.append(String.format("Expected output out: %x %.16f", Float.floatToRawIntBits(args.out), args.out)); |
| message.append("\n"); |
| message.append(String.format("Actual output out: %x %.16f", Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j])); |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 2 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| message.append(String.format(" FAILED, ulf needed %d, specified %d", neededUlf, ulf)); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkMixFloat2Float2FloatFloat2" + (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkMixFloat3Float3FloatFloat3() { |
| Allocation inStart = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xcdef317fe658f133L); |
| Allocation inStop = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xcdef317fe658f133L); |
| Allocation inAmount = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xcdef317fe658f133L); |
| try { |
| Allocation out = Allocation.createSized(mRS, GetElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); |
| script.set_gAllocInStop(inStop); |
| script.set_gAllocInAmount(inAmount); |
| script.forEach_testMixFloat3Float3FloatFloat3(inStart, out); |
| verifyResultsMixFloat3Float3FloatFloat3(inStart, inStop, inAmount, 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_gAllocInAmount(inAmount); |
| scriptRelaxed.forEach_testMixFloat3Float3FloatFloat3(inStart, out); |
| verifyResultsMixFloat3Float3FloatFloat3(inStart, inStop, inAmount, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat3Float3FloatFloat3: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsMixFloat3Float3FloatFloat3(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) { |
| float[] arrayInStart = new float[INPUTSIZE * 4]; |
| inStart.copyTo(arrayInStart); |
| float[] arrayInStop = new float[INPUTSIZE * 4]; |
| inStop.copyTo(arrayInStop); |
| float[] arrayInAmount = new float[INPUTSIZE * 1]; |
| inAmount.copyTo(arrayInAmount); |
| 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. |
| ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); |
| args.inStart = arrayInStart[i * 4 + j]; |
| args.inStop = arrayInStop[i * 4 + j]; |
| args.inAmount = arrayInAmount[i]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeMix(args); |
| int ulf = relaxed ? args.ulfRelaxed : args.ulf; |
| // Figure out what the outputs should have been. |
| boolean valid = true; |
| int neededUlf = 0; |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 4 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append(String.format("Input inStart: %x %.16f", Float.floatToRawIntBits(args.inStart), args.inStart)); |
| message.append("\n"); |
| message.append(String.format("Input inStop: %x %.16f", Float.floatToRawIntBits(args.inStop), args.inStop)); |
| message.append("\n"); |
| message.append(String.format("Input inAmount: %x %.16f", Float.floatToRawIntBits(args.inAmount), args.inAmount)); |
| message.append("\n"); |
| message.append(String.format("Expected output out: %x %.16f", Float.floatToRawIntBits(args.out), args.out)); |
| message.append("\n"); |
| message.append(String.format("Actual output out: %x %.16f", Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 4 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| message.append(String.format(" FAILED, ulf needed %d, specified %d", neededUlf, ulf)); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkMixFloat3Float3FloatFloat3" + (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkMixFloat4Float4FloatFloat4() { |
| Allocation inStart = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x975d24b87467d500L); |
| Allocation inStop = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x975d24b87467d500L); |
| Allocation inAmount = CreateRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x975d24b87467d500L); |
| try { |
| Allocation out = Allocation.createSized(mRS, GetElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); |
| script.set_gAllocInStop(inStop); |
| script.set_gAllocInAmount(inAmount); |
| script.forEach_testMixFloat4Float4FloatFloat4(inStart, out); |
| verifyResultsMixFloat4Float4FloatFloat4(inStart, inStop, inAmount, 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_gAllocInAmount(inAmount); |
| scriptRelaxed.forEach_testMixFloat4Float4FloatFloat4(inStart, out); |
| verifyResultsMixFloat4Float4FloatFloat4(inStart, inStop, inAmount, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testMixFloat4Float4FloatFloat4: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsMixFloat4Float4FloatFloat4(Allocation inStart, Allocation inStop, Allocation inAmount, Allocation out, boolean relaxed) { |
| float[] arrayInStart = new float[INPUTSIZE * 4]; |
| inStart.copyTo(arrayInStart); |
| float[] arrayInStop = new float[INPUTSIZE * 4]; |
| inStop.copyTo(arrayInStop); |
| float[] arrayInAmount = new float[INPUTSIZE * 1]; |
| inAmount.copyTo(arrayInAmount); |
| 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. |
| ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); |
| args.inStart = arrayInStart[i * 4 + j]; |
| args.inStop = arrayInStop[i * 4 + j]; |
| args.inAmount = arrayInAmount[i]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeMix(args); |
| int ulf = relaxed ? args.ulfRelaxed : args.ulf; |
| // Figure out what the outputs should have been. |
| boolean valid = true; |
| int neededUlf = 0; |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 4 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append(String.format("Input inStart: %x %.16f", Float.floatToRawIntBits(args.inStart), args.inStart)); |
| message.append("\n"); |
| message.append(String.format("Input inStop: %x %.16f", Float.floatToRawIntBits(args.inStop), args.inStop)); |
| message.append("\n"); |
| message.append(String.format("Input inAmount: %x %.16f", Float.floatToRawIntBits(args.inAmount), args.inAmount)); |
| message.append("\n"); |
| message.append(String.format("Expected output out: %x %.16f", Float.floatToRawIntBits(args.out), args.out)); |
| message.append("\n"); |
| message.append(String.format("Actual output out: %x %.16f", Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); |
| neededUlf = (int) (Math.abs(args.out - arrayOut[i * 4 + j]) / Math.ulp(args.out) + 0.5); |
| if (neededUlf > ulf) { |
| message.append(String.format(" FAILED, ulf needed %d, specified %d", neededUlf, ulf)); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkMixFloat4Float4FloatFloat4" + (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| public void testMix() { |
| checkMixFloatFloatFloatFloat(); |
| checkMixFloat2Float2Float2Float2(); |
| checkMixFloat3Float3Float3Float3(); |
| checkMixFloat4Float4Float4Float4(); |
| checkMixFloat2Float2FloatFloat2(); |
| checkMixFloat3Float3FloatFloat3(); |
| checkMixFloat4Float4FloatFloat4(); |
| } |
| } |