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

Use #file to get Swift script location. #20

Merged
merged 1 commit into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Autoencoder/Autoencoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ let outputFolder = "/tmp/mnist-test/"

func readDataset() -> (images: Tensor<Float>, labels: Tensor<Int32>)? {
print("Reading the data.")
guard let swiftFile = CommandLine.arguments.first else { return nil }
let swiftFileURL = URL(fileURLWithPath: swiftFile)
let swiftFileURL = URL(fileURLWithPath: #file)
var imageFolderURL = swiftFileURL.deletingLastPathComponent()
var labelFolderURL = swiftFileURL.deletingLastPathComponent()
imageFolderURL.appendPathComponent("Resources/train-images-idx3-ubyte")
Expand Down
8 changes: 3 additions & 5 deletions MNIST/MNIST.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ struct MNISTParameters : ParameterAggregate {

/// Train a MNIST classifier for the specified number of iterations.
func train(_ parameters: inout MNISTParameters, iterationCount: Int) {
// Get script directory. This is necessary for MNIST.swift to work when
// invoked from any directory.
let currentDirectory = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
let currentScriptPath = URL(fileURLWithPath: CommandLine.arguments[0],
relativeTo: currentDirectory)
// Get script path. This is necessary for MNIST.swift to work when invoked
// from any directory.
let currentScriptPath = URL(fileURLWithPath: #file)
let scriptDirectory = currentScriptPath.deletingLastPathComponent()

// Get training data.
Expand Down