소스 검색

Adds the ability to store arbitrary stl containers in output file. Adds visualization of Generator-Level objects using graphviz

Caleb Fangmeier 8 년 전
부모
커밋
88fc658241
3개의 변경된 파일24개의 추가작업 그리고 29개의 파일을 삭제
  1. 2 2
      api.hpp
  2. 6 23
      container.hpp
  3. 16 4
      value.hpp

+ 2 - 2
api.hpp

@@ -39,9 +39,9 @@ namespace fv{
     }
 
     template <typename Ret, typename... ArgTypes>
-    MapOver<Ret(ArgTypes...)>* map_over(Function<Ret(ArgTypes...)>& fn,
+    Map<Ret(ArgTypes...)>* map(Function<Ret(ArgTypes...)>& fn,
                                         Zip<ArgTypes...>* arg, const std::string& alias=""){
-        return new MapOver<Ret(ArgTypes...)>(fn, arg, alias);
+        return new Map<Ret(ArgTypes...)>(fn, arg, alias);
     }
 
     template <typename T>

+ 6 - 23
container.hpp

@@ -7,14 +7,19 @@
 #include "value.hpp"
 #include "filter.hpp"
 
+template class std::vector<std::vector<float> >;
+template class std::vector<std::vector<int> >;
+
 namespace fv::util{
-std::string& get_type_name(const std::type_index& index){
+std::string get_type_name(const std::type_index& index){
     std::map<std::type_index, std::string> _map;
     // Add to this list as needed :)
     _map[typeid(int)]="int";
     _map[typeid(unsigned int)]="unsigned int";
     _map[typeid(float)]="float";
     _map[typeid(double)]="double";
+    _map[typeid(std::vector<int>)]="std::vector<int>";
+    _map[typeid(std::vector<float>)]="std::vector<float>";
 
     if (_map[index] == ""){
         CRITICAL("Cannot lookup type name of \"" << index.name() << "\"",-1);
@@ -83,28 +88,6 @@ class Container : public GenContainer{
 
 };
 
-template <typename T>
-class ContainerVector : public Container<std::vector<T> >{
-    private:
-        Value<T>* value;
-
-        void _fill(){
-            this->container->push_back(value->get_value());
-        }
-    public:
-        ContainerVector(const std::string& name, std::vector<T> *container, Value<T>* value)
-          :Container<std::vector<T> >(name, container),
-           value(value){ }
-        ContainerVector(const std::string& name, Value<T>* value)
-          :Container<std::vector<T> >(name, nullptr),
-           value(value){
-            this->container = new std::vector<T>();
-        }
-        void save_as(const std::string& fname) {
-            WARNING("Saving of ContainerVector objects not supported");
-        }
-};
-
 template <typename T>
 class ContainerMean : public Container<T>{
     private:

+ 16 - 4
value.hpp

@@ -523,7 +523,19 @@ class _Zip<Head, Tail...> : private _Zip<Tail...> {
 };
 
 /**
- * Zips a series of observations together
+ * Zips a series of vectors together. Can be combined with Map to
+ * yield a Value whose elements are individually a function of the
+ * corresponding elements of the vectors that were zipped together. For those
+ * familiar with python, it accompilishes the same thing as
+ * @code{.py}
+ * xs = [1,2,3,4]
+ * ys = [10,20,30,40]
+ * print(list(map(lambda t:t[0]+t[1],zip(xs,ys))))
+ * @endcode
+ * which outputs
+ * @code
+ * [11, 22, 33, 44]
+ * @endcode
  */
 template <typename... ArgTypes>
 class Zip : public DerivedValue<std::vector<std::tuple<ArgTypes...>>>,
@@ -549,9 +561,9 @@ class Zip : public DerivedValue<std::vector<std::tuple<ArgTypes...>>>,
         }
 };
 
-template<typename> class MapOver; // undefined
+template<typename> class Map; // undefined
 template <typename Ret, typename... ArgTypes>
-class MapOver<Ret(ArgTypes...)> : public DerivedValue<std::vector<Ret>>{
+class Map<Ret(ArgTypes...)> : public DerivedValue<std::vector<Ret>>{
     private:
         Function<Ret(ArgTypes...)>& fn;
         Zip<ArgTypes...>* arg;
@@ -564,7 +576,7 @@ class MapOver<Ret(ArgTypes...)> : public DerivedValue<std::vector<Ret>>{
         }
 
     public:
-        MapOver(Function<Ret(ArgTypes...)>& fn, Zip<ArgTypes...>* arg, const std::string& alias)
+        Map(Function<Ret(ArgTypes...)>& fn, Zip<ArgTypes...>* arg, const std::string& alias)
           :DerivedValue<std::vector<Ret>>("map_over("+fn.get_name()+":"+arg->get_name()+")", alias),
            fn(fn), arg(arg){ }