Announcement

Collapse
No announcement yet.

HOPE: The Ease Of Python With The Speed Of C++

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #91
    Originally posted by erendorn View Post
    Out of curiosity, what happens in python if it is not?
    It depends on exactly what approach you use. In my case, I used the "index" method. This returns the index of the object in the list, or raises an exception if it isn't there. You can also just check for the presence of the item in the list, which returns a boolean. But in this case that would require searching the list twice (once to check if the object is present, and a second time to get its index), so I just used the method with an exception handler.

    Comment


    • #92
      Originally posted by pal666 View Post
      i didn't ask you why do you need those 7 lines. i told you that in c++ you need only one to do same thing.
      My point is that the one line example you gave does not do the same thing.

      Comment


      • #93
        Originally posted by kigurai View Post
        Let's just say I am not impressed with syntax if it confuses someone with the level of C++ knowledge I have.


        There might be numerous reasons why you can't use anything not in the standard lib. Regardless of which, standard functionality is what was discussed, not third party libraries, e.g. boost.


        There might be parts of the standard library that is only available in CPython. As far as I know, those exceptions are extremly rare for all relevant implementations.
        For all practical purposes, CPython is the standard, and thus the entire standard library is available everywhere Python is installed.
        (Also, in the example used, no module was used, so in this specific case the argument is moot)
        for all practical purposes cpython is reference implementation. there is no standard. you can have your reference implementation of "gcc+boost". there can be endless imaginable reasons to do any stupid thing, but then it is only your problem. btw, all boost functionality is possible to reimplement manually. i.e. you still could use same syntax without boost. which is what i was referring to in first message on the matter. btw, ranges are going to be added to standard library https://ericniebler.github.io/std/wg21/D4128.html and it will be real standard by international organization for standardization and not a 'standard' by ppl who happen make cpython.

        Comment


        • #94
          Why even bother with C++ or Python when you have Julia which is much faster/easier than both and is heavily optimized for this kind of task? Julia was created for this type of problem so it doesn't make sense to not use it. If you are using C++/Python for this kind of thing then you are using a hammer to drive a screw. Julia even features an interactive mode where you can write your program interactively like programming a calculator, then output the results in a fancy graph/plot/chart.

          Code:
          # Implements squared for integers.
          squared(x::Int) = x^2
          
          # Implements squared for Array{Int,1}, aka [1,2,3].
          function squared(numbers::Array{Int,1})
          	squaredNums = Int[]
          	for x in numbers push!(squaredNums, squared(x)) end
          	return squaredNums
          end
          
          # Implements squared for UnitRange{Int}, aka 1:10.
          function squared(numbers::UnitRange{Int})
          	squaredNums = Int[]
          	for x in numbers push!(squaredNums, squared(x)) end
          	return squaredNums
          end
          
          # average returns the average of an Int array.
          average(x::Array{Int,1}) = sum(x) / length(x)
          
          # returns the value of the Golden Ratio.
          goldenRatio() = (1 + 5^0.5) / 2
          Code:
          julia> squared(10)
          100
          
          julia> squared([1,2,3,4,5])
          5-element Array{Int64,1}:
            1
            4
            9
           16
           25
          
          julia> squared(1:10)
          10-element Array{Int64,1}:
             1
             4
             9
            16
            25
            36
            49
            64
            81
           100
          
          julia> average(squared(1:100))
          3383.5
          
          julia> sum(squared(1:1000))
          333833500
          
          julia> goldenRatio()
          1.618033988749895

          Comment


          • #95
            Originally posted by mmstick View Post
            Why even bother with C++ or Python when you have Julia which is much faster/easier than both and is heavily optimized for this kind of task?
            1. you can't be much faster than c++, that is bullshit
            2. c++ is general purpose language, you can do any task in it.
            3. c++ features backward compatibility. nobody is going to rewrite all of their code just because some random language of the day spawned. compatibility all the way back to plain c is the main reason for c++ syntax issues.
            4. i know nothing about julia, no doubt there are many more downsides to it.

            Comment


            • #96
              Originally posted by mmstick View Post
              Why even bother with C++ or Python when you have Julia which is much faster/easier than both and is heavily optimized for this kind of task? Julia was created for this type of problem so it doesn't make sense to not use it. If you are using C++/Python for this kind of thing then you are using a hammer to drive a screw.
              Four primary reasons, at least for me:
              1. (most important) Python has a much larger software community, with a much larger software ecosystem, and a lot more tools available. Further, those tools tend to be more mature, more tested, and have more help and documentation available. Its future is also a lot more certain due to the much larger community and much larger commercial stake in the language.
              2. Being a general-purpose language, it has a lot of tools for dealing with things besides just data analysis. Things like file and directory handling, interacting with online data, and accessing network resources are all much easier in python and are all very common when doing data analysis. When I am doing data analysis, I am almost never doing just data analysis. I need to find files, manipulate files, save files, often dozens if not thousands. So being a general-purpose language is actually a huge benefit.
              3. It seems that most of the new ideas are coming from python in terms of basic ways to work with data. Julia has some interesting ideas with performance, but in terms of data structures and graphics interfaces most of the development is happening in python and then, sometimes, is later ported to Julia (while the python version continues to advance).
              4. Generally the slow code paths are already in C++ (which is still far faster than Julia), so Python performance is not usually a major bottleneck for me.
              5. (much less important) I very much prefer python syntax. Julia is primarily a Matlab clone in terms of syntax. It fixes a few bone-headed Mathworks decisions and has a few Python features tacked on, but overall it is pretty much the same as Matlab in almost all areas.


              So I am keeping my eye on Julia, just as I am keeping my eye on efforts to improve python performance. But at the present time the performance improvement isn't worth all the other downsides.

              Originally posted by mmstick View Post
              Julia even features an interactive mode where you can write your program interactively like programming a calculator, then output the results in a fancy graph/plot/chart.
              That is called a REPL (read-eval-print-loop). It was first developed for Lisp decades ago. Python has had one all along (as has matlab, haskell, and probably dozens of other languages). And Python's IPython shell is much more advanced than anything available from Julia (although you can run Julia code in IPython, that is not its native language).
              Last edited by TheBlackCat; 21 October 2014, 11:19 AM.

              Comment


              • #97
                Originally posted by pal666 View Post
                1. you can't be much faster than c++, that is bullshit
                2. c++ is general purpose language, you can do any task in it.
                3. c++ features backward compatibility. nobody is going to rewrite all of their code just because some random language of the day spawned. compatibility all the way back to plain c is the main reason for c++ syntax issues.
                4. i know nothing about julia, no doubt there are many more downsides to it.
                1) You're really naive. Fortran is faster than C which is faster than C++. Julia makes heavy use of the best of C and Fortran math libraries so it is close to Fortran performance.
                2) That's not the point. C++ is an ugly bloated mess of inconsistency that only someone with years of experience can properly understand. In the real world, people prefer simplification over complification. C++ needs to die sooner rather than later. C++ certainly isn't made for scientific computing either, which Julia is.
                3) Again, irrelevant. There's no need to rewrite the bulk of code when you can import an existing Fortran/C library which you are probably already using in another language. Not to mention, because writing your code in Julia is easier to read and write you have more time to work on optimizing your algorithms.
                4) Then don't be a dumbass and learn about it.

                Comment


                • #98
                  Originally posted by mmstick View Post
                  1) You're really naive. Fortran is faster than C which is faster than C++. Julia makes heavy use of the best of C and Fortran math libraries so it is close to Fortran performance.
                  So does Python and C++ (and matlab). The libraries are pretty much standard. Julia's advantage isn't the libraries, it is that it uses multiple dispatch to allow optimized code paths for different data types. That gives it speed slower than C or C++, but usually faster than cpython (and to a lesser extent Pypy).

                  Comment


                  • #99
                    Originally posted by TheBlackCat View Post
                    So does Python and C++ (and matlab). The libraries are pretty much standard. Julia's advantage isn't the libraries, it is that it uses multiple dispatch to allow optimized code paths for different data types. That gives it speed slower than C or C++, but usually faster than cpython (and to a lesser extent Pypy).
                    If you want to claim that it is slower then explain the benchmark results which demonstrate otherwise.

                    Comment


                    • Originally posted by mmstick View Post
                      If you want to claim that it is slower then explain the benchmark results which demonstrate otherwise.
                      All the benchmarks I have seen put Julia's performance at about 6 times slower than C or C++. Do you have benchmarks showing Julia with better performance than C or C++ using the same libraires?

                      Comment

                      Working...
                      X