4 ms·
This could either be brilliant or a total nightmare: "Support for arrays with indexing starting at values different from 1. The array types are expected to be
by jmde 10y ago
This could either be brilliant or a total nightmare:
"Support for arrays with indexing starting at values different from 1. The array types are expected to be defined in packages, but now Julia provides an API for writing generic algorithms for arbitrary indexing schemes (#16260)."
Originally I thought total nightmare but now I'm not sure.
- KenoFischer 10y agoMany people think this was added for support of 0 offset arrays, but that's only a side effect really. This feature was requested by people who work with rather odd arrays (e.g. diagonal slices through high dimensional data). I have mentioned in previous threads on the subject that julia's 1-indexed arrays don't matter much in practice because the generic APIs hide that fact most of the time. This just adds the last bit of code to make that completely true and adds documentation/cleanup. For those seeking more information, I'd recommend Tim Holy's JuliaCon keynote on the subject: https://www.youtube.com/watch?v=fl0g9tHeghA https://www.youtube.com/watch?v=fl0g9tHeghA
- zerofan 10y ago> I have mentioned in previous threads on the subject that julia's 1-indexed arrays don't matter much in practice because the generic APIs hide that fact most of the time. My guess is that most people who prefer zero-based feel strongly about it, and most people that like one-based don't care that much. If it really doesn't matter that much, I think Julia should've gone with zero. FFTs, Vandermonde matrices (least squares), polynomials, and pretty much anything where the array subscript relates to the mathematics is cleaner with zero-based arrays.
- sundarurfriend 10y ago> My guess is that most people who prefer zero-based feel strongly about it, and most people that like one-based don't care that much. FWIW, as someone in the latter category (liking one-based indexing), I'd say you're partially correct: I'm not emotional attached to 1-based indexing the way some 0-based folks seem to be, but it's a practical nicety and one of the things I'm really glad Julia chose to do. Making 0-based the default would definitely reduce its appeal to me.
- zerofan 10y agoCall it emotional if you like, but I won't use a language that has an off by one error built into its specfication :-)
- deleted 10y ago[deleted]
- Avshalom 10y agoPascal and Ada have had arbitrary indexing for decades. It's been fine.
- StefanKarpinski 10y agoAnd Fortran, where it works fine. Perl lets you change the array index offset but everyone warns you that your computer will reach out and slap you in the face if you do. As is often the case, the devil is in the details.
- ch_123 10y agoEiffel too IIRC (same family I suppose)
- nimrody 10y agoPascal and Ada don't usually use their arrays as matrices in mathematical expressions. Julia is targeted at people using Matlab. How do you multiply two matrices that use different indexing? Ignore the indexing differences? It's also problematic when different libraries use different conventions (0-based vs 1-based). Can you use the output of one such library to feed another?
- yaantc 10y agoAda has the notion of attributes applying to types and variables, to access related properties. Among those, there are attributes to get the starting and ending indexes of an array. So it's possible to program completely generic array processing, independent of the underlying choice or range for the array. All this from memory, and it's been a long time...
- data_hope 10y agoDoesn't Fortran feature variable indices for quite a while now? I think the varying indices are a great feature for porting old code over from other programming languages.