Skip to content

Commit

Permalink
add a connection_index function for getting the index of a specific
Browse files Browse the repository at this point in the history
connection matrix
  • Loading branch information
MasonProtter committed Oct 30, 2024
1 parent 2fe7ec8 commit 8cb896c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/GraphDynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ end
isstochastic,

event_times,
connection_index
)

export
Expand Down Expand Up @@ -241,6 +242,23 @@ Base.getindex(m::ConnectionMatrices, i) = m.matrices[i]
Base.length(m::ConnectionMatrices) = length(m.matrices)
Base.size(m::ConnectionMatrix{N}) where {N} = (N, N)

"""
connection_index(ConnType, M::ConnectionMatrices)
give the first index `n` such that `M[n]` is a `ConnectionMatrix{N, ConnType} where {N}`, or throw an error if no such index exists.
"""
connection_index(::Type{ConnType}, M::ConnectionMatrices) where {ConnType} = _conn_index(ConnType, M.matrices, 1)
function _conn_index(::Type{ConnType}, tup::Tuple, i) where {ConnType}
if first(tup) isa ConnectionMatrix{N, ConnType} where {N}
return i
else
_conn_index(ConnType, Base.tail(tup), i+1)
end
end
@noinline _conn_index(::Type{ConnType}, ::Tuple{}, _) where {ConnType} =
error("ConnectionMatrices did not contain a ConnectionMatrix with connection type ", ConnType)


abstract type GraphSystem end

@kwdef struct ODEGraphSystem{CM <: ConnectionMatrices, S, P, EVT, CDEP, CCEP, Ns, SNM, PNM} <: GraphSystem
Expand Down

0 comments on commit 8cb896c

Please sign in to comment.