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

Inconsistent casting among the elements of a list may result in wrong results #3792

Closed
tnguyenh opened this issue Apr 25, 2023 · 2 comments
Closed

Comments

@tnguyenh
Copy link
Collaborator

Describe the bug
Currently, the type of the elements of a list or a matrix are based on the first element. However, some containers may have several different but compatible types (int and float). A non-aware user may mix them and get wrong results, and without being able to understand that it comes from different types being used. For example, consider those three lines:

write determinant(matrix([[1.0,0.0],[1.0,0.2]]));
write determinant(matrix([[1,0],[1,0.2]]));
write determinant(matrix([[1.0,0],[1,0.2]]));

the result obtained is

0.2
0.0
0.2

The first and third lines provide the good result. The second one provides a wrong result since all the elements are casted to the type of the first element, which is int. However, it is probably the most natural way to write the matrix, since people don't bother with the ".0" when not needed. What is more confusing is that when writing something like "float a <- 1", there is a warning telling that 1 will be casted to float, and here not, so there is no way for a common user to have a clue about a possible error in the result.

I label this as a bug, since a regular user would think that not having the correct result using a determinant is a bug.

@tnguyenh tnguyenh added the 😱 Bug The issue reveals a bug in GAMA label Apr 25, 2023
@AlexisDrogoul AlexisDrogoul removed the 😱 Bug The issue reveals a bug in GAMA label Apr 25, 2023
@AlexisDrogoul
Copy link
Member

Hi,

I wouldn't label this as a bug, because it is clearly the responsibility of the user to force the type when he/she "doesn't bother" writing float elements with a decimal but still wants a matrix<float>. For instance, he/she can use :

write determinant(matrix<float>([[1,0],[1,0.2]]));

Otherwise, we can always use a more expensive determination of the type, but that would be more of an enhancement. What do you think ?

@lesquoyb
Copy link
Collaborator

I think if you write:

let m <- matrix([ [1], [2.0] ]);

It would be natural for most that m is a matrix of float, so to me it's more a bug (marginal one, but still)

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

3 participants