-
Notifications
You must be signed in to change notification settings - Fork 0
add option for writable off-diagonal elements #4
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
base: master
Are you sure you want to change the base?
Conversation
c249450
to
d599889
Compare
I've been thinking of the reason why the type in Perhaps a solution then is to create a view of the matrix that is just the upper or lower triangle. Now it is perfectly valid to iterate over this triangle and mutate it. |
not being able to set off diagonal elements is frequently raised as an issue. see e.g. JuliaLang/julia#43818 from just 5 days ago. your logic to not permit this is the reason it was decided against. see JuliaLang/julia#33071 (comment) what i'm proposing here is to allow the user flexibility in choosing to permit it or not. there are use cases where it is desirable i imagine. and not being able to do so just seems strange to me. if you wanted to iterated over just the triangle, you can simply reach into the struct and iterate over the field 'tri'. if this were commonly desired, creating an interface to do that would be best. most importantly, what do you think of using a value type to parameterize whether the off diagonal elements are writeable? the alternative is to create two types. |
d599889
to
071fa65
Compare
Yes, but Simply adding a I think the read-write interface should be a |
Yes, but that describes an upper triangular matrix. I just want a triangle. It should not represent a matrix.
|
6b7a2ac
to
a908153
Compare
a908153
to
4d8f984
Compare
6ab5476
to
2e6a6f9
Compare
4d8f984
to
0ee1379
Compare
0ee1379
to
f3d0e50
Compare
Is there a lazy iterator for this sequence?
|
f3d0e50
to
10a0b9a
Compare
@bjarthur Do you have any thoughts about changing iteration when you turn on RW mode? If |
For a lazy iterator, here's what have so far: julia> struct TriangleIndices{N}
dims::Dims{N}
end
julia> Base.iterate(TI::TriangleIndices{N}) where N = (t = CartesianIndex(ntuple(i->1, N)); (t,t))
julia> function Base.iterate(TI::TriangleIndices{N}, state) where N
out = nothing
for d in 1:N
n = state[d] + 1
if n <= TI.dims[d] && (d == N) || n <= state[N]
out = ntuple(i-> i < d ? 1 :
i == d ? n :
state[i],
N)
break
end
if d == N
return nothing
end
end
out = CartesianIndex(out)
return (out, out)
end
julia> ti = TriangleIndices(4,4)
TriangleIndices{2}((4, 4))
julia> for i in ti
println(i)
end
CartesianIndex(1, 1)
CartesianIndex(1, 2)
CartesianIndex(2, 2)
CartesianIndex(1, 3)
CartesianIndex(2, 3)
CartesianIndex(3, 3)
CartesianIndex(1, 4)
CartesianIndex(2, 4)
CartesianIndex(3, 4)
CartesianIndex(4, 4) |
Any progress on this? I wanted to use this package specifically to populate a symmetric matrix, but this ability is explicitly blocked: SymmetricFormats.jl/src/SymmetricFormats.jl Line 119 in 5d602ee
Seems like the actual code supports setting non-diagonal elements: SymmetricFormats.jl/src/SymmetricFormats.jl Lines 121 to 127 in 5d602ee
Allowing setting non-diagonal entries could greatly simplify populating symmetric matrices and reduce storage of kernel matrices, for example. I could just do: N = 100 # observations
K = SymmetricPacked(N, N) # also, why not have this constructor?
for n in 1:N, m in n:N
K[n, m] = @views kernel(X[n, :], X[m, :])
end This would let me store just the upper diagonal, while the |
@mkitti this is the first time i've used value types. can you please review?
the idea is that
LinearAlgebra.Symmetric
does not allow the off diagonal elements to be set, and so neither should the defaultPackedArrays.SymmetricPacked
. but some might want this so add it as an option.