Cypress  1.0
C++ Spiking Neural Network Simulation Framework
transformation.hpp
Go to the documentation of this file.
1 /*
2  * Cypress -- C++ Spiking Neural Network Simulation Framework
3  * Copyright (C) 2016 Andreas Stöckel
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
35 #ifndef CYPRESS_CORE_TRANSFORMATION_HPP
36 #define CYPRESS_CORE_TRANSFORMATION_HPP
37 
38 #include <functional>
39 #include <memory>
40 #include <typeinfo>
41 #include <unordered_set>
42 #include <vector>
43 
44 #include <cypress/core/types.hpp>
45 
46 namespace cypress {
47 
48 // Forward declarations
49 class NeuronType;
50 class NetworkBase;
51 class Backend;
52 
53 template <typename T>
54 class Population;
55 
64  size_t cost = 100;
65 
71  bool lossy = false;
72 };
73 
83 };
84 
91 protected:
99  virtual NetworkBase do_transform(const NetworkBase &src,
100  TransformationAuxData &aux) = 0;
101 
109  virtual void do_copy_results(const NetworkBase &src,
110  NetworkBase &tar) const;
111 
112 public:
121  {
122  return TransformationProperties{};
123  }
124 
131  virtual std::string id() const = 0;
132 
141  NetworkBase transform(const NetworkBase &src, TransformationAuxData &aux);
142 
146  void copy_results(const NetworkBase &src, NetworkBase &tar) const;
147 
148  virtual ~Transformation(){};
149 };
150 
154 using TransformationCtor = std::function<std::unique_ptr<Transformation>()>;
155 
160 using TransformationTest =
161  std::function<bool(const Backend &, const NetworkBase &)>;
162 
168 
175 public:
181  static std::vector<TransformationCtor>
182  construct_neuron_type_transformation_chain(
183  const std::vector<const NeuronType *> &unsupported_types,
184  const std::unordered_set<const NeuronType *> &supported_types,
185  const std::vector<std::tuple<TransformationCtor, const NeuronType *,
186  const NeuronType *>> &transformations,
187  bool use_lossy);
188 
204  static void run(const Backend &backend, NetworkBase network,
205  const TransformationAuxData &aux,
206  std::unordered_set<std::string> disabled_trafo_ids =
207  std::unordered_set<std::string>(),
208  bool use_lossy = true);
209 
227  static RegisteredTransformation register_general_transformation(
228  TransformationCtor ctor, TransformationTest test);
229 
240  static RegisteredTransformation register_neuron_type_transformation(
241  TransformationCtor ctor, const NeuronType &src, const NeuronType &tar);
242 
243  template <typename SourceType, typename TargetType>
245  TransformationCtor ctor)
246  {
247  return register_neuron_type_transformation(ctor, SourceType::inst(),
248  TargetType::inst());
249  }
250 };
251 }
252 
253 #endif /* CYPRESS_CORE_TRANSFORMATION_HPP */
Definition: neurons_base.hpp:54
Definition: transformation.hpp:59
Definition: transformation.hpp:90
std::function< bool(const Backend &, const NetworkBase &)> TransformationTest
Definition: transformation.hpp:161
bool lossy
Definition: transformation.hpp:71
Definition: backend.hpp:50
Definition: transformation.hpp:174
Definition: transformation.hpp:77
virtual TransformationProperties properties() const
Definition: transformation.hpp:120
Real duration
Definition: transformation.hpp:82
double Real
Definition: types.hpp:56
Definition: network_base.hpp:116
size_t cost
Definition: transformation.hpp:64
Definition: brainscales_lib.hpp:39
std::function< std::unique_ptr< Transformation >()> TransformationCtor
Definition: transformation.hpp:154
size_t RegisteredTransformation
Definition: transformation.hpp:167
static RegisteredTransformation register_neuron_type_transformation(TransformationCtor ctor)
Definition: transformation.hpp:244
virtual ~Transformation()
Definition: transformation.hpp:148