Skip to content

Commit c4d78f8

Browse files
committed
Support higher order diff
1 parent f241cf7 commit c4d78f8

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "QuasiArrays"
22
uuid = "c4ea9172-b204-11e9-377d-29865faadc5c"
33
authors = ["Sheehan Olver <solver@mac.com>"]
4-
version = "0.11.9"
4+
version = "0.12"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/calculus.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,30 @@ cumsum_size(::NTuple{N,Integer}, A, dims) where N = error("Not implemented")
5151
# diff
5252
####
5353

54-
@inline diff(a::AbstractQuasiArray; dims::Integer=1) = diff_layout(MemoryLayout(a), a, dims)
55-
function diff_layout(LAY::ApplyLayout{typeof(*)}, V::AbstractQuasiVector, dims...)
54+
@inline diff(a::AbstractQuasiArray, order...; dims::Integer=1) = diff_layout(MemoryLayout(a), a, order...; dims)
55+
function diff_layout(LAY::ApplyLayout{typeof(*)}, V::AbstractQuasiVector, order...; dims=1)
5656
a = arguments(LAY, V)
57-
*(diff(a[1]), tail(a)...)
57+
dims == 1 || throw(ArgumentError("cannot differentiate a vector along dimension $dims"))
58+
*(diff(a[1], order...), tail(a)...)
5859
end
5960

60-
function diff_layout(LAY::ApplyLayout{typeof(*)}, V::AbstractQuasiMatrix, dims=1)
61+
function diff_layout(LAY::ApplyLayout{typeof(*)}, V::AbstractQuasiMatrix, order...; dims=1)
6162
a = arguments(LAY, V)
6263
@assert dims == 1 #for type stability, for now
6364
# if dims == 1
64-
*(diff(a[1]), tail(a)...)
65+
*(diff(a[1], order...), tail(a)...)
6566
# else
6667
# *(front(a)..., diff(a[end]; dims=dims))
6768
# end
6869
end
6970

70-
diff_layout(::MemoryLayout, A, dims...) = diff_size(size(A), A, dims...)
71-
diff_size(sz, a, dims...) = error("diff not implemented for $(typeof(a))")
71+
diff_layout(::MemoryLayout, A, order...; dims...) = diff_size(size(A), A, order...; dims...)
72+
diff_size(sz, a, order...; dims...) = error("diff not implemented for $(typeof(a))")
7273

7374
diff(x::Inclusion; dims::Integer=1) = ones(eltype(x), diffaxes(x))
74-
diff(c::AbstractQuasiFill{<:Any,1}; dims::Integer=1) = zeros(eltype(c), diffaxes(axes(c,1)))
75-
function diff(c::AbstractQuasiFill{<:Any,2}; dims::Integer=1)
75+
diff(x::Inclusion, order::Int; dims::Integer=1) = fill(ifelse(isone(order), one(eltype(x)), zero(eltype(x))), diffaxes(x))
76+
diff(c::AbstractQuasiFill{<:Any,1}, order...; dims::Integer=1) = zeros(eltype(c), diffaxes(axes(c,1)))
77+
function diff(c::AbstractQuasiFill{<:Any,2}, order...; dims::Integer=1)
7678
a,b = axes(c)
7779
if dims == 1
7880
zeros(eltype(c), diffaxes(a), b)

0 commit comments

Comments
 (0)