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 TestFract extends RSBaseCompute { 26 27 private ScriptC_TestFract script; 28 private ScriptC_TestFractRelaxed scriptRelaxed; 29 30 @Override 31 protected void setUp() throws Exception { 32 super.setUp(); 33 script = new ScriptC_TestFract(mRS); 34 scriptRelaxed = new ScriptC_TestFractRelaxed(mRS); 35 } 36 37 public class ArgumentsFloatFloatFloat { 38 public float inV; 39 public Target.Floaty outFloor; 40 public Target.Floaty out; 41 } 42 43 private void checkFractFloatFloatFloat() { 44 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x57d8e6573c675d27l, false); 45 try { 46 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 47 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 48 script.set_gAllocOutFloor(outFloor); 49 script.forEach_testFractFloatFloatFloat(inV, out); 50 verifyResultsFractFloatFloatFloat(inV, outFloor, out, false); 51 } catch (Exception e) { 52 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloatFloatFloat: " + e.toString()); 53 } 54 try { 55 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 56 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 57 scriptRelaxed.set_gAllocOutFloor(outFloor); 58 scriptRelaxed.forEach_testFractFloatFloatFloat(inV, out); 59 verifyResultsFractFloatFloatFloat(inV, outFloor, out, true); 60 } catch (Exception e) { 61 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloatFloatFloat: " + e.toString()); 62 } 63 } 64 65 private void verifyResultsFractFloatFloatFloat(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 66 float[] arrayInV = new float[INPUTSIZE * 1]; 67 inV.copyTo(arrayInV); 68 float[] arrayOutFloor = new float[INPUTSIZE * 1]; 69 outFloor.copyTo(arrayOutFloor); 70 float[] arrayOut = new float[INPUTSIZE * 1]; 71 out.copyTo(arrayOut); 72 for (int i = 0; i < INPUTSIZE; i++) { 73 for (int j = 0; j < 1 ; j++) { 74 // Extract the inputs. 75 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 76 args.inV = arrayInV[i]; 77 // Figure out what the outputs should have been. 78 Target target = new Target(relaxed); 79 CoreMathVerifier.computeFract(args, target); 80 // Validate the outputs. 81 boolean valid = true; 82 if (!args.outFloor.couldBe(arrayOutFloor[i * 1 + j])) { 83 valid = false; 84 } 85 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 86 valid = false; 87 } 88 if (!valid) { 89 StringBuilder message = new StringBuilder(); 90 message.append("Input inV: "); 91 message.append(String.format("%14.8g {%8x} %15a", 92 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 93 message.append("\n"); 94 message.append("Expected output outFloor: "); 95 message.append(args.outFloor.toString()); 96 message.append("\n"); 97 message.append("Actual output outFloor: "); 98 message.append(String.format("%14.8g {%8x} %15a", 99 arrayOutFloor[i * 1 + j], Float.floatToRawIntBits(arrayOutFloor[i * 1 + j]), arrayOutFloor[i * 1 + j])); 100 if (!args.outFloor.couldBe(arrayOutFloor[i * 1 + j])) { 101 message.append(" FAIL"); 102 } 103 message.append("\n"); 104 message.append("Expected output out: "); 105 message.append(args.out.toString()); 106 message.append("\n"); 107 message.append("Actual output out: "); 108 message.append(String.format("%14.8g {%8x} %15a", 109 arrayOut[i * 1 + j], Float.floatToRawIntBits(arrayOut[i * 1 + j]), arrayOut[i * 1 + j])); 110 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 111 message.append(" FAIL"); 112 } 113 message.append("\n"); 114 assertTrue("Incorrect output for checkFractFloatFloatFloat" + 115 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 116 } 117 } 118 } 119 } 120 121 private void checkFractFloat2Float2Float2() { 122 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xd1dbe683cdf8f525l, false); 123 try { 124 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 125 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 126 script.set_gAllocOutFloor(outFloor); 127 script.forEach_testFractFloat2Float2Float2(inV, out); 128 verifyResultsFractFloat2Float2Float2(inV, outFloor, out, false); 129 } catch (Exception e) { 130 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat2Float2Float2: " + e.toString()); 131 } 132 try { 133 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 134 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 135 scriptRelaxed.set_gAllocOutFloor(outFloor); 136 scriptRelaxed.forEach_testFractFloat2Float2Float2(inV, out); 137 verifyResultsFractFloat2Float2Float2(inV, outFloor, out, true); 138 } catch (Exception e) { 139 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat2Float2Float2: " + e.toString()); 140 } 141 } 142 143 private void verifyResultsFractFloat2Float2Float2(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 144 float[] arrayInV = new float[INPUTSIZE * 2]; 145 inV.copyTo(arrayInV); 146 float[] arrayOutFloor = new float[INPUTSIZE * 2]; 147 outFloor.copyTo(arrayOutFloor); 148 float[] arrayOut = new float[INPUTSIZE * 2]; 149 out.copyTo(arrayOut); 150 for (int i = 0; i < INPUTSIZE; i++) { 151 for (int j = 0; j < 2 ; j++) { 152 // Extract the inputs. 153 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 154 args.inV = arrayInV[i * 2 + j]; 155 // Figure out what the outputs should have been. 156 Target target = new Target(relaxed); 157 CoreMathVerifier.computeFract(args, target); 158 // Validate the outputs. 159 boolean valid = true; 160 if (!args.outFloor.couldBe(arrayOutFloor[i * 2 + j])) { 161 valid = false; 162 } 163 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 164 valid = false; 165 } 166 if (!valid) { 167 StringBuilder message = new StringBuilder(); 168 message.append("Input inV: "); 169 message.append(String.format("%14.8g {%8x} %15a", 170 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 171 message.append("\n"); 172 message.append("Expected output outFloor: "); 173 message.append(args.outFloor.toString()); 174 message.append("\n"); 175 message.append("Actual output outFloor: "); 176 message.append(String.format("%14.8g {%8x} %15a", 177 arrayOutFloor[i * 2 + j], Float.floatToRawIntBits(arrayOutFloor[i * 2 + j]), arrayOutFloor[i * 2 + j])); 178 if (!args.outFloor.couldBe(arrayOutFloor[i * 2 + j])) { 179 message.append(" FAIL"); 180 } 181 message.append("\n"); 182 message.append("Expected output out: "); 183 message.append(args.out.toString()); 184 message.append("\n"); 185 message.append("Actual output out: "); 186 message.append(String.format("%14.8g {%8x} %15a", 187 arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j])); 188 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 189 message.append(" FAIL"); 190 } 191 message.append("\n"); 192 assertTrue("Incorrect output for checkFractFloat2Float2Float2" + 193 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 194 } 195 } 196 } 197 } 198 199 private void checkFractFloat3Float3Float3() { 200 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x2640c4a3cfd6f6c6l, false); 201 try { 202 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 203 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 204 script.set_gAllocOutFloor(outFloor); 205 script.forEach_testFractFloat3Float3Float3(inV, out); 206 verifyResultsFractFloat3Float3Float3(inV, outFloor, out, false); 207 } catch (Exception e) { 208 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat3Float3Float3: " + e.toString()); 209 } 210 try { 211 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 212 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 213 scriptRelaxed.set_gAllocOutFloor(outFloor); 214 scriptRelaxed.forEach_testFractFloat3Float3Float3(inV, out); 215 verifyResultsFractFloat3Float3Float3(inV, outFloor, out, true); 216 } catch (Exception e) { 217 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat3Float3Float3: " + e.toString()); 218 } 219 } 220 221 private void verifyResultsFractFloat3Float3Float3(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 222 float[] arrayInV = new float[INPUTSIZE * 4]; 223 inV.copyTo(arrayInV); 224 float[] arrayOutFloor = new float[INPUTSIZE * 4]; 225 outFloor.copyTo(arrayOutFloor); 226 float[] arrayOut = new float[INPUTSIZE * 4]; 227 out.copyTo(arrayOut); 228 for (int i = 0; i < INPUTSIZE; i++) { 229 for (int j = 0; j < 3 ; j++) { 230 // Extract the inputs. 231 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 232 args.inV = arrayInV[i * 4 + j]; 233 // Figure out what the outputs should have been. 234 Target target = new Target(relaxed); 235 CoreMathVerifier.computeFract(args, target); 236 // Validate the outputs. 237 boolean valid = true; 238 if (!args.outFloor.couldBe(arrayOutFloor[i * 4 + j])) { 239 valid = false; 240 } 241 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 242 valid = false; 243 } 244 if (!valid) { 245 StringBuilder message = new StringBuilder(); 246 message.append("Input inV: "); 247 message.append(String.format("%14.8g {%8x} %15a", 248 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 249 message.append("\n"); 250 message.append("Expected output outFloor: "); 251 message.append(args.outFloor.toString()); 252 message.append("\n"); 253 message.append("Actual output outFloor: "); 254 message.append(String.format("%14.8g {%8x} %15a", 255 arrayOutFloor[i * 4 + j], Float.floatToRawIntBits(arrayOutFloor[i * 4 + j]), arrayOutFloor[i * 4 + j])); 256 if (!args.outFloor.couldBe(arrayOutFloor[i * 4 + j])) { 257 message.append(" FAIL"); 258 } 259 message.append("\n"); 260 message.append("Expected output out: "); 261 message.append(args.out.toString()); 262 message.append("\n"); 263 message.append("Actual output out: "); 264 message.append(String.format("%14.8g {%8x} %15a", 265 arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); 266 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 267 message.append(" FAIL"); 268 } 269 message.append("\n"); 270 assertTrue("Incorrect output for checkFractFloat3Float3Float3" + 271 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 272 } 273 } 274 } 275 } 276 277 private void checkFractFloat4Float4Float4() { 278 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x7aa5a2c3d1b4f867l, false); 279 try { 280 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 281 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 282 script.set_gAllocOutFloor(outFloor); 283 script.forEach_testFractFloat4Float4Float4(inV, out); 284 verifyResultsFractFloat4Float4Float4(inV, outFloor, out, false); 285 } catch (Exception e) { 286 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat4Float4Float4: " + e.toString()); 287 } 288 try { 289 Allocation outFloor = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 290 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 291 scriptRelaxed.set_gAllocOutFloor(outFloor); 292 scriptRelaxed.forEach_testFractFloat4Float4Float4(inV, out); 293 verifyResultsFractFloat4Float4Float4(inV, outFloor, out, true); 294 } catch (Exception e) { 295 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat4Float4Float4: " + e.toString()); 296 } 297 } 298 299 private void verifyResultsFractFloat4Float4Float4(Allocation inV, Allocation outFloor, Allocation out, boolean relaxed) { 300 float[] arrayInV = new float[INPUTSIZE * 4]; 301 inV.copyTo(arrayInV); 302 float[] arrayOutFloor = new float[INPUTSIZE * 4]; 303 outFloor.copyTo(arrayOutFloor); 304 float[] arrayOut = new float[INPUTSIZE * 4]; 305 out.copyTo(arrayOut); 306 for (int i = 0; i < INPUTSIZE; i++) { 307 for (int j = 0; j < 4 ; j++) { 308 // Extract the inputs. 309 ArgumentsFloatFloatFloat args = new ArgumentsFloatFloatFloat(); 310 args.inV = arrayInV[i * 4 + j]; 311 // Figure out what the outputs should have been. 312 Target target = new Target(relaxed); 313 CoreMathVerifier.computeFract(args, target); 314 // Validate the outputs. 315 boolean valid = true; 316 if (!args.outFloor.couldBe(arrayOutFloor[i * 4 + j])) { 317 valid = false; 318 } 319 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 320 valid = false; 321 } 322 if (!valid) { 323 StringBuilder message = new StringBuilder(); 324 message.append("Input inV: "); 325 message.append(String.format("%14.8g {%8x} %15a", 326 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 327 message.append("\n"); 328 message.append("Expected output outFloor: "); 329 message.append(args.outFloor.toString()); 330 message.append("\n"); 331 message.append("Actual output outFloor: "); 332 message.append(String.format("%14.8g {%8x} %15a", 333 arrayOutFloor[i * 4 + j], Float.floatToRawIntBits(arrayOutFloor[i * 4 + j]), arrayOutFloor[i * 4 + j])); 334 if (!args.outFloor.couldBe(arrayOutFloor[i * 4 + j])) { 335 message.append(" FAIL"); 336 } 337 message.append("\n"); 338 message.append("Expected output out: "); 339 message.append(args.out.toString()); 340 message.append("\n"); 341 message.append("Actual output out: "); 342 message.append(String.format("%14.8g {%8x} %15a", 343 arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); 344 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 345 message.append(" FAIL"); 346 } 347 message.append("\n"); 348 assertTrue("Incorrect output for checkFractFloat4Float4Float4" + 349 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 350 } 351 } 352 } 353 } 354 355 public class ArgumentsFloatFloat { 356 public float inV; 357 public Target.Floaty out; 358 } 359 360 private void checkFractFloatFloat() { 361 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xf559208b9db2cad3l, false); 362 try { 363 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 364 script.forEach_testFractFloatFloat(inV, out); 365 verifyResultsFractFloatFloat(inV, out, false); 366 } catch (Exception e) { 367 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloatFloat: " + e.toString()); 368 } 369 try { 370 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 371 scriptRelaxed.forEach_testFractFloatFloat(inV, out); 372 verifyResultsFractFloatFloat(inV, out, true); 373 } catch (Exception e) { 374 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloatFloat: " + e.toString()); 375 } 376 } 377 378 private void verifyResultsFractFloatFloat(Allocation inV, Allocation out, boolean relaxed) { 379 float[] arrayInV = new float[INPUTSIZE * 1]; 380 inV.copyTo(arrayInV); 381 float[] arrayOut = new float[INPUTSIZE * 1]; 382 out.copyTo(arrayOut); 383 for (int i = 0; i < INPUTSIZE; i++) { 384 for (int j = 0; j < 1 ; j++) { 385 // Extract the inputs. 386 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 387 args.inV = arrayInV[i]; 388 // Figure out what the outputs should have been. 389 Target target = new Target(relaxed); 390 CoreMathVerifier.computeFract(args, target); 391 // Validate the outputs. 392 boolean valid = true; 393 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 394 valid = false; 395 } 396 if (!valid) { 397 StringBuilder message = new StringBuilder(); 398 message.append("Input inV: "); 399 message.append(String.format("%14.8g {%8x} %15a", 400 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 401 message.append("\n"); 402 message.append("Expected output out: "); 403 message.append(args.out.toString()); 404 message.append("\n"); 405 message.append("Actual output out: "); 406 message.append(String.format("%14.8g {%8x} %15a", 407 arrayOut[i * 1 + j], Float.floatToRawIntBits(arrayOut[i * 1 + j]), arrayOut[i * 1 + j])); 408 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 409 message.append(" FAIL"); 410 } 411 message.append("\n"); 412 assertTrue("Incorrect output for checkFractFloatFloat" + 413 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 414 } 415 } 416 } 417 } 418 419 private void checkFractFloat2Float2() { 420 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x1096c5acc4d52edfl, false); 421 try { 422 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 423 script.forEach_testFractFloat2Float2(inV, out); 424 verifyResultsFractFloat2Float2(inV, out, false); 425 } catch (Exception e) { 426 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat2Float2: " + e.toString()); 427 } 428 try { 429 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 430 scriptRelaxed.forEach_testFractFloat2Float2(inV, out); 431 verifyResultsFractFloat2Float2(inV, out, true); 432 } catch (Exception e) { 433 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat2Float2: " + e.toString()); 434 } 435 } 436 437 private void verifyResultsFractFloat2Float2(Allocation inV, Allocation out, boolean relaxed) { 438 float[] arrayInV = new float[INPUTSIZE * 2]; 439 inV.copyTo(arrayInV); 440 float[] arrayOut = new float[INPUTSIZE * 2]; 441 out.copyTo(arrayOut); 442 for (int i = 0; i < INPUTSIZE; i++) { 443 for (int j = 0; j < 2 ; j++) { 444 // Extract the inputs. 445 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 446 args.inV = arrayInV[i * 2 + j]; 447 // Figure out what the outputs should have been. 448 Target target = new Target(relaxed); 449 CoreMathVerifier.computeFract(args, target); 450 // Validate the outputs. 451 boolean valid = true; 452 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 453 valid = false; 454 } 455 if (!valid) { 456 StringBuilder message = new StringBuilder(); 457 message.append("Input inV: "); 458 message.append(String.format("%14.8g {%8x} %15a", 459 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 460 message.append("\n"); 461 message.append("Expected output out: "); 462 message.append(args.out.toString()); 463 message.append("\n"); 464 message.append("Actual output out: "); 465 message.append(String.format("%14.8g {%8x} %15a", 466 arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j])); 467 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 468 message.append(" FAIL"); 469 } 470 message.append("\n"); 471 assertTrue("Incorrect output for checkFractFloat2Float2" + 472 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 473 } 474 } 475 } 476 } 477 478 private void checkFractFloat3Float3() { 479 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x10988ec7baf04fbdl, false); 480 try { 481 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 482 script.forEach_testFractFloat3Float3(inV, out); 483 verifyResultsFractFloat3Float3(inV, out, false); 484 } catch (Exception e) { 485 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat3Float3: " + e.toString()); 486 } 487 try { 488 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 489 scriptRelaxed.forEach_testFractFloat3Float3(inV, out); 490 verifyResultsFractFloat3Float3(inV, out, true); 491 } catch (Exception e) { 492 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat3Float3: " + e.toString()); 493 } 494 } 495 496 private void verifyResultsFractFloat3Float3(Allocation inV, Allocation out, boolean relaxed) { 497 float[] arrayInV = new float[INPUTSIZE * 4]; 498 inV.copyTo(arrayInV); 499 float[] arrayOut = new float[INPUTSIZE * 4]; 500 out.copyTo(arrayOut); 501 for (int i = 0; i < INPUTSIZE; i++) { 502 for (int j = 0; j < 3 ; j++) { 503 // Extract the inputs. 504 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 505 args.inV = arrayInV[i * 4 + j]; 506 // Figure out what the outputs should have been. 507 Target target = new Target(relaxed); 508 CoreMathVerifier.computeFract(args, target); 509 // Validate the outputs. 510 boolean valid = true; 511 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 512 valid = false; 513 } 514 if (!valid) { 515 StringBuilder message = new StringBuilder(); 516 message.append("Input inV: "); 517 message.append(String.format("%14.8g {%8x} %15a", 518 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 519 message.append("\n"); 520 message.append("Expected output out: "); 521 message.append(args.out.toString()); 522 message.append("\n"); 523 message.append("Actual output out: "); 524 message.append(String.format("%14.8g {%8x} %15a", 525 arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); 526 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 527 message.append(" FAIL"); 528 } 529 message.append("\n"); 530 assertTrue("Incorrect output for checkFractFloat3Float3" + 531 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 532 } 533 } 534 } 535 } 536 537 private void checkFractFloat4Float4() { 538 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x109a57e2b10b709bl, false); 539 try { 540 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 541 script.forEach_testFractFloat4Float4(inV, out); 542 verifyResultsFractFloat4Float4(inV, out, false); 543 } catch (Exception e) { 544 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat4Float4: " + e.toString()); 545 } 546 try { 547 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 548 scriptRelaxed.forEach_testFractFloat4Float4(inV, out); 549 verifyResultsFractFloat4Float4(inV, out, true); 550 } catch (Exception e) { 551 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testFractFloat4Float4: " + e.toString()); 552 } 553 } 554 555 private void verifyResultsFractFloat4Float4(Allocation inV, Allocation out, boolean relaxed) { 556 float[] arrayInV = new float[INPUTSIZE * 4]; 557 inV.copyTo(arrayInV); 558 float[] arrayOut = new float[INPUTSIZE * 4]; 559 out.copyTo(arrayOut); 560 for (int i = 0; i < INPUTSIZE; i++) { 561 for (int j = 0; j < 4 ; j++) { 562 // Extract the inputs. 563 ArgumentsFloatFloat args = new ArgumentsFloatFloat(); 564 args.inV = arrayInV[i * 4 + j]; 565 // Figure out what the outputs should have been. 566 Target target = new Target(relaxed); 567 CoreMathVerifier.computeFract(args, target); 568 // Validate the outputs. 569 boolean valid = true; 570 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 571 valid = false; 572 } 573 if (!valid) { 574 StringBuilder message = new StringBuilder(); 575 message.append("Input inV: "); 576 message.append(String.format("%14.8g {%8x} %15a", 577 args.inV, Float.floatToRawIntBits(args.inV), args.inV)); 578 message.append("\n"); 579 message.append("Expected output out: "); 580 message.append(args.out.toString()); 581 message.append("\n"); 582 message.append("Actual output out: "); 583 message.append(String.format("%14.8g {%8x} %15a", 584 arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j])); 585 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 586 message.append(" FAIL"); 587 } 588 message.append("\n"); 589 assertTrue("Incorrect output for checkFractFloat4Float4" + 590 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid); 591 } 592 } 593 } 594 } 595 596 public void testFract() { 597 checkFractFloatFloatFloat(); 598 checkFractFloat2Float2Float2(); 599 checkFractFloat3Float3Float3(); 600 checkFractFloat4Float4Float4(); 601 checkFractFloatFloat(); 602 checkFractFloat2Float2(); 603 checkFractFloat3Float3(); 604 checkFractFloat4Float4(); 605 } 606 } 607