nncombinator 0.9.8

A library of neural networks that can be written type-safely
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
//! Definition of various errors
use std::{error, fmt, io};
use std::array::TryFromSliceError;
#[cfg(feature = "cuda")]
use std::ffi::CStr;
#[cfg(feature = "cuda")]
use std::fmt::{Formatter};
use std::fmt::{Debug};
use std::num::{ParseFloatError, ParseIntError};
#[cfg(feature = "cuda")]
use cuda_runtime_sys::cudaError_t;
use try_from_primitive::error::FromPrimitiveError;

/// Errors made during neural network training
#[derive(Debug)]
pub enum TrainingError {
    /// Tried to get two or more mutable references from Arc in multiple threads at the same time
    /// (this error is currently not used within crate)
    ReferenceCountError,
    /// Errors occurring within the launched external thread
    /// (this error is currently not used within crate)
    ThreadError(String),
    /// Error generating fixed-length collections from collections of different sizes
    SizeMismatchError(SizeMismatchError),
    /// Illegal input value
    InvalidInputError(String),
    /// Error during forward propagation of neural network
    EvaluateError(EvaluateError),
    /// The value is too large to convert.
    /// (this error is currently not used within crate)
    ToLargeInput(f64),
    /// Error in cuda processing
    #[cfg(feature = "cuda")]
    CudaError(CudaError),
    /// Error in cublas processing
    #[cfg(feature = "cuda")]
    CublasError(rcublas::error::Error),
    /// Error in cudnn processing
    #[cfg(feature = "cuda")]
    CudnnError(rcudnn::Error),
    /// Error in cuda runtime
    #[cfg(feature = "cuda")]
    CudaRuntimeError(CudaRuntimeError),
    /// Errors that occur when the internal state of a particular object or other object is abnormal.
    InvalidStateError(InvalidStateError),
    /// Error that occurs when calling a function that is not supported by the specification
    UnsupportedOperationError(UnsupportedOperationError),
    /// Error raised when cast of primitive type fails
    TypeCastError(String),
    /// Error generated when type conversion fails
    TypeConvertError(TypeConvertError),
    /// Error raised if cast to fixed-length array fails
    TryFromSliceError(TryFromSliceError),
    /// Error raised when the value is not a valid primitive type.
    FromPrimitiveError(FromPrimitiveError),
    /// Error when reading model
    ModelLoadError(ModelLoadError)
}
impl fmt::Display for TrainingError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            TrainingError::ReferenceCountError => write!(f, "There must be only one reference to Arc or Weak to itself when training is performed."),
            TrainingError::ThreadError(s) => write!(f, "An error occurred while processing the thread. cause = ({})",s),
            TrainingError::SizeMismatchError(e) => write!(f, "{}",e),
            TrainingError::InvalidInputError(s) => write!(f, "{}",s),
            TrainingError::EvaluateError(e) => write!(f, "{}",e),
            TrainingError::ToLargeInput(n) => write!(f, "The value is too large to convert. (Value = {})",n),
            #[cfg(feature = "cuda")]
            TrainingError::CudaError(e) => write!(f, "An error occurred in the process of cuda. ({})",e),
            #[cfg(feature = "cuda")]
            TrainingError::CublasError(e) => write!(f, "An error occurred during the execution of a process in cublas. ({})",e),
            #[cfg(feature = "cuda")]
            TrainingError::CudnnError(e) => write!(f, "An error occurred during the execution of a process in cudnn. ({})",e),
            #[cfg(feature = "cuda")]
            TrainingError::CudaRuntimeError(e) => write!(f,"{}",e),
            TrainingError::InvalidStateError(e) => write!(f,"Invalid state. ({})",e),
            TrainingError::UnsupportedOperationError(e) => write!(f,"unsupported operation. ({})",e),
            TrainingError::TypeCastError(s) => write!(f,"{}",s),
            TrainingError::TypeConvertError(e) => write!(f,"{}",e),
            TrainingError::TryFromSliceError(e) => write!(f,"{}",e),
            TrainingError::FromPrimitiveError(e) => write!(f,"{}",e),
            TrainingError::ModelLoadError(e) => write!(f,"{}",e),
        }
    }
}
impl error::Error for TrainingError {
    fn description(&self) -> &str {
        match self {
            TrainingError::ReferenceCountError => "There must be only one reference to Arc or Weak to itself when training is performed.",
            TrainingError::ThreadError(_) => "An error occurred while processing the thread.",
            TrainingError::SizeMismatchError(_) => "memory size does not match.",
            TrainingError::InvalidInputError(_) => "Incorrect input.",
            TrainingError::EvaluateError(_) => "An error occurred when running the neural network.",
            TrainingError::ToLargeInput(_) => "The value is too large to convert.",
            #[cfg(feature = "cuda")]
            TrainingError::CudaError(_) => "An error occurred in the process of cuda.",
            #[cfg(feature = "cuda")]
            TrainingError::CublasError(_) => "An error occurred during the execution of a process in cublas.",
            #[cfg(feature = "cuda")]
            TrainingError::CudnnError(_) => "An error occurred during the execution of a process in cudnn.",
            #[cfg(feature = "cuda")]
            TrainingError::CudaRuntimeError(_) => "An error occurred while running the Cuda kernel.",
            TrainingError::InvalidStateError(_) => "Invalid state.",
            TrainingError::UnsupportedOperationError(_) => "unsupported operation.",
            TrainingError::TypeCastError(_) => "Typecast failed.",
            TrainingError::TypeConvertError(_) => "Type convert failed.",
            TrainingError::TryFromSliceError(_) => "Conversion to fixed-length array failed.",
            TrainingError::FromPrimitiveError(_) => "Conversion from primitive type failed.",
            TrainingError::ModelLoadError(_) => "An error occurred when loading the model.",
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            TrainingError::ReferenceCountError => None,
            TrainingError::ThreadError(_) => None,
            TrainingError::SizeMismatchError(e) => Some(e),
            TrainingError::InvalidInputError(_) => None,
            TrainingError::EvaluateError(e) => Some(e),
            TrainingError::ToLargeInput(_) => None,
            #[cfg(feature = "cuda")]
            TrainingError::CudaError(e) => Some(e),
            #[cfg(feature = "cuda")]
            TrainingError::CublasError(e) => Some(e),
            #[cfg(feature = "cuda")]
            TrainingError::CudnnError(e) => Some(e),
            #[cfg(feature = "cuda")]
            TrainingError::CudaRuntimeError(_) => None,
            TrainingError::InvalidStateError(e) => Some(e),
            TrainingError::UnsupportedOperationError(e) => Some(e),
            TrainingError::TypeCastError(_) => None,
            TrainingError::TypeConvertError(e) => Some(e),
            TrainingError::TryFromSliceError(e) => Some(e),
            TrainingError::FromPrimitiveError(e) => Some(e),
            TrainingError::ModelLoadError(e) => Some(e),
        }
    }
}
/// Error when reading model
#[derive(Debug)]
pub enum ModelLoadError {
    /// IO Error
    IOError(io::Error),
    /// Errors that occur when the internal state of a particular object or other object is abnormal.
    InvalidState(String),
    /// Error when trying to parse a numeric string into numbers
    ParseFloatError(ParseFloatError),
    /// Error when trying to parse a numeric string into integers
    ParseIntError(ParseIntError),
    /// Error in cudnn processing
    #[cfg(feature = "cuda")]
    CudnnError(rcudnn::Error),
    /// Error in specialization
    SpecializationError(SpecializationError),
}
impl fmt::Display for ModelLoadError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            ModelLoadError::IOError(_) => write!(f, "Error occurred in file I/O."),
            ModelLoadError::InvalidState(ref s) => write!(f, "Configuration is invalid. ({})", s),
            ModelLoadError::ParseFloatError(_) => write!(f, "An error occurred when converting a string to a double value."),
            ModelLoadError::ParseIntError(_) => write!(f, "An error occurred when converting a string to an integer value."),
            #[cfg(feature = "cuda")]
            ModelLoadError::CudnnError(e) => write!(f, "An error occurred during the execution of a process in cudnn. ({})", e),
            ModelLoadError::SpecializationError(e) => write!(f, "An error occurred during specialization. ({})", e),
        }
    }
}
impl error::Error for ModelLoadError {
    fn description(&self) -> &str {
        match self {
            ModelLoadError::IOError(_) => "Error occurred in file I/O.",
            ModelLoadError::InvalidState(_) => "Configuration is invalid.",
            ModelLoadError::ParseFloatError(_) => "An error occurred when converting a string to a double value.",
            ModelLoadError::ParseIntError(_) => "An error occurred when converting a string to an integer value.",
            #[cfg(feature = "cuda")]
            ModelLoadError::CudnnError(_) => "An error occurred during the execution of a process in cudnn.",
            ModelLoadError::SpecializationError(_) => "An error occurred during specialization."
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            ModelLoadError::IOError(ref e) => Some(e),
            ModelLoadError::InvalidState(_) => None,
            ModelLoadError::ParseFloatError(ref e) => Some(e),
            ModelLoadError::ParseIntError(ref e) => Some(e),
            #[cfg(feature = "cuda")]
            ModelLoadError::CudnnError(ref e) => Some(e),
            ModelLoadError::SpecializationError(ref e) => Some(e)
        }
    }
}
impl From<SizeMismatchError> for TrainingError {
    fn from(err: SizeMismatchError) -> TrainingError {
        TrainingError::SizeMismatchError(err)
    }
}
impl From<TypeConvertError> for TrainingError {
    fn from(err: TypeConvertError) -> TrainingError {
        TrainingError::TypeConvertError(err)
    }
}
impl From<EvaluateError> for TrainingError {
    fn from(err: EvaluateError) -> TrainingError {
        TrainingError::EvaluateError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<CudaError> for TrainingError {
    fn from(err: CudaError) -> TrainingError {
        TrainingError::CudaError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcublas::error::Error> for TrainingError {
    fn from(err: rcublas::error::Error) -> TrainingError {
        TrainingError::CublasError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcudnn::Error> for TrainingError {
    fn from(err: rcudnn::Error) -> TrainingError {
        TrainingError::CudnnError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<CudaRuntimeError> for TrainingError {
    fn from(err: CudaRuntimeError) -> TrainingError {
        TrainingError::CudaRuntimeError(err)
    }
}
impl From<InvalidStateError> for TrainingError {
    fn from(err: InvalidStateError) -> TrainingError {
        TrainingError::InvalidStateError(err)
    }
}
impl From<UnsupportedOperationError> for TrainingError {
    fn from(err: UnsupportedOperationError) -> TrainingError {
        TrainingError::UnsupportedOperationError(err)
    }
}
impl From<ModelLoadError> for TrainingError {
    fn from(err: ModelLoadError) -> TrainingError {
        TrainingError::ModelLoadError(err)
    }
}
impl From<io::Error> for ModelLoadError {
    fn from(err: io::Error) -> ModelLoadError {
        ModelLoadError::IOError(err)
    }
}
impl From<ParseFloatError> for ModelLoadError {
    fn from(err: ParseFloatError) -> ModelLoadError {
        ModelLoadError::ParseFloatError(err)
    }
}
impl From<ParseIntError> for ModelLoadError {
    fn from(err: ParseIntError) -> ModelLoadError {
        ModelLoadError::ParseIntError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcudnn::Error> for ModelLoadError {
    fn from(err: rcudnn::Error) -> ModelLoadError {
        ModelLoadError::CudnnError(err)
    }
}
impl From<SpecializationError> for ModelLoadError {
    fn from(err: SpecializationError) -> ModelLoadError {
        ModelLoadError::SpecializationError(err)
    }
}
impl From<TryFromSliceError> for TrainingError {
    fn from(err: TryFromSliceError) -> TrainingError {
        TrainingError::TryFromSliceError(err)
    }
}
impl From<FromPrimitiveError> for TrainingError {
    fn from(err: FromPrimitiveError) -> TrainingError {
        TrainingError::FromPrimitiveError(err)
    }
}
/// Error generating fixed-length collections from collections of different sizes
#[derive(Debug)]
pub struct SizeMismatchError(pub usize, pub usize);
impl fmt::Display for SizeMismatchError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            SizeMismatchError(from, to) => {
                write!(f, "memory size does not match. (from = {}, to = {})",from,to)
            }
        }
    }
}
impl error::Error for SizeMismatchError {
    fn description(&self) -> &str {
        "memory size does not match."
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        None
    }
}
/// An error that occurs when creating a fixed-length collection from collections
/// of different sizes, when the number of elements in the converted collection is not divisible
/// by the number of elements in the destination collection.
#[derive(Debug)]
pub struct IndivisibleError(pub usize, pub usize);
impl fmt::Display for IndivisibleError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            IndivisibleError(from, to) => {
                write!(f, "memory size indivisible. (dividend = {}, divisor = {})",from,to)
            }
        }
    }
}
impl error::Error for IndivisibleError {
    fn description(&self) -> &str {
        "memory size indivisible."
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        None
    }
}
#[derive(Debug)]
pub enum TypeConvertError {
    /// Error generating fixed-length collections from collections of different sizes
    SizeMismatchError(SizeMismatchError),
    /// Error when creating a fixed length collection from collections of different sizes (left side not divisible by right side)
    IndivisibleError(IndivisibleError),
    /// Error in cuda processing
    #[cfg(feature = "cuda")]
    CudaError(CudaError),
    /// Error in cudnn processing
    #[cfg(feature = "cuda")]
    CudnnError(rcudnn::Error),
}
impl fmt::Display for TypeConvertError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            TypeConvertError::SizeMismatchError(e) => write!(f,"{}",e),
            TypeConvertError::IndivisibleError(e) => write!(f,"{}",e),
            #[cfg(feature = "cuda")]
            TypeConvertError::CudaError(e) => write!(f, "An error occurred in the process of cuda. ({})",e),
            #[cfg(feature = "cuda")]
            TypeConvertError::CudnnError(e) => write!(f, "An error occurred during the execution of a process in cudnn. ({})",e),
        }
    }
}
impl error::Error for TypeConvertError {
    fn description(&self) -> &str {
        match *self {
            TypeConvertError::SizeMismatchError(_) => "memory size does not match.",
            TypeConvertError::IndivisibleError(_) => "memory size indivisible.",
            #[cfg(feature = "cuda")]
            TypeConvertError::CudaError(_) => "An error occurred in the process of cuda.",
            #[cfg(feature = "cuda")]
            TypeConvertError::CudnnError(_) => "An error occurred during the execution of a process in cudnn.",
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            TypeConvertError::SizeMismatchError(e) => Some(e),
            TypeConvertError::IndivisibleError(e) => Some(e),
            #[cfg(feature = "cuda")]
            TypeConvertError::CudaError(e) => Some(e),
            #[cfg(feature = "cuda")]
            TypeConvertError::CudnnError(e) => Some(e)
        }
    }
}
impl From<SizeMismatchError> for TypeConvertError {
    fn from(err: SizeMismatchError) -> TypeConvertError {
        TypeConvertError::SizeMismatchError(err)
    }
}
impl From<IndivisibleError> for TypeConvertError {
    fn from(err: IndivisibleError) -> TypeConvertError {
        TypeConvertError::IndivisibleError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<CudaError> for TypeConvertError {
    fn from(err: CudaError) -> TypeConvertError {
        TypeConvertError::CudaError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcudnn::Error> for TypeConvertError {
    fn from(err: rcudnn::Error) -> TypeConvertError {
        TypeConvertError::CudnnError(err)
    }
}
/// Error when accessing array out of range
#[derive(Debug)]
pub struct IndexOutBoundError {
    len:usize,
    index:usize
}
impl fmt::Display for IndexOutBoundError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            IndexOutBoundError { len, index}  => {
                write!(f, "The value {} specified for the index is out of range; it exceeds {}.",index, len - 1)
            }
        }
    }
}
impl error::Error for IndexOutBoundError {
    fn description(&self) -> &str {
        "The value specified for the index is out of range."
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        None
    }
}
impl IndexOutBoundError {
    /// Creation of an instance of IndexOutBoundError
    /// # Arguments
    /// * `len` - max len
    /// * `index` - Specified index
    pub fn new(len:usize,index:usize) -> IndexOutBoundError {
        IndexOutBoundError {
            len:len,
            index:index
        }
    }
}
/// Error during forward propagation of neural network
#[derive(Debug)]
pub enum EvaluateError {
    /// Error in cuda processing
    #[cfg(feature = "cuda")]
    CudaError(CudaError),
    /// Error in cublas processing
    #[cfg(feature = "cuda")]
    CublasError(rcublas::error::Error),
    /// Error in cudnn processing
    #[cfg(feature = "cuda")]
    CudnnError(rcudnn::Error),
    /// Error in cuda runtime
    #[cfg(feature = "cuda")]
    CudaRuntimeError(CudaRuntimeError),
    /// Error generating fixed-length collections from collections of different sizes
    SizeMismatchError(SizeMismatchError),
    /// Errors that occur when the internal state of a particular object or other object is abnormal.
    InvalidStateError(InvalidStateError),
    /// Error raised when cast of primitive type fails
    TypeCastError(String),
    /// Error generated when type conversion fails
    TypeConvertError(TypeConvertError),
    /// Error raised if cast to fixed-length array fails
    TryFromSliceError(TryFromSliceError)
}
impl fmt::Display for EvaluateError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            #[cfg(feature = "cuda")]
            EvaluateError::CudaError(e) => write!(f, "An error occurred in the process of cuda. ({})", e),
            #[cfg(feature = "cuda")]
            EvaluateError::CublasError(e) => write!(f, "An error occurred during the execution of a process in cublas. ({})", e),
            #[cfg(feature = "cuda")]
            EvaluateError::CudnnError(e) => write!(f, "An error occurred during the execution of a process in cudnn. ({})", e),
            #[cfg(feature = "cuda")]
            EvaluateError::CudaRuntimeError(e) => write!(f,"{}",e),
            EvaluateError::SizeMismatchError(e) => write!(f,"{}",e),
            EvaluateError::InvalidStateError(e) => write!(f,"Invalid state. ({})",e),
            EvaluateError::TypeCastError(s) => write!(f,"{}",s),
            EvaluateError::TypeConvertError(e) => write!(f,"{}",e),
            EvaluateError::TryFromSliceError(e) => write!(f,"{}",e)
        }
    }
}
impl error::Error for EvaluateError {
    fn description(&self) -> &str {
        match self {
            #[cfg(feature = "cuda")]
            EvaluateError::CudaError(_) => "An error occurred in the process of cuda.",
            #[cfg(feature = "cuda")]
            EvaluateError::CublasError(_) => "An error occurred during the execution of a process in cublas.",
            #[cfg(feature = "cuda")]
            EvaluateError::CudnnError(_) => "An error occurred during the execution of a process in cudnn.",
            #[cfg(feature = "cuda")]
            EvaluateError::CudaRuntimeError(_) => "An error occurred while running the Cuda kernel.",
            EvaluateError::SizeMismatchError(_) => "memory size does not match.",
            EvaluateError::InvalidStateError(_) => "Invalid state.",
            EvaluateError::TypeCastError(_) => "Typecast failed.",
            EvaluateError::TypeConvertError(_) => "Type covert failed.",
            EvaluateError::TryFromSliceError(_) => "Conversion to fixed-length array failed."
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            #[cfg(feature = "cuda")]
            EvaluateError::CudaError(e) => Some(e),
            #[cfg(feature = "cuda")]
            EvaluateError::CublasError(e) => Some(e),
            #[cfg(feature = "cuda")]
            EvaluateError::CudnnError(e) => Some(e),
            #[cfg(feature = "cuda")]
            EvaluateError::CudaRuntimeError(_) => None,
            EvaluateError::SizeMismatchError(e) => Some(e),
            EvaluateError::InvalidStateError(e) => Some(e),
            EvaluateError::TypeCastError(_) => None,
            EvaluateError::TypeConvertError(e) => Some(e),
            EvaluateError::TryFromSliceError(e) => Some(e)
        }
    }
}
#[cfg(feature = "cuda")]
impl From<CudaError> for EvaluateError {
    fn from(err: CudaError) -> EvaluateError {
        EvaluateError::CudaError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcublas::error::Error> for EvaluateError {
    fn from(err: rcublas::error::Error) -> EvaluateError {
        EvaluateError::CublasError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcudnn::Error> for EvaluateError {
    fn from(err: rcudnn::Error) -> EvaluateError {
        EvaluateError::CudnnError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<CudaRuntimeError> for EvaluateError {
    fn from(err: CudaRuntimeError) -> EvaluateError {
        EvaluateError::CudaRuntimeError(err)
    }
}
impl From<SizeMismatchError> for EvaluateError {
    fn from(err: SizeMismatchError) -> EvaluateError {
        EvaluateError::SizeMismatchError(err)
    }
}
impl From<TypeConvertError> for EvaluateError {
    fn from(err: TypeConvertError) -> EvaluateError {
        EvaluateError::TypeConvertError(err)
    }
}
impl From<InvalidStateError> for EvaluateError {
    fn from(err: InvalidStateError) -> EvaluateError {
        EvaluateError::InvalidStateError(err)
    }
}
impl From<TryFromSliceError> for EvaluateError {
    fn from(err: TryFromSliceError) -> EvaluateError {
        EvaluateError::TryFromSliceError(err)
    }
}
#[derive(Debug)]
pub enum PersistenceError {
    /// Error in cudnn processing
    #[cfg(feature = "cuda")]
    CudnnError(rcudnn::Error),
    /// Errors caused by generating fixed-length arrays from different size Vecs
    SizeMismatchError(SizeMismatchError),
    /// Error generated when type conversion fails
    TypeConvertError(TypeConvertError),
    /// Error in generalization
    GeneralizationError(GeneralizationError),
}
impl fmt::Display for PersistenceError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            #[cfg(feature = "cuda")]
            PersistenceError::CudnnError(e) => write!(f, "An error occurred during the execution of a process in cudnn. ({})",e),
            PersistenceError::SizeMismatchError(e) => write!(f, "{}",e),
            PersistenceError::TypeConvertError(e) => write!(f,"{}",e),
            PersistenceError::GeneralizationError(e) => write!(f,"{}",e),
        }
    }
}
impl error::Error for PersistenceError {
    fn description(&self) -> &str {
        match *self {
            #[cfg(feature = "cuda")]
            PersistenceError::CudnnError(_) => "An error occurred during the execution of a process in cudnn.",
            PersistenceError::SizeMismatchError(_) => "memory size does not match.",
            PersistenceError::TypeConvertError(_) => "Type convert failed.",
            PersistenceError::GeneralizationError(_) => "An error occurred during generalization.",
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match *self {
            #[cfg(feature = "cuda")]
            PersistenceError::CudnnError(ref e) => Some(e),
            PersistenceError::SizeMismatchError(ref e) => Some(e),
            PersistenceError::TypeConvertError(ref e) => Some(e),
            PersistenceError::GeneralizationError(ref e) => Some(e),
        }
    }
}
#[cfg(feature = "cuda")]
impl From<rcudnn::Error> for PersistenceError {
    fn from(err: rcudnn::Error) -> PersistenceError {
        PersistenceError::CudnnError(err)
    }
}
impl From<SizeMismatchError> for PersistenceError {
    fn from(err: SizeMismatchError) -> PersistenceError {
        PersistenceError::SizeMismatchError(err)
    }
}
impl From<TypeConvertError> for PersistenceError {
    fn from(err: TypeConvertError) -> PersistenceError {
        PersistenceError::TypeConvertError(err)
    }
}
impl From<GeneralizationError> for PersistenceError {
    fn from(err: GeneralizationError) -> PersistenceError {
        PersistenceError::GeneralizationError(err)
    }
}
/// Error in cuda processing
#[cfg(feature = "cuda")]
#[derive(Debug)]
pub enum CudaError {
    /// Memory allocation failed.
    AllocFailed(String),
    /// Error in cudnn processing
    CudnnError(rcudnn::Error),
    /// Error in cublas processing
    CublasError(rcublas::error::Error),
    /// Errors that occur when the internal state of a particular object or other object is abnormal.
    InvalidState(String),
    /// There is a problem with the implementation logic of the program
    LogicError(String),
    /// Error that occurs when a specified argument or other setting value is invalid.
    InvalidConfigurationError(String),
}
#[cfg(feature = "cuda")]
impl fmt::Display for CudaError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            CudaError::AllocFailed(s) => write!(f, "{}", s),
            CudaError::CudnnError(e) => write!(f, "An error occurred during the execution of a process in cudnn. ({})", e),
            CudaError::CublasError(e) => write!(f, "An error occurred during the execution of a process in cublas. ({})", e),
            CudaError::InvalidState(s) => write!(f, "{}", s),
            CudaError::LogicError(s) => write!(f,"{}",s),
            CudaError::InvalidConfigurationError(s) => write!(f,"{}",s),
        }
    }
}
#[cfg(feature = "cuda")]
impl error::Error for CudaError {
    fn description(&self) -> &str {
        match self {
            CudaError::AllocFailed(_) => "Memory allocation failed.",
            CudaError::CudnnError(_) => "An error occurred during the execution of a process in cudnn.",
            CudaError::CublasError(_) => "An error occurred during the execution of a process in cublas.",
            CudaError::InvalidState(_) => "Invalid state.s",
            CudaError::LogicError(_) => "Logic error.",
            CudaError::InvalidConfigurationError(_) => "Invalid configuration.",
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            CudaError::AllocFailed(_) => None,
            CudaError::CudnnError(e) => Some(e),
            CudaError::CublasError(e) => Some(e),
            CudaError::InvalidState(_) => None,
            CudaError::LogicError(_) => None,
            CudaError::InvalidConfigurationError(_) => None,
        }
    }
}
#[cfg(feature = "cuda")]
impl From<rcudnn::Error> for CudaError {
    fn from(err: rcudnn::Error) -> CudaError {
        CudaError::CudnnError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcublas::Error> for CudaError {
    fn from(err: rcublas::error::Error) -> CudaError {
        CudaError::CublasError(err)
    }
}
/// Errors that occur in processes implemented in objects that implement Device Traits
#[derive(Debug)]
pub enum DeviceError {
    /// Error in cuda processing
    #[cfg(feature = "cuda")]
    CudaError(CudaError),
    /// Error in cublas processing
    #[cfg(feature = "cuda")]
    CublasError(rcublas::error::Error),
    /// Error in cudnn processing
    #[cfg(feature = "cuda")]
    CudnnError(rcudnn::Error),
}
#[cfg(feature = "cuda")]
impl fmt::Display for DeviceError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            DeviceError::CudaError(e) => write!(f, "An error occurred in the process of cuda. ({})", e),
            DeviceError::CublasError(e) => write!(f, "An error occurred during the execution of a process in cublas. ({})", e),
            DeviceError::CudnnError(e) => write!(f, "An error occurred during the execution of a process in cudnn. ({})", e),
        }
    }
}
#[cfg(not(feature = "cuda"))]
impl fmt::Display for DeviceError {
    fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
        unreachable!()
    }
}
#[cfg(feature = "cuda")]
impl error::Error for DeviceError {
    fn description(&self) -> &str {
        match self {
            DeviceError::CudaError(_) => "Asn error occurred in the process of cuda.",
            DeviceError::CublasError(_) => "An error occurred during the execution of a process in cublas.",
            DeviceError::CudnnError(_) => "An error occurred during the execution of a process in cudnn.",
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            DeviceError::CudaError(e) => Some(e),
            DeviceError::CublasError(e) => Some(e),
            DeviceError::CudnnError(e) => Some(e),
        }
    }
}
#[cfg(not(feature = "cuda"))]
impl error::Error for DeviceError {
    fn description(&self) -> &str {
        unreachable!()
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        unreachable!()
    }
}
#[cfg(feature = "cuda")]
impl From<CudaError> for DeviceError {
    fn from(err: CudaError) -> DeviceError {
        DeviceError::CudaError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcublas::error::Error> for DeviceError {
    fn from(err: rcublas::error::Error) -> DeviceError {
        DeviceError::CublasError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcudnn::Error> for DeviceError {
    fn from(err: rcudnn::Error) -> DeviceError {
        DeviceError::CudnnError(err)
    }
}
/// Errors that occur when the internal state of a particular object or other object is abnormal.
#[derive(Debug)]
pub struct InvalidStateError(pub String);
impl fmt::Display for InvalidStateError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            InvalidStateError(s) => {
                write!(f,"{}",s)
            }
        }
    }
}
impl error::Error for InvalidStateError {
    fn description(&self) -> &str {
        match self {
            InvalidStateError(_) => "Invalid state."
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            InvalidStateError(_) => None,
        }
    }
}
/// Error that occurs when calling a function that is not supported by the specification
#[derive(Debug,PartialEq,Eq)]
pub struct UnsupportedOperationError(pub String);
impl fmt::Display for UnsupportedOperationError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            UnsupportedOperationError(s) => {
                write!(f,"{}",s)
            }
        }
    }
}
impl error::Error for UnsupportedOperationError {
    fn description(&self) -> &str {
        match self {
            UnsupportedOperationError(_) => "unsupported operation."
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            UnsupportedOperationError(_) => None,
        }
    }
}
/// Error in cuda runtime
#[cfg(feature = "cuda")]
pub struct CudaRuntimeError {
    raw: cudaError_t,
}
#[cfg(feature = "cuda")]
impl fmt::Debug for CudaRuntimeError {
    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
        write!(f,"{}",unsafe { CStr::from_ptr(cuda_runtime_sys::cudaGetErrorString(self.raw)) }.to_string_lossy())
    }
}
#[cfg(feature = "cuda")]
impl fmt::Display for CudaRuntimeError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f,"An error occurred while running the Cuda kernel. cause = {}",
            unsafe { CStr::from_ptr(cuda_runtime_sys::cudaGetErrorString(self.raw)) }.to_string_lossy()
        )
    }
}
#[cfg(feature = "cuda")]
impl error::Error for CudaRuntimeError {
    fn description(&self) -> &str {
        "An error occurred while running the Cuda kernel."
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        None
    }
}
#[cfg(feature = "cuda")]
impl CudaRuntimeError {
    /// Creation of an instance of CudaRuntimeError
    pub fn new(raw:cudaError_t) -> CudaRuntimeError {
        CudaRuntimeError {
            raw: raw
        }
    }
}
/// Error when layer instantiation fails
#[derive(Debug)]
pub enum LayerInstantiationError {
    /// Error in cuda processing
    #[cfg(feature = "cuda")]
    CudaError(CudaError),
    /// Error in cudnn processing
    #[cfg(feature = "cuda")]
    CudnnError(rcudnn::Error),
    /// Error in build optimizer processing
    OptimizerBuildError(OptimizerBuildError),
    /// Errors caused by generating fixed-length arrays from different size Vecs
    SizeMismatchError(SizeMismatchError),
    /// Error generated when type conversion fails
    TypeConvertError(TypeConvertError),
    /// Error during data specialization
    SpecializationError(SpecializationError)

}
impl fmt::Display for LayerInstantiationError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            #[cfg(feature = "cuda")]
            LayerInstantiationError::CudaError(e) => {
                write!(f,"An unexpected error occurred during layer instantiation ({})",e)
            },
            #[cfg(feature = "cuda")]
            LayerInstantiationError::CudnnError(e) => {
                write!(f,"An unexpected error occurred during layer instantiation ({})",e)
            },
            LayerInstantiationError::OptimizerBuildError(e) => {
                write!(f,"An unexpected error occurred during build optimizer ({})",e)
            },
            LayerInstantiationError::SizeMismatchError(e) => {
                write!(f,"An unexpected error occurred during layer instantiation ({})",e)
            },
            LayerInstantiationError::TypeConvertError(e) => {
                write!(f,"An unexpected error occurred during layer instantiation ({})",e)
            },
            LayerInstantiationError::SpecializationError(e) => {
                write!(f,"An unexpected error occurred during layer instantiation ({})",e)
            }
        }
    }
}
impl error::Error for LayerInstantiationError {
    fn description(&self) -> &str {
        match self {
            #[cfg(feature = "cuda")]
            LayerInstantiationError::CudaError(_) => {
                "An unexpected error occurred during layer instantiation (An error occurred in the process of cudas)."
            },
            #[cfg(feature = "cuda")]
            LayerInstantiationError::CudnnError(_) => {
                "An unexpected error occurred during layer instantiation (An error occurred in the process of cudnns)."
            },
            LayerInstantiationError::OptimizerBuildError(_) => {
                "An unexpected error occurred during build optimizer (An error occurred in the process of cudas)."
            },
            LayerInstantiationError::SizeMismatchError(_) => {
                "An unexpected error occurred during layer instantiation. (Error during conversion to fixed length array)."
            },
            LayerInstantiationError::TypeConvertError(_) => {
                "An error occurred during a type conversion operation within the layer object creation process."
            },
            LayerInstantiationError::SpecializationError(_) => {
                "An unexpected error occurred during layer instantiation. (Error during data specialization)"
            }
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            #[cfg(feature = "cuda")]
            LayerInstantiationError::CudaError(ref e) => Some(e),
            #[cfg(feature = "cuda")]
            LayerInstantiationError::CudnnError(ref e) => Some(e),
            LayerInstantiationError::OptimizerBuildError(ref e) => Some(e),
            LayerInstantiationError::SizeMismatchError(ref e) => Some(e),
            LayerInstantiationError::TypeConvertError(ref e) => Some(e),
            LayerInstantiationError::SpecializationError(ref e) => Some(e),
        }
    }
}
#[cfg(feature = "cuda")]
impl From<CudaError> for LayerInstantiationError {
    fn from(err: CudaError) -> LayerInstantiationError {
        LayerInstantiationError::CudaError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcudnn::Error> for LayerInstantiationError {
    fn from(err: rcudnn::Error) -> LayerInstantiationError {
        LayerInstantiationError::CudnnError(err)
    }
}
impl From<OptimizerBuildError> for LayerInstantiationError {
    fn from(err: OptimizerBuildError) -> LayerInstantiationError {
        LayerInstantiationError::OptimizerBuildError(err)
    }
}
impl From<SizeMismatchError> for LayerInstantiationError {
    fn from(err: SizeMismatchError) -> LayerInstantiationError {
        LayerInstantiationError::SizeMismatchError(err)
    }
}
impl From<TypeConvertError> for LayerInstantiationError {
    fn from(err: TypeConvertError) -> LayerInstantiationError {
        LayerInstantiationError::TypeConvertError(err)
    }
}
impl From<SpecializationError> for LayerInstantiationError {
    fn from(err: SpecializationError) -> LayerInstantiationError {
        LayerInstantiationError::SpecializationError(err)
    }
}
/// Error when layer instantiation fails
#[derive(Debug)]
pub enum OptimizerBuildError {
    /// Error in cuda processing
    #[cfg(feature = "cuda")]
    CudaError(CudaError),
    /// Error in cudnn processing
    #[cfg(feature = "cuda")]
    CudnnError(rcudnn::Error),
}
impl fmt::Display for OptimizerBuildError {
    #[cfg(feature = "cuda")]
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            OptimizerBuildError::CudaError(e) => {
                write!(f,"An unexpected error occurred during build optimizer ({})",e)
            },
            OptimizerBuildError::CudnnError(e) => {
                write!(f,"An unexpected error occurred during build optimizer ({})",e)
            }
        }
    }

    #[cfg(not(feature = "cuda"))]
    fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
        unreachable!()
    }
}
impl error::Error for OptimizerBuildError {
    #[cfg(feature = "cuda")]
    fn description(&self) -> &str {
        match self {
            OptimizerBuildError::CudaError(_) => {
                "An unexpected error occurred during build optimizer (An error occurred in the process of cudas)."
            },
            OptimizerBuildError::CudnnError(_) => {
                "An unexpected error occurred during build optimizer (An error occurred in the process of cudnn)."
            }
        }
    }

    #[cfg(feature = "cuda")]
    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            OptimizerBuildError::CudaError(ref e) => Some(e),
            OptimizerBuildError::CudnnError(ref e) => Some(e)
        }
    }
    #[cfg(not(feature = "cuda"))]
    fn description(&self) -> &str {
        unreachable!()
    }

    #[cfg(not(feature = "cuda"))]
    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        unreachable!()
    }
}
#[cfg(feature = "cuda")]
impl From<CudaError> for OptimizerBuildError {
    fn from(err: CudaError) -> OptimizerBuildError {
        OptimizerBuildError::CudaError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcudnn::Error> for OptimizerBuildError {
    fn from(err: rcudnn::Error) -> OptimizerBuildError {
        OptimizerBuildError::CudnnError(err)
    }
}
/// Errors when generalizing data
#[derive(Debug)]
pub enum GeneralizationError {
    /// Error in cuda processing
    #[cfg(feature = "cuda")]
    CudaError(CudaError),
    /// Error in cudnn processing
    #[cfg(feature = "cuda")]
    CudnnError(rcudnn::Error),
    /// Errors caused by generating fixed-length arrays from different size Vecs
    SizeMismatchError(SizeMismatchError),
    /// Error generated when type conversion fails
    TypeConvertError(TypeConvertError),
}
impl fmt::Display for GeneralizationError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            #[cfg(feature = "cuda")]
            GeneralizationError::CudaError(e) => {
                write!(f,"An unexpected error occurred during data generalization ({})",e)
            },
            #[cfg(feature = "cuda")]
            GeneralizationError::CudnnError(e) => {
                write!(f,"An unexpected error occurred during data generalization ({})",e)
            },
            GeneralizationError::SizeMismatchError(e) => {
                write!(f,"An unexpected error occurred during data generalization ({})",e)
            },
            GeneralizationError::TypeConvertError(e) => {
                write!(f,"An unexpected error occurred during data generalization ({})",e)
            }
        }
    }
}
impl error::Error for GeneralizationError {
    fn description(&self) -> &str {
        match self {
            #[cfg(feature = "cuda")]
            GeneralizationError::CudaError(_) => {
                "An unexpected error occurred during data generalization (An error occurred in the process of cudas)."
            },
            #[cfg(feature = "cuda")]
            GeneralizationError::CudnnError(_) => {
                "An unexpected error occurred during data generalization (An error occurred in the process of cudnns)."
            },
            GeneralizationError::SizeMismatchError(_) => {
                "An unexpected error occurred during data generalization. (Error during conversion to fixed length array)."
            },
            GeneralizationError::TypeConvertError(_) => {
                "An error occurred during a type conversion operation within the layer object creation process."
            }
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            #[cfg(feature = "cuda")]
            GeneralizationError::CudaError(ref e) => Some(e),
            #[cfg(feature = "cuda")]
            GeneralizationError::CudnnError(ref e) => Some(e),
            GeneralizationError::SizeMismatchError(ref e) => Some(e),
            GeneralizationError::TypeConvertError(ref e) => Some(e)
        }
    }
}
#[cfg(feature = "cuda")]
impl From<CudaError> for GeneralizationError {
    fn from(err: CudaError) -> GeneralizationError {
        GeneralizationError::CudaError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcudnn::Error> for GeneralizationError {
    fn from(err: rcudnn::Error) -> GeneralizationError {
        GeneralizationError::CudnnError(err)
    }
}
impl From<SizeMismatchError> for GeneralizationError {
    fn from(err: SizeMismatchError) -> GeneralizationError {
        GeneralizationError::SizeMismatchError(err)
    }
}
impl From<TypeConvertError> for GeneralizationError {
    fn from(err: TypeConvertError) -> GeneralizationError {
        GeneralizationError::TypeConvertError(err)
    }
}
/// Error during data specialization
#[derive(Debug)]
pub enum SpecializationError {
    /// Error in cuda processing
    #[cfg(feature = "cuda")]
    CudaError(CudaError),
    /// Error in cudnn processing
    #[cfg(feature = "cuda")]
    CudnnError(rcudnn::Error),
    /// Errors caused by generating fixed-length arrays from different size Vecs
    SizeMismatchError(SizeMismatchError),
    /// Error generated when type conversion fails
    TypeConvertError(TypeConvertError),
}
impl fmt::Display for SpecializationError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            #[cfg(feature = "cuda")]
            SpecializationError::CudaError(e) => {
                write!(f,"An unexpected error occurred during data specialization ({})",e)
            },
            #[cfg(feature = "cuda")]
            SpecializationError::CudnnError(e) => {
                write!(f,"An unexpected error occurred during data specialization ({})",e)
            },
            SpecializationError::SizeMismatchError(e) => {
                write!(f,"An unexpected error occurred during data specialization ({})",e)
            },
            SpecializationError::TypeConvertError(e) => {
                write!(f,"An unexpected error occurred during data specialization ({})",e)
            }
        }
    }
}
impl error::Error for SpecializationError {
    fn description(&self) -> &str {
        match self {
            #[cfg(feature = "cuda")]
            SpecializationError::CudaError(_) => {
                "An unexpected error occurred during data specialization (An error occurred in the process of cudas)."
            },
            #[cfg(feature = "cuda")]
            SpecializationError::CudnnError(_) => {
                "An unexpected error occurred during data specialization (An error occurred in the process of cudnns)."
            },
            SpecializationError::SizeMismatchError(_) => {
                "An unexpected error occurred during data specialization. (Error during conversion to fixed length array)."
            },
            SpecializationError::TypeConvertError(_) => {
                "An error occurred during a type conversion operation within the layer object creation process."
            }
        }
    }

    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match self {
            #[cfg(feature = "cuda")]
            SpecializationError::CudaError(ref e) => Some(e),
            #[cfg(feature = "cuda")]
            SpecializationError::CudnnError(ref e) => Some(e),
            SpecializationError::SizeMismatchError(ref e) => Some(e),
            SpecializationError::TypeConvertError(ref e) => Some(e)
        }
    }
}
#[cfg(feature = "cuda")]
impl From<CudaError> for SpecializationError {
    fn from(err: CudaError) -> SpecializationError {
        SpecializationError::CudaError(err)
    }
}
#[cfg(feature = "cuda")]
impl From<rcudnn::Error> for SpecializationError {
    fn from(err: rcudnn::Error) -> SpecializationError {
        SpecializationError::CudnnError(err)
    }
}
impl From<SizeMismatchError> for SpecializationError {
    fn from(err: SizeMismatchError) -> SpecializationError {
        SpecializationError::SizeMismatchError(err)
    }
}
impl From<TypeConvertError> for SpecializationError {
    fn from(err: TypeConvertError) -> SpecializationError {
        SpecializationError::TypeConvertError(err)
    }
}