Skip to content

Commit

Permalink
Merge pull request #332 from gridap/bugfix_for_0_length_arrays
Browse files Browse the repository at this point in the history
Bugfix for 0 length arrays
  • Loading branch information
fverdugo authored Jul 24, 2020
2 parents 20a1589 + 85ca44b commit 423a802
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 26 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.13.1] - Unreleased
## [0.13.1] - 2020-7-24

### Fixed

- Bug associated with `LinCom` kernel and triangulations with 0 cells. Since PR [#331](/~https://github.com/gridap/Gridap.jl/pull/331/).
- Bugs associated with the degenerated case of 0-length arrays. Since PR [#331](/~https://github.com/gridap/Gridap.jl/pull/331/) and [#332](/~https://github.com/gridap/Gridap.jl/pull/332/).

## [0.13.0] - 2020-07-23

Expand Down
4 changes: 1 addition & 3 deletions src/Arrays/Apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ function testitem(a::AppliedArray)
cg = array_cache(a.g)
gi = testitem(a.g)
fi = testitems(a.f...)
cf = array_caches(a.f...)
ai = kernel_testitem(gi,fi...)
ai
kernel_testitem(gi,fi...)
end

function getindex!(cache,a::AppliedArray,i::Integer...)
Expand Down
6 changes: 5 additions & 1 deletion src/Arrays/CompressedArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ struct CompressedArray{T,N,A,P} <: AbstractArray{T,N}
end

function testitem(a::CompressedArray)
testitem(a.values)
if length(a.ptrs) == 0
testitem(a.values)
else
a.values[first(a.ptrs)]
end
end

size(a::CompressedArray) = size(a.ptrs)
Expand Down
4 changes: 4 additions & 0 deletions src/Arrays/Interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ function test_array(
end
@test t
@test IndexStyle(a) == IndexStyle(b)
@test isa(testitem(a),eltype(a))
if length(a) > 0
@test testitem(a) == first(a)
end
true
end

Expand Down
4 changes: 2 additions & 2 deletions src/Arrays/Kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ abstract type Kernel <: GridapType end
Returns the type of the result of calling kernel `f` with
arguments of the types of the objects `x`.
It defaults to `typeof(apply_kernel(f,x...))`
It defaults to `typeof(kernel_testitem(f,x...))`
"""
function kernel_return_type(f,x...)
typeof(apply_kernel(f,x...))
typeof(kernel_testitem(f,x...))
end

"""
Expand Down
6 changes: 0 additions & 6 deletions src/Arrays/LocalToGlobalArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ struct LocalToGlobalArray{T,M,N,L,V} <: AbstractArray{Array{T,M},N}
end
end

function testitem(a::LocalToGlobalArray)
val = testitem(a.gid_to_val)
gids = testitem(a.lid_to_gid)
fill(val,size(gids))
end

size(a::LocalToGlobalArray) = size(a.lid_to_gid)

function IndexStyle(::Type{LocalToGlobalArray{T,M,N,L,V}}) where {T,M,N,L,V}
Expand Down
6 changes: 0 additions & 6 deletions src/Arrays/LocalToGlobalPosNegArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ struct LocalToGlobalPosNegArray{T,M,N,L,V,W} <: AbstractArray{Array{T,M},N}
end
end

function testitem(a::LocalToGlobalPosNegArray)
val = testitem(a.gid_to_val_pos)
gids = testitem(a.lid_to_gid)
fill(val,size(gids))
end

size(a::LocalToGlobalPosNegArray) = size(a.lid_to_gid)

function IndexStyle(::Type{<:LocalToGlobalPosNegArray{T,M,N,L}}) where {T,M,N,L}
Expand Down
2 changes: 0 additions & 2 deletions src/Arrays/Reindex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ end
a.i_to_v[i]=v
end



function testitem(a::Reindexed)
if length(a.j_to_i) == 0
testitem(a.i_to_v)
Expand Down
47 changes: 47 additions & 0 deletions test/ArraysTests/ApplyTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,53 @@ r = map(+,a,b)
test_array(c,r)
@test isa(c,Fill)

l = 10
ai = [8 0; 0 4]
a = Fill(ai,l)
c = apply(inv,a)
r = map(inv,a)
test_array(c,r)
@test isa(c,Fill)

l = 10
ai = [8 0; 0 4]
a = fill(ai,l)
c = apply(inv,a)
r = map(inv,a)
test_array(c,r)

l = 0
ai = [8 0; 0 4]
a = fill(ai,l)
c = apply(inv,a)
r = map(inv,a)
test_array(c,r)

ai = [8 0; 0 4]
a = CompressedArray([ai,],Int[])
c = apply(inv,a)
r = map(inv,a)
test_array(c,r)

l = 10
ai = [8, 0]
a = fill(ai,l)
f(ai) = ai[2]-ai[1]
c = apply(f,a)
r = map(f,a)
test_array(c,r)

g(ai) = ai[2]-ai[1]
import Gridap.Arrays: kernel_testitem!
kernel_testitem!(c,::typeof(g),ai) = zero(eltype(ai))
l = 0
ai = [8, 0]
a = fill(ai,l)
c = apply(g,a)
r = map(g,a)
test_array(c,r)


#f = rand(10)
#a = rand(10)
#@test apply(f,a) === f
Expand Down
4 changes: 1 addition & 3 deletions test/ArraysTests/LocalToGlobalArraysTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ r = reindex(ca,ids)
@test isa(r,LocalToGlobalArray)
test_array(r,ca[ids])


i_to_v=[[1, 2], [5, 6], [1, 5], [2, 6], [2, 3], [6, 7], [3, 7], [3, 4], [7, 8], [4, 8], [9, 10], [5, 9], [6, 10], [10, 11], [7, 11], [11, 12], [8, 12], [13, 14], [9, 13], [10, 14], [14, 15], [11, 15], [15, 16], [12, 16]]
j_to_i=Int64[]
lid_to_gid=reindex(i_to_v,j_to_i)
gid_to_val=VectorValue{2,Float64}[(0.0, 0.25), (0.25, 0.25), (0.5, 0.25), (0.75, 0.25), (0.0, 0.5), (0.25, 0.5), (0.5, 0.5), (0.75, 0.5), (0.0, 0.75), (0.25, 0.75), (0.5, 0.75), (0.75, 0.75), (0.0, 1.0), (0.25, 1.0), (0.5, 1.0), (0.75, 1.0)]
f2=LocalToGlobalArray(lid_to_gid,gid_to_val)
@test 2 == length(testitem(f2))

test_array(f2,Vector{VectorValue{2,Float64}}[])

end # module
2 changes: 1 addition & 1 deletion test/ArraysTests/LocalToGlobalPosNegArraysTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ j_to_i=Int64[]
lid_to_gid=reindex(i_to_v,j_to_i)
gid_to_val=VectorValue{2,Float64}[(0.0, 0.25), (0.25, 0.25), (0.5, 0.25), (0.75, 0.25), (0.0, 0.5), (0.25, 0.5), (0.5, 0.5), (0.75, 0.5), (0.0, 0.75), (0.25, 0.75), (0.5, 0.75), (0.75, 0.75), (0.0, 1.0), (0.25, 1.0), (0.5, 1.0), (0.75, 1.0)]
f2=LocalToGlobalPosNegArray(lid_to_gid,gid_to_val,gid_to_val)
@test 2 == length(testitem(f2))
test_array(f2,Vector{VectorValue{2,Float64}}[])

end # module
8 changes: 8 additions & 0 deletions test/FESpacesTests/ExtendedFESpacesTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ incell_to_cell = findall(oldcell_to_is_in)
outcell_to_cell = findall(collect(Bool, .! oldcell_to_is_in))

model_in = DiscreteModel(model,incell_to_cell)

V = TestFESpace(
model=model_in,valuetype=Float64,reffe=:Lagrangian,
order=1,conformity=:H1,dof_space=:physical)
@test isa(V,ExtendedFESpace)



model_out = DiscreteModel(model,outcell_to_cell)

trian_in = RestrictedTriangulation(trian, incell_to_cell)
Expand Down

2 comments on commit 423a802

@fverdugo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/18391

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.13.1 -m "<description of version>" 423a8022305ec256918c97e0365befa4c90401e9
git push origin v0.13.1

Please sign in to comment.