internal static double[][] checkAndConvert(Array observations, int dimension)
{
if (observations == null)
throw new ArgumentNullException("observations");
// Test if the observations are multivariate
{
double[][] multivariate = observations as double[][];
if (multivariate != null)
{
for (int i = 0; i < multivariate.Length; i++)
{
if (multivariate[i].Length != dimension)
{
throw new DimensionMismatchException("observations",
"This model expects observations of length " + dimension);
}
}
return multivariate;
}
// Test if the observations are univariate
double[] univariate = observations as double[];
if (univariate != null)
{
if (dimension != 1)
{
throw new DimensionMismatchException("observations",
"This model expects univariate observations");
}
return Accord.Math.Matrix.Split(univariate, dimension);
}
}
{
// Test if the observations are multivariate integers
int[][] multivariate = observations as int[][];
if (multivariate != null)
{
for (int i = 0; i < multivariate.Length; i++)
{
if (multivariate[i].Length != dimension)
{
throw new DimensionMismatchException("observations",
"This model expects observations of length " + dimension);
}
}
return multivariate.ToDouble();
}
// Test if the observations are univariate
int[] univariate = observations as int[];
if (univariate != null)
{
if (dimension != 1)
{
throw new DimensionMismatchException("observations",
"This model expects univariate observations");
}
return Accord.Math.Matrix.Split(univariate, dimension).ToDouble();
}
}
// else
throw new ArgumentException("Argument should be either of type " +
"double[] (for univariate observation) or double[][] (for " +
"multivariate observation).", "observations");
}