/// <summary>
        /// Checks equality of two containers
        /// </summary>
        /// <param name="other">Other container</param>
        /// <returns>True if data is equals</returns>
        public bool Equals(MatrixDataContainer <T> other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ColumnCount != other.ColumnCount || RowCount != other.RowCount)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            // Perform element wise comparison.
            for (var i = 0; i < RowCount; i++)
            {
                for (var j = 0; j < ColumnCount; j++)
                {
                    var item      = GetAt(i, j);
                    var otherItem = other.GetAt(i, j);
                    if (!item.Equals(otherItem))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
 /// <summary>
 /// Transposes data from current container to another
 /// </summary>
 /// <param name="target">Target container</param>
 internal virtual void TransposeTo(MatrixDataContainer <T> target)
 {
     for (var j = 0; j < ColumnCount; j++)
     {
         for (var i = 0; i < RowCount; i++)
         {
             target.SetAt(j, i, GetAt(i, j));
         }
     }
 }
 internal virtual void CopyToUnchecked(MatrixDataContainer <T> target)
 {
     for (var j = 0; j < ColumnCount; j++)
     {
         for (var i = 0; i < RowCount; i++)
         {
             target.SetAt(i, j, GetAt(i, j));
         }
     }
 }
        /// <summary>
        /// Copies all data from this container to another with
        /// range checking
        /// </summary>
        /// <param name="target">Target container</param>
        /// <exception cref="ArgumentNullException">If target is null</exception>
        /// <exception cref="ArgumentException">If dimensions of containers are not the same</exception>
        public void CopyTo(MatrixDataContainer <T> target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (ReferenceEquals(this, target))
            {
                return;
            }

            if (RowCount != target.RowCount || ColumnCount != target.ColumnCount)
            {
                var message = $"Matrix dimensions must be the same, first is ({RowCount} x {ColumnCount}), " +
                              $"second is ({target.RowCount} x {target.ColumnCount})";
                throw new ArgumentException(message, "target");
            }

            CopyToUnchecked(target);
        }
Пример #5
0
 protected Matrix(MatrixDataContainer <T> storage)
 {
     Storage     = storage;
     RowCount    = storage.RowCount;
     ColumnCount = storage.ColumnCount;
 }