Skip to content

Instantly share code, notes, and snippets.

@kurtbrose
Last active April 17, 2019 00:21
Show Gist options
  • Save kurtbrose/1b56f927760f7022cc8c41703a3185cc to your computer and use it in GitHub Desktop.
Save kurtbrose/1b56f927760f7022cc8c41703a3185cc to your computer and use it in GitHub Desktop.
playing with relativity APIs
m2m = M2M()
ch = M2MChain()
gr = M2MGraph()
# TRANSFORMING BETWEEN TYPES
chain(*ch.m2ms) # kind of a copy
chain(ch) # also results in copy
chain(ch.m2ms[1:]) # slices off left column
gr.chain(col1, col2, col3) # returns a chain
gr.star(col1, col2, col3) # returns M2MStar of 1-?2, 1->3
# "public" m2ms -- note this might be problematic b/c assignments
# to these data structures can screw up internal state
gr.m2ms[col1, col2] # selecting M2M out of internal dict
ch.m2ms[1] # selecting M2M out of internal list
# chain is a bit weird in that __getitem__ and __setitem__
# are not in sync with __iter__ -- [] accesses M2Ms, iter()
# goes "row-wise" down
# current iteration of chain
for row in chain:
pass
# alternatives
for row in chain.tuples():
pass
for row in chain.iter_tuples():
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment