From fe6523f9e1bf509f1283ae28dda0166649c0c225 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 23 Apr 2024 11:56:37 +0100 Subject: [PATCH] Get the C++ side in place --- .../include/CGAL/Accelerate_solver_traits.h | 53 +++++++++++++ .../include/CGAL/Accelerate_vector.h | 76 +++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 Solver_interface/include/CGAL/Accelerate_solver_traits.h create mode 100644 Solver_interface/include/CGAL/Accelerate_vector.h diff --git a/Solver_interface/include/CGAL/Accelerate_solver_traits.h b/Solver_interface/include/CGAL/Accelerate_solver_traits.h new file mode 100644 index 000000000000..b33f10630a8a --- /dev/null +++ b/Solver_interface/include/CGAL/Accelerate_solver_traits.h @@ -0,0 +1,53 @@ + +// Copyright (c) 2024 GeometryFactory SARL (France), All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_ACCELERATE_SOLVER_TRAIS_H +#define CGAL_ACCELERATE_SOLVER_TRAIS_H + + +#include +#include + +namespace CGAL { + +/*! + \ingroup PkgSolverInterfaceLS + + The class `Accelerate_solver_traits` provides an interface to the sparse solvers of +*/ +template +class Accelerate_solver_traits +{ +public: + using NT = T; + using Matrix = Accelerate_sparse_matrix; + using Vector = Accelerate_vector; + + Accelerate_solver_traits() + {} + + /// Solve the sparse linear system \f$ A \times X = B \f$. + /// Return `true` on success. The solution is then \f$ (1/D) \times X \f$. + /// + /// \pre A.row_dimension() == B.dimension(). + /// \pre A.column_dimension() == X.dimension(). + bool linear_solver(const Matrix& A, const Vector& B, Vector& X, NT& D) + { + D = 1; // Accelerate does not support homogeneous coordinates + return true; + } + + }; + +} // namespace CGAL + + +#endif // ACCELERATE_SOLVER_TRAITS diff --git a/Solver_interface/include/CGAL/Accelerate_vector.h b/Solver_interface/include/CGAL/Accelerate_vector.h new file mode 100644 index 000000000000..643d599d38f4 --- /dev/null +++ b/Solver_interface/include/CGAL/Accelerate_vector.h @@ -0,0 +1,76 @@ +// Copyright (c) 2024 GeometryFactory SARL (France), All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_ACCELERATE_VECTOR_H +#define CGAL_ACCELERATE_VECTOR_H + + +namespace CGAL { +/*! +\ingroup PkgSolverInterfaceLS + +The class `Accelerate_vector` is a vector of numbers. + +\cgalModels{SvdTraits::Vector,SparseLinearAlgebraTraits_d::Vector} + +\tparam T Number type. Must be `double` or `float` + +\sa `CGAL::Accelerate_solver_traits` +\sa `CGAL::Accelerate_sparse_matrix` +*/ + +template +class Accelerate_vector + +{ +// Public types +public: + /// \name Types + /// @{ + typedef T NT; + + /// @} + +// Public operations +public: + + /// Constructs a null vector. + Accelerate_vector() = default; + + /// Create a vector initialized with zeros. + Accelerate_vector(std::size_t dimension) + : m_vec(dimension, NT(0)) + {} + + + /// Return the vector's number of coefficients. + int dimension() const { return static_cast(m_vec.size()); } + + NT operator[](int row) const + { + return m_vec[row]; + } + + + NT& operator[](int row) + { + return m_vec[row]; + } + + /// Return a pointer to the data array of this vector. + const NT* data() { return &m_vec[0]; } + +private: + std::vector m_vec; +}; + +} // namespace CGAL + +#endif // CGAL_ACCELERATE_VECTOR_H