| 1066 | } |
| 1067 | |
| 1068 | Status MakeSparseTensorIndexCOO(FBB& fbb, const SparseCOOIndex& sparse_index, |
| 1069 | const std::vector<BufferMetadata>& buffers, |
| 1070 | flatbuf::SparseTensorIndex* fb_sparse_index_type, |
| 1071 | Offset* fb_sparse_index, size_t* num_buffers) { |
| 1072 | *fb_sparse_index_type = |
| 1073 | flatbuf::SparseTensorIndex::SparseTensorIndex_SparseTensorIndexCOO; |
| 1074 | |
| 1075 | // We assume that the value type of indices tensor is an integer. |
| 1076 | const auto& index_value_type = |
| 1077 | checked_cast<const IntegerType&>(*sparse_index.indices()->type()); |
| 1078 | auto indices_type_offset = |
| 1079 | flatbuf::CreateInt(fbb, index_value_type.bit_width(), index_value_type.is_signed()); |
| 1080 | |
| 1081 | auto fb_strides = fbb.CreateVector(sparse_index.indices()->strides().data(), |
| 1082 | sparse_index.indices()->strides().size()); |
| 1083 | |
| 1084 | const BufferMetadata& indices_metadata = buffers[0]; |
| 1085 | flatbuf::Buffer indices(indices_metadata.offset, indices_metadata.length); |
| 1086 | |
| 1087 | *fb_sparse_index = |
| 1088 | flatbuf::CreateSparseTensorIndexCOO(fbb, indices_type_offset, fb_strides, &indices, |
| 1089 | sparse_index.is_canonical()) |
| 1090 | .Union(); |
| 1091 | *num_buffers = 1; |
| 1092 | return Status::OK(); |
| 1093 | } |
| 1094 | |
| 1095 | template <typename SparseIndexType> |
| 1096 | struct SparseMatrixCompressedAxis {}; |
no test coverage detected