1 /* 2 * Copyright (C) 2015 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 package android.renderscript.cts; 18 19 import android.renderscript.Allocation; 20 import android.renderscript.Element; 21 import android.renderscript.Type; 22 import java.util.Random; 23 24 public class AllocationCopyPaddedTest extends RSBaseCompute { 25 public void test_AllocationPadded_Byte3_1D() { 26 Random random = new Random(0x172d8ab9); 27 int width = random.nextInt(128);; 28 int arr_len = width * 3; 29 30 byte[] inArray = new byte[arr_len]; 31 byte[] outArray = new byte[arr_len]; 32 random.nextBytes(inArray); 33 34 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); 35 typeBuilder.setX(width); 36 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 37 alloc.setAutoPadding(true); 38 alloc.copyFrom(inArray); 39 alloc.copyTo(outArray); 40 41 boolean result = true; 42 for (int i = 0; i < arr_len; i++) { 43 if (inArray[i] != outArray[i]) { 44 result = false; 45 break; 46 } 47 } 48 assertTrue("test_AllocationPadded_Byte3_1D Failed, output array does not match input", 49 result); 50 alloc.destroy(); 51 } 52 53 public void test_AllocationPadded_Byte3_2D() { 54 Random random = new Random(0x172d8ab9); 55 int width = random.nextInt(128); 56 int height = random.nextInt(128); 57 int arr_len = width * height * 3; 58 59 byte[] inArray = new byte[arr_len]; 60 byte[] outArray = new byte[arr_len]; 61 random.nextBytes(inArray); 62 63 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); 64 typeBuilder.setX(width).setY(height); 65 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 66 alloc.setAutoPadding(true); 67 alloc.copyFrom(inArray); 68 alloc.copyTo(outArray); 69 70 boolean result = true; 71 for (int i = 0; i < arr_len; i++) { 72 if (inArray[i] != outArray[i]) { 73 result = false; 74 break; 75 } 76 } 77 assertTrue("test_AllocationPadded_Byte3_2D Failed, output array does not match input", 78 result); 79 alloc.destroy(); 80 } 81 82 public void test_AllocationPadded_Byte3_3D() { 83 Random random = new Random(0x172d8ab9); 84 int w = random.nextInt(32); 85 int h = random.nextInt(32); 86 int d = random.nextInt(32); 87 int arr_len = w * d * h * 3; 88 89 byte[] inArray = new byte[arr_len]; 90 byte[] outArray = new byte[arr_len]; 91 random.nextBytes(inArray); 92 93 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); 94 typeBuilder.setX(w).setY(h).setZ(d); 95 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 96 alloc.setAutoPadding(true); 97 alloc.copyFrom(inArray); 98 alloc.copyTo(outArray); 99 100 boolean result = true; 101 for (int i = 0; i < arr_len; i++) { 102 if (inArray[i] != outArray[i]) { 103 result = false; 104 break; 105 } 106 } 107 assertTrue("test_AllocationPadded_Byte3_3D Failed, output array does not match input", 108 result); 109 alloc.destroy(); 110 } 111 112 void test_AllocationPadded_Short3_1D_Helper(Element element) { 113 Random random = new Random(0x172d8ab9); 114 int width = random.nextInt(512); 115 int arr_len = width * 3; 116 117 short[] inArray = new short[arr_len]; 118 short[] outArray = new short[arr_len]; 119 120 for (int i = 0; i < arr_len; i++) { 121 inArray[i] = (short)random.nextInt(); 122 } 123 124 Type.Builder typeBuilder = new Type.Builder(mRS, element); 125 typeBuilder.setX(width); 126 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 127 alloc.setAutoPadding(true); 128 alloc.copyFrom(inArray); 129 alloc.copyTo(outArray); 130 131 boolean result = true; 132 for (int i = 0; i < arr_len; i++) { 133 if (inArray[i] != outArray[i]) { 134 result = false; 135 break; 136 } 137 } 138 assertTrue("test_AllocationPadded_Short3_1D_Helper Failed, output array does not match input", 139 result); 140 alloc.destroy(); 141 } 142 143 public void test_AllocationPadded_Short3_1D() { 144 test_AllocationPadded_Short3_1D_Helper(Element.I16_3(mRS)); 145 test_AllocationPadded_Short3_1D_Helper(Element.F16_3(mRS)); 146 } 147 148 void test_AllocationPadded_Short3_2D_Helper(Element element) { 149 Random random = new Random(0x172d8ab9); 150 int width = random.nextInt(128); 151 int height = random.nextInt(128); 152 int arr_len = width * height * 3; 153 154 short[] inArray = new short[arr_len]; 155 short[] outArray = new short[arr_len]; 156 157 for (int i = 0; i < arr_len; i++) { 158 inArray[i] = (short)random.nextInt(); 159 } 160 161 Type.Builder typeBuilder = new Type.Builder(mRS, element); 162 typeBuilder.setX(width).setY(height); 163 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 164 alloc.setAutoPadding(true); 165 alloc.copyFrom(inArray); 166 alloc.copyTo(outArray); 167 168 boolean result = true; 169 for (int i = 0; i < arr_len; i++) { 170 if (inArray[i] != outArray[i]) { 171 result = false; 172 break; 173 } 174 } 175 assertTrue("test_AllocationPadded_Short3_2D_Helper Failed, output array does not match input", 176 result); 177 alloc.destroy(); 178 } 179 180 public void test_AllocationPadded_Short3_2D() { 181 test_AllocationPadded_Short3_2D_Helper(Element.I16_3(mRS)); 182 test_AllocationPadded_Short3_2D_Helper(Element.F16_3(mRS)); 183 } 184 185 void test_AllocationPadded_Short3_3D_Helper(Element element) { 186 Random random = new Random(0x172d8ab9); 187 int w = random.nextInt(32); 188 int h = random.nextInt(32); 189 int d = random.nextInt(32); 190 int arr_len = w * d * h * 3; 191 192 short[] inArray = new short[arr_len]; 193 short[] outArray = new short[arr_len]; 194 195 for (int i = 0; i < arr_len; i++) { 196 inArray[i] = (short)random.nextInt(); 197 } 198 199 Type.Builder typeBuilder = new Type.Builder(mRS, element); 200 typeBuilder.setX(w).setY(h).setZ(d); 201 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 202 alloc.setAutoPadding(true); 203 alloc.copyFrom(inArray); 204 alloc.copyTo(outArray); 205 206 boolean result = true; 207 for (int i = 0; i < arr_len; i++) { 208 if (inArray[i] != outArray[i]) { 209 result = false; 210 break; 211 } 212 } 213 assertTrue("test_AllocationPadded_Short3_3D_Helper Failed, output array does not match input", 214 result); 215 alloc.destroy(); 216 } 217 218 public void test_AllocationPadded_Short3_3D() { 219 test_AllocationPadded_Short3_3D_Helper(Element.I16_3(mRS)); 220 test_AllocationPadded_Short3_3D_Helper(Element.F16_3(mRS)); 221 } 222 223 public void test_AllocationPadded_Int3_1D() { 224 Random random = new Random(0x172d8ab9); 225 int width = random.nextInt(512); 226 int arr_len = width * 3; 227 228 int[] inArray = new int[arr_len]; 229 int[] outArray = new int[arr_len]; 230 231 for (int i = 0; i < arr_len; i++) { 232 inArray[i] = random.nextInt(); 233 } 234 235 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); 236 typeBuilder.setX(width); 237 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 238 alloc.setAutoPadding(true); 239 alloc.copyFrom(inArray); 240 alloc.copyTo(outArray); 241 242 boolean result = true; 243 for (int i = 0; i < arr_len; i++) { 244 if (inArray[i] != outArray[i]) { 245 result = false; 246 break; 247 } 248 } 249 assertTrue("test_AllocationPadded_Int3_1D Failed, output array does not match input", 250 result); 251 alloc.destroy(); 252 } 253 254 public void test_AllocationPadded_Int3_2D() { 255 Random random = new Random(0x172d8ab9); 256 int width = random.nextInt(128); 257 int height = random.nextInt(128); 258 int arr_len = width * height * 3; 259 260 int[] inArray = new int[arr_len]; 261 int[] outArray = new int[arr_len]; 262 263 for (int i = 0; i < arr_len; i++) { 264 inArray[i] = random.nextInt(); 265 } 266 267 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); 268 typeBuilder.setX(width).setY(height); 269 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 270 alloc.setAutoPadding(true); 271 alloc.copyFrom(inArray); 272 alloc.copyTo(outArray); 273 274 boolean result = true; 275 for (int i = 0; i < arr_len; i++) { 276 if (inArray[i] != outArray[i]) { 277 result = false; 278 break; 279 } 280 } 281 assertTrue("test_AllocationPadded_Int3_2D Failed, output array does not match input", 282 result); 283 alloc.destroy(); 284 } 285 286 public void test_AllocationPadded_Int3_3D() { 287 Random random = new Random(0x172d8ab9); 288 int w = random.nextInt(32); 289 int h = random.nextInt(32); 290 int d = random.nextInt(32); 291 int arr_len = w * d * h * 3; 292 293 int[] inArray = new int[arr_len]; 294 int[] outArray = new int[arr_len]; 295 296 for (int i = 0; i < arr_len; i++) { 297 inArray[i] = random.nextInt(); 298 } 299 300 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); 301 typeBuilder.setX(w).setY(h).setZ(d); 302 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 303 alloc.setAutoPadding(true); 304 alloc.copyFrom(inArray); 305 alloc.copyTo(outArray); 306 307 boolean result = true; 308 for (int i = 0; i < arr_len; i++) { 309 if (inArray[i] != outArray[i]) { 310 result = false; 311 break; 312 } 313 } 314 assertTrue("test_AllocationPadded_Int3_3D Failed, output array does not match input", 315 result); 316 alloc.destroy(); 317 } 318 319 public void test_AllocationPadded_Float3_1D() { 320 Random random = new Random(0x172d8ab9); 321 int width = random.nextInt(512); 322 int arr_len = width * 3; 323 324 float[] inArray = new float[arr_len]; 325 float[] outArray = new float[arr_len]; 326 327 for (int i = 0; i < arr_len; i++) { 328 inArray[i] = random.nextFloat(); 329 } 330 331 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); 332 typeBuilder.setX(width); 333 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 334 alloc.setAutoPadding(true); 335 alloc.copyFrom(inArray); 336 alloc.copyTo(outArray); 337 338 boolean result = true; 339 for (int i = 0; i < arr_len; i++) { 340 if (inArray[i] != outArray[i]) { 341 result = false; 342 break; 343 } 344 } 345 assertTrue("test_AllocationPadded_Float3_1D Failed, output array does not match input", 346 result); 347 alloc.destroy(); 348 } 349 public void test_AllocationPadded_Float3_2D() { 350 Random random = new Random(0x172d8ab9); 351 int width = random.nextInt(128); 352 int height = random.nextInt(128); 353 int arr_len = width * height * 3; 354 355 float[] inArray = new float[arr_len]; 356 float[] outArray = new float[arr_len]; 357 358 for (int i = 0; i < arr_len; i++) { 359 inArray[i] = random.nextFloat(); 360 } 361 362 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); 363 typeBuilder.setX(width).setY(height); 364 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 365 alloc.setAutoPadding(true); 366 alloc.copyFrom(inArray); 367 alloc.copyTo(outArray); 368 369 boolean result = true; 370 for (int i = 0; i < arr_len; i++) { 371 if (inArray[i] != outArray[i]) { 372 result = false; 373 break; 374 } 375 } 376 assertTrue("test_AllocationPadded_Float3_2D Failed, output array does not match input", 377 result); 378 alloc.destroy(); 379 } 380 public void test_AllocationPadded_Float3_3D() { 381 Random random = new Random(0x172d8ab9); 382 int w = random.nextInt(32); 383 int h = random.nextInt(32); 384 int d = random.nextInt(32); 385 int arr_len = w * d * h * 3; 386 387 float[] inArray = new float[arr_len]; 388 float[] outArray = new float[arr_len]; 389 390 for (int i = 0; i < arr_len; i++) { 391 inArray[i] = random.nextFloat(); 392 } 393 394 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); 395 typeBuilder.setX(w).setY(h).setZ(d); 396 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 397 alloc.setAutoPadding(true); 398 alloc.copyFrom(inArray); 399 alloc.copyTo(outArray); 400 401 boolean result = true; 402 for (int i = 0; i < arr_len; i++) { 403 if (inArray[i] != outArray[i]) { 404 result = false; 405 break; 406 } 407 } 408 assertTrue("test_AllocationPadded_Float3_3D Failed, output array does not match input", 409 result); 410 alloc.destroy(); 411 } 412 413 public void test_AllocationPadded_Double3_1D() { 414 Random random = new Random(0x172d8ab9); 415 int width = random.nextInt(512); 416 int arr_len = width * 3; 417 418 double[] inArray = new double[arr_len]; 419 double[] outArray = new double[arr_len]; 420 421 for (int i = 0; i < arr_len; i++) { 422 inArray[i] = (double)random.nextFloat(); 423 } 424 425 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F64_3(mRS)); 426 typeBuilder.setX(width); 427 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 428 alloc.setAutoPadding(true); 429 alloc.copyFrom(inArray); 430 alloc.copyTo(outArray); 431 432 boolean result = true; 433 for (int i = 0; i < arr_len; i++) { 434 if (inArray[i] != outArray[i]) { 435 result = false; 436 break; 437 } 438 } 439 assertTrue("test_AllocationPadded_Double3_1D Failed, output array does not match input", 440 result); 441 alloc.destroy(); 442 } 443 public void test_AllocationPadded_Double3_2D() { 444 Random random = new Random(0x172d8ab9); 445 int width = random.nextInt(128); 446 int height = random.nextInt(128); 447 int arr_len = width * height * 3; 448 449 double[] inArray = new double[arr_len]; 450 double[] outArray = new double[arr_len]; 451 452 for (int i = 0; i < arr_len; i++) { 453 inArray[i] = (double)random.nextFloat(); 454 } 455 456 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F64_3(mRS)); 457 typeBuilder.setX(width).setY(height); 458 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 459 alloc.setAutoPadding(true); 460 alloc.copyFrom(inArray); 461 alloc.copyTo(outArray); 462 463 boolean result = true; 464 for (int i = 0; i < arr_len; i++) { 465 if (inArray[i] != outArray[i]) { 466 result = false; 467 break; 468 } 469 } 470 assertTrue("test_AllocationPadded_Double3_2D Failed, output array does not match input", 471 result); 472 alloc.destroy(); 473 } 474 public void test_AllocationPadded_Double3_3D() { 475 Random random = new Random(0x172d8ab9); 476 int w = random.nextInt(32); 477 int h = random.nextInt(32); 478 int d = random.nextInt(32); 479 int arr_len = w * d * h * 3; 480 481 double[] inArray = new double[arr_len]; 482 double[] outArray = new double[arr_len]; 483 484 for (int i = 0; i < arr_len; i++) { 485 inArray[i] = (double)random.nextFloat(); 486 } 487 488 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F64_3(mRS)); 489 typeBuilder.setX(w).setY(h).setZ(d); 490 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 491 alloc.setAutoPadding(true); 492 alloc.copyFrom(inArray); 493 alloc.copyTo(outArray); 494 495 boolean result = true; 496 for (int i = 0; i < arr_len; i++) { 497 if (inArray[i] != outArray[i]) { 498 result = false; 499 break; 500 } 501 } 502 assertTrue("test_AllocationPadded_Double3_3D Failed, output array does not match input", 503 result); 504 alloc.destroy(); 505 } 506 507 public void test_AllocationPadded_Long3_1D() { 508 Random random = new Random(0x172d8ab9); 509 int width = random.nextInt(512); 510 int arr_len = width * 3; 511 512 long[] inArray = new long[arr_len]; 513 long[] outArray = new long[arr_len]; 514 515 for (int i = 0; i < arr_len; i++) { 516 inArray[i] = random.nextLong(); 517 } 518 519 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); 520 typeBuilder.setX(width); 521 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 522 alloc.setAutoPadding(true); 523 alloc.copyFrom(inArray); 524 alloc.copyTo(outArray); 525 526 boolean result = true; 527 for (int i = 0; i < arr_len; i++) { 528 if (inArray[i] != outArray[i]) { 529 result = false; 530 break; 531 } 532 } 533 assertTrue("test_AllocationPadded_Long3_1D Failed, output array does not match input", 534 result); 535 alloc.destroy(); 536 } 537 538 public void test_AllocationPadded_Long3_2D() { 539 Random random = new Random(0x172d8ab9); 540 int width = random.nextInt(128); 541 int height = random.nextInt(128); 542 int arr_len = width * height * 3; 543 544 long[] inArray = new long[arr_len]; 545 long[] outArray = new long[arr_len]; 546 547 for (int i = 0; i < arr_len; i++) { 548 inArray[i] = random.nextLong(); 549 } 550 551 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); 552 typeBuilder.setX(width).setY(height); 553 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 554 alloc.setAutoPadding(true); 555 alloc.copyFrom(inArray); 556 alloc.copyTo(outArray); 557 558 boolean result = true; 559 for (int i = 0; i < arr_len; i++) { 560 if (inArray[i] != outArray[i]) { 561 result = false; 562 break; 563 } 564 } 565 assertTrue("test_AllocationPadded_Long3_2D Failed, output array does not match input", 566 result); 567 alloc.destroy(); 568 } 569 570 public void test_AllocationPadded_Long3_3D() { 571 Random random = new Random(0x172d8ab9); 572 int w = random.nextInt(32); 573 int h = random.nextInt(32); 574 int d = random.nextInt(32); 575 int arr_len = w * d * h * 3; 576 577 long[] inArray = new long[arr_len]; 578 long[] outArray = new long[arr_len]; 579 580 for (int i = 0; i < arr_len; i++) { 581 inArray[i] = random.nextLong(); 582 } 583 584 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); 585 typeBuilder.setX(w).setY(h).setZ(d); 586 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 587 alloc.setAutoPadding(true); 588 alloc.copyFrom(inArray); 589 alloc.copyTo(outArray); 590 591 boolean result = true; 592 for (int i = 0; i < arr_len; i++) { 593 if (inArray[i] != outArray[i]) { 594 result = false; 595 break; 596 } 597 } 598 assertTrue("test_AllocationPadded_Long3_3D Failed, output array does not match input", 599 result); 600 alloc.destroy(); 601 } 602 603 604 public void test_AllocationPadded_copy1DRangeTo_Byte3() { 605 Random random = new Random(0x172d8ab9); 606 int width = random.nextInt(512); 607 int arr_len = width * 3; 608 609 byte[] inArray = new byte[arr_len]; 610 byte[] outArray = new byte[arr_len]; 611 random.nextBytes(inArray); 612 613 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); 614 typeBuilder.setX(width); 615 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 616 alloc.setAutoPadding(true); 617 int offset = random.nextInt(width); 618 int count = width - offset; 619 alloc.copy1DRangeFrom(offset, count, inArray); 620 alloc.copy1DRangeTo(offset, count, outArray); 621 622 boolean result = true; 623 for (int i = 0; i < count * 3; i++) { 624 if (inArray[i] != outArray[i]) { 625 result = false; 626 break; 627 } 628 } 629 for (int i = count * 3; i < arr_len; i++) { 630 if (outArray[i] != 0) { 631 result = false; 632 break; 633 } 634 } 635 assertTrue("test_AllocationPadded_copy1DRangeTo_Byte3, output array does not match input", 636 result); 637 alloc.destroy(); 638 } 639 640 void test_AllocationPadded_copy1DRangeTo_Short3_Helper(Element element) { 641 Random random = new Random(0x172d8ab9); 642 int width = random.nextInt(512); 643 int arr_len = width * 3; 644 645 short[] inArray = new short[arr_len]; 646 short[] outArray = new short[arr_len]; 647 648 for (int i = 0; i < arr_len; i++) { 649 inArray[i] = (short)random.nextInt(); 650 } 651 652 Type.Builder typeBuilder = new Type.Builder(mRS, element); 653 typeBuilder.setX(width); 654 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 655 alloc.setAutoPadding(true); 656 int offset = random.nextInt(width); 657 int count = width - offset; 658 alloc.copy1DRangeFrom(offset, count, inArray); 659 alloc.copy1DRangeTo(offset, count, outArray); 660 661 boolean result = true; 662 for (int i = 0; i < count * 3; i++) { 663 if (inArray[i] != outArray[i]) { 664 result = false; 665 break; 666 } 667 } 668 for (int i = count * 3; i < arr_len; i++) { 669 if (outArray[i] != 0) { 670 result = false; 671 break; 672 } 673 } 674 assertTrue("test_AllocationPadded_copy1DRangeTo_Short3_Helper Failed, output array does not match input", 675 result); 676 alloc.destroy(); 677 } 678 679 public void test_AllocationPadded_copy1DRangeTo_Short3() { 680 test_AllocationPadded_copy1DRangeTo_Short3_Helper(Element.I16_3(mRS)); 681 test_AllocationPadded_copy1DRangeTo_Short3_Helper(Element.F16_3(mRS)); 682 } 683 684 public void test_AllocationPadded_copy1DRangeTo_Int3() { 685 Random random = new Random(0x172d8ab9); 686 int width = random.nextInt(512); 687 int arr_len = width * 3; 688 689 int[] inArray = new int[arr_len]; 690 int[] outArray = new int[arr_len]; 691 692 for (int i = 0; i < arr_len; i++) { 693 inArray[i] = random.nextInt(); 694 } 695 696 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); 697 typeBuilder.setX(width); 698 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 699 alloc.setAutoPadding(true); 700 int offset = random.nextInt(width); 701 int count = width - offset; 702 alloc.copy1DRangeFrom(offset, count, inArray); 703 alloc.copy1DRangeTo(offset, count, outArray); 704 705 boolean result = true; 706 for (int i = 0; i < count * 3; i++) { 707 if (inArray[i] != outArray[i]) { 708 result = false; 709 break; 710 } 711 } 712 for (int i = count * 3; i < arr_len; i++) { 713 if (outArray[i] != 0) { 714 result = false; 715 break; 716 } 717 } 718 assertTrue("test_AllocationPadded_copy1DRangeTo_Int3 Failed, output array does not match input", 719 result); 720 alloc.destroy(); 721 } 722 723 public void test_AllocationPadded_copy1DRangeTo_Float3() { 724 Random random = new Random(0x172d8ab9); 725 int width = random.nextInt(512); 726 int arr_len = width * 3; 727 728 float[] inArray = new float[arr_len]; 729 float[] outArray = new float[arr_len]; 730 731 for (int i = 0; i < arr_len; i++) { 732 inArray[i] = random.nextFloat(); 733 } 734 735 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); 736 typeBuilder.setX(width); 737 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 738 alloc.setAutoPadding(true); 739 int offset = random.nextInt(width); 740 int count = width - offset; 741 alloc.copy1DRangeFrom(offset, count, inArray); 742 alloc.copy1DRangeTo(offset, count, outArray); 743 744 boolean result = true; 745 for (int i = 0; i < count * 3; i++) { 746 if (inArray[i] != outArray[i]) { 747 result = false; 748 break; 749 } 750 } 751 for (int i = count * 3; i < arr_len; i++) { 752 if (outArray[i] != 0f) { 753 result = false; 754 break; 755 } 756 } 757 assertTrue("test_AllocationPadded_copy1DRangeTo_Float3 Failed, output array does not match input", 758 result); 759 alloc.destroy(); 760 } 761 762 public void test_AllocationPadded_copy1DRangeTo_Long3() { 763 Random random = new Random(0x172d8ab9); 764 int width = random.nextInt(512); 765 int arr_len = width * 3; 766 767 long[] inArray = new long[arr_len]; 768 long[] outArray = new long[arr_len]; 769 770 for (int i = 0; i < arr_len; i++) { 771 inArray[i] = random.nextLong(); 772 } 773 774 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); 775 typeBuilder.setX(width); 776 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 777 alloc.setAutoPadding(true); 778 int offset = random.nextInt(width); 779 int count = width - offset; 780 alloc.copy1DRangeFrom(offset, count, inArray); 781 alloc.copy1DRangeTo(offset, count, outArray); 782 783 boolean result = true; 784 for (int i = 0; i < count * 3; i++) { 785 if (inArray[i] != outArray[i]) { 786 result = false; 787 break; 788 } 789 } 790 for (int i = count * 3; i < arr_len; i++) { 791 if (outArray[i] != 0) { 792 result = false; 793 break; 794 } 795 } 796 assertTrue("test_AllocationPadded_copy1DRangeTo_Long3 Failed, output array does not match input", 797 result); 798 alloc.destroy(); 799 } 800 801 public void test_AllocationPadded_copy2DRangeTo_Byte3() { 802 Random random = new Random(0x172d8ab9); 803 int width = random.nextInt(128); 804 int height = random.nextInt(128); 805 int xoff = random.nextInt(width); 806 int yoff = random.nextInt(height); 807 int xcount = width - xoff; 808 int ycount = height - yoff; 809 int arr_len = xcount * ycount * 3; 810 811 byte[] inArray = new byte[arr_len]; 812 byte[] outArray = new byte[arr_len]; 813 random.nextBytes(inArray); 814 815 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); 816 typeBuilder.setX(width).setY(height); 817 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 818 alloc.setAutoPadding(true); 819 alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); 820 alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); 821 822 boolean result = true; 823 for (int i = 0; i < arr_len; i++) { 824 if (inArray[i] != outArray[i]) { 825 result = false; 826 break; 827 } 828 } 829 assertTrue("test_AllocationPadded_copy2DRangeTo_Byte3 Failed, output array does not match input", 830 result); 831 alloc.destroy(); 832 } 833 834 void test_AllocationPadded_copy2DRangeTo_Short3_Helper(Element element) { 835 Random random = new Random(0x172d8ab9); 836 int width = random.nextInt(128); 837 int height = random.nextInt(128); 838 int xoff = random.nextInt(width); 839 int yoff = random.nextInt(height); 840 int xcount = width - xoff; 841 int ycount = height - yoff; 842 int arr_len = xcount * ycount * 3; 843 844 short[] inArray = new short[arr_len]; 845 short[] outArray = new short[arr_len]; 846 847 for (int i = 0; i < arr_len; i++) { 848 inArray[i] = (short)random.nextInt(); 849 } 850 851 Type.Builder typeBuilder = new Type.Builder(mRS, element); 852 typeBuilder.setX(width).setY(height); 853 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 854 alloc.setAutoPadding(true); 855 alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); 856 alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); 857 858 boolean result = true; 859 for (int i = 0; i < arr_len; i++) { 860 if (inArray[i] != outArray[i]) { 861 result = false; 862 break; 863 } 864 } 865 assertTrue("test_AllocationPadded_copy2DRangeTo_Short3_Helper Failed, output array does not match input", 866 result); 867 alloc.destroy(); 868 } 869 870 public void test_AllocationPadded_copy2DRangeTo_Short3() { 871 test_AllocationPadded_copy2DRangeTo_Short3_Helper(Element.I16_3(mRS)); 872 test_AllocationPadded_copy2DRangeTo_Short3_Helper(Element.F16_3(mRS)); 873 } 874 875 public void test_AllocationPadded_copy2DRangeTo_Int3() { 876 Random random = new Random(0x172d8ab9); 877 int width = random.nextInt(128); 878 int height = random.nextInt(128); 879 int xoff = random.nextInt(width); 880 int yoff = random.nextInt(height); 881 int xcount = width - xoff; 882 int ycount = height - yoff; 883 int arr_len = xcount * ycount * 3; 884 885 int[] inArray = new int[arr_len]; 886 int[] outArray = new int[arr_len]; 887 888 for (int i = 0; i < arr_len; i++) { 889 inArray[i] = random.nextInt(); 890 } 891 892 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); 893 typeBuilder.setX(width).setY(height); 894 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 895 alloc.setAutoPadding(true); 896 alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); 897 alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); 898 899 boolean result = true; 900 for (int i = 0; i < arr_len; i++) { 901 if (inArray[i] != outArray[i]) { 902 result = false; 903 break; 904 } 905 } 906 assertTrue("test_AllocationPadded_copy2DRangeTo_Int3 Failed, output array does not match input", 907 result); 908 alloc.destroy(); 909 } 910 911 public void test_AllocationPadded_copy2DRangeTo_Float3() { 912 Random random = new Random(0x172d8ab9); 913 int width = random.nextInt(128); 914 int height = random.nextInt(128); 915 int xoff = random.nextInt(width); 916 int yoff = random.nextInt(height); 917 int xcount = width - xoff; 918 int ycount = height - yoff; 919 int arr_len = xcount * ycount * 3; 920 921 float[] inArray = new float[arr_len]; 922 float[] outArray = new float[arr_len]; 923 924 for (int i = 0; i < arr_len; i++) { 925 inArray[i] = random.nextFloat(); 926 } 927 928 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); 929 typeBuilder.setX(width).setY(height); 930 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 931 alloc.setAutoPadding(true); 932 alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); 933 alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); 934 935 boolean result = true; 936 for (int i = 0; i < arr_len; i++) { 937 if (inArray[i] != outArray[i]) { 938 result = false; 939 break; 940 } 941 } 942 assertTrue("test_AllocationPadded_copy2DRangeTo_Float3 Failed, output array does not match input", 943 result); 944 alloc.destroy(); 945 } 946 947 public void test_AllocationPadded_copy2DRangeTo_Long3() { 948 Random random = new Random(0x172d8ab9); 949 int width = random.nextInt(128); 950 int height = random.nextInt(128); 951 int xoff = random.nextInt(width); 952 int yoff = random.nextInt(height); 953 int xcount = width - xoff; 954 int ycount = height - yoff; 955 int arr_len = xcount * ycount * 3; 956 957 long[] inArray = new long[arr_len]; 958 long[] outArray = new long[arr_len]; 959 960 for (int i = 0; i < arr_len; i++) { 961 inArray[i] = random.nextLong(); 962 } 963 964 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); 965 typeBuilder.setX(width).setY(height); 966 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 967 alloc.setAutoPadding(true); 968 alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); 969 alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); 970 971 boolean result = true; 972 for (int i = 0; i < arr_len; i++) { 973 if (inArray[i] != outArray[i]) { 974 result = false; 975 break; 976 } 977 } 978 assertTrue("test_AllocationPadded_copy2DRangeTo_Long3 Failed, output array does not match input", 979 result); 980 alloc.destroy(); 981 } 982 983 984 public void test_AllocationPadded_copy1DRangeToUnchecked_Byte3() { 985 Random random = new Random(0x172d8ab9); 986 int width = random.nextInt(512); 987 int arr_len = width * 3; 988 989 byte[] inArray = new byte[arr_len]; 990 byte[] outArray = new byte[arr_len]; 991 random.nextBytes(inArray); 992 993 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8_3(mRS)); 994 typeBuilder.setX(width); 995 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 996 alloc.setAutoPadding(true); 997 int offset = random.nextInt(width); 998 int count = width - offset; 999 alloc.copy1DRangeFrom(offset, count, inArray); 1000 alloc.copy1DRangeToUnchecked(offset, count, outArray); 1001 1002 boolean result = true; 1003 for (int i = 0; i < count * 3; i++) { 1004 if (inArray[i] != outArray[i]) { 1005 result = false; 1006 break; 1007 } 1008 } 1009 for (int i = count * 3; i < arr_len; i++) { 1010 if (outArray[i] != 0) { 1011 result = false; 1012 break; 1013 } 1014 } 1015 assertTrue("test_AllocationPadded_copy1DRangeToUnchecked_Byte3 Failed, output array does not match input", 1016 result); 1017 alloc.destroy(); 1018 } 1019 1020 void test_AllocationPadded_copy1DRangeToUnchecked_Short3_Helper(Element element) { 1021 Random random = new Random(0x172d8ab9); 1022 int width = random.nextInt(512); 1023 int arr_len = width * 3; 1024 1025 short[] inArray = new short[arr_len]; 1026 short[] outArray = new short[arr_len]; 1027 1028 for (int i = 0; i < arr_len; i++) { 1029 inArray[i] = (short)random.nextInt(); 1030 } 1031 1032 Type.Builder typeBuilder = new Type.Builder(mRS, element); 1033 typeBuilder.setX(width); 1034 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 1035 alloc.setAutoPadding(true); 1036 int offset = random.nextInt(width); 1037 int count = width - offset; 1038 alloc.copy1DRangeFrom(offset, count, inArray); 1039 alloc.copy1DRangeToUnchecked(offset, count, outArray); 1040 1041 boolean result = true; 1042 for (int i = 0; i < count * 3; i++) { 1043 if (inArray[i] != outArray[i]) { 1044 result = false; 1045 break; 1046 } 1047 } 1048 for (int i = count * 3; i < arr_len; i++) { 1049 if (outArray[i] != 0) { 1050 result = false; 1051 break; 1052 } 1053 } 1054 assertTrue("test_AllocationPadded_copy1DRangeToUnchecked_Short3_Helper Failed, output array does not match input", 1055 result); 1056 alloc.destroy(); 1057 } 1058 1059 public void test_AllocationPadded_copy1DRangeToUnchecked_Short3() { 1060 test_AllocationPadded_copy1DRangeToUnchecked_Short3_Helper(Element.I16_3(mRS)); 1061 test_AllocationPadded_copy1DRangeToUnchecked_Short3_Helper(Element.F16_3(mRS)); 1062 } 1063 1064 public void test_AllocationPadded_copy1DRangeToUnchecked_Int3() { 1065 Random random = new Random(0x172d8ab9); 1066 int width = random.nextInt(512); 1067 int arr_len = width * 3; 1068 1069 int[] inArray = new int[arr_len]; 1070 int[] outArray = new int[arr_len]; 1071 1072 for (int i = 0; i < arr_len; i++) { 1073 inArray[i] = random.nextInt(); 1074 } 1075 1076 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32_3(mRS)); 1077 typeBuilder.setX(width); 1078 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 1079 alloc.setAutoPadding(true); 1080 int offset = random.nextInt(width); 1081 int count = width - offset; 1082 alloc.copy1DRangeFrom(offset, count, inArray); 1083 alloc.copy1DRangeToUnchecked(offset, count, outArray); 1084 1085 boolean result = true; 1086 for (int i = 0; i < count * 3; i++) { 1087 if (inArray[i] != outArray[i]) { 1088 result = false; 1089 break; 1090 } 1091 } 1092 for (int i = count * 3; i < arr_len; i++) { 1093 if (outArray[i] != 0) { 1094 result = false; 1095 break; 1096 } 1097 } 1098 assertTrue("test_AllocationPadded_copy1DRangeToUnchecked_Int3 Failed, output array does not match input", 1099 result); 1100 alloc.destroy(); 1101 } 1102 1103 public void test_AllocationPadded_copy1DRangeToUnchecked_Float3() { 1104 Random random = new Random(0x172d8ab9); 1105 int width = random.nextInt(512); 1106 int arr_len = width * 3; 1107 1108 float[] inArray = new float[arr_len]; 1109 float[] outArray = new float[arr_len]; 1110 1111 for (int i = 0; i < arr_len; i++) { 1112 inArray[i] = random.nextFloat(); 1113 } 1114 1115 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32_3(mRS)); 1116 typeBuilder.setX(width); 1117 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 1118 alloc.setAutoPadding(true); 1119 int offset = random.nextInt(width); 1120 int count = width - offset; 1121 alloc.copy1DRangeFrom(offset, count, inArray); 1122 alloc.copy1DRangeToUnchecked(offset, count, outArray); 1123 1124 boolean result = true; 1125 for (int i = 0; i < count * 3; i++) { 1126 if (inArray[i] != outArray[i]) { 1127 result = false; 1128 break; 1129 } 1130 } 1131 for (int i = count * 3; i < arr_len; i++) { 1132 if (outArray[i] != 0f) { 1133 result = false; 1134 break; 1135 } 1136 } 1137 assertTrue("test_AllocationPadded_copy1DRangeToUnchecked_Float3 Failed, output array does not match input", 1138 result); 1139 alloc.destroy(); 1140 } 1141 1142 public void test_AllocationPadded_copy1DRangeToUnchecked_Long3() { 1143 Random random = new Random(0x172d8ab9); 1144 int width = random.nextInt(512); 1145 int arr_len = width * 3; 1146 1147 long[] inArray = new long[arr_len]; 1148 long[] outArray = new long[arr_len]; 1149 1150 for (int i = 0; i < arr_len; i++) { 1151 inArray[i] = random.nextLong(); 1152 } 1153 1154 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64_3(mRS)); 1155 typeBuilder.setX(width); 1156 Allocation alloc = Allocation.createTyped(mRS, typeBuilder.create()); 1157 alloc.setAutoPadding(true); 1158 int offset = random.nextInt(width); 1159 int count = width - offset; 1160 alloc.copy1DRangeFrom(offset, count, inArray); 1161 alloc.copy1DRangeToUnchecked(offset, count, outArray); 1162 1163 boolean result = true; 1164 for (int i = 0; i < count * 3; i++) { 1165 if (inArray[i] != outArray[i]) { 1166 result = false; 1167 break; 1168 } 1169 } 1170 for (int i = count * 3; i < arr_len; i++) { 1171 if (outArray[i] != 0) { 1172 result = false; 1173 break; 1174 } 1175 } 1176 assertTrue("test_AllocationPadded_copy1DRangeToUnchecked_Long3 Failed, output array does not match input", 1177 result); 1178 alloc.destroy(); 1179 } 1180 } 1181