MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
Utility.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.IO;
6
10namespace MyCaffe.basecode
11{
15 public interface IBinaryPersist
16 {
21 void Save(BinaryWriter bw);
28 object Load(BinaryReader br, bool bNewInstance = true);
29 }
30
34 public class Utility
35 {
39 public Utility()
40 {
41 }
42
50 public static int CanonicalAxisIndex(int nIdx, int nNumAxes)
51 {
52 if (nIdx < 0)
53 return nIdx + nNumAxes;
54 else
55 return nIdx;
56 }
57
64 public static int GetSpatialDim(List<int> rg, int nStartIdx = 0)
65 {
66 int nDim = 1;
67
68 for (int i = nStartIdx; i < rg.Count; i++)
69 {
70 nDim *= rg[i];
71 }
72
73 return nDim;
74 }
75
83 public static int Count(List<int> rgShape, int nStartIdx = 0, int nEndIdx = -1)
84 {
85 int nCount = 1;
86
87 if (nEndIdx == -1)
88 nEndIdx = rgShape.Count;
89
90 for (int i = nStartIdx; i < nEndIdx; i++)
91 {
92 nCount *= rgShape[i];
93 }
94
95 return nCount;
96 }
97
105 public static int Count(int[] rgShape, int nStartIdx = 0, int nEndIdx = -1)
106 {
107 int nCount = 1;
108
109 if (nEndIdx == -1)
110 nEndIdx = rgShape.Length;
111
112 for (int i = nStartIdx; i < nEndIdx; i++)
113 {
114 nCount *= rgShape[i];
115 }
116
117 return nCount;
118 }
119
126 public static void Save<T>(BinaryWriter bw, List<T> rg)
127 {
128 int nCount = (rg != null) ? rg.Count : 0;
129
130 bw.Write(nCount);
131
132 if (nCount == 0)
133 return;
134
135 if (typeof(T) == typeof(string))
136 {
137 foreach (T t in rg)
138 {
139 bw.Write(t.ToString());
140 }
141
142 return;
143 }
144
145 if (typeof(T) == typeof(double))
146 {
147 foreach (T t in rg)
148 {
149 bw.Write((double)Convert.ChangeType(t, typeof(double)));
150 }
151
152 return;
153 }
154
155 if (typeof(T) == typeof(float))
156 {
157 foreach (T t in rg)
158 {
159 bw.Write((float)Convert.ChangeType(t, typeof(float)));
160 }
161
162 return;
163 }
164
165 if (typeof(T) == typeof(int))
166 {
167 foreach (T t in rg)
168 {
169 bw.Write((int)Convert.ChangeType(t, typeof(int)));
170 }
171
172 return;
173 }
174
175 if (typeof(T) == typeof(long))
176 {
177 foreach (T t in rg)
178 {
179 bw.Write((long)Convert.ChangeType(t, typeof(long)));
180 }
181
182 return;
183 }
184
185 if (typeof(T) == typeof(uint))
186 {
187 foreach (T t in rg)
188 {
189 bw.Write((uint)Convert.ChangeType(t, typeof(uint)));
190 }
191
192 return;
193 }
194
195 if (typeof(T) == typeof(bool))
196 {
197 foreach (T t in rg)
198 {
199 bw.Write((bool)Convert.ChangeType(t, typeof(bool)));
200 }
201
202 return;
203 }
204
205 bool bSaved = true;
206
207 foreach (T t in rg)
208 {
210
211 if (p != null)
212 {
213 p.Save(bw);
214 bSaved = true;
215 }
216
217 return;
218 }
219
220 if (!bSaved)
221 throw new Exception("Persistance for type " + (typeof(T)).ToString() + " is not supported!");
222 }
223
230 public static List<T> Load<T>(BinaryReader br)
231 {
232 int nCount = br.ReadInt32();
233 List<T> rg = new List<T>(nCount);
234
235 if (nCount == 0)
236 return rg;
237
238 if (typeof(T) == typeof(string))
239 {
240 for (int i = 0; i < nCount; i++)
241 {
242 string val = br.ReadString();
243 rg.Add((T)Convert.ChangeType(val, typeof(T)));
244 }
245
246 return rg;
247 }
248
249 if (typeof(T) == typeof(double))
250 {
251 for (int i = 0; i < nCount; i++)
252 {
253 double val = br.ReadDouble();
254 rg.Add((T)Convert.ChangeType(val, typeof(T)));
255 }
256
257 return rg;
258 }
259
260 if (typeof(T) == typeof(float))
261 {
262 for (int i = 0; i < nCount; i++)
263 {
264 float val = br.ReadSingle();
265 rg.Add((T)Convert.ChangeType(val, typeof(T)));
266 }
267
268 return rg;
269 }
270
271 if (typeof(T) == typeof(int))
272 {
273 for (int i = 0; i < nCount; i++)
274 {
275 int val = br.ReadInt32();
276 rg.Add((T)Convert.ChangeType(val, typeof(T)));
277 }
278
279 return rg;
280 }
281
282 if (typeof(T) == typeof(long))
283 {
284 for (int i = 0; i < nCount; i++)
285 {
286 long val = br.ReadInt64();
287 rg.Add((T)Convert.ChangeType(val, typeof(T)));
288 }
289
290 return rg;
291 }
292
293 if (typeof(T) == typeof(uint))
294 {
295 for (int i = 0; i < nCount; i++)
296 {
297 uint val = br.ReadUInt32();
298 rg.Add((T)Convert.ChangeType(val, typeof(T)));
299 }
300
301 return rg;
302 }
303
304 if (typeof(T) == typeof(bool))
305 {
306 for (int i = 0; i < nCount; i++)
307 {
308 bool val = br.ReadBoolean();
309 rg.Add((T)Convert.ChangeType(val, typeof(T)));
310 }
311
312 return rg;
313 }
314
315 object obj = Activator.CreateInstance(typeof(T));
317
318 if (p != null)
319 {
320 for (int i = 0; i < nCount; i++)
321 {
322 object val = p.Load(br);
323 rg.Add((T)Convert.ChangeType(val, typeof(T)));
324 }
325
326 return rg;
327 }
328
329 throw new Exception("Persistance for type " + (typeof(T)).ToString() + " is not supported!");
330 }
331
337 public static void Save(BinaryWriter bw, List<double> rg)
338 {
339 bw.Write(rg.Count);
340
341 for (int i=0; i<rg.Count; i++)
342 {
343 bw.Write(rg[i]);
344 }
345 }
346
352 public static List<double> LoadDouble(BinaryReader br)
353 {
354 List<double> rg = new List<double>();
355 int nCount = br.ReadInt32();
356
357 for (int i = 0; i < nCount; i++)
358 {
359 rg.Add(br.ReadDouble());
360 }
361
362 return rg;
363 }
364
370 public static void Save(BinaryWriter bw, List<float> rg)
371 {
372 bw.Write(rg.Count);
373
374 for (int i = 0; i < rg.Count; i++)
375 {
376 bw.Write(rg[i]);
377 }
378 }
379
385 public static List<float> LoadFloat(BinaryReader br)
386 {
387 List<float> rg = new List<float>();
388 int nCount = br.ReadInt32();
389
390 for (int i = 0; i < nCount; i++)
391 {
392 rg.Add(br.ReadSingle());
393 }
394
395 return rg;
396 }
397
403 public static void Save(BinaryWriter bw, int? nVal)
404 {
405 bw.Write(nVal.HasValue);
406
407 if (nVal.HasValue)
408 bw.Write(nVal.Value);
409 }
410
416 public static int? LoadInt(BinaryReader br)
417 {
418 bool bHasVal = br.ReadBoolean();
419
420 if (!bHasVal)
421 return null;
422
423 return br.ReadInt32();
424 }
425
431 public static int BaseTypeSize<T>()
432 {
433 if (typeof(T) == typeof(float))
434 return sizeof(float);
435
436 return sizeof(double);
437 }
438
445 public static double ConvertVal<T>(T fVal)
446 {
447 return (double)Convert.ChangeType(fVal, typeof(double));
448 }
449
456 public static float ConvertValF<T>(T fVal)
457 {
458 return (float)Convert.ChangeType(fVal, typeof(float));
459 }
460
467 public static T ConvertVal<T>(double dfVal)
468 {
469 return (T)Convert.ChangeType(dfVal, typeof(T));
470 }
471
478 public static double[] ConvertVec<T>(T[] rg)
479 {
480 if (typeof(T) == typeof(double))
481 return (double[])Convert.ChangeType(rg, typeof(double[]));
482
483 double[] rgdf = new double[rg.Length];
484 Array.Copy(rg, rgdf, rg.Length);
485
486 return rgdf;
487 }
488
496 public static float[] ConvertVecF<T>(T[] rg, int nStart = 0)
497 {
498 if (typeof(T) == typeof(float) && nStart == 0)
499 return (float[])Convert.ChangeType(rg, typeof(float[]));
500
501 float[] rgf = new float[rg.Length - nStart];
502 Array.Copy(Array.ConvertAll(rg, p => Convert.ToSingle(p)), nStart, rgf, 0, rgf.Length);
503
504 return rgf;
505 }
506
513 public static T[] ConvertVec<T>(double[] rgdf)
514 {
515 if (typeof(T) == typeof(double))
516 return (T[])Convert.ChangeType(rgdf, typeof(T[]));
517
518 T[] rgt = new T[rgdf.Length];
519
520 if (typeof(T) == typeof(float))
521 Array.Copy(Array.ConvertAll(rgdf, p => Convert.ToSingle(p)), rgt, rgdf.Length);
522 else
523 Array.Copy(rgdf, rgt, rgdf.Length);
524
525 return rgt;
526 }
527
534 public static T[] ConvertVec<T>(float[] rgf)
535 {
536 if (typeof(T) == typeof(float))
537 return (T[])Convert.ChangeType(rgf, typeof(T[]));
538
539 T[] rgt = new T[rgf.Length];
540 Array.Copy(rgf, rgt, rgf.Length);
541
542 return rgt;
543 }
544
550 public static double[] ConvertVec(float[] rgf)
551 {
552 double[] rgt = new double[rgf.Length];
553 Array.Copy(rgf, rgt, rgf.Length);
554
555 return rgt;
556 }
557
565 public static void Resize<T>(ref List<T> rg, int nCount, T tDefault)
566 {
567 if (rg == null)
568 rg = new List<T>();
569
570 while (rg.Count < nCount)
571 {
572 rg.Add(tDefault);
573 }
574
575 while (rg.Count > nCount)
576 {
577 rg.RemoveAt(rg.Count - 1);
578 }
579 }
580
587 public static T[] Clone<T>(T[] rg)
588 {
589 if (rg == null)
590 return null;
591
592 T[] rg1 = new T[rg.Length];
593 Array.Copy(rg, rg1, rg.Length);
594
595 return rg1;
596 }
597
605 public static List<T> Clone<T>(List<T> rg, int nMaxCount = int.MaxValue)
606 {
607 if (rg == null)
608 return null;
609
610 List<T> rg1 = new List<T>();
611
612 for (int i=0; i<rg.Count && i<nMaxCount; i++)
613 {
614 ICloneable cloneable = rg[i] as ICloneable;
615
616 if (cloneable != null)
617 rg1.Add((T)Convert.ChangeType(cloneable.Clone(), typeof(T)));
618 else
619 rg1.Add(rg[i]);
620 }
621
622 return rg1;
623 }
624
632 public static List<T> Clone<T>(T[] rg, int nMaxCount = int.MaxValue)
633 {
634 List<T> rg1 = new List<T>();
635
636 for (int i = 0; i < rg.Length && i < nMaxCount; i++)
637 {
638 ICloneable cloneable = rg[i] as ICloneable;
639
640 if (cloneable != null)
641 rg1.Add((T)Convert.ChangeType(cloneable.Clone(), typeof(T)));
642 else
643 rg1.Add(rg[i]);
644 }
645
646 return rg1;
647 }
648
657 public static bool Compare<T>(List<T> rg1, List<T> rg2, bool bExact = true)
658 {
659 if (rg1.Count != rg2.Count)
660 {
661 if (bExact)
662 return false;
663
664 if (Math.Abs(rg1.Count - rg2.Count) > 1)
665 return false;
666
667 T tOne = (T)Convert.ChangeType(1, typeof(T));
668
669 if (rg1.Count > rg2.Count && !rg1[rg1.Count - 1].Equals(tOne))
670 return false;
671
672 if (rg2.Count > rg1.Count && !rg2[rg2.Count - 1].Equals(tOne))
673 return false;
674 }
675
676 for (int i = 0; i < rg1.Count && i < rg2.Count; i++)
677 {
678 IComparable compare1 = rg1[i] as IComparable;
679
680 if (compare1 != null)
681 {
682 if (compare1.CompareTo((object)Convert.ChangeType(rg2[i], typeof(object))) != 0)
683 return false;
684 }
685 else
686 {
687 if (rg1[i].ToString() != rg2[i].ToString())
688 return false;
689 }
690 }
691
692 return true;
693 }
694
702 public static List<T> Create<T>(int nCount, T fDefault)
703 {
704 List<T> rg = new List<T>();
705
706 for (int i = 0; i < nCount; i++)
707 {
708 rg.Add(fDefault);
709 }
710
711 return rg;
712 }
713
721 public static List<int> Create(int nCount, int nStart, int nInc)
722 {
723 List<int> rg = new List<int>();
724 int nVal = nStart;
725
726 for (int i = 0; i < nCount; i++)
727 {
728 rg.Add(nVal);
729 nVal += nInc;
730 }
731
732 return rg;
733 }
734
741 public static void Set<T>(List<T> rg, T fVal)
742 {
743 for (int i = 0; i < rg.Count; i++)
744 {
745 rg[i] = fVal;
746 }
747 }
748
755 public static void Set<T>(T[] rg, T fVal)
756 {
757 for (int i = 0; i < rg.Length; i++)
758 {
759 rg[i] = fVal;
760 }
761 }
762
773 public static string ToString<T>(List<T> rg, int nDecimals = -1, int nIdxHighight = -1, string strStart = "{", string strEnd = "}")
774 {
775 string strOut = strStart;
776
777 for (int i = 0; i < rg.Count; i++)
778 {
779 if (nIdxHighight >= 0 && i == nIdxHighight)
780 strOut += "[*";
781
782 if (nDecimals >= 0)
783 {
784 if (typeof(T) == typeof(float))
785 {
786 float f = (float)Convert.ChangeType(rg[i], typeof(float));
787 strOut += f.ToString("N" + nDecimals.ToString());
788 }
789 else if (typeof(T) == typeof(double))
790 {
791 double f = (double)Convert.ChangeType(rg[i], typeof(double));
792 strOut += f.ToString("N" + nDecimals.ToString());
793 }
794 else
795 {
796 strOut += rg[i].ToString();
797 }
798 }
799 else
800 strOut += rg[i].ToString();
801
802 if (nIdxHighight >= 0 && i == nIdxHighight)
803 strOut += "*]";
804
805 strOut += ",";
806 }
807
808 strOut = strOut.TrimEnd(',');
809 strOut += strEnd;
810
811 return strOut;
812 }
813
819 public static List<int> ParseListToInt(string str)
820 {
821 string[] rg = str.Split(',');
822 List<int> rgVal = new List<int>();
823
824 foreach (string str1 in rg)
825 {
826 rgVal.Add(int.Parse(str1));
827 }
828
829 return rgVal;
830 }
831
837 public static int GetNumber(string str)
838 {
839 if (str == null || str.Length == 0)
840 return 0;
841
842 if (!char.IsNumber(str[str.Length - 1]))
843 return 0;
844
845 for (int i = str.Length - 1; i > 0; i--)
846 {
847 if (!char.IsNumber(str[str.Length - 1]))
848 {
849 string strNum = str.Substring(i);
850 return int.Parse(strNum);
851 }
852 }
853
854 return 0;
855 }
856
864 public static string Replace(string str, char ch1, char ch2)
865 {
866 if (str == null)
867 return null;
868
869 string strOut = "";
870
871 foreach (char ch in str)
872 {
873 if (ch == ch1)
874 strOut += ch2;
875 else
876 strOut += ch;
877 }
878
879 return strOut;
880 }
881
889 public static string Replace(string str, char ch1, string str2)
890 {
891 if (str == null)
892 return null;
893
894 string strOut = "";
895
896 foreach (char ch in str)
897 {
898 if (ch == ch1)
899 strOut += str2;
900 else
901 strOut += ch;
902 }
903
904 return strOut;
905 }
906
914 public static string Replace(string str, string str1, char ch2)
915 {
916 if (str == null)
917 return null;
918
919 string strOut = "";
920
921 while (str.Length > 0)
922 {
923 int nPos = str.IndexOf(str1);
924 if (nPos >= 0)
925 {
926 strOut += str.Substring(0, nPos);
927 strOut += ch2;
928 str = str.Substring(nPos + str1.Length);
929 }
930 else
931 {
932 strOut += str;
933 str = "";
934 }
935 }
936
937 return strOut;
938 }
939
947 public static string ReplaceMacro(string strRaw, string strMacroName, string strReplacement)
948 {
949 int nPos = 0;
950 string strOut = "";
951
952 while (strRaw.Length > 0)
953 {
954 nPos = strRaw.IndexOf(strMacroName);
955
956 if (nPos >= 0)
957 {
958 strOut += strRaw.Substring(0, nPos);
959 strOut += strReplacement;
960 strRaw = strRaw.Substring(nPos + strMacroName.Length);
961 }
962 else
963 {
964 strOut += strRaw;
965 strRaw = "";
966 }
967 }
968
969 return strOut;
970 }
971
978 public static string ReplaceMacros(string strRaw, List<KeyValuePair<string, string>> rgMacros)
979 {
980 string strOut = strRaw;
981
982 foreach (KeyValuePair<string, string> kv in rgMacros)
983 {
984 strOut = ReplaceMacro(strOut, kv.Key, kv.Value);
985 }
986
987 return strOut;
988 }
989
990
996 public static double ConvertTimeToMinutes(DateTime dt)
997 {
998 DateTime dt1 = new DateTime(1980, 1, 1);
999 TimeSpan ts = dt - dt1;
1000 return ts.TotalMinutes;
1001 }
1002
1008 public static DateTime ConvertTimeFromMinutes(double dfMin)
1009 {
1010 DateTime dt1 = new DateTime(1980, 1, 1);
1011 TimeSpan ts = TimeSpan.FromMinutes(dfMin);
1012 return dt1 + ts;
1013 }
1014
1021 public static List<int> RandomShuffle(List<int> rg, int? nSeed = null)
1022 {
1023 if (!nSeed.HasValue)
1024 nSeed = (int)DateTime.Now.Ticks;
1025
1026 Random random = new Random(nSeed.Value);
1027 List<int> rg1 = new List<int>();
1028
1029 while (rg.Count > 0)
1030 {
1031 if (rg.Count == 1)
1032 {
1033 rg1.Add(rg[0]);
1034 rg.Clear();
1035 }
1036 else
1037 {
1038 int nIdx = random.Next(rg.Count);
1039 rg1.Add(rg[nIdx]);
1040 rg.RemoveAt(nIdx);
1041 }
1042 }
1043
1044 return rg1;
1045 }
1046
1054 public static List<string> LoadTextLines(string strFile, Log log = null, bool bPrependPath = true)
1055 {
1056 List<string> rgstr = new List<string>();
1057
1058 try
1059 {
1060 string strPath = Path.GetDirectoryName(strFile);
1061
1062 using (StreamReader sr = new StreamReader(strFile))
1063 {
1064 string strLine = sr.ReadLine();
1065
1066 while (strLine != null)
1067 {
1068 if (strLine.Length > 0)
1069 {
1070 if (strLine[0] == '.' && bPrependPath)
1071 {
1072 int nPos = strLine.LastIndexOf('/');
1073 if (nPos < 0)
1074 nPos = strLine.LastIndexOf('\\');
1075
1076 if (nPos >= 0)
1077 strLine = strLine.Substring(nPos + 1);
1078
1079 strLine = strPath + "\\" + Replace(strLine, '/', '\\');
1080 }
1081
1082 rgstr.Add(strLine);
1083 }
1084
1085 strLine = sr.ReadLine();
1086 }
1087 }
1088 }
1089 catch (Exception excpt)
1090 {
1091 if (log != null)
1092 log.FAIL("Failed to load '" + strFile + "'! Error: " + excpt.Message);
1093 else
1094 throw excpt;
1095 }
1096
1097 return rgstr;
1098 }
1099 }
1100}
The Log class provides general output in text form.
Definition: Log.cs:13
The Utility class provides general utility funtions.
Definition: Utility.cs:35
static bool Compare< T >(List< T > rg1, List< T > rg2, bool bExact=true)
Compares one List to another.
Definition: Utility.cs:657
static List< int > ParseListToInt(string str)
Parses a comma delimited string into an array of int.
Definition: Utility.cs:819
static string Replace(string str, char ch1, string str2)
Replaces each instance of one character with another string in a given string.
Definition: Utility.cs:889
static double[] ConvertVec< T >(T[] rg)
Convert an array of generics to an array of double.
Definition: Utility.cs:478
static void Save(BinaryWriter bw, List< double > rg)
Save a list of double to a binary writer.
Definition: Utility.cs:337
static string Replace(string str, char ch1, char ch2)
Replaces each instance of one character with another character in a given string.
Definition: Utility.cs:864
static double ConvertVal< T >(T fVal)
Convert a generic to a double.
Definition: Utility.cs:445
Utility()
The Utility constructor.
Definition: Utility.cs:39
static string ReplaceMacro(string strRaw, string strMacroName, string strReplacement)
The ConvertMacro method is used to replace a set of macros in a given string.
Definition: Utility.cs:947
static List< double > LoadDouble(BinaryReader br)
Loads a list of double from a binary reader.
Definition: Utility.cs:352
static int CanonicalAxisIndex(int nIdx, int nNumAxes)
Returns the 'canonical' version of a (usually) user-specified axis, allowing for negative indexing (e...
Definition: Utility.cs:50
static List< T > Create< T >(int nCount, T fDefault)
Create a new List and fill it with default values up to a given count.
Definition: Utility.cs:702
static List< int > Create(int nCount, int nStart, int nInc)
Create a new List and fill it with values starting with start and incrementing by inc.
Definition: Utility.cs:721
static void Save(BinaryWriter bw, int? nVal)
Saves a nullable int to a binary writer.
Definition: Utility.cs:403
static void Save< T >(BinaryWriter bw, List< T > rg)
Save a list of items to a binary writer.
Definition: Utility.cs:126
static float ConvertValF< T >(T fVal)
Convert a generic to a float.
Definition: Utility.cs:456
static string Replace(string str, string str1, char ch2)
Replaces each instance of one character with another string in a given string.
Definition: Utility.cs:914
static float[] ConvertVecF< T >(T[] rg, int nStart=0)
Convert an array of generics to an array of float.
Definition: Utility.cs:496
static List< int > RandomShuffle(List< int > rg, int? nSeed=null)
Randomly shuffle the entries in the specified list.
Definition: Utility.cs:1021
static int GetNumber(string str)
Parses a string into a number, or if the string does not contain a number returns 0.
Definition: Utility.cs:837
static DateTime ConvertTimeFromMinutes(double dfMin)
Convert a number of minutes into the date time equivalent to 1/1/1980 + the minutes.
Definition: Utility.cs:1008
static T[] Clone< T >(T[] rg)
Copy an array.
Definition: Utility.cs:587
static int Count(int[] rgShape, int nStartIdx=0, int nEndIdx=-1)
Return the count of items given the shape.
Definition: Utility.cs:105
static void Resize< T >(ref List< T > rg, int nCount, T tDefault)
Resize a List and fill the new elements with the default value.
Definition: Utility.cs:565
static List< float > LoadFloat(BinaryReader br)
Loads a list of float from a binary reader.
Definition: Utility.cs:385
static string ReplaceMacros(string strRaw, List< KeyValuePair< string, string > > rgMacros)
The ReplaceMacros method is used to replace a set of macros in a given string.
Definition: Utility.cs:978
static List< string > LoadTextLines(string strFile, Log log=null, bool bPrependPath=true)
Load each line of a text file and return the contents as a list.
Definition: Utility.cs:1054
static void Set< T >(List< T > rg, T fVal)
Set all values of a List with a given value.
Definition: Utility.cs:741
static int GetSpatialDim(List< int > rg, int nStartIdx=0)
Calculate the spatial dimension of an array starting at a given axis.
Definition: Utility.cs:64
static int BaseTypeSize< T >()
Returns the base type size, where double = 8, float = 4.
Definition: Utility.cs:431
static string ToString< T >(List< T > rg, int nDecimals=-1, int nIdxHighight=-1, string strStart="{", string strEnd="}")
Convert an array to a string.
Definition: Utility.cs:773
static int Count(List< int > rgShape, int nStartIdx=0, int nEndIdx=-1)
Return the count of items given the shape.
Definition: Utility.cs:83
static void Save(BinaryWriter bw, List< float > rg)
Save a list of float to a binary writer.
Definition: Utility.cs:370
static double[] ConvertVec(float[] rgf)
Convert an array of float to an array of generics.
Definition: Utility.cs:550
static List< T > Load< T >(BinaryReader br)
Loads a list of items from a binary reader.
Definition: Utility.cs:230
static double ConvertTimeToMinutes(DateTime dt)
Convert a date time into minutes since 1/1/1980
Definition: Utility.cs:996
static ? int LoadInt(BinaryReader br)
Loads a nullable int from a binary reader.
Definition: Utility.cs:416
The IBinaryPersist interface provides generic save and load functionality.
Definition: Utility.cs:16
void Save(BinaryWriter bw)
Save to a binary writer.
object Load(BinaryReader br, bool bNewInstance=true)
Load from a binary reader.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12