blob_id stringlengths 40 40 | filename stringlengths 5 48 | path stringlengths 7 169 | repo_name stringlengths 9 76 | length_bytes int64 369 8k | src_encoding stringclasses 1
value | content stringlengths 369 8k | split stringclasses 1
value | detected_licenses listlengths 0 18 | license_type stringclasses 2
values | star_events_count int64 0 209k |
|---|---|---|---|---|---|---|---|---|---|---|
7f71dc367de170c0170f50a6d80dc14187f10246 | hello.pyx | /hello.pyx | ckyma/PythonTutorial | 369 | UTF-8 | # -*- coding: utf-8 -*-
"""
Created on Thu Apr 10 16:13:18 2014
@author: phinary0
"""
def say_hello_to(name):
print("Hello %s!" % name)
cpdef double f(double x) except *:
return x**2-x
def integrate_f(double a, double b, int N):
cdef int i
cdef double s, dx
s = 0
dx = (b-a)/N
for i in ra... | sft_candidate | [] | no_license | 0 |
13f51bd2fbb6ef81a24db6f538d60377fa44c5ce | ex_prange.pyx | /cython/parallel/ex_prange.pyx | JBlaschke/divelite | 415 | UTF-8 | from cython.parallel import prange
import numpy as np
cdef int i
cdef int n = 1000
cdef int sum = 0
for i in prange(n, nogil=True):
#for i in range(n):
sum += i
print(sum)
"""
def func(double[:] x, double alpha):
cdef Py_ssize_t i
for i in prange(x.shape[0], nogil=True):
x[i] = alpha * x[i]
n... | sft_candidate | [] | no_license | 0 |
1949531910e5e150b1398a5d9580c37bb6e917c9 | csigdist.pyx | /SugarMap/csigdist.pyx | alexchonglian/sensor-ipsn2016 | 421 | UTF-8 | '''
Created on Feb 12, 2013
@author: imaveek
'''
from libc.math cimport sqrt
def sigdist(sig1,sig2):
'''
Gives distance between RToF signatures
'''
cdef float s1
cdef float s2
n = len(sig1)
cdef float sum = 0
for i in range(n):
s1 = sig1[i]
... | sft_candidate | [] | no_license | 0 |
95c583e3a5452cb0bf4f415ea562c7ee2a153179 | call_crash.pyx | /tests/run/call_crash.pyx | cython/cython | 423 | UTF-8 | cdef class A:
"""
>>> A().test(3)
9
"""
cdef int (*func_ptr)(int)
def __init__(self):
self.func_ptr = &func
cdef int do_it(self, int s):
cdef int r = first_call(self).func_ptr(s) # the temp for first_call(self) not properly freed
return r
def test(self, s):
... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 8,352 |
32dde1ea10e5554dbd70a4b13a8fb0b220436fd9 | cyforksqrt.pyx | /L3/cyforksqrt.pyx | DanielHipp/Betriebssysteme | 428 | UTF-8 | from libc.math cimport sqrt
from libc.math cimport fabs
# default sqrt2 values
cdef double start = 1
cdef loops = 100
cdef double tolerance = 1e-14
def sqrtm(double x):
return sqrt(x)
def sqrt2(double value):
cdef int i
cdef double x = start
for i in range(loops):
xpre = x
x = (x + ... | sft_candidate | [] | no_license | 0 |
109363e4425b4f33481c11226ba706e95b9b1a23 | functions.pyx | /src/python/cython/optimize_as_necessary_example/functions.pyx | luiarthur/mcmc-lang-compare | 436 | UTF-8 | import numpy as np
def f1(s, int n):
cdef double x = s.b
cdef int i, j
for i in range(n):
for j in range(n):
x += np.random.randn()
s.b = x
def f2(s, int n):
cdef double x = s.b
cdef int i, j
for i in range(n):
for j in range(n):
x += 1
s.b... | sft_candidate | [] | no_license | 0 |
70674d337e23c409e5dd69faf419b91363d75477 | distance_functions.pyx | /ObjectMatch/distance_functions.pyx | jefferickson/peer-object-matching | 562 | UTF-8 | from libc.math cimport sqrt
import ObjectMatch.utils as utils
cpdef float euclid_distance(coords1, coords2):
'''Calculates the Euclidean distance between two points of equal dimension.'''
cdef int dimensions = len(coords1)
if len(coords2) != dimensions:
raise utils.DiffNumOfDims('ERROR: the obj... | sft_candidate | [] | no_license | 4 |
85ae184158e38be4a1a05909bfded6a10cd5354d | loop_cy.pyx | /loop_cy.pyx | rapando/cythontut | 588 | UTF-8 | """
cpdef int some_loop(int x) means we are declaring a function called some_loop
cpdef -> the function can be used in both python and cython code.
int some_loop(int x) -> the function takes an integer as a parameter and it returns an integer value
"""
cpdef int some_loop(int x):
# the following lines declare varia... | sft_candidate | [] | no_license | 0 |
802724b2bbba54202ea0f541b4b18880ca6c58f5 | _fastclass.pyx | /src/pack_and_doc/submodule/_fastclass.pyx | chryswoods/python_pack_and_doc | 588 | UTF-8 |
import cython
__all__ = ["FastClass", "fast_function"]
class FastClass:
"""A class with some functions that are compiled"""
def __init__(self):
pass
def func(self):
cdef int i = 0
cdef float x = 0.0
cdef float y = 0.0
for i in range(0, 10):
x = 5.0 ... | sft_candidate | [
"Apache-2.0"
] | permissive | 5 |
b8212e033fb0a0dc839e9176b32e37b0dd70aabe | new_data_type.pyx | /learning-stuff/Cython/cython_youtube_tutorial/new_data_type/new_data_type.pyx | artfin/classical-trajectories | 603 | UTF-8 | cdef class DoubleList:
cdef double* v
cdef int n
def __init__(self, v):
self.n = len(v)
self.v = <double*> sage_malloc(sizeof(double) * self.n)
cdef int i
for i in range(self.n):
self.v[i] = v[i]
def __del__(self):
sage_free(self.v)
def var... | sft_candidate | [] | no_license | 4 |
14834b7d32cd6d788819f5842484cf3bd5313aa9 | utilities_cython.pyx | /primes/utilities_cython.pyx | jhidding/noodles-experiments | 613 | UTF-8 | from libc.math cimport ceil, sqrt
cdef inline int primeQ(int n) nogil:
"""return a boolean, is the input integer a prime?"""
if n == 2:
return True
cdef int max_i = <int>ceil(sqrt(n))
cdef int i = 2
while i <= max_i:
if n % i == 0:
return False
i += 1
return True
cpdef... | sft_candidate | [
"Apache-2.0"
] | permissive | 0 |
b96d3495a0b8cbd1a36a8c4a5774cf183d6045c5 | myutils_cython.pyx | /matrixrecovery/myutils_cython.pyx | jajajang/efalb | 632 | UTF-8 | #cython: language_level=3, boundscheck=False, wraparound=False, nonecheck=False
def calcRowwiseKron(D, X, ZV):
"""
X: N by d
ZV: N by r
returns D where D[i,:] = np.outer(X[i,:], ZV[i,:]).ravel()
"""
cdef int N = D.shape[0]
cdef int d = X.shape[1]
cdef int r = ZV.shape[1]
cd... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 0 |
1291c8b590b160abda403e34b4989d3c0f4ee94f | ode0_cy2.pyx | /examples/cython_for_ODEs/ode0_cy2.pyx | Ziaeemehr/cython | 669 | UTF-8 | """
ODE integration restricted to scalar ODEs.
No use of arrays.
Cython version with declaration of variables.
"""
cpdef solver(f, double I, double dt, double T, method):
cdef int N = int(round(float(T)/dt))
cdef double u = I # previous time step
cdef double t = 0
cdef int n
for n in xrange(N):
... | sft_candidate | [] | no_license | 0 |
4070166f904efd76277e81dc3abc19a41260023e | cyfib.pyx | /03-斐波那契数列比较性能/cyfib.pyx | weiyinfu/learnCython | 671 | UTF-8 | cdef fib_cdef(int n):
cdef int i
cdef double a = 0.0, b = 1.0
for i in range(n):
a, b = a + b, a
return a
def fib_def(int n):
cdef int i
cdef double a = 0.0, b = 1.0
for i in range(n):
a, b = a + b, a
return a
def fib_pure_py(n):
a, b = 0, 1
for i in range(n):
... | sft_candidate | [] | no_license | 1 |
bb96faf5cc195abf580814a1aae1780d46d199a8 | cosine.pyx | /cosine.pyx | wuwuwuxxx/dummy_file | 698 | UTF-8 | """
checked under python 3.
"""
cimport cython
from libc.math cimport sqrt
@cython.nonecheck(False)
@cython.boundscheck(False)
@cython.wraparound(False)
cdef double dot(double[:] v1, double[:] v2):
cdef double s=0.0
for i in range(v1.shape[0]):
s += v1[i]*v2[i]
return s
@cython.nonecheck(False... | sft_candidate | [] | no_license | 0 |
dd6f108767d588dd0632ce9cb0d07b1da90c822a | funcs.pyx | /python/cython/yield_and_function_overhead/funcs.pyx | Christopher-Bradshaw/learning | 720 | UTF-8 | # The point of this is to test the speed of generators/function calls in cython
def counter(int x):
cdef long count = 0
cdef int i
for i in range(x):
count += i
return count
def counter_that_calls_a_func(int x):
cdef long count = 0
cdef int i
for i in range(x):
count += _c... | sft_candidate | [] | no_license | 0 |
055f6686df5aedcd5115738a7d744e3de7d821e7 | polynomial_cy.pyx | /students/kmsnyde/lesson10/polynomial_cy.pyx | UWPCE-PythonCert-ClassRepos/SP_Online_Course2_2018 | 731 | UTF-8 | # -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 15:00:02 2018
@author: HP-Home
"""
# Find the root of a polynomial
cpdef double f( double x):
cdef double func = (x**3) - (x * 2) -1
return func
cpdef double derivative(double x):
cdef double h = 0.000001
cdef double derivative = (f(x + h) - f(x)) / ... | sft_candidate | [] | no_license | 4 |
aeea9e78afcfd6b2720284928fe900c1b030d232 | koshkas.pyx | /Course_I/Алгоритмы Python/Part2/семинары/pract5/task21/koshkas.pyx | GeorgiyDemo/FA | 739 | UTF-8 | #python3 setup.py build_ext --inplace
import numpy
cdef int carr[2001]
cdef int [:] carr_view = carr
cpdef int[:] generator():
cdef int [:] arr = carr_view
for i in range(arr.shape[0]):
arr[i] = numpy.random.randint(-5,4)
return arr
cpdef tuple summ():
cdef int [:] arr = generator()
cd... | sft_candidate | [
"WTFPL"
] | permissive | 46 |
2600a4533970a0cc22f44b551f7c008fdb0294a2 | cython_integrator.pyx | /INF4331/assignment4/cython_integrator.pyx | matkir/Master_subjects | 764 | UTF-8 | #cython: boundscheck=False
#cython: wraparound=False
cpdef cython_integrate(object f,double a,double b,int N):
""" integrates f from a to b with N points"""
cdef double dx=(b-a)/(N)
cdef double retsum=0
cdef int i
for i in range(int(N)... | sft_candidate | [] | no_license | 0 |
34eb7bf393034a3b474c6dffead875c6125c37fe | rng.pyx | /cython_utils/rng.pyx | jassak/topic-modeling-lda | 781 | UTF-8 | #!/usr/bin/env cython
# coding: utf-8
"""
Created on 1 November 2018
@author: jason
"""
cimport cython
from cpython.mem cimport PyMem_Malloc, PyMem_Free
from libc.stdlib cimport malloc, free, rand, RAND_MAX, srand
from libc.math cimport floor, fabs
@cython.cdivision(True)
cdef double randUniform() nogil:
return... | sft_candidate | [] | no_license | 0 |
9d18ac8d1e3237364fd343ab13287ebbd2c94480 | build_graph.pyx | /Trackers/GNNTracker/build_graph.pyx | ankush1123roy/Modular-Decomposition-of-Tracker- | 784 | UTF-8 |
from knnsearch import knnsearch
import random
def build_graph(X, k):
''' Build a Connected graph using k neighbours
Author: Ankush Roy (ankush2@ualberta.ca)
Kiana Hajebi (hajebi@ualberta.ca)
'''
cdef int I = 0
cdef int i = 0
cdef int nodes[5000]
cdef int nns_inds[41]
... | sft_candidate | [] | no_license | 4 |
a9af1de305dc057bf469a1b28266bfcb34c6e7d8 | trim_cython.pyx | /trim_cython.pyx | AlexeyG/ribosomes | 791 | UTF-8 | def find_poly_A(char *seq):
''' Find the index of the first A in the terminating stretch of (A or N)s.
'''
cdef int seq_length = len(seq)
cdef int start
for start in range(seq_length, 0, -1):
if seq[start - 1] != 'A' and seq[start - 1] != 'N':
return start
return 0
def find... | sft_candidate | [] | no_license | 0 |
cdc33132f455dec6d8b3fe5e50cbc390cf3c4f19 | mmview.pyx | /mmview.pyx | rth/cython-mmview-ro | 800 | UTF-8 | cpdef getmax(double[:] x):
"""Example code, should work with both
ro and rw memoryviews"""
cdef double max_val = -float('inf')
for val in x:
if val > max_val:
max_val = val
return max_val
cpdef update_array(double [:] x):
"""Modifying a ro memoryview should raise an error""... | sft_candidate | [] | no_license | 0 |
41fc2f3d36d1935a77000cdd44ce397c640bdb95 | libsimple.pyx | /cython-misc-example/libsimple.pyx | CharlieCrisp/cython-workshop | 816 | UTF-8 | # distutils: language = c++
# ^^ required for last point
# ptr dereference
cdef int int_from_ptr(int* int_ptr):
return int_ptr[0]
# ptr following (cake->num_candles)
cdef struct Cake:
int num_candles
cdef int get_num_candles(Cake* cake):
return cake.num_candles
# type casting
cdef long get_long_from_in... | sft_candidate | [] | no_license | 0 |
dca7bde02c313a01162cf69e000fe9eae7c9b478 | bad_c_struct_T252.pyx | /tests/run/bad_c_struct_T252.pyx | cython/cython | 845 | UTF-8 | # ticket: t252
cdef cf(default=None):
return default
cpdef cpf(default=100):
"""
>>> cpf()
100
>>> cpf(1)
1
>>> cpf(default=2)
2
"""
default = cf(default)
return default
def pf(default=100):
"""
>>> pf()
100
>>> pf(1)
1
>>> pf(default=2)
2
"... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 8,352 |
d238cc11c298eb8c7e2344cf4258c25aeda2cbad | locals_expressions_T430.pyx | /tests/run/locals_expressions_T430.pyx | cython/cython | 883 | UTF-8 | # ticket: t430
__doc__ = u"""
>>> sorted( get_locals(1,2,3, k=5) .items())
[('args', (2, 3)), ('kwds', {'k': 5}), ('x', 1), ('y', 'hi'), ('z', 5)]
>>> sorted(get_locals_items(1,2,3, k=5))
[('args', (2, 3)), ('kwds', {'k': 5}), ('x', 1), ('y', 'hi'), ('z', 5)]
>>> sorted(get_locals_items_listcomp(1,2,3, k=5))
[('args... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 8,352 |
1148120de8b9574bebd8ba2293ceef379c65f159 | utils708.pyx | /compiled/utils/utils708.pyx | MarkMoretto/project-euler | 883 | UTF-8 |
"""
Purpose: Compiled problem 708
Date created: 2020-04-02
Contributor(s):
Mark M.
"""
from functools import reduce
import numpy as np
import bottleneck as bn
def sqrt_(n):
return n ** (1/2)
def step_(x):
return 1 + (x<<2) - ((x>>1)<<1)
def maxq_(q):
return int(np.floor(np.sqrt(q)))
def pri... | sft_candidate | [] | no_license | 2 |
c5a83df9c1b6b624fa118d7e7eb14b6acd9ea353 | dot_product.pyx | /Cython/dot_product.pyx | MeeshCompBio/Random_Python_Scripts | 886 | UTF-8 | import numpy as np
from math import exp
from libc.math cimport exp as c_exp
from cython.parallel import prange
# normal numpy method
def array_f(X):
Y = np.zeros(X.shape)
index = X > 0.5
Y[index] = np.exp(X[index])
return Y
#using C libraries
def c_array_f(double[:] X):
# declare variables just l... | sft_candidate | [] | no_license | 0 |
109d9d93806ed7cd954b046b09e9ce7bab68c8b1 | fast_calc.pyx | /fast_calc/fast_calc.pyx | dmasad/InductiveGameTheory | 889 | UTF-8 | '''
Cython code to speed up calculating conditional probabilities.
'''
def fast_find_prob(array, A, B, int delta):
'''
Find the probability of event A given event B, with interval delta.
P(B->A)
Args:
array: The array to search in.
A: The target event to examine
B: The condi... | sft_candidate | [] | no_license | 0 |
69adda250912c1a4168b6e310583a64dd36ad69c | miasma.pyx | /pyx/demo/miasma.pyx | shakfu/polylab | 899 | UTF-8 | # functions
"""
a cython functionalist extravaganzum
"""
import math
def sum(long n):
"""a summing bird
"""
cdef long i, s = 0
for i in range(n):
s += i
return s
cdef class Function:
cpdef double evaluate(self, double x) except *:
return 0
cdef class SinOfSquareFunction(Func... | sft_candidate | [] | no_license | 3 |
1846657d33ecd757445eefdf38ac496f4535ef10 | converter.pyx | /converter.pyx | BlenderCN-Org/io_texture_VTF | 907 | UTF-8 |
import time
from libc.stdlib cimport malloc, free
from cpython.array cimport array, clone
# cpdef split = lambda A, n=3: [A[i:i + n] for i in range(0, len(A), n)]
cpdef list split(bytes A,int n):
cdef int i;
cdef int b;
cdef list pixel_array = []
b = len(A)
for i in range(0,b,n):
pixel_ar... | sft_candidate | [] | no_license | 0 |
75acabdae6747405e61c91dd5b24b43152185ccc | cython_funcs.pyx | /cython_funcs.pyx | apokrif333/Cython | 915 | UTF-8 | import cython
import math
# https://towardsdatascience.com/use-cython-to-get-more-than-30x-speedup-on-your-python-code-f6cb337919b6
""" Types in Cython
For variables we have:
cdef int a, b, c
cdef char *s
cdef float x = 0.5 (single precision)
cdef double x = 63.4 (double precision)
cdef list names... | sft_candidate | [] | no_license | 0 |
8d7ed0a9c6d4229a149aa0f53cce9d14741c2f8e | parallel.pyx | /tests/run/parallel.pyx | tkopczuk/cython | 929 | UTF-8 | # tag: run
# tag: openmp
cimport cython.parallel
from cython.parallel import prange, threadid
cimport openmp
from libc.stdlib cimport malloc, free
def test_parallel():
"""
>>> test_parallel()
"""
cdef int maxthreads = openmp.omp_get_max_threads()
cdef int *buf = <int *> malloc(sizeof(int) * maxthr... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 0 |
81fffe9e4fe42d5fb755660a3ba982417a67b613 | refactor_mod.pyx | /code_4_research/cython/refactor_mod.pyx | naereni/speedup-python | 956 | UTF-8 | '''
Python code with Cython refactoring
'''
# fibonacci numbers
cpdef double fib(double n):
if n < 3:
return 1
return fib(n-1) + fib(n-2)
# auxiliary function for list_prime_num()
cpdef is_prime(int n):
cdef int i
for i in range(2, n):
if n % i == 0:
return False
retu... | sft_candidate | [] | no_license | 0 |
bded54ee97ac0f2b8c474c512bf000e95ae76c2b | polynomial_cy_cprofile.pyx | /students/kmsnyde/lesson10/polynomial_cy_cprofile.pyx | UWPCE-PythonCert-ClassRepos/SP_Online_Course2_2018 | 958 | UTF-8 | # cython: profile=True
import cProfile
# Find the root of a polynomial
cpdef double f( double x):
cdef double func = (x**3) - (x * 2) -1
return func
cpdef double derivative(double x):
cdef double h = 0.000001
cdef double derivative = (f(x + h) - f(x)) / h
return derivative
cpdef newton_raphson(... | sft_candidate | [] | no_license | 4 |
3b4a6d932f91f2116ea14e7c1f39baecc975506d | polygon_x.pyx | /optimize/src/utils/polygon_x.pyx | jdonovanCS/Antimander | 977 | UTF-8 | cpdef bint contains_point(float[:, :] poly, float x, float y) except *:
# http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
assert poly.shape[1] == 2
cdef bint inside = False
cdef int i, j
cdef float xi, yi, xj, yj
for i in range(poly.shape[0]):
j = i-1 if i > 0 else... | sft_candidate | [
"BSD-3-Clause"
] | permissive | 0 |
75ddb856410cbd0d62a6e4adb2e1407185a44a28 | cython_funcs_fast_with_profiling.pyx | /python/cython/profiling/cython_funcs_fast_with_profiling.pyx | Christopher-Bradshaw/learning | 982 | UTF-8 | # cython: profile=True
from libc.math cimport sin
def sin_squared(double x):
return sin(x)**2
def integrate(double start, double stop, func, int n=200000):
cdef double dx, total
cdef int i
dx = (stop - start) / n
total = 0
for i in range(n):
total += func(start + (i+0.5)*dx)
retur... | sft_candidate | [] | no_license | 0 |
277d4709b30be54f4c3215404a8c4a68dfc4d43c | ray.pyx | /lib/ray.pyx | pelegs/cython_raytrace | 991 | UTF-8 | #cython: boundscheck=False, wraparound=False, nonecheck=False, language_level=3
cdef class Ray:
"""
A ray to be traced.
"""
def __init__(self, pos, dir):
self.pos = pos
self.dir = dir.normalize()
cpdef vec3 point_at_param(self, double t):
return self.pos + t * self.dir
... | sft_candidate | [] | no_license | 0 |
526aa418041d25be9c0d9e8b229ae7a0da52da52 | carrays.pyx | /tests/run/carrays.pyx | cython/cython | 1,010 | UTF-8 | def test1():
"""
>>> test1()
2
"""
cdef int[2][2] x
x[0][0] = 1
x[0][1] = 2
x[1][0] = 3
x[1][1] = 4
return f(x)[1]
cdef int* f(int x[2][2]):
return x[0]
def assign_index_in_loop():
"""
>>> assign_index_in_loop()
2
"""
cdef int i = 0
cdef int[1] a
... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 8,352 |
fd620965d32343ceec9a104e7f68c8e75e3bfa46 | L1_proj.pyx | /nosmo/cprox/L1_proj.pyx | wangsw09/nosmo | 1,025 | UTF-8 | from libc.stdlib cimport malloc, free, qsort
from libc.math cimport fmax, fabs
cdef int sorting_cmp(const void *a, const void *b) nogil:
cdef double av = (<double *> a)[0]
cdef double bv = (<double *> b)[0]
if av > bv:
return -1
elif av < bv:
return 1
else:
return 0
cdef vo... | sft_candidate | [] | no_license | 1 |
2ec03dbe6dcc780d17e7cbc8cec60a70c0ad0fdb | a_testscript.pyx | /performance-tests/a_testscript.pyx | numoonchld/cython-basics | 1,059 | UTF-8 | ## GOAL:
# given array of integers: a = [21, 7, 3, 11, 5, 108, 65], compute MSE
# MSE = (curr_value - arr_avg)^2/arr_length
## python only def and dynamic variables:
def mse():
# """ compute mean square error of input array 'a' """
a = [21, 7, 3, 11, 5, 108, 65]
mean = sum(a)/len(a)
accum = 0... | sft_candidate | [] | no_license | 3 |
1be6f44a905b3aebc1b3f316e657df45365ab5e1 | alignment_utils.pyx | /mDeepFRI/alignment_utils.pyx | bioinf-mcb/Metagenomic-DeepFRI | 1,062 | UTF-8 | cimport cython
from libc.stdlib cimport free, malloc
from libc.string cimport strlen
@cython.boundscheck(False)
@cython.wraparound(False)
cdef float alignment_sequences_identity(char* query, char* target) nogil:
cdef int matches = 0
cdef int i
cdef float seq_identity
cdef int query_len = strlen(query)... | sft_candidate | [
"BSD-3-Clause"
] | permissive | 22 |
65f19abbb70fca97202e2d39b832c51b5ff6b390 | Day1.pyx | /2018/day01/jorge/Day1.pyx | acmfi/AdventCode | 1,068 | UTF-8 | #Escrito en Cython
"""
import pyximport; pyximport.install(pyimport= True, build_dir = "/home/user/Desktop")
print("Finished compiling\n\t---===---")
import J_advent_of_code
print(Day1.day1_p1("/home..."))
print(Day1.day1_p2("/home..."))
"""
cdef int c_p1(file_location):
cdef str s
cdef list nums
with open(file... | sft_candidate | [] | no_license | 16 |
ac83a4a48519d38344203d8b1ddc1fa5df9295a4 | memoryview_in_subclasses.pyx | /tests/memoryview/memoryview_in_subclasses.pyx | cython/cython | 1,111 | UTF-8 | """
Test for memory leaks when adding more memory view attributes in subtypes.
"""
import gc
from cython.view cimport array
def count_memoryviews():
gc.collect()
return sum([1 if 'memoryview' in str(type(o)) else 0
for o in gc.get_objects()])
def run_test(cls, num_iters):
orig_count = ... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 8,352 |
adcee08affceba623d05910e6ea2c14d61c33672 | _utils.pyx | /pytraj/_utils.pyx | whip112/pytraj | 1,114 | UTF-8 | def _int_array2d_like_to_memview(mylist):
"""convert 2D array-like of integers to cython.view.array
"""
cdef int n_counts = len(mylist)
cdef int n_items = len(mylist[0])
cdef int[:, :] int_view
cdef view.array arr0 = view.array(shape=(n_counts, n_items),
itemsize=size... | sft_candidate | [
"BSD-2-Clause"
] | permissive | 0 |
314bdc8e35fec4a57a5cab6d02b2c37cdcced8a7 | utils.pyx | /compmech/fem/utils.pyx | saullocastro/compmech | 1,120 | UTF-8 | #cython: wraparound=False
#cython: boundscheck=False
#cython: cdivision=True
#cython: nonecheck=False
#cython: profile=False
#cython: infer_types=False
#from libc.stdlib cimport malloc, free
cdef void invJ2(int nel, int npts, double *J, double *invJ) nogil:
cdef double a, b, c, d, f
cdef int i, j, pos
cde... | sft_candidate | [
"BSD-3-Clause"
] | permissive | 5 |
fb04ee67bd9a6e9a9a473d1e3c5bdddce3a04e97 | libc_math.pyx | /tests/run/libc_math.pyx | cython/cython | 1,124 | UTF-8 | # mode: run
from libc.math cimport (M_E, M_LOG2E, M_LOG10E, M_LN2, M_LN10, M_PI, M_PI_2,
M_PI_4, M_1_PI, M_2_PI, M_2_SQRTPI, M_SQRT2, M_SQRT1_2)
from libc.math cimport (acos, asin, atan, atan2, cos, modf, sin, sinf, sinl,
tan, cosh, sinh, tanh, acosh, asinh, atanh, exp, log, log10, pow, sqrt)
cimport l... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 8,352 |
69ca35153497db8051141e74977ea30c0b370b8b | pade.pyx | /ana_cont/pade.pyx | josefkaufmann/ana_cont | 1,134 | UTF-8 | """
Very inefficient implementation of Pade approximation,
described in H. J. Vidberg and J. W. Serene, J. Low Temp. Phys. 29, 179 (1977).
Author: Josef Kaufmann
"""
import numpy as np
import sys
def compute_coefficients(zi,ui):
cdef int i,j,n
n=len(zi)
g=np.zeros((n,n),dtype=complex)
g[:,0]=ui
for i in r... | sft_candidate | [
"MIT"
] | permissive | 39 |
a67391335c8046e1d5d202fba116e0445807d7d8 | example.pyx | /memoryview_numpy/example.pyx | Digindataflow/PythonProfileOptimize | 1,146 | UTF-8 | """
- declare mv
cdef int[:, :, :] mv
mv = np.empty((10, 20, 30), dtype=np.int32)
- it can acquire a buffer from a fully strided ndarray:
mv = arr[4:10:2, ::3, 5::-2]
- C-contiguous typed memoryview
cdef float[:, ::1] c_contig_mv
c_contig_mv = np.ones((3, 4), dtype=np.float32, order='F')
#=> ValueError: ndarray is no... | sft_candidate | [] | no_license | 0 |
9f36102207fc47c498795e9c185f8b5d62dc4de3 | jsdiv.pyx | /MPSK_EQAPOL_Prior/jsdiv.pyx | clintko/Proj_MPSK_test | 1,173 | UTF-8 | cimport cython
import numpy as np
from libc.math cimport log
from cython.parallel cimport prange, parallel
@cython.boundscheck(False)
cdef double entropy_ufun(double p, double q, double tol = 1e-50) nogil:
if p < tol:
return 0
elif q < tol:
return 0
else:
return p * log(p / q)
... | sft_candidate | [] | no_license | 0 |
d464f6adae9dbfc0f0554eaefec2af8a31a5759e | io.pyx | /pandas/src/io.pyx | timClicks/pandas | 1,178 | UTF-8 | cdef int _EPOCH_ORD = 719163
from datetime import date as pydate
cdef inline int64_t gmtime(object date):
cdef int y, m, d, h, mn, s, days
y = PyDateTime_GET_YEAR(date)
m = PyDateTime_GET_MONTH(date)
d = PyDateTime_GET_DAY(date)
h = PyDateTime_DATE_GET_HOUR(date)
mn = PyDateTime_DATE_GET_MINU... | sft_candidate | [
"BSD-3-Clause"
] | permissive | 1 |
2a3a3bbbd4ee2d3cab694c1a1105e2290a0e7ff8 | cipher.pyx | /lib/cipher.pyx | smileboywtu/SEF | 1,217 | UTF-8 | # -*- coding: utf-8 -*-
"""
wrapper for c func
"""
from libc.stdlib cimport malloc, free
from libc.string cimport memset, memcpy
# encryption block size
cdef char dsize = 8
cpdef _encrypt(unsigned char* data, keys):
"""sef encrypt func"""
# define array and reset it to zero
cdef char key
cdef int index
cde... | sft_candidate | [
"Apache-2.0"
] | permissive | 2 |
712c03421bea22bc8a68e442a1444fbd59e66d5f | year_2017_day_15_lib.pyx | /2017/year_2017_day_15_lib.pyx | thearn/aoc | 1,218 | UTF-8 |
cdef int genAnext(int prev):
return (prev * 16807) % 2147483647
cdef int genBnext(int prev):
return (prev * 48271) % 2147483647
def day_15_2017_part_1(start):
"""Part 1."""
cdef int a = start[0]
cdef int b = start[1]
cdef int score = 0
cdef long i = 0L
for i in range(40*1000000L):
... | sft_candidate | [] | no_license | 0 |
1aaa7af8110600eeb42bbd550115079633617be1 | calculation.pyx | /grid2tin/calculation.pyx | umeier/GridToTIN | 1,244 | UTF-8 | from math import ceil, floor
def calc_interpolation(double a, double b, double c, int x, int y):
# for call from external
return a * x + b * y + c
cdef double interpolation(double a, double b, double c, int x, int y):
# for call from internal
return a * x + b * y + c
def scan_triangle_line(available,... | sft_candidate | [
"MIT"
] | permissive | 0 |
ab93e53dfba57300e5c81ad6d032f05ac3104138 | bc_util_cy.pyx | /python/bc_util_cy.pyx | bradleycolquitt/umi | 1,250 | UTF-8 | import fasta_cy as fasta
import Levenshtein as lev
cpdef int min_barcode(list barcodes, str sseq):
cdef int val = 0
cdef int distance_min = 100
cdef int i = 0
cdef int ind = 0
for bc in barcodes:
val = lev.distance(sseq, bc)
if val == 0:
ind = i
... | sft_candidate | [] | no_license | 0 |
6b0c1ba7b17cea70784b6fa6f3d31831b357ba46 | mandel2d_cy.pyx | /mandelbrot/mandel2d_cy.pyx | aroberge/py-fun | 1,251 | UTF-8 | # mandel2d_cy.pyx
# cython: profile=True
def mandel(double real, double imag, int max_iterations=20):
'''determines if a point is in the Mandelbrot set based on deciding if,
after a maximum allowed number of iterations, the absolute value of
the resulting number is greater or equal to 2.'''
cdef ... | sft_candidate | [] | no_license | 0 |
355006cf60087958c87ca8d989ac2a26878ea323 | negloglikelihood.pyx | /src/distance/negloglikelihood.pyx | Kalior/clustering-genomic-signatures | 1,257 | UTF-8 | cdef class NegativeLogLikelihood(object):
"""
Calculates the distance between two VLMCs.
D(left, right) = (D(left, right) + D(right, left)) / 2
Where, D(x, y) is the cross entropy calculated by generating a sequence S_x from model x,
and computing:
D(x, y) = log Pr(S_x | x) - log Pr(S_x | y)
Where log Pr... | sft_candidate | [] | no_license | 2 |
507dbdb8f83737bd7810e2e244cce936f12b140d | cyutils.pyx | /magis/utils/cyutils.pyx | braingineer/magis_deprecated | 1,260 | UTF-8 | from libc.stdlib cimport malloc, free, realloc
__all__ = ['BoundingBox', 'ngrams', 'unigrams', 'bigrams', 'trigrams']
cdef list _ngram(list words, int n=2):
cdef int i;
return list(zip(*[words[i:] for i in range(n)]))
cpdef list ngrams(list words, int start=1, int stop=10):
cdef int i
return [_ngram... | sft_candidate | [
"MIT"
] | permissive | 1 |
883c81cb1a9b3dd302f4cd96835ffa76d931e2c8 | ngrams_fast.pyx | /ngrams_fast.pyx | sanchestm/fastq-hashvectorizer | 1,260 | UTF-8 | tab_b = bytes.maketrans(b"ACGT", b"TGCA")
def bRevComp(seq):
return seq.translate(tab_b)[::-1]
cdef int char_transform(int char):
if char == 65: return 84
elif char == 67: return 71
elif char == 71: return 67
elif char == 84: return 65
return 78
cdef OK(unsigned char *kmer, int val):
cdef... | sft_candidate | [] | no_license | 0 |
3546b0a5a8484e57771b0db843315ab8ce0ab240 | _compression.pyx | /src/psd_tools/_compression.pyx | jacenfox/psd-tools2 | 1,266 | UTF-8 | """
Cython extension with utilities for "zip-with-prediction"
decompression method.
"""
cimport cpython.array
def _delta_decode(arr, int mod, int w, int h):
if mod == 256:
_delta_decode_bytes(arr, w, h)
return arr
elif mod == 256*256:
_delta_decode_words(arr, w, h)
arr.byteswap(... | sft_candidate | [
"MIT"
] | permissive | 3 |
64c91905ecca4689596c221b0ee3d21bfadd563a | GeneVariance.pyx | /measures/GeneVariance.pyx | clslabMSU/Biclustering-MOEA | 1,273 | UTF-8 | # cython: cdivision=True
# cython: boundscheck=False
# cython: wraparound=False
cimport cython
from libc.stdlib cimport malloc, free
def GeneVariance(float[:, :] bicluster):
"""
Gene variance according to:
Pontes, B., Giráldez, R., & Aguilar-Ruiz, J. S. (2013). Configurable pattern-based evolutionary bic... | sft_candidate | [] | no_license | 3 |
902d47d50d4465449b471ef777b856f85bb4bfd0 | static_methods.pyx | /3.FinalTransformation/makejson/Cython-0.24.1/tests/run/static_methods.pyx | mitragithub/Registration | 1,283 | UTF-8 | cdef class A:
@staticmethod
def static_def(int x):
"""
>>> A.static_def(2)
('def', 2)
>>> A().static_def(2)
('def', 2)
"""
return 'def', x
@staticmethod
cdef static_cdef(int* x):
return 'cdef', x[0]
# @staticmethod
# cpdef static_... | sft_candidate | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | 5 |
33ada4de7d3f3560d43c26e3c85c3ecb3a953ed9 | TDMAsolver.pyx | /tfg/Classes/Functions/TDMAsolver.pyx | rmhsik/TFG | 1,294 | UTF-8 | # distutils: language=c++
# cython: language_level=3
import numpy as np
def TDMAsolver(double complex[:] c,
double complex[:] b,
double complex[:] a,
double complex[:] d):
return cTDMAsolver(a,b,c,d)
cdef double complex[:] cTDMAsolver(double complex[:] a,
... | sft_candidate | [] | no_license | 0 |
1fef4196361f1496af80e03f3a5922d2a6d0cd65 | GoLComplete.pyx | /Cython/GoLComplete.pyx | jonasjuenemann/Bachelorarbeit | 1,296 | UTF-8 | from time import time
import numpy as np
np.random.seed(0)
def true(x, N):
return (x + N) % N
def Nachbarn(x, y, grid, N):
return grid[true(y - 1, N)][true(x + 1, N)] + grid[true(y - 1, N)][true(x, N)] + grid[true(y - 1, N)][true(x - 1, N)] + grid[true(y, N)][
true(x + 1, N)] + \
grid[true... | sft_candidate | [] | no_license | 0 |
9057fe324af0b3c732c7100a5d1934469278f07a | v_value.pyx | /shapley_cython/v_value.pyx | RMenoni/Shapley-Empiricus | 1,297 | UTF-8 | def subseq(seq):
cdef int n = len(seq)
cdef int i
for i in range(1, 2**n):
b = format(i, f'0{n}b')
list s = []
cdef int j
for j in range(len(b)):
if int(b[-j-1]) == 1:
s.append(seq[j])
s.sort()
yield ','.join(s)
cpdef int v_functi... | sft_candidate | [] | no_license | 0 |
838f2edc68a90d86eb3f46c1ae21db2993b0dbb7 | cython_func.pyx | /cython_func.pyx | rosinaSav/NAS_code | 1,307 | UTF-8 | '''
Author: Rosina Savisaar.
Functions that will be converted to C using Cython.
'''
#compile using python3 cython_setup.py build_ext --inplace
import numpy as np
def calc_density_c(motif, sequence, double motif_length, return_count = False):
cdef float density, match_length, seq_length
if not sequence:
... | sft_candidate | [] | no_license | 1 |
6ff04da0ce4d72d0128a4630f2e71b645e296e42 | FST_Functions.pyx | /src/pycropml/transpiler/lib/pyx/FST_Functions.pyx | AgriculturalModelExchangeInitiative/PyCrop2ML | 1,337 | UTF-8 | # FSTFunctions
def AFGEN1(float xy[], float t):
cdef float res;
cdef float x1, x2, y1, y2
cdef int i, n
n = len(xy)
res = float("nan")
if(n>1):
i = 0
while (i < n-1 and t >= xy[i]):
i = i + 2
if(i==0):
res = xy[1]
elif (i>n-2):
... | sft_candidate | [
"MIT"
] | permissive | 10 |
5da5a7e3fb722f09faaa0bb02b89936332ffdd95 | naive_parameter_sampling.pyx | /src/distance/naive_parameter_sampling.pyx | Kalior/clustering-genomic-signatures | 1,359 | UTF-8 | import math
cdef class NaiveParameterSampling(object):
"""
Proposed by Levinson et al. for discrete-observation density hidden Markov models.
Appears also in the paper by Juang et al. from 1985 on "A Probablistic Distance Measure For Hidden Markov Models".
"""
def __init__(self):
return
cpdef do... | sft_candidate | [] | no_license | 2 |
50c694060a295a347b46d8c25ccb82f3d6b6e246 | laguerre_functions.pyx | /cython_code/laguerre_functions.pyx | akniyev/cauchy_for_ode | 1,369 | UTF-8 | # cython: language_level=3, boundscheck=False
cdef double laguerre_iterative_cython(int k, double alpha, double x):
if k <= 0:
return 1
cdef double minus_2 = 1
cdef double minus_1 = -x + alpha + 1
cdef int i
cdef double a
cdef double b
cdef double current
for i in range(2, k+... | sft_candidate | [] | no_license | 1 |
166e2d600269a9d826d953232c2599f08177d4bd | demo.pyx | /docs/src/quickstart/demo.pyx | cython/cython | 1,379 | UTF-8 | from time import time
from math import sin
cdef double first_time = 0
def timeit(f, label):
global first_time
t = time()
f(1.0, 2.0, 10**7)
cdef double elapsed = time() - t
if first_time == 0:
first_time = elapsed
print label, elapsed, (100*elapsed/first_time), '% or', first_time/elaps... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 8,352 |
ffd93456b0b99958dac554b936ada902522a36a1 | pagefault.pyx | /thingking/pagefault.pyx | zero-py/thingking | 1,429 | UTF-8 | import sys, time
from thingking.httpmmap import httpfile
cdef object cookies = {}
cdef ssize_t tk_read(void *cookie, char *buf, size_t size) nogil:
global cookies
cdef int i
cdef ssize_t osize
cdef char* b
with gil:
tk_obj = cookies[(<int*>cookie)[0]]
s = tk_obj.read(int(size))
... | sft_candidate | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 1 |
fea05d617d3577f4e89f55f345e65ff0424ef076 | Res_sorter.pyx | /query/Res_sorter.pyx | Rossonero/qlin | 1,438 | UTF-8 | cdef struct Whit:
int docID
int pos #可以直接比较位置
float rank #得分
cdef class RankSorter:
'''
'''
cdef Whit *dali
cdef int length
def __cinit__(self,datalist):
pass
cdef init(self,Whit *li,int length):
self.dali = li
self.length = length
cdef f... | sft_candidate | [] | no_license | 0 |
ee16444420bfd84df115a24f92ec54595e9da692 | do_omp_basic.pyx | /do_omp_basic.pyx | AraiKensuke/cython_par | 1,461 | UTF-8 | import numpy as _N
from cython.parallel import prange, parallel
from libc.math cimport sin, fabs
def calc_using_prange(int rep, int TR, int N):
cdef int tr, i, r
cdef double tot
outs = _N.empty(rep*TR)
cdef double[::1] v_outs = outs
cdef double *p_outs = &v_outs[0]
with nogil:
for r fr... | sft_candidate | [] | no_license | 0 |
47ccb398b9bc8a107d7285757591afe33f05a7b6 | cython_ext_module.pyx | /tests/example-project/src/pypackage/cython_ext_module.pyx | lgpage/pytest-cython | 1,461 | UTF-8 |
cdef int cfoo(int a, int b) except? -1:
"""
>>> cfoo(1, 1)
2
"""
return a + b
cdef int cbar(int a, int b) nogil except? -1:
"""
>>> cbar(1, 1)
2
"""
return a + b
cdef inline int cspam(int a, int b) nogil except? -1:
"""
>>> cspam(1, 1)
2
"""
return (a + b)
... | sft_candidate | [
"MIT"
] | permissive | 18 |
aaa3d81203dce3e6ce4eea1282cd0983dbd791d6 | _nx_extensions_cython_backend.pyx | /netharn/initializers/_nx_extensions_cython_backend.pyx | Erotemic/netharn | 1,467 | UTF-8 | """
cythonize -a -i ~/code/netharn/netharn/initializers/_nx_extensions_cython_backend.pyx
>>> from netharn.initializers import _nx_extensions_cython_backend
>>> import timerit
>>> ti = timerit.Timerit(100, bestof=10, verbose=2)
>>> for timer in ti.reset('time'):
>>> with ti... | sft_candidate | [
"Apache-2.0"
] | permissive | 43 |
cb70cdacc8b04793c559f3ddeb7bc651ac51ea0b | utils.pyx | /hmm/utils.pyx | jassinm/hmm | 1,469 | UTF-8 | """
utilities functions: borrowed from pomgrenate - https://github.com/jmschrei/pomegranate
"""
from libc.math cimport log as clog
from libc.math cimport exp as cexp
DEF NEGINF = float("-inf")
DEF INF = float("inf")
cdef double logsum_pair(double x, double y) nogil:
"""
Perform log-sum-exp on a pair of numbe... | sft_candidate | [] | no_license | 1 |
59aa4bff92ffe9a5dbba1f2599872baf25c76382 | numbers.pyx | /common/numbers.pyx | akivajp/nlputils | 1,489 | UTF-8 | # distutils: language=c++
# -*- coding: utf-8 -*-
'''functions for numbers'''
# Standard libraries
import math
import sys
import nlputils.init
from nlputils.common import logging
cpdef object toNumber(anyNum, float margin = 0):
cdef float floatNum
#cdef int intNum
cdef long intNum
floatNum = float(a... | sft_candidate | [] | no_license | 0 |
a27e8953e27df92c3c606be3862f4675d452a194 | kd.pyx | /kd.pyx | tianhm/pyta-1 | 1,490 | UTF-8 | """
KD: KD indicator.
"""
import numpy as np
import pandas as pd
def kd(ohlc, int n=9, int m1=3, int m2=3):
"""KD indicator.
Params:
ohlc (DataFrame): Time series data of OHLC prices (open, high, low, close).
n, m1, m2 (int): KD params.
Returns:
DataFrame: K & D values.
""... | sft_candidate | [
"MIT"
] | permissive | 0 |
1bf37ff835d6548fbf1a50dd44b5ce6a1d4d1295 | argdefault.pyx | /tests/run/argdefault.pyx | cython/cython | 1,515 | UTF-8 | GLB0 = (1, 2)
def f0(arg=GLB0):
"""
>>> f0()
(1, 2)
"""
return arg
def g0(arg=(1, 2)):
"""
>>> g0()
(1, 2)
"""
return arg
GLB1 = [1, 2]
def f1(arg=GLB1):
"""
>>> f1()
[1, 2]
"""
return arg
def g1(arg=[1, 2]):
"""
>>> g1()
[1, 2]
"""
retur... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 8,352 |
6a0375babc3f199ece715f137cc203e0bb617145 | lj_utils.pyx | /pychemia/code/lennardjones/lj_utils.pyx | MaterialsDiscovery/PyChemia | 1,530 | UTF-8 | # cython: language_level=3
import numpy as np
def lj_forces(pos, sigmas, epsilons, cp=0.0):
#cdef int n, i, j
#cdef float distance, magnitude
pos = np.array(pos).reshape((-1, 3))
n = len(pos)
ret = np.zeros((n, 3))
for i in range(n - 1):
for j in range(i + 1, n):
vector = ... | sft_candidate | [
"MIT"
] | permissive | 73 |
f179e47b800193780412d84f1b3e8bab3069094d | assignment.pyx | /Cython_ex/assignment.pyx | letsjdosth/pyHigh | 1,546 | UTF-8 | # cytnon compiler에 hint를 주자
# 변수 type hint
cdef int i
cdef double a,b = 2.0, c=3.0
cdef int c = 0
cdef double d = <double> c #casting
# C 기본타입 모두 가능 (struct까지)
# 단, 그 외의 파이썬 객체는 object로 선언해야함
# 단 object는 Cython이 최적화를 잘 못하므로, 성능이득이 별로 없음
# 함수 type hint
# def: 타입검사하는 파이썬 임포트가능 버전
def max_python(int a, int b):
r... | sft_candidate | [] | no_license | 0 |
465b8487d0e8b0ca1a0165f5943cc54a69c219bb | annotate_html.pyx | /tests/run/annotate_html.pyx | cython/cython | 1,548 | UTF-8 | # cython: test_assert_c_code_has = Generated by Cython
# cython: test_assert_c_code_has = goto __pyx_L0;\n
"""
>>> from codecs import open
>>> import os.path as os_path
>>> module_path = os_path.join(os_path.dirname(__file__), os_path.basename(__file__).split('.', 1)[0])
>>> assert module_path.endswith('annotate_html'... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 8,352 |
195131daf04490d5f73c91320748d746f03de540 | ctruthtests.pyx | /tests/run/ctruthtests.pyx | cython/cython | 1,548 | UTF-8 | def test_ptr():
"""
>>> test_ptr()
False
"""
cdef void* p = NULL
if p:
return True
else:
return False
def test_ptr2():
"""
>>> test_ptr2()
2
"""
cdef char* p1 = NULL
cdef char* p2 = NULL
p1 += 1
if p1 and p2:
return 1
elif p1 or p... | sft_candidate | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | 8,352 |
bbf9e08312638f3c4ddb4f3494cebab5862e9d1c | class_block_string.pyx | /class_block_string.pyx | LionelMassoulard/TestCython | 1,561 | UTF-8 | # -*- coding: utf-8 -*-
"""
Created on Sun Mar 3 17:33:17 2019
@author: arwen
"""
cdef class CBlock(object):
cdef readonly double left
cdef readonly double right
cdef readonly double top
cdef readonly double bottom
cdef readonly str text
def __init__(self,
... | sft_candidate | [] | no_license | 0 |
55294d4ed595d4f74d1436f3c3444f3cc42ff051 | inheritance.pyx | /chp05_extended_type/inheritance.pyx | ccwang002/learn_cython | 1,576 | UTF-8 | from libc.math cimport sqrt
cdef class Particle:
"""Simple Particle extension type."""
cdef double mass, position, velocity
def __init__(self, m, p, v):
self.mass = m
self.position = p
self.velocity = v
cpdef double get_momentum(self):
return self.mass * self.velocity
... | sft_candidate | [] | no_license | 0 |
4f4844ee822534641538ac82d19ecee469160b54 | _misc.pyx | /home--tommy--mypy/mypy/lib/python2.7/site-packages/pystan/_misc.pyx | tommybutler/mlearnpy2 | 1,579 | UTF-8 | import cython
import numpy as np
@cython.boundscheck(False)
@cython.wraparound(False)
cpdef get_kept_samples(int n, dict sim):
"""See documentation in misc.py"""
cdef int i, j, num_chains, num_samples, num_warmup, ss_index, s_index
cdef double[:] s, ss
cdef long[:] perm
num_chains = sim['chains']... | sft_candidate | [
"Unlicense"
] | permissive | 0 |
272266267a44e5e82060c1de16fec82b37b350b9 | metrics.pyx | /metrics.pyx | IvanBrasilico/image-segmentation | 1,580 | UTF-8 | from libc.math cimport log10 as log_base_10
from libc.math cimport log2 as log_base_2
def huber(double[:] x, double[:] y):
cdef int n = x.shape[0]
cdef double delta = 0.0125
cdef double res = 0
cdef double res_sum = 0
for i in range(n):
res = abs(x[i] - y[i])
if res <= delta:
res_sum += (re... | sft_candidate | [] | no_license | 0 |
14d03598ab83cb75ab1ca36546a9b69a840d9401 | dateline.pyx | /karta/vector/dateline.pyx | MachineAi/karta | 1,582 | UTF-8 |
cdef double mind(double a, double b):
if a > b:
return b
else:
return a
cdef double maxd(double a, double b):
if a > b:
return a
else:
return b
cdef int signd(double a):
""" Return the sign of *a* """
if a == 0.0:
return 1
else:
return int(a... | sft_candidate | [
"MIT"
] | permissive | 0 |
cba910c99c08b0ffe8bac7d87e88316018b8ab72 | pil2epd.pyx | /pil2epd.pyx | ThePaperTop/pil2epd | 1,585 | UTF-8 | def __to_ints__(img):
data = [0] * 384000
cdef int c = 0
cdef int x
cdef int y
cdef int rgb
cdef int alpha
for x in range(0,800):
for y in range(0, 480):
rgb, alpha = img[y,x]
data[c]=rgb
c=c+1
return data
def __downsample__(ints):
pi... | sft_candidate | [
"MIT"
] | permissive | 0 |
e5a99f305b193e07ba07b297da4cea5ade9cce45 | sudoku_solver_c.pyx | /sudoku_solver_c.pyx | shkolovy/sudoku | 1,599 | UTF-8 | cpdef list _solve(list board, tuple p):
cdef tuple new_p = _get_next_p(board, p)
if not new_p:
return True
cdef int n = 0
for n in range(1, 10):
if _can_place(board, p, n):
board[p[0]][p[1]] = n
if _solve(board, new_p):
return True
#... | sft_candidate | [] | no_license | 0 |
731b31ede4e99a6989cdd0d6add9b508e2c754e1 | optimal_path_cython.pyx | /src/optimal_path_cython.pyx | zwbond/shortest_path | 1,600 | UTF-8 | import numpy as np
def optimal_path(gradx_interp,
grady_interp,
starting_point,
dx,
N=100):
"""
Find the optimal path from starting_point to the zero contour
of travel_time. dx is the grid spacing
Solve the equation x_t = - grad t / | ... | sft_candidate | [] | no_license | 0 |
c06c0d17526b09c5fb3d448257ecb7a072e3eb65 | TPC.pyx | /measures/TPC.pyx | clslabMSU/Biclustering-MOEA | 1,608 | UTF-8 | # cython: cdivision=True
# cython: boundscheck=False
# cython: wraparound=False
cimport cython
from libc.math cimport fabs, sqrt
from libc.stdlib cimport malloc, free
def TPC(float[:, :] bicluster):
"""
Trend-preserving correlation score
:param bicluster: bicluster in which the TPC is desired
:retur... | sft_candidate | [] | no_license | 3 |
21db8f3c1be66b8f8adb0b5a5cd65816a0442406 | statsfunctionscython.pyx | /statsfunctionscython.pyx | CodeDrome/speed-experiments-python | 1,619 | UTF-8 | import statistics
def python_functions(list data):
"""
Calculate a few statistics from
the numeric list using Python functions.
Inefficient due to repeated iteration.
This Cython implementation is no more
efficient than the Python version
and is only included for demonstration.
"""
... | sft_candidate | [] | no_license | 0 |
4158ec860b867240ff17655bb392de48a49281e1 | helpers.pyx | /02_evidence_assessment/02e_pesr_testing/scripts/helpers.pyx | awacs/PrenatalSVDiscoveryProject | 1,623 | UTF-8 | from pysam.libcalignedsegment cimport AlignedSegment
from pysam.libcalignmentfile cimport AlignmentFile
cpdef bint is_excluded(AlignedSegment read):
cdef bint exclude = (read.is_unmapped or
read.mate_is_unmapped or
read.is_secondary or
read... | sft_candidate | [] | no_license | 0 |
62e948730a990693030f1347641dec71b649050b | knucleotide.pyx | /knucleotide/knucleotide.pyx | ivanpepelko/jit-benchmarks | 1,627 | UTF-8 | # The Computer Language Benchmarks Game
# http://benchmarksgame.alioth.debian.org/
#
# submitted by Ian Osgood
# modified by Sokolov Yura
# modified by bearophile
# 2to3
from sys import stdin
import sys, time
def gen_freq(seq, int frame, frequences):
cdef int ns, ii
ns = len(seq) + 1 - frame
frequences.... | sft_candidate | [
"MIT"
] | permissive | 0 |
43e579693fe31b29899a5fedbc35f63b722a1de4 | PTQ.pyx | /src/pycropml/transpiler/antlr_py/csharp/examples/pheno_pkg/src/pyx/PTQ.pyx | AgriculturalModelExchangeInitiative/PyCrop2ML | 1,643 | UTF-8 | import numpy
from math import *
def model_PTQ(float tTWindowForPTQ=70.0,
float kl=0.45,
list listTTShootWindowForPTQ_t1=[0.0],
list listPARTTWindowForPTQ_t1=[0.0],
list listGAITTWindowForPTQ=[0.0, 5.2],
float pAR=0.0,
float deltaTT=0.0... | sft_candidate | [
"MIT"
] | permissive | 10 |
3d7e0d88672ad9e771f11dd0b277a22e1140a8b2 | log_sum_exp.pyx | /hips/inference/log_sum_exp.pyx | yarden/hips-lib | 1,649 | UTF-8 | # distutils: extra_compile_args = -O3
# cython: wraparound=False
# cython: boundscheck=False
# cython: nonecheck=False
# cython: cdivision=True
## cython: profile=True
import numpy as np
cimport numpy as np
from libc.math cimport log, exp
cpdef double log_sum_exp(double[::1] lnp):
"""
Sample uniformly from a... | sft_candidate | [] | no_license | 1 |
ddbfa853880fe631f1b34f54e0957cc16bf6bc6d | find_polyA_cython.pyx | /find_polyA_cython.pyx | AlexeyG/ribosomes | 1,689 | UTF-8 | def find_polyA(char* seq, int min_length):
''' Find the first polyA stretch at least min_length long in seq.
If there is no such stretch, return the index and length of
the longest stretch.
'''
cdef int i = 0
cdef int current_length = 0
cdef int longest_length = 0
cdef int long... | sft_candidate | [] | no_license | 0 |
d79367d33ab5dbc694125b8e309c6e59fd5c0a5c | distances.pyx | /alignment/distances.pyx | neosatrapahereje/bruckner_project | 1,696 | UTF-8 | import numpy as np
cimport cython
from libc.math cimport sqrt
@cython.boundscheck(False)
@cython.wraparound(False)
def euclidean_cdist(float[:, ::1] X, float[:, ::1] Y):
"""
Pairwise Euclidean Distance
"""
cdef int M = X.shape[0]
cdef int N = Y.shape[0]
cdef int L = X.shape[1]
cdef float di... | sft_candidate | [] | no_license | 0 |
a4adc501c5bea075b15887e013891157daaeb91b | mandel2j_cy.pyx | /mandelbrot/mandel2j_cy.pyx | aroberge/py-fun | 1,696 | UTF-8 | # mandel2g_cy.pyx
# cython: profile=True
import cython
@cython.profile(False)
cdef inline bint mandel(double real, double imag, int max_iterations=20):
'''determines if a point is in the Mandelbrot set based on deciding if,
after a maximum allowed number of iterations, the absolute value of
the resu... | sft_candidate | [] | no_license | 0 |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 31