Quantcast
Channel: Math.NET Numerics
Viewing all articles
Browse latest Browse all 971

New Post: Using Matrix types in VB

$
0
0
Yes, CreateFromColumns would be more flexible if instead of IList it used IEnumerable, which is covariant. We may want to change that in the future.

For now the following options come to mind that should all work (C#, I'm not fluent in VB.net but it should work the same way):
  • Declare your vector list with the base type instead (i.e. what the compiler suggests):
var vs = new List<Vector<double>>();
  • Convert the list to an array using ToArray, leveraging a small (although a bit nasty) trick around array covariance:
var m = Matrix.CreateFromColumns(vs.ToArray());
  • Cast properly, using Linq:
var m = Matrix.CreateFromColumns(vs.Cast<Vector<double>>().ToList());
  • Convert the list:
var m = Matrix.CreateFromColumns(vs.ConvertAll(x => (Vector<double>)x));
Thanks,
Christoph

Viewing all articles
Browse latest Browse all 971


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>