// 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 JaggedVisitor2() { Dirichlet d1 = new Dirichlet(2.0, 3.0, 4.0); Dirichlet d2 = new Dirichlet(3.0, 4.0, 5.0); Dirichlet d3 = d1 * d2; Array jaggedDir1 = JaggedArray.ConvertToNew( jagged, typeof(int), typeof(Dirichlet), delegate(object elt) { return(new Dirichlet(d1)); }); Array jaggedDir2 = JaggedArray.ConvertToNew( jagged, typeof(int), typeof(Dirichlet), delegate(object elt) { return(new Dirichlet(d2)); }); JaggedArray.VisitElements2( jaggedDir1, jaggedDir2, typeof(Dirichlet), typeof(Dirichlet), delegate(object elt1, object elt2) { ((Dirichlet)elt1).PseudoCount.SetTo((((Dirichlet)elt1) * ((Dirichlet)elt2)).PseudoCount); }); foreach (Dirichlet d in JaggedArray.ElementIterator(jaggedDir1, typeof(Dirichlet))) { Assert.Equal(d.PseudoCount, d3.PseudoCount); } }