Mercurial > repos > public > sbplib_julia
changeset 386:895ec483d741 feature/lazy_array/isapprox
Implement isapprox between LazyArray and scalars.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 01 Oct 2020 07:44:39 +0200 |
parents | 5c10cd0ed1fe |
children | d36df356dca0 |
files | TODO.md src/LazyTensors/lazy_array.jl test/testLazyTensors.jl |
diffstat | 3 files changed, 13 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/TODO.md Wed Sep 30 21:53:52 2020 +0200 +++ b/TODO.md Thu Oct 01 07:44:39 2020 +0200 @@ -12,6 +12,7 @@ - [ ] Replace getindex hack for flatteing tuples with flatten_tuple. - [ ] Fix indexing signatures. We should make sure we are not too specific. For the "inbetween" layers we don't know what type of index is coming so we should use `I...` instead of `I::Vararg{Int,R}` - [ ] Use `@inferred` in a lot of tests. + - [ ] Do we support broadcasting for Lazy arrays? ## Repo - [ ] Add Vidar to the authors list
--- a/src/LazyTensors/lazy_array.jl Wed Sep 30 21:53:52 2020 +0200 +++ b/src/LazyTensors/lazy_array.jl Thu Oct 01 07:44:39 2020 +0200 @@ -8,6 +8,9 @@ abstract type LazyArray{T,D} <: AbstractArray{T,D} end export LazyArray +Base.isapprox(x::LazyArray, y::Number; kwargs...) = isapprox(x, LazyConstantArray(y, size(x)); kwargs...) +Base.isapprox(x::Number, y::LazyArray; kwargs...) = isapprox(y,x; kwargs...) + struct LazyConstantArray{T,D} <: LazyArray{T,D} val::T size::NTuple{D,Int}
--- a/test/testLazyTensors.jl Wed Sep 30 21:53:52 2020 +0200 +++ b/test/testLazyTensors.jl Thu Oct 01 07:44:39 2020 +0200 @@ -126,6 +126,15 @@ @test ndims(lca) == 2 @test size(lca) == (3,2) @test lca[2] == 3.0 + + # Test that the ≈ operator works for scalars + @test lca ≈ 3 + @test lca ≈ 2 atol=3 + @test 3 ≈ lca + @test 2 ≈ lca atol=3 + + # And for vectors + @test lca ≈ lca end struct DummyArray{T,D, T1<:AbstractArray{T,D}} <: LazyArray{T,D} data::T1