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 TestFract extends RSBaseCompute { 29 30 private ScriptC_TestFract script; 31 private ScriptC_TestFractRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestFract(mRS); 37 scriptRelaxed = new ScriptC_TestFractRelaxed(mRS); 38 } 39 40 public class ArgumentsFloatFloatFloat { 41 public float inV; 42 public Target.Floaty outFloor; 43 public Target.Floaty out; 44 } 45 checkFractFloatFloatFloat()46 private void checkFractFloatFloatFloat() { 47 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x3c675d27l, false); 48 try { 49 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 50 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 51 script.set_gAllocOutFloor(outFloor); 52 script.forEach_testFractFloatFloatFloat(inV, out); 53 verifyResultsFractFloatFloatFloat(inV, outFloor, out, false); 54 } catch (Exception e) { 55 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloatFloatFloat: " + e.toString()); 56 } 57 try { 58 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 59 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 60 scriptRelaxed.set_gAllocOutFloor(outFloor); 61 scriptRelaxed.forEach_testFractFloatFloatFloat(inV, out); 62 verifyResultsFractFloatFloatFloat(inV, outFloor, out, true); 63 } catch (Exception e) { 64 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloatFloatFloat: " + e.toString()); 65 } 66 } 67 verifyResultsFractFloatFloatFloat(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed)68 private void verifyResultsFractFloatFloatFloat(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 69 float[] arrayInV = new float[INPUTSIZE * 1]; 70 Arrays.fill(arrayInV, (float) 42); 71 inV.copyTo(arrayInV); 72 float[] arrayOutFloor = new float[INPUTSIZE * 1]; 73 Arrays.fill(arrayOutFloor, (float) 42); 74 outFloor.copyTo(arrayOutFloor); 75 float[] arrayOut = new float[INPUTSIZE * 1]; 76 Arrays.fill(arrayOut, (float) 42); 77 out.copyTo(arrayOut); 78 StringBuilder message = new StringBuilder(); 79 boolean errorFound = false; 80 for (int i = 0; i < INPUTSIZE; i++) { 81 for (int j = 0; j < 1 ; j++) { 82 // Extract the inputs. 83 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 84 args.inV = arrayInV[i]; 85 // Figure out what the outputs should have been. 86 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 87 CoreMathVerifier.computeFract(args, target); 88 // Validate the outputs. 89 boolean valid = true; 90 if (!args.outFloor.couldBe(arrayOutFloor[i * 1 + j])) { 91 valid = false; 92 } 93 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 94 valid = false; 95 } 96 if (!valid) { 97 if (!errorFound) { 98 errorFound = true; 99 message.append("Input inV: "); 100 appendVariableToMessage(message, args.inV); 101 message.append("\n"); 102 message.append("Expected output outFloor: "); 103 appendVariableToMessage(message, args.outFloor); 104 message.append("\n"); 105 message.append("Actual output outFloor: "); 106 appendVariableToMessage(message, arrayOutFloor[i * 1 + j]); 107 if (!args.outFloor.couldBe(arrayOutFloor[i * 1 + j])) { 108 message.append(" FAIL"); 109 } 110 message.append("\n"); 111 message.append("Expected output out: "); 112 appendVariableToMessage(message, args.out); 113 message.append("\n"); 114 message.append("Actual output out: "); 115 appendVariableToMessage(message, arrayOut[i * 1 + j]); 116 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 117 message.append(" FAIL"); 118 } 119 message.append("\n"); 120 message.append("Errors at"); 121 } 122 message.append(" ["); 123 message.append(Integer.toString(i)); 124 message.append(", "); 125 message.append(Integer.toString(j)); 126 message.append("]"); 127 } 128 } 129 } 130 assertFalse("Incorrect output for checkFractFloatFloatFloat" + 131 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 132 } 133 checkFractFloat2Float2Float2()134 private void checkFractFloat2Float2Float2() { 135 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xcdf8f525l, false); 136 try { 137 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 138 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 139 script.set_gAllocOutFloor(outFloor); 140 script.forEach_testFractFloat2Float2Float2(inV, out); 141 verifyResultsFractFloat2Float2Float2(inV, outFloor, out, false); 142 } catch (Exception e) { 143 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat2Float2Float2: " + e.toString()); 144 } 145 try { 146 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 147 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 148 scriptRelaxed.set_gAllocOutFloor(outFloor); 149 scriptRelaxed.forEach_testFractFloat2Float2Float2(inV, out); 150 verifyResultsFractFloat2Float2Float2(inV, outFloor, out, true); 151 } catch (Exception e) { 152 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat2Float2Float2: " + e.toString()); 153 } 154 } 155 verifyResultsFractFloat2Float2Float2(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed)156 private void verifyResultsFractFloat2Float2Float2(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 157 float[] arrayInV = new float[INPUTSIZE * 2]; 158 Arrays.fill(arrayInV, (float) 42); 159 inV.copyTo(arrayInV); 160 float[] arrayOutFloor = new float[INPUTSIZE * 2]; 161 Arrays.fill(arrayOutFloor, (float) 42); 162 outFloor.copyTo(arrayOutFloor); 163 float[] arrayOut = new float[INPUTSIZE * 2]; 164 Arrays.fill(arrayOut, (float) 42); 165 out.copyTo(arrayOut); 166 StringBuilder message = new StringBuilder(); 167 boolean errorFound = false; 168 for (int i = 0; i < INPUTSIZE; i++) { 169 for (int j = 0; j < 2 ; j++) { 170 // Extract the inputs. 171 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 172 args.inV = arrayInV[i * 2 + j]; 173 // Figure out what the outputs should have been. 174 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 175 CoreMathVerifier.computeFract(args, target); 176 // Validate the outputs. 177 boolean valid = true; 178 if (!args.outFloor.couldBe(arrayOutFloor[i * 2 + j])) { 179 valid = false; 180 } 181 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 182 valid = false; 183 } 184 if (!valid) { 185 if (!errorFound) { 186 errorFound = true; 187 message.append("Input inV: "); 188 appendVariableToMessage(message, args.inV); 189 message.append("\n"); 190 message.append("Expected output outFloor: "); 191 appendVariableToMessage(message, args.outFloor); 192 message.append("\n"); 193 message.append("Actual output outFloor: "); 194 appendVariableToMessage(message, arrayOutFloor[i * 2 + j]); 195 if (!args.outFloor.couldBe(arrayOutFloor[i * 2 + j])) { 196 message.append(" FAIL"); 197 } 198 message.append("\n"); 199 message.append("Expected output out: "); 200 appendVariableToMessage(message, args.out); 201 message.append("\n"); 202 message.append("Actual output out: "); 203 appendVariableToMessage(message, arrayOut[i * 2 + j]); 204 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 205 message.append(" FAIL"); 206 } 207 message.append("\n"); 208 message.append("Errors at"); 209 } 210 message.append(" ["); 211 message.append(Integer.toString(i)); 212 message.append(", "); 213 message.append(Integer.toString(j)); 214 message.append("]"); 215 } 216 } 217 } 218 assertFalse("Incorrect output for checkFractFloat2Float2Float2" + 219 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 220 } 221 checkFractFloat3Float3Float3()222 private void checkFractFloat3Float3Float3() { 223 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xcfd6f6c6l, false); 224 try { 225 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 226 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 227 script.set_gAllocOutFloor(outFloor); 228 script.forEach_testFractFloat3Float3Float3(inV, out); 229 verifyResultsFractFloat3Float3Float3(inV, outFloor, out, false); 230 } catch (Exception e) { 231 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat3Float3Float3: " + e.toString()); 232 } 233 try { 234 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 235 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 236 scriptRelaxed.set_gAllocOutFloor(outFloor); 237 scriptRelaxed.forEach_testFractFloat3Float3Float3(inV, out); 238 verifyResultsFractFloat3Float3Float3(inV, outFloor, out, true); 239 } catch (Exception e) { 240 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat3Float3Float3: " + e.toString()); 241 } 242 } 243 verifyResultsFractFloat3Float3Float3(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed)244 private void verifyResultsFractFloat3Float3Float3(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 245 float[] arrayInV = new float[INPUTSIZE * 4]; 246 Arrays.fill(arrayInV, (float) 42); 247 inV.copyTo(arrayInV); 248 float[] arrayOutFloor = new float[INPUTSIZE * 4]; 249 Arrays.fill(arrayOutFloor, (float) 42); 250 outFloor.copyTo(arrayOutFloor); 251 float[] arrayOut = new float[INPUTSIZE * 4]; 252 Arrays.fill(arrayOut, (float) 42); 253 out.copyTo(arrayOut); 254 StringBuilder message = new StringBuilder(); 255 boolean errorFound = false; 256 for (int i = 0; i < INPUTSIZE; i++) { 257 for (int j = 0; j < 3 ; j++) { 258 // Extract the inputs. 259 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 260 args.inV = arrayInV[i * 4 + j]; 261 // Figure out what the outputs should have been. 262 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 263 CoreMathVerifier.computeFract(args, target); 264 // Validate the outputs. 265 boolean valid = true; 266 if (!args.outFloor.couldBe(arrayOutFloor[i * 4 + j])) { 267 valid = false; 268 } 269 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 270 valid = false; 271 } 272 if (!valid) { 273 if (!errorFound) { 274 errorFound = true; 275 message.append("Input inV: "); 276 appendVariableToMessage(message, args.inV); 277 message.append("\n"); 278 message.append("Expected output outFloor: "); 279 appendVariableToMessage(message, args.outFloor); 280 message.append("\n"); 281 message.append("Actual output outFloor: "); 282 appendVariableToMessage(message, arrayOutFloor[i * 4 + j]); 283 if (!args.outFloor.couldBe(arrayOutFloor[i * 4 + j])) { 284 message.append(" FAIL"); 285 } 286 message.append("\n"); 287 message.append("Expected output out: "); 288 appendVariableToMessage(message, args.out); 289 message.append("\n"); 290 message.append("Actual output out: "); 291 appendVariableToMessage(message, arrayOut[i * 4 + j]); 292 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 293 message.append(" FAIL"); 294 } 295 message.append("\n"); 296 message.append("Errors at"); 297 } 298 message.append(" ["); 299 message.append(Integer.toString(i)); 300 message.append(", "); 301 message.append(Integer.toString(j)); 302 message.append("]"); 303 } 304 } 305 } 306 assertFalse("Incorrect output for checkFractFloat3Float3Float3" + 307 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 308 } 309 checkFractFloat4Float4Float4()310 private void checkFractFloat4Float4Float4() { 311 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xd1b4f867l, false); 312 try { 313 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 314 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 315 script.set_gAllocOutFloor(outFloor); 316 script.forEach_testFractFloat4Float4Float4(inV, out); 317 verifyResultsFractFloat4Float4Float4(inV, outFloor, out, false); 318 } catch (Exception e) { 319 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat4Float4Float4: " + e.toString()); 320 } 321 try { 322 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 323 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 324 scriptRelaxed.set_gAllocOutFloor(outFloor); 325 scriptRelaxed.forEach_testFractFloat4Float4Float4(inV, out); 326 verifyResultsFractFloat4Float4Float4(inV, outFloor, out, true); 327 } catch (Exception e) { 328 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat4Float4Float4: " + e.toString()); 329 } 330 } 331 verifyResultsFractFloat4Float4Float4(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed)332 private void verifyResultsFractFloat4Float4Float4(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 333 float[] arrayInV = new float[INPUTSIZE * 4]; 334 Arrays.fill(arrayInV, (float) 42); 335 inV.copyTo(arrayInV); 336 float[] arrayOutFloor = new float[INPUTSIZE * 4]; 337 Arrays.fill(arrayOutFloor, (float) 42); 338 outFloor.copyTo(arrayOutFloor); 339 float[] arrayOut = new float[INPUTSIZE * 4]; 340 Arrays.fill(arrayOut, (float) 42); 341 out.copyTo(arrayOut); 342 StringBuilder message = new StringBuilder(); 343 boolean errorFound = false; 344 for (int i = 0; i < INPUTSIZE; i++) { 345 for (int j = 0; j < 4 ; j++) { 346 // Extract the inputs. 347 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 348 args.inV = arrayInV[i * 4 + j]; 349 // Figure out what the outputs should have been. 350 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 351 CoreMathVerifier.computeFract(args, target); 352 // Validate the outputs. 353 boolean valid = true; 354 if (!args.outFloor.couldBe(arrayOutFloor[i * 4 + j])) { 355 valid = false; 356 } 357 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 358 valid = false; 359 } 360 if (!valid) { 361 if (!errorFound) { 362 errorFound = true; 363 message.append("Input inV: "); 364 appendVariableToMessage(message, args.inV); 365 message.append("\n"); 366 message.append("Expected output outFloor: "); 367 appendVariableToMessage(message, args.outFloor); 368 message.append("\n"); 369 message.append("Actual output outFloor: "); 370 appendVariableToMessage(message, arrayOutFloor[i * 4 + j]); 371 if (!args.outFloor.couldBe(arrayOutFloor[i * 4 + j])) { 372 message.append(" FAIL"); 373 } 374 message.append("\n"); 375 message.append("Expected output out: "); 376 appendVariableToMessage(message, args.out); 377 message.append("\n"); 378 message.append("Actual output out: "); 379 appendVariableToMessage(message, arrayOut[i * 4 + j]); 380 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 381 message.append(" FAIL"); 382 } 383 message.append("\n"); 384 message.append("Errors at"); 385 } 386 message.append(" ["); 387 message.append(Integer.toString(i)); 388 message.append(", "); 389 message.append(Integer.toString(j)); 390 message.append("]"); 391 } 392 } 393 } 394 assertFalse("Incorrect output for checkFractFloat4Float4Float4" + 395 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 396 } 397 398 public class ArgumentsFloatFloat { 399 public float inV; 400 public Target.Floaty out; 401 } 402 checkFractFloatFloat()403 private void checkFractFloatFloat() { 404 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x9db2cad3l, false); 405 try { 406 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 407 script.forEach_testFractFloatFloat(inV, out); 408 verifyResultsFractFloatFloat(inV, out, false); 409 } catch (Exception e) { 410 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloatFloat: " + e.toString()); 411 } 412 try { 413 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 414 scriptRelaxed.forEach_testFractFloatFloat(inV, out); 415 verifyResultsFractFloatFloat(inV, out, true); 416 } catch (Exception e) { 417 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloatFloat: " + e.toString()); 418 } 419 } 420 verifyResultsFractFloatFloat(Allocation inV, Allocation out, boolean relaxed)421 private void verifyResultsFractFloatFloat(Allocation inV, Allocation out, boolean relaxed) { 422 float[] arrayInV = new float[INPUTSIZE * 1]; 423 Arrays.fill(arrayInV, (float) 42); 424 inV.copyTo(arrayInV); 425 float[] arrayOut = new float[INPUTSIZE * 1]; 426 Arrays.fill(arrayOut, (float) 42); 427 out.copyTo(arrayOut); 428 StringBuilder message = new StringBuilder(); 429 boolean errorFound = false; 430 for (int i = 0; i < INPUTSIZE; i++) { 431 for (int j = 0; j < 1 ; j++) { 432 // Extract the inputs. 433 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 434 args.inV = arrayInV[i]; 435 // Figure out what the outputs should have been. 436 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 437 CoreMathVerifier.computeFract(args, target); 438 // Validate the outputs. 439 boolean valid = true; 440 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 441 valid = false; 442 } 443 if (!valid) { 444 if (!errorFound) { 445 errorFound = true; 446 message.append("Input inV: "); 447 appendVariableToMessage(message, args.inV); 448 message.append("\n"); 449 message.append("Expected output out: "); 450 appendVariableToMessage(message, args.out); 451 message.append("\n"); 452 message.append("Actual output out: "); 453 appendVariableToMessage(message, arrayOut[i * 1 + j]); 454 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 455 message.append(" FAIL"); 456 } 457 message.append("\n"); 458 message.append("Errors at"); 459 } 460 message.append(" ["); 461 message.append(Integer.toString(i)); 462 message.append(", "); 463 message.append(Integer.toString(j)); 464 message.append("]"); 465 } 466 } 467 } 468 assertFalse("Incorrect output for checkFractFloatFloat" + 469 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 470 } 471 checkFractFloat2Float2()472 private void checkFractFloat2Float2() { 473 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xc4d52edfl, false); 474 try { 475 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 476 script.forEach_testFractFloat2Float2(inV, out); 477 verifyResultsFractFloat2Float2(inV, out, false); 478 } catch (Exception e) { 479 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat2Float2: " + e.toString()); 480 } 481 try { 482 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 483 scriptRelaxed.forEach_testFractFloat2Float2(inV, out); 484 verifyResultsFractFloat2Float2(inV, out, true); 485 } catch (Exception e) { 486 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat2Float2: " + e.toString()); 487 } 488 } 489 verifyResultsFractFloat2Float2(Allocation inV, Allocation out, boolean relaxed)490 private void verifyResultsFractFloat2Float2(Allocation inV, Allocation out, boolean relaxed) { 491 float[] arrayInV = new float[INPUTSIZE * 2]; 492 Arrays.fill(arrayInV, (float) 42); 493 inV.copyTo(arrayInV); 494 float[] arrayOut = new float[INPUTSIZE * 2]; 495 Arrays.fill(arrayOut, (float) 42); 496 out.copyTo(arrayOut); 497 StringBuilder message = new StringBuilder(); 498 boolean errorFound = false; 499 for (int i = 0; i < INPUTSIZE; i++) { 500 for (int j = 0; j < 2 ; j++) { 501 // Extract the inputs. 502 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 503 args.inV = arrayInV[i * 2 + j]; 504 // Figure out what the outputs should have been. 505 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 506 CoreMathVerifier.computeFract(args, target); 507 // Validate the outputs. 508 boolean valid = true; 509 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 510 valid = false; 511 } 512 if (!valid) { 513 if (!errorFound) { 514 errorFound = true; 515 message.append("Input inV: "); 516 appendVariableToMessage(message, args.inV); 517 message.append("\n"); 518 message.append("Expected output out: "); 519 appendVariableToMessage(message, args.out); 520 message.append("\n"); 521 message.append("Actual output out: "); 522 appendVariableToMessage(message, arrayOut[i * 2 + j]); 523 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 524 message.append(" FAIL"); 525 } 526 message.append("\n"); 527 message.append("Errors at"); 528 } 529 message.append(" ["); 530 message.append(Integer.toString(i)); 531 message.append(", "); 532 message.append(Integer.toString(j)); 533 message.append("]"); 534 } 535 } 536 } 537 assertFalse("Incorrect output for checkFractFloat2Float2" + 538 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 539 } 540 checkFractFloat3Float3()541 private void checkFractFloat3Float3() { 542 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xbaf04fbdl, false); 543 try { 544 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 545 script.forEach_testFractFloat3Float3(inV, out); 546 verifyResultsFractFloat3Float3(inV, out, false); 547 } catch (Exception e) { 548 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat3Float3: " + e.toString()); 549 } 550 try { 551 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 552 scriptRelaxed.forEach_testFractFloat3Float3(inV, out); 553 verifyResultsFractFloat3Float3(inV, out, true); 554 } catch (Exception e) { 555 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat3Float3: " + e.toString()); 556 } 557 } 558 verifyResultsFractFloat3Float3(Allocation inV, Allocation out, boolean relaxed)559 private void verifyResultsFractFloat3Float3(Allocation inV, Allocation out, boolean relaxed) { 560 float[] arrayInV = new float[INPUTSIZE * 4]; 561 Arrays.fill(arrayInV, (float) 42); 562 inV.copyTo(arrayInV); 563 float[] arrayOut = new float[INPUTSIZE * 4]; 564 Arrays.fill(arrayOut, (float) 42); 565 out.copyTo(arrayOut); 566 StringBuilder message = new StringBuilder(); 567 boolean errorFound = false; 568 for (int i = 0; i < INPUTSIZE; i++) { 569 for (int j = 0; j < 3 ; j++) { 570 // Extract the inputs. 571 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 572 args.inV = arrayInV[i * 4 + j]; 573 // Figure out what the outputs should have been. 574 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 575 CoreMathVerifier.computeFract(args, target); 576 // Validate the outputs. 577 boolean valid = true; 578 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 579 valid = false; 580 } 581 if (!valid) { 582 if (!errorFound) { 583 errorFound = true; 584 message.append("Input inV: "); 585 appendVariableToMessage(message, args.inV); 586 message.append("\n"); 587 message.append("Expected output out: "); 588 appendVariableToMessage(message, args.out); 589 message.append("\n"); 590 message.append("Actual output out: "); 591 appendVariableToMessage(message, arrayOut[i * 4 + j]); 592 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 593 message.append(" FAIL"); 594 } 595 message.append("\n"); 596 message.append("Errors at"); 597 } 598 message.append(" ["); 599 message.append(Integer.toString(i)); 600 message.append(", "); 601 message.append(Integer.toString(j)); 602 message.append("]"); 603 } 604 } 605 } 606 assertFalse("Incorrect output for checkFractFloat3Float3" + 607 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 608 } 609 checkFractFloat4Float4()610 private void checkFractFloat4Float4() { 611 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xb10b709bl, false); 612 try { 613 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 614 script.forEach_testFractFloat4Float4(inV, out); 615 verifyResultsFractFloat4Float4(inV, out, false); 616 } catch (Exception e) { 617 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat4Float4: " + e.toString()); 618 } 619 try { 620 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 621 scriptRelaxed.forEach_testFractFloat4Float4(inV, out); 622 verifyResultsFractFloat4Float4(inV, out, true); 623 } catch (Exception e) { 624 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat4Float4: " + e.toString()); 625 } 626 } 627 verifyResultsFractFloat4Float4(Allocation inV, Allocation out, boolean relaxed)628 private void verifyResultsFractFloat4Float4(Allocation inV, Allocation out, boolean relaxed) { 629 float[] arrayInV = new float[INPUTSIZE * 4]; 630 Arrays.fill(arrayInV, (float) 42); 631 inV.copyTo(arrayInV); 632 float[] arrayOut = new float[INPUTSIZE * 4]; 633 Arrays.fill(arrayOut, (float) 42); 634 out.copyTo(arrayOut); 635 StringBuilder message = new StringBuilder(); 636 boolean errorFound = false; 637 for (int i = 0; i < INPUTSIZE; i++) { 638 for (int j = 0; j < 4 ; j++) { 639 // Extract the inputs. 640 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 641 args.inV = arrayInV[i * 4 + j]; 642 // Figure out what the outputs should have been. 643 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 644 CoreMathVerifier.computeFract(args, target); 645 // Validate the outputs. 646 boolean valid = true; 647 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 648 valid = false; 649 } 650 if (!valid) { 651 if (!errorFound) { 652 errorFound = true; 653 message.append("Input inV: "); 654 appendVariableToMessage(message, args.inV); 655 message.append("\n"); 656 message.append("Expected output out: "); 657 appendVariableToMessage(message, args.out); 658 message.append("\n"); 659 message.append("Actual output out: "); 660 appendVariableToMessage(message, arrayOut[i * 4 + j]); 661 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 662 message.append(" FAIL"); 663 } 664 message.append("\n"); 665 message.append("Errors at"); 666 } 667 message.append(" ["); 668 message.append(Integer.toString(i)); 669 message.append(", "); 670 message.append(Integer.toString(j)); 671 message.append("]"); 672 } 673 } 674 } 675 assertFalse("Incorrect output for checkFractFloat4Float4" + 676 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 677 } 678 679 public class ArgumentsHalfHalfHalf { 680 public short inV; 681 public double inVDouble; 682 public Target.Floaty outFloor; 683 public Target.Floaty out; 684 } 685 checkFractHalfHalfHalf()686 private void checkFractHalfHalfHalf() { 687 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x64a42fb6l, false); 688 try { 689 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 690 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 691 script.set_gAllocOutFloor(outFloor); 692 script.forEach_testFractHalfHalfHalf(inV, out); 693 verifyResultsFractHalfHalfHalf(inV, outFloor, out, false); 694 } catch (Exception e) { 695 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalfHalfHalf: " + e.toString()); 696 } 697 try { 698 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 699 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 700 scriptRelaxed.set_gAllocOutFloor(outFloor); 701 scriptRelaxed.forEach_testFractHalfHalfHalf(inV, out); 702 verifyResultsFractHalfHalfHalf(inV, outFloor, out, true); 703 } catch (Exception e) { 704 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalfHalfHalf: " + e.toString()); 705 } 706 } 707 verifyResultsFractHalfHalfHalf(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed)708 private void verifyResultsFractHalfHalfHalf(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 709 short[] arrayInV = new short[INPUTSIZE * 1]; 710 Arrays.fill(arrayInV, (short) 42); 711 inV.copyTo(arrayInV); 712 short[] arrayOutFloor = new short[INPUTSIZE * 1]; 713 Arrays.fill(arrayOutFloor, (short) 42); 714 outFloor.copyTo(arrayOutFloor); 715 short[] arrayOut = new short[INPUTSIZE * 1]; 716 Arrays.fill(arrayOut, (short) 42); 717 out.copyTo(arrayOut); 718 StringBuilder message = new StringBuilder(); 719 boolean errorFound = false; 720 for (int i = 0; i < INPUTSIZE; i++) { 721 for (int j = 0; j < 1 ; j++) { 722 // Extract the inputs. 723 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 724 args.inV = arrayInV[i]; 725 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 726 // Figure out what the outputs should have been. 727 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 728 CoreMathVerifier.computeFract(args, target); 729 // Validate the outputs. 730 boolean valid = true; 731 if (!args.outFloor.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 1 + j]))) { 732 valid = false; 733 } 734 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 735 valid = false; 736 } 737 if (!valid) { 738 if (!errorFound) { 739 errorFound = true; 740 message.append("Input inV: "); 741 appendVariableToMessage(message, args.inV); 742 message.append("\n"); 743 message.append("Expected output outFloor: "); 744 appendVariableToMessage(message, args.outFloor); 745 message.append("\n"); 746 message.append("Actual output outFloor: "); 747 appendVariableToMessage(message, arrayOutFloor[i * 1 + j]); 748 message.append("\n"); 749 message.append("Actual output outFloor (in double): "); 750 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 1 + j])); 751 if (!args.outFloor.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 1 + j]))) { 752 message.append(" FAIL"); 753 } 754 message.append("\n"); 755 message.append("Expected output out: "); 756 appendVariableToMessage(message, args.out); 757 message.append("\n"); 758 message.append("Actual output out: "); 759 appendVariableToMessage(message, arrayOut[i * 1 + j]); 760 message.append("\n"); 761 message.append("Actual output out (in double): "); 762 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j])); 763 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 764 message.append(" FAIL"); 765 } 766 message.append("\n"); 767 message.append("Errors at"); 768 } 769 message.append(" ["); 770 message.append(Integer.toString(i)); 771 message.append(", "); 772 message.append(Integer.toString(j)); 773 message.append("]"); 774 } 775 } 776 } 777 assertFalse("Incorrect output for checkFractHalfHalfHalf" + 778 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 779 } 780 checkFractHalf2Half2Half2()781 private void checkFractHalf2Half2Half2() { 782 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x734da11cl, false); 783 try { 784 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 785 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 786 script.set_gAllocOutFloor(outFloor); 787 script.forEach_testFractHalf2Half2Half2(inV, out); 788 verifyResultsFractHalf2Half2Half2(inV, outFloor, out, false); 789 } catch (Exception e) { 790 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf2Half2Half2: " + e.toString()); 791 } 792 try { 793 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 794 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 795 scriptRelaxed.set_gAllocOutFloor(outFloor); 796 scriptRelaxed.forEach_testFractHalf2Half2Half2(inV, out); 797 verifyResultsFractHalf2Half2Half2(inV, outFloor, out, true); 798 } catch (Exception e) { 799 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf2Half2Half2: " + e.toString()); 800 } 801 } 802 verifyResultsFractHalf2Half2Half2(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed)803 private void verifyResultsFractHalf2Half2Half2(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 804 short[] arrayInV = new short[INPUTSIZE * 2]; 805 Arrays.fill(arrayInV, (short) 42); 806 inV.copyTo(arrayInV); 807 short[] arrayOutFloor = new short[INPUTSIZE * 2]; 808 Arrays.fill(arrayOutFloor, (short) 42); 809 outFloor.copyTo(arrayOutFloor); 810 short[] arrayOut = new short[INPUTSIZE * 2]; 811 Arrays.fill(arrayOut, (short) 42); 812 out.copyTo(arrayOut); 813 StringBuilder message = new StringBuilder(); 814 boolean errorFound = false; 815 for (int i = 0; i < INPUTSIZE; i++) { 816 for (int j = 0; j < 2 ; j++) { 817 // Extract the inputs. 818 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 819 args.inV = arrayInV[i * 2 + j]; 820 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 821 // Figure out what the outputs should have been. 822 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 823 CoreMathVerifier.computeFract(args, target); 824 // Validate the outputs. 825 boolean valid = true; 826 if (!args.outFloor.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 2 + j]))) { 827 valid = false; 828 } 829 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 830 valid = false; 831 } 832 if (!valid) { 833 if (!errorFound) { 834 errorFound = true; 835 message.append("Input inV: "); 836 appendVariableToMessage(message, args.inV); 837 message.append("\n"); 838 message.append("Expected output outFloor: "); 839 appendVariableToMessage(message, args.outFloor); 840 message.append("\n"); 841 message.append("Actual output outFloor: "); 842 appendVariableToMessage(message, arrayOutFloor[i * 2 + j]); 843 message.append("\n"); 844 message.append("Actual output outFloor (in double): "); 845 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 2 + j])); 846 if (!args.outFloor.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 2 + j]))) { 847 message.append(" FAIL"); 848 } 849 message.append("\n"); 850 message.append("Expected output out: "); 851 appendVariableToMessage(message, args.out); 852 message.append("\n"); 853 message.append("Actual output out: "); 854 appendVariableToMessage(message, arrayOut[i * 2 + j]); 855 message.append("\n"); 856 message.append("Actual output out (in double): "); 857 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j])); 858 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 859 message.append(" FAIL"); 860 } 861 message.append("\n"); 862 message.append("Errors at"); 863 } 864 message.append(" ["); 865 message.append(Integer.toString(i)); 866 message.append(", "); 867 message.append(Integer.toString(j)); 868 message.append("]"); 869 } 870 } 871 } 872 assertFalse("Incorrect output for checkFractHalf2Half2Half2" + 873 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 874 } 875 checkFractHalf3Half3Half3()876 private void checkFractHalf3Half3Half3() { 877 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xd1ecb1ebl, false); 878 try { 879 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 880 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 881 script.set_gAllocOutFloor(outFloor); 882 script.forEach_testFractHalf3Half3Half3(inV, out); 883 verifyResultsFractHalf3Half3Half3(inV, outFloor, out, false); 884 } catch (Exception e) { 885 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf3Half3Half3: " + e.toString()); 886 } 887 try { 888 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 889 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 890 scriptRelaxed.set_gAllocOutFloor(outFloor); 891 scriptRelaxed.forEach_testFractHalf3Half3Half3(inV, out); 892 verifyResultsFractHalf3Half3Half3(inV, outFloor, out, true); 893 } catch (Exception e) { 894 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf3Half3Half3: " + e.toString()); 895 } 896 } 897 verifyResultsFractHalf3Half3Half3(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed)898 private void verifyResultsFractHalf3Half3Half3(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 899 short[] arrayInV = new short[INPUTSIZE * 4]; 900 Arrays.fill(arrayInV, (short) 42); 901 inV.copyTo(arrayInV); 902 short[] arrayOutFloor = new short[INPUTSIZE * 4]; 903 Arrays.fill(arrayOutFloor, (short) 42); 904 outFloor.copyTo(arrayOutFloor); 905 short[] arrayOut = new short[INPUTSIZE * 4]; 906 Arrays.fill(arrayOut, (short) 42); 907 out.copyTo(arrayOut); 908 StringBuilder message = new StringBuilder(); 909 boolean errorFound = false; 910 for (int i = 0; i < INPUTSIZE; i++) { 911 for (int j = 0; j < 3 ; j++) { 912 // Extract the inputs. 913 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 914 args.inV = arrayInV[i * 4 + j]; 915 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 916 // Figure out what the outputs should have been. 917 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 918 CoreMathVerifier.computeFract(args, target); 919 // Validate the outputs. 920 boolean valid = true; 921 if (!args.outFloor.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 4 + j]))) { 922 valid = false; 923 } 924 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 925 valid = false; 926 } 927 if (!valid) { 928 if (!errorFound) { 929 errorFound = true; 930 message.append("Input inV: "); 931 appendVariableToMessage(message, args.inV); 932 message.append("\n"); 933 message.append("Expected output outFloor: "); 934 appendVariableToMessage(message, args.outFloor); 935 message.append("\n"); 936 message.append("Actual output outFloor: "); 937 appendVariableToMessage(message, arrayOutFloor[i * 4 + j]); 938 message.append("\n"); 939 message.append("Actual output outFloor (in double): "); 940 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 4 + j])); 941 if (!args.outFloor.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 4 + j]))) { 942 message.append(" FAIL"); 943 } 944 message.append("\n"); 945 message.append("Expected output out: "); 946 appendVariableToMessage(message, args.out); 947 message.append("\n"); 948 message.append("Actual output out: "); 949 appendVariableToMessage(message, arrayOut[i * 4 + j]); 950 message.append("\n"); 951 message.append("Actual output out (in double): "); 952 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 953 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 954 message.append(" FAIL"); 955 } 956 message.append("\n"); 957 message.append("Errors at"); 958 } 959 message.append(" ["); 960 message.append(Integer.toString(i)); 961 message.append(", "); 962 message.append(Integer.toString(j)); 963 message.append("]"); 964 } 965 } 966 } 967 assertFalse("Incorrect output for checkFractHalf3Half3Half3" + 968 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 969 } 970 checkFractHalf4Half4Half4()971 private void checkFractHalf4Half4Half4() { 972 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x308bc2bal, false); 973 try { 974 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 975 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 976 script.set_gAllocOutFloor(outFloor); 977 script.forEach_testFractHalf4Half4Half4(inV, out); 978 verifyResultsFractHalf4Half4Half4(inV, outFloor, out, false); 979 } catch (Exception e) { 980 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf4Half4Half4: " + e.toString()); 981 } 982 try { 983 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 984 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 985 scriptRelaxed.set_gAllocOutFloor(outFloor); 986 scriptRelaxed.forEach_testFractHalf4Half4Half4(inV, out); 987 verifyResultsFractHalf4Half4Half4(inV, outFloor, out, true); 988 } catch (Exception e) { 989 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf4Half4Half4: " + e.toString()); 990 } 991 } 992 verifyResultsFractHalf4Half4Half4(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed)993 private void verifyResultsFractHalf4Half4Half4(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 994 short[] arrayInV = new short[INPUTSIZE * 4]; 995 Arrays.fill(arrayInV, (short) 42); 996 inV.copyTo(arrayInV); 997 short[] arrayOutFloor = new short[INPUTSIZE * 4]; 998 Arrays.fill(arrayOutFloor, (short) 42); 999 outFloor.copyTo(arrayOutFloor); 1000 short[] arrayOut = new short[INPUTSIZE * 4]; 1001 Arrays.fill(arrayOut, (short) 42); 1002 out.copyTo(arrayOut); 1003 StringBuilder message = new StringBuilder(); 1004 boolean errorFound = false; 1005 for (int i = 0; i < INPUTSIZE; i++) { 1006 for (int j = 0; j < 4 ; j++) { 1007 // Extract the inputs. 1008 ArgumentsHalfHalfHalf args = new ArgumentsHalfHalfHalf(); 1009 args.inV = arrayInV[i * 4 + j]; 1010 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 1011 // Figure out what the outputs should have been. 1012 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1013 CoreMathVerifier.computeFract(args, target); 1014 // Validate the outputs. 1015 boolean valid = true; 1016 if (!args.outFloor.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 4 + j]))) { 1017 valid = false; 1018 } 1019 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1020 valid = false; 1021 } 1022 if (!valid) { 1023 if (!errorFound) { 1024 errorFound = true; 1025 message.append("Input inV: "); 1026 appendVariableToMessage(message, args.inV); 1027 message.append("\n"); 1028 message.append("Expected output outFloor: "); 1029 appendVariableToMessage(message, args.outFloor); 1030 message.append("\n"); 1031 message.append("Actual output outFloor: "); 1032 appendVariableToMessage(message, arrayOutFloor[i * 4 + j]); 1033 message.append("\n"); 1034 message.append("Actual output outFloor (in double): "); 1035 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 4 + j])); 1036 if (!args.outFloor.couldBe(Float16Utils.convertFloat16ToDouble(arrayOutFloor[i * 4 + j]))) { 1037 message.append(" FAIL"); 1038 } 1039 message.append("\n"); 1040 message.append("Expected output out: "); 1041 appendVariableToMessage(message, args.out); 1042 message.append("\n"); 1043 message.append("Actual output out: "); 1044 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1045 message.append("\n"); 1046 message.append("Actual output out (in double): "); 1047 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 1048 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1049 message.append(" FAIL"); 1050 } 1051 message.append("\n"); 1052 message.append("Errors at"); 1053 } 1054 message.append(" ["); 1055 message.append(Integer.toString(i)); 1056 message.append(", "); 1057 message.append(Integer.toString(j)); 1058 message.append("]"); 1059 } 1060 } 1061 } 1062 assertFalse("Incorrect output for checkFractHalf4Half4Half4" + 1063 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1064 } 1065 1066 public class ArgumentsHalfHalf { 1067 public short inV; 1068 public double inVDouble; 1069 public Target.Floaty out; 1070 } 1071 checkFractHalfHalf()1072 private void checkFractHalfHalf() { 1073 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x96468e55l, false); 1074 try { 1075 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 1076 script.forEach_testFractHalfHalf(inV, out); 1077 verifyResultsFractHalfHalf(inV, out, false); 1078 } catch (Exception e) { 1079 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalfHalf: " + e.toString()); 1080 } 1081 try { 1082 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 1083 scriptRelaxed.forEach_testFractHalfHalf(inV, out); 1084 verifyResultsFractHalfHalf(inV, out, true); 1085 } catch (Exception e) { 1086 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalfHalf: " + e.toString()); 1087 } 1088 } 1089 verifyResultsFractHalfHalf(Allocation inV, Allocation out, boolean relaxed)1090 private void verifyResultsFractHalfHalf(Allocation inV, Allocation out, boolean relaxed) { 1091 short[] arrayInV = new short[INPUTSIZE * 1]; 1092 Arrays.fill(arrayInV, (short) 42); 1093 inV.copyTo(arrayInV); 1094 short[] arrayOut = new short[INPUTSIZE * 1]; 1095 Arrays.fill(arrayOut, (short) 42); 1096 out.copyTo(arrayOut); 1097 StringBuilder message = new StringBuilder(); 1098 boolean errorFound = false; 1099 for (int i = 0; i < INPUTSIZE; i++) { 1100 for (int j = 0; j < 1 ; j++) { 1101 // Extract the inputs. 1102 ArgumentsHalfHalf args = new ArgumentsHalfHalf(); 1103 args.inV = arrayInV[i]; 1104 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 1105 // Figure out what the outputs should have been. 1106 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1107 CoreMathVerifier.computeFract(args, target); 1108 // Validate the outputs. 1109 boolean valid = true; 1110 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 1111 valid = false; 1112 } 1113 if (!valid) { 1114 if (!errorFound) { 1115 errorFound = true; 1116 message.append("Input inV: "); 1117 appendVariableToMessage(message, args.inV); 1118 message.append("\n"); 1119 message.append("Expected output out: "); 1120 appendVariableToMessage(message, args.out); 1121 message.append("\n"); 1122 message.append("Actual output out: "); 1123 appendVariableToMessage(message, arrayOut[i * 1 + j]); 1124 message.append("\n"); 1125 message.append("Actual output out (in double): "); 1126 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j])); 1127 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 1128 message.append(" FAIL"); 1129 } 1130 message.append("\n"); 1131 message.append("Errors at"); 1132 } 1133 message.append(" ["); 1134 message.append(Integer.toString(i)); 1135 message.append(", "); 1136 message.append(Integer.toString(j)); 1137 message.append("]"); 1138 } 1139 } 1140 } 1141 assertFalse("Incorrect output for checkFractHalfHalf" + 1142 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1143 } 1144 checkFractHalf2Half2()1145 private void checkFractHalf2Half2() { 1146 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0xad1120fl, false); 1147 try { 1148 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 1149 script.forEach_testFractHalf2Half2(inV, out); 1150 verifyResultsFractHalf2Half2(inV, out, false); 1151 } catch (Exception e) { 1152 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf2Half2: " + e.toString()); 1153 } 1154 try { 1155 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 1156 scriptRelaxed.forEach_testFractHalf2Half2(inV, out); 1157 verifyResultsFractHalf2Half2(inV, out, true); 1158 } catch (Exception e) { 1159 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf2Half2: " + e.toString()); 1160 } 1161 } 1162 verifyResultsFractHalf2Half2(Allocation inV, Allocation out, boolean relaxed)1163 private void verifyResultsFractHalf2Half2(Allocation inV, Allocation out, boolean relaxed) { 1164 short[] arrayInV = new short[INPUTSIZE * 2]; 1165 Arrays.fill(arrayInV, (short) 42); 1166 inV.copyTo(arrayInV); 1167 short[] arrayOut = new short[INPUTSIZE * 2]; 1168 Arrays.fill(arrayOut, (short) 42); 1169 out.copyTo(arrayOut); 1170 StringBuilder message = new StringBuilder(); 1171 boolean errorFound = false; 1172 for (int i = 0; i < INPUTSIZE; i++) { 1173 for (int j = 0; j < 2 ; j++) { 1174 // Extract the inputs. 1175 ArgumentsHalfHalf args = new ArgumentsHalfHalf(); 1176 args.inV = arrayInV[i * 2 + j]; 1177 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 1178 // Figure out what the outputs should have been. 1179 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1180 CoreMathVerifier.computeFract(args, target); 1181 // Validate the outputs. 1182 boolean valid = true; 1183 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 1184 valid = false; 1185 } 1186 if (!valid) { 1187 if (!errorFound) { 1188 errorFound = true; 1189 message.append("Input inV: "); 1190 appendVariableToMessage(message, args.inV); 1191 message.append("\n"); 1192 message.append("Expected output out: "); 1193 appendVariableToMessage(message, args.out); 1194 message.append("\n"); 1195 message.append("Actual output out: "); 1196 appendVariableToMessage(message, arrayOut[i * 2 + j]); 1197 message.append("\n"); 1198 message.append("Actual output out (in double): "); 1199 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j])); 1200 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 1201 message.append(" FAIL"); 1202 } 1203 message.append("\n"); 1204 message.append("Errors at"); 1205 } 1206 message.append(" ["); 1207 message.append(Integer.toString(i)); 1208 message.append(", "); 1209 message.append(Integer.toString(j)); 1210 message.append("]"); 1211 } 1212 } 1213 } 1214 assertFalse("Incorrect output for checkFractHalf2Half2" + 1215 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1216 } 1217 checkFractHalf3Half3()1218 private void checkFractHalf3Half3() { 1219 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x69d8d703l, false); 1220 try { 1221 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 1222 script.forEach_testFractHalf3Half3(inV, out); 1223 verifyResultsFractHalf3Half3(inV, out, false); 1224 } catch (Exception e) { 1225 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf3Half3: " + e.toString()); 1226 } 1227 try { 1228 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 1229 scriptRelaxed.forEach_testFractHalf3Half3(inV, out); 1230 verifyResultsFractHalf3Half3(inV, out, true); 1231 } catch (Exception e) { 1232 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf3Half3: " + e.toString()); 1233 } 1234 } 1235 verifyResultsFractHalf3Half3(Allocation inV, Allocation out, boolean relaxed)1236 private void verifyResultsFractHalf3Half3(Allocation inV, Allocation out, boolean relaxed) { 1237 short[] arrayInV = new short[INPUTSIZE * 4]; 1238 Arrays.fill(arrayInV, (short) 42); 1239 inV.copyTo(arrayInV); 1240 short[] arrayOut = new short[INPUTSIZE * 4]; 1241 Arrays.fill(arrayOut, (short) 42); 1242 out.copyTo(arrayOut); 1243 StringBuilder message = new StringBuilder(); 1244 boolean errorFound = false; 1245 for (int i = 0; i < INPUTSIZE; i++) { 1246 for (int j = 0; j < 3 ; j++) { 1247 // Extract the inputs. 1248 ArgumentsHalfHalf args = new ArgumentsHalfHalf(); 1249 args.inV = arrayInV[i * 4 + j]; 1250 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 1251 // Figure out what the outputs should have been. 1252 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1253 CoreMathVerifier.computeFract(args, target); 1254 // Validate the outputs. 1255 boolean valid = true; 1256 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1257 valid = false; 1258 } 1259 if (!valid) { 1260 if (!errorFound) { 1261 errorFound = true; 1262 message.append("Input inV: "); 1263 appendVariableToMessage(message, args.inV); 1264 message.append("\n"); 1265 message.append("Expected output out: "); 1266 appendVariableToMessage(message, args.out); 1267 message.append("\n"); 1268 message.append("Actual output out: "); 1269 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1270 message.append("\n"); 1271 message.append("Actual output out (in double): "); 1272 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 1273 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1274 message.append(" FAIL"); 1275 } 1276 message.append("\n"); 1277 message.append("Errors at"); 1278 } 1279 message.append(" ["); 1280 message.append(Integer.toString(i)); 1281 message.append(", "); 1282 message.append(Integer.toString(j)); 1283 message.append("]"); 1284 } 1285 } 1286 } 1287 assertFalse("Incorrect output for checkFractHalf3Half3" + 1288 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1289 } 1290 checkFractHalf4Half4()1291 private void checkFractHalf4Half4() { 1292 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xc8e09bf7l, false); 1293 try { 1294 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 1295 script.forEach_testFractHalf4Half4(inV, out); 1296 verifyResultsFractHalf4Half4(inV, out, false); 1297 } catch (Exception e) { 1298 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf4Half4: " + e.toString()); 1299 } 1300 try { 1301 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 1302 scriptRelaxed.forEach_testFractHalf4Half4(inV, out); 1303 verifyResultsFractHalf4Half4(inV, out, true); 1304 } catch (Exception e) { 1305 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractHalf4Half4: " + e.toString()); 1306 } 1307 } 1308 verifyResultsFractHalf4Half4(Allocation inV, Allocation out, boolean relaxed)1309 private void verifyResultsFractHalf4Half4(Allocation inV, Allocation out, boolean relaxed) { 1310 short[] arrayInV = new short[INPUTSIZE * 4]; 1311 Arrays.fill(arrayInV, (short) 42); 1312 inV.copyTo(arrayInV); 1313 short[] arrayOut = new short[INPUTSIZE * 4]; 1314 Arrays.fill(arrayOut, (short) 42); 1315 out.copyTo(arrayOut); 1316 StringBuilder message = new StringBuilder(); 1317 boolean errorFound = false; 1318 for (int i = 0; i < INPUTSIZE; i++) { 1319 for (int j = 0; j < 4 ; j++) { 1320 // Extract the inputs. 1321 ArgumentsHalfHalf args = new ArgumentsHalfHalf(); 1322 args.inV = arrayInV[i * 4 + j]; 1323 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 1324 // Figure out what the outputs should have been. 1325 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 1326 CoreMathVerifier.computeFract(args, target); 1327 // Validate the outputs. 1328 boolean valid = true; 1329 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1330 valid = false; 1331 } 1332 if (!valid) { 1333 if (!errorFound) { 1334 errorFound = true; 1335 message.append("Input inV: "); 1336 appendVariableToMessage(message, args.inV); 1337 message.append("\n"); 1338 message.append("Expected output out: "); 1339 appendVariableToMessage(message, args.out); 1340 message.append("\n"); 1341 message.append("Actual output out: "); 1342 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1343 message.append("\n"); 1344 message.append("Actual output out (in double): "); 1345 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 1346 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 1347 message.append(" FAIL"); 1348 } 1349 message.append("\n"); 1350 message.append("Errors at"); 1351 } 1352 message.append(" ["); 1353 message.append(Integer.toString(i)); 1354 message.append(", "); 1355 message.append(Integer.toString(j)); 1356 message.append("]"); 1357 } 1358 } 1359 } 1360 assertFalse("Incorrect output for checkFractHalf4Half4" + 1361 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1362 } 1363 testFract()1364 public void testFract() { 1365 checkFractFloatFloatFloat(); 1366 checkFractFloat2Float2Float2(); 1367 checkFractFloat3Float3Float3(); 1368 checkFractFloat4Float4Float4(); 1369 checkFractFloatFloat(); 1370 checkFractFloat2Float2(); 1371 checkFractFloat3Float3(); 1372 checkFractFloat4Float4(); 1373 checkFractHalfHalfHalf(); 1374 checkFractHalf2Half2Half2(); 1375 checkFractHalf3Half3Half3(); 1376 checkFractHalf4Half4Half4(); 1377 checkFractHalfHalf(); 1378 checkFractHalf2Half2(); 1379 checkFractHalf3Half3(); 1380 checkFractHalf4Half4(); 1381 } 1382 } 1383