Skip to content

Commit 006bc07

Browse files
committed
add write
1 parent 05c43e1 commit 006bc07

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

Plugins/CodeGeneratorPlugin.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ import PackagePlugin
44
@main
55
struct CodeGeneratorPlugin: BuildToolPlugin {
66
func createBuildCommands(context: PackagePlugin.PluginContext, target _: PackagePlugin.Target) async throws -> [PackagePlugin.Command] {
7-
let output = context.pluginWorkDirectoryURL
7+
let output = context.pluginWorkDirectory
88
let floatingPointTypes: [String] = ["Float", "Double"]
99
let simdSizes = [2, 4, 8, 16, 32, 64]
1010

1111
let outputFiles = floatingPointTypes.flatMap { floatingPointType in
1212
simdSizes.flatMap { simdSize in
1313
[
14-
output.appending(component: "SIMD\(simdSize)+\(floatingPointType)+RealFunctions.swift"),
15-
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"),
1616
]
1717
} + [
18-
output.appending(component: "\(floatingPointType)+RealFunctions+Derivatives.swift"),
18+
output.appending("\(floatingPointType)+RealFunctions+Derivatives.swift"),
1919
]
2020
} + [
21-
output.appending(component: "SIMD+RealFunctions.swift"),
21+
output.appending("SIMD+RealFunctions.swift"),
2222
]
2323

2424
return [
2525
.buildCommand(
2626
displayName: "Generate Code",
27-
executable: try context.tool(named: "CodeGeneratorExecutable").url,
28-
arguments: [output.absoluteString],
27+
executable: try context.tool(named: "CodeGeneratorExecutable").path,
28+
arguments: [output.string],
2929
environment: [:],
3030
inputFiles: [],
3131
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", directoryHint: .notDirectory)
1515
let realFunctionsSIMDExtension = RealFunctionsGenerator.realFunctionsExtension(

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)