MCPcopy Create free account
hub / github.com/BindsNET/bindsnet / run

Function run

examples/benchmark/sparse_vs_dense_tensors.py:62–102  ·  view source on GitHub ↗
(sparse)

Source from the content-addressed store, hash-verified

60
61
62def run(sparse):
63 n_classes = 10
64 proportions = torch.zeros((500, n_classes), device=device)
65 rates = torch.zeros((500, n_classes), device=device)
66 assignments = -torch.ones(500, device=device)
67 spike_record = []
68 for _ in range(5):
69 tmp = torch.zeros(shape, device=device)
70 spike_record.append(tmp.to_sparse() if sparse else tmp)
71
72 spike_record_idx = 0
73
74 delta = 0
75 for _ in range(10):
76 start = time.perf_counter()
77 label_tensor = torch.randint(0, n_classes, (n_classes,), device=device)
78 spike_record_tensor = torch.cat(spike_record, dim=0)
79 all_activity(
80 spikes=spike_record_tensor, assignments=assignments, n_labels=n_classes
81 )
82 proportion_weighting(
83 spikes=spike_record_tensor,
84 assignments=assignments,
85 proportions=proportions,
86 n_labels=n_classes,
87 )
88
89 assignments, proportions, rates = assign_labels(
90 spikes=spike_record_tensor,
91 labels=label_tensor,
92 n_labels=n_classes,
93 rates=rates,
94 )
95 delta += time.perf_counter() - start
96 spike_record[spike_record_idx] = create_spikes_tensor(
97 0.03, sparse, return_memory_usage=False
98 )
99 spike_record_idx += 1
100 if spike_record_idx == len(spike_record):
101 spike_record_idx = 0
102 return round(delta, 1)
103
104
105def runtime_benchmark():

Callers 3

runtime_benchmarkFunction · 0.85
BRIAN2Function · 0.85
BRIAN2GENNFunction · 0.85

Calls 4

all_activityFunction · 0.90
proportion_weightingFunction · 0.90
assign_labelsFunction · 0.90
create_spikes_tensorFunction · 0.85

Tested by

no test coverage detected