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

Consistent rounding in adjacency matrix functions #2579

Open
szhorvat opened this issue Apr 18, 2024 · 3 comments
Open

Consistent rounding in adjacency matrix functions #2579

szhorvat opened this issue Apr 18, 2024 · 3 comments
Milestone

Comments

@szhorvat
Copy link
Member

Rounding should work consistently and identically in adjacency matrix functions.

There is currently a difference in rounding behaviour between igraph_adjacency() and igraph_biadjacency(). Only the latter uses ceil().

@szhorvat szhorvat added this to the 1.0 milestone Apr 18, 2024
@szhorvat
Copy link
Member Author

Decisions to be made:

  1. Do we guarantee any sort of behaviour at all when some entries are not integers? It is tempting not to, as it simplifies things and makes efficient implementations easier.
  2. Do we issue a warning or error if there's a non-integer matrix entry?
  3. Do we round using ceil(), floor(), round(), trunc() or plain cast (which I believe is equivalent to trunc())? Currently, igraph_adjacency() does a plain cast (not documented) and igraph_biadjacency() uses ceil() (documented). Note that ceil(), floor() and round() are slow while trunc()/cast are fast (by a large margin).
  4. When operating together lower/upper triangular elements, do we round before or after the operation? Currently it's done before.

@szhorvat
Copy link
Member Author

My suggestions:

  1. Guarantee a behaviour, but prioritize integer values. I.e. don't try to implement a "nice" behaviour for non-integer.
  2. No strong opinion, leaning towards a warning (or not checking at all).
  3. Use a plain cast, which is equivalent to trunc(). GCC/Clang generate the same code for trunc() and a cast. MSVC still generates a call to trunc(), which is likely much slower. This will be a breaking change for igraph_biadjacency(), but it brings consistency with igraph_adjacency().
  4. There is no explicit addition here, round before.

@ntamas
Copy link
Member

ntamas commented Apr 19, 2024

  1. Agreed
  2. A warning would be nice.
  3. I don't think the performance implictions are significant here, except for maybe sparse matrices. Plain cast is okay for me.
  4. Whichever is easiest to do in code, there's no real significance. If we round after, then it's only one operation instead of two, but it might complicate the code and there's no reason for micro-optimization here.

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

No branches or pull requests

2 participants