I/O

Warning

These functions have only been tested on OSX.

Functions

class io_swix.CSVFile[source]

A simple class to represent a CSV file. It has two members, “header” and “data”. “header” is a list of string and “data” is a matrix.

>>> var x:matrix = rand(N:(3, 3))
>>> csv = CSVFile(x, ["1", "2", "3"])
>>> write_csv(csv, filename:"/path/to/file")
>>>
>>> # one of the following options
>>> var csv:CSVFile = read_csv("/path/to/file")
>>> var x:matrix = read_csv("/path/to/file").data
io_swix.read_binary(x, filename)[source]
Parameters:
  • x (vector, matrix) – What to write to a file.
  • filename (String) – Where to write the file.
Returns:

The contents of the file. Either an vector or matrix.

io_swix.read_csv(filename)[source]

Reads a CSV.

Parameters:
  • filename (String) – The file to read from. The file read from the directory containing swix/.
  • rowWithoutMissingData (Int) – A row that has complete data. From this row, we infer if that particular row is categorical or numerical for the entire CSV. If there are N categories, we assign indicies 0 through N-1.
  • header_present – If false, the first row will be included as part of the dataset. It default to true in which case the header will also be returned.
Return type:

vector. The contents of the csv.

See also

read_binary()

io_swix.write_binary(x, filename)[source]
Parameters:
  • x (vector, matrix) – The content to write to a file.
  • filename (String) – Where to write the file.
>>> # SWIFT
>>> var N = 5
>>> var x = ones((N, N)) * phi
>>> write_binary(x, filename:"x.bin")
>>> #
>>> # PYTHON:
>>> data = np.fromfile("x.bin")
>>> width, height = data[0], data[1]
>>> x = data[2:].reshape(width, height)
io_swix.write_csv(x, filename, header)[source]

Writes a CSV.

Parameters:
  • x (vector, matrix, CSVFile) – The vector to write to a csv
  • header (List of strings.) – The header to write at the top of the CSV file
  • filename (String) – Where to write.

See also

write_binary()

Binary example; optimized

>>> var x = arange(9).reshape((3,3))
>>> write_binary(x, filename:"x.npy")
>>> #
>>> # be sure to include what type the variable is!
>>> var y:matrix = read_binary("x.npy")
>>> var z:vector = read_binary("x.npy")

CSV example; unoptimized

>>> var x = arange(9).reshape((3,3))
>>> write_csv(x, filename:"x.csv")
>>> #
>>> # be sure to include what type the variable is!
>>> var y:matrix = read_csv("x.csv")
>>> var z:vector = read_csv("x.csv")