Class Util
Helpful methods used throughout the library.
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
Methods
AreEqual<T>(T, T)
Declaration
public static bool AreEqual<T>(T a, T b)
Parameters
Type |
Name |
Description |
T |
a |
|
T |
b |
|
Returns
Type Parameters
ArrayInit<T>(Int32, Converter<Int32, T>)
Declaration
public static T[] ArrayInit<T>(int length, Converter<int, T> init)
Parameters
Returns
Type Parameters
ArrayInit<T>(Int32, Int32, Func<Int32, Int32, T>)
Declaration
public static T[, ] ArrayInit<T>(int length1, int length2, Func<int, int, T> init)
Parameters
Returns
Type Parameters
CartesianProduct<T>(IEnumerable<IEnumerable<T>>)
Declaration
public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(IEnumerable<IEnumerable<T>> listOfLists)
Parameters
Returns
Type Parameters
ChangeElementTypeAndRank(Type, Type, Int32)
Change the element type of an array type to another type.
Declaration
public static Type ChangeElementTypeAndRank(Type arrayType, Type newElementType, int newRank)
Parameters
Type |
Name |
Description |
Type |
arrayType |
A scalar, array, multidimensional array, or nested array type.
|
Type |
newElementType |
Any type.
|
Int32 |
newRank |
An integer greater than zero.
|
Returns
Type |
Description |
Type |
An array type whose element type is newElementType and whose rank is newRank
|
Remarks
CollectionToString<T>(IEnumerable<T>)
Declaration
public static string CollectionToString<T>(IEnumerable<T> list)
Parameters
Returns
Type Parameters
CreateArray<T>(Int32[])
Declaration
public static Array CreateArray<T>(params int[] lengths)
Parameters
Type |
Name |
Description |
Int32[] |
lengths |
|
Returns
Type |
Description |
Array |
A new array.
|
Type Parameters
Name |
Description |
T |
Array element type.
|
DynamicInvoke(Delegate, Object[])
Invoke a Delegate, preserving the stack trace of any exception thrown.
Declaration
public static object DynamicInvoke(Delegate del, params object[] parameters)
Parameters
Returns
GetArrayDepth(Type, Type)
The number of indexing brackets needed to turn arrayType into innermostElementType.
Declaration
public static int GetArrayDepth(Type arrayType, Type innermostElementType)
Parameters
Type |
Name |
Description |
Type |
arrayType |
|
Type |
innermostElementType |
|
Returns
Type |
Description |
Int32 |
An integer between 0 and the full depth of arrayType.
|
GetElementType(Type)
Declaration
public static Type GetElementType(Type type)
Parameters
Type |
Name |
Description |
Type |
type |
|
Returns
GetElementType(Type, out Int32)
Declaration
public static Type GetElementType(Type type, out int rank)
Parameters
Returns
GetEqualityComparer<T>()
Declaration
public static IEqualityComparer<T> GetEqualityComparer<T>()
Returns
Type Parameters
GetInnermostElementType(Type)
Gets the innermost array element type of a given array type.
Declaration
public static Type GetInnermostElementType(Type arrayType)
Parameters
Type |
Name |
Description |
Type |
arrayType |
The array type.
|
Returns
Type |
Description |
Type |
The innermost array element type.
|
GetMaxKValues<T>(IEnumerable<T>, Int32, IComparer<T>)
Gets the maximum k values from an enumerable (by using a heap).
Declaration
public static IEnumerable<T> GetMaxKValues<T>(IEnumerable<T> values, int k, IComparer<T> comparer = null)
Parameters
Type |
Name |
Description |
IEnumerable<T> |
values |
The enumerable of values.
|
Int32 |
k |
The number of values to get.
|
IComparer<T> |
comparer |
The comparer to use for ordering.
|
Returns
Type |
Description |
IEnumerable<T> |
The list of the maximum k values.
|
Type Parameters
Name |
Description |
T |
The type of an element in the enumerable.
|
IArrayFromFunc<T>(Int32, Func<Int32, T>)
Create an implicit array that calls a delegate whenever an element is read
Declaration
public static IArray<T> IArrayFromFunc<T>(int length, Func<int, T> getItem)
Parameters
Type |
Name |
Description |
Int32 |
length |
The length of the array
|
Func<Int32, T> |
getItem |
The delegate to call on every element read
|
Returns
Type |
Description |
IArray<T> |
An IArray
|
Type Parameters
Name |
Description |
T |
The element type
|
IArrayFromFunc<T>(Int32, Int32, Func<Int32, Int32, T>)
Create an implicit 2D array that calls a delegate whenever an element is read
Declaration
public static IArray2D<T> IArrayFromFunc<T>(int length0, int length1, Func<int, int, T> getItem)
Parameters
Type |
Name |
Description |
Int32 |
length0 |
The length of the first dimension
|
Int32 |
length1 |
The length of the second dimension
|
Func<Int32, Int32, T> |
getItem |
The delegate to call on every element read
|
Returns
Type |
Description |
IArray2D<T> |
An IArray2D
|
Type Parameters
Name |
Description |
T |
The element type
|
Invoke(MethodBase, Object, Object[])
Invoke a method, preserving the stack trace of any exception thrown.
Declaration
public static object Invoke(MethodBase method, object target, params object[] parameters)
Parameters
Returns
IsIList(Type)
Declaration
public static bool IsIList(Type type)
Parameters
Type |
Name |
Description |
Type |
type |
|
Returns
MakeArrayType(Type, Int32)
Declaration
public static Type MakeArrayType(Type elementType, int rank)
Parameters
Type |
Name |
Description |
Type |
elementType |
|
Int32 |
rank |
|
Returns
SetToProduct<T>(T, IEnumerable<T>)
Set result to the product of all items in list.
Declaration
public static void SetToProduct<T>(T result, IEnumerable<T> list)
where T : SettableToProduct<T>
Parameters
Type |
Name |
Description |
T |
result |
|
IEnumerable<T> |
list |
Must have Count > 1.
|
Type Parameters
Swap<T>(ref T, ref T)
Swaps the values of two given variables.
Declaration
public static void Swap<T>(ref T value1, ref T value2)
Parameters
Type |
Name |
Description |
T |
value1 |
The first variable passed by reference.
|
T |
value2 |
The second variable passed by reference.
|
Type Parameters
Name |
Description |
T |
The type of the variables.
|