Why does ordering of dependent numba jitt'ed functions matter?What is the difference between contiguous and non-contiguous arrays?Numba - How to fill 2D array in parallelWhy does comparing strings using either '==' or 'is' sometimes produce a different result?Creating a singleton in PythonWhy does Python code run faster in a function?numba error when using scipy.specialHow to specify function signature for a method using custom types in numbaHow to call ctypes functions that use pointer to return value in Numba @jitFastest way to compute a factorial in a numba nopython functionCompare strings in numba-compiled functionNumpy attributes not recognized in NumbaLinear Combinations of Numba jitted functions in nopython mode

I reverse the source code, you negate the input!

Manager manipulates my leaves, what's in it for him?

US entry with tourist visa but past alcohol arrest

The 100 soldier problem

Would Taiwan and China's dispute be solved if Taiwan gave up being the Republic of China?

Is there a connection between IT and Ghostbusters?

Automate tasks with Lambdas in java

What do solvers like Gurobi and CPLEX do when they run into hard instances of MIP

Resolving moral conflict

Applications of mathematics in clinical setting

As an employer, can I compel my employees to vote?

Removing rows containing NA in every column

Writing a letter of recommendation for a mediocre student

How to ask a man to not take up more than one seat on public transport while avoiding conflict?

Why are Fuji lenses more expensive than others?

How can I prevent soul energy from dissipating?

Do the villains know Batman has no superpowers?

Can one guy with a duplicator initiate a nuclear apocalypse?

Can Northern Ireland's border issue be solved by repartition?

Temporarily moving a SQL Server 2016 database to SQL Server 2017 and then moving back. Is it possible?

What can a pilot do, if an air traffic controller is incapacitated?

What was the deeper meaning of Hermione wanting the cloak?

C# Fastest way to do Array Table Lookup with Integer Index

Shimano 105 FD-R7000-F front dereailleur chain rub



Why does ordering of dependent numba jitt'ed functions matter?


What is the difference between contiguous and non-contiguous arrays?Numba - How to fill 2D array in parallelWhy does comparing strings using either '==' or 'is' sometimes produce a different result?Creating a singleton in PythonWhy does Python code run faster in a function?numba error when using scipy.specialHow to specify function signature for a method using custom types in numbaHow to call ctypes functions that use pointer to return value in Numba @jitFastest way to compute a factorial in a numba nopython functionCompare strings in numba-compiled functionNumpy attributes not recognized in NumbaLinear Combinations of Numba jitted functions in nopython mode






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















In python you can define multiple functions that call each other in any order, and at runtime the functions will be called on. The order that these functions are defined in a script doesn't matter, once they exist. For example, the below is valid and will work



import numpy as np

def func1(arr):
out = np.empty_like(arr)
for i in range(arr.shape[0]):
out[i] = func2(arr[i]) # calling func2 here which is defined below
return out

def func2(a):
out = a + 1
return out


func1 can call on func2 even though func2 is defined after func1.



However, if I decorate these functions with numba, I get an error



import numpy as np
import numba as nb


@nb.jit("f8[:](f8[:])", nopython=True)
def func1(arr):
out = np.empty_like(arr)
for i in range(arr.shape[0]):
out[i] = func2(arr[i])
return out

@nb.jit("f8(f8)", nopython=True)
def func2(a):
out = a + 1
return out

>>> TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name 'func2': cannot determine Numba type of <class
'numba.ir.UndefinedType'>


So numba doesn't know what func2 is when compiling func1 using JIT. Simply switching the order of these functions works though, so that func2 comes before func1



@nb.jit("f8(f8)", nopython=True)
def func2(a):
out = a + 1
return out

@nb.jit("f8[:](f8[:])", nopython=True)
def func1(arr):
out = np.empty_like(arr)
for i in range(arr.shape[0]):
out[i] = func2(arr[i])
return out


Why is this? I have a feeling the pure python mode works because python is dynamically typed and not compiled, whereas numba, using JIT, by definition does compile the functions (and maybe therefore needs perfect knowledge of everything that happens within every function?). But I don't understand why numba doesn't search within the scope for all functions if it comes across a function it hasn't seen.










share|improve this question






























    3















    In python you can define multiple functions that call each other in any order, and at runtime the functions will be called on. The order that these functions are defined in a script doesn't matter, once they exist. For example, the below is valid and will work



    import numpy as np

    def func1(arr):
    out = np.empty_like(arr)
    for i in range(arr.shape[0]):
    out[i] = func2(arr[i]) # calling func2 here which is defined below
    return out

    def func2(a):
    out = a + 1
    return out


    func1 can call on func2 even though func2 is defined after func1.



    However, if I decorate these functions with numba, I get an error



    import numpy as np
    import numba as nb


    @nb.jit("f8[:](f8[:])", nopython=True)
    def func1(arr):
    out = np.empty_like(arr)
    for i in range(arr.shape[0]):
    out[i] = func2(arr[i])
    return out

    @nb.jit("f8(f8)", nopython=True)
    def func2(a):
    out = a + 1
    return out

    >>> TypingError: Failed in nopython mode pipeline (step: nopython frontend)
    Untyped global name 'func2': cannot determine Numba type of <class
    'numba.ir.UndefinedType'>


    So numba doesn't know what func2 is when compiling func1 using JIT. Simply switching the order of these functions works though, so that func2 comes before func1



    @nb.jit("f8(f8)", nopython=True)
    def func2(a):
    out = a + 1
    return out

    @nb.jit("f8[:](f8[:])", nopython=True)
    def func1(arr):
    out = np.empty_like(arr)
    for i in range(arr.shape[0]):
    out[i] = func2(arr[i])
    return out


    Why is this? I have a feeling the pure python mode works because python is dynamically typed and not compiled, whereas numba, using JIT, by definition does compile the functions (and maybe therefore needs perfect knowledge of everything that happens within every function?). But I don't understand why numba doesn't search within the scope for all functions if it comes across a function it hasn't seen.










    share|improve this question


























      3












      3








      3


      1






      In python you can define multiple functions that call each other in any order, and at runtime the functions will be called on. The order that these functions are defined in a script doesn't matter, once they exist. For example, the below is valid and will work



      import numpy as np

      def func1(arr):
      out = np.empty_like(arr)
      for i in range(arr.shape[0]):
      out[i] = func2(arr[i]) # calling func2 here which is defined below
      return out

      def func2(a):
      out = a + 1
      return out


      func1 can call on func2 even though func2 is defined after func1.



      However, if I decorate these functions with numba, I get an error



      import numpy as np
      import numba as nb


      @nb.jit("f8[:](f8[:])", nopython=True)
      def func1(arr):
      out = np.empty_like(arr)
      for i in range(arr.shape[0]):
      out[i] = func2(arr[i])
      return out

      @nb.jit("f8(f8)", nopython=True)
      def func2(a):
      out = a + 1
      return out

      >>> TypingError: Failed in nopython mode pipeline (step: nopython frontend)
      Untyped global name 'func2': cannot determine Numba type of <class
      'numba.ir.UndefinedType'>


      So numba doesn't know what func2 is when compiling func1 using JIT. Simply switching the order of these functions works though, so that func2 comes before func1



      @nb.jit("f8(f8)", nopython=True)
      def func2(a):
      out = a + 1
      return out

      @nb.jit("f8[:](f8[:])", nopython=True)
      def func1(arr):
      out = np.empty_like(arr)
      for i in range(arr.shape[0]):
      out[i] = func2(arr[i])
      return out


      Why is this? I have a feeling the pure python mode works because python is dynamically typed and not compiled, whereas numba, using JIT, by definition does compile the functions (and maybe therefore needs perfect knowledge of everything that happens within every function?). But I don't understand why numba doesn't search within the scope for all functions if it comes across a function it hasn't seen.










      share|improve this question














      In python you can define multiple functions that call each other in any order, and at runtime the functions will be called on. The order that these functions are defined in a script doesn't matter, once they exist. For example, the below is valid and will work



      import numpy as np

      def func1(arr):
      out = np.empty_like(arr)
      for i in range(arr.shape[0]):
      out[i] = func2(arr[i]) # calling func2 here which is defined below
      return out

      def func2(a):
      out = a + 1
      return out


      func1 can call on func2 even though func2 is defined after func1.



      However, if I decorate these functions with numba, I get an error



      import numpy as np
      import numba as nb


      @nb.jit("f8[:](f8[:])", nopython=True)
      def func1(arr):
      out = np.empty_like(arr)
      for i in range(arr.shape[0]):
      out[i] = func2(arr[i])
      return out

      @nb.jit("f8(f8)", nopython=True)
      def func2(a):
      out = a + 1
      return out

      >>> TypingError: Failed in nopython mode pipeline (step: nopython frontend)
      Untyped global name 'func2': cannot determine Numba type of <class
      'numba.ir.UndefinedType'>


      So numba doesn't know what func2 is when compiling func1 using JIT. Simply switching the order of these functions works though, so that func2 comes before func1



      @nb.jit("f8(f8)", nopython=True)
      def func2(a):
      out = a + 1
      return out

      @nb.jit("f8[:](f8[:])", nopython=True)
      def func1(arr):
      out = np.empty_like(arr)
      for i in range(arr.shape[0]):
      out[i] = func2(arr[i])
      return out


      Why is this? I have a feeling the pure python mode works because python is dynamically typed and not compiled, whereas numba, using JIT, by definition does compile the functions (and maybe therefore needs perfect knowledge of everything that happens within every function?). But I don't understand why numba doesn't search within the scope for all functions if it comes across a function it hasn't seen.







      python jit numba






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 14:30









      PyRsquaredPyRsquared

      1,9892 gold badges22 silver badges36 bronze badges




      1,9892 gold badges22 silver badges36 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          3
















          Short version - delete the "f8[:](f8[:])"



          Your intuition is right. Python functions are looked up at call time, which is why they can be defined out of order. Looking at the python bytecode with a dis (disassembly) module make this clear - the name b is looked up as a global each time function a is called.



          def a():
          return b()

          def b():
          return 2

          import dis
          dis.dis(a)
          # 2 0 LOAD_GLOBAL 0 (b)
          # 2 CALL_FUNCTION 0
          # 4 RETURN_VALUE


          In nopython mode, numba needs to statically know the address of each function that is being called - this makes the code fast (no longer doing a runtime lookup), and also opens the door to other optimizations, like inlining.



          That said, numba can handle this case. By specifying the type signature ("f8[:](f8[:])"), you are forcing ahead of time compilation. Omit it, and a number will defer to the first function call it and it will work.






          share|improve this answer

























          • Thanks for the explanation. I did notice that by omitting the signature (but still decorating the function with jit) seemed to work. However for my use case I'll leave the signature because I want to get the proper error messages incase some incorrect type is passed to the function before I start operating on it. Thanks again!

            – PyRsquared
            Mar 28 at 20:22






          • 1





            @PyRsquared Please note also that explicitly declaring non contiguous arrays [:] usually prevents SIMD-vectorization and can lead to slower runtimes (just replace out = a + 1 by out = np.sin(a) to see a quite noticeable effect. But if you explicitly declare contiguous arrays [::1] the function won't work on non-contigous arrays anymore....

            – max9111
            Mar 29 at 8:20











          • @max9111 Excellent observation, thanks! So in this case here, for optimal performance (using SIMD), you suggest using f[::1] ? I'm not entirely sure how numpy arrays are stored in memory, but for 1D case surely they are contiguous?

            – PyRsquared
            Mar 29 at 10:40






          • 1





            @PyRsquared You can check this things with ndarray.flags (eg. A=B[0:-1:2] -> A is a non contiguous view on B). Well you have to choose it. If it is OK for you limit the function to contiguous arrays... Another possibility is to use np.ascontiguousarray, but this has the downside of copying an array. Sometimes you want to explicitly create a contiguous copy eg. stackoverflow.com/a/55405644/4045774, sometimes not. It depends on the algorithm...

            – max9111
            Mar 29 at 14:01










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400141%2fwhy-does-ordering-of-dependent-numba-jitted-functions-matter%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3
















          Short version - delete the "f8[:](f8[:])"



          Your intuition is right. Python functions are looked up at call time, which is why they can be defined out of order. Looking at the python bytecode with a dis (disassembly) module make this clear - the name b is looked up as a global each time function a is called.



          def a():
          return b()

          def b():
          return 2

          import dis
          dis.dis(a)
          # 2 0 LOAD_GLOBAL 0 (b)
          # 2 CALL_FUNCTION 0
          # 4 RETURN_VALUE


          In nopython mode, numba needs to statically know the address of each function that is being called - this makes the code fast (no longer doing a runtime lookup), and also opens the door to other optimizations, like inlining.



          That said, numba can handle this case. By specifying the type signature ("f8[:](f8[:])"), you are forcing ahead of time compilation. Omit it, and a number will defer to the first function call it and it will work.






          share|improve this answer

























          • Thanks for the explanation. I did notice that by omitting the signature (but still decorating the function with jit) seemed to work. However for my use case I'll leave the signature because I want to get the proper error messages incase some incorrect type is passed to the function before I start operating on it. Thanks again!

            – PyRsquared
            Mar 28 at 20:22






          • 1





            @PyRsquared Please note also that explicitly declaring non contiguous arrays [:] usually prevents SIMD-vectorization and can lead to slower runtimes (just replace out = a + 1 by out = np.sin(a) to see a quite noticeable effect. But if you explicitly declare contiguous arrays [::1] the function won't work on non-contigous arrays anymore....

            – max9111
            Mar 29 at 8:20











          • @max9111 Excellent observation, thanks! So in this case here, for optimal performance (using SIMD), you suggest using f[::1] ? I'm not entirely sure how numpy arrays are stored in memory, but for 1D case surely they are contiguous?

            – PyRsquared
            Mar 29 at 10:40






          • 1





            @PyRsquared You can check this things with ndarray.flags (eg. A=B[0:-1:2] -> A is a non contiguous view on B). Well you have to choose it. If it is OK for you limit the function to contiguous arrays... Another possibility is to use np.ascontiguousarray, but this has the downside of copying an array. Sometimes you want to explicitly create a contiguous copy eg. stackoverflow.com/a/55405644/4045774, sometimes not. It depends on the algorithm...

            – max9111
            Mar 29 at 14:01















          3
















          Short version - delete the "f8[:](f8[:])"



          Your intuition is right. Python functions are looked up at call time, which is why they can be defined out of order. Looking at the python bytecode with a dis (disassembly) module make this clear - the name b is looked up as a global each time function a is called.



          def a():
          return b()

          def b():
          return 2

          import dis
          dis.dis(a)
          # 2 0 LOAD_GLOBAL 0 (b)
          # 2 CALL_FUNCTION 0
          # 4 RETURN_VALUE


          In nopython mode, numba needs to statically know the address of each function that is being called - this makes the code fast (no longer doing a runtime lookup), and also opens the door to other optimizations, like inlining.



          That said, numba can handle this case. By specifying the type signature ("f8[:](f8[:])"), you are forcing ahead of time compilation. Omit it, and a number will defer to the first function call it and it will work.






          share|improve this answer

























          • Thanks for the explanation. I did notice that by omitting the signature (but still decorating the function with jit) seemed to work. However for my use case I'll leave the signature because I want to get the proper error messages incase some incorrect type is passed to the function before I start operating on it. Thanks again!

            – PyRsquared
            Mar 28 at 20:22






          • 1





            @PyRsquared Please note also that explicitly declaring non contiguous arrays [:] usually prevents SIMD-vectorization and can lead to slower runtimes (just replace out = a + 1 by out = np.sin(a) to see a quite noticeable effect. But if you explicitly declare contiguous arrays [::1] the function won't work on non-contigous arrays anymore....

            – max9111
            Mar 29 at 8:20











          • @max9111 Excellent observation, thanks! So in this case here, for optimal performance (using SIMD), you suggest using f[::1] ? I'm not entirely sure how numpy arrays are stored in memory, but for 1D case surely they are contiguous?

            – PyRsquared
            Mar 29 at 10:40






          • 1





            @PyRsquared You can check this things with ndarray.flags (eg. A=B[0:-1:2] -> A is a non contiguous view on B). Well you have to choose it. If it is OK for you limit the function to contiguous arrays... Another possibility is to use np.ascontiguousarray, but this has the downside of copying an array. Sometimes you want to explicitly create a contiguous copy eg. stackoverflow.com/a/55405644/4045774, sometimes not. It depends on the algorithm...

            – max9111
            Mar 29 at 14:01













          3














          3










          3









          Short version - delete the "f8[:](f8[:])"



          Your intuition is right. Python functions are looked up at call time, which is why they can be defined out of order. Looking at the python bytecode with a dis (disassembly) module make this clear - the name b is looked up as a global each time function a is called.



          def a():
          return b()

          def b():
          return 2

          import dis
          dis.dis(a)
          # 2 0 LOAD_GLOBAL 0 (b)
          # 2 CALL_FUNCTION 0
          # 4 RETURN_VALUE


          In nopython mode, numba needs to statically know the address of each function that is being called - this makes the code fast (no longer doing a runtime lookup), and also opens the door to other optimizations, like inlining.



          That said, numba can handle this case. By specifying the type signature ("f8[:](f8[:])"), you are forcing ahead of time compilation. Omit it, and a number will defer to the first function call it and it will work.






          share|improve this answer













          Short version - delete the "f8[:](f8[:])"



          Your intuition is right. Python functions are looked up at call time, which is why they can be defined out of order. Looking at the python bytecode with a dis (disassembly) module make this clear - the name b is looked up as a global each time function a is called.



          def a():
          return b()

          def b():
          return 2

          import dis
          dis.dis(a)
          # 2 0 LOAD_GLOBAL 0 (b)
          # 2 CALL_FUNCTION 0
          # 4 RETURN_VALUE


          In nopython mode, numba needs to statically know the address of each function that is being called - this makes the code fast (no longer doing a runtime lookup), and also opens the door to other optimizations, like inlining.



          That said, numba can handle this case. By specifying the type signature ("f8[:](f8[:])"), you are forcing ahead of time compilation. Omit it, and a number will defer to the first function call it and it will work.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 28 at 18:25









          chrisbchrisb

          28k7 gold badges42 silver badges45 bronze badges




          28k7 gold badges42 silver badges45 bronze badges















          • Thanks for the explanation. I did notice that by omitting the signature (but still decorating the function with jit) seemed to work. However for my use case I'll leave the signature because I want to get the proper error messages incase some incorrect type is passed to the function before I start operating on it. Thanks again!

            – PyRsquared
            Mar 28 at 20:22






          • 1





            @PyRsquared Please note also that explicitly declaring non contiguous arrays [:] usually prevents SIMD-vectorization and can lead to slower runtimes (just replace out = a + 1 by out = np.sin(a) to see a quite noticeable effect. But if you explicitly declare contiguous arrays [::1] the function won't work on non-contigous arrays anymore....

            – max9111
            Mar 29 at 8:20











          • @max9111 Excellent observation, thanks! So in this case here, for optimal performance (using SIMD), you suggest using f[::1] ? I'm not entirely sure how numpy arrays are stored in memory, but for 1D case surely they are contiguous?

            – PyRsquared
            Mar 29 at 10:40






          • 1





            @PyRsquared You can check this things with ndarray.flags (eg. A=B[0:-1:2] -> A is a non contiguous view on B). Well you have to choose it. If it is OK for you limit the function to contiguous arrays... Another possibility is to use np.ascontiguousarray, but this has the downside of copying an array. Sometimes you want to explicitly create a contiguous copy eg. stackoverflow.com/a/55405644/4045774, sometimes not. It depends on the algorithm...

            – max9111
            Mar 29 at 14:01

















          • Thanks for the explanation. I did notice that by omitting the signature (but still decorating the function with jit) seemed to work. However for my use case I'll leave the signature because I want to get the proper error messages incase some incorrect type is passed to the function before I start operating on it. Thanks again!

            – PyRsquared
            Mar 28 at 20:22






          • 1





            @PyRsquared Please note also that explicitly declaring non contiguous arrays [:] usually prevents SIMD-vectorization and can lead to slower runtimes (just replace out = a + 1 by out = np.sin(a) to see a quite noticeable effect. But if you explicitly declare contiguous arrays [::1] the function won't work on non-contigous arrays anymore....

            – max9111
            Mar 29 at 8:20











          • @max9111 Excellent observation, thanks! So in this case here, for optimal performance (using SIMD), you suggest using f[::1] ? I'm not entirely sure how numpy arrays are stored in memory, but for 1D case surely they are contiguous?

            – PyRsquared
            Mar 29 at 10:40






          • 1





            @PyRsquared You can check this things with ndarray.flags (eg. A=B[0:-1:2] -> A is a non contiguous view on B). Well you have to choose it. If it is OK for you limit the function to contiguous arrays... Another possibility is to use np.ascontiguousarray, but this has the downside of copying an array. Sometimes you want to explicitly create a contiguous copy eg. stackoverflow.com/a/55405644/4045774, sometimes not. It depends on the algorithm...

            – max9111
            Mar 29 at 14:01
















          Thanks for the explanation. I did notice that by omitting the signature (but still decorating the function with jit) seemed to work. However for my use case I'll leave the signature because I want to get the proper error messages incase some incorrect type is passed to the function before I start operating on it. Thanks again!

          – PyRsquared
          Mar 28 at 20:22





          Thanks for the explanation. I did notice that by omitting the signature (but still decorating the function with jit) seemed to work. However for my use case I'll leave the signature because I want to get the proper error messages incase some incorrect type is passed to the function before I start operating on it. Thanks again!

          – PyRsquared
          Mar 28 at 20:22




          1




          1





          @PyRsquared Please note also that explicitly declaring non contiguous arrays [:] usually prevents SIMD-vectorization and can lead to slower runtimes (just replace out = a + 1 by out = np.sin(a) to see a quite noticeable effect. But if you explicitly declare contiguous arrays [::1] the function won't work on non-contigous arrays anymore....

          – max9111
          Mar 29 at 8:20





          @PyRsquared Please note also that explicitly declaring non contiguous arrays [:] usually prevents SIMD-vectorization and can lead to slower runtimes (just replace out = a + 1 by out = np.sin(a) to see a quite noticeable effect. But if you explicitly declare contiguous arrays [::1] the function won't work on non-contigous arrays anymore....

          – max9111
          Mar 29 at 8:20













          @max9111 Excellent observation, thanks! So in this case here, for optimal performance (using SIMD), you suggest using f[::1] ? I'm not entirely sure how numpy arrays are stored in memory, but for 1D case surely they are contiguous?

          – PyRsquared
          Mar 29 at 10:40





          @max9111 Excellent observation, thanks! So in this case here, for optimal performance (using SIMD), you suggest using f[::1] ? I'm not entirely sure how numpy arrays are stored in memory, but for 1D case surely they are contiguous?

          – PyRsquared
          Mar 29 at 10:40




          1




          1





          @PyRsquared You can check this things with ndarray.flags (eg. A=B[0:-1:2] -> A is a non contiguous view on B). Well you have to choose it. If it is OK for you limit the function to contiguous arrays... Another possibility is to use np.ascontiguousarray, but this has the downside of copying an array. Sometimes you want to explicitly create a contiguous copy eg. stackoverflow.com/a/55405644/4045774, sometimes not. It depends on the algorithm...

          – max9111
          Mar 29 at 14:01





          @PyRsquared You can check this things with ndarray.flags (eg. A=B[0:-1:2] -> A is a non contiguous view on B). Well you have to choose it. If it is OK for you limit the function to contiguous arrays... Another possibility is to use np.ascontiguousarray, but this has the downside of copying an array. Sometimes you want to explicitly create a contiguous copy eg. stackoverflow.com/a/55405644/4045774, sometimes not. It depends on the algorithm...

          – max9111
          Mar 29 at 14:01








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400141%2fwhy-does-ordering-of-dependent-numba-jitted-functions-matter%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해