NMath User's Guide

TOC |  Previous |  Next |  Index

31.2 Creating Vector and Matrices from ADO.NET Objects (.NET, C#, CSharp, Visual Basic, VB.NET)

You can construct NMath vector and matrix classes from standard ADO.NET database objects. Real-value vector and matrix class constructors accept DataTable, DataRow, DataRowCollection, and DataView objects, typically obtained from a database query. Complex number vector and matrix class constructors accept paired database objects containing the real and imaginary parts, respectively.

For example, assuming table is a DataTable instance:

DoubleMatrix A = new DoubleMatrix( table );

The resulting matrix has the same number of rows and columns as the data table. Note that all values must be able to be converted to a double through a cast. If not, the constructor throws an InvalidCastException.

Similarly, assuming view1 and view2 are DataView objects, this code creates a FloatComplexVector instance whose real parts are derived from the first column of view1, and whose imaginary parts are derived from the first column of view2:

FloatComplexVector v = new FloatComplexVector( view1, view2 );

In this case, all values must be able to be converted to a float through a cast.

TOC |  Previous |  Next |  Index