Skip to content

Commit 3dc7940

Browse files
committed
Upgrade to Swift 6.1: Update tools version, CI matrix, and fix unsafe
pointer usage
1 parent 8c676ce commit 3dc7940

6 files changed

Lines changed: 22 additions & 6 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ jobs:
1414
strategy:
1515
matrix:
1616
swift-version:
17-
- "5.9"
17+
- "6.0"
18+
- "6.1"
19+
- "6.2"
1820
runs-on: macos-latest
1921
steps:
2022
- uses: actions/checkout@v4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ DerivedData/
1111

1212
**.log
1313
**.bak
14+
15+
.DS_Store

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.4
1+
// swift-tools-version:6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription

Sources/NdArray/NdArray.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ open class NdArray<T>: CustomDebugStringConvertible,
186186
for i in 0..<rowCount {
187187
let row = a[i]
188188
precondition(row.count == colCount, "\(row.count) == \(colCount) at row \(i)")
189-
memcpy(dataStart + i * strides[0], row, colCount * MemoryLayout<T>.stride)
189+
row.withUnsafeBufferPointer { p in
190+
if let base = p.baseAddress {
191+
memcpy(dataStart + i * strides[0], base, colCount * MemoryLayout<T>.stride)
192+
}
193+
}
190194
}
191195
case .F:
192196
for i in 0..<rowCount {
@@ -219,7 +223,11 @@ open class NdArray<T>: CustomDebugStringConvertible,
219223
for j in 0..<jCount {
220224
let aij = ai[j]
221225
precondition(aij.count == kCount, "\(aij.count) == \(kCount) at index \(i), \(j)")
222-
memcpy(dataStart + i * strides[0] + j * strides[1], aij, kCount * MemoryLayout<T>.stride)
226+
aij.withUnsafeBufferPointer { p in
227+
if let base = p.baseAddress {
228+
memcpy(dataStart + i * strides[0] + j * strides[1], base, kCount * MemoryLayout<T>.stride)
229+
}
230+
}
223231
}
224232
}
225233
case .F:

Sources/NdArray/matrix/Matrix.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ open class Matrix<T>: NdArray<T>, Sequence {
3333
for i in 0..<rowCount {
3434
let row = a[i]
3535
precondition(row.count == colCount, "\(row.count) == \(colCount) at row \(i)")
36-
memcpy(dataStart + i * strides[0], row, colCount * MemoryLayout<T>.stride)
36+
row.withUnsafeBufferPointer { p in
37+
if let base = p.baseAddress {
38+
memcpy(dataStart + i * strides[0], base, colCount * MemoryLayout<T>.stride)
39+
}
40+
}
3741
}
3842
case .F:
3943
for i in 0..<rowCount {

Tests/NdArrayTests/test_support.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import XCTest
88
internal func XCTAssertEqual<T>(_ expression1: @autoclosure () throws -> [T],
99
_ expression2: @autoclosure () throws -> [T],
1010
accuracy: T, _ message: @autoclosure () -> String = "",
11-
file: StaticString = #file, line: UInt = #line) rethrows where T: FloatingPoint {
11+
file: StaticString = #filePath, line: UInt = #line) rethrows where T: FloatingPoint {
1212
let array1: [T] = try expression1()
1313
let array2: [T] = try expression2()
1414
XCTAssertEqual(array1.count, array2.count, file: file, line: line)

0 commit comments

Comments
 (0)