Index: branches/3040_VectorBasedGP/HeuristicLab.MathNet.Numerics/VectorTransformer.cs
===================================================================
--- branches/3040_VectorBasedGP/HeuristicLab.MathNet.Numerics/VectorTransformer.cs	(revision 17449)
+++ branches/3040_VectorBasedGP/HeuristicLab.MathNet.Numerics/VectorTransformer.cs	(revision 17452)
@@ -35,7 +35,9 @@
   #region Vector Transformer
   public abstract class VectorTransformer<T> : BoxTransformer<Vector<T>> where T : struct, IEquatable<T>, IFormattable {
+
     public override bool CanTransformType(Type type) {
       return typeof(Vector<T>).IsAssignableFrom(type);
     }
+
     public override Box CreateBox(object o, Mapper mapper) {
       var box = base.CreateBox(o, mapper);
@@ -43,8 +45,10 @@
       return box;
     }
+
     protected override void Populate(Box box, Vector<T> vector, Mapper mapper) {
       var storageId = mapper.GetBoxId(vector.Storage);
       box.Value.ULong = storageId;
     }
+
     protected override Vector<T> Extract(Box box, Type type, Mapper mapper) {
       var storageId = (uint)box.Value.ULong;
@@ -53,4 +57,7 @@
     }
   }
+
+  [Transformer("76A21F63-36B4-4073-ABBC-56623ECBF42E", 400)]
+  public class DoubleVectorTransformer : VectorTransformer<double> { }
 
   [Transformer("78276F91-D075-4472-B81B-3A736184CC22", 400)]
@@ -62,65 +69,9 @@
   [Transformer("2D978104-A174-4AE2-AEA1-20FD50CADF0D", 400)]
   public class Complex32VectorTransformer : VectorTransformer<Complex32> { }
-
-  [Transformer("76A21F63-36B4-4073-ABBC-56623ECBF42E", 400)]
-  public class DoubleVectorTransformer : VectorTransformer<double> { }
   #endregion
 
   #region Dense Vector Storage Transformer
-  [Transformer("CA28BA16-2C95-4270-9A04-3502D492F070", 200)]
-  public class DenseDoubleVectorStorageTransformer : BoxTransformer<DenseVectorStorage<double>> {
-    public override Box CreateBox(object o, Mapper mapper) {
-      var box = base.CreateBox(o, mapper);
-      box.Values = new RepeatedValueBox() {
-        Doubles = new RepeatedDoubleBox()
-      };
-      return box;
-    }
-    protected override void Populate(Box box, DenseVectorStorage<double> storage, Mapper mapper) {
-      box.Values.Doubles.Values.AddRange(storage.Data);
-    }
-    protected override DenseVectorStorage<double> Extract(Box box, Type type, Mapper mapper) {
-      var data = box.Values.Doubles.Values;
-      return DenseVectorStorage<double>.OfEnumerable(data);
-    }
-  }
-  #endregion
+  public abstract class DenseVectorStorageTransformer<T> : BoxTransformer<DenseVectorStorage<T>> where T : struct, IEquatable<T>, IFormattable {
 
-  #region Sparse Vector Storage Transformer
-  [Transformer("25FDFB3B-5849-44F6-81AC-3D16CB093ADE", 200)]
-  public class SparseDoubleVectorStorageTransformer : BoxTransformer<SparseVectorStorage<double>> {
-    public override Box CreateBox(object o, Mapper mapper) {
-      var box = base.CreateBox(o, mapper);
-      box.Value = new ScalarValueBox();
-      box.Values = new RepeatedValueBox() {
-        Doubles = new RepeatedDoubleBox(),
-        Ints = new RepeatedIntBox()
-      };
-      return box;
-    }
-    protected override void Populate(Box box, SparseVectorStorage<double> storage, Mapper mapper) {
-      box.Value.Long = storage.ValueCount;
-      box.Values.Doubles.Values.AddRange(storage.Values);
-      box.Values.Ints.Values.AddRange(storage.Indices);
-    }
-    protected override SparseVectorStorage<double> Extract(Box box, Type type, Mapper mapper) {
-      int valueCount = (int)box.Value.Long;
-      var values = box.Values.Doubles.Values;
-      var indices = box.Values.Ints.Values;
-      var data = indices.Zip(values, Tuple.Create);
-      return SparseVectorStorage<double>.OfIndexedEnumerable(valueCount, data);
-    }
-  }
-  #endregion
-
-
-
-  [Transformer("45EFC879-241D-404F-BCC1-341A41F6AB90", 1000)]
-  public class DataContractTransformer : BoxTransformer<object> {
-    private readonly DataContractSerializer serializer = new DataContractSerializer(typeof(DenseVectorStorage<>));
-    public override bool CanTransformType(Type type) {
-      return Attribute.GetCustomAttribute(type, typeof(SerializableAttribute)) != null &&
-             Attribute.GetCustomAttribute(type, typeof(DataContractAttribute)) != null;
-    }
     public override Box CreateBox(object o, Mapper mapper) {
       var box = base.CreateBox(o, mapper);
@@ -128,19 +79,79 @@
       return box;
     }
-    protected override void Populate(Box box, object o, Mapper mapper) {
-      using (var stream = new MemoryStream()) {
-        serializer.WriteObject(stream, o);
-        var data = stream.ToArray();
-        box.Value.Bytes = ByteString.CopyFrom(data);
-      }
+
+    protected override void Populate(Box box, DenseVectorStorage<T> storage, Mapper mapper) {
+      var dataId = mapper.GetBoxId(storage.Data);
+      box.Value.ULong = dataId;
     }
-    protected override object Extract(Box box, Type type, Mapper mapper) {
-      var data = box.Value.Bytes.ToByteArray();
-      using (var stream = new MemoryStream()) {
-        stream.Write(data, 0, data.Length);
-        stream.Seek(0, SeekOrigin.Begin);
-        return serializer.ReadObject(stream);
-      }
+
+    protected override DenseVectorStorage<T> Extract(Box box, Type type, Mapper mapper) {
+      var dataId = (uint)box.Value.ULong;
+      var data = (T[])mapper.GetObject(dataId);
+      return DenseVectorStorage<T>.OfEnumerable(data);
+    }
+
+    public override void FillFromBox(object obj, Box box, Mapper mapper) {
+      var storage = (DenseVectorStorage<T>)obj;
+      var dataId = (uint)box.Value.ULong;
+      var data = (T[])mapper.GetObject(dataId);
+      Array.Copy(data, storage.Data, data.Length);
     }
   }
+
+  [Transformer("24705F16-FDB8-487A-ABEA-F69D58B50D60", 200)]
+  public class DoubleDenseVectorStorageTransform : DenseVectorStorageTransformer<double> { }
+
+  [Transformer("87FBC62F-E8A0-4C50-9289-CAD2B7F448E4", 200)]
+  public class SingleDenseVectorStorageTransform : DenseVectorStorageTransformer<float> { }
+
+  [Transformer("4391F230-2C0C-4876-B2EF-DE43197F4557", 200)]
+  public class ComplexDenseVectorStorageTransform : DenseVectorStorageTransformer<Complex> { }
+
+  [Transformer("6E07F8A9-DF19-4A2F-B7A3-209917B58355", 200)]
+  public class Complex32DenseVectorStorageTransform : DenseVectorStorageTransformer<Complex32> { }
+  #endregion
+
+  #region Sparse Vector Storage Transformer
+  public abstract class SparseVectorStorageTransformer<T> : BoxTransformer<SparseVectorStorage<T>> where T : struct, IEquatable<T>, IFormattable {
+
+    public override Box CreateBox(object o, Mapper mapper) {
+      var box = base.CreateBox(o, mapper);
+      box.Values = new RepeatedValueBox() {
+        UInts = new RepeatedUIntBox()
+      };
+      return box;
+    }
+
+    protected override void Populate(Box box, SparseVectorStorage<T> storage, Mapper mapper) {
+      var valueCount = storage.ValueCount;
+      var valuesId = mapper.GetBoxId(storage.Values);
+      var indicesId = mapper.GetBoxId(storage.Indices);
+      box.Values.UInts.Values.AddRange(new[] { (uint)valueCount, valuesId, indicesId });
+    }
+
+    protected override SparseVectorStorage<T> Extract(Box box, Type type, Mapper mapper) {
+      var boxValues = box.Values.UInts.Values;
+      int valueCount = (int)boxValues[0];
+      uint valuesId = boxValues[1];
+      uint indicesId = boxValues[2];
+      var values = (T[])mapper.GetObject(valuesId);
+      var indices = (int[])mapper.GetObject(indicesId);
+
+      var data = indices.Zip(values, Tuple.Create);
+      return SparseVectorStorage<T>.OfIndexedEnumerable(valueCount, data);
+    }
+  }
+
+  [Transformer("AC9ACF75-7E50-460F-B81A-57D7269548AE", 200)]
+  public class DoubleSparseVectorStorageTransform : SparseVectorStorageTransformer<double> { }
+
+  [Transformer("28BD551A-ACF1-48D0-B83F-C328902C8AB1", 200)]
+  public class SingleSparseVectorStorageTransform : SparseVectorStorageTransformer<float> { }
+
+  [Transformer("B3CF9306-8359-4DEF-B68C-83F1D936A86F", 200)]
+  public class ComplexSparseVectorStorageTransform : SparseVectorStorageTransformer<Complex> { }
+
+  [Transformer("57674C51-02BC-44D2-81C5-D8F5F6322C87", 200)]
+  public class Complex32SparseVectorStorageTransform : SparseVectorStorageTransformer<Complex32> { }
+  #endregion
 }
