SparseNDArray and SparseTensor.
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 20/100
- Issue 類型
- 功能
- 描述清晰度
- 需要釐清
- 活躍度
- 停滯
- 領域
- data, machine-learning
研究方向
從 java-ndarray 套件以及既有的 NdArray、DataBuffer 和 DataBufferWindow 語意開始,接著將 AbstractSparseNdArray 和 FloatSparseNdArray 與 SciPy COO 和 TensorFlow SparseTensor 進行比較。完成的要求是決定一種表示方式,並記錄索引、切片、部分座標和零值更新的行為。
由索引模型根據 Issue 內容生成。
描述
This may be a more appropriate issue for java-ndarray, but I thought I would kick off discussion here as it relates to SparseTensor.
@karl has asked that I explore setting up a SparseNDArray within java-ndarray, and I have done that partially, but I thought I would highlight some issues I am running up against.
I started writing a SparseNDArray under a new package (sparse) in java-ndarray.
A Sparse Array contains a dense shape, indices of coordinates as a LongNDArray, and a set of values as
U extends NdArray<T> array (e.g. FloatSparseNdArray would have a FloatNDArray for the values).
The indices would contain a set of coordinates in the dense shape space that would match non-zero values in the hypothetical dense array that the sparse array represents. The index of the matched coordinates would also be the index into the Values array for the corresponding value entry.
The indices shape is [N, ndims], where N is the number non-zero values, and ndims is the number of dimensions in the dense shape. The values shape is [N], or the number of non-zero values.
It is straight forward to create an AbstractSparseNdArray class and a subclass, e.g FloatSparseNdArray. It is also straight forward to get a value based on getObject using full coordinates. First do a binary search of the sorted indices and if the there is a match, return the corresponding value from the values ndarray, else return zero.
When doing the setObject commands it becomes a little more complicated. If it is changing one non-zero value to another non-zero value, then just change the corresponding entry in the values array. However, if the value changes from zero to non-zero, one has to add to the indices and values arrays. Likewise, if a value changes from non-zero to zero, it entails removing the corresponding entries in the indices and values. This, on the surface, creates a lot of objects, and we have already mentioned object creation as a problem in java-ndarray. (A work around for the non-zero to zero problem would be to just set the value in the values array to zero.)
Some other patterns in java-ndarray are very problematic.
For example,
- What does
parse.elements(dimensionIdx)mean? IsdimensionIdxequivalent to a row in the dense matrix? How do you iterate the elements? - How do you
slicethe sparse array? Presumably, there would have to be a window into the sparse array. In the existing NDArray classes this is done via aDataBufferandDataBufferWindowwhich are dense and do not apply to sparse. - What does
NdArray<T> get(long... coordinates)mean? How do you get an NDArray if you only provide partial coordinates? For partial coordinates, the concept of a higher dimension NDArray does not make sense unless it is converted to dense. - Same issue with
NdArray<T> set(NdArray<T> src, long... coordinates)( but one could walk the src array and pull out non-zero entires and make the internal modifications).
One option to deal with these issues is to make all or part of the sparse array dense when required, but doesn't that defeat the purpose of a sparse array?
In looking for how other packages deal with sparse matrices, an analogous class in SciPy, scipy.sparse.coo_matrix states:
scipy.sparse.coo_matrix
Disadvantages of the COO format
does not directly support:
arithmetic operations
slicing
It is also noteworthy, the the coo_matrix class is in the SciPy package and not in NumPy, so it is not constrained by NumPy.array semantics.
My first question is do we need all this complexity to represent a SparseTensor, or is there a simpler way to create it without dealing with all the ambiguities between Sparse and Dense in the java-ndarray package? This is what Python TF did with the SparseTensor class. In Python TF SparseTensor, the dense_shape, indices and values are Tensors that are passed to the tf.sparse low level APIs. The SparseTensor is a Tensor that is passed in higher level operations, but it is a first class Tensor.
I would appreciate any thoughts on this.
- 主要語言
- Java
- 星號
- 927
- 分支
- 227
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
tensorflow/java 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 65/100
tensorflow/java#653 · 1 則留言 · 4 個 reaction ·
-
難度 5/5 一週以上 新手友好度 25/100
tensorflow/java#621 · 4 則留言 ·
-
難度 5/5 一週以上 新手友好度 25/100
tensorflow/java#617 · 3 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 55/100
tensorflow/java#615 · 1 則留言 ·
-
難度 5/5 一週以上 新手友好度 25/100
tensorflow/java#614 · 1 則留言 ·
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
NationalSecurityAgency/ghidra#9748 ·
維護者通常 1 天內回覆
-
enhancement
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆
-
spring-mcp-tools
難度 2/5 1-3 小時 新手友好度 85/100
explyt/spring-plugin#591 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
jenkinsci/build-monitor-plugin#1367 ·
維護者通常 1 天內回覆
-
waiting-for-triage
難度 1/5 1 小時以內 新手友好度 72/100
spring-cloud/spring-cloud-openfeign#1443 ·
維護者通常 1 天內回覆