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

refactor: consolidate graph.incidence.* (#1483) #1654

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

schochastics
Copy link
Contributor

@schochastics schochastics commented Jan 9, 2025

This PR removes (nested) for loops for graph.incidence.dense() when weighted = TRUE

(cherry picked commits from #1518)

This PR removes graph.incidence.sparse() and graph.incidence.dense() and replaces it with a general graph.incidence.build() and more specialized helper functions.

Copy link
Contributor

aviator-app bot commented Jan 9, 2025

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This pull request is currently open (not queued).

How to merge

To merge this PR, comment /aviator merge or add the mergequeue label.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@schochastics schochastics changed the title removed for loops in graph.incidence.dense (#1483) refactor: removed for loops in graph.incidence.dense (#1483) Jan 9, 2025
@schochastics
Copy link
Contributor Author

schochastics commented Jan 9, 2025

not sure why it fails but I am checking it.
I think I switched from row-first to column-first in the output.

@schochastics schochastics requested a review from krlmlr January 10, 2025 10:22
Copy link
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Overall, the code doesn't seem to be well-prepared for the edge case of one-row matrices, we might need drop = TRUE in several places.

Could we perhaps forward to graph.incidence.sparse() in this case, perhaps even change graph.incidence.sparse() to accept both sparse and dense matrices? A lot of code there looks similar to what we have here.

R/incidence.R Outdated Show resolved Hide resolved
R/incidence.R Outdated Show resolved Hide resolved
R/incidence.R Outdated Show resolved Hide resolved
R/incidence.R Outdated Show resolved Hide resolved
@schochastics
Copy link
Contributor Author

Yes I now realize that I borrowed the logic from the sparse function and simply adapted where needed for the dense case. Thats not optimal. I think I can refactor both *.sparse() and *.dense() into one function.

@schochastics schochastics marked this pull request as draft January 14, 2025 20:56
@schochastics schochastics changed the title refactor: removed for loops in graph.incidence.dense (#1483) refactor: consolidate graph.incidence.* (#1483) Jan 14, 2025
@schochastics
Copy link
Contributor Author

The logic is now completely rewritten. There are no dedicated graph.incidence.sparse and graph.incidence.dense anymore since there was a lot of code duplication. Helper functions are now disjoint and there is no duplication of code anymore

@schochastics schochastics requested a review from krlmlr January 15, 2025 08:51
@szhorvat
Copy link
Member

@schochastics I haven't been able to follow what's going on with the "incidence" (bipartite adjacency) matrix work, as I'm overwhelmed with other work at the moment. Do you think it would be good to have a short video meeting to discuss how the C library handled bipartite incidence matrices, so that when the R package finally starts using this functionality, the behaviour wouldn't change? I.e., just make sure that whatever's implemented in pure R now matches the C behaviour.

@schochastics
Copy link
Contributor Author

@szhorvat Happy to do so. I sent you an email

@schochastics
Copy link
Contributor Author

This PR can be reviewed now

Copy link
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this might need yet another iteration or two.

R/incidence.R Outdated Show resolved Hide resolved
R/incidence.R Outdated Show resolved Hide resolved
R/incidence.R Outdated Show resolved Hide resolved
@schochastics
Copy link
Contributor Author

schochastics commented Jan 16, 2025

@krlmlr ready to be reviewed again

@schochastics schochastics marked this pull request as ready for review January 18, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants