Idea: Add immutable diagonal matrix view with O(n) space #1500
Waterdragen
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Thank you for the idea! I am particularly curious to know whether you ran across a use case for this in your own work, or whether this is driven more by curiosity. Right now, |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Current state
Currently,
ndarray
provides:Array2::from_diag
: Create a mutable 2D array from a vectorArray2::from_diag_elem
: Create a mutable 2D array with repeated diagonal elementsArray.diag()
: Make a view of the diagonal elements of the ndarrayProblem
However, the mutability might not be needed, in this case, only the diagonal elements are non-zero, thus we only need O(n) space. Using a large
Array
might waste a lot of space.Possible use case
Let's call the new struct
DiagArray
, and since it can represent diagonal arrays of any dimension, we have to specify the dimensions. Here is a possible use case:Unresolved questions
Array2
hasfrom_diag
, do we really need diagonal arrays for all dimensions?Beta Was this translation helpful? Give feedback.
All reactions