Re:Julia 1.0
by creativeembassy on Thursday August 09, 2018 @10:00AM
(#17724225)
To use a silly example... can I finally realize my dream of two-based indexing?
Re:Julia 1.0
by ChrisRackauckas on Thursday August 09, 2018 @10:08AM
(#17724295)
Yes. And 1.5-based indexing, though I would recommend using rational numbers instead of floating point numbers for this one.
Re:Julia 1.0
by JulianMorrison on Thursday August 09, 2018 @10:50AM
(#17724660)
And imaginary is right out.
Maybe you could use complex numbers to index matrices
Sure can:
# Magic
julia> Base.to_indices(A, inds, I::Tuple{Complex, Vararg{Any}}) = (real(I[1]), imag(I[1]), to_indices(A, Base._maybetail(Base._maybetail(inds)), Base.tail(I))...)
julia> A
4×5 reshape(::UnitRange{Int64}, 4, 5) with eltype Int64:
1 5 9 13 17
2 6 10 14 18
3 7 11 15 19
4 8 12 16 20
julia> A[3 + 2im]
7
```Story time!
When Octave was getting a lot of traffic from the first Coursera machine learning class, when it was just Andrew Ng doing a course and before the Coursera org existed, we were getting a lot of novice users who would do something like
some_matrix(i,j) = 5
and get cryptic errors about how matrices cannot be indexed by complex numbers. This is because by default, in Matlab and Octave `i` and `j` are functions that evaluate to the imaginary unit. You have to overwrite the function names with `i=2, j=3` or whatever beforehand, which novices often forget. This was happening often enough that I pushed some patches to warn, "did you forget to assign i or j?" if someone tried to index matrices with complex numbers.Point is, people in Matlab and Octave often unintentionally try to index by complex numbers.
Re:Julia 1.0
by ChrisRackauckas on Thursday August 09, 2018 @11:28AM
(#17725003)
And quaternions for image stacks in ML? Troll, but not too troll...
One-based indexing has a good, long history.