Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinnedSpikeTrain optional CSC format #402

Merged
merged 3 commits into from
Feb 24, 2021

Conversation

dizcza
Copy link
Member

@dizcza dizcza commented Feb 10, 2021

Could be useful in ASSET HEAT backend implementation.

Also, BinnedSpikeTrain.binarize is refactored: the copy parameter is back. If set to True, a shallow copy is returned.


Slicing a scipy CSC matrix does not internally convert it to a CSR matrix.

import time
import tracemalloc

import numpy as np
import scipy.sparse

tracemalloc.start()
start = time.time()


def print_traced_mem(name=''):
    global start
    duration = time.time() - start
    curr, peak = tracemalloc.get_traced_memory()
    print(f">>> [{name}] curr={curr / 2 ** 20:.2f} Mb, peak={peak / 2 ** 20:.2f} Mb; duration={duration:.3f} sec")
    tracemalloc.reset_peak()
    start = time.time()


n = 5_000
a = np.arange(n * n, dtype=np.float32).reshape((n, n))
a_csc = scipy.sparse.csc_matrix(a)
print_traced_mem('begin')
a11 = a_csc[:n//2, :n//2]
print_traced_mem('a11')
a12 = a_csc[:n//2, n//2:]
print_traced_mem('a12')
>>> [begin] curr=286.14 Mb, peak=762.94 Mb; duration=0.793 sec
>>> [a11] curr=333.84 Mb, peak=333.84 Mb; duration=0.043 sec
>>> [a12] curr=381.53 Mb, peak=381.53 Mb; duration=0.042 sec

Same for a CSR matrix.

@dizcza dizcza added the enhancement Editing an existing module, improving something label Feb 10, 2021
@coveralls
Copy link
Collaborator

coveralls commented Feb 10, 2021

Coverage Status

Coverage increased (+0.02%) to 89.671% when pulling 7c9c079 on INM-6:feature/csc_matrix into f56a62a on NeuralEnsemble:master.

@dizcza dizcza merged commit 68b3243 into NeuralEnsemble:master Feb 24, 2021
@dizcza dizcza deleted the feature/csc_matrix branch February 24, 2021 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Editing an existing module, improving something
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants