Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3751810
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:07:37+00:00 2026-05-19T09:07:37+00:00

I’m doing some loop-intensive calculations and converted the code into Cython. I did profiling

  • 0

I’m doing some loop-intensive calculations and converted the code into Cython.
I did profiling with cython -a option, and inspected the .html file, and it seems whenever I do the float division, there is somewhat yellow line and it does something like the following:

if (unlikely(__pyx_t_37 == 0)) {
        PyErr_Format(PyExc_ZeroDivisionError, "float division");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }

I guess it is for the cases where the divider is 0. I am using a constant for that and there is no probability that the divider is 0, and I was wondering if there is anything I can do to make it faster.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T09:07:37+00:00Added an answer on May 19, 2026 at 9:07 am

    You need to add @cython.cdivision(True) to avoid the exception checking.

    import cython
    
    cdef double pydivision():
      cdef int i
      cdef double k, j
      k = 2.0
      j = 0.0
      for i in range(10):
        j += i/k
      # Generated code: Python exception checking
      # /* "checksum.pyx":9
      # *   j = 0.0
      # *   for i in range(10):
      # *     j += i/k             # <<<<<<<<<<<<<<
      # *   return j
      # *
      # */
      #    if (unlikely(__pyx_v_k == 0)) {
      #      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      #      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #    }
      #    __pyx_v_j = (__pyx_v_j + (__pyx_v_i / __pyx_v_k));
      #  }
      return j
    
    #This decorator works wonders
    @cython.cdivision(True)
    cdef double cdivision():
      cdef int i
      cdef double k, j
      k = 2.0
      j = 0.0
      for i in range(10):
        j += i/k
      # Generated code: no exception checking
      # /* "checksum.pyx":20
      # *   j = 0.0
      # *   for i in range(10):
      # *     j += i/k             # <<<<<<<<<<<<<<
      # *   return j
      # *
      # */
      #    __pyx_v_j = (__pyx_v_j + (__pyx_v_i / __pyx_v_k));
      #  }
      return j
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.