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 TestLog10 extends RSBaseCompute { 29 30 private ScriptC_TestLog10 script; 31 private ScriptC_TestLog10Relaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestLog10(mRS); 37 scriptRelaxed = new ScriptC_TestLog10Relaxed(mRS); 38 } 39 40 public class ArgumentsFloatFloat { 41 public float inV; 42 public Target.Floaty out; 43 } 44 checkLog10FloatFloat()45 private void checkLog10FloatFloat() { 46 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x3171d836l, false); 47 try { 48 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 49 script.forEach_testLog10FloatFloat(inV, out); 50 verifyResultsLog10FloatFloat(inV, out, false); 51 } catch (Exception e) { 52 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10FloatFloat: " + e.toString()); 53 } 54 try { 55 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 56 scriptRelaxed.forEach_testLog10FloatFloat(inV, out); 57 verifyResultsLog10FloatFloat(inV, out, true); 58 } catch (Exception e) { 59 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10FloatFloat: " + e.toString()); 60 } 61 } 62 verifyResultsLog10FloatFloat(Allocation inV, Allocation out, boolean relaxed)63 private void verifyResultsLog10FloatFloat(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.computeLog10(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 checkLog10FloatFloat" + 111 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 112 } 113 checkLog10Float2Float2()114 private void checkLog10Float2Float2() { 115 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xe3bcdeeal, false); 116 try { 117 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 118 script.forEach_testLog10Float2Float2(inV, out); 119 verifyResultsLog10Float2Float2(inV, out, false); 120 } catch (Exception e) { 121 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Float2Float2: " + e.toString()); 122 } 123 try { 124 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 125 scriptRelaxed.forEach_testLog10Float2Float2(inV, out); 126 verifyResultsLog10Float2Float2(inV, out, true); 127 } catch (Exception e) { 128 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Float2Float2: " + e.toString()); 129 } 130 } 131 verifyResultsLog10Float2Float2(Allocation inV, Allocation out, boolean relaxed)132 private void verifyResultsLog10Float2Float2(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.computeLog10(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 checkLog10Float2Float2" + 180 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 181 } 182 checkLog10Float3Float3()183 private void checkLog10Float3Float3() { 184 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xd9d7ffc8l, false); 185 try { 186 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 187 script.forEach_testLog10Float3Float3(inV, out); 188 verifyResultsLog10Float3Float3(inV, out, false); 189 } catch (Exception e) { 190 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Float3Float3: " + e.toString()); 191 } 192 try { 193 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 194 scriptRelaxed.forEach_testLog10Float3Float3(inV, out); 195 verifyResultsLog10Float3Float3(inV, out, true); 196 } catch (Exception e) { 197 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Float3Float3: " + e.toString()); 198 } 199 } 200 verifyResultsLog10Float3Float3(Allocation inV, Allocation out, boolean relaxed)201 private void verifyResultsLog10Float3Float3(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.computeLog10(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 checkLog10Float3Float3" + 249 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 250 } 251 checkLog10Float4Float4()252 private void checkLog10Float4Float4() { 253 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xcff320a6l, false); 254 try { 255 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 256 script.forEach_testLog10Float4Float4(inV, out); 257 verifyResultsLog10Float4Float4(inV, out, false); 258 } catch (Exception e) { 259 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Float4Float4: " + e.toString()); 260 } 261 try { 262 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 263 scriptRelaxed.forEach_testLog10Float4Float4(inV, out); 264 verifyResultsLog10Float4Float4(inV, out, true); 265 } catch (Exception e) { 266 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Float4Float4: " + e.toString()); 267 } 268 } 269 verifyResultsLog10Float4Float4(Allocation inV, Allocation out, boolean relaxed)270 private void verifyResultsLog10Float4Float4(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.computeLog10(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 checkLog10Float4Float4" + 318 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 319 } 320 321 public class ArgumentsHalfHalf { 322 public short inV; 323 public double inVDouble; 324 public Target.Floaty out; 325 } 326 checkLog10HalfHalf()327 private void checkLog10HalfHalf() { 328 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xdd61cbd0l, false); 329 try { 330 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 331 script.forEach_testLog10HalfHalf(inV, out); 332 verifyResultsLog10HalfHalf(inV, out, false); 333 } catch (Exception e) { 334 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10HalfHalf: " + e.toString()); 335 } 336 try { 337 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 338 scriptRelaxed.forEach_testLog10HalfHalf(inV, out); 339 verifyResultsLog10HalfHalf(inV, out, true); 340 } catch (Exception e) { 341 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10HalfHalf: " + e.toString()); 342 } 343 } 344 verifyResultsLog10HalfHalf(Allocation inV, Allocation out, boolean relaxed)345 private void verifyResultsLog10HalfHalf(Allocation inV, Allocation out, boolean relaxed) { 346 short[] arrayInV = new short[INPUTSIZE * 1]; 347 Arrays.fill(arrayInV, (short) 42); 348 inV.copyTo(arrayInV); 349 short[] arrayOut = new short[INPUTSIZE * 1]; 350 Arrays.fill(arrayOut, (short) 42); 351 out.copyTo(arrayOut); 352 StringBuilder message = new StringBuilder(); 353 boolean errorFound = false; 354 for (int i = 0; i < INPUTSIZE; i++) { 355 for (int j = 0; j < 1 ; j++) { 356 // Extract the inputs. 357 ArgumentsHalfHalf args = new ArgumentsHalfHalf(); 358 args.inV = arrayInV[i]; 359 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 360 // Figure out what the outputs should have been. 361 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 362 CoreMathVerifier.computeLog10(args, target); 363 // Validate the outputs. 364 boolean valid = true; 365 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 366 valid = false; 367 } 368 if (!valid) { 369 if (!errorFound) { 370 errorFound = true; 371 message.append("Input inV: "); 372 appendVariableToMessage(message, args.inV); 373 message.append("\n"); 374 message.append("Expected output out: "); 375 appendVariableToMessage(message, args.out); 376 message.append("\n"); 377 message.append("Actual output out: "); 378 appendVariableToMessage(message, arrayOut[i * 1 + j]); 379 message.append("\n"); 380 message.append("Actual output out (in double): "); 381 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j])); 382 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 383 message.append(" FAIL"); 384 } 385 message.append("\n"); 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 checkLog10HalfHalf" + 397 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 398 } 399 checkLog10Half2Half2()400 private void checkLog10Half2Half2() { 401 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x9e901f72l, false); 402 try { 403 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 404 script.forEach_testLog10Half2Half2(inV, out); 405 verifyResultsLog10Half2Half2(inV, out, false); 406 } catch (Exception e) { 407 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Half2Half2: " + e.toString()); 408 } 409 try { 410 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 411 scriptRelaxed.forEach_testLog10Half2Half2(inV, out); 412 verifyResultsLog10Half2Half2(inV, out, true); 413 } catch (Exception e) { 414 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Half2Half2: " + e.toString()); 415 } 416 } 417 verifyResultsLog10Half2Half2(Allocation inV, Allocation out, boolean relaxed)418 private void verifyResultsLog10Half2Half2(Allocation inV, Allocation out, boolean relaxed) { 419 short[] arrayInV = new short[INPUTSIZE * 2]; 420 Arrays.fill(arrayInV, (short) 42); 421 inV.copyTo(arrayInV); 422 short[] arrayOut = new short[INPUTSIZE * 2]; 423 Arrays.fill(arrayOut, (short) 42); 424 out.copyTo(arrayOut); 425 StringBuilder message = new StringBuilder(); 426 boolean errorFound = false; 427 for (int i = 0; i < INPUTSIZE; i++) { 428 for (int j = 0; j < 2 ; j++) { 429 // Extract the inputs. 430 ArgumentsHalfHalf args = new ArgumentsHalfHalf(); 431 args.inV = arrayInV[i * 2 + j]; 432 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 433 // Figure out what the outputs should have been. 434 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 435 CoreMathVerifier.computeLog10(args, target); 436 // Validate the outputs. 437 boolean valid = true; 438 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 439 valid = false; 440 } 441 if (!valid) { 442 if (!errorFound) { 443 errorFound = true; 444 message.append("Input inV: "); 445 appendVariableToMessage(message, args.inV); 446 message.append("\n"); 447 message.append("Expected output out: "); 448 appendVariableToMessage(message, args.out); 449 message.append("\n"); 450 message.append("Actual output out: "); 451 appendVariableToMessage(message, arrayOut[i * 2 + j]); 452 message.append("\n"); 453 message.append("Actual output out (in double): "); 454 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j])); 455 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 456 message.append(" FAIL"); 457 } 458 message.append("\n"); 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 checkLog10Half2Half2" + 470 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 471 } 472 checkLog10Half3Half3()473 private void checkLog10Half3Half3() { 474 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xfd97e466l, false); 475 try { 476 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 477 script.forEach_testLog10Half3Half3(inV, out); 478 verifyResultsLog10Half3Half3(inV, out, false); 479 } catch (Exception e) { 480 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Half3Half3: " + e.toString()); 481 } 482 try { 483 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 484 scriptRelaxed.forEach_testLog10Half3Half3(inV, out); 485 verifyResultsLog10Half3Half3(inV, out, true); 486 } catch (Exception e) { 487 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Half3Half3: " + e.toString()); 488 } 489 } 490 verifyResultsLog10Half3Half3(Allocation inV, Allocation out, boolean relaxed)491 private void verifyResultsLog10Half3Half3(Allocation inV, Allocation out, boolean relaxed) { 492 short[] arrayInV = new short[INPUTSIZE * 4]; 493 Arrays.fill(arrayInV, (short) 42); 494 inV.copyTo(arrayInV); 495 short[] arrayOut = new short[INPUTSIZE * 4]; 496 Arrays.fill(arrayOut, (short) 42); 497 out.copyTo(arrayOut); 498 StringBuilder message = new StringBuilder(); 499 boolean errorFound = false; 500 for (int i = 0; i < INPUTSIZE; i++) { 501 for (int j = 0; j < 3 ; j++) { 502 // Extract the inputs. 503 ArgumentsHalfHalf args = new ArgumentsHalfHalf(); 504 args.inV = arrayInV[i * 4 + j]; 505 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 506 // Figure out what the outputs should have been. 507 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 508 CoreMathVerifier.computeLog10(args, target); 509 // Validate the outputs. 510 boolean valid = true; 511 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 512 valid = false; 513 } 514 if (!valid) { 515 if (!errorFound) { 516 errorFound = true; 517 message.append("Input inV: "); 518 appendVariableToMessage(message, args.inV); 519 message.append("\n"); 520 message.append("Expected output out: "); 521 appendVariableToMessage(message, args.out); 522 message.append("\n"); 523 message.append("Actual output out: "); 524 appendVariableToMessage(message, arrayOut[i * 4 + j]); 525 message.append("\n"); 526 message.append("Actual output out (in double): "); 527 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 528 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 529 message.append(" FAIL"); 530 } 531 message.append("\n"); 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 checkLog10Half3Half3" + 543 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 544 } 545 checkLog10Half4Half4()546 private void checkLog10Half4Half4() { 547 Allocation inV = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x5c9fa95al, false); 548 try { 549 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 550 script.forEach_testLog10Half4Half4(inV, out); 551 verifyResultsLog10Half4Half4(inV, out, false); 552 } catch (Exception e) { 553 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Half4Half4: " + e.toString()); 554 } 555 try { 556 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 557 scriptRelaxed.forEach_testLog10Half4Half4(inV, out); 558 verifyResultsLog10Half4Half4(inV, out, true); 559 } catch (Exception e) { 560 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testLog10Half4Half4: " + e.toString()); 561 } 562 } 563 verifyResultsLog10Half4Half4(Allocation inV, Allocation out, boolean relaxed)564 private void verifyResultsLog10Half4Half4(Allocation inV, Allocation out, boolean relaxed) { 565 short[] arrayInV = new short[INPUTSIZE * 4]; 566 Arrays.fill(arrayInV, (short) 42); 567 inV.copyTo(arrayInV); 568 short[] arrayOut = new short[INPUTSIZE * 4]; 569 Arrays.fill(arrayOut, (short) 42); 570 out.copyTo(arrayOut); 571 StringBuilder message = new StringBuilder(); 572 boolean errorFound = false; 573 for (int i = 0; i < INPUTSIZE; i++) { 574 for (int j = 0; j < 4 ; j++) { 575 // Extract the inputs. 576 ArgumentsHalfHalf args = new ArgumentsHalfHalf(); 577 args.inV = arrayInV[i * 4 + j]; 578 args.inVDouble = Float16Utils.convertFloat16ToDouble(args.inV); 579 // Figure out what the outputs should have been. 580 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 581 CoreMathVerifier.computeLog10(args, target); 582 // Validate the outputs. 583 boolean valid = true; 584 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 585 valid = false; 586 } 587 if (!valid) { 588 if (!errorFound) { 589 errorFound = true; 590 message.append("Input inV: "); 591 appendVariableToMessage(message, args.inV); 592 message.append("\n"); 593 message.append("Expected output out: "); 594 appendVariableToMessage(message, args.out); 595 message.append("\n"); 596 message.append("Actual output out: "); 597 appendVariableToMessage(message, arrayOut[i * 4 + j]); 598 message.append("\n"); 599 message.append("Actual output out (in double): "); 600 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 601 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 602 message.append(" FAIL"); 603 } 604 message.append("\n"); 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 checkLog10Half4Half4" + 616 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 617 } 618 testLog10()619 public void testLog10() { 620 checkLog10FloatFloat(); 621 checkLog10Float2Float2(); 622 checkLog10Float3Float3(); 623 checkLog10Float4Float4(); 624 checkLog10HalfHalf(); 625 checkLog10Half2Half2(); 626 checkLog10Half3Half3(); 627 checkLog10Half4Half4(); 628 } 629 } 630