ILNumerics Ultimate VS

ScopeEnter Method

ILNumerics Ultimate VS Documentation
ILNumerics - Technical Application Development
Begins an artificial scope block within a local function.

[ILNumerics Core Module]

Namespace:  ILNumerics
Assembly:  ILNumerics.Core (in ILNumerics.Core.dll) Version: (5.5.7503.3146)

public static IDisposable Enter()

Return Value

Type: IDisposable
The new scope object.

The Scope class plays an important role for the ILNumerics memory management. When writing functions in ILNumerics, Scope is used to define blocks of artificial scopes for local function blocks. ILNumerics ensures that no memory is left as garbage after the scope block is left. Furthermore, it garantees that input arrays are kept alive during the execution of the block. By following these ILNumerics function rules ILNumerics is able to optimize the execution of the algorithm regarding execution speed and memory footprint.

Several overloads exist allowing to specify one or multiple arrays together with the array style setting.

[ILNumerics Core Module]


The examples demonstrates a custom function in ILNumerics. It demonstrates the use of an artificial scope block to temporarily change the array style for the thread.

public void ScopeWithArrayStyle() {

    using (Settings.Ensure(() => Settings.ArrayStyle, ArrayStyles.numpy)) {
        // numpy style is valid here...
        Assert.IsTrue(Settings.ArrayStyle == ArrayStyles.numpy);

        using (Scope.Enter(ArrayStyles.ILNumericsV4)) {
            // in the scope: array style is ILNumericsV4

            Assert.IsTrue(Settings.ArrayStyle == ArrayStyles.ILNumericsV4);

            // the style may be changed again ... 
            Settings.ArrayStyle = ArrayStyles.numpy;
            Assert.IsTrue(Settings.ArrayStyle == ArrayStyles.numpy);
            Settings.ArrayStyle = ArrayStyles.ILNumericsV4;
            Assert.IsTrue(Settings.ArrayStyle == ArrayStyles.ILNumericsV4);
            // ...
        // array style which was valid immediately before the scope began is restored 
        Assert.IsTrue(Settings.ArrayStyle == ArrayStyles.numpy);

See Also