Skip to content

Conversation

wrcorcoran
Copy link

#455 - Define pow function for graph matrices

  • Implemented pow functionality for adjacency and transition matrices (powAdjMatrix and powTransitionMatrix, respectively).
    @ZigRazor @sbaldu

namespace CXXGraph {

template <typename T>
const PowAdjResult Graph<T>::powAdjMatrix(unsigned int k) const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why two specific methods? I think that one method overloaded two times would be better.

Copy link
Author

Choose a reason for hiding this comment

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

Okay! I'll just have the user pass an enum value to distinguish. Or, would you prefer they pass the actual matrices themselves to the function? I just want to make sure I'm being consistent with the rest of the repo's style.

Copy link
Author

@wrcorcoran wrcorcoran Aug 22, 2024

Choose a reason for hiding this comment

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

virtual const PowAdjResult matrixPow(unsigned int k, AdjacencyMatrix adj) const
with usage like:
graph.matrixPow(2, graph.getAdjMatrix());

This feels wrong to me... should I make a function w/ is not a member of the CXXGraph class? That also feels wrong...

What kind of overloading are you thinking?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi, sorry for the delay, I'm very busy these weeks. For me the best thing would be to implement them as free functions, not as Graph methods. But we can hear what @ZigRazor thinks.

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good! No worries!

Copy link
Author

Choose a reason for hiding this comment

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

Hey @ZigRazor
Just following up here - would like to get this wrapped up soon! Thoughts on implementing this as a free function?

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry for the delay.
Yes, the best choice for me is to implement them as a free functions.
Thank you

std::vector<std::vector<T>> res(n, std::vector<T>(n, 0));

// build identity matrix
for (int i = 0; i < n; i++) res[i][i] = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would use a standard algorithm for this, like std::transform, std::fill or std::generate

Copy link

codecov bot commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 98.97436% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.89%. Comparing base (564a8c0) to head (0f1de02).

Files with missing lines Patch % Lines
include/CXXGraph/Graph/Algorithm/Pow_impl.hpp 97.40% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #463      +/-   ##
==========================================
+ Coverage   97.87%   97.89%   +0.02%     
==========================================
  Files          87       89       +2     
  Lines       10079    10274     +195     
  Branches      670      687      +17     
==========================================
+ Hits         9865    10058     +193     
- Misses        214      216       +2     
Flag Coverage Δ
unittests 97.89% <98.97%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wrcorcoran wrcorcoran requested a review from ZigRazor September 16, 2024 02:17
@ZigRazor ZigRazor linked an issue Jun 26, 2025 that may be closed by this pull request
@ZigRazor
Copy link
Owner

@wrcorcoran this pull request seems good, but the workflow does not compile, can you check why?

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.

Define pow function for graph matrices
3 participants