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 CSRMatrix #359

Merged
merged 2 commits into from
Jun 30, 2021
Merged

Conversation

angriman
Copy link
Member

@angriman angriman commented Jun 27, 2019

This adds a template parameter to the CSRMatrix class allowing to store generic data types. The class is renamed to CSRGeneralMatrix. Additional minor changes:

  • Remove ad-hoc implementation of binary search in favor of std::lower_bound
  • Add noexcept operator where applicable
  • Replace push_back with emplace_back where applicable (and addition of two new constructors for Triplet)

@angriman angriman force-pushed the refactor/CSRMatrix branch 2 times, most recently from b45faa6 to db7ba88 Compare June 28, 2019 14:10
Copy link
Contributor

@avdgrinten avdgrinten left a comment

Choose a reason for hiding this comment

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

LGTM now. I did not review the algorithm; I assume that they did not change except for changing double -> ValueType (?).

@avdgrinten avdgrinten self-requested a review June 28, 2019 14:52
@angriman angriman force-pushed the refactor/CSRMatrix branch 4 times, most recently from f11c992 to 8be5f46 Compare June 30, 2019 10:16
@avdgrinten
Copy link
Contributor

Why does the code break with an earlier version of Clang? We should not increase the version of Clang without a good reason. People who want run NetworKit on clusters that they do not control might not have the option to upgrade Clang.

@angriman
Copy link
Member Author

The build fails with clang 3.8 because of this error:

/home/travis/build/networkit/networkit/include/networkit/algebraic/CSRGeneralMatrix.hpp:1231:10: error: 
      definition with same mangled name as another definition
    void forNonZeroElementsInRow(index row, L handle) const {
         ^
/home/travis/build/networkit/networkit/include/networkit/algebraic/CSRGeneralMatrix.hpp:1231:10: note: 
      previous definition is here

I searched for this error and did not find much apart this page. It could be a bug in clang 3.8 but I am not sure about that. Do you have some other solutions in mind?

@angriman
Copy link
Member Author

angriman commented Jul 4, 2019

Moving forNonZeroElementsInRow somewhere else in the class did not solve the issue, I still get the same error. Shall we switch to clang 3.9?

@angriman angriman force-pushed the refactor/CSRMatrix branch 2 times, most recently from 7421696 to 1e247b0 Compare July 13, 2019 22:38
@angriman angriman mentioned this pull request Mar 4, 2020
@fabratu fabratu changed the base branch from Dev to master May 29, 2020 16:54
@angriman angriman force-pushed the refactor/CSRMatrix branch 2 times, most recently from dca2088 to ede57c6 Compare March 9, 2021 16:13
@angriman
Copy link
Member Author

Now that we raised the minimum supported clang version to 3.9 this PR can be reviewed.

@angriman angriman force-pushed the refactor/CSRMatrix branch 2 times, most recently from 10efc2b to 89744e7 Compare April 19, 2021 07:48
fabratu
fabratu previously approved these changes Apr 19, 2021
Copy link
Member

@fabratu fabratu left a comment

Choose a reason for hiding this comment

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

LGTM.

@angriman
Copy link
Member Author

We also need approval from @avdgrinten.

Copy link
Contributor

@avdgrinten avdgrinten left a comment

Choose a reason for hiding this comment

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

I have one comment below.

As a side note: a few algorithms are really inefficient here, for example setValue(). There is no way to implement setValue() well for CSR, so why does the class provide it at all?

@angriman
Copy link
Member Author

I agree that there are several inefficiencies in this class that should be fixed, I already fixed a trivial one in the last commit. However, I think that fixing those inefficiencies is out of the scope of this PR and it should be done on a separate PR.

@hmeyerhenke
Copy link

Not sure that setValue() is really obsolete. But the docs should be clear about the inherent inefficiency. Other -- unnecessary -- inefficiencies should be addressed. This is rather old code that has not been touched for quite some time, I believe.

@hmeyerhenke
Copy link

But I leave it up to you guys if they are addressed in this PR or separately.

@avdgrinten
Copy link
Contributor

It's not necessarily the case that the code is inefficient due to the implementation but it just provides tons of operations that you really would not use if you want your code to be fast (setting values, getting individual values, extracting columns, etc.). These operations are simply not fast because CSR cannot implement them in a fast way.

@hmeyerhenke
Copy link

I know @avdgrinten. Such operations should not be the preferred way to do things, I completely agree. But there may be cases where they are simply necessary. We can make a decision, though, that we do not want to support such cases. But that's a decision I'd like to be involved in and should follow from a comprehensive discussion of use cases.

@angriman
Copy link
Member Author

It might be a good idea to open a new issue/discussion about that.

@angriman
Copy link
Member Author

angriman commented Apr 22, 2021

Are there any other issues that need to be addressed in this PR?

@angriman angriman force-pushed the refactor/CSRMatrix branch 2 times, most recently from da33d2a to 07b16b6 Compare May 31, 2021 14:00
Comment on lines 22 to 25

Triplet() = default;

Triplet(index row, index column, double value) : row(row), column(column), value(value) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change done?

Comment on lines 243 to 244
/** Default destructor */
virtual ~CSRGeneralMatrix() = default;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this destructor virtual? Does the class have any virtual methods?

}
}

#ifndef NDEBUG
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be gated behind the sanity check macros, right?. Seems to be an expensive check.

/**
* @return Number of rows.
*/
inline count numberOfRows() const noexcept { return nRows; }
Copy link
Contributor

Choose a reason for hiding this comment

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

inline is redundant if a method is defined within class { ... } or struct { ... }.

triplets.push_back({i, j, result});
triplets.emplace_back(i, j, result);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I do not change this then the clang-tidy build fails due to modernize-use-emplace.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why doesn't clang-tidy fail right now?

triples.push_back({k, coarseIndex[j], w});
triples.emplace_back(k, coarseIndex[j], w);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change?

triplets.push_back({i, j, value});
triplets.emplace_back(i, j, value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change?

triplets.push_back({i,j,val});
triplets.emplace_back(i,j,val);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change?

triplets.push_back({i,j,value});
triplets.emplace_back(i,j,value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change?

triplets.push_back({v, j, dist[v]});
triplets.emplace_back(v, j, dist[v]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change?

@angriman angriman force-pushed the refactor/CSRMatrix branch 3 times, most recently from 26e5a2b to b5cd845 Compare June 17, 2021 08:37
@angriman
Copy link
Member Author

I addressed the comments, the emplace_back were not really necessary, so I removed them.

Copy link
Contributor

@avdgrinten avdgrinten left a comment

Choose a reason for hiding this comment

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

LGTM now.

@avdgrinten avdgrinten merged commit 0353e6c into networkit:master Jun 30, 2021
@avdgrinten avdgrinten deleted the refactor/CSRMatrix branch June 30, 2021 08:45
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.

None yet

4 participants