Skip to content

Conversation

LecrisUT
Copy link
Collaborator

@LecrisUT LecrisUT commented Mar 3, 2023

I think this is no longer necessary

@codecov-commenter
Copy link

codecov-commenter commented Mar 3, 2023

Codecov Report

Patch coverage: 88.65% and project coverage change: +0.02 🎉

Comparison is base (3681a8a) 85.69% compared to head (493eeea) 85.72%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #258      +/-   ##
===========================================
+ Coverage    85.69%   85.72%   +0.02%     
===========================================
  Files           23       23              
  Lines         6069     6079      +10     
===========================================
+ Hits          5201     5211      +10     
  Misses         868      868              
Flag Coverage Δ
c_api 73.68% <82.47%> (-0.03%) ⬇️
fortran_api 37.39% <55.67%> (+0.02%) ⬆️
python_api 82.87% <80.41%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
src/overlap.c 93.20% <ø> (+0.23%) ⬆️
src/site_symmetry.c 97.95% <ø> (ø)
src/spin.c 91.88% <ø> (ø)
src/spglib.c 73.00% <70.58%> (+0.09%) ⬆️
src/delaunay.c 89.13% <75.00%> (ø)
src/symmetry.c 80.70% <83.33%> (ø)
src/pointgroup.c 76.94% <91.66%> (ø)
src/mathfunc.c 89.31% <92.00%> (-0.05%) ⬇️
src/refinement.c 84.85% <93.33%> (+0.02%) ⬆️
src/cell.c 79.48% <100.00%> (ø)
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@LecrisUT LecrisUT mentioned this pull request Mar 3, 2023
@atztogo
Copy link
Collaborator

atztogo commented Mar 3, 2023

SPGCONST implies const, but const emits warning. I made it easy-to-read the code. Do you have a better idea?

@LecrisUT
Copy link
Collaborator Author

LecrisUT commented Mar 3, 2023

Oh, it is supposed to be the other way around, I'll test to see what warning it throws

@atztogo
Copy link
Collaborator

atztogo commented Mar 3, 2023

It is something like "incompatible pointer type".

I'm sorry for badly written codes. Spglib code was maintained almost alone for long time, so it was enough if I understand it. But now I should explain more about details.

@LecrisUT
Copy link
Collaborator Author

LecrisUT commented Mar 3, 2023

Ok, this one is an issue:
tmat here is marked as SPGCONST:

Cell *msg_get_transformed_cell(const Cell *cell, SPGCONST double tmat[3][3],

But it call mat_inverse_matrix_d3 which changes it:
mat_inverse_matrix_d3(tmat, (*ref_sg)->bravais_lattice, 0);

int mat_inverse_matrix_d3(double m[3][3], SPGCONST double a[3][3],

So it is indeed an implementation error that should be fixed. I.e. copy it if you want to edit it.

@LecrisUT
Copy link
Collaborator Author

LecrisUT commented Mar 3, 2023

spglib/src/mathfunc.c

Lines 268 to 289 in 1d17e5e

int mat_inverse_matrix_d3(double m[3][3], SPGCONST double a[3][3],
const double precision) {
double det;
double c[3][3];
det = mat_get_determinant_d3(a);
if (mat_Dabs(det) < precision) {
warning_print("spglib: No inverse matrix (det=%f)\n", det);
return 0;
}
c[0][0] = (a[1][1] * a[2][2] - a[1][2] * a[2][1]) / det;
c[1][0] = (a[1][2] * a[2][0] - a[1][0] * a[2][2]) / det;
c[2][0] = (a[1][0] * a[2][1] - a[1][1] * a[2][0]) / det;
c[0][1] = (a[2][1] * a[0][2] - a[2][2] * a[0][1]) / det;
c[1][1] = (a[2][2] * a[0][0] - a[2][0] * a[0][2]) / det;
c[2][1] = (a[2][0] * a[0][1] - a[2][1] * a[0][0]) / det;
c[0][2] = (a[0][1] * a[1][2] - a[0][2] * a[1][1]) / det;
c[1][2] = (a[0][2] * a[1][0] - a[0][0] * a[1][2]) / det;
c[2][2] = (a[0][0] * a[1][1] - a[0][1] * a[1][0]) / det;
mat_copy_matrix_d3(m, c);
return 1;
}

You don't need to save to a temporary array c here. The intent of m is always to be overwritten, and you don't use it anywhere else.

I think most of these issues can be resolved, it just needs a bit of working through to detangle the intents. Some doxygen comments would help, even if it is internal. Just what are each argument meant to be.

Oh, you're allowing for operations on the same pointer like mat_inverse_matrix_d3(a,a)

@LecrisUT
Copy link
Collaborator Author

LecrisUT commented Mar 4, 2023

Note that there are a lot of redundant func(const double variable). variable is always passed by value. const is only meant to be used for pointers and references to guarantee the function caller that it is not editted. When you pass by value, it is copies, so it becomes meaningless in that regard. Use func(double variable). Use something like CLion to automatically detect and correct these issues.

Anyway, there were only 4 spots that needed fixing, excluding the thousands of meaningless func(const double variable).

@atztogo
Copy link
Collaborator

atztogo commented Mar 4, 2023

Note that there are a lot of redundant func(const double variable). variable is always passed by value. const is only meant to be used for pointers and references to guarantee the function caller that it is not editted.

Indeed! I tend to use const to remember the variable not to be changed in the function. But you are correct. It should be fixed.

@atztogo
Copy link
Collaborator

atztogo commented Mar 4, 2023

Oh, you're allowing for operations on the same pointer like mat_inverse_matrix_d3(a,a)

This can happen. So I think it is safe to write in this way, but I don't mean this is the best way.

@LecrisUT
Copy link
Collaborator Author

LecrisUT commented Mar 4, 2023

Indeed. To be honest I don't know of an elegant way to do it without C++ templates, and otherwise if the non-copy is worth it for a 3x3 matrix. I would do it on my codes just for the designing exercise

@LecrisUT LecrisUT added the enhancement Significant ehancements label Mar 4, 2023
@LecrisUT
Copy link
Collaborator Author

LecrisUT commented Mar 4, 2023

Rminder: if we merge #257 I need to add some words there.

With regards to versioning, I don't think it is that severe since there was an indication of the intent, we just might have allowed people to shoot themselves in the foot. I don't think we need to increase a major just for this. As long as the bindings are correctly configured also

LecrisUT added 2 commits April 5, 2023 09:32
Should be `const`

Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
@LecrisUT LecrisUT requested review from atztogo and lan496 April 6, 2023 14:12
@LecrisUT
Copy link
Collaborator Author

LecrisUT commented Apr 6, 2023

We should merge this soon, the const is not enforced in the current state.

@LecrisUT LecrisUT changed the title Remove SPGCONST Change SPGCONST to const Apr 6, 2023
Copy link
Collaborator

@atztogo atztogo left a comment

Choose a reason for hiding this comment

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

Great. Thanks @LecrisUT!

@LecrisUT LecrisUT merged commit 77a8e5d into spglib:develop Apr 13, 2023
@LecrisUT LecrisUT deleted the remove-spgconst branch June 8, 2023 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Significant ehancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants