| 188 | |
| 189 | |
| 190 | def test_view(): |
| 191 | x = np.arange(56).reshape((7, 8)) |
| 192 | d = da.from_array(cupy.array(x), chunks=(2, 3)) |
| 193 | |
| 194 | result = d.view() |
| 195 | assert type(result._meta) == cupy.ndarray |
| 196 | assert_eq(result, result) # Check that _meta and computed arrays match types |
| 197 | assert_eq(result, x.view(), check_type=False) |
| 198 | |
| 199 | result = d.view("i4") |
| 200 | assert type(result._meta) == cupy.ndarray |
| 201 | assert_eq(result, result) # Check that _meta and computed arrays match types |
| 202 | assert_eq(result, x.view("i4"), check_type=False) |
| 203 | |
| 204 | result = d.view("i2") |
| 205 | assert type(result._meta) == cupy.ndarray |
| 206 | assert_eq(result, result) # Check that _meta and computed arrays match types |
| 207 | assert_eq(result, x.view("i2"), check_type=False) |
| 208 | assert all(isinstance(s, int) for s in d.shape) |
| 209 | |
| 210 | x = np.arange(8, dtype="i1") |
| 211 | d = da.from_array(cupy.array(x), chunks=(4,)) |
| 212 | result = d.view("i4") |
| 213 | assert type(result._meta) == cupy.ndarray |
| 214 | assert_eq(result, result) # Check that _meta and computed arrays match types |
| 215 | assert_eq(x.view("i4"), d.view("i4"), check_type=False) |
| 216 | |
| 217 | with pytest.raises(ValueError): |
| 218 | x = np.arange(8, dtype="i1") |
| 219 | d = da.from_array(cupy.array(x), chunks=(3,)) |
| 220 | d.view("i4") |
| 221 | |
| 222 | with pytest.raises(ValueError): |
| 223 | d.view("i4", order="asdf") |
| 224 | |
| 225 | |
| 226 | def test_view_fortran(): |