@@ -89,9 +89,7 @@ extension BNNSImageStackDescriptor {
89
89
channels: Int,
90
90
row_stride: Int,
91
91
image_stride: Int,
92
- data_type: BNNSDataType,
93
- data_scale: Float = 1,
94
- data_bias: Float = 0) {
92
+ data_type: BNNSDataType) {
95
93
96
94
_precondition(data_type != .indexed8,
97
95
"Image stacks cannot use the indexed8 data type.")
@@ -102,25 +100,23 @@ extension BNNSImageStackDescriptor {
102
100
self.row_stride = row_stride
103
101
self.image_stride = image_stride
104
102
self.data_type = data_type
105
- self.data_scale = data_scale
106
- self.data_bias = data_bias
103
+ self.data_scale = 1
104
+ self.data_bias = 0
107
105
}
108
106
}
109
107
110
108
extension BNNSVectorDescriptor {
111
109
${available(bnns2016)}
112
110
public init(size: Int,
113
- data_type: BNNSDataType,
114
- data_scale: Float = 1,
115
- data_bias: Float = 0) {
111
+ data_type: BNNSDataType) {
116
112
117
113
_precondition(data_type != .indexed8,
118
114
"Vectors cannot use the indexed8 data type.")
119
115
120
116
self.size = size
121
117
self.data_type = data_type
122
- self.data_scale = data_scale
123
- self.data_bias = data_bias
118
+ self.data_scale = 1
119
+ self.data_bias = 0
124
120
}
125
121
}
126
122
@@ -129,25 +125,34 @@ extension BNNSLayerData {
129
125
public init(data: UnsafeRawPointer?,
130
126
data_type: BNNSDataType,
131
127
data_scale: Float = 1,
132
- data_bias: Float = 0,
133
- data_table: UnsafePointer<Float>? = nil) {
128
+ data_bias: Float = 0) {
134
129
135
- if data_type == .indexed8 {
136
- _precondition(data_table != nil,
137
- "data_table cannot be nil if data_type is .indexed8.")
138
- }
130
+ _precondition(data_type != .indexed8,
131
+ "This initializer cannot be used with the indexed8 data type; use BNNSLayerData.indexed8 instead.")
139
132
140
133
self.data = data
141
134
self.data_type = data_type
142
135
self.data_scale = data_scale
143
136
self.data_bias = data_bias
144
- self.data_table = data_table
137
+ self.data_table = nil
145
138
}
146
139
147
140
${available(bnns2016)}
148
141
public static var zero: BNNSLayerData {
149
142
return BNNSLayerData()
150
143
}
144
+
145
+ /// A BNNSLayerData object with the indexed8 data type.
146
+ ${available(bnns2016)}
147
+ public static func indexed8(data: UnsafePointer<Int8>?,
148
+ data_table: UnsafePointer<Float>)
149
+ -> BNNSLayerData {
150
+ return BNNSLayerData(data: data,
151
+ data_type: .indexed8,
152
+ data_scale: 1, // unused
153
+ data_bias: 0, // unused
154
+ data_table: data_table)
155
+ }
151
156
}
152
157
153
158
extension BNNSActivation {
@@ -231,9 +236,7 @@ extension BNNSConvolutionLayerParameters {
231
236
k_height: Int,
232
237
in_channels: Int,
233
238
out_channels: Int,
234
- weights: BNNSLayerData,
235
- bias: BNNSLayerData = .zero,
236
- activation: BNNSActivation = .identity) {
239
+ weights: BNNSLayerData) {
237
240
self.x_stride = x_stride
238
241
self.y_stride = y_stride
239
242
self.x_padding = x_padding
@@ -243,8 +246,8 @@ extension BNNSConvolutionLayerParameters {
243
246
self.in_channels = in_channels
244
247
self.out_channels = out_channels
245
248
self.weights = weights
246
- self.bias = bias
247
- self.activation = activation
249
+ self.bias = .zero
250
+ self.activation = .identity
248
251
}
249
252
}
250
253
@@ -258,9 +261,7 @@ extension BNNSPoolingLayerParameters {
258
261
k_height: Int,
259
262
in_channels: Int,
260
263
out_channels: Int,
261
- pooling_function: BNNSPoolingFunction,
262
- bias: BNNSLayerData = .zero,
263
- activation: BNNSActivation = .identity) {
264
+ pooling_function: BNNSPoolingFunction) {
264
265
self.x_stride = x_stride
265
266
self.y_stride = y_stride
266
267
self.x_padding = x_padding
@@ -270,22 +271,20 @@ extension BNNSPoolingLayerParameters {
270
271
self.in_channels = in_channels
271
272
self.out_channels = out_channels
272
273
self.pooling_function = pooling_function
273
- self.bias = bias
274
- self.activation = activation
274
+ self.bias = .zero
275
+ self.activation = .identity
275
276
}
276
277
}
277
278
278
279
extension BNNSFullyConnectedLayerParameters {
279
280
${available(bnns2016)}
280
281
public init(in_size: Int,
281
282
out_size: Int,
282
- weights: BNNSLayerData,
283
- bias: BNNSLayerData = .zero,
284
- activation: BNNSActivation = .identity) {
283
+ weights: BNNSLayerData) {
285
284
self.in_size = in_size
286
285
self.out_size = out_size
287
286
self.weights = weights
288
- self.bias = bias
289
- self.activation = activation
287
+ self.bias = .zero
288
+ self.activation = .identity
290
289
}
291
290
}
0 commit comments