|
8 | 8 |
|
9 | 9 | import numpy |
10 | 10 |
|
| 11 | +from nose.tools import assert_raises |
11 | 12 | import pygpu |
12 | 13 | from pygpu.gpuarray import GpuArray, GpuContext, GpuKernel |
13 | 14 |
|
@@ -448,6 +449,32 @@ def reshape(shps, offseted, order1, order2): |
448 | 449 | assert numpy.allclose(outc, numpy.asarray(outg)) |
449 | 450 |
|
450 | 451 |
|
| 452 | +def test_strides(): |
| 453 | + yield strides_, (4, 4), 'c', 1, (4, 4) |
| 454 | + yield strides_, (4, 4), 'c', 1, (4, 16) |
| 455 | + yield strides_, (4, 4), 'c', 1, (16, 4) |
| 456 | + yield strides_, (4, 4), 'c', 1, (16, 8) |
| 457 | + yield strides_, (4, 4), 'c', 1, (16, 0) |
| 458 | + yield strides_, (4, 4), 'c', -1, (-20, 4) |
| 459 | + yield strides_, (4, 4), 'c', -1, (-12, 4) |
| 460 | + |
| 461 | + |
| 462 | +def set_strides(a, newstr): |
| 463 | + a.strides = newstr |
| 464 | + |
| 465 | + |
| 466 | +def strides_(shp, order, sliced, newstr): |
| 467 | + ac, ag = gen_gpuarray(shp, 'float32', sliced=sliced, order=order, ctx=ctx) |
| 468 | + try: |
| 469 | + ac.strides = newstr |
| 470 | + except ValueError: |
| 471 | + assert_raises(ValueError, set_strides, ag, newstr) |
| 472 | + return |
| 473 | + ag.strides = newstr |
| 474 | + check_flags(ag, ac) |
| 475 | + assert numpy.allclose(ac, numpy.asarray(ag)) |
| 476 | + |
| 477 | + |
451 | 478 | def test_transpose(): |
452 | 479 | for shp in [(2, 3), (4, 8, 9), (1, 2, 3, 4)]: |
453 | 480 | for offseted in [True, False]: |
|
0 commit comments