Skip to content

Commit 93beec8

Browse files
authored
add swift 5.3 build to travis build matrix. (#13)
* add swift 5.3 build to travis build matrix. * use withUnsafeMutableBufferPointer where necessary to fix Swift 5.3 issues. See also: https://gist.github.com/dastrobu/ccef82aeb98ab289d94a2cc685ba2e45
1 parent df4461a commit 93beec8

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ jobs:
1818
osx_image: xcode11.2
1919
env: SWIFT_VERSION=5.1
2020
- os: osx
21-
osx_image: xcode11.2
21+
osx_image: xcode11.6
2222
env: SWIFT_VERSION=5.2
23+
- os: osx
24+
osx_image: xcode12
25+
env: SWIFT_VERSION=5.3
2326

2427
install:
2528
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"

Sources/AccelerateArray/cblas.swift

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public extension Array where Element == Float {
1818
"\(offset) == 0 || (\(offset) >= 0 && \(offset) < \(count))")
1919
assert(n >= 0 && n <= count - offset, "\(n) >= 0 && \(n) <= \(count) - \(offset)")
2020
assert(incX >= 1, "\(incX) >= 1")
21-
cblas_sscal(n, alpha, &self + offset, incX)
21+
withUnsafeMutableBufferPointer {
22+
cblas_sscal(n, alpha, $0.baseAddress! + offset, incX)
23+
}
2224
}
2325

2426
/// Modifies a vector in place, setting each element to a given value.
@@ -40,7 +42,9 @@ public extension Array where Element == Float {
4042
"\(offset) == 0 || (\(offset) >= 0 && \(offset) < \(count))")
4143
assert(n >= 0 && n / incX <= count - offset, "\(n) >= 0 && \(n) / \(incX) <= \(count) - \(offset)")
4244
assert(incX >= 1, "\(incX) >= 1")
43-
catlas_sset(n, alpha, &self + offset, incX)
45+
withUnsafeMutableBufferPointer {
46+
catlas_sset(n, alpha, $0.baseAddress! + offset, incX)
47+
}
4448
}
4549

4650
/// Computes the sum of two vectors, scaling each one separately (single-precision).
@@ -75,7 +79,11 @@ public extension Array where Element == Float {
7579
assert(n >= 0 && n / incY <= y.count - offsetY, "\(n) >= 0 && \(n) / \(incY) <= \(y.count) - \(offsetY)")
7680
assert(incX >= 1, "\(incX) >= 1")
7781
assert(incY >= 1, "\(incY) >= 1")
78-
catlas_saxpby(n, alpha, &self + offsetX, incX, beta, &y + offsetY, incY)
82+
withUnsafeMutableBufferPointer { X in
83+
y.withUnsafeMutableBufferPointer { Y in
84+
catlas_saxpby(n, alpha, X.baseAddress! + offsetX, incX, beta, Y.baseAddress! + offsetY, incY)
85+
}
86+
}
7987
}
8088

8189
}
@@ -98,7 +106,9 @@ public extension Array where Element == Double {
98106
"\(offset) == 0 || (\(offset) >= 0 && \(offset) < \(count))")
99107
assert(n >= 0 && n <= count - offset, "\(n) >= 0 && \(n) <= \(count) - \(offset)")
100108
assert(incX >= 1, "\(incX) >= 1")
101-
cblas_dscal(n, alpha, &self + offset, incX)
109+
withUnsafeMutableBufferPointer {
110+
cblas_dscal(n, alpha, $0.baseAddress! + offset, incX)
111+
}
102112
}
103113

104114
/// Modifies a vector in place, setting each element to a given value.
@@ -121,7 +131,9 @@ public extension Array where Element == Double {
121131
assert(n >= 0 && n <= count - offset,
122132
"\(n) >= 0 && \(n) <= \(count) - \(offset)")
123133
assert(incX >= 1, "\(incX) >= 1")
124-
catlas_dset(n, alpha, &self + offset, incX)
134+
withUnsafeMutableBufferPointer {
135+
catlas_dset(n, alpha, $0.baseAddress! + offset, incX)
136+
}
125137
}
126138

127139
/// Computes the sum of two vectors, scaling each one separately (single-precision).
@@ -156,6 +168,10 @@ public extension Array where Element == Double {
156168
assert(n >= 0 && n / incY <= y.count - offsetY, "\(n) >= 0 && \(n) / \(incY) <= \(y.count) - \(offsetY)")
157169
assert(incX >= 1, "\(incX) >= 1")
158170
assert(incY >= 1, "\(incY) >= 1")
159-
catlas_daxpby(n, alpha, &self + offsetX, incX, beta, &y + offsetY, incY)
171+
withUnsafeMutableBufferPointer { X in
172+
y.withUnsafeMutableBufferPointer { Y in
173+
catlas_daxpby(n, alpha, X.baseAddress! + offsetX, incX, beta, Y.baseAddress! + offsetY, incY)
174+
}
175+
}
160176
}
161177
}

0 commit comments

Comments
 (0)