This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
from numpy import array | |
import typing | |
class GrB_NULL: | |
pass | |
@dataclass | |
class GrB_Descriptor: | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*); | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BF_tuple = Record.make_c_struct([ | |
('w', double), | |
('h', uint64), | |
('pi', uint64), | |
]) | |
src = """ | |
typedef struct BF_tuple { | |
double w; | |
uint64_t h; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
NewerOlder