should users know about `similar`?
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.
On Fri, Dec 20, 2024 at 03:31:08AM -0800, Tommy Hofmann wrote:
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 referenceIf this is not a bug but on purpose, I propose that we change it back. I don't think we should have any user-facing function producing illegal matrix objects.
Here of course, this is trivial. But how do I get an non-initialized matrix (to save time)? generically?
-- Reply to this email directly or view it on GitHub: https://github.com/Nemocas/AbstractAlgebra.jl/issues/1940 You are receiving this because you are subscribed to this thread.
Message ID: @.***>
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.
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.)