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