Пример #1
0
 /// <summary>
 /// Apply a reduction action to produce a smaller array.
 /// </summary>
 public void ReduceTo(int[] keep, ICursorArray <DistributionType> result)
 {
     Assert.IsTrue(keep.Length == result.Rank);
     int[] index        = new int[Rank];
     int[] result_index = new int[result.Rank];
     for (int i = 0; i < Count; i++)
     {
         LinearIndexToMultidimensionalIndex(i, index);
         int index_sum = 0;
         for (int d = 0; d < index.Length; d++)
         {
             index_sum += index[d];
         }
         int result_index_sum = 0;
         for (int d = 0; d < keep.Length; d++)
         {
             result_index[d]   = index[keep[d]];
             result_index_sum += result_index[d];
         }
         DistributionType d1    = this[index];
         DistributionType d2    = result[result_index];
         bool             first = (result_index_sum == index_sum);
         if (first)
         {
             d2.SetTo(d1);
         }
         else
         {
             d2.SetToProduct(d2, d1);
         }
     }
 }
Пример #2
0
 public void CheckCompatible(ICursorArray that)
 {
     if (!IsCompatibleWith(that))
     {
         throw new InferRuntimeException("StructArrays are incompatible");
     }
 }
Пример #3
0
        /// <summary>
        /// Invoke an element-wise action across two arrays.
        /// </summary>
        /// <param name="that">An array of the same size as <c>this</c>.  Can be the same object as <c>this</c>.</param>
        /// <param name="action">A delegate which accesses the array cursors.</param>
        public void ForEach(ICursorArray that, Action action)
        {
            IEnumerator iter = that.GetEnumerator();

            foreach (CursorType item in this)
            {
                bool ok = iter.MoveNext();
                Assert.IsTrue(ok);
                action();
            }
        }
Пример #4
0
        /// <summary>
        /// Invoke an element-wise action across three arrays.
        /// </summary>
        /// <param name="a">An array of the same size as <c>this</c>.  Can be the same object as <c>this</c>.</param>
        /// <param name="b">An array of the same size as <c>this</c>.  Can be the same object as <c>this</c>.</param>
        /// <param name="action">A delegate which accesses the array cursors.</param>
        public void ForEach(ICursorArray a, ICursorArray b, Action action)
        {
            IEnumerator a_iter = a.GetEnumerator();
            IEnumerator b_iter = b.GetEnumerator();

            foreach (CursorType item in this)
            {
                bool a_ok = a_iter.MoveNext();
                bool b_ok = b_iter.MoveNext();
                Assert.IsTrue(a_ok);
                Assert.IsTrue(b_ok);
                action();
            }
        }
Пример #5
0
 public bool IsCompatibleWith(ICursorArray that)
 {
     return(Lengths.ValueEquals(that.Lengths));
 }