@@ -23,6 +23,9 @@ include "Schema.fbs";
2323
2424namespace org.apache.arrow.flatbuf;
2525
26+ /// ----------------------------------------------------------------------
27+ /// Data structures for dense tensors
28+
2629/// Shape data for a single axis in a tensor
2730table TensorDim {
2831 /// Length of dimension
@@ -48,3 +51,96 @@ table Tensor {
4851}
4952
5053root_type Tensor;
54+
55+ /// ----------------------------------------------------------------------
56+ /// Data structures for sparse tensors
57+
58+ /// Coodinate format of sparse tensor index.
59+ table SparseTensorIndexCOO {
60+ /// COO's index list are represented as a NxM matrix,
61+ /// where N is the number of non-zero values,
62+ /// and M is the number of dimensions of a sparse tensor.
63+ /// indicesBuffer stores the location and size of this index matrix.
64+ /// The type of index value is long, so the stride for the index matrix is unnecessary.
65+ ///
66+ /// For example, let X be a 2x3x4x5 tensor, and it has the following 6 non-zero values:
67+ ///
68+ /// X[0, 1, 2, 0] := 1
69+ /// X[1, 1, 2, 3] := 2
70+ /// X[0, 2, 1, 0] := 3
71+ /// X[0, 1, 3, 0] := 4
72+ /// X[0, 1, 2, 1] := 5
73+ /// X[1, 2, 0, 4] := 6
74+ ///
75+ /// In COO format, the index matrix of X is the following 4x10 matrix:
76+ ///
77+ /// [[0, 0, 0, 0, 1, 1],
78+ /// [1, 1, 1, 2, 1, 2],
79+ /// [2, 2, 3, 1, 2, 0],
80+ /// [0, 1, 0, 0, 3, 4]]
81+ ///
82+ /// Note that the indices are sorted in lexcographical order.
83+ indicesBuffer: Buffer;
84+ }
85+
86+ /// Compressed Sparse Row format, that is matrix-specific.
87+ table SparseMatrixIndexCSR {
88+ /// indptrBuffer stores the location and size of indptr array that
89+ /// represents the range of the rows.
90+ /// The i-th row spans from indptr[i] to indptr[i+1] in the data.
91+ /// The length of this array is 1 + (the number of rows), and the type
92+ /// of index value is long.
93+ ///
94+ /// For example, let X be the following 6x4 matrix:
95+ ///
96+ /// X := [[0, 1, 2, 0],
97+ /// [0, 0, 3, 0],
98+ /// [0, 4, 0, 5],
99+ /// [0, 0, 0, 0],
100+ /// [6, 0, 7, 8],
101+ /// [0, 9, 0, 0]].
102+ ///
103+ /// The array of non-zero values in X is:
104+ ///
105+ /// values(X) = [1, 2, 3, 4, 5, 6, 7, 8, 9].
106+ ///
107+ /// And the indptr of X is:
108+ ///
109+ /// indptr(X) = [0, 2, 3, 5, 5, 8, 10].
110+ indptrBuffer: Buffer;
111+
112+ /// indicesBuffer stores the location and size of the array that
113+ /// contains the column indices of the corresponding non-zero values.
114+ /// The type of index value is long.
115+ ///
116+ /// For example, the indices of the above X is:
117+ ///
118+ /// indices(X) = [1, 2, 2, 1, 3, 0, 2, 3, 1].
119+ indicesBuffer: Buffer;
120+ }
121+
122+ union SparseTensorIndex {
123+ SparseTensorIndexCOO,
124+ SparseMatrixIndexCSR
125+ }
126+
127+ table SparseTensor {
128+ /// The type of data contained in a value cell.
129+ /// Currently only fixed-width value types are supported,
130+ /// no strings or nested types.
131+ type: Type;
132+
133+ /// The dimensions of the tensor, optionally named.
134+ shape: [TensorDim];
135+
136+ /// The number of non-zero values in a sparse tensor.
137+ length: long;
138+
139+ /// Sparse tensor index
140+ sparseIndex: SparseTensorIndex;
141+
142+ /// The location and size of the tensor's data
143+ data: Buffer;
144+ }
145+
146+ root_type SparseTensor;
0 commit comments