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 TestLdexp extends RSBaseCompute { 29 30 private ScriptC_TestLdexp script; 31 private ScriptC_TestLdexpRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestLdexp(mRS); 37 scriptRelaxed = new ScriptC_TestLdexpRelaxed(mRS); 38 } 39 40 public class ArgumentsFloatIntFloat { 41 public float inMantissa; 42 public int inExponent; 43 public Target.Floaty out; 44 } 45 checkLdexpFloatIntFloat()46 private void checkLdexpFloatIntFloat() { 47 Allocation inMantissa = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x90f0e26fl, false); 48 Allocation inExponent = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0x2e4133c4l, false); 49 try { 50 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 51 script.set_gAllocInExponent(inExponent); 52 script.forEach_testLdexpFloatIntFloat(inMantissa, out); 53 verifyResultsLdexpFloatIntFloat(inMantissa, inExponent, out, false); 54 } catch (Exception e) { 55 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloatIntFloat: " + e.toString()); 56 } 57 try { 58 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 59 scriptRelaxed.set_gAllocInExponent(inExponent); 60 scriptRelaxed.forEach_testLdexpFloatIntFloat(inMantissa, out); 61 verifyResultsLdexpFloatIntFloat(inMantissa, inExponent, out, true); 62 } catch (Exception e) { 63 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloatIntFloat: " + e.toString()); 64 } 65 } 66 verifyResultsLdexpFloatIntFloat(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed)67 private void verifyResultsLdexpFloatIntFloat(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed) { 68 float[] arrayInMantissa = new float[INPUTSIZE * 1]; 69 Arrays.fill(arrayInMantissa, (float) 42); 70 inMantissa.copyTo(arrayInMantissa); 71 int[] arrayInExponent = new int[INPUTSIZE * 1]; 72 Arrays.fill(arrayInExponent, (int) 42); 73 inExponent.copyTo(arrayInExponent); 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 ArgumentsFloatIntFloat args = new ArgumentsFloatIntFloat(); 83 args.inMantissa = arrayInMantissa[i]; 84 args.inExponent = arrayInExponent[i]; 85 // Figure out what the outputs should have been. 86 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 87 CoreMathVerifier.computeLdexp(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 inMantissa: "); 97 appendVariableToMessage(message, args.inMantissa); 98 message.append("\n"); 99 message.append("Input inExponent: "); 100 appendVariableToMessage(message, args.inExponent); 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 checkLdexpFloatIntFloat" + 122 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 123 } 124 checkLdexpFloat2Int2Float2()125 private void checkLdexpFloat2Int2Float2() { 126 Allocation inMantissa = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x4fe92893l, false); 127 Allocation inExponent = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 2, 0xed3979e8l, false); 128 try { 129 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 130 script.set_gAllocInExponent(inExponent); 131 script.forEach_testLdexpFloat2Int2Float2(inMantissa, out); 132 verifyResultsLdexpFloat2Int2Float2(inMantissa, inExponent, out, false); 133 } catch (Exception e) { 134 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat2Int2Float2: " + e.toString()); 135 } 136 try { 137 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 138 scriptRelaxed.set_gAllocInExponent(inExponent); 139 scriptRelaxed.forEach_testLdexpFloat2Int2Float2(inMantissa, out); 140 verifyResultsLdexpFloat2Int2Float2(inMantissa, inExponent, out, true); 141 } catch (Exception e) { 142 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat2Int2Float2: " + e.toString()); 143 } 144 } 145 verifyResultsLdexpFloat2Int2Float2(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed)146 private void verifyResultsLdexpFloat2Int2Float2(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed) { 147 float[] arrayInMantissa = new float[INPUTSIZE * 2]; 148 Arrays.fill(arrayInMantissa, (float) 42); 149 inMantissa.copyTo(arrayInMantissa); 150 int[] arrayInExponent = new int[INPUTSIZE * 2]; 151 Arrays.fill(arrayInExponent, (int) 42); 152 inExponent.copyTo(arrayInExponent); 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 ArgumentsFloatIntFloat args = new ArgumentsFloatIntFloat(); 162 args.inMantissa = arrayInMantissa[i * 2 + j]; 163 args.inExponent = arrayInExponent[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.computeLdexp(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 inMantissa: "); 176 appendVariableToMessage(message, args.inMantissa); 177 message.append("\n"); 178 message.append("Input inExponent: "); 179 appendVariableToMessage(message, args.inExponent); 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 checkLdexpFloat2Int2Float2" + 201 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 202 } 203 checkLdexpFloat3Int3Float3()204 private void checkLdexpFloat3Int3Float3() { 205 Allocation inMantissa = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x3fa3335el, false); 206 Allocation inExponent = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 3, 0xdcf384b3l, false); 207 try { 208 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 209 script.set_gAllocInExponent(inExponent); 210 script.forEach_testLdexpFloat3Int3Float3(inMantissa, out); 211 verifyResultsLdexpFloat3Int3Float3(inMantissa, inExponent, out, false); 212 } catch (Exception e) { 213 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat3Int3Float3: " + e.toString()); 214 } 215 try { 216 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 217 scriptRelaxed.set_gAllocInExponent(inExponent); 218 scriptRelaxed.forEach_testLdexpFloat3Int3Float3(inMantissa, out); 219 verifyResultsLdexpFloat3Int3Float3(inMantissa, inExponent, out, true); 220 } catch (Exception e) { 221 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat3Int3Float3: " + e.toString()); 222 } 223 } 224 verifyResultsLdexpFloat3Int3Float3(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed)225 private void verifyResultsLdexpFloat3Int3Float3(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed) { 226 float[] arrayInMantissa = new float[INPUTSIZE * 4]; 227 Arrays.fill(arrayInMantissa, (float) 42); 228 inMantissa.copyTo(arrayInMantissa); 229 int[] arrayInExponent = new int[INPUTSIZE * 4]; 230 Arrays.fill(arrayInExponent, (int) 42); 231 inExponent.copyTo(arrayInExponent); 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 ArgumentsFloatIntFloat args = new ArgumentsFloatIntFloat(); 241 args.inMantissa = arrayInMantissa[i * 4 + j]; 242 args.inExponent = arrayInExponent[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.computeLdexp(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 inMantissa: "); 255 appendVariableToMessage(message, args.inMantissa); 256 message.append("\n"); 257 message.append("Input inExponent: "); 258 appendVariableToMessage(message, args.inExponent); 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 checkLdexpFloat3Int3Float3" + 280 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 281 } 282 checkLdexpFloat4Int4Float4()283 private void checkLdexpFloat4Int4Float4() { 284 Allocation inMantissa = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x2f5d3e29l, false); 285 Allocation inExponent = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 4, 0xccad8f7el, false); 286 try { 287 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 288 script.set_gAllocInExponent(inExponent); 289 script.forEach_testLdexpFloat4Int4Float4(inMantissa, out); 290 verifyResultsLdexpFloat4Int4Float4(inMantissa, inExponent, out, false); 291 } catch (Exception e) { 292 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat4Int4Float4: " + e.toString()); 293 } 294 try { 295 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 296 scriptRelaxed.set_gAllocInExponent(inExponent); 297 scriptRelaxed.forEach_testLdexpFloat4Int4Float4(inMantissa, out); 298 verifyResultsLdexpFloat4Int4Float4(inMantissa, inExponent, out, true); 299 } catch (Exception e) { 300 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat4Int4Float4: " + e.toString()); 301 } 302 } 303 verifyResultsLdexpFloat4Int4Float4(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed)304 private void verifyResultsLdexpFloat4Int4Float4(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed) { 305 float[] arrayInMantissa = new float[INPUTSIZE * 4]; 306 Arrays.fill(arrayInMantissa, (float) 42); 307 inMantissa.copyTo(arrayInMantissa); 308 int[] arrayInExponent = new int[INPUTSIZE * 4]; 309 Arrays.fill(arrayInExponent, (int) 42); 310 inExponent.copyTo(arrayInExponent); 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 ArgumentsFloatIntFloat args = new ArgumentsFloatIntFloat(); 320 args.inMantissa = arrayInMantissa[i * 4 + j]; 321 args.inExponent = arrayInExponent[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.computeLdexp(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 inMantissa: "); 334 appendVariableToMessage(message, args.inMantissa); 335 message.append("\n"); 336 message.append("Input inExponent: "); 337 appendVariableToMessage(message, args.inExponent); 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 checkLdexpFloat4Int4Float4" + 359 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 360 } 361 checkLdexpFloat2IntFloat2()362 private void checkLdexpFloat2IntFloat2() { 363 Allocation inMantissa = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x38bd38d1l, false); 364 Allocation inExponent = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0xd60d8a26l, false); 365 try { 366 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 367 script.set_gAllocInExponent(inExponent); 368 script.forEach_testLdexpFloat2IntFloat2(inMantissa, out); 369 verifyResultsLdexpFloat2IntFloat2(inMantissa, inExponent, out, false); 370 } catch (Exception e) { 371 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat2IntFloat2: " + e.toString()); 372 } 373 try { 374 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 375 scriptRelaxed.set_gAllocInExponent(inExponent); 376 scriptRelaxed.forEach_testLdexpFloat2IntFloat2(inMantissa, out); 377 verifyResultsLdexpFloat2IntFloat2(inMantissa, inExponent, out, true); 378 } catch (Exception e) { 379 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat2IntFloat2: " + e.toString()); 380 } 381 } 382 verifyResultsLdexpFloat2IntFloat2(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed)383 private void verifyResultsLdexpFloat2IntFloat2(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed) { 384 float[] arrayInMantissa = new float[INPUTSIZE * 2]; 385 Arrays.fill(arrayInMantissa, (float) 42); 386 inMantissa.copyTo(arrayInMantissa); 387 int[] arrayInExponent = new int[INPUTSIZE * 1]; 388 Arrays.fill(arrayInExponent, (int) 42); 389 inExponent.copyTo(arrayInExponent); 390 float[] arrayOut = new float[INPUTSIZE * 2]; 391 Arrays.fill(arrayOut, (float) 42); 392 out.copyTo(arrayOut); 393 StringBuilder message = new StringBuilder(); 394 boolean errorFound = false; 395 for (int i = 0; i < INPUTSIZE; i++) { 396 for (int j = 0; j < 2 ; j++) { 397 // Extract the inputs. 398 ArgumentsFloatIntFloat args = new ArgumentsFloatIntFloat(); 399 args.inMantissa = arrayInMantissa[i * 2 + j]; 400 args.inExponent = arrayInExponent[i]; 401 // Figure out what the outputs should have been. 402 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 403 CoreMathVerifier.computeLdexp(args, target); 404 // Validate the outputs. 405 boolean valid = true; 406 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 407 valid = false; 408 } 409 if (!valid) { 410 if (!errorFound) { 411 errorFound = true; 412 message.append("Input inMantissa: "); 413 appendVariableToMessage(message, args.inMantissa); 414 message.append("\n"); 415 message.append("Input inExponent: "); 416 appendVariableToMessage(message, args.inExponent); 417 message.append("\n"); 418 message.append("Expected output out: "); 419 appendVariableToMessage(message, args.out); 420 message.append("\n"); 421 message.append("Actual output out: "); 422 appendVariableToMessage(message, arrayOut[i * 2 + j]); 423 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 424 message.append(" FAIL"); 425 } 426 message.append("\n"); 427 message.append("Errors at"); 428 } 429 message.append(" ["); 430 message.append(Integer.toString(i)); 431 message.append(", "); 432 message.append(Integer.toString(j)); 433 message.append("]"); 434 } 435 } 436 } 437 assertFalse("Incorrect output for checkLdexpFloat2IntFloat2" + 438 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 439 } 440 checkLdexpFloat3IntFloat3()441 private void checkLdexpFloat3IntFloat3() { 442 Allocation inMantissa = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x5150f83dl, false); 443 Allocation inExponent = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0xeea14992l, false); 444 try { 445 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 446 script.set_gAllocInExponent(inExponent); 447 script.forEach_testLdexpFloat3IntFloat3(inMantissa, out); 448 verifyResultsLdexpFloat3IntFloat3(inMantissa, inExponent, out, false); 449 } catch (Exception e) { 450 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat3IntFloat3: " + e.toString()); 451 } 452 try { 453 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 454 scriptRelaxed.set_gAllocInExponent(inExponent); 455 scriptRelaxed.forEach_testLdexpFloat3IntFloat3(inMantissa, out); 456 verifyResultsLdexpFloat3IntFloat3(inMantissa, inExponent, out, true); 457 } catch (Exception e) { 458 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat3IntFloat3: " + e.toString()); 459 } 460 } 461 verifyResultsLdexpFloat3IntFloat3(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed)462 private void verifyResultsLdexpFloat3IntFloat3(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed) { 463 float[] arrayInMantissa = new float[INPUTSIZE * 4]; 464 Arrays.fill(arrayInMantissa, (float) 42); 465 inMantissa.copyTo(arrayInMantissa); 466 int[] arrayInExponent = new int[INPUTSIZE * 1]; 467 Arrays.fill(arrayInExponent, (int) 42); 468 inExponent.copyTo(arrayInExponent); 469 float[] arrayOut = new float[INPUTSIZE * 4]; 470 Arrays.fill(arrayOut, (float) 42); 471 out.copyTo(arrayOut); 472 StringBuilder message = new StringBuilder(); 473 boolean errorFound = false; 474 for (int i = 0; i < INPUTSIZE; i++) { 475 for (int j = 0; j < 3 ; j++) { 476 // Extract the inputs. 477 ArgumentsFloatIntFloat args = new ArgumentsFloatIntFloat(); 478 args.inMantissa = arrayInMantissa[i * 4 + j]; 479 args.inExponent = arrayInExponent[i]; 480 // Figure out what the outputs should have been. 481 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 482 CoreMathVerifier.computeLdexp(args, target); 483 // Validate the outputs. 484 boolean valid = true; 485 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 486 valid = false; 487 } 488 if (!valid) { 489 if (!errorFound) { 490 errorFound = true; 491 message.append("Input inMantissa: "); 492 appendVariableToMessage(message, args.inMantissa); 493 message.append("\n"); 494 message.append("Input inExponent: "); 495 appendVariableToMessage(message, args.inExponent); 496 message.append("\n"); 497 message.append("Expected output out: "); 498 appendVariableToMessage(message, args.out); 499 message.append("\n"); 500 message.append("Actual output out: "); 501 appendVariableToMessage(message, arrayOut[i * 4 + j]); 502 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 503 message.append(" FAIL"); 504 } 505 message.append("\n"); 506 message.append("Errors at"); 507 } 508 message.append(" ["); 509 message.append(Integer.toString(i)); 510 message.append(", "); 511 message.append(Integer.toString(j)); 512 message.append("]"); 513 } 514 } 515 } 516 assertFalse("Incorrect output for checkLdexpFloat3IntFloat3" + 517 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 518 } 519 checkLdexpFloat4IntFloat4()520 private void checkLdexpFloat4IntFloat4() { 521 Allocation inMantissa = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x69e4b7a9l, false); 522 Allocation inExponent = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0x73508fel, false); 523 try { 524 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 525 script.set_gAllocInExponent(inExponent); 526 script.forEach_testLdexpFloat4IntFloat4(inMantissa, out); 527 verifyResultsLdexpFloat4IntFloat4(inMantissa, inExponent, out, false); 528 } catch (Exception e) { 529 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat4IntFloat4: " + e.toString()); 530 } 531 try { 532 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 533 scriptRelaxed.set_gAllocInExponent(inExponent); 534 scriptRelaxed.forEach_testLdexpFloat4IntFloat4(inMantissa, out); 535 verifyResultsLdexpFloat4IntFloat4(inMantissa, inExponent, out, true); 536 } catch (Exception e) { 537 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLdexpFloat4IntFloat4: " + e.toString()); 538 } 539 } 540 verifyResultsLdexpFloat4IntFloat4(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed)541 private void verifyResultsLdexpFloat4IntFloat4(Allocation inMantissa, Allocation inExponent, Allocation out, boolean relaxed) { 542 float[] arrayInMantissa = new float[INPUTSIZE * 4]; 543 Arrays.fill(arrayInMantissa, (float) 42); 544 inMantissa.copyTo(arrayInMantissa); 545 int[] arrayInExponent = new int[INPUTSIZE * 1]; 546 Arrays.fill(arrayInExponent, (int) 42); 547 inExponent.copyTo(arrayInExponent); 548 float[] arrayOut = new float[INPUTSIZE * 4]; 549 Arrays.fill(arrayOut, (float) 42); 550 out.copyTo(arrayOut); 551 StringBuilder message = new StringBuilder(); 552 boolean errorFound = false; 553 for (int i = 0; i < INPUTSIZE; i++) { 554 for (int j = 0; j < 4 ; j++) { 555 // Extract the inputs. 556 ArgumentsFloatIntFloat args = new ArgumentsFloatIntFloat(); 557 args.inMantissa = arrayInMantissa[i * 4 + j]; 558 args.inExponent = arrayInExponent[i]; 559 // Figure out what the outputs should have been. 560 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 561 CoreMathVerifier.computeLdexp(args, target); 562 // Validate the outputs. 563 boolean valid = true; 564 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 565 valid = false; 566 } 567 if (!valid) { 568 if (!errorFound) { 569 errorFound = true; 570 message.append("Input inMantissa: "); 571 appendVariableToMessage(message, args.inMantissa); 572 message.append("\n"); 573 message.append("Input inExponent: "); 574 appendVariableToMessage(message, args.inExponent); 575 message.append("\n"); 576 message.append("Expected output out: "); 577 appendVariableToMessage(message, args.out); 578 message.append("\n"); 579 message.append("Actual output out: "); 580 appendVariableToMessage(message, arrayOut[i * 4 + j]); 581 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 582 message.append(" FAIL"); 583 } 584 message.append("\n"); 585 message.append("Errors at"); 586 } 587 message.append(" ["); 588 message.append(Integer.toString(i)); 589 message.append(", "); 590 message.append(Integer.toString(j)); 591 message.append("]"); 592 } 593 } 594 } 595 assertFalse("Incorrect output for checkLdexpFloat4IntFloat4" + 596 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 597 } 598 testLdexp()599 public void testLdexp() { 600 checkLdexpFloatIntFloat(); 601 checkLdexpFloat2Int2Float2(); 602 checkLdexpFloat3Int3Float3(); 603 checkLdexpFloat4Int4Float4(); 604 checkLdexpFloat2IntFloat2(); 605 checkLdexpFloat3IntFloat3(); 606 checkLdexpFloat4IntFloat4(); 607 } 608 } 609