ILNumerics Ultimate VS

ScopeEnter Method (NullableArrayStyles)

ILNumerics Ultimate VS Documentation
ILNumerics - Technical Application Development
Begins an artificial scope block within a local function, determine the array style.

[ILNumerics Core Module]

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

public static IDisposable Enter(
	Nullable<ArrayStyles> arrayStyle
)

Parameters

arrayStyle
Type: SystemNullableArrayStyles
The ArrayStyle valid within the scope block. A non-null value will be used within the scope block as current array style.

Return Value

Type: IDisposable
The new scope object.
Remarks

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.

If a value other than null is given for arrayStyle the value of ArrayStyle is modified for the operations within this scope block. After the scope is left, the old setting is reliably restored. If null is provided the current setting of ArrayStyle is not touched.

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

[ILNumerics Core Module]

Examples

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.

[TestMethod]
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

Reference