Skip to main content

arrow_ipc/gen/
Tensor.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5#![allow(dead_code)]
6#![allow(unused_imports)]
7
8use crate::r#gen::Schema::*;
9use flatbuffers::EndianScalar;
10use std::{cmp::Ordering, mem};
11// automatically generated by the FlatBuffers compiler, do not modify
12
13// @generated
14
15pub enum TensorDimOffset {}
16#[derive(Copy, Clone, PartialEq)]
17
18/// ----------------------------------------------------------------------
19/// Data structures for dense tensors
20/// Shape data for a single axis in a tensor
21pub struct TensorDim<'a> {
22    pub _tab: flatbuffers::Table<'a>,
23}
24
25impl<'a> flatbuffers::Follow<'a> for TensorDim<'a> {
26    type Inner = TensorDim<'a>;
27    #[inline]
28    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
29        Self {
30            _tab: unsafe { flatbuffers::Table::new(buf, loc) },
31        }
32    }
33}
34
35impl<'a> TensorDim<'a> {
36    pub const VT_SIZE: flatbuffers::VOffsetT = 4;
37    pub const VT_NAME: flatbuffers::VOffsetT = 6;
38
39    #[inline]
40    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
41        TensorDim { _tab: table }
42    }
43    #[allow(unused_mut)]
44    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
45        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
46        args: &'args TensorDimArgs<'args>,
47    ) -> flatbuffers::WIPOffset<TensorDim<'bldr>> {
48        let mut builder = TensorDimBuilder::new(_fbb);
49        builder.add_size(args.size);
50        if let Some(x) = args.name {
51            builder.add_name(x);
52        }
53        builder.finish()
54    }
55
56    /// Length of dimension
57    #[inline]
58    pub fn size(&self) -> i64 {
59        // Safety:
60        // Created from valid Table for this object
61        // which contains a valid value in this slot
62        unsafe { self._tab.get::<i64>(TensorDim::VT_SIZE, Some(0)).unwrap() }
63    }
64    /// Name of the dimension, optional
65    #[inline]
66    pub fn name(&self) -> Option<&'a str> {
67        // Safety:
68        // Created from valid Table for this object
69        // which contains a valid value in this slot
70        unsafe {
71            self._tab
72                .get::<flatbuffers::ForwardsUOffset<&str>>(TensorDim::VT_NAME, None)
73        }
74    }
75}
76
77impl flatbuffers::Verifiable for TensorDim<'_> {
78    #[inline]
79    fn run_verifier(
80        v: &mut flatbuffers::Verifier,
81        pos: usize,
82    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
83        use flatbuffers::Verifiable;
84        v.visit_table(pos)?
85            .visit_field::<i64>("size", Self::VT_SIZE, false)?
86            .visit_field::<flatbuffers::ForwardsUOffset<&str>>("name", Self::VT_NAME, false)?
87            .finish();
88        Ok(())
89    }
90}
91pub struct TensorDimArgs<'a> {
92    pub size: i64,
93    pub name: Option<flatbuffers::WIPOffset<&'a str>>,
94}
95impl<'a> Default for TensorDimArgs<'a> {
96    #[inline]
97    fn default() -> Self {
98        TensorDimArgs {
99            size: 0,
100            name: None,
101        }
102    }
103}
104
105pub struct TensorDimBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
106    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
107    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
108}
109impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> TensorDimBuilder<'a, 'b, A> {
110    #[inline]
111    pub fn add_size(&mut self, size: i64) {
112        self.fbb_.push_slot::<i64>(TensorDim::VT_SIZE, size, 0);
113    }
114    #[inline]
115    pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) {
116        self.fbb_
117            .push_slot_always::<flatbuffers::WIPOffset<_>>(TensorDim::VT_NAME, name);
118    }
119    #[inline]
120    pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> TensorDimBuilder<'a, 'b, A> {
121        let start = _fbb.start_table();
122        TensorDimBuilder {
123            fbb_: _fbb,
124            start_: start,
125        }
126    }
127    #[inline]
128    pub fn finish(self) -> flatbuffers::WIPOffset<TensorDim<'a>> {
129        let o = self.fbb_.end_table(self.start_);
130        flatbuffers::WIPOffset::new(o.value())
131    }
132}
133
134impl core::fmt::Debug for TensorDim<'_> {
135    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
136        let mut ds = f.debug_struct("TensorDim");
137        ds.field("size", &self.size());
138        ds.field("name", &self.name());
139        ds.finish()
140    }
141}
142pub enum TensorOffset {}
143#[derive(Copy, Clone, PartialEq)]
144
145/// DEPRECATED: The recommended way to pass tensors over Arrow IPC is
146/// using columns with the `arrow.fixed_shape_tensor` canonical type.
147pub struct Tensor<'a> {
148    pub _tab: flatbuffers::Table<'a>,
149}
150
151impl<'a> flatbuffers::Follow<'a> for Tensor<'a> {
152    type Inner = Tensor<'a>;
153    #[inline]
154    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
155        Self {
156            _tab: unsafe { flatbuffers::Table::new(buf, loc) },
157        }
158    }
159}
160
161impl<'a> Tensor<'a> {
162    pub const VT_TYPE_TYPE: flatbuffers::VOffsetT = 4;
163    pub const VT_TYPE_: flatbuffers::VOffsetT = 6;
164    pub const VT_SHAPE: flatbuffers::VOffsetT = 8;
165    pub const VT_STRIDES: flatbuffers::VOffsetT = 10;
166    pub const VT_DATA: flatbuffers::VOffsetT = 12;
167
168    #[inline]
169    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
170        Tensor { _tab: table }
171    }
172    #[allow(unused_mut)]
173    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
174        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
175        args: &'args TensorArgs<'args>,
176    ) -> flatbuffers::WIPOffset<Tensor<'bldr>> {
177        let mut builder = TensorBuilder::new(_fbb);
178        if let Some(x) = args.data {
179            builder.add_data(x);
180        }
181        if let Some(x) = args.strides {
182            builder.add_strides(x);
183        }
184        if let Some(x) = args.shape {
185            builder.add_shape(x);
186        }
187        if let Some(x) = args.type_ {
188            builder.add_type_(x);
189        }
190        builder.add_type_type(args.type_type);
191        builder.finish()
192    }
193
194    #[inline]
195    pub fn type_type(&self) -> Type {
196        // Safety:
197        // Created from valid Table for this object
198        // which contains a valid value in this slot
199        unsafe {
200            self._tab
201                .get::<Type>(Tensor::VT_TYPE_TYPE, Some(Type::NONE))
202                .unwrap()
203        }
204    }
205    /// The type of data contained in a value cell. Currently only fixed-width
206    /// value types are supported, no strings or nested types
207    #[inline]
208    pub fn type_(&self) -> flatbuffers::Table<'a> {
209        // Safety:
210        // Created from valid Table for this object
211        // which contains a valid value in this slot
212        unsafe {
213            self._tab
214                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Tensor::VT_TYPE_, None)
215                .unwrap()
216        }
217    }
218    /// The dimensions of the tensor, optionally named
219    #[inline]
220    pub fn shape(&self) -> flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<TensorDim<'a>>> {
221        // Safety:
222        // Created from valid Table for this object
223        // which contains a valid value in this slot
224        unsafe {
225            self._tab
226                .get::<flatbuffers::ForwardsUOffset<
227                    flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<TensorDim>>,
228                >>(Tensor::VT_SHAPE, None)
229                .unwrap()
230        }
231    }
232    /// Non-negative byte offsets to advance one value cell along each dimension
233    /// If omitted, default to row-major order (C-like).
234    #[inline]
235    pub fn strides(&self) -> Option<flatbuffers::Vector<'a, i64>> {
236        // Safety:
237        // Created from valid Table for this object
238        // which contains a valid value in this slot
239        unsafe {
240            self._tab
241                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i64>>>(
242                    Tensor::VT_STRIDES,
243                    None,
244                )
245        }
246    }
247    /// The location and size of the tensor's data
248    #[inline]
249    pub fn data(&self) -> &'a Buffer {
250        // Safety:
251        // Created from valid Table for this object
252        // which contains a valid value in this slot
253        unsafe { self._tab.get::<Buffer>(Tensor::VT_DATA, None).unwrap() }
254    }
255    #[inline]
256    #[allow(non_snake_case)]
257    pub fn type_as_null(&self) -> Option<Null<'a>> {
258        if self.type_type() == Type::Null {
259            let u = self.type_();
260            // Safety:
261            // Created from a valid Table for this object
262            // Which contains a valid union in this slot
263            Some(unsafe { Null::init_from_table(u) })
264        } else {
265            None
266        }
267    }
268
269    #[inline]
270    #[allow(non_snake_case)]
271    pub fn type_as_int(&self) -> Option<Int<'a>> {
272        if self.type_type() == Type::Int {
273            let u = self.type_();
274            // Safety:
275            // Created from a valid Table for this object
276            // Which contains a valid union in this slot
277            Some(unsafe { Int::init_from_table(u) })
278        } else {
279            None
280        }
281    }
282
283    #[inline]
284    #[allow(non_snake_case)]
285    pub fn type_as_floating_point(&self) -> Option<FloatingPoint<'a>> {
286        if self.type_type() == Type::FloatingPoint {
287            let u = self.type_();
288            // Safety:
289            // Created from a valid Table for this object
290            // Which contains a valid union in this slot
291            Some(unsafe { FloatingPoint::init_from_table(u) })
292        } else {
293            None
294        }
295    }
296
297    #[inline]
298    #[allow(non_snake_case)]
299    pub fn type_as_binary(&self) -> Option<Binary<'a>> {
300        if self.type_type() == Type::Binary {
301            let u = self.type_();
302            // Safety:
303            // Created from a valid Table for this object
304            // Which contains a valid union in this slot
305            Some(unsafe { Binary::init_from_table(u) })
306        } else {
307            None
308        }
309    }
310
311    #[inline]
312    #[allow(non_snake_case)]
313    pub fn type_as_utf_8(&self) -> Option<Utf8<'a>> {
314        if self.type_type() == Type::Utf8 {
315            let u = self.type_();
316            // Safety:
317            // Created from a valid Table for this object
318            // Which contains a valid union in this slot
319            Some(unsafe { Utf8::init_from_table(u) })
320        } else {
321            None
322        }
323    }
324
325    #[inline]
326    #[allow(non_snake_case)]
327    pub fn type_as_bool(&self) -> Option<Bool<'a>> {
328        if self.type_type() == Type::Bool {
329            let u = self.type_();
330            // Safety:
331            // Created from a valid Table for this object
332            // Which contains a valid union in this slot
333            Some(unsafe { Bool::init_from_table(u) })
334        } else {
335            None
336        }
337    }
338
339    #[inline]
340    #[allow(non_snake_case)]
341    pub fn type_as_decimal(&self) -> Option<Decimal<'a>> {
342        if self.type_type() == Type::Decimal {
343            let u = self.type_();
344            // Safety:
345            // Created from a valid Table for this object
346            // Which contains a valid union in this slot
347            Some(unsafe { Decimal::init_from_table(u) })
348        } else {
349            None
350        }
351    }
352
353    #[inline]
354    #[allow(non_snake_case)]
355    pub fn type_as_date(&self) -> Option<Date<'a>> {
356        if self.type_type() == Type::Date {
357            let u = self.type_();
358            // Safety:
359            // Created from a valid Table for this object
360            // Which contains a valid union in this slot
361            Some(unsafe { Date::init_from_table(u) })
362        } else {
363            None
364        }
365    }
366
367    #[inline]
368    #[allow(non_snake_case)]
369    pub fn type_as_time(&self) -> Option<Time<'a>> {
370        if self.type_type() == Type::Time {
371            let u = self.type_();
372            // Safety:
373            // Created from a valid Table for this object
374            // Which contains a valid union in this slot
375            Some(unsafe { Time::init_from_table(u) })
376        } else {
377            None
378        }
379    }
380
381    #[inline]
382    #[allow(non_snake_case)]
383    pub fn type_as_timestamp(&self) -> Option<Timestamp<'a>> {
384        if self.type_type() == Type::Timestamp {
385            let u = self.type_();
386            // Safety:
387            // Created from a valid Table for this object
388            // Which contains a valid union in this slot
389            Some(unsafe { Timestamp::init_from_table(u) })
390        } else {
391            None
392        }
393    }
394
395    #[inline]
396    #[allow(non_snake_case)]
397    pub fn type_as_interval(&self) -> Option<Interval<'a>> {
398        if self.type_type() == Type::Interval {
399            let u = self.type_();
400            // Safety:
401            // Created from a valid Table for this object
402            // Which contains a valid union in this slot
403            Some(unsafe { Interval::init_from_table(u) })
404        } else {
405            None
406        }
407    }
408
409    #[inline]
410    #[allow(non_snake_case)]
411    pub fn type_as_list(&self) -> Option<List<'a>> {
412        if self.type_type() == Type::List {
413            let u = self.type_();
414            // Safety:
415            // Created from a valid Table for this object
416            // Which contains a valid union in this slot
417            Some(unsafe { List::init_from_table(u) })
418        } else {
419            None
420        }
421    }
422
423    #[inline]
424    #[allow(non_snake_case)]
425    pub fn type_as_struct_(&self) -> Option<Struct_<'a>> {
426        if self.type_type() == Type::Struct_ {
427            let u = self.type_();
428            // Safety:
429            // Created from a valid Table for this object
430            // Which contains a valid union in this slot
431            Some(unsafe { Struct_::init_from_table(u) })
432        } else {
433            None
434        }
435    }
436
437    #[inline]
438    #[allow(non_snake_case)]
439    pub fn type_as_union(&self) -> Option<Union<'a>> {
440        if self.type_type() == Type::Union {
441            let u = self.type_();
442            // Safety:
443            // Created from a valid Table for this object
444            // Which contains a valid union in this slot
445            Some(unsafe { Union::init_from_table(u) })
446        } else {
447            None
448        }
449    }
450
451    #[inline]
452    #[allow(non_snake_case)]
453    pub fn type_as_fixed_size_binary(&self) -> Option<FixedSizeBinary<'a>> {
454        if self.type_type() == Type::FixedSizeBinary {
455            let u = self.type_();
456            // Safety:
457            // Created from a valid Table for this object
458            // Which contains a valid union in this slot
459            Some(unsafe { FixedSizeBinary::init_from_table(u) })
460        } else {
461            None
462        }
463    }
464
465    #[inline]
466    #[allow(non_snake_case)]
467    pub fn type_as_fixed_size_list(&self) -> Option<FixedSizeList<'a>> {
468        if self.type_type() == Type::FixedSizeList {
469            let u = self.type_();
470            // Safety:
471            // Created from a valid Table for this object
472            // Which contains a valid union in this slot
473            Some(unsafe { FixedSizeList::init_from_table(u) })
474        } else {
475            None
476        }
477    }
478
479    #[inline]
480    #[allow(non_snake_case)]
481    pub fn type_as_map(&self) -> Option<Map<'a>> {
482        if self.type_type() == Type::Map {
483            let u = self.type_();
484            // Safety:
485            // Created from a valid Table for this object
486            // Which contains a valid union in this slot
487            Some(unsafe { Map::init_from_table(u) })
488        } else {
489            None
490        }
491    }
492
493    #[inline]
494    #[allow(non_snake_case)]
495    pub fn type_as_duration(&self) -> Option<Duration<'a>> {
496        if self.type_type() == Type::Duration {
497            let u = self.type_();
498            // Safety:
499            // Created from a valid Table for this object
500            // Which contains a valid union in this slot
501            Some(unsafe { Duration::init_from_table(u) })
502        } else {
503            None
504        }
505    }
506
507    #[inline]
508    #[allow(non_snake_case)]
509    pub fn type_as_large_binary(&self) -> Option<LargeBinary<'a>> {
510        if self.type_type() == Type::LargeBinary {
511            let u = self.type_();
512            // Safety:
513            // Created from a valid Table for this object
514            // Which contains a valid union in this slot
515            Some(unsafe { LargeBinary::init_from_table(u) })
516        } else {
517            None
518        }
519    }
520
521    #[inline]
522    #[allow(non_snake_case)]
523    pub fn type_as_large_utf_8(&self) -> Option<LargeUtf8<'a>> {
524        if self.type_type() == Type::LargeUtf8 {
525            let u = self.type_();
526            // Safety:
527            // Created from a valid Table for this object
528            // Which contains a valid union in this slot
529            Some(unsafe { LargeUtf8::init_from_table(u) })
530        } else {
531            None
532        }
533    }
534
535    #[inline]
536    #[allow(non_snake_case)]
537    pub fn type_as_large_list(&self) -> Option<LargeList<'a>> {
538        if self.type_type() == Type::LargeList {
539            let u = self.type_();
540            // Safety:
541            // Created from a valid Table for this object
542            // Which contains a valid union in this slot
543            Some(unsafe { LargeList::init_from_table(u) })
544        } else {
545            None
546        }
547    }
548
549    #[inline]
550    #[allow(non_snake_case)]
551    pub fn type_as_run_end_encoded(&self) -> Option<RunEndEncoded<'a>> {
552        if self.type_type() == Type::RunEndEncoded {
553            let u = self.type_();
554            // Safety:
555            // Created from a valid Table for this object
556            // Which contains a valid union in this slot
557            Some(unsafe { RunEndEncoded::init_from_table(u) })
558        } else {
559            None
560        }
561    }
562
563    #[inline]
564    #[allow(non_snake_case)]
565    pub fn type_as_binary_view(&self) -> Option<BinaryView<'a>> {
566        if self.type_type() == Type::BinaryView {
567            let u = self.type_();
568            // Safety:
569            // Created from a valid Table for this object
570            // Which contains a valid union in this slot
571            Some(unsafe { BinaryView::init_from_table(u) })
572        } else {
573            None
574        }
575    }
576
577    #[inline]
578    #[allow(non_snake_case)]
579    pub fn type_as_utf_8_view(&self) -> Option<Utf8View<'a>> {
580        if self.type_type() == Type::Utf8View {
581            let u = self.type_();
582            // Safety:
583            // Created from a valid Table for this object
584            // Which contains a valid union in this slot
585            Some(unsafe { Utf8View::init_from_table(u) })
586        } else {
587            None
588        }
589    }
590
591    #[inline]
592    #[allow(non_snake_case)]
593    pub fn type_as_list_view(&self) -> Option<ListView<'a>> {
594        if self.type_type() == Type::ListView {
595            let u = self.type_();
596            // Safety:
597            // Created from a valid Table for this object
598            // Which contains a valid union in this slot
599            Some(unsafe { ListView::init_from_table(u) })
600        } else {
601            None
602        }
603    }
604
605    #[inline]
606    #[allow(non_snake_case)]
607    pub fn type_as_large_list_view(&self) -> Option<LargeListView<'a>> {
608        if self.type_type() == Type::LargeListView {
609            let u = self.type_();
610            // Safety:
611            // Created from a valid Table for this object
612            // Which contains a valid union in this slot
613            Some(unsafe { LargeListView::init_from_table(u) })
614        } else {
615            None
616        }
617    }
618}
619
620impl flatbuffers::Verifiable for Tensor<'_> {
621    #[inline]
622    fn run_verifier(
623        v: &mut flatbuffers::Verifier,
624        pos: usize,
625    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
626        use flatbuffers::Verifiable;
627        v.visit_table(pos)?
628            .visit_union::<Type, _>(
629                "type_type",
630                Self::VT_TYPE_TYPE,
631                "type_",
632                Self::VT_TYPE_,
633                true,
634                |key, v, pos| match key {
635                    Type::Null => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Null>>(
636                        "Type::Null",
637                        pos,
638                    ),
639                    Type::Int => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Int>>(
640                        "Type::Int",
641                        pos,
642                    ),
643                    Type::FloatingPoint => v
644                        .verify_union_variant::<flatbuffers::ForwardsUOffset<FloatingPoint>>(
645                            "Type::FloatingPoint",
646                            pos,
647                        ),
648                    Type::Binary => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Binary>>(
649                        "Type::Binary",
650                        pos,
651                    ),
652                    Type::Utf8 => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Utf8>>(
653                        "Type::Utf8",
654                        pos,
655                    ),
656                    Type::Bool => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Bool>>(
657                        "Type::Bool",
658                        pos,
659                    ),
660                    Type::Decimal => v
661                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Decimal>>(
662                            "Type::Decimal",
663                            pos,
664                        ),
665                    Type::Date => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Date>>(
666                        "Type::Date",
667                        pos,
668                    ),
669                    Type::Time => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Time>>(
670                        "Type::Time",
671                        pos,
672                    ),
673                    Type::Timestamp => v
674                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Timestamp>>(
675                            "Type::Timestamp",
676                            pos,
677                        ),
678                    Type::Interval => v
679                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Interval>>(
680                            "Type::Interval",
681                            pos,
682                        ),
683                    Type::List => v.verify_union_variant::<flatbuffers::ForwardsUOffset<List>>(
684                        "Type::List",
685                        pos,
686                    ),
687                    Type::Struct_ => v
688                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Struct_>>(
689                            "Type::Struct_",
690                            pos,
691                        ),
692                    Type::Union => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Union>>(
693                        "Type::Union",
694                        pos,
695                    ),
696                    Type::FixedSizeBinary => v
697                        .verify_union_variant::<flatbuffers::ForwardsUOffset<FixedSizeBinary>>(
698                            "Type::FixedSizeBinary",
699                            pos,
700                        ),
701                    Type::FixedSizeList => v
702                        .verify_union_variant::<flatbuffers::ForwardsUOffset<FixedSizeList>>(
703                            "Type::FixedSizeList",
704                            pos,
705                        ),
706                    Type::Map => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Map>>(
707                        "Type::Map",
708                        pos,
709                    ),
710                    Type::Duration => v
711                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Duration>>(
712                            "Type::Duration",
713                            pos,
714                        ),
715                    Type::LargeBinary => v
716                        .verify_union_variant::<flatbuffers::ForwardsUOffset<LargeBinary>>(
717                            "Type::LargeBinary",
718                            pos,
719                        ),
720                    Type::LargeUtf8 => v
721                        .verify_union_variant::<flatbuffers::ForwardsUOffset<LargeUtf8>>(
722                            "Type::LargeUtf8",
723                            pos,
724                        ),
725                    Type::LargeList => v
726                        .verify_union_variant::<flatbuffers::ForwardsUOffset<LargeList>>(
727                            "Type::LargeList",
728                            pos,
729                        ),
730                    Type::RunEndEncoded => v
731                        .verify_union_variant::<flatbuffers::ForwardsUOffset<RunEndEncoded>>(
732                            "Type::RunEndEncoded",
733                            pos,
734                        ),
735                    Type::BinaryView => v
736                        .verify_union_variant::<flatbuffers::ForwardsUOffset<BinaryView>>(
737                            "Type::BinaryView",
738                            pos,
739                        ),
740                    Type::Utf8View => v
741                        .verify_union_variant::<flatbuffers::ForwardsUOffset<Utf8View>>(
742                            "Type::Utf8View",
743                            pos,
744                        ),
745                    Type::ListView => v
746                        .verify_union_variant::<flatbuffers::ForwardsUOffset<ListView>>(
747                            "Type::ListView",
748                            pos,
749                        ),
750                    Type::LargeListView => v
751                        .verify_union_variant::<flatbuffers::ForwardsUOffset<LargeListView>>(
752                            "Type::LargeListView",
753                            pos,
754                        ),
755                    _ => Ok(()),
756                },
757            )?
758            .visit_field::<flatbuffers::ForwardsUOffset<
759                flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<TensorDim>>,
760            >>("shape", Self::VT_SHAPE, true)?
761            .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, i64>>>(
762                "strides",
763                Self::VT_STRIDES,
764                false,
765            )?
766            .visit_field::<Buffer>("data", Self::VT_DATA, true)?
767            .finish();
768        Ok(())
769    }
770}
771pub struct TensorArgs<'a> {
772    pub type_type: Type,
773    pub type_: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
774    pub shape: Option<
775        flatbuffers::WIPOffset<
776            flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<TensorDim<'a>>>,
777        >,
778    >,
779    pub strides: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, i64>>>,
780    pub data: Option<&'a Buffer>,
781}
782impl<'a> Default for TensorArgs<'a> {
783    #[inline]
784    fn default() -> Self {
785        TensorArgs {
786            type_type: Type::NONE,
787            type_: None, // required field
788            shape: None, // required field
789            strides: None,
790            data: None, // required field
791        }
792    }
793}
794
795pub struct TensorBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
796    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
797    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
798}
799impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> TensorBuilder<'a, 'b, A> {
800    #[inline]
801    pub fn add_type_type(&mut self, type_type: Type) {
802        self.fbb_
803            .push_slot::<Type>(Tensor::VT_TYPE_TYPE, type_type, Type::NONE);
804    }
805    #[inline]
806    pub fn add_type_(&mut self, type_: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>) {
807        self.fbb_
808            .push_slot_always::<flatbuffers::WIPOffset<_>>(Tensor::VT_TYPE_, type_);
809    }
810    #[inline]
811    pub fn add_shape(
812        &mut self,
813        shape: flatbuffers::WIPOffset<
814            flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset<TensorDim<'b>>>,
815        >,
816    ) {
817        self.fbb_
818            .push_slot_always::<flatbuffers::WIPOffset<_>>(Tensor::VT_SHAPE, shape);
819    }
820    #[inline]
821    pub fn add_strides(&mut self, strides: flatbuffers::WIPOffset<flatbuffers::Vector<'b, i64>>) {
822        self.fbb_
823            .push_slot_always::<flatbuffers::WIPOffset<_>>(Tensor::VT_STRIDES, strides);
824    }
825    #[inline]
826    pub fn add_data(&mut self, data: &Buffer) {
827        self.fbb_.push_slot_always::<&Buffer>(Tensor::VT_DATA, data);
828    }
829    #[inline]
830    pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> TensorBuilder<'a, 'b, A> {
831        let start = _fbb.start_table();
832        TensorBuilder {
833            fbb_: _fbb,
834            start_: start,
835        }
836    }
837    #[inline]
838    pub fn finish(self) -> flatbuffers::WIPOffset<Tensor<'a>> {
839        let o = self.fbb_.end_table(self.start_);
840        self.fbb_.required(o, Tensor::VT_TYPE_, "type_");
841        self.fbb_.required(o, Tensor::VT_SHAPE, "shape");
842        self.fbb_.required(o, Tensor::VT_DATA, "data");
843        flatbuffers::WIPOffset::new(o.value())
844    }
845}
846
847impl core::fmt::Debug for Tensor<'_> {
848    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
849        let mut ds = f.debug_struct("Tensor");
850        ds.field("type_type", &self.type_type());
851        match self.type_type() {
852            Type::Null => {
853                if let Some(x) = self.type_as_null() {
854                    ds.field("type_", &x)
855                } else {
856                    ds.field(
857                        "type_",
858                        &"InvalidFlatbuffer: Union discriminant does not match value.",
859                    )
860                }
861            }
862            Type::Int => {
863                if let Some(x) = self.type_as_int() {
864                    ds.field("type_", &x)
865                } else {
866                    ds.field(
867                        "type_",
868                        &"InvalidFlatbuffer: Union discriminant does not match value.",
869                    )
870                }
871            }
872            Type::FloatingPoint => {
873                if let Some(x) = self.type_as_floating_point() {
874                    ds.field("type_", &x)
875                } else {
876                    ds.field(
877                        "type_",
878                        &"InvalidFlatbuffer: Union discriminant does not match value.",
879                    )
880                }
881            }
882            Type::Binary => {
883                if let Some(x) = self.type_as_binary() {
884                    ds.field("type_", &x)
885                } else {
886                    ds.field(
887                        "type_",
888                        &"InvalidFlatbuffer: Union discriminant does not match value.",
889                    )
890                }
891            }
892            Type::Utf8 => {
893                if let Some(x) = self.type_as_utf_8() {
894                    ds.field("type_", &x)
895                } else {
896                    ds.field(
897                        "type_",
898                        &"InvalidFlatbuffer: Union discriminant does not match value.",
899                    )
900                }
901            }
902            Type::Bool => {
903                if let Some(x) = self.type_as_bool() {
904                    ds.field("type_", &x)
905                } else {
906                    ds.field(
907                        "type_",
908                        &"InvalidFlatbuffer: Union discriminant does not match value.",
909                    )
910                }
911            }
912            Type::Decimal => {
913                if let Some(x) = self.type_as_decimal() {
914                    ds.field("type_", &x)
915                } else {
916                    ds.field(
917                        "type_",
918                        &"InvalidFlatbuffer: Union discriminant does not match value.",
919                    )
920                }
921            }
922            Type::Date => {
923                if let Some(x) = self.type_as_date() {
924                    ds.field("type_", &x)
925                } else {
926                    ds.field(
927                        "type_",
928                        &"InvalidFlatbuffer: Union discriminant does not match value.",
929                    )
930                }
931            }
932            Type::Time => {
933                if let Some(x) = self.type_as_time() {
934                    ds.field("type_", &x)
935                } else {
936                    ds.field(
937                        "type_",
938                        &"InvalidFlatbuffer: Union discriminant does not match value.",
939                    )
940                }
941            }
942            Type::Timestamp => {
943                if let Some(x) = self.type_as_timestamp() {
944                    ds.field("type_", &x)
945                } else {
946                    ds.field(
947                        "type_",
948                        &"InvalidFlatbuffer: Union discriminant does not match value.",
949                    )
950                }
951            }
952            Type::Interval => {
953                if let Some(x) = self.type_as_interval() {
954                    ds.field("type_", &x)
955                } else {
956                    ds.field(
957                        "type_",
958                        &"InvalidFlatbuffer: Union discriminant does not match value.",
959                    )
960                }
961            }
962            Type::List => {
963                if let Some(x) = self.type_as_list() {
964                    ds.field("type_", &x)
965                } else {
966                    ds.field(
967                        "type_",
968                        &"InvalidFlatbuffer: Union discriminant does not match value.",
969                    )
970                }
971            }
972            Type::Struct_ => {
973                if let Some(x) = self.type_as_struct_() {
974                    ds.field("type_", &x)
975                } else {
976                    ds.field(
977                        "type_",
978                        &"InvalidFlatbuffer: Union discriminant does not match value.",
979                    )
980                }
981            }
982            Type::Union => {
983                if let Some(x) = self.type_as_union() {
984                    ds.field("type_", &x)
985                } else {
986                    ds.field(
987                        "type_",
988                        &"InvalidFlatbuffer: Union discriminant does not match value.",
989                    )
990                }
991            }
992            Type::FixedSizeBinary => {
993                if let Some(x) = self.type_as_fixed_size_binary() {
994                    ds.field("type_", &x)
995                } else {
996                    ds.field(
997                        "type_",
998                        &"InvalidFlatbuffer: Union discriminant does not match value.",
999                    )
1000                }
1001            }
1002            Type::FixedSizeList => {
1003                if let Some(x) = self.type_as_fixed_size_list() {
1004                    ds.field("type_", &x)
1005                } else {
1006                    ds.field(
1007                        "type_",
1008                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1009                    )
1010                }
1011            }
1012            Type::Map => {
1013                if let Some(x) = self.type_as_map() {
1014                    ds.field("type_", &x)
1015                } else {
1016                    ds.field(
1017                        "type_",
1018                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1019                    )
1020                }
1021            }
1022            Type::Duration => {
1023                if let Some(x) = self.type_as_duration() {
1024                    ds.field("type_", &x)
1025                } else {
1026                    ds.field(
1027                        "type_",
1028                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1029                    )
1030                }
1031            }
1032            Type::LargeBinary => {
1033                if let Some(x) = self.type_as_large_binary() {
1034                    ds.field("type_", &x)
1035                } else {
1036                    ds.field(
1037                        "type_",
1038                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1039                    )
1040                }
1041            }
1042            Type::LargeUtf8 => {
1043                if let Some(x) = self.type_as_large_utf_8() {
1044                    ds.field("type_", &x)
1045                } else {
1046                    ds.field(
1047                        "type_",
1048                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1049                    )
1050                }
1051            }
1052            Type::LargeList => {
1053                if let Some(x) = self.type_as_large_list() {
1054                    ds.field("type_", &x)
1055                } else {
1056                    ds.field(
1057                        "type_",
1058                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1059                    )
1060                }
1061            }
1062            Type::RunEndEncoded => {
1063                if let Some(x) = self.type_as_run_end_encoded() {
1064                    ds.field("type_", &x)
1065                } else {
1066                    ds.field(
1067                        "type_",
1068                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1069                    )
1070                }
1071            }
1072            Type::BinaryView => {
1073                if let Some(x) = self.type_as_binary_view() {
1074                    ds.field("type_", &x)
1075                } else {
1076                    ds.field(
1077                        "type_",
1078                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1079                    )
1080                }
1081            }
1082            Type::Utf8View => {
1083                if let Some(x) = self.type_as_utf_8_view() {
1084                    ds.field("type_", &x)
1085                } else {
1086                    ds.field(
1087                        "type_",
1088                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1089                    )
1090                }
1091            }
1092            Type::ListView => {
1093                if let Some(x) = self.type_as_list_view() {
1094                    ds.field("type_", &x)
1095                } else {
1096                    ds.field(
1097                        "type_",
1098                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1099                    )
1100                }
1101            }
1102            Type::LargeListView => {
1103                if let Some(x) = self.type_as_large_list_view() {
1104                    ds.field("type_", &x)
1105                } else {
1106                    ds.field(
1107                        "type_",
1108                        &"InvalidFlatbuffer: Union discriminant does not match value.",
1109                    )
1110                }
1111            }
1112            _ => {
1113                let x: Option<()> = None;
1114                ds.field("type_", &x)
1115            }
1116        };
1117        ds.field("shape", &self.shape());
1118        ds.field("strides", &self.strides());
1119        ds.field("data", &self.data());
1120        ds.finish()
1121    }
1122}
1123#[inline]
1124/// Verifies that a buffer of bytes contains a `Tensor`
1125/// and returns it.
1126/// Note that verification is still experimental and may not
1127/// catch every error, or be maximally performant. For the
1128/// previous, unchecked, behavior use
1129/// `root_as_tensor_unchecked`.
1130pub fn root_as_tensor(buf: &[u8]) -> Result<Tensor, flatbuffers::InvalidFlatbuffer> {
1131    flatbuffers::root::<Tensor>(buf)
1132}
1133#[inline]
1134/// Verifies that a buffer of bytes contains a size prefixed
1135/// `Tensor` and returns it.
1136/// Note that verification is still experimental and may not
1137/// catch every error, or be maximally performant. For the
1138/// previous, unchecked, behavior use
1139/// `size_prefixed_root_as_tensor_unchecked`.
1140pub fn size_prefixed_root_as_tensor(buf: &[u8]) -> Result<Tensor, flatbuffers::InvalidFlatbuffer> {
1141    flatbuffers::size_prefixed_root::<Tensor>(buf)
1142}
1143#[inline]
1144/// Verifies, with the given options, that a buffer of bytes
1145/// contains a `Tensor` and returns it.
1146/// Note that verification is still experimental and may not
1147/// catch every error, or be maximally performant. For the
1148/// previous, unchecked, behavior use
1149/// `root_as_tensor_unchecked`.
1150pub fn root_as_tensor_with_opts<'b, 'o>(
1151    opts: &'o flatbuffers::VerifierOptions,
1152    buf: &'b [u8],
1153) -> Result<Tensor<'b>, flatbuffers::InvalidFlatbuffer> {
1154    flatbuffers::root_with_opts::<Tensor<'b>>(opts, buf)
1155}
1156#[inline]
1157/// Verifies, with the given verifier options, that a buffer of
1158/// bytes contains a size prefixed `Tensor` and returns
1159/// it. Note that verification is still experimental and may not
1160/// catch every error, or be maximally performant. For the
1161/// previous, unchecked, behavior use
1162/// `root_as_tensor_unchecked`.
1163pub fn size_prefixed_root_as_tensor_with_opts<'b, 'o>(
1164    opts: &'o flatbuffers::VerifierOptions,
1165    buf: &'b [u8],
1166) -> Result<Tensor<'b>, flatbuffers::InvalidFlatbuffer> {
1167    flatbuffers::size_prefixed_root_with_opts::<Tensor<'b>>(opts, buf)
1168}
1169#[inline]
1170/// Assumes, without verification, that a buffer of bytes contains a Tensor and returns it.
1171/// # Safety
1172/// Callers must trust the given bytes do indeed contain a valid `Tensor`.
1173pub unsafe fn root_as_tensor_unchecked(buf: &[u8]) -> Tensor {
1174    unsafe { flatbuffers::root_unchecked::<Tensor>(buf) }
1175}
1176#[inline]
1177/// Assumes, without verification, that a buffer of bytes contains a size prefixed Tensor and returns it.
1178/// # Safety
1179/// Callers must trust the given bytes do indeed contain a valid size prefixed `Tensor`.
1180pub unsafe fn size_prefixed_root_as_tensor_unchecked(buf: &[u8]) -> Tensor {
1181    unsafe { flatbuffers::size_prefixed_root_unchecked::<Tensor>(buf) }
1182}
1183#[inline]
1184pub fn finish_tensor_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(
1185    fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
1186    root: flatbuffers::WIPOffset<Tensor<'a>>,
1187) {
1188    fbb.finish(root, None);
1189}
1190
1191#[inline]
1192pub fn finish_size_prefixed_tensor_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(
1193    fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
1194    root: flatbuffers::WIPOffset<Tensor<'a>>,
1195) {
1196    fbb.finish_size_prefixed(root, None);
1197}