diff --git a/src/utils.jl b/src/utils.jl index 791b8c6a3..c5c759966 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -12,6 +12,8 @@ If no axis reversal is required the same objects will be returned, without alloc """ function reorder end +reorder(x, A) = reorder(x, dims(A)) +reorder(x, ::Nothing) = throw(ArgumentError("object has no dimensions")) reorder(x, p::Pair, ps::Vararg{Pair}) = reorder(x, (p, ps...)) reorder(x, ps::Tuple{Vararg{Pair}}) = reorder(x, Dimensions.pairdims(ps...)) # Reorder specific dims. diff --git a/test/utils.jl b/test/utils.jl index e99ad946d..4602d9cb6 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -78,10 +78,11 @@ end # reorder with dimension lookups rev = reverse(da, dims=Y) - reo = reorder(rev, dims(da)) + reo = reorder(rev, da) @test rev != da @test reo == da @test dims(reo) == dims(da) + @test_throws ArgumentError reorder(rev, :test) end @testset "modify" begin