arrow_ipc/gen/
SparseTensor.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#![allow(dead_code)]
19#![allow(unused_imports)]
20
21use crate::r#gen::Schema::*;
22use crate::r#gen::Tensor::*;
23use flatbuffers::EndianScalar;
24use std::{cmp::Ordering, mem};
25// automatically generated by the FlatBuffers compiler, do not modify
26
27// @generated
28
29#[deprecated(
30    since = "2.0.0",
31    note = "Use associated constants instead. This will no longer be generated in 2021."
32)]
33pub const ENUM_MIN_SPARSE_MATRIX_COMPRESSED_AXIS: i16 = 0;
34#[deprecated(
35    since = "2.0.0",
36    note = "Use associated constants instead. This will no longer be generated in 2021."
37)]
38pub const ENUM_MAX_SPARSE_MATRIX_COMPRESSED_AXIS: i16 = 1;
39#[deprecated(
40    since = "2.0.0",
41    note = "Use associated constants instead. This will no longer be generated in 2021."
42)]
43#[allow(non_camel_case_types)]
44pub const ENUM_VALUES_SPARSE_MATRIX_COMPRESSED_AXIS: [SparseMatrixCompressedAxis; 2] = [
45    SparseMatrixCompressedAxis::Row,
46    SparseMatrixCompressedAxis::Column,
47];
48
49#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
50#[repr(transparent)]
51pub struct SparseMatrixCompressedAxis(pub i16);
52#[allow(non_upper_case_globals)]
53impl SparseMatrixCompressedAxis {
54    pub const Row: Self = Self(0);
55    pub const Column: Self = Self(1);
56
57    pub const ENUM_MIN: i16 = 0;
58    pub const ENUM_MAX: i16 = 1;
59    pub const ENUM_VALUES: &'static [Self] = &[Self::Row, Self::Column];
60    /// Returns the variant's name or "" if unknown.
61    pub fn variant_name(self) -> Option<&'static str> {
62        match self {
63            Self::Row => Some("Row"),
64            Self::Column => Some("Column"),
65            _ => None,
66        }
67    }
68}
69impl core::fmt::Debug for SparseMatrixCompressedAxis {
70    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
71        if let Some(name) = self.variant_name() {
72            f.write_str(name)
73        } else {
74            f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
75        }
76    }
77}
78impl<'a> flatbuffers::Follow<'a> for SparseMatrixCompressedAxis {
79    type Inner = Self;
80    #[inline]
81    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
82        let b = unsafe { flatbuffers::read_scalar_at::<i16>(buf, loc) };
83        Self(b)
84    }
85}
86
87impl flatbuffers::Push for SparseMatrixCompressedAxis {
88    type Output = SparseMatrixCompressedAxis;
89    #[inline]
90    unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
91        unsafe {
92            flatbuffers::emplace_scalar::<i16>(dst, self.0);
93        }
94    }
95}
96
97impl flatbuffers::EndianScalar for SparseMatrixCompressedAxis {
98    type Scalar = i16;
99    #[inline]
100    fn to_little_endian(self) -> i16 {
101        self.0.to_le()
102    }
103    #[inline]
104    #[allow(clippy::wrong_self_convention)]
105    fn from_little_endian(v: i16) -> Self {
106        let b = i16::from_le(v);
107        Self(b)
108    }
109}
110
111impl<'a> flatbuffers::Verifiable for SparseMatrixCompressedAxis {
112    #[inline]
113    fn run_verifier(
114        v: &mut flatbuffers::Verifier,
115        pos: usize,
116    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
117        use flatbuffers::Verifiable;
118        i16::run_verifier(v, pos)
119    }
120}
121
122impl flatbuffers::SimpleToVerifyInSlice for SparseMatrixCompressedAxis {}
123#[deprecated(
124    since = "2.0.0",
125    note = "Use associated constants instead. This will no longer be generated in 2021."
126)]
127pub const ENUM_MIN_SPARSE_TENSOR_INDEX: u8 = 0;
128#[deprecated(
129    since = "2.0.0",
130    note = "Use associated constants instead. This will no longer be generated in 2021."
131)]
132pub const ENUM_MAX_SPARSE_TENSOR_INDEX: u8 = 3;
133#[deprecated(
134    since = "2.0.0",
135    note = "Use associated constants instead. This will no longer be generated in 2021."
136)]
137#[allow(non_camel_case_types)]
138pub const ENUM_VALUES_SPARSE_TENSOR_INDEX: [SparseTensorIndex; 4] = [
139    SparseTensorIndex::NONE,
140    SparseTensorIndex::SparseTensorIndexCOO,
141    SparseTensorIndex::SparseMatrixIndexCSX,
142    SparseTensorIndex::SparseTensorIndexCSF,
143];
144
145#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
146#[repr(transparent)]
147pub struct SparseTensorIndex(pub u8);
148#[allow(non_upper_case_globals)]
149impl SparseTensorIndex {
150    pub const NONE: Self = Self(0);
151    pub const SparseTensorIndexCOO: Self = Self(1);
152    pub const SparseMatrixIndexCSX: Self = Self(2);
153    pub const SparseTensorIndexCSF: Self = Self(3);
154
155    pub const ENUM_MIN: u8 = 0;
156    pub const ENUM_MAX: u8 = 3;
157    pub const ENUM_VALUES: &'static [Self] = &[
158        Self::NONE,
159        Self::SparseTensorIndexCOO,
160        Self::SparseMatrixIndexCSX,
161        Self::SparseTensorIndexCSF,
162    ];
163    /// Returns the variant's name or "" if unknown.
164    pub fn variant_name(self) -> Option<&'static str> {
165        match self {
166            Self::NONE => Some("NONE"),
167            Self::SparseTensorIndexCOO => Some("SparseTensorIndexCOO"),
168            Self::SparseMatrixIndexCSX => Some("SparseMatrixIndexCSX"),
169            Self::SparseTensorIndexCSF => Some("SparseTensorIndexCSF"),
170            _ => None,
171        }
172    }
173}
174impl core::fmt::Debug for SparseTensorIndex {
175    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
176        if let Some(name) = self.variant_name() {
177            f.write_str(name)
178        } else {
179            f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
180        }
181    }
182}
183impl<'a> flatbuffers::Follow<'a> for SparseTensorIndex {
184    type Inner = Self;
185    #[inline]
186    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
187        let b = unsafe { flatbuffers::read_scalar_at::<u8>(buf, loc) };
188        Self(b)
189    }
190}
191
192impl flatbuffers::Push for SparseTensorIndex {
193    type Output = SparseTensorIndex;
194    #[inline]
195    unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
196        unsafe {
197            flatbuffers::emplace_scalar::<u8>(dst, self.0);
198        }
199    }
200}
201
202impl flatbuffers::EndianScalar for SparseTensorIndex {
203    type Scalar = u8;
204    #[inline]
205    fn to_little_endian(self) -> u8 {
206        self.0.to_le()
207    }
208    #[inline]
209    #[allow(clippy::wrong_self_convention)]
210    fn from_little_endian(v: u8) -> Self {
211        let b = u8::from_le(v);
212        Self(b)
213    }
214}
215
216impl<'a> flatbuffers::Verifiable for SparseTensorIndex {
217    #[inline]
218    fn run_verifier(
219        v: &mut flatbuffers::Verifier,
220        pos: usize,
221    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
222        use flatbuffers::Verifiable;
223        u8::run_verifier(v, pos)
224    }
225}
226
227impl flatbuffers::SimpleToVerifyInSlice for SparseTensorIndex {}
228pub struct SparseTensorIndexUnionTableOffset {}
229
230pub enum SparseTensorIndexCOOOffset {}
231#[derive(Copy, Clone, PartialEq)]
232
233/// ----------------------------------------------------------------------
234/// EXPERIMENTAL: Data structures for sparse tensors
235/// Coordinate (COO) format of sparse tensor index.
236///
237/// COO's index list are represented as a NxM matrix,
238/// where N is the number of non-zero values,
239/// and M is the number of dimensions of a sparse tensor.
240///
241/// indicesBuffer stores the location and size of the data of this indices
242/// matrix.  The value type and the stride of the indices matrix is
243/// specified in indicesType and indicesStrides fields.
244///
245/// For example, let X be a 2x3x4x5 tensor, and it has the following
246/// 6 non-zero values:
247/// ```text
248///   X[0, 1, 2, 0] := 1
249///   X[1, 1, 2, 3] := 2
250///   X[0, 2, 1, 0] := 3
251///   X[0, 1, 3, 0] := 4
252///   X[0, 1, 2, 1] := 5
253///   X[1, 2, 0, 4] := 6
254/// ```
255/// In COO format, the index matrix of X is the following 4x6 matrix:
256/// ```text
257///   [[0, 0, 0, 0, 1, 1],
258///    [1, 1, 1, 2, 1, 2],
259///    [2, 2, 3, 1, 2, 0],
260///    [0, 1, 0, 0, 3, 4]]
261/// ```
262/// When isCanonical is true, the indices is sorted in lexicographical order
263/// (row-major order), and it does not have duplicated entries.  Otherwise,
264/// the indices may not be sorted, or may have duplicated entries.
265pub struct SparseTensorIndexCOO<'a> {
266    pub _tab: flatbuffers::Table<'a>,
267}
268
269impl<'a> flatbuffers::Follow<'a> for SparseTensorIndexCOO<'a> {
270    type Inner = SparseTensorIndexCOO<'a>;
271    #[inline]
272    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
273        Self {
274            _tab: unsafe { flatbuffers::Table::new(buf, loc) },
275        }
276    }
277}
278
279impl<'a> SparseTensorIndexCOO<'a> {
280    pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 4;
281    pub const VT_INDICESSTRIDES: flatbuffers::VOffsetT = 6;
282    pub const VT_INDICESBUFFER: flatbuffers::VOffsetT = 8;
283    pub const VT_ISCANONICAL: flatbuffers::VOffsetT = 10;
284
285    #[inline]
286    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
287        SparseTensorIndexCOO { _tab: table }
288    }
289    #[allow(unused_mut)]
290    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
291        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
292        args: &'args SparseTensorIndexCOOArgs<'args>,
293    ) -> flatbuffers::WIPOffset<SparseTensorIndexCOO<'bldr>> {
294        let mut builder = SparseTensorIndexCOOBuilder::new(_fbb);
295        if let Some(x) = args.indicesBuffer {
296            builder.add_indicesBuffer(x);
297        }
298        if let Some(x) = args.indicesStrides {
299            builder.add_indicesStrides(x);
300        }
301        if let Some(x) = args.indicesType {
302            builder.add_indicesType(x);
303        }
304        builder.add_isCanonical(args.isCanonical);
305        builder.finish()
306    }
307
308    /// The type of values in indicesBuffer
309    #[inline]
310    pub fn indicesType(&self) -> Int<'a> {
311        // Safety:
312        // Created from valid Table for this object
313        // which contains a valid value in this slot
314        unsafe {
315            self._tab
316                .get::<flatbuffers::ForwardsUOffset<Int>>(
317                    SparseTensorIndexCOO::VT_INDICESTYPE,
318                    None,
319                )
320                .unwrap()
321        }
322    }
323    /// Non-negative byte offsets to advance one value cell along each dimension
324    /// If omitted, default to row-major order (C-like).
325    #[inline]
326    pub fn indicesStrides(&self) -> Option<flatbuffers::Vector<'a, i64>> {
327        // Safety:
328        // Created from valid Table for this object
329        // which contains a valid value in this slot
330        unsafe {
331            self._tab
332                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i64>>>(
333                    SparseTensorIndexCOO::VT_INDICESSTRIDES,
334                    None,
335                )
336        }
337    }
338    /// The location and size of the indices matrix's data
339    #[inline]
340    pub fn indicesBuffer(&self) -> &'a Buffer {
341        // Safety:
342        // Created from valid Table for this object
343        // which contains a valid value in this slot
344        unsafe {
345            self._tab
346                .get::<Buffer>(SparseTensorIndexCOO::VT_INDICESBUFFER, None)
347                .unwrap()
348        }
349    }
350    /// This flag is true if and only if the indices matrix is sorted in
351    /// row-major order, and does not have duplicated entries.
352    /// This sort order is the same as of Tensorflow's SparseTensor,
353    /// but it is inverse order of SciPy's canonical coo_matrix
354    /// (SciPy employs column-major order for its coo_matrix).
355    #[inline]
356    pub fn isCanonical(&self) -> bool {
357        // Safety:
358        // Created from valid Table for this object
359        // which contains a valid value in this slot
360        unsafe {
361            self._tab
362                .get::<bool>(SparseTensorIndexCOO::VT_ISCANONICAL, Some(false))
363                .unwrap()
364        }
365    }
366}
367
368impl flatbuffers::Verifiable for SparseTensorIndexCOO<'_> {
369    #[inline]
370    fn run_verifier(
371        v: &mut flatbuffers::Verifier,
372        pos: usize,
373    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
374        use flatbuffers::Verifiable;
375        v.visit_table(pos)?
376            .visit_field::<flatbuffers::ForwardsUOffset<Int>>(
377                "indicesType",
378                Self::VT_INDICESTYPE,
379                true,
380            )?
381            .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, i64>>>(
382                "indicesStrides",
383                Self::VT_INDICESSTRIDES,
384                false,
385            )?
386            .visit_field::<Buffer>("indicesBuffer", Self::VT_INDICESBUFFER, true)?
387            .visit_field::<bool>("isCanonical", Self::VT_ISCANONICAL, false)?
388            .finish();
389        Ok(())
390    }
391}
392pub struct SparseTensorIndexCOOArgs<'a> {
393    pub indicesType: Option<flatbuffers::WIPOffset<Int<'a>>>,
394    pub indicesStrides: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, i64>>>,
395    pub indicesBuffer: Option<&'a Buffer>,
396    pub isCanonical: bool,
397}
398impl<'a> Default for SparseTensorIndexCOOArgs<'a> {
399    #[inline]
400    fn default() -> Self {
401        SparseTensorIndexCOOArgs {
402            indicesType: None, // required field
403            indicesStrides: None,
404            indicesBuffer: None, // required field
405            isCanonical: false,
406        }
407    }
408}
409
410pub struct SparseTensorIndexCOOBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
411    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
412    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
413}
414impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> SparseTensorIndexCOOBuilder<'a, 'b, A> {
415    #[inline]
416    pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset<Int<'b>>) {
417        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<Int>>(
418            SparseTensorIndexCOO::VT_INDICESTYPE,
419            indicesType,
420        );
421    }
422    #[inline]
423    pub fn add_indicesStrides(
424        &mut self,
425        indicesStrides: flatbuffers::WIPOffset<flatbuffers::Vector<'b, i64>>,
426    ) {
427        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(
428            SparseTensorIndexCOO::VT_INDICESSTRIDES,
429            indicesStrides,
430        );
431    }
432    #[inline]
433    pub fn add_indicesBuffer(&mut self, indicesBuffer: &Buffer) {
434        self.fbb_
435            .push_slot_always::<&Buffer>(SparseTensorIndexCOO::VT_INDICESBUFFER, indicesBuffer);
436    }
437    #[inline]
438    pub fn add_isCanonical(&mut self, isCanonical: bool) {
439        self.fbb_
440            .push_slot::<bool>(SparseTensorIndexCOO::VT_ISCANONICAL, isCanonical, false);
441    }
442    #[inline]
443    pub fn new(
444        _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
445    ) -> SparseTensorIndexCOOBuilder<'a, 'b, A> {
446        let start = _fbb.start_table();
447        SparseTensorIndexCOOBuilder {
448            fbb_: _fbb,
449            start_: start,
450        }
451    }
452    #[inline]
453    pub fn finish(self) -> flatbuffers::WIPOffset<SparseTensorIndexCOO<'a>> {
454        let o = self.fbb_.end_table(self.start_);
455        self.fbb_
456            .required(o, SparseTensorIndexCOO::VT_INDICESTYPE, "indicesType");
457        self.fbb_
458            .required(o, SparseTensorIndexCOO::VT_INDICESBUFFER, "indicesBuffer");
459        flatbuffers::WIPOffset::new(o.value())
460    }
461}
462
463impl core::fmt::Debug for SparseTensorIndexCOO<'_> {
464    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
465        let mut ds = f.debug_struct("SparseTensorIndexCOO");
466        ds.field("indicesType", &self.indicesType());
467        ds.field("indicesStrides", &self.indicesStrides());
468        ds.field("indicesBuffer", &self.indicesBuffer());
469        ds.field("isCanonical", &self.isCanonical());
470        ds.finish()
471    }
472}
473pub enum SparseMatrixIndexCSXOffset {}
474#[derive(Copy, Clone, PartialEq)]
475
476/// Compressed Sparse format, that is matrix-specific.
477pub struct SparseMatrixIndexCSX<'a> {
478    pub _tab: flatbuffers::Table<'a>,
479}
480
481impl<'a> flatbuffers::Follow<'a> for SparseMatrixIndexCSX<'a> {
482    type Inner = SparseMatrixIndexCSX<'a>;
483    #[inline]
484    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
485        Self {
486            _tab: unsafe { flatbuffers::Table::new(buf, loc) },
487        }
488    }
489}
490
491impl<'a> SparseMatrixIndexCSX<'a> {
492    pub const VT_COMPRESSEDAXIS: flatbuffers::VOffsetT = 4;
493    pub const VT_INDPTRTYPE: flatbuffers::VOffsetT = 6;
494    pub const VT_INDPTRBUFFER: flatbuffers::VOffsetT = 8;
495    pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 10;
496    pub const VT_INDICESBUFFER: flatbuffers::VOffsetT = 12;
497
498    #[inline]
499    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
500        SparseMatrixIndexCSX { _tab: table }
501    }
502    #[allow(unused_mut)]
503    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
504        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
505        args: &'args SparseMatrixIndexCSXArgs<'args>,
506    ) -> flatbuffers::WIPOffset<SparseMatrixIndexCSX<'bldr>> {
507        let mut builder = SparseMatrixIndexCSXBuilder::new(_fbb);
508        if let Some(x) = args.indicesBuffer {
509            builder.add_indicesBuffer(x);
510        }
511        if let Some(x) = args.indicesType {
512            builder.add_indicesType(x);
513        }
514        if let Some(x) = args.indptrBuffer {
515            builder.add_indptrBuffer(x);
516        }
517        if let Some(x) = args.indptrType {
518            builder.add_indptrType(x);
519        }
520        builder.add_compressedAxis(args.compressedAxis);
521        builder.finish()
522    }
523
524    /// Which axis, row or column, is compressed
525    #[inline]
526    pub fn compressedAxis(&self) -> SparseMatrixCompressedAxis {
527        // Safety:
528        // Created from valid Table for this object
529        // which contains a valid value in this slot
530        unsafe {
531            self._tab
532                .get::<SparseMatrixCompressedAxis>(
533                    SparseMatrixIndexCSX::VT_COMPRESSEDAXIS,
534                    Some(SparseMatrixCompressedAxis::Row),
535                )
536                .unwrap()
537        }
538    }
539    /// The type of values in indptrBuffer
540    #[inline]
541    pub fn indptrType(&self) -> Int<'a> {
542        // Safety:
543        // Created from valid Table for this object
544        // which contains a valid value in this slot
545        unsafe {
546            self._tab
547                .get::<flatbuffers::ForwardsUOffset<Int>>(SparseMatrixIndexCSX::VT_INDPTRTYPE, None)
548                .unwrap()
549        }
550    }
551    /// indptrBuffer stores the location and size of indptr array that
552    /// represents the range of the rows.
553    /// The i-th row spans from `indptr[i]` to `indptr[i+1]` in the data.
554    /// The length of this array is 1 + (the number of rows), and the type
555    /// of index value is long.
556    ///
557    /// For example, let X be the following 6x4 matrix:
558    /// ```text
559    ///   X := [[0, 1, 2, 0],
560    ///         [0, 0, 3, 0],
561    ///         [0, 4, 0, 5],
562    ///         [0, 0, 0, 0],
563    ///         [6, 0, 7, 8],
564    ///         [0, 9, 0, 0]].
565    /// ```
566    /// The array of non-zero values in X is:
567    /// ```text
568    ///   values(X) = [1, 2, 3, 4, 5, 6, 7, 8, 9].
569    /// ```
570    /// And the indptr of X is:
571    /// ```text
572    ///   indptr(X) = [0, 2, 3, 5, 5, 8, 10].
573    /// ```
574    #[inline]
575    pub fn indptrBuffer(&self) -> &'a Buffer {
576        // Safety:
577        // Created from valid Table for this object
578        // which contains a valid value in this slot
579        unsafe {
580            self._tab
581                .get::<Buffer>(SparseMatrixIndexCSX::VT_INDPTRBUFFER, None)
582                .unwrap()
583        }
584    }
585    /// The type of values in indicesBuffer
586    #[inline]
587    pub fn indicesType(&self) -> Int<'a> {
588        // Safety:
589        // Created from valid Table for this object
590        // which contains a valid value in this slot
591        unsafe {
592            self._tab
593                .get::<flatbuffers::ForwardsUOffset<Int>>(
594                    SparseMatrixIndexCSX::VT_INDICESTYPE,
595                    None,
596                )
597                .unwrap()
598        }
599    }
600    /// indicesBuffer stores the location and size of the array that
601    /// contains the column indices of the corresponding non-zero values.
602    /// The type of index value is long.
603    ///
604    /// For example, the indices of the above X is:
605    /// ```text
606    ///   indices(X) = [1, 2, 2, 1, 3, 0, 2, 3, 1].
607    /// ```
608    /// Note that the indices are sorted in lexicographical order for each row.
609    #[inline]
610    pub fn indicesBuffer(&self) -> &'a Buffer {
611        // Safety:
612        // Created from valid Table for this object
613        // which contains a valid value in this slot
614        unsafe {
615            self._tab
616                .get::<Buffer>(SparseMatrixIndexCSX::VT_INDICESBUFFER, None)
617                .unwrap()
618        }
619    }
620}
621
622impl flatbuffers::Verifiable for SparseMatrixIndexCSX<'_> {
623    #[inline]
624    fn run_verifier(
625        v: &mut flatbuffers::Verifier,
626        pos: usize,
627    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
628        use flatbuffers::Verifiable;
629        v.visit_table(pos)?
630            .visit_field::<SparseMatrixCompressedAxis>(
631                "compressedAxis",
632                Self::VT_COMPRESSEDAXIS,
633                false,
634            )?
635            .visit_field::<flatbuffers::ForwardsUOffset<Int>>(
636                "indptrType",
637                Self::VT_INDPTRTYPE,
638                true,
639            )?
640            .visit_field::<Buffer>("indptrBuffer", Self::VT_INDPTRBUFFER, true)?
641            .visit_field::<flatbuffers::ForwardsUOffset<Int>>(
642                "indicesType",
643                Self::VT_INDICESTYPE,
644                true,
645            )?
646            .visit_field::<Buffer>("indicesBuffer", Self::VT_INDICESBUFFER, true)?
647            .finish();
648        Ok(())
649    }
650}
651pub struct SparseMatrixIndexCSXArgs<'a> {
652    pub compressedAxis: SparseMatrixCompressedAxis,
653    pub indptrType: Option<flatbuffers::WIPOffset<Int<'a>>>,
654    pub indptrBuffer: Option<&'a Buffer>,
655    pub indicesType: Option<flatbuffers::WIPOffset<Int<'a>>>,
656    pub indicesBuffer: Option<&'a Buffer>,
657}
658impl<'a> Default for SparseMatrixIndexCSXArgs<'a> {
659    #[inline]
660    fn default() -> Self {
661        SparseMatrixIndexCSXArgs {
662            compressedAxis: SparseMatrixCompressedAxis::Row,
663            indptrType: None,    // required field
664            indptrBuffer: None,  // required field
665            indicesType: None,   // required field
666            indicesBuffer: None, // required field
667        }
668    }
669}
670
671pub struct SparseMatrixIndexCSXBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
672    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
673    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
674}
675impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> SparseMatrixIndexCSXBuilder<'a, 'b, A> {
676    #[inline]
677    pub fn add_compressedAxis(&mut self, compressedAxis: SparseMatrixCompressedAxis) {
678        self.fbb_.push_slot::<SparseMatrixCompressedAxis>(
679            SparseMatrixIndexCSX::VT_COMPRESSEDAXIS,
680            compressedAxis,
681            SparseMatrixCompressedAxis::Row,
682        );
683    }
684    #[inline]
685    pub fn add_indptrType(&mut self, indptrType: flatbuffers::WIPOffset<Int<'b>>) {
686        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<Int>>(
687            SparseMatrixIndexCSX::VT_INDPTRTYPE,
688            indptrType,
689        );
690    }
691    #[inline]
692    pub fn add_indptrBuffer(&mut self, indptrBuffer: &Buffer) {
693        self.fbb_
694            .push_slot_always::<&Buffer>(SparseMatrixIndexCSX::VT_INDPTRBUFFER, indptrBuffer);
695    }
696    #[inline]
697    pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset<Int<'b>>) {
698        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<Int>>(
699            SparseMatrixIndexCSX::VT_INDICESTYPE,
700            indicesType,
701        );
702    }
703    #[inline]
704    pub fn add_indicesBuffer(&mut self, indicesBuffer: &Buffer) {
705        self.fbb_
706            .push_slot_always::<&Buffer>(SparseMatrixIndexCSX::VT_INDICESBUFFER, indicesBuffer);
707    }
708    #[inline]
709    pub fn new(
710        _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
711    ) -> SparseMatrixIndexCSXBuilder<'a, 'b, A> {
712        let start = _fbb.start_table();
713        SparseMatrixIndexCSXBuilder {
714            fbb_: _fbb,
715            start_: start,
716        }
717    }
718    #[inline]
719    pub fn finish(self) -> flatbuffers::WIPOffset<SparseMatrixIndexCSX<'a>> {
720        let o = self.fbb_.end_table(self.start_);
721        self.fbb_
722            .required(o, SparseMatrixIndexCSX::VT_INDPTRTYPE, "indptrType");
723        self.fbb_
724            .required(o, SparseMatrixIndexCSX::VT_INDPTRBUFFER, "indptrBuffer");
725        self.fbb_
726            .required(o, SparseMatrixIndexCSX::VT_INDICESTYPE, "indicesType");
727        self.fbb_
728            .required(o, SparseMatrixIndexCSX::VT_INDICESBUFFER, "indicesBuffer");
729        flatbuffers::WIPOffset::new(o.value())
730    }
731}
732
733impl core::fmt::Debug for SparseMatrixIndexCSX<'_> {
734    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
735        let mut ds = f.debug_struct("SparseMatrixIndexCSX");
736        ds.field("compressedAxis", &self.compressedAxis());
737        ds.field("indptrType", &self.indptrType());
738        ds.field("indptrBuffer", &self.indptrBuffer());
739        ds.field("indicesType", &self.indicesType());
740        ds.field("indicesBuffer", &self.indicesBuffer());
741        ds.finish()
742    }
743}
744pub enum SparseTensorIndexCSFOffset {}
745#[derive(Copy, Clone, PartialEq)]
746
747/// Compressed Sparse Fiber (CSF) sparse tensor index.
748pub struct SparseTensorIndexCSF<'a> {
749    pub _tab: flatbuffers::Table<'a>,
750}
751
752impl<'a> flatbuffers::Follow<'a> for SparseTensorIndexCSF<'a> {
753    type Inner = SparseTensorIndexCSF<'a>;
754    #[inline]
755    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
756        Self {
757            _tab: unsafe { flatbuffers::Table::new(buf, loc) },
758        }
759    }
760}
761
762impl<'a> SparseTensorIndexCSF<'a> {
763    pub const VT_INDPTRTYPE: flatbuffers::VOffsetT = 4;
764    pub const VT_INDPTRBUFFERS: flatbuffers::VOffsetT = 6;
765    pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 8;
766    pub const VT_INDICESBUFFERS: flatbuffers::VOffsetT = 10;
767    pub const VT_AXISORDER: flatbuffers::VOffsetT = 12;
768
769    #[inline]
770    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
771        SparseTensorIndexCSF { _tab: table }
772    }
773    #[allow(unused_mut)]
774    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
775        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
776        args: &'args SparseTensorIndexCSFArgs<'args>,
777    ) -> flatbuffers::WIPOffset<SparseTensorIndexCSF<'bldr>> {
778        let mut builder = SparseTensorIndexCSFBuilder::new(_fbb);
779        if let Some(x) = args.axisOrder {
780            builder.add_axisOrder(x);
781        }
782        if let Some(x) = args.indicesBuffers {
783            builder.add_indicesBuffers(x);
784        }
785        if let Some(x) = args.indicesType {
786            builder.add_indicesType(x);
787        }
788        if let Some(x) = args.indptrBuffers {
789            builder.add_indptrBuffers(x);
790        }
791        if let Some(x) = args.indptrType {
792            builder.add_indptrType(x);
793        }
794        builder.finish()
795    }
796
797    /// CSF is a generalization of compressed sparse row (CSR) index.
798    /// See [smith2017knl](http://shaden.io/pub-files/smith2017knl.pdf)
799    ///
800    /// CSF index recursively compresses each dimension of a tensor into a set
801    /// of prefix trees. Each path from a root to leaf forms one tensor
802    /// non-zero index. CSF is implemented with two arrays of buffers and one
803    /// arrays of integers.
804    ///
805    /// For example, let X be a 2x3x4x5 tensor and let it have the following
806    /// 8 non-zero values:
807    /// ```text
808    ///   X[0, 0, 0, 1] := 1
809    ///   X[0, 0, 0, 2] := 2
810    ///   X[0, 1, 0, 0] := 3
811    ///   X[0, 1, 0, 2] := 4
812    ///   X[0, 1, 1, 0] := 5
813    ///   X[1, 1, 1, 0] := 6
814    ///   X[1, 1, 1, 1] := 7
815    ///   X[1, 1, 1, 2] := 8
816    /// ```
817    /// As a prefix tree this would be represented as:
818    /// ```text
819    ///         0          1
820    ///        / \         |
821    ///       0   1        1
822    ///      /   / \       |
823    ///     0   0   1      1
824    ///    /|  /|   |    /| |
825    ///   1 2 0 2   0   0 1 2
826    /// ```
827    /// The type of values in indptrBuffers
828    #[inline]
829    pub fn indptrType(&self) -> Int<'a> {
830        // Safety:
831        // Created from valid Table for this object
832        // which contains a valid value in this slot
833        unsafe {
834            self._tab
835                .get::<flatbuffers::ForwardsUOffset<Int>>(SparseTensorIndexCSF::VT_INDPTRTYPE, None)
836                .unwrap()
837        }
838    }
839    /// indptrBuffers stores the sparsity structure.
840    /// Each two consecutive dimensions in a tensor correspond to a buffer in
841    /// indptrBuffers. A pair of consecutive values at `indptrBuffers[dim][i]`
842    /// and `indptrBuffers[dim][i + 1]` signify a range of nodes in
843    /// `indicesBuffers[dim + 1]` who are children of `indicesBuffers[dim][i]` node.
844    ///
845    /// For example, the indptrBuffers for the above X is:
846    /// ```text
847    ///   indptrBuffer(X) = [
848    ///                       [0, 2, 3],
849    ///                       [0, 1, 3, 4],
850    ///                       [0, 2, 4, 5, 8]
851    ///                     ].
852    /// ```
853    #[inline]
854    pub fn indptrBuffers(&self) -> flatbuffers::Vector<'a, Buffer> {
855        // Safety:
856        // Created from valid Table for this object
857        // which contains a valid value in this slot
858        unsafe {
859            self._tab
860                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Buffer>>>(
861                    SparseTensorIndexCSF::VT_INDPTRBUFFERS,
862                    None,
863                )
864                .unwrap()
865        }
866    }
867    /// The type of values in indicesBuffers
868    #[inline]
869    pub fn indicesType(&self) -> Int<'a> {
870        // Safety:
871        // Created from valid Table for this object
872        // which contains a valid value in this slot
873        unsafe {
874            self._tab
875                .get::<flatbuffers::ForwardsUOffset<Int>>(
876                    SparseTensorIndexCSF::VT_INDICESTYPE,
877                    None,
878                )
879                .unwrap()
880        }
881    }
882    /// indicesBuffers stores values of nodes.
883    /// Each tensor dimension corresponds to a buffer in indicesBuffers.
884    /// For example, the indicesBuffers for the above X is:
885    /// ```text
886    ///   indicesBuffer(X) = [
887    ///                        [0, 1],
888    ///                        [0, 1, 1],
889    ///                        [0, 0, 1, 1],
890    ///                        [1, 2, 0, 2, 0, 0, 1, 2]
891    ///                      ].
892    /// ```
893    #[inline]
894    pub fn indicesBuffers(&self) -> flatbuffers::Vector<'a, Buffer> {
895        // Safety:
896        // Created from valid Table for this object
897        // which contains a valid value in this slot
898        unsafe {
899            self._tab
900                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Buffer>>>(
901                    SparseTensorIndexCSF::VT_INDICESBUFFERS,
902                    None,
903                )
904                .unwrap()
905        }
906    }
907    /// axisOrder stores the sequence in which dimensions were traversed to
908    /// produce the prefix tree.
909    /// For example, the axisOrder for the above X is:
910    /// ```text
911    ///   axisOrder(X) = [0, 1, 2, 3].
912    /// ```
913    #[inline]
914    pub fn axisOrder(&self) -> flatbuffers::Vector<'a, i32> {
915        // Safety:
916        // Created from valid Table for this object
917        // which contains a valid value in this slot
918        unsafe {
919            self._tab
920                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i32>>>(
921                    SparseTensorIndexCSF::VT_AXISORDER,
922                    None,
923                )
924                .unwrap()
925        }
926    }
927}
928
929impl flatbuffers::Verifiable for SparseTensorIndexCSF<'_> {
930    #[inline]
931    fn run_verifier(
932        v: &mut flatbuffers::Verifier,
933        pos: usize,
934    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
935        use flatbuffers::Verifiable;
936        v.visit_table(pos)?
937            .visit_field::<flatbuffers::ForwardsUOffset<Int>>(
938                "indptrType",
939                Self::VT_INDPTRTYPE,
940                true,
941            )?
942            .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, Buffer>>>(
943                "indptrBuffers",
944                Self::VT_INDPTRBUFFERS,
945                true,
946            )?
947            .visit_field::<flatbuffers::ForwardsUOffset<Int>>(
948                "indicesType",
949                Self::VT_INDICESTYPE,
950                true,
951            )?
952            .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, Buffer>>>(
953                "indicesBuffers",
954                Self::VT_INDICESBUFFERS,
955                true,
956            )?
957            .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, i32>>>(
958                "axisOrder",
959                Self::VT_AXISORDER,
960                true,
961            )?
962            .finish();
963        Ok(())
964    }
965}
966pub struct SparseTensorIndexCSFArgs<'a> {
967    pub indptrType: Option<flatbuffers::WIPOffset<Int<'a>>>,
968    pub indptrBuffers: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, Buffer>>>,
969    pub indicesType: Option<flatbuffers::WIPOffset<Int<'a>>>,
970    pub indicesBuffers: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, Buffer>>>,
971    pub axisOrder: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, i32>>>,
972}
973impl<'a> Default for SparseTensorIndexCSFArgs<'a> {
974    #[inline]
975    fn default() -> Self {
976        SparseTensorIndexCSFArgs {
977            indptrType: None,     // required field
978            indptrBuffers: None,  // required field
979            indicesType: None,    // required field
980            indicesBuffers: None, // required field
981            axisOrder: None,      // required field
982        }
983    }
984}
985
986pub struct SparseTensorIndexCSFBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
987    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
988    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
989}
990impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> SparseTensorIndexCSFBuilder<'a, 'b, A> {
991    #[inline]
992    pub fn add_indptrType(&mut self, indptrType: flatbuffers::WIPOffset<Int<'b>>) {
993        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<Int>>(
994            SparseTensorIndexCSF::VT_INDPTRTYPE,
995            indptrType,
996        );
997    }
998    #[inline]
999    pub fn add_indptrBuffers(
1000        &mut self,
1001        indptrBuffers: flatbuffers::WIPOffset<flatbuffers::Vector<'b, Buffer>>,
1002    ) {
1003        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(
1004            SparseTensorIndexCSF::VT_INDPTRBUFFERS,
1005            indptrBuffers,
1006        );
1007    }
1008    #[inline]
1009    pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset<Int<'b>>) {
1010        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<Int>>(
1011            SparseTensorIndexCSF::VT_INDICESTYPE,
1012            indicesType,
1013        );
1014    }
1015    #[inline]
1016    pub fn add_indicesBuffers(
1017        &mut self,
1018        indicesBuffers: flatbuffers::WIPOffset<flatbuffers::Vector<'b, Buffer>>,
1019    ) {
1020        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(
1021            SparseTensorIndexCSF::VT_INDICESBUFFERS,
1022            indicesBuffers,
1023        );
1024    }
1025    #[inline]
1026    pub fn add_axisOrder(
1027        &mut self,
1028        axisOrder: flatbuffers::WIPOffset<flatbuffers::Vector<'b, i32>>,
1029    ) {
1030        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(
1031            SparseTensorIndexCSF::VT_AXISORDER,
1032            axisOrder,
1033        );
1034    }
1035    #[inline]
1036    pub fn new(
1037        _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
1038    ) -> SparseTensorIndexCSFBuilder<'a, 'b, A> {
1039        let start = _fbb.start_table();
1040        SparseTensorIndexCSFBuilder {
1041            fbb_: _fbb,
1042            start_: start,
1043        }
1044    }
1045    #[inline]
1046    pub fn finish(self) -> flatbuffers::WIPOffset<SparseTensorIndexCSF<'a>> {
1047        let o = self.fbb_.end_table(self.start_);
1048        self.fbb_
1049            .required(o, SparseTensorIndexCSF::VT_INDPTRTYPE, "indptrType");
1050        self.fbb_
1051            .required(o, SparseTensorIndexCSF::VT_INDPTRBUFFERS, "indptrBuffers");
1052        self.fbb_
1053            .required(o, SparseTensorIndexCSF::VT_INDICESTYPE, "indicesType");
1054        self.fbb_
1055            .required(o, SparseTensorIndexCSF::VT_INDICESBUFFERS, "indicesBuffers");
1056        self.fbb_
1057            .required(o, SparseTensorIndexCSF::VT_AXISORDER, "axisOrder");
1058        flatbuffers::WIPOffset::new(o.value())
1059    }
1060}
1061
1062impl core::fmt::Debug for SparseTensorIndexCSF<'_> {
1063    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1064        let mut ds = f.debug_struct("SparseTensorIndexCSF");
1065        ds.field("indptrType", &self.indptrType());
1066        ds.field("indptrBuffers", &self.indptrBuffers());
1067        ds.field("indicesType", &self.indicesType());
1068        ds.field("indicesBuffers", &self.indicesBuffers());
1069        ds.field("axisOrder", &self.axisOrder());
1070        ds.finish()
1071    }
1072}
1073pub enum SparseTensorOffset {}
1074#[derive(Copy, Clone, PartialEq)]
1075
1076pub struct SparseTensor<'a> {
1077    pub _tab: flatbuffers::Table<'a>,
1078}
1079
1080impl<'a> flatbuffers::Follow<'a> for SparseTensor<'a> {
1081    type Inner = SparseTensor<'a>;
1082    #[inline]
1083    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
1084        Self {
1085            _tab: unsafe { flatbuffers::Table::new(buf, loc) },
1086        }
1087    }
1088}
1089
1090impl<'a> SparseTensor<'a> {
1091    pub const VT_TYPE_TYPE: flatbuffers::VOffsetT = 4;
1092    pub const VT_TYPE_: flatbuffers::VOffsetT = 6;
1093    pub const VT_SHAPE: flatbuffers::VOffsetT = 8;
1094    pub const VT_NON_ZERO_LENGTH: flatbuffers::VOffsetT = 10;
1095    pub const VT_SPARSEINDEX_TYPE: flatbuffers::VOffsetT = 12;
1096    pub const VT_SPARSEINDEX: flatbuffers::VOffsetT = 14;
1097    pub const VT_DATA: flatbuffers::VOffsetT = 16;
1098
1099    #[inline]
1100    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
1101        SparseTensor { _tab: table }
1102    }
1103    #[allow(unused_mut)]
1104    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
1105        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
1106        args: &'args SparseTensorArgs<'args>,
1107    ) -> flatbuffers::WIPOffset<SparseTensor<'bldr>> {
1108        let mut builder = SparseTensorBuilder::new(_fbb);
1109        builder.add_non_zero_length(args.non_zero_length);
1110        if let Some(x) = args.data {
1111            builder.add_data(x);
1112        }
1113        if let Some(x) = args.sparseIndex {
1114            builder.add_sparseIndex(x);
1115        }
1116        if let Some(x) = args.shape {
1117            builder.add_shape(x);
1118        }
1119        if let Some(x) = args.type_ {
1120            builder.add_type_(x);
1121        }
1122        builder.add_sparseIndex_type(args.sparseIndex_type);
1123        builder.add_type_type(args.type_type);
1124        builder.finish()
1125    }
1126
1127    #[inline]
1128    pub fn type_type(&self) -> Type {
1129        // Safety:
1130        // Created from valid Table for this object
1131        // which contains a valid value in this slot
1132        unsafe {
1133            self._tab
1134                .get::<Type>(SparseTensor::VT_TYPE_TYPE, Some(Type::NONE))
1135                .unwrap()
1136        }
1137    }
1138    /// The type of data contained in a value cell.
1139    /// Currently only fixed-width value types are supported,
1140    /// no strings or nested types.
1141    #[inline]
1142    pub fn type_(&self) -> flatbuffers::Table<'a> {
1143        // Safety:
1144        // Created from valid Table for this object
1145        // which contains a valid value in this slot
1146        unsafe {
1147            self._tab
1148                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(
1149                    SparseTensor::VT_TYPE_,
1150                    None,
1151                )
1152                .unwrap()
1153        }
1154    }
1155    /// The dimensions of the tensor, optionally named.
1156    #[inline]
1157    pub fn shape(&self) -> flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<TensorDim<'a>>> {
1158        // Safety:
1159        // Created from valid Table for this object
1160        // which contains a valid value in this slot
1161        unsafe {
1162            self._tab
1163                .get::<flatbuffers::ForwardsUOffset<
1164                    flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<TensorDim>>,
1165                >>(SparseTensor::VT_SHAPE, None)
1166                .unwrap()
1167        }
1168    }
1169    /// The number of non-zero values in a sparse tensor.
1170    #[inline]
1171    pub fn non_zero_length(&self) -> i64 {
1172        // Safety:
1173        // Created from valid Table for this object
1174        // which contains a valid value in this slot
1175        unsafe {
1176            self._tab
1177                .get::<i64>(SparseTensor::VT_NON_ZERO_LENGTH, Some(0))
1178                .unwrap()
1179        }
1180    }
1181    #[inline]
1182    pub fn sparseIndex_type(&self) -> SparseTensorIndex {
1183        // Safety:
1184        // Created from valid Table for this object
1185        // which contains a valid value in this slot
1186        unsafe {
1187            self._tab
1188                .get::<SparseTensorIndex>(
1189                    SparseTensor::VT_SPARSEINDEX_TYPE,
1190                    Some(SparseTensorIndex::NONE),
1191                )
1192                .unwrap()
1193        }
1194    }
1195    /// Sparse tensor index
1196    #[inline]
1197    pub fn sparseIndex(&self) -> flatbuffers::Table<'a> {
1198        // Safety:
1199        // Created from valid Table for this object
1200        // which contains a valid value in this slot
1201        unsafe {
1202            self._tab
1203                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(
1204                    SparseTensor::VT_SPARSEINDEX,
1205                    None,
1206                )
1207                .unwrap()
1208        }
1209    }
1210    /// The location and size of the tensor's data
1211    #[inline]
1212    pub fn data(&self) -> &'a Buffer {
1213        // Safety:
1214        // Created from valid Table for this object
1215        // which contains a valid value in this slot
1216        unsafe {
1217            self._tab
1218                .get::<Buffer>(SparseTensor::VT_DATA, None)
1219                .unwrap()
1220        }
1221    }
1222    #[inline]
1223    #[allow(non_snake_case)]
1224    pub fn type_as_null(&self) -> Option<Null<'a>> {
1225        if self.type_type() == Type::Null {
1226            let u = self.type_();
1227            // Safety:
1228            // Created from a valid Table for this object
1229            // Which contains a valid union in this slot
1230            Some(unsafe { Null::init_from_table(u) })
1231        } else {
1232            None
1233        }
1234    }
1235
1236    #[inline]
1237    #[allow(non_snake_case)]
1238    pub fn type_as_int(&self) -> Option<Int<'a>> {
1239        if self.type_type() == Type::Int {
1240            let u = self.type_();
1241            // Safety:
1242            // Created from a valid Table for this object
1243            // Which contains a valid union in this slot
1244            Some(unsafe { Int::init_from_table(u) })
1245        } else {
1246            None
1247        }
1248    }
1249
1250    #[inline]
1251    #[allow(non_snake_case)]
1252    pub fn type_as_floating_point(&self) -> Option<FloatingPoint<'a>> {
1253        if self.type_type() == Type::FloatingPoint {
1254            let u = self.type_();
1255            // Safety:
1256            // Created from a valid Table for this object
1257            // Which contains a valid union in this slot
1258            Some(unsafe { FloatingPoint::init_from_table(u) })
1259        } else {
1260            None
1261        }
1262    }
1263
1264    #[inline]
1265    #[allow(non_snake_case)]
1266    pub fn type_as_binary(&self) -> Option<Binary<'a>> {
1267        if self.type_type() == Type::Binary {
1268            let u = self.type_();
1269            // Safety:
1270            // Created from a valid Table for this object
1271            // Which contains a valid union in this slot
1272            Some(unsafe { Binary::init_from_table(u) })
1273        } else {
1274            None
1275        }
1276    }
1277
1278    #[inline]
1279    #[allow(non_snake_case)]
1280    pub fn type_as_utf_8(&self) -> Option<Utf8<'a>> {
1281        if self.type_type() == Type::Utf8 {
1282            let u = self.type_();
1283            // Safety:
1284            // Created from a valid Table for this object
1285            // Which contains a valid union in this slot
1286            Some(unsafe { Utf8::init_from_table(u) })
1287        } else {
1288            None
1289        }
1290    }
1291
1292    #[inline]
1293    #[allow(non_snake_case)]
1294    pub fn type_as_bool(&self) -> Option<Bool<'a>> {
1295        if self.type_type() == Type::Bool {
1296            let u = self.type_();
1297            // Safety:
1298            // Created from a valid Table for this object
1299            // Which contains a valid union in this slot
1300            Some(unsafe { Bool::init_from_table(u) })
1301        } else {
1302            None
1303        }
1304    }
1305
1306    #[inline]
1307    #[allow(non_snake_case)]
1308    pub fn type_as_decimal(&self) -> Option<Decimal<'a>> {
1309        if self.type_type() == Type::Decimal {
1310            let u = self.type_();
1311            // Safety:
1312            // Created from a valid Table for this object
1313            // Which contains a valid union in this slot
1314            Some(unsafe { Decimal::init_from_table(u) })
1315        } else {
1316            None
1317        }
1318    }
1319
1320    #[inline]
1321    #[allow(non_snake_case)]
1322    pub fn type_as_date(&self) -> Option<Date<'a>> {
1323        if self.type_type() == Type::Date {
1324            let u = self.type_();
1325            // Safety:
1326            // Created from a valid Table for this object
1327            // Which contains a valid union in this slot
1328            Some(unsafe { Date::init_from_table(u) })
1329        } else {
1330            None
1331        }
1332    }
1333
1334    #[inline]
1335    #[allow(non_snake_case)]
1336    pub fn type_as_time(&self) -> Option<Time<'a>> {
1337        if self.type_type() == Type::Time {
1338            let u = self.type_();
1339            // Safety:
1340            // Created from a valid Table for this object
1341            // Which contains a valid union in this slot
1342            Some(unsafe { Time::init_from_table(u) })
1343        } else {
1344            None
1345        }
1346    }
1347
1348    #[inline]
1349    #[allow(non_snake_case)]
1350    pub fn type_as_timestamp(&self) -> Option<Timestamp<'a>> {
1351        if self.type_type() == Type::Timestamp {
1352            let u = self.type_();
1353            // Safety:
1354            // Created from a valid Table for this object
1355            // Which contains a valid union in this slot
1356            Some(unsafe { Timestamp::init_from_table(u) })
1357        } else {
1358            None
1359        }
1360    }
1361
1362    #[inline]
1363    #[allow(non_snake_case)]
1364    pub fn type_as_interval(&self) -> Option<Interval<'a>> {
1365        if self.type_type() == Type::Interval {
1366            let u = self.type_();
1367            // Safety:
1368            // Created from a valid Table for this object
1369            // Which contains a valid union in this slot
1370            Some(unsafe { Interval::init_from_table(u) })
1371        } else {
1372            None
1373        }
1374    }
1375
1376    #[inline]
1377    #[allow(non_snake_case)]
1378    pub fn type_as_list(&self) -> Option<List<'a>> {
1379        if self.type_type() == Type::List {
1380            let u = self.type_();
1381            // Safety:
1382            // Created from a valid Table for this object
1383            // Which contains a valid union in this slot
1384            Some(unsafe { List::init_from_table(u) })
1385        } else {
1386            None
1387        }
1388    }
1389
1390    #[inline]
1391    #[allow(non_snake_case)]
1392    pub fn type_as_struct_(&self) -> Option<Struct_<'a>> {
1393        if self.type_type() == Type::Struct_ {
1394            let u = self.type_();
1395            // Safety:
1396            // Created from a valid Table for this object
1397            // Which contains a valid union in this slot
1398            Some(unsafe { Struct_::init_from_table(u) })
1399        } else {
1400            None
1401        }
1402    }
1403
1404    #[inline]
1405    #[allow(non_snake_case)]
1406    pub fn type_as_union(&self) -> Option<Union<'a>> {
1407        if self.type_type() == Type::Union {
1408            let u = self.type_();
1409            // Safety:
1410            // Created from a valid Table for this object
1411            // Which contains a valid union in this slot
1412            Some(unsafe { Union::init_from_table(u) })
1413        } else {
1414            None
1415        }
1416    }
1417
1418    #[inline]
1419    #[allow(non_snake_case)]
1420    pub fn type_as_fixed_size_binary(&self) -> Option<FixedSizeBinary<'a>> {
1421        if self.type_type() == Type::FixedSizeBinary {
1422            let u = self.type_();
1423            // Safety:
1424            // Created from a valid Table for this object
1425            // Which contains a valid union in this slot
1426            Some(unsafe { FixedSizeBinary::init_from_table(u) })
1427        } else {
1428            None
1429        }
1430    }
1431
1432    #[inline]
1433    #[allow(non_snake_case)]
1434    pub fn type_as_fixed_size_list(&self) -> Option<FixedSizeList<'a>> {
1435        if self.type_type() == Type::FixedSizeList {
1436            let u = self.type_();
1437            // Safety:
1438            // Created from a valid Table for this object
1439            // Which contains a valid union in this slot
1440            Some(unsafe { FixedSizeList::init_from_table(u) })
1441        } else {
1442            None
1443        }
1444    }
1445
1446    #[inline]
1447    #[allow(non_snake_case)]
1448    pub fn type_as_map(&self) -> Option<Map<'a>> {
1449        if self.type_type() == Type::Map {
1450            let u = self.type_();
1451            // Safety:
1452            // Created from a valid Table for this object
1453            // Which contains a valid union in this slot
1454            Some(unsafe { Map::init_from_table(u) })
1455        } else {
1456            None
1457        }
1458    }
1459
1460    #[inline]
1461    #[allow(non_snake_case)]
1462    pub fn type_as_duration(&self) -> Option<Duration<'a>> {
1463        if self.type_type() == Type::Duration {
1464            let u = self.type_();
1465            // Safety:
1466            // Created from a valid Table for this object
1467            // Which contains a valid union in this slot
1468            Some(unsafe { Duration::init_from_table(u) })
1469        } else {
1470            None
1471        }
1472    }
1473
1474    #[inline]
1475    #[allow(non_snake_case)]
1476    pub fn type_as_large_binary(&self) -> Option<LargeBinary<'a>> {
1477        if self.type_type() == Type::LargeBinary {
1478            let u = self.type_();
1479            // Safety:
1480            // Created from a valid Table for this object
1481            // Which contains a valid union in this slot
1482            Some(unsafe { LargeBinary::init_from_table(u) })
1483        } else {
1484            None
1485        }
1486    }
1487
1488    #[inline]
1489    #[allow(non_snake_case)]
1490    pub fn type_as_large_utf_8(&self) -> Option<LargeUtf8<'a>> {
1491        if self.type_type() == Type::LargeUtf8 {
1492            let u = self.type_();
1493            // Safety:
1494            // Created from a valid Table for this object
1495            // Which contains a valid union in this slot
1496            Some(unsafe { LargeUtf8::init_from_table(u) })
1497        } else {
1498            None
1499        }
1500    }
1501
1502    #[inline]
1503    #[allow(non_snake_case)]
1504    pub fn type_as_large_list(&self) -> Option<LargeList<'a>> {
1505        if self.type_type() == Type::LargeList {
1506            let u = self.type_();
1507            // Safety:
1508            // Created from a valid Table for this object
1509            // Which contains a valid union in this slot
1510            Some(unsafe { LargeList::init_from_table(u) })
1511        } else {
1512            None
1513        }
1514    }
1515
1516    #[inline]
1517    #[allow(non_snake_case)]
1518    pub fn type_as_run_end_encoded(&self) -> Option<RunEndEncoded<'a>> {
1519        if self.type_type() == Type::RunEndEncoded {
1520            let u = self.type_();
1521            // Safety:
1522            // Created from a valid Table for this object
1523            // Which contains a valid union in this slot
1524            Some(unsafe { RunEndEncoded::init_from_table(u) })
1525        } else {
1526            None
1527        }
1528    }
1529
1530    #[inline]
1531    #[allow(non_snake_case)]
1532    pub fn type_as_binary_view(&self) -> Option<BinaryView<'a>> {
1533        if self.type_type() == Type::BinaryView {
1534            let u = self.type_();
1535            // Safety:
1536            // Created from a valid Table for this object
1537            // Which contains a valid union in this slot
1538            Some(unsafe { BinaryView::init_from_table(u) })
1539        } else {
1540            None
1541        }
1542    }
1543
1544    #[inline]
1545    #[allow(non_snake_case)]
1546    pub fn type_as_utf_8_view(&self) -> Option<Utf8View<'a>> {
1547        if self.type_type() == Type::Utf8View {
1548            let u = self.type_();
1549            // Safety:
1550            // Created from a valid Table for this object
1551            // Which contains a valid union in this slot
1552            Some(unsafe { Utf8View::init_from_table(u) })
1553        } else {
1554            None
1555        }
1556    }
1557
1558    #[inline]
1559    #[allow(non_snake_case)]
1560    pub fn type_as_list_view(&self) -> Option<ListView<'a>> {
1561        if self.type_type() == Type::ListView {
1562            let u = self.type_();
1563            // Safety:
1564            // Created from a valid Table for this object
1565            // Which contains a valid union in this slot
1566            Some(unsafe { ListView::init_from_table(u) })
1567        } else {
1568            None
1569        }
1570    }
1571
1572    #[inline]
1573    #[allow(non_snake_case)]
1574    pub fn type_as_large_list_view(&self) -> Option<LargeListView<'a>> {
1575        if self.type_type() == Type::LargeListView {
1576            let u = self.type_();
1577            // Safety:
1578            // Created from a valid Table for this object
1579            // Which contains a valid union in this slot
1580            Some(unsafe { LargeListView::init_from_table(u) })
1581        } else {
1582            None
1583        }
1584    }
1585
1586    #[inline]
1587    #[allow(non_snake_case)]
1588    pub fn sparseIndex_as_sparse_tensor_index_coo(&self) -> Option<SparseTensorIndexCOO<'a>> {
1589        if self.sparseIndex_type() == SparseTensorIndex::SparseTensorIndexCOO {
1590            let u = self.sparseIndex();
1591            // Safety:
1592            // Created from a valid Table for this object
1593            // Which contains a valid union in this slot
1594            Some(unsafe { SparseTensorIndexCOO::init_from_table(u) })
1595        } else {
1596            None
1597        }
1598    }
1599
1600    #[inline]
1601    #[allow(non_snake_case)]
1602    pub fn sparseIndex_as_sparse_matrix_index_csx(&self) -> Option<SparseMatrixIndexCSX<'a>> {
1603        if self.sparseIndex_type() == SparseTensorIndex::SparseMatrixIndexCSX {
1604            let u = self.sparseIndex();
1605            // Safety:
1606            // Created from a valid Table for this object
1607            // Which contains a valid union in this slot
1608            Some(unsafe { SparseMatrixIndexCSX::init_from_table(u) })
1609        } else {
1610            None
1611        }
1612    }
1613
1614    #[inline]
1615    #[allow(non_snake_case)]
1616    pub fn sparseIndex_as_sparse_tensor_index_csf(&self) -> Option<SparseTensorIndexCSF<'a>> {
1617        if self.sparseIndex_type() == SparseTensorIndex::SparseTensorIndexCSF {
1618            let u = self.sparseIndex();
1619            // Safety:
1620            // Created from a valid Table for this object
1621            // Which contains a valid union in this slot
1622            Some(unsafe { SparseTensorIndexCSF::init_from_table(u) })
1623        } else {
1624            None
1625        }
1626    }
1627}
1628
1629impl flatbuffers::Verifiable for SparseTensor<'_> {
1630    #[inline]
1631    fn run_verifier(
1632        v: &mut flatbuffers::Verifier,
1633        pos: usize,
1634    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
1635        use flatbuffers::Verifiable;
1636        v.visit_table(pos)?
1637            .visit_union::<Type, _>(
1638                "type_type",
1639                Self::VT_TYPE_TYPE,
1640                "type_",
1641                Self::VT_TYPE_,
1642                true,
1643                |key, v, pos| match key {
1644                    Type::Null => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Null>>(
1645                        "Type::Null",
1646                        pos,
1647                    ),
1648                    Type::Int => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Int>>(
1649                        "Type::Int",
1650                        pos,
1651                    ),
1652                    Type::FloatingPoint => v
1653                        .verify_union_variant::<flatbuffers::ForwardsUOffset<FloatingPoint>>(
1654                            "Type::FloatingPoint",
1655                            pos,
1656                        ),
1657                    Type::Binary => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Binary>>(
1658                        "Type::Binary",
1659                        pos,
1660                    ),
1661                    Type::Utf8 => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Utf8>>(
1662                        "Type::Utf8",
1663                        pos,
1664                    ),
1665                    Type::Bool => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Bool>>(
1666                        "Type::Bool",
1667                        pos,
1668                    ),
1669                    Type::Decimal => v
1670                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Decimal>>(
1671                            "Type::Decimal",
1672                            pos,
1673                        ),
1674                    Type::Date => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Date>>(
1675                        "Type::Date",
1676                        pos,
1677                    ),
1678                    Type::Time => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Time>>(
1679                        "Type::Time",
1680                        pos,
1681                    ),
1682                    Type::Timestamp => v
1683                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Timestamp>>(
1684                            "Type::Timestamp",
1685                            pos,
1686                        ),
1687                    Type::Interval => v
1688                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Interval>>(
1689                            "Type::Interval",
1690                            pos,
1691                        ),
1692                    Type::List => v.verify_union_variant::<flatbuffers::ForwardsUOffset<List>>(
1693                        "Type::List",
1694                        pos,
1695                    ),
1696                    Type::Struct_ => v
1697                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Struct_>>(
1698                            "Type::Struct_",
1699                            pos,
1700                        ),
1701                    Type::Union => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Union>>(
1702                        "Type::Union",
1703                        pos,
1704                    ),
1705                    Type::FixedSizeBinary => v
1706                        .verify_union_variant::<flatbuffers::ForwardsUOffset<FixedSizeBinary>>(
1707                            "Type::FixedSizeBinary",
1708                            pos,
1709                        ),
1710                    Type::FixedSizeList => v
1711                        .verify_union_variant::<flatbuffers::ForwardsUOffset<FixedSizeList>>(
1712                            "Type::FixedSizeList",
1713                            pos,
1714                        ),
1715                    Type::Map => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Map>>(
1716                        "Type::Map",
1717                        pos,
1718                    ),
1719                    Type::Duration => v
1720                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Duration>>(
1721                            "Type::Duration",
1722                            pos,
1723                        ),
1724                    Type::LargeBinary => v
1725                        .verify_union_variant::<flatbuffers::ForwardsUOffset<LargeBinary>>(
1726                            "Type::LargeBinary",
1727                            pos,
1728                        ),
1729                    Type::LargeUtf8 => v
1730                        .verify_union_variant::<flatbuffers::ForwardsUOffset<LargeUtf8>>(
1731                            "Type::LargeUtf8",
1732                            pos,
1733                        ),
1734                    Type::LargeList => v
1735                        .verify_union_variant::<flatbuffers::ForwardsUOffset<LargeList>>(
1736                            "Type::LargeList",
1737                            pos,
1738                        ),
1739                    Type::RunEndEncoded => v
1740                        .verify_union_variant::<flatbuffers::ForwardsUOffset<RunEndEncoded>>(
1741                            "Type::RunEndEncoded",
1742                            pos,
1743                        ),
1744                    Type::BinaryView => v
1745                        .verify_union_variant::<flatbuffers::ForwardsUOffset<BinaryView>>(
1746                            "Type::BinaryView",
1747                            pos,
1748                        ),
1749                    Type::Utf8View => v
1750                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Utf8View>>(
1751                            "Type::Utf8View",
1752                            pos,
1753                        ),
1754                    Type::ListView => v
1755                        .verify_union_variant::<flatbuffers::ForwardsUOffset<ListView>>(
1756                            "Type::ListView",
1757                            pos,
1758                        ),
1759                    Type::LargeListView => v
1760                        .verify_union_variant::<flatbuffers::ForwardsUOffset<LargeListView>>(
1761                            "Type::LargeListView",
1762                            pos,
1763                        ),
1764                    _ => Ok(()),
1765                },
1766            )?
1767            .visit_field::<flatbuffers::ForwardsUOffset<
1768                flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<TensorDim>>,
1769            >>("shape", Self::VT_SHAPE, true)?
1770            .visit_field::<i64>("non_zero_length", Self::VT_NON_ZERO_LENGTH, false)?
1771            .visit_union::<SparseTensorIndex, _>(
1772                "sparseIndex_type",
1773                Self::VT_SPARSEINDEX_TYPE,
1774                "sparseIndex",
1775                Self::VT_SPARSEINDEX,
1776                true,
1777                |key, v, pos| match key {
1778                    SparseTensorIndex::SparseTensorIndexCOO => v
1779                        .verify_union_variant::<flatbuffers::ForwardsUOffset<SparseTensorIndexCOO>>(
1780                            "SparseTensorIndex::SparseTensorIndexCOO",
1781                            pos,
1782                        ),
1783                    SparseTensorIndex::SparseMatrixIndexCSX => v
1784                        .verify_union_variant::<flatbuffers::ForwardsUOffset<SparseMatrixIndexCSX>>(
1785                            "SparseTensorIndex::SparseMatrixIndexCSX",
1786                            pos,
1787                        ),
1788                    SparseTensorIndex::SparseTensorIndexCSF => v
1789                        .verify_union_variant::<flatbuffers::ForwardsUOffset<SparseTensorIndexCSF>>(
1790                            "SparseTensorIndex::SparseTensorIndexCSF",
1791                            pos,
1792                        ),
1793                    _ => Ok(()),
1794                },
1795            )?
1796            .visit_field::<Buffer>("data", Self::VT_DATA, true)?
1797            .finish();
1798        Ok(())
1799    }
1800}
1801pub struct SparseTensorArgs<'a> {
1802    pub type_type: Type,
1803    pub type_: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
1804    pub shape: Option<
1805        flatbuffers::WIPOffset<
1806            flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<TensorDim<'a>>>,
1807        >,
1808    >,
1809    pub non_zero_length: i64,
1810    pub sparseIndex_type: SparseTensorIndex,
1811    pub sparseIndex: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
1812    pub data: Option<&'a Buffer>,
1813}
1814impl<'a> Default for SparseTensorArgs<'a> {
1815    #[inline]
1816    fn default() -> Self {
1817        SparseTensorArgs {
1818            type_type: Type::NONE,
1819            type_: None, // required field
1820            shape: None, // required field
1821            non_zero_length: 0,
1822            sparseIndex_type: SparseTensorIndex::NONE,
1823            sparseIndex: None, // required field
1824            data: None,        // required field
1825        }
1826    }
1827}
1828
1829pub struct SparseTensorBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
1830    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
1831    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
1832}
1833impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> SparseTensorBuilder<'a, 'b, A> {
1834    #[inline]
1835    pub fn add_type_type(&mut self, type_type: Type) {
1836        self.fbb_
1837            .push_slot::<Type>(SparseTensor::VT_TYPE_TYPE, type_type, Type::NONE);
1838    }
1839    #[inline]
1840    pub fn add_type_(&mut self, type_: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>) {
1841        self.fbb_
1842            .push_slot_always::<flatbuffers::WIPOffset<_>>(SparseTensor::VT_TYPE_, type_);
1843    }
1844    #[inline]
1845    pub fn add_shape(
1846        &mut self,
1847        shape: flatbuffers::WIPOffset<
1848            flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset<TensorDim<'b>>>,
1849        >,
1850    ) {
1851        self.fbb_
1852            .push_slot_always::<flatbuffers::WIPOffset<_>>(SparseTensor::VT_SHAPE, shape);
1853    }
1854    #[inline]
1855    pub fn add_non_zero_length(&mut self, non_zero_length: i64) {
1856        self.fbb_
1857            .push_slot::<i64>(SparseTensor::VT_NON_ZERO_LENGTH, non_zero_length, 0);
1858    }
1859    #[inline]
1860    pub fn add_sparseIndex_type(&mut self, sparseIndex_type: SparseTensorIndex) {
1861        self.fbb_.push_slot::<SparseTensorIndex>(
1862            SparseTensor::VT_SPARSEINDEX_TYPE,
1863            sparseIndex_type,
1864            SparseTensorIndex::NONE,
1865        );
1866    }
1867    #[inline]
1868    pub fn add_sparseIndex(
1869        &mut self,
1870        sparseIndex: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>,
1871    ) {
1872        self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(
1873            SparseTensor::VT_SPARSEINDEX,
1874            sparseIndex,
1875        );
1876    }
1877    #[inline]
1878    pub fn add_data(&mut self, data: &Buffer) {
1879        self.fbb_
1880            .push_slot_always::<&Buffer>(SparseTensor::VT_DATA, data);
1881    }
1882    #[inline]
1883    pub fn new(
1884        _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
1885    ) -> SparseTensorBuilder<'a, 'b, A> {
1886        let start = _fbb.start_table();
1887        SparseTensorBuilder {
1888            fbb_: _fbb,
1889            start_: start,
1890        }
1891    }
1892    #[inline]
1893    pub fn finish(self) -> flatbuffers::WIPOffset<SparseTensor<'a>> {
1894        let o = self.fbb_.end_table(self.start_);
1895        self.fbb_.required(o, SparseTensor::VT_TYPE_, "type_");
1896        self.fbb_.required(o, SparseTensor::VT_SHAPE, "shape");
1897        self.fbb_
1898            .required(o, SparseTensor::VT_SPARSEINDEX, "sparseIndex");
1899        self.fbb_.required(o, SparseTensor::VT_DATA, "data");
1900        flatbuffers::WIPOffset::new(o.value())
1901    }
1902}
1903
1904impl core::fmt::Debug for SparseTensor<'_> {
1905    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1906        let mut ds = f.debug_struct("SparseTensor");
1907        ds.field("type_type", &self.type_type());
1908        match self.type_type() {
1909            Type::Null => {
1910                if let Some(x) = self.type_as_null() {
1911                    ds.field("type_", &x)
1912                } else {
1913                    ds.field(
1914                        "type_",
1915                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1916                    )
1917                }
1918            }
1919            Type::Int => {
1920                if let Some(x) = self.type_as_int() {
1921                    ds.field("type_", &x)
1922                } else {
1923                    ds.field(
1924                        "type_",
1925                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1926                    )
1927                }
1928            }
1929            Type::FloatingPoint => {
1930                if let Some(x) = self.type_as_floating_point() {
1931                    ds.field("type_", &x)
1932                } else {
1933                    ds.field(
1934                        "type_",
1935                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1936                    )
1937                }
1938            }
1939            Type::Binary => {
1940                if let Some(x) = self.type_as_binary() {
1941                    ds.field("type_", &x)
1942                } else {
1943                    ds.field(
1944                        "type_",
1945                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1946                    )
1947                }
1948            }
1949            Type::Utf8 => {
1950                if let Some(x) = self.type_as_utf_8() {
1951                    ds.field("type_", &x)
1952                } else {
1953                    ds.field(
1954                        "type_",
1955                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1956                    )
1957                }
1958            }
1959            Type::Bool => {
1960                if let Some(x) = self.type_as_bool() {
1961                    ds.field("type_", &x)
1962                } else {
1963                    ds.field(
1964                        "type_",
1965                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1966                    )
1967                }
1968            }
1969            Type::Decimal => {
1970                if let Some(x) = self.type_as_decimal() {
1971                    ds.field("type_", &x)
1972                } else {
1973                    ds.field(
1974                        "type_",
1975                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1976                    )
1977                }
1978            }
1979            Type::Date => {
1980                if let Some(x) = self.type_as_date() {
1981                    ds.field("type_", &x)
1982                } else {
1983                    ds.field(
1984                        "type_",
1985                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1986                    )
1987                }
1988            }
1989            Type::Time => {
1990                if let Some(x) = self.type_as_time() {
1991                    ds.field("type_", &x)
1992                } else {
1993                    ds.field(
1994                        "type_",
1995                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1996                    )
1997                }
1998            }
1999            Type::Timestamp => {
2000                if let Some(x) = self.type_as_timestamp() {
2001                    ds.field("type_", &x)
2002                } else {
2003                    ds.field(
2004                        "type_",
2005                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2006                    )
2007                }
2008            }
2009            Type::Interval => {
2010                if let Some(x) = self.type_as_interval() {
2011                    ds.field("type_", &x)
2012                } else {
2013                    ds.field(
2014                        "type_",
2015                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2016                    )
2017                }
2018            }
2019            Type::List => {
2020                if let Some(x) = self.type_as_list() {
2021                    ds.field("type_", &x)
2022                } else {
2023                    ds.field(
2024                        "type_",
2025                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2026                    )
2027                }
2028            }
2029            Type::Struct_ => {
2030                if let Some(x) = self.type_as_struct_() {
2031                    ds.field("type_", &x)
2032                } else {
2033                    ds.field(
2034                        "type_",
2035                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2036                    )
2037                }
2038            }
2039            Type::Union => {
2040                if let Some(x) = self.type_as_union() {
2041                    ds.field("type_", &x)
2042                } else {
2043                    ds.field(
2044                        "type_",
2045                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2046                    )
2047                }
2048            }
2049            Type::FixedSizeBinary => {
2050                if let Some(x) = self.type_as_fixed_size_binary() {
2051                    ds.field("type_", &x)
2052                } else {
2053                    ds.field(
2054                        "type_",
2055                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2056                    )
2057                }
2058            }
2059            Type::FixedSizeList => {
2060                if let Some(x) = self.type_as_fixed_size_list() {
2061                    ds.field("type_", &x)
2062                } else {
2063                    ds.field(
2064                        "type_",
2065                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2066                    )
2067                }
2068            }
2069            Type::Map => {
2070                if let Some(x) = self.type_as_map() {
2071                    ds.field("type_", &x)
2072                } else {
2073                    ds.field(
2074                        "type_",
2075                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2076                    )
2077                }
2078            }
2079            Type::Duration => {
2080                if let Some(x) = self.type_as_duration() {
2081                    ds.field("type_", &x)
2082                } else {
2083                    ds.field(
2084                        "type_",
2085                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2086                    )
2087                }
2088            }
2089            Type::LargeBinary => {
2090                if let Some(x) = self.type_as_large_binary() {
2091                    ds.field("type_", &x)
2092                } else {
2093                    ds.field(
2094                        "type_",
2095                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2096                    )
2097                }
2098            }
2099            Type::LargeUtf8 => {
2100                if let Some(x) = self.type_as_large_utf_8() {
2101                    ds.field("type_", &x)
2102                } else {
2103                    ds.field(
2104                        "type_",
2105                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2106                    )
2107                }
2108            }
2109            Type::LargeList => {
2110                if let Some(x) = self.type_as_large_list() {
2111                    ds.field("type_", &x)
2112                } else {
2113                    ds.field(
2114                        "type_",
2115                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2116                    )
2117                }
2118            }
2119            Type::RunEndEncoded => {
2120                if let Some(x) = self.type_as_run_end_encoded() {
2121                    ds.field("type_", &x)
2122                } else {
2123                    ds.field(
2124                        "type_",
2125                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2126                    )
2127                }
2128            }
2129            Type::BinaryView => {
2130                if let Some(x) = self.type_as_binary_view() {
2131                    ds.field("type_", &x)
2132                } else {
2133                    ds.field(
2134                        "type_",
2135                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2136                    )
2137                }
2138            }
2139            Type::Utf8View => {
2140                if let Some(x) = self.type_as_utf_8_view() {
2141                    ds.field("type_", &x)
2142                } else {
2143                    ds.field(
2144                        "type_",
2145                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2146                    )
2147                }
2148            }
2149            Type::ListView => {
2150                if let Some(x) = self.type_as_list_view() {
2151                    ds.field("type_", &x)
2152                } else {
2153                    ds.field(
2154                        "type_",
2155                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2156                    )
2157                }
2158            }
2159            Type::LargeListView => {
2160                if let Some(x) = self.type_as_large_list_view() {
2161                    ds.field("type_", &x)
2162                } else {
2163                    ds.field(
2164                        "type_",
2165                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2166                    )
2167                }
2168            }
2169            _ => {
2170                let x: Option<()> = None;
2171                ds.field("type_", &x)
2172            }
2173        };
2174        ds.field("shape", &self.shape());
2175        ds.field("non_zero_length", &self.non_zero_length());
2176        ds.field("sparseIndex_type", &self.sparseIndex_type());
2177        match self.sparseIndex_type() {
2178            SparseTensorIndex::SparseTensorIndexCOO => {
2179                if let Some(x) = self.sparseIndex_as_sparse_tensor_index_coo() {
2180                    ds.field("sparseIndex", &x)
2181                } else {
2182                    ds.field(
2183                        "sparseIndex",
2184                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2185                    )
2186                }
2187            }
2188            SparseTensorIndex::SparseMatrixIndexCSX => {
2189                if let Some(x) = self.sparseIndex_as_sparse_matrix_index_csx() {
2190                    ds.field("sparseIndex", &x)
2191                } else {
2192                    ds.field(
2193                        "sparseIndex",
2194                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2195                    )
2196                }
2197            }
2198            SparseTensorIndex::SparseTensorIndexCSF => {
2199                if let Some(x) = self.sparseIndex_as_sparse_tensor_index_csf() {
2200                    ds.field("sparseIndex", &x)
2201                } else {
2202                    ds.field(
2203                        "sparseIndex",
2204                        &"InvalidFlatbuffer: Union discriminant does not match value.",
2205                    )
2206                }
2207            }
2208            _ => {
2209                let x: Option<()> = None;
2210                ds.field("sparseIndex", &x)
2211            }
2212        };
2213        ds.field("data", &self.data());
2214        ds.finish()
2215    }
2216}
2217#[inline]
2218/// Verifies that a buffer of bytes contains a `SparseTensor`
2219/// and returns it.
2220/// Note that verification is still experimental and may not
2221/// catch every error, or be maximally performant. For the
2222/// previous, unchecked, behavior use
2223/// `root_as_sparse_tensor_unchecked`.
2224pub fn root_as_sparse_tensor(buf: &[u8]) -> Result<SparseTensor, flatbuffers::InvalidFlatbuffer> {
2225    flatbuffers::root::<SparseTensor>(buf)
2226}
2227#[inline]
2228/// Verifies that a buffer of bytes contains a size prefixed
2229/// `SparseTensor` and returns it.
2230/// Note that verification is still experimental and may not
2231/// catch every error, or be maximally performant. For the
2232/// previous, unchecked, behavior use
2233/// `size_prefixed_root_as_sparse_tensor_unchecked`.
2234pub fn size_prefixed_root_as_sparse_tensor(
2235    buf: &[u8],
2236) -> Result<SparseTensor, flatbuffers::InvalidFlatbuffer> {
2237    flatbuffers::size_prefixed_root::<SparseTensor>(buf)
2238}
2239#[inline]
2240/// Verifies, with the given options, that a buffer of bytes
2241/// contains a `SparseTensor` and returns it.
2242/// Note that verification is still experimental and may not
2243/// catch every error, or be maximally performant. For the
2244/// previous, unchecked, behavior use
2245/// `root_as_sparse_tensor_unchecked`.
2246pub fn root_as_sparse_tensor_with_opts<'b, 'o>(
2247    opts: &'o flatbuffers::VerifierOptions,
2248    buf: &'b [u8],
2249) -> Result<SparseTensor<'b>, flatbuffers::InvalidFlatbuffer> {
2250    flatbuffers::root_with_opts::<SparseTensor<'b>>(opts, buf)
2251}
2252#[inline]
2253/// Verifies, with the given verifier options, that a buffer of
2254/// bytes contains a size prefixed `SparseTensor` and returns
2255/// it. Note that verification is still experimental and may not
2256/// catch every error, or be maximally performant. For the
2257/// previous, unchecked, behavior use
2258/// `root_as_sparse_tensor_unchecked`.
2259pub fn size_prefixed_root_as_sparse_tensor_with_opts<'b, 'o>(
2260    opts: &'o flatbuffers::VerifierOptions,
2261    buf: &'b [u8],
2262) -> Result<SparseTensor<'b>, flatbuffers::InvalidFlatbuffer> {
2263    flatbuffers::size_prefixed_root_with_opts::<SparseTensor<'b>>(opts, buf)
2264}
2265#[inline]
2266/// Assumes, without verification, that a buffer of bytes contains a SparseTensor and returns it.
2267/// # Safety
2268/// Callers must trust the given bytes do indeed contain a valid `SparseTensor`.
2269pub unsafe fn root_as_sparse_tensor_unchecked(buf: &[u8]) -> SparseTensor {
2270    unsafe { flatbuffers::root_unchecked::<SparseTensor>(buf) }
2271}
2272#[inline]
2273/// Assumes, without verification, that a buffer of bytes contains a size prefixed SparseTensor and returns it.
2274/// # Safety
2275/// Callers must trust the given bytes do indeed contain a valid size prefixed `SparseTensor`.
2276pub unsafe fn size_prefixed_root_as_sparse_tensor_unchecked(buf: &[u8]) -> SparseTensor {
2277    unsafe { flatbuffers::size_prefixed_root_unchecked::<SparseTensor>(buf) }
2278}
2279#[inline]
2280pub fn finish_sparse_tensor_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(
2281    fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
2282    root: flatbuffers::WIPOffset<SparseTensor<'a>>,
2283) {
2284    fbb.finish(root, None);
2285}
2286
2287#[inline]
2288pub fn finish_size_prefixed_sparse_tensor_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(
2289    fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
2290    root: flatbuffers::WIPOffset<SparseTensor<'a>>,
2291) {
2292    fbb.finish_size_prefixed(root, None);
2293}