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

should users know about similar? #1940

Open
thofma opened this issue Dec 20, 2024 · 3 comments
Open

should users know about similar? #1940

thofma opened this issue Dec 20, 2024 · 3 comments

Comments

@thofma
Copy link
Member

thofma commented Dec 20, 2024

julia> b = matrix(ZZ, 2, 2, [i for i in 1:4])
[1   2]
[3   4]

julia> c = similar(b)
[#undef   #undef]
[#undef   #undef]

julia> c == c
ERROR: UndefRefError: access to undefined reference

I don't feel too comfortable that a user-facing function produces illegal (useless for most purposes) matrices. I understand the Base array has the same "feature", but our matrices should be mathematical things, where this seems problematic for a user.

@thofma thofma changed the title similar should not produce illegal matrices should users know about similar? Dec 20, 2024
@fieker
Copy link
Contributor

fieker commented Dec 20, 2024 via email

@fingolfin
Copy link
Member

So yeah, this was/is intentional -- matching precisely what Julia does.

My view is this: the function similar is for developers who know what they are doing. The docstring has stated "Create an uninitialized matrix" for years.

I don't understand why this should be a problem either: Regular users won't use similar, they won't even know about it. They'll use things like zero_matrix, identity_matrix, zero, one etc. to get new matrices.

@thofma
Copy link
Member Author

thofma commented Dec 23, 2024

My original phrasing was not optimal and I have reformulated it. I don't mind that this functionality exists. But in my opinion, the whole notion of uninitialized entries should not be made part of the API of matrices. Unfortunately we are doing this by overloading the "public" method similar, including adding documentation. The docstring is also not correct, since the matrix is not always "uninitialized".

(For julia Arrays this notion makes sense to me, since it is just a container of a specific shape, which may or may not have entries.)

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