« first day (4794 days earlier)      last day (372 days later) » 

05:42
helped me a lot 2 years ago when I wanted to know Python.
@roganjosh uh, never used numba since I thought it needed a GPU, but I guess this works with CPU too...Nice
tried it on my end and it does give a decent speed improvement
 
6 hours later…
11:41
Is it possible to generate class attributes based on type annotations so that they can be accessed in the class body? I.e. make this code print some arbitrary value instead of crashing
class Demo(MagicBaseClass):
    foo: int

    print(foo)
12:13
Yeah, MagicBaseClass should be able to inspect the __annotations__ and populate the class namespace with it..
You'll probably need a metaclass.
Just figured it out
class MagicDict(dict):
    def __missing__(self, key):
        return 12345

class MagicMetaClass(type):
    @classmethod
    def __prepare__(cls, name, bases, **kwargs):
        return MagicDict()

class Demo(metaclass=MagicMetaClass):
    foo: int
    print(foo)
Could've saved 4 lines by using a defaultdict. Oh well
If you want you can actually access all annotations up to that point:
class AnnotationDefaultNamespace(dict[str, "Any"]):
    def __getitem__(self, __key: str) -> "Any":
        try:
            return super().__getitem__(__key)
        except KeyError:
            tp = super().__getitem__("__annotations__")[__key]
            self[__key] = tp()
            return super().__getitem__(__key)

class MagicMeta(type):
    @classmethod
    def __prepare__(mcs, name, bases, **kwds):
        return AnnotationDefaultNamespace()
This will make print(foo) in your Demo print 0 automatically.
I can already see the bug reports, "Code doesn't work if you don't write the type annotation at the top of the class" :D
Don't think there's anything I can do about that. I thought the annotations would be populated all at once, but nope, it assigns an empty dict and fills it up 1-by-1
I didn't realize annotations were evaluated just like any other statement. That's funky
class Huh:
    if False:
        foo: int
print(Huh.__annotations__)  # {}
 
3 hours later…
15:15
does anyone plan on unfreezing the room chat.stackoverflow.com/rooms/225306/advent-of-code? I think the first puzzle is out
15:54
@DimitrisPapageorgiou Google
16:09
I already addressed this @GaryOak. There's little benefit to saying "google" for multiple answers.
Google Domains, I meant...
16:56
Is there a meaningful way to talk about time complexity of an algorithm and the execution of the algorithm? For example, I'm pretty happy with my implementation for AOC day 1 in terms of the intent, but my execution of that intent is probably diabolical. I'm again trying it in Rust and I no doubt have more assignments than actually necessary if I just knew how to chain things together better
I guess you could just call it "amortised" if you have unnecessary heap allocations everywhere since the principle is the same but, well, that doesn't tell me anything about whether I could avoid a lot of the amortised cost
Is it possible to post a question from another stackexchange channel here? The question concerns Python but at the same time also statistics
You can try ... ask your question and see if anyone answers.
@Horiatiki it is, but please be aware of the room rules particularly in regard to the question being > 48 hours old first
Ok i understand. Well! Then I'll wait 48, it's only been 24. Thanks
However, is there a "statistics/mathematics" chat room and a "datascience" chat room? The math one seems to exist, but I can't find it
17:12
@roganjosh If I'm reading you are right, you are wondering about the constant factor of your implementation. The algorithm is going to be some O(n^x) thingy, but the constant factor is the c * n^x that you get in real life.
If your question is this then we will really struggle on any site, I think. Whilst I appreciate your headings to try break it down, you're probably just packing too much noise into the problem itself. For technical questions, my eyes will glaze over on big blocks of text
@MisterMiyagi something like that, yeah. For python: I might have an algorithm that works in O(N) time, but I choose to just .deepcopy() every single object for the fun of it
I'm trivialising, but the point is that the overhead of that implementation starts to far outweigh the actual algorithm itself
@roganjosh No, that's not the question. I've lost hope with this question now. The question I was referring to is another. I'll post it tomorrow here in chat
@Horiatiki If it has no answers, I'm happy for you to post a link to it here on this occasion. The room is quiet and there might be feedback on your question style to help garner responses, even if nobody here can answer it themselves
18:05
The Advent of Code room has been defrosted: chat.stackoverflow.com/rooms/225306/advent-of-code
4
 
1 hour later…
19:29
@roganjosh Python's list.append has two internal algorithms: 1. creating a new internal array with a larger size and copying the data across -- O(n), and 2. adding the entry to the array -- O(1). Because Python overprevisions the array to a great extent most of the time the algorithm is O(1). So the complexity of list.append is O(n), with an amortized (expected) of O(1). If you're doing a bunch of needles deep copys (O(n)) then amortized isn't the word you would want to use.
That's actually the opposite of what I've come to understand of "amortized"
My understanding was "this is O(N) but btw there are blips when we need to find new space on the heap to copy it over with extra leg room"
The list example would be "this is O(1) but btw there are blips when we need to find new space [...] to copy it over O(n)"
So "amortised" does sweep that complexity under the rug, though?
Only if you can form a logical argument where the overhead isn't dominant.
19:45
I think that answers my question. I asked for a "meaningful" way to explain this overhead, but if there's no accepted term then I will have to argue it (to myself, not only others) on its base principles. Thanks
Were you looking for "asymptotic?"
Nope. That would converge on the same output as I have understood from Big-O. What I was more interested in is some formal principal to argue against poor implementation. Basically "You've implemented the Smith algorithm fantastically, but have you looked at all the overhead in language fundamentals (like copying to the heap) to achieve it?"
20:11
I can't think of a word. I'd probably just describe the difference between 'perfect' and 'actual'

« first day (4794 days earlier)      last day (372 days later) »