1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // Don't edit this file! It is auto-generated by frameworks/rs/api/gen_runtime. 18 19 package android.renderscript.cts; 20 21 import android.renderscript.Allocation; 22 import android.renderscript.RSRuntimeException; 23 import android.renderscript.Element; 24 25 public class TestNativeHypot extends RSBaseCompute { 26 27 private ScriptC_TestNativeHypot script; 28 private ScriptC_TestNativeHypotRelaxed scriptRelaxed; 29 30 @Override 31 protected void setUp() throws Exception { 32 super.setUp(); 33 script = new ScriptC_TestNativeHypot(mRS); 34 scriptRelaxed = new ScriptC_TestNativeHypotRelaxed(mRS); 35 } 36 37 public class ArgumentsFloatFloatFloat { 38 public float inX; 39 public float inY; 40 public Target.Floaty out; 41 } 42 43 private void checkNativeHypotFloatFloatFloat() { 44 Allocation inX = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x3d61f129bdf66018l, false); 45 Allocation inY = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x3d61f129bdf66019l, false); 46 try { 47 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 48 script.set_gAllocInY(inY); 49 script.forEach_testNativeHypotFloatFloatFloat(inX, out); 50 verifyResultsNativeHypotFloatFloatFloat(inX, inY, out, false); 51 } catch (Exception e) { 52 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeHypotFloatFloatFloat: " + e.toString()); 53 } 54 try { 55 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 56 scriptRelaxed.set_gAllocInY(inY); 57 scriptRelaxed.forEach_testNativeHypotFloatFloatFloat(inX, out); 58 verifyResultsNativeHypotFloatFloatFloat(inX, inY, out, true); 59 } catch (Exception e) { 60 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeHypotFloatFloatFloat: " + e.toString()); 61 } 62 } 63 64 private void verifyResultsNativeHypotFloatFloatFloat(Allocation inX, Allocation inY, Allocation out, boolean relaxed) { 65 float[] arrayInX = new float[INPUTSIZE * 1]; 66 inX.copyTo(arrayInX); 67 float[] arrayInY = new float[INPUTSIZE * 1]; 68 inY.copyTo(arrayInY); 69 float[] arrayOut = new float[INPUTSIZE * 1]; 70 out.copyTo(arrayOut); 71 for (int i = 0; i < INPUTSIZE; i++) { 72 for (int j = 0; j < 1 ; j++) { 73 // Extract the inputs. 74 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 75 args.inX = arrayInX[i]; 76 args.inY = arrayInY[i]; 77 // Figure out what the outputs should have been. 78 Target target = new Target(relaxed); 79 CoreMathVerifier.computeNativeHypot(args, target); 80 // Validate the outputs. 81 boolean valid = true; 82 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 83 valid = false; 84 } 85 if (!valid) { 86 StringBuilder message = new StringBuilder(); 87 message.append("Input inX: "); 88 message.append(String.format("%14.8g {%8x} %15a", 89 args.inX, Float.floatToRawIntBits(args.inX), args.inX)); 90 message.append("\n"); 91 message.append("Input inY: "); 92 message.append(String.format("%14.8g {%8x} %15a", 93 args.inY, Float.floatToRawIntBits(args.inY), args.inY)); 94 message.append("\n"); 95 message.append("Expected output out: "); 96 message.append(args.out.toString()); 97 message.append("\n"); 98 message.append("Actual output out: "); 99 message.append(String.format("%14.8g {%8x} %15a", 100 arrayOut[i * 1 + j], Float.floatToRawIntBits(arrayOut[i * 1 + j]), arrayOut[i * 1 + j])); 101 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 102 message.append(" FAIL"); 103 } 104 message.append("\n"); 105 assertTrue("Incorrect output for checkNativeHypotFloatFloatFloat" + 106 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 107 } 108 } 109 } 110 } 111 112 private void checkNativeHypotFloat2Float2Float2() { 113 Allocation inX = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x92a8064760a50e64l, false); 114 Allocation inY = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x92a8064760a50e65l, false); 115 try { 116 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 117 script.set_gAllocInY(inY); 118 script.forEach_testNativeHypotFloat2Float2Float2(inX, out); 119 verifyResultsNativeHypotFloat2Float2Float2(inX, inY, out, false); 120 } catch (Exception e) { 121 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeHypotFloat2Float2Float2: " + e.toString()); 122 } 123 try { 124 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 125 scriptRelaxed.set_gAllocInY(inY); 126 scriptRelaxed.forEach_testNativeHypotFloat2Float2Float2(inX, out); 127 verifyResultsNativeHypotFloat2Float2Float2(inX, inY, out, true); 128 } catch (Exception e) { 129 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeHypotFloat2Float2Float2: " + e.toString()); 130 } 131 } 132 133 private void verifyResultsNativeHypotFloat2Float2Float2(Allocation inX, Allocation inY, Allocation out, boolean relaxed) { 134 float[] arrayInX = new float[INPUTSIZE * 2]; 135 inX.copyTo(arrayInX); 136 float[] arrayInY = new float[INPUTSIZE * 2]; 137 inY.copyTo(arrayInY); 138 float[] arrayOut = new float[INPUTSIZE * 2]; 139 out.copyTo(arrayOut); 140 for (int i = 0; i < INPUTSIZE; i++) { 141 for (int j = 0; j < 2 ; j++) { 142 // Extract the inputs. 143 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 144 args.inX = arrayInX[i * 2 + j]; 145 args.inY = arrayInY[i * 2 + j]; 146 // Figure out what the outputs should have been. 147 Target target = new Target(relaxed); 148 CoreMathVerifier.computeNativeHypot(args, target); 149 // Validate the outputs. 150 boolean valid = true; 151 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 152 valid = false; 153 } 154 if (!valid) { 155 StringBuilder message = new StringBuilder(); 156 message.append("Input inX: "); 157 message.append(String.format("%14.8g {%8x} %15a", 158 args.inX, Float.floatToRawIntBits(args.inX), args.inX)); 159 message.append("\n"); 160 message.append("Input inY: "); 161 message.append(String.format("%14.8g {%8x} %15a", 162 args.inY, Float.floatToRawIntBits(args.inY), args.inY)); 163 message.append("\n"); 164 message.append("Expected output out: "); 165 message.append(args.out.toString()); 166 message.append("\n"); 167 message.append("Actual output out: "); 168 message.append(String.format("%14.8g {%8x} %15a", 169 arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j])); 170 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 171 message.append(" FAIL"); 172 } 173 message.append("\n"); 174 assertTrue("Incorrect output for checkNativeHypotFloat2Float2Float2" + 175 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 176 } 177 } 178 } 179 } 180 181 private void checkNativeHypotFloat3Float3Float3() { 182 Allocation inX = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe70ce46762831005l, false); 183 Allocation inY = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xe70ce46762831006l, false); 184 try { 185 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 186 script.set_gAllocInY(inY); 187 script.forEach_testNativeHypotFloat3Float3Float3(inX, out); 188 verifyResultsNativeHypotFloat3Float3Float3(inX, inY, out, false); 189 } catch (Exception e) { 190 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeHypotFloat3Float3Float3: " + e.toString()); 191 } 192 try { 193 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 194 scriptRelaxed.set_gAllocInY(inY); 195 scriptRelaxed.forEach_testNativeHypotFloat3Float3Float3(inX, out); 196 verifyResultsNativeHypotFloat3Float3Float3(inX, inY, out, true); 197 } catch (Exception e) { 198 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeHypotFloat3Float3Float3: " + e.toString()); 199 } 200 } 201 202 private void verifyResultsNativeHypotFloat3Float3Float3(Allocation inX, Allocation inY, Allocation out, boolean relaxed) { 203 float[] arrayInX = new float[INPUTSIZE * 4]; 204 inX.copyTo(arrayInX); 205 float[] arrayInY = new float[INPUTSIZE * 4]; 206 inY.copyTo(arrayInY); 207 float[] arrayOut = new float[INPUTSIZE * 4]; 208 out.copyTo(arrayOut); 209 for (int i = 0; i < INPUTSIZE; i++) { 210 for (int j = 0; j < 3 ; j++) { 211 // Extract the inputs. 212 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 213 args.inX = arrayInX[i * 4 + j]; 214 args.inY = arrayInY[i * 4 + j]; 215 // Figure out what the outputs should have been. 216 Target target = new Target(relaxed); 217 CoreMathVerifier.computeNativeHypot(args, target); 218 // Validate the outputs. 219 boolean valid = true; 220 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 221 valid = false; 222 } 223 if (!valid) { 224 StringBuilder message = new StringBuilder(); 225 message.append("Input inX: "); 226 message.append(String.format("%14.8g {%8x} %15a", 227 args.inX, Float.floatToRawIntBits(args.inX), args.inX)); 228 message.append("\n"); 229 message.append("Input inY: "); 230 message.append(String.format("%14.8g {%8x} %15a", 231 args.inY, Float.floatToRawIntBits(args.inY), args.inY)); 232 message.append("\n"); 233 message.append("Expected output out: "); 234 message.append(args.out.toString()); 235 message.append("\n"); 236 message.append("Actual output out: "); 237 message.append(String.format("%14.8g {%8x} %15a", 238 arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); 239 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 240 message.append(" FAIL"); 241 } 242 message.append("\n"); 243 assertTrue("Incorrect output for checkNativeHypotFloat3Float3Float3" + 244 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 245 } 246 } 247 } 248 } 249 250 private void checkNativeHypotFloat4Float4Float4() { 251 Allocation inX = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x3b71c287646111a6l, false); 252 Allocation inY = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x3b71c287646111a7l, false); 253 try { 254 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 255 script.set_gAllocInY(inY); 256 script.forEach_testNativeHypotFloat4Float4Float4(inX, out); 257 verifyResultsNativeHypotFloat4Float4Float4(inX, inY, out, false); 258 } catch (Exception e) { 259 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeHypotFloat4Float4Float4: " + e.toString()); 260 } 261 try { 262 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 263 scriptRelaxed.set_gAllocInY(inY); 264 scriptRelaxed.forEach_testNativeHypotFloat4Float4Float4(inX, out); 265 verifyResultsNativeHypotFloat4Float4Float4(inX, inY, out, true); 266 } catch (Exception e) { 267 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testNativeHypotFloat4Float4Float4: " + e.toString()); 268 } 269 } 270 271 private void verifyResultsNativeHypotFloat4Float4Float4(Allocation inX, Allocation inY, Allocation out, boolean relaxed) { 272 float[] arrayInX = new float[INPUTSIZE * 4]; 273 inX.copyTo(arrayInX); 274 float[] arrayInY = new float[INPUTSIZE * 4]; 275 inY.copyTo(arrayInY); 276 float[] arrayOut = new float[INPUTSIZE * 4]; 277 out.copyTo(arrayOut); 278 for (int i = 0; i < INPUTSIZE; i++) { 279 for (int j = 0; j < 4 ; j++) { 280 // Extract the inputs. 281 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 282 args.inX = arrayInX[i * 4 + j]; 283 args.inY = arrayInY[i * 4 + j]; 284 // Figure out what the outputs should have been. 285 Target target = new Target(relaxed); 286 CoreMathVerifier.computeNativeHypot(args, target); 287 // Validate the outputs. 288 boolean valid = true; 289 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 290 valid = false; 291 } 292 if (!valid) { 293 StringBuilder message = new StringBuilder(); 294 message.append("Input inX: "); 295 message.append(String.format("%14.8g {%8x} %15a", 296 args.inX, Float.floatToRawIntBits(args.inX), args.inX)); 297 message.append("\n"); 298 message.append("Input inY: "); 299 message.append(String.format("%14.8g {%8x} %15a", 300 args.inY, Float.floatToRawIntBits(args.inY), args.inY)); 301 message.append("\n"); 302 message.append("Expected output out: "); 303 message.append(args.out.toString()); 304 message.append("\n"); 305 message.append("Actual output out: "); 306 message.append(String.format("%14.8g {%8x} %15a", 307 arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); 308 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 309 message.append(" FAIL"); 310 } 311 message.append("\n"); 312 assertTrue("Incorrect output for checkNativeHypotFloat4Float4Float4" + 313 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 314 } 315 } 316 } 317 } 318 319 public void testNativeHypot() { 320 checkNativeHypotFloatFloatFloat(); 321 checkNativeHypotFloat2Float2Float2(); 322 checkNativeHypotFloat3Float3Float3(); 323 checkNativeHypotFloat4Float4Float4(); 324 } 325 } 326