Skip to content
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

incident with invalid entries #57

Closed
slwu89 opened this issue Sep 27, 2023 · 3 comments · Fixed by #62
Closed

incident with invalid entries #57

slwu89 opened this issue Sep 27, 2023 · 3 comments · Fixed by #62
Assignees
Labels
bug Something isn't working

Comments

@slwu89
Copy link
Member

slwu89 commented Sep 27, 2023

After removing parts in the codom of a hom, the resulting rows in the printed acset appear as 0 entries. However, using 0 in incident cannot get the rows with invalid codom elements. I'm not sure how to do this, and it would be nice if incident could find those rows.

Very happy to work on PR to get this addressed before the next ACSets.jl update if someone can give me some pointers on where to look in the source.

MWE below, exhibiting this behavior with non indexed and indexed hom.

@present MySch(FreeSchema) begin
  (A,B)::Ob
  f::Hom(A,B)
end

@acset_type MyDataNoIdx(MySch)

@acset_type MyDataIdx(MySch, index=[:f])

data_noidx = @acset MyDataNoIdx begin
  A = 5
  B = 5
  f = [1,2,3,4,5]
end

data_idx = @acset MyDataNoIdx begin
  A = 5
  B = 5
  f = [1,2,3,4,5]
end

rem_parts!(data_noidx, :B, 1:3)
rem_parts!(data_idx, :B, 1:3)

incident(data_noidx, 0, :f)
incident(data_idx, 0, :f)

# would be nice if incident could do
findall(data_noidx[:,:f] .== 0)
findall(data_idx[:,:f] .== 0)
@slwu89
Copy link
Member Author

slwu89 commented Sep 27, 2023

Not sure if a possible "fix" that looks directly at the Mapping object that implements the hom to find the rows for which the hom is not defined is too janky, when the user calls incident with 0 as input. Something like using haskey and iterating over rows.

@slwu89
Copy link
Member Author

slwu89 commented Sep 28, 2023

@olynch and @epatters based off the zulip thread, I think we do desire for incident to retrieve indices of undefined elements, and that the computation should be done on the fly when called, for performance and consistency with the math.

Given that when the acset is pretty-printed, undefined elements are shown as 0, it's natural to want the incident(data_noidx, 0, :f) call to be the way the user asks for the indices of undef elements. But I guess there's a few ways to go from here.

  • Because the relevant method of incident called here is
    @inline function ACSetInterface.incident(acs::SimpleACSet, part, f::Symbol)
    preimage(dom_parts(acs, f), acs.subparts[f], part)
    end
    we could check here if part is 0 or not, and if so we could then send it off to preimage, maybe having a special method of preimage that dispatches on ::Val{0}, although I'm not sure if that's really advantageous for speed in this small case.
  • Can ignore it until we get to preimage and do the checking if the user passed 0 at this point.
  • Something else I can't think of.

What are your opinions on how to best make this work?

Note to self, check how getindex is converting invalid entries to 0s when using something like acs[:,:f] where f has invalid entries.

@kris-brown kris-brown added the bug Something isn't working label Sep 29, 2023
@kris-brown
Copy link
Collaborator

kris-brown commented Sep 29, 2023

I think that it would be straightforward to add a new method undefined_parts(my_acset, my_column_name) rather than try to make incident have different behavior when given 0. It's kind of an implementation detail that 0 is how we visualize undefined parts. Plus, incident is a high-performance/low-level function that we don't want to make more complicated.

@kris-brown kris-brown linked a pull request Oct 3, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants