{"id":1373,"url":"https://github.com/qoncept/TensorSwift","last_synced_at":"2025-08-02T04:31:12.170Z","repository":{"id":56923876,"uuid":"53657141","full_name":"qoncept/TensorSwift","owner":"qoncept","description":"A lightweight library to calculate tensors in Swift, which has similar APIs to TensorFlow's","archived":false,"fork":false,"pushed_at":"2017-10-24T09:02:48.000Z","size":14335,"stargazers_count":324,"open_issues_count":0,"forks_count":22,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-07-10T21:49:53.691Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qoncept.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-11T09:50:51.000Z","updated_at":"2025-06-30T20:30:55.000Z","dependencies_parsed_at":"2022-08-20T22:20:23.988Z","dependency_job_id":null,"html_url":"https://github.com/qoncept/TensorSwift","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/qoncept/TensorSwift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qoncept%2FTensorSwift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qoncept%2FTensorSwift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qoncept%2FTensorSwift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qoncept%2FTensorSwift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qoncept","download_url":"https://codeload.github.com/qoncept/TensorSwift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qoncept%2FTensorSwift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268334611,"owners_count":24233793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:44.978Z","updated_at":"2025-08-02T04:31:10.790Z","avatar_url":"https://github.com/qoncept.png","language":"Swift","funding_links":[],"categories":["Machine Learning","Misc"],"sub_categories":["Other Hardware","Other free courses","Other ML frameworks"],"readme":"# TensorSwift\n\n_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_**.\n\n```swift\nlet a = Tensor(shape: [2, 3], elements: [1, 2, 3, 4, 5, 6])\nlet b = Tensor(shape: [2, 3], elements: [7, 8, 9, 10, 11, 12])\nlet sum = a + b // Tensor(shape: [2, 3], elements: [8, 10, 12, 14, 16, 18])\nlet mul = a * b // Tensor(shape: [2, 3], elements: [7, 16, 27, 40, 55, 72])\n\nlet c = Tensor(shape: [3, 1], elements: [7, 8, 9])\nlet matmul = a.matmul(c) // Tensor(shape: [2, 1], elements: [50, 122])\n\nlet zeros = Tensor(shape: [2, 3, 4])\nlet ones = Tensor(shape: [2, 3, 4], element: 1)\n```\n\n## Deep MNIST for Experts\n\n![deep-mnist.gif](Resources/DeepMnist.gif)\n\nThe 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_.\n\n```swift\npublic struct Classifier {\n    public let W_conv1: Tensor\n    public let b_conv1: Tensor\n    public let W_conv2: Tensor\n    public let b_conv2: Tensor\n    public let W_fc1: Tensor\n    public let b_fc1: Tensor\n    public let W_fc2: Tensor\n    public let b_fc2: Tensor\n    \n    public func classify(_ x_image: Tensor) -\u003e Int {\n        let h_conv1 = (x_image.conv2d(filter: W_conv1, strides: [1, 1, 1]) + b_conv1).relu()\n        let h_pool1 = h_conv1.maxPool(kernelSize: [2, 2, 1], strides: [2, 2, 1])\n        \n        let h_conv2 = (h_pool1.conv2d(filter: W_conv2, strides: [1, 1, 1]) + b_conv2).relu()\n        let h_pool2 = h_conv2.maxPool(kernelSize: [2, 2, 1], strides: [2, 2, 1])\n        \n        let h_pool2_flat = h_pool2.reshaped([1, Dimension(7 * 7 * 64)])\n        let h_fc1 = (h_pool2_flat.matmul(W_fc1) + b_fc1).relu()\n        \n        let y_conv = (h_fc1.matmul(W_fc2) + b_fc2).softmax()\n\n        return y_conv.elements.enumerated().max { $0.1 \u003c $1.1 }!.0\n    }\n}\n```\n\n## Installation\n\n### Swift Package Manager\n\n```swift\n.Package(url: \"git@github.com:qoncept/TensorSwift.git\", from: \"0.2.0\"),\n```\n\n### CocoaPods\n\n```\npod 'TensorSwift', '~\u003e 0.2'\n```\n\n### Carthage\n\n```\ngithub \"qoncept/TensorSwift\" ~\u003e 0.2\n```\n\n## License\n\n[The MIT License](LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqoncept%2FTensorSwift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqoncept%2FTensorSwift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqoncept%2FTensorSwift/lists"}