Exemplo n.º 1
0
        /// <summary>
        ///     Transposes the matrix and stores the result in the output matrix
        /// </summary>
        /// <param name="output">The matrix in which the result will be stored.</param>
        public void Transpose([NotNull] MatrixF output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            if (this.Rows != output.Columns || this.Columns != output.Rows)
            {
                throw new ArgumentException(
                          $"The output matrix has the wrong size (Size: {output.Rows}x{output.Columns}, Required: {this.Columns}x{this.Rows}");
            }

            this.TransposeInternal(output);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Does the multiplication process, can assume that the preconditions are met.
        /// </summary>
        /// <param name="other">The other matrix.</param>
        /// <param name="output">The output matrix (Preinitialized).</param>
        protected virtual void MultiplyInternal([NotNull] MatrixF other, [NotNull] MatrixF output)
        {
            for (var i = 0; i < this.Rows; i++)
            {
                for (var j = 0; j < other.Columns; j++)
                {
                    float entry = 0;

                    for (int lr = 0; lr < this.Columns; lr++)
                    {
                        entry += this.GetAt(i, lr) * other.GetAt(lr, j);
                    }

                    output.SetAt(i, j, entry);
                }
            }
        }
Exemplo n.º 3
0
        public MatrixF Multiply([NotNull] MatrixF other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (this.Columns != other.Rows)
            {
                throw new ArgumentException(
                          $"The amount of columns of the left matrix mismatch the amount of rows of the right matrix. (left: {this.Columns}, right: {other.Rows})");
            }

            var result = MatrixFactory.ZeroF(this.Rows, other.Columns);

            this.MultiplyInternal(other, result);
            return(result);
        }