     }
 
     public mutating func assign(_ sourceElements: DeviceArray<Element>, multipliedBy alpha: Element) {
+        let count = Swift.min(self.count, sourceElements.count)
         let scale = kernelManager.kernel(.scale, forType: Element.self)
         let blockSize = Swift.min(512, count)
         let blockCount = (count+blockSize-1)/blockSize


    public mutating func assignElementwiseResult(of operation: DeviceBinaryOperation,
                                                 x: DeviceArray<Element>, y: DeviceArray<Element>) {
        precondition(count == x.count && count == y.count, "Array count mismatch")
        let elementOp = kernelManager.kernel(.elementwise, operation: operation, forType: Element.self)
        let blockSize = Swift.min(512, count)
        let blockCount = (count+blockSize-1)/blockSize

    }

    public mutating func assign(_ sourceElements: DeviceArray<Element>) {
        let count = Swift.min(self.count, sourceElements.count)
        let copy = kernelManager.kernel(.copy, forType: Element.self)
        let blockSize = Swift.min(512, count)
        let blockCount = (count+blockSize-1)/blockSize
