Skip to content

Instantly share code, notes, and snippets.

@dschult
dschult / get_index_dtype_inout_count.txt
Created July 22, 2024 03:26
dict keyed by inputs for get_index_dtype to how many times those inputs are used in one pass through TestCSR, etc.
###########################################################
#### Summary All Tests:
(('()', 6, False), <class 'numpy.int32'>): 9920
(('()', 4, False), <class 'numpy.int32'>): 8393
(('(array([0, 0, 1, 1, 2, 3], dtype=int32), array([4, 5, 0, 1, 1, 0], dtype=int32))', 6, False), <class 'numpy.int32'>): 3654
(('()', 5, False), <class 'numpy.int32'>): 3441
(('()', 3, False), <class 'numpy.int32'>): 3402
(('(array([1, 2, 0, 1, 2, 0, 1, 2], dtype=int32), array([0, 2, 5, 8], dtype=int32))', 3, True), <class 'numpy.int32'>): 3247
(('(array([0, 3, 0, 2, 1], dtype=int32), array([0, 2, 4, 5], dtype=int32))', 4, True), <class 'numpy.int32'>): 3129
(('(array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2], dtype=int32), array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3], dtype=int32))', 4, False), <class 'numpy.int32'>): 2791
@dschult
dschult / ndsparray.py
Created July 16, 2024 15:43
Proof of concept for nD sparse arrays using 2D storage with NumPy tools and 2D sparsetools
# See the bottom for demo lines that print desired output
#
# key idea: store the nD array as a 2D array by raveling
# some axes into the rows and some axes into the columns.
#
# element-wise operations work nicely with the 2D version of the array
# and can be converted back to nD when needed.
#
# Two important functions here are `get_2d_coords` and `get_nd_coords`
# which convert between nD and 2D coords. The data elements stay in the
@dschult
dschult / benchmark.py
Last active July 8, 2022 18:37
A script to time simple operations with various graph classes. The output is just text tables of the timing results. The code itself is pretty ugly, but it gets the job done.
from timeit import Timer
# This is gratefully modeled after the benchmarks found in
# the numpy svn repository. http://svn.scipy.org/svn/numpy/trunk
import networkx as nx
class Benchmark(object):
"""
Benchmark a method or simple bit of code using different Graph classes.
@dschult
dschult / graphview.py
Last active December 31, 2015 19:34
NodeView and EdgesView classes for NetworkX Graphs
from __future__ import print_function
class NodesView(object):
def __init__(self, graph, data=False, default=None):
self.G = graph
self.data = data
self.default = default
def __iter__(self):
data=self.data
if data is True: