Skip to content

Commit 1ef9856

Browse files
authored
Allow expansion of matrices in diff and sum (#160)
* Allow expansion of matrices in diff and sum * Update bases.jl
1 parent 52dcdcd commit 1ef9856

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
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.15.1"
3+
version = "0.15.2"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/ContinuumArrays.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ include("plotting.jl")
104104
# sum/dot
105105
###
106106

107-
sum_size(::Tuple{InfiniteCardinal{1}}, a, dims) = _sum(expand(a), dims)
107+
sum_size(::Tuple{InfiniteCardinal{1}, Vararg{Integer}}, a, dims) = _sum(expand(a), dims)
108108
dot_size(::InfiniteCardinal{1}, a, b) = dot(expand(a), expand(b))
109-
diff_size(::Tuple{InfiniteCardinal{1}}, a, dims) = diff(expand(a); dims=dims)
109+
diff_size(::Tuple{InfiniteCardinal{1}, Vararg{Integer}}, a, dims) = diff(expand(a); dims=dims)
110110
function copy(d::Dot{<:ExpansionLayout,<:ExpansionLayout,<:AbstractQuasiArray,<:AbstractQuasiArray})
111111
a,b = d.A,d.B
112112
P,c = basis(a),coefficients(a)

src/bases/bases.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ end
567567
####
568568
# sum
569569
####
570+
sum_layout(::AbstractBasisLayout, Vm, dims) = error("Overload _sum(::$(typeof(Vm)), ::$(typeof(dims)))")
571+
570572
function sum_layout(::SubBasisLayout, Vm, dims)
571573
dims == 1 || error("not implemented")
572574
sum(parent(Vm); dims=dims)[:,parentindices(Vm)[2]]
@@ -588,19 +590,21 @@ cumsum_layout(::ExpansionLayout, A, dims) = cumsum_layout(ApplyLayout{typeof(*)}
588590
# diff
589591
###
590592

591-
function diff_layout(::SubBasisLayout, Vm, dims::Integer)
593+
diff_layout(::AbstractBasisLayout, Vm, dims...) = error("Overload diff(::$(typeof(Vm)))")
594+
595+
function diff_layout(::SubBasisLayout, Vm, dims::Integer=1)
592596
dims == 1 || error("not implemented")
593597
diff(parent(Vm); dims=dims)[:,parentindices(Vm)[2]]
594598
end
595599

596-
function diff_layout(::WeightedBasisLayout{<:SubBasisLayout}, Vm, dims::Integer)
600+
function diff_layout(::WeightedBasisLayout{SubBasisLayout}, Vm, dims::Integer=1)
597601
dims == 1 || error("not implemented")
598602
w = weight(Vm)
599603
V = unweighted(Vm)
600604
view(diff(w .* parent(V)), parentindices(V)...)
601605
end
602606

603-
function diff_layout(::MappedBasisLayouts, V, dims)
607+
function diff_layout(::MappedBasisLayouts, V, dims::Integer=1)
604608
kr = basismap(V)
605609
@assert kr isa AbstractAffineQuasiVector
606610
D = diff(demap(V); dims=dims)

test/test_chebyshev.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ Base.:(==)(::FooBasis, ::FooBasis) = true
168168
@test dot(exp.(x), x) 2/
169169
@test diff(exp.(x))[0.1] exp(0.1)
170170

171+
@test sum(exp.(x .* (1:2)'); dims=1) [ℯ - 1/ℯ (ℯ^2 - 1/^2)/2]
172+
@test diff(exp.(x .* (1:2)'); dims=1)[0.1,:] [exp(0.1), exp(0.2)]
173+
171174
@test_throws ErrorException diff(wT[:,1:3])
175+
@test_throws ErrorException sum(wT[:,1:3]; dims=1)
172176
@test_throws ErrorException cumsum(x)
173177
end
174178

0 commit comments

Comments
 (0)