@@ -3,8 +3,6 @@ use crate::lib::{Cow, HashMap, String, ToString, Vec};
33use crate :: slice:: { InvalidSlice , SliceIterator , TensorIndexer } ;
44use bincode:: { Decode , Encode } ;
55use digest:: Digest ;
6- #[ cfg( not( feature = "std" ) ) ]
7- use serde:: { Deserialize , Serialize } ;
86#[ cfg( feature = "std" ) ]
97use std:: io:: Write ;
108
@@ -544,33 +542,16 @@ impl<'data> BinTensors<'data> {
544542
545543/// The stuct representing the header of bintensor files which allow
546544/// indexing into the raw byte-buffer array and how to interpret it.
547- #[ cfg_attr ( feature = "std" , derive( Debug , Clone , Encode , Decode ) ) ]
548- #[ cfg_attr( not ( feature = "std" ) , derive( Debug , Serialize , Deserialize ) ) ]
545+ #[ derive( Debug , Encode , Decode ) ]
546+ #[ cfg_attr( feature = "std" , derive( Clone ) ) ]
549547pub struct Metadata {
548+ #[ bincode( with_serde) ]
550549 metadata : Option < HashMap < String , String > > ,
551550 tensors : Vec < TensorInfo > ,
551+ #[ bincode( with_serde) ]
552552 index_map : HashMap < String , usize > ,
553553}
554554
555- #[ cfg( not( feature = "std" ) ) ]
556- impl bincode:: Encode for Metadata {
557- fn encode < E : bincode:: enc:: Encoder > (
558- & self ,
559- encoder : & mut E ,
560- ) -> Result < ( ) , bincode:: error:: EncodeError > {
561- bincode:: serde:: encode_into_writer ( self , encoder. writer ( ) , bincode:: config:: standard ( ) )
562- }
563- }
564-
565- #[ cfg( not( feature = "std" ) ) ]
566- impl < Context > bincode:: Decode < Context > for Metadata {
567- fn decode < D : bincode:: de:: Decoder < Context = Context > > (
568- decoder : & mut D ,
569- ) -> core:: result:: Result < Self , bincode:: error:: DecodeError > {
570- bincode:: serde:: decode_from_reader ( decoder. reader ( ) , bincode:: config:: standard ( ) )
571- }
572- }
573-
574555impl Metadata {
575556 fn new (
576557 metadata : Option < HashMap < String , String > > ,
@@ -739,8 +720,8 @@ impl<'data> TensorView<'data> {
739720/// A single tensor information.
740721/// Endianness is assumed to be little endian
741722/// Ordering is assumed to be 'C'.
742- #[ cfg_attr ( feature = "std" , derive( Debug , Clone , Encode , Decode ) ) ]
743- #[ cfg_attr( not ( feature = "std" ) , derive( Debug , Serialize , Deserialize ) ) ]
723+ #[ derive( Debug , Encode , Decode ) ]
724+ #[ cfg_attr( feature = "std" , derive( Clone ) ) ]
744725pub struct TensorInfo {
745726 /// The type of each element of the tensor
746727 pub dtype : Dtype ,
@@ -751,24 +732,8 @@ pub struct TensorInfo {
751732}
752733
753734/// The various available dtypes. They MUST be in increasing alignment order
754- #[ cfg_attr(
755- feature = "std" ,
756- derive( Debug , Encode , Decode , Clone , Copy , PartialEq , Eq , Ord , PartialOrd )
757- ) ]
758- #[ cfg_attr(
759- not( feature = "std" ) ,
760- derive(
761- Debug ,
762- Clone ,
763- Copy ,
764- PartialEq ,
765- Eq ,
766- Ord ,
767- PartialOrd ,
768- Serialize ,
769- Deserialize
770- )
771- ) ]
735+
736+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Ord , PartialOrd , Encode , Decode ) ]
772737#[ non_exhaustive]
773738pub enum Dtype {
774739 /// Boolan type
0 commit comments