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 AllocationCopyToTest extends RSBaseCompute { 25 private Allocation alloc; 26 27 @Override 28 protected void tearDown() throws Exception { 29 if (alloc != null) { 30 alloc.destroy(); 31 } 32 super.tearDown(); 33 } 34 35 public void test_Allocationcopy1DRangeTo_Byte() { 36 Random random = new Random(0x172d8ab9); 37 int width = random.nextInt(512); 38 int arr_len = width; 39 40 byte[] inArray = new byte[arr_len]; 41 byte[] outArray = new byte[arr_len]; 42 random.nextBytes(inArray); 43 44 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8(mRS)); 45 typeBuilder.setX(width); 46 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 47 int offset = random.nextInt(arr_len); 48 int count = arr_len - offset; 49 alloc.copy1DRangeFrom(offset, count, inArray); 50 alloc.copy1DRangeTo(offset, count, outArray); 51 52 boolean result = true; 53 for (int i = 0; i < count; i++) { 54 if (inArray[i] != outArray[i]) { 55 result = false; 56 break; 57 } 58 } 59 for (int i = count; i < arr_len; i++) { 60 if (outArray[i] != 0) { 61 result = false; 62 break; 63 } 64 } 65 assertTrue("test_Allocationcopy1DRangeTo_Byte failed, output array does not match input", 66 result); 67 } 68 69 void test_Allocationcopy1DRangeTo_Short_Helper(Element element, boolean testTyped) { 70 Random random = new Random(0x172d8ab9); 71 int width = random.nextInt(512); 72 int arr_len = width; 73 74 short[] inArray = new short[arr_len]; 75 short[] outArray = new short[arr_len]; 76 77 for (int i = 0; i < arr_len; i++) { 78 inArray[i] = (short)random.nextInt(); 79 } 80 81 Type.Builder typeBuilder = new Type.Builder(mRS, element); 82 typeBuilder.setX(width); 83 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 84 int offset = random.nextInt(arr_len); 85 int count = arr_len - offset; 86 if (testTyped) { 87 alloc.copy1DRangeFrom(offset, count, inArray); 88 alloc.copy1DRangeTo(offset, count, outArray); 89 } else { 90 alloc.copy1DRangeFrom(offset, count, (Object) inArray); 91 alloc.copy1DRangeTo(offset, count, (Object) outArray); 92 } 93 94 boolean result = true; 95 for (int i = 0; i < count; i++) { 96 if (inArray[i] != outArray[i]) { 97 result = false; 98 break; 99 } 100 } 101 for (int i = count; i < arr_len; i++) { 102 if (outArray[i] != 0) { 103 result = false; 104 break; 105 } 106 } 107 assertTrue("test_Allocationcopy1DRangeTo_Short_Helper failed, output array does not match input", 108 result); 109 } 110 111 public void test_Allocationcopy1DRangeTo_Short() { 112 test_Allocationcopy1DRangeTo_Short_Helper(Element.I16(mRS), true); 113 test_Allocationcopy1DRangeTo_Short_Helper(Element.F16(mRS), true); 114 test_Allocationcopy1DRangeTo_Short_Helper(Element.F16(mRS), false); 115 } 116 117 public void test_Allocationcopy1DRangeTo_Int() { 118 Random random = new Random(0x172d8ab9); 119 int width = random.nextInt(512); 120 int arr_len = width; 121 122 int[] inArray = new int[arr_len]; 123 int[] outArray = new int[arr_len]; 124 125 for (int i = 0; i < arr_len; i++) { 126 inArray[i] = random.nextInt(); 127 } 128 129 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32(mRS)); 130 typeBuilder.setX(width); 131 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 132 int offset = random.nextInt(arr_len); 133 int count = arr_len - offset; 134 alloc.copy1DRangeFrom(offset, count, inArray); 135 alloc.copy1DRangeTo(offset, count, outArray); 136 137 boolean result = true; 138 for (int i = 0; i < count; i++) { 139 if (inArray[i] != outArray[i]) { 140 result = false; 141 break; 142 } 143 } 144 for (int i = count; i < arr_len; i++) { 145 if (outArray[i] != 0) { 146 result = false; 147 break; 148 } 149 } 150 assertTrue("test_Allocationcopy1DRangeTo_Int failed, output array does not match input", 151 result); 152 } 153 154 public void test_Allocationcopy1DRangeTo_Float() { 155 Random random = new Random(0x172d8ab9); 156 int width = random.nextInt(512); 157 int arr_len = width; 158 159 float[] inArray = new float[arr_len]; 160 float[] outArray = new float[arr_len]; 161 162 for (int i = 0; i < arr_len; i++) { 163 inArray[i] = random.nextFloat(); 164 } 165 166 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32(mRS)); 167 typeBuilder.setX(width); 168 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 169 int offset = random.nextInt(arr_len); 170 int count = arr_len - offset; 171 alloc.copy1DRangeFrom(offset, count, inArray); 172 alloc.copy1DRangeTo(offset, count, outArray); 173 174 boolean result = true; 175 for (int i = 0; i < count; i++) { 176 if (inArray[i] != outArray[i]) { 177 result = false; 178 break; 179 } 180 } 181 for (int i = count; i < arr_len; i++) { 182 if (outArray[i] != 0f) { 183 result = false; 184 break; 185 } 186 } 187 assertTrue("test_Allocationcopy1DRangeTo_Float failed, output array does not match input", 188 result); 189 } 190 191 public void test_Allocationcopy1DRangeTo_Long() { 192 Random random = new Random(0x172d8ab9); 193 int width = random.nextInt(512); 194 int arr_len = width; 195 196 long[] inArray = new long[arr_len]; 197 long[] outArray = new long[arr_len]; 198 199 for (int i = 0; i < arr_len; i++) { 200 inArray[i] = random.nextLong(); 201 } 202 203 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64(mRS)); 204 typeBuilder.setX(width); 205 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 206 int offset = random.nextInt(arr_len); 207 int count = arr_len - offset; 208 alloc.copy1DRangeFrom(offset, count, inArray); 209 alloc.copy1DRangeTo(offset, count, outArray); 210 211 boolean result = true; 212 for (int i = 0; i < count; i++) { 213 if (inArray[i] != outArray[i]) { 214 result = false; 215 break; 216 } 217 } 218 for (int i = count; i < arr_len; i++) { 219 if (outArray[i] != 0) { 220 result = false; 221 break; 222 } 223 } 224 assertTrue("test_Allocationcopy1DRangeTo_Long failed, output array does not match input", 225 result); 226 } 227 228 public void test_Allocationcopy2DRangeTo_Byte() { 229 Random random = new Random(0x172d8ab9); 230 int width = random.nextInt(128); 231 int height = random.nextInt(128); 232 int xoff = random.nextInt(width); 233 int yoff = random.nextInt(height); 234 int xcount = width - xoff; 235 int ycount = height - yoff; 236 int arr_len = xcount * ycount; 237 238 byte[] inArray = new byte[arr_len]; 239 byte[] outArray = new byte[arr_len]; 240 random.nextBytes(inArray); 241 242 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8(mRS)); 243 typeBuilder.setX(width).setY(height); 244 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 245 alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); 246 alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); 247 248 boolean result = true; 249 for (int i = 0; i < arr_len; i++) { 250 if (inArray[i] != outArray[i]) { 251 result = false; 252 break; 253 } 254 } 255 assertTrue("test_Allocationcopy2DRangeTo_Byte failed, output array does not match input", 256 result); 257 } 258 259 void test_Allocationcopy2DRangeTo_Short_Helper(Element element, boolean testTyped) { 260 Random random = new Random(0x172d8ab9); 261 int width = random.nextInt(128); 262 int height = random.nextInt(128); 263 int xoff = random.nextInt(width); 264 int yoff = random.nextInt(height); 265 int xcount = width - xoff; 266 int ycount = height - yoff; 267 int arr_len = xcount * ycount; 268 269 short[] inArray = new short[arr_len]; 270 short[] outArray = new short[arr_len]; 271 272 for (int i = 0; i < arr_len; i++) { 273 inArray[i] = (short)random.nextInt(); 274 } 275 276 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I16(mRS)); 277 typeBuilder.setX(width).setY(height); 278 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 279 if (testTyped) { 280 alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); 281 alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); 282 } else { 283 alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, (Object) inArray); 284 alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, (Object) outArray); 285 } 286 287 boolean result = true; 288 for (int i = 0; i < arr_len; i++) { 289 if (inArray[i] != outArray[i]) { 290 result = false; 291 break; 292 } 293 } 294 assertTrue("test_Allocationcopy2DRangeTo_Short_Helper failed, output array does not match input", 295 result); 296 } 297 298 public void test_Allocationcopy2DRangeTo_Short() { 299 test_Allocationcopy2DRangeTo_Short_Helper(Element.I16(mRS), true); 300 test_Allocationcopy2DRangeTo_Short_Helper(Element.F16(mRS), true); 301 test_Allocationcopy2DRangeTo_Short_Helper(Element.F16(mRS), false); 302 } 303 304 public void test_Allocationcopy2DRangeTo_Int() { 305 Random random = new Random(0x172d8ab9); 306 int width = random.nextInt(128); 307 int height = random.nextInt(128); 308 int xoff = random.nextInt(width); 309 int yoff = random.nextInt(height); 310 int xcount = width - xoff; 311 int ycount = height - yoff; 312 int arr_len = xcount * ycount; 313 314 int[] inArray = new int[arr_len]; 315 int[] outArray = new int[arr_len]; 316 317 for (int i = 0; i < arr_len; i++) { 318 inArray[i] = random.nextInt(); 319 } 320 321 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32(mRS)); 322 typeBuilder.setX(width).setY(height); 323 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 324 alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); 325 alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); 326 327 boolean result = true; 328 for (int i = 0; i < arr_len; i++) { 329 if (inArray[i] != outArray[i]) { 330 result = false; 331 break; 332 } 333 } 334 assertTrue("test_Allocationcopy2DRangeTo_Int failed, output array does not match input", 335 result); 336 } 337 338 public void test_Allocationcopy2DRangeTo_Float() { 339 Random random = new Random(0x172d8ab9); 340 int width = random.nextInt(128); 341 int height = random.nextInt(128); 342 int xoff = random.nextInt(width); 343 int yoff = random.nextInt(height); 344 int xcount = width - xoff; 345 int ycount = height - yoff; 346 int arr_len = xcount * ycount; 347 348 float[] inArray = new float[arr_len]; 349 float[] outArray = new float[arr_len]; 350 351 for (int i = 0; i < arr_len; i++) { 352 inArray[i] = random.nextFloat(); 353 } 354 355 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32(mRS)); 356 typeBuilder.setX(width).setY(height); 357 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 358 alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); 359 alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); 360 361 boolean result = true; 362 for (int i = 0; i < arr_len; i++) { 363 if (inArray[i] != outArray[i]) { 364 result = false; 365 break; 366 } 367 } 368 assertTrue("test_Allocationcopy2DRangeTo_Float failed, output array does not match input", 369 result); 370 } 371 372 public void test_Allocationcopy2DRangeTo_Long() { 373 Random random = new Random(0x172d8ab9); 374 int width = random.nextInt(128); 375 int height = random.nextInt(128); 376 int xoff = random.nextInt(width); 377 int yoff = random.nextInt(height); 378 int xcount = width - xoff; 379 int ycount = height - yoff; 380 int arr_len = xcount * ycount; 381 382 long[] inArray = new long[arr_len]; 383 long[] outArray = new long[arr_len]; 384 385 for (int i = 0; i < arr_len; i++) { 386 inArray[i] = random.nextLong(); 387 } 388 389 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64(mRS)); 390 typeBuilder.setX(width).setY(height); 391 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 392 alloc.copy2DRangeFrom(xoff, yoff, xcount, ycount, inArray); 393 alloc.copy2DRangeTo(xoff, yoff, xcount, ycount, outArray); 394 395 boolean result = true; 396 for (int i = 0; i < arr_len; i++) { 397 if (inArray[i] != outArray[i]) { 398 result = false; 399 break; 400 } 401 } 402 assertTrue("test_Allocationcopy2DRangeTo_Long failed, output array does not match input", 403 result); 404 } 405 406 public void test_Allocationcopy3DRangeTo_Byte() { 407 Random random = new Random(0x172d8ab9); 408 int width = random.nextInt(64); 409 int height = random.nextInt(64); 410 int depth = random.nextInt(64); 411 412 int xoff = random.nextInt(width); 413 int yoff = random.nextInt(height); 414 int zoff = random.nextInt(height); 415 416 int xcount = width - xoff; 417 int ycount = height - yoff; 418 int zcount = depth - zoff; 419 int arr_len = xcount * ycount * zcount; 420 421 byte[] inArray = new byte[arr_len]; 422 byte[] outArray = new byte[arr_len]; 423 random.nextBytes(inArray); 424 425 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8(mRS)); 426 typeBuilder.setX(width).setY(height).setZ(depth); 427 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 428 alloc.copy3DRangeFrom(xoff, yoff, zoff, xcount, ycount, zcount, (Object)inArray); 429 alloc.copy3DRangeTo(xoff, yoff, zoff, xcount, ycount, zcount, (Object)outArray); 430 431 boolean result = true; 432 for (int i = 0; i < arr_len; i++) { 433 if (inArray[i] != outArray[i]) { 434 result = false; 435 android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); 436 break; 437 } 438 } 439 assertTrue("test_Allocationcopy3DRangeTo_Byte failed, output array does not match input", 440 result); 441 } 442 443 void test_Allocationcopy3DRangeTo_Short_Helper(Element element) { 444 Random random = new Random(0x172d8ab9); 445 int width = random.nextInt(64); 446 int height = random.nextInt(64); 447 int depth = random.nextInt(64); 448 449 int xoff = random.nextInt(width); 450 int yoff = random.nextInt(height); 451 int zoff = random.nextInt(height); 452 453 int xcount = width - xoff; 454 int ycount = height - yoff; 455 int zcount = depth - zoff; 456 int arr_len = xcount * ycount * zcount; 457 458 short[] inArray = new short[arr_len]; 459 short[] outArray = new short[arr_len]; 460 461 for (int i = 0; i < arr_len; i++) { 462 inArray[i] = (short)random.nextInt(); 463 } 464 465 Type.Builder typeBuilder = new Type.Builder(mRS, element); 466 typeBuilder.setX(width).setY(height).setZ(depth); 467 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 468 alloc.copy3DRangeFrom(xoff, yoff, zoff, xcount, ycount, zcount, (Object)inArray); 469 alloc.copy3DRangeTo(xoff, yoff, zoff, xcount, ycount, zcount, (Object)outArray); 470 471 boolean result = true; 472 for (int i = 0; i < arr_len; i++) { 473 if (inArray[i] != outArray[i]) { 474 result = false; 475 android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); 476 break; 477 } 478 } 479 assertTrue("test_Allocationcopy3DRangeTo_Short_Helper failed, output array does not match input", 480 result); 481 } 482 483 public void test_Allocationcopy3DRangeTo_Short() { 484 test_Allocationcopy3DRangeTo_Short_Helper(Element.I16(mRS)); 485 test_Allocationcopy3DRangeTo_Short_Helper(Element.F16(mRS)); 486 } 487 488 public void test_Allocationcopy3DRangeTo_Int() { 489 Random random = new Random(0x172d8ab9); 490 int width = random.nextInt(64); 491 int height = random.nextInt(64); 492 int depth = random.nextInt(64); 493 494 int xoff = random.nextInt(width); 495 int yoff = random.nextInt(height); 496 int zoff = random.nextInt(height); 497 498 int xcount = width - xoff; 499 int ycount = height - yoff; 500 int zcount = depth - zoff; 501 int arr_len = xcount * ycount * zcount; 502 503 int[] inArray = new int[arr_len]; 504 int[] outArray = new int[arr_len]; 505 506 for (int i = 0; i < arr_len; i++) { 507 inArray[i] = random.nextInt(); 508 } 509 510 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32(mRS)); 511 typeBuilder.setX(width).setY(height).setZ(depth); 512 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 513 alloc.copy3DRangeFrom(xoff, yoff, zoff, xcount, ycount, zcount, (Object)inArray); 514 alloc.copy3DRangeTo(xoff, yoff, zoff, xcount, ycount, zcount, (Object)outArray); 515 516 boolean result = true; 517 for (int i = 0; i < arr_len; i++) { 518 if (inArray[i] != outArray[i]) { 519 result = false; 520 android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); 521 break; 522 } 523 } 524 assertTrue("test_Allocationcopy3DRangeTo_Int failed, output array does not match input", 525 result); 526 } 527 528 public void test_Allocationcopy3DRangeTo_Float() { 529 Random random = new Random(0x172d8ab9); 530 int width = random.nextInt(64); 531 int height = random.nextInt(64); 532 int depth = random.nextInt(64); 533 534 int xoff = random.nextInt(width); 535 int yoff = random.nextInt(height); 536 int zoff = random.nextInt(height); 537 538 int xcount = width - xoff; 539 int ycount = height - yoff; 540 int zcount = depth - zoff; 541 int arr_len = xcount * ycount * zcount; 542 543 float[] inArray = new float[arr_len]; 544 float[] outArray = new float[arr_len]; 545 546 for (int i = 0; i < arr_len; i++) { 547 inArray[i] = random.nextFloat(); 548 } 549 550 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32(mRS)); 551 typeBuilder.setX(width).setY(height).setZ(depth); 552 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 553 alloc.copy3DRangeFrom(xoff, yoff, zoff, xcount, ycount, zcount, (Object)inArray); 554 alloc.copy3DRangeTo(xoff, yoff, zoff, xcount, ycount, zcount, (Object)outArray); 555 556 boolean result = true; 557 for (int i = 0; i < arr_len; i++) { 558 if (inArray[i] != outArray[i]) { 559 result = false; 560 android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); 561 break; 562 } 563 } 564 assertTrue("test_Allocationcopy3DRangeTo_Float failed, output array does not match input", 565 result); 566 } 567 568 public void test_Allocationcopy3DRangeTo_Long() { 569 Random random = new Random(0x172d8ab9); 570 int width = random.nextInt(64); 571 int height = random.nextInt(64); 572 int depth = random.nextInt(64); 573 574 int xoff = random.nextInt(width); 575 int yoff = random.nextInt(height); 576 int zoff = random.nextInt(height); 577 578 int xcount = width - xoff; 579 int ycount = height - yoff; 580 int zcount = depth - zoff; 581 int arr_len = xcount * ycount * zcount; 582 583 long[] inArray = new long[arr_len]; 584 long[] outArray = new long[arr_len]; 585 586 for (int i = 0; i < arr_len; i++) { 587 inArray[i] = random.nextLong(); 588 } 589 590 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64(mRS)); 591 typeBuilder.setX(width).setY(height).setZ(depth); 592 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 593 alloc.copy3DRangeFrom(xoff, yoff, zoff, xcount, ycount, zcount, (Object)inArray); 594 alloc.copy3DRangeTo(xoff, yoff, zoff, xcount, ycount, zcount, (Object)outArray); 595 596 boolean result = true; 597 for (int i = 0; i < arr_len; i++) { 598 if (inArray[i] != outArray[i]) { 599 result = false; 600 android.util.Log.v("Allocation CopyTo Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); 601 break; 602 } 603 } 604 assertTrue("test_Allocationcopy3DRangeTo_Long failed, output array does not match input", 605 result); 606 } 607 608 public void test_AllocationCopy3DRangeFrom_Alloc() { 609 Random random = new Random(0x172d8ab9); 610 int width = random.nextInt(64); 611 int height = random.nextInt(64); 612 int depth = random.nextInt(64); 613 614 int xoff = random.nextInt(width); 615 int yoff = random.nextInt(height); 616 int zoff = random.nextInt(height); 617 618 int xcount = width - xoff; 619 int ycount = height - yoff; 620 int zcount = depth - zoff; 621 int arr_len = xcount * ycount * zcount; 622 623 long[] inArray = new long[arr_len]; 624 long[] outArray = new long[arr_len]; 625 626 for (int i = 0; i < arr_len; i++) { 627 inArray[i] = random.nextLong(); 628 } 629 630 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64(mRS)); 631 typeBuilder.setX(width).setY(height).setZ(depth); 632 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 633 Allocation allocRef = Allocation.createTyped(mRS, typeBuilder.create()); 634 635 allocRef.copy3DRangeFrom(xoff, yoff, zoff, xcount, ycount, zcount, (Object)inArray); 636 alloc.copy3DRangeFrom(xoff, yoff, zoff, xcount, ycount, zcount, allocRef, xoff, yoff, zoff); 637 alloc.copy3DRangeTo(xoff, yoff, zoff, xcount, ycount, zcount, (Object)outArray); 638 639 boolean result = true; 640 for (int i = 0; i < arr_len; i++) { 641 if (inArray[i] != outArray[i]) { 642 result = false; 643 android.util.Log.v("Allocation Copy3DRangeFrom (alloc) Test", "Failed: " + i + " " + inArray[i] + " " + outArray[i]); 644 break; 645 } 646 } 647 assertTrue("test_AllocationCopy3DRangeFrom_Alloc failed, output array does not match input", 648 result); 649 } 650 651 public void test_Allocationcopy1DRangeToUnchecked_Byte() { 652 Random random = new Random(0x172d8ab9); 653 int width = random.nextInt(512); 654 int arr_len = width; 655 656 byte[] inArray = new byte[arr_len]; 657 byte[] outArray = new byte[arr_len]; 658 random.nextBytes(inArray); 659 660 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I8(mRS)); 661 typeBuilder.setX(width); 662 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 663 int offset = random.nextInt(arr_len); 664 int count = arr_len - offset; 665 alloc.copy1DRangeFrom(offset, count, inArray); 666 alloc.copy1DRangeToUnchecked(offset, count, outArray); 667 668 boolean result = true; 669 for (int i = 0; i < count; i++) { 670 if (inArray[i] != outArray[i]) { 671 result = false; 672 break; 673 } 674 } 675 for (int i = count; i < arr_len; i++) { 676 if (outArray[i] != 0) { 677 result = false; 678 break; 679 } 680 } 681 assertTrue("test_Allocationcopy1DRangeToUnchecked_Byte failed, output array does not match input", 682 result); 683 } 684 685 void test_Allocationcopy1DRangeToUnchecked_Short_Helper(Element element) { 686 Random random = new Random(0x172d8ab9); 687 int width = random.nextInt(512); 688 int arr_len = width; 689 690 short[] inArray = new short[arr_len]; 691 short[] outArray = new short[arr_len]; 692 693 for (int i = 0; i < arr_len; i++) { 694 inArray[i] = (short)random.nextInt(); 695 } 696 697 Type.Builder typeBuilder = new Type.Builder(mRS, element); 698 typeBuilder.setX(width); 699 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 700 int offset = random.nextInt(arr_len); 701 int count = arr_len - offset; 702 alloc.copy1DRangeFrom(offset, count, inArray); 703 alloc.copy1DRangeToUnchecked(offset, count, outArray); 704 705 boolean result = true; 706 for (int i = 0; i < count; i++) { 707 if (inArray[i] != outArray[i]) { 708 result = false; 709 break; 710 } 711 } 712 for (int i = count; i < arr_len; i++) { 713 if (outArray[i] != 0) { 714 result = false; 715 break; 716 } 717 } 718 assertTrue("test_Allocationcopy1DRangeToUnchecked_Short_Helper failed, output array does not match input", 719 result); 720 } 721 722 public void test_Allocationcopy1DRangeToUnchecked_Short() { 723 test_Allocationcopy1DRangeToUnchecked_Short_Helper(Element.I16(mRS)); 724 test_Allocationcopy1DRangeToUnchecked_Short_Helper(Element.F16(mRS)); 725 } 726 727 public void test_Allocationcopy1DRangeToUnchecked_Int() { 728 Random random = new Random(0x172d8ab9); 729 int width = random.nextInt(512); 730 int arr_len = width; 731 732 int[] inArray = new int[arr_len]; 733 int[] outArray = new int[arr_len]; 734 735 for (int i = 0; i < arr_len; i++) { 736 inArray[i] = random.nextInt(); 737 } 738 739 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I32(mRS)); 740 typeBuilder.setX(width); 741 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 742 int offset = random.nextInt(arr_len); 743 int count = arr_len - offset; 744 alloc.copy1DRangeFrom(offset, count, inArray); 745 alloc.copy1DRangeToUnchecked(offset, count, outArray); 746 747 boolean result = true; 748 for (int i = 0; i < count; i++) { 749 if (inArray[i] != outArray[i]) { 750 result = false; 751 break; 752 } 753 } 754 for (int i = count; i < arr_len; i++) { 755 if (outArray[i] != 0) { 756 result = false; 757 break; 758 } 759 } 760 assertTrue("test_Allocationcopy1DRangeToUnchecked_Int Failed, output array does not match input", 761 result); 762 } 763 764 public void test_Allocationcopy1DRangeToUnchecked_Float() { 765 Random random = new Random(0x172d8ab9); 766 int width = random.nextInt(512); 767 int arr_len = width; 768 769 float[] inArray = new float[arr_len]; 770 float[] outArray = new float[arr_len]; 771 772 for (int i = 0; i < arr_len; i++) { 773 inArray[i] = random.nextFloat(); 774 } 775 776 Type.Builder typeBuilder = new Type.Builder(mRS, Element.F32(mRS)); 777 typeBuilder.setX(width); 778 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 779 int offset = random.nextInt(arr_len); 780 int count = arr_len - offset; 781 alloc.copy1DRangeFrom(offset, count, inArray); 782 alloc.copy1DRangeToUnchecked(offset, count, outArray); 783 784 boolean result = true; 785 for (int i = 0; i < count; i++) { 786 if (inArray[i] != outArray[i]) { 787 result = false; 788 break; 789 } 790 } 791 for (int i = count; i < arr_len; i++) { 792 if (outArray[i] != 0f) { 793 result = false; 794 break; 795 } 796 } 797 assertTrue("test_Allocationcopy1DRangeToUnchecked_Float Failed, output array does not match input", 798 result); 799 } 800 801 public void test_Allocationcopy1DRangeToUnchecked_Long() { 802 Random random = new Random(0x172d8ab9); 803 int width = random.nextInt(512); 804 int arr_len = width; 805 806 long[] inArray = new long[arr_len]; 807 long[] outArray = new long[arr_len]; 808 809 for (int i = 0; i < arr_len; i++) { 810 inArray[i] = random.nextLong(); 811 } 812 813 Type.Builder typeBuilder = new Type.Builder(mRS, Element.I64(mRS)); 814 typeBuilder.setX(width); 815 alloc = Allocation.createTyped(mRS, typeBuilder.create()); 816 int offset = random.nextInt(arr_len); 817 int count = arr_len - offset; 818 alloc.copy1DRangeFrom(offset, count, inArray); 819 alloc.copy1DRangeToUnchecked(offset, count, outArray); 820 821 boolean result = true; 822 for (int i = 0; i < count; i++) { 823 if (inArray[i] != outArray[i]) { 824 result = false; 825 break; 826 } 827 } 828 for (int i = count; i < arr_len; i++) { 829 if (outArray[i] != 0) { 830 result = false; 831 break; 832 } 833 } 834 assertTrue("test_Allocationcopy1DRangeToUnchecked_Long Failed, output array does not match input", 835 result); 836 } 837 } 838