« first day (4491 days earlier)      last day (440 days later) » 

6:16 AM
I need advice on how to represent a time span. I'm working on something animation-related, and I need to store the duration how long each frame is displayed. The obvious solution is to use a float (seconds), but floats can't accurately represent a frame rate of 30/60 fps. So I thought of supporting floats, Decimals and Fractions, but those 3 classes refuse to work together (you can't subtract a float from a Decimal, for instance).
Is there a good solution for this, or should I just accept the inaccuracy and use floats?
class Frame:
    image: PIL.Image.Image
    duration: ???
 
 
2 hours later…
8:22 AM
@Aran-Fey Would float and Fractions work together? Decimal rarely seems advantageous to me, since it is inherently inaccurate like float but also slow like `Fractions? .
Otherwise, if your duration is always for a framerate, why not directly use fps? float is accurate for common integer numbers.
 
Is the inaccuracy gonna matter?
 
Looks like yes, floats and fractions work together. Omitting Decimal seems like a good compromise then, thanks
Unfortunately I don't have a constant frame rate; each frame can be visible for a different amount of time
 
From 9:40 onwards in this video I'm not sure that's true with the python GC? He equates None to Null, effectively
 
@matszwecja I don't know tbh. Maybe I worry too much
 
If that's something similiar to gaming framerate, I don't think anyone would care less if it was 29.9999997 or 30 fps
 
8:32 AM
In fact it can't be because of the None singleton so it's a very poor example :/
 
Actually the standard for video specifies that what we call "30fps" is actually 29.97
 
@roganjosh I don't think he said anything wrong. But it's a bit unfortunate that he emphasizes the null/None bit; he makes it sound like those play a special role in garbage collection. As if None was the only thing that could "destroy" a reference
 
9:06 AM
@Aran-Fey does this work?
 
@Aran-Fey are you adding subtitles to a video?
 
stackoverflow.com/a/75307780 I don't have 3.10 installed to test, so I'd appreciate review, feedback for caveats, etc. For example I'm pretty sure this only works to test against constants, since trying to test against variables would instead capture parts of the matched pattern. would appreciate some examples of what happens when trying that.
 
@Kevin could be totally wrong, but I'm guessing Rational Root might be it?: en.wikipedia.org/wiki/Rational_root_theorem
@ChrisP Yes. I do that all the time without really noticing. When you do an MRE, the end result isn't the only important thing, the process of making one is too. For instance, you could get a clue by trying but failing to implement one, etc.
@Aran-Fey coincidently, I found an answer you made when looking around for what you asked: stackoverflow.com/a/38433875/12349101
it's not directly related of course...
 
9:32 AM
Since it's coming up here stackoverflow.com/questions/75301122 and was also relevant to one of my most popular answers (recently completely redone) stackoverflow.com/a/6633912/523612 : is there a good technical reason why locale settings have to be global, and can't easily be used for a one-off localized parse/format?
 
9:44 AM
@Aran-Fey btw, It's hard to give complete advice/recommendation in this case. If the format/file you planned to use was known, then it might make things easier. For example, GIF do not technically have a general fps for the whole sequence.
I can't help but relate to what you mentioned though. I remember that I still didn't fix the fps on my screen recorder :/
 
 
2 hours later…
11:48 AM
cbge
anyone here with some decent Django knowledge?
 
 
1 hour later…
12:55 PM
@Aran-Fey Proposal: represent duration in milliseconds using int
Interesting that Arne should bring up subtitles, because just yesterday I tried subtitling a video for the first time. I learned about the .srt file format, which is fairly ubiquitous. It requires timestamps specified down to the millisecond.
 
had to do that a year ago, but did it using Vim/Emacs interchangeably. There are a couple of nice extensions there to edit subtitles using live update on the video (using mpv player)
 
All of which is to say: for durations of events perceivable by humans, perhaps integer milliseconds is good enough.
I ended up writing my srt file by hand in Notepad++. It's a human-readable format, so you don't need any cool tools for it... But I did yearn for a live update system like Nordine just mentioned.
I had several rounds of "hmm, subtitle number N started a bit too late, I'll nudge its timestamp back", and I'd have to close VLC and open it again to see if my new timing was satisfactory
 
there is probably a way to do the same thing with VLC. From what I recall, it also supports ipc-sockets, which is what I used with MPV: wiki.videolan.org/Documentation:Advanced_Use_of_VLC
it's just a json file passed around through unix sockets (probably different on Windows though)
 
1:12 PM
It wouldn't surprise me too much if VLC had tools for this. I elected to skip the research and do it the hard way.
 
@roganjosh @Kevin I suppose that would work well enough. Technically an int also can't accurately represent 1/30, but, well, I really shouldn't worry about inaccuracies at this scale... So I guess the solution was to use floats all along
@Arne No, it's more of a general-purpose library for working with animations. Creating loops, transitions, that kind of thing
 
I was thinking that if the number of frames could be constrained to two hours of content, the maximum error for floats could be estimated
if loops are involved I'd probably also be worrying about things going out of sync
 
You gotta be careful when you add lots of little floats together
 
Currently I even load all the frames into memory, so if you want to have a 2 hour animation you'll need a lot of RAM...
@Kevin That's a good point, actually. But even then, the error seems to be negligible
>>> d = 60*60*2 / 30
>>> sum([d]*100)
24000.0
 
@Aran-Fey that's bigger issue than slight float inaccuracies, imho
 
1:25 PM
Conclusion: Was worried over nothing. As per usual
 
Alternate proposal: define a new unit, the Aran, as exactly 1/60 of a second. Then define all your durations in integer Arans.
 
Aran was unfortunately beat to the punch by a few years (given a very liberal definition of "few").
 
That will be hard to market. The gamers are all gonna scoff and say "You can't even do 120 fps with this thing"?
 
"no, but I can do 199876545678987654 Aran :)" sounds very marketable to me. Maybe a bit confusing but I'm sure the marketing teams can turn this around into a good ad
 
1:43 PM
@0x263A I'm only around 20813760000 Arans late
 
@Aran-Fey d == 240.0, exact value
Try sum([1/30] * 60 * 60 * 2 * 100)
Small diff though; usual 1e-15 relative error per operation or something like that
 
Welp, I just realized that my math from earlier made no sense
So with a length of 200 hours, you lose 0.18 microseconds of footage? Am I reading this right? I don't trust my half-awake brain anymore
 
I'm trying to remember if sum has some magic that prevents especially bad float imprecision... I'd expect doing "+=" in a loop to have no magic, in comparison
My initial tests indicate no difference in behavior. I withdraw my alarmism, until such time as I can find a concrete reason to be afraid
 
@Kevin I doubt it because it works with arbitrary iterables
 
I bet numpy et al has a "sum very accurately" function
 
1:58 PM
@Kevin Thus proving yourself to be smarter than me!
 
You'd have to sort or know the length to sum in batches usually
 
I'm not smart, just dumb along an unusual vector
 
Ah, just what I was looking for 👍
 
@Aran-Fey I think you need another factor of 30. 125 microseconds.
 
2:03 PM
Still an acceptable margin of error, I'd say
 
Also, do you really "lose" footage? Isn't it just a matter of it being that much longer/shorter?
 
Well, yeah
 
Does anyone here use SQL or pandasql
 
Yeah
 
2:25 PM
I use SQL but never through pandas
 
2:42 PM
Trying to learn more about the specifics of floating point numerical error... en.wikipedia.org/wiki/Kahan_summation_algorithm says "simply summing n numbers in sequence has a worst-case error that grows proportional to n, and a root mean square error that grows as sqrt(n) for random inputs". I do not know what that means.
I looked up "root mean square" and it seems easy enough to calculate, but on a conceptual level I don't know what it's useful for.
 
2:56 PM
It's the standard error computation that most domains use.
 
MASE might make more sense
 
I think RMSE is better than flat summed error for comparing errors of data with one big outlier vs each data point being off
 
It's hard to know what doesn't make sense given the numerical background demonstrated from years of speaking to you. Is there a physical analogy to put it to?
Although I'm pushed to think of a practical analogy beyond just "this means my model is gud"
 
It might make more sense if you look it up in the context of linear regressions.
 
 
2 hours later…
4:43 PM
TIL about str.translate... cool but why?
 
Why not?
 
TIL about str.translate... cool but why?
uh did that send twice... huh
What's the usecase?
 
Translate symbols to others?
Say replace all variants of 1 with an actual 1.
Remove all punctuation at once.
Generally do the stuff that people misuse multiple str.replace for.
 
How would you remove all punctuation at once?
 
Have a str.translate table mapping from ",", "." etc to None.
 
5:22 PM
@Kevin is "standard deviation" better for you?
 
 
1 hour later…
6:23 PM
Why do so many beginners in Python incorrectly refer to lists as "arrays"? It seems like they do this even when they haven't learned another programming language before. Where are they getting the terminology from? Is there enough pop literature out there about programming that one picks it up even without trying to learn a programming language?
 
I could imagine they get this term on some youtube channel, course, or blog and just use it intuitively. The term itself isn't too hard to "guess" what it means, even if incorrectly
 
Good question. I guess you could ask them?
 
btw, you can't necessarily assume they don't know another language before they ask a python related question. Knowledge can be fragmented heavily if someone doesn't try to pick up the basis of said language. So it's very easy to know say, 0.01% of a language just by understanding what a snippet does (roughly), and then picking up assumptions based on that previous understanding.
from there, you could then use those assumptions/understanding and see if it apply on other similar to related term (whether or not they are truly related doesn't matter here, so emphasis on "see if")
for example, I remember once saying in this room that a language (don't remember the exact name) looked like Latex. I don't know Latex (based on the fact I can't really write anything in it without looking at everything on google) but I intuitively know the "feeling" of the syntax based on previous snippet/code I saw, and my own assumptions
so, it "depends" on how you see it. On a technical level, you could say I don't know Latex, but I still know it just enough to recognize the syntax from time to time.
 
@KarlKnechtel realpython, geeksforgeeks etc.
 
realpython has some decent content, especially if you compare them to other sites. But I admit they sometimes use weird analogies
 
6:38 PM
I agree.
 
6:48 PM
(But I have no opinion on the part that sometimes they use bizarre analogies - I don't remember seeing/or never seen this occur).
 
I used to call other language's arrays as lists lol.
 
7:03 PM
I don't see it as something serious to interchange these terms unless you are referring to a specific programming language, in the programming logic classes I took, when it is not about any specific language, 1D array is a simple list and 2D array is a matrix. This is just my opinion.
This is just my opinion BASED in the classes I took*.
 
@AndrasDeak--СлаваУкраїні ... Somewhat. I am at least familiar with the term "standard deviation", although I don't think I could explain it correctly.
 
7:32 PM
Maybe my confusion is due to the "dimensionality" of the problem. When I learned standard deviations in college, the input was one unordered set of numbers, for example the age of each person in the city. But this problem has more moving parts: we've got the variable N, and an N-sized list of floats, and a function that takes a list and returns a number...
My first instinct would be to discard everything except the list of floats. But finding its standard deviation seems useless, since we already know that it's randomly generated.
 
@Kevin well imagine Fred taking off the monster mask of root mean square error and it's the standard deviation underneath
@Kevin for each N you have an "unordered set" of N numbers to take the std of.
 
Perhaps I'm supposed to choose some largeish integer D, and perform D trials of the following: I randomly generate N floats, and calculate error = abs(naive_sum(floats) - smart_sum(floats)). When my D trials are finished, I take my list of errors, and do "root mean square" to it, and that tells me how good naive_sum is.
 
So your std is a function of N, i.e. a sequence
There's no randomness. That's actually why it's called RMSE here.
I assume :P
So as if estimating the std from a finite sample
 
I suppose there are a finite number of floats.
2^64, give or take. Depends on whether NaN and inf and such count.
 
8:16 PM
@KarlKnechtel c++ background maybe
 
W3Schools conflates lists and arrays. I sent them an angry email.
 
8:42 PM
@sahasrara62 perhaps that's more common than I thought
though perhaps it's because of tutorial writers having that background, and not thinking enough about what they're writing
@Marco it isn't serious WRT the student understanding the fundamentals. But it is serious from a perspective of clear communication, especially if Numpy could be involved, or the array standard library module, or other things offering an "array"
I don't think I need to say explicitly which perspective is more important for Stack Overflow ;)
 
Sure, I agree, when it comes to a programming language it is necessary to differentiate.
 
@KarlKnechtel yup, in most college/school, array is mentioned in introductory programming language as data type than lists
 
Exact
I was taught that way
 
@KarlKnechtel you know there's like a gigantic bin fire outside of SO going on? Today I learned that FORTRAN is going to die in 2023. Seems this is the year
 
@roganjosh will oracle licence change impact java usages ?
 
8:51 PM
Wut? In case it wasn't clear, I just got recommended some garbage article telling me the 10 languages that will die in 2023. I haven't mentioned java?
 
FORTRAN can't die. We can only drive it back below the waves, to slumber in dread R'lyeh until the stars are right once more
 
It's me that missed the joke I guess, then?
 
@roganjosh i didn't get the joke truely speaking
 
@Kevin it also depend on the kind of floats you choose for your task, no? If they're closer to zero floats will be more exact.
my recent insights into maths tell me that for a float64 there are 2048 * 2^53 floats between 0 and 1, and less than 1 float between 2^53 and 2^53+1
 
9:05 PM
Floats: Proving once again that programmers can make any topic complicated
 
For a given float, you can find the next higher or lower float using math.nextafter
 
that's really neat, thanks
 
@roganjosh "die" how
@Arne surely not. 2048 is 2^11, so 2048 * 2^53 would be 2^64, i.e. every possible value
 
yeah, I thought I'd be brave and skip the "i dunno though lol" disclaimer at the bottom of any mathematical claims I make. looks like I really don't
 
@KarlKnechtel dunno, that's just what the article told me (I'm being facetious, they were just being dumb)
 
9:20 PM
@KarlKnechtel ok, updated calculation - you have half of all possible exponents, because the other half would be negative -- so only 1024 -- times the full mantissa, still 2^53.
 
these article are better than tech influencer telling how to get into FAANG
 
But, I have found the pinnacle of stupidity and I feel very proud of my discovery. I'm driving randomly around the UK and I found pub in one of our fishing villages. I was,quite literally, the only customer. The barman had a go at me for using my phone - it's banned. So I got a refund on my pint and now I'm sat next door in a pub full of people
So not only are they empty but their policy basically poured my drink down the sink because "yam tech". What a way to run a pub
 
@Arne given that the mantissa only needs 52 bits to be represented because the "1" to the left of the point is implicit, that'd mean that half of all floats are between 1 and -1
(trust these statements at your own discretion)
if I didn't mess up again, I was only off by one (bit)
 
Only one mistake :P
 
duplicate stackoverflow.com/questions/75316149 we do have a duplicate for this, right? I can't think of search terms rn, somehow
>half of all floats are between 1 and -1
that actually sounds close to correct, if not actually correct
 

« first day (4491 days earlier)      last day (440 days later) »