-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00448cb
commit 0bb83ba
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export | ||
list_groups, | ||
list_matrices | ||
|
||
# include all matrices | ||
|
||
# matrix groups | ||
const MATRIX_GROUPS = Dict{Group,Set{Type{<:AbstractMatrix}}}() | ||
MATRIX_GROUPS[Group(:builtin)] = Set([ | ||
]) | ||
MATRIX_GROUPS[Group(:user)] = Set([]) | ||
|
||
# group functions | ||
list_groups() = collect(keys(MATRIX_GROUPS)) | ||
# function add_to_group(::Type{<:AbstractMatrix}, group::Symbol...=:user) | ||
# function remove_from_all_groups(::Type{<:AbstractMatrix}) | ||
# function remove_from_group(::Type{<:AbstractMatrix}, group::Symbol) | ||
|
||
# list matrices | ||
list_matrices() = list_matrices(Group[], Property[]) | ||
list_matrices(properties::Property...) = list_matrices(Group[], collect(properties)) | ||
list_matrices(groups::Group...) = list_matrices(collect(groups), Property[]) | ||
function list_matrices(groups::Vector{Group}, props::Vector{Property}) | ||
# check properties | ||
assert_properties_exists(props) | ||
|
||
# groups | ||
groups_results = union(values(MATRIX_GROUPS)...) | ||
for group = groups | ||
if group ∉ keys(MATRIX_GROUPS) | ||
throw(ArgumentError("Group $group not exists")) | ||
else | ||
intersect!(groups_results, MATRIX_GROUPS[group]) | ||
end | ||
end | ||
|
||
# properties | ||
results::Vector{Type{<:AbstractMatrix}} = [] | ||
for matrix = groups_results | ||
if all(props .∈ Ref(properties(matrix))) | ||
push!(results, matrix) | ||
end | ||
end | ||
|
||
# return | ||
return results | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
export | ||
list_properties, | ||
@properties, | ||
properties | ||
|
||
# property list | ||
const PROPERTIES = [Property(i) for i in [ | ||
:symmetric, | ||
:inverse, | ||
:illcond, | ||
:posdef, | ||
:eigen, | ||
:sparse, | ||
:random, | ||
:regprob, | ||
:graph, | ||
]] | ||
|
||
# list properties | ||
list_properties() = PROPERTIES | ||
|
||
# assert properties exists | ||
function assert_properties_exists(props::Vector{Property}) | ||
for prop in props | ||
if prop ∉ PROPERTIES | ||
throw(ArgumentError("Property $prop not exists")) | ||
end | ||
end | ||
end | ||
|
||
# register properties macro | ||
macro properties(type::Symbol, ex::Expr) | ||
return quote | ||
register_properties($(esc(type)), $ex) | ||
end | ||
end | ||
|
||
# register properties | ||
function register_properties(T::Type, props::Vector{Property}) | ||
# check props | ||
assert_properties_exists(props) | ||
|
||
# register properties | ||
@eval properties(::Type{$T}) = $props | ||
end | ||
|
||
# register properties alternative interfaces | ||
register_properties(T::Type, props::Vector{Symbol}) = register_properties(T, [Property(prop) for prop in props]) | ||
register_properties(T::Type, props::Symbol...) = register_properties(T, collect(props)) | ||
register_properties(T::Type, props::Property...) = register_properties(T, collect(props)) | ||
|
||
# properties function interfaces | ||
properties(::Type{<:AbstractMatrix})::Vector{Property} = [] | ||
properties(m::AbstractMatrix{}) = properties(typeof(m).name.wrapper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export | ||
Property, | ||
Group | ||
|
||
struct Property | ||
name::Symbol | ||
end | ||
|
||
struct Group | ||
name::Symbol | ||
end |