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 TestClamp extends RSBaseCompute { 29 30 private ScriptC_TestClamp script; 31 private ScriptC_TestClampRelaxed scriptRelaxed; 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 script = new ScriptC_TestClamp(mRS); 37 scriptRelaxed = new ScriptC_TestClampRelaxed(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 ArgumentsFloatFloatFloatFloat { 48 public float inValue; 49 public float inMinValue; 50 public float inMaxValue; 51 public Target.Floaty out; 52 } 53 checkClampFloatFloatFloatFloat()54 private void checkClampFloatFloatFloatFloat() { 55 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x7e886d7cc83c447dl, false); 56 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xdcebf6f230234027l, false); 57 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0xdcebf6e6c180322dl, false); 58 enforceOrdering(inMinValue, inMaxValue); 59 try { 60 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 61 script.set_gAllocInMinValue(inMinValue); 62 script.set_gAllocInMaxValue(inMaxValue); 63 script.forEach_testClampFloatFloatFloatFloat(inValue, out); 64 verifyResultsClampFloatFloatFloatFloat(inValue, inMinValue, inMaxValue, out, false); 65 out.destroy(); 66 } catch (Exception e) { 67 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloatFloatFloatFloat: " + e.toString()); 68 } 69 try { 70 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 1), INPUTSIZE); 71 scriptRelaxed.set_gAllocInMinValue(inMinValue); 72 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 73 scriptRelaxed.forEach_testClampFloatFloatFloatFloat(inValue, out); 74 verifyResultsClampFloatFloatFloatFloat(inValue, inMinValue, inMaxValue, out, true); 75 out.destroy(); 76 } catch (Exception e) { 77 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloatFloatFloatFloat: " + e.toString()); 78 } 79 inValue.destroy(); 80 inMinValue.destroy(); 81 inMaxValue.destroy(); 82 } 83 verifyResultsClampFloatFloatFloatFloat(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)84 private void verifyResultsClampFloatFloatFloatFloat(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 85 float[] arrayInValue = new float[INPUTSIZE * 1]; 86 Arrays.fill(arrayInValue, (float) 42); 87 inValue.copyTo(arrayInValue); 88 float[] arrayInMinValue = new float[INPUTSIZE * 1]; 89 Arrays.fill(arrayInMinValue, (float) 42); 90 inMinValue.copyTo(arrayInMinValue); 91 float[] arrayInMaxValue = new float[INPUTSIZE * 1]; 92 Arrays.fill(arrayInMaxValue, (float) 42); 93 inMaxValue.copyTo(arrayInMaxValue); 94 float[] arrayOut = new float[INPUTSIZE * 1]; 95 Arrays.fill(arrayOut, (float) 42); 96 out.copyTo(arrayOut); 97 StringBuilder message = new StringBuilder(); 98 boolean errorFound = false; 99 for (int i = 0; i < INPUTSIZE; i++) { 100 for (int j = 0; j < 1 ; j++) { 101 // Extract the inputs. 102 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); 103 args.inValue = arrayInValue[i]; 104 args.inMinValue = arrayInMinValue[i]; 105 args.inMaxValue = arrayInMaxValue[i]; 106 // Figure out what the outputs should have been. 107 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 108 CoreMathVerifier.computeClamp(args, target); 109 // Validate the outputs. 110 boolean valid = true; 111 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 112 valid = false; 113 } 114 if (!valid) { 115 if (!errorFound) { 116 errorFound = true; 117 message.append("Input inValue: "); 118 appendVariableToMessage(message, args.inValue); 119 message.append("\n"); 120 message.append("Input inMinValue: "); 121 appendVariableToMessage(message, args.inMinValue); 122 message.append("\n"); 123 message.append("Input inMaxValue: "); 124 appendVariableToMessage(message, args.inMaxValue); 125 message.append("\n"); 126 message.append("Expected output out: "); 127 appendVariableToMessage(message, args.out); 128 message.append("\n"); 129 message.append("Actual output out: "); 130 appendVariableToMessage(message, arrayOut[i * 1 + j]); 131 if (!args.out.couldBe(arrayOut[i * 1 + j])) { 132 message.append(" FAIL"); 133 } 134 message.append("\n"); 135 message.append("Errors at"); 136 } 137 message.append(" ["); 138 message.append(Integer.toString(i)); 139 message.append(", "); 140 message.append(Integer.toString(j)); 141 message.append("]"); 142 } 143 } 144 } 145 assertFalse("Incorrect output for checkClampFloatFloatFloatFloat" + 146 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 147 } 148 checkClampFloat2Float2Float2Float2()149 private void checkClampFloat2Float2Float2Float2() { 150 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xa0d28bf142b07a5l, false); 151 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xb4e5c5f6ea8fc01fl, false); 152 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xb4e5c5eb7becb225l, false); 153 enforceOrdering(inMinValue, inMaxValue); 154 try { 155 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 156 script.set_gAllocInMinValue(inMinValue); 157 script.set_gAllocInMaxValue(inMaxValue); 158 script.forEach_testClampFloat2Float2Float2Float2(inValue, out); 159 verifyResultsClampFloat2Float2Float2Float2(inValue, inMinValue, inMaxValue, out, false); 160 out.destroy(); 161 } catch (Exception e) { 162 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat2Float2Float2Float2: " + e.toString()); 163 } 164 try { 165 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 166 scriptRelaxed.set_gAllocInMinValue(inMinValue); 167 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 168 scriptRelaxed.forEach_testClampFloat2Float2Float2Float2(inValue, out); 169 verifyResultsClampFloat2Float2Float2Float2(inValue, inMinValue, inMaxValue, out, true); 170 out.destroy(); 171 } catch (Exception e) { 172 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat2Float2Float2Float2: " + e.toString()); 173 } 174 inValue.destroy(); 175 inMinValue.destroy(); 176 inMaxValue.destroy(); 177 } 178 verifyResultsClampFloat2Float2Float2Float2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)179 private void verifyResultsClampFloat2Float2Float2Float2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 180 float[] arrayInValue = new float[INPUTSIZE * 2]; 181 Arrays.fill(arrayInValue, (float) 42); 182 inValue.copyTo(arrayInValue); 183 float[] arrayInMinValue = new float[INPUTSIZE * 2]; 184 Arrays.fill(arrayInMinValue, (float) 42); 185 inMinValue.copyTo(arrayInMinValue); 186 float[] arrayInMaxValue = new float[INPUTSIZE * 2]; 187 Arrays.fill(arrayInMaxValue, (float) 42); 188 inMaxValue.copyTo(arrayInMaxValue); 189 float[] arrayOut = new float[INPUTSIZE * 2]; 190 Arrays.fill(arrayOut, (float) 42); 191 out.copyTo(arrayOut); 192 StringBuilder message = new StringBuilder(); 193 boolean errorFound = false; 194 for (int i = 0; i < INPUTSIZE; i++) { 195 for (int j = 0; j < 2 ; j++) { 196 // Extract the inputs. 197 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); 198 args.inValue = arrayInValue[i * 2 + j]; 199 args.inMinValue = arrayInMinValue[i * 2 + j]; 200 args.inMaxValue = arrayInMaxValue[i * 2 + j]; 201 // Figure out what the outputs should have been. 202 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 203 CoreMathVerifier.computeClamp(args, target); 204 // Validate the outputs. 205 boolean valid = true; 206 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 207 valid = false; 208 } 209 if (!valid) { 210 if (!errorFound) { 211 errorFound = true; 212 message.append("Input inValue: "); 213 appendVariableToMessage(message, args.inValue); 214 message.append("\n"); 215 message.append("Input inMinValue: "); 216 appendVariableToMessage(message, args.inMinValue); 217 message.append("\n"); 218 message.append("Input inMaxValue: "); 219 appendVariableToMessage(message, args.inMaxValue); 220 message.append("\n"); 221 message.append("Expected output out: "); 222 appendVariableToMessage(message, args.out); 223 message.append("\n"); 224 message.append("Actual output out: "); 225 appendVariableToMessage(message, arrayOut[i * 2 + j]); 226 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 227 message.append(" FAIL"); 228 } 229 message.append("\n"); 230 message.append("Errors at"); 231 } 232 message.append(" ["); 233 message.append(Integer.toString(i)); 234 message.append(", "); 235 message.append(Integer.toString(j)); 236 message.append("]"); 237 } 238 } 239 } 240 assertFalse("Incorrect output for checkClampFloat2Float2Float2Float2" + 241 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 242 } 243 checkClampFloat3Float3Float3Float3()244 private void checkClampFloat3Float3Float3Float3() { 245 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xd3716a4730ad7481l, false); 246 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xc0d239a53946aa73l, false); 247 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xc0d23999caa39c79l, false); 248 enforceOrdering(inMinValue, inMaxValue); 249 try { 250 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 251 script.set_gAllocInMinValue(inMinValue); 252 script.set_gAllocInMaxValue(inMaxValue); 253 script.forEach_testClampFloat3Float3Float3Float3(inValue, out); 254 verifyResultsClampFloat3Float3Float3Float3(inValue, inMinValue, inMaxValue, out, false); 255 out.destroy(); 256 } catch (Exception e) { 257 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat3Float3Float3Float3: " + e.toString()); 258 } 259 try { 260 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 261 scriptRelaxed.set_gAllocInMinValue(inMinValue); 262 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 263 scriptRelaxed.forEach_testClampFloat3Float3Float3Float3(inValue, out); 264 verifyResultsClampFloat3Float3Float3Float3(inValue, inMinValue, inMaxValue, out, true); 265 out.destroy(); 266 } catch (Exception e) { 267 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat3Float3Float3Float3: " + e.toString()); 268 } 269 inValue.destroy(); 270 inMinValue.destroy(); 271 inMaxValue.destroy(); 272 } 273 verifyResultsClampFloat3Float3Float3Float3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)274 private void verifyResultsClampFloat3Float3Float3Float3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 275 float[] arrayInValue = new float[INPUTSIZE * 4]; 276 Arrays.fill(arrayInValue, (float) 42); 277 inValue.copyTo(arrayInValue); 278 float[] arrayInMinValue = new float[INPUTSIZE * 4]; 279 Arrays.fill(arrayInMinValue, (float) 42); 280 inMinValue.copyTo(arrayInMinValue); 281 float[] arrayInMaxValue = new float[INPUTSIZE * 4]; 282 Arrays.fill(arrayInMaxValue, (float) 42); 283 inMaxValue.copyTo(arrayInMaxValue); 284 float[] arrayOut = new float[INPUTSIZE * 4]; 285 Arrays.fill(arrayOut, (float) 42); 286 out.copyTo(arrayOut); 287 StringBuilder message = new StringBuilder(); 288 boolean errorFound = false; 289 for (int i = 0; i < INPUTSIZE; i++) { 290 for (int j = 0; j < 3 ; j++) { 291 // Extract the inputs. 292 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); 293 args.inValue = arrayInValue[i * 4 + j]; 294 args.inMinValue = arrayInMinValue[i * 4 + j]; 295 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 296 // Figure out what the outputs should have been. 297 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 298 CoreMathVerifier.computeClamp(args, target); 299 // Validate the outputs. 300 boolean valid = true; 301 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 302 valid = false; 303 } 304 if (!valid) { 305 if (!errorFound) { 306 errorFound = true; 307 message.append("Input inValue: "); 308 appendVariableToMessage(message, args.inValue); 309 message.append("\n"); 310 message.append("Input inMinValue: "); 311 appendVariableToMessage(message, args.inMinValue); 312 message.append("\n"); 313 message.append("Input inMaxValue: "); 314 appendVariableToMessage(message, args.inMaxValue); 315 message.append("\n"); 316 message.append("Expected output out: "); 317 appendVariableToMessage(message, args.out); 318 message.append("\n"); 319 message.append("Actual output out: "); 320 appendVariableToMessage(message, arrayOut[i * 4 + j]); 321 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 322 message.append(" FAIL"); 323 } 324 message.append("\n"); 325 message.append("Errors at"); 326 } 327 message.append(" ["); 328 message.append(Integer.toString(i)); 329 message.append(", "); 330 message.append(Integer.toString(j)); 331 message.append("]"); 332 } 333 } 334 } 335 assertFalse("Incorrect output for checkClampFloat3Float3Float3Float3" + 336 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 337 } 338 checkClampFloat4Float4Float4Float4()339 private void checkClampFloat4Float4Float4Float4() { 340 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x9cd5abcf4d2fe15dl, false); 341 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xccbead5387fd94c7l, false); 342 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xccbead48195a86cdl, false); 343 enforceOrdering(inMinValue, inMaxValue); 344 try { 345 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 346 script.set_gAllocInMinValue(inMinValue); 347 script.set_gAllocInMaxValue(inMaxValue); 348 script.forEach_testClampFloat4Float4Float4Float4(inValue, out); 349 verifyResultsClampFloat4Float4Float4Float4(inValue, inMinValue, inMaxValue, out, false); 350 out.destroy(); 351 } catch (Exception e) { 352 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat4Float4Float4Float4: " + e.toString()); 353 } 354 try { 355 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 356 scriptRelaxed.set_gAllocInMinValue(inMinValue); 357 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 358 scriptRelaxed.forEach_testClampFloat4Float4Float4Float4(inValue, out); 359 verifyResultsClampFloat4Float4Float4Float4(inValue, inMinValue, inMaxValue, out, true); 360 out.destroy(); 361 } catch (Exception e) { 362 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat4Float4Float4Float4: " + e.toString()); 363 } 364 inValue.destroy(); 365 inMinValue.destroy(); 366 inMaxValue.destroy(); 367 } 368 verifyResultsClampFloat4Float4Float4Float4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)369 private void verifyResultsClampFloat4Float4Float4Float4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 370 float[] arrayInValue = new float[INPUTSIZE * 4]; 371 Arrays.fill(arrayInValue, (float) 42); 372 inValue.copyTo(arrayInValue); 373 float[] arrayInMinValue = new float[INPUTSIZE * 4]; 374 Arrays.fill(arrayInMinValue, (float) 42); 375 inMinValue.copyTo(arrayInMinValue); 376 float[] arrayInMaxValue = new float[INPUTSIZE * 4]; 377 Arrays.fill(arrayInMaxValue, (float) 42); 378 inMaxValue.copyTo(arrayInMaxValue); 379 float[] arrayOut = new float[INPUTSIZE * 4]; 380 Arrays.fill(arrayOut, (float) 42); 381 out.copyTo(arrayOut); 382 StringBuilder message = new StringBuilder(); 383 boolean errorFound = false; 384 for (int i = 0; i < INPUTSIZE; i++) { 385 for (int j = 0; j < 4 ; j++) { 386 // Extract the inputs. 387 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); 388 args.inValue = arrayInValue[i * 4 + j]; 389 args.inMinValue = arrayInMinValue[i * 4 + j]; 390 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 391 // Figure out what the outputs should have been. 392 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 393 CoreMathVerifier.computeClamp(args, target); 394 // Validate the outputs. 395 boolean valid = true; 396 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 397 valid = false; 398 } 399 if (!valid) { 400 if (!errorFound) { 401 errorFound = true; 402 message.append("Input inValue: "); 403 appendVariableToMessage(message, args.inValue); 404 message.append("\n"); 405 message.append("Input inMinValue: "); 406 appendVariableToMessage(message, args.inMinValue); 407 message.append("\n"); 408 message.append("Input inMaxValue: "); 409 appendVariableToMessage(message, args.inMaxValue); 410 message.append("\n"); 411 message.append("Expected output out: "); 412 appendVariableToMessage(message, args.out); 413 message.append("\n"); 414 message.append("Actual output out: "); 415 appendVariableToMessage(message, arrayOut[i * 4 + j]); 416 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 417 message.append(" FAIL"); 418 } 419 message.append("\n"); 420 message.append("Errors at"); 421 } 422 message.append(" ["); 423 message.append(Integer.toString(i)); 424 message.append(", "); 425 message.append(Integer.toString(j)); 426 message.append("]"); 427 } 428 } 429 } 430 assertFalse("Incorrect output for checkClampFloat4Float4Float4Float4" + 431 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 432 } 433 checkClampFloat2FloatFloatFloat2()434 private void checkClampFloat2FloatFloatFloat2() { 435 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x71623fb3f1fca1a1l, false); 436 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x148e792e1a6253d3l, false); 437 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x148e7922abbf45d9l, false); 438 enforceOrdering(inMinValue, inMaxValue); 439 try { 440 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 441 script.set_gAllocInMinValue(inMinValue); 442 script.set_gAllocInMaxValue(inMaxValue); 443 script.forEach_testClampFloat2FloatFloatFloat2(inValue, out); 444 verifyResultsClampFloat2FloatFloatFloat2(inValue, inMinValue, inMaxValue, out, false); 445 out.destroy(); 446 } catch (Exception e) { 447 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat2FloatFloatFloat2: " + e.toString()); 448 } 449 try { 450 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE); 451 scriptRelaxed.set_gAllocInMinValue(inMinValue); 452 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 453 scriptRelaxed.forEach_testClampFloat2FloatFloatFloat2(inValue, out); 454 verifyResultsClampFloat2FloatFloatFloat2(inValue, inMinValue, inMaxValue, out, true); 455 out.destroy(); 456 } catch (Exception e) { 457 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat2FloatFloatFloat2: " + e.toString()); 458 } 459 inValue.destroy(); 460 inMinValue.destroy(); 461 inMaxValue.destroy(); 462 } 463 verifyResultsClampFloat2FloatFloatFloat2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)464 private void verifyResultsClampFloat2FloatFloatFloat2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 465 float[] arrayInValue = new float[INPUTSIZE * 2]; 466 Arrays.fill(arrayInValue, (float) 42); 467 inValue.copyTo(arrayInValue); 468 float[] arrayInMinValue = new float[INPUTSIZE * 1]; 469 Arrays.fill(arrayInMinValue, (float) 42); 470 inMinValue.copyTo(arrayInMinValue); 471 float[] arrayInMaxValue = new float[INPUTSIZE * 1]; 472 Arrays.fill(arrayInMaxValue, (float) 42); 473 inMaxValue.copyTo(arrayInMaxValue); 474 float[] arrayOut = new float[INPUTSIZE * 2]; 475 Arrays.fill(arrayOut, (float) 42); 476 out.copyTo(arrayOut); 477 StringBuilder message = new StringBuilder(); 478 boolean errorFound = false; 479 for (int i = 0; i < INPUTSIZE; i++) { 480 for (int j = 0; j < 2 ; j++) { 481 // Extract the inputs. 482 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); 483 args.inValue = arrayInValue[i * 2 + j]; 484 args.inMinValue = arrayInMinValue[i]; 485 args.inMaxValue = arrayInMaxValue[i]; 486 // Figure out what the outputs should have been. 487 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 488 CoreMathVerifier.computeClamp(args, target); 489 // Validate the outputs. 490 boolean valid = true; 491 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 492 valid = false; 493 } 494 if (!valid) { 495 if (!errorFound) { 496 errorFound = true; 497 message.append("Input inValue: "); 498 appendVariableToMessage(message, args.inValue); 499 message.append("\n"); 500 message.append("Input inMinValue: "); 501 appendVariableToMessage(message, args.inMinValue); 502 message.append("\n"); 503 message.append("Input inMaxValue: "); 504 appendVariableToMessage(message, args.inMaxValue); 505 message.append("\n"); 506 message.append("Expected output out: "); 507 appendVariableToMessage(message, args.out); 508 message.append("\n"); 509 message.append("Actual output out: "); 510 appendVariableToMessage(message, arrayOut[i * 2 + j]); 511 if (!args.out.couldBe(arrayOut[i * 2 + j])) { 512 message.append(" FAIL"); 513 } 514 message.append("\n"); 515 message.append("Errors at"); 516 } 517 message.append(" ["); 518 message.append(Integer.toString(i)); 519 message.append(", "); 520 message.append(Integer.toString(j)); 521 message.append("]"); 522 } 523 } 524 } 525 assertFalse("Incorrect output for checkClampFloat2FloatFloatFloat2" + 526 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 527 } 528 checkClampFloat3FloatFloatFloat3()529 private void checkClampFloat3FloatFloatFloat3() { 530 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xc06893ff6ab8cf27l, false); 531 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x1f4444b84d90bbc5l, false); 532 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x1f4444acdeedadcbl, false); 533 enforceOrdering(inMinValue, inMaxValue); 534 try { 535 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 536 script.set_gAllocInMinValue(inMinValue); 537 script.set_gAllocInMaxValue(inMaxValue); 538 script.forEach_testClampFloat3FloatFloatFloat3(inValue, out); 539 verifyResultsClampFloat3FloatFloatFloat3(inValue, inMinValue, inMaxValue, out, false); 540 out.destroy(); 541 } catch (Exception e) { 542 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat3FloatFloatFloat3: " + e.toString()); 543 } 544 try { 545 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE); 546 scriptRelaxed.set_gAllocInMinValue(inMinValue); 547 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 548 scriptRelaxed.forEach_testClampFloat3FloatFloatFloat3(inValue, out); 549 verifyResultsClampFloat3FloatFloatFloat3(inValue, inMinValue, inMaxValue, out, true); 550 out.destroy(); 551 } catch (Exception e) { 552 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat3FloatFloatFloat3: " + e.toString()); 553 } 554 inValue.destroy(); 555 inMinValue.destroy(); 556 inMaxValue.destroy(); 557 } 558 verifyResultsClampFloat3FloatFloatFloat3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)559 private void verifyResultsClampFloat3FloatFloatFloat3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 560 float[] arrayInValue = new float[INPUTSIZE * 4]; 561 Arrays.fill(arrayInValue, (float) 42); 562 inValue.copyTo(arrayInValue); 563 float[] arrayInMinValue = new float[INPUTSIZE * 1]; 564 Arrays.fill(arrayInMinValue, (float) 42); 565 inMinValue.copyTo(arrayInMinValue); 566 float[] arrayInMaxValue = new float[INPUTSIZE * 1]; 567 Arrays.fill(arrayInMaxValue, (float) 42); 568 inMaxValue.copyTo(arrayInMaxValue); 569 float[] arrayOut = new float[INPUTSIZE * 4]; 570 Arrays.fill(arrayOut, (float) 42); 571 out.copyTo(arrayOut); 572 StringBuilder message = new StringBuilder(); 573 boolean errorFound = false; 574 for (int i = 0; i < INPUTSIZE; i++) { 575 for (int j = 0; j < 3 ; j++) { 576 // Extract the inputs. 577 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); 578 args.inValue = arrayInValue[i * 4 + j]; 579 args.inMinValue = arrayInMinValue[i]; 580 args.inMaxValue = arrayInMaxValue[i]; 581 // Figure out what the outputs should have been. 582 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 583 CoreMathVerifier.computeClamp(args, target); 584 // Validate the outputs. 585 boolean valid = true; 586 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 587 valid = false; 588 } 589 if (!valid) { 590 if (!errorFound) { 591 errorFound = true; 592 message.append("Input inValue: "); 593 appendVariableToMessage(message, args.inValue); 594 message.append("\n"); 595 message.append("Input inMinValue: "); 596 appendVariableToMessage(message, args.inMinValue); 597 message.append("\n"); 598 message.append("Input inMaxValue: "); 599 appendVariableToMessage(message, args.inMaxValue); 600 message.append("\n"); 601 message.append("Expected output out: "); 602 appendVariableToMessage(message, args.out); 603 message.append("\n"); 604 message.append("Actual output out: "); 605 appendVariableToMessage(message, arrayOut[i * 4 + j]); 606 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 607 message.append(" FAIL"); 608 } 609 message.append("\n"); 610 message.append("Errors at"); 611 } 612 message.append(" ["); 613 message.append(Integer.toString(i)); 614 message.append(", "); 615 message.append(Integer.toString(j)); 616 message.append("]"); 617 } 618 } 619 } 620 assertFalse("Incorrect output for checkClampFloat3FloatFloatFloat3" + 621 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 622 } 623 checkClampFloat4FloatFloatFloat4()624 private void checkClampFloat4FloatFloatFloat4() { 625 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xf6ee84ae374fcadl, false); 626 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x29fa104280bf23b7l, false); 627 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_32, 1, 0x29fa1037121c15bdl, false); 628 enforceOrdering(inMinValue, inMaxValue); 629 try { 630 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 631 script.set_gAllocInMinValue(inMinValue); 632 script.set_gAllocInMaxValue(inMaxValue); 633 script.forEach_testClampFloat4FloatFloatFloat4(inValue, out); 634 verifyResultsClampFloat4FloatFloatFloat4(inValue, inMinValue, inMaxValue, out, false); 635 out.destroy(); 636 } catch (Exception e) { 637 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat4FloatFloatFloat4: " + e.toString()); 638 } 639 try { 640 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE); 641 scriptRelaxed.set_gAllocInMinValue(inMinValue); 642 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 643 scriptRelaxed.forEach_testClampFloat4FloatFloatFloat4(inValue, out); 644 verifyResultsClampFloat4FloatFloatFloat4(inValue, inMinValue, inMaxValue, out, true); 645 out.destroy(); 646 } catch (Exception e) { 647 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampFloat4FloatFloatFloat4: " + e.toString()); 648 } 649 inValue.destroy(); 650 inMinValue.destroy(); 651 inMaxValue.destroy(); 652 } 653 verifyResultsClampFloat4FloatFloatFloat4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)654 private void verifyResultsClampFloat4FloatFloatFloat4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 655 float[] arrayInValue = new float[INPUTSIZE * 4]; 656 Arrays.fill(arrayInValue, (float) 42); 657 inValue.copyTo(arrayInValue); 658 float[] arrayInMinValue = new float[INPUTSIZE * 1]; 659 Arrays.fill(arrayInMinValue, (float) 42); 660 inMinValue.copyTo(arrayInMinValue); 661 float[] arrayInMaxValue = new float[INPUTSIZE * 1]; 662 Arrays.fill(arrayInMaxValue, (float) 42); 663 inMaxValue.copyTo(arrayInMaxValue); 664 float[] arrayOut = new float[INPUTSIZE * 4]; 665 Arrays.fill(arrayOut, (float) 42); 666 out.copyTo(arrayOut); 667 StringBuilder message = new StringBuilder(); 668 boolean errorFound = false; 669 for (int i = 0; i < INPUTSIZE; i++) { 670 for (int j = 0; j < 4 ; j++) { 671 // Extract the inputs. 672 ArgumentsFloatFloatFloatFloat args = new ArgumentsFloatFloatFloatFloat(); 673 args.inValue = arrayInValue[i * 4 + j]; 674 args.inMinValue = arrayInMinValue[i]; 675 args.inMaxValue = arrayInMaxValue[i]; 676 // Figure out what the outputs should have been. 677 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.FLOAT, relaxed); 678 CoreMathVerifier.computeClamp(args, target); 679 // Validate the outputs. 680 boolean valid = true; 681 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 682 valid = false; 683 } 684 if (!valid) { 685 if (!errorFound) { 686 errorFound = true; 687 message.append("Input inValue: "); 688 appendVariableToMessage(message, args.inValue); 689 message.append("\n"); 690 message.append("Input inMinValue: "); 691 appendVariableToMessage(message, args.inMinValue); 692 message.append("\n"); 693 message.append("Input inMaxValue: "); 694 appendVariableToMessage(message, args.inMaxValue); 695 message.append("\n"); 696 message.append("Expected output out: "); 697 appendVariableToMessage(message, args.out); 698 message.append("\n"); 699 message.append("Actual output out: "); 700 appendVariableToMessage(message, arrayOut[i * 4 + j]); 701 if (!args.out.couldBe(arrayOut[i * 4 + j])) { 702 message.append(" FAIL"); 703 } 704 message.append("\n"); 705 message.append("Errors at"); 706 } 707 message.append(" ["); 708 message.append(Integer.toString(i)); 709 message.append(", "); 710 message.append(Integer.toString(j)); 711 message.append("]"); 712 } 713 } 714 } 715 assertFalse("Incorrect output for checkClampFloat4FloatFloatFloat4" + 716 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 717 } 718 719 public class ArgumentsCharCharCharChar { 720 public byte inValue; 721 public byte inMinValue; 722 public byte inMaxValue; 723 public byte out; 724 } 725 checkClampCharCharCharChar()726 private void checkClampCharCharCharChar() { 727 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0xaec8640bb673cf75l, false); 728 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0x6379f7c3c505c8fl, false); 729 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0x6379f70cdad4e95l, false); 730 enforceOrdering(inMinValue, inMaxValue); 731 try { 732 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 1), INPUTSIZE); 733 script.set_gAllocInMinValue(inMinValue); 734 script.set_gAllocInMaxValue(inMaxValue); 735 script.forEach_testClampCharCharCharChar(inValue, out); 736 verifyResultsClampCharCharCharChar(inValue, inMinValue, inMaxValue, out, false); 737 out.destroy(); 738 } catch (Exception e) { 739 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampCharCharCharChar: " + e.toString()); 740 } 741 try { 742 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 1), INPUTSIZE); 743 scriptRelaxed.set_gAllocInMinValue(inMinValue); 744 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 745 scriptRelaxed.forEach_testClampCharCharCharChar(inValue, out); 746 verifyResultsClampCharCharCharChar(inValue, inMinValue, inMaxValue, out, true); 747 out.destroy(); 748 } catch (Exception e) { 749 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampCharCharCharChar: " + e.toString()); 750 } 751 inValue.destroy(); 752 inMinValue.destroy(); 753 inMaxValue.destroy(); 754 } 755 verifyResultsClampCharCharCharChar(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)756 private void verifyResultsClampCharCharCharChar(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 757 byte[] arrayInValue = new byte[INPUTSIZE * 1]; 758 Arrays.fill(arrayInValue, (byte) 42); 759 inValue.copyTo(arrayInValue); 760 byte[] arrayInMinValue = new byte[INPUTSIZE * 1]; 761 Arrays.fill(arrayInMinValue, (byte) 42); 762 inMinValue.copyTo(arrayInMinValue); 763 byte[] arrayInMaxValue = new byte[INPUTSIZE * 1]; 764 Arrays.fill(arrayInMaxValue, (byte) 42); 765 inMaxValue.copyTo(arrayInMaxValue); 766 byte[] arrayOut = new byte[INPUTSIZE * 1]; 767 Arrays.fill(arrayOut, (byte) 42); 768 out.copyTo(arrayOut); 769 StringBuilder message = new StringBuilder(); 770 boolean errorFound = false; 771 for (int i = 0; i < INPUTSIZE; i++) { 772 for (int j = 0; j < 1 ; j++) { 773 // Extract the inputs. 774 ArgumentsCharCharCharChar args = new ArgumentsCharCharCharChar(); 775 args.inValue = arrayInValue[i]; 776 args.inMinValue = arrayInMinValue[i]; 777 args.inMaxValue = arrayInMaxValue[i]; 778 // Figure out what the outputs should have been. 779 CoreMathVerifier.computeClamp(args); 780 // Validate the outputs. 781 boolean valid = true; 782 if (args.out != arrayOut[i * 1 + j]) { 783 valid = false; 784 } 785 if (!valid) { 786 if (!errorFound) { 787 errorFound = true; 788 message.append("Input inValue: "); 789 appendVariableToMessage(message, args.inValue); 790 message.append("\n"); 791 message.append("Input inMinValue: "); 792 appendVariableToMessage(message, args.inMinValue); 793 message.append("\n"); 794 message.append("Input inMaxValue: "); 795 appendVariableToMessage(message, args.inMaxValue); 796 message.append("\n"); 797 message.append("Expected output out: "); 798 appendVariableToMessage(message, args.out); 799 message.append("\n"); 800 message.append("Actual output out: "); 801 appendVariableToMessage(message, arrayOut[i * 1 + j]); 802 if (args.out != arrayOut[i * 1 + j]) { 803 message.append(" FAIL"); 804 } 805 message.append("\n"); 806 message.append("Errors at"); 807 } 808 message.append(" ["); 809 message.append(Integer.toString(i)); 810 message.append(", "); 811 message.append(Integer.toString(j)); 812 message.append("]"); 813 } 814 } 815 } 816 assertFalse("Incorrect output for checkClampCharCharCharChar" + 817 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 818 } 819 checkClampChar2Char2Char2Char2()820 private void checkClampChar2Char2Char2Char2() { 821 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xa209cfe6c3feb45dl, false); 822 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xed63d0ab3442bdc7l, false); 823 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xed63d09fc59fafcdl, false); 824 enforceOrdering(inMinValue, inMaxValue); 825 try { 826 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE); 827 script.set_gAllocInMinValue(inMinValue); 828 script.set_gAllocInMaxValue(inMaxValue); 829 script.forEach_testClampChar2Char2Char2Char2(inValue, out); 830 verifyResultsClampChar2Char2Char2Char2(inValue, inMinValue, inMaxValue, out, false); 831 out.destroy(); 832 } catch (Exception e) { 833 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar2Char2Char2Char2: " + e.toString()); 834 } 835 try { 836 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE); 837 scriptRelaxed.set_gAllocInMinValue(inMinValue); 838 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 839 scriptRelaxed.forEach_testClampChar2Char2Char2Char2(inValue, out); 840 verifyResultsClampChar2Char2Char2Char2(inValue, inMinValue, inMaxValue, out, true); 841 out.destroy(); 842 } catch (Exception e) { 843 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar2Char2Char2Char2: " + e.toString()); 844 } 845 inValue.destroy(); 846 inMinValue.destroy(); 847 inMaxValue.destroy(); 848 } 849 verifyResultsClampChar2Char2Char2Char2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)850 private void verifyResultsClampChar2Char2Char2Char2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 851 byte[] arrayInValue = new byte[INPUTSIZE * 2]; 852 Arrays.fill(arrayInValue, (byte) 42); 853 inValue.copyTo(arrayInValue); 854 byte[] arrayInMinValue = new byte[INPUTSIZE * 2]; 855 Arrays.fill(arrayInMinValue, (byte) 42); 856 inMinValue.copyTo(arrayInMinValue); 857 byte[] arrayInMaxValue = new byte[INPUTSIZE * 2]; 858 Arrays.fill(arrayInMaxValue, (byte) 42); 859 inMaxValue.copyTo(arrayInMaxValue); 860 byte[] arrayOut = new byte[INPUTSIZE * 2]; 861 Arrays.fill(arrayOut, (byte) 42); 862 out.copyTo(arrayOut); 863 StringBuilder message = new StringBuilder(); 864 boolean errorFound = false; 865 for (int i = 0; i < INPUTSIZE; i++) { 866 for (int j = 0; j < 2 ; j++) { 867 // Extract the inputs. 868 ArgumentsCharCharCharChar args = new ArgumentsCharCharCharChar(); 869 args.inValue = arrayInValue[i * 2 + j]; 870 args.inMinValue = arrayInMinValue[i * 2 + j]; 871 args.inMaxValue = arrayInMaxValue[i * 2 + j]; 872 // Figure out what the outputs should have been. 873 CoreMathVerifier.computeClamp(args); 874 // Validate the outputs. 875 boolean valid = true; 876 if (args.out != arrayOut[i * 2 + j]) { 877 valid = false; 878 } 879 if (!valid) { 880 if (!errorFound) { 881 errorFound = true; 882 message.append("Input inValue: "); 883 appendVariableToMessage(message, args.inValue); 884 message.append("\n"); 885 message.append("Input inMinValue: "); 886 appendVariableToMessage(message, args.inMinValue); 887 message.append("\n"); 888 message.append("Input inMaxValue: "); 889 appendVariableToMessage(message, args.inMaxValue); 890 message.append("\n"); 891 message.append("Expected output out: "); 892 appendVariableToMessage(message, args.out); 893 message.append("\n"); 894 message.append("Actual output out: "); 895 appendVariableToMessage(message, arrayOut[i * 2 + j]); 896 if (args.out != arrayOut[i * 2 + j]) { 897 message.append(" FAIL"); 898 } 899 message.append("\n"); 900 message.append("Errors at"); 901 } 902 message.append(" ["); 903 message.append(Integer.toString(i)); 904 message.append(", "); 905 message.append(Integer.toString(j)); 906 message.append("]"); 907 } 908 } 909 } 910 assertFalse("Incorrect output for checkClampChar2Char2Char2Char2" + 911 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 912 } 913 checkClampChar3Char3Char3Char3()914 private void checkClampChar3Char3Char3Char3() { 915 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 3, 0xfab6edb7b9d3b0a5l, false); 916 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 3, 0x7ae6f958470ecb1fl, false); 917 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 3, 0x7ae6f94cd86bbd25l, false); 918 enforceOrdering(inMinValue, inMaxValue); 919 try { 920 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE); 921 script.set_gAllocInMinValue(inMinValue); 922 script.set_gAllocInMaxValue(inMaxValue); 923 script.forEach_testClampChar3Char3Char3Char3(inValue, out); 924 verifyResultsClampChar3Char3Char3Char3(inValue, inMinValue, inMaxValue, out, false); 925 out.destroy(); 926 } catch (Exception e) { 927 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar3Char3Char3Char3: " + e.toString()); 928 } 929 try { 930 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE); 931 scriptRelaxed.set_gAllocInMinValue(inMinValue); 932 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 933 scriptRelaxed.forEach_testClampChar3Char3Char3Char3(inValue, out); 934 verifyResultsClampChar3Char3Char3Char3(inValue, inMinValue, inMaxValue, out, true); 935 out.destroy(); 936 } catch (Exception e) { 937 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar3Char3Char3Char3: " + e.toString()); 938 } 939 inValue.destroy(); 940 inMinValue.destroy(); 941 inMaxValue.destroy(); 942 } 943 verifyResultsClampChar3Char3Char3Char3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)944 private void verifyResultsClampChar3Char3Char3Char3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 945 byte[] arrayInValue = new byte[INPUTSIZE * 4]; 946 Arrays.fill(arrayInValue, (byte) 42); 947 inValue.copyTo(arrayInValue); 948 byte[] arrayInMinValue = new byte[INPUTSIZE * 4]; 949 Arrays.fill(arrayInMinValue, (byte) 42); 950 inMinValue.copyTo(arrayInMinValue); 951 byte[] arrayInMaxValue = new byte[INPUTSIZE * 4]; 952 Arrays.fill(arrayInMaxValue, (byte) 42); 953 inMaxValue.copyTo(arrayInMaxValue); 954 byte[] arrayOut = new byte[INPUTSIZE * 4]; 955 Arrays.fill(arrayOut, (byte) 42); 956 out.copyTo(arrayOut); 957 StringBuilder message = new StringBuilder(); 958 boolean errorFound = false; 959 for (int i = 0; i < INPUTSIZE; i++) { 960 for (int j = 0; j < 3 ; j++) { 961 // Extract the inputs. 962 ArgumentsCharCharCharChar args = new ArgumentsCharCharCharChar(); 963 args.inValue = arrayInValue[i * 4 + j]; 964 args.inMinValue = arrayInMinValue[i * 4 + j]; 965 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 966 // Figure out what the outputs should have been. 967 CoreMathVerifier.computeClamp(args); 968 // Validate the outputs. 969 boolean valid = true; 970 if (args.out != arrayOut[i * 4 + j]) { 971 valid = false; 972 } 973 if (!valid) { 974 if (!errorFound) { 975 errorFound = true; 976 message.append("Input inValue: "); 977 appendVariableToMessage(message, args.inValue); 978 message.append("\n"); 979 message.append("Input inMinValue: "); 980 appendVariableToMessage(message, args.inMinValue); 981 message.append("\n"); 982 message.append("Input inMaxValue: "); 983 appendVariableToMessage(message, args.inMaxValue); 984 message.append("\n"); 985 message.append("Expected output out: "); 986 appendVariableToMessage(message, args.out); 987 message.append("\n"); 988 message.append("Actual output out: "); 989 appendVariableToMessage(message, arrayOut[i * 4 + j]); 990 if (args.out != arrayOut[i * 4 + j]) { 991 message.append(" FAIL"); 992 } 993 message.append("\n"); 994 message.append("Errors at"); 995 } 996 message.append(" ["); 997 message.append(Integer.toString(i)); 998 message.append(", "); 999 message.append(Integer.toString(j)); 1000 message.append("]"); 1001 } 1002 } 1003 } 1004 assertFalse("Incorrect output for checkClampChar3Char3Char3Char3" + 1005 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1006 } 1007 checkClampChar4Char4Char4Char4()1008 private void checkClampChar4Char4Char4Char4() { 1009 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 4, 0x53640b88afa8acedl, false); 1010 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 4, 0x86a220559dad877l, false); 1011 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 4, 0x86a21f9eb37ca7dl, false); 1012 enforceOrdering(inMinValue, inMaxValue); 1013 try { 1014 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE); 1015 script.set_gAllocInMinValue(inMinValue); 1016 script.set_gAllocInMaxValue(inMaxValue); 1017 script.forEach_testClampChar4Char4Char4Char4(inValue, out); 1018 verifyResultsClampChar4Char4Char4Char4(inValue, inMinValue, inMaxValue, out, false); 1019 out.destroy(); 1020 } catch (Exception e) { 1021 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar4Char4Char4Char4: " + e.toString()); 1022 } 1023 try { 1024 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE); 1025 scriptRelaxed.set_gAllocInMinValue(inMinValue); 1026 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 1027 scriptRelaxed.forEach_testClampChar4Char4Char4Char4(inValue, out); 1028 verifyResultsClampChar4Char4Char4Char4(inValue, inMinValue, inMaxValue, out, true); 1029 out.destroy(); 1030 } catch (Exception e) { 1031 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar4Char4Char4Char4: " + e.toString()); 1032 } 1033 inValue.destroy(); 1034 inMinValue.destroy(); 1035 inMaxValue.destroy(); 1036 } 1037 verifyResultsClampChar4Char4Char4Char4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)1038 private void verifyResultsClampChar4Char4Char4Char4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 1039 byte[] arrayInValue = new byte[INPUTSIZE * 4]; 1040 Arrays.fill(arrayInValue, (byte) 42); 1041 inValue.copyTo(arrayInValue); 1042 byte[] arrayInMinValue = new byte[INPUTSIZE * 4]; 1043 Arrays.fill(arrayInMinValue, (byte) 42); 1044 inMinValue.copyTo(arrayInMinValue); 1045 byte[] arrayInMaxValue = new byte[INPUTSIZE * 4]; 1046 Arrays.fill(arrayInMaxValue, (byte) 42); 1047 inMaxValue.copyTo(arrayInMaxValue); 1048 byte[] arrayOut = new byte[INPUTSIZE * 4]; 1049 Arrays.fill(arrayOut, (byte) 42); 1050 out.copyTo(arrayOut); 1051 StringBuilder message = new StringBuilder(); 1052 boolean errorFound = false; 1053 for (int i = 0; i < INPUTSIZE; i++) { 1054 for (int j = 0; j < 4 ; j++) { 1055 // Extract the inputs. 1056 ArgumentsCharCharCharChar args = new ArgumentsCharCharCharChar(); 1057 args.inValue = arrayInValue[i * 4 + j]; 1058 args.inMinValue = arrayInMinValue[i * 4 + j]; 1059 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 1060 // Figure out what the outputs should have been. 1061 CoreMathVerifier.computeClamp(args); 1062 // Validate the outputs. 1063 boolean valid = true; 1064 if (args.out != arrayOut[i * 4 + j]) { 1065 valid = false; 1066 } 1067 if (!valid) { 1068 if (!errorFound) { 1069 errorFound = true; 1070 message.append("Input inValue: "); 1071 appendVariableToMessage(message, args.inValue); 1072 message.append("\n"); 1073 message.append("Input inMinValue: "); 1074 appendVariableToMessage(message, args.inMinValue); 1075 message.append("\n"); 1076 message.append("Input inMaxValue: "); 1077 appendVariableToMessage(message, args.inMaxValue); 1078 message.append("\n"); 1079 message.append("Expected output out: "); 1080 appendVariableToMessage(message, args.out); 1081 message.append("\n"); 1082 message.append("Actual output out: "); 1083 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1084 if (args.out != arrayOut[i * 4 + j]) { 1085 message.append(" FAIL"); 1086 } 1087 message.append("\n"); 1088 message.append("Errors at"); 1089 } 1090 message.append(" ["); 1091 message.append(Integer.toString(i)); 1092 message.append(", "); 1093 message.append(Integer.toString(j)); 1094 message.append("]"); 1095 } 1096 } 1097 } 1098 assertFalse("Incorrect output for checkClampChar4Char4Char4Char4" + 1099 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1100 } 1101 1102 public class ArgumentsUcharUcharUcharUchar { 1103 public byte inValue; 1104 public byte inMinValue; 1105 public byte inMaxValue; 1106 public byte out; 1107 } 1108 checkClampUcharUcharUcharUchar()1109 private void checkClampUcharUcharUcharUchar() { 1110 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0x680c818a4447655l, false); 1111 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0xae40bae375336f2fl, false); 1112 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0xae40bad806906135l, false); 1113 enforceOrdering(inMinValue, inMaxValue); 1114 try { 1115 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE); 1116 script.set_gAllocInMinValue(inMinValue); 1117 script.set_gAllocInMaxValue(inMaxValue); 1118 script.forEach_testClampUcharUcharUcharUchar(inValue, out); 1119 verifyResultsClampUcharUcharUcharUchar(inValue, inMinValue, inMaxValue, out, false); 1120 out.destroy(); 1121 } catch (Exception e) { 1122 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUcharUcharUcharUchar: " + e.toString()); 1123 } 1124 try { 1125 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE); 1126 scriptRelaxed.set_gAllocInMinValue(inMinValue); 1127 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 1128 scriptRelaxed.forEach_testClampUcharUcharUcharUchar(inValue, out); 1129 verifyResultsClampUcharUcharUcharUchar(inValue, inMinValue, inMaxValue, out, true); 1130 out.destroy(); 1131 } catch (Exception e) { 1132 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUcharUcharUcharUchar: " + e.toString()); 1133 } 1134 inValue.destroy(); 1135 inMinValue.destroy(); 1136 inMaxValue.destroy(); 1137 } 1138 verifyResultsClampUcharUcharUcharUchar(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)1139 private void verifyResultsClampUcharUcharUcharUchar(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 1140 byte[] arrayInValue = new byte[INPUTSIZE * 1]; 1141 Arrays.fill(arrayInValue, (byte) 42); 1142 inValue.copyTo(arrayInValue); 1143 byte[] arrayInMinValue = new byte[INPUTSIZE * 1]; 1144 Arrays.fill(arrayInMinValue, (byte) 42); 1145 inMinValue.copyTo(arrayInMinValue); 1146 byte[] arrayInMaxValue = new byte[INPUTSIZE * 1]; 1147 Arrays.fill(arrayInMaxValue, (byte) 42); 1148 inMaxValue.copyTo(arrayInMaxValue); 1149 byte[] arrayOut = new byte[INPUTSIZE * 1]; 1150 Arrays.fill(arrayOut, (byte) 42); 1151 out.copyTo(arrayOut); 1152 StringBuilder message = new StringBuilder(); 1153 boolean errorFound = false; 1154 for (int i = 0; i < INPUTSIZE; i++) { 1155 for (int j = 0; j < 1 ; j++) { 1156 // Extract the inputs. 1157 ArgumentsUcharUcharUcharUchar args = new ArgumentsUcharUcharUcharUchar(); 1158 args.inValue = arrayInValue[i]; 1159 args.inMinValue = arrayInMinValue[i]; 1160 args.inMaxValue = arrayInMaxValue[i]; 1161 // Figure out what the outputs should have been. 1162 CoreMathVerifier.computeClamp(args); 1163 // Validate the outputs. 1164 boolean valid = true; 1165 if (args.out != arrayOut[i * 1 + j]) { 1166 valid = false; 1167 } 1168 if (!valid) { 1169 if (!errorFound) { 1170 errorFound = true; 1171 message.append("Input inValue: "); 1172 appendVariableToMessage(message, args.inValue); 1173 message.append("\n"); 1174 message.append("Input inMinValue: "); 1175 appendVariableToMessage(message, args.inMinValue); 1176 message.append("\n"); 1177 message.append("Input inMaxValue: "); 1178 appendVariableToMessage(message, args.inMaxValue); 1179 message.append("\n"); 1180 message.append("Expected output out: "); 1181 appendVariableToMessage(message, args.out); 1182 message.append("\n"); 1183 message.append("Actual output out: "); 1184 appendVariableToMessage(message, arrayOut[i * 1 + j]); 1185 if (args.out != arrayOut[i * 1 + j]) { 1186 message.append(" FAIL"); 1187 } 1188 message.append("\n"); 1189 message.append("Errors at"); 1190 } 1191 message.append(" ["); 1192 message.append(Integer.toString(i)); 1193 message.append(", "); 1194 message.append(Integer.toString(j)); 1195 message.append("]"); 1196 } 1197 } 1198 } 1199 assertFalse("Incorrect output for checkClampUcharUcharUcharUchar" + 1200 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1201 } 1202 checkClampUchar2Uchar2Uchar2Uchar2()1203 private void checkClampUchar2Uchar2Uchar2Uchar2() { 1204 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0xd69df43245dae301l, false); 1205 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x82681747662c1df3l, false); 1206 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x8268173bf7890ff9l, false); 1207 enforceOrdering(inMinValue, inMaxValue); 1208 try { 1209 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE); 1210 script.set_gAllocInMinValue(inMinValue); 1211 script.set_gAllocInMaxValue(inMaxValue); 1212 script.forEach_testClampUchar2Uchar2Uchar2Uchar2(inValue, out); 1213 verifyResultsClampUchar2Uchar2Uchar2Uchar2(inValue, inMinValue, inMaxValue, out, false); 1214 out.destroy(); 1215 } catch (Exception e) { 1216 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar2Uchar2Uchar2Uchar2: " + e.toString()); 1217 } 1218 try { 1219 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE); 1220 scriptRelaxed.set_gAllocInMinValue(inMinValue); 1221 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 1222 scriptRelaxed.forEach_testClampUchar2Uchar2Uchar2Uchar2(inValue, out); 1223 verifyResultsClampUchar2Uchar2Uchar2Uchar2(inValue, inMinValue, inMaxValue, out, true); 1224 out.destroy(); 1225 } catch (Exception e) { 1226 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar2Uchar2Uchar2Uchar2: " + e.toString()); 1227 } 1228 inValue.destroy(); 1229 inMinValue.destroy(); 1230 inMaxValue.destroy(); 1231 } 1232 verifyResultsClampUchar2Uchar2Uchar2Uchar2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)1233 private void verifyResultsClampUchar2Uchar2Uchar2Uchar2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 1234 byte[] arrayInValue = new byte[INPUTSIZE * 2]; 1235 Arrays.fill(arrayInValue, (byte) 42); 1236 inValue.copyTo(arrayInValue); 1237 byte[] arrayInMinValue = new byte[INPUTSIZE * 2]; 1238 Arrays.fill(arrayInMinValue, (byte) 42); 1239 inMinValue.copyTo(arrayInMinValue); 1240 byte[] arrayInMaxValue = new byte[INPUTSIZE * 2]; 1241 Arrays.fill(arrayInMaxValue, (byte) 42); 1242 inMaxValue.copyTo(arrayInMaxValue); 1243 byte[] arrayOut = new byte[INPUTSIZE * 2]; 1244 Arrays.fill(arrayOut, (byte) 42); 1245 out.copyTo(arrayOut); 1246 StringBuilder message = new StringBuilder(); 1247 boolean errorFound = false; 1248 for (int i = 0; i < INPUTSIZE; i++) { 1249 for (int j = 0; j < 2 ; j++) { 1250 // Extract the inputs. 1251 ArgumentsUcharUcharUcharUchar args = new ArgumentsUcharUcharUcharUchar(); 1252 args.inValue = arrayInValue[i * 2 + j]; 1253 args.inMinValue = arrayInMinValue[i * 2 + j]; 1254 args.inMaxValue = arrayInMaxValue[i * 2 + j]; 1255 // Figure out what the outputs should have been. 1256 CoreMathVerifier.computeClamp(args); 1257 // Validate the outputs. 1258 boolean valid = true; 1259 if (args.out != arrayOut[i * 2 + j]) { 1260 valid = false; 1261 } 1262 if (!valid) { 1263 if (!errorFound) { 1264 errorFound = true; 1265 message.append("Input inValue: "); 1266 appendVariableToMessage(message, args.inValue); 1267 message.append("\n"); 1268 message.append("Input inMinValue: "); 1269 appendVariableToMessage(message, args.inMinValue); 1270 message.append("\n"); 1271 message.append("Input inMaxValue: "); 1272 appendVariableToMessage(message, args.inMaxValue); 1273 message.append("\n"); 1274 message.append("Expected output out: "); 1275 appendVariableToMessage(message, args.out); 1276 message.append("\n"); 1277 message.append("Actual output out: "); 1278 appendVariableToMessage(message, arrayOut[i * 2 + j]); 1279 if (args.out != arrayOut[i * 2 + j]) { 1280 message.append(" FAIL"); 1281 } 1282 message.append("\n"); 1283 message.append("Errors at"); 1284 } 1285 message.append(" ["); 1286 message.append(Integer.toString(i)); 1287 message.append(", "); 1288 message.append(Integer.toString(j)); 1289 message.append("]"); 1290 } 1291 } 1292 } 1293 assertFalse("Incorrect output for checkClampUchar2Uchar2Uchar2Uchar2" + 1294 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1295 } 1296 checkClampUchar3Uchar3Uchar3Uchar3()1297 private void checkClampUchar3Uchar3Uchar3Uchar3() { 1298 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0xa00235ba625d4fddl, false); 1299 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x8e548af5b4e30847l, false); 1300 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x8e548aea463ffa4dl, false); 1301 enforceOrdering(inMinValue, inMaxValue); 1302 try { 1303 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE); 1304 script.set_gAllocInMinValue(inMinValue); 1305 script.set_gAllocInMaxValue(inMaxValue); 1306 script.forEach_testClampUchar3Uchar3Uchar3Uchar3(inValue, out); 1307 verifyResultsClampUchar3Uchar3Uchar3Uchar3(inValue, inMinValue, inMaxValue, out, false); 1308 out.destroy(); 1309 } catch (Exception e) { 1310 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar3Uchar3Uchar3Uchar3: " + e.toString()); 1311 } 1312 try { 1313 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE); 1314 scriptRelaxed.set_gAllocInMinValue(inMinValue); 1315 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 1316 scriptRelaxed.forEach_testClampUchar3Uchar3Uchar3Uchar3(inValue, out); 1317 verifyResultsClampUchar3Uchar3Uchar3Uchar3(inValue, inMinValue, inMaxValue, out, true); 1318 out.destroy(); 1319 } catch (Exception e) { 1320 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar3Uchar3Uchar3Uchar3: " + e.toString()); 1321 } 1322 inValue.destroy(); 1323 inMinValue.destroy(); 1324 inMaxValue.destroy(); 1325 } 1326 verifyResultsClampUchar3Uchar3Uchar3Uchar3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)1327 private void verifyResultsClampUchar3Uchar3Uchar3Uchar3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 1328 byte[] arrayInValue = new byte[INPUTSIZE * 4]; 1329 Arrays.fill(arrayInValue, (byte) 42); 1330 inValue.copyTo(arrayInValue); 1331 byte[] arrayInMinValue = new byte[INPUTSIZE * 4]; 1332 Arrays.fill(arrayInMinValue, (byte) 42); 1333 inMinValue.copyTo(arrayInMinValue); 1334 byte[] arrayInMaxValue = new byte[INPUTSIZE * 4]; 1335 Arrays.fill(arrayInMaxValue, (byte) 42); 1336 inMaxValue.copyTo(arrayInMaxValue); 1337 byte[] arrayOut = new byte[INPUTSIZE * 4]; 1338 Arrays.fill(arrayOut, (byte) 42); 1339 out.copyTo(arrayOut); 1340 StringBuilder message = new StringBuilder(); 1341 boolean errorFound = false; 1342 for (int i = 0; i < INPUTSIZE; i++) { 1343 for (int j = 0; j < 3 ; j++) { 1344 // Extract the inputs. 1345 ArgumentsUcharUcharUcharUchar args = new ArgumentsUcharUcharUcharUchar(); 1346 args.inValue = arrayInValue[i * 4 + j]; 1347 args.inMinValue = arrayInMinValue[i * 4 + j]; 1348 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 1349 // Figure out what the outputs should have been. 1350 CoreMathVerifier.computeClamp(args); 1351 // Validate the outputs. 1352 boolean valid = true; 1353 if (args.out != arrayOut[i * 4 + j]) { 1354 valid = false; 1355 } 1356 if (!valid) { 1357 if (!errorFound) { 1358 errorFound = true; 1359 message.append("Input inValue: "); 1360 appendVariableToMessage(message, args.inValue); 1361 message.append("\n"); 1362 message.append("Input inMinValue: "); 1363 appendVariableToMessage(message, args.inMinValue); 1364 message.append("\n"); 1365 message.append("Input inMaxValue: "); 1366 appendVariableToMessage(message, args.inMaxValue); 1367 message.append("\n"); 1368 message.append("Expected output out: "); 1369 appendVariableToMessage(message, args.out); 1370 message.append("\n"); 1371 message.append("Actual output out: "); 1372 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1373 if (args.out != arrayOut[i * 4 + j]) { 1374 message.append(" FAIL"); 1375 } 1376 message.append("\n"); 1377 message.append("Errors at"); 1378 } 1379 message.append(" ["); 1380 message.append(Integer.toString(i)); 1381 message.append(", "); 1382 message.append(Integer.toString(j)); 1383 message.append("]"); 1384 } 1385 } 1386 } 1387 assertFalse("Incorrect output for checkClampUchar3Uchar3Uchar3Uchar3" + 1388 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1389 } 1390 checkClampUchar4Uchar4Uchar4Uchar4()1391 private void checkClampUchar4Uchar4Uchar4Uchar4() { 1392 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x696677427edfbcb9l, false); 1393 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x9a40fea40399f29bl, false); 1394 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x9a40fe9894f6e4a1l, false); 1395 enforceOrdering(inMinValue, inMaxValue); 1396 try { 1397 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE); 1398 script.set_gAllocInMinValue(inMinValue); 1399 script.set_gAllocInMaxValue(inMaxValue); 1400 script.forEach_testClampUchar4Uchar4Uchar4Uchar4(inValue, out); 1401 verifyResultsClampUchar4Uchar4Uchar4Uchar4(inValue, inMinValue, inMaxValue, out, false); 1402 out.destroy(); 1403 } catch (Exception e) { 1404 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar4Uchar4Uchar4Uchar4: " + e.toString()); 1405 } 1406 try { 1407 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE); 1408 scriptRelaxed.set_gAllocInMinValue(inMinValue); 1409 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 1410 scriptRelaxed.forEach_testClampUchar4Uchar4Uchar4Uchar4(inValue, out); 1411 verifyResultsClampUchar4Uchar4Uchar4Uchar4(inValue, inMinValue, inMaxValue, out, true); 1412 out.destroy(); 1413 } catch (Exception e) { 1414 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar4Uchar4Uchar4Uchar4: " + e.toString()); 1415 } 1416 inValue.destroy(); 1417 inMinValue.destroy(); 1418 inMaxValue.destroy(); 1419 } 1420 verifyResultsClampUchar4Uchar4Uchar4Uchar4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)1421 private void verifyResultsClampUchar4Uchar4Uchar4Uchar4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 1422 byte[] arrayInValue = new byte[INPUTSIZE * 4]; 1423 Arrays.fill(arrayInValue, (byte) 42); 1424 inValue.copyTo(arrayInValue); 1425 byte[] arrayInMinValue = new byte[INPUTSIZE * 4]; 1426 Arrays.fill(arrayInMinValue, (byte) 42); 1427 inMinValue.copyTo(arrayInMinValue); 1428 byte[] arrayInMaxValue = new byte[INPUTSIZE * 4]; 1429 Arrays.fill(arrayInMaxValue, (byte) 42); 1430 inMaxValue.copyTo(arrayInMaxValue); 1431 byte[] arrayOut = new byte[INPUTSIZE * 4]; 1432 Arrays.fill(arrayOut, (byte) 42); 1433 out.copyTo(arrayOut); 1434 StringBuilder message = new StringBuilder(); 1435 boolean errorFound = false; 1436 for (int i = 0; i < INPUTSIZE; i++) { 1437 for (int j = 0; j < 4 ; j++) { 1438 // Extract the inputs. 1439 ArgumentsUcharUcharUcharUchar args = new ArgumentsUcharUcharUcharUchar(); 1440 args.inValue = arrayInValue[i * 4 + j]; 1441 args.inMinValue = arrayInMinValue[i * 4 + j]; 1442 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 1443 // Figure out what the outputs should have been. 1444 CoreMathVerifier.computeClamp(args); 1445 // Validate the outputs. 1446 boolean valid = true; 1447 if (args.out != arrayOut[i * 4 + j]) { 1448 valid = false; 1449 } 1450 if (!valid) { 1451 if (!errorFound) { 1452 errorFound = true; 1453 message.append("Input inValue: "); 1454 appendVariableToMessage(message, args.inValue); 1455 message.append("\n"); 1456 message.append("Input inMinValue: "); 1457 appendVariableToMessage(message, args.inMinValue); 1458 message.append("\n"); 1459 message.append("Input inMaxValue: "); 1460 appendVariableToMessage(message, args.inMaxValue); 1461 message.append("\n"); 1462 message.append("Expected output out: "); 1463 appendVariableToMessage(message, args.out); 1464 message.append("\n"); 1465 message.append("Actual output out: "); 1466 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1467 if (args.out != arrayOut[i * 4 + j]) { 1468 message.append(" FAIL"); 1469 } 1470 message.append("\n"); 1471 message.append("Errors at"); 1472 } 1473 message.append(" ["); 1474 message.append(Integer.toString(i)); 1475 message.append(", "); 1476 message.append(Integer.toString(j)); 1477 message.append("]"); 1478 } 1479 } 1480 } 1481 assertFalse("Incorrect output for checkClampUchar4Uchar4Uchar4Uchar4" + 1482 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1483 } 1484 1485 public class ArgumentsShortShortShortShort { 1486 public short inValue; 1487 public short inMinValue; 1488 public short inMaxValue; 1489 public short out; 1490 } 1491 checkClampShortShortShortShort()1492 private void checkClampShortShortShortShort() { 1493 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0x8035c0627fc993ddl, false); 1494 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0xb5d4bd1fb4661447l, false); 1495 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0xb5d4bd1445c3064dl, false); 1496 enforceOrdering(inMinValue, inMaxValue); 1497 try { 1498 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 1), INPUTSIZE); 1499 script.set_gAllocInMinValue(inMinValue); 1500 script.set_gAllocInMaxValue(inMaxValue); 1501 script.forEach_testClampShortShortShortShort(inValue, out); 1502 verifyResultsClampShortShortShortShort(inValue, inMinValue, inMaxValue, out, false); 1503 out.destroy(); 1504 } catch (Exception e) { 1505 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShortShortShortShort: " + e.toString()); 1506 } 1507 try { 1508 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 1), INPUTSIZE); 1509 scriptRelaxed.set_gAllocInMinValue(inMinValue); 1510 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 1511 scriptRelaxed.forEach_testClampShortShortShortShort(inValue, out); 1512 verifyResultsClampShortShortShortShort(inValue, inMinValue, inMaxValue, out, true); 1513 out.destroy(); 1514 } catch (Exception e) { 1515 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShortShortShortShort: " + e.toString()); 1516 } 1517 inValue.destroy(); 1518 inMinValue.destroy(); 1519 inMaxValue.destroy(); 1520 } 1521 verifyResultsClampShortShortShortShort(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)1522 private void verifyResultsClampShortShortShortShort(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 1523 short[] arrayInValue = new short[INPUTSIZE * 1]; 1524 Arrays.fill(arrayInValue, (short) 42); 1525 inValue.copyTo(arrayInValue); 1526 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 1527 Arrays.fill(arrayInMinValue, (short) 42); 1528 inMinValue.copyTo(arrayInMinValue); 1529 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 1530 Arrays.fill(arrayInMaxValue, (short) 42); 1531 inMaxValue.copyTo(arrayInMaxValue); 1532 short[] arrayOut = new short[INPUTSIZE * 1]; 1533 Arrays.fill(arrayOut, (short) 42); 1534 out.copyTo(arrayOut); 1535 StringBuilder message = new StringBuilder(); 1536 boolean errorFound = false; 1537 for (int i = 0; i < INPUTSIZE; i++) { 1538 for (int j = 0; j < 1 ; j++) { 1539 // Extract the inputs. 1540 ArgumentsShortShortShortShort args = new ArgumentsShortShortShortShort(); 1541 args.inValue = arrayInValue[i]; 1542 args.inMinValue = arrayInMinValue[i]; 1543 args.inMaxValue = arrayInMaxValue[i]; 1544 // Figure out what the outputs should have been. 1545 CoreMathVerifier.computeClamp(args); 1546 // Validate the outputs. 1547 boolean valid = true; 1548 if (args.out != arrayOut[i * 1 + j]) { 1549 valid = false; 1550 } 1551 if (!valid) { 1552 if (!errorFound) { 1553 errorFound = true; 1554 message.append("Input inValue: "); 1555 appendVariableToMessage(message, args.inValue); 1556 message.append("\n"); 1557 message.append("Input inMinValue: "); 1558 appendVariableToMessage(message, args.inMinValue); 1559 message.append("\n"); 1560 message.append("Input inMaxValue: "); 1561 appendVariableToMessage(message, args.inMaxValue); 1562 message.append("\n"); 1563 message.append("Expected output out: "); 1564 appendVariableToMessage(message, args.out); 1565 message.append("\n"); 1566 message.append("Actual output out: "); 1567 appendVariableToMessage(message, arrayOut[i * 1 + j]); 1568 if (args.out != arrayOut[i * 1 + j]) { 1569 message.append(" FAIL"); 1570 } 1571 message.append("\n"); 1572 message.append("Errors at"); 1573 } 1574 message.append(" ["); 1575 message.append(Integer.toString(i)); 1576 message.append(", "); 1577 message.append(Integer.toString(j)); 1578 message.append("]"); 1579 } 1580 } 1581 } 1582 assertFalse("Incorrect output for checkClampShortShortShortShort" + 1583 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1584 } 1585 checkClampShort2Short2Short2Short2()1586 private void checkClampShort2Short2Short2Short2() { 1587 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x7eab8e9b984e0915l, false); 1588 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x7b334b992e67336fl, false); 1589 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x7b334b8dbfc42575l, false); 1590 enforceOrdering(inMinValue, inMaxValue); 1591 try { 1592 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE); 1593 script.set_gAllocInMinValue(inMinValue); 1594 script.set_gAllocInMaxValue(inMaxValue); 1595 script.forEach_testClampShort2Short2Short2Short2(inValue, out); 1596 verifyResultsClampShort2Short2Short2Short2(inValue, inMinValue, inMaxValue, out, false); 1597 out.destroy(); 1598 } catch (Exception e) { 1599 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort2Short2Short2Short2: " + e.toString()); 1600 } 1601 try { 1602 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE); 1603 scriptRelaxed.set_gAllocInMinValue(inMinValue); 1604 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 1605 scriptRelaxed.forEach_testClampShort2Short2Short2Short2(inValue, out); 1606 verifyResultsClampShort2Short2Short2Short2(inValue, inMinValue, inMaxValue, out, true); 1607 out.destroy(); 1608 } catch (Exception e) { 1609 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort2Short2Short2Short2: " + e.toString()); 1610 } 1611 inValue.destroy(); 1612 inMinValue.destroy(); 1613 inMaxValue.destroy(); 1614 } 1615 verifyResultsClampShort2Short2Short2Short2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)1616 private void verifyResultsClampShort2Short2Short2Short2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 1617 short[] arrayInValue = new short[INPUTSIZE * 2]; 1618 Arrays.fill(arrayInValue, (short) 42); 1619 inValue.copyTo(arrayInValue); 1620 short[] arrayInMinValue = new short[INPUTSIZE * 2]; 1621 Arrays.fill(arrayInMinValue, (short) 42); 1622 inMinValue.copyTo(arrayInMinValue); 1623 short[] arrayInMaxValue = new short[INPUTSIZE * 2]; 1624 Arrays.fill(arrayInMaxValue, (short) 42); 1625 inMaxValue.copyTo(arrayInMaxValue); 1626 short[] arrayOut = new short[INPUTSIZE * 2]; 1627 Arrays.fill(arrayOut, (short) 42); 1628 out.copyTo(arrayOut); 1629 StringBuilder message = new StringBuilder(); 1630 boolean errorFound = false; 1631 for (int i = 0; i < INPUTSIZE; i++) { 1632 for (int j = 0; j < 2 ; j++) { 1633 // Extract the inputs. 1634 ArgumentsShortShortShortShort args = new ArgumentsShortShortShortShort(); 1635 args.inValue = arrayInValue[i * 2 + j]; 1636 args.inMinValue = arrayInMinValue[i * 2 + j]; 1637 args.inMaxValue = arrayInMaxValue[i * 2 + j]; 1638 // Figure out what the outputs should have been. 1639 CoreMathVerifier.computeClamp(args); 1640 // Validate the outputs. 1641 boolean valid = true; 1642 if (args.out != arrayOut[i * 2 + j]) { 1643 valid = false; 1644 } 1645 if (!valid) { 1646 if (!errorFound) { 1647 errorFound = true; 1648 message.append("Input inValue: "); 1649 appendVariableToMessage(message, args.inValue); 1650 message.append("\n"); 1651 message.append("Input inMinValue: "); 1652 appendVariableToMessage(message, args.inMinValue); 1653 message.append("\n"); 1654 message.append("Input inMaxValue: "); 1655 appendVariableToMessage(message, args.inMaxValue); 1656 message.append("\n"); 1657 message.append("Expected output out: "); 1658 appendVariableToMessage(message, args.out); 1659 message.append("\n"); 1660 message.append("Actual output out: "); 1661 appendVariableToMessage(message, arrayOut[i * 2 + j]); 1662 if (args.out != arrayOut[i * 2 + j]) { 1663 message.append(" FAIL"); 1664 } 1665 message.append("\n"); 1666 message.append("Errors at"); 1667 } 1668 message.append(" ["); 1669 message.append(Integer.toString(i)); 1670 message.append(", "); 1671 message.append(Integer.toString(j)); 1672 message.append("]"); 1673 } 1674 } 1675 } 1676 assertFalse("Incorrect output for checkClampShort2Short2Short2Short2" + 1677 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1678 } 1679 checkClampShort3Short3Short3Short3()1680 private void checkClampShort3Short3Short3Short3() { 1681 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x480fd023b4d075f1l, false); 1682 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x871fbf477d1e1dc3l, false); 1683 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x871fbf3c0e7b0fc9l, false); 1684 enforceOrdering(inMinValue, inMaxValue); 1685 try { 1686 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE); 1687 script.set_gAllocInMinValue(inMinValue); 1688 script.set_gAllocInMaxValue(inMaxValue); 1689 script.forEach_testClampShort3Short3Short3Short3(inValue, out); 1690 verifyResultsClampShort3Short3Short3Short3(inValue, inMinValue, inMaxValue, out, false); 1691 out.destroy(); 1692 } catch (Exception e) { 1693 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort3Short3Short3Short3: " + e.toString()); 1694 } 1695 try { 1696 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE); 1697 scriptRelaxed.set_gAllocInMinValue(inMinValue); 1698 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 1699 scriptRelaxed.forEach_testClampShort3Short3Short3Short3(inValue, out); 1700 verifyResultsClampShort3Short3Short3Short3(inValue, inMinValue, inMaxValue, out, true); 1701 out.destroy(); 1702 } catch (Exception e) { 1703 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort3Short3Short3Short3: " + e.toString()); 1704 } 1705 inValue.destroy(); 1706 inMinValue.destroy(); 1707 inMaxValue.destroy(); 1708 } 1709 verifyResultsClampShort3Short3Short3Short3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)1710 private void verifyResultsClampShort3Short3Short3Short3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 1711 short[] arrayInValue = new short[INPUTSIZE * 4]; 1712 Arrays.fill(arrayInValue, (short) 42); 1713 inValue.copyTo(arrayInValue); 1714 short[] arrayInMinValue = new short[INPUTSIZE * 4]; 1715 Arrays.fill(arrayInMinValue, (short) 42); 1716 inMinValue.copyTo(arrayInMinValue); 1717 short[] arrayInMaxValue = new short[INPUTSIZE * 4]; 1718 Arrays.fill(arrayInMaxValue, (short) 42); 1719 inMaxValue.copyTo(arrayInMaxValue); 1720 short[] arrayOut = new short[INPUTSIZE * 4]; 1721 Arrays.fill(arrayOut, (short) 42); 1722 out.copyTo(arrayOut); 1723 StringBuilder message = new StringBuilder(); 1724 boolean errorFound = false; 1725 for (int i = 0; i < INPUTSIZE; i++) { 1726 for (int j = 0; j < 3 ; j++) { 1727 // Extract the inputs. 1728 ArgumentsShortShortShortShort args = new ArgumentsShortShortShortShort(); 1729 args.inValue = arrayInValue[i * 4 + j]; 1730 args.inMinValue = arrayInMinValue[i * 4 + j]; 1731 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 1732 // Figure out what the outputs should have been. 1733 CoreMathVerifier.computeClamp(args); 1734 // Validate the outputs. 1735 boolean valid = true; 1736 if (args.out != arrayOut[i * 4 + j]) { 1737 valid = false; 1738 } 1739 if (!valid) { 1740 if (!errorFound) { 1741 errorFound = true; 1742 message.append("Input inValue: "); 1743 appendVariableToMessage(message, args.inValue); 1744 message.append("\n"); 1745 message.append("Input inMinValue: "); 1746 appendVariableToMessage(message, args.inMinValue); 1747 message.append("\n"); 1748 message.append("Input inMaxValue: "); 1749 appendVariableToMessage(message, args.inMaxValue); 1750 message.append("\n"); 1751 message.append("Expected output out: "); 1752 appendVariableToMessage(message, args.out); 1753 message.append("\n"); 1754 message.append("Actual output out: "); 1755 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1756 if (args.out != arrayOut[i * 4 + j]) { 1757 message.append(" FAIL"); 1758 } 1759 message.append("\n"); 1760 message.append("Errors at"); 1761 } 1762 message.append(" ["); 1763 message.append(Integer.toString(i)); 1764 message.append(", "); 1765 message.append(Integer.toString(j)); 1766 message.append("]"); 1767 } 1768 } 1769 } 1770 assertFalse("Incorrect output for checkClampShort3Short3Short3Short3" + 1771 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1772 } 1773 checkClampShort4Short4Short4Short4()1774 private void checkClampShort4Short4Short4Short4() { 1775 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x117411abd152e2cdl, false); 1776 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x930c32f5cbd50817l, false); 1777 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x930c32ea5d31fa1dl, false); 1778 enforceOrdering(inMinValue, inMaxValue); 1779 try { 1780 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE); 1781 script.set_gAllocInMinValue(inMinValue); 1782 script.set_gAllocInMaxValue(inMaxValue); 1783 script.forEach_testClampShort4Short4Short4Short4(inValue, out); 1784 verifyResultsClampShort4Short4Short4Short4(inValue, inMinValue, inMaxValue, out, false); 1785 out.destroy(); 1786 } catch (Exception e) { 1787 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort4Short4Short4Short4: " + e.toString()); 1788 } 1789 try { 1790 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE); 1791 scriptRelaxed.set_gAllocInMinValue(inMinValue); 1792 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 1793 scriptRelaxed.forEach_testClampShort4Short4Short4Short4(inValue, out); 1794 verifyResultsClampShort4Short4Short4Short4(inValue, inMinValue, inMaxValue, out, true); 1795 out.destroy(); 1796 } catch (Exception e) { 1797 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort4Short4Short4Short4: " + e.toString()); 1798 } 1799 inValue.destroy(); 1800 inMinValue.destroy(); 1801 inMaxValue.destroy(); 1802 } 1803 verifyResultsClampShort4Short4Short4Short4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)1804 private void verifyResultsClampShort4Short4Short4Short4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 1805 short[] arrayInValue = new short[INPUTSIZE * 4]; 1806 Arrays.fill(arrayInValue, (short) 42); 1807 inValue.copyTo(arrayInValue); 1808 short[] arrayInMinValue = new short[INPUTSIZE * 4]; 1809 Arrays.fill(arrayInMinValue, (short) 42); 1810 inMinValue.copyTo(arrayInMinValue); 1811 short[] arrayInMaxValue = new short[INPUTSIZE * 4]; 1812 Arrays.fill(arrayInMaxValue, (short) 42); 1813 inMaxValue.copyTo(arrayInMaxValue); 1814 short[] arrayOut = new short[INPUTSIZE * 4]; 1815 Arrays.fill(arrayOut, (short) 42); 1816 out.copyTo(arrayOut); 1817 StringBuilder message = new StringBuilder(); 1818 boolean errorFound = false; 1819 for (int i = 0; i < INPUTSIZE; i++) { 1820 for (int j = 0; j < 4 ; j++) { 1821 // Extract the inputs. 1822 ArgumentsShortShortShortShort args = new ArgumentsShortShortShortShort(); 1823 args.inValue = arrayInValue[i * 4 + j]; 1824 args.inMinValue = arrayInMinValue[i * 4 + j]; 1825 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 1826 // Figure out what the outputs should have been. 1827 CoreMathVerifier.computeClamp(args); 1828 // Validate the outputs. 1829 boolean valid = true; 1830 if (args.out != arrayOut[i * 4 + j]) { 1831 valid = false; 1832 } 1833 if (!valid) { 1834 if (!errorFound) { 1835 errorFound = true; 1836 message.append("Input inValue: "); 1837 appendVariableToMessage(message, args.inValue); 1838 message.append("\n"); 1839 message.append("Input inMinValue: "); 1840 appendVariableToMessage(message, args.inMinValue); 1841 message.append("\n"); 1842 message.append("Input inMaxValue: "); 1843 appendVariableToMessage(message, args.inMaxValue); 1844 message.append("\n"); 1845 message.append("Expected output out: "); 1846 appendVariableToMessage(message, args.out); 1847 message.append("\n"); 1848 message.append("Actual output out: "); 1849 appendVariableToMessage(message, arrayOut[i * 4 + j]); 1850 if (args.out != arrayOut[i * 4 + j]) { 1851 message.append(" FAIL"); 1852 } 1853 message.append("\n"); 1854 message.append("Errors at"); 1855 } 1856 message.append(" ["); 1857 message.append(Integer.toString(i)); 1858 message.append(", "); 1859 message.append(Integer.toString(j)); 1860 message.append("]"); 1861 } 1862 } 1863 } 1864 assertFalse("Incorrect output for checkClampShort4Short4Short4Short4" + 1865 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1866 } 1867 1868 public class ArgumentsUshortUshortUshortUshort { 1869 public short inValue; 1870 public short inMinValue; 1871 public short inMaxValue; 1872 public short out; 1873 } 1874 checkClampUshortUshortUshortUshort()1875 private void checkClampUshortUshortUshortUshort() { 1876 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0xf5881eeff74c4341l, false); 1877 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0xd2a0571394d3e2b3l, false); 1878 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0xd2a057082630d4b9l, false); 1879 enforceOrdering(inMinValue, inMaxValue); 1880 try { 1881 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE); 1882 script.set_gAllocInMinValue(inMinValue); 1883 script.set_gAllocInMaxValue(inMaxValue); 1884 script.forEach_testClampUshortUshortUshortUshort(inValue, out); 1885 verifyResultsClampUshortUshortUshortUshort(inValue, inMinValue, inMaxValue, out, false); 1886 out.destroy(); 1887 } catch (Exception e) { 1888 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshortUshortUshortUshort: " + e.toString()); 1889 } 1890 try { 1891 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE); 1892 scriptRelaxed.set_gAllocInMinValue(inMinValue); 1893 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 1894 scriptRelaxed.forEach_testClampUshortUshortUshortUshort(inValue, out); 1895 verifyResultsClampUshortUshortUshortUshort(inValue, inMinValue, inMaxValue, out, true); 1896 out.destroy(); 1897 } catch (Exception e) { 1898 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshortUshortUshortUshort: " + e.toString()); 1899 } 1900 inValue.destroy(); 1901 inMinValue.destroy(); 1902 inMaxValue.destroy(); 1903 } 1904 verifyResultsClampUshortUshortUshortUshort(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)1905 private void verifyResultsClampUshortUshortUshortUshort(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 1906 short[] arrayInValue = new short[INPUTSIZE * 1]; 1907 Arrays.fill(arrayInValue, (short) 42); 1908 inValue.copyTo(arrayInValue); 1909 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 1910 Arrays.fill(arrayInMinValue, (short) 42); 1911 inMinValue.copyTo(arrayInMinValue); 1912 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 1913 Arrays.fill(arrayInMaxValue, (short) 42); 1914 inMaxValue.copyTo(arrayInMaxValue); 1915 short[] arrayOut = new short[INPUTSIZE * 1]; 1916 Arrays.fill(arrayOut, (short) 42); 1917 out.copyTo(arrayOut); 1918 StringBuilder message = new StringBuilder(); 1919 boolean errorFound = false; 1920 for (int i = 0; i < INPUTSIZE; i++) { 1921 for (int j = 0; j < 1 ; j++) { 1922 // Extract the inputs. 1923 ArgumentsUshortUshortUshortUshort args = new ArgumentsUshortUshortUshortUshort(); 1924 args.inValue = arrayInValue[i]; 1925 args.inMinValue = arrayInMinValue[i]; 1926 args.inMaxValue = arrayInMaxValue[i]; 1927 // Figure out what the outputs should have been. 1928 CoreMathVerifier.computeClamp(args); 1929 // Validate the outputs. 1930 boolean valid = true; 1931 if (args.out != arrayOut[i * 1 + j]) { 1932 valid = false; 1933 } 1934 if (!valid) { 1935 if (!errorFound) { 1936 errorFound = true; 1937 message.append("Input inValue: "); 1938 appendVariableToMessage(message, args.inValue); 1939 message.append("\n"); 1940 message.append("Input inMinValue: "); 1941 appendVariableToMessage(message, args.inMinValue); 1942 message.append("\n"); 1943 message.append("Input inMaxValue: "); 1944 appendVariableToMessage(message, args.inMaxValue); 1945 message.append("\n"); 1946 message.append("Expected output out: "); 1947 appendVariableToMessage(message, args.out); 1948 message.append("\n"); 1949 message.append("Actual output out: "); 1950 appendVariableToMessage(message, arrayOut[i * 1 + j]); 1951 if (args.out != arrayOut[i * 1 + j]) { 1952 message.append(" FAIL"); 1953 } 1954 message.append("\n"); 1955 message.append("Errors at"); 1956 } 1957 message.append(" ["); 1958 message.append(Integer.toString(i)); 1959 message.append(", "); 1960 message.append(Integer.toString(j)); 1961 message.append("]"); 1962 } 1963 } 1964 } 1965 assertFalse("Incorrect output for checkClampUshortUshortUshortUshort" + 1966 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 1967 } 1968 checkClampUshort2Ushort2Ushort2Ushort2()1969 private void checkClampUshort2Ushort2Ushort2Ushort2() { 1970 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0x6441dbe2fc36b705l, false); 1971 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0x52161e934fa3b43fl, false); 1972 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0x52161e87e100a645l, false); 1973 enforceOrdering(inMinValue, inMaxValue); 1974 try { 1975 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE); 1976 script.set_gAllocInMinValue(inMinValue); 1977 script.set_gAllocInMaxValue(inMaxValue); 1978 script.forEach_testClampUshort2Ushort2Ushort2Ushort2(inValue, out); 1979 verifyResultsClampUshort2Ushort2Ushort2Ushort2(inValue, inMinValue, inMaxValue, out, false); 1980 out.destroy(); 1981 } catch (Exception e) { 1982 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort2Ushort2Ushort2Ushort2: " + e.toString()); 1983 } 1984 try { 1985 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE); 1986 scriptRelaxed.set_gAllocInMinValue(inMinValue); 1987 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 1988 scriptRelaxed.forEach_testClampUshort2Ushort2Ushort2Ushort2(inValue, out); 1989 verifyResultsClampUshort2Ushort2Ushort2Ushort2(inValue, inMinValue, inMaxValue, out, true); 1990 out.destroy(); 1991 } catch (Exception e) { 1992 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort2Ushort2Ushort2Ushort2: " + e.toString()); 1993 } 1994 inValue.destroy(); 1995 inMinValue.destroy(); 1996 inMaxValue.destroy(); 1997 } 1998 verifyResultsClampUshort2Ushort2Ushort2Ushort2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)1999 private void verifyResultsClampUshort2Ushort2Ushort2Ushort2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 2000 short[] arrayInValue = new short[INPUTSIZE * 2]; 2001 Arrays.fill(arrayInValue, (short) 42); 2002 inValue.copyTo(arrayInValue); 2003 short[] arrayInMinValue = new short[INPUTSIZE * 2]; 2004 Arrays.fill(arrayInMinValue, (short) 42); 2005 inMinValue.copyTo(arrayInMinValue); 2006 short[] arrayInMaxValue = new short[INPUTSIZE * 2]; 2007 Arrays.fill(arrayInMaxValue, (short) 42); 2008 inMaxValue.copyTo(arrayInMaxValue); 2009 short[] arrayOut = new short[INPUTSIZE * 2]; 2010 Arrays.fill(arrayOut, (short) 42); 2011 out.copyTo(arrayOut); 2012 StringBuilder message = new StringBuilder(); 2013 boolean errorFound = false; 2014 for (int i = 0; i < INPUTSIZE; i++) { 2015 for (int j = 0; j < 2 ; j++) { 2016 // Extract the inputs. 2017 ArgumentsUshortUshortUshortUshort args = new ArgumentsUshortUshortUshortUshort(); 2018 args.inValue = arrayInValue[i * 2 + j]; 2019 args.inMinValue = arrayInMinValue[i * 2 + j]; 2020 args.inMaxValue = arrayInMaxValue[i * 2 + j]; 2021 // Figure out what the outputs should have been. 2022 CoreMathVerifier.computeClamp(args); 2023 // Validate the outputs. 2024 boolean valid = true; 2025 if (args.out != arrayOut[i * 2 + j]) { 2026 valid = false; 2027 } 2028 if (!valid) { 2029 if (!errorFound) { 2030 errorFound = true; 2031 message.append("Input inValue: "); 2032 appendVariableToMessage(message, args.inValue); 2033 message.append("\n"); 2034 message.append("Input inMinValue: "); 2035 appendVariableToMessage(message, args.inMinValue); 2036 message.append("\n"); 2037 message.append("Input inMaxValue: "); 2038 appendVariableToMessage(message, args.inMaxValue); 2039 message.append("\n"); 2040 message.append("Expected output out: "); 2041 appendVariableToMessage(message, args.out); 2042 message.append("\n"); 2043 message.append("Actual output out: "); 2044 appendVariableToMessage(message, arrayOut[i * 2 + j]); 2045 if (args.out != arrayOut[i * 2 + j]) { 2046 message.append(" FAIL"); 2047 } 2048 message.append("\n"); 2049 message.append("Errors at"); 2050 } 2051 message.append(" ["); 2052 message.append(Integer.toString(i)); 2053 message.append(", "); 2054 message.append(Integer.toString(j)); 2055 message.append("]"); 2056 } 2057 } 2058 } 2059 assertFalse("Incorrect output for checkClampUshort2Ushort2Ushort2Ushort2" + 2060 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 2061 } 2062 checkClampUshort3Ushort3Ushort3Ushort3()2063 private void checkClampUshort3Ushort3Ushort3Ushort3() { 2064 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0x6b244d61fc64ee3dl, false); 2065 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0x7b8d14b8610b3967l, false); 2066 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0x7b8d14acf2682b6dl, false); 2067 enforceOrdering(inMinValue, inMaxValue); 2068 try { 2069 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE); 2070 script.set_gAllocInMinValue(inMinValue); 2071 script.set_gAllocInMaxValue(inMaxValue); 2072 script.forEach_testClampUshort3Ushort3Ushort3Ushort3(inValue, out); 2073 verifyResultsClampUshort3Ushort3Ushort3Ushort3(inValue, inMinValue, inMaxValue, out, false); 2074 out.destroy(); 2075 } catch (Exception e) { 2076 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort3Ushort3Ushort3Ushort3: " + e.toString()); 2077 } 2078 try { 2079 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE); 2080 scriptRelaxed.set_gAllocInMinValue(inMinValue); 2081 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 2082 scriptRelaxed.forEach_testClampUshort3Ushort3Ushort3Ushort3(inValue, out); 2083 verifyResultsClampUshort3Ushort3Ushort3Ushort3(inValue, inMinValue, inMaxValue, out, true); 2084 out.destroy(); 2085 } catch (Exception e) { 2086 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort3Ushort3Ushort3Ushort3: " + e.toString()); 2087 } 2088 inValue.destroy(); 2089 inMinValue.destroy(); 2090 inMaxValue.destroy(); 2091 } 2092 verifyResultsClampUshort3Ushort3Ushort3Ushort3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)2093 private void verifyResultsClampUshort3Ushort3Ushort3Ushort3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 2094 short[] arrayInValue = new short[INPUTSIZE * 4]; 2095 Arrays.fill(arrayInValue, (short) 42); 2096 inValue.copyTo(arrayInValue); 2097 short[] arrayInMinValue = new short[INPUTSIZE * 4]; 2098 Arrays.fill(arrayInMinValue, (short) 42); 2099 inMinValue.copyTo(arrayInMinValue); 2100 short[] arrayInMaxValue = new short[INPUTSIZE * 4]; 2101 Arrays.fill(arrayInMaxValue, (short) 42); 2102 inMaxValue.copyTo(arrayInMaxValue); 2103 short[] arrayOut = new short[INPUTSIZE * 4]; 2104 Arrays.fill(arrayOut, (short) 42); 2105 out.copyTo(arrayOut); 2106 StringBuilder message = new StringBuilder(); 2107 boolean errorFound = false; 2108 for (int i = 0; i < INPUTSIZE; i++) { 2109 for (int j = 0; j < 3 ; j++) { 2110 // Extract the inputs. 2111 ArgumentsUshortUshortUshortUshort args = new ArgumentsUshortUshortUshortUshort(); 2112 args.inValue = arrayInValue[i * 4 + j]; 2113 args.inMinValue = arrayInMinValue[i * 4 + j]; 2114 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 2115 // Figure out what the outputs should have been. 2116 CoreMathVerifier.computeClamp(args); 2117 // Validate the outputs. 2118 boolean valid = true; 2119 if (args.out != arrayOut[i * 4 + j]) { 2120 valid = false; 2121 } 2122 if (!valid) { 2123 if (!errorFound) { 2124 errorFound = true; 2125 message.append("Input inValue: "); 2126 appendVariableToMessage(message, args.inValue); 2127 message.append("\n"); 2128 message.append("Input inMinValue: "); 2129 appendVariableToMessage(message, args.inMinValue); 2130 message.append("\n"); 2131 message.append("Input inMaxValue: "); 2132 appendVariableToMessage(message, args.inMaxValue); 2133 message.append("\n"); 2134 message.append("Expected output out: "); 2135 appendVariableToMessage(message, args.out); 2136 message.append("\n"); 2137 message.append("Actual output out: "); 2138 appendVariableToMessage(message, arrayOut[i * 4 + j]); 2139 if (args.out != arrayOut[i * 4 + j]) { 2140 message.append(" FAIL"); 2141 } 2142 message.append("\n"); 2143 message.append("Errors at"); 2144 } 2145 message.append(" ["); 2146 message.append(Integer.toString(i)); 2147 message.append(", "); 2148 message.append(Integer.toString(j)); 2149 message.append("]"); 2150 } 2151 } 2152 } 2153 assertFalse("Incorrect output for checkClampUshort3Ushort3Ushort3Ushort3" + 2154 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 2155 } 2156 checkClampUshort4Ushort4Ushort4Ushort4()2157 private void checkClampUshort4Ushort4Ushort4Ushort4() { 2158 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0x7206bee0fc932575l, false); 2159 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0xa5040add7272be8fl, false); 2160 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0xa5040ad203cfb095l, false); 2161 enforceOrdering(inMinValue, inMaxValue); 2162 try { 2163 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE); 2164 script.set_gAllocInMinValue(inMinValue); 2165 script.set_gAllocInMaxValue(inMaxValue); 2166 script.forEach_testClampUshort4Ushort4Ushort4Ushort4(inValue, out); 2167 verifyResultsClampUshort4Ushort4Ushort4Ushort4(inValue, inMinValue, inMaxValue, out, false); 2168 out.destroy(); 2169 } catch (Exception e) { 2170 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort4Ushort4Ushort4Ushort4: " + e.toString()); 2171 } 2172 try { 2173 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE); 2174 scriptRelaxed.set_gAllocInMinValue(inMinValue); 2175 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 2176 scriptRelaxed.forEach_testClampUshort4Ushort4Ushort4Ushort4(inValue, out); 2177 verifyResultsClampUshort4Ushort4Ushort4Ushort4(inValue, inMinValue, inMaxValue, out, true); 2178 out.destroy(); 2179 } catch (Exception e) { 2180 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort4Ushort4Ushort4Ushort4: " + e.toString()); 2181 } 2182 inValue.destroy(); 2183 inMinValue.destroy(); 2184 inMaxValue.destroy(); 2185 } 2186 verifyResultsClampUshort4Ushort4Ushort4Ushort4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)2187 private void verifyResultsClampUshort4Ushort4Ushort4Ushort4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 2188 short[] arrayInValue = new short[INPUTSIZE * 4]; 2189 Arrays.fill(arrayInValue, (short) 42); 2190 inValue.copyTo(arrayInValue); 2191 short[] arrayInMinValue = new short[INPUTSIZE * 4]; 2192 Arrays.fill(arrayInMinValue, (short) 42); 2193 inMinValue.copyTo(arrayInMinValue); 2194 short[] arrayInMaxValue = new short[INPUTSIZE * 4]; 2195 Arrays.fill(arrayInMaxValue, (short) 42); 2196 inMaxValue.copyTo(arrayInMaxValue); 2197 short[] arrayOut = new short[INPUTSIZE * 4]; 2198 Arrays.fill(arrayOut, (short) 42); 2199 out.copyTo(arrayOut); 2200 StringBuilder message = new StringBuilder(); 2201 boolean errorFound = false; 2202 for (int i = 0; i < INPUTSIZE; i++) { 2203 for (int j = 0; j < 4 ; j++) { 2204 // Extract the inputs. 2205 ArgumentsUshortUshortUshortUshort args = new ArgumentsUshortUshortUshortUshort(); 2206 args.inValue = arrayInValue[i * 4 + j]; 2207 args.inMinValue = arrayInMinValue[i * 4 + j]; 2208 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 2209 // Figure out what the outputs should have been. 2210 CoreMathVerifier.computeClamp(args); 2211 // Validate the outputs. 2212 boolean valid = true; 2213 if (args.out != arrayOut[i * 4 + j]) { 2214 valid = false; 2215 } 2216 if (!valid) { 2217 if (!errorFound) { 2218 errorFound = true; 2219 message.append("Input inValue: "); 2220 appendVariableToMessage(message, args.inValue); 2221 message.append("\n"); 2222 message.append("Input inMinValue: "); 2223 appendVariableToMessage(message, args.inMinValue); 2224 message.append("\n"); 2225 message.append("Input inMaxValue: "); 2226 appendVariableToMessage(message, args.inMaxValue); 2227 message.append("\n"); 2228 message.append("Expected output out: "); 2229 appendVariableToMessage(message, args.out); 2230 message.append("\n"); 2231 message.append("Actual output out: "); 2232 appendVariableToMessage(message, arrayOut[i * 4 + j]); 2233 if (args.out != arrayOut[i * 4 + j]) { 2234 message.append(" FAIL"); 2235 } 2236 message.append("\n"); 2237 message.append("Errors at"); 2238 } 2239 message.append(" ["); 2240 message.append(Integer.toString(i)); 2241 message.append(", "); 2242 message.append(Integer.toString(j)); 2243 message.append("]"); 2244 } 2245 } 2246 } 2247 assertFalse("Incorrect output for checkClampUshort4Ushort4Ushort4Ushort4" + 2248 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 2249 } 2250 2251 public class ArgumentsIntIntIntInt { 2252 public int inValue; 2253 public int inMinValue; 2254 public int inMaxValue; 2255 public int out; 2256 } 2257 checkClampIntIntIntInt()2258 private void checkClampIntIntIntInt() { 2259 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0xfeb3aa11be6164c5l, false); 2260 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0xd11c228c7c8bf97fl, false); 2261 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0xd11c22810de8eb85l, false); 2262 enforceOrdering(inMinValue, inMaxValue); 2263 try { 2264 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE); 2265 script.set_gAllocInMinValue(inMinValue); 2266 script.set_gAllocInMaxValue(inMaxValue); 2267 script.forEach_testClampIntIntIntInt(inValue, out); 2268 verifyResultsClampIntIntIntInt(inValue, inMinValue, inMaxValue, out, false); 2269 out.destroy(); 2270 } catch (Exception e) { 2271 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampIntIntIntInt: " + e.toString()); 2272 } 2273 try { 2274 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE); 2275 scriptRelaxed.set_gAllocInMinValue(inMinValue); 2276 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 2277 scriptRelaxed.forEach_testClampIntIntIntInt(inValue, out); 2278 verifyResultsClampIntIntIntInt(inValue, inMinValue, inMaxValue, out, true); 2279 out.destroy(); 2280 } catch (Exception e) { 2281 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampIntIntIntInt: " + e.toString()); 2282 } 2283 inValue.destroy(); 2284 inMinValue.destroy(); 2285 inMaxValue.destroy(); 2286 } 2287 verifyResultsClampIntIntIntInt(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)2288 private void verifyResultsClampIntIntIntInt(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 2289 int[] arrayInValue = new int[INPUTSIZE * 1]; 2290 Arrays.fill(arrayInValue, (int) 42); 2291 inValue.copyTo(arrayInValue); 2292 int[] arrayInMinValue = new int[INPUTSIZE * 1]; 2293 Arrays.fill(arrayInMinValue, (int) 42); 2294 inMinValue.copyTo(arrayInMinValue); 2295 int[] arrayInMaxValue = new int[INPUTSIZE * 1]; 2296 Arrays.fill(arrayInMaxValue, (int) 42); 2297 inMaxValue.copyTo(arrayInMaxValue); 2298 int[] arrayOut = new int[INPUTSIZE * 1]; 2299 Arrays.fill(arrayOut, (int) 42); 2300 out.copyTo(arrayOut); 2301 StringBuilder message = new StringBuilder(); 2302 boolean errorFound = false; 2303 for (int i = 0; i < INPUTSIZE; i++) { 2304 for (int j = 0; j < 1 ; j++) { 2305 // Extract the inputs. 2306 ArgumentsIntIntIntInt args = new ArgumentsIntIntIntInt(); 2307 args.inValue = arrayInValue[i]; 2308 args.inMinValue = arrayInMinValue[i]; 2309 args.inMaxValue = arrayInMaxValue[i]; 2310 // Figure out what the outputs should have been. 2311 CoreMathVerifier.computeClamp(args); 2312 // Validate the outputs. 2313 boolean valid = true; 2314 if (args.out != arrayOut[i * 1 + j]) { 2315 valid = false; 2316 } 2317 if (!valid) { 2318 if (!errorFound) { 2319 errorFound = true; 2320 message.append("Input inValue: "); 2321 appendVariableToMessage(message, args.inValue); 2322 message.append("\n"); 2323 message.append("Input inMinValue: "); 2324 appendVariableToMessage(message, args.inMinValue); 2325 message.append("\n"); 2326 message.append("Input inMaxValue: "); 2327 appendVariableToMessage(message, args.inMaxValue); 2328 message.append("\n"); 2329 message.append("Expected output out: "); 2330 appendVariableToMessage(message, args.out); 2331 message.append("\n"); 2332 message.append("Actual output out: "); 2333 appendVariableToMessage(message, arrayOut[i * 1 + j]); 2334 if (args.out != arrayOut[i * 1 + j]) { 2335 message.append(" FAIL"); 2336 } 2337 message.append("\n"); 2338 message.append("Errors at"); 2339 } 2340 message.append(" ["); 2341 message.append(Integer.toString(i)); 2342 message.append(", "); 2343 message.append(Integer.toString(j)); 2344 message.append("]"); 2345 } 2346 } 2347 } 2348 assertFalse("Incorrect output for checkClampIntIntIntInt" + 2349 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 2350 } 2351 checkClampInt2Int2Int2Int2()2352 private void checkClampInt2Int2Int2Int2() { 2353 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x56252903bd307c01l, false); 2354 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x770112109398f8f3l, false); 2355 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x7701120524f5eaf9l, false); 2356 enforceOrdering(inMinValue, inMaxValue); 2357 try { 2358 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE); 2359 script.set_gAllocInMinValue(inMinValue); 2360 script.set_gAllocInMaxValue(inMaxValue); 2361 script.forEach_testClampInt2Int2Int2Int2(inValue, out); 2362 verifyResultsClampInt2Int2Int2Int2(inValue, inMinValue, inMaxValue, out, false); 2363 out.destroy(); 2364 } catch (Exception e) { 2365 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt2Int2Int2Int2: " + e.toString()); 2366 } 2367 try { 2368 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE); 2369 scriptRelaxed.set_gAllocInMinValue(inMinValue); 2370 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 2371 scriptRelaxed.forEach_testClampInt2Int2Int2Int2(inValue, out); 2372 verifyResultsClampInt2Int2Int2Int2(inValue, inMinValue, inMaxValue, out, true); 2373 out.destroy(); 2374 } catch (Exception e) { 2375 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt2Int2Int2Int2: " + e.toString()); 2376 } 2377 inValue.destroy(); 2378 inMinValue.destroy(); 2379 inMaxValue.destroy(); 2380 } 2381 verifyResultsClampInt2Int2Int2Int2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)2382 private void verifyResultsClampInt2Int2Int2Int2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 2383 int[] arrayInValue = new int[INPUTSIZE * 2]; 2384 Arrays.fill(arrayInValue, (int) 42); 2385 inValue.copyTo(arrayInValue); 2386 int[] arrayInMinValue = new int[INPUTSIZE * 2]; 2387 Arrays.fill(arrayInMinValue, (int) 42); 2388 inMinValue.copyTo(arrayInMinValue); 2389 int[] arrayInMaxValue = new int[INPUTSIZE * 2]; 2390 Arrays.fill(arrayInMaxValue, (int) 42); 2391 inMaxValue.copyTo(arrayInMaxValue); 2392 int[] arrayOut = new int[INPUTSIZE * 2]; 2393 Arrays.fill(arrayOut, (int) 42); 2394 out.copyTo(arrayOut); 2395 StringBuilder message = new StringBuilder(); 2396 boolean errorFound = false; 2397 for (int i = 0; i < INPUTSIZE; i++) { 2398 for (int j = 0; j < 2 ; j++) { 2399 // Extract the inputs. 2400 ArgumentsIntIntIntInt args = new ArgumentsIntIntIntInt(); 2401 args.inValue = arrayInValue[i * 2 + j]; 2402 args.inMinValue = arrayInMinValue[i * 2 + j]; 2403 args.inMaxValue = arrayInMaxValue[i * 2 + j]; 2404 // Figure out what the outputs should have been. 2405 CoreMathVerifier.computeClamp(args); 2406 // Validate the outputs. 2407 boolean valid = true; 2408 if (args.out != arrayOut[i * 2 + j]) { 2409 valid = false; 2410 } 2411 if (!valid) { 2412 if (!errorFound) { 2413 errorFound = true; 2414 message.append("Input inValue: "); 2415 appendVariableToMessage(message, args.inValue); 2416 message.append("\n"); 2417 message.append("Input inMinValue: "); 2418 appendVariableToMessage(message, args.inMinValue); 2419 message.append("\n"); 2420 message.append("Input inMaxValue: "); 2421 appendVariableToMessage(message, args.inMaxValue); 2422 message.append("\n"); 2423 message.append("Expected output out: "); 2424 appendVariableToMessage(message, args.out); 2425 message.append("\n"); 2426 message.append("Actual output out: "); 2427 appendVariableToMessage(message, arrayOut[i * 2 + j]); 2428 if (args.out != arrayOut[i * 2 + j]) { 2429 message.append(" FAIL"); 2430 } 2431 message.append("\n"); 2432 message.append("Errors at"); 2433 } 2434 message.append(" ["); 2435 message.append(Integer.toString(i)); 2436 message.append(", "); 2437 message.append(Integer.toString(j)); 2438 message.append("]"); 2439 } 2440 } 2441 } 2442 assertFalse("Incorrect output for checkClampInt2Int2Int2Int2" + 2443 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 2444 } 2445 checkClampInt3Int3Int3Int3()2446 private void checkClampInt3Int3Int3Int3() { 2447 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x966882045600d2edl, false); 2448 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 3, 0xeb73e6749c7caa77l, false); 2449 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 3, 0xeb73e6692dd99c7dl, false); 2450 enforceOrdering(inMinValue, inMaxValue); 2451 try { 2452 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE); 2453 script.set_gAllocInMinValue(inMinValue); 2454 script.set_gAllocInMaxValue(inMaxValue); 2455 script.forEach_testClampInt3Int3Int3Int3(inValue, out); 2456 verifyResultsClampInt3Int3Int3Int3(inValue, inMinValue, inMaxValue, out, false); 2457 out.destroy(); 2458 } catch (Exception e) { 2459 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt3Int3Int3Int3: " + e.toString()); 2460 } 2461 try { 2462 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE); 2463 scriptRelaxed.set_gAllocInMinValue(inMinValue); 2464 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 2465 scriptRelaxed.forEach_testClampInt3Int3Int3Int3(inValue, out); 2466 verifyResultsClampInt3Int3Int3Int3(inValue, inMinValue, inMaxValue, out, true); 2467 out.destroy(); 2468 } catch (Exception e) { 2469 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt3Int3Int3Int3: " + e.toString()); 2470 } 2471 inValue.destroy(); 2472 inMinValue.destroy(); 2473 inMaxValue.destroy(); 2474 } 2475 verifyResultsClampInt3Int3Int3Int3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)2476 private void verifyResultsClampInt3Int3Int3Int3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 2477 int[] arrayInValue = new int[INPUTSIZE * 4]; 2478 Arrays.fill(arrayInValue, (int) 42); 2479 inValue.copyTo(arrayInValue); 2480 int[] arrayInMinValue = new int[INPUTSIZE * 4]; 2481 Arrays.fill(arrayInMinValue, (int) 42); 2482 inMinValue.copyTo(arrayInMinValue); 2483 int[] arrayInMaxValue = new int[INPUTSIZE * 4]; 2484 Arrays.fill(arrayInMaxValue, (int) 42); 2485 inMaxValue.copyTo(arrayInMaxValue); 2486 int[] arrayOut = new int[INPUTSIZE * 4]; 2487 Arrays.fill(arrayOut, (int) 42); 2488 out.copyTo(arrayOut); 2489 StringBuilder message = new StringBuilder(); 2490 boolean errorFound = false; 2491 for (int i = 0; i < INPUTSIZE; i++) { 2492 for (int j = 0; j < 3 ; j++) { 2493 // Extract the inputs. 2494 ArgumentsIntIntIntInt args = new ArgumentsIntIntIntInt(); 2495 args.inValue = arrayInValue[i * 4 + j]; 2496 args.inMinValue = arrayInMinValue[i * 4 + j]; 2497 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 2498 // Figure out what the outputs should have been. 2499 CoreMathVerifier.computeClamp(args); 2500 // Validate the outputs. 2501 boolean valid = true; 2502 if (args.out != arrayOut[i * 4 + j]) { 2503 valid = false; 2504 } 2505 if (!valid) { 2506 if (!errorFound) { 2507 errorFound = true; 2508 message.append("Input inValue: "); 2509 appendVariableToMessage(message, args.inValue); 2510 message.append("\n"); 2511 message.append("Input inMinValue: "); 2512 appendVariableToMessage(message, args.inMinValue); 2513 message.append("\n"); 2514 message.append("Input inMaxValue: "); 2515 appendVariableToMessage(message, args.inMaxValue); 2516 message.append("\n"); 2517 message.append("Expected output out: "); 2518 appendVariableToMessage(message, args.out); 2519 message.append("\n"); 2520 message.append("Actual output out: "); 2521 appendVariableToMessage(message, arrayOut[i * 4 + j]); 2522 if (args.out != arrayOut[i * 4 + j]) { 2523 message.append(" FAIL"); 2524 } 2525 message.append("\n"); 2526 message.append("Errors at"); 2527 } 2528 message.append(" ["); 2529 message.append(Integer.toString(i)); 2530 message.append(", "); 2531 message.append(Integer.toString(j)); 2532 message.append("]"); 2533 } 2534 } 2535 } 2536 assertFalse("Incorrect output for checkClampInt3Int3Int3Int3" + 2537 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 2538 } 2539 checkClampInt4Int4Int4Int4()2540 private void checkClampInt4Int4Int4Int4() { 2541 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 4, 0xd6abdb04eed129d9l, false); 2542 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x5fe6bad8a5605bfbl, false); 2543 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x5fe6bacd36bd4e01l, false); 2544 enforceOrdering(inMinValue, inMaxValue); 2545 try { 2546 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE); 2547 script.set_gAllocInMinValue(inMinValue); 2548 script.set_gAllocInMaxValue(inMaxValue); 2549 script.forEach_testClampInt4Int4Int4Int4(inValue, out); 2550 verifyResultsClampInt4Int4Int4Int4(inValue, inMinValue, inMaxValue, out, false); 2551 out.destroy(); 2552 } catch (Exception e) { 2553 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt4Int4Int4Int4: " + e.toString()); 2554 } 2555 try { 2556 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE); 2557 scriptRelaxed.set_gAllocInMinValue(inMinValue); 2558 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 2559 scriptRelaxed.forEach_testClampInt4Int4Int4Int4(inValue, out); 2560 verifyResultsClampInt4Int4Int4Int4(inValue, inMinValue, inMaxValue, out, true); 2561 out.destroy(); 2562 } catch (Exception e) { 2563 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt4Int4Int4Int4: " + e.toString()); 2564 } 2565 inValue.destroy(); 2566 inMinValue.destroy(); 2567 inMaxValue.destroy(); 2568 } 2569 verifyResultsClampInt4Int4Int4Int4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)2570 private void verifyResultsClampInt4Int4Int4Int4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 2571 int[] arrayInValue = new int[INPUTSIZE * 4]; 2572 Arrays.fill(arrayInValue, (int) 42); 2573 inValue.copyTo(arrayInValue); 2574 int[] arrayInMinValue = new int[INPUTSIZE * 4]; 2575 Arrays.fill(arrayInMinValue, (int) 42); 2576 inMinValue.copyTo(arrayInMinValue); 2577 int[] arrayInMaxValue = new int[INPUTSIZE * 4]; 2578 Arrays.fill(arrayInMaxValue, (int) 42); 2579 inMaxValue.copyTo(arrayInMaxValue); 2580 int[] arrayOut = new int[INPUTSIZE * 4]; 2581 Arrays.fill(arrayOut, (int) 42); 2582 out.copyTo(arrayOut); 2583 StringBuilder message = new StringBuilder(); 2584 boolean errorFound = false; 2585 for (int i = 0; i < INPUTSIZE; i++) { 2586 for (int j = 0; j < 4 ; j++) { 2587 // Extract the inputs. 2588 ArgumentsIntIntIntInt args = new ArgumentsIntIntIntInt(); 2589 args.inValue = arrayInValue[i * 4 + j]; 2590 args.inMinValue = arrayInMinValue[i * 4 + j]; 2591 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 2592 // Figure out what the outputs should have been. 2593 CoreMathVerifier.computeClamp(args); 2594 // Validate the outputs. 2595 boolean valid = true; 2596 if (args.out != arrayOut[i * 4 + j]) { 2597 valid = false; 2598 } 2599 if (!valid) { 2600 if (!errorFound) { 2601 errorFound = true; 2602 message.append("Input inValue: "); 2603 appendVariableToMessage(message, args.inValue); 2604 message.append("\n"); 2605 message.append("Input inMinValue: "); 2606 appendVariableToMessage(message, args.inMinValue); 2607 message.append("\n"); 2608 message.append("Input inMaxValue: "); 2609 appendVariableToMessage(message, args.inMaxValue); 2610 message.append("\n"); 2611 message.append("Expected output out: "); 2612 appendVariableToMessage(message, args.out); 2613 message.append("\n"); 2614 message.append("Actual output out: "); 2615 appendVariableToMessage(message, arrayOut[i * 4 + j]); 2616 if (args.out != arrayOut[i * 4 + j]) { 2617 message.append(" FAIL"); 2618 } 2619 message.append("\n"); 2620 message.append("Errors at"); 2621 } 2622 message.append(" ["); 2623 message.append(Integer.toString(i)); 2624 message.append(", "); 2625 message.append(Integer.toString(j)); 2626 message.append("]"); 2627 } 2628 } 2629 } 2630 assertFalse("Incorrect output for checkClampInt4Int4Int4Int4" + 2631 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 2632 } 2633 2634 public class ArgumentsUintUintUintUint { 2635 public int inValue; 2636 public int inMinValue; 2637 public int inMaxValue; 2638 public int out; 2639 } 2640 checkClampUintUintUintUint()2641 private void checkClampUintUintUintUint() { 2642 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0xd8df32b2efc89475l, false); 2643 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0xcf8ec8eece8b7b8fl, false); 2644 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0xcf8ec8e35fe86d95l, false); 2645 enforceOrdering(inMinValue, inMaxValue); 2646 try { 2647 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE); 2648 script.set_gAllocInMinValue(inMinValue); 2649 script.set_gAllocInMaxValue(inMaxValue); 2650 script.forEach_testClampUintUintUintUint(inValue, out); 2651 verifyResultsClampUintUintUintUint(inValue, inMinValue, inMaxValue, out, false); 2652 out.destroy(); 2653 } catch (Exception e) { 2654 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUintUintUintUint: " + e.toString()); 2655 } 2656 try { 2657 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE); 2658 scriptRelaxed.set_gAllocInMinValue(inMinValue); 2659 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 2660 scriptRelaxed.forEach_testClampUintUintUintUint(inValue, out); 2661 verifyResultsClampUintUintUintUint(inValue, inMinValue, inMaxValue, out, true); 2662 out.destroy(); 2663 } catch (Exception e) { 2664 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUintUintUintUint: " + e.toString()); 2665 } 2666 inValue.destroy(); 2667 inMinValue.destroy(); 2668 inMaxValue.destroy(); 2669 } 2670 verifyResultsClampUintUintUintUint(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)2671 private void verifyResultsClampUintUintUintUint(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 2672 int[] arrayInValue = new int[INPUTSIZE * 1]; 2673 Arrays.fill(arrayInValue, (int) 42); 2674 inValue.copyTo(arrayInValue); 2675 int[] arrayInMinValue = new int[INPUTSIZE * 1]; 2676 Arrays.fill(arrayInMinValue, (int) 42); 2677 inMinValue.copyTo(arrayInMinValue); 2678 int[] arrayInMaxValue = new int[INPUTSIZE * 1]; 2679 Arrays.fill(arrayInMaxValue, (int) 42); 2680 inMaxValue.copyTo(arrayInMaxValue); 2681 int[] arrayOut = new int[INPUTSIZE * 1]; 2682 Arrays.fill(arrayOut, (int) 42); 2683 out.copyTo(arrayOut); 2684 StringBuilder message = new StringBuilder(); 2685 boolean errorFound = false; 2686 for (int i = 0; i < INPUTSIZE; i++) { 2687 for (int j = 0; j < 1 ; j++) { 2688 // Extract the inputs. 2689 ArgumentsUintUintUintUint args = new ArgumentsUintUintUintUint(); 2690 args.inValue = arrayInValue[i]; 2691 args.inMinValue = arrayInMinValue[i]; 2692 args.inMaxValue = arrayInMaxValue[i]; 2693 // Figure out what the outputs should have been. 2694 CoreMathVerifier.computeClamp(args); 2695 // Validate the outputs. 2696 boolean valid = true; 2697 if (args.out != arrayOut[i * 1 + j]) { 2698 valid = false; 2699 } 2700 if (!valid) { 2701 if (!errorFound) { 2702 errorFound = true; 2703 message.append("Input inValue: "); 2704 appendVariableToMessage(message, args.inValue); 2705 message.append("\n"); 2706 message.append("Input inMinValue: "); 2707 appendVariableToMessage(message, args.inMinValue); 2708 message.append("\n"); 2709 message.append("Input inMaxValue: "); 2710 appendVariableToMessage(message, args.inMaxValue); 2711 message.append("\n"); 2712 message.append("Expected output out: "); 2713 appendVariableToMessage(message, args.out); 2714 message.append("\n"); 2715 message.append("Actual output out: "); 2716 appendVariableToMessage(message, arrayOut[i * 1 + j]); 2717 if (args.out != arrayOut[i * 1 + j]) { 2718 message.append(" FAIL"); 2719 } 2720 message.append("\n"); 2721 message.append("Errors at"); 2722 } 2723 message.append(" ["); 2724 message.append(Integer.toString(i)); 2725 message.append(", "); 2726 message.append(Integer.toString(j)); 2727 message.append("]"); 2728 } 2729 } 2730 } 2731 assertFalse("Incorrect output for checkClampUintUintUintUint" + 2732 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 2733 } 2734 checkClampUint2Uint2Uint2Uint2()2735 private void checkClampUint2Uint2Uint2Uint2() { 2736 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0xaf28d478873ae5dl, false); 2737 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0x5bbd21aa2a4bc7l, false); 2738 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0x5bbd163b873dcdl, false); 2739 enforceOrdering(inMinValue, inMaxValue); 2740 try { 2741 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE); 2742 script.set_gAllocInMinValue(inMinValue); 2743 script.set_gAllocInMaxValue(inMaxValue); 2744 script.forEach_testClampUint2Uint2Uint2Uint2(inValue, out); 2745 verifyResultsClampUint2Uint2Uint2Uint2(inValue, inMinValue, inMaxValue, out, false); 2746 out.destroy(); 2747 } catch (Exception e) { 2748 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint2Uint2Uint2Uint2: " + e.toString()); 2749 } 2750 try { 2751 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE); 2752 scriptRelaxed.set_gAllocInMinValue(inMinValue); 2753 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 2754 scriptRelaxed.forEach_testClampUint2Uint2Uint2Uint2(inValue, out); 2755 verifyResultsClampUint2Uint2Uint2Uint2(inValue, inMinValue, inMaxValue, out, true); 2756 out.destroy(); 2757 } catch (Exception e) { 2758 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint2Uint2Uint2Uint2: " + e.toString()); 2759 } 2760 inValue.destroy(); 2761 inMinValue.destroy(); 2762 inMaxValue.destroy(); 2763 } 2764 verifyResultsClampUint2Uint2Uint2Uint2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)2765 private void verifyResultsClampUint2Uint2Uint2Uint2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 2766 int[] arrayInValue = new int[INPUTSIZE * 2]; 2767 Arrays.fill(arrayInValue, (int) 42); 2768 inValue.copyTo(arrayInValue); 2769 int[] arrayInMinValue = new int[INPUTSIZE * 2]; 2770 Arrays.fill(arrayInMinValue, (int) 42); 2771 inMinValue.copyTo(arrayInMinValue); 2772 int[] arrayInMaxValue = new int[INPUTSIZE * 2]; 2773 Arrays.fill(arrayInMaxValue, (int) 42); 2774 inMaxValue.copyTo(arrayInMaxValue); 2775 int[] arrayOut = new int[INPUTSIZE * 2]; 2776 Arrays.fill(arrayOut, (int) 42); 2777 out.copyTo(arrayOut); 2778 StringBuilder message = new StringBuilder(); 2779 boolean errorFound = false; 2780 for (int i = 0; i < INPUTSIZE; i++) { 2781 for (int j = 0; j < 2 ; j++) { 2782 // Extract the inputs. 2783 ArgumentsUintUintUintUint args = new ArgumentsUintUintUintUint(); 2784 args.inValue = arrayInValue[i * 2 + j]; 2785 args.inMinValue = arrayInMinValue[i * 2 + j]; 2786 args.inMaxValue = arrayInMaxValue[i * 2 + j]; 2787 // Figure out what the outputs should have been. 2788 CoreMathVerifier.computeClamp(args); 2789 // Validate the outputs. 2790 boolean valid = true; 2791 if (args.out != arrayOut[i * 2 + j]) { 2792 valid = false; 2793 } 2794 if (!valid) { 2795 if (!errorFound) { 2796 errorFound = true; 2797 message.append("Input inValue: "); 2798 appendVariableToMessage(message, args.inValue); 2799 message.append("\n"); 2800 message.append("Input inMinValue: "); 2801 appendVariableToMessage(message, args.inMinValue); 2802 message.append("\n"); 2803 message.append("Input inMaxValue: "); 2804 appendVariableToMessage(message, args.inMaxValue); 2805 message.append("\n"); 2806 message.append("Expected output out: "); 2807 appendVariableToMessage(message, args.out); 2808 message.append("\n"); 2809 message.append("Actual output out: "); 2810 appendVariableToMessage(message, arrayOut[i * 2 + j]); 2811 if (args.out != arrayOut[i * 2 + j]) { 2812 message.append(" FAIL"); 2813 } 2814 message.append("\n"); 2815 message.append("Errors at"); 2816 } 2817 message.append(" ["); 2818 message.append(Integer.toString(i)); 2819 message.append(", "); 2820 message.append(Integer.toString(j)); 2821 message.append("]"); 2822 } 2823 } 2824 } 2825 assertFalse("Incorrect output for checkClampUint2Uint2Uint2Uint2" + 2826 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 2827 } 2828 checkClampUint3Uint3Uint3Uint3()2829 private void checkClampUint3Uint3Uint3Uint3() { 2830 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0x639fab187e48aaa5l, false); 2831 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0x8ddee5cebcf6591fl, false); 2832 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0x8ddee5c34e534b25l, false); 2833 enforceOrdering(inMinValue, inMaxValue); 2834 try { 2835 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE); 2836 script.set_gAllocInMinValue(inMinValue); 2837 script.set_gAllocInMaxValue(inMaxValue); 2838 script.forEach_testClampUint3Uint3Uint3Uint3(inValue, out); 2839 verifyResultsClampUint3Uint3Uint3Uint3(inValue, inMinValue, inMaxValue, out, false); 2840 out.destroy(); 2841 } catch (Exception e) { 2842 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint3Uint3Uint3Uint3: " + e.toString()); 2843 } 2844 try { 2845 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE); 2846 scriptRelaxed.set_gAllocInMinValue(inMinValue); 2847 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 2848 scriptRelaxed.forEach_testClampUint3Uint3Uint3Uint3(inValue, out); 2849 verifyResultsClampUint3Uint3Uint3Uint3(inValue, inMinValue, inMaxValue, out, true); 2850 out.destroy(); 2851 } catch (Exception e) { 2852 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint3Uint3Uint3Uint3: " + e.toString()); 2853 } 2854 inValue.destroy(); 2855 inMinValue.destroy(); 2856 inMaxValue.destroy(); 2857 } 2858 verifyResultsClampUint3Uint3Uint3Uint3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)2859 private void verifyResultsClampUint3Uint3Uint3Uint3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 2860 int[] arrayInValue = new int[INPUTSIZE * 4]; 2861 Arrays.fill(arrayInValue, (int) 42); 2862 inValue.copyTo(arrayInValue); 2863 int[] arrayInMinValue = new int[INPUTSIZE * 4]; 2864 Arrays.fill(arrayInMinValue, (int) 42); 2865 inMinValue.copyTo(arrayInMinValue); 2866 int[] arrayInMaxValue = new int[INPUTSIZE * 4]; 2867 Arrays.fill(arrayInMaxValue, (int) 42); 2868 inMaxValue.copyTo(arrayInMaxValue); 2869 int[] arrayOut = new int[INPUTSIZE * 4]; 2870 Arrays.fill(arrayOut, (int) 42); 2871 out.copyTo(arrayOut); 2872 StringBuilder message = new StringBuilder(); 2873 boolean errorFound = false; 2874 for (int i = 0; i < INPUTSIZE; i++) { 2875 for (int j = 0; j < 3 ; j++) { 2876 // Extract the inputs. 2877 ArgumentsUintUintUintUint args = new ArgumentsUintUintUintUint(); 2878 args.inValue = arrayInValue[i * 4 + j]; 2879 args.inMinValue = arrayInMinValue[i * 4 + j]; 2880 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 2881 // Figure out what the outputs should have been. 2882 CoreMathVerifier.computeClamp(args); 2883 // Validate the outputs. 2884 boolean valid = true; 2885 if (args.out != arrayOut[i * 4 + j]) { 2886 valid = false; 2887 } 2888 if (!valid) { 2889 if (!errorFound) { 2890 errorFound = true; 2891 message.append("Input inValue: "); 2892 appendVariableToMessage(message, args.inValue); 2893 message.append("\n"); 2894 message.append("Input inMinValue: "); 2895 appendVariableToMessage(message, args.inMinValue); 2896 message.append("\n"); 2897 message.append("Input inMaxValue: "); 2898 appendVariableToMessage(message, args.inMaxValue); 2899 message.append("\n"); 2900 message.append("Expected output out: "); 2901 appendVariableToMessage(message, args.out); 2902 message.append("\n"); 2903 message.append("Actual output out: "); 2904 appendVariableToMessage(message, arrayOut[i * 4 + j]); 2905 if (args.out != arrayOut[i * 4 + j]) { 2906 message.append(" FAIL"); 2907 } 2908 message.append("\n"); 2909 message.append("Errors at"); 2910 } 2911 message.append(" ["); 2912 message.append(Integer.toString(i)); 2913 message.append(", "); 2914 message.append(Integer.toString(j)); 2915 message.append("]"); 2916 } 2917 } 2918 } 2919 assertFalse("Incorrect output for checkClampUint3Uint3Uint3Uint3" + 2920 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 2921 } 2922 checkClampUint4Uint4Uint4Uint4()2923 private void checkClampUint4Uint4Uint4Uint4() { 2924 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0xbc4cc8e9741da6edl, false); 2925 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0x1b620e7bcfc26677l, false); 2926 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0x1b620e70611f587dl, false); 2927 enforceOrdering(inMinValue, inMaxValue); 2928 try { 2929 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE); 2930 script.set_gAllocInMinValue(inMinValue); 2931 script.set_gAllocInMaxValue(inMaxValue); 2932 script.forEach_testClampUint4Uint4Uint4Uint4(inValue, out); 2933 verifyResultsClampUint4Uint4Uint4Uint4(inValue, inMinValue, inMaxValue, out, false); 2934 out.destroy(); 2935 } catch (Exception e) { 2936 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint4Uint4Uint4Uint4: " + e.toString()); 2937 } 2938 try { 2939 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE); 2940 scriptRelaxed.set_gAllocInMinValue(inMinValue); 2941 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 2942 scriptRelaxed.forEach_testClampUint4Uint4Uint4Uint4(inValue, out); 2943 verifyResultsClampUint4Uint4Uint4Uint4(inValue, inMinValue, inMaxValue, out, true); 2944 out.destroy(); 2945 } catch (Exception e) { 2946 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint4Uint4Uint4Uint4: " + e.toString()); 2947 } 2948 inValue.destroy(); 2949 inMinValue.destroy(); 2950 inMaxValue.destroy(); 2951 } 2952 verifyResultsClampUint4Uint4Uint4Uint4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)2953 private void verifyResultsClampUint4Uint4Uint4Uint4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 2954 int[] arrayInValue = new int[INPUTSIZE * 4]; 2955 Arrays.fill(arrayInValue, (int) 42); 2956 inValue.copyTo(arrayInValue); 2957 int[] arrayInMinValue = new int[INPUTSIZE * 4]; 2958 Arrays.fill(arrayInMinValue, (int) 42); 2959 inMinValue.copyTo(arrayInMinValue); 2960 int[] arrayInMaxValue = new int[INPUTSIZE * 4]; 2961 Arrays.fill(arrayInMaxValue, (int) 42); 2962 inMaxValue.copyTo(arrayInMaxValue); 2963 int[] arrayOut = new int[INPUTSIZE * 4]; 2964 Arrays.fill(arrayOut, (int) 42); 2965 out.copyTo(arrayOut); 2966 StringBuilder message = new StringBuilder(); 2967 boolean errorFound = false; 2968 for (int i = 0; i < INPUTSIZE; i++) { 2969 for (int j = 0; j < 4 ; j++) { 2970 // Extract the inputs. 2971 ArgumentsUintUintUintUint args = new ArgumentsUintUintUintUint(); 2972 args.inValue = arrayInValue[i * 4 + j]; 2973 args.inMinValue = arrayInMinValue[i * 4 + j]; 2974 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 2975 // Figure out what the outputs should have been. 2976 CoreMathVerifier.computeClamp(args); 2977 // Validate the outputs. 2978 boolean valid = true; 2979 if (args.out != arrayOut[i * 4 + j]) { 2980 valid = false; 2981 } 2982 if (!valid) { 2983 if (!errorFound) { 2984 errorFound = true; 2985 message.append("Input inValue: "); 2986 appendVariableToMessage(message, args.inValue); 2987 message.append("\n"); 2988 message.append("Input inMinValue: "); 2989 appendVariableToMessage(message, args.inMinValue); 2990 message.append("\n"); 2991 message.append("Input inMaxValue: "); 2992 appendVariableToMessage(message, args.inMaxValue); 2993 message.append("\n"); 2994 message.append("Expected output out: "); 2995 appendVariableToMessage(message, args.out); 2996 message.append("\n"); 2997 message.append("Actual output out: "); 2998 appendVariableToMessage(message, arrayOut[i * 4 + j]); 2999 if (args.out != arrayOut[i * 4 + j]) { 3000 message.append(" FAIL"); 3001 } 3002 message.append("\n"); 3003 message.append("Errors at"); 3004 } 3005 message.append(" ["); 3006 message.append(Integer.toString(i)); 3007 message.append(", "); 3008 message.append(Integer.toString(j)); 3009 message.append("]"); 3010 } 3011 } 3012 } 3013 assertFalse("Incorrect output for checkClampUint4Uint4Uint4Uint4" + 3014 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 3015 } 3016 3017 public class ArgumentsLongLongLongLong { 3018 public long inValue; 3019 public long inMinValue; 3020 public long inMaxValue; 3021 public long out; 3022 } 3023 checkClampLongLongLongLong()3024 private void checkClampLongLongLongLong() { 3025 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 1, 0x63fd360531c9c41dl, false); 3026 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 1, 0x9d04d1824ef4907l, false); 3027 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 1, 0x9d04d0cb64c3b0dl, false); 3028 enforceOrdering(inMinValue, inMaxValue); 3029 try { 3030 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 1), INPUTSIZE); 3031 script.set_gAllocInMinValue(inMinValue); 3032 script.set_gAllocInMaxValue(inMaxValue); 3033 script.forEach_testClampLongLongLongLong(inValue, out); 3034 verifyResultsClampLongLongLongLong(inValue, inMinValue, inMaxValue, out, false); 3035 out.destroy(); 3036 } catch (Exception e) { 3037 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLongLongLongLong: " + e.toString()); 3038 } 3039 try { 3040 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 1), INPUTSIZE); 3041 scriptRelaxed.set_gAllocInMinValue(inMinValue); 3042 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 3043 scriptRelaxed.forEach_testClampLongLongLongLong(inValue, out); 3044 verifyResultsClampLongLongLongLong(inValue, inMinValue, inMaxValue, out, true); 3045 out.destroy(); 3046 } catch (Exception e) { 3047 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLongLongLongLong: " + e.toString()); 3048 } 3049 inValue.destroy(); 3050 inMinValue.destroy(); 3051 inMaxValue.destroy(); 3052 } 3053 verifyResultsClampLongLongLongLong(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)3054 private void verifyResultsClampLongLongLongLong(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 3055 long[] arrayInValue = new long[INPUTSIZE * 1]; 3056 Arrays.fill(arrayInValue, (long) 42); 3057 inValue.copyTo(arrayInValue); 3058 long[] arrayInMinValue = new long[INPUTSIZE * 1]; 3059 Arrays.fill(arrayInMinValue, (long) 42); 3060 inMinValue.copyTo(arrayInMinValue); 3061 long[] arrayInMaxValue = new long[INPUTSIZE * 1]; 3062 Arrays.fill(arrayInMaxValue, (long) 42); 3063 inMaxValue.copyTo(arrayInMaxValue); 3064 long[] arrayOut = new long[INPUTSIZE * 1]; 3065 Arrays.fill(arrayOut, (long) 42); 3066 out.copyTo(arrayOut); 3067 StringBuilder message = new StringBuilder(); 3068 boolean errorFound = false; 3069 for (int i = 0; i < INPUTSIZE; i++) { 3070 for (int j = 0; j < 1 ; j++) { 3071 // Extract the inputs. 3072 ArgumentsLongLongLongLong args = new ArgumentsLongLongLongLong(); 3073 args.inValue = arrayInValue[i]; 3074 args.inMinValue = arrayInMinValue[i]; 3075 args.inMaxValue = arrayInMaxValue[i]; 3076 // Figure out what the outputs should have been. 3077 CoreMathVerifier.computeClamp(args); 3078 // Validate the outputs. 3079 boolean valid = true; 3080 if (args.out != arrayOut[i * 1 + j]) { 3081 valid = false; 3082 } 3083 if (!valid) { 3084 if (!errorFound) { 3085 errorFound = true; 3086 message.append("Input inValue: "); 3087 appendVariableToMessage(message, args.inValue); 3088 message.append("\n"); 3089 message.append("Input inMinValue: "); 3090 appendVariableToMessage(message, args.inMinValue); 3091 message.append("\n"); 3092 message.append("Input inMaxValue: "); 3093 appendVariableToMessage(message, args.inMaxValue); 3094 message.append("\n"); 3095 message.append("Expected output out: "); 3096 appendVariableToMessage(message, args.out); 3097 message.append("\n"); 3098 message.append("Actual output out: "); 3099 appendVariableToMessage(message, arrayOut[i * 1 + j]); 3100 if (args.out != arrayOut[i * 1 + j]) { 3101 message.append(" FAIL"); 3102 } 3103 message.append("\n"); 3104 message.append("Errors at"); 3105 } 3106 message.append(" ["); 3107 message.append(Integer.toString(i)); 3108 message.append(", "); 3109 message.append(Integer.toString(j)); 3110 message.append("]"); 3111 } 3112 } 3113 } 3114 assertFalse("Incorrect output for checkClampLongLongLongLong" + 3115 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 3116 } 3117 checkClampLong2Long2Long2Long2()3118 private void checkClampLong2Long2Long2Long2() { 3119 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 2, 0xccbae869c2b0f12dl, false); 3120 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 2, 0xe4c3844f4a3f8937l, false); 3121 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 2, 0xe4c38443db9c7b3dl, false); 3122 enforceOrdering(inMinValue, inMaxValue); 3123 try { 3124 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE); 3125 script.set_gAllocInMinValue(inMinValue); 3126 script.set_gAllocInMaxValue(inMaxValue); 3127 script.forEach_testClampLong2Long2Long2Long2(inValue, out); 3128 verifyResultsClampLong2Long2Long2Long2(inValue, inMinValue, inMaxValue, out, false); 3129 out.destroy(); 3130 } catch (Exception e) { 3131 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong2Long2Long2Long2: " + e.toString()); 3132 } 3133 try { 3134 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE); 3135 scriptRelaxed.set_gAllocInMinValue(inMinValue); 3136 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 3137 scriptRelaxed.forEach_testClampLong2Long2Long2Long2(inValue, out); 3138 verifyResultsClampLong2Long2Long2Long2(inValue, inMinValue, inMaxValue, out, true); 3139 out.destroy(); 3140 } catch (Exception e) { 3141 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong2Long2Long2Long2: " + e.toString()); 3142 } 3143 inValue.destroy(); 3144 inMinValue.destroy(); 3145 inMaxValue.destroy(); 3146 } 3147 verifyResultsClampLong2Long2Long2Long2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)3148 private void verifyResultsClampLong2Long2Long2Long2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 3149 long[] arrayInValue = new long[INPUTSIZE * 2]; 3150 Arrays.fill(arrayInValue, (long) 42); 3151 inValue.copyTo(arrayInValue); 3152 long[] arrayInMinValue = new long[INPUTSIZE * 2]; 3153 Arrays.fill(arrayInMinValue, (long) 42); 3154 inMinValue.copyTo(arrayInMinValue); 3155 long[] arrayInMaxValue = new long[INPUTSIZE * 2]; 3156 Arrays.fill(arrayInMaxValue, (long) 42); 3157 inMaxValue.copyTo(arrayInMaxValue); 3158 long[] arrayOut = new long[INPUTSIZE * 2]; 3159 Arrays.fill(arrayOut, (long) 42); 3160 out.copyTo(arrayOut); 3161 StringBuilder message = new StringBuilder(); 3162 boolean errorFound = false; 3163 for (int i = 0; i < INPUTSIZE; i++) { 3164 for (int j = 0; j < 2 ; j++) { 3165 // Extract the inputs. 3166 ArgumentsLongLongLongLong args = new ArgumentsLongLongLongLong(); 3167 args.inValue = arrayInValue[i * 2 + j]; 3168 args.inMinValue = arrayInMinValue[i * 2 + j]; 3169 args.inMaxValue = arrayInMaxValue[i * 2 + j]; 3170 // Figure out what the outputs should have been. 3171 CoreMathVerifier.computeClamp(args); 3172 // Validate the outputs. 3173 boolean valid = true; 3174 if (args.out != arrayOut[i * 2 + j]) { 3175 valid = false; 3176 } 3177 if (!valid) { 3178 if (!errorFound) { 3179 errorFound = true; 3180 message.append("Input inValue: "); 3181 appendVariableToMessage(message, args.inValue); 3182 message.append("\n"); 3183 message.append("Input inMinValue: "); 3184 appendVariableToMessage(message, args.inMinValue); 3185 message.append("\n"); 3186 message.append("Input inMaxValue: "); 3187 appendVariableToMessage(message, args.inMaxValue); 3188 message.append("\n"); 3189 message.append("Expected output out: "); 3190 appendVariableToMessage(message, args.out); 3191 message.append("\n"); 3192 message.append("Actual output out: "); 3193 appendVariableToMessage(message, arrayOut[i * 2 + j]); 3194 if (args.out != arrayOut[i * 2 + j]) { 3195 message.append(" FAIL"); 3196 } 3197 message.append("\n"); 3198 message.append("Errors at"); 3199 } 3200 message.append(" ["); 3201 message.append(Integer.toString(i)); 3202 message.append(", "); 3203 message.append(Integer.toString(j)); 3204 message.append("]"); 3205 } 3206 } 3207 } 3208 assertFalse("Incorrect output for checkClampLong2Long2Long2Long2" + 3209 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 3210 } 3211 checkClampLong3Long3Long3Long3()3212 private void checkClampLong3Long3Long3Long3() { 3213 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 3, 0x2568063ab885ed75l, false); 3214 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 3, 0x7246acfc5d0b968fl, false); 3215 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 3, 0x7246acf0ee688895l, false); 3216 enforceOrdering(inMinValue, inMaxValue); 3217 try { 3218 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE); 3219 script.set_gAllocInMinValue(inMinValue); 3220 script.set_gAllocInMaxValue(inMaxValue); 3221 script.forEach_testClampLong3Long3Long3Long3(inValue, out); 3222 verifyResultsClampLong3Long3Long3Long3(inValue, inMinValue, inMaxValue, out, false); 3223 out.destroy(); 3224 } catch (Exception e) { 3225 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong3Long3Long3Long3: " + e.toString()); 3226 } 3227 try { 3228 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE); 3229 scriptRelaxed.set_gAllocInMinValue(inMinValue); 3230 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 3231 scriptRelaxed.forEach_testClampLong3Long3Long3Long3(inValue, out); 3232 verifyResultsClampLong3Long3Long3Long3(inValue, inMinValue, inMaxValue, out, true); 3233 out.destroy(); 3234 } catch (Exception e) { 3235 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong3Long3Long3Long3: " + e.toString()); 3236 } 3237 inValue.destroy(); 3238 inMinValue.destroy(); 3239 inMaxValue.destroy(); 3240 } 3241 verifyResultsClampLong3Long3Long3Long3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)3242 private void verifyResultsClampLong3Long3Long3Long3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 3243 long[] arrayInValue = new long[INPUTSIZE * 4]; 3244 Arrays.fill(arrayInValue, (long) 42); 3245 inValue.copyTo(arrayInValue); 3246 long[] arrayInMinValue = new long[INPUTSIZE * 4]; 3247 Arrays.fill(arrayInMinValue, (long) 42); 3248 inMinValue.copyTo(arrayInMinValue); 3249 long[] arrayInMaxValue = new long[INPUTSIZE * 4]; 3250 Arrays.fill(arrayInMaxValue, (long) 42); 3251 inMaxValue.copyTo(arrayInMaxValue); 3252 long[] arrayOut = new long[INPUTSIZE * 4]; 3253 Arrays.fill(arrayOut, (long) 42); 3254 out.copyTo(arrayOut); 3255 StringBuilder message = new StringBuilder(); 3256 boolean errorFound = false; 3257 for (int i = 0; i < INPUTSIZE; i++) { 3258 for (int j = 0; j < 3 ; j++) { 3259 // Extract the inputs. 3260 ArgumentsLongLongLongLong args = new ArgumentsLongLongLongLong(); 3261 args.inValue = arrayInValue[i * 4 + j]; 3262 args.inMinValue = arrayInMinValue[i * 4 + j]; 3263 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 3264 // Figure out what the outputs should have been. 3265 CoreMathVerifier.computeClamp(args); 3266 // Validate the outputs. 3267 boolean valid = true; 3268 if (args.out != arrayOut[i * 4 + j]) { 3269 valid = false; 3270 } 3271 if (!valid) { 3272 if (!errorFound) { 3273 errorFound = true; 3274 message.append("Input inValue: "); 3275 appendVariableToMessage(message, args.inValue); 3276 message.append("\n"); 3277 message.append("Input inMinValue: "); 3278 appendVariableToMessage(message, args.inMinValue); 3279 message.append("\n"); 3280 message.append("Input inMaxValue: "); 3281 appendVariableToMessage(message, args.inMaxValue); 3282 message.append("\n"); 3283 message.append("Expected output out: "); 3284 appendVariableToMessage(message, args.out); 3285 message.append("\n"); 3286 message.append("Actual output out: "); 3287 appendVariableToMessage(message, arrayOut[i * 4 + j]); 3288 if (args.out != arrayOut[i * 4 + j]) { 3289 message.append(" FAIL"); 3290 } 3291 message.append("\n"); 3292 message.append("Errors at"); 3293 } 3294 message.append(" ["); 3295 message.append(Integer.toString(i)); 3296 message.append(", "); 3297 message.append(Integer.toString(j)); 3298 message.append("]"); 3299 } 3300 } 3301 } 3302 assertFalse("Incorrect output for checkClampLong3Long3Long3Long3" + 3303 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 3304 } 3305 checkClampLong4Long4Long4Long4()3306 private void checkClampLong4Long4Long4Long4() { 3307 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 4, 0x7e15240bae5ae9bdl, false); 3308 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 4, 0xffc9d5a96fd7a3e7l, false); 3309 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 4, 0xffc9d59e013495edl, false); 3310 enforceOrdering(inMinValue, inMaxValue); 3311 try { 3312 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE); 3313 script.set_gAllocInMinValue(inMinValue); 3314 script.set_gAllocInMaxValue(inMaxValue); 3315 script.forEach_testClampLong4Long4Long4Long4(inValue, out); 3316 verifyResultsClampLong4Long4Long4Long4(inValue, inMinValue, inMaxValue, out, false); 3317 out.destroy(); 3318 } catch (Exception e) { 3319 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong4Long4Long4Long4: " + e.toString()); 3320 } 3321 try { 3322 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE); 3323 scriptRelaxed.set_gAllocInMinValue(inMinValue); 3324 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 3325 scriptRelaxed.forEach_testClampLong4Long4Long4Long4(inValue, out); 3326 verifyResultsClampLong4Long4Long4Long4(inValue, inMinValue, inMaxValue, out, true); 3327 out.destroy(); 3328 } catch (Exception e) { 3329 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong4Long4Long4Long4: " + e.toString()); 3330 } 3331 inValue.destroy(); 3332 inMinValue.destroy(); 3333 inMaxValue.destroy(); 3334 } 3335 verifyResultsClampLong4Long4Long4Long4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)3336 private void verifyResultsClampLong4Long4Long4Long4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 3337 long[] arrayInValue = new long[INPUTSIZE * 4]; 3338 Arrays.fill(arrayInValue, (long) 42); 3339 inValue.copyTo(arrayInValue); 3340 long[] arrayInMinValue = new long[INPUTSIZE * 4]; 3341 Arrays.fill(arrayInMinValue, (long) 42); 3342 inMinValue.copyTo(arrayInMinValue); 3343 long[] arrayInMaxValue = new long[INPUTSIZE * 4]; 3344 Arrays.fill(arrayInMaxValue, (long) 42); 3345 inMaxValue.copyTo(arrayInMaxValue); 3346 long[] arrayOut = new long[INPUTSIZE * 4]; 3347 Arrays.fill(arrayOut, (long) 42); 3348 out.copyTo(arrayOut); 3349 StringBuilder message = new StringBuilder(); 3350 boolean errorFound = false; 3351 for (int i = 0; i < INPUTSIZE; i++) { 3352 for (int j = 0; j < 4 ; j++) { 3353 // Extract the inputs. 3354 ArgumentsLongLongLongLong args = new ArgumentsLongLongLongLong(); 3355 args.inValue = arrayInValue[i * 4 + j]; 3356 args.inMinValue = arrayInMinValue[i * 4 + j]; 3357 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 3358 // Figure out what the outputs should have been. 3359 CoreMathVerifier.computeClamp(args); 3360 // Validate the outputs. 3361 boolean valid = true; 3362 if (args.out != arrayOut[i * 4 + j]) { 3363 valid = false; 3364 } 3365 if (!valid) { 3366 if (!errorFound) { 3367 errorFound = true; 3368 message.append("Input inValue: "); 3369 appendVariableToMessage(message, args.inValue); 3370 message.append("\n"); 3371 message.append("Input inMinValue: "); 3372 appendVariableToMessage(message, args.inMinValue); 3373 message.append("\n"); 3374 message.append("Input inMaxValue: "); 3375 appendVariableToMessage(message, args.inMaxValue); 3376 message.append("\n"); 3377 message.append("Expected output out: "); 3378 appendVariableToMessage(message, args.out); 3379 message.append("\n"); 3380 message.append("Actual output out: "); 3381 appendVariableToMessage(message, arrayOut[i * 4 + j]); 3382 if (args.out != arrayOut[i * 4 + j]) { 3383 message.append(" FAIL"); 3384 } 3385 message.append("\n"); 3386 message.append("Errors at"); 3387 } 3388 message.append(" ["); 3389 message.append(Integer.toString(i)); 3390 message.append(", "); 3391 message.append(Integer.toString(j)); 3392 message.append("]"); 3393 } 3394 } 3395 } 3396 assertFalse("Incorrect output for checkClampLong4Long4Long4Long4" + 3397 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 3398 } 3399 3400 public class ArgumentsUlongUlongUlongUlong { 3401 public long inValue; 3402 public long inMinValue; 3403 public long inMaxValue; 3404 public long out; 3405 } 3406 checkClampUlongUlongUlongUlong()3407 private void checkClampUlongUlongUlongUlong() { 3408 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 1, 0x2b378139749bf4c5l, false); 3409 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 1, 0x75ac5050a8ca97fl, false); 3410 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 1, 0x75ac4f99be99b85l, false); 3411 enforceOrdering(inMinValue, inMaxValue); 3412 try { 3413 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 1), INPUTSIZE); 3414 script.set_gAllocInMinValue(inMinValue); 3415 script.set_gAllocInMaxValue(inMaxValue); 3416 script.forEach_testClampUlongUlongUlongUlong(inValue, out); 3417 verifyResultsClampUlongUlongUlongUlong(inValue, inMinValue, inMaxValue, out, false); 3418 out.destroy(); 3419 } catch (Exception e) { 3420 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlongUlongUlongUlong: " + e.toString()); 3421 } 3422 try { 3423 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 1), INPUTSIZE); 3424 scriptRelaxed.set_gAllocInMinValue(inMinValue); 3425 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 3426 scriptRelaxed.forEach_testClampUlongUlongUlongUlong(inValue, out); 3427 verifyResultsClampUlongUlongUlongUlong(inValue, inMinValue, inMaxValue, out, true); 3428 out.destroy(); 3429 } catch (Exception e) { 3430 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlongUlongUlongUlong: " + e.toString()); 3431 } 3432 inValue.destroy(); 3433 inMinValue.destroy(); 3434 inMaxValue.destroy(); 3435 } 3436 verifyResultsClampUlongUlongUlongUlong(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)3437 private void verifyResultsClampUlongUlongUlongUlong(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 3438 long[] arrayInValue = new long[INPUTSIZE * 1]; 3439 Arrays.fill(arrayInValue, (long) 42); 3440 inValue.copyTo(arrayInValue); 3441 long[] arrayInMinValue = new long[INPUTSIZE * 1]; 3442 Arrays.fill(arrayInMinValue, (long) 42); 3443 inMinValue.copyTo(arrayInMinValue); 3444 long[] arrayInMaxValue = new long[INPUTSIZE * 1]; 3445 Arrays.fill(arrayInMaxValue, (long) 42); 3446 inMaxValue.copyTo(arrayInMaxValue); 3447 long[] arrayOut = new long[INPUTSIZE * 1]; 3448 Arrays.fill(arrayOut, (long) 42); 3449 out.copyTo(arrayOut); 3450 StringBuilder message = new StringBuilder(); 3451 boolean errorFound = false; 3452 for (int i = 0; i < INPUTSIZE; i++) { 3453 for (int j = 0; j < 1 ; j++) { 3454 // Extract the inputs. 3455 ArgumentsUlongUlongUlongUlong args = new ArgumentsUlongUlongUlongUlong(); 3456 args.inValue = arrayInValue[i]; 3457 args.inMinValue = arrayInMinValue[i]; 3458 args.inMaxValue = arrayInMaxValue[i]; 3459 // Figure out what the outputs should have been. 3460 CoreMathVerifier.computeClamp(args); 3461 // Validate the outputs. 3462 boolean valid = true; 3463 if (args.out != arrayOut[i * 1 + j]) { 3464 valid = false; 3465 } 3466 if (!valid) { 3467 if (!errorFound) { 3468 errorFound = true; 3469 message.append("Input inValue: "); 3470 appendVariableToMessage(message, args.inValue); 3471 message.append("\n"); 3472 message.append("Input inMinValue: "); 3473 appendVariableToMessage(message, args.inMinValue); 3474 message.append("\n"); 3475 message.append("Input inMaxValue: "); 3476 appendVariableToMessage(message, args.inMaxValue); 3477 message.append("\n"); 3478 message.append("Expected output out: "); 3479 appendVariableToMessage(message, args.out); 3480 message.append("\n"); 3481 message.append("Actual output out: "); 3482 appendVariableToMessage(message, arrayOut[i * 1 + j]); 3483 if (args.out != arrayOut[i * 1 + j]) { 3484 message.append(" FAIL"); 3485 } 3486 message.append("\n"); 3487 message.append("Errors at"); 3488 } 3489 message.append(" ["); 3490 message.append(Integer.toString(i)); 3491 message.append(", "); 3492 message.append(Integer.toString(j)); 3493 message.append("]"); 3494 } 3495 } 3496 } 3497 assertFalse("Incorrect output for checkClampUlongUlongUlongUlong" + 3498 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 3499 } 3500 checkClampUlong2Ulong2Ulong2Ulong2()3501 private void checkClampUlong2Ulong2Ulong2Ulong2() { 3502 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0xa8c7fb17a09bb299l, false); 3503 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0x14e3c8dffe45623bl, false); 3504 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0x14e3c8d48fa25441l, false); 3505 enforceOrdering(inMinValue, inMaxValue); 3506 try { 3507 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE); 3508 script.set_gAllocInMinValue(inMinValue); 3509 script.set_gAllocInMaxValue(inMaxValue); 3510 script.forEach_testClampUlong2Ulong2Ulong2Ulong2(inValue, out); 3511 verifyResultsClampUlong2Ulong2Ulong2Ulong2(inValue, inMinValue, inMaxValue, out, false); 3512 out.destroy(); 3513 } catch (Exception e) { 3514 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong2Ulong2Ulong2Ulong2: " + e.toString()); 3515 } 3516 try { 3517 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE); 3518 scriptRelaxed.set_gAllocInMinValue(inMinValue); 3519 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 3520 scriptRelaxed.forEach_testClampUlong2Ulong2Ulong2Ulong2(inValue, out); 3521 verifyResultsClampUlong2Ulong2Ulong2Ulong2(inValue, inMinValue, inMaxValue, out, true); 3522 out.destroy(); 3523 } catch (Exception e) { 3524 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong2Ulong2Ulong2Ulong2: " + e.toString()); 3525 } 3526 inValue.destroy(); 3527 inMinValue.destroy(); 3528 inMaxValue.destroy(); 3529 } 3530 verifyResultsClampUlong2Ulong2Ulong2Ulong2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)3531 private void verifyResultsClampUlong2Ulong2Ulong2Ulong2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 3532 long[] arrayInValue = new long[INPUTSIZE * 2]; 3533 Arrays.fill(arrayInValue, (long) 42); 3534 inValue.copyTo(arrayInValue); 3535 long[] arrayInMinValue = new long[INPUTSIZE * 2]; 3536 Arrays.fill(arrayInMinValue, (long) 42); 3537 inMinValue.copyTo(arrayInMinValue); 3538 long[] arrayInMaxValue = new long[INPUTSIZE * 2]; 3539 Arrays.fill(arrayInMaxValue, (long) 42); 3540 inMaxValue.copyTo(arrayInMaxValue); 3541 long[] arrayOut = new long[INPUTSIZE * 2]; 3542 Arrays.fill(arrayOut, (long) 42); 3543 out.copyTo(arrayOut); 3544 StringBuilder message = new StringBuilder(); 3545 boolean errorFound = false; 3546 for (int i = 0; i < INPUTSIZE; i++) { 3547 for (int j = 0; j < 2 ; j++) { 3548 // Extract the inputs. 3549 ArgumentsUlongUlongUlongUlong args = new ArgumentsUlongUlongUlongUlong(); 3550 args.inValue = arrayInValue[i * 2 + j]; 3551 args.inMinValue = arrayInMinValue[i * 2 + j]; 3552 args.inMaxValue = arrayInMaxValue[i * 2 + j]; 3553 // Figure out what the outputs should have been. 3554 CoreMathVerifier.computeClamp(args); 3555 // Validate the outputs. 3556 boolean valid = true; 3557 if (args.out != arrayOut[i * 2 + j]) { 3558 valid = false; 3559 } 3560 if (!valid) { 3561 if (!errorFound) { 3562 errorFound = true; 3563 message.append("Input inValue: "); 3564 appendVariableToMessage(message, args.inValue); 3565 message.append("\n"); 3566 message.append("Input inMinValue: "); 3567 appendVariableToMessage(message, args.inMinValue); 3568 message.append("\n"); 3569 message.append("Input inMaxValue: "); 3570 appendVariableToMessage(message, args.inMaxValue); 3571 message.append("\n"); 3572 message.append("Expected output out: "); 3573 appendVariableToMessage(message, args.out); 3574 message.append("\n"); 3575 message.append("Actual output out: "); 3576 appendVariableToMessage(message, arrayOut[i * 2 + j]); 3577 if (args.out != arrayOut[i * 2 + j]) { 3578 message.append(" FAIL"); 3579 } 3580 message.append("\n"); 3581 message.append("Errors at"); 3582 } 3583 message.append(" ["); 3584 message.append(Integer.toString(i)); 3585 message.append(", "); 3586 message.append(Integer.toString(j)); 3587 message.append("]"); 3588 } 3589 } 3590 } 3591 assertFalse("Incorrect output for checkClampUlong2Ulong2Ulong2Ulong2" + 3592 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 3593 } 3594 checkClampUlong3Ulong3Ulong3Ulong3()3595 private void checkClampUlong3Ulong3Ulong3Ulong3() { 3596 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0x722c3c9fbd1e1f75l, false); 3597 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0x20d03c8e4cfc4c8fl, false); 3598 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0x20d03c82de593e95l, false); 3599 enforceOrdering(inMinValue, inMaxValue); 3600 try { 3601 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE); 3602 script.set_gAllocInMinValue(inMinValue); 3603 script.set_gAllocInMaxValue(inMaxValue); 3604 script.forEach_testClampUlong3Ulong3Ulong3Ulong3(inValue, out); 3605 verifyResultsClampUlong3Ulong3Ulong3Ulong3(inValue, inMinValue, inMaxValue, out, false); 3606 out.destroy(); 3607 } catch (Exception e) { 3608 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong3Ulong3Ulong3Ulong3: " + e.toString()); 3609 } 3610 try { 3611 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE); 3612 scriptRelaxed.set_gAllocInMinValue(inMinValue); 3613 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 3614 scriptRelaxed.forEach_testClampUlong3Ulong3Ulong3Ulong3(inValue, out); 3615 verifyResultsClampUlong3Ulong3Ulong3Ulong3(inValue, inMinValue, inMaxValue, out, true); 3616 out.destroy(); 3617 } catch (Exception e) { 3618 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong3Ulong3Ulong3Ulong3: " + e.toString()); 3619 } 3620 inValue.destroy(); 3621 inMinValue.destroy(); 3622 inMaxValue.destroy(); 3623 } 3624 verifyResultsClampUlong3Ulong3Ulong3Ulong3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)3625 private void verifyResultsClampUlong3Ulong3Ulong3Ulong3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 3626 long[] arrayInValue = new long[INPUTSIZE * 4]; 3627 Arrays.fill(arrayInValue, (long) 42); 3628 inValue.copyTo(arrayInValue); 3629 long[] arrayInMinValue = new long[INPUTSIZE * 4]; 3630 Arrays.fill(arrayInMinValue, (long) 42); 3631 inMinValue.copyTo(arrayInMinValue); 3632 long[] arrayInMaxValue = new long[INPUTSIZE * 4]; 3633 Arrays.fill(arrayInMaxValue, (long) 42); 3634 inMaxValue.copyTo(arrayInMaxValue); 3635 long[] arrayOut = new long[INPUTSIZE * 4]; 3636 Arrays.fill(arrayOut, (long) 42); 3637 out.copyTo(arrayOut); 3638 StringBuilder message = new StringBuilder(); 3639 boolean errorFound = false; 3640 for (int i = 0; i < INPUTSIZE; i++) { 3641 for (int j = 0; j < 3 ; j++) { 3642 // Extract the inputs. 3643 ArgumentsUlongUlongUlongUlong args = new ArgumentsUlongUlongUlongUlong(); 3644 args.inValue = arrayInValue[i * 4 + j]; 3645 args.inMinValue = arrayInMinValue[i * 4 + j]; 3646 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 3647 // Figure out what the outputs should have been. 3648 CoreMathVerifier.computeClamp(args); 3649 // Validate the outputs. 3650 boolean valid = true; 3651 if (args.out != arrayOut[i * 4 + j]) { 3652 valid = false; 3653 } 3654 if (!valid) { 3655 if (!errorFound) { 3656 errorFound = true; 3657 message.append("Input inValue: "); 3658 appendVariableToMessage(message, args.inValue); 3659 message.append("\n"); 3660 message.append("Input inMinValue: "); 3661 appendVariableToMessage(message, args.inMinValue); 3662 message.append("\n"); 3663 message.append("Input inMaxValue: "); 3664 appendVariableToMessage(message, args.inMaxValue); 3665 message.append("\n"); 3666 message.append("Expected output out: "); 3667 appendVariableToMessage(message, args.out); 3668 message.append("\n"); 3669 message.append("Actual output out: "); 3670 appendVariableToMessage(message, arrayOut[i * 4 + j]); 3671 if (args.out != arrayOut[i * 4 + j]) { 3672 message.append(" FAIL"); 3673 } 3674 message.append("\n"); 3675 message.append("Errors at"); 3676 } 3677 message.append(" ["); 3678 message.append(Integer.toString(i)); 3679 message.append(", "); 3680 message.append(Integer.toString(j)); 3681 message.append("]"); 3682 } 3683 } 3684 } 3685 assertFalse("Incorrect output for checkClampUlong3Ulong3Ulong3Ulong3" + 3686 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 3687 } 3688 checkClampUlong4Ulong4Ulong4Ulong4()3689 private void checkClampUlong4Ulong4Ulong4Ulong4() { 3690 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x3b907e27d9a08c51l, false); 3691 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x2cbcb03c9bb336e3l, false); 3692 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x2cbcb0312d1028e9l, false); 3693 enforceOrdering(inMinValue, inMaxValue); 3694 try { 3695 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE); 3696 script.set_gAllocInMinValue(inMinValue); 3697 script.set_gAllocInMaxValue(inMaxValue); 3698 script.forEach_testClampUlong4Ulong4Ulong4Ulong4(inValue, out); 3699 verifyResultsClampUlong4Ulong4Ulong4Ulong4(inValue, inMinValue, inMaxValue, out, false); 3700 out.destroy(); 3701 } catch (Exception e) { 3702 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong4Ulong4Ulong4Ulong4: " + e.toString()); 3703 } 3704 try { 3705 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE); 3706 scriptRelaxed.set_gAllocInMinValue(inMinValue); 3707 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 3708 scriptRelaxed.forEach_testClampUlong4Ulong4Ulong4Ulong4(inValue, out); 3709 verifyResultsClampUlong4Ulong4Ulong4Ulong4(inValue, inMinValue, inMaxValue, out, true); 3710 out.destroy(); 3711 } catch (Exception e) { 3712 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong4Ulong4Ulong4Ulong4: " + e.toString()); 3713 } 3714 inValue.destroy(); 3715 inMinValue.destroy(); 3716 inMaxValue.destroy(); 3717 } 3718 verifyResultsClampUlong4Ulong4Ulong4Ulong4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)3719 private void verifyResultsClampUlong4Ulong4Ulong4Ulong4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 3720 long[] arrayInValue = new long[INPUTSIZE * 4]; 3721 Arrays.fill(arrayInValue, (long) 42); 3722 inValue.copyTo(arrayInValue); 3723 long[] arrayInMinValue = new long[INPUTSIZE * 4]; 3724 Arrays.fill(arrayInMinValue, (long) 42); 3725 inMinValue.copyTo(arrayInMinValue); 3726 long[] arrayInMaxValue = new long[INPUTSIZE * 4]; 3727 Arrays.fill(arrayInMaxValue, (long) 42); 3728 inMaxValue.copyTo(arrayInMaxValue); 3729 long[] arrayOut = new long[INPUTSIZE * 4]; 3730 Arrays.fill(arrayOut, (long) 42); 3731 out.copyTo(arrayOut); 3732 StringBuilder message = new StringBuilder(); 3733 boolean errorFound = false; 3734 for (int i = 0; i < INPUTSIZE; i++) { 3735 for (int j = 0; j < 4 ; j++) { 3736 // Extract the inputs. 3737 ArgumentsUlongUlongUlongUlong args = new ArgumentsUlongUlongUlongUlong(); 3738 args.inValue = arrayInValue[i * 4 + j]; 3739 args.inMinValue = arrayInMinValue[i * 4 + j]; 3740 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 3741 // Figure out what the outputs should have been. 3742 CoreMathVerifier.computeClamp(args); 3743 // Validate the outputs. 3744 boolean valid = true; 3745 if (args.out != arrayOut[i * 4 + j]) { 3746 valid = false; 3747 } 3748 if (!valid) { 3749 if (!errorFound) { 3750 errorFound = true; 3751 message.append("Input inValue: "); 3752 appendVariableToMessage(message, args.inValue); 3753 message.append("\n"); 3754 message.append("Input inMinValue: "); 3755 appendVariableToMessage(message, args.inMinValue); 3756 message.append("\n"); 3757 message.append("Input inMaxValue: "); 3758 appendVariableToMessage(message, args.inMaxValue); 3759 message.append("\n"); 3760 message.append("Expected output out: "); 3761 appendVariableToMessage(message, args.out); 3762 message.append("\n"); 3763 message.append("Actual output out: "); 3764 appendVariableToMessage(message, arrayOut[i * 4 + j]); 3765 if (args.out != arrayOut[i * 4 + j]) { 3766 message.append(" FAIL"); 3767 } 3768 message.append("\n"); 3769 message.append("Errors at"); 3770 } 3771 message.append(" ["); 3772 message.append(Integer.toString(i)); 3773 message.append(", "); 3774 message.append(Integer.toString(j)); 3775 message.append("]"); 3776 } 3777 } 3778 } 3779 assertFalse("Incorrect output for checkClampUlong4Ulong4Ulong4Ulong4" + 3780 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 3781 } 3782 checkClampChar2CharCharChar2()3783 private void checkClampChar2CharCharChar2() { 3784 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xd6884bbb7c57a5d1l, false); 3785 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0x3bf8830cc3b7db63l, false); 3786 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0x3bf883015514cd69l, false); 3787 enforceOrdering(inMinValue, inMaxValue); 3788 try { 3789 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE); 3790 script.set_gAllocInMinValue(inMinValue); 3791 script.set_gAllocInMaxValue(inMaxValue); 3792 script.forEach_testClampChar2CharCharChar2(inValue, out); 3793 verifyResultsClampChar2CharCharChar2(inValue, inMinValue, inMaxValue, out, false); 3794 out.destroy(); 3795 } catch (Exception e) { 3796 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar2CharCharChar2: " + e.toString()); 3797 } 3798 try { 3799 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE); 3800 scriptRelaxed.set_gAllocInMinValue(inMinValue); 3801 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 3802 scriptRelaxed.forEach_testClampChar2CharCharChar2(inValue, out); 3803 verifyResultsClampChar2CharCharChar2(inValue, inMinValue, inMaxValue, out, true); 3804 out.destroy(); 3805 } catch (Exception e) { 3806 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar2CharCharChar2: " + e.toString()); 3807 } 3808 inValue.destroy(); 3809 inMinValue.destroy(); 3810 inMaxValue.destroy(); 3811 } 3812 verifyResultsClampChar2CharCharChar2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)3813 private void verifyResultsClampChar2CharCharChar2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 3814 byte[] arrayInValue = new byte[INPUTSIZE * 2]; 3815 Arrays.fill(arrayInValue, (byte) 42); 3816 inValue.copyTo(arrayInValue); 3817 byte[] arrayInMinValue = new byte[INPUTSIZE * 1]; 3818 Arrays.fill(arrayInMinValue, (byte) 42); 3819 inMinValue.copyTo(arrayInMinValue); 3820 byte[] arrayInMaxValue = new byte[INPUTSIZE * 1]; 3821 Arrays.fill(arrayInMaxValue, (byte) 42); 3822 inMaxValue.copyTo(arrayInMaxValue); 3823 byte[] arrayOut = new byte[INPUTSIZE * 2]; 3824 Arrays.fill(arrayOut, (byte) 42); 3825 out.copyTo(arrayOut); 3826 StringBuilder message = new StringBuilder(); 3827 boolean errorFound = false; 3828 for (int i = 0; i < INPUTSIZE; i++) { 3829 for (int j = 0; j < 2 ; j++) { 3830 // Extract the inputs. 3831 ArgumentsCharCharCharChar args = new ArgumentsCharCharCharChar(); 3832 args.inValue = arrayInValue[i * 2 + j]; 3833 args.inMinValue = arrayInMinValue[i]; 3834 args.inMaxValue = arrayInMaxValue[i]; 3835 // Figure out what the outputs should have been. 3836 CoreMathVerifier.computeClamp(args); 3837 // Validate the outputs. 3838 boolean valid = true; 3839 if (args.out != arrayOut[i * 2 + j]) { 3840 valid = false; 3841 } 3842 if (!valid) { 3843 if (!errorFound) { 3844 errorFound = true; 3845 message.append("Input inValue: "); 3846 appendVariableToMessage(message, args.inValue); 3847 message.append("\n"); 3848 message.append("Input inMinValue: "); 3849 appendVariableToMessage(message, args.inMinValue); 3850 message.append("\n"); 3851 message.append("Input inMaxValue: "); 3852 appendVariableToMessage(message, args.inMaxValue); 3853 message.append("\n"); 3854 message.append("Expected output out: "); 3855 appendVariableToMessage(message, args.out); 3856 message.append("\n"); 3857 message.append("Actual output out: "); 3858 appendVariableToMessage(message, arrayOut[i * 2 + j]); 3859 if (args.out != arrayOut[i * 2 + j]) { 3860 message.append(" FAIL"); 3861 } 3862 message.append("\n"); 3863 message.append("Errors at"); 3864 } 3865 message.append(" ["); 3866 message.append(Integer.toString(i)); 3867 message.append(", "); 3868 message.append(Integer.toString(j)); 3869 message.append("]"); 3870 } 3871 } 3872 } 3873 assertFalse("Incorrect output for checkClampChar2CharCharChar2" + 3874 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 3875 } 3876 checkClampChar3CharCharChar3()3877 private void checkClampChar3CharCharChar3() { 3878 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 3, 0x4aa68c1b65a26ee5l, false); 3879 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0x8b4b9ea0492789dfl, false); 3880 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0x8b4b9e94da847be5l, false); 3881 enforceOrdering(inMinValue, inMaxValue); 3882 try { 3883 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE); 3884 script.set_gAllocInMinValue(inMinValue); 3885 script.set_gAllocInMaxValue(inMaxValue); 3886 script.forEach_testClampChar3CharCharChar3(inValue, out); 3887 verifyResultsClampChar3CharCharChar3(inValue, inMinValue, inMaxValue, out, false); 3888 out.destroy(); 3889 } catch (Exception e) { 3890 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar3CharCharChar3: " + e.toString()); 3891 } 3892 try { 3893 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE); 3894 scriptRelaxed.set_gAllocInMinValue(inMinValue); 3895 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 3896 scriptRelaxed.forEach_testClampChar3CharCharChar3(inValue, out); 3897 verifyResultsClampChar3CharCharChar3(inValue, inMinValue, inMaxValue, out, true); 3898 out.destroy(); 3899 } catch (Exception e) { 3900 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar3CharCharChar3: " + e.toString()); 3901 } 3902 inValue.destroy(); 3903 inMinValue.destroy(); 3904 inMaxValue.destroy(); 3905 } 3906 verifyResultsClampChar3CharCharChar3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)3907 private void verifyResultsClampChar3CharCharChar3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 3908 byte[] arrayInValue = new byte[INPUTSIZE * 4]; 3909 Arrays.fill(arrayInValue, (byte) 42); 3910 inValue.copyTo(arrayInValue); 3911 byte[] arrayInMinValue = new byte[INPUTSIZE * 1]; 3912 Arrays.fill(arrayInMinValue, (byte) 42); 3913 inMinValue.copyTo(arrayInMinValue); 3914 byte[] arrayInMaxValue = new byte[INPUTSIZE * 1]; 3915 Arrays.fill(arrayInMaxValue, (byte) 42); 3916 inMaxValue.copyTo(arrayInMaxValue); 3917 byte[] arrayOut = new byte[INPUTSIZE * 4]; 3918 Arrays.fill(arrayOut, (byte) 42); 3919 out.copyTo(arrayOut); 3920 StringBuilder message = new StringBuilder(); 3921 boolean errorFound = false; 3922 for (int i = 0; i < INPUTSIZE; i++) { 3923 for (int j = 0; j < 3 ; j++) { 3924 // Extract the inputs. 3925 ArgumentsCharCharCharChar args = new ArgumentsCharCharCharChar(); 3926 args.inValue = arrayInValue[i * 4 + j]; 3927 args.inMinValue = arrayInMinValue[i]; 3928 args.inMaxValue = arrayInMaxValue[i]; 3929 // Figure out what the outputs should have been. 3930 CoreMathVerifier.computeClamp(args); 3931 // Validate the outputs. 3932 boolean valid = true; 3933 if (args.out != arrayOut[i * 4 + j]) { 3934 valid = false; 3935 } 3936 if (!valid) { 3937 if (!errorFound) { 3938 errorFound = true; 3939 message.append("Input inValue: "); 3940 appendVariableToMessage(message, args.inValue); 3941 message.append("\n"); 3942 message.append("Input inMinValue: "); 3943 appendVariableToMessage(message, args.inMinValue); 3944 message.append("\n"); 3945 message.append("Input inMaxValue: "); 3946 appendVariableToMessage(message, args.inMaxValue); 3947 message.append("\n"); 3948 message.append("Expected output out: "); 3949 appendVariableToMessage(message, args.out); 3950 message.append("\n"); 3951 message.append("Actual output out: "); 3952 appendVariableToMessage(message, arrayOut[i * 4 + j]); 3953 if (args.out != arrayOut[i * 4 + j]) { 3954 message.append(" FAIL"); 3955 } 3956 message.append("\n"); 3957 message.append("Errors at"); 3958 } 3959 message.append(" ["); 3960 message.append(Integer.toString(i)); 3961 message.append(", "); 3962 message.append(Integer.toString(j)); 3963 message.append("]"); 3964 } 3965 } 3966 } 3967 assertFalse("Incorrect output for checkClampChar3CharCharChar3" + 3968 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 3969 } 3970 checkClampChar4CharCharChar4()3971 private void checkClampChar4CharCharChar4() { 3972 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 4, 0xbec4cc7b4eed37f9l, false); 3973 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0xda9eba33ce97385bl, false); 3974 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0xda9eba285ff42a61l, false); 3975 enforceOrdering(inMinValue, inMaxValue); 3976 try { 3977 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE); 3978 script.set_gAllocInMinValue(inMinValue); 3979 script.set_gAllocInMaxValue(inMaxValue); 3980 script.forEach_testClampChar4CharCharChar4(inValue, out); 3981 verifyResultsClampChar4CharCharChar4(inValue, inMinValue, inMaxValue, out, false); 3982 out.destroy(); 3983 } catch (Exception e) { 3984 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar4CharCharChar4: " + e.toString()); 3985 } 3986 try { 3987 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE); 3988 scriptRelaxed.set_gAllocInMinValue(inMinValue); 3989 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 3990 scriptRelaxed.forEach_testClampChar4CharCharChar4(inValue, out); 3991 verifyResultsClampChar4CharCharChar4(inValue, inMinValue, inMaxValue, out, true); 3992 out.destroy(); 3993 } catch (Exception e) { 3994 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampChar4CharCharChar4: " + e.toString()); 3995 } 3996 inValue.destroy(); 3997 inMinValue.destroy(); 3998 inMaxValue.destroy(); 3999 } 4000 verifyResultsClampChar4CharCharChar4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)4001 private void verifyResultsClampChar4CharCharChar4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 4002 byte[] arrayInValue = new byte[INPUTSIZE * 4]; 4003 Arrays.fill(arrayInValue, (byte) 42); 4004 inValue.copyTo(arrayInValue); 4005 byte[] arrayInMinValue = new byte[INPUTSIZE * 1]; 4006 Arrays.fill(arrayInMinValue, (byte) 42); 4007 inMinValue.copyTo(arrayInMinValue); 4008 byte[] arrayInMaxValue = new byte[INPUTSIZE * 1]; 4009 Arrays.fill(arrayInMaxValue, (byte) 42); 4010 inMaxValue.copyTo(arrayInMaxValue); 4011 byte[] arrayOut = new byte[INPUTSIZE * 4]; 4012 Arrays.fill(arrayOut, (byte) 42); 4013 out.copyTo(arrayOut); 4014 StringBuilder message = new StringBuilder(); 4015 boolean errorFound = false; 4016 for (int i = 0; i < INPUTSIZE; i++) { 4017 for (int j = 0; j < 4 ; j++) { 4018 // Extract the inputs. 4019 ArgumentsCharCharCharChar args = new ArgumentsCharCharCharChar(); 4020 args.inValue = arrayInValue[i * 4 + j]; 4021 args.inMinValue = arrayInMinValue[i]; 4022 args.inMaxValue = arrayInMaxValue[i]; 4023 // Figure out what the outputs should have been. 4024 CoreMathVerifier.computeClamp(args); 4025 // Validate the outputs. 4026 boolean valid = true; 4027 if (args.out != arrayOut[i * 4 + j]) { 4028 valid = false; 4029 } 4030 if (!valid) { 4031 if (!errorFound) { 4032 errorFound = true; 4033 message.append("Input inValue: "); 4034 appendVariableToMessage(message, args.inValue); 4035 message.append("\n"); 4036 message.append("Input inMinValue: "); 4037 appendVariableToMessage(message, args.inMinValue); 4038 message.append("\n"); 4039 message.append("Input inMaxValue: "); 4040 appendVariableToMessage(message, args.inMaxValue); 4041 message.append("\n"); 4042 message.append("Expected output out: "); 4043 appendVariableToMessage(message, args.out); 4044 message.append("\n"); 4045 message.append("Actual output out: "); 4046 appendVariableToMessage(message, arrayOut[i * 4 + j]); 4047 if (args.out != arrayOut[i * 4 + j]) { 4048 message.append(" FAIL"); 4049 } 4050 message.append("\n"); 4051 message.append("Errors at"); 4052 } 4053 message.append(" ["); 4054 message.append(Integer.toString(i)); 4055 message.append(", "); 4056 message.append(Integer.toString(j)); 4057 message.append("]"); 4058 } 4059 } 4060 } 4061 assertFalse("Incorrect output for checkClampChar4CharCharChar4" + 4062 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 4063 } 4064 checkClampUchar2UcharUcharUchar2()4065 private void checkClampUchar2UcharUcharUchar2() { 4066 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0xafd4a680f02e0d63l, false); 4067 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0x78bbbcb3e9402039l, false); 4068 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0x78bbbca87a9d123fl, false); 4069 enforceOrdering(inMinValue, inMaxValue); 4070 try { 4071 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE); 4072 script.set_gAllocInMinValue(inMinValue); 4073 script.set_gAllocInMaxValue(inMaxValue); 4074 script.forEach_testClampUchar2UcharUcharUchar2(inValue, out); 4075 verifyResultsClampUchar2UcharUcharUchar2(inValue, inMinValue, inMaxValue, out, false); 4076 out.destroy(); 4077 } catch (Exception e) { 4078 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar2UcharUcharUchar2: " + e.toString()); 4079 } 4080 try { 4081 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE); 4082 scriptRelaxed.set_gAllocInMinValue(inMinValue); 4083 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 4084 scriptRelaxed.forEach_testClampUchar2UcharUcharUchar2(inValue, out); 4085 verifyResultsClampUchar2UcharUcharUchar2(inValue, inMinValue, inMaxValue, out, true); 4086 out.destroy(); 4087 } catch (Exception e) { 4088 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar2UcharUcharUchar2: " + e.toString()); 4089 } 4090 inValue.destroy(); 4091 inMinValue.destroy(); 4092 inMaxValue.destroy(); 4093 } 4094 verifyResultsClampUchar2UcharUcharUchar2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)4095 private void verifyResultsClampUchar2UcharUcharUchar2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 4096 byte[] arrayInValue = new byte[INPUTSIZE * 2]; 4097 Arrays.fill(arrayInValue, (byte) 42); 4098 inValue.copyTo(arrayInValue); 4099 byte[] arrayInMinValue = new byte[INPUTSIZE * 1]; 4100 Arrays.fill(arrayInMinValue, (byte) 42); 4101 inMinValue.copyTo(arrayInMinValue); 4102 byte[] arrayInMaxValue = new byte[INPUTSIZE * 1]; 4103 Arrays.fill(arrayInMaxValue, (byte) 42); 4104 inMaxValue.copyTo(arrayInMaxValue); 4105 byte[] arrayOut = new byte[INPUTSIZE * 2]; 4106 Arrays.fill(arrayOut, (byte) 42); 4107 out.copyTo(arrayOut); 4108 StringBuilder message = new StringBuilder(); 4109 boolean errorFound = false; 4110 for (int i = 0; i < INPUTSIZE; i++) { 4111 for (int j = 0; j < 2 ; j++) { 4112 // Extract the inputs. 4113 ArgumentsUcharUcharUcharUchar args = new ArgumentsUcharUcharUcharUchar(); 4114 args.inValue = arrayInValue[i * 2 + j]; 4115 args.inMinValue = arrayInMinValue[i]; 4116 args.inMaxValue = arrayInMaxValue[i]; 4117 // Figure out what the outputs should have been. 4118 CoreMathVerifier.computeClamp(args); 4119 // Validate the outputs. 4120 boolean valid = true; 4121 if (args.out != arrayOut[i * 2 + j]) { 4122 valid = false; 4123 } 4124 if (!valid) { 4125 if (!errorFound) { 4126 errorFound = true; 4127 message.append("Input inValue: "); 4128 appendVariableToMessage(message, args.inValue); 4129 message.append("\n"); 4130 message.append("Input inMinValue: "); 4131 appendVariableToMessage(message, args.inMinValue); 4132 message.append("\n"); 4133 message.append("Input inMaxValue: "); 4134 appendVariableToMessage(message, args.inMaxValue); 4135 message.append("\n"); 4136 message.append("Expected output out: "); 4137 appendVariableToMessage(message, args.out); 4138 message.append("\n"); 4139 message.append("Actual output out: "); 4140 appendVariableToMessage(message, arrayOut[i * 2 + j]); 4141 if (args.out != arrayOut[i * 2 + j]) { 4142 message.append(" FAIL"); 4143 } 4144 message.append("\n"); 4145 message.append("Errors at"); 4146 } 4147 message.append(" ["); 4148 message.append(Integer.toString(i)); 4149 message.append(", "); 4150 message.append(Integer.toString(j)); 4151 message.append("]"); 4152 } 4153 } 4154 } 4155 assertFalse("Incorrect output for checkClampUchar2UcharUcharUchar2" + 4156 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 4157 } 4158 checkClampUchar3UcharUcharUchar3()4159 private void checkClampUchar3UcharUcharUchar3() { 4160 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0xfedafacc68ea3ae9l, false); 4161 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0x8371883e1c6e882bl, false); 4162 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0x83718832adcb7a31l, false); 4163 enforceOrdering(inMinValue, inMaxValue); 4164 try { 4165 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE); 4166 script.set_gAllocInMinValue(inMinValue); 4167 script.set_gAllocInMaxValue(inMaxValue); 4168 script.forEach_testClampUchar3UcharUcharUchar3(inValue, out); 4169 verifyResultsClampUchar3UcharUcharUchar3(inValue, inMinValue, inMaxValue, out, false); 4170 out.destroy(); 4171 } catch (Exception e) { 4172 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar3UcharUcharUchar3: " + e.toString()); 4173 } 4174 try { 4175 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE); 4176 scriptRelaxed.set_gAllocInMinValue(inMinValue); 4177 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 4178 scriptRelaxed.forEach_testClampUchar3UcharUcharUchar3(inValue, out); 4179 verifyResultsClampUchar3UcharUcharUchar3(inValue, inMinValue, inMaxValue, out, true); 4180 out.destroy(); 4181 } catch (Exception e) { 4182 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar3UcharUcharUchar3: " + e.toString()); 4183 } 4184 inValue.destroy(); 4185 inMinValue.destroy(); 4186 inMaxValue.destroy(); 4187 } 4188 verifyResultsClampUchar3UcharUcharUchar3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)4189 private void verifyResultsClampUchar3UcharUcharUchar3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 4190 byte[] arrayInValue = new byte[INPUTSIZE * 4]; 4191 Arrays.fill(arrayInValue, (byte) 42); 4192 inValue.copyTo(arrayInValue); 4193 byte[] arrayInMinValue = new byte[INPUTSIZE * 1]; 4194 Arrays.fill(arrayInMinValue, (byte) 42); 4195 inMinValue.copyTo(arrayInMinValue); 4196 byte[] arrayInMaxValue = new byte[INPUTSIZE * 1]; 4197 Arrays.fill(arrayInMaxValue, (byte) 42); 4198 inMaxValue.copyTo(arrayInMaxValue); 4199 byte[] arrayOut = new byte[INPUTSIZE * 4]; 4200 Arrays.fill(arrayOut, (byte) 42); 4201 out.copyTo(arrayOut); 4202 StringBuilder message = new StringBuilder(); 4203 boolean errorFound = false; 4204 for (int i = 0; i < INPUTSIZE; i++) { 4205 for (int j = 0; j < 3 ; j++) { 4206 // Extract the inputs. 4207 ArgumentsUcharUcharUcharUchar args = new ArgumentsUcharUcharUcharUchar(); 4208 args.inValue = arrayInValue[i * 4 + j]; 4209 args.inMinValue = arrayInMinValue[i]; 4210 args.inMaxValue = arrayInMaxValue[i]; 4211 // Figure out what the outputs should have been. 4212 CoreMathVerifier.computeClamp(args); 4213 // Validate the outputs. 4214 boolean valid = true; 4215 if (args.out != arrayOut[i * 4 + j]) { 4216 valid = false; 4217 } 4218 if (!valid) { 4219 if (!errorFound) { 4220 errorFound = true; 4221 message.append("Input inValue: "); 4222 appendVariableToMessage(message, args.inValue); 4223 message.append("\n"); 4224 message.append("Input inMinValue: "); 4225 appendVariableToMessage(message, args.inMinValue); 4226 message.append("\n"); 4227 message.append("Input inMaxValue: "); 4228 appendVariableToMessage(message, args.inMaxValue); 4229 message.append("\n"); 4230 message.append("Expected output out: "); 4231 appendVariableToMessage(message, args.out); 4232 message.append("\n"); 4233 message.append("Actual output out: "); 4234 appendVariableToMessage(message, arrayOut[i * 4 + j]); 4235 if (args.out != arrayOut[i * 4 + j]) { 4236 message.append(" FAIL"); 4237 } 4238 message.append("\n"); 4239 message.append("Errors at"); 4240 } 4241 message.append(" ["); 4242 message.append(Integer.toString(i)); 4243 message.append(", "); 4244 message.append(Integer.toString(j)); 4245 message.append("]"); 4246 } 4247 } 4248 } 4249 assertFalse("Incorrect output for checkClampUchar3UcharUcharUchar3" + 4250 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 4251 } 4252 checkClampUchar4UcharUcharUchar4()4253 private void checkClampUchar4UcharUcharUchar4() { 4254 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x4de14f17e1a6686fl, false); 4255 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0x8e2753c84f9cf01dl, false); 4256 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0x8e2753bce0f9e223l, false); 4257 enforceOrdering(inMinValue, inMaxValue); 4258 try { 4259 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE); 4260 script.set_gAllocInMinValue(inMinValue); 4261 script.set_gAllocInMaxValue(inMaxValue); 4262 script.forEach_testClampUchar4UcharUcharUchar4(inValue, out); 4263 verifyResultsClampUchar4UcharUcharUchar4(inValue, inMinValue, inMaxValue, out, false); 4264 out.destroy(); 4265 } catch (Exception e) { 4266 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar4UcharUcharUchar4: " + e.toString()); 4267 } 4268 try { 4269 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE); 4270 scriptRelaxed.set_gAllocInMinValue(inMinValue); 4271 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 4272 scriptRelaxed.forEach_testClampUchar4UcharUcharUchar4(inValue, out); 4273 verifyResultsClampUchar4UcharUcharUchar4(inValue, inMinValue, inMaxValue, out, true); 4274 out.destroy(); 4275 } catch (Exception e) { 4276 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUchar4UcharUcharUchar4: " + e.toString()); 4277 } 4278 inValue.destroy(); 4279 inMinValue.destroy(); 4280 inMaxValue.destroy(); 4281 } 4282 verifyResultsClampUchar4UcharUcharUchar4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)4283 private void verifyResultsClampUchar4UcharUcharUchar4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 4284 byte[] arrayInValue = new byte[INPUTSIZE * 4]; 4285 Arrays.fill(arrayInValue, (byte) 42); 4286 inValue.copyTo(arrayInValue); 4287 byte[] arrayInMinValue = new byte[INPUTSIZE * 1]; 4288 Arrays.fill(arrayInMinValue, (byte) 42); 4289 inMinValue.copyTo(arrayInMinValue); 4290 byte[] arrayInMaxValue = new byte[INPUTSIZE * 1]; 4291 Arrays.fill(arrayInMaxValue, (byte) 42); 4292 inMaxValue.copyTo(arrayInMaxValue); 4293 byte[] arrayOut = new byte[INPUTSIZE * 4]; 4294 Arrays.fill(arrayOut, (byte) 42); 4295 out.copyTo(arrayOut); 4296 StringBuilder message = new StringBuilder(); 4297 boolean errorFound = false; 4298 for (int i = 0; i < INPUTSIZE; i++) { 4299 for (int j = 0; j < 4 ; j++) { 4300 // Extract the inputs. 4301 ArgumentsUcharUcharUcharUchar args = new ArgumentsUcharUcharUcharUchar(); 4302 args.inValue = arrayInValue[i * 4 + j]; 4303 args.inMinValue = arrayInMinValue[i]; 4304 args.inMaxValue = arrayInMaxValue[i]; 4305 // Figure out what the outputs should have been. 4306 CoreMathVerifier.computeClamp(args); 4307 // Validate the outputs. 4308 boolean valid = true; 4309 if (args.out != arrayOut[i * 4 + j]) { 4310 valid = false; 4311 } 4312 if (!valid) { 4313 if (!errorFound) { 4314 errorFound = true; 4315 message.append("Input inValue: "); 4316 appendVariableToMessage(message, args.inValue); 4317 message.append("\n"); 4318 message.append("Input inMinValue: "); 4319 appendVariableToMessage(message, args.inMinValue); 4320 message.append("\n"); 4321 message.append("Input inMaxValue: "); 4322 appendVariableToMessage(message, args.inMaxValue); 4323 message.append("\n"); 4324 message.append("Expected output out: "); 4325 appendVariableToMessage(message, args.out); 4326 message.append("\n"); 4327 message.append("Actual output out: "); 4328 appendVariableToMessage(message, arrayOut[i * 4 + j]); 4329 if (args.out != arrayOut[i * 4 + j]) { 4330 message.append(" FAIL"); 4331 } 4332 message.append("\n"); 4333 message.append("Errors at"); 4334 } 4335 message.append(" ["); 4336 message.append(Integer.toString(i)); 4337 message.append(", "); 4338 message.append(Integer.toString(j)); 4339 message.append("]"); 4340 } 4341 } 4342 } 4343 assertFalse("Incorrect output for checkClampUchar4UcharUcharUchar4" + 4344 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 4345 } 4346 checkClampShort2ShortShortShort2()4347 private void checkClampShort2ShortShortShort2() { 4348 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x89e3627eae2d6a9l, false); 4349 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0x886d6d2ccaca776bl, false); 4350 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0x886d6d215c276971l, false); 4351 enforceOrdering(inMinValue, inMaxValue); 4352 try { 4353 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE); 4354 script.set_gAllocInMinValue(inMinValue); 4355 script.set_gAllocInMaxValue(inMaxValue); 4356 script.forEach_testClampShort2ShortShortShort2(inValue, out); 4357 verifyResultsClampShort2ShortShortShort2(inValue, inMinValue, inMaxValue, out, false); 4358 out.destroy(); 4359 } catch (Exception e) { 4360 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort2ShortShortShort2: " + e.toString()); 4361 } 4362 try { 4363 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE); 4364 scriptRelaxed.set_gAllocInMinValue(inMinValue); 4365 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 4366 scriptRelaxed.forEach_testClampShort2ShortShortShort2(inValue, out); 4367 verifyResultsClampShort2ShortShortShort2(inValue, inMinValue, inMaxValue, out, true); 4368 out.destroy(); 4369 } catch (Exception e) { 4370 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort2ShortShortShort2: " + e.toString()); 4371 } 4372 inValue.destroy(); 4373 inMinValue.destroy(); 4374 inMaxValue.destroy(); 4375 } 4376 verifyResultsClampShort2ShortShortShort2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)4377 private void verifyResultsClampShort2ShortShortShort2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 4378 short[] arrayInValue = new short[INPUTSIZE * 2]; 4379 Arrays.fill(arrayInValue, (short) 42); 4380 inValue.copyTo(arrayInValue); 4381 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 4382 Arrays.fill(arrayInMinValue, (short) 42); 4383 inMinValue.copyTo(arrayInMinValue); 4384 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 4385 Arrays.fill(arrayInMaxValue, (short) 42); 4386 inMaxValue.copyTo(arrayInMaxValue); 4387 short[] arrayOut = new short[INPUTSIZE * 2]; 4388 Arrays.fill(arrayOut, (short) 42); 4389 out.copyTo(arrayOut); 4390 StringBuilder message = new StringBuilder(); 4391 boolean errorFound = false; 4392 for (int i = 0; i < INPUTSIZE; i++) { 4393 for (int j = 0; j < 2 ; j++) { 4394 // Extract the inputs. 4395 ArgumentsShortShortShortShort args = new ArgumentsShortShortShortShort(); 4396 args.inValue = arrayInValue[i * 2 + j]; 4397 args.inMinValue = arrayInMinValue[i]; 4398 args.inMaxValue = arrayInMaxValue[i]; 4399 // Figure out what the outputs should have been. 4400 CoreMathVerifier.computeClamp(args); 4401 // Validate the outputs. 4402 boolean valid = true; 4403 if (args.out != arrayOut[i * 2 + j]) { 4404 valid = false; 4405 } 4406 if (!valid) { 4407 if (!errorFound) { 4408 errorFound = true; 4409 message.append("Input inValue: "); 4410 appendVariableToMessage(message, args.inValue); 4411 message.append("\n"); 4412 message.append("Input inMinValue: "); 4413 appendVariableToMessage(message, args.inMinValue); 4414 message.append("\n"); 4415 message.append("Input inMaxValue: "); 4416 appendVariableToMessage(message, args.inMaxValue); 4417 message.append("\n"); 4418 message.append("Expected output out: "); 4419 appendVariableToMessage(message, args.out); 4420 message.append("\n"); 4421 message.append("Actual output out: "); 4422 appendVariableToMessage(message, arrayOut[i * 2 + j]); 4423 if (args.out != arrayOut[i * 2 + j]) { 4424 message.append(" FAIL"); 4425 } 4426 message.append("\n"); 4427 message.append("Errors at"); 4428 } 4429 message.append(" ["); 4430 message.append(Integer.toString(i)); 4431 message.append(", "); 4432 message.append(Integer.toString(j)); 4433 message.append("]"); 4434 } 4435 } 4436 } 4437 assertFalse("Incorrect output for checkClampShort2ShortShortShort2" + 4438 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 4439 } 4440 checkClampShort3ShortShortShort3()4441 private void checkClampShort3ShortShortShort3() { 4442 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x57a48a73639f042fl, false); 4443 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0x932338b6fdf8df5dl, false); 4444 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0x932338ab8f55d163l, false); 4445 enforceOrdering(inMinValue, inMaxValue); 4446 try { 4447 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE); 4448 script.set_gAllocInMinValue(inMinValue); 4449 script.set_gAllocInMaxValue(inMaxValue); 4450 script.forEach_testClampShort3ShortShortShort3(inValue, out); 4451 verifyResultsClampShort3ShortShortShort3(inValue, inMinValue, inMaxValue, out, false); 4452 out.destroy(); 4453 } catch (Exception e) { 4454 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort3ShortShortShort3: " + e.toString()); 4455 } 4456 try { 4457 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE); 4458 scriptRelaxed.set_gAllocInMinValue(inMinValue); 4459 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 4460 scriptRelaxed.forEach_testClampShort3ShortShortShort3(inValue, out); 4461 verifyResultsClampShort3ShortShortShort3(inValue, inMinValue, inMaxValue, out, true); 4462 out.destroy(); 4463 } catch (Exception e) { 4464 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort3ShortShortShort3: " + e.toString()); 4465 } 4466 inValue.destroy(); 4467 inMinValue.destroy(); 4468 inMaxValue.destroy(); 4469 } 4470 verifyResultsClampShort3ShortShortShort3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)4471 private void verifyResultsClampShort3ShortShortShort3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 4472 short[] arrayInValue = new short[INPUTSIZE * 4]; 4473 Arrays.fill(arrayInValue, (short) 42); 4474 inValue.copyTo(arrayInValue); 4475 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 4476 Arrays.fill(arrayInMinValue, (short) 42); 4477 inMinValue.copyTo(arrayInMinValue); 4478 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 4479 Arrays.fill(arrayInMaxValue, (short) 42); 4480 inMaxValue.copyTo(arrayInMaxValue); 4481 short[] arrayOut = new short[INPUTSIZE * 4]; 4482 Arrays.fill(arrayOut, (short) 42); 4483 out.copyTo(arrayOut); 4484 StringBuilder message = new StringBuilder(); 4485 boolean errorFound = false; 4486 for (int i = 0; i < INPUTSIZE; i++) { 4487 for (int j = 0; j < 3 ; j++) { 4488 // Extract the inputs. 4489 ArgumentsShortShortShortShort args = new ArgumentsShortShortShortShort(); 4490 args.inValue = arrayInValue[i * 4 + j]; 4491 args.inMinValue = arrayInMinValue[i]; 4492 args.inMaxValue = arrayInMaxValue[i]; 4493 // Figure out what the outputs should have been. 4494 CoreMathVerifier.computeClamp(args); 4495 // Validate the outputs. 4496 boolean valid = true; 4497 if (args.out != arrayOut[i * 4 + j]) { 4498 valid = false; 4499 } 4500 if (!valid) { 4501 if (!errorFound) { 4502 errorFound = true; 4503 message.append("Input inValue: "); 4504 appendVariableToMessage(message, args.inValue); 4505 message.append("\n"); 4506 message.append("Input inMinValue: "); 4507 appendVariableToMessage(message, args.inMinValue); 4508 message.append("\n"); 4509 message.append("Input inMaxValue: "); 4510 appendVariableToMessage(message, args.inMaxValue); 4511 message.append("\n"); 4512 message.append("Expected output out: "); 4513 appendVariableToMessage(message, args.out); 4514 message.append("\n"); 4515 message.append("Actual output out: "); 4516 appendVariableToMessage(message, arrayOut[i * 4 + j]); 4517 if (args.out != arrayOut[i * 4 + j]) { 4518 message.append(" FAIL"); 4519 } 4520 message.append("\n"); 4521 message.append("Errors at"); 4522 } 4523 message.append(" ["); 4524 message.append(Integer.toString(i)); 4525 message.append(", "); 4526 message.append(Integer.toString(j)); 4527 message.append("]"); 4528 } 4529 } 4530 } 4531 assertFalse("Incorrect output for checkClampShort3ShortShortShort3" + 4532 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 4533 } 4534 checkClampShort4ShortShortShort4()4535 private void checkClampShort4ShortShortShort4() { 4536 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 4, 0xa6aadebedc5b31b5l, false); 4537 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0x9dd904413127474fl, false); 4538 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0x9dd90435c2843955l, false); 4539 enforceOrdering(inMinValue, inMaxValue); 4540 try { 4541 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE); 4542 script.set_gAllocInMinValue(inMinValue); 4543 script.set_gAllocInMaxValue(inMaxValue); 4544 script.forEach_testClampShort4ShortShortShort4(inValue, out); 4545 verifyResultsClampShort4ShortShortShort4(inValue, inMinValue, inMaxValue, out, false); 4546 out.destroy(); 4547 } catch (Exception e) { 4548 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort4ShortShortShort4: " + e.toString()); 4549 } 4550 try { 4551 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE); 4552 scriptRelaxed.set_gAllocInMinValue(inMinValue); 4553 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 4554 scriptRelaxed.forEach_testClampShort4ShortShortShort4(inValue, out); 4555 verifyResultsClampShort4ShortShortShort4(inValue, inMinValue, inMaxValue, out, true); 4556 out.destroy(); 4557 } catch (Exception e) { 4558 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampShort4ShortShortShort4: " + e.toString()); 4559 } 4560 inValue.destroy(); 4561 inMinValue.destroy(); 4562 inMaxValue.destroy(); 4563 } 4564 verifyResultsClampShort4ShortShortShort4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)4565 private void verifyResultsClampShort4ShortShortShort4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 4566 short[] arrayInValue = new short[INPUTSIZE * 4]; 4567 Arrays.fill(arrayInValue, (short) 42); 4568 inValue.copyTo(arrayInValue); 4569 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 4570 Arrays.fill(arrayInMinValue, (short) 42); 4571 inMinValue.copyTo(arrayInMinValue); 4572 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 4573 Arrays.fill(arrayInMaxValue, (short) 42); 4574 inMaxValue.copyTo(arrayInMaxValue); 4575 short[] arrayOut = new short[INPUTSIZE * 4]; 4576 Arrays.fill(arrayOut, (short) 42); 4577 out.copyTo(arrayOut); 4578 StringBuilder message = new StringBuilder(); 4579 boolean errorFound = false; 4580 for (int i = 0; i < INPUTSIZE; i++) { 4581 for (int j = 0; j < 4 ; j++) { 4582 // Extract the inputs. 4583 ArgumentsShortShortShortShort args = new ArgumentsShortShortShortShort(); 4584 args.inValue = arrayInValue[i * 4 + j]; 4585 args.inMinValue = arrayInMinValue[i]; 4586 args.inMaxValue = arrayInMaxValue[i]; 4587 // Figure out what the outputs should have been. 4588 CoreMathVerifier.computeClamp(args); 4589 // Validate the outputs. 4590 boolean valid = true; 4591 if (args.out != arrayOut[i * 4 + j]) { 4592 valid = false; 4593 } 4594 if (!valid) { 4595 if (!errorFound) { 4596 errorFound = true; 4597 message.append("Input inValue: "); 4598 appendVariableToMessage(message, args.inValue); 4599 message.append("\n"); 4600 message.append("Input inMinValue: "); 4601 appendVariableToMessage(message, args.inMinValue); 4602 message.append("\n"); 4603 message.append("Input inMaxValue: "); 4604 appendVariableToMessage(message, args.inMaxValue); 4605 message.append("\n"); 4606 message.append("Expected output out: "); 4607 appendVariableToMessage(message, args.out); 4608 message.append("\n"); 4609 message.append("Actual output out: "); 4610 appendVariableToMessage(message, arrayOut[i * 4 + j]); 4611 if (args.out != arrayOut[i * 4 + j]) { 4612 message.append(" FAIL"); 4613 } 4614 message.append("\n"); 4615 message.append("Errors at"); 4616 } 4617 message.append(" ["); 4618 message.append(Integer.toString(i)); 4619 message.append(", "); 4620 message.append(Integer.toString(j)); 4621 message.append("]"); 4622 } 4623 } 4624 } 4625 assertFalse("Incorrect output for checkClampShort4ShortShortShort4" + 4626 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 4627 } 4628 checkClampUshort2UshortUshortUshort2()4629 private void checkClampUshort2UshortUshortUshort2() { 4630 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0x2ece6d045621ef07l, false); 4631 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0xd88bd79cc7874965l, false); 4632 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0xd88bd79158e43b6bl, false); 4633 enforceOrdering(inMinValue, inMaxValue); 4634 try { 4635 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE); 4636 script.set_gAllocInMinValue(inMinValue); 4637 script.set_gAllocInMaxValue(inMaxValue); 4638 script.forEach_testClampUshort2UshortUshortUshort2(inValue, out); 4639 verifyResultsClampUshort2UshortUshortUshort2(inValue, inMinValue, inMaxValue, out, false); 4640 out.destroy(); 4641 } catch (Exception e) { 4642 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort2UshortUshortUshort2: " + e.toString()); 4643 } 4644 try { 4645 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE); 4646 scriptRelaxed.set_gAllocInMinValue(inMinValue); 4647 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 4648 scriptRelaxed.forEach_testClampUshort2UshortUshortUshort2(inValue, out); 4649 verifyResultsClampUshort2UshortUshortUshort2(inValue, inMinValue, inMaxValue, out, true); 4650 out.destroy(); 4651 } catch (Exception e) { 4652 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort2UshortUshortUshort2: " + e.toString()); 4653 } 4654 inValue.destroy(); 4655 inMinValue.destroy(); 4656 inMaxValue.destroy(); 4657 } 4658 verifyResultsClampUshort2UshortUshortUshort2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)4659 private void verifyResultsClampUshort2UshortUshortUshort2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 4660 short[] arrayInValue = new short[INPUTSIZE * 2]; 4661 Arrays.fill(arrayInValue, (short) 42); 4662 inValue.copyTo(arrayInValue); 4663 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 4664 Arrays.fill(arrayInMinValue, (short) 42); 4665 inMinValue.copyTo(arrayInMinValue); 4666 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 4667 Arrays.fill(arrayInMaxValue, (short) 42); 4668 inMaxValue.copyTo(arrayInMaxValue); 4669 short[] arrayOut = new short[INPUTSIZE * 2]; 4670 Arrays.fill(arrayOut, (short) 42); 4671 out.copyTo(arrayOut); 4672 StringBuilder message = new StringBuilder(); 4673 boolean errorFound = false; 4674 for (int i = 0; i < INPUTSIZE; i++) { 4675 for (int j = 0; j < 2 ; j++) { 4676 // Extract the inputs. 4677 ArgumentsUshortUshortUshortUshort args = new ArgumentsUshortUshortUshortUshort(); 4678 args.inValue = arrayInValue[i * 2 + j]; 4679 args.inMinValue = arrayInMinValue[i]; 4680 args.inMaxValue = arrayInMaxValue[i]; 4681 // Figure out what the outputs should have been. 4682 CoreMathVerifier.computeClamp(args); 4683 // Validate the outputs. 4684 boolean valid = true; 4685 if (args.out != arrayOut[i * 2 + j]) { 4686 valid = false; 4687 } 4688 if (!valid) { 4689 if (!errorFound) { 4690 errorFound = true; 4691 message.append("Input inValue: "); 4692 appendVariableToMessage(message, args.inValue); 4693 message.append("\n"); 4694 message.append("Input inMinValue: "); 4695 appendVariableToMessage(message, args.inMinValue); 4696 message.append("\n"); 4697 message.append("Input inMaxValue: "); 4698 appendVariableToMessage(message, args.inMaxValue); 4699 message.append("\n"); 4700 message.append("Expected output out: "); 4701 appendVariableToMessage(message, args.out); 4702 message.append("\n"); 4703 message.append("Actual output out: "); 4704 appendVariableToMessage(message, arrayOut[i * 2 + j]); 4705 if (args.out != arrayOut[i * 2 + j]) { 4706 message.append(" FAIL"); 4707 } 4708 message.append("\n"); 4709 message.append("Errors at"); 4710 } 4711 message.append(" ["); 4712 message.append(Integer.toString(i)); 4713 message.append(", "); 4714 message.append(Integer.toString(j)); 4715 message.append("]"); 4716 } 4717 } 4718 } 4719 assertFalse("Incorrect output for checkClampUshort2UshortUshortUshort2" + 4720 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 4721 } 4722 checkClampUshort3UshortUshortUshort3()4723 private void checkClampUshort3UshortUshortUshort3() { 4724 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0x393771467c9cd603l, false); 4725 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0xfe016431b3cf1419l, false); 4726 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0xfe016426452c061fl, false); 4727 enforceOrdering(inMinValue, inMaxValue); 4728 try { 4729 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE); 4730 script.set_gAllocInMinValue(inMinValue); 4731 script.set_gAllocInMaxValue(inMaxValue); 4732 script.forEach_testClampUshort3UshortUshortUshort3(inValue, out); 4733 verifyResultsClampUshort3UshortUshortUshort3(inValue, inMinValue, inMaxValue, out, false); 4734 out.destroy(); 4735 } catch (Exception e) { 4736 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort3UshortUshortUshort3: " + e.toString()); 4737 } 4738 try { 4739 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE); 4740 scriptRelaxed.set_gAllocInMinValue(inMinValue); 4741 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 4742 scriptRelaxed.forEach_testClampUshort3UshortUshortUshort3(inValue, out); 4743 verifyResultsClampUshort3UshortUshortUshort3(inValue, inMinValue, inMaxValue, out, true); 4744 out.destroy(); 4745 } catch (Exception e) { 4746 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort3UshortUshortUshort3: " + e.toString()); 4747 } 4748 inValue.destroy(); 4749 inMinValue.destroy(); 4750 inMaxValue.destroy(); 4751 } 4752 verifyResultsClampUshort3UshortUshortUshort3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)4753 private void verifyResultsClampUshort3UshortUshortUshort3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 4754 short[] arrayInValue = new short[INPUTSIZE * 4]; 4755 Arrays.fill(arrayInValue, (short) 42); 4756 inValue.copyTo(arrayInValue); 4757 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 4758 Arrays.fill(arrayInMinValue, (short) 42); 4759 inMinValue.copyTo(arrayInMinValue); 4760 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 4761 Arrays.fill(arrayInMaxValue, (short) 42); 4762 inMaxValue.copyTo(arrayInMaxValue); 4763 short[] arrayOut = new short[INPUTSIZE * 4]; 4764 Arrays.fill(arrayOut, (short) 42); 4765 out.copyTo(arrayOut); 4766 StringBuilder message = new StringBuilder(); 4767 boolean errorFound = false; 4768 for (int i = 0; i < INPUTSIZE; i++) { 4769 for (int j = 0; j < 3 ; j++) { 4770 // Extract the inputs. 4771 ArgumentsUshortUshortUshortUshort args = new ArgumentsUshortUshortUshortUshort(); 4772 args.inValue = arrayInValue[i * 4 + j]; 4773 args.inMinValue = arrayInMinValue[i]; 4774 args.inMaxValue = arrayInMaxValue[i]; 4775 // Figure out what the outputs should have been. 4776 CoreMathVerifier.computeClamp(args); 4777 // Validate the outputs. 4778 boolean valid = true; 4779 if (args.out != arrayOut[i * 4 + j]) { 4780 valid = false; 4781 } 4782 if (!valid) { 4783 if (!errorFound) { 4784 errorFound = true; 4785 message.append("Input inValue: "); 4786 appendVariableToMessage(message, args.inValue); 4787 message.append("\n"); 4788 message.append("Input inMinValue: "); 4789 appendVariableToMessage(message, args.inMinValue); 4790 message.append("\n"); 4791 message.append("Input inMaxValue: "); 4792 appendVariableToMessage(message, args.inMaxValue); 4793 message.append("\n"); 4794 message.append("Expected output out: "); 4795 appendVariableToMessage(message, args.out); 4796 message.append("\n"); 4797 message.append("Actual output out: "); 4798 appendVariableToMessage(message, arrayOut[i * 4 + j]); 4799 if (args.out != arrayOut[i * 4 + j]) { 4800 message.append(" FAIL"); 4801 } 4802 message.append("\n"); 4803 message.append("Errors at"); 4804 } 4805 message.append(" ["); 4806 message.append(Integer.toString(i)); 4807 message.append(", "); 4808 message.append(Integer.toString(j)); 4809 message.append("]"); 4810 } 4811 } 4812 } 4813 assertFalse("Incorrect output for checkClampUshort3UshortUshortUshort3" + 4814 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 4815 } 4816 checkClampUshort4UshortUshortUshort4()4817 private void checkClampUshort4UshortUshortUshort4() { 4818 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0x43a07588a317bcffl, false); 4819 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0x2376f0c6a016decdl, false); 4820 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0x2376f0bb3173d0d3l, false); 4821 enforceOrdering(inMinValue, inMaxValue); 4822 try { 4823 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE); 4824 script.set_gAllocInMinValue(inMinValue); 4825 script.set_gAllocInMaxValue(inMaxValue); 4826 script.forEach_testClampUshort4UshortUshortUshort4(inValue, out); 4827 verifyResultsClampUshort4UshortUshortUshort4(inValue, inMinValue, inMaxValue, out, false); 4828 out.destroy(); 4829 } catch (Exception e) { 4830 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort4UshortUshortUshort4: " + e.toString()); 4831 } 4832 try { 4833 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE); 4834 scriptRelaxed.set_gAllocInMinValue(inMinValue); 4835 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 4836 scriptRelaxed.forEach_testClampUshort4UshortUshortUshort4(inValue, out); 4837 verifyResultsClampUshort4UshortUshortUshort4(inValue, inMinValue, inMaxValue, out, true); 4838 out.destroy(); 4839 } catch (Exception e) { 4840 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUshort4UshortUshortUshort4: " + e.toString()); 4841 } 4842 inValue.destroy(); 4843 inMinValue.destroy(); 4844 inMaxValue.destroy(); 4845 } 4846 verifyResultsClampUshort4UshortUshortUshort4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)4847 private void verifyResultsClampUshort4UshortUshortUshort4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 4848 short[] arrayInValue = new short[INPUTSIZE * 4]; 4849 Arrays.fill(arrayInValue, (short) 42); 4850 inValue.copyTo(arrayInValue); 4851 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 4852 Arrays.fill(arrayInMinValue, (short) 42); 4853 inMinValue.copyTo(arrayInMinValue); 4854 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 4855 Arrays.fill(arrayInMaxValue, (short) 42); 4856 inMaxValue.copyTo(arrayInMaxValue); 4857 short[] arrayOut = new short[INPUTSIZE * 4]; 4858 Arrays.fill(arrayOut, (short) 42); 4859 out.copyTo(arrayOut); 4860 StringBuilder message = new StringBuilder(); 4861 boolean errorFound = false; 4862 for (int i = 0; i < INPUTSIZE; i++) { 4863 for (int j = 0; j < 4 ; j++) { 4864 // Extract the inputs. 4865 ArgumentsUshortUshortUshortUshort args = new ArgumentsUshortUshortUshortUshort(); 4866 args.inValue = arrayInValue[i * 4 + j]; 4867 args.inMinValue = arrayInMinValue[i]; 4868 args.inMaxValue = arrayInMaxValue[i]; 4869 // Figure out what the outputs should have been. 4870 CoreMathVerifier.computeClamp(args); 4871 // Validate the outputs. 4872 boolean valid = true; 4873 if (args.out != arrayOut[i * 4 + j]) { 4874 valid = false; 4875 } 4876 if (!valid) { 4877 if (!errorFound) { 4878 errorFound = true; 4879 message.append("Input inValue: "); 4880 appendVariableToMessage(message, args.inValue); 4881 message.append("\n"); 4882 message.append("Input inMinValue: "); 4883 appendVariableToMessage(message, args.inMinValue); 4884 message.append("\n"); 4885 message.append("Input inMaxValue: "); 4886 appendVariableToMessage(message, args.inMaxValue); 4887 message.append("\n"); 4888 message.append("Expected output out: "); 4889 appendVariableToMessage(message, args.out); 4890 message.append("\n"); 4891 message.append("Actual output out: "); 4892 appendVariableToMessage(message, arrayOut[i * 4 + j]); 4893 if (args.out != arrayOut[i * 4 + j]) { 4894 message.append(" FAIL"); 4895 } 4896 message.append("\n"); 4897 message.append("Errors at"); 4898 } 4899 message.append(" ["); 4900 message.append(Integer.toString(i)); 4901 message.append(", "); 4902 message.append(Integer.toString(j)); 4903 message.append("]"); 4904 } 4905 } 4906 } 4907 assertFalse("Incorrect output for checkClampUshort4UshortUshortUshort4" + 4908 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 4909 } 4910 checkClampInt2IntIntInt2()4911 private void checkClampInt2IntIntInt2() { 4912 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 2, 0xbb55c0997906d1dbl, false); 4913 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0x69776e80fba24121l, false); 4914 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0x69776e758cff3327l, false); 4915 enforceOrdering(inMinValue, inMaxValue); 4916 try { 4917 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE); 4918 script.set_gAllocInMinValue(inMinValue); 4919 script.set_gAllocInMaxValue(inMaxValue); 4920 script.forEach_testClampInt2IntIntInt2(inValue, out); 4921 verifyResultsClampInt2IntIntInt2(inValue, inMinValue, inMaxValue, out, false); 4922 out.destroy(); 4923 } catch (Exception e) { 4924 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt2IntIntInt2: " + e.toString()); 4925 } 4926 try { 4927 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE); 4928 scriptRelaxed.set_gAllocInMinValue(inMinValue); 4929 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 4930 scriptRelaxed.forEach_testClampInt2IntIntInt2(inValue, out); 4931 verifyResultsClampInt2IntIntInt2(inValue, inMinValue, inMaxValue, out, true); 4932 out.destroy(); 4933 } catch (Exception e) { 4934 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt2IntIntInt2: " + e.toString()); 4935 } 4936 inValue.destroy(); 4937 inMinValue.destroy(); 4938 inMaxValue.destroy(); 4939 } 4940 verifyResultsClampInt2IntIntInt2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)4941 private void verifyResultsClampInt2IntIntInt2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 4942 int[] arrayInValue = new int[INPUTSIZE * 2]; 4943 Arrays.fill(arrayInValue, (int) 42); 4944 inValue.copyTo(arrayInValue); 4945 int[] arrayInMinValue = new int[INPUTSIZE * 1]; 4946 Arrays.fill(arrayInMinValue, (int) 42); 4947 inMinValue.copyTo(arrayInMinValue); 4948 int[] arrayInMaxValue = new int[INPUTSIZE * 1]; 4949 Arrays.fill(arrayInMaxValue, (int) 42); 4950 inMaxValue.copyTo(arrayInMaxValue); 4951 int[] arrayOut = new int[INPUTSIZE * 2]; 4952 Arrays.fill(arrayOut, (int) 42); 4953 out.copyTo(arrayOut); 4954 StringBuilder message = new StringBuilder(); 4955 boolean errorFound = false; 4956 for (int i = 0; i < INPUTSIZE; i++) { 4957 for (int j = 0; j < 2 ; j++) { 4958 // Extract the inputs. 4959 ArgumentsIntIntIntInt args = new ArgumentsIntIntIntInt(); 4960 args.inValue = arrayInValue[i * 2 + j]; 4961 args.inMinValue = arrayInMinValue[i]; 4962 args.inMaxValue = arrayInMaxValue[i]; 4963 // Figure out what the outputs should have been. 4964 CoreMathVerifier.computeClamp(args); 4965 // Validate the outputs. 4966 boolean valid = true; 4967 if (args.out != arrayOut[i * 2 + j]) { 4968 valid = false; 4969 } 4970 if (!valid) { 4971 if (!errorFound) { 4972 errorFound = true; 4973 message.append("Input inValue: "); 4974 appendVariableToMessage(message, args.inValue); 4975 message.append("\n"); 4976 message.append("Input inMinValue: "); 4977 appendVariableToMessage(message, args.inMinValue); 4978 message.append("\n"); 4979 message.append("Input inMaxValue: "); 4980 appendVariableToMessage(message, args.inMaxValue); 4981 message.append("\n"); 4982 message.append("Expected output out: "); 4983 appendVariableToMessage(message, args.out); 4984 message.append("\n"); 4985 message.append("Actual output out: "); 4986 appendVariableToMessage(message, arrayOut[i * 2 + j]); 4987 if (args.out != arrayOut[i * 2 + j]) { 4988 message.append(" FAIL"); 4989 } 4990 message.append("\n"); 4991 message.append("Errors at"); 4992 } 4993 message.append(" ["); 4994 message.append(Integer.toString(i)); 4995 message.append(", "); 4996 message.append(Integer.toString(j)); 4997 message.append("]"); 4998 } 4999 } 5000 } 5001 assertFalse("Incorrect output for checkClampInt2IntIntInt2" + 5002 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 5003 } 5004 checkClampInt3IntIntInt3()5005 private void checkClampInt3IntIntInt3() { 5006 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x3af8924ab5370be9l, false); 5007 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0xdde27628f1a08b2bl, false); 5008 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0xdde2761d82fd7d31l, false); 5009 enforceOrdering(inMinValue, inMaxValue); 5010 try { 5011 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE); 5012 script.set_gAllocInMinValue(inMinValue); 5013 script.set_gAllocInMaxValue(inMaxValue); 5014 script.forEach_testClampInt3IntIntInt3(inValue, out); 5015 verifyResultsClampInt3IntIntInt3(inValue, inMinValue, inMaxValue, out, false); 5016 out.destroy(); 5017 } catch (Exception e) { 5018 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt3IntIntInt3: " + e.toString()); 5019 } 5020 try { 5021 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE); 5022 scriptRelaxed.set_gAllocInMinValue(inMinValue); 5023 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 5024 scriptRelaxed.forEach_testClampInt3IntIntInt3(inValue, out); 5025 verifyResultsClampInt3IntIntInt3(inValue, inMinValue, inMaxValue, out, true); 5026 out.destroy(); 5027 } catch (Exception e) { 5028 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt3IntIntInt3: " + e.toString()); 5029 } 5030 inValue.destroy(); 5031 inMinValue.destroy(); 5032 inMaxValue.destroy(); 5033 } 5034 verifyResultsClampInt3IntIntInt3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)5035 private void verifyResultsClampInt3IntIntInt3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 5036 int[] arrayInValue = new int[INPUTSIZE * 4]; 5037 Arrays.fill(arrayInValue, (int) 42); 5038 inValue.copyTo(arrayInValue); 5039 int[] arrayInMinValue = new int[INPUTSIZE * 1]; 5040 Arrays.fill(arrayInMinValue, (int) 42); 5041 inMinValue.copyTo(arrayInMinValue); 5042 int[] arrayInMaxValue = new int[INPUTSIZE * 1]; 5043 Arrays.fill(arrayInMaxValue, (int) 42); 5044 inMaxValue.copyTo(arrayInMaxValue); 5045 int[] arrayOut = new int[INPUTSIZE * 4]; 5046 Arrays.fill(arrayOut, (int) 42); 5047 out.copyTo(arrayOut); 5048 StringBuilder message = new StringBuilder(); 5049 boolean errorFound = false; 5050 for (int i = 0; i < INPUTSIZE; i++) { 5051 for (int j = 0; j < 3 ; j++) { 5052 // Extract the inputs. 5053 ArgumentsIntIntIntInt args = new ArgumentsIntIntIntInt(); 5054 args.inValue = arrayInValue[i * 4 + j]; 5055 args.inMinValue = arrayInMinValue[i]; 5056 args.inMaxValue = arrayInMaxValue[i]; 5057 // Figure out what the outputs should have been. 5058 CoreMathVerifier.computeClamp(args); 5059 // Validate the outputs. 5060 boolean valid = true; 5061 if (args.out != arrayOut[i * 4 + j]) { 5062 valid = false; 5063 } 5064 if (!valid) { 5065 if (!errorFound) { 5066 errorFound = true; 5067 message.append("Input inValue: "); 5068 appendVariableToMessage(message, args.inValue); 5069 message.append("\n"); 5070 message.append("Input inMinValue: "); 5071 appendVariableToMessage(message, args.inMinValue); 5072 message.append("\n"); 5073 message.append("Input inMaxValue: "); 5074 appendVariableToMessage(message, args.inMaxValue); 5075 message.append("\n"); 5076 message.append("Expected output out: "); 5077 appendVariableToMessage(message, args.out); 5078 message.append("\n"); 5079 message.append("Actual output out: "); 5080 appendVariableToMessage(message, arrayOut[i * 4 + j]); 5081 if (args.out != arrayOut[i * 4 + j]) { 5082 message.append(" FAIL"); 5083 } 5084 message.append("\n"); 5085 message.append("Errors at"); 5086 } 5087 message.append(" ["); 5088 message.append(Integer.toString(i)); 5089 message.append(", "); 5090 message.append(Integer.toString(j)); 5091 message.append("]"); 5092 } 5093 } 5094 } 5095 assertFalse("Incorrect output for checkClampInt3IntIntInt3" + 5096 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 5097 } 5098 checkClampInt4IntIntInt4()5099 private void checkClampInt4IntIntInt4() { 5100 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 4, 0xba9b63fbf16745f7l, false); 5101 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0x524d7dd0e79ed535l, false); 5102 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0x524d7dc578fbc73bl, false); 5103 enforceOrdering(inMinValue, inMaxValue); 5104 try { 5105 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE); 5106 script.set_gAllocInMinValue(inMinValue); 5107 script.set_gAllocInMaxValue(inMaxValue); 5108 script.forEach_testClampInt4IntIntInt4(inValue, out); 5109 verifyResultsClampInt4IntIntInt4(inValue, inMinValue, inMaxValue, out, false); 5110 out.destroy(); 5111 } catch (Exception e) { 5112 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt4IntIntInt4: " + e.toString()); 5113 } 5114 try { 5115 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE); 5116 scriptRelaxed.set_gAllocInMinValue(inMinValue); 5117 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 5118 scriptRelaxed.forEach_testClampInt4IntIntInt4(inValue, out); 5119 verifyResultsClampInt4IntIntInt4(inValue, inMinValue, inMaxValue, out, true); 5120 out.destroy(); 5121 } catch (Exception e) { 5122 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampInt4IntIntInt4: " + e.toString()); 5123 } 5124 inValue.destroy(); 5125 inMinValue.destroy(); 5126 inMaxValue.destroy(); 5127 } 5128 verifyResultsClampInt4IntIntInt4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)5129 private void verifyResultsClampInt4IntIntInt4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 5130 int[] arrayInValue = new int[INPUTSIZE * 4]; 5131 Arrays.fill(arrayInValue, (int) 42); 5132 inValue.copyTo(arrayInValue); 5133 int[] arrayInMinValue = new int[INPUTSIZE * 1]; 5134 Arrays.fill(arrayInMinValue, (int) 42); 5135 inMinValue.copyTo(arrayInMinValue); 5136 int[] arrayInMaxValue = new int[INPUTSIZE * 1]; 5137 Arrays.fill(arrayInMaxValue, (int) 42); 5138 inMaxValue.copyTo(arrayInMaxValue); 5139 int[] arrayOut = new int[INPUTSIZE * 4]; 5140 Arrays.fill(arrayOut, (int) 42); 5141 out.copyTo(arrayOut); 5142 StringBuilder message = new StringBuilder(); 5143 boolean errorFound = false; 5144 for (int i = 0; i < INPUTSIZE; i++) { 5145 for (int j = 0; j < 4 ; j++) { 5146 // Extract the inputs. 5147 ArgumentsIntIntIntInt args = new ArgumentsIntIntIntInt(); 5148 args.inValue = arrayInValue[i * 4 + j]; 5149 args.inMinValue = arrayInMinValue[i]; 5150 args.inMaxValue = arrayInMaxValue[i]; 5151 // Figure out what the outputs should have been. 5152 CoreMathVerifier.computeClamp(args); 5153 // Validate the outputs. 5154 boolean valid = true; 5155 if (args.out != arrayOut[i * 4 + j]) { 5156 valid = false; 5157 } 5158 if (!valid) { 5159 if (!errorFound) { 5160 errorFound = true; 5161 message.append("Input inValue: "); 5162 appendVariableToMessage(message, args.inValue); 5163 message.append("\n"); 5164 message.append("Input inMinValue: "); 5165 appendVariableToMessage(message, args.inMinValue); 5166 message.append("\n"); 5167 message.append("Input inMaxValue: "); 5168 appendVariableToMessage(message, args.inMaxValue); 5169 message.append("\n"); 5170 message.append("Expected output out: "); 5171 appendVariableToMessage(message, args.out); 5172 message.append("\n"); 5173 message.append("Actual output out: "); 5174 appendVariableToMessage(message, arrayOut[i * 4 + j]); 5175 if (args.out != arrayOut[i * 4 + j]) { 5176 message.append(" FAIL"); 5177 } 5178 message.append("\n"); 5179 message.append("Errors at"); 5180 } 5181 message.append(" ["); 5182 message.append(Integer.toString(i)); 5183 message.append(", "); 5184 message.append(Integer.toString(j)); 5185 message.append("]"); 5186 } 5187 } 5188 } 5189 assertFalse("Incorrect output for checkClampInt4IntIntInt4" + 5190 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 5191 } 5192 checkClampUint2UintUintUint2()5193 private void checkClampUint2UintUintUint2() { 5194 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0x4fd098dd770d5a51l, false); 5195 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0x6de3f327c2a180e3l, false); 5196 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0x6de3f31c53fe72e9l, false); 5197 enforceOrdering(inMinValue, inMaxValue); 5198 try { 5199 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE); 5200 script.set_gAllocInMinValue(inMinValue); 5201 script.set_gAllocInMaxValue(inMaxValue); 5202 script.forEach_testClampUint2UintUintUint2(inValue, out); 5203 verifyResultsClampUint2UintUintUint2(inValue, inMinValue, inMaxValue, out, false); 5204 out.destroy(); 5205 } catch (Exception e) { 5206 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint2UintUintUint2: " + e.toString()); 5207 } 5208 try { 5209 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE); 5210 scriptRelaxed.set_gAllocInMinValue(inMinValue); 5211 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 5212 scriptRelaxed.forEach_testClampUint2UintUintUint2(inValue, out); 5213 verifyResultsClampUint2UintUintUint2(inValue, inMinValue, inMaxValue, out, true); 5214 out.destroy(); 5215 } catch (Exception e) { 5216 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint2UintUintUint2: " + e.toString()); 5217 } 5218 inValue.destroy(); 5219 inMinValue.destroy(); 5220 inMaxValue.destroy(); 5221 } 5222 verifyResultsClampUint2UintUintUint2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)5223 private void verifyResultsClampUint2UintUintUint2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 5224 int[] arrayInValue = new int[INPUTSIZE * 2]; 5225 Arrays.fill(arrayInValue, (int) 42); 5226 inValue.copyTo(arrayInValue); 5227 int[] arrayInMinValue = new int[INPUTSIZE * 1]; 5228 Arrays.fill(arrayInMinValue, (int) 42); 5229 inMinValue.copyTo(arrayInMinValue); 5230 int[] arrayInMaxValue = new int[INPUTSIZE * 1]; 5231 Arrays.fill(arrayInMaxValue, (int) 42); 5232 inMaxValue.copyTo(arrayInMaxValue); 5233 int[] arrayOut = new int[INPUTSIZE * 2]; 5234 Arrays.fill(arrayOut, (int) 42); 5235 out.copyTo(arrayOut); 5236 StringBuilder message = new StringBuilder(); 5237 boolean errorFound = false; 5238 for (int i = 0; i < INPUTSIZE; i++) { 5239 for (int j = 0; j < 2 ; j++) { 5240 // Extract the inputs. 5241 ArgumentsUintUintUintUint args = new ArgumentsUintUintUintUint(); 5242 args.inValue = arrayInValue[i * 2 + j]; 5243 args.inMinValue = arrayInMinValue[i]; 5244 args.inMaxValue = arrayInMaxValue[i]; 5245 // Figure out what the outputs should have been. 5246 CoreMathVerifier.computeClamp(args); 5247 // Validate the outputs. 5248 boolean valid = true; 5249 if (args.out != arrayOut[i * 2 + j]) { 5250 valid = false; 5251 } 5252 if (!valid) { 5253 if (!errorFound) { 5254 errorFound = true; 5255 message.append("Input inValue: "); 5256 appendVariableToMessage(message, args.inValue); 5257 message.append("\n"); 5258 message.append("Input inMinValue: "); 5259 appendVariableToMessage(message, args.inMinValue); 5260 message.append("\n"); 5261 message.append("Input inMaxValue: "); 5262 appendVariableToMessage(message, args.inMaxValue); 5263 message.append("\n"); 5264 message.append("Expected output out: "); 5265 appendVariableToMessage(message, args.out); 5266 message.append("\n"); 5267 message.append("Actual output out: "); 5268 appendVariableToMessage(message, arrayOut[i * 2 + j]); 5269 if (args.out != arrayOut[i * 2 + j]) { 5270 message.append(" FAIL"); 5271 } 5272 message.append("\n"); 5273 message.append("Errors at"); 5274 } 5275 message.append(" ["); 5276 message.append(Integer.toString(i)); 5277 message.append(", "); 5278 message.append(Integer.toString(j)); 5279 message.append("]"); 5280 } 5281 } 5282 } 5283 assertFalse("Incorrect output for checkClampUint2UintUintUint2" + 5284 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 5285 } 5286 checkClampUint3UintUintUint3()5287 private void checkClampUint3UintUintUint3() { 5288 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0xc3eed93d60582365l, false); 5289 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0xbd370ebb48112f5fl, false); 5290 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0xbd370eafd96e2165l, false); 5291 enforceOrdering(inMinValue, inMaxValue); 5292 try { 5293 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE); 5294 script.set_gAllocInMinValue(inMinValue); 5295 script.set_gAllocInMaxValue(inMaxValue); 5296 script.forEach_testClampUint3UintUintUint3(inValue, out); 5297 verifyResultsClampUint3UintUintUint3(inValue, inMinValue, inMaxValue, out, false); 5298 out.destroy(); 5299 } catch (Exception e) { 5300 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint3UintUintUint3: " + e.toString()); 5301 } 5302 try { 5303 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE); 5304 scriptRelaxed.set_gAllocInMinValue(inMinValue); 5305 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 5306 scriptRelaxed.forEach_testClampUint3UintUintUint3(inValue, out); 5307 verifyResultsClampUint3UintUintUint3(inValue, inMinValue, inMaxValue, out, true); 5308 out.destroy(); 5309 } catch (Exception e) { 5310 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint3UintUintUint3: " + e.toString()); 5311 } 5312 inValue.destroy(); 5313 inMinValue.destroy(); 5314 inMaxValue.destroy(); 5315 } 5316 verifyResultsClampUint3UintUintUint3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)5317 private void verifyResultsClampUint3UintUintUint3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 5318 int[] arrayInValue = new int[INPUTSIZE * 4]; 5319 Arrays.fill(arrayInValue, (int) 42); 5320 inValue.copyTo(arrayInValue); 5321 int[] arrayInMinValue = new int[INPUTSIZE * 1]; 5322 Arrays.fill(arrayInMinValue, (int) 42); 5323 inMinValue.copyTo(arrayInMinValue); 5324 int[] arrayInMaxValue = new int[INPUTSIZE * 1]; 5325 Arrays.fill(arrayInMaxValue, (int) 42); 5326 inMaxValue.copyTo(arrayInMaxValue); 5327 int[] arrayOut = new int[INPUTSIZE * 4]; 5328 Arrays.fill(arrayOut, (int) 42); 5329 out.copyTo(arrayOut); 5330 StringBuilder message = new StringBuilder(); 5331 boolean errorFound = false; 5332 for (int i = 0; i < INPUTSIZE; i++) { 5333 for (int j = 0; j < 3 ; j++) { 5334 // Extract the inputs. 5335 ArgumentsUintUintUintUint args = new ArgumentsUintUintUintUint(); 5336 args.inValue = arrayInValue[i * 4 + j]; 5337 args.inMinValue = arrayInMinValue[i]; 5338 args.inMaxValue = arrayInMaxValue[i]; 5339 // Figure out what the outputs should have been. 5340 CoreMathVerifier.computeClamp(args); 5341 // Validate the outputs. 5342 boolean valid = true; 5343 if (args.out != arrayOut[i * 4 + j]) { 5344 valid = false; 5345 } 5346 if (!valid) { 5347 if (!errorFound) { 5348 errorFound = true; 5349 message.append("Input inValue: "); 5350 appendVariableToMessage(message, args.inValue); 5351 message.append("\n"); 5352 message.append("Input inMinValue: "); 5353 appendVariableToMessage(message, args.inMinValue); 5354 message.append("\n"); 5355 message.append("Input inMaxValue: "); 5356 appendVariableToMessage(message, args.inMaxValue); 5357 message.append("\n"); 5358 message.append("Expected output out: "); 5359 appendVariableToMessage(message, args.out); 5360 message.append("\n"); 5361 message.append("Actual output out: "); 5362 appendVariableToMessage(message, arrayOut[i * 4 + j]); 5363 if (args.out != arrayOut[i * 4 + j]) { 5364 message.append(" FAIL"); 5365 } 5366 message.append("\n"); 5367 message.append("Errors at"); 5368 } 5369 message.append(" ["); 5370 message.append(Integer.toString(i)); 5371 message.append(", "); 5372 message.append(Integer.toString(j)); 5373 message.append("]"); 5374 } 5375 } 5376 } 5377 assertFalse("Incorrect output for checkClampUint3UintUintUint3" + 5378 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 5379 } 5380 checkClampUint4UintUintUint4()5381 private void checkClampUint4UintUintUint4() { 5382 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0x380d199d49a2ec79l, false); 5383 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0xc8a2a4ecd80dddbl, false); 5384 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0xc8a2a435eddcfe1l, false); 5385 enforceOrdering(inMinValue, inMaxValue); 5386 try { 5387 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE); 5388 script.set_gAllocInMinValue(inMinValue); 5389 script.set_gAllocInMaxValue(inMaxValue); 5390 script.forEach_testClampUint4UintUintUint4(inValue, out); 5391 verifyResultsClampUint4UintUintUint4(inValue, inMinValue, inMaxValue, out, false); 5392 out.destroy(); 5393 } catch (Exception e) { 5394 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint4UintUintUint4: " + e.toString()); 5395 } 5396 try { 5397 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE); 5398 scriptRelaxed.set_gAllocInMinValue(inMinValue); 5399 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 5400 scriptRelaxed.forEach_testClampUint4UintUintUint4(inValue, out); 5401 verifyResultsClampUint4UintUintUint4(inValue, inMinValue, inMaxValue, out, true); 5402 out.destroy(); 5403 } catch (Exception e) { 5404 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUint4UintUintUint4: " + e.toString()); 5405 } 5406 inValue.destroy(); 5407 inMinValue.destroy(); 5408 inMaxValue.destroy(); 5409 } 5410 verifyResultsClampUint4UintUintUint4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)5411 private void verifyResultsClampUint4UintUintUint4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 5412 int[] arrayInValue = new int[INPUTSIZE * 4]; 5413 Arrays.fill(arrayInValue, (int) 42); 5414 inValue.copyTo(arrayInValue); 5415 int[] arrayInMinValue = new int[INPUTSIZE * 1]; 5416 Arrays.fill(arrayInMinValue, (int) 42); 5417 inMinValue.copyTo(arrayInMinValue); 5418 int[] arrayInMaxValue = new int[INPUTSIZE * 1]; 5419 Arrays.fill(arrayInMaxValue, (int) 42); 5420 inMaxValue.copyTo(arrayInMaxValue); 5421 int[] arrayOut = new int[INPUTSIZE * 4]; 5422 Arrays.fill(arrayOut, (int) 42); 5423 out.copyTo(arrayOut); 5424 StringBuilder message = new StringBuilder(); 5425 boolean errorFound = false; 5426 for (int i = 0; i < INPUTSIZE; i++) { 5427 for (int j = 0; j < 4 ; j++) { 5428 // Extract the inputs. 5429 ArgumentsUintUintUintUint args = new ArgumentsUintUintUintUint(); 5430 args.inValue = arrayInValue[i * 4 + j]; 5431 args.inMinValue = arrayInMinValue[i]; 5432 args.inMaxValue = arrayInMaxValue[i]; 5433 // Figure out what the outputs should have been. 5434 CoreMathVerifier.computeClamp(args); 5435 // Validate the outputs. 5436 boolean valid = true; 5437 if (args.out != arrayOut[i * 4 + j]) { 5438 valid = false; 5439 } 5440 if (!valid) { 5441 if (!errorFound) { 5442 errorFound = true; 5443 message.append("Input inValue: "); 5444 appendVariableToMessage(message, args.inValue); 5445 message.append("\n"); 5446 message.append("Input inMinValue: "); 5447 appendVariableToMessage(message, args.inMinValue); 5448 message.append("\n"); 5449 message.append("Input inMaxValue: "); 5450 appendVariableToMessage(message, args.inMaxValue); 5451 message.append("\n"); 5452 message.append("Expected output out: "); 5453 appendVariableToMessage(message, args.out); 5454 message.append("\n"); 5455 message.append("Actual output out: "); 5456 appendVariableToMessage(message, arrayOut[i * 4 + j]); 5457 if (args.out != arrayOut[i * 4 + j]) { 5458 message.append(" FAIL"); 5459 } 5460 message.append("\n"); 5461 message.append("Errors at"); 5462 } 5463 message.append(" ["); 5464 message.append(Integer.toString(i)); 5465 message.append(", "); 5466 message.append(Integer.toString(j)); 5467 message.append("]"); 5468 } 5469 } 5470 } 5471 assertFalse("Incorrect output for checkClampUint4UintUintUint4" + 5472 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 5473 } 5474 checkClampLong2LongLongLong2()5475 private void checkClampLong2LongLongLong2() { 5476 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 2, 0x19353a9f7c535bb5l, false); 5477 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 1, 0xee8dc7f38f83654fl, false); 5478 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 1, 0xee8dc7e820e05755l, false); 5479 enforceOrdering(inMinValue, inMaxValue); 5480 try { 5481 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE); 5482 script.set_gAllocInMinValue(inMinValue); 5483 script.set_gAllocInMaxValue(inMaxValue); 5484 script.forEach_testClampLong2LongLongLong2(inValue, out); 5485 verifyResultsClampLong2LongLongLong2(inValue, inMinValue, inMaxValue, out, false); 5486 out.destroy(); 5487 } catch (Exception e) { 5488 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong2LongLongLong2: " + e.toString()); 5489 } 5490 try { 5491 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE); 5492 scriptRelaxed.set_gAllocInMinValue(inMinValue); 5493 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 5494 scriptRelaxed.forEach_testClampLong2LongLongLong2(inValue, out); 5495 verifyResultsClampLong2LongLongLong2(inValue, inMinValue, inMaxValue, out, true); 5496 out.destroy(); 5497 } catch (Exception e) { 5498 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong2LongLongLong2: " + e.toString()); 5499 } 5500 inValue.destroy(); 5501 inMinValue.destroy(); 5502 inMaxValue.destroy(); 5503 } 5504 verifyResultsClampLong2LongLongLong2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)5505 private void verifyResultsClampLong2LongLongLong2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 5506 long[] arrayInValue = new long[INPUTSIZE * 2]; 5507 Arrays.fill(arrayInValue, (long) 42); 5508 inValue.copyTo(arrayInValue); 5509 long[] arrayInMinValue = new long[INPUTSIZE * 1]; 5510 Arrays.fill(arrayInMinValue, (long) 42); 5511 inMinValue.copyTo(arrayInMinValue); 5512 long[] arrayInMaxValue = new long[INPUTSIZE * 1]; 5513 Arrays.fill(arrayInMaxValue, (long) 42); 5514 inMaxValue.copyTo(arrayInMaxValue); 5515 long[] arrayOut = new long[INPUTSIZE * 2]; 5516 Arrays.fill(arrayOut, (long) 42); 5517 out.copyTo(arrayOut); 5518 StringBuilder message = new StringBuilder(); 5519 boolean errorFound = false; 5520 for (int i = 0; i < INPUTSIZE; i++) { 5521 for (int j = 0; j < 2 ; j++) { 5522 // Extract the inputs. 5523 ArgumentsLongLongLongLong args = new ArgumentsLongLongLongLong(); 5524 args.inValue = arrayInValue[i * 2 + j]; 5525 args.inMinValue = arrayInMinValue[i]; 5526 args.inMaxValue = arrayInMaxValue[i]; 5527 // Figure out what the outputs should have been. 5528 CoreMathVerifier.computeClamp(args); 5529 // Validate the outputs. 5530 boolean valid = true; 5531 if (args.out != arrayOut[i * 2 + j]) { 5532 valid = false; 5533 } 5534 if (!valid) { 5535 if (!errorFound) { 5536 errorFound = true; 5537 message.append("Input inValue: "); 5538 appendVariableToMessage(message, args.inValue); 5539 message.append("\n"); 5540 message.append("Input inMinValue: "); 5541 appendVariableToMessage(message, args.inMinValue); 5542 message.append("\n"); 5543 message.append("Input inMaxValue: "); 5544 appendVariableToMessage(message, args.inMaxValue); 5545 message.append("\n"); 5546 message.append("Expected output out: "); 5547 appendVariableToMessage(message, args.out); 5548 message.append("\n"); 5549 message.append("Actual output out: "); 5550 appendVariableToMessage(message, arrayOut[i * 2 + j]); 5551 if (args.out != arrayOut[i * 2 + j]) { 5552 message.append(" FAIL"); 5553 } 5554 message.append("\n"); 5555 message.append("Errors at"); 5556 } 5557 message.append(" ["); 5558 message.append(Integer.toString(i)); 5559 message.append(", "); 5560 message.append(Integer.toString(j)); 5561 message.append("]"); 5562 } 5563 } 5564 } 5565 assertFalse("Incorrect output for checkClampLong2LongLongLong2" + 5566 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 5567 } 5568 checkClampLong3LongLongLong3()5569 private void checkClampLong3LongLongLong3() { 5570 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 3, 0x8d537aff659e24c9l, false); 5571 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 1, 0x3de0e38714f313cbl, false); 5572 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 1, 0x3de0e37ba65005d1l, false); 5573 enforceOrdering(inMinValue, inMaxValue); 5574 try { 5575 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE); 5576 script.set_gAllocInMinValue(inMinValue); 5577 script.set_gAllocInMaxValue(inMaxValue); 5578 script.forEach_testClampLong3LongLongLong3(inValue, out); 5579 verifyResultsClampLong3LongLongLong3(inValue, inMinValue, inMaxValue, out, false); 5580 out.destroy(); 5581 } catch (Exception e) { 5582 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong3LongLongLong3: " + e.toString()); 5583 } 5584 try { 5585 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE); 5586 scriptRelaxed.set_gAllocInMinValue(inMinValue); 5587 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 5588 scriptRelaxed.forEach_testClampLong3LongLongLong3(inValue, out); 5589 verifyResultsClampLong3LongLongLong3(inValue, inMinValue, inMaxValue, out, true); 5590 out.destroy(); 5591 } catch (Exception e) { 5592 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong3LongLongLong3: " + e.toString()); 5593 } 5594 inValue.destroy(); 5595 inMinValue.destroy(); 5596 inMaxValue.destroy(); 5597 } 5598 verifyResultsClampLong3LongLongLong3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)5599 private void verifyResultsClampLong3LongLongLong3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 5600 long[] arrayInValue = new long[INPUTSIZE * 4]; 5601 Arrays.fill(arrayInValue, (long) 42); 5602 inValue.copyTo(arrayInValue); 5603 long[] arrayInMinValue = new long[INPUTSIZE * 1]; 5604 Arrays.fill(arrayInMinValue, (long) 42); 5605 inMinValue.copyTo(arrayInMinValue); 5606 long[] arrayInMaxValue = new long[INPUTSIZE * 1]; 5607 Arrays.fill(arrayInMaxValue, (long) 42); 5608 inMaxValue.copyTo(arrayInMaxValue); 5609 long[] arrayOut = new long[INPUTSIZE * 4]; 5610 Arrays.fill(arrayOut, (long) 42); 5611 out.copyTo(arrayOut); 5612 StringBuilder message = new StringBuilder(); 5613 boolean errorFound = false; 5614 for (int i = 0; i < INPUTSIZE; i++) { 5615 for (int j = 0; j < 3 ; j++) { 5616 // Extract the inputs. 5617 ArgumentsLongLongLongLong args = new ArgumentsLongLongLongLong(); 5618 args.inValue = arrayInValue[i * 4 + j]; 5619 args.inMinValue = arrayInMinValue[i]; 5620 args.inMaxValue = arrayInMaxValue[i]; 5621 // Figure out what the outputs should have been. 5622 CoreMathVerifier.computeClamp(args); 5623 // Validate the outputs. 5624 boolean valid = true; 5625 if (args.out != arrayOut[i * 4 + j]) { 5626 valid = false; 5627 } 5628 if (!valid) { 5629 if (!errorFound) { 5630 errorFound = true; 5631 message.append("Input inValue: "); 5632 appendVariableToMessage(message, args.inValue); 5633 message.append("\n"); 5634 message.append("Input inMinValue: "); 5635 appendVariableToMessage(message, args.inMinValue); 5636 message.append("\n"); 5637 message.append("Input inMaxValue: "); 5638 appendVariableToMessage(message, args.inMaxValue); 5639 message.append("\n"); 5640 message.append("Expected output out: "); 5641 appendVariableToMessage(message, args.out); 5642 message.append("\n"); 5643 message.append("Actual output out: "); 5644 appendVariableToMessage(message, arrayOut[i * 4 + j]); 5645 if (args.out != arrayOut[i * 4 + j]) { 5646 message.append(" FAIL"); 5647 } 5648 message.append("\n"); 5649 message.append("Errors at"); 5650 } 5651 message.append(" ["); 5652 message.append(Integer.toString(i)); 5653 message.append(", "); 5654 message.append(Integer.toString(j)); 5655 message.append("]"); 5656 } 5657 } 5658 } 5659 assertFalse("Incorrect output for checkClampLong3LongLongLong3" + 5660 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 5661 } 5662 checkClampLong4LongLongLong4()5663 private void checkClampLong4LongLongLong4() { 5664 Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 4, 0x171bb5f4ee8edddl, false); 5665 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 1, 0x8d33ff1a9a62c247l, false); 5666 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.SIGNED_64, 1, 0x8d33ff0f2bbfb44dl, false); 5667 enforceOrdering(inMinValue, inMaxValue); 5668 try { 5669 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE); 5670 script.set_gAllocInMinValue(inMinValue); 5671 script.set_gAllocInMaxValue(inMaxValue); 5672 script.forEach_testClampLong4LongLongLong4(inValue, out); 5673 verifyResultsClampLong4LongLongLong4(inValue, inMinValue, inMaxValue, out, false); 5674 out.destroy(); 5675 } catch (Exception e) { 5676 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong4LongLongLong4: " + e.toString()); 5677 } 5678 try { 5679 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE); 5680 scriptRelaxed.set_gAllocInMinValue(inMinValue); 5681 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 5682 scriptRelaxed.forEach_testClampLong4LongLongLong4(inValue, out); 5683 verifyResultsClampLong4LongLongLong4(inValue, inMinValue, inMaxValue, out, true); 5684 out.destroy(); 5685 } catch (Exception e) { 5686 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampLong4LongLongLong4: " + e.toString()); 5687 } 5688 inValue.destroy(); 5689 inMinValue.destroy(); 5690 inMaxValue.destroy(); 5691 } 5692 verifyResultsClampLong4LongLongLong4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)5693 private void verifyResultsClampLong4LongLongLong4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 5694 long[] arrayInValue = new long[INPUTSIZE * 4]; 5695 Arrays.fill(arrayInValue, (long) 42); 5696 inValue.copyTo(arrayInValue); 5697 long[] arrayInMinValue = new long[INPUTSIZE * 1]; 5698 Arrays.fill(arrayInMinValue, (long) 42); 5699 inMinValue.copyTo(arrayInMinValue); 5700 long[] arrayInMaxValue = new long[INPUTSIZE * 1]; 5701 Arrays.fill(arrayInMaxValue, (long) 42); 5702 inMaxValue.copyTo(arrayInMaxValue); 5703 long[] arrayOut = new long[INPUTSIZE * 4]; 5704 Arrays.fill(arrayOut, (long) 42); 5705 out.copyTo(arrayOut); 5706 StringBuilder message = new StringBuilder(); 5707 boolean errorFound = false; 5708 for (int i = 0; i < INPUTSIZE; i++) { 5709 for (int j = 0; j < 4 ; j++) { 5710 // Extract the inputs. 5711 ArgumentsLongLongLongLong args = new ArgumentsLongLongLongLong(); 5712 args.inValue = arrayInValue[i * 4 + j]; 5713 args.inMinValue = arrayInMinValue[i]; 5714 args.inMaxValue = arrayInMaxValue[i]; 5715 // Figure out what the outputs should have been. 5716 CoreMathVerifier.computeClamp(args); 5717 // Validate the outputs. 5718 boolean valid = true; 5719 if (args.out != arrayOut[i * 4 + j]) { 5720 valid = false; 5721 } 5722 if (!valid) { 5723 if (!errorFound) { 5724 errorFound = true; 5725 message.append("Input inValue: "); 5726 appendVariableToMessage(message, args.inValue); 5727 message.append("\n"); 5728 message.append("Input inMinValue: "); 5729 appendVariableToMessage(message, args.inMinValue); 5730 message.append("\n"); 5731 message.append("Input inMaxValue: "); 5732 appendVariableToMessage(message, args.inMaxValue); 5733 message.append("\n"); 5734 message.append("Expected output out: "); 5735 appendVariableToMessage(message, args.out); 5736 message.append("\n"); 5737 message.append("Actual output out: "); 5738 appendVariableToMessage(message, arrayOut[i * 4 + j]); 5739 if (args.out != arrayOut[i * 4 + j]) { 5740 message.append(" FAIL"); 5741 } 5742 message.append("\n"); 5743 message.append("Errors at"); 5744 } 5745 message.append(" ["); 5746 message.append(Integer.toString(i)); 5747 message.append(", "); 5748 message.append(Integer.toString(j)); 5749 message.append("]"); 5750 } 5751 } 5752 } 5753 assertFalse("Incorrect output for checkClampLong4LongLongLong4" + 5754 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 5755 } 5756 checkClampUlong2UlongUlongUlong2()5757 private void checkClampUlong2UlongUlongUlong2() { 5758 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0xf275dabaa7fa1bf7l, false); 5759 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 1, 0xf08a9e698d13b735l, false); 5760 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 1, 0xf08a9e5e1e70a93bl, false); 5761 enforceOrdering(inMinValue, inMaxValue); 5762 try { 5763 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE); 5764 script.set_gAllocInMinValue(inMinValue); 5765 script.set_gAllocInMaxValue(inMaxValue); 5766 script.forEach_testClampUlong2UlongUlongUlong2(inValue, out); 5767 verifyResultsClampUlong2UlongUlongUlong2(inValue, inMinValue, inMaxValue, out, false); 5768 out.destroy(); 5769 } catch (Exception e) { 5770 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong2UlongUlongUlong2: " + e.toString()); 5771 } 5772 try { 5773 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE); 5774 scriptRelaxed.set_gAllocInMinValue(inMinValue); 5775 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 5776 scriptRelaxed.forEach_testClampUlong2UlongUlongUlong2(inValue, out); 5777 verifyResultsClampUlong2UlongUlongUlong2(inValue, inMinValue, inMaxValue, out, true); 5778 out.destroy(); 5779 } catch (Exception e) { 5780 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong2UlongUlongUlong2: " + e.toString()); 5781 } 5782 inValue.destroy(); 5783 inMinValue.destroy(); 5784 inMaxValue.destroy(); 5785 } 5786 verifyResultsClampUlong2UlongUlongUlong2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)5787 private void verifyResultsClampUlong2UlongUlongUlong2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 5788 long[] arrayInValue = new long[INPUTSIZE * 2]; 5789 Arrays.fill(arrayInValue, (long) 42); 5790 inValue.copyTo(arrayInValue); 5791 long[] arrayInMinValue = new long[INPUTSIZE * 1]; 5792 Arrays.fill(arrayInMinValue, (long) 42); 5793 inMinValue.copyTo(arrayInMinValue); 5794 long[] arrayInMaxValue = new long[INPUTSIZE * 1]; 5795 Arrays.fill(arrayInMaxValue, (long) 42); 5796 inMaxValue.copyTo(arrayInMaxValue); 5797 long[] arrayOut = new long[INPUTSIZE * 2]; 5798 Arrays.fill(arrayOut, (long) 42); 5799 out.copyTo(arrayOut); 5800 StringBuilder message = new StringBuilder(); 5801 boolean errorFound = false; 5802 for (int i = 0; i < INPUTSIZE; i++) { 5803 for (int j = 0; j < 2 ; j++) { 5804 // Extract the inputs. 5805 ArgumentsUlongUlongUlongUlong args = new ArgumentsUlongUlongUlongUlong(); 5806 args.inValue = arrayInValue[i * 2 + j]; 5807 args.inMinValue = arrayInMinValue[i]; 5808 args.inMaxValue = arrayInMaxValue[i]; 5809 // Figure out what the outputs should have been. 5810 CoreMathVerifier.computeClamp(args); 5811 // Validate the outputs. 5812 boolean valid = true; 5813 if (args.out != arrayOut[i * 2 + j]) { 5814 valid = false; 5815 } 5816 if (!valid) { 5817 if (!errorFound) { 5818 errorFound = true; 5819 message.append("Input inValue: "); 5820 appendVariableToMessage(message, args.inValue); 5821 message.append("\n"); 5822 message.append("Input inMinValue: "); 5823 appendVariableToMessage(message, args.inMinValue); 5824 message.append("\n"); 5825 message.append("Input inMaxValue: "); 5826 appendVariableToMessage(message, args.inMaxValue); 5827 message.append("\n"); 5828 message.append("Expected output out: "); 5829 appendVariableToMessage(message, args.out); 5830 message.append("\n"); 5831 message.append("Actual output out: "); 5832 appendVariableToMessage(message, arrayOut[i * 2 + j]); 5833 if (args.out != arrayOut[i * 2 + j]) { 5834 message.append(" FAIL"); 5835 } 5836 message.append("\n"); 5837 message.append("Errors at"); 5838 } 5839 message.append(" ["); 5840 message.append(Integer.toString(i)); 5841 message.append(", "); 5842 message.append(Integer.toString(j)); 5843 message.append("]"); 5844 } 5845 } 5846 } 5847 assertFalse("Incorrect output for checkClampUlong2UlongUlongUlong2" + 5848 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 5849 } 5850 checkClampUlong3UlongUlongUlong3()5851 private void checkClampUlong3UlongUlongUlong3() { 5852 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0x417c2f0620b6497dl, false); 5853 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 1, 0xfb4069f3c0421f27l, false); 5854 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 1, 0xfb4069e8519f112dl, false); 5855 enforceOrdering(inMinValue, inMaxValue); 5856 try { 5857 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE); 5858 script.set_gAllocInMinValue(inMinValue); 5859 script.set_gAllocInMaxValue(inMaxValue); 5860 script.forEach_testClampUlong3UlongUlongUlong3(inValue, out); 5861 verifyResultsClampUlong3UlongUlongUlong3(inValue, inMinValue, inMaxValue, out, false); 5862 out.destroy(); 5863 } catch (Exception e) { 5864 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong3UlongUlongUlong3: " + e.toString()); 5865 } 5866 try { 5867 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE); 5868 scriptRelaxed.set_gAllocInMinValue(inMinValue); 5869 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 5870 scriptRelaxed.forEach_testClampUlong3UlongUlongUlong3(inValue, out); 5871 verifyResultsClampUlong3UlongUlongUlong3(inValue, inMinValue, inMaxValue, out, true); 5872 out.destroy(); 5873 } catch (Exception e) { 5874 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong3UlongUlongUlong3: " + e.toString()); 5875 } 5876 inValue.destroy(); 5877 inMinValue.destroy(); 5878 inMaxValue.destroy(); 5879 } 5880 verifyResultsClampUlong3UlongUlongUlong3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)5881 private void verifyResultsClampUlong3UlongUlongUlong3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 5882 long[] arrayInValue = new long[INPUTSIZE * 4]; 5883 Arrays.fill(arrayInValue, (long) 42); 5884 inValue.copyTo(arrayInValue); 5885 long[] arrayInMinValue = new long[INPUTSIZE * 1]; 5886 Arrays.fill(arrayInMinValue, (long) 42); 5887 inMinValue.copyTo(arrayInMinValue); 5888 long[] arrayInMaxValue = new long[INPUTSIZE * 1]; 5889 Arrays.fill(arrayInMaxValue, (long) 42); 5890 inMaxValue.copyTo(arrayInMaxValue); 5891 long[] arrayOut = new long[INPUTSIZE * 4]; 5892 Arrays.fill(arrayOut, (long) 42); 5893 out.copyTo(arrayOut); 5894 StringBuilder message = new StringBuilder(); 5895 boolean errorFound = false; 5896 for (int i = 0; i < INPUTSIZE; i++) { 5897 for (int j = 0; j < 3 ; j++) { 5898 // Extract the inputs. 5899 ArgumentsUlongUlongUlongUlong args = new ArgumentsUlongUlongUlongUlong(); 5900 args.inValue = arrayInValue[i * 4 + j]; 5901 args.inMinValue = arrayInMinValue[i]; 5902 args.inMaxValue = arrayInMaxValue[i]; 5903 // Figure out what the outputs should have been. 5904 CoreMathVerifier.computeClamp(args); 5905 // Validate the outputs. 5906 boolean valid = true; 5907 if (args.out != arrayOut[i * 4 + j]) { 5908 valid = false; 5909 } 5910 if (!valid) { 5911 if (!errorFound) { 5912 errorFound = true; 5913 message.append("Input inValue: "); 5914 appendVariableToMessage(message, args.inValue); 5915 message.append("\n"); 5916 message.append("Input inMinValue: "); 5917 appendVariableToMessage(message, args.inMinValue); 5918 message.append("\n"); 5919 message.append("Input inMaxValue: "); 5920 appendVariableToMessage(message, args.inMaxValue); 5921 message.append("\n"); 5922 message.append("Expected output out: "); 5923 appendVariableToMessage(message, args.out); 5924 message.append("\n"); 5925 message.append("Actual output out: "); 5926 appendVariableToMessage(message, arrayOut[i * 4 + j]); 5927 if (args.out != arrayOut[i * 4 + j]) { 5928 message.append(" FAIL"); 5929 } 5930 message.append("\n"); 5931 message.append("Errors at"); 5932 } 5933 message.append(" ["); 5934 message.append(Integer.toString(i)); 5935 message.append(", "); 5936 message.append(Integer.toString(j)); 5937 message.append("]"); 5938 } 5939 } 5940 } 5941 assertFalse("Incorrect output for checkClampUlong3UlongUlongUlong3" + 5942 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 5943 } 5944 checkClampUlong4UlongUlongUlong4()5945 private void checkClampUlong4UlongUlongUlong4() { 5946 Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x9082835199727703l, false); 5947 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 1, 0x5f6357df3708719l, false); 5948 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_64, 1, 0x5f6357284cd791fl, false); 5949 enforceOrdering(inMinValue, inMaxValue); 5950 try { 5951 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE); 5952 script.set_gAllocInMinValue(inMinValue); 5953 script.set_gAllocInMaxValue(inMaxValue); 5954 script.forEach_testClampUlong4UlongUlongUlong4(inValue, out); 5955 verifyResultsClampUlong4UlongUlongUlong4(inValue, inMinValue, inMaxValue, out, false); 5956 out.destroy(); 5957 } catch (Exception e) { 5958 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong4UlongUlongUlong4: " + e.toString()); 5959 } 5960 try { 5961 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE); 5962 scriptRelaxed.set_gAllocInMinValue(inMinValue); 5963 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 5964 scriptRelaxed.forEach_testClampUlong4UlongUlongUlong4(inValue, out); 5965 verifyResultsClampUlong4UlongUlongUlong4(inValue, inMinValue, inMaxValue, out, true); 5966 out.destroy(); 5967 } catch (Exception e) { 5968 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampUlong4UlongUlongUlong4: " + e.toString()); 5969 } 5970 inValue.destroy(); 5971 inMinValue.destroy(); 5972 inMaxValue.destroy(); 5973 } 5974 verifyResultsClampUlong4UlongUlongUlong4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)5975 private void verifyResultsClampUlong4UlongUlongUlong4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 5976 long[] arrayInValue = new long[INPUTSIZE * 4]; 5977 Arrays.fill(arrayInValue, (long) 42); 5978 inValue.copyTo(arrayInValue); 5979 long[] arrayInMinValue = new long[INPUTSIZE * 1]; 5980 Arrays.fill(arrayInMinValue, (long) 42); 5981 inMinValue.copyTo(arrayInMinValue); 5982 long[] arrayInMaxValue = new long[INPUTSIZE * 1]; 5983 Arrays.fill(arrayInMaxValue, (long) 42); 5984 inMaxValue.copyTo(arrayInMaxValue); 5985 long[] arrayOut = new long[INPUTSIZE * 4]; 5986 Arrays.fill(arrayOut, (long) 42); 5987 out.copyTo(arrayOut); 5988 StringBuilder message = new StringBuilder(); 5989 boolean errorFound = false; 5990 for (int i = 0; i < INPUTSIZE; i++) { 5991 for (int j = 0; j < 4 ; j++) { 5992 // Extract the inputs. 5993 ArgumentsUlongUlongUlongUlong args = new ArgumentsUlongUlongUlongUlong(); 5994 args.inValue = arrayInValue[i * 4 + j]; 5995 args.inMinValue = arrayInMinValue[i]; 5996 args.inMaxValue = arrayInMaxValue[i]; 5997 // Figure out what the outputs should have been. 5998 CoreMathVerifier.computeClamp(args); 5999 // Validate the outputs. 6000 boolean valid = true; 6001 if (args.out != arrayOut[i * 4 + j]) { 6002 valid = false; 6003 } 6004 if (!valid) { 6005 if (!errorFound) { 6006 errorFound = true; 6007 message.append("Input inValue: "); 6008 appendVariableToMessage(message, args.inValue); 6009 message.append("\n"); 6010 message.append("Input inMinValue: "); 6011 appendVariableToMessage(message, args.inMinValue); 6012 message.append("\n"); 6013 message.append("Input inMaxValue: "); 6014 appendVariableToMessage(message, args.inMaxValue); 6015 message.append("\n"); 6016 message.append("Expected output out: "); 6017 appendVariableToMessage(message, args.out); 6018 message.append("\n"); 6019 message.append("Actual output out: "); 6020 appendVariableToMessage(message, arrayOut[i * 4 + j]); 6021 if (args.out != arrayOut[i * 4 + j]) { 6022 message.append(" FAIL"); 6023 } 6024 message.append("\n"); 6025 message.append("Errors at"); 6026 } 6027 message.append(" ["); 6028 message.append(Integer.toString(i)); 6029 message.append(", "); 6030 message.append(Integer.toString(j)); 6031 message.append("]"); 6032 } 6033 } 6034 } 6035 assertFalse("Incorrect output for checkClampUlong4UlongUlongUlong4" + 6036 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 6037 } 6038 6039 public class ArgumentsHalfHalfHalfHalf { 6040 public short inValue; 6041 public double inValueDouble; 6042 public short inMinValue; 6043 public double inMinValueDouble; 6044 public short inMaxValue; 6045 public double inMaxValueDouble; 6046 public Target.Floaty out; 6047 } 6048 checkClampHalfHalfHalfHalf()6049 private void checkClampHalfHalfHalfHalf() { 6050 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xa14cfae504b82831l, false); 6051 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xd705630af102f883l, false); 6052 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xd70562ff825fea89l, false); 6053 enforceOrdering(inMinValue, inMaxValue); 6054 try { 6055 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 6056 script.set_gAllocInMinValue(inMinValue); 6057 script.set_gAllocInMaxValue(inMaxValue); 6058 script.forEach_testClampHalfHalfHalfHalf(inValue, out); 6059 verifyResultsClampHalfHalfHalfHalf(inValue, inMinValue, inMaxValue, out, false); 6060 out.destroy(); 6061 } catch (Exception e) { 6062 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalfHalfHalfHalf: " + e.toString()); 6063 } 6064 try { 6065 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 1), INPUTSIZE); 6066 scriptRelaxed.set_gAllocInMinValue(inMinValue); 6067 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 6068 scriptRelaxed.forEach_testClampHalfHalfHalfHalf(inValue, out); 6069 verifyResultsClampHalfHalfHalfHalf(inValue, inMinValue, inMaxValue, out, true); 6070 out.destroy(); 6071 } catch (Exception e) { 6072 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalfHalfHalfHalf: " + e.toString()); 6073 } 6074 inValue.destroy(); 6075 inMinValue.destroy(); 6076 inMaxValue.destroy(); 6077 } 6078 verifyResultsClampHalfHalfHalfHalf(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)6079 private void verifyResultsClampHalfHalfHalfHalf(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 6080 short[] arrayInValue = new short[INPUTSIZE * 1]; 6081 Arrays.fill(arrayInValue, (short) 42); 6082 inValue.copyTo(arrayInValue); 6083 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 6084 Arrays.fill(arrayInMinValue, (short) 42); 6085 inMinValue.copyTo(arrayInMinValue); 6086 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 6087 Arrays.fill(arrayInMaxValue, (short) 42); 6088 inMaxValue.copyTo(arrayInMaxValue); 6089 short[] arrayOut = new short[INPUTSIZE * 1]; 6090 Arrays.fill(arrayOut, (short) 42); 6091 out.copyTo(arrayOut); 6092 StringBuilder message = new StringBuilder(); 6093 boolean errorFound = false; 6094 for (int i = 0; i < INPUTSIZE; i++) { 6095 for (int j = 0; j < 1 ; j++) { 6096 // Extract the inputs. 6097 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf(); 6098 args.inValue = arrayInValue[i]; 6099 args.inValueDouble = Float16Utils.convertFloat16ToDouble(args.inValue); 6100 args.inMinValue = arrayInMinValue[i]; 6101 args.inMinValueDouble = Float16Utils.convertFloat16ToDouble(args.inMinValue); 6102 args.inMaxValue = arrayInMaxValue[i]; 6103 args.inMaxValueDouble = Float16Utils.convertFloat16ToDouble(args.inMaxValue); 6104 // Figure out what the outputs should have been. 6105 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 6106 CoreMathVerifier.computeClamp(args, target); 6107 // Validate the outputs. 6108 boolean valid = true; 6109 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 6110 valid = false; 6111 } 6112 if (!valid) { 6113 if (!errorFound) { 6114 errorFound = true; 6115 message.append("Input inValue: "); 6116 appendVariableToMessage(message, args.inValue); 6117 message.append("\n"); 6118 message.append("Input inMinValue: "); 6119 appendVariableToMessage(message, args.inMinValue); 6120 message.append("\n"); 6121 message.append("Input inMaxValue: "); 6122 appendVariableToMessage(message, args.inMaxValue); 6123 message.append("\n"); 6124 message.append("Expected output out: "); 6125 appendVariableToMessage(message, args.out); 6126 message.append("\n"); 6127 message.append("Actual output out: "); 6128 appendVariableToMessage(message, arrayOut[i * 1 + j]); 6129 message.append("\n"); 6130 message.append("Actual output out (in double): "); 6131 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j])); 6132 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 1 + j]))) { 6133 message.append(" FAIL"); 6134 } 6135 message.append("\n"); 6136 message.append("Errors at"); 6137 } 6138 message.append(" ["); 6139 message.append(Integer.toString(i)); 6140 message.append(", "); 6141 message.append(Integer.toString(j)); 6142 message.append("]"); 6143 } 6144 } 6145 } 6146 assertFalse("Incorrect output for checkClampHalfHalfHalfHalf" + 6147 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 6148 } 6149 checkClampHalf2Half2Half2Half2()6150 private void checkClampHalf2Half2Half2Half2() { 6151 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x21a2a411b1049715l, false); 6152 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x4311a0566f2ebd6fl, false); 6153 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x4311a04b008baf75l, false); 6154 enforceOrdering(inMinValue, inMaxValue); 6155 try { 6156 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 6157 script.set_gAllocInMinValue(inMinValue); 6158 script.set_gAllocInMaxValue(inMaxValue); 6159 script.forEach_testClampHalf2Half2Half2Half2(inValue, out); 6160 verifyResultsClampHalf2Half2Half2Half2(inValue, inMinValue, inMaxValue, out, false); 6161 out.destroy(); 6162 } catch (Exception e) { 6163 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf2Half2Half2Half2: " + e.toString()); 6164 } 6165 try { 6166 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 6167 scriptRelaxed.set_gAllocInMinValue(inMinValue); 6168 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 6169 scriptRelaxed.forEach_testClampHalf2Half2Half2Half2(inValue, out); 6170 verifyResultsClampHalf2Half2Half2Half2(inValue, inMinValue, inMaxValue, out, true); 6171 out.destroy(); 6172 } catch (Exception e) { 6173 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf2Half2Half2Half2: " + e.toString()); 6174 } 6175 inValue.destroy(); 6176 inMinValue.destroy(); 6177 inMaxValue.destroy(); 6178 } 6179 verifyResultsClampHalf2Half2Half2Half2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)6180 private void verifyResultsClampHalf2Half2Half2Half2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 6181 short[] arrayInValue = new short[INPUTSIZE * 2]; 6182 Arrays.fill(arrayInValue, (short) 42); 6183 inValue.copyTo(arrayInValue); 6184 short[] arrayInMinValue = new short[INPUTSIZE * 2]; 6185 Arrays.fill(arrayInMinValue, (short) 42); 6186 inMinValue.copyTo(arrayInMinValue); 6187 short[] arrayInMaxValue = new short[INPUTSIZE * 2]; 6188 Arrays.fill(arrayInMaxValue, (short) 42); 6189 inMaxValue.copyTo(arrayInMaxValue); 6190 short[] arrayOut = new short[INPUTSIZE * 2]; 6191 Arrays.fill(arrayOut, (short) 42); 6192 out.copyTo(arrayOut); 6193 StringBuilder message = new StringBuilder(); 6194 boolean errorFound = false; 6195 for (int i = 0; i < INPUTSIZE; i++) { 6196 for (int j = 0; j < 2 ; j++) { 6197 // Extract the inputs. 6198 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf(); 6199 args.inValue = arrayInValue[i * 2 + j]; 6200 args.inValueDouble = Float16Utils.convertFloat16ToDouble(args.inValue); 6201 args.inMinValue = arrayInMinValue[i * 2 + j]; 6202 args.inMinValueDouble = Float16Utils.convertFloat16ToDouble(args.inMinValue); 6203 args.inMaxValue = arrayInMaxValue[i * 2 + j]; 6204 args.inMaxValueDouble = Float16Utils.convertFloat16ToDouble(args.inMaxValue); 6205 // Figure out what the outputs should have been. 6206 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 6207 CoreMathVerifier.computeClamp(args, target); 6208 // Validate the outputs. 6209 boolean valid = true; 6210 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 6211 valid = false; 6212 } 6213 if (!valid) { 6214 if (!errorFound) { 6215 errorFound = true; 6216 message.append("Input inValue: "); 6217 appendVariableToMessage(message, args.inValue); 6218 message.append("\n"); 6219 message.append("Input inMinValue: "); 6220 appendVariableToMessage(message, args.inMinValue); 6221 message.append("\n"); 6222 message.append("Input inMaxValue: "); 6223 appendVariableToMessage(message, args.inMaxValue); 6224 message.append("\n"); 6225 message.append("Expected output out: "); 6226 appendVariableToMessage(message, args.out); 6227 message.append("\n"); 6228 message.append("Actual output out: "); 6229 appendVariableToMessage(message, arrayOut[i * 2 + j]); 6230 message.append("\n"); 6231 message.append("Actual output out (in double): "); 6232 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j])); 6233 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 6234 message.append(" FAIL"); 6235 } 6236 message.append("\n"); 6237 message.append("Errors at"); 6238 } 6239 message.append(" ["); 6240 message.append(Integer.toString(i)); 6241 message.append(", "); 6242 message.append(Integer.toString(j)); 6243 message.append("]"); 6244 } 6245 } 6246 } 6247 assertFalse("Incorrect output for checkClampHalf2Half2Half2Half2" + 6248 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 6249 } 6250 checkClampHalf3Half3Half3Half3()6251 private void checkClampHalf3Half3Half3Half3() { 6252 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0x7a4fc1e2a6d9935dl, false); 6253 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xd094c90381facac7l, false); 6254 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xd094c8f81357bccdl, false); 6255 enforceOrdering(inMinValue, inMaxValue); 6256 try { 6257 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 6258 script.set_gAllocInMinValue(inMinValue); 6259 script.set_gAllocInMaxValue(inMaxValue); 6260 script.forEach_testClampHalf3Half3Half3Half3(inValue, out); 6261 verifyResultsClampHalf3Half3Half3Half3(inValue, inMinValue, inMaxValue, out, false); 6262 out.destroy(); 6263 } catch (Exception e) { 6264 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf3Half3Half3Half3: " + e.toString()); 6265 } 6266 try { 6267 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 6268 scriptRelaxed.set_gAllocInMinValue(inMinValue); 6269 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 6270 scriptRelaxed.forEach_testClampHalf3Half3Half3Half3(inValue, out); 6271 verifyResultsClampHalf3Half3Half3Half3(inValue, inMinValue, inMaxValue, out, true); 6272 out.destroy(); 6273 } catch (Exception e) { 6274 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf3Half3Half3Half3: " + e.toString()); 6275 } 6276 inValue.destroy(); 6277 inMinValue.destroy(); 6278 inMaxValue.destroy(); 6279 } 6280 verifyResultsClampHalf3Half3Half3Half3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)6281 private void verifyResultsClampHalf3Half3Half3Half3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 6282 short[] arrayInValue = new short[INPUTSIZE * 4]; 6283 Arrays.fill(arrayInValue, (short) 42); 6284 inValue.copyTo(arrayInValue); 6285 short[] arrayInMinValue = new short[INPUTSIZE * 4]; 6286 Arrays.fill(arrayInMinValue, (short) 42); 6287 inMinValue.copyTo(arrayInMinValue); 6288 short[] arrayInMaxValue = new short[INPUTSIZE * 4]; 6289 Arrays.fill(arrayInMaxValue, (short) 42); 6290 inMaxValue.copyTo(arrayInMaxValue); 6291 short[] arrayOut = new short[INPUTSIZE * 4]; 6292 Arrays.fill(arrayOut, (short) 42); 6293 out.copyTo(arrayOut); 6294 StringBuilder message = new StringBuilder(); 6295 boolean errorFound = false; 6296 for (int i = 0; i < INPUTSIZE; i++) { 6297 for (int j = 0; j < 3 ; j++) { 6298 // Extract the inputs. 6299 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf(); 6300 args.inValue = arrayInValue[i * 4 + j]; 6301 args.inValueDouble = Float16Utils.convertFloat16ToDouble(args.inValue); 6302 args.inMinValue = arrayInMinValue[i * 4 + j]; 6303 args.inMinValueDouble = Float16Utils.convertFloat16ToDouble(args.inMinValue); 6304 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 6305 args.inMaxValueDouble = Float16Utils.convertFloat16ToDouble(args.inMaxValue); 6306 // Figure out what the outputs should have been. 6307 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 6308 CoreMathVerifier.computeClamp(args, target); 6309 // Validate the outputs. 6310 boolean valid = true; 6311 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 6312 valid = false; 6313 } 6314 if (!valid) { 6315 if (!errorFound) { 6316 errorFound = true; 6317 message.append("Input inValue: "); 6318 appendVariableToMessage(message, args.inValue); 6319 message.append("\n"); 6320 message.append("Input inMinValue: "); 6321 appendVariableToMessage(message, args.inMinValue); 6322 message.append("\n"); 6323 message.append("Input inMaxValue: "); 6324 appendVariableToMessage(message, args.inMaxValue); 6325 message.append("\n"); 6326 message.append("Expected output out: "); 6327 appendVariableToMessage(message, args.out); 6328 message.append("\n"); 6329 message.append("Actual output out: "); 6330 appendVariableToMessage(message, arrayOut[i * 4 + j]); 6331 message.append("\n"); 6332 message.append("Actual output out (in double): "); 6333 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 6334 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 6335 message.append(" FAIL"); 6336 } 6337 message.append("\n"); 6338 message.append("Errors at"); 6339 } 6340 message.append(" ["); 6341 message.append(Integer.toString(i)); 6342 message.append(", "); 6343 message.append(Integer.toString(j)); 6344 message.append("]"); 6345 } 6346 } 6347 } 6348 assertFalse("Incorrect output for checkClampHalf3Half3Half3Half3" + 6349 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 6350 } 6351 checkClampHalf4Half4Half4Half4()6352 private void checkClampHalf4Half4Half4Half4() { 6353 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0xd2fcdfb39cae8fa5l, false); 6354 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x5e17f1b094c6d81fl, false); 6355 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x5e17f1a52623ca25l, false); 6356 enforceOrdering(inMinValue, inMaxValue); 6357 try { 6358 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 6359 script.set_gAllocInMinValue(inMinValue); 6360 script.set_gAllocInMaxValue(inMaxValue); 6361 script.forEach_testClampHalf4Half4Half4Half4(inValue, out); 6362 verifyResultsClampHalf4Half4Half4Half4(inValue, inMinValue, inMaxValue, out, false); 6363 out.destroy(); 6364 } catch (Exception e) { 6365 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf4Half4Half4Half4: " + e.toString()); 6366 } 6367 try { 6368 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 6369 scriptRelaxed.set_gAllocInMinValue(inMinValue); 6370 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 6371 scriptRelaxed.forEach_testClampHalf4Half4Half4Half4(inValue, out); 6372 verifyResultsClampHalf4Half4Half4Half4(inValue, inMinValue, inMaxValue, out, true); 6373 out.destroy(); 6374 } catch (Exception e) { 6375 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf4Half4Half4Half4: " + e.toString()); 6376 } 6377 inValue.destroy(); 6378 inMinValue.destroy(); 6379 inMaxValue.destroy(); 6380 } 6381 verifyResultsClampHalf4Half4Half4Half4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)6382 private void verifyResultsClampHalf4Half4Half4Half4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 6383 short[] arrayInValue = new short[INPUTSIZE * 4]; 6384 Arrays.fill(arrayInValue, (short) 42); 6385 inValue.copyTo(arrayInValue); 6386 short[] arrayInMinValue = new short[INPUTSIZE * 4]; 6387 Arrays.fill(arrayInMinValue, (short) 42); 6388 inMinValue.copyTo(arrayInMinValue); 6389 short[] arrayInMaxValue = new short[INPUTSIZE * 4]; 6390 Arrays.fill(arrayInMaxValue, (short) 42); 6391 inMaxValue.copyTo(arrayInMaxValue); 6392 short[] arrayOut = new short[INPUTSIZE * 4]; 6393 Arrays.fill(arrayOut, (short) 42); 6394 out.copyTo(arrayOut); 6395 StringBuilder message = new StringBuilder(); 6396 boolean errorFound = false; 6397 for (int i = 0; i < INPUTSIZE; i++) { 6398 for (int j = 0; j < 4 ; j++) { 6399 // Extract the inputs. 6400 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf(); 6401 args.inValue = arrayInValue[i * 4 + j]; 6402 args.inValueDouble = Float16Utils.convertFloat16ToDouble(args.inValue); 6403 args.inMinValue = arrayInMinValue[i * 4 + j]; 6404 args.inMinValueDouble = Float16Utils.convertFloat16ToDouble(args.inMinValue); 6405 args.inMaxValue = arrayInMaxValue[i * 4 + j]; 6406 args.inMaxValueDouble = Float16Utils.convertFloat16ToDouble(args.inMaxValue); 6407 // Figure out what the outputs should have been. 6408 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 6409 CoreMathVerifier.computeClamp(args, target); 6410 // Validate the outputs. 6411 boolean valid = true; 6412 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 6413 valid = false; 6414 } 6415 if (!valid) { 6416 if (!errorFound) { 6417 errorFound = true; 6418 message.append("Input inValue: "); 6419 appendVariableToMessage(message, args.inValue); 6420 message.append("\n"); 6421 message.append("Input inMinValue: "); 6422 appendVariableToMessage(message, args.inMinValue); 6423 message.append("\n"); 6424 message.append("Input inMaxValue: "); 6425 appendVariableToMessage(message, args.inMaxValue); 6426 message.append("\n"); 6427 message.append("Expected output out: "); 6428 appendVariableToMessage(message, args.out); 6429 message.append("\n"); 6430 message.append("Actual output out: "); 6431 appendVariableToMessage(message, arrayOut[i * 4 + j]); 6432 message.append("\n"); 6433 message.append("Actual output out (in double): "); 6434 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 6435 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 6436 message.append(" FAIL"); 6437 } 6438 message.append("\n"); 6439 message.append("Errors at"); 6440 } 6441 message.append(" ["); 6442 message.append(Integer.toString(i)); 6443 message.append(", "); 6444 message.append(Integer.toString(j)); 6445 message.append("]"); 6446 } 6447 } 6448 } 6449 assertFalse("Incorrect output for checkClampHalf4Half4Half4Half4" + 6450 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 6451 } 6452 checkClampHalf2HalfHalfHalf2()6453 private void checkClampHalf2HalfHalfHalf2() { 6454 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 2, 0x5a2c9cb635f68507l, false); 6455 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xcd629fcbbc3d6b65l, false); 6456 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0xcd629fc04d9a5d6bl, false); 6457 enforceOrdering(inMinValue, inMaxValue); 6458 try { 6459 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 6460 script.set_gAllocInMinValue(inMinValue); 6461 script.set_gAllocInMaxValue(inMaxValue); 6462 script.forEach_testClampHalf2HalfHalfHalf2(inValue, out); 6463 verifyResultsClampHalf2HalfHalfHalf2(inValue, inMinValue, inMaxValue, out, false); 6464 out.destroy(); 6465 } catch (Exception e) { 6466 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf2HalfHalfHalf2: " + e.toString()); 6467 } 6468 try { 6469 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 2), INPUTSIZE); 6470 scriptRelaxed.set_gAllocInMinValue(inMinValue); 6471 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 6472 scriptRelaxed.forEach_testClampHalf2HalfHalfHalf2(inValue, out); 6473 verifyResultsClampHalf2HalfHalfHalf2(inValue, inMinValue, inMaxValue, out, true); 6474 out.destroy(); 6475 } catch (Exception e) { 6476 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf2HalfHalfHalf2: " + e.toString()); 6477 } 6478 inValue.destroy(); 6479 inMinValue.destroy(); 6480 inMaxValue.destroy(); 6481 } 6482 verifyResultsClampHalf2HalfHalfHalf2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)6483 private void verifyResultsClampHalf2HalfHalfHalf2(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 6484 short[] arrayInValue = new short[INPUTSIZE * 2]; 6485 Arrays.fill(arrayInValue, (short) 42); 6486 inValue.copyTo(arrayInValue); 6487 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 6488 Arrays.fill(arrayInMinValue, (short) 42); 6489 inMinValue.copyTo(arrayInMinValue); 6490 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 6491 Arrays.fill(arrayInMaxValue, (short) 42); 6492 inMaxValue.copyTo(arrayInMaxValue); 6493 short[] arrayOut = new short[INPUTSIZE * 2]; 6494 Arrays.fill(arrayOut, (short) 42); 6495 out.copyTo(arrayOut); 6496 StringBuilder message = new StringBuilder(); 6497 boolean errorFound = false; 6498 for (int i = 0; i < INPUTSIZE; i++) { 6499 for (int j = 0; j < 2 ; j++) { 6500 // Extract the inputs. 6501 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf(); 6502 args.inValue = arrayInValue[i * 2 + j]; 6503 args.inValueDouble = Float16Utils.convertFloat16ToDouble(args.inValue); 6504 args.inMinValue = arrayInMinValue[i]; 6505 args.inMinValueDouble = Float16Utils.convertFloat16ToDouble(args.inMinValue); 6506 args.inMaxValue = arrayInMaxValue[i]; 6507 args.inMaxValueDouble = Float16Utils.convertFloat16ToDouble(args.inMaxValue); 6508 // Figure out what the outputs should have been. 6509 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 6510 CoreMathVerifier.computeClamp(args, target); 6511 // Validate the outputs. 6512 boolean valid = true; 6513 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 6514 valid = false; 6515 } 6516 if (!valid) { 6517 if (!errorFound) { 6518 errorFound = true; 6519 message.append("Input inValue: "); 6520 appendVariableToMessage(message, args.inValue); 6521 message.append("\n"); 6522 message.append("Input inMinValue: "); 6523 appendVariableToMessage(message, args.inMinValue); 6524 message.append("\n"); 6525 message.append("Input inMaxValue: "); 6526 appendVariableToMessage(message, args.inMaxValue); 6527 message.append("\n"); 6528 message.append("Expected output out: "); 6529 appendVariableToMessage(message, args.out); 6530 message.append("\n"); 6531 message.append("Actual output out: "); 6532 appendVariableToMessage(message, arrayOut[i * 2 + j]); 6533 message.append("\n"); 6534 message.append("Actual output out (in double): "); 6535 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j])); 6536 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 2 + j]))) { 6537 message.append(" FAIL"); 6538 } 6539 message.append("\n"); 6540 message.append("Errors at"); 6541 } 6542 message.append(" ["); 6543 message.append(Integer.toString(i)); 6544 message.append(", "); 6545 message.append(Integer.toString(j)); 6546 message.append("]"); 6547 } 6548 } 6549 } 6550 assertFalse("Incorrect output for checkClampHalf2HalfHalfHalf2" + 6551 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 6552 } 6553 checkClampHalf3HalfHalfHalf3()6554 private void checkClampHalf3HalfHalfHalf3() { 6555 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 3, 0xce4add161f414e1bl, false); 6556 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x1cb5bb5f41ad19e1l, false); 6557 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x1cb5bb53d30a0be7l, false); 6558 enforceOrdering(inMinValue, inMaxValue); 6559 try { 6560 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 6561 script.set_gAllocInMinValue(inMinValue); 6562 script.set_gAllocInMaxValue(inMaxValue); 6563 script.forEach_testClampHalf3HalfHalfHalf3(inValue, out); 6564 verifyResultsClampHalf3HalfHalfHalf3(inValue, inMinValue, inMaxValue, out, false); 6565 out.destroy(); 6566 } catch (Exception e) { 6567 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf3HalfHalfHalf3: " + e.toString()); 6568 } 6569 try { 6570 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 3), INPUTSIZE); 6571 scriptRelaxed.set_gAllocInMinValue(inMinValue); 6572 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 6573 scriptRelaxed.forEach_testClampHalf3HalfHalfHalf3(inValue, out); 6574 verifyResultsClampHalf3HalfHalfHalf3(inValue, inMinValue, inMaxValue, out, true); 6575 out.destroy(); 6576 } catch (Exception e) { 6577 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf3HalfHalfHalf3: " + e.toString()); 6578 } 6579 inValue.destroy(); 6580 inMinValue.destroy(); 6581 inMaxValue.destroy(); 6582 } 6583 verifyResultsClampHalf3HalfHalfHalf3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)6584 private void verifyResultsClampHalf3HalfHalfHalf3(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 6585 short[] arrayInValue = new short[INPUTSIZE * 4]; 6586 Arrays.fill(arrayInValue, (short) 42); 6587 inValue.copyTo(arrayInValue); 6588 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 6589 Arrays.fill(arrayInMinValue, (short) 42); 6590 inMinValue.copyTo(arrayInMinValue); 6591 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 6592 Arrays.fill(arrayInMaxValue, (short) 42); 6593 inMaxValue.copyTo(arrayInMaxValue); 6594 short[] arrayOut = new short[INPUTSIZE * 4]; 6595 Arrays.fill(arrayOut, (short) 42); 6596 out.copyTo(arrayOut); 6597 StringBuilder message = new StringBuilder(); 6598 boolean errorFound = false; 6599 for (int i = 0; i < INPUTSIZE; i++) { 6600 for (int j = 0; j < 3 ; j++) { 6601 // Extract the inputs. 6602 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf(); 6603 args.inValue = arrayInValue[i * 4 + j]; 6604 args.inValueDouble = Float16Utils.convertFloat16ToDouble(args.inValue); 6605 args.inMinValue = arrayInMinValue[i]; 6606 args.inMinValueDouble = Float16Utils.convertFloat16ToDouble(args.inMinValue); 6607 args.inMaxValue = arrayInMaxValue[i]; 6608 args.inMaxValueDouble = Float16Utils.convertFloat16ToDouble(args.inMaxValue); 6609 // Figure out what the outputs should have been. 6610 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 6611 CoreMathVerifier.computeClamp(args, target); 6612 // Validate the outputs. 6613 boolean valid = true; 6614 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 6615 valid = false; 6616 } 6617 if (!valid) { 6618 if (!errorFound) { 6619 errorFound = true; 6620 message.append("Input inValue: "); 6621 appendVariableToMessage(message, args.inValue); 6622 message.append("\n"); 6623 message.append("Input inMinValue: "); 6624 appendVariableToMessage(message, args.inMinValue); 6625 message.append("\n"); 6626 message.append("Input inMaxValue: "); 6627 appendVariableToMessage(message, args.inMaxValue); 6628 message.append("\n"); 6629 message.append("Expected output out: "); 6630 appendVariableToMessage(message, args.out); 6631 message.append("\n"); 6632 message.append("Actual output out: "); 6633 appendVariableToMessage(message, arrayOut[i * 4 + j]); 6634 message.append("\n"); 6635 message.append("Actual output out (in double): "); 6636 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 6637 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 6638 message.append(" FAIL"); 6639 } 6640 message.append("\n"); 6641 message.append("Errors at"); 6642 } 6643 message.append(" ["); 6644 message.append(Integer.toString(i)); 6645 message.append(", "); 6646 message.append(Integer.toString(j)); 6647 message.append("]"); 6648 } 6649 } 6650 } 6651 assertFalse("Incorrect output for checkClampHalf3HalfHalfHalf3" + 6652 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 6653 } 6654 checkClampHalf4HalfHalfHalf4()6655 private void checkClampHalf4HalfHalfHalf4() { 6656 Allocation inValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 4, 0x42691d76088c172fl, false); 6657 Allocation inMinValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x6c08d6f2c71cc85dl, false); 6658 Allocation inMaxValue = createRandomAllocation(mRS, Element.DataType.FLOAT_16, 1, 0x6c08d6e75879ba63l, false); 6659 enforceOrdering(inMinValue, inMaxValue); 6660 try { 6661 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 6662 script.set_gAllocInMinValue(inMinValue); 6663 script.set_gAllocInMaxValue(inMaxValue); 6664 script.forEach_testClampHalf4HalfHalfHalf4(inValue, out); 6665 verifyResultsClampHalf4HalfHalfHalf4(inValue, inMinValue, inMaxValue, out, false); 6666 out.destroy(); 6667 } catch (Exception e) { 6668 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf4HalfHalfHalf4: " + e.toString()); 6669 } 6670 try { 6671 Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_16, 4), INPUTSIZE); 6672 scriptRelaxed.set_gAllocInMinValue(inMinValue); 6673 scriptRelaxed.set_gAllocInMaxValue(inMaxValue); 6674 scriptRelaxed.forEach_testClampHalf4HalfHalfHalf4(inValue, out); 6675 verifyResultsClampHalf4HalfHalfHalf4(inValue, inMinValue, inMaxValue, out, true); 6676 out.destroy(); 6677 } catch (Exception e) { 6678 throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClampHalf4HalfHalfHalf4: " + e.toString()); 6679 } 6680 inValue.destroy(); 6681 inMinValue.destroy(); 6682 inMaxValue.destroy(); 6683 } 6684 verifyResultsClampHalf4HalfHalfHalf4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed)6685 private void verifyResultsClampHalf4HalfHalfHalf4(Allocation inValue, Allocation inMinValue, Allocation inMaxValue, Allocation out, boolean relaxed) { 6686 short[] arrayInValue = new short[INPUTSIZE * 4]; 6687 Arrays.fill(arrayInValue, (short) 42); 6688 inValue.copyTo(arrayInValue); 6689 short[] arrayInMinValue = new short[INPUTSIZE * 1]; 6690 Arrays.fill(arrayInMinValue, (short) 42); 6691 inMinValue.copyTo(arrayInMinValue); 6692 short[] arrayInMaxValue = new short[INPUTSIZE * 1]; 6693 Arrays.fill(arrayInMaxValue, (short) 42); 6694 inMaxValue.copyTo(arrayInMaxValue); 6695 short[] arrayOut = new short[INPUTSIZE * 4]; 6696 Arrays.fill(arrayOut, (short) 42); 6697 out.copyTo(arrayOut); 6698 StringBuilder message = new StringBuilder(); 6699 boolean errorFound = false; 6700 for (int i = 0; i < INPUTSIZE; i++) { 6701 for (int j = 0; j < 4 ; j++) { 6702 // Extract the inputs. 6703 ArgumentsHalfHalfHalfHalf args = new ArgumentsHalfHalfHalfHalf(); 6704 args.inValue = arrayInValue[i * 4 + j]; 6705 args.inValueDouble = Float16Utils.convertFloat16ToDouble(args.inValue); 6706 args.inMinValue = arrayInMinValue[i]; 6707 args.inMinValueDouble = Float16Utils.convertFloat16ToDouble(args.inMinValue); 6708 args.inMaxValue = arrayInMaxValue[i]; 6709 args.inMaxValueDouble = Float16Utils.convertFloat16ToDouble(args.inMaxValue); 6710 // Figure out what the outputs should have been. 6711 Target target = new Target(Target.FunctionType.NORMAL, Target.ReturnType.HALF, relaxed); 6712 CoreMathVerifier.computeClamp(args, target); 6713 // Validate the outputs. 6714 boolean valid = true; 6715 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 6716 valid = false; 6717 } 6718 if (!valid) { 6719 if (!errorFound) { 6720 errorFound = true; 6721 message.append("Input inValue: "); 6722 appendVariableToMessage(message, args.inValue); 6723 message.append("\n"); 6724 message.append("Input inMinValue: "); 6725 appendVariableToMessage(message, args.inMinValue); 6726 message.append("\n"); 6727 message.append("Input inMaxValue: "); 6728 appendVariableToMessage(message, args.inMaxValue); 6729 message.append("\n"); 6730 message.append("Expected output out: "); 6731 appendVariableToMessage(message, args.out); 6732 message.append("\n"); 6733 message.append("Actual output out: "); 6734 appendVariableToMessage(message, arrayOut[i * 4 + j]); 6735 message.append("\n"); 6736 message.append("Actual output out (in double): "); 6737 appendVariableToMessage(message, Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j])); 6738 if (!args.out.couldBe(Float16Utils.convertFloat16ToDouble(arrayOut[i * 4 + j]))) { 6739 message.append(" FAIL"); 6740 } 6741 message.append("\n"); 6742 message.append("Errors at"); 6743 } 6744 message.append(" ["); 6745 message.append(Integer.toString(i)); 6746 message.append(", "); 6747 message.append(Integer.toString(j)); 6748 message.append("]"); 6749 } 6750 } 6751 } 6752 assertFalse("Incorrect output for checkClampHalf4HalfHalfHalf4" + 6753 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound); 6754 } 6755 testClamp()6756 public void testClamp() { 6757 checkClampFloatFloatFloatFloat(); 6758 checkClampFloat2Float2Float2Float2(); 6759 checkClampFloat3Float3Float3Float3(); 6760 checkClampFloat4Float4Float4Float4(); 6761 checkClampFloat2FloatFloatFloat2(); 6762 checkClampFloat3FloatFloatFloat3(); 6763 checkClampFloat4FloatFloatFloat4(); 6764 checkClampCharCharCharChar(); 6765 checkClampChar2Char2Char2Char2(); 6766 checkClampChar3Char3Char3Char3(); 6767 checkClampChar4Char4Char4Char4(); 6768 checkClampUcharUcharUcharUchar(); 6769 checkClampUchar2Uchar2Uchar2Uchar2(); 6770 checkClampUchar3Uchar3Uchar3Uchar3(); 6771 checkClampUchar4Uchar4Uchar4Uchar4(); 6772 checkClampShortShortShortShort(); 6773 checkClampShort2Short2Short2Short2(); 6774 checkClampShort3Short3Short3Short3(); 6775 checkClampShort4Short4Short4Short4(); 6776 checkClampUshortUshortUshortUshort(); 6777 checkClampUshort2Ushort2Ushort2Ushort2(); 6778 checkClampUshort3Ushort3Ushort3Ushort3(); 6779 checkClampUshort4Ushort4Ushort4Ushort4(); 6780 checkClampIntIntIntInt(); 6781 checkClampInt2Int2Int2Int2(); 6782 checkClampInt3Int3Int3Int3(); 6783 checkClampInt4Int4Int4Int4(); 6784 checkClampUintUintUintUint(); 6785 checkClampUint2Uint2Uint2Uint2(); 6786 checkClampUint3Uint3Uint3Uint3(); 6787 checkClampUint4Uint4Uint4Uint4(); 6788 checkClampLongLongLongLong(); 6789 checkClampLong2Long2Long2Long2(); 6790 checkClampLong3Long3Long3Long3(); 6791 checkClampLong4Long4Long4Long4(); 6792 checkClampUlongUlongUlongUlong(); 6793 checkClampUlong2Ulong2Ulong2Ulong2(); 6794 checkClampUlong3Ulong3Ulong3Ulong3(); 6795 checkClampUlong4Ulong4Ulong4Ulong4(); 6796 checkClampChar2CharCharChar2(); 6797 checkClampChar3CharCharChar3(); 6798 checkClampChar4CharCharChar4(); 6799 checkClampUchar2UcharUcharUchar2(); 6800 checkClampUchar3UcharUcharUchar3(); 6801 checkClampUchar4UcharUcharUchar4(); 6802 checkClampShort2ShortShortShort2(); 6803 checkClampShort3ShortShortShort3(); 6804 checkClampShort4ShortShortShort4(); 6805 checkClampUshort2UshortUshortUshort2(); 6806 checkClampUshort3UshortUshortUshort3(); 6807 checkClampUshort4UshortUshortUshort4(); 6808 checkClampInt2IntIntInt2(); 6809 checkClampInt3IntIntInt3(); 6810 checkClampInt4IntIntInt4(); 6811 checkClampUint2UintUintUint2(); 6812 checkClampUint3UintUintUint3(); 6813 checkClampUint4UintUintUint4(); 6814 checkClampLong2LongLongLong2(); 6815 checkClampLong3LongLongLong3(); 6816 checkClampLong4LongLongLong4(); 6817 checkClampUlong2UlongUlongUlong2(); 6818 checkClampUlong3UlongUlongUlong3(); 6819 checkClampUlong4UlongUlongUlong4(); 6820 checkClampHalfHalfHalfHalf(); 6821 checkClampHalf2Half2Half2Half2(); 6822 checkClampHalf3Half3Half3Half3(); 6823 checkClampHalf4Half4Half4Half4(); 6824 checkClampHalf2HalfHalfHalf2(); 6825 checkClampHalf3HalfHalfHalf3(); 6826 checkClampHalf4HalfHalfHalf4(); 6827 } 6828 } 6829