diff --git a/src/BlockArrays.jl b/src/BlockArrays.jl index dfd81619..fde5df5d 100644 --- a/src/BlockArrays.jl +++ b/src/BlockArrays.jl @@ -25,7 +25,7 @@ import Base: @propagate_inbounds, Array, to_indices, to_index, step, broadcast, eltype, convert, similar, tail, reindex, - RangeIndex, Int, Integer, Number, + RangeIndex, Int, Integer, Number, Tuple, +, -, *, /, \, min, max, isless, in, copy, copyto!, axes, @deprecate, BroadcastStyle, checkbounds, throw_boundserror, oneunit, ones, zeros, intersect, Slice, resize! diff --git a/src/blockindices.jl b/src/blockindices.jl index 9521eeb4..06c02f71 100644 --- a/src/blockindices.jl +++ b/src/blockindices.jl @@ -96,11 +96,12 @@ icmp(a, b) = ifelse(isless(a,b), 1, ifelse(a==b, 0, -1)) # conversions convert(::Type{T}, index::Block{1}) where {T<:Number} = convert(T, index.n[1]) -convert(::Type{T}, index::Block) where {T<:Tuple} = convert(T, index.n) +convert(::Type{T}, index::Block) where {T<:Tuple} = convert(T, Block.(index.n)) Int(index::Block{1}) = Int(index.n[1]) Integer(index::Block{1}) = index.n[1] Number(index::Block{1}) = index.n[1] +Tuple(index::Block) = Block.(index.n) # print Base.show(io::IO, B::Block{0,Int}) = print(io, "Block()") diff --git a/test/test_blockindices.jl b/test/test_blockindices.jl index 38ca5a4c..f3beadf2 100644 --- a/test/test_blockindices.jl +++ b/test/test_blockindices.jl @@ -4,6 +4,7 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice @testset "Blocks" begin @test Int(Block(2)) === Integer(Block(2)) === Number(Block(2)) === 2 + @test Tuple(Block(2,3)) === (Block(2),Block(3)) @test Block((Block(3), Block(4))) === Block(3,4) @test Block() === Block(()) === Block{0}() === Block{0}(()) @test Block(1) === Block((1,)) === Block{1}(1) === Block{1}((1,)) @@ -70,6 +71,8 @@ import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice @test convert(Int, Block(2)) == 2 @test convert(Float64, Block(2)) == 2.0 + @test convert(Tuple, Block(2,3)) == (Block(2),Block(3)) + @test convert(Tuple{Vararg{Int}}, Block(2,3)) == (2,3) @test_throws MethodError convert(Int, Block(2,1)) @test convert(Tuple{Int,Int}, Block(2,1)) == (2,1)