NdArray
NdArray copied to clipboard
Make index slices ExpressibleByIntegerLiteral
trafficstars
To remove the need to convert to a slice expliclty a[Slice(1)] one can make Slice conform to ExpressibleByIntegerLiteral.
This should not be done before the old index API is removed, since old slices with strides:
let a = A[0..., 2]
would be interpreted as
let a = A[0..., Slice(2)]
leading to unexpected behaviour.
/**
Auto convert integer literals to an index slice.
let s = a[..., 1]
*/
extension Slice: ExpressibleByIntegerLiteral {
public typealias IntegerLiteralType = Int
public init(integerLiteral i: Int) {
self.init(i)
}
}
The question will be if
let a[1] = 9
will work as expected.