Skip to content

Commit c3bc6ed

Browse files
committed
Add tentative SparseTensor format
1 parent 090a8c0 commit c3bc6ed

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

format/Message.fbs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
include "Schema.fbs";
1919
include "Tensor.fbs";
20+
include "SparseTensor.fbs";
2021

2122
namespace org.apache.arrow.flatbuf;
2223

@@ -87,7 +88,7 @@ table DictionaryBatch {
8788
/// which may include experimental metadata types. For maximum compatibility,
8889
/// it is best to send data using RecordBatch
8990
union MessageHeader {
90-
Schema, DictionaryBatch, RecordBatch, Tensor
91+
Schema, DictionaryBatch, RecordBatch, Tensor, SparseTensor
9192
}
9293

9394
table Message {
@@ -96,4 +97,4 @@ table Message {
9697
bodyLength: long;
9798
}
9899

99-
root_type Message;
100+
root_type Message;

format/SparseTensor.fbs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
include "Tensor.fbs"
2+
3+
namespace org.apache.arrow.flatbuf;
4+
5+
/// Coodinate format.
6+
table SparseTensorIndexCOO {
7+
/// COO's index list are represented as a NxM matrix,
8+
/// where N is the number of non-zero values,
9+
/// and M is the number of dimensions of a sparse tensor.
10+
/// indicesBuffer stores the location and size of this index matrix.
11+
/// The type of index value is long, so the stride for the index matrix is unnecessary.
12+
indicesBuffer: Buffer
13+
};
14+
15+
/// Compressed Sparse Row format, that is matrix-specific.
16+
table SparseMatrixIndexCSR {
17+
/// This array represents the range of the rows.
18+
/// The ith row spans from indptr[i] to indptr[i+1] in the data.
19+
/// The length of this array is 1 + (the number of rows).
20+
indptr: [long]
21+
22+
/// indicesBuffer stores the location and size of the array that
23+
/// contains the column indices of the corresponding non-zero values.
24+
/// The type of index value is long.
25+
indicesBuffer: Buffer
26+
};
27+
28+
union SparseTensorIndex {
29+
SparseTensorIndexCOO,
30+
SparseMatrixIndexCSR
31+
};
32+
33+
table SparseTensor {
34+
/// The type of data contained in a value cell.
35+
/// Currently only fixed-width value types are supported,
36+
/// no strings or nested types.
37+
type: Type;
38+
39+
/// The dimensions of the tensor, optionally named.
40+
shape: [TensorDim];
41+
42+
/// The number of non-zero values in a sparse tensor.
43+
length: long
44+
45+
/// Sparse tensor index
46+
sparseIndex: SparseTensorIndex;
47+
48+
/// The location and size of the tensor's data
49+
data: Buffer;
50+
}
51+
52+
root_type SparseTensor;

0 commit comments

Comments
 (0)