Re: help: pandas and 2d table

2024-04-13 Thread Tim Williams via Python-list
On Sat, Apr 13, 2024 at 1:10 PM Mats Wichmann via Python-list < python-list@python.org> wrote: > On 4/13/24 07:00, jak via Python-list wrote: > > doesn't Pandas have a "where" method that can do this kind of thing? Or > doesn't it match what you are looking for? Pretty sure numpy does, but >

Re: Is there a Python module to parse a date like the 'date' command in Linux?

2023-05-22 Thread Tim Williams
On Mon, May 22, 2023 at 12:41 PM Mats Wichmann wrote: > On 5/20/23 13:53, Chris Green wrote: > > I'm converting a bash script to python as it has become rather clumsy > > in bash. > > > > However I have hit a problem with converting dates, the bash script > > has:- > > > > dat=$(date --date

Re: Is npyscreen still alive?

2023-04-24 Thread Tim Daneliuk via Python-list
On 4/24/23 11:32, Grant Edwards wrote: On 2023-04-24, Grant Edwards wrote: The other big advantage of an ncurses program is that since curses support is in the std library, a curses app is simpler to distribute. Right now, the application is a single .py file you just copy to the destination

Re: Is npyscreen still alive?

2023-04-24 Thread Tim Daneliuk via Python-list
On 4/24/23 09:14, Stefan Ram wrote: Grant Edwards writes: The other big advantage of an ncurses program is that since curses support is in the std library, a curses app is simpler to distribute. IIRC curses is not in the standard library /on Windows/. I miss a platform independent

Re: Beautiful Soup - close tags more promptly?

2022-10-25 Thread Tim Delaney
of malformed input and edge cases. I use html5lib - it's fast enough for what I do, and the most likely to return results matching what the author saw when they maybe tried it in a single web browser. Tim Delaney -- https://mail.python.org/mailman/listinfo/python-list

Re: any author you find very good has written a book on Python?

2022-09-07 Thread Tim Daneliuk via Python-list
On 9/5/22 21:22, Meredith Montgomery wrote: I never read a book on Python. I'm looking for a good one now. I just searched the web for names such as Charles Petzold, but it looks like he never wrote a book on Python. I also searched for Peter Seibel, but he also never did. I also tried to

Re: Question about building Python-3.9.12 on OpenBSD 7.1

2022-06-03 Thread Tim Brazil
Thanks for the response HTH. Your comment led me to think that perhaps a "ports" dependency failed to be generated correctly. They are patched on the fly. I went back to "scratch" on fresh installation with a clean Python build. This time it worked correctly. Go figur

Question about building Python-3.9.12 on OpenBSD 7.1

2022-06-02 Thread Tim Brazil
unknown-openbsd7.1.py module under: ./build/lib.openbsd-7.1-amd64-3.9/_sysconfigdata__openbsd7_amd64-unknown-openbsd7.1.py I suspect somewhere, it's not picking up the full 7.1 version string. I am having a problem figuring it out. I kindly ask if you have any pointers on fixing it. Should I log a

Accuracy of multiprocessing.Queue.qsize before any Queue.get invocations?

2022-05-12 Thread Tim Chase
The documentation says[1] > Return the approximate size of the queue. Because of > multithreading/multiprocessing semantics, this number is not > reliable. Are there any circumstances under which it *is* reliable? Most germane, if I've added a bunch of items to the Queue, but not yet launched

No shortcut Icon on Desktop

2022-04-13 Thread Tim Deke
Dear Sir, I have successfully downloaded Python into my laptop but the shortcut icon is not appearing on the desktop. I am using Windows 10 with the PC specifications as per snap shot attached below. Can you advise what to do? Thank you Tim Deke [image: image.png] -- https://mail.python.org

[issue47121] math.isfinite() can raise exception when called on a number

2022-04-05 Thread Tim Peters
Tim Peters added the comment: I'll testify that I won't volunteer one second of my time pursuing these abstract "purity" crusades ;-) `isfinite()` et alia were added to supply functions defined by current standards to work on IEEE floating-point values. People working with f

[issue47145] Improve graphlib.TopologicalSort by removing the prepare step

2022-03-30 Thread Tim Peters
Tim Peters added the comment: I believe I'm elaborating on your "footgun". It doesn't matter to me whether we pick some scheme and document it, _if_ that scheme is incoherent, impossible to remember, error-prone, etc. That's how, e.g., regular expression syntax was designe

[issue47145] Improve graphlib.TopologicalSort by removing the prepare step

2022-03-30 Thread Tim Peters
Tim Peters added the comment: Various kinds of tasks: - "Power switch must be on." Needs to done the first time. _May_ need to be done again later (if some later task turns the power off again). Can be done any number of times without harm (beyond the expense of checking

Re: Add a method to list the current named logging levels

2022-03-30 Thread Tim Chase
On 2022-03-30 16:37, Barry wrote: > Is logging.getLevelNamesMapping() what you are looking for? Is this in some version newer than the 3.8 that comes stock on my machine? $ python3 -q >>> import logging >>> logging.getLevelNamesMapping() Traceback (most recent call last): File "",

[issue45382] platform() is not able to detect windows 11

2022-03-28 Thread Tim Golden
Tim Golden added the comment: > I don't see why the wmi module ( https://pypi.org/project/WMI/ ) can't be > used instead to get the information Well I can speak here as the author of that module and as an (occasional) core developer. The wmi module stands on the shoulderes of the p

[issue47114] random.choice and random.choices have different distributions

2022-03-24 Thread Tim Peters
Tim Peters added the comment: Definitely a duplicate, and I doubt Mark or Raymond will change their mind. One observation: while floats are not uniformly dense in [0, 1), random() results are uniformly spaced. Each is of the form I / 2**53 for an integer I in range(2**53). -- nosy

[issue47080] Use atomic groups to simplify fnmatch

2022-03-21 Thread Tim Peters
Change by Tim Peters : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.or

[issue47080] Use atomic groups to simplify fnmatch

2022-03-21 Thread Tim Peters
Tim Peters added the comment: New changeset 5c3201e146b251017cd77202015f47912ddcb980 by Tim Peters in branch 'main': bpo-47080: Use atomic groups to simplify fnmatch (GH-32029) https://github.com/python/cpython/commit/5c3201e146b251017cd77202015f47912ddcb980

[issue47080] Use atomic groups to simplify fnmatch

2022-03-21 Thread Tim Peters
Change by Tim Peters : -- keywords: +patch pull_requests: +30118 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/32029 ___ Python tracker <https://bugs.python.org/issu

[issue47080] Use atomic groups to simplify fnmatch

2022-03-20 Thread Tim Peters
New submission from Tim Peters : I added some excruciatingly obscure technical tricks to ensure that fnmatch.py's regexps can't fall into exponential-time match failures. It's hard to stop re from useless backtracking. But the new "atomic groups" make that easy instead in

[issue36457] functools.singledispatchmethod interacts poorly with subclasses

2022-03-18 Thread Tim Mitchell
Change by Tim Mitchell : Added file: https://bugs.python.org/file50689/test_sdm.py ___ Python tracker <https://bugs.python.org/issue36457> ___ ___ Python-bugs-list mailin

[issue36457] functools.singledispatchmethod interacts poorly with subclasses

2022-03-18 Thread Tim Mitchell
Tim Mitchell added the comment: I've come up with a version that does not require a base class. Seems a bit hacky as the descriptor __get__ method now modifies the class to put the dispatch table in place the first time the method is accessed. -- Added file: https://bugs.python.org

[issue36744] functools.singledispatch: Shouldn't require a positional argument if there is only one keyword argument

2022-03-17 Thread Tim Mitchell
Tim Mitchell added the comment: I would really prefer the dispatch logic remains simple and fast, rather than handle single keyword arguments. -- nosy: +Tim Mitchell2 ___ Python tracker <https://bugs.python.org/issue36

[issue47037] Build problems on Windows

2022-03-16 Thread Tim Peters
Tim Peters added the comment: Christian, yes, but only in a debug build. See Eryk Sun's message a bit above: the machinery to prevent this is already present, but isn't getting called early enough. -- ___ Python tracker <https://bugs.python.

[issue47037] Build problems on Windows

2022-03-16 Thread Tim Peters
Tim Peters added the comment: BTW, the frequency of this new failure mode appears to be vastly increased if running the debug tests with "-j0". For example, the box popping up is reliably the very first sign of life if I run this from the PCBuild directory: rt

[issue47037] Build problems on Windows

2022-03-16 Thread Tim Peters
Tim Peters added the comment: Actually, I see this ('Debug Assertion Failed!' in the same spot) every time I try to run the test suite with a debug build, starting yesterday. Didn't have time to track it down. It _appeared_ to an obscure consequence of this commit: ""&

[issue46990] Surprising list overallocation from .split()

2022-03-11 Thread Tim Peters
Tim Peters added the comment: Well, that's annoying ;-) In context, the OP was saving a list of 10 million splits. So each overallocation by a single element burned 80 million bytes of RAM. Overallocating by 7 burned 560 million bytes. Which is unusual. Usually a split result is short-lived

[issue46990] Surprising list overallocation from .split()

2022-03-11 Thread Tim Peters
Change by Tim Peters : -- type: behavior -> resource usage ___ Python tracker <https://bugs.python.org/issue46990> ___ ___ Python-bugs-list mailing list Un

[issue46990] Surprising list overallocation from .split()

2022-03-11 Thread Tim Peters
New submission from Tim Peters : When looking into a StackOverflow question about surprisingly high memory use, I stumbled into this (under 3.10.1, Win64): >>> import sys >>> s = "1 2 3 4 5".split() >>> s ['1', '2', '3', '4', '5'] >>> sys.getsiz

Re: Behavior of the for-else construct

2022-03-04 Thread Tim Chase
On 2022-03-04 11:55, Chris Angelico wrote: > In MS-DOS, it was perfectly possible to have spaces in file names DOS didn't allow space (0x20) in filenames unless you hacked it by hex-editing your filesystem (which I may have done a couple times). However it did allow you to use 0xFF in filenames

Re: Behavior of the for-else construct

2022-03-03 Thread Tim Chase
On 2022-03-04 02:02, Chris Angelico wrote: >> I want to make a little survey here. >> >> Do you find the for-else construct useful? Have you used it in >> practice? Do you even know how it works, or that there is such a >> thing in Python? > > Yes, yes, and yes-yes. It's extremely useful. Just

Re: Timezone jokes (was: All permutations from 2 lists)

2022-03-03 Thread Tim Chase
On 2022-03-03 06:27, Grant Edwards wrote: > On 2022-03-03, Chris Angelico wrote: > > Awww, I was going to make a really bad joke about timezones :) > > As opposed to all the really good jokes about timezones... ;) And here I thought you were just Trolling with timezones...

[issue46868] Improve performance of math.prod with bignums (and functools.reduce?)

2022-02-28 Thread Tim Peters
Tim Peters added the comment: > the total number of trailing 1 bits in the integers from 1 > through N inclusive is N - N.bit_count() Sorry, that's the total number of trailing 0 bits. The total number of trailing 1 bits is (N+1) - (N+1).bit

[issue46868] Improve performance of math.prod with bignums (and functools.reduce?)

2022-02-28 Thread Tim Peters
Tim Peters added the comment: About runtime, you're right. I did a ballpark "OK, if there are N incoming values, the inner loop has to go around, for each one, looking for a NULL, across a vector of at most log2(N) entries. So N * log2(N)". But, in fact, it's highly skewed towa

[issue46868] Improve performance of math.prod with bignums (and functools.reduce?)

2022-02-28 Thread Tim Peters
Tim Peters added the comment: Too abstract for me to find compelling. I suspect the title of this report referenced "math.prod with bignums" because it's the only actual concrete use case you had ;-) Here's another: math.lcm. That can benefit for the same reason as math.prod -

[issue46868] Improve performance of math.prod with bignums (and functools.reduce?)

2022-02-27 Thread Tim Peters
Tim Peters added the comment: Hi. "It's pretty good for a lot of things" is precisely what I'm questioning. Name some, and please be specific ;-) Tree reduction is very popular in the parallel processing world, for obvious reasons. But we're talking about a single t

[issue46868] Improve performance of math.prod with bignums (and functools.reduce?)

2022-02-26 Thread Tim Peters
Tim Peters added the comment: I don't know that there's a good use case for this. For floating addition, tree-based summation can greatly reduce total roundoff error, but that's not true of floating multiplication. The advantage for prod(range(2, 50001)) doesn't really stem from turning

[issue45735] Promise the long-time truth that `args=list` works

2022-02-25 Thread Tim Peters
Tim Peters added the comment: New changeset e466faa9df9a1bd377d9725de5484471bc4af8d0 by Charlie Zhao in branch 'main': bpo-45735: Promise the long-time truth that `args=list` works (GH-30982) https://github.com/python/cpython/commit/e466faa9df9a1bd377d9725de5484471bc4af8d0

[issue46812] Thread starvation with threading.Condition

2022-02-20 Thread Tim Peters
Tim Peters added the comment: Unassigning myself - I have no insight into this. I suspect the eternally contentious issue 7946 is related. -- ___ Python tracker <https://bugs.python.org/issue46

[issue46726] Thread spuriously marked dead after interrupting a join call

2022-02-13 Thread Tim Peters
Tim Peters added the comment: > It's nice that _maintain_shutdown_locks() gets > called in _stop(), but the more important call site is in > _set_tstate_lock(). I didn't have that in mind at all. What at the Python level cares whether the thread is alive? Well. is_alive() does, and

[issue46726] Thread spuriously marked dead after interrupting a join call

2022-02-13 Thread Tim Peters
Tim Peters added the comment: >> is there a bulletproof way to guarantee that `self._stop()` gets >> called if the acquire_and_release() succeeds? > I don't think it's critical. Agreed! Anything at the Python level that cares whether the thread is still

[issue46726] Thread spuriously marked dead after interrupting a join call

2022-02-12 Thread Tim Peters
Tim Peters added the comment: While bundling the lock.release() into C makes that bulletproof, is there a bulletproof way to guarantee that `self._stop()` gets called if the acquire_and_release() succeeds? Offhand, I don't see a reason for why that isn't just as vulnerable to getting

[issue46726] Thread spuriously marked dead after interrupting a join call

2022-02-12 Thread Tim Peters
Tim Peters added the comment: > Maybe add an `acquire_and_release()` method Bingo - that should do the trick, in an "obviously correct" way. Of course it's of limited applicability, but fine by me. Will you open a PR w

[issue46726] Thread spuriously marked dead after interrupting a join call

2022-02-12 Thread Tim Peters
Tim Peters added the comment: Na, we've been doing excruciatingly clever stuff to deal with thread shutdown for decades, and it always proves to be wrong in some way. Even if code like except: if lock.locked(): lock.release() self._stop() raise did work as hoped

[issue46726] Thread spuriously marked dead after interrupting a join call

2022-02-12 Thread Tim Peters
Tim Peters added the comment: Eryk, I don't think that workaround is solid on Windows in all cases. For example, if .join() is called with a timeout, the same timeout is passed to lock.acquire(block, timeout). If the acquire() in fact times out, but the store to the `acquired` variable

[issue46639] Ceil division with math.ceildiv

2022-02-07 Thread Tim Peters
Tim Peters added the comment: The `decimal` module intends to be a faithful implementation of external standards. The identity x == (x // y) * y + x % y isn't a minor detail, it's the dog on which all else is but a tail ;-) It's why Guido picked -7 // 4 = -2 in Python[1]. That's really

[issue46667] SequenceMatcher & autojunk - false negative

2022-02-07 Thread Tim Peters
Tim Peters added the comment: We can't change defaults without superb reason - Python has millions of users, and changing the output of code "that works" is almost always a non-starter. Improvements to the docs are welcome. In your example, try running this code after using aut

[issue46667] SequenceMatcher & autojunk - false negative

2022-02-06 Thread Tim Peters
Tim Peters added the comment: SequenceMatcher looks for the longest _contiguous_ match. "UNIQUESTRING" isn't the longest by far when autojunk is False, but is the longest when autojunk is True. All those bpopular characters then effectively prevent finding a longer match th

[issue46639] Ceil division with math.ceildiv

2022-02-05 Thread Tim Peters
Tim Peters added the comment: I expect "obviousness" is mostly driven by background here. You know, e.g., that ceil(x) = -floor(-x) for any real x, and the application to integer division is just a special case of that. I expect programmers mostly don't know that, though. And Pyt

[issue46187] Optionally support rounding for math.isqrt()

2022-02-05 Thread Tim Peters
Tim Peters added the comment: I've been keeping my eyes open. The only mariginally relevant thing I've noticed is Hart's "one line factoring" method: http://wrap.warwick.ac.uk/54707/1/WRAP_Hart_S1446788712000146a.pdf That wants the _ceiling_ of the square root. And in another plac

[issue46639] Ceil division with math.ceildiv

2022-02-05 Thread Tim Peters
Tim Peters added the comment: GMP's mpz has 18 functions of this form. These are the 6 "ceiling" flavors: c_divmod c_div c_mod c_divmod_2exp c_div_2exp c_mod_2exp The suggestion here is for c_div. There are 6 more for floor rounding (with prefix "f_" instead of &

[issue46627] Regex hangs indefinitely

2022-02-03 Thread Tim Peters
Tim Peters added the comment: Introducing some kind of optional timeout is too involved to just drop in without significant discussion and design effort first. If you want to pursue this, please bring it up on the python-ideas mailing list. My first take: it wouldn't really help, because

[issue46615] Use-after-free by mutating set during set operations

2022-02-03 Thread Tim Peters
Tim Peters added the comment: Raised the priority back to normal. I agree with Dennis's observation that PyDict_Next is safe, provided it's used as intended: it returns borrowed references, but to things that absolutely are legitimate at the time. In the presence of mutations, *what

[issue46618] Exponent operator(**) interpreter issue

2022-02-02 Thread Tim Peters
Tim Peters added the comment: Exponentiation has higher precedence (binds more tightly) than unary minus, so the expression groups as -(2**2). Virtually all computer languages (those that _have_ an exponentiation operator) do the same. For example, here from wxMaxima: (%i1) -2**2; (%o1) -4

[issue46558] Quadratic time internal base conversions

2022-01-30 Thread Tim Peters
Tim Peters added the comment: > todecstr treats it as an "input" conversion instead, ... Worth pointing this out since it doesn't seem widely known: "input" base conversions are _generally_ faster than "output" ones. Working in the destination base (or a

[issue46558] Quadratic time internal base conversions

2022-01-30 Thread Tim Peters
Tim Peters added the comment: The factorial of a million is much smaller than the case I was looking at. Here are rough timings on my box, for computing the decimal string from the bigint (and, yes, they all return the same string): native: 475seconds (about 8 minutes) numeral: 22.3

[issue46558] Quadratic time internal base conversions

2022-01-29 Thread Tim Peters
Tim Peters added the comment: Addendum: the "native" time (for built in str(a)) in the msg above turned out to be over 3 hours and 50 minutes. -- ___ Python tracker <https://bugs.python.o

[issue3451] Asymptotically faster divmod and str(long)

2022-01-29 Thread Tim Peters
Tim Peters added the comment: Ha! This will never die. More discussion in bpo-46558. Ya, I already closed it, but don't want to. I opened it to begin with to record an int->str method that doesn't use division, so it didn't really belong on this report. What if we _didn't_ conv

[issue46558] Quadratic time internal base conversions

2022-01-29 Thread Tim Peters
Tim Peters added the comment: The test case here is a = (1 << 1) - 1, a solid string of 100 million 1 bits. The goal is to convert to a decimal string. Methods: native: str(a) numeral: the Python numeral() function from bpo-3451's div.py after adapting to use the

[issue46558] Quadratic time internal base conversions

2022-01-27 Thread Tim Peters
Tim Peters added the comment: Changed the code so that inner() only references one of the O(log log n) powers of 2 we actually precomputed (it could get lost before if `lo` was non-zero but within `n` had at least one leading zero bit - now we _pass_ the conceptual width instead

[issue46558] Quadratic time internal base conversions

2022-01-27 Thread Tim Peters
Tim Peters added the comment: Dennis, partly, although that was more aimed at speeding division, while the approach here doesn't use division at all. However, thinking about it, the implementation I attached doesn't actually for many cases (it doesn't build as much of the power tree

[issue46558] Quadratic time internal base conversions

2022-01-27 Thread Tim Peters
New submission from Tim Peters : Our internal base conversion algorithms between power-of-2 and non-power-of-2 bases are quadratic time, and that's been annoying forever ;-) This applies to int<->str and int<->decimal.Decimal conversions. Sometimes the conversion is implici

[issue46407] optimizing `1 << n` or `2 ** n` and modulo-only operations

2022-01-27 Thread Tim Peters
Tim Peters added the comment: I only merged the split-off PR that added new remainder-only functions. Still thinking about the `1 << n` and `2**n` one. -- assignee: -> tim.peters resolution: -> fixed stage: patch review -> resolved status:

[issue46407] optimizing `1 << n` or `2 ** n` and modulo-only operations

2022-01-27 Thread Tim Peters
Tim Peters added the comment: New changeset f10dafc430279b4e6cf5b981ae3d1d76e8f431ad by Crowthebird in branch 'main': bpo-46407: Optimizing some modulo operations (GH-30653) https://github.com/python/cpython/commit/f10dafc430279b4e6cf5b981ae3d1d76e8f431ad

[issue45735] Promise the long-time truth that `args=list` works

2022-01-26 Thread Tim Peters
Tim Peters added the comment: Charliz, please do! I have no idea why Raymond just stopped. He even deleted his initial message here, saying "I relied on this for many years. So, yet it would be nice to guarantee it :-)". Best I can tell, nothing has changed: lots of people h

[issue46524] test_peg_generator takes 8 minutes on Windows

2022-01-25 Thread Tim Peters
Tim Peters added the comment: As a general thing, I expect people on Windows always run the tests with multiple processes. In which case it would be generally helpful to start the longest-running tests first. As is, because of its late-in-the-alphabet name, "test_peg_generator" ge

[issue46524] test_peg_generator takes 8 minutes on Windows

2022-01-25 Thread Tim Peters
Change by Tim Peters : -- nosy: +tim.peters ___ Python tracker <https://bugs.python.org/issue46524> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46504] Faster code for trial quotient in x_divrem

2022-01-24 Thread Tim Peters
Change by Tim Peters : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.or

[issue46504] Faster code for trial quotient in x_divrem

2022-01-24 Thread Tim Peters
Tim Peters added the comment: New changeset 7c26472d09548905d8c158b26b6a2b12de6cdc32 by Tim Peters in branch 'main': bpo-46504: faster code for trial quotient in x_divrem() (GH-30856) https://github.com/python/cpython/commit/7c26472d09548905d8c158b26b6a2b12de6cdc32

[issue46406] optimize int division

2022-01-24 Thread Tim Peters
Tim Peters added the comment: New changeset 7c26472d09548905d8c158b26b6a2b12de6cdc32 by Tim Peters in branch 'main': bpo-46504: faster code for trial quotient in x_divrem() (GH-30856) https://github.com/python/cpython/commit/7c26472d09548905d8c158b26b6a2b12de6cdc32

[issue46504] Faster code for trial quotient in x_divrem

2022-01-24 Thread Tim Peters
Change by Tim Peters : -- assignee: -> tim.peters nosy: +gregory.p.smith, mark.dickinson ___ Python tracker <https://bugs.python.org/issue46504> ___ ___ Py

[issue46504] Faster code for trial quotient in x_divrem

2022-01-24 Thread Tim Peters
Change by Tim Peters : -- keywords: +patch pull_requests: +29037 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/30856 ___ Python tracker <https://bugs.python.org/issu

[issue46406] optimize int division

2022-01-24 Thread Tim Peters
Change by Tim Peters : -- pull_requests: +29038 pull_request: https://github.com/python/cpython/pull/30856 ___ Python tracker <https://bugs.python.org/issue46

[issue46504] Faster code for trial quotient in x_divrem

2022-01-24 Thread Tim Peters
Change by Tim Peters : -- versions: +Python 3.11 ___ Python tracker <https://bugs.python.org/issue46504> ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46504] Faster code for trial quotient in x_divrem

2022-01-24 Thread Tim Peters
New submission from Tim Peters : x_divrem1() was recently (bpo-46406) changed to generate faster code for division, essentially nudging optimizing compilers into recognizing that modern processors compute the quotient and remainder with a single machine instruction. The same can be done

[issue46488] listsort.txt wrongly assumes you cannot calculate leading zeros in O(1) time.

2022-01-23 Thread Tim Peters
Tim Peters added the comment: For any fixed width integer type, the worst case of the dead simple loop (all bits are zero) is a fixed upper bound. So you don't mean "constant bounded" either. You mean something more like "clever C code that usually runs faster than the obvi

[issue37295] Possible optimizations for math.comb()

2022-01-23 Thread Tim Peters
Tim Peters added the comment: OK, here's the last version I had. Preconditions are that d > 0, n > 0, and n % d == 0. This version tries to use the narrowest possible integers on each step. The lowermost `good_bits` of dinv at the start of the loop are correct already. Taking o

[issue46488] listsort.txt wrongly assumes you cannot calculate leading zeros in O(1) time.

2022-01-23 Thread Tim Peters
Tim Peters added the comment: I'm not inclined to change anything here. It's a trivial point, and by "primitive" I had in mind a dedicated hardware instruction, blazing fast. Yes, I was aware of long-winded ways of doing it for specific fixed integer widths. But that's not what `O

[issue37295] Possible optimizations for math.comb()

2022-01-22 Thread Tim Peters
Tim Peters added the comment: Ya, I don't expect anyone will check in a change without doing comparative timings in C first. Not worried about that. I'd be happy to declare victory and move on at this point ;-) But that's me. Near the start of this, I noted that we just won't compete

[issue46071] Graphlib documentation (edge direction)

2022-01-21 Thread Tim Peters
Tim Peters added the comment: > I know that there are many different ways to represent > a graph, but your graph format *is just plain wrong.* Yet when I offered to support an option to support the graph format you insist is uniquely "right", you poo-poo'ed the idea. So w

[issue46071] Graphlib documentation (edge direction)

2022-01-21 Thread Tim Peters
Tim Peters added the comment: Perhaps you've overlooking something so obvious to the module authors that I haven't thought to mention it? The purpose here is to compute a linear order. Now not even you ;-) can pretend to be confused about what "predecessor" and "successor&qu

[issue46071] Graphlib documentation (edge direction)

2022-01-21 Thread Tim Peters
Tim Peters added the comment: Now you may be getting somewhere ;-) Complaining about the docs wasn't getting traction because they're using standard terminology with the standard meanings, and tell the plain truth about what the class requires and delivers. You wish it required something

[issue46071] Graphlib documentation (edge direction)

2022-01-20 Thread Tim Peters
Tim Peters added the comment: >> the meanings of "predecessor" and "successor" are >> universally agreed upon > I disagree. I can post literally hundreds of citations that all agree: in u -> v, u is a direct predecessor of v, and v is a dir

[issue46071] Graphlib documentation (edge direction)

2022-01-20 Thread Tim Peters
Tim Peters added the comment: I think you should give up on this. But suit yourself ;-) Exactly the same information is conveyed whether representing a graph by successor or predecessor dicts. Some operations are more convenient in one representation than the other, but each is easily

[issue46071] Graphlib documentation (edge direction)

2022-01-20 Thread Tim Peters
Tim Peters added the comment: I'm going to leave this to Pablo - adding the `graph` argument was his idea ;-) It would, I think, have been better if this argument had been named, say, "preds" instead of "graph". The docs, to my eyes, are entirely clear about that `graph`

[issue46071] Graphlib documentation (edge direction)

2022-01-20 Thread Tim Peters
Tim Peters added the comment: For the purpose of topological sorting, yes, it's by far most natural to give, for each node, the collection of that node's predecessors. And that's the way topsort applications typically collect their data to begin with, like, "here, for each recipe, is a

[issue37295] Possible optimizations for math.comb()

2022-01-14 Thread Tim Peters
Tim Peters added the comment: Another trick, building on the last one: computing factorial(k) isn't cheap, in time or space, and neither is dividing by it. But we know it will entirely cancel out. Indeed, for each outer loop iteration, prod(p) is divisible by the current k. But, unlike

[issue37295] Possible optimizations for math.comb()

2022-01-13 Thread Tim Peters
Tim Peters added the comment: I was thinking about comb(100, 50) The simple "* --n / ++k" loop does 499,999 each of multiplication and division, and in all instances the second operand is a single Python digit. Cheap as can be. In contrast, despite that it short-ci

[issue46020] Optimize long_pow for the common case

2022-01-12 Thread Tim Peters

[issue37295] Possible optimizations for math.comb()

2022-01-12 Thread Tim Peters
Tim Peters added the comment: A feature of the current code is that, while the recursion tree can be very wide, it's not tall, with max depth proportional to the log of k. But it's proportional to k in the proposal (the C(n-j, k-j) term's second argument goes down by at most 20 per

[issue37295] Possible optimizations for math.comb()

2022-01-11 Thread Tim Peters
Tim Peters added the comment: Just noting that comb_pole.py requires a development version of Python to run (under all released versions, a byteorder argument is required for int.{to, from}_byte() calls). -- ___ Python tracker <ht

[issue46020] Optimize long_pow for the common case

2022-01-11 Thread Tim Peters
Tim Peters added the comment: GH_30555 helps a bit by leaving the giant-exponent table of small odd powers as uninitialized stack trash unless it's actually used. -- ___ Python tracker <https://bugs.python.org/issue46

[issue46020] Optimize long_pow for the common case

2022-01-11 Thread Tim Peters
Change by Tim Peters : -- keywords: +patch pull_requests: +28756 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30555 ___ Python tracker <https://bugs.python.org/issu

[issue46235] Do all ref-counting at once for sequence multiplication

2022-01-07 Thread Tim Peters
Change by Tim Peters : -- assignee: -> Dennis Sweeney resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python

[issue46235] Do all ref-counting at once for sequence multiplication

2022-01-07 Thread Tim Peters
Tim Peters added the comment: New changeset ad1d5908ada171eff768291371a80022bfad4f04 by Dennis Sweeney in branch 'main': bpo-46235: Do all ref-counting at once during list/tuple multiplication (GH-30346) https://github.com/python/cpython/commit/ad1d5908ada171eff768291371a80022bfad4f04

[issue46187] Optionally support rounding for math.isqrt()

2022-01-04 Thread Tim Peters
Tim Peters added the comment: > Is > > i, rem = isqrt_rem(n) > i + (rem != 0) > > better than > > (isqrt(n<<2) + 1) >> 1 > > or > > n and isqrt(n-1) + 1 > > ? Define "better"? The first way is by far the most obvious of

[issue46233] Minor speedup for bigint squaring

2022-01-03 Thread Tim Peters
Change by Tim Peters : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker <https://bugs.python.or

[issue46233] Minor speedup for bigint squaring

2022-01-03 Thread Tim Peters
Tim Peters added the comment: New changeset 3aa5242b54b0627293d95cfb4a26b2f917f667be by Tim Peters in branch 'main': bpo-46233: Minor speedup for bigint squaring (GH-30345) https://github.com/python/cpython/commit/3aa5242b54b0627293d95cfb4a26b2f917f667be

[issue46187] Optionally support rounding for math.isqrt()

2022-01-03 Thread Tim Peters
Tim Peters added the comment: I've made several good-faith efforts to find any hint of demand for rounded isqrt on the web; I've found no direct support for it in other languages/environments(*); and the one use case you presented isn't compelling. Building static tables to help implement

[issue46020] Optimize long_pow for the common case

2022-01-03 Thread Tim Peters
Tim Peters added the comment: I was suprised that https://bugs.python.org/issue44376 managed to get i**2 to within a factor of 2 of i*i's speed. The overheads of running long_pow() at all are high! Don't overlook that initialization of stack variables at the start, like PyLongObject

  1   2   3   4   5   6   7   8   9   10   >