Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implicit conversion for Vector and Matrix types#1033

antonott started this conversation inIdeas
Discussion options

When using Math.NET I often find myself having to convert a scalar into a vector or matrix, to match a particular function signature. The typical example would be a class that implements a probability distribution, which can be either univariate or multivariate:

var distribution = new SomeDistribution(...);double x = 1.3;double y = distribution.Density(Vector<double>.Build.Dense(1, x));...public class SomeDistribution{    public double Density(Vector<double> x)    {        ...    }    ...}

It would be nice to be able to pass the double directly in this case, and have it be automatically converted to a one-element vector. Same for matrix arguments, where scalar input could be automatically converted to a 1-by-1 matrix. Other solutions, such as overloading functions or making separate classes for the univariate cases, are cumbersome and lead to a lot of boilerplate.

I'm by no means a C# expert, but should this not be possible to implement withuser-defined implicit conversion operators?

You must be logged in to vote

Replies: 1 comment

Comment options

Also, one could similarly consider automatic casting ofVector<T> into toMatrix<T>. That is, if a function expects a matrix you should be able to call it with an n-dimensional vector, which is automatically converted to an n-by-1 matrix.

While nice in principle, I don't see this getting as much use as the main suggestion, since I expect most functions with a matrix parameter will require asquare matrix. But it might be usefull for the MatrixNormal class, which I suspect most people use as avector normal distribution anyway.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
Labels
None yet
1 participant
@antonott

[8]ページ先頭

©2009-2025 Movatter.jp