Re:Swift for TensorFlow Shuts Down
by freedomben on Friday February 12, 2021 @06:56PM
(#26120057)
Julia is fascinating to me, and I don't do any ML (currently). Julia seems like such a well designed language. I'm excited to see where it goes.
[ Parent
| on HN ]
As weird as it sounds, the only thing that stops me from trying Julia is 1 indexing
Re:Swift for TensorFlow Shuts Down
by adgjlsfhk1 on Saturday February 13, 2021 @02:44AM
(#26122088)
IMO, Julia is good enough that you might not notice. you can use constructions like `for i in axes(V)` that will automatically give you the indexes, or `V[begin:begin+2]` to get the first 2 elements. Also higher order functions eg. `map` (and broadcasting) mean that you will rarely be manually working with indexes.
You still need to access indexes if you're working with arrays though, which is a very common data structure.
Re:Swift for TensorFlow Shuts Down
by improbable22 on Saturday February 13, 2021 @07:25AM
(#26123216)
That's not so obvious, the abstractions for multi-dimensional indexing are better than (I think) you're imagining.
Here's a nice recent example: a new reverse!(A; dims) function, which is fast and works on arrays with any number of dimensions. And is completely indifferent to where the indices start:
https://github.com/JuliaLang/julia/pull/37367/files#diff-eb9...
I'm not 100% sure what I'm looking at, but that seems to be related to reversing arrays/matrices, not accessing arrays through indexes.
Re:Swift for TensorFlow Shuts Down
by improbable22 on Saturday February 13, 2021 @07:59AM
(#26123353)
Maybe less readable than I remembered, sorry! But these `CartesianIndex` things are how you index multi-dimensional arrays.
If by indexing you only mean adding offsets to pointers with your bare hands, this is possible but discouraged. Because you'll produce a buggier and less general version of exactly what already exists. In this case, reversing an N-dimensional array, along any M of its axes, with arbitrary offsets -- there are a lot of ways to get that wrong.
What I mean is something like this:
# one dimensional
a = [1, 2, 3]
# prints the number 1 @ index 0
print(a[0])
# multi-dimensional
b = [[1, 2, 3], [4, 5, 6]]
# prints the number 4 @ index (1, 0)
print(b[1][0])
In Julia these indexes would start from 1. It doesn't seem like `CartesianIndex` solves this, since looking at some examples you still have to specify array indexes (Which start from 1): https://docs.julialang.org/en/v1/base/arrays/#Base.Iterators...
Re:Swift for TensorFlow Shuts Down
by improbable22 on Saturday February 13, 2021 @08:59AM
(#26123617)
OK, I thought you were advocating zero based on complicated index calculations for some algorithm, with mod & div, which is what I was trying to say could be abstracted away. The literal syntax `a=[1,2,3]` makes a one-dimensional `Array{Int,1}` whose first element is indeed `a[1]`. (`b` is an array of arrays, while `c = [1 2 3; 4 5 6]` is an honest 2-dimensional array.)
Because you believe that you can't get used to a different convention? It gets brought up a lot that for array offsets, zero based is more natural. In my experience, the amount of index calculations you need in Julia is minimal anyway because there are really nice abstractions for n-dimensional indexing.
Re:Swift for TensorFlow Shuts Down
by viktorcode on Saturday February 13, 2021 @04:30AM
(#26122500)
0-based indexing is an artefact of pointer math. Modern languages don't treat arrays as a pointers to their first element. So, it is still with us only because almost no language designer decided to challenge existing convention.
Re:Swift for TensorFlow Shuts Down
by threatofrain on Saturday February 13, 2021 @06:36AM
(#26122998)
I see 1-indexing as an artifact of a lot of linear algebra texts, whereas 0-indexing is more popular in analysis. Julia just wants it to be easier to directly copy formulas from publications.
I also think it’s blurry as to whether mathematicians and programmers see indexing numbers as merely indices or richer numbers.