Giter Site home page Giter Site logo

cythonbuilder's Introduction

Hi, I'm Mike!

I'm a full-stack developer from the Netherlands with a passion for programming and traveling.

Writing

I like to share my adventures, experiments, failures and successes by writing articles at:
https://mikehuls.com
and
https://mikehuls.medium.com

Latest articles

Recent Article 0
Recent Article 1
Recent Article 2

Get in touch

twitter medium linked-in

P.s: like what I do?
Foo

cythonbuilder's People

Contributors

kulothunganug avatar mike-huls avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cythonbuilder's Issues

build error on new version

on versions > 0.1.0 on windows 10 I have an error:

[cythonbuilder] 15:39:44 cli      133  Cleanup complete
[cythonbuilder] 15:39:44 cli      137  Generating interface files..
[cythonbuilder] 15:39:44 cython_builder 161  [cy_interface] - generating interface files for 1 found pyx files
st_ration.pyx
[cythonbuilder] 15:39:44 cli      143  [build] build error: string index out of [range]([url](url))

On 0.1.0 it works well

code:

#!python
#cython: language_level=3


#///// # cython: infer_types=True
# https://idlecoding.com/from-python-to-cython/


import numpy as np

# "cimport" is used to import special compile-time information
# about the numpy module (this is stored in a file numpy.pxd which is
# currently part of the Cython distribution).
cimport numpy as np

# It's necessary to call "import_array" if you use any part of the
# numpy PyArray_* API. From Cython 3, accessing attributes like
# ".shape" on a typed Numpy array use this API. Therefore we recommend
# always calling "import_array" whenever you "cimport numpy"
np.import_array()

# We now need to fix a datatype for our arrays. I've used the variable
# DTYPE for this, which is assigned to the usual NumPy runtime
# type info object.
###DTYPE = np.int

# "ctypedef" assigns a corresponding compile-time type to DTYPE_t. For
# every type in the numpy module there's a corresponding compile-time
# type with a _t-suffix.
#ctypedef np.int_t DTYPE_t



cimport cython


@cython.boundscheck(False) # turn off bounds-checking for entire function
@cython.wraparound(False)  # turn off negative index wrapping for entire function
@cython.cdivision(True)
def eval_nutrients(
    np.ndarray[np.float32_t, ndim=1] norms,
    np.ndarray[np.float32_t, ndim=1] target,
    np.ndarray[np.float32_t, ndim=1] lower_border,
    np.ndarray[np.float32_t, ndim=1] upper_border,
    np.ndarray[np.float32_t, ndim=1] importances_lower,
    np.ndarray[np.float32_t, ndim=1] importances_upper,
    float INNER_COEF,
    float OUTER_COEF
):

    cdef float total_okay = 0, total_not_okay = 0, v, t
    cdef int length = target.shape[0]
    cdef Py_ssize_t i

    for i in range(length):
        t = target[i]
        v = (norms[i] - t) / t

        if v < lower_border[i]:
            total_not_okay += abs(v)*importances_lower[i]
        elif v > upper_border[i]:
            total_not_okay += abs(v)*importances_upper[i]
        else:
            total_okay += abs(v)
        
    return total_okay*INNER_COEF + total_not_okay*OUTER_COEF



@cython.boundscheck(False) # turn off bounds-checking for entire function
@cython.wraparound(False)  # turn off negative index wrapping for entire function
def vector_to_norms(
    np.ndarray[np.float32_t, ndim=1] portions_vector,
    np.ndarray[np.float32_t, ndim=2] matrix,
    np.ndarray[np.float32_t, ndim=1] result
):

    cdef float s 

    cdef Py_ssize_t row, col

    for col in range(matrix.shape[1]):

        s = 0
        for row in range(matrix.shape[0]):
            s += portions_vector[row]*matrix[row, col]
        
        result[col] = s
    


@cython.boundscheck(False) # turn off bounds-checking for entire function
@cython.wraparound(False)  # turn off negative index wrapping for entire function
@cython.cdivision(True)
def eval_split(
    np.ndarray[np.float32_t, ndim=1] vector_converted,
    np.ndarray[np.uint8_t, ndim=1] meals_indexes,
    np.ndarray[np.float32_t, ndim=1] energy_array,

    np.ndarray[np.float32_t, ndim=1] by_meal,
    np.ndarray[np.float32_t, ndim=1] target_percents,

    float split_coef
):

    cdef Py_ssize_t i
    cdef float tot_energy, tot_energy_percent, s

    for i in range(meals_indexes.shape[0]):
        by_meal[meals_indexes[i]] += energy_array[i]*vector_converted[i]

    s = 0
    for i in range(by_meal.shape[0]):
        s += by_meal[i]

    tot_energy = s
    if tot_energy == 0:
        return 0.0

    tot_energy_percent = 100.0 / tot_energy

    s = 0
    for i in range(target_percents.shape[0]):
        s += abs(target_percents[i] - by_meal[i] * tot_energy_percent)

    return split_coef * s

Having issues with cython build command

Cython version 0.29.33 Python 3.7.2 on Windows 10 system

I get this error whenever I run Cython builder command in the terminal
File "c:\python37\lib\site-packages\cythonbuilder_init.py", line 2, in
from cythonbuilder.cython_builder import cy_init, cy_clean, cy_build, cy_list, cy_interface
File "c:\python37\lib\site-packages\cythonbuilder\cython_builder.py", line 9, in
from cythonbuilder import pyigenerator
File "", line 1
(argument=)
^
SyntaxError: invalid syntax_
image

some error for first time user

great tool, thanks for working on this

I see some error, trying to run this in a fresh env.

In main.py, I need to change to "from .cli import app", which is a relative import, in order to fix a import error.

Also, coloredlogs is a dependency which is not listed.

I am using version 0.1.19

Code is not up to date with pypi

The code of this repository is not up to date with the current pypi releases. It would be nice if you could also commit the code here :)

[bug] generating pyi file decode errors

I have got this error while generating pyi file.

[cythonbuilder] [build] build error: 'gbk' codec can't decode byte 0xaf in position 1204: illegal multibyte sequence

I think the reason might be that there are some chinese characters in my code.

I have add parameter "encoding='utf-8'" to all open() function in pyigenerator.py to fix this problem.

I'm not sure if it's the only way to fix this problem, if so, please consider to add a encoding switch in cli to avoid changing the source code, thanks!

Cannot generate pyi correctly for Cython enum

for example, the following code:
cpdef enum PluginType: PY PYD
This will generate a pyi like below:
def enum PluginType: ...
But it's cannot be used in IDE.
Maybe it should generate something like this:
class PluginType: PY=... PYD=...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.