This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if false | |
Changes to Unmanaged | |
-public struct Unmanaged<Instance : AnyObject> { | |
// New API: `UnsafeReference(bitPattern:)`. | |
- public static func fromOpaque(value: COpaquePointer) -> Unmanaged | |
// New API: `OpaquePointer(bitPattern:)`. | |
- public func toOpaque() -> COpaquePointer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A Dictionary with a nominal `Element` type, that can conform to things. | |
@frozen public struct Dictionary2<Key: Hashable, Value> { | |
public typealias Base = [Key : Value] | |
/// A view of a dictionary's keys. | |
public typealias Keys = Base.Keys | |
/// A view of a dictionary's values. | |
public typealias Values = Base.Values | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (A) Definition | |
protocol P { | |
static var isEquatable: Bool { get } | |
} | |
// (B) Default implementation | |
extension P { | |
static var isEquatable: Bool { false } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Sequence { | |
var array: Array<Element> { | |
print("preallocating", self.underestimatedCount) | |
return Array(self) | |
} | |
} | |
_ = Array(0..<1000).reversed().array // preallocating 1000 | |
_ = repeatElement(1..<10, count: 200).joined().array // preallocating 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A repository of functionality depending on the conformances of `Model`. | |
/// | |
/// Conditional conformances provide implementation functions that take a | |
/// generic argument type with the safe assumption that the argument's concrete | |
/// type is `Model`. | |
struct Dispatch<Model> { | |
/// Returns `f(a as! Model) as! R1` | |
/// | |
/// Used by implementation functions to avoid the clutter of casting | |
/// explicitly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol True {} | |
struct IsBidirectional<C> {} | |
extension IsBidirectional: True where C : BidirectionalCollection { } | |
extension Collection { | |
var isBidirectional: Bool { | |
return IsBidirectional<Self>() is True | |
} | |
} | |
func testIsBidirectional() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A simple pseudo-random number generator. | |
struct LinearCongruential: RandomNumberGenerator { | |
/// The last value returned by `self.next`, or what `self` was seeded with. | |
private var lastValue: UInt64 | |
/// Creates an instance with the given seed. | |
/// | |
/// Instances created with the same seed produce the same sequence of | |
/// pseuedo-random results from `next()`. | |
init(seed: UInt64 = 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Please see https://github.com/dabrahams/DivideAndConquer where this has moved. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Tensor<Scalar> { | |
let count: Int | |
let indexer: (Int) -> Scalar | |
init<Base: RandomAccessCollection>(_ base: Base) | |
where Base.Element == Scalar | |
{ | |
count = base.count | |
indexer = { base[base.index(base.startIndex, offsetBy: $0)] } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol TensorElement { | |
static func box<T: LazyTensor>(_:T) -> TensorBoxBase<Self> | |
where T.Scalar == Self | |
} | |
extension TensorElement { | |
static func box<T: LazyTensor>(_ x:T) -> TensorBoxBase<Self> | |
where T.Scalar == Self | |
{ | |
TensorBox(x) |