|
301 | 301 | end
|
302 | 302 | end
|
303 | 303 | end
|
| 304 | + |
| 305 | + @testset "`reshape`" begin |
| 306 | + length_to_shapes = Dict( |
| 307 | + (0 => ((0,), (0, 0), (0, 1), (1, 0), (1, 0, 0), (0, 0, 1))), |
| 308 | + (1 => ((), (1,), (1, 1), (1, 1, 1))), |
| 309 | + (2 => ((2,), (1, 2), (2, 1), (1, 2, 1))), |
| 310 | + (3 => ((3,), (1, 3), (3, 1), (1, 3, 1))), |
| 311 | + (4 => ((4,), (1, 4), (4, 1), (2, 2), (1, 2, 2), (2, 1, 2))), |
| 312 | + (6 => ((6,), (1, 6), (6, 1), (2, 3), (3, 2), (1, 3, 2), (2, 1, 3))), |
| 313 | + ) |
| 314 | + for elem_type ∈ (Int, Number, Union{Nothing,Int}) |
| 315 | + for len ∈ keys(length_to_shapes) |
| 316 | + shapes = length_to_shapes[len] |
| 317 | + for shape1 ∈ shapes |
| 318 | + a = FixedSizeArray{elem_type,length(shape1)}(undef, shape1) |
| 319 | + @test_throws DimensionMismatch reshape(a, length(a)+1) |
| 320 | + @test_throws DimensionMismatch reshape(a, length(a)+1, 1) |
| 321 | + @test_throws DimensionMismatch reshape(a, 1, length(a)+1) |
| 322 | + for shape2 ∈ shapes |
| 323 | + @test prod(shape1) === prod(shape2) === len # meta |
| 324 | + T = FixedSizeArray{elem_type,length(shape2)} |
| 325 | + test_inferred_noalloc(reshape, T, (a, shape2)) |
| 326 | + test_inferred_noalloc(reshape, T, (a, shape2...)) |
| 327 | + b = reshape(a, shape2) |
| 328 | + @test size(b) === shape2 |
| 329 | + @test a.mem === b.mem |
| 330 | + @test a === reshape(b, shape1) |
| 331 | + end |
| 332 | + end |
| 333 | + end |
| 334 | + end |
| 335 | + end |
304 | 336 | end
|
0 commit comments