MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
MyCaffe.basecode.Utility Class Reference

The Utility class provides general utility funtions. More...

Public Member Functions

 Utility ()
 The Utility constructor. More...
 

Static Public Member Functions

static int CanonicalAxisIndex (int nIdx, int nNumAxes)
 Returns the 'canonical' version of a (usually) user-specified axis, allowing for negative indexing (e.g., -1 for the last axis). More...
 
static int GetSpatialDim (List< int > rg, int nStartIdx=0)
 Calculate the spatial dimension of an array starting at a given axis. More...
 
static int Count (List< int > rgShape, int nStartIdx=0, int nEndIdx=-1)
 Return the count of items given the shape. More...
 
static int Count (int[] rgShape, int nStartIdx=0, int nEndIdx=-1)
 Return the count of items given the shape. More...
 
static void Save< T > (BinaryWriter bw, List< T > rg)
 Save a list of items to a binary writer. More...
 
static List< T > Load< T > (BinaryReader br)
 Loads a list of items from a binary reader. More...
 
static void Save (BinaryWriter bw, List< double > rg)
 Save a list of double to a binary writer. More...
 
static List< double > LoadDouble (BinaryReader br)
 Loads a list of double from a binary reader. More...
 
static void Save (BinaryWriter bw, List< float > rg)
 Save a list of float to a binary writer. More...
 
static List< float > LoadFloat (BinaryReader br)
 Loads a list of float from a binary reader. More...
 
static void Save (BinaryWriter bw, int? nVal)
 Saves a nullable int to a binary writer. More...
 
static ? int LoadInt (BinaryReader br)
 Loads a nullable int from a binary reader. More...
 
static int BaseTypeSize< T > ()
 Returns the base type size, where double = 8, float = 4. More...
 
static double ConvertVal< T > (T fVal)
 Convert a generic to a double. More...
 
static float ConvertValF< T > (T fVal)
 Convert a generic to a float. More...
 
static T ConvertVal< T > (double dfVal)
 Convert a double to a generic. More...
 
static double[] ConvertVec< T > (T[] rg)
 Convert an array of generics to an array of double. More...
 
static float[] ConvertVecF< T > (T[] rg, int nStart=0)
 Convert an array of generics to an array of float. More...
 
static T[] ConvertVec< T > (double[] rgdf)
 Convert an array of double to an array of generics. More...
 
static T[] ConvertVec< T > (float[] rgf)
 Convert an array of float to an array of generics. More...
 
static double[] ConvertVec (float[] rgf)
 Convert an array of float to an array of generics. More...
 
static void Resize< T > (ref List< T > rg, int nCount, T tDefault)
 Resize a List and fill the new elements with the default value. More...
 
static T[] Clone< T > (T[] rg)
 Copy an array. More...
 
static List< T > Clone< T > (List< T > rg, int nMaxCount=int.MaxValue)
 Copy a List up to a maximum count. More...
 
static List< T > Clone< T > (T[] rg, int nMaxCount=int.MaxValue)
 Copy a List up to a maximum count. More...
 
static bool Compare< T > (List< T > rg1, List< T > rg2, bool bExact=true)
 Compares one List to another. More...
 
static List< T > Create< T > (int nCount, T fDefault)
 Create a new List and fill it with default values up to a given count. More...
 
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. More...
 
static void Set< T > (List< T > rg, T fVal)
 Set all values of a List with a given value. More...
 
static void Set< T > (T[] rg, T fVal)
 Set all values within an array with a given value. More...
 
static string ToString< T > (List< T > rg, int nDecimals=-1, int nIdxHighight=-1, string strStart="{", string strEnd="}")
 Convert an array to a string. More...
 
static List< int > ParseListToInt (string str)
 Parses a comma delimited string into an array of int. More...
 
static int GetNumber (string str)
 Parses a string into a number, or if the string does not contain a number returns 0. More...
 
static string Replace (string str, char ch1, char ch2)
 Replaces each instance of one character with another character in a given string. More...
 
static string Replace (string str, char ch1, string str2)
 Replaces each instance of one character with another string in a given string. More...
 
static string Replace (string str, string str1, char ch2)
 Replaces each instance of one character with another string in a given string. More...
 
static string ReplaceMacro (string strRaw, string strMacroName, string strReplacement)
 The ConvertMacro method is used to replace a set of macros in a given string. More...
 
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. More...
 
static double ConvertTimeToMinutes (DateTime dt)
 Convert a date time into minutes since 1/1/1980 More...
 
static DateTime ConvertTimeFromMinutes (double dfMin)
 Convert a number of minutes into the date time equivalent to 1/1/1980 + the minutes. More...
 
static List< int > RandomShuffle (List< int > rg, int? nSeed=null)
 Randomly shuffle the entries in the specified list. More...
 
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. More...
 

Detailed Description

The Utility class provides general utility funtions.

Definition at line 34 of file Utility.cs.

Constructor & Destructor Documentation

◆ Utility()

MyCaffe.basecode.Utility.Utility ( )

The Utility constructor.

Definition at line 39 of file Utility.cs.

Member Function Documentation

◆ BaseTypeSize< T >()

static int MyCaffe.basecode.Utility.BaseTypeSize< T > ( )
static

Returns the base type size, where double = 8, float = 4.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Returns
The base type size (in bytes) is returned.

Definition at line 431 of file Utility.cs.

◆ CanonicalAxisIndex()

static int MyCaffe.basecode.Utility.CanonicalAxisIndex ( int  nIdx,
int  nNumAxes 
)
static

Returns the 'canonical' version of a (usually) user-specified axis, allowing for negative indexing (e.g., -1 for the last axis).

Parameters
nIdxThe axis index.
nNumAxesThe total number of axes.
Returns
The zero based index is returned.

Definition at line 50 of file Utility.cs.

◆ Clone< T >() [1/3]

static List< T > MyCaffe.basecode.Utility.Clone< T > ( List< T >  rg,
int  nMaxCount = int.MaxValue 
)
static

Copy a List up to a maximum count.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
rgSpecifies the list to copy.
nMaxCountOptionally, specifies a maximum count to copy.
Returns
The new copy of the List is returned.

Definition at line 605 of file Utility.cs.

◆ Clone< T >() [2/3]

static T[] MyCaffe.basecode.Utility.Clone< T > ( T[]  rg)
static

Copy an array.

Template Parameters
TSpecifies the base type.
Parameters
rgSpecifies the source array.
Returns
The new array is returned.

Definition at line 587 of file Utility.cs.

◆ Clone< T >() [3/3]

static List< T > MyCaffe.basecode.Utility.Clone< T > ( T[]  rg,
int  nMaxCount = int.MaxValue 
)
static

Copy a List up to a maximum count.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
rgSpecifies the array to copy.
nMaxCountOptionally, specifies a maximum count to copy.
Returns
The new copy of the List is returned.

Definition at line 632 of file Utility.cs.

◆ Compare< T >()

static bool MyCaffe.basecode.Utility.Compare< T > ( List< T >  rg1,
List< T >  rg2,
bool  bExact = true 
)
static

Compares one List to another.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
rg1Specifies the first List.
rg2Specifies the second List.
bExactOptionally, specifies to look for an exact match. When false a trailing one is accepted if the count()'s match.
Returns
If the Lists are the same, true is returned, otherwise false is returned.

Definition at line 657 of file Utility.cs.

◆ ConvertTimeFromMinutes()

static DateTime MyCaffe.basecode.Utility.ConvertTimeFromMinutes ( double  dfMin)
static

Convert a number of minutes into the date time equivalent to 1/1/1980 + the minutes.

Parameters
dfMinSpecifies the minutes since 1/1/1980.
Returns
The datetime is returned.

Definition at line 1008 of file Utility.cs.

◆ ConvertTimeToMinutes()

static double MyCaffe.basecode.Utility.ConvertTimeToMinutes ( DateTime  dt)
static

Convert a date time into minutes since 1/1/1980

Parameters
dtSpecifies the datetime to convert.
Returns
The minutes since 1/1/1980 is returned.

Definition at line 996 of file Utility.cs.

◆ ConvertVal< T >() [1/2]

static T MyCaffe.basecode.Utility.ConvertVal< T > ( double  dfVal)
static

Convert a double to a generic.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
dfValSpecifies the double value.
Returns
The generic value is returned.

Definition at line 467 of file Utility.cs.

◆ ConvertVal< T >() [2/2]

static double MyCaffe.basecode.Utility.ConvertVal< T > ( fVal)
static

Convert a generic to a double.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
fValSpecifies the generic value.
Returns
The double value is returned.

Definition at line 445 of file Utility.cs.

◆ ConvertValF< T >()

static float MyCaffe.basecode.Utility.ConvertValF< T > ( fVal)
static

Convert a generic to a float.

Template Parameters
TSpecifies the base type float or float. Using float is recommended to conserve GPU memory.
Parameters
fValSpecifies the generic value.
Returns
The float value is returned.

Definition at line 456 of file Utility.cs.

◆ ConvertVec()

static double[] MyCaffe.basecode.Utility.ConvertVec ( float[]  rgf)
static

Convert an array of float to an array of generics.

Parameters
rgfSpecifies the array of float.
Returns
The array of generics is returned.

Definition at line 550 of file Utility.cs.

◆ ConvertVec< T >() [1/3]

static T[] MyCaffe.basecode.Utility.ConvertVec< T > ( double[]  rgdf)
static

Convert an array of double to an array of generics.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
rgdfSpecifies the array of double.
Returns
The array of generics is returned.

Definition at line 513 of file Utility.cs.

◆ ConvertVec< T >() [2/3]

static T[] MyCaffe.basecode.Utility.ConvertVec< T > ( float[]  rgf)
static

Convert an array of float to an array of generics.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
rgfSpecifies the array of float.
Returns
The array of generics is returned.

Definition at line 534 of file Utility.cs.

◆ ConvertVec< T >() [3/3]

static double[] MyCaffe.basecode.Utility.ConvertVec< T > ( T[]  rg)
static

Convert an array of generics to an array of double.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
rgSpecifies the array of generics.
Returns
The array of double is returned.

Definition at line 478 of file Utility.cs.

◆ ConvertVecF< T >()

static float[] MyCaffe.basecode.Utility.ConvertVecF< T > ( T[]  rg,
int  nStart = 0 
)
static

Convert an array of generics to an array of float.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
rgSpecifies the array of generics.
nStartSpecifies a start offset (default = 0).
Returns
The array of float is returned.

Definition at line 496 of file Utility.cs.

◆ Count() [1/2]

static int MyCaffe.basecode.Utility.Count ( int[]  rgShape,
int  nStartIdx = 0,
int  nEndIdx = -1 
)
static

Return the count of items given the shape.

Parameters
rgShapeSpecifies the shape to count from the start index through the end index.
nStartIdxSpecifies the start index (default = 0).
nEndIdxSpecifies the end index (default = -1, which uses length of rgShape).
Returns
The count is returned.

Definition at line 105 of file Utility.cs.

◆ Count() [2/2]

static int MyCaffe.basecode.Utility.Count ( List< int >  rgShape,
int  nStartIdx = 0,
int  nEndIdx = -1 
)
static

Return the count of items given the shape.

Parameters
rgShapeSpecifies the shape to count from the start index through the end index.
nStartIdxSpecifies the start index (default = 0).
nEndIdxSpecifies the end index (default = -1, which uses length of rgShape).
Returns
The count is returned.

Definition at line 83 of file Utility.cs.

◆ Create()

static List< int > MyCaffe.basecode.Utility.Create ( int  nCount,
int  nStart,
int  nInc 
)
static

Create a new List and fill it with values starting with start and incrementing by inc.

Parameters
nCountSpecifies the number of items.
nStartSpecifies the start value.
nIncSpecifies the increment added to the last value added.
Returns
The new List is returned.

Definition at line 721 of file Utility.cs.

◆ Create< T >()

static List< T > MyCaffe.basecode.Utility.Create< T > ( int  nCount,
fDefault 
)
static

Create a new List and fill it with default values up to a given count.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
nCountSpecifies the number of items.
fDefaultSpecifies the default value.
Returns
The new List is returned.

Definition at line 702 of file Utility.cs.

◆ GetNumber()

static int MyCaffe.basecode.Utility.GetNumber ( string  str)
static

Parses a string into a number, or if the string does not contain a number returns 0.

Parameters
strSpecifies the string to parse.
Returns
The parsed number is returned, or if the string does not contan a number, 0 is returned.

Definition at line 837 of file Utility.cs.

◆ GetSpatialDim()

static int MyCaffe.basecode.Utility.GetSpatialDim ( List< int >  rg,
int  nStartIdx = 0 
)
static

Calculate the spatial dimension of an array starting at a given axis.

Parameters
rgSpecifies the shape to measure.
nStartIdxSpecifies the starting axis.
Returns
The spacial dimension is returned.

Definition at line 64 of file Utility.cs.

◆ Load< T >()

static List< T > MyCaffe.basecode.Utility.Load< T > ( BinaryReader  br)
static

Loads a list of items from a binary reader.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
brSpecifies the binary reader.
Returns
The list of items is returned.

Definition at line 230 of file Utility.cs.

◆ LoadDouble()

static List< double > MyCaffe.basecode.Utility.LoadDouble ( BinaryReader  br)
static

Loads a list of double from a binary reader.

Parameters
brSpecifies the binary reader.
Returns
The list of items is returned.

Definition at line 352 of file Utility.cs.

◆ LoadFloat()

static List< float > MyCaffe.basecode.Utility.LoadFloat ( BinaryReader  br)
static

Loads a list of float from a binary reader.

Parameters
brSpecifies the binary reader.
Returns
The list of items is returned.

Definition at line 385 of file Utility.cs.

◆ LoadInt()

static ? int MyCaffe.basecode.Utility.LoadInt ( BinaryReader  br)
static

Loads a nullable int from a binary reader.

Parameters
brSpecifies the binary reader.
Returns
The value read in is returned.

Definition at line 416 of file Utility.cs.

◆ LoadTextLines()

static List< string > MyCaffe.basecode.Utility.LoadTextLines ( string  strFile,
Log  log = null,
bool  bPrependPath = true 
)
static

Load each line of a text file and return the contents as a list.

Parameters
strFileSpecifies the text file to load.
logOptionally, specifies the output log used to output errors (default = null). When null, any errors are thrown as exceptions.
bPrependPathOptionallly, specifies to prepend the path of the 'strFile' to each file within the file, but only do so with entries starting with '.'
Returns
A list containing each line of the text file is returned.

Definition at line 1054 of file Utility.cs.

◆ ParseListToInt()

static List< int > MyCaffe.basecode.Utility.ParseListToInt ( string  str)
static

Parses a comma delimited string into an array of int.

Parameters
strSpecifies the string to parse.
Returns
The array of int is returned.

Definition at line 819 of file Utility.cs.

◆ RandomShuffle()

static List< int > MyCaffe.basecode.Utility.RandomShuffle ( List< int >  rg,
int?  nSeed = null 
)
static

Randomly shuffle the entries in the specified list.

Parameters
rgSpecifies the input list to shuffle.
nSeedOptionally, specifies a seed for the random generator.
Returns
The newly shuffled list is returned.

Definition at line 1021 of file Utility.cs.

◆ Replace() [1/3]

static string MyCaffe.basecode.Utility.Replace ( string  str,
char  ch1,
char  ch2 
)
static

Replaces each instance of one character with another character in a given string.

Parameters
strSpecifies the string.
ch1Specifies the character to find.
ch2Specifies the character replacement.
Returns
The new string is returned.

Definition at line 864 of file Utility.cs.

◆ Replace() [2/3]

static string MyCaffe.basecode.Utility.Replace ( string  str,
char  ch1,
string  str2 
)
static

Replaces each instance of one character with another string in a given string.

Parameters
strSpecifies the string.
ch1Specifies the character to find.
str2Specifies the string replacement.
Returns
The new string is returned.

Definition at line 889 of file Utility.cs.

◆ Replace() [3/3]

static string MyCaffe.basecode.Utility.Replace ( string  str,
string  str1,
char  ch2 
)
static

Replaces each instance of one character with another string in a given string.

Parameters
strSpecifies the string.
str1Specifies the string to find.
ch2Specifies the char replacement.
Returns
The new string is returned.

Definition at line 914 of file Utility.cs.

◆ ReplaceMacro()

static string MyCaffe.basecode.Utility.ReplaceMacro ( string  strRaw,
string  strMacroName,
string  strReplacement 
)
static

The ConvertMacro method is used to replace a set of macros in a given string.

Parameters
strRawSpecifies the raw string.
strMacroNameSpecifies the macro to be replaced.
strReplacementSpecifies the replacement string.
Returns
The new string with all macros replaced is returned.

Definition at line 947 of file Utility.cs.

◆ ReplaceMacros()

static string MyCaffe.basecode.Utility.ReplaceMacros ( string  strRaw,
List< KeyValuePair< string, string > >  rgMacros 
)
static

The ReplaceMacros method is used to replace a set of macros in a given string.

Parameters
strRawSpecifies the raw string.
rgMacrosSpecifies the set of macros.
Returns
The new string with the macros replaced, is returned.

Definition at line 978 of file Utility.cs.

◆ Resize< T >()

static void MyCaffe.basecode.Utility.Resize< T > ( ref List< T >  rg,
int  nCount,
tDefault 
)
static

Resize a List and fill the new elements with the default value.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
rgSpecifies the List to resize.
nCountSpecifies the new count.
tDefaultSpecifies the default value used when expanding the list.

Definition at line 565 of file Utility.cs.

◆ Save() [1/3]

static void MyCaffe.basecode.Utility.Save ( BinaryWriter  bw,
int?  nVal 
)
static

Saves a nullable int to a binary writer.

Parameters
bwSpecifies the binary writer.
nValSpecifies the value to write.

Definition at line 403 of file Utility.cs.

◆ Save() [2/3]

static void MyCaffe.basecode.Utility.Save ( BinaryWriter  bw,
List< double >  rg 
)
static

Save a list of double to a binary writer.

Parameters
bwSpecifies the binary writer.
rgSpecifies the list of items.

Definition at line 337 of file Utility.cs.

◆ Save() [3/3]

static void MyCaffe.basecode.Utility.Save ( BinaryWriter  bw,
List< float >  rg 
)
static

Save a list of float to a binary writer.

Parameters
bwSpecifies the binary writer.
rgSpecifies the list of items.

Definition at line 370 of file Utility.cs.

◆ Save< T >()

static void MyCaffe.basecode.Utility.Save< T > ( BinaryWriter  bw,
List< T >  rg 
)
static

Save a list of items to a binary writer.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
bwSpecifies the binary writer.
rgSpecifies the list of items.

Definition at line 126 of file Utility.cs.

◆ Set< T >() [1/2]

static void MyCaffe.basecode.Utility.Set< T > ( List< T >  rg,
fVal 
)
static

Set all values of a List with a given value.

Template Parameters
T
Parameters
rgSpecifies the List.
fValSpecifies the value.

Definition at line 741 of file Utility.cs.

◆ Set< T >() [2/2]

static void MyCaffe.basecode.Utility.Set< T > ( T[]  rg,
fVal 
)
static

Set all values within an array with a given value.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.
Parameters
rgSpecifies the array to set.
fValSpecifies the value.

Definition at line 755 of file Utility.cs.

◆ ToString< T >()

static string MyCaffe.basecode.Utility.ToString< T > ( List< T >  rg,
int  nDecimals = -1,
int  nIdxHighight = -1,
string  strStart = "{",
string  strEnd = "}" 
)
static

Convert an array to a string.

Template Parameters
TSpecifies the base type of the array.
Parameters
rgSpecifies the array.
nDecimalsOptionally, specifies the number of decimals (default = -1, ignored)
nIdxHighightOptionally, specifies the index to highlight (default = -1, ignored)
strStartOptionally, specifies the start bracket (default = '{')
strEndOptionally, specifies the end bracket (default = '}')
Returns
The string representation of the array is returned.

Definition at line 773 of file Utility.cs.


The documentation for this class was generated from the following file: