# Constructor methods for Generic Gaussian random vector

Hi,

I’m trying to implement a generic (w.r.t. scalar type, dimension and storage) Gaussian random vector using nalgebra. Basically it’s a struct containing a mean vector and a covariance matrix. This is the code:

``````use nalgebra as na;
use nalgebra::allocator::Allocator;
use nalgebra::storage::Owned;
use nalgebra::{DefaultAllocator, Dim, DimName, Dynamic, RealField, U1};

pub struct RandomVector<N: RealField, D: Dim, MeanStorage, CovStorage> {
mean: na::Matrix<N, D, U1, MeanStorage>,
cov: na::Matrix<N, D, D, CovStorage>,
}

type RandomVectorN<N, D> = RandomVector<N, D, Owned<N, D, U1>, Owned<N, D, D>>;

impl<N: RealField, D: DimName> RandomVectorN<N, D>
where
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
{
fn standard_normal() -> Self {
RandomVectorN {
mean: na::VectorN::zeros(),
cov: na::MatrixN::<N, D>::identity(),
}
}
}

impl<N: RealField> RandomVectorN<N, Dynamic>
where
DefaultAllocator: Allocator<N, Dynamic> + Allocator<N, Dynamic, Dynamic>,
{
fn standard_normal(n: usize) -> Self {
RandomVectorN {
mean: na::VectorN::<N, Dynamic>::zeros(n),
cov: na::MatrixN::<N, Dynamic>::identity(n, n),
}
}
}
``````

Unfortunately I’m getting the following compiler error:

``````error[E0592]: duplicate definitions with name `standard_normal`
--> src\gaussian.rs:17:5
|
17 |     fn standard_normal() -> Self {
|     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `standard_normal`
...
29 |     fn standard_normal(n: usize) -> Self {
|     ------------------------------------ other definition for `standard_normal`
|
= note: upstream crates may add a new impl of trait `nalgebra::DimName` for type `nalgebra::Dynamic` in future versions
``````

As I’m new to Rust I’m not quite sure that I understand the reason for this correctly. I’m assuming that the error occurs because DimName is not implemented in my own crate and future changes could make the two implementations of standard_normal overlap. Hence my question: Is there another way to implement the `standard_normal()` function, or a way I can restructure the code, so as to avoid this error? Any help would be appreciated!