Matrix<double> Matrix<double>::Multiply(const Matrix<double>& m) const { if ( GetColumnLength() != m.GetRowLength() ) { Matrix<double> null; return null; } Matrix<double> multiplied(GetRowLength(), m.GetColumnLength()); #if 0 for (size_t row = 0; row < multiplied.GetRowLength(); ++row) { for (size_t col = 0; col < multiplied.GetColumnLength(); ++col) { double v = 0; for (size_t k = 0; k < GetColumnLength(); ++k) { v += (*this)[row][k] * m[k][col]; } multiplied[row][col] = v; } } #else Matrix<double> transposed(m.T()); for (size_t row = 0; row < multiplied.GetRowLength(); ++row) { for (size_t col = 0; col < multiplied.GetColumnLength(); ++col) { multiplied[row][col] = (*this)[row].Dot(transposed[col]); } } #endif return multiplied; }
/** @brief operator* * */ Vector2D Vector2D::operator*( const Vector2D& lhs, const float rhs ) { float x = lhs.underwater_vector[0] * rhs; float y = lhs.underwater_vector[1] * rhs; Vector2D multiplied( x, y ); return multiplied; }
void ImagePlaneWindow::onMemoryMultiplyClicked() { if(_memory != 0) { Image2DPtr multiplied(Image2D::MakePtr(*_memory)); Image2DCPtr old = _heatMapPlot.Image(); for(size_t y=0;y<multiplied->Height();++y) { for(size_t x=0;x<multiplied->Width();++x) { multiplied->SetValue(x, y, multiplied->Value(x, y) * old->Value(x, y)); } } _heatMapPlot.SetImage(std::move(multiplied)); _imageWidget.Update(); printStats(); } }
void RectangularMatrixTest::multiplyDivide() { Matrix2 matrix(Vector2(1.0f, 2.0f), Vector2(3.0f, 4.0f)); Matrix2 multiplied(Vector2(-1.5f, -3.0f), Vector2(-4.5f, -6.0f)); CORRADE_COMPARE(matrix*-1.5f, multiplied); CORRADE_COMPARE(-1.5f*matrix, multiplied); CORRADE_COMPARE(multiplied/-1.5f, matrix); Math::RectangularMatrix<1, 1, Byte> matrixChar(32); Math::RectangularMatrix<1, 1, Byte> multipliedChar(-48); CORRADE_COMPARE(matrixChar*-1.5f, multipliedChar); CORRADE_COMPARE(multipliedChar/-1.5f, matrixChar); CORRADE_COMPARE(-1.5f*matrixChar, multipliedChar); /* Divide vector with number and inverse */ Matrix2 divisor(Vector2( 1.0f, 2.0f), Vector2(-4.0f, 8.0f)); Matrix2 result(Vector2( 1.0f, 0.5f), Vector2(-0.25f, 0.125f)); CORRADE_COMPARE(1.0f/divisor, result); CORRADE_COMPARE(-1550.0f/multipliedChar, matrixChar); }