#also I think it has matrices by default so probably not what you're looking for for this project
Explore tagged Tumblr posts
Text
Throw caution to the wind and remove all type checks! Accept the string as a list of length two! If no one ever sees it then no one will ever know how horrible it is.
But yeah, python is stinky and the best solution would be writing your own C package :/
This is sort of an indirect addition to this ask maddy got about learning rust, I haven't actually gotten to learning rust yet but I do want to talk about an incident I recently had with python (I think with C the reasons why you'd rather not use it are fairly obvious) So recently tried to implement a basic matrix class in python, and since I wanted to do a whole thing where I did my own implementations of numerical optimization and more general linear algebra stuff, I tried to do it "properly" and make it "robust" and everything, but without installing any external libraries.
And to me, that obviously involved making sure that the matrix is formatted sensibly, i.e. that a matrix contains m rows of n numbers each. This seemed like a very obvious thing you should do in any serious piece of code, since if the contents of a matrix are accidentally formatted in a weird way, then you might get errors, or, significantly worse, python might just decide that it "can handle them" anyways and do some really unintuitive dumb stuff that's really hard to debug. (See this older post of mine for an example of how the pythonic willingness to work with bad inputs leads to really weird unintuitive behavior).
Turns out this is not something you can do directly in python without installing external type checking libraries! And I didn't want to just loop through all the contents and check their type individually during object creation, since that felt incredibly slow, stupid and inefficient. It didnt help that my algorithms theory exam was coming up soon, which meant I was thinking about asymptotic runtimes all day.
And so I was like "well surely at least it's easy to check for a matrix being a 2D array with consistent row sizes". However, at this point, with dawning horror, I came to a realization:
and at this moment I could just feel pretty much all of my remaining "python is easy to work with" attitude turning into dust and soaring away in the wind. If anyone here knows a way to enforce a given argument being a 2D array of numbers with consistent row sizes that doesn't involve O(n*m) overhead during object creation and that can be implemented in python using only internal modules (no external type checkers that need to be installed manually first) please tell me lol
#also I think it has matrices by default so probably not what you're looking for for this project#but you shoulf check out Julia#it has simplistic syntax like python but runs way faster and is generally better suited for computing
50 notes
·
View notes