Skip to content
Open
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
16 changes: 16 additions & 0 deletions csa/elementary.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ def ival (beg, end):
# Cartesian product
#
def cross (set0, set1):
"""
Compute the Cartesian product of two sets.

Note
----
The Cartesian product returned by `cross()` is not automatically
restricted to a finite mask. When visualized using `show()`,
connections may appear in the default (infinite) mask unless
explicitly multiplied with a finite mask.

Example
-------
# To obtain a bounded all-to-all connectivity pattern:
cross(A, B) * full(len(A), len(B))
"""

return _cs.intervalSetMask (set0, set1)

# Elementary masks
Expand Down
14 changes: 14 additions & 0 deletions csa/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
import numpy as _numpy
import matplotlib
import matplotlib.pyplot as _plt
from matplotlib.colors import ListedColormap

# Color mapping for masks in show()
MASK_COLOR = {
'full': 'purple',
'oneToOne': 'purple',
'randomMask': 'green',
}

from . import elementary

Expand All @@ -40,9 +48,15 @@ def show (cset, N0 = 30, N1 = None):
N1 = N0 if N1 == None else N1
_plt.clf ()
_plt.axis ('equal')
# Determine color from mask type
mask_tag = getattr(cset, 'tag', None)
color = MASK_COLOR.get(mask_tag, 'gray')
# Create a colormap with only this color
cmap = ListedColormap([color_name])
a = _numpy.zeros ((N0, N1))
for (i, j) in elementary.cross (range (N0), range (N1)) * cset:
a[i,j] += 1.0
# Show with consistent color
_plt.imshow (a, interpolation='nearest', vmin = 0.0, vmax = 1.0)
_plt.show ()

Expand Down