Skip to content

Commit d6a8c38

Browse files
committed
Unify Tensor.fbs and SparseTensor.fbs
1 parent b3a62eb commit d6a8c38

File tree

5 files changed

+96
-117
lines changed

5 files changed

+96
-117
lines changed

cpp/src/arrow/ipc/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ set(FBS_SRC
6464
${CMAKE_SOURCE_DIR}/../format/File.fbs
6565
${CMAKE_SOURCE_DIR}/../format/Schema.fbs
6666
${CMAKE_SOURCE_DIR}/../format/Tensor.fbs
67-
${CMAKE_SOURCE_DIR}/../format/SparseTensor.fbs
6867
${CMAKE_CURRENT_SOURCE_DIR}/feather.fbs)
6968

7069
foreach(FIL ${FBS_SRC})

cpp/src/arrow/ipc/metadata-internal.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "arrow/io/interfaces.h"
2929
#include "arrow/ipc/File_generated.h" // IWYU pragma: keep
3030
#include "arrow/ipc/Message_generated.h"
31-
#include "arrow/ipc/SparseTensor_generated.h"
3231
#include "arrow/ipc/Tensor_generated.h" // IWYU pragma: keep
3332
#include "arrow/ipc/message.h"
3433
#include "arrow/ipc/util.h"

format/Message.fbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
include "Schema.fbs";
1919
include "Tensor.fbs";
20-
include "SparseTensor.fbs";
2120

2221
namespace org.apache.arrow.flatbuf;
2322

format/SparseTensor.fbs

Lines changed: 0 additions & 114 deletions
This file was deleted.

format/Tensor.fbs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ include "Schema.fbs";
2323

2424
namespace org.apache.arrow.flatbuf;
2525

26+
/// ----------------------------------------------------------------------
27+
/// Data structures for dense tensors
28+
2629
/// Shape data for a single axis in a tensor
2730
table TensorDim {
2831
/// Length of dimension
@@ -48,3 +51,96 @@ table Tensor {
4851
}
4952

5053
root_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

Comments
 (0)