<commit_before># coding: utf-8
# cython: boundscheck=False
# cython: nonecheck=False
# cython: cdivision=True
# cython: wraparound=False
# cython: profile=False

""" Leapfrog integration in Cython. """

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Third-party
import numpy as np
cimport numpy as np
np.import_array()

# Project
from ..potential.cpotential cimport _CPotential

# ctypedef void (*f_type)(int, double*, double*)

cdef void c_init_velocity(_CPotential p, int ndim, double t, double dt,
                          double *x_jm1, double *v_jm1, double *v_jm1_2, double *grad) nogil:
    cdef int k

    p._gradient(x_jm1, grad)

    for k in range(ndim):
        v_jm1_2[k] = v_jm1[k] - grad[k] * dt/2.  # acceleration is minus gradient

cdef void c_leapfrog_step(_CPotential p, int ndim, double t, double dt,
                          double *x_jm1, double *v_jm1, double *v_jm1_2, double *grad) nogil:
    cdef int k

    # full step the positions
    for k in range(ndim):
        x_jm1[k] = x_jm1[k] + v_jm1_2[k] * dt

    p._gradient(x_jm1, grad)  # compute gradient at new position

    # step velocity forward by half step, aligned w/ position, then
    #   finish the full step to leapfrog over position
    for k in range(ndim):
        v_jm1[k] = v_jm1_2[k] - grad[k] * dt/2.
        v_jm1_2[k] = v_jm1_2[k] - grad[k] * dt

cpdef cy_leapfrog_run(_CPotential potential, double [:,::1] w0,
                      double dt, int nsteps, double t1):
    # temporary scalars
    cdef int i,j,k
    cdef int n = w0.shape[0]<commit_msg>fix leapfrog integrator to pass in time<commit_after># coding: utf-8
# cython: boundscheck=False
# cython: nonecheck=False
# cython: cdivision=True
# cython: wraparound=False
# cython: profile=False

""" Leapfrog integration in Cython. """

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Third-party
import numpy as np
cimport numpy as np
np.import_array()

# Project
from ..potential.cpotential cimport _CPotential

# ctypedef void (*f_type)(int, double*, double*)

cdef void c_init_velocity(_CPotential p, int ndim, double t, double dt,
                          double *x_jm1, double *v_jm1, double *v_jm1_2, double *grad) nogil:
    cdef int k

    p._gradient(t, x_jm1, grad)

    for k in range(ndim):
        v_jm1_2[k] = v_jm1[k] - grad[k] * dt/2.  # acceleration is minus gradient

cdef void c_leapfrog_step(_CPotential p, int ndim, double t, double dt,
                          double *x_jm1, double *v_jm1, double *v_jm1_2, double *grad) nogil:
    cdef int k

    # full step the positions
    for k in range(ndim):
        x_jm1[k] = x_jm1[k] + v_jm1_2[k] * dt

    p._gradient(t, x_jm1, grad)  # compute gradient at new position

    # step velocity forward by half step, aligned w/ position, then
    #   finish the full step to leapfrog over position
    for k in range(ndim):
        v_jm1[k] = v_jm1_2[k] - grad[k] * dt/2.
        v_jm1_2[k] = v_jm1_2[k] - grad[k] * dt

cpdef cy_leapfrog_run(_CPotential potential, double [:,::1] w0,
                      double dt, int nsteps, double t1):
    # temporary scalars
    cdef int i,j,k
    cdef int n = w0.shape[0]
{'fraction_non_alphanumeric': 0.10555902560899438, 'fraction_numerical': 0.019987507807620236, 'mean_word_length': 2.9987515605493136, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7220929', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1178, 'n_words': 353}