Skip to content

Commit

Permalink
Merge pull request #26 from YingboMa/bc
Browse files Browse the repository at this point in the history
Broadcast between LArray and Array
  • Loading branch information
ChrisRackauckas authored Nov 8, 2018
2 parents fa9fed8 + 79418a2 commit fec0e5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/larray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Base.unsafe_convert(::Type{Ptr{T}}, a::LArray{T,N,S}) where {T,N,S} = Base.unsaf
struct LAStyle{T,N,L} <: Broadcast.AbstractArrayStyle{N} end
LAStyle{T,N,L}(x::Val{1}) where {T,N,L} = LAStyle{T,N,L}()
Base.BroadcastStyle(::Type{LArray{T,N,L}}) where {T,N,L} = LAStyle{T,N,L}()
Base.BroadcastStyle(::LabelledArrays.LAStyle{T,N,L}, ::LabelledArrays.LAStyle{E,N,L}) where{T,E,N,L} = LAStyle{promote_type(T,E),N,L}()

function Base.similar(bc::Broadcast.Broadcasted{LAStyle{T,N,L}}, ::Type{ElType}) where {T,N,L,ElType}
return LArray{ElType,N,L}(similar(Array{ElType,N},axes(bc)))
Expand Down
12 changes: 8 additions & 4 deletions test/larrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ g(x) = x.a
@inferred g(x)

x = @LArray [1,2,3] (:a,:b,:c)
x .* x isa LArray
x .+ 1 isa LArray
x .+ 1. isa LArray
eltype(x .+ 1.) === Float64
@test x .* x isa LArray
@test x .+ 1 isa LArray
@test x .+ 1. isa LArray
z = x .+ ones(Int, 3)
@test z isa LArray && eltype(z) === Int
z = x .+ ones(Float64, 3)
@test z isa LArray && eltype(z) === Float64
@test eltype(x .+ 1.) === Float64

z = @LArray Float64 (2,2) (:a,:b,:c,:d)
w = rand(2,2)
Expand Down

0 comments on commit fec0e5c

Please sign in to comment.