     }
 }
 
+
+// TODO: there is a lot to fill in here ..
+// In theory there should be better ways of doing this. However, how Integer
+// protocols are defined, it doesn't look currently possible (though it looks
+// like proposals are in place to make this less painful)
+public func asType<S1:Storage, S2:Storage>(_ from:Tensor<S1>) -> Tensor<S2> where S1.ElementType == Int, S2.ElementType == Int {
+    let result = Tensor<S2>(from.shape)
+    for i in 0..<result.shape.elements {
+        result.storage[i] = Int(from.storage[i])
+    }
+    
+    return result
+}
+
+public func asType<S1:Storage, S2:Storage>(_ from:Tensor<S1>) -> Tensor<S2> where S1.ElementType == UInt8, S2.ElementType == Float {
+    let result = Tensor<S2>(from.shape)
+    for i in 0..<result.shape.elements {
+        result.storage[i] = Float(from.storage[i])
+    }
+    
+    return result
+}
+
 public func ones<S:Storage>(_ shape:Extent) -> Tensor<S> {
     return Tensor<S>(shape, value: S.ElementType(1))
 }

            }
        }
        
//        singletons = shape.map { Int($0 == 1) }
//        fixedDims = tensor.fixedDims
        
        self.fixedDims = [Int](repeating: -1, count: self.stride.count)
        
        dimIndex = storage.calculateOrder(shape.count)
        self.view = ViewType(shape: shape, offset: tensor.view.offset)
    }

    open func calculateOffset() -> Int {
        var pos = 0
        for i in 0..<shape.count {

    // convenience variable to access the shape of the view
    open var shape:Extent {
        get { return view.shape }
        
        // TODO: check, this may be a bad thing to do.. call reshape here? or get rid of.
        set {
            precondition(view.shape.elements == newValue.elements, "Number of elements must match")
            view.shape = newValue
