AST converts the following snippet of the code:
for i, dims in enumerate(self.text_range_tuples):
mod = int(dims[0].split("_", 1)[-1])
# Left is up along the 0th dimension
if dims[0].startswith("left"):
self.adjacency_matrix[i, mod:, :] = 0
# Right is down along the 0th dimension
elif dims[0].startswith("right"):
print(dims[0], i, mod)
self.adjacency_matrix[i, :mod, :] = 0
into the following:
for (i, dims) in enumerate(self.text_range_tuples):
mod = int(dims[0].split('_', 1)[(- 1)])
if dims[0].startswith('left'):
self.adjacency_matrix[(i, mod:, :)] = 0
elif dims[0].startswith('right'):
print(dims[0], i, mod)
self.adjacency_matrix[(i, :mod, :)] = 0
where adjacency_matrix is an n-dimensional numpy array (np.ndarray).
Basically, AST creates a tuple of indexing dimensions for the numpy array, but you cannot have slice indices (:) when using a tuple for indexing. The issue can be avoided if a user uses slice(0, mod) and slice(0, len(data)) instead, but it's better to do this things automatically on a background.
AST converts the following snippet of the code:
into the following:
where
adjacency_matrixis an n-dimensionalnumpyarray (np.ndarray).Basically, AST creates a tuple of indexing dimensions for the
numpyarray, but you cannot have slice indices(:)when using a tuple for indexing. The issue can be avoided if a user usesslice(0, mod)andslice(0, len(data))instead, but it's better to do this things automatically on a background.