Skip to content

Commit aac355d

Browse files
committed
add write
1 parent 13fafaa commit aac355d

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

Plugins/CodeGeneratorPlugin.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,29 @@ import PackagePlugin
33

44
@main
55
struct CodeGeneratorPlugin: BuildToolPlugin {
6-
func createBuildCommands(context: PackagePlugin.PluginContext, target: PackagePlugin.Target) async throws -> [PackagePlugin.Command] {
7-
let output = context.pluginWorkDirectoryURL.appending(component: "GeneratedCode")
8-
6+
func createBuildCommands(context: PackagePlugin.PluginContext, target _: PackagePlugin.Target) async throws -> [PackagePlugin.Command] {
7+
let output = context.pluginWorkDirectory.appending("GeneratedCode")
98
let floatingPointTypes: [String] = ["Float", "Double"]
109
let simdSizes = [2, 4, 8, 16, 32, 64]
1110

1211
let outputFiles = floatingPointTypes.flatMap { floatingPointType in
1312
simdSizes.flatMap { simdSize in
1413
[
15-
output.appending(component: "SIMD\(simdSize)+\(floatingPointType)+RealFunctions.swift"),
16-
output.appending(component: "SIMD\(simdSize)+\(floatingPointType)+RealFunctions+Derivatives.swift"),
14+
output.appending("SIMD\(simdSize)+\(floatingPointType)+RealFunctions.swift"),
15+
output.appending("SIMD\(simdSize)+\(floatingPointType)+RealFunctions+Derivatives.swift"),
1716
]
1817
} + [
19-
output.appending(component: "\(floatingPointType)+RealFunctions+Derivatives.swift"),
18+
output.appending("\(floatingPointType)+RealFunctions+Derivatives.swift"),
2019
]
2120
} + [
22-
output.appending(component: "SIMD+RealFunctions.swift")
21+
output.appending("SIMD+RealFunctions.swift"),
2322
]
2423

2524
return [
2625
.buildCommand(
2726
displayName: "Generate Code",
28-
executable: try context.tool(named: "CodeGeneratorExecutable").url,
29-
arguments: [output.absoluteString],
27+
executable: try context.tool(named: "CodeGeneratorExecutable").path,
28+
arguments: [output.string],
3029
environment: [:],
3130
inputFiles: [],
3231
outputFiles: outputFiles

Sources/CodeGeneratorExecutable/CodeGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct CodeGenerator {
99
}
1010
// arguments[0] is the path to this command line tool
1111
let output = URL(filePath: CommandLine.arguments[1])
12-
12+
1313
// generate default implementations of RealFunctions for SIMD protocol
1414
let realFunctionSIMDFileURL = output.appending(component: "SIMD+RealFunctions.swift")
1515
let realFunctionsSIMDExtension = RealFunctionsGenerator.realFunctionsExtension(objectType: "SIMD", type: "Self", whereClause: true, simdAccelerated: false)

Sources/RealModuleDifferentiable/FloatingPoint+ConcreteImplementations.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ extension Double {
1515
}
1616
}
1717

18+
#if !(os(macOS) || os(iOS) || os(tvOS) || os(watchOS))
19+
// This is a concrete version of the default implementation on the `Real` protocol
20+
// this exists here so we can associate a derivative with this function on platforms that do not have a math library that provides exp10
21+
extension Float {
22+
@_transparent
23+
public static func exp10(_ x: Float) -> Float {
24+
pow(10, x)
25+
}
26+
}
27+
28+
extension Double {
29+
@_transparent
30+
public static func exp10(_ x: Double) -> Double {
31+
pow(10, x)
32+
}
33+
}
34+
#endif
35+
1836
// Extensions so that SIMD can have a fallback `abs` implementation with similar api as the RealFunctions protocol
1937
extension Float {
2038
@_transparent

0 commit comments

Comments
 (0)