Skip to content

Commit 5bdd8fb

Browse files
authored
Add dot for Inclusion (#59)
* Update ContinuumArrays.jl * Add tests
1 parent ce336c3 commit 5bdd8fb

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ContinuumArrays"
22
uuid = "7ae1f121-cc2c-504b-ac30-9b923412ae5c"
3-
version = "0.3.0"
3+
version = "0.3.1"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -19,7 +19,7 @@ FillArrays = "0.9.3"
1919
InfiniteArrays = "0.8"
2020
IntervalSets = "0.3.2, 0.4, 0.5"
2121
LazyArrays = "0.17.1"
22-
QuasiArrays = "0.3"
22+
QuasiArrays = "0.3.1"
2323
julia = "1.5"
2424

2525
[extras]

src/ContinuumArrays.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ContinuumArrays
22
using IntervalSets, LinearAlgebra, LazyArrays, FillArrays, BandedMatrices, QuasiArrays, InfiniteArrays
3-
import Base: @_inline_meta, @_propagate_inbounds_meta, axes, getindex, convert, prod, *, /, \, +, -, ==,
3+
import Base: @_inline_meta, @_propagate_inbounds_meta, axes, getindex, convert, prod, *, /, \, +, -, ==, ^,
44
IndexStyle, IndexLinear, ==, OneTo, tail, similar, copyto!, copy, diff,
55
first, last, show, isempty, findfirst, findlast, findall, Slice, union, minimum, maximum, sum, _sum,
66
getproperty, isone, iszero, zero, abs, <, , >, , string
@@ -9,7 +9,7 @@ import LazyArrays: MemoryLayout, Applied, ApplyStyle, flatten, _flatten, colsupp
99
adjointlayout, arguments, _mul_arguments, call, broadcastlayout, layout_getindex,
1010
sublayout, sub_materialize, ApplyLayout, BroadcastLayout, combine_mul_styles, applylayout,
1111
simplifiable, _simplify
12-
import LinearAlgebra: pinv
12+
import LinearAlgebra: pinv, dot, norm2
1313
import BandedMatrices: AbstractBandedLayout, _BandedMatrix
1414
import FillArrays: AbstractFill, getindex_value, SquareEye
1515
import ArrayLayouts: mul
@@ -79,6 +79,17 @@ Inclusion(d::AbstractInterval{T}) where T = Inclusion{float(T)}(d)
7979
first(S::Inclusion{<:Any,<:AbstractInterval}) = leftendpoint(S.domain)
8080
last(S::Inclusion{<:Any,<:AbstractInterval}) = rightendpoint(S.domain)
8181

82+
norm2(x::Inclusion{T,<:AbstractInterval}) where T = sqrt(dot(x,x))
83+
84+
function dot(x::Inclusion{T,<:AbstractInterval}, y::Inclusion{V,<:AbstractInterval}) where {T,V}
85+
x == y || throw(DimensionMismatch("first quasivector has axis $(x) which does not match the axis of the second, $(y)."))
86+
TV = promote_type(T,V)
87+
isempty(x) && return zero(TV)
88+
a,b = endpoints(x.domain)
89+
convert(TV, b^3 - a^3)/3
90+
end
91+
92+
8293
for find in (:findfirst, :findlast)
8394
@eval $find(f::Base.Fix2{typeof(isequal)}, d::Inclusion) = f.x in d.domain ? f.x : nothing
8495
end

test/runtests.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ end
3737
@test exp.(-x)[1.0] == exp(-1.0)
3838
@test exp.(x.^2)[1.0] == exp(1.0)
3939
@test exp.(-x.^2/(20/2))[1.0] == exp(-1.0^2/(20/2))
40+
41+
@test dot(x,x) 2/3
42+
@test norm(x) sqrt(2/3)
4043
end
4144

4245
@testset "DiracDelta" begin
@@ -199,8 +202,6 @@ end
199202
@test length(fp.args) == 2
200203
@test fp[1.1] 1
201204
@test fp[2.2] 2
202-
203-
@test D^2 isa ApplyQuasiMatrix{Float64,typeof(*)}
204205
end
205206

206207
@testset "Weak Laplacian" begin

0 commit comments

Comments
 (0)