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