Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

See all packages published by wvabrinskas.

wvabrinskas/NumSwift 2.0.1

Array arithmetic library for Swift

⭐️ 0

🕓 10 weeks ago

iOS
macOS
watchOS
tvOS

.package(url: "https://github.com/wvabrinskas/NumSwift.git", from: "2.0.1")

Adds complex arithmetic to Swift with support for array arithmetic. Utilizes Apple's `Accelerate`

framework when possible.

```
let test = 10.0
let testArray = [1.0, 2.0, 3.0, 4.0, 5.0]
let expected = [11.0, 12.0, 13.0, 14.0, 15.0]
let result = testArray + test
print(result)
```

- You can add a single value to every member of an array
- This will return the
`expected`

value.

```
let testArray = [1.0, 2.0, 3.0, 4.0, 5.0]
let testArray2 = [10.0, 20.0, 30.0, 40.0, 50.0]
let expected = [11.0, 22.0, 33.0, 44.0, 55.0]
let result = testArray + testArray2
print(result)
```

- You can also add a whole array to another array given they are the same length
- This will return the
`expected`

value.

```
let test = 10.0
let testArray = [1.0, 2.0, 3.0, 4.0, 5.0]
let expected = [10.0, 20.0, 30.0, 40.0, 50.0]
let result = testArray * test
print(result)
```

- You can multiply a single value to every member of an array
- This will return the
`expected`

value.

```
let testArray = [1.0, 2.0, 3.0, 4.0, 5.0]
let testArray2 = [10.0, 20.0, 30.0, 40.0, 50.0]
let expected = [10.0, 40.0, 90.0, 160.0, 250.0]
let result = testArray * testArray2
print(result)
```

- You can also multiply a whole array to another array given they are the same length
- This will return the
`expected`

value.

```
let test = 10.0
let testArray = [10.0, 20.0, 30.0, 40.0, 50.0]
let expected = [1.0, 2.0, 3.0, 4.0, 5.0]
let result = testArray / test
print(result)
```

- You can divide a single value to every member of an array
- This will return the
`expected`

value.

```
let testArray = [10.0, 40.0, 90.0, 160.0, 250.0]
let testArray2 = [1.0, 2.0, 3.0, 4.0, 5.0]
let expected = [10.0, 20.0, 30.0, 40.0, 50.0]
let result = testArray / testArray2
print(result)
```

- You can also multiply a whole array to another array given they are the same length
- This will return the
`expected`

value.

You can scale an array in a given range to a desired range.

```
let testArray = [0.0, 5.0, 10.0, 20.0]
let expected = [-1.0, -0.5, 0.0, 1.0]
let scaled = testArray.scale(from: 0...20, to: -1...1)
```

You can get the shape of a matrix. This will return the count at each layer. The subarrays must all be the same length

```
let testArray = [[1,0], [1, 0]]
let expected = [2, 2]
print(testArray.shape)
```

`multiply(B: [Element], columns: Int32, rows: Int32, dimensions: Int32 = 1) -> [Element]`

`dot(_ b: [Element]) -> Element`

`transpose(columns: Int, rows: Int) -> [Element]`

```
conv2D(_ filter: [[Double]],
filterSize: (rows: Int, columns: Int),
inputSize: (rows: Int, columns: Int)) -> Element
conv2D(_ filter: [[Float]],
filterSize: (rows: Int, columns: Int),
inputSize: (rows: Int, columns: Int)) -> Element
```

`func l2Normalize(limit: Element)`

`func l1Normalize(limit: Element)`

`clip(_ to: Element)`

link |

Stars: 0 |

Last commit: 10 weeks ago |

v2.0.1

10 weeks ago

Fixed a bug in convolution with index calculation

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics