{"id":16686420,"url":"https://github.com/dastrobu/acceleratearray","last_synced_at":"2025-04-10T00:16:04.710Z","repository":{"id":45234201,"uuid":"179843727","full_name":"dastrobu/AccelerateArray","owner":"dastrobu","description":"Swift Array Extensions for the Apple Accelerate Framework","archived":false,"fork":false,"pushed_at":"2023-12-18T17:05:28.000Z","size":1102,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T00:15:57.764Z","etag":null,"topics":["accelerate-framework","blas","lapack","linear-algebra","swift"],"latest_commit_sha":null,"homepage":"https://dastrobu.github.io/AccelerateArray/documentation/acceleratearray/swift/array","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dastrobu.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-06T14:30:06.000Z","updated_at":"2025-03-20T15:54:24.000Z","dependencies_parsed_at":"2025-02-16T03:32:06.904Z","dependency_job_id":"89447947-dac7-448c-b896-a5bfefb7477e","html_url":"https://github.com/dastrobu/AccelerateArray","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dastrobu%2FAccelerateArray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dastrobu%2FAccelerateArray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dastrobu%2FAccelerateArray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dastrobu%2FAccelerateArray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dastrobu","download_url":"https://codeload.github.com/dastrobu/AccelerateArray/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131315,"owners_count":21052819,"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","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":["accelerate-framework","blas","lapack","linear-algebra","swift"],"created_at":"2024-10-12T15:05:54.982Z","updated_at":"2025-04-10T00:16:04.691Z","avatar_url":"https://github.com/dastrobu.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AccelerateArray\n\n[![Swift Version](https://img.shields.io/badge/swift-5.9-blue.svg)](https://swift.org)\n![Platform](https://img.shields.io/badge/platform-macOS-lightgray.svg)\n![Build](https://github.com/dastrobu/AccelerateArray/actions/workflows/ci.yaml/badge.svg)\n\nSwift Array Extensions for the Apple Accelerate Framework. \n\nThe goal of this package is to provide slightly easier access to the [BLAS](http://www.netlib.org/blas/), \n[LAPACK](http://www.netlib.org/lapack/) and [vDSP](https://developer.apple.com/documentation/accelerate/vdsp) functions\nof the [Accelerate](https://developer.apple.com/documentation/accelerate) framework, \nto apply these functions to Float and Double swift arrays. \n\nOut of scope of this package are more convenient wrappers to handle arrays as matrices, which \nwould include storing strides, shapes and order (row/column major). This would require to add \nadditional types, which can be easily built on top of this package. \n\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n## Table of Contents\n\n- [Installation](#installation)\n  - [Swift Package Manager](#swift-package-manager)\n  - [Cocoa Pods](#cocoa-pods)\n  - [Dependencies](#dependencies)\n- [Examples](#examples)\n  - [BLAS (ATLAS)](#blas-atlas)\n    - [Scale Vector (sscal, dscal)](#scale-vector-sscal-dscal)\n    - [Set Vector to Constant (sset, dset)](#set-vector-to-constant-sset-dset)\n  - [LAPACK](#lapack)\n    - [LU Factorization](#lu-factorization)\n    - [Inverse](#inverse)\n- [Docs](#docs)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n     \n## Installation\n\n### Swift Package Manager\n\n```swift\nlet package = Package(\n        dependencies: [\n          .package(url: \"https://github.com/dastrobu/AccelerateArray.git\", from: \"0.5.0\"),\n        ]\n)\n```\n        \n### Cocoa Pods\n\nMake sure a valid deployment target is setup in the Podfile and add\n\n    pod 'AccelerateArray', '~\u003e 0'\n    \n### Dependencies\n\nThere are no dependencies on macOS apart from the Accelerate framework, which is installed by default.\nSince Accelerate is also included in iOS and other Apple Platforms, this package should run on all Apple plattforms.\n\n## Examples\n\n### BLAS (ATLAS)\n\n#### Scale Vector (sscal, dscal)\n\nVector can be scaled by\n```swift\na = [1, 2, 3]\na.scal(2) // [2, 4, 6]\n```\nor by providing all parameters for example with a stride of two\n```swift\na = [1, 2, 3]\na.scal(n: Int32(a.count), alpha: 2, incX: 2) // [2, 2, 6]\n```\n\n#### Set Vector to Constant (sset, dset)\n\nSet all elements of a vector to a single constant.\n```swift\na = [1, 2, 3]\na.set(9) // [9, 9, 9]\n```\nor by providing all parameters for example with a stride of two\n```swift\na = [1, 2, 3]\na.set(n: Int32(a.count), alpha: 2, incX: 2) // [9, 2, 9]\n```\n\n### LAPACK\n\n#### LU Factorization \n\nCompute LU factorization.\n\n```swift\n// A in row major\nlet A: [Float] = [\n    1.0, 2.0,\n    3.0, 4.0,\n    5.0, 6.0,\n    7.0, 8.0\n]\n// convert A to col major (for fortran)\nvar At = A.mtrans(m: 2, n: 4)\n// compute factorization\n\nlet ipiv = try At.getrf(m: 4, n: 2)\n\n// convert solution to row major\nlet X = At.mtrans(m: 4, n: 2)\n\n// L in row major (pic lower triangular matrix)\nlet L: [Float] = [\n    1.0, 0.0,\n    X[2], 1.0,\n    X[4], X[5],\n    X[6], X[7],\n]\n\n// U in row major (pic upper triangular matrix)\nlet U: [Float] = [\n    X[0], X[1],\n    0.0, X[3],\n]\n\n// note, the indices in ipiv are one base (fortran)\n// construct the permutation vector\n// see: https://math.stackexchange.com/a/3112224/91477\nvar p = [0, 1, 2, 3]\nfor i in 0..\u003cipiv.count {\n    p.swapAt(i, Int(ipiv[i] - 1))\n}\n\n// construct the full permuation matrix\nlet n = 4\nvar P: [Float] = Array(repeating: 0, count: n * n)\nfor i in 0..\u003cp.count {\n    // i iterates columns of P (in row major)\n    // p[i] indicates which element in the column must be set to one, to create the permutation matrix\n    P[i + p[i] * n] = 1.0\n}\n\n// now compute PLU (which should be equal to A within numerical accuracy)\nlet PLU = P.mmul(B: L.mmul(B: U, m: 4, n: 2, p: 2), m: 4, n: 2, p: 4)\n// gives [\n//   1.0      , 2.0,\n//   3.0000002, 4.0,\n//   5.0      , 6.0,\n//   7.0      , 8.0\n// ]\n```\n\n#### Inverse\n\nInvert matrix by \n```swift\n// inversion is independent of row/col major storage\nvar A: [Float] = [\n    1.0, 2.0,\n    3.0, 4.0,\n]\ntry A.getri()\n// gives [\n//  -2.0, 1.0,\n//  1.5, -0.5,\n// ]\n```\n\n## Docs\n\nRead the [docs](https://dastrobu.github.io/AccelerateArray/documentation/acceleratearray/swift/array). \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdastrobu%2Facceleratearray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdastrobu%2Facceleratearray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdastrobu%2Facceleratearray/lists"}