MyCaffe  1.11.8.27
Deep learning software for Windows C# programmers.
BaseParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Globalization;
4using System.Linq;
5using System.Text;
6using System.Threading;
7using MyCaffe.basecode;
8
12namespace MyCaffe.basecode
13{
17 public abstract class BaseParameter
18 {
19 static CultureInfo cultureUS = null;
20
25 {
26 }
27
35 public static double ParseDouble(string strVal)
36 {
37 if (Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator == "." || string.IsNullOrEmpty(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
38 return double.Parse(strVal);
39
40 if (strVal.Contains(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
41 return double.Parse(strVal);
42
43 if (cultureUS == null)
44 cultureUS = CultureInfo.CreateSpecificCulture("en-US");
45
46 return double.Parse(strVal, cultureUS);
47 }
48
57 public static bool TryParse(string strVal, out double df)
58 {
59 if (Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator == "." || string.IsNullOrEmpty(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
60 return double.TryParse(strVal, out df);
61
62 if (strVal.Contains(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
63 return double.TryParse(strVal, out df);
64
65 if (cultureUS == null)
66 cultureUS = CultureInfo.CreateSpecificCulture("en-US");
67
68 return double.TryParse(strVal, NumberStyles.Any, cultureUS, out df);
69 }
70
78 public static float ParseFloat(string strVal)
79 {
80 if (Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator == "." || string.IsNullOrEmpty(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
81 return float.Parse(strVal);
82
83 if (strVal.Contains(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
84 return float.Parse(strVal);
85
86 if (cultureUS == null)
87 cultureUS = CultureInfo.CreateSpecificCulture("en-US");
88
89 return float.Parse(strVal, cultureUS);
90 }
91
100 public static bool TryParse(string strVal, out float f)
101 {
102 if (Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator == "." || string.IsNullOrEmpty(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
103 return float.TryParse(strVal, out f);
104
105 if (strVal.Contains(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
106 return float.TryParse(strVal, out f);
107
108 if (cultureUS == null)
109 cultureUS = CultureInfo.CreateSpecificCulture("en-US");
110
111 return float.TryParse(strVal, NumberStyles.Any, cultureUS, out f);
112 }
113
114
120 public abstract RawProto ToProto(string strName);
121
127 public virtual bool Compare(BaseParameter p)
128 {
129 RawProto p1 = ToProto("foo");
130 RawProto p2 = p.ToProto("foo");
131 string str1 = p1.ToString();
132 string str2 = p2.ToString();
133
134 return str1 == str2;
135 }
136 }
137}
The BaseParameter class is the base class for all other parameter classes.
static float ParseFloat(string strVal)
Parse float values using the US culture if the decimal separator = '.', then using the native culture...
static bool TryParse(string strVal, out double df)
Parse double values using the US culture if the decimal separator = '.', then using the native cultur...
BaseParameter()
Constructor for the parameter.
static double ParseDouble(string strVal)
Parse double values using the US culture if the decimal separator = '.', then using the native cultur...
abstract RawProto ToProto(string strName)
Convert the parameter into a RawProto.
static bool TryParse(string strVal, out float f)
Parse doufloatble values using the US culture if the decimal separator = '.', then using the native c...
virtual bool Compare(BaseParameter p)
Compare this parameter to another parameter.
The RawProto class is used to parse and output Google prototxt file data.
Definition: RawProto.cs:17
override string ToString()
Returns the RawProto as its full prototxt string.
Definition: RawProto.cs:677
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12