Skip to content
This repository was archived by the owner on Jan 25, 2021. It is now read-only.

Commit e6f7ac1

Browse files
author
pcpLiu
committed
Fix previous force downcasting codes in several places.
Suggestion from: https://goo.gl/RyyFHo
1 parent 78dc86d commit e6f7ac1

5 files changed

Lines changed: 32 additions & 7 deletions

File tree

Source/Serrano/core/symbol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ extension ScalarSymbol {
229229
if bindedData == nil {
230230
return nil
231231
} else {
232-
return [self.bindedData as! DataSymbolSupportedDataType]
232+
return [self.bindedData!]
233233
}
234234
}
235235
}

Source/Serrano/graph/symbols/scalar_symbol.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ public class SerranoScalarSymbol: SerranoGraphSymbol, ScalarSymbol {
101101
return false
102102
}
103103

104-
self._bindedData = data as! SupportedScalarDataType
105-
104+
guard let bindedData = data as? SupportedScalarDataType else {
105+
SerranoLogging.errorLogging(message: "Scalar symbol \(self.symbolLabel) was trying to bind to data \(data). But seems this data is not a scalar.",
106+
file: "\(#file)", function: "\(#function)", line: "\(#line)")
107+
fatalError("Faltal error raised by Serrano. Check log for details.")
108+
}
109+
self._bindedData = bindedData
106110
return true
107111
}
108112
}

Source/Serrano/operators/nn/common/fullyconnected_op.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,19 @@ public class FullyconnectedOperator: ComputableOperator {
395395
fatalError("Faltal error raised by Serrano. Check log for details.")
396396
}
397397
if label == "weight" {
398-
self.weight = dataSymbol.bindedData! as! Tensor
398+
guard let weightTensor = dataSymbol.bindedData! as? Tensor else {
399+
SerranoLogging.errorLogging(message: "Fully connected operator \(self.operatorLabel) is trying to bind to data symbol \(dataSymbol) for weight. But seems this symbol is not a tensor symbol as expected.",
400+
file: "\(#file)", function: "\(#function)", line: "\(#line)")
401+
fatalError("Faltal error raised by Serrano. Check log for details.")
402+
}
403+
self.weight = weightTensor
399404
} else {
400-
self.bias = dataSymbol.bindedData! as! Tensor
405+
guard let biasTensor = dataSymbol.bindedData! as? Tensor else {
406+
SerranoLogging.errorLogging(message: "Fully connected operator \(self.operatorLabel) is trying to bind to data symbol \(dataSymbol) for bias. But seems this symbol is not a tensor symbol as expected.",
407+
file: "\(#file)", function: "\(#function)", line: "\(#line)")
408+
fatalError("Faltal error raised by Serrano. Check log for details.")
409+
}
410+
self.bias = biasTensor
401411
}
402412
}
403413
}

Source/Serrano/operators/nn/convolution/conv_op.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,13 @@ public class ConvOperator2D: ComputableOperator {
358358
fatalError("Faltal error raised by Serrano. Check log for details.")
359359
}
360360

361-
self.weight = dataSymbol.bindedData! as! Tensor
362-
361+
// self.weight = dataSymbol.bindedData! as! Tensor
362+
guard let weightTensor = dataSymbol.bindedData! as? Tensor else {
363+
SerranoLogging.errorLogging(message: "Cov2D operator \(self.operatorLabel) was trying to bind to data symbol \(dataSymbol). But seems this symbol is not a tensor symbol as expected.",
364+
file: "\(#file)", function: "\(#function)", line: "\(#line)")
365+
fatalError("Faltal error raised by Serrano. Check log for details.")
366+
}
367+
self.weight = weightTensor
363368
}
364369
}
365370

docs/Contribution/Contribution.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Contribution Guide
2+
3+
Please contribute to improve Serrano :hot_pepper: helping make it better.
4+
Before opening an issue or submitting a pull request, please read through this guide.
5+
6+
## Issue submitting

0 commit comments

Comments
 (0)