File indexing completed on 2026-06-02 08:17:12
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "apfel/matrix.h"
0010
0011 #include <map>
0012 #include <string>
0013 #include <iostream>
0014
0015 namespace apfel
0016 {
0017
0018
0019
0020
0021 class ConvolutionMap
0022 {
0023 public:
0024
0025
0026
0027 struct rule
0028 {
0029 int operand;
0030 int object;
0031 double coefficient;
0032 bool operator == (rule const& r) const
0033 {
0034 if (r.operand != operand) return false;
0035 if (r.object != object) return false;
0036 if (r.coefficient != coefficient) return false;
0037 return true;
0038 }
0039 rule& operator *= (double const& s)
0040 {
0041 coefficient *= s;
0042 return *this;
0043 }
0044 rule& operator /= (double const& s)
0045 {
0046 coefficient /= s;
0047 return *this;
0048 }
0049 };
0050
0051
0052
0053
0054
0055 ConvolutionMap(std::string const& name);
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 void SetRules(std::map<int, std::vector<rule>> const& rules) { _rules = rules; }
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 std::string const& GetName() const { return _name; }
0077
0078
0079
0080
0081
0082 std::map<int, std::vector<rule>> const& GetRules() const { return _rules; }
0083
0084
0085
0086
0087
0088 matrix<std::vector<double>> const GetRuleMatrix() const;
0089
0090
0091
0092
0093
0094
0095 matrix<std::vector<int>> const GetRuleIndices() const;
0096
0097
0098
0099
0100 void Print() const { std::cout << *this << std::endl; }
0101
0102 protected:
0103 std::map<int, std::vector<rule>> _rules;
0104 std::string _name;
0105
0106 friend std::ostream& operator << (std::ostream& os, ConvolutionMap const& cm);
0107 };
0108
0109
0110
0111
0112 std::ostream& operator << (std::ostream& os, ConvolutionMap const& cm);
0113
0114
0115
0116
0117
0118 ConvolutionMap::rule operator * (double const& s, ConvolutionMap::rule rhs);
0119 ConvolutionMap::rule operator * (ConvolutionMap::rule lhs, double const& s);
0120 ConvolutionMap::rule operator / (ConvolutionMap::rule lhs, double const& s);
0121 std::vector<ConvolutionMap::rule> operator + (std::vector<ConvolutionMap::rule> lhs, std::vector<ConvolutionMap::rule> rhs);
0122 std::vector<ConvolutionMap::rule> operator - (std::vector<ConvolutionMap::rule> lhs, std::vector<ConvolutionMap::rule> rhs);
0123 std::vector<ConvolutionMap::rule> operator * (double const& s, std::vector<ConvolutionMap::rule> lhs);
0124 std::vector<ConvolutionMap::rule> operator * (std::vector<ConvolutionMap::rule> lhs, double const& s);
0125 std::vector<ConvolutionMap::rule> operator / (std::vector<ConvolutionMap::rule> lhs, double const& s);
0126
0127 }