| /* |
| * 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 TestAbs extends RSBaseCompute { |
| |
| private ScriptC_TestAbs script; |
| private ScriptC_TestAbsRelaxed scriptRelaxed; |
| |
| @Override |
| protected void setUp() throws Exception { |
| super.setUp(); |
| script = new ScriptC_TestAbs(mRS); |
| scriptRelaxed = new ScriptC_TestAbsRelaxed(mRS); |
| } |
| |
| public class ArgumentsCharUchar { |
| public byte inValue; |
| public byte out; |
| } |
| |
| private void checkAbsCharUchar() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0x4c0d03eb0d0c5a91l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE); |
| script.forEach_testAbsCharUchar(inValue, out); |
| verifyResultsAbsCharUchar(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsCharUchar: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsCharUchar(inValue, out); |
| verifyResultsAbsCharUchar(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsCharUchar: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsCharUchar(Allocation inValue, Allocation out, boolean relaxed) { |
| byte[] arrayInValue = new byte[INPUTSIZE * 1]; |
| inValue.copyTo(arrayInValue); |
| byte[] arrayOut = new byte[INPUTSIZE * 1]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 1 ; j++) { |
| // Extract the inputs. |
| ArgumentsCharUchar args = new ArgumentsCharUchar(); |
| args.inValue = arrayInValue[i]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 1 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 1 + j])); |
| if (args.out != arrayOut[i * 1 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsCharUchar" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkAbsChar2Uchar2() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 2, 0x901d551e7f67bb87l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE); |
| script.forEach_testAbsChar2Uchar2(inValue, out); |
| verifyResultsAbsChar2Uchar2(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar2Uchar2: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsChar2Uchar2(inValue, out); |
| verifyResultsAbsChar2Uchar2(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar2Uchar2: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsChar2Uchar2(Allocation inValue, Allocation out, boolean relaxed) { |
| byte[] arrayInValue = new byte[INPUTSIZE * 2]; |
| inValue.copyTo(arrayInValue); |
| byte[] arrayOut = new byte[INPUTSIZE * 2]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 2 ; j++) { |
| // Extract the inputs. |
| ArgumentsCharUchar args = new ArgumentsCharUchar(); |
| args.inValue = arrayInValue[i * 2 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 2 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 2 + j])); |
| if (args.out != arrayOut[i * 2 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsChar2Uchar2" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkAbsChar3Uchar3() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 3, 0xb5d1caa5c8a5e105l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE); |
| script.forEach_testAbsChar3Uchar3(inValue, out); |
| verifyResultsAbsChar3Uchar3(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar3Uchar3: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsChar3Uchar3(inValue, out); |
| verifyResultsAbsChar3Uchar3(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar3Uchar3: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsChar3Uchar3(Allocation inValue, Allocation out, boolean relaxed) { |
| byte[] arrayInValue = new byte[INPUTSIZE * 4]; |
| inValue.copyTo(arrayInValue); |
| byte[] arrayOut = new byte[INPUTSIZE * 4]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 3 ; j++) { |
| // Extract the inputs. |
| ArgumentsCharUchar args = new ArgumentsCharUchar(); |
| args.inValue = arrayInValue[i * 4 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 4 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 4 + j])); |
| if (args.out != arrayOut[i * 4 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsChar3Uchar3" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkAbsChar4Uchar4() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 4, 0xdb86402d11e40683l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE); |
| script.forEach_testAbsChar4Uchar4(inValue, out); |
| verifyResultsAbsChar4Uchar4(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar4Uchar4: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsChar4Uchar4(inValue, out); |
| verifyResultsAbsChar4Uchar4(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsChar4Uchar4: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsChar4Uchar4(Allocation inValue, Allocation out, boolean relaxed) { |
| byte[] arrayInValue = new byte[INPUTSIZE * 4]; |
| inValue.copyTo(arrayInValue); |
| byte[] arrayOut = new byte[INPUTSIZE * 4]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 4 ; j++) { |
| // Extract the inputs. |
| ArgumentsCharUchar args = new ArgumentsCharUchar(); |
| args.inValue = arrayInValue[i * 4 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 4 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 4 + j])); |
| if (args.out != arrayOut[i * 4 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsChar4Uchar4" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| public class ArgumentsShortUshort { |
| public short inValue; |
| public short out; |
| } |
| |
| private void checkAbsShortUshort() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0xaead1a96b6ea02a7l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE); |
| script.forEach_testAbsShortUshort(inValue, out); |
| verifyResultsAbsShortUshort(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShortUshort: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsShortUshort(inValue, out); |
| verifyResultsAbsShortUshort(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShortUshort: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsShortUshort(Allocation inValue, Allocation out, boolean relaxed) { |
| short[] arrayInValue = new short[INPUTSIZE * 1]; |
| inValue.copyTo(arrayInValue); |
| short[] arrayOut = new short[INPUTSIZE * 1]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 1 ; j++) { |
| // Extract the inputs. |
| ArgumentsShortUshort args = new ArgumentsShortUshort(); |
| args.inValue = arrayInValue[i]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 1 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 1 + j])); |
| if (args.out != arrayOut[i * 1 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsShortUshort" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkAbsShort2Ushort2() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x41a1894ff6b0da9l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE); |
| script.forEach_testAbsShort2Ushort2(inValue, out); |
| verifyResultsAbsShort2Ushort2(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort2Ushort2: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsShort2Ushort2(inValue, out); |
| verifyResultsAbsShort2Ushort2(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort2Ushort2: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsShort2Ushort2(Allocation inValue, Allocation out, boolean relaxed) { |
| short[] arrayInValue = new short[INPUTSIZE * 2]; |
| inValue.copyTo(arrayInValue); |
| short[] arrayOut = new short[INPUTSIZE * 2]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 2 ; j++) { |
| // Extract the inputs. |
| ArgumentsShortUshort args = new ArgumentsShortUshort(); |
| args.inValue = arrayInValue[i * 2 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 2 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 2 + j])); |
| if (args.out != arrayOut[i * 2 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsShort2Ushort2" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkAbsShort3Ushort3() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x5969cbec377ba515l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE); |
| script.forEach_testAbsShort3Ushort3(inValue, out); |
| verifyResultsAbsShort3Ushort3(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort3Ushort3: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsShort3Ushort3(inValue, out); |
| verifyResultsAbsShort3Ushort3(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort3Ushort3: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsShort3Ushort3(Allocation inValue, Allocation out, boolean relaxed) { |
| short[] arrayInValue = new short[INPUTSIZE * 4]; |
| inValue.copyTo(arrayInValue); |
| short[] arrayOut = new short[INPUTSIZE * 4]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 3 ; j++) { |
| // Extract the inputs. |
| ArgumentsShortUshort args = new ArgumentsShortUshort(); |
| args.inValue = arrayInValue[i * 4 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 4 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 4 + j])); |
| if (args.out != arrayOut[i * 4 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsShort3Ushort3" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkAbsShort4Ushort4() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 4, 0xaeb97f436f8c3c81l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE); |
| script.forEach_testAbsShort4Ushort4(inValue, out); |
| verifyResultsAbsShort4Ushort4(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort4Ushort4: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsShort4Ushort4(inValue, out); |
| verifyResultsAbsShort4Ushort4(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsShort4Ushort4: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsShort4Ushort4(Allocation inValue, Allocation out, boolean relaxed) { |
| short[] arrayInValue = new short[INPUTSIZE * 4]; |
| inValue.copyTo(arrayInValue); |
| short[] arrayOut = new short[INPUTSIZE * 4]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 4 ; j++) { |
| // Extract the inputs. |
| ArgumentsShortUshort args = new ArgumentsShortUshort(); |
| args.inValue = arrayInValue[i * 4 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 4 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 4 + j])); |
| if (args.out != arrayOut[i * 4 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsShort4Ushort4" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| public class ArgumentsIntUint { |
| public int inValue; |
| public int out; |
| } |
| |
| private void checkAbsIntUint() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0xcda40fd4fa1abbd1l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE); |
| script.forEach_testAbsIntUint(inValue, out); |
| verifyResultsAbsIntUint(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsIntUint: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsIntUint(inValue, out); |
| verifyResultsAbsIntUint(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsIntUint: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsIntUint(Allocation inValue, Allocation out, boolean relaxed) { |
| int[] arrayInValue = new int[INPUTSIZE * 1]; |
| inValue.copyTo(arrayInValue); |
| int[] arrayOut = new int[INPUTSIZE * 1]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 1 ; j++) { |
| // Extract the inputs. |
| ArgumentsIntUint args = new ArgumentsIntUint(); |
| args.inValue = arrayInValue[i]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 1 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 1 + j])); |
| if (args.out != arrayOut[i * 1 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsIntUint" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkAbsInt2Uint2() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x71326739aabbb4a5l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE); |
| script.forEach_testAbsInt2Uint2(inValue, out); |
| verifyResultsAbsInt2Uint2(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt2Uint2: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsInt2Uint2(inValue, out); |
| verifyResultsAbsInt2Uint2(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt2Uint2: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsInt2Uint2(Allocation inValue, Allocation out, boolean relaxed) { |
| int[] arrayInValue = new int[INPUTSIZE * 2]; |
| inValue.copyTo(arrayInValue); |
| int[] arrayOut = new int[INPUTSIZE * 2]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 2 ; j++) { |
| // Extract the inputs. |
| ArgumentsIntUint args = new ArgumentsIntUint(); |
| args.inValue = arrayInValue[i * 2 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 2 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 2 + j])); |
| if (args.out != arrayOut[i * 2 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsInt2Uint2" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkAbsInt3Uint3() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x9bbf87f7a6fae959l, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE); |
| script.forEach_testAbsInt3Uint3(inValue, out); |
| verifyResultsAbsInt3Uint3(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt3Uint3: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsInt3Uint3(inValue, out); |
| verifyResultsAbsInt3Uint3(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt3Uint3: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsInt3Uint3(Allocation inValue, Allocation out, boolean relaxed) { |
| int[] arrayInValue = new int[INPUTSIZE * 4]; |
| inValue.copyTo(arrayInValue); |
| int[] arrayOut = new int[INPUTSIZE * 4]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 3 ; j++) { |
| // Extract the inputs. |
| ArgumentsIntUint args = new ArgumentsIntUint(); |
| args.inValue = arrayInValue[i * 4 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 4 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 4 + j])); |
| if (args.out != arrayOut[i * 4 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsInt3Uint3" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| private void checkAbsInt4Uint4() { |
| Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 4, 0xc64ca8b5a33a1e0dl, false); |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE); |
| script.forEach_testAbsInt4Uint4(inValue, out); |
| verifyResultsAbsInt4Uint4(inValue, out, false); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt4Uint4: " + e.toString()); |
| } |
| try { |
| Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE); |
| scriptRelaxed.forEach_testAbsInt4Uint4(inValue, out); |
| verifyResultsAbsInt4Uint4(inValue, out, true); |
| } catch (Exception e) { |
| throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAbsInt4Uint4: " + e.toString()); |
| } |
| } |
| |
| private void verifyResultsAbsInt4Uint4(Allocation inValue, Allocation out, boolean relaxed) { |
| int[] arrayInValue = new int[INPUTSIZE * 4]; |
| inValue.copyTo(arrayInValue); |
| int[] arrayOut = new int[INPUTSIZE * 4]; |
| out.copyTo(arrayOut); |
| for (int i = 0; i < INPUTSIZE; i++) { |
| for (int j = 0; j < 4 ; j++) { |
| // Extract the inputs. |
| ArgumentsIntUint args = new ArgumentsIntUint(); |
| args.inValue = arrayInValue[i * 4 + j]; |
| // Figure out what the outputs should have been. |
| CoreMathVerifier.computeAbs(args); |
| // Validate the outputs. |
| boolean valid = true; |
| if (args.out != arrayOut[i * 4 + j]) { |
| valid = false; |
| } |
| if (!valid) { |
| StringBuilder message = new StringBuilder(); |
| message.append("Input inValue: "); |
| message.append(String.format("%d", args.inValue)); |
| message.append("\n"); |
| message.append("Expected output out: "); |
| message.append(String.format("0x%x", args.out)); |
| message.append("\n"); |
| message.append("Actual output out: "); |
| message.append(String.format("0x%x", arrayOut[i * 4 + j])); |
| if (args.out != arrayOut[i * 4 + j]) { |
| message.append(" FAIL"); |
| } |
| message.append("\n"); |
| assertTrue("Incorrect output for checkAbsInt4Uint4" + |
| (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); |
| } |
| } |
| } |
| } |
| |
| public void testAbs() { |
| checkAbsCharUchar(); |
| checkAbsChar2Uchar2(); |
| checkAbsChar3Uchar3(); |
| checkAbsChar4Uchar4(); |
| checkAbsShortUshort(); |
| checkAbsShort2Ushort2(); |
| checkAbsShort3Ushort3(); |
| checkAbsShort4Ushort4(); |
| checkAbsIntUint(); |
| checkAbsInt2Uint2(); |
| checkAbsInt3Uint3(); |
| checkAbsInt4Uint4(); |
| } |
| } |