#ifndef FESA_SRC_FESA_MATH_DENSE_BLAS_INTERNAL_H_ #define FESA_SRC_FESA_MATH_DENSE_BLAS_INTERNAL_H_ #include #include #include "fesa/core/status.h" #include "fesa/math/matrix.h" #include "fesa/math/vector.h" namespace fesa::dense_blas_internal { /// @brief Limits only default-policy one-equation backend calls to one thread. /// @note Existing caller TLS overrides are retained. Destruction restores the /// default request; process-wide MKL/OpenMP settings are never changed. class ScopedSingleEquationThreads { public: explicit ScopedSingleEquationThreads(std::size_t equation_count) noexcept; ScopedSingleEquationThreads(const ScopedSingleEquationThreads&) = delete; ScopedSingleEquationThreads& operator=(const ScopedSingleEquationThreads&) = delete; ~ScopedSingleEquationThreads(); private: bool restore_default_{false}; }; /// @brief Converts a dense storage length to the private MKL integer type. /// @return The converted length or an uncategorized overflow failure. Result ToMklSize(std::size_t size); /// @brief Computes left-transpose times right through ordinary dense MKL. /// @throws std::invalid_argument for mismatched rows or nonfinite operands. Matrix MultiplyTransposeLeft(const Matrix& left, const Matrix& right); /// @brief Multiplies a compact diagonal matrix by a vector through MKL. /// @throws std::invalid_argument if shapes differ or inputs are nonfinite. /// @throws std::length_error if the size exceeds the backend integer range. Vector MultiplyDiagonal(const Vector& diagonal, const Vector& rhs); /// @brief Computes a lower Cholesky factor and its inverse with MKL LAPACK. /// @return False for a nonpositive pivot or nonfinite factor/inverse. /// @note Outputs are replaced only after both finite candidates succeed. /// @throws std::invalid_argument for a nonsquare or nonfinite input. /// @throws std::length_error for a backend size overflow. bool CholeskyLowerAndInverse(const Matrix& matrix, Matrix& lower, Matrix& inverse_lower); /// @brief Copies contiguous double values through the private BLAS backend. /// @param source Readable storage for size values when size is nonzero. /// @param size Number of contiguous values to copy. /// @param destination Writable storage for size values when size is nonzero. /// @throws std::length_error if size exceeds the MKL integer range. /// @note A zero-length copy accepts null pointers and does not call BLAS. void CopyValues(const double* source, std::size_t size, double* destination); } // namespace fesa::dense_blas_internal #endif // FESA_SRC_FESA_MATH_DENSE_BLAS_INTERNAL_H_