Beispiel #1
0
        public IEnumerable <T> GetEnumerable()
        {
            var denseArrayView = DenseView != null?DenseView.GetEnumerable() : null;

            var sparseIndicesArrayView = SparseIndices != null?SparseIndices.GetEnumerable() : null;

            var sparseValuesArrayView = SparseValues != null?SparseValues.GetEnumerable() : null;

            using (var sparseIndicesIter = sparseIndicesArrayView != null ? sparseIndicesArrayView.GetEnumerator() : null)
            {
                var nextIndex = uint.MaxValue;
                if (sparseIndicesIter != null)
                {
                    sparseIndicesIter.MoveNext();
                    nextIndex = sparseIndicesIter.Current;
                }

                var sparseIndex = 0;
                for (int i = 0; i < Length; ++i)
                {
                    var v = default(T);

                    if (denseArrayView != null)
                    {
                        v = denseArrayView.ElementAt(i);
                    }

                    if (i == nextIndex)
                    {
                        v = sparseValuesArrayView.ElementAt(sparseIndex);
                        ++sparseIndex;

                        // Set uint.MaxValue when the iterator reached to end to prevent matching for condition.
                        nextIndex = sparseIndicesIter.MoveNext() ? sparseIndicesIter.Current : uint.MaxValue;
                    }

                    yield return(v);
                }
            }
        }
 /// <summary>
 /// Sets this sparse Gamma list to be a uniform distribution
 /// </summary>
 public void SetToUniform()
 {
     CommonValue.SetToUniform();
     SparseValues.Clear();
 }