Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 40c239b

Browse files
committed
Use URL.deletingLastPathComponent.
`deletingLastPathComponent` is the proper way to get the parent directory for a `URL`. The old method `appendingPathComponent("..")` worked on Mac but not Ubuntu.
1 parent 52a11a6 commit 40c239b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

MNIST/MNIST.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func train(_ parameters: inout MNISTParameters, iterationCount: Int) {
4646
let currentDirectory = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
4747
let currentScriptPath = URL(fileURLWithPath: CommandLine.arguments[0],
4848
relativeTo: currentDirectory)
49-
let scriptDirectory = currentScriptPath.appendingPathComponent("..")
49+
let scriptDirectory = currentScriptPath.deletingLastPathComponent()
5050

5151
// Get training data.
5252
let imagesFile = scriptDirectory.appendingPathComponent("train-images-idx3-ubyte").path
@@ -91,7 +91,7 @@ func train(_ parameters: inout MNISTParameters, iterationCount: Int) {
9191
let part1 = -labels * log(predictions)
9292
let part2 = -(1 - labels) * log(1 - predictions)
9393
loss = (part1 + part2).sum() / batchSize
94-
94+
9595
print("Loss:", loss)
9696
}
9797
}

0 commit comments

Comments
 (0)