public double MaxDiff(object thatd)
        {
            DistributionCursorArray <DistributionType, DomainType> that = thatd as DistributionCursorArray <DistributionType, DomainType>;

            if (that == null)
            {
                return(Double.PositiveInfinity);
            }
            if (!IsCompatibleWith(that))
            {
                return(Double.PositiveInfinity);
            }
            double max = 0;
            IEnumerator <DistributionType> iter = that.GetEnumerator();

            foreach (DistributionType d in this)
            {
                bool ok = iter.MoveNext();
                Assert.IsTrue(ok);
                double diff = ((Diffable)d).MaxDiff(iter.Current);
                if (diff > max)
                {
                    max = diff;
                }
            }
            return(max);
        }
        public override bool Equals(object thatd)
        {
            DistributionCursorArray <DistributionType, DomainType> that = thatd as DistributionCursorArray <DistributionType, DomainType>;

            if (that == null)
            {
                return(false);
            }
            if (!IsCompatibleWith(that))
            {
                return(false);
            }
            IEnumerator <DistributionType> iter = that.GetEnumerator();

            foreach (DistributionType d in this)
            {
                bool ok = iter.MoveNext();
                Assert.IsTrue(ok);
                if (!d.Equals(iter.Current))
                {
                    return(false);
                }
            }
            return(true);
        }
        public void SetTo(DistributionCursorArray <DistributionType, DomainType> that)
        {
            CheckCompatible(that);
            Action action = delegate() { cursor.SetTo(that.cursor); };

            ForEach(that, action);
        }
        // a and b may be the same object as this.
        public void SetToProduct(DistributionCursorArray <DistributionType, DomainType> a, DistributionCursorArray <DistributionType, DomainType> b)
        {
            CheckCompatible(a);
            CheckCompatible(b);
            Action action = delegate() { cursor.SetToProduct(a.cursor, b.cursor); };

            ForEach(a, b, action);
        }
        public bool IsCompatibleWith(object thatd)
        {
            DistributionCursorArray <DistributionType, DomainType> that = thatd as DistributionCursorArray <DistributionType, DomainType>;

            if (that == null)
            {
                return(false);
            }
            if (!base.IsCompatibleWith(that))
            {
                return(false);
            }
            return(true);
            //return cursor.IsCompatibleWith(that.cursor);
        }
        Split(IList <bool> isOuterDimension)
        {
            int outerRank = StringUtil.Sum(isOuterDimension);

            if (outerRank == 0)
            {
                throw new ArgumentException("No outer dimensions chosen");
            }
            int innerRank = Rank - outerRank;

            if (innerRank == 0)
            {
                throw new ArgumentException("No inner dimensions left");
            }
            int[] innerLengths = new int[innerRank];
            int[] innerStride  = new int[innerRank];
            int[] outerLengths = new int[outerRank];
            int[] outerStride  = new int[outerRank];
            int   innerIndex   = 0;
            int   outerIndex   = 0;
            int   i            = 0;

            foreach (bool isOuter in isOuterDimension)
            {
                if (isOuter)
                {
                    outerLengths[outerIndex] = dim[i];
                    outerStride[outerIndex]  = stride[i];
                    outerIndex++;
                }
                else
                {
                    innerLengths[innerIndex] = dim[i];
                    innerStride[innerIndex]  = stride[i];
                    innerIndex++;
                }
                i++;
            }
            DistributionCursorArray <DistributionType, DomainType> inner =
                new DistributionCursorArray <DistributionType, DomainType>
                    ((DistributionType)this[0].ReferenceClone(), innerLengths, innerStride);

            return(new DistributionCursorArray <DistributionCursorArray <DistributionType, DomainType>, DomainType[]>
                       (inner, outerLengths, outerStride));
        }