Search Results for

    Show / Hide Table of Contents

    Class Util

    Helpful methods used throughout the library.

    Inheritance
    Object
    Util
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Microsoft.ML.Probabilistic.Utilities
    Assembly: Microsoft.ML.Probabilistic.dll
    Syntax
    public static class Util

    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 Description
    Boolean
    Type Parameters
    Name Description
    T

    ArrayInit<T>(Int32, Converter<Int32, T>)

    Declaration
    public static T[] ArrayInit<T>(int length, Converter<int, T> init)
    Parameters
    Type Name Description
    Int32 length
    Converter<Int32, T> init
    Returns
    Type Description
    T[]
    Type Parameters
    Name Description
    T

    ArrayInit<T>(Int32, Int32, Func<Int32, Int32, T>)

    Declaration
    public static T[, ] ArrayInit<T>(int length1, int length2, Func<int, int, T> init)
    Parameters
    Type Name Description
    Int32 length1
    Int32 length2
    Func<Int32, Int32, T> init
    Returns
    Type Description
    T[,]
    Type Parameters
    Name Description
    T

    CartesianProduct<T>(IEnumerable<IEnumerable<T>>)

    Declaration
    public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(IEnumerable<IEnumerable<T>> listOfLists)
    Parameters
    Type Name Description
    IEnumerable<IEnumerable<T>> listOfLists
    Returns
    Type Description
    IEnumerable<IEnumerable<T>>
    Type Parameters
    Name Description
    T

    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

    For example, ChangeElementTypeAndRank(typeof(int[,][]), typeof(double), 2) returns typeof(double[,]).

    CollectionToString<T>(IEnumerable<T>)

    Declaration
    public static string CollectionToString<T>(IEnumerable<T> list)
    Parameters
    Type Name Description
    IEnumerable<T> list
    Returns
    Type Description
    String
    Type Parameters
    Name Description
    T

    CreateArray<T>(Int32[])

    Like CreateInstance(Type, Int32[]) but 5x faster.

    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
    Type Name Description
    Delegate del
    Object[] parameters
    Returns
    Type Description
    Object

    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.

    Remarks

    For example, if arrayType is int[][] and innermostElementType is int, the result is 2. If arrayType is int[][] and innermostElementType is int[], the result is 1. If arrayType is int[][] and innermostElementType is int[][], the result is 0.

    GetElementType(Type)

    Declaration
    public static Type GetElementType(Type type)
    Parameters
    Type Name Description
    Type type
    Returns
    Type Description
    Type

    GetElementType(Type, out Int32)

    Declaration
    public static Type GetElementType(Type type, out int rank)
    Parameters
    Type Name Description
    Type type
    Int32 rank
    Returns
    Type Description
    Type

    GetEqualityComparer<T>()

    Declaration
    public static IEqualityComparer<T> GetEqualityComparer<T>()
    Returns
    Type Description
    IEqualityComparer<T>
    Type Parameters
    Name Description
    T

    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.

    Remarks

    If the type is not an array, result will be the type itself.

    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
    Type Name Description
    MethodBase method
    Object target
    Object[] parameters
    Returns
    Type Description
    Object

    IsIList(Type)

    Declaration
    public static bool IsIList(Type type)
    Parameters
    Type Name Description
    Type type
    Returns
    Type Description
    Boolean

    MakeArrayType(Type, Int32)

    Declaration
    public static Type MakeArrayType(Type elementType, int rank)
    Parameters
    Type Name Description
    Type elementType
    Int32 rank
    Returns
    Type Description
    Type

    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
    Name Description
    T

    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.

    In This Article
    Back to top Copyright © .NET Foundation. All rights reserved.