1 /* 2 * Copyright (C) 2016 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/generate.sh. 18 19 package android.renderscript.cts; 20 21 import android.renderscript.Allocation; 22 import android.renderscript.RSRuntimeException; 23 import android.renderscript.Element; 24 import android.renderscript.cts.Target; 25 26 import java.util.Arrays; 27 28 public class TestAtan2 extends RSBaseCompute { 29 30 private ScriptC_TestAtan2 script; 31 private ScriptC_TestAtan2Relaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestAtan2(mRS); 37 scriptRelaxed = new ScriptC_TestAtan2Relaxed(mRS); 38 } 39 40 public class ArgumentsFloatFloatFloat { 41 public float inNumerator; 42 public float inDenominator; 43 public Target.Floaty out; 44 } 45 checkAtan2FloatFloatFloat()46 private void checkAtan2FloatFloatFloat() { 47 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xe261d332l, false); 48 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x7bd90d5bl, false); 49 try { 50 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 51 script.set_gAllocInDenominator(inDenominator); 52 script.forEach_testAtan2FloatFloatFloat(inNumerator, out); 53 verifyResultsAtan2FloatFloatFloat(inNumerator, inDenominator, out, false); 54 } catch (Exception e) { 55 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2FloatFloatFloat: " + e.toString()); 56 } 57 try { 58 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 59 scriptRelaxed.set_gAllocInDenominator(inDenominator); 60 scriptRelaxed.forEach_testAtan2FloatFloatFloat(inNumerator, out); 61 verifyResultsAtan2FloatFloatFloat(inNumerator, inDenominator, out, true); 62 } catch (Exception e) { 63 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2FloatFloatFloat: " + e.toString()); 64 } 65 } 66 verifyResultsAtan2FloatFloatFloat(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed)67 private void verifyResultsAtan2FloatFloatFloat(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) { 68 float[] arrayInNumerator = new float[INPUTSIZE * 1]; 69 Arrays.fill(arrayInNumerator, (float) 42); 70 inNumerator.copyTo(arrayInNumerator); 71 float[] arrayInDenominator = new float[INPUTSIZE * 1]; 72 Arrays.fill(arrayInDenominator, (float) 42); 73 inDenominator.copyTo(arrayInDenominator); 74 float[] arrayOut = new float[INPUTSIZE * 1]; 75 Arrays.fill(arrayOut, (float) 42); 76 out.copyTo(arrayOut); 77 StringBuilder message = new StringBuilder(); 78 boolean errorFound = false; 79 for (int i = 0; i < INPUTSIZE; i++) { 80 for (int j = 0; j < 1 ; j++) { 81 // Extract the inputs. 82 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 83 args.inNumerator = arrayInNumerator[i]; 84 args.inDenominator = arrayInDenominator[i]; 85 // Figure out what the outputs should have been. 86 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 87 CoreMathVerifier.computeAtan2(args, target); 88 // Validate the outputs. 89 boolean valid = true; 90 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 91 valid = false; 92 } 93 if (!valid) { 94 if (!errorFound) { 95 errorFound = true; 96 message.append("Input inNumerator: "); 97 appendVariableToMessage(message, args.inNumerator); 98 message.append("\n"); 99 message.append("Input inDenominator: "); 100 appendVariableToMessage(message, args.inDenominator); 101 message.append("\n"); 102 message.append("Expected output out: "); 103 appendVariableToMessage(message, args.out); 104 message.append("\n"); 105 message.append("Actual output out: "); 106 appendVariableToMessage(message, arrayOut[i * 1 + j]); 107 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 108 message.append(" FAIL"); 109 } 110 message.append("\n"); 111 message.append("Errors at"); 112 } 113 message.append(" ["); 114 message.append(Integer.toString(i)); 115 message.append(", "); 116 message.append(Integer.toString(j)); 117 message.append("]"); 118 } 119 } 120 } 121 assertFalse("Incorrect output for checkAtan2FloatFloatFloat" + 122 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 123 } 124 checkAtan2Float2Float2Float2()125 private void checkAtan2Float2Float2Float2() { 126 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xefb30700l, false); 127 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xab583839l, false); 128 try { 129 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 130 script.set_gAllocInDenominator(inDenominator); 131 script.forEach_testAtan2Float2Float2Float2(inNumerator, out); 132 verifyResultsAtan2Float2Float2Float2(inNumerator, inDenominator, out, false); 133 } catch (Exception e) { 134 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Float2Float2Float2: " + e.toString()); 135 } 136 try { 137 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 138 scriptRelaxed.set_gAllocInDenominator(inDenominator); 139 scriptRelaxed.forEach_testAtan2Float2Float2Float2(inNumerator, out); 140 verifyResultsAtan2Float2Float2Float2(inNumerator, inDenominator, out, true); 141 } catch (Exception e) { 142 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Float2Float2Float2: " + e.toString()); 143 } 144 } 145 verifyResultsAtan2Float2Float2Float2(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed)146 private void verifyResultsAtan2Float2Float2Float2(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) { 147 float[] arrayInNumerator = new float[INPUTSIZE * 2]; 148 Arrays.fill(arrayInNumerator, (float) 42); 149 inNumerator.copyTo(arrayInNumerator); 150 float[] arrayInDenominator = new float[INPUTSIZE * 2]; 151 Arrays.fill(arrayInDenominator, (float) 42); 152 inDenominator.copyTo(arrayInDenominator); 153 float[] arrayOut = new float[INPUTSIZE * 2]; 154 Arrays.fill(arrayOut, (float) 42); 155 out.copyTo(arrayOut); 156 StringBuilder message = new StringBuilder(); 157 boolean errorFound = false; 158 for (int i = 0; i < INPUTSIZE; i++) { 159 for (int j = 0; j < 2 ; j++) { 160 // Extract the inputs. 161 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 162 args.inNumerator = arrayInNumerator[i * 2 + j]; 163 args.inDenominator = arrayInDenominator[i * 2 + j]; 164 // Figure out what the outputs should have been. 165 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 166 CoreMathVerifier.computeAtan2(args, target); 167 // Validate the outputs. 168 boolean valid = true; 169 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 170 valid = false; 171 } 172 if (!valid) { 173 if (!errorFound) { 174 errorFound = true; 175 message.append("Input inNumerator: "); 176 appendVariableToMessage(message, args.inNumerator); 177 message.append("\n"); 178 message.append("Input inDenominator: "); 179 appendVariableToMessage(message, args.inDenominator); 180 message.append("\n"); 181 message.append("Expected output out: "); 182 appendVariableToMessage(message, args.out); 183 message.append("\n"); 184 message.append("Actual output out: "); 185 appendVariableToMessage(message, arrayOut[i * 2 + j]); 186 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 187 message.append(" FAIL"); 188 } 189 message.append("\n"); 190 message.append("Errors at"); 191 } 192 message.append(" ["); 193 message.append(Integer.toString(i)); 194 message.append(", "); 195 message.append(Integer.toString(j)); 196 message.append("]"); 197 } 198 } 199 } 200 assertFalse("Incorrect output for checkAtan2Float2Float2Float2" + 201 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 202 } 203 checkAtan2Float3Float3Float3()204 private void checkAtan2Float3Float3Float3() { 205 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x927ef301l, false); 206 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x7e33cb72l, false); 207 try { 208 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 209 script.set_gAllocInDenominator(inDenominator); 210 script.forEach_testAtan2Float3Float3Float3(inNumerator, out); 211 verifyResultsAtan2Float3Float3Float3(inNumerator, inDenominator, out, false); 212 } catch (Exception e) { 213 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Float3Float3Float3: " + e.toString()); 214 } 215 try { 216 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 217 scriptRelaxed.set_gAllocInDenominator(inDenominator); 218 scriptRelaxed.forEach_testAtan2Float3Float3Float3(inNumerator, out); 219 verifyResultsAtan2Float3Float3Float3(inNumerator, inDenominator, out, true); 220 } catch (Exception e) { 221 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Float3Float3Float3: " + e.toString()); 222 } 223 } 224 verifyResultsAtan2Float3Float3Float3(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed)225 private void verifyResultsAtan2Float3Float3Float3(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) { 226 float[] arrayInNumerator = new float[INPUTSIZE * 4]; 227 Arrays.fill(arrayInNumerator, (float) 42); 228 inNumerator.copyTo(arrayInNumerator); 229 float[] arrayInDenominator = new float[INPUTSIZE * 4]; 230 Arrays.fill(arrayInDenominator, (float) 42); 231 inDenominator.copyTo(arrayInDenominator); 232 float[] arrayOut = new float[INPUTSIZE * 4]; 233 Arrays.fill(arrayOut, (float) 42); 234 out.copyTo(arrayOut); 235 StringBuilder message = new StringBuilder(); 236 boolean errorFound = false; 237 for (int i = 0; i < INPUTSIZE; i++) { 238 for (int j = 0; j < 3 ; j++) { 239 // Extract the inputs. 240 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 241 args.inNumerator = arrayInNumerator[i * 4 + j]; 242 args.inDenominator = arrayInDenominator[i * 4 + j]; 243 // Figure out what the outputs should have been. 244 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 245 CoreMathVerifier.computeAtan2(args, target); 246 // Validate the outputs. 247 boolean valid = true; 248 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 249 valid = false; 250 } 251 if (!valid) { 252 if (!errorFound) { 253 errorFound = true; 254 message.append("Input inNumerator: "); 255 appendVariableToMessage(message, args.inNumerator); 256 message.append("\n"); 257 message.append("Input inDenominator: "); 258 appendVariableToMessage(message, args.inDenominator); 259 message.append("\n"); 260 message.append("Expected output out: "); 261 appendVariableToMessage(message, args.out); 262 message.append("\n"); 263 message.append("Actual output out: "); 264 appendVariableToMessage(message, arrayOut[i * 4 + j]); 265 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 266 message.append(" FAIL"); 267 } 268 message.append("\n"); 269 message.append("Errors at"); 270 } 271 message.append(" ["); 272 message.append(Integer.toString(i)); 273 message.append(", "); 274 message.append(Integer.toString(j)); 275 message.append("]"); 276 } 277 } 278 } 279 assertFalse("Incorrect output for checkAtan2Float3Float3Float3" + 280 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 281 } 282 checkAtan2Float4Float4Float4()283 private void checkAtan2Float4Float4Float4() { 284 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x354adf02l, false); 285 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x510f5eabl, false); 286 try { 287 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 288 script.set_gAllocInDenominator(inDenominator); 289 script.forEach_testAtan2Float4Float4Float4(inNumerator, out); 290 verifyResultsAtan2Float4Float4Float4(inNumerator, inDenominator, out, false); 291 } catch (Exception e) { 292 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Float4Float4Float4: " + e.toString()); 293 } 294 try { 295 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 296 scriptRelaxed.set_gAllocInDenominator(inDenominator); 297 scriptRelaxed.forEach_testAtan2Float4Float4Float4(inNumerator, out); 298 verifyResultsAtan2Float4Float4Float4(inNumerator, inDenominator, out, true); 299 } catch (Exception e) { 300 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Float4Float4Float4: " + e.toString()); 301 } 302 } 303 verifyResultsAtan2Float4Float4Float4(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed)304 private void verifyResultsAtan2Float4Float4Float4(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) { 305 float[] arrayInNumerator = new float[INPUTSIZE * 4]; 306 Arrays.fill(arrayInNumerator, (float) 42); 307 inNumerator.copyTo(arrayInNumerator); 308 float[] arrayInDenominator = new float[INPUTSIZE * 4]; 309 Arrays.fill(arrayInDenominator, (float) 42); 310 inDenominator.copyTo(arrayInDenominator); 311 float[] arrayOut = new float[INPUTSIZE * 4]; 312 Arrays.fill(arrayOut, (float) 42); 313 out.copyTo(arrayOut); 314 StringBuilder message = new StringBuilder(); 315 boolean errorFound = false; 316 for (int i = 0; i < INPUTSIZE; i++) { 317 for (int j = 0; j < 4 ; j++) { 318 // Extract the inputs. 319 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 320 args.inNumerator = arrayInNumerator[i * 4 + j]; 321 args.inDenominator = arrayInDenominator[i * 4 + j]; 322 // Figure out what the outputs should have been. 323 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 324 CoreMathVerifier.computeAtan2(args, target); 325 // Validate the outputs. 326 boolean valid = true; 327 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 328 valid = false; 329 } 330 if (!valid) { 331 if (!errorFound) { 332 errorFound = true; 333 message.append("Input inNumerator: "); 334 appendVariableToMessage(message, args.inNumerator); 335 message.append("\n"); 336 message.append("Input inDenominator: "); 337 appendVariableToMessage(message, args.inDenominator); 338 message.append("\n"); 339 message.append("Expected output out: "); 340 appendVariableToMessage(message, args.out); 341 message.append("\n"); 342 message.append("Actual output out: "); 343 appendVariableToMessage(message, arrayOut[i * 4 + j]); 344 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 345 message.append(" FAIL"); 346 } 347 message.append("\n"); 348 message.append("Errors at"); 349 } 350 message.append(" ["); 351 message.append(Integer.toString(i)); 352 message.append(", "); 353 message.append(Integer.toString(j)); 354 message.append("]"); 355 } 356 } 357 } 358 assertFalse("Incorrect output for checkAtan2Float4Float4Float4" + 359 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 360 } 361 362 public class ArgumentsHalfHalfHalf { 363 public short inNumerator; 364 public double inNumeratorDouble; 365 public short inDenominator; 366 public double inDenominatorDouble; 367 public Target.Floaty out; 368 } 369 checkAtan2HalfHalfHalf()370 private void checkAtan2HalfHalfHalf() { 371 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xa6793e31l, false); 372 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xc8fcd922l, false); 373 try { 374 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 375 script.set_gAllocInDenominator(inDenominator); 376 script.forEach_testAtan2HalfHalfHalf(inNumerator, out); 377 verifyResultsAtan2HalfHalfHalf(inNumerator, inDenominator, out, false); 378 } catch (Exception e) { 379 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2HalfHalfHalf: " + e.toString()); 380 } 381 try { 382 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 383 scriptRelaxed.set_gAllocInDenominator(inDenominator); 384 scriptRelaxed.forEach_testAtan2HalfHalfHalf(inNumerator, out); 385 verifyResultsAtan2HalfHalfHalf(inNumerator, inDenominator, out, true); 386 } catch (Exception e) { 387 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2HalfHalfHalf: " + e.toString()); 388 } 389 } 390 verifyResultsAtan2HalfHalfHalf(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed)391 private void verifyResultsAtan2HalfHalfHalf(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) { 392 short[] arrayInNumerator = new short[INPUTSIZE * 1]; 393 Arrays.fill(arrayInNumerator, (short) 42); 394 inNumerator.copyTo(arrayInNumerator); 395 short[] arrayInDenominator = new short[INPUTSIZE * 1]; 396 Arrays.fill(arrayInDenominator, (short) 42); 397 inDenominator.copyTo(arrayInDenominator); 398 short[] arrayOut = new short[INPUTSIZE * 1]; 399 Arrays.fill(arrayOut, (short) 42); 400 out.copyTo(arrayOut); 401 StringBuilder message = new StringBuilder(); 402 boolean errorFound = false; 403 for (int i = 0; i < INPUTSIZE; i++) { 404 for (int j = 0; j < 1 ; j++) { 405 // Extract the inputs. 406 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 407 args.inNumerator = arrayInNumerator[i]; 408 args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator); 409 args.inDenominator = arrayInDenominator[i]; 410 args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator); 411 // Figure out what the outputs should have been. 412 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 413 CoreMathVerifier.computeAtan2(args, target); 414 // Validate the outputs. 415 boolean valid = true; 416 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 417 valid = false; 418 } 419 if (!valid) { 420 if (!errorFound) { 421 errorFound = true; 422 message.append("Input inNumerator: "); 423 appendVariableToMessage(message, args.inNumerator); 424 message.append("\n"); 425 message.append("Input inDenominator: "); 426 appendVariableToMessage(message, args.inDenominator); 427 message.append("\n"); 428 message.append("Expected output out: "); 429 appendVariableToMessage(message, args.out); 430 message.append("\n"); 431 message.append("Actual output out: "); 432 appendVariableToMessage(message, arrayOut[i * 1 + j]); 433 message.append("\n"); 434 message.append("Actual output out (in double): "); 435 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j])); 436 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 437 message.append(" FAIL"); 438 } 439 message.append("\n"); 440 message.append("Errors at"); 441 } 442 message.append(" ["); 443 message.append(Integer.toString(i)); 444 message.append(", "); 445 message.append(Integer.toString(j)); 446 message.append("]"); 447 } 448 } 449 } 450 assertFalse("Incorrect output for checkAtan2HalfHalfHalf" + 451 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 452 } 453 checkAtan2Half2Half2Half2()454 private void checkAtan2Half2Half2Half2() { 455 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xec117907l, false); 456 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x717dccc8l, false); 457 try { 458 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 459 script.set_gAllocInDenominator(inDenominator); 460 script.forEach_testAtan2Half2Half2Half2(inNumerator, out); 461 verifyResultsAtan2Half2Half2Half2(inNumerator, inDenominator, out, false); 462 } catch (Exception e) { 463 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Half2Half2Half2: " + e.toString()); 464 } 465 try { 466 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 467 scriptRelaxed.set_gAllocInDenominator(inDenominator); 468 scriptRelaxed.forEach_testAtan2Half2Half2Half2(inNumerator, out); 469 verifyResultsAtan2Half2Half2Half2(inNumerator, inDenominator, out, true); 470 } catch (Exception e) { 471 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Half2Half2Half2: " + e.toString()); 472 } 473 } 474 verifyResultsAtan2Half2Half2Half2(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed)475 private void verifyResultsAtan2Half2Half2Half2(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) { 476 short[] arrayInNumerator = new short[INPUTSIZE * 2]; 477 Arrays.fill(arrayInNumerator, (short) 42); 478 inNumerator.copyTo(arrayInNumerator); 479 short[] arrayInDenominator = new short[INPUTSIZE * 2]; 480 Arrays.fill(arrayInDenominator, (short) 42); 481 inDenominator.copyTo(arrayInDenominator); 482 short[] arrayOut = new short[INPUTSIZE * 2]; 483 Arrays.fill(arrayOut, (short) 42); 484 out.copyTo(arrayOut); 485 StringBuilder message = new StringBuilder(); 486 boolean errorFound = false; 487 for (int i = 0; i < INPUTSIZE; i++) { 488 for (int j = 0; j < 2 ; j++) { 489 // Extract the inputs. 490 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 491 args.inNumerator = arrayInNumerator[i * 2 + j]; 492 args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator); 493 args.inDenominator = arrayInDenominator[i * 2 + j]; 494 args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator); 495 // Figure out what the outputs should have been. 496 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 497 CoreMathVerifier.computeAtan2(args, target); 498 // Validate the outputs. 499 boolean valid = true; 500 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 501 valid = false; 502 } 503 if (!valid) { 504 if (!errorFound) { 505 errorFound = true; 506 message.append("Input inNumerator: "); 507 appendVariableToMessage(message, args.inNumerator); 508 message.append("\n"); 509 message.append("Input inDenominator: "); 510 appendVariableToMessage(message, args.inDenominator); 511 message.append("\n"); 512 message.append("Expected output out: "); 513 appendVariableToMessage(message, args.out); 514 message.append("\n"); 515 message.append("Actual output out: "); 516 appendVariableToMessage(message, arrayOut[i * 2 + j]); 517 message.append("\n"); 518 message.append("Actual output out (in double): "); 519 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j])); 520 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 521 message.append(" FAIL"); 522 } 523 message.append("\n"); 524 message.append("Errors at"); 525 } 526 message.append(" ["); 527 message.append(Integer.toString(i)); 528 message.append(", "); 529 message.append(Integer.toString(j)); 530 message.append("]"); 531 } 532 } 533 } 534 assertFalse("Incorrect output for checkAtan2Half2Half2Half2" + 535 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 536 } 537 checkAtan2Half3Half3Half3()538 private void checkAtan2Half3Half3Half3() { 539 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x3783a976l, false); 540 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x5d3d9e7fl, false); 541 try { 542 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 543 script.set_gAllocInDenominator(inDenominator); 544 script.forEach_testAtan2Half3Half3Half3(inNumerator, out); 545 verifyResultsAtan2Half3Half3Half3(inNumerator, inDenominator, out, false); 546 } catch (Exception e) { 547 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Half3Half3Half3: " + e.toString()); 548 } 549 try { 550 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 551 scriptRelaxed.set_gAllocInDenominator(inDenominator); 552 scriptRelaxed.forEach_testAtan2Half3Half3Half3(inNumerator, out); 553 verifyResultsAtan2Half3Half3Half3(inNumerator, inDenominator, out, true); 554 } catch (Exception e) { 555 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Half3Half3Half3: " + e.toString()); 556 } 557 } 558 verifyResultsAtan2Half3Half3Half3(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed)559 private void verifyResultsAtan2Half3Half3Half3(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) { 560 short[] arrayInNumerator = new short[INPUTSIZE * 4]; 561 Arrays.fill(arrayInNumerator, (short) 42); 562 inNumerator.copyTo(arrayInNumerator); 563 short[] arrayInDenominator = new short[INPUTSIZE * 4]; 564 Arrays.fill(arrayInDenominator, (short) 42); 565 inDenominator.copyTo(arrayInDenominator); 566 short[] arrayOut = new short[INPUTSIZE * 4]; 567 Arrays.fill(arrayOut, (short) 42); 568 out.copyTo(arrayOut); 569 StringBuilder message = new StringBuilder(); 570 boolean errorFound = false; 571 for (int i = 0; i < INPUTSIZE; i++) { 572 for (int j = 0; j < 3 ; j++) { 573 // Extract the inputs. 574 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 575 args.inNumerator = arrayInNumerator[i * 4 + j]; 576 args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator); 577 args.inDenominator = arrayInDenominator[i * 4 + j]; 578 args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator); 579 // Figure out what the outputs should have been. 580 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 581 CoreMathVerifier.computeAtan2(args, target); 582 // Validate the outputs. 583 boolean valid = true; 584 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 585 valid = false; 586 } 587 if (!valid) { 588 if (!errorFound) { 589 errorFound = true; 590 message.append("Input inNumerator: "); 591 appendVariableToMessage(message, args.inNumerator); 592 message.append("\n"); 593 message.append("Input inDenominator: "); 594 appendVariableToMessage(message, args.inDenominator); 595 message.append("\n"); 596 message.append("Expected output out: "); 597 appendVariableToMessage(message, args.out); 598 message.append("\n"); 599 message.append("Actual output out: "); 600 appendVariableToMessage(message, arrayOut[i * 4 + j]); 601 message.append("\n"); 602 message.append("Actual output out (in double): "); 603 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 604 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 605 message.append(" FAIL"); 606 } 607 message.append("\n"); 608 message.append("Errors at"); 609 } 610 message.append(" ["); 611 message.append(Integer.toString(i)); 612 message.append(", "); 613 message.append(Integer.toString(j)); 614 message.append("]"); 615 } 616 } 617 } 618 assertFalse("Incorrect output for checkAtan2Half3Half3Half3" + 619 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 620 } 621 checkAtan2Half4Half4Half4()622 private void checkAtan2Half4Half4Half4() { 623 Allocation inNumerator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x82f5d9e5l, false); 624 Allocation inDenominator = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x48fd7036l, false); 625 try { 626 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 627 script.set_gAllocInDenominator(inDenominator); 628 script.forEach_testAtan2Half4Half4Half4(inNumerator, out); 629 verifyResultsAtan2Half4Half4Half4(inNumerator, inDenominator, out, false); 630 } catch (Exception e) { 631 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Half4Half4Half4: " + e.toString()); 632 } 633 try { 634 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 635 scriptRelaxed.set_gAllocInDenominator(inDenominator); 636 scriptRelaxed.forEach_testAtan2Half4Half4Half4(inNumerator, out); 637 verifyResultsAtan2Half4Half4Half4(inNumerator, inDenominator, out, true); 638 } catch (Exception e) { 639 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testAtan2Half4Half4Half4: " + e.toString()); 640 } 641 } 642 verifyResultsAtan2Half4Half4Half4(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed)643 private void verifyResultsAtan2Half4Half4Half4(Allocation inNumerator, Allocation inDenominator, Allocation out, boolean relaxed) { 644 short[] arrayInNumerator = new short[INPUTSIZE * 4]; 645 Arrays.fill(arrayInNumerator, (short) 42); 646 inNumerator.copyTo(arrayInNumerator); 647 short[] arrayInDenominator = new short[INPUTSIZE * 4]; 648 Arrays.fill(arrayInDenominator, (short) 42); 649 inDenominator.copyTo(arrayInDenominator); 650 short[] arrayOut = new short[INPUTSIZE * 4]; 651 Arrays.fill(arrayOut, (short) 42); 652 out.copyTo(arrayOut); 653 StringBuilder message = new StringBuilder(); 654 boolean errorFound = false; 655 for (int i = 0; i < INPUTSIZE; i++) { 656 for (int j = 0; j < 4 ; j++) { 657 // Extract the inputs. 658 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 659 args.inNumerator = arrayInNumerator[i * 4 + j]; 660 args.inNumeratorDouble = Float16Utils.convertFloat16ToDouble(args.inNumerator); 661 args.inDenominator = arrayInDenominator[i * 4 + j]; 662 args.inDenominatorDouble = Float16Utils.convertFloat16ToDouble(args.inDenominator); 663 // Figure out what the outputs should have been. 664 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 665 CoreMathVerifier.computeAtan2(args, target); 666 // Validate the outputs. 667 boolean valid = true; 668 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 669 valid = false; 670 } 671 if (!valid) { 672 if (!errorFound) { 673 errorFound = true; 674 message.append("Input inNumerator: "); 675 appendVariableToMessage(message, args.inNumerator); 676 message.append("\n"); 677 message.append("Input inDenominator: "); 678 appendVariableToMessage(message, args.inDenominator); 679 message.append("\n"); 680 message.append("Expected output out: "); 681 appendVariableToMessage(message, args.out); 682 message.append("\n"); 683 message.append("Actual output out: "); 684 appendVariableToMessage(message, arrayOut[i * 4 + j]); 685 message.append("\n"); 686 message.append("Actual output out (in double): "); 687 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 688 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 689 message.append(" FAIL"); 690 } 691 message.append("\n"); 692 message.append("Errors at"); 693 } 694 message.append(" ["); 695 message.append(Integer.toString(i)); 696 message.append(", "); 697 message.append(Integer.toString(j)); 698 message.append("]"); 699 } 700 } 701 } 702 assertFalse("Incorrect output for checkAtan2Half4Half4Half4" + 703 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 704 } 705 testAtan2()706 public void testAtan2() { 707 checkAtan2FloatFloatFloat(); 708 checkAtan2Float2Float2Float2(); 709 checkAtan2Float3Float3Float3(); 710 checkAtan2Float4Float4Float4(); 711 checkAtan2HalfHalfHalf(); 712 checkAtan2Half2Half2Half2(); 713 checkAtan2Half3Half3Half3(); 714 checkAtan2Half4Half4Half4(); 715 } 716 } 717