Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving #18 #19

Merged
merged 9 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1.0, 1.1, 1.2, 1.3, 1.4]
julia-version: [1.0, 1.1, 1.2, 1.3, 1.4, '~1.5.0-0']
os: [ubuntu-latest, macOS-latest, windows-latest]
steps:
- uses: actions/checkout@v2
Expand Down
7 changes: 5 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
name = "HybridArrays"
uuid = "1baab800-613f-4b0a-84e4-9cd3431bfbb9"
authors = ["Mateusz Baran <[email protected]>"]
version = "0.3.6"
version = "0.3.7"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
Requires = "1"
StaticArrays = "=0.12.4"
julia = "1"

[extras]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Random"]
test = ["Test", "Random", "ArrayInterface"]
7 changes: 7 additions & 0 deletions src/HybridArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using StaticArrays: Dynamic
import StaticArrays: _setindex!_scalar, Size

using LinearAlgebra
using Requires


@generated function hasdynamic(::Type{Size}) where Size<:Tuple
Expand Down Expand Up @@ -149,4 +150,10 @@ include("indexing.jl")
include("linalg.jl")
include("utils.jl")

function __init__()
@require ArrayInterface="4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" begin
include("array_interface_compat.jl")
end
end

end # module
5 changes: 5 additions & 0 deletions src/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ _h_similar_type(::Type{A},::Type{T},s::Size{S}) where {A<:HybridArray,T,S} = hyb


Size(::Type{<:HybridArray{S}}) where {S} = Size(S)

Base.IndexStyle(a::HybridArray) = Base.IndexStyle(a.data)
Base.IndexStyle(::Type{HA}) where {S,T,N,M,TData,HA<:HybridArray{S,T,N,M,TData}} = Base.IndexStyle(TData)

Base.vec(a::HybridArray) = vec(a.data)
16 changes: 16 additions & 0 deletions src/array_interface_compat.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

function ArrayInterface.ismutable(::Type{HybridArray{S,T,N,M,TData}}) where {S,T,N,M,TData}
return ArrayInterface.ismutable(TData)
end

function ArrayInterface.can_setindex(::Type{HybridArray{S,T,N,M,TData}}) where {S,T,N,M,TData}
return ArrayInterface.can_setindex(TData)
end

function ArrayInterface.parent_type(::Type{HybridArray{S,T,N,M,TData}}) where {S,T,N,M,TData}
return TData
end

function ArrayInterface.restructure(x::HybridArray{S}, y) where {S}
return HybridArray{S}(reshape(convert(Array, y), size(x)...))
end
4 changes: 4 additions & 0 deletions src/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ Base.one(A::HA) where {HA<:HybridMatrix} = HA(one(A.data))
end

Base.fill!(A::HybridArray, x) = fill!(A.data, x)

function Base.zero(a::HybridArray{S}) where {S}
return HybridArray{S}(zero(a.data))
end
18 changes: 18 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,22 @@ using StaticArrays, HybridArrays, Test, LinearAlgebra
@test isa(@inferred(similar(M, Float64)), HybridMatrix{2, StaticArrays.Dynamic(), Float64})
end

@testset "IndexStyle" begin
M = HybridMatrix{2, StaticArrays.Dynamic(), Int}([1 2; 3 4])
MT = HybridMatrix{2, StaticArrays.Dynamic(), Int}([1 2; 3 4]')
@test (@inferred IndexStyle(M)) === IndexLinear()
@test (@inferred IndexStyle(MT)) === IndexCartesian()
@test (@inferred IndexStyle(typeof(M))) === IndexLinear()
@test (@inferred IndexStyle(typeof(MT))) === IndexCartesian()
end

@testset "vec" begin
M = HybridMatrix{2, StaticArrays.Dynamic(), Int}([1 2; 3 4])
Mv = vec(M)
@test Mv == [1, 3, 2, 4]
@test Mv isa Vector{Int}
Mv[2] = 100
@test M[2, 1] == 100
end

end
11 changes: 11 additions & 0 deletions test/array_interface_compat.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

using HybridArrays, ArrayInterface, Test, StaticArrays

@testset "ArrayInterface compatibility" begin
M = HybridMatrix{2, StaticArrays.Dynamic()}([1 2; 4 5])
@test ArrayInterface.ismutable(M)
@test ArrayInterface.can_setindex(M)
@test ArrayInterface.parent_type(M) === Matrix{Int}
@test ArrayInterface.restructure(M, [2, 4, 6, 8]) == HybridMatrix{2, StaticArrays.Dynamic()}([2 6; 4 8])
@test isa(ArrayInterface.restructure(M, [2, 4, 6, 8]), HybridMatrix{2, StaticArrays.Dynamic()})
end
3 changes: 2 additions & 1 deletion test/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ using StaticArrays, HybridArrays, Test, LinearAlgebra
@testset "zero()" begin
M = HybridMatrix{2, StaticArrays.Dynamic()}([1 2; 4 5])
@test (@inferred zero(M)) == @SMatrix [0 0; 0 0]
@test isa(one(M), HybridMatrix{2,StaticArrays.Dynamic(),Int})
@test isa(zero(M), HybridMatrix{2,StaticArrays.Dynamic(),Int})

Mv = view(M, :, SOneTo(2))
@test (@inferred zero(Mv)) === @SMatrix [0 0; 0 0]

end

@testset "fill!()" begin
Expand Down