예제 #1
0
bool operator==(const SquareMatrix &a, const SquareMatrix &b)
{
    if (a.dimensions() != b.dimensions())
    {
        return false;
    }

    size_t elementCount = a.elementCount();
    for (size_t i = 0; i < elementCount; ++i)
    {
        if (a.at(i) != b.at(i))
        {
            return false;
        }
    }
    return true;
}
예제 #2
0
SquareMatrix SquareMatrix::operator*(const SquareMatrix &other) const
{
    if (other.columns() != rows())
    {
        throw std::logic_error("SquareMatrix::operator*(): incompatible dimensions");
    }

    SquareMatrix m(mDimensions, false);
    for (size_t r = 0; r < rows(); ++r)
    {
        for (size_t c = 0; c < columns(); ++c)
        {
            int &v = m.at(r, c) = 0;
            for (size_t s = 0; s < rows(); ++s)
            {
                v += at(r, s) * other.at(s, c);
            }
        }
    }

    return m;
}