Basic concepts for ILNumerics.Net
Creating arrays
The most important type for working with ILNumerics.Net currently is ILArray<T>. Here T is the generic parameter, substituting
the inner type of elements the array holds. Mostly this will be a System.Double.
The following expressions list only some examples how to create those arrays.
ILArray<double> Arr = ILMath.ones(5,4,3); // construct 3 dimensional array of ones
ILArray<double> Mat = ILMath.zeros(5,4); // construct matrix of zeros
ILArray<double> Vec = ILMath.ones(1,5); // construct (row) vector of ones
ILArray<double> Vec = ILMath.rand(5,1); // construct (column) vector with random values
See the array creation tutorial for a detailed introduction of the ILArray class.
Using built in functions
ILNumerics.Net provides a large collection of built in functions wich expect ILArray objects as parameter.
Those functions are organized as static member functions of the ILMath class, which resides in the ILNumerics.BuiltInFunctions namespace.
Consult the TODO: function list, to learn more about all the functions currently available.
There are two possible models of accessing ILNumerics.Net built in functions. Depending on the class model you choose, you may reference those functions externally or internally. The following sections will help you to decide which model to choose.
Class design - External usage of ILNumerics.Net
One possible model is to design your classes by using an 'outside view' onto ILNumerics.Net: Every time you want to access the mathematical functions of ILNumerics.Net you create the arrays in your classes and access the built in functions by referencing the static class nameILMath:
Example #1 (C#)
using ILNumerics;
using ILNumerics.BuiltInFunctions;
using ILNumerics.Exceptions;
using ILNumerics.Algorithms;
namespace your.name.space {
public class yourClass {
public void YourFunction() {
...
ILArray<double> A,RS,Res;
A = ILMath.ones(20,30);
RS = ILMath.zeros(20,3);
...
// fill A,RS with your data here
...
// do the computations by calling ILNumerics.Net externally
ILArray<double> Result = ILMath.linsolve(A,RS);
...
}
}
}
This model is recommended if you only want to access high level functionality like algorithms from the
ILNumerics.Algorithms namespace and the number of calls to the library is limited.
This model is comparable with the process of accessing a high level built in function, a package of *.m file functions or with accessing a mex file from your C-code.
Internal usage class model
Another way of designing your code is to place your computations into a seperate class derived fromILNumerics.Algorithms.ILAlgorithm.
This way your computational class becomes somehow a part of the library, accessing the functions gets even simpler:
Example #2 (C#)
namespace your.name.space {
public class yourComputation : ILAlgorithm{
public ILArray<double> Compute(ILArray<double> RS, ...) {
...
ILArray<double> A,Res;
A = ones(20,30);
RS = zeros(20,3);
...
// fill A,RS with your data here
...
// do the computations by calling ILNumerics.Net
ILArray<double> Result = linsolve(A,RS);
...
return Res;
}
}
}
Note that the class name ILMath is ommitted in this example. This is due to the
fact that from inside a class derived from ILNumerics.Algorithms.ILAlgorithm all
functions of the ILMath class are also directly / locally accessible. This is valid for both: synchronous algorithms
and asynchronous algorithms. See the algorithm tutorial for details on implementing and using algorithm classes for ILNumerics.Net.
Use this model if the number of accesses to the library is relatively high. For example, if you are designing a high level algorithm by accessing a lot of low level functionality this model is recommended.
This model is comparable with the concept of writing an *.m file in Matlab.