This section describes the data block classes that underlie the NMath matrix and vector types.
NOTE- You will rarely need to deal directly with data block objects.
The classes that encapsulate blocks of data in NMath are named <Type>DataBlock, where <Type> is Float, Double, FloatComplex, or DoubleComplex. (See Chapter 3 for a description of the complex number structures.) Thus:
The data referenced by the NMath vector and matrix classes is in the form of an instance of one of the data block classes.
Each data block object contains a reference to an array of the appropriate datatype, and an offset into the array. For instance, a FloatComplexDataBlock object contains a reference to an array of FloatComplex instances.
Think of a data block as encapsulating the concept of a pointer without using unsafe code. The value of an equivalent pointer is the address of the first element of the array, plus the offset.
Data block classes have the following public, read-only properties:
You rarely need to deal directly with data block objects. However, for applications that need to interface with native or legacy code, the NMath vector and matrix classes can be used to obtain a pointer to the underlying data. Each of these classes has a property called DataBlock that returns the data block object being viewed. As mentioned above, each data block class contains an array and an offset that allows you to extract a pointer to the beginning of the data. For example:
DoubleVector v = new DoubleVector( 12, 0, 1 ); DoubleDataBlock dataBlock = v.DataBlock; unsafe { double *ptr = &(dataBlock.Data[dataBlock.Offset]); // Do something with *ptr here }
NOTE- Exercise caution when using raw data pointers.
Vector and matrix classes also provide ToArray() methods that return data copied into an array. Thus:
DoubleVector v = new DoubleVector( "1 2 3 4 5" ); double[] d = v.ToArray(); DoubleMatrix A = new DoubleMatrix( "3x3 [1 2 3 4 5 6 7 8 9]" ); double[,] d2 = A.ToArray();TOC | Previous | Next | Index