-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Higher level incident call #60
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using DiagrammaticEquations | ||
using ACSets | ||
|
||
export is_var_target, is_var_source, get_variable_parents, get_next_op1s, get_next_op2s | ||
|
||
function is_var_target(d::SummationDecapode, var::Int) | ||
return !isempty(collected_incident(d, var, [:tgt, :res, :sum])) | ||
end | ||
|
||
function is_var_source(d::SummationDecapode, var::Int) | ||
return !isempty(collected_incident(d, var, [:src, :proj1, :proj2, :summand])) | ||
end | ||
|
||
function get_variable_parents(d::SummationDecapode, var::Int) | ||
return collected_incident(d, var, [:tgt, :res, :res, [:summation, :sum]], [:src, :proj1, :proj2, :summand]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea what this is supposed to do, is this supposed to be a conjucnction of disjunctions type query? |
||
end | ||
|
||
function get_next_op1s(d::SummationDecapode, var::Int) | ||
collected_incident(d, var, [:src]) | ||
end | ||
|
||
function get_next_op2s(d::SummationDecapode, var::Int) | ||
collected_incident(d, var, [:proj1, :proj2]) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using DiagrammaticEquations | ||
using ACSets | ||
|
||
export collected_incident | ||
|
||
function collected_incident(d::ACSet, searches::AbstractVector, args...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docstring on exported function |
||
|
||
isempty(searches) && error("Cannot have an empty search") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't empty search return empty list? |
||
|
||
query_result = mapreduce(vcat, searches) do search | ||
collected_incident(d, search, args...) | ||
end | ||
|
||
return unique!(query_result) | ||
end | ||
|
||
function collected_incident(d::ACSet, search, lookup_array) | ||
numof_channels = length(lookup_array) | ||
empty_outputchannels = fill(nothing, numof_channels) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this an array of nothings? You can't push something into these "channels" |
||
return collected_incident(d, search, lookup_array, empty_outputchannels) | ||
end | ||
|
||
|
||
function collected_incident(d::ACSet, search, lookup_array, output_array) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the type of |
||
length(lookup_array) == length(output_array) || error("Input and output channels are different lengths") | ||
isempty(lookup_array) && error("Cannot have an empty lookup") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should empty |
||
|
||
query_result = mapreduce(vcat, zip(lookup_array, output_array)) do (lookup, output) | ||
runincident_output_result(d, search, lookup, output) | ||
end | ||
|
||
return unique!(query_result) | ||
end | ||
|
||
function runincident_output_result(d::ACSet, search, lookup::Union{Symbol, AbstractVector{Symbol}}, output_channel::Union{Symbol, Nothing}) | ||
index_result = incident(d, search, lookup) | ||
isnothing(output_channel) ? index_result : d[index_result, output_channel] | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this file feels over engineered for something simple, but I can't tell what it is supposed to do because of the lack of docstrings. |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using Test | ||
using DiagrammaticEquations | ||
using DiagrammaticEquations.Deca | ||
using ACSets | ||
|
||
function array_contains_same(test, expected) | ||
sort(test) == sort(expected) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so you want to handle multiplicity? Could replace with |
||
end | ||
|
||
get_index_from_name(d::SummationDecapode, varname::Symbol) = only(incident(d, varname, :name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no java please. just call this |
||
|
||
@testset "Check sources and targets" begin | ||
singleton_deca = @decapode begin | ||
V::infer | ||
end | ||
|
||
@test !is_var_source(singleton_deca, 1) | ||
@test !is_var_target(singleton_deca, 1) | ||
|
||
|
||
path_op1_deca = @decapode begin | ||
(X,Z)::infer | ||
X == d(d(Z)) | ||
end | ||
|
||
idxX = get_index_from_name(path_op1_deca, :X) | ||
idxZ = get_index_from_name(path_op1_deca, :Z) | ||
|
||
@test is_var_source(path_op1_deca, idxZ) | ||
@test !is_var_target(path_op1_deca, idxZ) | ||
|
||
@test !is_var_source(path_op1_deca, idxX) | ||
@test is_var_target(path_op1_deca, idxX) | ||
|
||
|
||
path_op2_deca = @decapode begin | ||
X == ∧(Y,Z) | ||
end | ||
|
||
idxX = get_index_from_name(path_op2_deca, :X) | ||
idxY = get_index_from_name(path_op2_deca, :Y) | ||
idxZ = get_index_from_name(path_op2_deca, :Z) | ||
|
||
idxsYZ = [idxY, idxZ] | ||
|
||
for idx in idxsYZ | ||
@test is_var_source(path_op2_deca, idx) | ||
@test !is_var_target(path_op2_deca, idx) | ||
end | ||
@test !is_var_source(path_op2_deca, idxX) | ||
@test is_var_target(path_op2_deca, idxX) | ||
|
||
|
||
path_sum_deca = @decapode begin | ||
X == Y + Z | ||
end | ||
|
||
idxX = get_index_from_name(path_sum_deca, :X) | ||
idxY = get_index_from_name(path_sum_deca, :Y) | ||
idxZ = get_index_from_name(path_sum_deca, :Z) | ||
|
||
idxsYZ = [idxY, idxZ] | ||
|
||
for idx in idxsYZ | ||
@test is_var_source(path_sum_deca, idx) | ||
@test !is_var_target(path_sum_deca, idx) | ||
end | ||
@test !is_var_source(path_sum_deca, idxX) | ||
@test is_var_target(path_sum_deca, idxX) | ||
|
||
mixedop_deca = @decapode begin | ||
Inter == d(X) + ∧(Y, Z) | ||
Res == d(Inter) | ||
end | ||
|
||
idxX = get_index_from_name(mixedop_deca, :X) | ||
idxY = get_index_from_name(mixedop_deca, :Y) | ||
idxZ = get_index_from_name(mixedop_deca, :Z) | ||
idxInter = get_index_from_name(mixedop_deca, :Inter) | ||
idxRes = get_index_from_name(mixedop_deca, :Res) | ||
|
||
@test is_var_source(mixedop_deca, idxX) | ||
@test is_var_source(mixedop_deca, idxY) | ||
@test is_var_source(mixedop_deca, idxZ) | ||
|
||
@test is_var_target(mixedop_deca, idxRes) | ||
|
||
@test is_var_target(mixedop_deca, idxInter) && is_var_source(mixedop_deca, idxInter) | ||
end | ||
|
||
# TODO: Finish writing these tests | ||
@testset "Get states and terminals" begin | ||
singleton_deca = @decapode begin | ||
V::Form1 | ||
end | ||
@test infer_state_names(singleton_deca) == infer_terminal_names(singleton_deca) | ||
|
||
path_op1_deca = @decapode begin | ||
(X,Z)::infer | ||
X == d(d(Z)) | ||
end | ||
@test array_contains_same(infer_state_names(path_op1_deca), [:Z]) | ||
@test array_contains_same(infer_terminal_names(path_op1_deca), [:X]) | ||
|
||
path_op2_deca = @decapode begin | ||
(X,Y,Z)::infer | ||
X == ∧(Y,Z) | ||
end | ||
@test array_contains_same(infer_state_names(path_op2_deca), [:Y, :Z]) | ||
@test array_contains_same(infer_terminal_names(path_op2_deca), [:X]) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we rename all these java getters to remove
get_