Skip to content

Commit 8f18e86

Browse files
committed
added diff(::TupleVector)
1 parent a01b77b commit 8f18e86

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AbstractTensors"
22
uuid = "a8e43f4a-99b7-5565-8bf1-0165161caaea"
33
authors = ["Michael Reed"]
4-
version = "0.5.5"
4+
version = "0.5.6"
55

66
[deps]
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

src/static.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,27 @@ end
336336
end
337337
end
338338

339+
# Diff is slightly different
340+
@inline LinearAlgebra.diff(a::TupleVector{N}; dims=Val(1)) where N = _diff(Val(N),a,dims)
341+
342+
@inline function _diff(sz::Val, a::TupleVector, D::Int)
343+
_diff(sz,a,Val(D))
344+
end
345+
@generated function _diff(::Val{N}, a::TupleVector, ::Val{1}) where N
346+
Snew = N-1
347+
exprs = Array{Expr}(undef, Snew)
348+
for i1 = Base.product(1:Snew)
349+
i2 = copy([i1...])
350+
i2[1] = i1[1] + 1
351+
exprs[i1...] = :(a[$(i2...)] - a[$(i1...)])
352+
end
353+
return quote
354+
@_inline_meta
355+
elements = tuple($(exprs...))
356+
@inbounds return similar_type(a, eltype(elements), Val($Snew))(elements)
357+
end
358+
end
359+
339360
# Values
340361

341362
struct Values{N,T} <: TupleVector{N,T}

0 commit comments

Comments
 (0)