Skip to content

Instantly share code, notes, and snippets.

View michelp's full-sized avatar

Michel Pelletier michelp

View GitHub Profile
gb.binary.ss.register_new(
"relu",
"""void relu (int64_t *z, int64_t *x, int64_t *y) {
int64_t v;
v = (*x) + (*y);
v = v < 32 ? v : 32;
(*z) = v < 0 ? 0 : v;
}; """,
gb.dtypes.INT64,
gb.dtypes.INT64,
@michelp
michelp / AxB.py
Last active October 11, 2020 22:10
from dataclasses import dataclass
from numpy import array
import typing
class GrB_NULL:
pass
@dataclass
class GrB_Descriptor:
pass
create table test (
id serial primary key,
parent_id integer references test(id) default null -- null is a root
);
insert into test (id, parent_id) values (1, null);
insert into test (id, parent_id) values (2, 1);
insert into test (id, parent_id) values (3, 2);
insert into test (id, parent_id) values (4, 2);
insert into test (id, parent_id) values (5, 2);
from pygraphblas import *
M = Matrix.random(FP32, 7, 7, 30, no_diagonal=True, make_pattern=True, seed=42)
def pagerank3f(A, damping, itermax):
n = A.nrows
r = Vector.sparse(FP32, n)
t = Vector.sparse(FP32, n)
d = A.reduce_vector()
with Accum(FP32.DIV):
drop event trigger ddl_event_trigger_trigger;
drop event trigger test_event_trigger_for_drops;
drop event trigger test_table_rewrite_oid;
CREATE OR REPLACE FUNCTION test_event_trigger_ddl()
RETURNS event_trigger AS $$
DECLARE obj record;
BEGIN
FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands()
LOOP
from textwrap import dedent
from operator import methodcaller
from numba import cfunc, types, jit, carray, cffi_support
from numba.types import Record, CPointer, void, double, uint64
from pygraphblas import Matrix, BinaryOp, lib, ffi as gbffi
from cffi import FFI
def type_head(name):
return dedent("""
typedef struct %s {
In [1]: import numpy as np
In [2]: a = np.array([1,2,3])
In [3]: a
Out[3]: array([1, 2, 3])
In [4]: a > 2
Out[4]: array([False, False, True])
src = """
typedef struct BF_tuple {
double w;
uint64_t h;
uint64_t pi;
} BF_tuple;
typedef void (*bf_min)(BF_tuple*, BF_tuple*, BF_tuple*);
typedef void (*bf_plus)(BF_tuple*, BF_tuple*, BF_tuple*);
"""
BF_tuple = Record.make_c_struct([
('w', double),
('h', uint64),
('pi', uint64),
])
src = """
typedef struct BF_tuple {
double w;
uint64_t h;
from pygraphblas import Type, Monoid, Semiring, binary_op
class BF_Tuple3(Type):
identity = (float('inf'), # sum of edge lengths
UINT64_MAX, # parent of ith vertex
UINT64_MAX) # number of edges from s to i
@binary_op
def min(self, other):