Skip to content

Commit 504e751

Browse files
committed
[FORMATTING] apply formatting to the Python API files
Closes #2115
1 parent 7bc6ee4 commit 504e751

File tree

113 files changed

+2072
-1474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+2072
-1474
lines changed

src/main/python/systemds/context/systemds_context.py

Lines changed: 202 additions & 118 deletions
Large diffs are not rendered by default.

src/main/python/systemds/examples/tutorials/adult.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,56 +47,62 @@ class DataManager:
4747
_data_string_labels: list
4848

4949
def __init__(self):
50-
self._data_zip_url = "https://systemds.apache.org/assets/datasets/adult/data.zip"
50+
self._data_zip_url = (
51+
"https://systemds.apache.org/assets/datasets/adult/data.zip"
52+
)
5153
self._data_zip_loc = "systemds/examples/tutorials/adult/data.zip"
5254

5355
self._train_data_loc = "systemds/examples/tutorials/adult/train_data.csv"
5456
self._test_data_loc = "systemds/examples/tutorials/adult/test_data.csv"
5557
self._jspec_loc = "systemds/examples/tutorials/adult/jspec.json"
5658

5759
def get_preprocessed_dataset(self, sds: SystemDSContext) -> List[pd.DataFrame]:
58-
return self.get_train_data(sds), \
59-
self.get_train_labels(sds), \
60-
self.get_test_data(sds), \
61-
self.get_test_labels(sds)
62-
63-
def get_preprocessed_dataset_pandas(self, sds: SystemDSContext) -> List[pd.DataFrame]:
64-
return self.get_train_data_pandas(sds), \
65-
self.get_train_labels_pandas(sds), \
66-
self.get_test_data_pandas(sds), \
67-
self.get_test_labels_pandas(sds)
60+
return (
61+
self.get_train_data(sds),
62+
self.get_train_labels(sds),
63+
self.get_test_data(sds),
64+
self.get_test_labels(sds),
65+
)
66+
67+
def get_preprocessed_dataset_pandas(
68+
self, sds: SystemDSContext
69+
) -> List[pd.DataFrame]:
70+
return (
71+
self.get_train_data_pandas(sds),
72+
self.get_train_labels_pandas(sds),
73+
self.get_test_data_pandas(sds),
74+
self.get_test_labels_pandas(sds),
75+
)
6876

6977
def get_train_data_pandas(self) -> pd.DataFrame:
7078
self._get_data(self._train_data_loc)
71-
return self._parse_data(self._train_data_loc)\
72-
.drop(labels=["income"], axis=1)
79+
return self._parse_data(self._train_data_loc).drop(labels=["income"], axis=1)
7380

74-
def get_train_data(self, sds: SystemDSContext) -> 'Frame':
81+
def get_train_data(self, sds: SystemDSContext) -> "Frame":
7582
self._get_data(self._train_data_loc)
7683
return sds.read(self._train_data_loc)[:, 0:14]
7784

7885
def get_train_labels_pandas(self) -> pd.DataFrame:
7986
self._get_data(self._train_data_loc)
8087
return self._parse_data(self._train_data_loc)[["income"]]
8188

82-
def get_train_labels(self, sds: SystemDSContext) -> 'Frame':
89+
def get_train_labels(self, sds: SystemDSContext) -> "Frame":
8390
self._get_data(self._train_data_loc)
8491
return sds.read(self._train_data_loc)[:, 14]
8592

8693
def get_test_data_pandas(self) -> pd.DataFrame:
8794
self._get_data(self._test_data_loc)
88-
return self._parse_data(self._test_data_loc)\
89-
.drop(labels=["income"], axis=1)
95+
return self._parse_data(self._test_data_loc).drop(labels=["income"], axis=1)
9096

91-
def get_test_data(self, sds: SystemDSContext) -> 'Frame':
97+
def get_test_data(self, sds: SystemDSContext) -> "Frame":
9298
self._get_data(self._test_data_loc)
9399
return sds.read(self._test_data_loc)[:, 0:14]
94100

95101
def get_test_labels_pandas(self) -> pd.DataFrame:
96102
self._get_data(self._test_data_loc)
97103
return self._parse_data(self._test_data_loc)[["income"]]
98104

99-
def get_test_labels(self, sds: SystemDSContext) -> 'Frame':
105+
def get_test_labels(self, sds: SystemDSContext) -> "Frame":
100106
self._get_data(self._test_data_loc)
101107
return sds.read(self._test_data_loc)[:, 14]
102108

@@ -105,7 +111,7 @@ def get_jspec_string(self) -> str:
105111
with open(self._jspec_loc, "r") as f:
106112
return f.read()
107113

108-
def get_jspec(self, sds: SystemDSContext) -> 'Scalar':
114+
def get_jspec(self, sds: SystemDSContext) -> "Scalar":
109115
self._get_data(self._jspec_loc)
110116
return sds.read(self._jspec_loc, data_type="scalar", value_type="string")
111117

@@ -119,7 +125,7 @@ def _get_data(self, loc):
119125
os.makedirs(folder)
120126
if not os.path.isfile(self._data_zip_loc):
121127
myZip = requests.get(self._data_zip_url)
122-
with open(self._data_zip_loc, 'wb') as f:
128+
with open(self._data_zip_loc, "wb") as f:
123129
f.write(myZip.content)
124130
with zipfile.ZipFile(self._data_zip_loc) as z:
125131
z.extractall(folder)

src/main/python/systemds/examples/tutorials/mnist.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,26 @@ def get_test_labels(self) -> np.array:
7272
return self._parse_data(self._test_labels_loc)
7373

7474
def _parse_data(self, loc):
75-
f = gzip.open if os.path.splitext(loc)[1] == '.gz' else open
76-
with f(loc, 'rb') as fd:
75+
f = gzip.open if os.path.splitext(loc)[1] == ".gz" else open
76+
with f(loc, "rb") as fd:
7777
return self._parse(fd)
7878

7979
def _parse(self, fd):
80-
DATA_TYPES = {0x08: 'B', # unsigned byte
81-
0x09: 'b', # signed byte
82-
0x0b: 'h', # short (2 bytes)
83-
0x0c: 'i', # int (4 bytes)
84-
0x0d: 'f', # float (4 bytes)
85-
0x0e: 'd'} # double (8 bytes)
80+
DATA_TYPES = {
81+
0x08: "B", # unsigned byte
82+
0x09: "b", # signed byte
83+
0x0B: "h", # short (2 bytes)
84+
0x0C: "i", # int (4 bytes)
85+
0x0D: "f", # float (4 bytes)
86+
0x0E: "d",
87+
} # double (8 bytes)
8688

8789
header = fd.read(4)
88-
zeros, data_type, num_dimensions = struct.unpack('>HBB', header)
90+
zeros, data_type, num_dimensions = struct.unpack(">HBB", header)
8991
data_type = DATA_TYPES[data_type]
90-
dimension_sizes = struct.unpack('>' + 'I' * num_dimensions,
91-
fd.read(4 * num_dimensions))
92+
dimension_sizes = struct.unpack(
93+
">" + "I" * num_dimensions, fd.read(4 * num_dimensions)
94+
)
9295

9396
data = array.array(data_type, fd.read())
9497
data.byteswap() # looks like array.array reads data as little endian
@@ -103,5 +106,5 @@ def _get_data(self, url, loc):
103106
folder = os.path.dirname(loc)
104107
if not os.path.isdir(folder):
105108
os.makedirs(folder)
106-
with open(loc, 'wb') as f:
109+
with open(loc, "wb") as f:
107110
f.write(myfile.content)

src/main/python/systemds/operator/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,15 @@
3030
from systemds.operator.nodes.source import Source
3131
from systemds.operator import algorithm
3232

33-
__all__ = ["OperationNode", "algorithm", "Scalar", "List",
34-
"ListAccess", "Matrix", "Frame", "Source", "MultiReturn", "Combine"]
33+
__all__ = [
34+
"OperationNode",
35+
"algorithm",
36+
"Scalar",
37+
"List",
38+
"ListAccess",
39+
"Matrix",
40+
"Frame",
41+
"Source",
42+
"MultiReturn",
43+
"Combine",
44+
]

src/main/python/systemds/operator/nn/affine.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@ def __init__(self, sds_context: SystemDSContext, d, m, seed=-1):
3131
"""
3232
sds_context: The systemdsContext to construct the layer inside of
3333
d: The number of features that are input to the affine layer
34-
m: The number of neurons that are contained in the layer,
34+
m: The number of neurons that are contained in the layer,
3535
and the number of features output
3636
"""
37-
super().__init__(sds_context, 'affine.dml')
37+
super().__init__(sds_context, "affine.dml")
3838
self._X = None
3939

4040
# init weight and bias
41-
self.weight = Matrix(sds_context, '')
42-
self.bias = Matrix(sds_context, '')
43-
params_dict = {'D': d, 'M': m, 'seed': seed}
41+
self.weight = Matrix(sds_context, "")
42+
self.bias = Matrix(sds_context, "")
43+
params_dict = {"D": d, "M": m, "seed": seed}
4444
out = [self.weight, self.bias]
45-
op = MultiReturn(sds_context, "affine::init", output_nodes=out, named_input_nodes=params_dict)
45+
op = MultiReturn(
46+
sds_context, "affine::init", output_nodes=out, named_input_nodes=params_dict
47+
)
4648
self.weight._unnamed_input_nodes = [op]
4749
self.bias._unnamed_input_nodes = [op]
4850
op._source_node = self._source
@@ -59,7 +61,7 @@ def forward(X: Matrix, W: Matrix, b: Matrix):
5961
return Affine._source.forward(X, W, b)
6062

6163
@staticmethod
62-
def backward(dout:Matrix, X: Matrix, W: Matrix, b: Matrix):
64+
def backward(dout: Matrix, X: Matrix, W: Matrix, b: Matrix):
6365
"""
6466
dout: The gradient of the output, passed from the upstream
6567
X: The input matrix of this layer
@@ -69,12 +71,14 @@ def backward(dout:Matrix, X: Matrix, W: Matrix, b: Matrix):
6971
"""
7072
sds = X.sds_context
7173
Affine._create_source(sds, "affine.dml")
72-
params_dict = {'dout': dout, 'X': X, 'W': W, 'b': b}
73-
dX = Matrix(sds, '')
74-
dW = Matrix(sds, '')
75-
db = Matrix(sds, '')
74+
params_dict = {"dout": dout, "X": X, "W": W, "b": b}
75+
dX = Matrix(sds, "")
76+
dW = Matrix(sds, "")
77+
db = Matrix(sds, "")
7678
out = [dX, dW, db]
77-
op = MultiReturn(sds, "affine::backward", output_nodes=out, named_input_nodes=params_dict)
79+
op = MultiReturn(
80+
sds, "affine::backward", output_nodes=out, named_input_nodes=params_dict
81+
)
7882
dX._unnamed_input_nodes = [op]
7983
dW._unnamed_input_nodes = [op]
8084
db._unnamed_input_nodes = [op]

src/main/python/systemds/operator/nodes/combine.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,25 @@
2929

3030
class Combine(OperationNode):
3131

32-
def __init__(self, sds_context, func='',
33-
unnamed_input_nodes: Iterable[OperationNode] = None):
32+
def __init__(
33+
self, sds_context, func="", unnamed_input_nodes: Iterable[OperationNode] = None
34+
):
3435
for a in unnamed_input_nodes:
3536
if not a._datatype_is_none:
3637
raise ValueError(
37-
"Cannot combine elements that have outputs, all elements must be instances of print or write")
38+
"Cannot combine elements that have outputs, all elements must be instances of print or write"
39+
)
3840

3941
self._outputs = {}
4042
super().__init__(sds_context, func, unnamed_input_nodes, None, False)
4143

42-
def code_line(self, var_name: str, unnamed_input_vars: Sequence[str],
43-
named_input_vars: Dict[str, str]) -> str:
44-
return ''
44+
def code_line(
45+
self,
46+
var_name: str,
47+
unnamed_input_vars: Sequence[str],
48+
named_input_vars: Dict[str, str],
49+
) -> str:
50+
return ""
4551

4652
def compute(self, verbose: bool = False, lineage: bool = False):
4753
return super().compute(verbose, lineage)

0 commit comments

Comments
 (0)