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