Full Code of qoncept/TensorSwift for AI

master f4616d049b2d cached
55 files
12.4 MB
38.4k tokens
1 requests
Download .txt
Repository: qoncept/TensorSwift
Branch: master
Commit: f4616d049b2d
Files: 55
Total size: 12.4 MB

Directory structure:
gitextract_qun949lr/

├── .gitignore
├── LICENSE
├── Package.swift
├── README.md
├── Sources/
│   ├── MNIST/
│   │   ├── AppDelegate.swift
│   │   ├── Assets.xcassets/
│   │   │   └── AppIcon.appiconset/
│   │   │       └── Contents.json
│   │   ├── Base.lproj/
│   │   │   ├── LaunchScreen.storyboard
│   │   │   └── Main.storyboard
│   │   ├── Canvas.swift
│   │   ├── CanvasView.swift
│   │   ├── Classifier.swift
│   │   ├── Info.plist
│   │   ├── Line.swift
│   │   ├── Models/
│   │   │   ├── W_conv1
│   │   │   ├── W_conv2
│   │   │   ├── W_fc1
│   │   │   ├── W_fc2
│   │   │   ├── b_conv1
│   │   │   ├── b_conv2
│   │   │   ├── b_fc1
│   │   │   └── b_fc2
│   │   ├── String.swift
│   │   └── ViewController.swift
│   └── TensorSwift/
│       ├── Dimension.swift
│       ├── Info.plist
│       ├── Operators.swift
│       ├── Shape.swift
│       ├── Tensor.swift
│       ├── TensorMath.swift
│       ├── TensorNN.swift
│       ├── TensorSwift.h
│       └── Utils.swift
├── TensorSwift.podspec
├── TensorSwift.xcodeproj/
│   ├── Configs/
│   │   └── Project.xcconfig
│   ├── TensorSwiftTests_Info.plist
│   ├── TensorSwift_Info.plist
│   ├── project.pbxproj
│   └── project.xcworkspace/
│       └── contents.xcworkspacedata
└── Tests/
    ├── LinuxMain.swift
    ├── MNISTTests/
    │   ├── Array.swift
    │   ├── ClassifierTests.swift
    │   ├── Downloader.swift
    │   ├── DownloaderTests.swift
    │   ├── Info.plist
    │   ├── MNISTTests-Bridging-Header.h
    │   └── SHA1.swift
    └── TensorSwiftTests/
        ├── CalculationPerformanceTests.swift
        ├── DimensionTests.swift
        ├── Info.plist
        ├── PowerTests.swift
        ├── TensorMathTest.swift
        ├── TensorNNTests.swift
        ├── TensorSwiftSample.swift
        ├── TensorSwiftTests.swift
        └── TensorTests.swift

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# SwiftPackageManager
#
.build
/*.xcodeproj/xcshareddata/
/*.xcodeproj/project.xcworkspace/xcuserdata/
/*.xcodeproj/xcuserdata/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build


================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2016 Qoncept, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


================================================
FILE: Package.swift
================================================
// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "TensorSwift",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "TensorSwift",
            targets: ["TensorSwift"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "TensorSwift",
            dependencies: []),
        .testTarget(
            name: "TensorSwiftTests",
            dependencies: ["TensorSwift"]),
    ]
)


================================================
FILE: README.md
================================================
# TensorSwift

_TensorSwift_ is a lightweight library to calculate tensors, which has similar APIs to [_TensorFlow_](https://www.tensorflow.org/)'s. _TensorSwift_ is useful to simulate calculating tensors in Swift **using models trained by _TensorFlow_**.

```swift
let a = Tensor(shape: [2, 3], elements: [1, 2, 3, 4, 5, 6])
let b = Tensor(shape: [2, 3], elements: [7, 8, 9, 10, 11, 12])
let sum = a + b // Tensor(shape: [2, 3], elements: [8, 10, 12, 14, 16, 18])
let mul = a * b // Tensor(shape: [2, 3], elements: [7, 16, 27, 40, 55, 72])

let c = Tensor(shape: [3, 1], elements: [7, 8, 9])
let matmul = a.matmul(c) // Tensor(shape: [2, 1], elements: [50, 122])

let zeros = Tensor(shape: [2, 3, 4])
let ones = Tensor(shape: [2, 3, 4], element: 1)
```

## Deep MNIST for Experts

![deep-mnist.gif](Resources/DeepMnist.gif)

The following code shows how to simulate [Deep MNIST for Experts](https://www.tensorflow.org/versions/r0.8/tutorials/mnist/pros/index.html), a tutorial of _TensorFlow_, by _TensorSwift_.

```swift
public struct Classifier {
    public let W_conv1: Tensor
    public let b_conv1: Tensor
    public let W_conv2: Tensor
    public let b_conv2: Tensor
    public let W_fc1: Tensor
    public let b_fc1: Tensor
    public let W_fc2: Tensor
    public let b_fc2: Tensor
    
    public func classify(_ x_image: Tensor) -> Int {
        let h_conv1 = (x_image.conv2d(filter: W_conv1, strides: [1, 1, 1]) + b_conv1).relu()
        let h_pool1 = h_conv1.maxPool(kernelSize: [2, 2, 1], strides: [2, 2, 1])
        
        let h_conv2 = (h_pool1.conv2d(filter: W_conv2, strides: [1, 1, 1]) + b_conv2).relu()
        let h_pool2 = h_conv2.maxPool(kernelSize: [2, 2, 1], strides: [2, 2, 1])
        
        let h_pool2_flat = h_pool2.reshaped([1, Dimension(7 * 7 * 64)])
        let h_fc1 = (h_pool2_flat.matmul(W_fc1) + b_fc1).relu()
        
        let y_conv = (h_fc1.matmul(W_fc2) + b_fc2).softmax()

        return y_conv.elements.enumerated().max { $0.1 < $1.1 }!.0
    }
}
```

## Installation

### Swift Package Manager

```swift
.Package(url: "git@github.com:qoncept/TensorSwift.git", from: "0.2.0"),
```

### CocoaPods

```
pod 'TensorSwift', '~> 0.2'
```

### Carthage

```
github "qoncept/TensorSwift" ~> 0.2
```

## License

[The MIT License](LICENSE)



================================================
FILE: Sources/MNIST/AppDelegate.swift
================================================
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}



================================================
FILE: Sources/MNIST/Assets.xcassets/AppIcon.appiconset/Contents.json
================================================
{
  "images" : [
    {
      "idiom" : "iphone",
      "size" : "29x29",
      "scale" : "2x"
    },
    {
      "idiom" : "iphone",
      "size" : "29x29",
      "scale" : "3x"
    },
    {
      "idiom" : "iphone",
      "size" : "40x40",
      "scale" : "2x"
    },
    {
      "idiom" : "iphone",
      "size" : "40x40",
      "scale" : "3x"
    },
    {
      "idiom" : "iphone",
      "size" : "60x60",
      "scale" : "2x"
    },
    {
      "idiom" : "iphone",
      "size" : "60x60",
      "scale" : "3x"
    },
    {
      "idiom" : "ipad",
      "size" : "29x29",
      "scale" : "1x"
    },
    {
      "idiom" : "ipad",
      "size" : "29x29",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "size" : "40x40",
      "scale" : "1x"
    },
    {
      "idiom" : "ipad",
      "size" : "40x40",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "size" : "76x76",
      "scale" : "1x"
    },
    {
      "idiom" : "ipad",
      "size" : "76x76",
      "scale" : "2x"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode"
  }
}

================================================
FILE: Sources/MNIST/Base.lproj/LaunchScreen.storyboard
================================================
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
    <dependencies>
        <deployment identifier="iOS"/>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
    </dependencies>
    <scenes>
        <!--View Controller-->
        <scene sceneID="EHf-IW-A2E">
            <objects>
                <viewController id="01J-lp-oVM" sceneMemberID="viewController">
                    <layoutGuides>
                        <viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
                        <viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
                    </layoutGuides>
                    <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
                        <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                    </view>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="53" y="375"/>
        </scene>
    </scenes>
</document>


================================================
FILE: Sources/MNIST/Base.lproj/Main.storyboard
================================================
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
    <dependencies>
        <deployment identifier="iOS"/>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
        <capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
    </dependencies>
    <scenes>
        <!--View Controller-->
        <scene sceneID="tne-QT-ifu">
            <objects>
                <viewController id="BYZ-38-t0r" customClass="ViewController" customModule="MNIST" customModuleProvider="target" sceneMemberID="viewController">
                    <layoutGuides>
                        <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
                        <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
                    </layoutGuides>
                    <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
                        <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <subviews>
                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uby-G9-0HG" customClass="CanvasView" customModule="MNIST" customModuleProvider="target">
                                <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
                                <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                <constraints>
                                    <constraint firstAttribute="width" secondItem="uby-G9-0HG" secondAttribute="height" multiplier="1:1" id="iMN-cJ-Vll"/>
                                </constraints>
                            </view>
                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7vG-JB-rEi">
                                <rect key="frame" x="273" y="560" width="54" height="30"/>
                                <state key="normal" title="Classify"/>
                                <connections>
                                    <action selector="onPressClassifyButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="84U-07-SXk"/>
                                </connections>
                            </button>
                        </subviews>
                        <color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
                        <constraints>
                            <constraint firstItem="wfy-db-euE" firstAttribute="top" relation="greaterThanOrEqual" secondItem="uby-G9-0HG" secondAttribute="bottom" id="3fz-2w-v7P"/>
                            <constraint firstItem="uby-G9-0HG" firstAttribute="top" relation="greaterThanOrEqual" secondItem="8bC-Xf-vdC" secondAttribute="top" priority="500" id="3ok-ag-yr9"/>
                            <constraint firstItem="uby-G9-0HG" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="8eu-2d-nsr"/>
                            <constraint firstItem="7vG-JB-rEi" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="BhB-lX-8dI"/>
                            <constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="7vG-JB-rEi" secondAttribute="bottom" constant="10" id="O49-dA-vBd"/>
                            <constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="uby-G9-0HG" secondAttribute="trailing" priority="500" id="Sfv-CX-pTg"/>
                            <constraint firstItem="uby-G9-0HG" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" priority="500" id="Wnr-Cj-5Zd"/>
                            <constraint firstItem="uby-G9-0HG" firstAttribute="height" secondItem="8bC-Xf-vdC" secondAttribute="height" priority="500" id="k6J-97-4Bu"/>
                            <constraint firstItem="uby-G9-0HG" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="8bC-Xf-vdC" secondAttribute="leading" priority="500" id="mkG-Cu-hyV"/>
                            <constraint firstItem="uby-G9-0HG" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="pWY-OM-cRn"/>
                        </constraints>
                    </view>
                    <connections>
                        <outlet property="canvasView" destination="uby-G9-0HG" id="1zv-6w-oc8"/>
                    </connections>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
            </objects>
        </scene>
    </scenes>
</document>


================================================
FILE: Sources/MNIST/Canvas.swift
================================================
import CoreGraphics

struct Canvas {
    var lines: [Line] = [Line()]
    
    mutating func draw(_ point: CGPoint) {
        lines[lines.endIndex - 1].points.append(point)
    }
    
    mutating func newLine() {
        lines.append(Line())
    }
}


================================================
FILE: Sources/MNIST/CanvasView.swift
================================================
import UIKit

class CanvasView: UIView {
    private(set) var canvas: Canvas
    
    required init?(coder: NSCoder) {
        canvas = Canvas()
        super.init(coder: coder)
        
        self.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(CanvasView.onPanGesture(_:))))
    }
    
    var image: UIImage {
        UIGraphicsBeginImageContext(bounds.size)
        layer.render(in: UIGraphicsGetCurrentContext()!)
        let result = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return result!
    }

    override func draw(_ rect: CGRect) {
        let context = UIGraphicsGetCurrentContext()
        for line in canvas.lines {
            context?.setLineWidth(20.0)
            context?.setStrokeColor(UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0).cgColor)
            context?.setLineCap(.round)
            context?.setLineJoin(.round)
            for (index, point) in line.points.enumerated() {
                if index == 0 {
                    context?.move(to: CGPoint(x: point.x, y: point.y))
                } else {
                    context?.addLine(to: CGPoint(x: point.x, y: point.y))
                }
            }
        }
        context?.strokePath()
    }
    
    @objc func onPanGesture(_ gestureRecognizer: UIPanGestureRecognizer) {
        canvas.draw(gestureRecognizer.location(in: self))
        if gestureRecognizer.state == .ended {
            canvas.newLine()
        }
        
        setNeedsDisplay()
    }
    
    func clear() {
        canvas = Canvas()
        setNeedsDisplay()
    }
}


================================================
FILE: Sources/MNIST/Classifier.swift
================================================
import Foundation
import TensorSwift

public struct Classifier {
    public let W_conv1: Tensor
    public let b_conv1: Tensor
    public let W_conv2: Tensor
    public let b_conv2: Tensor
    public let W_fc1: Tensor
    public let b_fc1: Tensor
    public let W_fc2: Tensor
    public let b_fc2: Tensor
    
    public func classify(_ x_image: Tensor) -> Int {
        let h_conv1 = (x_image.conv2d(filter: W_conv1, strides: [1, 1, 1]) + b_conv1).relu()
        let h_pool1 = h_conv1.maxPool(kernelSize: [2, 2, 1], strides: [2, 2, 1])
        
        let h_conv2 = (h_pool1.conv2d(filter: W_conv2, strides: [1, 1, 1]) + b_conv2).relu()
        let h_pool2 = h_conv2.maxPool(kernelSize: [2, 2, 1], strides: [2, 2, 1])
        
        let h_pool2_flat = h_pool2.reshaped([1, Dimension(7 * 7 * 64)])
        let h_fc1 = (h_pool2_flat.matmul(W_fc1) + b_fc1).relu()
        
        let y_conv = (h_fc1.matmul(W_fc2) + b_fc2).softmax()

        return y_conv.elements.enumerated().max { $0.1 < $1.1 }!.0
    }
}

extension Classifier {
    public init(path: String) {
        W_conv1 = Tensor(shape: [5, 5, 1, 32], elements: loadFloatArray(path, file: "W_conv1"))
        b_conv1 = Tensor(shape: [32], elements: loadFloatArray(path, file: "b_conv1"))
        W_conv2 = Tensor(shape: [5, 5, 32, 64], elements: loadFloatArray(path, file: "W_conv2"))
        b_conv2 = Tensor(shape: [64], elements: loadFloatArray(path, file: "b_conv2"))
        W_fc1 = Tensor(shape: [Dimension(7 * 7 * 64), 1024], elements: loadFloatArray(path, file: "W_fc1"))
        b_fc1 = Tensor(shape: [1024], elements: loadFloatArray(path, file: "b_fc1"))
        W_fc2 = Tensor(shape: [1024, 10], elements: loadFloatArray(path, file: "W_fc2"))
        b_fc2 = Tensor(shape: [10], elements: loadFloatArray(path, file: "b_fc2"))
    }
}

private func loadFloatArray(_ directory: String, file: String) -> [Float] {
    let data = try! Data(contentsOf: URL(fileURLWithPath: directory.stringByAppendingPathComponent(file)))
    return Array(UnsafeBufferPointer(start: UnsafeMutablePointer<Float>(mutating: (data as NSData).bytes.bindMemory(to: Float.self, capacity: data.count)), count: data.count / 4))
}


================================================
FILE: Sources/MNIST/Info.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>en</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleVersion</key>
	<string>1</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
	<key>UIMainStoryboardFile</key>
	<string>Main</string>
	<key>UIRequiredDeviceCapabilities</key>
	<array>
		<string>armv7</string>
	</array>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSExceptionDomains</key>
		<dict>
			<key>yann.lecun.com</key>
			<string></string>
		</dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
	</dict>
</dict>
</plist>


================================================
FILE: Sources/MNIST/Line.swift
================================================
import CoreGraphics

struct Line {
    var points: [CGPoint]
    
    init() {
        self.init([])
    }
    
    init(_ points: [CGPoint]) {
        self.points = points
    }
}

================================================
FILE: Sources/MNIST/Models/W_fc1
================================================
[File too large to display: 12.2 MB]

================================================
FILE: Sources/MNIST/Models/b_conv1
================================================
Ԝ=7=֩=x=o=s=Z=^=[;=ߋ=fVj=f=m=Z=T===e=W==3===/X=='^=؍="=`==[[=d=

================================================
FILE: Sources/MNIST/Models/b_conv2
================================================
==^=
={F=k=D=_ڴ=f==zI=Ŧ=ܕ=9==== =ذ=\==u='===l=Ҭ=ա=,===O=PͰ==Ķ====.==숵=_=9=~==Li==Ds=k6==9=s===YJ=H===%Π=.==ׇ==͔=

================================================
FILE: Sources/MNIST/Models/b_fc2
================================================
=K=II==G==6==16=y%=

================================================
FILE: Sources/MNIST/String.swift
================================================
import Foundation

extension String {
    public func stringByAppendingPathComponent(_ str: String) -> String {
        return (self as NSString).appendingPathComponent(str)
    }
}


================================================
FILE: Sources/MNIST/ViewController.swift
================================================
import UIKit
import TensorSwift

class ViewController: UIViewController {
    @IBOutlet private var canvasView: CanvasView!
    
    private let inputSize = 28
    private let classifier = Classifier(path: Bundle.main.resourcePath!)

    @IBAction func onPressClassifyButton(_ sender: UIButton) {
        let input: Tensor
        do {
            let image = canvasView.image
            
            let cgImage = image.cgImage!
            
            var pixels = [UInt8](repeating: 0, count: inputSize * inputSize)
            
            let context  = CGContext(data: &pixels, width: inputSize, height: inputSize, bitsPerComponent: 8, bytesPerRow: inputSize, space: CGColorSpaceCreateDeviceGray(), bitmapInfo: 0)!
            context.clear(CGRect(x: 0.0, y: 0.0, width: CGFloat(inputSize), height: CGFloat(inputSize)))
            
            let rect = CGRect(x: 0.0, y: 0.0, width: CGFloat(inputSize), height: CGFloat(inputSize))
            context.draw(cgImage, in: rect)
            
            input = Tensor(shape: [Dimension(inputSize), Dimension(inputSize), 1], elements: pixels.map { (pixel: UInt8) -> Float in -(Float(pixel) / 255.0 - 0.5) + 0.5 })
        }

        let estimatedLabel = classifier.classify(input)

        let alertController = UIAlertController(title: "\(estimatedLabel)", message: nil, preferredStyle: .alert)
        alertController.addAction(UIAlertAction(title: "Dismiss", style: .default) { _ in self.canvasView.clear() })
        present(alertController, animated: true, completion: nil)
    }
}



================================================
FILE: Sources/TensorSwift/Dimension.swift
================================================
public struct Dimension {
    public let value: Int
    
    public init(_ value: Int) {
        guard value >= 0 else { fatalError("`value` must be greater than or equal to 0: \(value)") }
        self.value = value
    }
}

extension Dimension: ExpressibleByIntegerLiteral {
    public init(integerLiteral value: Int) {
        self.init(value)
    }
}

extension Dimension: Equatable {}
public func ==(lhs: Dimension, rhs: Dimension) -> Bool {
    return lhs.value == rhs.value
}

extension Dimension: CustomStringConvertible {
    public var description: String {
        return value.description
    }
}

public func +(lhs: Dimension, rhs: Dimension) -> Dimension {
    return Dimension(lhs.value + rhs.value)
}

public func -(lhs: Dimension, rhs: Dimension) -> Dimension {
    return Dimension(lhs.value - rhs.value)
}

public func *(lhs: Dimension, rhs: Dimension) -> Dimension {
    return Dimension(lhs.value * rhs.value)
}

public func /(lhs: Dimension, rhs: Dimension) -> Dimension {
    return Dimension(lhs.value / rhs.value)
}


================================================
FILE: Sources/TensorSwift/Info.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>en</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>FMWK</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>$(CURRENT_PROJECT_VERSION)</string>
	<key>NSPrincipalClass</key>
	<string></string>
</dict>
</plist>


================================================
FILE: Sources/TensorSwift/Operators.swift
================================================
infix operator ** : PowerPrecedence
precedencegroup PowerPrecedence {
    associativity: right
    higherThan: MultiplicationPrecedence
}


================================================
FILE: Sources/TensorSwift/Shape.swift
================================================
public struct Shape {
    public let dimensions: [Dimension]
    
    public func volume() -> Int {
        return dimensions.reduce(1) { $0 * $1.value }
    }
    
    public init(_ dimensions: [Dimension]) {
        self.dimensions = dimensions
    }
}

extension Shape: ExpressibleByArrayLiteral {
    public init(arrayLiteral elements: Dimension...) {
        self.init(elements)
    }
}

extension Shape: Equatable {}
public func ==(lhs: Shape, rhs: Shape) -> Bool {
    return lhs.dimensions == rhs.dimensions
}

extension Shape: CustomStringConvertible {
    public var description: String {
        return dimensions.description
    }
}


================================================
FILE: Sources/TensorSwift/Tensor.swift
================================================

#if os(iOS) || os(OSX)
import Accelerate
#endif

public struct Tensor {
    public typealias Element = Float
    
    public let shape: Shape
    public fileprivate(set) var elements: [Element]
    
    public init(shape: Shape, elements: [Element]) {
        let volume = shape.volume()
        precondition(elements.count >= volume, "`elements.count` must be greater than or equal to `shape.volume`: elements.count = \(elements.count), shape.volume = \(shape.volume())")
        self.shape = shape
        self.elements = (elements.count == volume) ? elements : Array(elements[0..<volume])
    }
}

extension Tensor { // Additional Initializers
    public init(shape: Shape, element: Element = 0.0) {
        self.init(shape: shape, elements: [Element](repeating: element, count: shape.volume()))
    }
}

extension Tensor {
    public mutating func reshape(_ shape: Shape) {
        self = reshaped(shape)
    }
    
    public func reshaped(_ shape: Shape) -> Tensor {
        return Tensor(shape: shape, elements: elements)
    }
}

extension Tensor { // like CollentionType
    internal func index(_ indices: [Int]) -> Int {
        assert(indices.count == shape.dimensions.count, "`indices.count` must be \(shape.dimensions.count): \(indices.count)")
        return zip(shape.dimensions, indices).reduce(0) {
            assert(0 <= $1.1 && $1.1 < $1.0.value, "Illegal index: indices = \(indices), shape = \(shape)")
            return $0 * $1.0.value + $1.1
        }
    }
    
    public subscript(indices: Int...) -> Element {
        get {
            return elements[index(indices)]
        }
        set {
            elements[index(indices)] = newValue
        }
    }
    
    public func volume() -> Int {
        return shape.volume()
    }
}

extension Tensor: Sequence {
    public func makeIterator() -> IndexingIterator<[Element]> {
        return elements.makeIterator()
    }
}

extension Tensor: Equatable {}
public func ==(lhs: Tensor, rhs: Tensor) -> Bool {
    return lhs.shape == rhs.shape && lhs.elements == rhs.elements
}

internal func commutativeBinaryOperation(_ lhs: Tensor, _ rhs: Tensor, operation: (Float, Float) -> Float) -> Tensor {
    let lSize = lhs.shape.dimensions.count
    let rSize = rhs.shape.dimensions.count
    
    if lSize == rSize {
        precondition(lhs.shape == rhs.shape, "Incompatible shapes of tensors: lhs.shape = \(lhs.shape), rhs.shape = \(rhs.shape)")
        return Tensor(shape: lhs.shape, elements: zipMap(lhs.elements, rhs.elements, operation: operation))
    }
    
    let a: Tensor
    let b: Tensor
    if lSize < rSize {
        a = rhs
        b = lhs
    } else {
        a = lhs
        b = rhs
    }
    assert(hasSuffix(array: a.shape.dimensions, suffix: b.shape.dimensions), "Incompatible shapes of tensors: lhs.shape = \(lhs.shape), rhs.shape = \(rhs.shape)")
    
    return Tensor(shape: a.shape, elements: zipMapRepeat(a.elements, b.elements, operation: operation))
}

internal func noncommutativeBinaryOperation(_ lhs: Tensor, _ rhs: Tensor, operation: (Float, Float) -> Float) -> Tensor {
    let lSize = lhs.shape.dimensions.count
    let rSize = rhs.shape.dimensions.count
    
    if lSize == rSize {
        precondition(lhs.shape == rhs.shape, "Incompatible shapes of tensors: lhs.shape = \(lhs.shape), rhs.shape = \(rhs.shape)")
        return Tensor(shape: lhs.shape, elements: zipMap(lhs.elements, rhs.elements, operation: operation))
    } else if lSize < rSize {
        precondition(hasSuffix(array: rhs.shape.dimensions, suffix: lhs.shape.dimensions), "Incompatible shapes of tensors: lhs.shape = \(lhs.shape), rhs.shape = \(rhs.shape)")
        return Tensor(shape: rhs.shape, elements: zipMapRepeat(rhs.elements, lhs.elements, operation: { operation($1, $0) }))
    } else {
        precondition(hasSuffix(array: lhs.shape.dimensions, suffix: rhs.shape.dimensions), "Incompatible shapes of tensors: lhs.shape = \(lhs.shape), rhs.shape = \(rhs.shape)")
        return Tensor(shape: lhs.shape, elements: zipMapRepeat(lhs.elements, rhs.elements, operation: operation))
    }
}

public func +(lhs: Tensor, rhs: Tensor) -> Tensor {
    return commutativeBinaryOperation(lhs, rhs, operation: +)
}

public func -(lhs: Tensor, rhs: Tensor) -> Tensor {
    return noncommutativeBinaryOperation(lhs, rhs, operation: -)
}

public func *(lhs: Tensor, rhs: Tensor) -> Tensor {
    return commutativeBinaryOperation(lhs, rhs, operation: *)
}

public func /(lhs: Tensor, rhs: Tensor) -> Tensor {
    return noncommutativeBinaryOperation(lhs, rhs, operation: /)
}

public func *(lhs: Tensor, rhs: Float) -> Tensor {
    return Tensor(shape: lhs.shape, elements: lhs.elements.map { $0 * rhs })
}

public func *(lhs: Float, rhs: Tensor) -> Tensor {
    return Tensor(shape: rhs.shape, elements: rhs.elements.map { lhs * $0 })
}

public func /(lhs: Tensor, rhs: Float) -> Tensor {
    return Tensor(shape: lhs.shape, elements: lhs.elements.map { $0 / rhs })
}

public func /(lhs: Float, rhs: Tensor) -> Tensor {
    return Tensor(shape: rhs.shape, elements: rhs.elements.map { lhs / $0 })
}

extension Tensor { // Matrix
    public func matmul(_ tensor: Tensor) -> Tensor {
        precondition(shape.dimensions.count == 2, "This tensor is not a matrix: shape = \(shape)")
        precondition(tensor.shape.dimensions.count == 2, "The given tensor is not a matrix: shape = \(tensor.shape)")
        precondition(tensor.shape.dimensions[0] == shape.dimensions[1], "Incompatible shapes of matrices: self.shape = \(shape), tensor.shape = \(tensor.shape)")
        
        #if os(iOS) || os(OSX)
            let result = Tensor(shape: [shape.dimensions[0], tensor.shape.dimensions[1]])
            
            let n = Int32(tensor.shape.dimensions[1].value)
            let k = Int32(shape.dimensions[1].value)
            cblas_sgemm(
                CblasRowMajor,                                // Order
                CblasNoTrans,                                 // TransA
                CblasNoTrans,                                 // TransB
                Int32(shape.dimensions[0].value),             // M
                n,                                            // N
                k,                                            // K
                1.0,                                          // alpha
                elements,                                     // A
                k,                                            // lda
                tensor.elements,                              // B
                n,                                            // ldb
                1.0,                                          // beta
                UnsafeMutablePointer<Float>(mutating: result.elements), // C
                n                                             // ldc
            )
            
            return result
        #else
            let n = shape.dimensions[1].value
            
            let numRows = shape.dimensions[0]
            let numCols = tensor.shape.dimensions[1]
            
            let leftHead = UnsafeMutablePointer<Float>(self.elements)
            let rightHead = UnsafeMutablePointer<Float>(tensor.elements)
            
            let elements = [Float](count: (numCols * numRows).value, repeatedValue: 0.0)
            for r in 0..<numRows.value {
                for i in 0..<n {
                    var pointer = UnsafeMutablePointer<Float>(elements) + r * numCols.value
                    let left = leftHead[r * n + i]
                    var rightPointer = rightHead + i * numCols.value
                    for _ in 0..<numCols.value {
                        pointer.memory += left * rightPointer.memory
                        pointer += 1
                        rightPointer += 1
                    }
                }
            }
            
            return Tensor(shape: [numRows, numCols], elements: elements)
        #endif
    }
}


================================================
FILE: Sources/TensorSwift/TensorMath.swift
================================================
import Darwin

public func **(lhs: Tensor, rhs: Tensor) -> Tensor {
    return noncommutativeBinaryOperation(lhs, rhs, operation: powf)
}

public func **(lhs: Tensor, rhs: Tensor.Element) -> Tensor {
    return Tensor(shape: lhs.shape, elements: lhs.elements.map { powf($0, rhs) })
}

public func **(lhs: Tensor.Element, rhs: Tensor) -> Tensor {
    return Tensor(shape: rhs.shape, elements: rhs.elements.map { powf(lhs, $0) })
}

extension Tensor {
    public func sin() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(sinf))
    }

    public func cos() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(cosf))
    }

    public func tan() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(tanf))
    }

    public func asin() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(asinf))
    }
    
    public func acos() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(acosf))
    }
    
    public func atan() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(atanf))
    }
    
    public func sinh() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(sinhf))
    }
    
    public func cosh() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(coshf))
    }
    
    public func tanh() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(tanhf))
    }
    
    public func exp() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(expf))
    }
    
    public func log() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(logf))
    }
    
    public func sqrt() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(sqrtf))
    }
    
    public func cbrt() -> Tensor {
        return Tensor(shape: shape, elements: elements.map(cbrtf))
    }
}

extension Tensor {
    public func sigmoid() -> Tensor {
        return Tensor(shape: shape, elements: elements.map { 1.0 / (1.0 + expf(-$0)) })
    }
}


================================================
FILE: Sources/TensorSwift/TensorNN.swift
================================================
import Darwin
#if os(iOS) || os(OSX)
import Accelerate
#endif

extension Tensor {
    public func softmax() -> Tensor {
        let exps = exp()
        let sum = exps.elements.reduce(0.0, +)
        return exps / sum
    }
    
    public func relu() -> Tensor {
        return Tensor(shape: shape, elements: elements.map { fmax($0, 0.0) })
    }
}

extension Tensor {
    public func maxPool(kernelSize: [Int], strides: [Int]) -> Tensor { // padding = Same
        precondition(shape.dimensions.count == 3, "`shape.dimensions.count` must be 3: \(shape.dimensions.count)")
        precondition(kernelSize.count == 3, "`ksize.count` must be 3: \(kernelSize.count)")
        precondition(kernelSize[2] == 1, "`ksize[3]` != 1 is not supported: \(kernelSize[2])")
        precondition(strides.count == 3, "`strides.count` must be 3: \(strides.count)")
        precondition(strides[2] == 1, "`strides[2]` != 1 is not supported: \(strides[2])")
        
        let inRows = shape.dimensions[0].value
        let inCols = shape.dimensions[1].value
        let numChannels = shape.dimensions[2].value
        
        let filterHeight = kernelSize[0]
        let filterWidth = kernelSize[1]
        
        let inMinDy = -(filterHeight - 1) / 2
        let inMaxDy = inMinDy + filterHeight - 1
        let inMinDx = -(filterWidth - 1) / 2
        let inMaxDx = inMinDx + filterWidth - 1
        
        let rowStride = strides[0]
        let colStride = strides[1]

        let outRows = shape.dimensions[0].value.ceilDiv(rowStride)
        let outCols = shape.dimensions[1].value.ceilDiv(colStride)
        
        // Initialize with -infinity for maximization.
        let elements = [Element](repeating: -Float.infinity, count: outCols * outRows * numChannels)
        
        for y in 0..<outRows {
            let inY0 = y * rowStride
            let inMinY = Swift.max(inY0 + inMinDy, 0)
            let inMaxY = Swift.min(inY0 + inMaxDy, inRows - 1)

            for inY in inMinY...inMaxY {
                var outPixelIndex = y * outCols
                for x in 0..<outCols {
                    let inX0 = x * colStride
                    let inMinX = Swift.max(inX0 + inMinDx, 0)
                    let inMaxX = Swift.min(inX0 + inMaxDx, inCols - 1)
                    
                    var inPointer = UnsafeMutablePointer<Element>(mutating: self.elements) + (inY * inCols + inMinX) * numChannels
                    for _ in inMinX...inMaxX {
                        var outPointer = UnsafeMutablePointer<Element>(mutating: elements) + outPixelIndex * numChannels
                        for _ in 0..<numChannels {
                            outPointer.pointee = Swift.max(outPointer.pointee, inPointer.pointee)
                            outPointer += 1
                            inPointer += 1
                        }
                    }
                    outPixelIndex += 1
                }
            }
        }
        
        return Tensor(shape: [Dimension(outRows), Dimension(outCols), Dimension(numChannels)], elements: elements)
    }
    
    
    public func conv2d(filter: Tensor, strides: [Int]) -> Tensor { // padding = Same
        let inChannels = filter.shape.dimensions[2].value
        
        precondition(shape.dimensions.count == 3, "`shape.dimensions.count` must be 3: \(shape.dimensions.count)")
        precondition(filter.shape.dimensions.count == 4, "`filter.shape.dimensions.count` must be 4: \(filter.shape.dimensions.count)")
        precondition(strides.count == 3, "`strides.count` must be 3: \(strides.count)")
        precondition(strides[2] == 1, "`strides[2]` must be 1")
        precondition(shape.dimensions[2].value == inChannels, "The number of channels of this tensor and the filter are not compatible: \(shape.dimensions[2]) != \(inChannels)")
        
        let inRows = shape.dimensions[0].value
        let inCols = shape.dimensions[1].value
        
        let filterHeight = filter.shape.dimensions[0].value
        let filterWidth = filter.shape.dimensions[1].value
        
        let inMinDy = -(filterHeight - 1) / 2
        let inMaxDy = inMinDy + filterHeight - 1
        let inMinDx = -(filterWidth - 1) / 2
        let inMaxDx = inMinDx + filterWidth - 1
        
        let rowStride = strides[0]
        let colStride = strides[1]
        
        let outRows = inRows.ceilDiv(rowStride)
        let outCols = inCols.ceilDiv(colStride)
        let outChannels = filter.shape.dimensions[3].value
        
        #if os(iOS) || os(OSX)
            let elementsPointer = UnsafePointer<Float>(elements)
            
            // a.shape == [outRows * outCols, rowSize]
            let rowSize = filterHeight * filterWidth * inChannels
            let a = [Float](repeating: 0, count: outRows * outCols * rowSize)
            for y in 0..<outRows {
                let inY0 = y * rowStride
                let inMinY = Swift.max(inY0 + inMinDy, 0)
                let inMaxY = Swift.min(inY0 + inMaxDy, inRows - 1)
                
                for x in 0..<outCols{
                    let inX0 = x * colStride
                    let inMinX = Swift.max(inX0 + inMinDx, 0)
                    let inMaxX = Swift.min(inX0 + inMaxDx, inCols - 1)
                    
                    // Add (x,y)'s patch as a vector
                    var dest = UnsafeMutablePointer<Float>(mutating: a) + ((y * outCols + x) * filterHeight - Swift.min(inY0 + inMinDy, 0)) * filterWidth * inChannels
                    var src = elementsPointer + (inMinY * inCols + inMinX) * inChannels
                    for _ in inMinY...inMaxY {
                        memcpy(dest - Swift.min(inX0 + inMinDx, 0) * inChannels, src, (inMinX...inMaxX).count * inChannels * MemoryLayout<Float>.size)
                        dest += filterWidth * inChannels
                        src += inCols * inChannels
                    }
                }
            }
            
            let result = Tensor(shape: [Dimension(outRows), Dimension(outCols), Dimension(outChannels)])
            
            let n = Int32(outChannels)
            let k = Int32(rowSize)
            
            // Calculate [M, N] matrix, it automatically turns into [outRows, outCols, outChannels] Tensor
            cblas_sgemm(
                CblasRowMajor,                                // Order
                CblasNoTrans,                                 // TransA
                CblasNoTrans,                                 // TransB
                Int32(outRows * outCols),                     // M
                n,                                            // N
                k,                                            // K
                1.0,                                          // alpha
                UnsafePointer<Float>(a),                      // A
                k,                                            // lda
                UnsafePointer<Float>(filter.elements),        // B
                n,                                            // ldb
                1.0,                                          // beta
                UnsafeMutablePointer<Float>(mutating: result.elements), // C
                n                                             // ldc
            )
            
            return result
        #else
            let elements = [Float](count: outCols * outRows * outChannels, repeatedValue: 0.0)
            
            for y in 0..<outRows {
                let inY0 = y * rowStride
                let inMinY = max(inY0 + inMinDy, 0)
                let inMaxY = min(inY0 + inMaxDy, inRows - 1)
                
                for x in 0..<outCols{
                    let inX0 = x * colStride
                    let inMinX = max(inX0 + inMinDx, 0)
                    let inMaxX = min(inX0 + inMaxDx, inCols - 1)
                    
                    let inYOffset = inY0 + inMinDy
                    let inXOffset = inX0 + inMinDx
                    
                    for inY in inMinY...inMaxY {
                        for inX in inMinX...inMaxX {
                            matmuladd(
                                inChannels, outChannels,
                                (inY * inCols + inX) * inChannels, UnsafeMutablePointer(self.elements),
                                ((inY - inYOffset) * filterWidth + (inX - inXOffset)) * inChannels * outChannels, UnsafeMutablePointer(filter.elements),
                                (y * outCols + x) * outChannels, UnsafeMutablePointer(elements)
                            )
                        }
                    }
                }
            }
            
            return Tensor(shape: [Dimension(outRows), Dimension(outCols), Dimension(outChannels)], elements: elements)
        #endif
    }
}

#if os(iOS) || os(OSX)
#else
    private func matmuladd(inCols1Rows2: Int, _ outCols: Int, _ o1: Int, _ vec: UnsafeMutablePointer<Float>, _ o2: Int, _ mat: UnsafeMutablePointer<Float>, _ oo: Int, _ out: UnsafeMutablePointer<Float>) {
        var v = vec + o1
        for i in 0..<inCols1Rows2 {
            var o = out + oo
            let left = v.memory
            for c in 0..<outCols {
                o.memory += left * mat[i * outCols + c + o2]
                o += 1
            }
            v += 1
        }
    }
#endif


================================================
FILE: Sources/TensorSwift/TensorSwift.h
================================================
#import <Foundation/Foundation.h>

//! Project version number for TensorSwift.
FOUNDATION_EXPORT double TensorSwiftVersionNumber;

//! Project version string for TensorSwift.
FOUNDATION_EXPORT const unsigned char TensorSwiftVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <TensorSwift/PublicHeader.h>




================================================
FILE: Sources/TensorSwift/Utils.swift
================================================
extension Int {
    internal func ceilDiv(_ rhs: Int) -> Int {
        return (self + rhs - 1) / rhs
    }
}

internal func hasSuffix<Element: Equatable>(array: [Element], suffix: [Element]) -> Bool {
    guard array.count >= suffix.count else { return false }
    return zip(array[(array.count - suffix.count)..<array.count], suffix).reduce(true) { $0 && $1.0 == $1.1 }
}

internal func zipMap(_ a: [Float], _ b: [Float], operation: (Float, Float) -> Float) -> [Float] {
    var result: [Float] = []
    for i in a.indices {
        result.append(operation(a[i], b[i]))
    }
    return result
}

internal func zipMapRepeat(_ a: [Float], _ infiniteB: [Float], operation: (Float, Float) -> Float) -> [Float] {
    var result: [Float] = []
    for i in a.indices {
        result.append(operation(a[i], infiniteB[i % infiniteB.count]))
    }
    return result
}



================================================
FILE: TensorSwift.podspec
================================================
Pod::Spec.new do |s|
  s.name         = "TensorSwift"
  s.version      = "0.2.2"
  s.summary      = "TensorSwift is a lightweight library to calculate tensors, which has similar APIs to TensorFlow's."
  s.homepage     = "https://github.com/qoncept/TensorSwift"
  s.license      = { :type => "MIT", :file => "LICENSE" }
  s.authors      = { "Yuta Koshizawa" => "koshizawa@qoncept.co.jp", "Takehiro Araki" => "araki@qoncept.co.jp" }

  s.ios.deployment_target = "8.0"
  s.osx.deployment_target = "10.9"
  # s.watchos.deployment_target = "2.0"
  # s.tvos.deployment_target = "9.0"
  s.source       = { :git => "https://github.com/qoncept/TensorSwift.git", :tag => "#{s.version}" }
  s.source_files  = "Sources/*.swift"
end


================================================
FILE: TensorSwift.xcodeproj/Configs/Project.xcconfig
================================================
PRODUCT_NAME = $(TARGET_NAME)
SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator
MACOSX_DEPLOYMENT_TARGET = 10.10
DYLIB_INSTALL_NAME_BASE = @rpath
OTHER_SWIFT_FLAGS = -DXcode
COMBINE_HIDPI_IMAGES = YES
USE_HEADERMAP = NO


================================================
FILE: TensorSwift.xcodeproj/TensorSwiftTests_Info.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
  <key>CFBundleDevelopmentRegion</key>
  <string>en</string>
  <key>CFBundleExecutable</key>
  <string>$(EXECUTABLE_NAME)</string>
  <key>CFBundleIdentifier</key>
  <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
  <key>CFBundleInfoDictionaryVersion</key>
  <string>6.0</string>
  <key>CFBundleName</key>
  <string>$(PRODUCT_NAME)</string>
  <key>CFBundlePackageType</key>
  <string>BNDL</string>
  <key>CFBundleShortVersionString</key>
  <string>1.0</string>
  <key>CFBundleSignature</key>
  <string>????</string>
  <key>CFBundleVersion</key>
  <string>$(CURRENT_PROJECT_VERSION)</string>
  <key>NSPrincipalClass</key>
  <string></string>
</dict>
</plist>


================================================
FILE: TensorSwift.xcodeproj/TensorSwift_Info.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
  <key>CFBundleDevelopmentRegion</key>
  <string>en</string>
  <key>CFBundleExecutable</key>
  <string>$(EXECUTABLE_NAME)</string>
  <key>CFBundleIdentifier</key>
  <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
  <key>CFBundleInfoDictionaryVersion</key>
  <string>6.0</string>
  <key>CFBundleName</key>
  <string>$(PRODUCT_NAME)</string>
  <key>CFBundlePackageType</key>
  <string>FMWK</string>
  <key>CFBundleShortVersionString</key>
  <string>1.0</string>
  <key>CFBundleSignature</key>
  <string>????</string>
  <key>CFBundleVersion</key>
  <string>$(CURRENT_PROJECT_VERSION)</string>
  <key>NSPrincipalClass</key>
  <string></string>
</dict>
</plist>


================================================
FILE: TensorSwift.xcodeproj/project.pbxproj
================================================
// !$*UTF8*$!
{
	archiveVersion = 1;
	classes = {
	};
	objectVersion = 46;
	objects = {

/* Begin PBXBuildFile section */
		A7C046091D9F514600FAF16F /* TensorSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7DF6F8E1D9BB9660097CEB7 /* TensorSwiftTests.swift */; };
		A7C0460A1D9F514600FAF16F /* CalculationPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7DF6F811D9BB9240097CEB7 /* CalculationPerformanceTests.swift */; };
		A7C0460B1D9F514600FAF16F /* DimensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7DF6F821D9BB9240097CEB7 /* DimensionTests.swift */; };
		A7C0460C1D9F514600FAF16F /* PowerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7DF6F841D9BB9240097CEB7 /* PowerTests.swift */; };
		A7C0460D1D9F514600FAF16F /* TensorNNTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7DF6F851D9BB9240097CEB7 /* TensorNNTests.swift */; };
		A7C0460E1D9F514600FAF16F /* TensorSwiftSample.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7DF6F861D9BB9240097CEB7 /* TensorSwiftSample.swift */; };
		A7C0460F1D9F514600FAF16F /* TensorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7DF6F871D9BB9240097CEB7 /* TensorTests.swift */; };
		A7C387DE1D9F611D00091506 /* TensorSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "_____Product_TensorSwift" /* TensorSwift.framework */; };
		A7C387DF1D9F611D00091506 /* TensorSwift.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = "_____Product_TensorSwift" /* TensorSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
		A7C388031D9F629A00091506 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A7C388001D9F619000091506 /* libz.tbd */; };
		D646CEF61DBE1A25003E8A59 /* TensorMathTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D646CEF51DBE1A25003E8A59 /* TensorMathTest.swift */; };
		D66840171F9DDD7500D1DE7F /* Dimension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D668400E1F9DDD7500D1DE7F /* Dimension.swift */; };
		D66840181F9DDD7500D1DE7F /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840101F9DDD7500D1DE7F /* Operators.swift */; };
		D66840191F9DDD7500D1DE7F /* Shape.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840111F9DDD7500D1DE7F /* Shape.swift */; };
		D668401A1F9DDD7500D1DE7F /* Tensor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840121F9DDD7500D1DE7F /* Tensor.swift */; };
		D668401B1F9DDD7500D1DE7F /* TensorMath.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840131F9DDD7500D1DE7F /* TensorMath.swift */; };
		D668401C1F9DDD7500D1DE7F /* TensorNN.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840141F9DDD7500D1DE7F /* TensorNN.swift */; };
		D668401D1F9DDD7500D1DE7F /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840161F9DDD7500D1DE7F /* Utils.swift */; };
		D66840271F9DE8DF00D1DE7F /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = D668401F1F9DE8DF00D1DE7F /* Array.swift */; };
		D66840281F9DE8DF00D1DE7F /* ClassifierTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840201F9DE8DF00D1DE7F /* ClassifierTests.swift */; };
		D66840291F9DE8DF00D1DE7F /* Downloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840211F9DE8DF00D1DE7F /* Downloader.swift */; };
		D668402A1F9DE8DF00D1DE7F /* DownloaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840221F9DE8DF00D1DE7F /* DownloaderTests.swift */; };
		D668402D1F9DE8DF00D1DE7F /* SHA1.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840261F9DE8DF00D1DE7F /* SHA1.swift */; };
		D66840451F9DE8F000D1DE7F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D668402F1F9DE8F000D1DE7F /* AppDelegate.swift */; };
		D66840461F9DE8F000D1DE7F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D66840301F9DE8F000D1DE7F /* Assets.xcassets */; };
		D66840471F9DE8F000D1DE7F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D66840311F9DE8F000D1DE7F /* LaunchScreen.storyboard */; };
		D66840481F9DE8F000D1DE7F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D66840331F9DE8F000D1DE7F /* Main.storyboard */; };
		D66840491F9DE8F000D1DE7F /* Canvas.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840351F9DE8F000D1DE7F /* Canvas.swift */; };
		D668404A1F9DE8F000D1DE7F /* CanvasView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840361F9DE8F000D1DE7F /* CanvasView.swift */; };
		D668404B1F9DE8F000D1DE7F /* Classifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840371F9DE8F000D1DE7F /* Classifier.swift */; };
		D668404D1F9DE8F000D1DE7F /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840391F9DE8F000D1DE7F /* Line.swift */; };
		D668404E1F9DE8F000D1DE7F /* b_conv1 in Resources */ = {isa = PBXBuildFile; fileRef = D668403B1F9DE8F000D1DE7F /* b_conv1 */; };
		D668404F1F9DE8F000D1DE7F /* b_conv2 in Resources */ = {isa = PBXBuildFile; fileRef = D668403C1F9DE8F000D1DE7F /* b_conv2 */; };
		D66840501F9DE8F000D1DE7F /* b_fc1 in Resources */ = {isa = PBXBuildFile; fileRef = D668403D1F9DE8F000D1DE7F /* b_fc1 */; };
		D66840511F9DE8F000D1DE7F /* b_fc2 in Resources */ = {isa = PBXBuildFile; fileRef = D668403E1F9DE8F000D1DE7F /* b_fc2 */; };
		D66840521F9DE8F000D1DE7F /* W_conv1 in Resources */ = {isa = PBXBuildFile; fileRef = D668403F1F9DE8F000D1DE7F /* W_conv1 */; };
		D66840531F9DE8F000D1DE7F /* W_conv2 in Resources */ = {isa = PBXBuildFile; fileRef = D66840401F9DE8F000D1DE7F /* W_conv2 */; };
		D66840541F9DE8F000D1DE7F /* W_fc1 in Resources */ = {isa = PBXBuildFile; fileRef = D66840411F9DE8F000D1DE7F /* W_fc1 */; };
		D66840551F9DE8F000D1DE7F /* W_fc2 in Resources */ = {isa = PBXBuildFile; fileRef = D66840421F9DE8F000D1DE7F /* W_fc2 */; };
		D66840561F9DE8F000D1DE7F /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840431F9DE8F000D1DE7F /* String.swift */; };
		D66840571F9DE8F000D1DE7F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66840441F9DE8F000D1DE7F /* ViewController.swift */; };
		_LinkFileRef_TensorSwift_via_TensorSwiftTests /* TensorSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "_____Product_TensorSwift" /* TensorSwift.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
		A7C387BA1D9F604900091506 /* PBXContainerItemProxy */ = {
			isa = PBXContainerItemProxy;
			containerPortal = __RootObject_ /* Project object */;
			proxyType = 1;
			remoteGlobalIDString = A7C387A51D9F604900091506;
			remoteInfo = MNIST;
		};
		A7C387E01D9F611D00091506 /* PBXContainerItemProxy */ = {
			isa = PBXContainerItemProxy;
			containerPortal = __RootObject_ /* Project object */;
			proxyType = 1;
			remoteGlobalIDString = "______Target_TensorSwift";
			remoteInfo = TensorSwift;
		};
		A7DF6EB61D9A1AC40097CEB7 /* PBXContainerItemProxy */ = {
			isa = PBXContainerItemProxy;
			containerPortal = __RootObject_ /* Project object */;
			proxyType = 1;
			remoteGlobalIDString = "______Target_TensorSwift";
			remoteInfo = TensorSwift;
		};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
		A7C387E21D9F611E00091506 /* Embed Frameworks */ = {
			isa = PBXCopyFilesBuildPhase;
			buildActionMask = 2147483647;
			dstPath = "";
			dstSubfolderSpec = 10;
			files = (
				A7C387DF1D9F611D00091506 /* TensorSwift.framework in Embed Frameworks */,
			);
			name = "Embed Frameworks";
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
		A7C387A61D9F604900091506 /* MNIST.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MNIST.app; sourceTree = BUILT_PRODUCTS_DIR; };
		A7C387B91D9F604900091506 /* MNISTTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MNISTTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
		A7C388001D9F619000091506 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; };
		A7DF6F811D9BB9240097CEB7 /* CalculationPerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalculationPerformanceTests.swift; sourceTree = "<group>"; };
		A7DF6F821D9BB9240097CEB7 /* DimensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DimensionTests.swift; sourceTree = "<group>"; };
		A7DF6F841D9BB9240097CEB7 /* PowerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PowerTests.swift; sourceTree = "<group>"; };
		A7DF6F851D9BB9240097CEB7 /* TensorNNTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TensorNNTests.swift; sourceTree = "<group>"; };
		A7DF6F861D9BB9240097CEB7 /* TensorSwiftSample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TensorSwiftSample.swift; sourceTree = "<group>"; };
		A7DF6F871D9BB9240097CEB7 /* TensorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TensorTests.swift; sourceTree = "<group>"; };
		A7DF6F8E1D9BB9660097CEB7 /* TensorSwiftTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TensorSwiftTests.swift; sourceTree = "<group>"; };
		D646CEF51DBE1A25003E8A59 /* TensorMathTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TensorMathTest.swift; sourceTree = "<group>"; };
		D668400E1F9DDD7500D1DE7F /* Dimension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dimension.swift; sourceTree = "<group>"; };
		D668400F1F9DDD7500D1DE7F /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
		D66840101F9DDD7500D1DE7F /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = "<group>"; };
		D66840111F9DDD7500D1DE7F /* Shape.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shape.swift; sourceTree = "<group>"; };
		D66840121F9DDD7500D1DE7F /* Tensor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tensor.swift; sourceTree = "<group>"; };
		D66840131F9DDD7500D1DE7F /* TensorMath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TensorMath.swift; sourceTree = "<group>"; };
		D66840141F9DDD7500D1DE7F /* TensorNN.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TensorNN.swift; sourceTree = "<group>"; };
		D66840151F9DDD7500D1DE7F /* TensorSwift.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TensorSwift.h; sourceTree = "<group>"; };
		D66840161F9DDD7500D1DE7F /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
		D668401F1F9DE8DF00D1DE7F /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = "<group>"; };
		D66840201F9DE8DF00D1DE7F /* ClassifierTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClassifierTests.swift; sourceTree = "<group>"; };
		D66840211F9DE8DF00D1DE7F /* Downloader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Downloader.swift; sourceTree = "<group>"; };
		D66840221F9DE8DF00D1DE7F /* DownloaderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloaderTests.swift; sourceTree = "<group>"; };
		D66840231F9DE8DF00D1DE7F /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
		D66840241F9DE8DF00D1DE7F /* MNISTTests-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MNISTTests-Bridging-Header.h"; sourceTree = "<group>"; };
		D66840261F9DE8DF00D1DE7F /* SHA1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SHA1.swift; sourceTree = "<group>"; };
		D668402F1F9DE8F000D1DE7F /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
		D66840301F9DE8F000D1DE7F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
		D66840321F9DE8F000D1DE7F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
		D66840341F9DE8F000D1DE7F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
		D66840351F9DE8F000D1DE7F /* Canvas.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Canvas.swift; sourceTree = "<group>"; };
		D66840361F9DE8F000D1DE7F /* CanvasView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CanvasView.swift; sourceTree = "<group>"; };
		D66840371F9DE8F000D1DE7F /* Classifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Classifier.swift; sourceTree = "<group>"; };
		D66840381F9DE8F000D1DE7F /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
		D66840391F9DE8F000D1DE7F /* Line.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = "<group>"; };
		D668403B1F9DE8F000D1DE7F /* b_conv1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = b_conv1; sourceTree = "<group>"; };
		D668403C1F9DE8F000D1DE7F /* b_conv2 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = b_conv2; sourceTree = "<group>"; };
		D668403D1F9DE8F000D1DE7F /* b_fc1 */ = {isa = PBXFileReference; lastKnownFileType = file; path = b_fc1; sourceTree = "<group>"; };
		D668403E1F9DE8F000D1DE7F /* b_fc2 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = b_fc2; sourceTree = "<group>"; };
		D668403F1F9DE8F000D1DE7F /* W_conv1 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = W_conv1; sourceTree = "<group>"; };
		D66840401F9DE8F000D1DE7F /* W_conv2 */ = {isa = PBXFileReference; lastKnownFileType = file; path = W_conv2; sourceTree = "<group>"; };
		D66840411F9DE8F000D1DE7F /* W_fc1 */ = {isa = PBXFileReference; lastKnownFileType = file; path = W_fc1; sourceTree = "<group>"; };
		D66840421F9DE8F000D1DE7F /* W_fc2 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = W_fc2; sourceTree = "<group>"; };
		D66840431F9DE8F000D1DE7F /* String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
		D66840441F9DE8F000D1DE7F /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
		__PBXFileRef_Package.swift /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
		__PBXFileRef_Resources /* Resources */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Resources; sourceTree = "<group>"; };
		__PBXFileRef_TensorSwift.xcodeproj/Configs/Project.xcconfig /* TensorSwift.xcodeproj/Configs/Project.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = TensorSwift.xcodeproj/Configs/Project.xcconfig; sourceTree = "<group>"; };
		"_____Product_TensorSwift" /* TensorSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = TensorSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
		"_____Product_TensorSwiftTests" /* TensorSwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = TensorSwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
		A7C387A31D9F604900091506 /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 2147483647;
			files = (
				A7C387DE1D9F611D00091506 /* TensorSwift.framework in Frameworks */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
		A7C387B61D9F604900091506 /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 2147483647;
			files = (
				A7C388031D9F629A00091506 /* libz.tbd in Frameworks */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
		"___LinkPhase_TensorSwift" /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 0;
			files = (
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
		"___LinkPhase_TensorSwiftTests" /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 0;
			files = (
				_LinkFileRef_TensorSwift_via_TensorSwiftTests /* TensorSwift.framework in Frameworks */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
		A7C387FF1D9F619000091506 /* Frameworks */ = {
			isa = PBXGroup;
			children = (
				A7C388001D9F619000091506 /* libz.tbd */,
			);
			name = Frameworks;
			sourceTree = "<group>";
		};
		D668400D1F9DDD7500D1DE7F /* TensorSwift */ = {
			isa = PBXGroup;
			children = (
				D668400E1F9DDD7500D1DE7F /* Dimension.swift */,
				D668400F1F9DDD7500D1DE7F /* Info.plist */,
				D66840101F9DDD7500D1DE7F /* Operators.swift */,
				D66840111F9DDD7500D1DE7F /* Shape.swift */,
				D66840121F9DDD7500D1DE7F /* Tensor.swift */,
				D66840131F9DDD7500D1DE7F /* TensorMath.swift */,
				D66840141F9DDD7500D1DE7F /* TensorNN.swift */,
				D66840151F9DDD7500D1DE7F /* TensorSwift.h */,
				D66840161F9DDD7500D1DE7F /* Utils.swift */,
			);
			name = TensorSwift;
			path = Sources/TensorSwift;
			sourceTree = "<group>";
		};
		D668401E1F9DE8DF00D1DE7F /* MNISTTests */ = {
			isa = PBXGroup;
			children = (
				D668401F1F9DE8DF00D1DE7F /* Array.swift */,
				D66840201F9DE8DF00D1DE7F /* ClassifierTests.swift */,
				D66840211F9DE8DF00D1DE7F /* Downloader.swift */,
				D66840221F9DE8DF00D1DE7F /* DownloaderTests.swift */,
				D66840231F9DE8DF00D1DE7F /* Info.plist */,
				D66840241F9DE8DF00D1DE7F /* MNISTTests-Bridging-Header.h */,
				D66840261F9DE8DF00D1DE7F /* SHA1.swift */,
			);
			name = MNISTTests;
			path = Tests/MNISTTests;
			sourceTree = "<group>";
		};
		D668402E1F9DE8F000D1DE7F /* MNIST */ = {
			isa = PBXGroup;
			children = (
				D668402F1F9DE8F000D1DE7F /* AppDelegate.swift */,
				D66840301F9DE8F000D1DE7F /* Assets.xcassets */,
				D66840311F9DE8F000D1DE7F /* LaunchScreen.storyboard */,
				D66840331F9DE8F000D1DE7F /* Main.storyboard */,
				D66840351F9DE8F000D1DE7F /* Canvas.swift */,
				D66840361F9DE8F000D1DE7F /* CanvasView.swift */,
				D66840371F9DE8F000D1DE7F /* Classifier.swift */,
				D66840381F9DE8F000D1DE7F /* Info.plist */,
				D66840391F9DE8F000D1DE7F /* Line.swift */,
				D668403A1F9DE8F000D1DE7F /* Models */,
				D66840431F9DE8F000D1DE7F /* String.swift */,
				D66840441F9DE8F000D1DE7F /* ViewController.swift */,
			);
			name = MNIST;
			path = Sources/MNIST;
			sourceTree = "<group>";
		};
		D668403A1F9DE8F000D1DE7F /* Models */ = {
			isa = PBXGroup;
			children = (
				D668403B1F9DE8F000D1DE7F /* b_conv1 */,
				D668403C1F9DE8F000D1DE7F /* b_conv2 */,
				D668403D1F9DE8F000D1DE7F /* b_fc1 */,
				D668403E1F9DE8F000D1DE7F /* b_fc2 */,
				D668403F1F9DE8F000D1DE7F /* W_conv1 */,
				D66840401F9DE8F000D1DE7F /* W_conv2 */,
				D66840411F9DE8F000D1DE7F /* W_fc1 */,
				D66840421F9DE8F000D1DE7F /* W_fc2 */,
			);
			path = Models;
			sourceTree = "<group>";
		};
		TestProducts_ /* Tests */ = {
			isa = PBXGroup;
			children = (
				"_____Product_TensorSwiftTests" /* TensorSwiftTests.xctest */,
			);
			name = Tests;
			sourceTree = "<group>";
		};
		"___RootGroup_" = {
			isa = PBXGroup;
			children = (
				__PBXFileRef_Package.swift /* Package.swift */,
				"_____Configs_" /* Configs */,
				"_____Sources_" /* Sources */,
				__PBXFileRef_Resources /* Resources */,
				"_______Tests_" /* Tests */,
				"____Products_" /* Products */,
				A7C387FF1D9F619000091506 /* Frameworks */,
			);
			sourceTree = "<group>";
		};
		"____Products_" /* Products */ = {
			isa = PBXGroup;
			children = (
				TestProducts_ /* Tests */,
				"_____Product_TensorSwift" /* TensorSwift.framework */,
				A7C387A61D9F604900091506 /* MNIST.app */,
				A7C387B91D9F604900091506 /* MNISTTests.xctest */,
			);
			name = Products;
			sourceTree = "<group>";
		};
		"_____Configs_" /* Configs */ = {
			isa = PBXGroup;
			children = (
				__PBXFileRef_TensorSwift.xcodeproj/Configs/Project.xcconfig /* TensorSwift.xcodeproj/Configs/Project.xcconfig */,
			);
			name = Configs;
			sourceTree = "<group>";
		};
		"_____Sources_" /* Sources */ = {
			isa = PBXGroup;
			children = (
				D668400D1F9DDD7500D1DE7F /* TensorSwift */,
				D668402E1F9DE8F000D1DE7F /* MNIST */,
			);
			name = Sources;
			sourceTree = "<group>";
		};
		"_______Group_TensorSwiftTests" /* TensorSwiftTests */ = {
			isa = PBXGroup;
			children = (
				A7DF6F8E1D9BB9660097CEB7 /* TensorSwiftTests.swift */,
				A7DF6F811D9BB9240097CEB7 /* CalculationPerformanceTests.swift */,
				A7DF6F821D9BB9240097CEB7 /* DimensionTests.swift */,
				A7DF6F841D9BB9240097CEB7 /* PowerTests.swift */,
				D646CEF51DBE1A25003E8A59 /* TensorMathTest.swift */,
				A7DF6F851D9BB9240097CEB7 /* TensorNNTests.swift */,
				A7DF6F861D9BB9240097CEB7 /* TensorSwiftSample.swift */,
				A7DF6F871D9BB9240097CEB7 /* TensorTests.swift */,
			);
			name = TensorSwiftTests;
			path = Tests/TensorSwiftTests;
			sourceTree = "<group>";
		};
		"_______Tests_" /* Tests */ = {
			isa = PBXGroup;
			children = (
				"_______Group_TensorSwiftTests" /* TensorSwiftTests */,
				D668401E1F9DE8DF00D1DE7F /* MNISTTests */,
			);
			name = Tests;
			sourceTree = "<group>";
		};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
		A7C387A51D9F604900091506 /* MNIST */ = {
			isa = PBXNativeTarget;
			buildConfigurationList = A7C387D11D9F604A00091506 /* Build configuration list for PBXNativeTarget "MNIST" */;
			buildPhases = (
				A7C387A21D9F604900091506 /* Sources */,
				A7C387A31D9F604900091506 /* Frameworks */,
				A7C387A41D9F604900091506 /* Resources */,
				A7C387E21D9F611E00091506 /* Embed Frameworks */,
			);
			buildRules = (
			);
			dependencies = (
				A7C387E11D9F611D00091506 /* PBXTargetDependency */,
			);
			name = MNIST;
			productName = MNIST;
			productReference = A7C387A61D9F604900091506 /* MNIST.app */;
			productType = "com.apple.product-type.application";
		};
		A7C387B81D9F604900091506 /* MNISTTests */ = {
			isa = PBXNativeTarget;
			buildConfigurationList = A7C387D21D9F604A00091506 /* Build configuration list for PBXNativeTarget "MNISTTests" */;
			buildPhases = (
				A7C387B51D9F604900091506 /* Sources */,
				A7C387B61D9F604900091506 /* Frameworks */,
				A7C387B71D9F604900091506 /* Resources */,
			);
			buildRules = (
			);
			dependencies = (
				A7C387BB1D9F604900091506 /* PBXTargetDependency */,
			);
			name = MNISTTests;
			productName = MNISTTests;
			productReference = A7C387B91D9F604900091506 /* MNISTTests.xctest */;
			productType = "com.apple.product-type.bundle.unit-test";
		};
		"______Target_TensorSwift" /* TensorSwift */ = {
			isa = PBXNativeTarget;
			buildConfigurationList = "_______Confs_TensorSwift" /* Build configuration list for PBXNativeTarget "TensorSwift" */;
			buildPhases = (
				CompilePhase_TensorSwift /* Sources */,
				"___LinkPhase_TensorSwift" /* Frameworks */,
			);
			buildRules = (
			);
			dependencies = (
			);
			name = TensorSwift;
			productName = TensorSwift;
			productReference = "_____Product_TensorSwift" /* TensorSwift.framework */;
			productType = "com.apple.product-type.framework";
		};
		"______Target_TensorSwiftTests" /* TensorSwiftTests */ = {
			isa = PBXNativeTarget;
			buildConfigurationList = "_______Confs_TensorSwiftTests" /* Build configuration list for PBXNativeTarget "TensorSwiftTests" */;
			buildPhases = (
				CompilePhase_TensorSwiftTests /* Sources */,
				"___LinkPhase_TensorSwiftTests" /* Frameworks */,
			);
			buildRules = (
			);
			dependencies = (
				__Dependency_TensorSwift /* PBXTargetDependency */,
			);
			name = TensorSwiftTests;
			productName = TensorSwiftTests;
			productReference = "_____Product_TensorSwiftTests" /* TensorSwiftTests.xctest */;
			productType = "com.apple.product-type.bundle.unit-test";
		};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
		__RootObject_ /* Project object */ = {
			isa = PBXProject;
			attributes = {
				LastSwiftUpdateCheck = 0800;
				LastUpgradeCheck = 0900;
				TargetAttributes = {
					A7C387A51D9F604900091506 = {
						CreatedOnToolsVersion = 8.0;
						DevelopmentTeam = 3B8C483UAP;
						LastSwiftMigration = 0900;
						ProvisioningStyle = Automatic;
					};
					A7C387B81D9F604900091506 = {
						CreatedOnToolsVersion = 8.0;
						DevelopmentTeam = 3B8C483UAP;
						LastSwiftMigration = 0900;
						ProvisioningStyle = Automatic;
						TestTargetID = A7C387A51D9F604900091506;
					};
					"______Target_TensorSwift" = {
						LastSwiftMigration = 0900;
					};
					"______Target_TensorSwiftTests" = {
						LastSwiftMigration = 0800;
					};
				};
			};
			buildConfigurationList = "___RootConfs_" /* Build configuration list for PBXProject "TensorSwift" */;
			compatibilityVersion = "Xcode 3.2";
			developmentRegion = English;
			hasScannedForEncodings = 0;
			knownRegions = (
				en,
				Base,
			);
			mainGroup = "___RootGroup_";
			productRefGroup = "____Products_" /* Products */;
			projectDirPath = "";
			projectRoot = "";
			targets = (
				"______Target_TensorSwift" /* TensorSwift */,
				"______Target_TensorSwiftTests" /* TensorSwiftTests */,
				A7C387A51D9F604900091506 /* MNIST */,
				A7C387B81D9F604900091506 /* MNISTTests */,
			);
		};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
		A7C387A41D9F604900091506 /* Resources */ = {
			isa = PBXResourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				D66840541F9DE8F000D1DE7F /* W_fc1 in Resources */,
				D66840521F9DE8F000D1DE7F /* W_conv1 in Resources */,
				D668404F1F9DE8F000D1DE7F /* b_conv2 in Resources */,
				D66840511F9DE8F000D1DE7F /* b_fc2 in Resources */,
				D668404E1F9DE8F000D1DE7F /* b_conv1 in Resources */,
				D66840551F9DE8F000D1DE7F /* W_fc2 in Resources */,
				D66840501F9DE8F000D1DE7F /* b_fc1 in Resources */,
				D66840481F9DE8F000D1DE7F /* Main.storyboard in Resources */,
				D66840461F9DE8F000D1DE7F /* Assets.xcassets in Resources */,
				D66840471F9DE8F000D1DE7F /* LaunchScreen.storyboard in Resources */,
				D66840531F9DE8F000D1DE7F /* W_conv2 in Resources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
		A7C387B71D9F604900091506 /* Resources */ = {
			isa = PBXResourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
		A7C387A21D9F604900091506 /* Sources */ = {
			isa = PBXSourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				D66840561F9DE8F000D1DE7F /* String.swift in Sources */,
				D668404B1F9DE8F000D1DE7F /* Classifier.swift in Sources */,
				D66840451F9DE8F000D1DE7F /* AppDelegate.swift in Sources */,
				D66840491F9DE8F000D1DE7F /* Canvas.swift in Sources */,
				D66840571F9DE8F000D1DE7F /* ViewController.swift in Sources */,
				D668404A1F9DE8F000D1DE7F /* CanvasView.swift in Sources */,
				D668404D1F9DE8F000D1DE7F /* Line.swift in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
		A7C387B51D9F604900091506 /* Sources */ = {
			isa = PBXSourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				D66840281F9DE8DF00D1DE7F /* ClassifierTests.swift in Sources */,
				D66840271F9DE8DF00D1DE7F /* Array.swift in Sources */,
				D668402D1F9DE8DF00D1DE7F /* SHA1.swift in Sources */,
				D668402A1F9DE8DF00D1DE7F /* DownloaderTests.swift in Sources */,
				D66840291F9DE8DF00D1DE7F /* Downloader.swift in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
		CompilePhase_TensorSwift /* Sources */ = {
			isa = PBXSourcesBuildPhase;
			buildActionMask = 0;
			files = (
				D66840171F9DDD7500D1DE7F /* Dimension.swift in Sources */,
				D66840191F9DDD7500D1DE7F /* Shape.swift in Sources */,
				D668401C1F9DDD7500D1DE7F /* TensorNN.swift in Sources */,
				D668401D1F9DDD7500D1DE7F /* Utils.swift in Sources */,
				D668401A1F9DDD7500D1DE7F /* Tensor.swift in Sources */,
				D66840181F9DDD7500D1DE7F /* Operators.swift in Sources */,
				D668401B1F9DDD7500D1DE7F /* TensorMath.swift in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
		CompilePhase_TensorSwiftTests /* Sources */ = {
			isa = PBXSourcesBuildPhase;
			buildActionMask = 0;
			files = (
				A7C046091D9F514600FAF16F /* TensorSwiftTests.swift in Sources */,
				A7C0460A1D9F514600FAF16F /* CalculationPerformanceTests.swift in Sources */,
				A7C0460B1D9F514600FAF16F /* DimensionTests.swift in Sources */,
				A7C0460C1D9F514600FAF16F /* PowerTests.swift in Sources */,
				D646CEF61DBE1A25003E8A59 /* TensorMathTest.swift in Sources */,
				A7C0460D1D9F514600FAF16F /* TensorNNTests.swift in Sources */,
				A7C0460E1D9F514600FAF16F /* TensorSwiftSample.swift in Sources */,
				A7C0460F1D9F514600FAF16F /* TensorTests.swift in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
		A7C387BB1D9F604900091506 /* PBXTargetDependency */ = {
			isa = PBXTargetDependency;
			target = A7C387A51D9F604900091506 /* MNIST */;
			targetProxy = A7C387BA1D9F604900091506 /* PBXContainerItemProxy */;
		};
		A7C387E11D9F611D00091506 /* PBXTargetDependency */ = {
			isa = PBXTargetDependency;
			target = "______Target_TensorSwift" /* TensorSwift */;
			targetProxy = A7C387E01D9F611D00091506 /* PBXContainerItemProxy */;
		};
		__Dependency_TensorSwift /* PBXTargetDependency */ = {
			isa = PBXTargetDependency;
			target = "______Target_TensorSwift" /* TensorSwift */;
			targetProxy = A7DF6EB61D9A1AC40097CEB7 /* PBXContainerItemProxy */;
		};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
		D66840311F9DE8F000D1DE7F /* LaunchScreen.storyboard */ = {
			isa = PBXVariantGroup;
			children = (
				D66840321F9DE8F000D1DE7F /* Base */,
			);
			name = LaunchScreen.storyboard;
			sourceTree = "<group>";
		};
		D66840331F9DE8F000D1DE7F /* Main.storyboard */ = {
			isa = PBXVariantGroup;
			children = (
				D66840341F9DE8F000D1DE7F /* Base */,
			);
			name = Main.storyboard;
			sourceTree = "<group>";
		};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
		A7C387CB1D9F604A00091506 /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
				ALWAYS_SEARCH_USER_PATHS = NO;
				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
				CLANG_ANALYZER_NONNULL = YES;
				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_SUSPICIOUS_MOVES = YES;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
				COPY_PHASE_STRIP = NO;
				DEBUG_INFORMATION_FORMAT = dwarf;
				DEVELOPMENT_TEAM = 3B8C483UAP;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				ENABLE_TESTABILITY = YES;
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_NO_COMMON_BLOCKS = YES;
				GCC_OPTIMIZATION_LEVEL = 0;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"DEBUG=1",
					"$(inherited)",
				);
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				INFOPLIST_FILE = Sources/MNIST/Info.plist;
				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
				MTL_ENABLE_DEBUG_INFO = YES;
				ONLY_ACTIVE_ARCH = YES;
				PRODUCT_BUNDLE_IDENTIFIER = jp.co.qoncept.MNIST;
				PRODUCT_NAME = "$(TARGET_NAME)";
				SDKROOT = iphoneos;
				SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
				SWIFT_SWIFT3_OBJC_INFERENCE = Default;
				SWIFT_VERSION = 4.0;
				TARGETED_DEVICE_FAMILY = "1,2";
			};
			name = Debug;
		};
		A7C387CC1D9F604A00091506 /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
				ALWAYS_SEARCH_USER_PATHS = NO;
				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
				CLANG_ANALYZER_NONNULL = YES;
				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_SUSPICIOUS_MOVES = YES;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
				COPY_PHASE_STRIP = NO;
				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
				DEVELOPMENT_TEAM = 3B8C483UAP;
				ENABLE_NS_ASSERTIONS = NO;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_NO_COMMON_BLOCKS = YES;
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				INFOPLIST_FILE = Sources/MNIST/Info.plist;
				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
				MTL_ENABLE_DEBUG_INFO = NO;
				PRODUCT_BUNDLE_IDENTIFIER = jp.co.qoncept.MNIST;
				PRODUCT_NAME = "$(TARGET_NAME)";
				SDKROOT = iphoneos;
				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
				SWIFT_SWIFT3_OBJC_INFERENCE = Default;
				SWIFT_VERSION = 4.0;
				TARGETED_DEVICE_FAMILY = "1,2";
				VALIDATE_PRODUCT = YES;
			};
			name = Release;
		};
		A7C387CD1D9F604A00091506 /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
				ALWAYS_SEARCH_USER_PATHS = NO;
				BUNDLE_LOADER = "$(TEST_HOST)";
				CLANG_ANALYZER_NONNULL = YES;
				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_SUSPICIOUS_MOVES = YES;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
				COPY_PHASE_STRIP = NO;
				DEBUG_INFORMATION_FORMAT = dwarf;
				DEVELOPMENT_TEAM = 3B8C483UAP;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				ENABLE_TESTABILITY = YES;
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_NO_COMMON_BLOCKS = YES;
				GCC_OPTIMIZATION_LEVEL = 0;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"DEBUG=1",
					"$(inherited)",
				);
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				INFOPLIST_FILE = Tests/MNISTTests/Info.plist;
				IPHONEOS_DEPLOYMENT_TARGET = 10.0;
				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
				MTL_ENABLE_DEBUG_INFO = YES;
				ONLY_ACTIVE_ARCH = YES;
				PRODUCT_BUNDLE_IDENTIFIER = jp.co.qoncept.MNISTTests;
				PRODUCT_NAME = "$(TARGET_NAME)";
				SDKROOT = iphoneos;
				SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
				SWIFT_OBJC_BRIDGING_HEADER = "Tests/MNISTTests/MNISTTests-Bridging-Header.h";
				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
				SWIFT_SWIFT3_OBJC_INFERENCE = Default;
				SWIFT_VERSION = 4.0;
				TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MNIST.app/MNIST";
			};
			name = Debug;
		};
		A7C387CE1D9F604A00091506 /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
				ALWAYS_SEARCH_USER_PATHS = NO;
				BUNDLE_LOADER = "$(TEST_HOST)";
				CLANG_ANALYZER_NONNULL = YES;
				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_SUSPICIOUS_MOVES = YES;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
				COPY_PHASE_STRIP = NO;
				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
				DEVELOPMENT_TEAM = 3B8C483UAP;
				ENABLE_NS_ASSERTIONS = NO;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				GCC_C_LANGUAGE_STANDARD = gnu99;
				GCC_NO_COMMON_BLOCKS = YES;
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				INFOPLIST_FILE = Tests/MNISTTests/Info.plist;
				IPHONEOS_DEPLOYMENT_TARGET = 10.0;
				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
				MTL_ENABLE_DEBUG_INFO = NO;
				PRODUCT_BUNDLE_IDENTIFIER = jp.co.qoncept.MNISTTests;
				PRODUCT_NAME = "$(TARGET_NAME)";
				SDKROOT = iphoneos;
				SWIFT_OBJC_BRIDGING_HEADER = "Tests/MNISTTests/MNISTTests-Bridging-Header.h";
				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
				SWIFT_SWIFT3_OBJC_INFERENCE = Default;
				SWIFT_VERSION = 4.0;
				TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MNIST.app/MNIST";
				VALIDATE_PRODUCT = YES;
			};
			name = Release;
		};
		_ReleaseConf_TensorSwift /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				DEVELOPMENT_TEAM = 3B8C483UAP;
				ENABLE_TESTABILITY = YES;
				FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks";
				INFOPLIST_FILE = TensorSwift.xcodeproj/TensorSwift_Info.plist;
				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
				LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
				OTHER_LDFLAGS = "$(inherited)";
				OTHER_SWIFT_FLAGS = "$(inherited)";
				PRODUCT_BUNDLE_IDENTIFIER = TensorSwift;
				PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
				PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
				SWIFT_SWIFT3_OBJC_INFERENCE = Default;
				SWIFT_VERSION = 4.0;
			};
			name = Release;
		};
		_ReleaseConf_TensorSwiftTests /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
				CLANG_ENABLE_MODULES = YES;
				FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks";
				INFOPLIST_FILE = TensorSwift.xcodeproj/TensorSwiftTests_Info.plist;
				LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
				OTHER_LDFLAGS = "$(inherited)";
				OTHER_SWIFT_FLAGS = "$(inherited)";
				SWIFT_VERSION = 3.0;
			};
			name = Release;
		};
		"___DebugConf_TensorSwift" /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				DEVELOPMENT_TEAM = "";
				ENABLE_TESTABILITY = YES;
				FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks";
				INFOPLIST_FILE = TensorSwift.xcodeproj/TensorSwift_Info.plist;
				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
				LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
				OTHER_LDFLAGS = "$(inherited)";
				OTHER_SWIFT_FLAGS = "$(inherited)";
				PRODUCT_BUNDLE_IDENTIFIER = TensorSwift;
				PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
				PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
				SWIFT_SWIFT3_OBJC_INFERENCE = Default;
				SWIFT_VERSION = 4.0;
			};
			name = Debug;
		};
		"___DebugConf_TensorSwiftTests" /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
				CLANG_ENABLE_MODULES = YES;
				FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks";
				INFOPLIST_FILE = TensorSwift.xcodeproj/TensorSwiftTests_Info.plist;
				LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
				OTHER_LDFLAGS = "$(inherited)";
				OTHER_SWIFT_FLAGS = "$(inherited)";
				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
				SWIFT_VERSION = 3.0;
			};
			name = Debug;
		};
		"_____Release_" /* Release */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = __PBXFileRef_TensorSwift.xcodeproj/Configs/Project.xcconfig /* TensorSwift.xcodeproj/Configs/Project.xcconfig */;
			buildSettings = {
				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_COMMA = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
				CLANG_WARN_STRICT_PROTOTYPES = YES;
				CLANG_WARN_SUSPICIOUS_MOVE = YES;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				GCC_NO_COMMON_BLOCKS = YES;
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
			};
			name = Release;
		};
		"_______Debug_" /* Debug */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = __PBXFileRef_TensorSwift.xcodeproj/Configs/Project.xcconfig /* TensorSwift.xcodeproj/Configs/Project.xcconfig */;
			buildSettings = {
				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_COMMA = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
				CLANG_WARN_STRICT_PROTOTYPES = YES;
				CLANG_WARN_SUSPICIOUS_MOVE = YES;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				ENABLE_TESTABILITY = YES;
				GCC_NO_COMMON_BLOCKS = YES;
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				ONLY_ACTIVE_ARCH = YES;
			};
			name = Debug;
		};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
		A7C387D11D9F604A00091506 /* Build configuration list for PBXNativeTarget "MNIST" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				A7C387CB1D9F604A00091506 /* Debug */,
				A7C387CC1D9F604A00091506 /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
		A7C387D21D9F604A00091506 /* Build configuration list for PBXNativeTarget "MNISTTests" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				A7C387CD1D9F604A00091506 /* Debug */,
				A7C387CE1D9F604A00091506 /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
		"___RootConfs_" /* Build configuration list for PBXProject "TensorSwift" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				"_______Debug_" /* Debug */,
				"_____Release_" /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
		"_______Confs_TensorSwift" /* Build configuration list for PBXNativeTarget "TensorSwift" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				"___DebugConf_TensorSwift" /* Debug */,
				_ReleaseConf_TensorSwift /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
		"_______Confs_TensorSwiftTests" /* Build configuration list for PBXNativeTarget "TensorSwiftTests" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				"___DebugConf_TensorSwiftTests" /* Debug */,
				_ReleaseConf_TensorSwiftTests /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Debug;
		};
/* End XCConfigurationList section */
	};
	rootObject = __RootObject_ /* Project object */;
}


================================================
FILE: TensorSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata
================================================
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
   version = "1.0">
   <FileRef
      location = "self:">
   </FileRef>
</Workspace>


================================================
FILE: Tests/LinuxMain.swift
================================================
import XCTest
@testable import TensorSwiftTests

XCTMain([
     testCase(TensorSwiftTests.allTests),
     testCase(DimensionTests.allTests),
     testCase(PowerTests.allTests),
     testCase(TensorTests.allTests),
     testCase(TensorNNTests.allTests),
     testCase(CalculationPerformanceTests.allTests),
     testCase(TensorSwiftSample.allTests),
])


================================================
FILE: Tests/MNISTTests/Array.swift
================================================
extension Array {
    func grouped(_ count: Int) -> [[Element]] {
        var result: [[Element]] = []
        var group: [Element] = []
        for element in self {
            group.append(element)
            if group.count == count {
                result.append(group)
                group = []
            }
        }
        return result
    }
}


================================================
FILE: Tests/MNISTTests/ClassifierTests.swift
================================================
import XCTest
import TensorSwift
@testable import MNIST

class ClassifierTests: XCTestCase {
    func testClassify() {
        
        let classifier = Classifier(path: Bundle(for: ViewController.self).resourcePath!)
        let (images, labels) = downloadTestData()
        
        let count = 1000
        
        let xArray: [[Float]] = images.withUnsafeBytes { ptr in
            [UInt8](UnsafeBufferPointer(start: UnsafePointer<UInt8>(ptr + 16), count: 28 * 28 * count))
                .map { Float($0) / 255.0 }
                .grouped(28 * 28)
        }
        
        let yArray: [Int] = labels.withUnsafeBytes { ptr in
            [UInt8](UnsafeBufferPointer(start: UnsafePointer<UInt8>(ptr + 8), count: count))
                .map { Int($0) }
        }
        
        let accuracy = Float(zip(xArray, yArray)
            .reduce(0) { $0 + (classifier.classify(Tensor(shape: [28, 28, 1], elements: $1.0)) == $1.1 ? 1 : 0) })
            / Float(yArray.count)
        
        print("accuracy: \(accuracy)")
        
        XCTAssertGreaterThan(accuracy, 0.97)
    }
}


================================================
FILE: Tests/MNISTTests/Downloader.swift
================================================
import Foundation

func downloadTestData() -> (images: Data, labels: Data) {
    let baseUrl = "http://yann.lecun.com/exdb/mnist/"
    
    let testImagesUrl = URL(string: baseUrl)!.appendingPathComponent("t10k-images-idx3-ubyte.gz")
    let testLabelsUrl = URL(string: baseUrl)!.appendingPathComponent("t10k-labels-idx1-ubyte.gz")
    
    print("download: \(testImagesUrl)")
    let testImages = try! Data(contentsOf: testImagesUrl)
    print("download: \(testLabelsUrl)")
    let testLabels = try! Data(contentsOf: testLabelsUrl)

    return (images: ungzip(testImages)!, labels: ungzip(testLabels)!)
}

private func ungzip(_ source: Data) -> Data? {
    guard source.count > 0 else {
        return nil
    }
    
    var stream: z_stream = z_stream.init(next_in: UnsafeMutablePointer<Bytef>(mutating: (source as NSData).bytes.bindMemory(to: Bytef.self, capacity: source.count)), avail_in: uint(source.count), total_in: 0, next_out: nil, avail_out: 0, total_out: 0, msg: nil, state: nil, zalloc: nil, zfree: nil, opaque: nil, data_type: 0, adler: 0, reserved: 0)
    guard inflateInit2_(&stream, MAX_WBITS + 32, ZLIB_VERSION, Int32(MemoryLayout<z_stream>.size)) == Z_OK else {
        return nil
    }
    
    let data = NSMutableData()
    
    while stream.avail_out == 0 {
        let bufferSize = 0x10000
        let buffer: UnsafeMutablePointer<Bytef> = UnsafeMutablePointer<Bytef>.allocate(capacity: bufferSize)
        stream.next_out = buffer
        stream.avail_out = uint(MemoryLayout.size(ofValue: buffer))
        inflate(&stream, Z_FINISH)
        let length: size_t = MemoryLayout.size(ofValue: buffer) - Int(stream.avail_out)
        if length > 0 {
            data.append(buffer, length: length)
        }
        buffer.deallocate(capacity: bufferSize)
    }
    
    inflateEnd(&stream)
    return (NSData(data: data as Data) as Data)
}


================================================
FILE: Tests/MNISTTests/DownloaderTests.swift
================================================
import XCTest

class DownloaderTests: XCTestCase {
    func testDownloadTestData() {
        let testData = downloadTestData()
        
        XCTAssertEqual(testData.images.count, 7840016)
        XCTAssertEqual(testData.images.sha1, "65e11ec1fd220343092a5070b58418b5c2644e26")
    }
}


================================================
FILE: Tests/MNISTTests/Info.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSExceptionDomains</key>
		<dict>
			<key>yann.lecun.com</key>
			<string></string>
		</dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
	</dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>en</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>BNDL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleVersion</key>
	<string>1</string>
</dict>
</plist>


================================================
FILE: Tests/MNISTTests/MNISTTests-Bridging-Header.h
================================================
#ifndef MNISTTests_Bridging_Header_h
#define MNISTTests_Bridging_Header_h

#import <CommonCrypto/CommonCrypto.h>
#import "zlib.h"

#endif /* MNISTTests_Bridging_Header_h */


================================================
FILE: Tests/MNISTTests/SHA1.swift
================================================
import Foundation

extension Data {
    var sha1: String {
        let data = self
        var digest = [UInt8](repeating: 0, count: Int(CC_SHA1_DIGEST_LENGTH))
        CC_SHA1((data as NSData).bytes, CC_LONG(data.count), &digest)
        let hexBytes = digest.map { String(format: "%02hhx", $0) }
        return hexBytes.joined(separator: "")
    }
}


================================================
FILE: Tests/TensorSwiftTests/CalculationPerformanceTests.swift
================================================
import XCTest
@testable import TensorSwift

private func getTensor1000x1000() -> Tensor {
    let elements = [Float](repeating: 0.1 ,count: 1000*1000)
    return Tensor(shape: [1000, 1000], elements: elements)
}

private func getTensor1x1000() -> Tensor {
    let elements = [Float](repeating: 0, count: 1000)
    return Tensor(shape: [1, 1000], elements: elements)
}

class CalculationPerformanceTests : XCTestCase {
    func testElementAccess(){
        let W = getTensor1000x1000()
        measure{
            for _ in 0..<100000{
                let _ = W[500,500]
            }
        }
    }
    
    func testElementAccessRaw(){
        let W = getTensor1000x1000()
        measure{
            for _ in 0..<100000{
                let _ = W.elements[500*W.shape.dimensions[1].value + 500]
            }
        }
    }
    
    func testMultiplication(){
        let W = getTensor1000x1000()
        let x = getTensor1x1000()
        
        measure{
            let _ = x.matmul(W)
        }
    }
    
    func testMultiplicationRaw() {
        let W = getTensor1000x1000()
        let x = getTensor1x1000()
        
        measure{
            let xRow = x.shape.dimensions[0].value
            let WRow = W.shape.dimensions[0].value
            let WColumn = W.shape.dimensions[1].value
            var elements = [Float](repeating: 0, count: 1000)
            for r in 0..<xRow {
                for i in 0..<WRow {
                    let tmp = x.elements[r * WRow + i]
                    for c in 0..<WColumn {
                        elements[r * WRow + c] = tmp * W.elements[i * WRow + c]
                    }
                }
            }
            let _ = Tensor(shape: [1,1000], elements: elements)
        }
    }
    
    static var allTests : [(String, (CalculationPerformanceTests) -> () throws -> Void)] {
        return [
            ("testElementAccess", testElementAccess),
            ("testElementAccessRaw", testElementAccessRaw),
            ("testElementMultiplication", testMultiplication),
            ("testElementMultiplicationRaw", testMultiplicationRaw),
        ]
    }
}


================================================
FILE: Tests/TensorSwiftTests/DimensionTests.swift
================================================
import XCTest
@testable import TensorSwift

class DimensionTests: XCTestCase {
    func testAdd() {
        do {
            let a = Dimension(2)
            let b = Dimension(3)
            XCTAssertEqual(a + b, 5)
        }
    }
    
    func testSub() {
        do {
            
            let a = Dimension(3)
            let b = Dimension(2)
            XCTAssertEqual(a - b, 1)
        }
    }

    func testMul() {
        do {
            let a = Dimension(2)
            let b = Dimension(3)
            XCTAssertEqual(a * b, 6)
        }
    }

    func testDiv() {
        do {
            let a = Dimension(6)
            let b = Dimension(2)
            XCTAssertEqual(a / b, 3)
        }
    }
    
    static var allTests : [(String, (DimensionTests) -> () throws -> Void)] {
        return [
            ("testAdd", testAdd),
            ("testSub", testSub),
            ("testMul", testMul),
            ("testDiv", testDiv),
        ]
    }
}


================================================
FILE: Tests/TensorSwiftTests/Info.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>en</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>BNDL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>1</string>
</dict>
</plist>


================================================
FILE: Tests/TensorSwiftTests/PowerTests.swift
================================================
import XCTest
@testable import TensorSwift

class PowerTests: XCTestCase {

    func testScalar() {
        let tensor = Tensor(shape: [2, 2], elements: [1, 2, 3, 4])
        let scalar = Tensor.Element(2)
        
        XCTAssertEqual(tensor ** scalar, Tensor(shape: [2, 2], elements: [1, 4, 9, 16]))
        XCTAssertEqual(scalar ** tensor, Tensor(shape: [2, 2], elements: [2, 4, 8, 16]))
        
        XCTAssertEqual(scalar ** tensor ** scalar, Tensor(shape: [2, 2], elements: [2, 16, 512, 65536]))
    }
    
    func testMatrices() {
        let tensor = Tensor(shape: [2, 2], elements: [1, 2, 3, 4])
        let tensor2 = Tensor(shape: [2, 2], elements: [2, 2, 2, 2])
        
        XCTAssertEqual(tensor ** tensor2, Tensor(shape: [2, 2], elements: [1, 4, 9, 16]))
        XCTAssertEqual(tensor ** tensor, Tensor(shape: [2, 2], elements: [1, 4, 27, 256]))
        
        XCTAssertEqual(tensor ** tensor2 ** tensor, Tensor(shape: [2, 2], elements: [1, 16, powf(3, 8), powf(4, 16)]))
    }

    static var allTests : [(String, (PowerTests) -> () throws -> Void)] {
        return [
            ("testScalar", testScalar),
            ("testMatrices", testMatrices),
        ]
    }
}


================================================
FILE: Tests/TensorSwiftTests/TensorMathTest.swift
================================================
import XCTest
@testable import TensorSwift

class TensorMathTest: XCTestCase {
    func testPow() {
        do {
            let a = Tensor(shape: [2, 3], elements: [1, 2, 3, 4, 5, 6])
            let b = Tensor(shape: [2, 3], elements: [6, 5, 4, 3, 2, 1])
            XCTAssertEqual(a ** b, Tensor(shape: [2, 3], elements: [1, 32, 81, 64, 25, 6]))
            XCTAssertEqual(b ** a, Tensor(shape: [2, 3], elements: [6, 25, 64, 81, 32, 1]))
        }
        
        do {
            let a = Tensor(shape: [2, 3, 2], elements: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
            let b = Tensor(shape: [2], elements: [2, 3])
            XCTAssertEqual(a ** b, Tensor(shape: [2, 3, 2], elements: [1, 8, 9, 64, 25, 216, 49, 512, 81, 1000, 121, 1728]))
            XCTAssertEqual(b ** a, Tensor(shape: [2, 3, 2], elements: [2, 9, 8, 81, 32, 729, 128, 6561, 512, 59049, 2048, 531441]))
        }
        
        do {
            let a = Tensor(shape: [2, 1, 3, 2], elements: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
            let b = Tensor(shape: [3, 2], elements: [6, 5, 4, 3, 2, 1])
            XCTAssertEqual(a ** b, Tensor(shape: [2, 1, 3, 2], elements: [1, 32, 81, 64, 25, 6, 117649, 32768, 6561, 1000, 121, 12]))
            XCTAssertEqual(b ** a, Tensor(shape: [2, 1, 3, 2], elements: [6, 25, 64, 81, 32, 1, 279936, 390625, 262144, 59049, 2048, 1]))
        }
        
        do {
            let a = Tensor(shape: [2, 3], elements: [1, 2, 3, 4, 5, 6])
            let b: Float = 2.0
            XCTAssertEqual(a ** b, Tensor(shape: [2, 3], elements: [1, 4, 9, 16, 25, 36]))
            XCTAssertEqual(b ** a, Tensor(shape: [2, 3], elements: [2, 4, 8, 16, 32, 64]))
        }
    }
    
    func testSigmoid() {
        do {
            let a = Tensor(shape: [2, 3], elements: [-10, -1, 0, 1, 10, 100])
            XCTAssertEqual(a.sigmoid(), Tensor(shape: [2, 3], elements: [4.53978719e-05, 2.68941432e-01, 5.00000000e-01, 7.31058598e-01, 9.99954581e-01, 1.00000000e+00]))
        }
    }
}


================================================
FILE: Tests/TensorSwiftTests/TensorNNTests.swift
================================================
import XCTest
@testable import TensorSwift

class TensorNNTests: XCTestCase {
    func testMaxPool() {
        do {
            let a = Tensor(shape: [2,3,1], elements: [0,1,2,3,4,5])
            let r = a.maxPool(kernelSize: [1,3,1], strides: [1,1,1])
            XCTAssertEqual(r, Tensor(shape: [2,3,1], elements: [1,2,2,4,5,5]))
        }

        do {
            let a = Tensor(shape: [2,2,2], elements: [0,1,2,3,4,5,6,7])
            
            do {
                let r = a.maxPool(kernelSize:[1,2,1], strides: [1,1,1])
                XCTAssertEqual(r, Tensor(shape: [2,2,2], elements: [2, 3, 2, 3, 6, 7, 6, 7]))
            }
            
            do {
                let r = a.maxPool(kernelSize:[1,2,1], strides: [1,2,1])
                XCTAssertEqual(r, Tensor(shape: [2,1,2], elements: [2, 3, 6, 7]))
            }
        }
    }
    
    func testConv2d() {
        do {
            let a = Tensor(shape: [2,4,1], elements: [1,2,3,4,5,6,7,8])
            
            do {
                let filter = Tensor(shape: [2,1,1,2], elements: [1,2,1,2])
                let result = a.conv2d(filter: filter, strides: [1,1,1])
                XCTAssertEqual(result, Tensor(shape: [2,4,2], elements: [6,12,8,16,10,20,12,24,5,10,6,12,7,14,8,16]))
            }
            
            do {
                let filter = Tensor(shape: [1,1,1,5], elements: [1,2,1,2,3])
                let result = a.conv2d(filter: filter, strides: [1,1,1])
                XCTAssertEqual(result, Tensor(shape: [2,4,5], elements: [1,2,1,2,3,2,4,2,4,6,3,6,3,6,9,4,8,4,8,12,5,10,5,10,15,6,12,6,12,18,7,14,7,14,21,8,16,8,16,24]))
            }
        }
        
        do {
            let a = Tensor(shape: [2,2,4], elements: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])
            let filter = Tensor(shape: [1,1,4,2], elements: [1,2,1,2,3,2,1,1])
            let result = a.conv2d(filter: filter, strides: [1,1,1])
            XCTAssertEqual(result, Tensor(shape: [2,2,2], elements: [16, 16, 40, 44, 64, 72, 88, 100]))
        }
        
        do {
            let a = Tensor(shape: [4,2,2], elements: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])
            let filter = Tensor(shape: [2,2,2,1], elements: [1,2,1,2,3,2,1,1])
            let result = a.conv2d(filter: filter, strides: [2,2,1])
            XCTAssertEqual(result, Tensor(shape: [2,1,1], elements: [58,162]))
        }
        
        do {
            let a = Tensor(shape: [4,4,1], elements: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])
            let filter = Tensor(shape: [3,3,1,1], elements: [1,2,1,2,3,2,1,1,1])
            let result = a.conv2d(filter: filter, strides: [3,3,1])
            XCTAssertEqual(result, Tensor(shape: [2,2,1], elements: [18,33,95,113]))
        }
        
        do {
            let a = Tensor(shape: [1,3,1], elements: [1,2,3])
            let filter = Tensor(shape: [1,3,1,2], elements: [1,1,2,2,3,3])
            let result = a.conv2d(filter: filter, strides: [1,1,1])
            XCTAssertEqual(result, Tensor(shape: [1,3,2], elements: [8, 8, 14, 14, 8, 8]))
        }
    }
    
    func testMaxPoolPerformance(){
        let image = Tensor(shape: [28,28,3], element: 0.1)
        measure{
            _ = image.maxPool(kernelSize: [2,2,1], strides: [2,2,1])
        }
    }
    
    func testConv2dPerformance(){
        let image = Tensor(shape: [28,28,1], element: 0.1)
        let filter = Tensor(shape: [5,5,1,16], element: 0.1)
        measure{
            _ = image.conv2d(filter: filter, strides: [1,1,1])
        }
    }
    
    static var allTests : [(String, (TensorNNTests) -> () throws -> Void)] {
        return [
            ("testMaxPool", testMaxPool),
            ("testConv2d", testConv2d),
            ("testMaxPoolPerformance", testMaxPoolPerformance),
            ("testConv2dPerformance", testConv2dPerformance),
        ]
    }
}


================================================
FILE: Tests/TensorSwiftTests/TensorSwiftSample.swift
================================================
import XCTest
import TensorSwift

class TensorSwiftSample: XCTestCase {
    func testSample() {
        let a = Tensor(shape: [2, 3], elements: [1, 2, 3, 4, 5, 6])
        let b = Tensor(shape: [2, 3], elements: [7, 8, 9, 10, 11, 12])
        let sum = a + b // Tensor(shape: [2, 3], elements: [8, 10, 12, 14, 16, 18])
        let mul = a * b // Tensor(shape: [2, 3], elements: [7, 16, 27, 40, 55, 72])
        
        let c = Tensor(shape: [3, 1], elements: [7, 8, 9])
        let matmul = a.matmul(c) // Tensor(shape: [2, 1], elements: [50, 122])
        
        let zeros = Tensor(shape: [2, 3, 4])
        let ones = Tensor(shape: [2, 3, 4], element: 1)
        
        XCTAssertEqual(sum, Tensor(shape: [2, 3], elements: [8, 10, 12, 14, 16, 18]))
        XCTAssertEqual(mul, Tensor(shape: [2, 3], elements: [7, 16, 27, 40, 55, 72]))
        XCTAssertEqual(matmul, Tensor(shape: [2, 1], elements: [50, 122]))
        XCTAssertEqual(zeros, Tensor(shape: [2, 3, 4], elements: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]))
        XCTAssertEqual(ones, Tensor(shape: [2, 3, 4], elements: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]))
    }
    
    static var allTests : [(String, (TensorSwiftSample) -> () throws -> Void)] {
        return [
            ("testSample", testSample),
        ]
    }
}


================================================
FILE: Tests/TensorSwiftTests/TensorSwiftTests.swift
================================================
//
//  TensorSwiftTests.swift
//  TensorSwift
//
//  Created by Araki Takehiro on 2016/09/28.
//
//

import XCTest

class TensorSwiftTests: XCTestCase {
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
    static var allTests : [(String, (TensorSwiftTests) -> () throws -> Void)] {
        return [
            
        ]
    }
}


================================================
FILE: Tests/TensorSwiftTests/TensorTests.swift
================================================
import XCTest
@testable import TensorSwift

class TensorTests: XCTestCase {
    func testIndex() {
        do {
            let a = Tensor(shape: [])
            XCTAssertEqual(a.index([]), 0)
        }
        
        do {
            let a = Tensor(shape: [7])
            XCTAssertEqual(a.index([3]), 3)
        }
        
        do {
            let a = Tensor(shape: [5, 7])
            XCTAssertEqual(a.index([1, 2]), 9)
        }
        
        do {
            let a = Tensor(shape: [5, 7, 11])
            XCTAssertEqual(a.index([3, 1, 2]), 244)
        }
    }
    
    func testAdd() {
        do {
            let a = Tensor(shape: [2, 3], elements: [1, 2, 3, 4, 5, 6])
            let b = Tensor(shape: [2, 3], elements: [7, 8, 9, 10, 11, 12])
            let r = a + b
            XCTAssertEqual(r, Tensor(shape: [2, 3], elements: [8, 10, 12, 14, 16, 18]))
        }
        
        do {
            let a = Tensor(shape: [2, 3, 2], elements: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
            let b = Tensor(shape: [2], elements: [100, 200])
            XCTAssertEqual(a + b, Tensor(shape: [2, 3, 2], elements: [101, 202, 103, 204, 105, 206, 107, 208, 109, 210, 111, 212]))
            XCTAssertEqual(b + a, Tensor(shape: [2, 3, 2], elements: [101, 202, 103, 204, 105, 206, 107, 208, 109, 210, 111, 212]))
        }
        
        do {
            let a = Tensor(shape: [2, 1, 3, 2], elements: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
            let b = Tensor(shape: [3, 2], elements: [100, 200, 300, 400, 500, 600])
            XCTAssertEqual(a + b, Tensor(shape: [2, 1, 3, 2], elements: [101, 202, 303, 404, 505, 606, 107, 208, 309, 410, 511, 612]))
            XCTAssertEqual(b + a, Tensor(shape: [2, 1, 3, 2], elements: [101, 202, 303, 404, 505, 606, 107, 208, 309, 410, 511, 612]))
        }
    }
    
    func testSub() {
        do {
            let a = Tensor(shape: [2, 3], elements: [1, 2, 3, 4, 5, 6])
            let b = Tensor(shape: [2, 3], elements: [12, 11, 10, 9, 8, 7])
            let r = a - b
            XCTAssertEqual(r, Tensor(shape: [2, 3], elements: [-11, -9, -7, -5, -3, -1]))
        }
        
        do {
            let a = Tensor(shape: [2, 3, 2], elements: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
            let b = Tensor(shape: [2], elements: [100, 200])
            XCTAssertEqual(a - b, Tensor(shape: [2, 3, 2], elements: [-99, -198, -97, -196, -95, -194, -93, -192, -91, -190, -89, -188]))
            XCTAssertEqual(b - a, Tensor(shape: [2, 3, 2], elements: [99, 198, 97, 196, 95, 194, 93, 192, 91, 190, 89, 188]))
        }
        
        do {
            let a = Tensor(shape: [2, 1, 3, 2], elements: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
            let b = Tensor(shape: [3, 2], elements: [100, 200, 300, 400, 500, 600])
            XCTAssertEqual(a - b, Tensor(shape: [2, 1, 3, 2], elements: [-99, -198, -297, -396, -495, -594, -93, -192, -291, -390, -489, -588]))
            XCTAssertEqual(b - a, Tensor(shape: [2, 1, 3, 2], elements: [99, 198, 297, 396, 495, 594, 93, 192, 291, 390, 489, 588]))
        }
    }
    
    func testMul() {
        do {
            let a = Tensor(shape: [2, 3], elements: [1, 2, 3, 4, 5, 6])
            let b = Tensor(shape: [2, 3], elements: [7, 8, 9, 10, 11, 12])
            XCTAssertEqual(a * b, Tensor(shape: [2, 3], elements: [7, 16, 27, 40, 55, 72]))
            XCTAssertEqual(b * a, Tensor(shape: [2, 3], elements: [7, 16, 27, 40, 55, 72]))
        }
        
        do {
            let a = Tensor(shape: [2, 3, 2], elements: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
            let b = Tensor(shape: [2], elements: [10, 100])
            XCTAssertEqual(a * b, Tensor(shape: [2, 3, 2], elements: [10, 200, 30, 400, 50, 600, 70, 800, 90, 1000, 110, 1200]))
            XCTAssertEqual(b * a, Tensor(shape: [2, 3, 2], elements: [10, 200, 30, 400, 50, 600, 70, 800, 90, 1000, 110, 1200]))
        }
        
        do {
            let a = Tensor(shape: [2, 1, 3, 2], elements: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
            let b = Tensor(shape: [3, 2], elements: [10, 100, 1000, -10, -100, -1000])
            XCTAssertEqual(a * b, Tensor(shape: [2, 1, 3, 2], elements: [10, 200, 3000, -40, -500, -6000, 70, 800, 9000, -100, -1100, -12000]))
            XCTAssertEqual(b * a, Tensor(shape: [2, 1, 3, 2], elements: [10, 200, 3000, -40, -500, -6000, 70, 800, 9000, -100, -1100, -12000]))
        }
        
        do {
            let a = Tensor(shape: [2, 3], elements: [1, 2, 3, 4, 5, 6])
            let b: Float = 2.0
            XCTAssertEqual(a * b, Tensor(shape: [2, 3], elements: [2, 4, 6, 8, 10, 12]))
            XCTAssertEqual(b * a, Tensor(shape: [2, 3], elements: [2, 4, 6, 8, 10, 12]))
        }
    }
    
    func testDiv() {
        do {
            let a = Tensor(shape: [2, 3], elements: [2048, 512, 128, 32, 8, 2])
            let b = Tensor(shape: [2, 3], elements: [2, 4, 8, 16, 32, 64])
            XCTAssertEqual(a / b, Tensor(shape: [2, 3], elements: [1024, 128, 16, 2, 0.25, 0.03125]))
            XCTAssertEqual(b / a, Tensor(shape: [2, 3], elements: [0.0009765625, 0.0078125, 0.0625, 0.5, 4, 32]))
        }
        
        do {
            let a = Tensor(shape: [2, 3, 2], elements: [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096])
            let b = Tensor(shape: [2], elements: [8, 2])
            XCTAssertEqual(a / b, Tensor(shape: [2, 3, 2], elements: [0.25, 2.0, 1.0, 8.0, 4.0, 32.0, 16.0, 128.0, 64.0, 512.0, 256.0, 2048.0]))
            XCTAssertEqual(b / a, Tensor(shape: [2, 3, 2], elements: [4.0, 0.5, 1.0, 0.125, 0.25, 0.03125, 0.0625, 0.0078125, 0.015625, 0.001953125, 0.00390625, 0.00048828125]))
        }
        
        do {
            let a = Tensor(shape: [3, 1, 2, 2], elements: [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096])
            let b = Tensor(shape: [2, 2], elements: [8, 2, -8, -2])
            XCTAssertEqual(a / b, Tensor(shape: [3, 1, 2, 2], elements: [0.25, 2.0, -1.0, -8.0, 4.0, 32.0, -16.0, -128.0, 64.0, 512.0, -256.0, -2048.0]))
            XCTAssertEqual(b / a, Tensor(shape: [3, 1, 2, 2], elements: [4.0, 0.5, -1.0, -0.125, 0.25, 0.03125, -0.0625, -0.0078125, 0.015625, 0.001953125, -0.00390625, -0.00048828125]))
        }
        
        do {
            let a = Tensor(shape:[2, 3], elements: [ 1, 2, 4, 8, 16, 32])
            let b: Float = 2.0
            XCTAssertEqual(a / b, Tensor(shape: [2, 3], elements: [0.5, 1, 2, 4, 8, 16]))
            XCTAssertEqual(b / a, Tensor(shape: [2, 3], elements: [2, 1, 0.5, 0.25, 0.125, 0.0625]))
        }
    }
    
    func testMatmul() {
        do {
            let a = Tensor(shape: [2, 3], elements: [1, 2, 3, 4, 5, 6])
            let b = Tensor(shape: [3, 4], elements: [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18])
            let r = a.matmul(b)
            XCTAssertEqual(r, Tensor(shape: [2, 4], elements: [74, 80, 86, 92, 173, 188, 203, 218]))
        }
        do {
            let a = Tensor(shape: [3, 3], elements: [1, 1, 1, 2, 2, 2, 3, 3, 3])
            let b = Tensor(shape: [3, 3], elements: [1, 1, 1, 2, 2, 2, 3, 3, 3])
            let r = a.matmul(b)
            XCTAssertEqual(r, Tensor(shape: [3, 3], elements: [6, 6, 6, 12, 12, 12, 18, 18, 18]))
        }
    }
    
    func testMatmulPerformance(){
        let a = Tensor(shape: [1000, 1000], element: 0.1)
        let b = Tensor(shape: [1000, 1000], element: 0.1)
        measure{
            _ = a.matmul(b)
        }
    }
    
    static var allTests : [(String, (TensorTests) -> () throws -> Void)] {
        return [
            ("testIndex", testIndex),
            ("testAdd", testAdd),
            ("testSub", testSub),
            ("testMul", testMul),
            ("testDiv", testDiv),
            ("testMatmul", testMatmul),
            ("testMatmulPerformance", testMatmulPerformance),
        ]
    }
}
Download .txt
gitextract_qun949lr/

├── .gitignore
├── LICENSE
├── Package.swift
├── README.md
├── Sources/
│   ├── MNIST/
│   │   ├── AppDelegate.swift
│   │   ├── Assets.xcassets/
│   │   │   └── AppIcon.appiconset/
│   │   │       └── Contents.json
│   │   ├── Base.lproj/
│   │   │   ├── LaunchScreen.storyboard
│   │   │   └── Main.storyboard
│   │   ├── Canvas.swift
│   │   ├── CanvasView.swift
│   │   ├── Classifier.swift
│   │   ├── Info.plist
│   │   ├── Line.swift
│   │   ├── Models/
│   │   │   ├── W_conv1
│   │   │   ├── W_conv2
│   │   │   ├── W_fc1
│   │   │   ├── W_fc2
│   │   │   ├── b_conv1
│   │   │   ├── b_conv2
│   │   │   ├── b_fc1
│   │   │   └── b_fc2
│   │   ├── String.swift
│   │   └── ViewController.swift
│   └── TensorSwift/
│       ├── Dimension.swift
│       ├── Info.plist
│       ├── Operators.swift
│       ├── Shape.swift
│       ├── Tensor.swift
│       ├── TensorMath.swift
│       ├── TensorNN.swift
│       ├── TensorSwift.h
│       └── Utils.swift
├── TensorSwift.podspec
├── TensorSwift.xcodeproj/
│   ├── Configs/
│   │   └── Project.xcconfig
│   ├── TensorSwiftTests_Info.plist
│   ├── TensorSwift_Info.plist
│   ├── project.pbxproj
│   └── project.xcworkspace/
│       └── contents.xcworkspacedata
└── Tests/
    ├── LinuxMain.swift
    ├── MNISTTests/
    │   ├── Array.swift
    │   ├── ClassifierTests.swift
    │   ├── Downloader.swift
    │   ├── DownloaderTests.swift
    │   ├── Info.plist
    │   ├── MNISTTests-Bridging-Header.h
    │   └── SHA1.swift
    └── TensorSwiftTests/
        ├── CalculationPerformanceTests.swift
        ├── DimensionTests.swift
        ├── Info.plist
        ├── PowerTests.swift
        ├── TensorMathTest.swift
        ├── TensorNNTests.swift
        ├── TensorSwiftSample.swift
        ├── TensorSwiftTests.swift
        └── TensorTests.swift
Condensed preview — 55 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (132K chars).
[
  {
    "path": ".gitignore",
    "chars": 764,
    "preview": "# Xcode\n#\nbuild/\n*.pbxuser\n!default.pbxuser\n*.mode1v3\n!default.mode1v3\n*.mode2v3\n!default.mode2v3\n*.perspectivev3\n!defau"
  },
  {
    "path": "LICENSE",
    "chars": 1080,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2016 Qoncept, Inc.\n\nPermission is hereby granted, free of charge, to any person obt"
  },
  {
    "path": "Package.swift",
    "chars": 1037,
    "preview": "// swift-tools-version:4.0\n// The swift-tools-version declares the minimum version of Swift required to build this packa"
  },
  {
    "path": "README.md",
    "chars": 2282,
    "preview": "# TensorSwift\n\n_TensorSwift_ is a lightweight library to calculate tensors, which has similar APIs to [_TensorFlow_](htt"
  },
  {
    "path": "Sources/MNIST/AppDelegate.swift",
    "chars": 2032,
    "preview": "import UIKit\n\n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n\n    var window: UIWindow?\n\n\n  "
  },
  {
    "path": "Sources/MNIST/Assets.xcassets/AppIcon.appiconset/Contents.json",
    "chars": 1077,
    "preview": "{\n  \"images\" : [\n    {\n      \"idiom\" : \"iphone\",\n      \"size\" : \"29x29\",\n      \"scale\" : \"2x\"\n    },\n    {\n      \"idiom\""
  },
  {
    "path": "Sources/MNIST/Base.lproj/LaunchScreen.storyboard",
    "chars": 1665,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<document type=\"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard"
  },
  {
    "path": "Sources/MNIST/Base.lproj/Main.storyboard",
    "chars": 5193,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<document type=\"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard"
  },
  {
    "path": "Sources/MNIST/Canvas.swift",
    "chars": 251,
    "preview": "import CoreGraphics\n\nstruct Canvas {\n    var lines: [Line] = [Line()]\n    \n    mutating func draw(_ point: CGPoint) {\n  "
  },
  {
    "path": "Sources/MNIST/CanvasView.swift",
    "chars": 1617,
    "preview": "import UIKit\n\nclass CanvasView: UIView {\n    private(set) var canvas: Canvas\n    \n    required init?(coder: NSCoder) {\n "
  },
  {
    "path": "Sources/MNIST/Classifier.swift",
    "chars": 2173,
    "preview": "import Foundation\nimport TensorSwift\n\npublic struct Classifier {\n    public let W_conv1: Tensor\n    public let b_conv1: "
  },
  {
    "path": "Sources/MNIST/Info.plist",
    "chars": 1641,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
  },
  {
    "path": "Sources/MNIST/Line.swift",
    "chars": 180,
    "preview": "import CoreGraphics\n\nstruct Line {\n    var points: [CGPoint]\n    \n    init() {\n        self.init([])\n    }\n    \n    init"
  },
  {
    "path": "Sources/MNIST/Models/b_conv1",
    "chars": 71,
    "preview": "Ԝ=7=֩=x=o=s=Z=^=[;=ߋ=fVj=f=\u0004m=Z=T\u0004=\b==e\u000f=W=\u0018=3=\u0002=\f\u0007=/X=='^=؍=\"=`==[[=d="
  },
  {
    "path": "Sources/MNIST/Models/b_conv2",
    "chars": 123,
    "preview": "\u0012=\u0004=^=\r\u0004={F=k=D=_ڴ=f==zI=Ŧ=ܕ=9=\u0001=== =ذ=\\==u='===l=Ҭ=\u001cա=,===O=PͰ==Ķ=\f===\u0007.=\u0019=숵=_=9=~==Li==Ds=k6==9=s===YJ=H=\u001f==%Π=.=\u0004=ׇ="
  },
  {
    "path": "Sources/MNIST/Models/b_fc2",
    "chars": 20,
    "preview": "\u0015=K=II==G==6==16=y%="
  },
  {
    "path": "Sources/MNIST/String.swift",
    "chars": 182,
    "preview": "import Foundation\n\nextension String {\n    public func stringByAppendingPathComponent(_ str: String) -> String {\n        "
  },
  {
    "path": "Sources/MNIST/ViewController.swift",
    "chars": 1545,
    "preview": "import UIKit\nimport TensorSwift\n\nclass ViewController: UIViewController {\n    @IBOutlet private var canvasView: CanvasVi"
  },
  {
    "path": "Sources/TensorSwift/Dimension.swift",
    "chars": 1041,
    "preview": "public struct Dimension {\n    public let value: Int\n    \n    public init(_ value: Int) {\n        guard value >= 0 else {"
  },
  {
    "path": "Sources/TensorSwift/Info.plist",
    "chars": 806,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
  },
  {
    "path": "Sources/TensorSwift/Operators.swift",
    "chars": 138,
    "preview": "infix operator ** : PowerPrecedence\nprecedencegroup PowerPrecedence {\n    associativity: right\n    higherThan: Multiplic"
  },
  {
    "path": "Sources/TensorSwift/Shape.swift",
    "chars": 645,
    "preview": "public struct Shape {\n    public let dimensions: [Dimension]\n    \n    public func volume() -> Int {\n        return dimen"
  },
  {
    "path": "Sources/TensorSwift/Tensor.swift",
    "chars": 7922,
    "preview": "\n#if os(iOS) || os(OSX)\nimport Accelerate\n#endif\n\npublic struct Tensor {\n    public typealias Element = Float\n    \n    p"
  },
  {
    "path": "Sources/TensorSwift/TensorMath.swift",
    "chars": 2048,
    "preview": "import Darwin\n\npublic func **(lhs: Tensor, rhs: Tensor) -> Tensor {\n    return noncommutativeBinaryOperation(lhs, rhs, o"
  },
  {
    "path": "Sources/TensorSwift/TensorNN.swift",
    "chars": 9333,
    "preview": "import Darwin\n#if os(iOS) || os(OSX)\nimport Accelerate\n#endif\n\nextension Tensor {\n    public func softmax() -> Tensor {\n"
  },
  {
    "path": "Sources/TensorSwift/TensorSwift.h",
    "chars": 381,
    "preview": "#import <Foundation/Foundation.h>\n\n//! Project version number for TensorSwift.\nFOUNDATION_EXPORT double TensorSwiftVersi"
  },
  {
    "path": "Sources/TensorSwift/Utils.swift",
    "chars": 862,
    "preview": "extension Int {\n    internal func ceilDiv(_ rhs: Int) -> Int {\n        return (self + rhs - 1) / rhs\n    }\n}\n\ninternal f"
  },
  {
    "path": "TensorSwift.podspec",
    "chars": 720,
    "preview": "Pod::Spec.new do |s|\n  s.name         = \"TensorSwift\"\n  s.version      = \"0.2.2\"\n  s.summary      = \"TensorSwift is a li"
  },
  {
    "path": "TensorSwift.xcodeproj/Configs/Project.xcconfig",
    "chars": 274,
    "preview": "PRODUCT_NAME = $(TARGET_NAME)\nSUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator appletvos appletvsimulator watchos w"
  },
  {
    "path": "TensorSwift.xcodeproj/TensorSwiftTests_Info.plist",
    "chars": 723,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<plist version=\"1.0\">\n<dict>\n  <key>CFBundleDevelopmentRegion</key>\n  <string>en<"
  },
  {
    "path": "TensorSwift.xcodeproj/TensorSwift_Info.plist",
    "chars": 723,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<plist version=\"1.0\">\n<dict>\n  <key>CFBundleDevelopmentRegion</key>\n  <string>en<"
  },
  {
    "path": "TensorSwift.xcodeproj/project.pbxproj",
    "chars": 47058,
    "preview": "// !$*UTF8*$!\n{\n\tarchiveVersion = 1;\n\tclasses = {\n\t};\n\tobjectVersion = 46;\n\tobjects = {\n\n/* Begin PBXBuildFile section *"
  },
  {
    "path": "TensorSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata",
    "chars": 135,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Workspace\n   version = \"1.0\">\n   <FileRef\n      location = \"self:\">\n   </FileRef"
  },
  {
    "path": "Tests/LinuxMain.swift",
    "chars": 352,
    "preview": "import XCTest\n@testable import TensorSwiftTests\n\nXCTMain([\n     testCase(TensorSwiftTests.allTests),\n     testCase(Dimen"
  },
  {
    "path": "Tests/MNISTTests/Array.swift",
    "chars": 357,
    "preview": "extension Array {\n    func grouped(_ count: Int) -> [[Element]] {\n        var result: [[Element]] = []\n        var group"
  },
  {
    "path": "Tests/MNISTTests/ClassifierTests.swift",
    "chars": 1088,
    "preview": "import XCTest\nimport TensorSwift\n@testable import MNIST\n\nclass ClassifierTests: XCTestCase {\n    func testClassify() {\n "
  },
  {
    "path": "Tests/MNISTTests/Downloader.swift",
    "chars": 1862,
    "preview": "import Foundation\n\nfunc downloadTestData() -> (images: Data, labels: Data) {\n    let baseUrl = \"http://yann.lecun.com/ex"
  },
  {
    "path": "Tests/MNISTTests/DownloaderTests.swift",
    "chars": 288,
    "preview": "import XCTest\n\nclass DownloaderTests: XCTestCase {\n    func testDownloadTestData() {\n        let testData = downloadTest"
  },
  {
    "path": "Tests/MNISTTests/Info.plist",
    "chars": 879,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
  },
  {
    "path": "Tests/MNISTTests/MNISTTests-Bridging-Header.h",
    "chars": 173,
    "preview": "#ifndef MNISTTests_Bridging_Header_h\n#define MNISTTests_Bridging_Header_h\n\n#import <CommonCrypto/CommonCrypto.h>\n#import"
  },
  {
    "path": "Tests/MNISTTests/SHA1.swift",
    "chars": 352,
    "preview": "import Foundation\n\nextension Data {\n    var sha1: String {\n        let data = self\n        var digest = [UInt8](repeatin"
  },
  {
    "path": "Tests/TensorSwiftTests/CalculationPerformanceTests.swift",
    "chars": 2122,
    "preview": "import XCTest\n@testable import TensorSwift\n\nprivate func getTensor1000x1000() -> Tensor {\n    let elements = [Float](rep"
  },
  {
    "path": "Tests/TensorSwiftTests/DimensionTests.swift",
    "chars": 965,
    "preview": "import XCTest\n@testable import TensorSwift\n\nclass DimensionTests: XCTestCase {\n    func testAdd() {\n        do {\n       "
  },
  {
    "path": "Tests/TensorSwiftTests/Info.plist",
    "chars": 733,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
  },
  {
    "path": "Tests/TensorSwiftTests/PowerTests.swift",
    "chars": 1197,
    "preview": "import XCTest\n@testable import TensorSwift\n\nclass PowerTests: XCTestCase {\n\n    func testScalar() {\n        let tensor ="
  },
  {
    "path": "Tests/TensorSwiftTests/TensorMathTest.swift",
    "chars": 2001,
    "preview": "import XCTest\n@testable import TensorSwift\n\nclass TensorMathTest: XCTestCase {\n    func testPow() {\n        do {\n       "
  },
  {
    "path": "Tests/TensorSwiftTests/TensorNNTests.swift",
    "chars": 3854,
    "preview": "import XCTest\n@testable import TensorSwift\n\nclass TensorNNTests: XCTestCase {\n    func testMaxPool() {\n        do {\n    "
  },
  {
    "path": "Tests/TensorSwiftTests/TensorSwiftSample.swift",
    "chars": 1362,
    "preview": "import XCTest\nimport TensorSwift\n\nclass TensorSwiftSample: XCTestCase {\n    func testSample() {\n        let a = Tensor(s"
  },
  {
    "path": "Tests/TensorSwiftTests/TensorSwiftTests.swift",
    "chars": 636,
    "preview": "//\n//  TensorSwiftTests.swift\n//  TensorSwift\n//\n//  Created by Araki Takehiro on 2016/09/28.\n//\n//\n\nimport XCTest\n\nclas"
  },
  {
    "path": "Tests/TensorSwiftTests/TensorTests.swift",
    "chars": 7860,
    "preview": "import XCTest\n@testable import TensorSwift\n\nclass TensorTests: XCTestCase {\n    func testIndex() {\n        do {\n        "
  }
]

// ... and 5 more files (download for full content)

About this extraction

This page contains the full source code of the qoncept/TensorSwift GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 55 files (12.4 MB), approximately 38.4k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!