- Proposal: SE-NNNN
- Authors: Marc Rasi, Chris Lattner
- Review Manager: TBD
- Status: Awaiting implementation
Swift-evolution thread: https://forums.swift.org/t/pitch-compile-time-constant-expressions-for-swift/12879
Swift-evolution thread: https://forums.swift.org/t/pitch-compile-time-constant-expressions-for-swift/12879
protocol Proto { | |
@differentiable(reverse) | |
func f(_ x: Float) -> Float | |
} | |
func callF<T: Proto>(_ t: T, _ x: Float) -> Float { | |
return t.f(x) | |
} | |
func gradFWrtX<T: Proto>(_ t: T, at x: Float) -> Float { |
sil_stage canonical | |
import Builtin | |
import Swift | |
import SwiftShims | |
protocol Proto { | |
@differentiable(reverse) | |
func f(_ x: Float) -> Float | |
} |
[1/33] Performing build step for 'libdispatch' | |
ninja: no work to do. | |
[2/27] Compiling /usr/local/google/home/marcrasi/swift-base/build/buildbot_linux/swift-linux-x86_64/stdlib/public/core/linux/x86_64/Swift.o | |
FAILED: stdlib/public/core/linux/x86_64/Swift.o | |
cd /usr/local/google/home/marcrasi/swift-base/build/buildbot_linux/swift-linux-x86_64/stdlib/public/core && /usr/bin/python /usr/local/google/home/marcrasi/swift-base/swift/utils/line-directive @/usr/local/google/home/marcrasi/swift-base/build/buildbot_linux/swift-linux-x86_64/stdlib/public/core/OdCaQ.txt -- /usr/local/google/home/marcrasi/swift-base/build/buildbot_linux/swift-linux-x86_64/./bin/swiftc -c -sdk / -target x86_64-unknown-linux-gnu -resource-dir /usr/local/google/home/marcrasi/swift-base/build/buildbot_linux/swift-linux-x86_64/./lib/swift -O -I /usr/local/google/home/marcrasi/swift-base/build/buildbot_linux/swift-linux-x86_64/./lib/swift/linux/x86_64 -module-cache-path /usr/local/google/home/marcrasi/swift-base/build/buildbot_linux/swift-linux |
# -*- coding: utf-8 -*- | |
"""split_into_batches_oom.ipynb | |
Automatically generated by Colaboratory. | |
Original file is located at | |
https://colab.research.google.com/drive/1UWb-URpxZgdkTICBZlxGWfJr7U35uvJk | |
""" | |
# %enableCompletion |
import TensorFlow | |
struct ConvBN: Layer { | |
var conv: Conv2D<Float> | |
var norm: BatchNorm<Float> | |
public init(filterShape: (Int, Int, Int, Int), strides: (Int, Int) = (1, 1), | |
padding: Padding, learningPhaseIndicator: LearningPhaseIndicator) { | |
self.conv = Conv2D( | |
filterShape: filterShape, strides: strides, padding: padding) |
First the package needs a dynamic library product. You might have to modify the package to have one. Here's an example.
Now make a notebook that clones the package, builds the package, and copies the build artifacts into the right places. Here's an example.
In a Swift notebook, dlopen the shared library and then import the module. For example:
import Glibc
dlopen("/swift/toolchain/usr/lib/swift/linux/libDeckOfPlayingCards.so", RTLD_NOW)
import DeckOfPlayingCards
public struct ProductSpaceVector<Element> { | |
public var elements: [Element] | |
public init(_ elements: [Element]) { self.elements = elements } | |
} | |
extension ProductSpaceVector : Equatable where Element : Equatable { | |
public static func == (lhs: ProductSpaceVector, rhs: ProductSpaceVector) -> Bool { | |
return lhs.elements == rhs.elements | |
} | |
} |
public struct ProductSpaceVector<Element> { | |
public var elements: [Element] | |
public init(_ elements: [Element]) { self.elements = elements } | |
} | |
extension ProductSpaceVector : Equatable where Element : Equatable { | |
public static func == (lhs: ProductSpaceVector, rhs: ProductSpaceVector) -> Bool { | |
return lhs.elements == rhs.elements | |
} | |
} |
extension Array where Element: Differentiable { | |
/// Views the array as the differentiable product manifold of `Element` with itself `count` times. | |
public struct DifferentiableView: Differentiable { | |
/// The array that we are viewing. | |
public var base: [Element] | |
/// Construct a view of the given array. | |
public init(_ base: [Element]) { self.base = base } | |
// MARK: - Differentiable conformance. |