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