File tree 5 files changed +40
-25
lines changed
Tests/SwiftFusionTests/Core 5 files changed +40
-25
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"object" : {
3
3
"pins" : [
4
- {
5
- "package" : " Benchmark" ,
6
- "repositoryURL" : " https://github.com/google/swift-benchmark.git" ,
7
- "state" : {
8
- "branch" : null ,
9
- "revision" : " 8e0ef8bb7482ab97dcd2cd1d6855bd38921c345d" ,
10
- "version" : " 0.1.0"
11
- }
12
- },
13
4
{
14
5
"package" : " CSV.swift" ,
15
6
"repositoryURL" : " https://github.com/yaslab/CSV.swift.git" ,
46
37
"version" : " 0.3.1"
47
38
}
48
39
},
40
+ {
41
+ "package" : " Benchmark" ,
42
+ "repositoryURL" : " https://github.com/google/swift-benchmark.git" ,
43
+ "state" : {
44
+ "branch" : null ,
45
+ "revision" : " 8e0ef8bb7482ab97dcd2cd1d6855bd38921c345d" ,
46
+ "version" : " 0.1.0"
47
+ }
48
+ },
49
+ {
50
+ "package" : " swift-models" ,
51
+ "repositoryURL" : " https://github.com/tensorflow/swift-models.git" ,
52
+ "state" : {
53
+ "branch" : null ,
54
+ "revision" : " b2fc0325bf9d476bf2d7a4cd0a09d36486c506e4" ,
55
+ "version" : null
56
+ }
57
+ },
58
+ {
59
+ "package" : " SwiftProtobuf" ,
60
+ "repositoryURL" : " https://github.com/apple/swift-protobuf.git" ,
61
+ "state" : {
62
+ "branch" : null ,
63
+ "revision" : " da9a52be9cd36c63993291ce3f1b65dafcd1e826" ,
64
+ "version" : " 1.14.0"
65
+ }
66
+ },
49
67
{
50
68
"package" : " swift-tools-support-core" ,
51
69
"repositoryURL" : " https://github.com/apple/swift-tools-support-core.git" ,
Original file line number Diff line number Diff line change @@ -128,11 +128,11 @@ extension TensorVector: Vector {
128
128
129
129
/// Returns the result of calling `body` on the scalars of `self`.
130
130
public mutating func withUnsafeMutableBufferPointer< R> (
131
- _ body: ( UnsafeMutableBufferPointer < Double > ) throws -> R
131
+ _ body: ( inout UnsafeMutableBufferPointer < Double > ) throws -> R
132
132
) rethrows -> R {
133
133
var scalars = self . tensor. scalars
134
134
let r = try scalars. withUnsafeMutableBufferPointer { b in
135
- try body ( b)
135
+ try body ( & b)
136
136
}
137
137
self . tensor = Tensor ( shape: self . shape, scalars: scalars)
138
138
return r
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ public protocol Vector: Differentiable where Self.TangentVector == Self {
78
78
/// A default is provided that is correct for types that are represented as contiguous scalars
79
79
/// in memory.
80
80
mutating func withUnsafeMutableBufferPointer< R> (
81
- _ body: ( UnsafeMutableBufferPointer < Double > ) throws -> R
81
+ _ body: ( inout UnsafeMutableBufferPointer < Double > ) throws -> R
82
82
) rethrows -> R
83
83
#endif
84
84
}
@@ -233,14 +233,13 @@ extension Vector {
233
233
234
234
/// Returns the result of calling `body` on the scalars of `self`.
235
235
public mutating func withUnsafeMutableBufferPointer< R> (
236
- _ body: ( UnsafeMutableBufferPointer < Double > ) throws -> R
236
+ _ body: ( inout UnsafeMutableBufferPointer < Double > ) throws -> R
237
237
) rethrows -> R {
238
- return try withUnsafeMutablePointer ( to: & self ) { [ dimension = self . dimension] p in
239
- try body (
240
- UnsafeMutableBufferPointer < Double > (
241
- start: UnsafeMutableRawPointer ( p)
242
- . assumingMemoryBound ( to: Double . self) ,
243
- count: dimension) )
238
+ try withUnsafeMutablePointer ( to: & self ) { [ dimension = self . dimension] p in
239
+ var b = UnsafeMutableBufferPointer < Double > (
240
+ start: UnsafeMutableRawPointer ( p) . assumingMemoryBound ( to: Double . self) ,
241
+ count: dimension)
242
+ return try body ( & b)
244
243
}
245
244
}
246
245
}
Original file line number Diff line number Diff line change @@ -180,10 +180,10 @@ extension AnyVectorArrayBuffer: Vector {
180
180
181
181
/// Returns the result of calling `body` on the scalars of `self`.
182
182
public mutating func withUnsafeMutableBufferPointer< R> (
183
- _ body: ( UnsafeMutableBufferPointer < Double > ) throws -> R
183
+ _ body: ( inout UnsafeMutableBufferPointer < Double > ) throws -> R
184
184
) rethrows -> R {
185
185
var buffer = Array ( scalars)
186
- let r = try buffer. withUnsafeMutableBufferPointer { try body ( $0) }
186
+ let r = try buffer. withUnsafeMutableBufferPointer { try body ( & $0) }
187
187
scalars. assign ( buffer)
188
188
return r
189
189
}
Original file line number Diff line number Diff line change @@ -100,10 +100,8 @@ extension Vector {
100
100
}
101
101
102
102
mutableSelf = self
103
- mutableSelf. withUnsafeMutableBufferPointer { b in
104
- for (i, j) in zip ( b. indices, distinctScalars. indices) {
105
- b [ i] = distinctScalars [ j]
106
- }
103
+ _ = mutableSelf. withUnsafeMutableBufferPointer { b in
104
+ b. assign ( distinctScalars)
107
105
}
108
106
XCTAssertTrue ( mutableSelf. scalars. elementsEqual ( distinctScalars) )
109
107
}
You can’t perform that action at this time.
0 commit comments