Skip to content

Commit

Permalink
add swift 5.3 build to travis build matrix. (#13)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dastrobu authored Sep 28, 2020
1 parent df4461a commit 93beec8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ jobs:
osx_image: xcode11.2
env: SWIFT_VERSION=5.1
- os: osx
osx_image: xcode11.2
osx_image: xcode11.6
env: SWIFT_VERSION=5.2
- os: osx
osx_image: xcode12
env: SWIFT_VERSION=5.3

install:
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
Expand Down
28 changes: 22 additions & 6 deletions Sources/AccelerateArray/cblas.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public extension Array where Element == Float {
"\(offset) == 0 || (\(offset) >= 0 && \(offset) < \(count))")
assert(n >= 0 && n <= count - offset, "\(n) >= 0 && \(n) <= \(count) - \(offset)")
assert(incX >= 1, "\(incX) >= 1")
cblas_sscal(n, alpha, &self + offset, incX)
withUnsafeMutableBufferPointer {
cblas_sscal(n, alpha, $0.baseAddress! + offset, incX)
}
}

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

/// Computes the sum of two vectors, scaling each one separately (single-precision).
Expand Down Expand Up @@ -75,7 +79,11 @@ public extension Array where Element == Float {
assert(n >= 0 && n / incY <= y.count - offsetY, "\(n) >= 0 && \(n) / \(incY) <= \(y.count) - \(offsetY)")
assert(incX >= 1, "\(incX) >= 1")
assert(incY >= 1, "\(incY) >= 1")
catlas_saxpby(n, alpha, &self + offsetX, incX, beta, &y + offsetY, incY)
withUnsafeMutableBufferPointer { X in
y.withUnsafeMutableBufferPointer { Y in
catlas_saxpby(n, alpha, X.baseAddress! + offsetX, incX, beta, Y.baseAddress! + offsetY, incY)
}
}
}

}
Expand All @@ -98,7 +106,9 @@ public extension Array where Element == Double {
"\(offset) == 0 || (\(offset) >= 0 && \(offset) < \(count))")
assert(n >= 0 && n <= count - offset, "\(n) >= 0 && \(n) <= \(count) - \(offset)")
assert(incX >= 1, "\(incX) >= 1")
cblas_dscal(n, alpha, &self + offset, incX)
withUnsafeMutableBufferPointer {
cblas_dscal(n, alpha, $0.baseAddress! + offset, incX)
}
}

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

/// Computes the sum of two vectors, scaling each one separately (single-precision).
Expand Down Expand Up @@ -156,6 +168,10 @@ public extension Array where Element == Double {
assert(n >= 0 && n / incY <= y.count - offsetY, "\(n) >= 0 && \(n) / \(incY) <= \(y.count) - \(offsetY)")
assert(incX >= 1, "\(incX) >= 1")
assert(incY >= 1, "\(incY) >= 1")
catlas_daxpby(n, alpha, &self + offsetX, incX, beta, &y + offsetY, incY)
withUnsafeMutableBufferPointer { X in
y.withUnsafeMutableBufferPointer { Y in
catlas_daxpby(n, alpha, X.baseAddress! + offsetX, incX, beta, Y.baseAddress! + offsetY, incY)
}
}
}
}

0 comments on commit 93beec8

Please sign in to comment.