QPALM 1.0.0
Proximal Augmented Lagrangian method for Quadratic Programs
sparse.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Sparse> // Eigen::SparseMatrix
4#include <Eigen/src/Core/Map.h> // Eigen::Map
5#include <Eigen/src/Core/Matrix.h> // Eigen::Matrix
6
7#include <global_opts.h> // c_float
8#include <ladel_constants.h> // UNSYMMETRIC
9#include <ladel_types.h> // ladel_sparse_matrix
10
11#include <memory> // unique_ptr
12
13#include <qpalm_cxx-export.hpp>
14
15namespace qpalm {
16
17/// Index types for vectors and matrices.
18using index_t = Eigen::Index;
19/// Index type for sparse matrices representation.
20using sp_index_t = ladel_int;
21/// Owning sparse matrix type.
22using sparse_mat_t = Eigen::SparseMatrix<c_float, Eigen::ColMajor, sp_index_t>;
23/// Read-only view on a sparse matrix.
24using sparse_mat_view_t = Eigen::Map<const sparse_mat_t>;
25/// Type for (row, column, value) triplets for initializing sparse matrices.
26using triplet_t = Eigen::Triplet<c_float, sp_index_t>;
27/// Owning dense vector type.
28using vec_t = Eigen::Matrix<c_float, Eigen::Dynamic, 1>;
29/// Borrowed dense vector type (vector view).
30using borrowed_vec_t = Eigen::Map<vec_t>;
31/// Read-only borrowed dense vector type (vector view).
32using const_borrowed_vec_t = Eigen::Map<const vec_t>;
33/// Reference to a dense vector (vector view).
34using ref_vec_t = Eigen::Ref<vec_t>;
35/// Read-only reference to a dense vector (vector view).
36using const_ref_vec_t = Eigen::Ref<const vec_t>;
37
38namespace alloc {
40 QPALM_CXX_EXPORT void operator()(ladel_sparse_matrix *) const;
41};
42} // namespace alloc
43
44/// Smart pointer that automatically cleans up an owning ladel_sparse_matrix
45/// object.
47 std::unique_ptr<ladel_sparse_matrix, alloc::ladel_sparse_matrix_deleter>;
48
49/// Convert an Eigen sparse matrix to a LADEL sparse matrix, without creating
50/// a copy.
51/// @note The returned object contains pointers to the data of @p mat, so do
52/// not reallocate or deallocate using the @c ladel_sparse_free
53/// and similar functions. Modifications of the returned LADEL matrix
54/// will affect the original Eigen matrix, so make sure that the
55/// representation remains consistent.
56QPALM_CXX_EXPORT ladel_sparse_matrix eigen_to_ladel(sparse_mat_t &mat,
57 ladel_int symmetry = UNSYMMETRIC);
58
59/// Similar to @ref eigen_to_ladel, but creates a copy of all data, in such a
60/// way that the returned matrix is completely decoupled from @p mat, and such
61/// that it can be reallocated and deallocated by the @c ladel_sparse_free
62/// and similar functions.
64
65} // namespace qpalm
Custom memory allocation, print and utility functions, and data types for floats and ints.
Definition: qpalm.hpp:18
Eigen::Matrix< c_float, Eigen::Dynamic, 1 > vec_t
Owning dense vector type.
Definition: sparse.hpp:28
Eigen::Ref< const vec_t > const_ref_vec_t
Read-only reference to a dense vector (vector view).
Definition: sparse.hpp:36
Eigen::Map< const sparse_mat_t > sparse_mat_view_t
Read-only view on a sparse matrix.
Definition: sparse.hpp:24
ladel_int sp_index_t
Index type for sparse matrices representation.
Definition: sparse.hpp:20
std::unique_ptr< ladel_sparse_matrix, alloc::ladel_sparse_matrix_deleter > ladel_sparse_matrix_ptr
Smart pointer that automatically cleans up an owning ladel_sparse_matrix object.
Definition: sparse.hpp:47
QPALM_CXX_EXPORT ladel_sparse_matrix eigen_to_ladel(sparse_mat_t &mat, ladel_int symmetry=UNSYMMETRIC)
Convert an Eigen sparse matrix to a LADEL sparse matrix, without creating a copy.
Definition: sparse.cpp:9
Eigen::Index index_t
Index types for vectors and matrices.
Definition: sparse.hpp:18
Eigen::Map< vec_t > borrowed_vec_t
Borrowed dense vector type (vector view).
Definition: sparse.hpp:30
Eigen::Ref< vec_t > ref_vec_t
Reference to a dense vector (vector view).
Definition: sparse.hpp:34
Eigen::SparseMatrix< c_float, Eigen::ColMajor, sp_index_t > sparse_mat_t
Owning sparse matrix type.
Definition: sparse.hpp:22
Eigen::Map< const vec_t > const_borrowed_vec_t
Read-only borrowed dense vector type (vector view).
Definition: sparse.hpp:32
Eigen::Triplet< c_float, sp_index_t > triplet_t
Type for (row, column, value) triplets for initializing sparse matrices.
Definition: sparse.hpp:26
QPALM_CXX_EXPORT ladel_sparse_matrix_ptr eigen_to_ladel_copy(const sparse_mat_t &mat)
Similar to eigen_to_ladel, but creates a copy of all data, in such a way that the returned matrix is ...
Definition: sparse.cpp:29
#define QPALM_CXX_EXPORT
QPALM_CXX_EXPORT void operator()(ladel_sparse_matrix *) const
Definition: sparse.cpp:24