Integrate Refactor solver sources and dual MSVC CMake builds
This commit is contained in:
+14
-58
@@ -1,8 +1,5 @@
|
||||
#include "fesa/math/matrix.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <mkl.h>
|
||||
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
@@ -24,17 +21,6 @@ std::size_t CheckedStorageSize(const std::size_t rows,
|
||||
return rows * columns;
|
||||
}
|
||||
|
||||
/// @brief Preserves the Matrix exception contract around private size
|
||||
/// conversion.
|
||||
MKL_INT MklSizeOrThrow(const std::size_t size) {
|
||||
const auto converted = dense_blas_internal::ToMklSize(size);
|
||||
if (!converted.HasValue()) {
|
||||
throw std::length_error{
|
||||
"Dense matrix dimension exceeds the MKL integer range."};
|
||||
}
|
||||
return converted.Value();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Matrix::Matrix(const std::size_t rows, const std::size_t columns,
|
||||
@@ -88,6 +74,18 @@ std::size_t Matrix::Rows() const noexcept { return rows_; }
|
||||
|
||||
std::size_t Matrix::Columns() const noexcept { return columns_; }
|
||||
|
||||
double* Matrix::Data() noexcept { return values_.data(); }
|
||||
|
||||
const double* Matrix::Data() const noexcept { return values_.data(); }
|
||||
|
||||
double Matrix::Norm() const {
|
||||
return dense_blas_internal::NormValues(Data(), values_.size());
|
||||
}
|
||||
|
||||
void Matrix::Scale(const double alpha) {
|
||||
dense_blas_internal::ScaleValues(alpha, Data(), values_.size());
|
||||
}
|
||||
|
||||
double& Matrix::operator()(const std::size_t row, const std::size_t column) {
|
||||
if (row >= rows_ || column >= columns_) {
|
||||
throw std::out_of_range{"Matrix index is outside its dimensions."};
|
||||
@@ -104,53 +102,11 @@ const double& Matrix::operator()(const std::size_t row,
|
||||
}
|
||||
|
||||
Vector Matrix::Multiply(const Vector& rhs) const {
|
||||
if (columns_ != rhs.Size()) {
|
||||
throw std::invalid_argument{
|
||||
"Matrix-vector multiplication has incompatible dimensions."};
|
||||
}
|
||||
for (const double value : values_)
|
||||
if (!std::isfinite(value))
|
||||
throw std::invalid_argument{"Matrix product inputs must be finite."};
|
||||
for (std::size_t i = 0; i < rhs.Size(); ++i)
|
||||
if (!std::isfinite(rhs.Data()[i]))
|
||||
throw std::invalid_argument{"Matrix product inputs must be finite."};
|
||||
|
||||
Vector result{rows_};
|
||||
if (rows_ == 0 || columns_ == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// The owned layout is row-major, so the leading dimension is the column
|
||||
// count for the adapter call and remains invisible to public consumers.
|
||||
cblas_dgemv(CblasRowMajor, CblasNoTrans, MklSizeOrThrow(rows_),
|
||||
MklSizeOrThrow(columns_), 1.0, values_.data(),
|
||||
MklSizeOrThrow(columns_), rhs.Data(), 1, 0.0, result.Data(), 1);
|
||||
return result;
|
||||
return dense_blas_internal::Multiply(*this, rhs);
|
||||
}
|
||||
|
||||
Matrix Matrix::Multiply(const Matrix& rhs) const {
|
||||
if (columns_ != rhs.rows_) {
|
||||
throw std::invalid_argument{
|
||||
"Matrix multiplication has incompatible dimensions."};
|
||||
}
|
||||
for (const double value : values_)
|
||||
if (!std::isfinite(value))
|
||||
throw std::invalid_argument{"Matrix product inputs must be finite."};
|
||||
for (const double value : rhs.values_)
|
||||
if (!std::isfinite(value))
|
||||
throw std::invalid_argument{"Matrix product inputs must be finite."};
|
||||
|
||||
Matrix result{rows_, rhs.columns_};
|
||||
if (rows_ == 0 || columns_ == 0 || rhs.columns_ == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, MklSizeOrThrow(rows_),
|
||||
MklSizeOrThrow(rhs.columns_), MklSizeOrThrow(columns_), 1.0,
|
||||
values_.data(), MklSizeOrThrow(columns_), rhs.values_.data(),
|
||||
MklSizeOrThrow(rhs.columns_), 0.0, result.values_.data(),
|
||||
MklSizeOrThrow(rhs.columns_));
|
||||
return result;
|
||||
return dense_blas_internal::Multiply(*this, rhs);
|
||||
}
|
||||
|
||||
} // namespace fesa
|
||||
|
||||
Reference in New Issue
Block a user