Skip to content

Commit f36bad5

Browse files
committed
better type for derivatives
1 parent eceeec9 commit f36bad5

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "InfinitesimalGenerators"
22
uuid = "2fce0c6f-5f0b-5c85-85c9-2ffe1d5ee30d"
3-
version = "2.1.0"
3+
version = "2.2.0"
44

55
[deps]
66
Arpack = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"

src/derivatives.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11

2-
struct FirstDerivative{T} <: AbstractVector{T}
3-
x::AbstractVector{<:Real}
4-
y::AbstractVector{T}
2+
struct FirstDerivative{T, X <: AbstractVector{<:Real}, Y <: AbstractVector{<: Real}} <: AbstractVector{T}
3+
x::X
4+
y::Y
55
bc::NTuple{2}{T}
66
direction::Symbol
7-
function FirstDerivative{T}(x, y, bc, direction) where {T}
7+
function FirstDerivative(x, y, bc, direction)
88
size(x) == size(y) || throw(DimensionMismatch(
99
"cannot match grid of length $(length(x)) with vector of length $(length(y))"))
1010
direction (:upward, :downward) || throw(ArgumentError("direction must be :upward or :downward"))
11-
return new(x, y, bc, direction)
11+
return new{float(eltype(y)), typeof(x), typeof(y)}(x, y, bc, direction)
1212
end
1313
end
1414

15-
function FirstDerivative(x::AbstractVector, y::AbstractVector; bc = (0, 0), direction = :upward)
16-
FirstDerivative{eltype(y)}(x, y, bc, direction)
15+
function FirstDerivative(x, y; bc = (0, 0), direction = :upward)
16+
FirstDerivative(x, y, bc, direction)
1717
end
1818

1919
Base.size(d::FirstDerivative) = (length(d.x), 1)
@@ -40,19 +40,19 @@ function Base.getindex(d::FirstDerivative{T}, i::Int) where {T}
4040
end
4141

4242

43-
struct SecondDerivative{T} <: AbstractVector{T}
44-
x::AbstractVector{<:Real}
45-
y::AbstractVector{T}
43+
struct SecondDerivative{T, X <: AbstractVector{<:Real}, Y <: AbstractVector{<: Real}} <: AbstractVector{T}
44+
x::X
45+
y::Y
4646
bc::NTuple{2}{T}
47-
function SecondDerivative{T}(x, y, bc) where {T}
47+
function SecondDerivative(x, y, bc)
4848
length(x) == length(y) || throw(DimensionMismatch(
4949
"cannot match grid of length $(length(x)) with vector of length $(length(y))"))
50-
return new(x, y, bc)
50+
return new{float(eltype(y)), typeof(x), typeof(y)}(x, y, bc)
5151
end
5252
end
5353

54-
function SecondDerivative(x::AbstractVector, y::AbstractVector; bc = (0, 0))
55-
SecondDerivative{eltype(y)}(x, y, bc)
54+
function SecondDerivative(x, y; bc = (0, 0))
55+
SecondDerivative(x, y, bc)
5656
end
5757

5858
Base.size(d::SecondDerivative) = (length(d.x), 1)

src/jointoperator.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
function jointoperator(operators, Q::Array)
1+
function jointoperator(operators::AbstractVector{<:Tridiagonal}, Q::Array)
22
N = length(operators)
33
wn = size(operators[1], 1)
4-
@assert all(o isa Tridiagonal for o in operators)
54
# check if all os have same size
65
@assert all(size(o) == (wn, wn) for o in operators)
7-
# check if the size of transition matrix is
8-
# same as the number of operators
6+
# check if the size of transition matrix is same as the number of operators
97
@assert size(Q,1) == size(Q,2) == N
108
J = BandedBlockBandedMatrix(Zeros(wn * N, wn * N), fill(wn, N) ,fill(wn, N), (N-1, N-1), (1, 1))
119
for i in 1:N

0 commit comments

Comments
 (0)