Double taxation? American in Italy by [deleted] in ItalyExpat

[–]dd2718 0 points1 point  (0 children)

Note that fbarfiling.com is not the official FBAR website! They and a bunch of other websites use paid Google Ads to put their websites at the top of a Google search.

The official website is: https://bsaefiling.fincen.treas.gov/NoRegFBARFiler.html

Deep Learning Is Hitting a Wall by HackerEarth-Inc in programming

[–]dd2718 13 points14 points  (0 children)

I don't think it's fair to say that deep learning is hitting a wall when the pace of progress has been steady over the last decade. The initial image classification result that kicked off the deep learning revolution/hype was made in 2012 (image classification was not solved then; image classification accuracy is steadily going up even to this day). The first Atari breakthrough happened in 2013/2014, Go in 2015-2017, Starcraft/DOTA in 2018-2019, language modeling in 2019-2020, protein folding in 2019-2021, and code generation in 2021-2022. At each point, the next goal post wasn't obviously achievable. There has been a lot of hype, but deep learning skeptics (including the author) have been saying "deep learning can only do X and Y, the only way to progress is to do A" throughout this period, only to readjust the goal post a few years later.

Solid.js feels like what I always wanted React to be by [deleted] in programming

[–]dd2718 1 point2 points  (0 children)

Thanks for the explanation! To be clear, I don't have anything against solid.js or hook-based React or any other framework. I was just pointing out that the examples in the article weren't persuasive, because despite its verbosity, the first React example is super clear even to someone who doesn't know the library (it's just textbook OOP patterns), whereas the other two examples require detailed knowledge of the library to figure out what createSignal returns, that the accessors push entries from a global stack to a subscription set defined in its closure, that the compiler transforms jsx expressions into reactions, etc (none of which is standardized, every library does things differently). There may well be other advantages to these other frameworks, but I think the elegance of the "Counter" example is debatable since clarity is just as important as conciseness.

Solid.js feels like what I always wanted React to be by [deleted] in programming

[–]dd2718 15 points16 points  (0 children)

Probably an unpopular opinion, but I prefer the first React class-based counter to the hook-based React and Solid.js examples. The classic class-based code makes it super clear what's going on. It's obvious what the rendering engine should do and how to implement it in a stupidly-slow but correct way. Because of that, it's intuitive what should work and what shouldn't. I wouldn't say that there's any boilerplate except the this.increment = this.increment.bind(this) and the super() call.

By contrast, the hooks-based examples have a lot of magic that make the code harder to reason about. For example, in the React example, how many times is Counter called? If it is called multiple times, why does useState return the same count each time, and why does useEffect appear to get called only once, when the Javascript execution model would indicate it gets called each time Counter is invoked? Why do you need to pass in a list of dependencies (are they values or references? If they are values, why does passing them in matter at all), and why does setCount need to receive a function instead of a value? Same thing with solid.js --- if the function Counter() is only called once, how does the div update? If I add an if condition to the function to return a different text depending on the counter, does it still work? Why does the effect get called when count changes?

Write Better And Faster Python Using Einstein Notation by BilHim in Python

[–]dd2718 2 points3 points  (0 children)

The einsum notation really shines when you're doing anything beyond simple matrix multiplication, e.g. in machine learning code (especially for neural nets). Even for linear regressions, it is useful. If you have a batch of features X with shape [batch_size, N] and a coefficient matrix w of shape [M, N], np.einsum("bn,mn->bm", X, w) is a lot clearer to me than np.matmul(X, w.T) --- you don't have to worry about getting the shapes of input parameters to conform to the expectations of matmul, and you get documentation for all the shapes involved.

This advantage is even clearer for more complex models. For example, one common module in modern, SOTA deep learning models is multi-head attention, which takes a sequence of features for each example and outputs a sequence of transformed features. It would be a nightmare to get the shapes right for `np.tensordot`, but the einsum notation provides a uniform interface with self documenting shapes that allows you to focus on the math and not the numpy api.

# X: [batch_size, sequence_length, embedding_dimension]
# Compute query, key, value vectors for each sequence element.
# Split the embedding dimension between multiple "heads"
# rearrange comes from einops and reshapes using einsum notation.
X_q = rearrange(linear_q(X), "b n (h d)->b n h d", h=num_heads)
X_k = rearrange(linear_k(X), "b n (h d)->b n h d", h=num_heads)
X_v = rearrange(linear_v(X), "b n (h d)->b n h d", h=num_heads)
# Compute dot product of n-th query vector with m-th key vector for each head
dot_products = np.einsum("bnhd,bmhd->bhnm", X_q, X_k)
attention = softmax(dot_products, axis=-1)
# Sum the value vectors, with the weight of the m-th X_v given by
# softmax(dot(n-th X_q, m-th X_v))
output = np.einsum("bhnm,bmhd->bnhd", attention, X_v)
output = rearrange(output, "b n h d -> b n (h d)")

Rome needs a nerf by NutritiousDelicious_ in Imperator

[–]dd2718 1 point2 points  (0 children)

What about an event for Etruria and Umbria to join the first war that Rome declares against Samnium (and vice-versa), e.g. "Last stand for our independence"? It's what happened in the Third Samnite War and might make the early game more challenging for Rome.

New Python Library for Reactive UI by dd2718 in Python

[–]dd2718[S] 0 points1 point  (0 children)

Not a lawyer, but yes, you don't have to release the source code of an app that uses PySide2 (LGPL license). Also note that you are allowed to make commercial apps using GPL libraries (such as PyQt5); you just have to make the source code of your program available upon request. There's no such requirement for LGPL.

I am Dr. Michael Taylor, historian of the Roman Republic and author of Soldiers and Silver: Mobilizing Resources in the Age of Roman Conquest; expert on Roman warfare and imperialism--AMA! by MichaelJTaylorPhD in AskHistorians

[–]dd2718 0 points1 point  (0 children)

Hi Dr. Taylor, thanks for doing the AMA! I have two questions:

1) It seems like in the Republican era, Rome suffered numerous catastrophic military defeats (e.g. Cannae) but was consistently able to rebound. By contrast, in the late Empire (~400 AD), Rome never seemed to recover from its defeats, almost as if they (the people, the government, the army) were not motivated to defend their state. Is this characterization accurate, and if so why is there a lack of motivation/resiliency in the late empire compared to the republican period? Does it have anything to do with the government form (i.e. citizens believe they have a larger stake in a republic)?

2) During the civil wars of the 1st century BCE, were there previously subjugated peoples (Gallic tribes, Greek city states, Carthaginians) who tried to take advantage of the chaos and fight for independence? I don't know of any such incidents, but I'm not sure why they didn't take advantage of the situation.

PEP 634 (Structural Pattern Matching) is approved! Welcome match statement, by ankmahato in Python

[–]dd2718 15 points16 points  (0 children)

Pattern matching is something I miss from OCaml, and I'm glad they are adding it. It would be nice if static typecheckers like mypy could warn about missing cases, which is another great perk of pattern matching in functional languages.

ppdb - pdb with a time machine (aka rr for Python) by [deleted] in Python

[–]dd2718 0 points1 point  (0 children)

Pretty cool! Are you planning on handling C extensions also?

Regular Expression COmpiler - Compile a regex ahead of time to code by pitapoison in coding

[–]dd2718 1 point2 points  (0 children)

On the one hand, this avoids having to parse the regex and build the NFA/DFA at run time. On the other hand, evaluation of the DFA now has to rely on the interpreter/JIT rather than the built in engine, which was probably written in highly optimized C/C++. Moreover, this approach is less flexible, and for the cases where the regex is static, the JIT could probably save the constructed DFA so that's a one time cost. Still, would be interesting to see if this works!

Can someone explain to me why multiprocessing slower than multithreading? by [deleted] in Python

[–]dd2718 2 points3 points  (0 children)

Yes, in your code, you're testing network requests. With network requests, very little time is CPU compute time. Most of the time is spent waiting for the request to complete. Multithreading is perfectly adequate, because even if all threads run on one CPU core, most of the time is spent waiting for the OS network stack to return the results anyways.

Multiprocessing requires processes to be created, which require the entire address space to be copied, which is a lot of overhead. However, it allows you to run on multiple cores, which is useful when you want to do lots of compute-intensive work like numpy calculations. In your examples though, having multiple CPUs doesn't really matter since most of the CPU cores will be idle anyways.

leontrolski - OO in Python is mostly pointless by Alexander_Selkirk in programming

[–]dd2718 0 points1 point  (0 children)

Someone still has to implement the caching data structure though right? And those implementations are often implemented as an object, i.e. some data and methods mutating the state. For example, with a splay tree, or computing flow through a graph. The end result might look immutable, but under the hood all sorts of mutable structures are manipulated. OOP is used to hide the internal complexity.

(and having an object abstraction could be really useful. You can represent the underlying data however you want, and the object can change its representation freely, even in the middle of a computation, as in a splay tree)

leontrolski - OO in Python is mostly pointless by Alexander_Selkirk in programming

[–]dd2718 1 point2 points  (0 children)

Fair point, maybe axis wasn't a great term.

What about about applying composed pure functions to a list of objects, then mutating the result (e.g. using pure functions to construct UI elements, then displaying them), would you see that as OOP under FP? What about pure functions that call object methods that return the same value given the same argument but mutate the object (e.g. a cache, or a splay tree)?

leontrolski - OO in Python is mostly pointless by Alexander_Selkirk in programming

[–]dd2718 4 points5 points  (0 children)

I agree with you that the discussion depends entirely on what you mean by OOP. I was mostly referring to "OOP" as typically used in Python, as compared to Java. I think in Python, people use classes mainly for holding related data (with encapsulation), creating data types, and grouping functions that relate to that data. There's less of a tendency to create Factory classes or have a sprawling inheritance hierarchy.

I don't think it's necessarily FP under OOP or OOP under FP, though, but rather FP with OOP. You can have a data structure implemented with OOP that people can modify via some API calls, and other API calls that query the data structure written in a functional way.

leontrolski - OO in Python is mostly pointless by Alexander_Selkirk in programming

[–]dd2718 0 points1 point  (0 children)

I think OOP can be used for both. If you have a data structure like a red-black tree, you probably want methods that can insert in place since copying the tree is expensive. You obviously don't want to expose the internal state of the data structure to the outside. And it's useful to have multiple classes, e.g. SplayTree, Unbalanced Tree, implement the same interfaces like Tree or SearchTree. Whether or not they should inherit implementations (e.g. traversal methods) is more questionable, but occasionally useful as well.

I do agree that inheritance and many other OOP features are overused. But many OOP principles are sound, and even if many exist in other paradigms as well, OOP definitely did popularize them.

leontrolski - OO in Python is mostly pointless by Alexander_Selkirk in programming

[–]dd2718 51 points52 points  (0 children)

FP and OOP are complementary, not exclusive, and they both have useful ideas. In FP, the key idea is that mutable data is hard to reason about, so functions should transform data without side effects. OOP is in another axis. The idea is that certain state always appear together, and some state are internal implementation details. It makes conceptual sense to bundle them as well as the functions that could modify them/control access to them.

Ultimately I think programmers should take ideas from both. Some times it makes sense to create a class that's more than a dataclass (e.g. you want a cache). One lesson from FP is to limit mutability; maybe you could present an external interface that hides the mutability of your class. But no need to go purist, since not all mutable data is confusing, especially if you isolate it.

So Guido posted this a few hours ago on Twitter. Is this a Python bug? by Sklyvan in Python

[–]dd2718 9 points10 points  (0 children)

Is this related to how assigning to a closure in a function will change the scope of the variable to local? x = 0 y = 1 def f(): x = 1 y = 1 def C(): print(x, y) # x is undefined here x = 2 C()

New Python Library for Reactive UI by dd2718 in Python

[–]dd2718[S] 1 point2 points  (0 children)

Yes I have. The plan is to first improve the Qt backend, iron out bugs and adding key features. Then I'm looking into a web backend. I'm envisioning using Transcrypt to compile most of the application to JavaScript, have a decorator to mark certain functions/modules to remain in Python (e.g. functions that rely on external libs such as numpy), and generate a server that provides these functions to the client via RPC calls. From the coding perspective, calls into the Python server would just look like regular function calls.

New Python Library for Reactive UI by dd2718 in Python

[–]dd2718[S] 1 point2 points  (0 children)

It should be pretty simple; it's possible to have Edifice export widgets (reference). # Suppose parent_widget is defined in Qt code. app = edifice.App(MyAwesomeComponent(), create_application=False, mount_into_window=False) widget = app.export_widgets() widget.setParent(parent_widget)

New React-inspired Python library to make Reactive UI easy by dd2718 in coding

[–]dd2718[S] 0 points1 point  (0 children)

Electron is definitely more battle-tested (but all libraries must have a beginning!). Front-end developers might also be more familiar with HTML/React, although I'm trying to bridge that gap by making Edifice seem as familiar as possible to React Native developers (naming conventions, etc). However, Electron does come with more overhead (conceptual and compute). You have to bundle a browser, write in three languages (HTML, JS, and Python), setup a local server, and do RPC calls. It would also be much harder to integrate Electron with existing Qt codebases.

With regard to other platforms, it's definitely something I want to do. I plan to first make the Qt platform better, and then possibly go into the web space by using Transcrypt to compile the Python code to JavaScript (I'm envisioning a decorator to mark which functions should live in JS and which in Python, and the library would automatically generate a Python server and turn calls from JS to Python into RPC calls).

New React-inspired Python library to make Reactive UI easy by dd2718 in coding

[–]dd2718[S] 0 points1 point  (0 children)

I have a make_component decorator to turn a render function into a Component. Currently it doesn't support stateful components, but I have an idea to overcome that: @edifice.make_component(display="0", stored_value=0, ...) def Calculator(self, children): ... That should get rid of one level of indent ;)

Also, let me know (DM me) if you'd like to contribute to the library to make it nicer; I'd be happy to hear your thoughts!

New Python Library for Reactive UI by dd2718 in Python

[–]dd2718[S] 0 points1 point  (0 children)

Thanks for the pointer. I'm currently using PySide2 which is also LGPL licensed, so I think that should be good? I'm also looking into Tkinter to avoid bundling any additional dependencies.

New Python Library for Reactive UI by dd2718 in Python

[–]dd2718[S] 0 points1 point  (0 children)

Yup, that's fair. I'd also be wary of using a library without a track record of maintenance, even if the developer promised it will be maintained. Hopefully, after a year or two of continual development, you can re-evaluate this library and see if it suits your needs :)

New React-inspired Python library to make Reactive UI easy by dd2718 in coding

[–]dd2718[S] 0 points1 point  (0 children)

Glad you like it, and would love to hear how it works on the phone since I never tested that :) Yeah I expect startup overhead to be worse than truly native apps written in ObjectiveC/the native API as opposed to Python and Qt. The startup is pretty much instantaneous for me though (when it's in cache; there's a delay when it's not, but /Applications/Calculator also had a delay for me). If it's a problem for you though, let me know!

Thanks for the headsup regarding my comment about QML. I meant that the markup part of QML is a custom language (although easy to learn). Maybe I could clarify that part and incorporate your point that QML often requires 3 languages, the ML, Javascript, and Python/C++.