<commit_before>#<NAME> (<EMAIL>) - October 2012

#This Cython program provides a wrapper for C-functions which compute the finite-sum of the Riemann Theta approximation

cimport cython
import numpy as np
cimport numpy as np
np.import_array()
import scipy.linalg as la
import time

cdef extern from 'riemanntheta.h':
        void finite_sum_without_derivatives(double *, double *, double *,
                                            double *, double *, double *,
                                            double *, double *, int, int)

        void finite_sum_with_derivatives(double*, double*, double*, double*, 
                                         double*, double*, double*, double*,
                                         double*, double*, int , int , int )

#Creates a Python-accessible function in cython that calls the 
#C - function above

@cython.boundscheck(False) #Turns off bounds checking
def finite_sum(X, Yinv, T, Z, S, g, List):
    vals = []
    N = len(S)/g
    cdef double real[0]
    cdef double imag[0]
    for z in Z:
        x = z.real
        y = z.imag
        N = len(S)/g
        X = np.ascontiguousarray(X, dtype = 'double')
        Yinv = np.ascontiguousarray(Yinv, dtype = 'double')
        T = np.ascontiguousarray(T, dtype = 'double')
        x = np.ascontiguousarray(x, dtype = 'double')
        y = np.ascontiguousarray(y, dtype = 'double')
        S = np.ascontiguousarray(S, dtype = 'double')
        finite_sum_without_derivatives(real, imag, 
				       <double*> np.PyArray_DATA(X),
                                       <double*> np.PyArray_DATA(Yinv),
                                       <double*> np.PyArray_DATA(T),
                                       <double*> np.PyArray_DATA(x),
                                       <double*> np.PyArray_DATA(y),
                                       <double*> np.PyArray_DATA(S),
                                       g, N)
        if (List):
           vals.append(real[0] + imag[0] * 1.0j)
        else:
           return real[0] + imag[0] * 1.0j
    return np.array(vals)
                

@cython.boundscheck(False) #Turns off bounds checking
def finite_sum_derivatives(X, Yinv, T, z, S, deriv, g, List):
    vals = []
    N = len(S)/g
    nderivs = len(deriv)
    cdef double real[0]
    cdef double imag[0]
    for i in range(z.shape[0]):
        x = z[i,:].real
        y = z[i,:].imag
        deriv_real = np.ascontiguousarray(deriv.real, dtype = 'double')
        deriv_imag = np.ascontiguousarray(deriv.imag, dtype = 'double')
        X = np.ascontiguousarray(X, dtype = 'double')<commit_msg>Fix major bug in riemanntheta_cy.<commit_after>#<NAME> (<EMAIL>) - October 2012

#This Cython program provides a wrapper for C-functions which compute the finite-sum of the Riemann Theta approximation

cimport cython
import numpy as np
cimport numpy as np
np.import_array()
import scipy.linalg as la
import time

cdef extern from 'riemanntheta.h':
        void finite_sum_without_derivatives(double *, double *, double *,
                                            double *, double *, double *,
                                            double *, double *, int, int)

        void finite_sum_with_derivatives(double*, double*, double*, double*, 
                                         double*, double*, double*, double*,
                                         double*, double*, int , int , int )

#Creates a Python-accessible function in cython that calls the 
#C - function above

@cython.boundscheck(False) #Turns off bounds checking
def finite_sum(X, Yinv, T, Z, S, g, List):
    vals = []
    N = len(S)/g
    real = np.array([0],'double')
    imag = np.array([0],'double')
    for z in Z:
        x = z.real
        y = z.imag
        N = len(S)/g
        X = np.ascontiguousarray(X, dtype = 'double')
        Yinv = np.ascontiguousarray(Yinv, dtype = 'double')
        T = np.ascontiguousarray(T, dtype = 'double')
        x = np.ascontiguousarray(x, dtype = 'double')
        y = np.ascontiguousarray(y, dtype = 'double')
        S = np.ascontiguousarray(S, dtype = 'double')
        finite_sum_without_derivatives(<double*> np.PyArray_DATA(real),
                                       <double*> np.PyArray_DATA(imag),
				       <double*> np.PyArray_DATA(X),
                                       <double*> np.PyArray_DATA(Yinv),
                                       <double*> np.PyArray_DATA(T),
                                       <double*> np.PyArray_DATA(x),
                                       <double*> np.PyArray_DATA(y),
                                       <double*> np.PyArray_DATA(S),
                                       g, N)
        if (List):
           vals.append(real[0] + imag[0] * 1.0j)
        else:
           return real[0] + imag[0] * 1.0j
    return np.array(vals)
                

@cython.boundscheck(False) #Turns off bounds checking
def finite_sum_derivatives(X, Yinv, T, z, S, deriv, g, List):
    vals = []
    N = len(S)/g
    nderivs = len(deriv)
    cdef double real[0]
    cdef double imag[0]
    for i in range(z.shape[0]):
        x = z[i,:].real
        y = z[i,:].imag
        deriv_real = np.ascontiguousarray(deriv.real, dtype = 'double')
        deriv_imag = np.ascontiguousarray(deriv.imag, dtype = 'double')
        X = np.ascontiguousarray(X, dtype = 'double')
{'fraction_non_alphanumeric': 0.1156296851574213, 'fraction_numerical': 0.006371814092953523, 'mean_word_length': 1.7174134419551934, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 29, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7549518', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1573, 'n_words': 419}