Make Python code 1000x Faster with Numba

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ก.ย. 2024

ความคิดเห็น • 682

  • @gdsvsrv
    @gdsvsrv 3 ปีที่แล้ว +515

    finally, my print("hello world") can run at the speed of light!

    • @felicytatomaszewska2934
      @felicytatomaszewska2934 3 ปีที่แล้ว +1

      That's not true

    • @MartinoxxHD
      @MartinoxxHD 3 ปีที่แล้ว +12

      @@felicytatomaszewska2934 no way

    • @dv_interval42
      @dv_interval42 3 ปีที่แล้ว +16

      This meme is much closer to the truth than people would think.

    • @hanchen2355
      @hanchen2355 3 ปีที่แล้ว

      You can’t because it’s IO

    • @aryanmn1569
      @aryanmn1569 3 ปีที่แล้ว

      @@dv_interval42 how?

  • @MichaelKudlatheInterested
    @MichaelKudlatheInterested 3 ปีที่แล้ว +605

    Amazing, amazing video. As a PhD student, I'm sure you've saved me much more than 8 hrs of compute.

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +301

      I expect a co-author ship on all your papers now 👀

    • @sorry4all
      @sorry4all 3 ปีที่แล้ว +7

      Lol

    • @senwang1982
      @senwang1982 3 ปีที่แล้ว +11

      @@JackofSome fair enough😂

    • @alexp6013
      @alexp6013 3 ปีที่แล้ว +6

      I've once had code run for 48h, so I fully believe that it could be true

    • @username42
      @username42 3 ปีที่แล้ว +16

      @@JackofSome i think he will thank you in the acknowledgement part in his thesis for sure :)

  • @tronali5703
    @tronali5703 4 ปีที่แล้ว +65

    One thing to note is that Numba really optimizes nested loops. If you say have to call a function a 100 or million times, better to have an outerloop instead that iterates within the function. With parallel turned on, you can see a 1000x increase.

    • @JackofSome
      @JackofSome  4 ปีที่แล้ว +9

      This actually makes a lot of sense. Thanks for the comment!

    • @chriskeo392
      @chriskeo392 2 ปีที่แล้ว +2

      This is crazy! Awesome

    • @AlexanderHyll
      @AlexanderHyll ปีที่แล้ว +3

      Its one of the only ways to run the notoriously slow nested loops in Python (whenever it can’t be vectorized). We had a simulation to run that went from 81 days pure python to 2h (~1000x).

  • @klioseth4336
    @klioseth4336 3 ปีที่แล้ว +48

    Seriously this is brilliant.
    By applying this to the 3 main functions of a 1500 lines project I went from a 24 minutes runtime to about 20 seconds. that's 70X faster for a day's work (it'd be faster now that I learned the more complicated details). The C++ equivalent of the code does it in about 15 seconds.

  • @ger15100
    @ger15100 3 ปีที่แล้ว +32

    Numba really is great. Here is my first experience with it: I have some code that I estimated would take up to half a year to run. With some minor changes to the code for compatibility with Numba, the run time for the same conditions was up to 1.5 hours. This was a game-changer for me as I needed to run this script many times.
    One of my colleagues also implemented it into his machine learning code and managed to obtain some significant speed bumps.

  • @joshuatyler4657
    @joshuatyler4657 3 ปีที่แล้ว +16

    I implemented it in my code, and it took around an hour worth of computation and put it down to 30 seconds. Amazing stuff.

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +2

      Nice nice!

    • @joshuatyler4657
      @joshuatyler4657 3 ปีที่แล้ว +4

      @@JackofSome One funny thing that I found is that you can’t create numpy.linespace or numpy.arrange arrays with anything besides integers. I had to create an integer array, then divide it by 2 to make it a float32, and then populate it with a for loop to get the actual array I wanted. Also, numpy.zero arrays have to be initialized outside of the function and passed as an argument instead of being initialized in the array. But the extra work is worth the speed up.

  • @jmnunezd1231
    @jmnunezd1231 4 ปีที่แล้ว +238

    One of the most awesome Python tutorials I have seen. The narratives, the examples and the way you explain it is just awesome, 5 starts to you man! keep on doing it!

  • @kaandonbekci6414
    @kaandonbekci6414 3 ปีที่แล้ว +65

    Similar to other commenters, I have to say this is one of the best TH-cam tutorials on writing fast Python code. Great buildup to the mic drop moment, amazing progression. Jack, I hope you make it big in the CS-tutorials TH-cam space and have a great day.

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +9

      Thanks for the kind words. Videos have been recommended a lot lately so fingers crossed.

  • @valente.victor
    @valente.victor 3 ปีที่แล้ว +67

    This is one of the best programming-related video tutorials I've ever seen. No-nonsense style, very direct and still computationally rigorous. Awesome stuff!

  • @id104335409
    @id104335409 3 ปีที่แล้ว +123

    I nod my head with approving noises as if I understand what is going on.

  • @gabrielcesar568
    @gabrielcesar568 3 ปีที่แล้ว +9

    Grad students from around the world are thankfull for this video.

  • @muhammadanas1201
    @muhammadanas1201 2 ปีที่แล้ว +2

    I had to submit a project in 2 days (that I had months to do but waited until the last minute) and in one piece of code, I needed to clean data of 6 million tweets. Regular python code showed runtime of 400+ hours (I used tqdm library for it). I got cold feet thinking I’m going to miss the deadline, but finally got the idea to search for ways to make the code faster. Found this library out on the internet and using it, I was able to run that piece of code in JUST 10 MINUTES. This library saved my project that day 👌.

    • @JackofSome
      @JackofSome  2 ปีที่แล้ว +2

      Numba: enabling procrastinators since 2012 😂

  • @frodobaggins3974
    @frodobaggins3974 4 ปีที่แล้ว +21

    11:45 - try this: np.zeros_like(input_list, dtype = np.int64, order='C')
    My experience with numba - it works great, but types have to be very precisely defined for every single object. Otherwise nopython will fail, and where numba sucks is generating traceback messages - in the case of complex functions it will take forever to debug. So type whatever you can - it is not a 'Pythonic' way of thinking and writing, but in this particular case it is necessary. Anyway, great introduction!

    • @JackofSome
      @JackofSome  4 ปีที่แล้ว +27

      Thanks for the tip, and best of luck on your journey to mount Doom. We're all counting on you.

    • @0.Andi.0
      @0.Andi.0 2 ปีที่แล้ว +1

      Hi, I have a question, how can I declare like a type so numba can compile it? For example I have a vector3 class that cannot compile with numba (class with x,y,z components)

    • @mariomuysensual
      @mariomuysensual 2 ปีที่แล้ว +1

      @@0.Andi.0 use numpy arrays instead

  • @syoudipta
    @syoudipta ปีที่แล้ว +2

    After being skeptical about this library for a while, I've gotten used to it. I've watched many tutorials and read many articles and documentation. After weeks of determination to learn this technique properly,...
    I have become, comfortably Numba. 🤟

  • @MisterFresh022
    @MisterFresh022 3 ปีที่แล้ว +10

    What an amazing video. I'm a student in Computer Science and we just did a week ago an introduction to Numba.
    And you sir not only explained to me the concepts in a positive astonishing way, but also gave me the desire and the excitement to apply it on all my old and future codes. Thanks you !
    PS : Is there more videos where you're explaining the others topics ( convolution, neural networks .. )

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +2

      Great. I hope you share it with your class :)
      Unfortunately no other videos on Numba

  • @mpilosov
    @mpilosov 2 ปีที่แล้ว +3

    This was wonderfully clear and helpful! Thank you!
    My PhD involved running a lot of these forward problems under uncertainty, Lost much time trying to parallelize physics simulations and fighting with the GIL. Sometimes it is just worth waiting.

  • @trizzzzlez
    @trizzzzlez 2 ปีที่แล้ว +1

    I came back to say a huge thank you. currently doing my Phd. my code was to run 300k iterations it took like 3days+. your short video changed everything, i took few hours to rewrite the code to suit numba as you explained. boom 2hrs i have results on the screen instead of 3days+

    • @JackofSome
      @JackofSome  2 ปีที่แล้ว +1

      That sounds amazing. Please be very careful and do consistency checks between the two codes. Don't wanna find out there was an issue when you're writing your dissertation 😅

    • @trizzzzlez
      @trizzzzlez 2 ปีที่แล้ว

      @@JackofSome yes I will jack thank you.

  • @Meodoc
    @Meodoc 2 ปีที่แล้ว +2

    I really liked that you stayed real and just said that you aren't qualified to comment on why the python loop with the numpy array took so much longer to execute than just saying something with the risk of talking bullshit and spreading misinformation in order to sound competent, a behaviour I have seen way to often online and which bothers me quite much.
    Very great, clear tutorial, truly one of the best python tutorials I have seen so far on TH-cam. Keep it up! :)

    • @JackofSome
      @JackofSome  2 ปีที่แล้ว +1

      Nice. Yeah it's always better for me to just say "I don't know" when I don't know :)

    • @Meodoc
      @Meodoc 2 ปีที่แล้ว

      @@JackofSome Love it 🙌

  • @MVHiltunen
    @MVHiltunen 4 ปีที่แล้ว +14

    numba is really sometimes absolutely stunning in it's acceleration per extra work.

    • @JackofSome
      @JackofSome  4 ปีที่แล้ว

      That it is friend.

  • @sasimitra5871
    @sasimitra5871 3 ปีที่แล้ว +16

    I don't know why I need this. I'm still a High School student doing python for fun.
    But imma keep this tucked away in my mind.
    I have a feeling I'll need it soon enough.

    • @CrazyFanaticMan
      @CrazyFanaticMan 3 ปีที่แล้ว +8

      When your'e working on projects that needs the program to do things fast, you want C like performance because low level languages like C/C++ are about as fast as you can get.
      Python is not a low level language. It's a high level dynamically typed language. This means it's pretty slow.
      So even though it's pretty fast to write a python program because it's basically the same as writing in English, you're giving up the actual execution speed (performance) in order to keep that fast typing speed (developer performance).
      Numba solves this problem by keeping the Python typing that we all love and getting the C like performance that is needed for projects where speed is very important.

    • @eskees9498
      @eskees9498 3 ปีที่แล้ว +1

      @@CrazyFanaticMan so I'm also in high-school just doing python for fun. Is number useful for smaller projects or only for large projects. My biggest code is only about 80 lines of code, but it uses my Webcam to track hands. Would it be worth it to implement numba for this low amount of code?

    • @CrazyFanaticMan
      @CrazyFanaticMan 3 ปีที่แล้ว +2

      @@eskees9498 It doesn't matter how many lines of code you have, whether it's 80 lines or a billion lines.
      What matters is the problem you are trying to solve. If for example you say "I want my webcam to not only accurately detect the location of my hands but I also want my webcam to track my hands if I move them really fast".
      I would imagine a webcam tracking hands that are moving really fast would require very fast performance speed in order to keep up. So in this case, numba may help you a lot.
      It all really depends on what you want and what your expectations are.
      The size of your program does not matter, numba can you help you whether you're program is big or small

    • @eskees9498
      @eskees9498 3 ปีที่แล้ว

      @@CrazyFanaticMan thank you, I appreciate the info

  • @vibhu8024
    @vibhu8024 ปีที่แล้ว +1

    I love how "incredibly fast" python code is pretty much about going back to c/c++ syntax.

  • @SomeFreakingCactus
    @SomeFreakingCactus 3 ปีที่แล้ว +9

    These are some seriously impressive results. I wonder if this could give Python a niche in indie game development.

  • @brockobama257
    @brockobama257 3 ปีที่แล้ว +43

    There’s no way this delivers as promised. I’m about to implement it and will update soon.

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +20

      You're on!
      (feel free to DM me on reddit/twitter if you're running into issues)

    • @szymonozimek
      @szymonozimek 3 ปีที่แล้ว +2

      let us know

    • @profoundgenius9726
      @profoundgenius9726 3 ปีที่แล้ว +3

      Let us know

    • @lucianomachado9271
      @lucianomachado9271 3 ปีที่แล้ว +3

      Yup, would gladly want know

    • @linear9185
      @linear9185 3 ปีที่แล้ว +3

      so how did it work?

  • @dadogh
    @dadogh 3 ปีที่แล้ว +5

    That's an awesome video. Thank you! I've been running orekit scripts which took me ~4h, and with numba there are taking ridiculously 2min!

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +1

      Oh wow those are amazing gains! Glad I could help

    • @shahnawazazam
      @shahnawazazam 3 ปีที่แล้ว

      Just make sure your cpu cores arnt too angy at you

  • @drepi57
    @drepi57 3 ปีที่แล้ว +2

    Jack!!! Congrats for this fast, clear and insightful video. This is a game changer for me (I'm a Fortran 77...20** programmer now starting with python). Live long and prosper \\//

  • @nahiyanalamgir7056
    @nahiyanalamgir7056 ปีที่แล้ว +1

    Amazing tutorial and Numba is a great software. I hope Python officially will one day ship with a compiler because the community got so huge that people often write performance-intense code in Python that goes against its nature. Moreover, it'd be amazing to ship a Python product statically compiled without gigabytes of libraries!

  • @TimmyTam
    @TimmyTam 3 ปีที่แล้ว +3

    I really thought the title was clickbait. It wasn't. This is honestly amazing, thanks for showing us this :D

  • @evertonsantosdeandradejuni3787
    @evertonsantosdeandradejuni3787 2 ปีที่แล้ว

    Holy shit, I'm sold. Examples on point, mic indeed touched the ground. Thanks for the tip

  • @RealLionTion
    @RealLionTion 3 ปีที่แล้ว +19

    YES, I LOVE PYTHON AND THIS IS PERFECT THANK YOU MATE

  • @irok1
    @irok1 3 ปีที่แล้ว +357

    Finally, this is what Python has needed

    • @raycao88124
      @raycao88124 3 ปีที่แล้ว +26

      Just use C🤣

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +46

      cPython is already "just use C" so not quite

    • @tsunekakou1275
      @tsunekakou1275 3 ปีที่แล้ว +30

      python doesn't need to be faster, it designed to be simple not efficient. there are plenty other programming languages that designed to be efficient like C, C++ that has proved themself. sure they are hard to learn but trying to get python faster is just like reinvented the wheel, learning C++ from scratch in my opinion is much more beneficial in long term than trying to make python faster because essentially you are learning the same things but you won't get far with python.

    • @tando6266
      @tando6266 3 ปีที่แล้ว +42

      @@tsunekakou1275 Couldn't disagree more, for a lot of science we are paid to do things, not write c++ libraries to do things. As much as I like C++ it is woefully inadequate for a research setting with deadlines.

    • @tsunekakou1275
      @tsunekakou1275 3 ปีที่แล้ว

      @@tando6266 which points?

  • @ecielyang9719
    @ecielyang9719 2 ปีที่แล้ว

    I have struggle for Numba for 3 days. This Vedic is really clear

  • @peterbonnema8913
    @peterbonnema8913 3 ปีที่แล้ว +2

    Both Numba and this video are amazing. The video was really really clear and concise. I'm definitely gonna remember Numba for future projects.

  • @nitsanbh
    @nitsanbh 3 ปีที่แล้ว

    This is one of the best intro/tutor videos I’ve ever watched on any subject

  • @jakubkahoun8383
    @jakubkahoun8383 2 ปีที่แล้ว

    This is the best Numba video, short , good examples etc.

  • @jongmassey
    @jongmassey 3 ปีที่แล้ว +11

    Damnit, why did I only discover this 6 days before my PhD submission deadline?!

    • @eskees9498
      @eskees9498 3 ปีที่แล้ว

      How was your submission deadline?

    • @jongmassey
      @jongmassey 3 ปีที่แล้ว +1

      @@eskees9498 horrendous, my stomach is still in knots!

    • @eskees9498
      @eskees9498 3 ปีที่แล้ว

      @@jongmassey well good luck 👍

  • @MrRyanroberson1
    @MrRyanroberson1 3 ปีที่แล้ว +1

    this is absolutely perfect because i just found this while running a really oddly intensive random number process (something like one million terms per second? i need billions) and numba sped it up by a factor of 100 halfway through the video, and with njit it didn't actually speed up any further, it just got a more consistent time (randomly jit is 10% faster or slower depending i guess on the random values

  • @AnthonyThomas_Ant
    @AnthonyThomas_Ant 3 ปีที่แล้ว +1

    Liked and subscribed. The length and pace of the video were spot on, especially as you’ve shared the notebook.

  • @dinoscheidt
    @dinoscheidt 3 ปีที่แล้ว

    Awesome video. Simply forwarded this to two of my junior devs and they completely got it now. THANK YOU!

  • @PandemicGameplay
    @PandemicGameplay 3 ปีที่แล้ว

    This is revolutionary. I always wanted a library to allow these but without the hassle of installing something like Cython, etc. Just a good ol' pip lib that can allow my code to speed up orders of magnitude. A nice bonus is the ability to release the GIL.

  • @dmgeo
    @dmgeo 3 ปีที่แล้ว

    Thank you for your video. I work with satellite image processing and we are used to spend hours waiting for a particular processing task to finish... I for sure will be trying to use Numba

  • @stxnw
    @stxnw 3 ปีที่แล้ว

    couldn’t understand what this video was saying 4 months ago. i’m back and i finally understand.

  • @lordtejas9659
    @lordtejas9659 4 ปีที่แล้ว +2

    You deserve my like. Nice work sir. Now I can show to my friends how a optimizated and we'll written code looks like. Numba.

  • @vishawashkumar5159
    @vishawashkumar5159 3 ปีที่แล้ว +2

    This needs much more views.. This is a revolution..

  • @yashmanwani6232
    @yashmanwani6232 3 ปีที่แล้ว +1

    Man. I must have been living under a rock to have missed numba for so long

  • @eddantes_
    @eddantes_ 3 ปีที่แล้ว

    Great video. The fact that you are sharing the jup notebook is amazing. Thanks a lot. Please consider making a follow up video with more complex applications of numba. For example, integrations!

  • @unflexian
    @unflexian 6 หลายเดือนก่อน

    mate you're a jupyter magician

  • @lemurmad
    @lemurmad 3 ปีที่แล้ว

    The fact i got this in my recomended when i made a screencapture to table that was at 1 - 4 fps at 480p
    This is gonna help a lot!

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว

      Do let me know if it helps (or even if it doesn't). If your app/project is public I would love to take a look at it.

    • @lemurmad
      @lemurmad 3 ปีที่แล้ว

      Ill test tomorrow as its kinda late. Its not currently public as its just something specific, but I dont mind sharing it.
      I do really hope it makes it faster!

  • @janewan1196
    @janewan1196 2 ปีที่แล้ว

    Thank you so much! I was trying and failing to turn to C++ for number crunching, but this has just saved me!

  • @michaelc3650
    @michaelc3650 3 ปีที่แล้ว +6

    Damn this is really cool, just came across it and it should definitely help in speeding up machine learning or ai projects

  • @CoolDude911
    @CoolDude911 2 ปีที่แล้ว

    10:10 Why are numpy arrays slow to dynamically allocate? -> The basic answer is that it is a C++ vector underneath and that vector which can be given extra capacity to append elements but at a certain point it will have to ask the operating system for more contiguous memory and has to be reallocated (this is very slow). The solution is to assign the numpy array a certain length beforehand with the np.empty() function.
    Python is designed to be fast to allocate an object of any amount of memory and a uses a linked list for its List type. This does have a cost in terms of defragmentation and garbage collection and it is slower to iterate through a linked list as well.
    Thank you for this informative video.

    • @JackofSome
      @JackofSome  2 ปีที่แล้ว

      Python's lists are not linked lists, they are Implemented somewhat similar to vectors. They also have O(1) lookup, something you can't have with a linked list. This is a pretty common misconception I wonder where it comes from. Maybe a really old version used to have linked lists?
      Here's a link in the python docs talking about the basic implementation
      docs.python.org/3/faq/design.html#how-are-lists-implemented-in-cpython

    • @CoolDude911
      @CoolDude911 2 ปีที่แล้ว

      @@JackofSome Oh cool, that's interesting. I assumed that because I found it faster to append a list than a numpy array. Maybe the numpy array is using a vector without a smart way of having extra capacity so it has to be reallocated all the time.
      I assume that a list in python has to contain pointers to a generic memory buffer objects so I guess the is linking going on there, as it has to allow fast generic memory allocation. It's funny how the inference time and allocation is measured but that does not take into account garbage collection and fragmentation.

  • @djudju8047
    @djudju8047 2 ปีที่แล้ว

    This video was very interesting for me. I just understood why Python is so slow.

  • @IndellableHatesHandles
    @IndellableHatesHandles 3 ปีที่แล้ว +21

    I bet my friend who called Python a "fake language" is soiling himself right now.

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +10

      Ehh, let him call it a fake language. You can instead occupy yourself with making awesome things instead :)

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +3

      That's exactly how you say it in English :). Thank you for your kind words

    • @overloader7900
      @overloader7900 3 ปีที่แล้ว +2

      I mean, its technically just translates python to actual machine code... So, as usual, the best way to make python fast, is to not use python

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +3

      Exactly. Because when you compile C++ you officially stop using C++, right?

    • @overloader7900
      @overloader7900 3 ปีที่แล้ว +1

      At this point its about the language that is the easiest to convert to machine code

  • @Epiphonication
    @Epiphonication 3 ปีที่แล้ว

    that's fantastic, I used to resort to using my uni's HPC cluster to get some more speed but now it's so much faster even on my old thinkpad, thank you so much!

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว

      Wow ... If you're able to go from HPC cluster to a laptop those are ... Those are some massive gainz

    • @Epiphonication
      @Epiphonication 3 ปีที่แล้ว

      @@JackofSome truly massive! I'm going to try numba + HPC soon, let's see how fast that goes

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว

      Them: nooo you can't write heavy workloads in pure python
      You: haha, numba go brrrrrr

    • @Epiphonication
      @Epiphonication 3 ปีที่แล้ว

      @@JackofSome exactly my thought :D

  • @MichaelBrown-gt4qi
    @MichaelBrown-gt4qi 3 ปีที่แล้ว +8

    This is amazing. This completely changes python for me.

  • @Blooddarkstar
    @Blooddarkstar 3 ปีที่แล้ว

    Very well explained and saved me from some mistakes. You deserve way more subscribers!

  • @mkthakral
    @mkthakral 2 ปีที่แล้ว

    Fist visit on this channel, but you are the best ;-)

  • @jamesmarchetti3305
    @jamesmarchetti3305 ปีที่แล้ว

    My new fav channel. Have you done a video talking about your Linux setup? If not I would love to see it/could you share some info?

  • @mengzhu8385
    @mengzhu8385 2 ปีที่แล้ว

    Amazing video! I'm starting to think to give numba a try.

  • @shkhrvarshney
    @shkhrvarshney 2 ปีที่แล้ว

    Awesome tutorial! Thank you so much. I shared the video with my old Intro to Parallel computing professor. Hopefully he sees the email coming from non UW email id lmao. Video would be pretty helpful to any new(&old) students of the course.

  • @sumit_singh_live
    @sumit_singh_live 2 ปีที่แล้ว

    Your video was that amazing and well executed that I was hypnotized to hit subscribe and like. Keep it going.

  • @hectorminator4
    @hectorminator4 3 ปีที่แล้ว

    Dude, I'm an aerospace engineer student currently taking my masters studies, and I have to program with python and some programs take some minutes to calculate, because I have to solve complex nonlinear equation systems, and that takes some time that makes me desperate, I'll definitely try this, thanks a lot

  • @guy-dev
    @guy-dev 3 ปีที่แล้ว +1

    I'm a Java dev but I'm saving this for later, don't mind me.

  • @b992152
    @b992152 4 ปีที่แล้ว +2

    Great video mate. Really enjoyed it

  • @AJ-et3vf
    @AJ-et3vf 3 ปีที่แล้ว +1

    Heyy man! This is a very nice tutorial for numba! There are only few numba tutorials out there and I hope you could make a bit more. For example, I became interested in using numba to speed up my Runge-Kutta Algorithms that I coded myself, but I couldn't make it work. I would try to apply it on the for-loop part but it would throw an error that numba doesn't now the class function, something like that.
    Hopefully, an extensive numba tutorial would be made in the future.

  • @usualunusualkid7149
    @usualunusualkid7149 3 ปีที่แล้ว

    I primarily use Python to solve Project Euler problems, and while this library makes the code faster it also gives the wrong result. The other comments say it worked nicely for them though, so good for them.

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว

      Can you elaborate? I'm curious why the result would be wrong. Maybe you can share a gist I can look at?

    • @usualunusualkid7149
      @usualunusualkid7149 3 ปีที่แล้ว

      @@JackofSome
      Sadly I don't have GitHub, and I don't have the exact code I tested it on either, so I will paste some example code here:
      def matrixmulti(a, b):
      return [[sum([a[row][i] * b[i][column] for i in range(len(b))]) for column in range(len(b[0]))] for row in range(len(a))]
      def matrixmod(matrix, mod):
      return [[matrix[row][column] % mod for column in range(len(matrix[0]))] for row in range(len(matrix))]
      def matrixexp(matrix, exp, mod):
      if exp == 0:
      return [[int(row == column) for column in range(len(matrix))] for row in range(len(matrix))]
      matrixsqr = matrixmod(matrixmulti(matrix, matrix), mod)
      if exp % 2 == 0:
      return matrixexp(matrixsqr, exp // 2, mod)
      else:
      return matrixmod(matrixmulti(matrix, matrixexp(matrixsqr, exp // 2, mod)), mod)
      print(matrixexp([[1, 1], [1, 0]], 12345678910, 1000)[0][0])
      When this code is run, it prints out the last 3 digits of 12345678910th Fibonacci number (I tested this code with smaller values instead of 12345678910 and it works fine). Normally, it prints out 689. However when I apply the @numba.jit decorators to all 3 functions, it prints out 512.
      Note: I used matrix multiplication to calculate the numbers (en.wikipedia.org/wiki/Fibonacci_number#Matrix_form)

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +1

      Oh, this is probably overflow.

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +2

      Looks like that's still an open issue with Numba. Unfortunate.
      github.com/numba/numba/issues/5005

  • @MrProzaki
    @MrProzaki 3 ปีที่แล้ว +1

    oh nice, you just gave me lots of work to do xDDDD time to change the whole project code... thanks :'D , no really i mean it THANK YOU it was a great vid will def look into that 10% for sure.

  • @famaral42
    @famaral42 3 ปีที่แล้ว +1

    Thank very much for your insights! Clear explanations and with examples (I run from documentations :p )

  • @erkanturan7215
    @erkanturan7215 2 ปีที่แล้ว

    Perfect video! Are you really writing that fast or do you talk over the fast-forwarded video? I would go for the second one but then I saw you going like "this one" or "that one" with the cursor and I am not sure anymore :)

    • @JackofSome
      @JackofSome  2 ปีที่แล้ว

      It's probably the magic of editing. I'm against wasting the viewer's time so I edit like a crazy person. I can navigate code pretty fast though so it's possible some stuff was actually real time

  • @culperat
    @culperat 2 ปีที่แล้ว

    Love the video, I'll definitely have to try this on some future projects.

  • @geraldmerkowitz4360
    @geraldmerkowitz4360 ปีที่แล้ว

    Thanks for the tip, let's try it!

  • @SourabhBhat
    @SourabhBhat 3 ปีที่แล้ว +1

    I rewrote your first code in Java (imperative-style):
    int[ ] function(int[ ] input) {
    int N = input.length;
    int[ ] output = new int[N];
    for (int i = 0; i < N; i++) {
    output[i] = input[i] % 2 == 0 ? 2 : 1;
    }
    return output;
    }
    --- and ---
    Modern-Java (functional style):
    int[ ] function(int[ ] input) {
    return IntStream.of(input)
    .map(e -> (e % 2 == 0) ? 2 : 1)
    .toArray();
    }
    ---
    It takes an average time of about *0.38065 ms*, for the above serial code, on Intel i5 6200U @ 2.3GHz (which is of the same order as Numba). I took an average of 1000 calls, so that Java JIT compiles it, probably the _%time_ uses an average in similar way.

  • @robosergTV
    @robosergTV 3 ปีที่แล้ว

    this is golden. You explain stuff very clearly and easy to understand. Please do more vids :)
    ps. do you still playing around with Reinforcement Learning? Does your job relate to it in any way?

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +1

      Unfortunately that's a no on both counts. I do lots of deep learning work in my job but it's all related to object detection.

  • @Shane1994322
    @Shane1994322 3 ปีที่แล้ว

    This video is concise and clear. amazing. Thank you!

  • @pward17
    @pward17 3 ปีที่แล้ว

    Dude your great. Is that suckless window manager? You know I find videos all the time where they just aren't at the right level for me but this was just perfect pace, perfect insight. No fat just perfect. Reading other comments it seems im not alone as well. Thanks.

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว

      "No fat"
      That should be my channel motto

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว

      That's not suckless. Just straight up i3-gaps

    • @pward17
      @pward17 3 ปีที่แล้ว

      @@JackofSome oh cool I use it myself just didnt recognize it I've been using the manjaro build of i3 for so long. What distro do you use if I may ask?

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว

      I forget what this was, probably Manjaro. The DE here is xfce and i3 is there as its window manager

  • @ianh5537
    @ianh5537 3 ปีที่แล้ว

    Awesome, thanks! Definitely going to start leveraging mumba!

  • @anon10101
    @anon10101 3 ปีที่แล้ว +2

    This is, as DJ Khaled would say, a major key. wow.

    • @iosbase
      @iosbase 3 ปีที่แล้ว

      "Another one!" - Numba Fan Number 1

  • @Arnichoutoutou
    @Arnichoutoutou ปีที่แล้ว

    Wow thats hot, why am I just learning this now

  • @TunkFey
    @TunkFey 3 ปีที่แล้ว

    Thanks for sharing. This video is really a treasure!

  • @Firigion
    @Firigion 3 ปีที่แล้ว

    Okay, I'm hooked. Now i just need this for DDEs.

  • @juanjpnv
    @juanjpnv 3 ปีที่แล้ว

    Thanks, that'll be really helpful to my masters course

  • @6872elpado
    @6872elpado 3 ปีที่แล้ว

    This is very interesting, but I wanted to add something. Errors in the output can be very difficult to spot when parallelizing! I had many times that the function run fine without errors, but the output was completely wrong. Long story short, when you use parallel=True with prange make sure to also check the output!

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +1

      Can't like this comment enough. This is where automated tests / regression tests can really shine as well.
      In the video I did the bare minimum which is plotting the output and squinting and saying "yeah that looks right"

    • @6872elpado
      @6872elpado 3 ปีที่แล้ว

      @@JackofSome You are absolutely right. I'm actually implementing now least squares non linear fitting with quite large problems where I fit sums of 3D gaussians to multiple peaks (= 8*number of peaks fitting parameters) and the two key things were constraining the problem AND properly parallelizing the model.

  • @ImtihanAhmed
    @ImtihanAhmed 3 ปีที่แล้ว

    Numba might just have fixed my biggest bottleneck on the computation for my master's thesis :)

  • @realabrar
    @realabrar 3 ปีที่แล้ว

    I'm crying. Thanks Sir

  • @fadillahmaani7413
    @fadillahmaani7413 4 ปีที่แล้ว +2

    Great video, thank you very much ! I hope that you will make numba tutorial for class too.

  • @prashanthb6521
    @prashanthb6521 4 ปีที่แล้ว +14

    I cant thank you enough for this. Still THANKS :)

    • @JackofSome
      @JackofSome  4 ปีที่แล้ว +4

      Thank you for watching. You can also thank me by sharing this with others that might be interested 🙂

  • @Mostafa-cv8jc
    @Mostafa-cv8jc 2 ปีที่แล้ว

    This is so good that almost made me cry! crazy

  • @KANGAR1982
    @KANGAR1982 3 ปีที่แล้ว

    Great video! subscribed instantly after seeing it!!!

  • @itsTyrion
    @itsTyrion 3 ปีที่แล้ว +2

    I'd love to know the performance difference between Numba and Cython.
    Great vid

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +5

      As far as I know Cython can always outperform numba if someone knowledgeable enough is writing the code but I think numba will always win when you want to put in very little effort.

    • @Alche_mist
      @Alche_mist 3 ปีที่แล้ว

      It might be also interesting to know the comparison not only between Numba and Cython, but also with other common option of "Writing it in Julia".

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +1

      I actually did write it in Julia in my Julia video 😅. They were close. With some optimization Julia could be faster as well

  • @marcusdudebro9426
    @marcusdudebro9426 3 ปีที่แล้ว +1

    This is big. How did I not know this existed.

  • @VictorRodriguez-zp2do
    @VictorRodriguez-zp2do 3 ปีที่แล้ว +1

    Basically it makes you have to things the way you would in C or C++, in my opinion just using a faster typed language would make more sense. The only problem is that right now the majority of libraries and work for scientific work is being done in python when it should be done in fast, typed, compiled languages.

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว +1

      The majority of libraries that are used for scientific work in python are written using C or C++, with thin python wrappers (e.g. numpy, scipy, opencv, tensorflow, etc)
      Numba code deviates ever so slightly from python norms. It in no way looks as tedious as performant C or C++ code (especially considering you can use numpy code in numba functions)

  • @dyrevennen
    @dyrevennen 3 ปีที่แล้ว

    Thanks for posting the video. I learned something new, and useful.:)

  • @frankkoslowski6917
    @frankkoslowski6917 ปีที่แล้ว

    Inspirational ! 😇
    Yes, C++ is good idea, but then then comes all the compiling with a well behaved compiler that suits the code. 😢

  • @muhammadumaranzar3431
    @muhammadumaranzar3431 2 ปีที่แล้ว

    Amazing explanation

  • @rodrigoctgouvea
    @rodrigoctgouvea 3 ปีที่แล้ว

    Thanks for the video.

  • @Guilfordust
    @Guilfordust 4 ปีที่แล้ว +5

    This was great, thank you!

  • @harshraj22_
    @harshraj22_ 4 ปีที่แล้ว +1

    Awesome ! Thanks for this video.

  • @MarsCorporations
    @MarsCorporations 3 ปีที่แล้ว

    Mr. Scott says: use the right tool for the right job. Python is not the right tool for computational heavy tasks and C++ is not the right tool for fancy graphics in a single line of code.

    • @JackofSome
      @JackofSome  3 ปีที่แล้ว

      Is Numba the right tool for computationally heavy tasks? Cython? How about straight up C++ with a python wrapper?
      Python isn't a monolith. Also pure python is pretty terrible for fancy graphics but that's a different story.

  • @justinb3781
    @justinb3781 3 ปีที่แล้ว

    this is python with turbo lag, i love it

  • @mohegyux4072
    @mohegyux4072 ปีที่แล้ว

    top notch tutorial

  • @vanviethieuanh2237
    @vanviethieuanh2237 2 ปีที่แล้ว

    your tutorial is amazing, thanks!