Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: numpy.dot() result different with classic computation for large-size arrays
Post: RE: numpy.dot() result different with classic comp...

The quick answer is that numpy.dot calculates the using the type in the construction of arrary.array. "q" represents a 64-bit signed integer which overflows at 2**63-1. This eventually overflows and t...
casevh General Coding Help 5 151 Jan-25-2022, 08:09 AM
    Thread: efficiency of CPython expression comppilation
Post: RE: efficiency of CPython expression comppilation

Python does perform constant expression optimizations. The dis (short for disassemble) module can show it in action. >>> def f(x): ... return x/(7*24*60*60) ... >>> import dis &g...
casevh News and Discussions 1 133 Jan-09-2022, 06:03 AM
    Thread: f-strings round float down too much
Post: RE: f-strings round float down too much

You are correct. My memory is a bit hazy. Looking at this again, I'm not exactly sure what is the bug....
casevh News and Discussions 5 344 Dec-29-2021, 04:13 PM
    Thread: f-strings round float down too much
Post: RE: f-strings round float down too much

There are at least two different strategies for representing 64-bit IEEE floating point values as a decimal string that round-trip. In other words, they guarantee that x == float(str(x)). One choice i...
casevh News and Discussions 5 344 Dec-29-2021, 07:25 AM
    Thread: unexpected decimal.InvalidOperation
Post: RE: unexpected decimal.InvalidOperation

The behavior you are seeing is part of IEEE-754 standard. The easiest chart I found is in the "Special Operations" section of https://steve.hollasch.net/cgindex/codin...float.html. The specification...
casevh News and Discussions 2 237 Dec-25-2021, 07:53 AM
    Thread: smallest float that can increment a given value
Post: RE: smallest float that can increment a given valu...

(Dec-11-2021, 06:35 PM)snippsat Wrote: (Dec-11-2021, 06:05 PM)Skaperen Wrote: what would you pick for a name?There is hint in his post,as he already has chosen names in gmpy2. Also hi is the autho...
casevh News and Discussions 7 449 Dec-11-2021, 10:22 PM
    Thread: smallest float that can increment a given value
Post: RE: smallest float that can increment a given valu...

sudo apt install libmpc-devThat will install the GMP, MPFR, and MPC libraries. You can then compile from source. Or if you are using a version of Python distributed by Ubuntu, you can use sudo apt i...
casevh News and Discussions 7 449 Dec-11-2021, 10:08 PM
    Thread: smallest float that can increment a given value
Post: RE: smallest float that can increment a given valu...

Not exactly, but the math module provides the function nextafter(x,y) that returns the next floating-point value after x towards y. >>> math.nextafter(12,0) # The next float towards 0. 11.99...
casevh News and Discussions 7 449 Dec-11-2021, 05:32 AM
    Thread: shouldn't this raise an exception?
Post: RE: shouldn't this raise an exception?

>>> from decimal import * >>> getcontext() Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999, capitals=1, clamp=0, flags=[], traps=[InvalidOperation, DivisionByZer...
casevh News and Discussions 3 1,007 Dec-08-2021, 05:01 AM
    Thread: who is Barry?
Post: RE: who is Barry?

Barry was one of the early users of Python and he is still involved with Python. You might want to look at PEP 0401 ( https://www.python.org/dev/peps/pep-0401/ ).
casevh Bar 7 662 Nov-15-2021, 11:01 PM
    Thread: Calculate the Euler Number with more decimal places
Post: RE: Calculate the Euler Number with more decimal p...

(Oct-22-2021, 12:17 AM)Pedroski55 Wrote: Thanks for your replies! I use Ubuntu 20.04 I only tried to install gmpy2 using pip. I'm not very clear about installing from source, I never do that, but...
casevh General Coding Help 10 1,244 Oct-31-2021, 03:46 AM
    Thread: Pass by object reference when does it behave like pass by value or reference?
Post: RE: Pass by object reference when does it behave l...

The Python interpreter only comprehends pass by object reference. Whether a new object is returned (kind of, but not really, like pass by value) or an existing object is modified (kind of, but not rea...
casevh General Coding Help 2 1,240 Sep-07-2020, 06:05 AM
    Thread: system-wide unique incrementing string or number
Post: RE: system-wide unique incrementing string or numb...

I would look at time.monotonic() and some related functions. They are designed to monotonically increase even if NTP is used to adjust the time. I don't know how they behave after a system reboot if t...
casevh News and Discussions 11 1,938 Jul-07-2020, 07:05 PM
    Thread: time complexity of int
Post: RE: time complexity of int

Python does use an improved algorithm for squaring large numbers. The improvement just decreases the constant so the time complexity doesn't change. The improvement is measurable. a is 1232 bits long...
casevh News and Discussions 6 1,381 Jul-05-2020, 03:03 PM
    Thread: time complexity of int
Post: RE: time complexity of int

Yes, comparison is also O(n).
casevh News and Discussions 6 1,381 Jul-05-2020, 05:06 AM
    Thread: time complexity of int
Post: RE: time complexity of int

Assume n is length of the number in bits and let's use ^ for exponentiation. Addition and subtraction are O(n). Multiplication uses the Karatsuba algorithm that is O(n^1.585) instead of the classica...
casevh News and Discussions 6 1,381 Jul-04-2020, 08:28 PM
    Thread: PyArray_SimpleNew gives "ValueError: array is too big; for 3-cubed array
Post: RE: PyArray_SimpleNew gives "ValueError: array is ...

Have you tried declaring dims[] as "npy_intp dims[3];"? casevh
casevh General Coding Help 1 1,827 Nov-30-2019, 05:02 AM
    Thread: Python C API - Issue with string as arugments
Post: RE: Python C API - Issue with string as arugments

Since you haven't provided enough source code, I can only make some general comments. How do you create pTuple? You aren't checking the return value of of PyTuple_SetItem() or Py_BuildValue() or any...
casevh General Coding Help 2 1,463 Nov-30-2019, 04:53 AM
    Thread: Embedded Python PyObject_CallObject function
Post: RE: Embedded Python PyObject_CallObject function

A Python function always returns something. If the function returns via a bare return statement, it actually returns None. From the interactive prompt, return values of None are not shown. >>&g...
casevh General Coding Help 1 1,201 Nov-27-2019, 01:50 AM
    Thread: Anaconda Spyder erratically reset by distutils C extension
Post: RE: Anaconda Spyder erratically reset by distutils...

I think the issue is with your use of PyArg_ParseTuple. The command O! returns a borrowed reference via matin. You are returning the borrowed reference without incrementing it. Untested... static Py...
casevh General Coding Help 4 1,255 Nov-26-2019, 09:43 PM

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020