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

io_swix.read_binary(x, filename)[source]
Parameters: x (vector, matrix) – What to write to a file. filename (String) – Where to write the file. The contents of the file. Either an vector or matrix.
io_swix.read_csv(filename)[source]

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. vector. The contents of the csv.
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.

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 x = arange(9).reshape((3,3))