Turn off list reflection in Numba










0















I'm trying to accelerate my code using Numba. One of the arguments I'm passing into the function is a mutable list of lists. When I try changing one of the sublists, I get this error:




Failed in nopython mode pipeline (step: nopython mode backend)
cannot reflect element of reflected container: reflected list(reflected list(int64))




I don't actually care about reflecting changes I make to the native list into the original Python list. How do I go about telling Numba not to reflect the changes? The documentation is pretty vague regarding list reflection in Numba.



Thanks,










share|improve this question




























    0















    I'm trying to accelerate my code using Numba. One of the arguments I'm passing into the function is a mutable list of lists. When I try changing one of the sublists, I get this error:




    Failed in nopython mode pipeline (step: nopython mode backend)
    cannot reflect element of reflected container: reflected list(reflected list(int64))




    I don't actually care about reflecting changes I make to the native list into the original Python list. How do I go about telling Numba not to reflect the changes? The documentation is pretty vague regarding list reflection in Numba.



    Thanks,










    share|improve this question


























      0












      0








      0








      I'm trying to accelerate my code using Numba. One of the arguments I'm passing into the function is a mutable list of lists. When I try changing one of the sublists, I get this error:




      Failed in nopython mode pipeline (step: nopython mode backend)
      cannot reflect element of reflected container: reflected list(reflected list(int64))




      I don't actually care about reflecting changes I make to the native list into the original Python list. How do I go about telling Numba not to reflect the changes? The documentation is pretty vague regarding list reflection in Numba.



      Thanks,










      share|improve this question
















      I'm trying to accelerate my code using Numba. One of the arguments I'm passing into the function is a mutable list of lists. When I try changing one of the sublists, I get this error:




      Failed in nopython mode pipeline (step: nopython mode backend)
      cannot reflect element of reflected container: reflected list(reflected list(int64))




      I don't actually care about reflecting changes I make to the native list into the original Python list. How do I go about telling Numba not to reflect the changes? The documentation is pretty vague regarding list reflection in Numba.



      Thanks,







      python numba






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 7:05









      Torxed

      13.5k105689




      13.5k105689










      asked Nov 15 '18 at 7:04









      Alec TarashanskyAlec Tarashansky

      469




      469






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Quoting directly from the docs:




          In nopython mode, Numba does not operate on Python objects. list are
          compiled into an internal representation. Any list arguments must be
          converted into this representation on the way in to nopython mode and
          their contained elements must be restored in the original Python
          objects via a process called reflection.



          Reflection is required to maintain the same semantics as found in
          regular Python code. However, the reflection process can be expensive
          for large lists and it is not supported for lists that contain
          reflected data types. Users cannot use list-of-list as an argument
          because of this limitation.




          Your best bet would be to give a 2D numpy array of shape len(ll) x max(len(x) for x in ll), ll being the list of lists. I myself use something like this to achieve this, and then pass the arr, lengths to the njit compiled function:



          def make_2D_array(lis):
          """Funciton to get 2D array from a list of lists
          """
          n = len(lis)
          lengths = np.array([len(x) for x in lis])
          max_len = max(lengths)
          arr = np.zeros((n, max_len))

          for i in range(n):
          arr[i, :lengths[i]] = lis[i]
          return arr, lengths


          HTH.






          share|improve this answer
























            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/3.0/"u003ecc by-sa 3.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%2f53314071%2fturn-off-list-reflection-in-numba%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









            1














            Quoting directly from the docs:




            In nopython mode, Numba does not operate on Python objects. list are
            compiled into an internal representation. Any list arguments must be
            converted into this representation on the way in to nopython mode and
            their contained elements must be restored in the original Python
            objects via a process called reflection.



            Reflection is required to maintain the same semantics as found in
            regular Python code. However, the reflection process can be expensive
            for large lists and it is not supported for lists that contain
            reflected data types. Users cannot use list-of-list as an argument
            because of this limitation.




            Your best bet would be to give a 2D numpy array of shape len(ll) x max(len(x) for x in ll), ll being the list of lists. I myself use something like this to achieve this, and then pass the arr, lengths to the njit compiled function:



            def make_2D_array(lis):
            """Funciton to get 2D array from a list of lists
            """
            n = len(lis)
            lengths = np.array([len(x) for x in lis])
            max_len = max(lengths)
            arr = np.zeros((n, max_len))

            for i in range(n):
            arr[i, :lengths[i]] = lis[i]
            return arr, lengths


            HTH.






            share|improve this answer





























              1














              Quoting directly from the docs:




              In nopython mode, Numba does not operate on Python objects. list are
              compiled into an internal representation. Any list arguments must be
              converted into this representation on the way in to nopython mode and
              their contained elements must be restored in the original Python
              objects via a process called reflection.



              Reflection is required to maintain the same semantics as found in
              regular Python code. However, the reflection process can be expensive
              for large lists and it is not supported for lists that contain
              reflected data types. Users cannot use list-of-list as an argument
              because of this limitation.




              Your best bet would be to give a 2D numpy array of shape len(ll) x max(len(x) for x in ll), ll being the list of lists. I myself use something like this to achieve this, and then pass the arr, lengths to the njit compiled function:



              def make_2D_array(lis):
              """Funciton to get 2D array from a list of lists
              """
              n = len(lis)
              lengths = np.array([len(x) for x in lis])
              max_len = max(lengths)
              arr = np.zeros((n, max_len))

              for i in range(n):
              arr[i, :lengths[i]] = lis[i]
              return arr, lengths


              HTH.






              share|improve this answer



























                1












                1








                1







                Quoting directly from the docs:




                In nopython mode, Numba does not operate on Python objects. list are
                compiled into an internal representation. Any list arguments must be
                converted into this representation on the way in to nopython mode and
                their contained elements must be restored in the original Python
                objects via a process called reflection.



                Reflection is required to maintain the same semantics as found in
                regular Python code. However, the reflection process can be expensive
                for large lists and it is not supported for lists that contain
                reflected data types. Users cannot use list-of-list as an argument
                because of this limitation.




                Your best bet would be to give a 2D numpy array of shape len(ll) x max(len(x) for x in ll), ll being the list of lists. I myself use something like this to achieve this, and then pass the arr, lengths to the njit compiled function:



                def make_2D_array(lis):
                """Funciton to get 2D array from a list of lists
                """
                n = len(lis)
                lengths = np.array([len(x) for x in lis])
                max_len = max(lengths)
                arr = np.zeros((n, max_len))

                for i in range(n):
                arr[i, :lengths[i]] = lis[i]
                return arr, lengths


                HTH.






                share|improve this answer















                Quoting directly from the docs:




                In nopython mode, Numba does not operate on Python objects. list are
                compiled into an internal representation. Any list arguments must be
                converted into this representation on the way in to nopython mode and
                their contained elements must be restored in the original Python
                objects via a process called reflection.



                Reflection is required to maintain the same semantics as found in
                regular Python code. However, the reflection process can be expensive
                for large lists and it is not supported for lists that contain
                reflected data types. Users cannot use list-of-list as an argument
                because of this limitation.




                Your best bet would be to give a 2D numpy array of shape len(ll) x max(len(x) for x in ll), ll being the list of lists. I myself use something like this to achieve this, and then pass the arr, lengths to the njit compiled function:



                def make_2D_array(lis):
                """Funciton to get 2D array from a list of lists
                """
                n = len(lis)
                lengths = np.array([len(x) for x in lis])
                max_len = max(lengths)
                arr = np.zeros((n, max_len))

                for i in range(n):
                arr[i, :lengths[i]] = lis[i]
                return arr, lengths


                HTH.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 15 '18 at 7:40

























                answered Nov 15 '18 at 7:25









                Deepak SainiDeepak Saini

                1,599815




                1,599815





























                    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%2f53314071%2fturn-off-list-reflection-in-numba%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

                    Top Tejano songwriter Luis Silva dead of heart attack at 64

                    政党

                    天津地下鉄3号線