DiSMEC++
reorder.cpp
Go to the documentation of this file.
1 // Copyright (c) 2021, Aalto University, developed by Erik Schultheis
2 // All rights reserved.
3 //
4 // SPDX-License-Identifier: MIT
5 
6 #include <utility>
8 #include "data/types.h"
9 
10 namespace dismec::postproc {
11  class ReorderPostProc : public PostProcessor {
12  public:
13  ReorderPostProc(const std::shared_ptr<objective::Objective>& objective,
14  Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, int> order) : m_Ordering(std::move(order)) {
15  }
16 
17  void process(label_id_t label_id, Eigen::Ref<DenseRealVector> weight_vector, solvers::MinimizationResult& result) override {
18  weight_vector.applyOnTheLeft(m_Ordering);
19  }
20  private:
21  Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, int> m_Ordering;
22  };
23 }
24 
25 std::shared_ptr<dismec::postproc::PostProcessFactory> dismec::postproc::create_reordering(Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, int> ordering) {
26  return std::make_shared<GenericPostProcFactory<ReorderPostProc, Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, int>>>(ordering);
27 }
Strong typedef for an int to signify a label id.
Definition: types.h:20
Eigen::PermutationMatrix< Eigen::Dynamic, Eigen::Dynamic, int > m_Ordering
Definition: reorder.cpp:21
ReorderPostProc(const std::shared_ptr< objective::Objective > &objective, Eigen::PermutationMatrix< Eigen::Dynamic, Eigen::Dynamic, int > order)
Definition: reorder.cpp:13
void process(label_id_t label_id, Eigen::Ref< DenseRealVector > weight_vector, solvers::MinimizationResult &result) override
Apply post-processing for the weight_vector corresponding to the label label_id.
Definition: reorder.cpp:17
FactoryPtr create_reordering(Eigen::PermutationMatrix< Eigen::Dynamic, Eigen::Dynamic, int > ordering)
Definition: reorder.cpp:25