Live data from Hacker News

Automatic Differentiation with Julia

blog.rogerluo.me

11–20 of 83 posts

Re: Automatic Differentiation with Julia

#11
post #6

Julia is a great language, but I'm still waiting for someone to create a Julia fork that uses 0-based indexing.

So, fun times: if the 1-based indexing throws you off that much, it is entirely straightforward to configure it to use 0 based indexing if you want (or any other kind of offset that you so desire) https://docs.julialang.org/en/latest/devdocs/offset-arrays/ Having said that, I encourage you to try out the 1-based indexing, as I think you might find a lot of things become surprisingly more intuitive.

> or any other kind of offset that you so desire

This is too often the attitude of Julia people. But zero-based indexing is not just some arbitrary offset. Programmers just like it. You say that many things are more intuitive with one-based indexing, but many things are less intuitive too. I don't think python ever would have become popular without zero-based indexing.

The thing is, we really don't know why people prefer certain types of language. All we know is that they do. Computer languages can't evolve gradually like natural languages, but if they could I really don't think we'd go to one-based indexing.

Re: Automatic Differentiation with Julia

#12
post #2

For those curious about Julia, I just found this: https://www.infoworld.com/article/3284380/data-science/what-... Close to C speed in a dynamic language? Seems pretty great on paper. Is this generally the case?

As long as you write code that's type stable, yea. Type stable means that the compiler can deduce the types of the variables used in a function given the types of the arguments passed to the function. An example of code that's not type stable is code something like this:

  function test1(n)
    x = 0
    for i = 1:n
      if i == 10
        x = x + 0.1
      else
        x = x + 1
      end
    end
    return x
  end
It isn't type stable because x starts out as an int but then changes to a float in the middle of the loop. This code compiles to 78 instructions.

The following code is type stable:

  function test2(n)
    x = 0.0
    for i = 1:n
      if i == 10
        x = x + 0.1
      else
        x = x + 1.0
      end
    end
    return x
  end
This code compiles to 14 instructions.

Re: Automatic Differentiation with Julia

#13
post #11

Earlier quoted context omitted.

So, fun times: if the 1-based indexing throws you off that much, it is entirely straightforward to configure it to use 0 based indexing if you want (or any other kind of offset that you so desire) https://docs.julialang.org/en/latest/devdocs/offset-arrays/ Having said that, I encourage you to try out the 1-based indexing, as I think you might find a lot of things become surprisingly more intuitive.

> or any other kind of offset that you so desire This is too often the attitude of Julia people. But zero-based indexing is not just some arbitrary offset. Programmers just like it. You say that many things are more intuitive with one-based indexing, but many things are less intuitive too. I don't think python ever would have become popular without zero-based indexing. The thing is, we really don't know why people pr…

> But zero-based indexing is not just some arbitrary offset. Programmers just like it.

Um, that's the definition of "arbitrary".

Re: Automatic Differentiation with Julia

#14
post #10
post #8

Earlier quoted context omitted.

There are others that actually like 1-based indexing languages.

And they already have Julia! Looks like you can't joke with array indexing...

Actually there are plenty of options with Algol derived languages.

Re: Automatic Differentiation with Julia

#15
post #11

Earlier quoted context omitted.

So, fun times: if the 1-based indexing throws you off that much, it is entirely straightforward to configure it to use 0 based indexing if you want (or any other kind of offset that you so desire) https://docs.julialang.org/en/latest/devdocs/offset-arrays/ Having said that, I encourage you to try out the 1-based indexing, as I think you might find a lot of things become surprisingly more intuitive.

> or any other kind of offset that you so desire This is too often the attitude of Julia people. But zero-based indexing is not just some arbitrary offset. Programmers just like it. You say that many things are more intuitive with one-based indexing, but many things are less intuitive too. I don't think python ever would have become popular without zero-based indexing. The thing is, we really don't know why people pr…

> This is too often the attitude of Julia people

And it's a good attitude for the Julia people to have. Their target audience is not just (or even mainly) full time developers. They're targeting scientists, statisticians etc. As such, it makes sense for Julia to use conventions that are appropriate to their audience. This pervades the whole of Julia, not just indexing although the latter is exceptionally rich for this reason.

> Programmers just like it

That's a reason for having 0-based indexing but not an especially good one. And for Python it was an arbitrary decision. That's not to say that 0-based indexing is necessarily an arbitrary decision, it wasn't for C, for example, but it often is.

Re: Automatic Differentiation with Julia

#16
post #6

Julia is a great language, but I'm still waiting for someone to create a Julia fork that uses 0-based indexing.

So, fun times: if the 1-based indexing throws you off that much, it is entirely straightforward to configure it to use 0 based indexing if you want (or any other kind of offset that you so desire) https://docs.julialang.org/en/latest/devdocs/offset-arrays/ Having said that, I encourage you to try out the 1-based indexing, as I think you might find a lot of things become surprisingly more intuitive.

> Having said that, I encourage you to try out the 1-based indexing, as I think you might find a lot of things become surprisingly more intuitive.

Can you provide an example? It seems that the assertion only reflects a personal point of view, similar to the egg endianness discussion in Gulliver.

Re: Automatic Differentiation with Julia

#17
post #11

Earlier quoted context omitted.

So, fun times: if the 1-based indexing throws you off that much, it is entirely straightforward to configure it to use 0 based indexing if you want (or any other kind of offset that you so desire) https://docs.julialang.org/en/latest/devdocs/offset-arrays/ Having said that, I encourage you to try out the 1-based indexing, as I think you might find a lot of things become surprisingly more intuitive.

> or any other kind of offset that you so desire This is too often the attitude of Julia people. But zero-based indexing is not just some arbitrary offset. Programmers just like it. You say that many things are more intuitive with one-based indexing, but many things are less intuitive too. I don't think python ever would have become popular without zero-based indexing. The thing is, we really don't know why people pr…

Well for one, most situations I can think of when an index is calculated a 0-based index is more useful.

Addressing an element T[h][w][c] in a linearized 3D tensor with 0-based indexing:

    T[h*W*C+w*C+c]
with 1-based indexing:

    T[(h-1)*W*C+(w-1)*C+c]
Or let's say you want to take a string "abc" and repeat it until the length is 10, getting "abcabcabca". With 0-based indexing:

    a,b = "abc", [" "]*10
    for i in range(0,10):
      b[i]=a[i%3]
In a 1-based language that's:

    for i in range(1,11):
        b[i]=a[(i-1)%3+1]
Here's what Dijkstra has to say about it:

http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...

Re: Automatic Differentiation with Julia

#18
post #11

Earlier quoted context omitted.

> or any other kind of offset that you so desire This is too often the attitude of Julia people. But zero-based indexing is not just some arbitrary offset. Programmers just like it. You say that many things are more intuitive with one-based indexing, but many things are less intuitive too. I don't think python ever would have become popular without zero-based indexing. The thing is, we really don't know why people pr…

> This is too often the attitude of Julia people And it's a good attitude for the Julia people to have. Their target audience is not just (or even mainly) full time developers. They're targeting scientists, statisticians etc. As such, it makes sense for Julia to use conventions that are appropriate to their audience. This pervades the whole of Julia, not just indexing although the latter is exceptionally rich for thi…

> And it's a good attitude for the Julia people to have. Their target audience is not just (or even mainly) full time developers. They're targeting scientists, statisticians etc.

I don't see how scientists or staticians would be unable to understand a basic knowledge like zero-based indexing. In fact, zero-based indexing already is widely used in basic areas such as series and sequences. Why are freshmen quite capable of understanding such a fundamental convention but somehow seasoned scientists and statitians are not?

Re: Automatic Differentiation with Julia

#20

Earlier quoted context omitted.

> This is too often the attitude of Julia people And it's a good attitude for the Julia people to have. Their target audience is not just (or even mainly) full time developers. They're targeting scientists, statisticians etc. As such, it makes sense for Julia to use conventions that are appropriate to their audience. This pervades the whole of Julia, not just indexing although the latter is exceptionally rich for thi…

> And it's a good attitude for the Julia people to have. Their target audience is not just (or even mainly) full time developers. They're targeting scientists, statisticians etc. I don't see how scientists or staticians would be unable to understand a basic knowledge like zero-based indexing. In fact, zero-based indexing already is widely used in basic areas such as series and sequences. Why are freshmen quite capabl…

> I don't see how scientists or staticians would be unable to understand a basic knowledge like zero-based indexing

Of course they can. In fact, they tend to have a complex relationship with indexing which is why Julia supports such a rich indexing language.

But the default the Julia team chose was the natural, mathematical default rather than the natural memory addressing default. Which, given what they were trying to achieve, was entirely sensible.

And, on a side note, just because something is physically possible, it doesn't follow that it's the most sensible choice. Otherwise language development would have stopped at the first Turing complete language.

What the Julia team is attempting to do is make the transition for their target audience as seamless as possible. This can be seen in their indexing language but also in their choice of dispatch, their type conversion architecture etc. A great deal of thought goes into these decisions (you can see it in their issue/RFC trackers). "A CS freshman could work it out" doesn't even come close.

Post reply on HN