csc_matrix_conv.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2021 The Autoware Foundation
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef OSQP_INTERFACE__CSC_MATRIX_CONV_HPP_
  15. #define OSQP_INTERFACE__CSC_MATRIX_CONV_HPP_
  16. #include "osqp/glob_opts.h" // for 'c_int' type ('long' or 'long long')
  17. #include "osqp_interface/visibility_control.hpp"
  18. #include <Eigen/Core>
  19. #include <vector>
  20. namespace autoware
  21. {
  22. namespace common
  23. {
  24. namespace osqp
  25. {
  26. /// \brief Compressed-Column-Sparse Matrix
  27. struct OSQP_INTERFACE_PUBLIC CSC_Matrix
  28. {
  29. /// Vector of non-zero values. Ex: [4,1,1,2]
  30. std::vector<c_float> m_vals;
  31. /// Vector of row index corresponding to values. Ex: [0, 1, 0, 1] (Eigen: 'inner')
  32. std::vector<c_int> m_row_idxs;
  33. /// Vector of 'val' indices where each column starts. Ex: [0, 2, 4] (Eigen: 'outer')
  34. std::vector<c_int> m_col_idxs;
  35. };
  36. /// \brief Calculate CSC matrix from Eigen matrix
  37. OSQP_INTERFACE_PUBLIC CSC_Matrix calCSCMatrix(const Eigen::MatrixXd & mat);
  38. /// \brief Calculate upper trapezoidal CSC matrix from square Eigen matrix
  39. OSQP_INTERFACE_PUBLIC CSC_Matrix calCSCMatrixTrapezoidal(const Eigen::MatrixXd & mat);
  40. /// \brief Print the given CSC matrix to the standard output
  41. OSQP_INTERFACE_PUBLIC void printCSCMatrix(const CSC_Matrix & csc_mat);
  42. } // namespace osqp
  43. } // namespace common
  44. } // namespace autoware
  45. #endif // OSQP_INTERFACE__CSC_MATRIX_CONV_HPP_