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 (#7)

* add a `connection_index` function for getting the index of a specific
connection matrix

* bump version
  • Loading branch information
MasonProtter authored Oct 30, 2024
1 parent 2e7ed10 commit f3e3d30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "GraphDynamics"
uuid = "bcd5d0fe-e6b7-4ef1-9848-780c183c7f4c"
version = "0.1.4"
version = "0.1.5"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
18 changes: 18 additions & 0 deletions src/GraphDynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ end
isstochastic,

event_times,
connection_index
)

export
Expand Down Expand Up @@ -244,6 +245,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

2 comments on commit f3e3d30

@MasonProtter
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/118393

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.5 -m "<description of version>" f3e3d309a91ba2dd28f58a659511fcd77a1a2608
git push origin v0.1.5

Please sign in to comment.