Exemple #1
0
        public MatrixF GetQuotient(float denominator)
        {
            var divided         = new MatrixF(Rows, Columns);
            var dividedElements = divided._elements;

#if HAS_CODECONTRACTS
            Assume(_elements.Length == dividedElements.Length);
#endif

            for (var elementIndex = 0; elementIndex < dividedElements.Length; elementIndex++)
            {
                dividedElements[elementIndex] = _elements[elementIndex] / denominator;
            }

            return(divided);
        }
Exemple #2
0
        public MatrixF GetScaled(float scalar)
        {
            var scaled         = new MatrixF(Rows, Columns);
            var scaledElements = scaled._elements;

#if HAS_CODECONTRACTS
            Assume(_elements.Length == scaledElements.Length);
#endif

            for (var elementIndex = 0; elementIndex < scaledElements.Length; elementIndex++)
            {
                scaledElements[elementIndex] = _elements[elementIndex] * scalar;
            }

            return(scaled);
        }
Exemple #3
0
        public MatrixF GetProduct(MatrixF right)
        {
            if (right == null)
            {
                throw new ArgumentNullException(nameof(right));
            }
            if (Columns != right.Rows)
            {
                throw new ArgumentOutOfRangeException(nameof(right));
            }

            var product = new MatrixF(Rows, right.Columns);

#if HAS_CODECONTRACTS
            Assume(Columns == right.Rows);
            Assume(product.Rows == Rows);
            Assume(product.Columns == right.Columns);
#endif

            var rightElements   = right._elements;
            var rightColumns    = right.Columns;
            var productElements = product._elements;

            for (var row = 0; row < product.Rows; row++)
            {
                var leftRowOffset    = Columns * row;
                var productRowOffset = product.Columns * row;

                for (var column = 0; column < product.Columns; column++)
                {
                    float sum = _elements[leftRowOffset] * rightElements[column];
                    for (var innerIndex = 1; innerIndex < Columns; innerIndex++)
                    {
                        sum += _elements[leftRowOffset + innerIndex] * rightElements[(rightColumns * innerIndex) + column];
                    }

                    productElements[productRowOffset + column] = sum;
                }
            }

            return(product);
        }