Skip to content

Add dot for Inclusion #59

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

Merged
merged 2 commits into from
Aug 26, 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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ContinuumArrays"
uuid = "7ae1f121-cc2c-504b-ac30-9b923412ae5c"
version = "0.3.0"
version = "0.3.1"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -19,7 +19,7 @@ FillArrays = "0.9.3"
InfiniteArrays = "0.8"
IntervalSets = "0.3.2, 0.4, 0.5"
LazyArrays = "0.17.1"
QuasiArrays = "0.3"
QuasiArrays = "0.3.1"
julia = "1.5"

[extras]
Expand Down
15 changes: 13 additions & 2 deletions src/ContinuumArrays.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ContinuumArrays
using IntervalSets, LinearAlgebra, LazyArrays, FillArrays, BandedMatrices, QuasiArrays, InfiniteArrays
import Base: @_inline_meta, @_propagate_inbounds_meta, axes, getindex, convert, prod, *, /, \, +, -, ==,
import Base: @_inline_meta, @_propagate_inbounds_meta, axes, getindex, convert, prod, *, /, \, +, -, ==, ^,
IndexStyle, IndexLinear, ==, OneTo, tail, similar, copyto!, copy, diff,
first, last, show, isempty, findfirst, findlast, findall, Slice, union, minimum, maximum, sum, _sum,
getproperty, isone, iszero, zero, abs, <, ≤, >, ≥, string
Expand All @@ -9,7 +9,7 @@ import LazyArrays: MemoryLayout, Applied, ApplyStyle, flatten, _flatten, colsupp
adjointlayout, arguments, _mul_arguments, call, broadcastlayout, layout_getindex,
sublayout, sub_materialize, ApplyLayout, BroadcastLayout, combine_mul_styles, applylayout,
simplifiable, _simplify
import LinearAlgebra: pinv
import LinearAlgebra: pinv, dot, norm2
import BandedMatrices: AbstractBandedLayout, _BandedMatrix
import FillArrays: AbstractFill, getindex_value, SquareEye
import ArrayLayouts: mul
Expand Down Expand Up @@ -79,6 +79,17 @@ Inclusion(d::AbstractInterval{T}) where T = Inclusion{float(T)}(d)
first(S::Inclusion{<:Any,<:AbstractInterval}) = leftendpoint(S.domain)
last(S::Inclusion{<:Any,<:AbstractInterval}) = rightendpoint(S.domain)

norm2(x::Inclusion{T,<:AbstractInterval}) where T = sqrt(dot(x,x))

function dot(x::Inclusion{T,<:AbstractInterval}, y::Inclusion{V,<:AbstractInterval}) where {T,V}
x == y || throw(DimensionMismatch("first quasivector has axis $(x) which does not match the axis of the second, $(y)."))
TV = promote_type(T,V)
isempty(x) && return zero(TV)
a,b = endpoints(x.domain)
convert(TV, b^3 - a^3)/3
end


for find in (:findfirst, :findlast)
@eval $find(f::Base.Fix2{typeof(isequal)}, d::Inclusion) = f.x in d.domain ? f.x : nothing
end
Expand Down
5 changes: 3 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ end
@test exp.(-x)[1.0] == exp(-1.0)
@test exp.(x.^2)[1.0] == exp(1.0)
@test exp.(-x.^2/(20/2))[1.0] == exp(-1.0^2/(20/2))

@test dot(x,x) ≈ 2/3
@test norm(x) ≈ sqrt(2/3)
end

@testset "DiracDelta" begin
Expand Down Expand Up @@ -199,8 +202,6 @@ end
@test length(fp.args) == 2
@test fp[1.1] ≈ 1
@test fp[2.2] ≈ 2

@test D^2 isa ApplyQuasiMatrix{Float64,typeof(*)}
end

@testset "Weak Laplacian" begin
Expand Down