public void JaggedSetValues2() { Array jaggedGaussian = JaggedArray.ConvertToNew( jagged, typeof(int), typeof(Gaussian), delegate(object elt) { return(new Gaussian(1.0, 1.0)); }); Assert.Equal( JaggedArray.GetLength(jaggedGaussian, typeof(Gaussian)), JaggedArray.GetLength(jagged, typeof(int))); JaggedArray.ConvertElements2( jaggedGaussian, jagged, typeof(Gaussian), delegate(object elt1, object elt2) { Gaussian g = (Gaussian)elt1; double d = (int)elt2; return(Gaussian.FromMeanAndPrecision(d + g.GetMean(), 2.0)); }); int i = 0; foreach (Gaussian g in JaggedArray.ElementIterator(jaggedGaussian, typeof(Gaussian))) { Assert.Equal(g.GetMean(), 1.0 + arrExpected[i++]); } }
// Tests that visitor works when one jagged is a distribution array and the // other is a jagged array public void Array2DArrayVisitor() { int count = JaggedArray.GetLength(ga2aArrayOfDist); // We must use the expanded form of VisitElements2 here because the element type of // ga2aDistArray will be wrongly determined by the shorter version JaggedArray.VisitElements2( ga2aDistArray, ga2aArrayOfDist, typeof(Gaussian), typeof(Gaussian), delegate(object a, object b) { Assert.True(((Gaussian)a).Equals((Gaussian)b)); count--; }); Assert.Equal(0, count); }
public void JaggedConvertToNewTypeGeneric() { Array jaggedGaussian = JaggedArray.ConvertToNew <int, Gaussian>( jagged, delegate(int elt) { return(new Gaussian(0.5, 1.0)); }); Assert.Equal( JaggedArray.GetLength(jaggedGaussian, typeof(Gaussian)), JaggedArray.GetLength(jagged, typeof(int))); foreach (Gaussian g in JaggedArray.ElementIterator <Gaussian>(jaggedGaussian)) { Assert.Equal(0.5, g.GetMean()); } }
public void JaggedSetValues() { Array jaggedGaussian = JaggedArray.ConvertToNew( jagged, typeof(int), typeof(Gaussian), delegate(object elt) { return(new Gaussian(0.0, 1.0)); }); Assert.Equal( JaggedArray.GetLength(jaggedGaussian, typeof(Gaussian)), JaggedArray.GetLength(jagged, typeof(int))); JaggedArray.ConvertElements( jaggedGaussian, typeof(Gaussian), delegate(object elt) { return(Gaussian.FromMeanAndPrecision(1.0, 2.0)); }); foreach (Gaussian g in JaggedArray.ElementIterator(jaggedGaussian, typeof(Gaussian))) { Assert.Equal(1.0, g.GetMean()); } }