-
Notifications
You must be signed in to change notification settings - Fork 69
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
Implement hasVertexP and hasEdgeP #135
base: main
Are you sure you want to change the base?
Conversation
@jmtd Cool, thank you! I like how nicely it all worked out. There seem to be a performance regression for
While 1.17 may just be noise, 1.66 feels like a proper regression, likely due to the missing Performace regression is reported by our CI infrastructure on every commit, so if you push any fixes you should be able to see the results in the https://travis-ci.org/snowleopard/alga/jobs/446759541 Further things to do:
|
Hi,
The two are proper regression in this case :) About the The problem is that The solution is to add an
Maybe lazyness can help preventing a performance drop, but I am not sure. |
Predicate versions of hasVertex and hasEdge. Re-implement hasVertex and hasEdge in terms of the predicate versions.
Thanks Alexandre Moine!
Adding (There is still this strange result @jmtd Could you try the following? {-# INLINE [1] findVertices #-}
findVertices :: (a -> Bool) -> Graph a -> [a]
findVertices p = foldg [] [ x | p x ] (++) (++)
hasVertex :: Eq a => a -> Graph a -> Bool
hasVertex x = not . null $ findVertices (== x) I'm interested to see whether this will be as fast as your implementation via |
Hi @snowleopard
I think there must be a typo in the list comprehension here, my GHCI doesn't like it either, or perhaps I need to load a language extension? |
@jmtd Oh, I'm sorry, I meant: findVertices p = foldg [] (\x -> [ x | p x ]) (++) (++) |
re-implement hasVertex in terms of findVertices
NP. I've just pushed that, let's see what the performance is like. I'd quite like to reproduce the performance measurement stuff locally (to avoid round-tripping github PRs to test things). I should perhaps also take a look at Stack if I'm spring-cleaning my setup. I'm working on a |
As an aside, would you like PRs to add things like |
Required by the implementation of `box`
Results for
|
@jmtd Thanks for giving it a try. I suggest we proceed as follows. Let's keep the findVertices :: ToGraph g => (ToVertex g -> Bool) -> g -> [ToVertex g]
findVertices p = foldg [] (\x -> [ x | p x ]) (++) (++) With this approach other instances of the Also, I'd like to understand your use case a bit better: how do you plan to use these functions? Merely checking if a vertex with the right properties exist (using My understanding is that you actually want to write some sort of graph transformation function that, for example, turns merges all edges that satisfy a given property into a vertex. Could you provide some more details? Otherwise, I worry that we might end up providing too many functions with similar looking functionality, hence confusing Alga users: |
@snowleopard wrote:
That's right. Here's an example of a graph rewrite rule, coded in a string, using composition to represent the flow of the stream data
We have stream graphs coded up using Graph and and ADT like the following
What I am hoping to do is encode the stream rules using a similar ADT to the above instead of strings (so probably make the parameters argument a type variable and re-use the above), then apply rules to instances of All the rules I am working with at the moment are derived from analysing operators pair-wise, and generally swap the order of two operators, but also change their parameters; so from a Graph POV adding and removing both edges and nodes. More complex rewrite rules could involve introducing more nodes and consequently edges. We don't currently label edges, but direction is important. |
@jmtd Thanks! Let me think about this for a few days. I'm travelling until 11 November, so it's a bit difficult to find time to figure out a small set of graph transformation primitives that will be useful both for your problem and for other users of the library. |
Thanks @snowleopard. I'm going to see what PoC I can build on top of these primitives to further assess how this all might work for me. |
This is an initial PR for hasVertexP and hasEdgeP - predicate variants of hasVertex and hasEdge (reimplemented in terms of the predicate versions). (the latter of which will be useful for some rewriting work I hope to build on top of Algebra.Graph).
I've only looked at the code so far; on my todo list is at least