Re: [julia-users] indexing over `zip(collection1, collection2)`
I've found it very useful, even if it is O(n) complexity to get the n-th element, to allow indexing. For a database, if you have a packed record (for example, like SQLite's row format), and you only need to access a single field, it's better to be able to do just that, and *not* have to unpack the entire record just to do that (skipping fields can be many many times faster than unpacking them, plus the amount of time wasted on allocating objects for all of the fields of records scanned and then GCing them). I think it would be better to have a trait that you could find out if an indexable structure is directly indexable or not, kind of like strings used to have) (or does that exist now, with all of the changes for Arraymageddon?) On Thursday, June 23, 2016 at 3:35:06 PM UTC-4, Mauro wrote: > > My recollection is that part of the indexing interface in Julia (just by > convention) is that indexing should be of O(1) (or close to that) > complexity. Iterable things, in general, have O(n) complexity to access > the n-th element, because you have to traverse the data to get there > (the classic example are linked lists). Thus, it makes sense that > indexing is not supported, instead you have to call collect first if you > want to index. > > On Thu, 2016-06-23 at 20:43, Davide Lasagna> wrote: > > Hi Jacob, > > > > In my view, in principle, all "iterators" should be indexable, (at least > > read-only), *unless *the underlying data is not indexable by nature, > e.g. > > with data that comes from a stream... Doing `zip([1, 2], [2, 3])[1]` > > should probably just work. > > > > I also think that for `Zip`s if the zipped collections are not > indexable, > > then the "outer" getindex method should fail internally with a > MethodError, > > on the "inner" getindex calls not implemented for the non-indexable > > collections. > > > > On Thursday, June 23, 2016 at 7:23:34 PM UTC+1, Jacob Quinn wrote: > >> > >> Sorry, to clarify a little: > >> > >> The things you're zipping are not necessarily indexable (i.e. other > >> iterators), so it's not safe to assume you can always index a Zip. > >> > >> On Thu, Jun 23, 2016 at 2:21 PM, Jacob Quinn >> > wrote: > >> > >>> Most "iterator" types are not indexable, AFAIK. The typical > >>> recommendation/idiom is to just call `collect(itr)` if you need to > >>> specifically index. > >>> > >>> -Jacob > >>> > >>> On Thu, Jun 23, 2016 at 2:18 PM, Davide Lasagna >>> > wrote: > >>> > Is there any particular reason why `Zip` objects are iterable but not > indexable? Python allows that. > > From previous discussion on the topic (2014 topic at > https://groups.google.com/forum/#!topic/julia-dev/5bgMvzJveWA) it > seems > that it has not been implemented yet. > > Thanks, > > > > >>> > >> >
Re: [julia-users] indexing over `zip(collection1, collection2)`
On Fri, 2016-06-24 at 05:26, Rafael Fourquetwrote: >> My recollection is that part of the indexing interface in Julia (just by >> convention) is that indexing should be of O(1) (or close to that) >> complexity. > > As the OP suggested, this could still be the case, the zip object > would simply forward the indexing to the zipped collections, which > would fail if one of then is not indexable (in O(1)). Alternatively > there could be a trait for that. > I've also wanted that for a long time, and even setindex!, to be able > to sort an array2 according to the order defined in array1: > sort!(zip(array1, array2)). Yes, you're right.
Re: [julia-users] indexing over `zip(collection1, collection2)`
My recollection is that part of the indexing interface in Julia (just by convention) is that indexing should be of O(1) (or close to that) complexity. Iterable things, in general, have O(n) complexity to access the n-th element, because you have to traverse the data to get there (the classic example are linked lists). Thus, it makes sense that indexing is not supported, instead you have to call collect first if you want to index. On Thu, 2016-06-23 at 20:43, Davide Lasagnawrote: > Hi Jacob, > > In my view, in principle, all "iterators" should be indexable, (at least > read-only), *unless *the underlying data is not indexable by nature, e.g. > with data that comes from a stream... Doing `zip([1, 2], [2, 3])[1]` > should probably just work. > > I also think that for `Zip`s if the zipped collections are not indexable, > then the "outer" getindex method should fail internally with a MethodError, > on the "inner" getindex calls not implemented for the non-indexable > collections. > > On Thursday, June 23, 2016 at 7:23:34 PM UTC+1, Jacob Quinn wrote: >> >> Sorry, to clarify a little: >> >> The things you're zipping are not necessarily indexable (i.e. other >> iterators), so it's not safe to assume you can always index a Zip. >> >> On Thu, Jun 23, 2016 at 2:21 PM, Jacob Quinn > > wrote: >> >>> Most "iterator" types are not indexable, AFAIK. The typical >>> recommendation/idiom is to just call `collect(itr)` if you need to >>> specifically index. >>> >>> -Jacob >>> >>> On Thu, Jun 23, 2016 at 2:18 PM, Davide Lasagna >> > wrote: >>> Is there any particular reason why `Zip` objects are iterable but not indexable? Python allows that. From previous discussion on the topic (2014 topic at https://groups.google.com/forum/#!topic/julia-dev/5bgMvzJveWA) it seems that it has not been implemented yet. Thanks, >>> >>
Re: [julia-users] indexing over `zip(collection1, collection2)`
Hi Jacob, In my view, in principle, all "iterators" should be indexable, (at least read-only), *unless *the underlying data is not indexable by nature, e.g. with data that comes from a stream... Doing `zip([1, 2], [2, 3])[1]` should probably just work. I also think that for `Zip`s if the zipped collections are not indexable, then the "outer" getindex method should fail internally with a MethodError, on the "inner" getindex calls not implemented for the non-indexable collections. On Thursday, June 23, 2016 at 7:23:34 PM UTC+1, Jacob Quinn wrote: > > Sorry, to clarify a little: > > The things you're zipping are not necessarily indexable (i.e. other > iterators), so it's not safe to assume you can always index a Zip. > > On Thu, Jun 23, 2016 at 2:21 PM, Jacob Quinn> wrote: > >> Most "iterator" types are not indexable, AFAIK. The typical >> recommendation/idiom is to just call `collect(itr)` if you need to >> specifically index. >> >> -Jacob >> >> On Thu, Jun 23, 2016 at 2:18 PM, Davide Lasagna > > wrote: >> >>> Is there any particular reason why `Zip` objects are iterable but not >>> indexable? Python allows that. >>> >>> From previous discussion on the topic (2014 topic at >>> https://groups.google.com/forum/#!topic/julia-dev/5bgMvzJveWA) it seems >>> that it has not been implemented yet. >>> >>> Thanks, >>> >>> >>> >> >
Re: [julia-users] indexing over `zip(collection1, collection2)`
Sorry, to clarify a little: The things you're zipping are not necessarily indexable (i.e. other iterators), so it's not safe to assume you can always index a Zip. On Thu, Jun 23, 2016 at 2:21 PM, Jacob Quinnwrote: > Most "iterator" types are not indexable, AFAIK. The typical > recommendation/idiom is to just call `collect(itr)` if you need to > specifically index. > > -Jacob > > On Thu, Jun 23, 2016 at 2:18 PM, Davide Lasagna > wrote: > >> Is there any particular reason why `Zip` objects are iterable but not >> indexable? Python allows that. >> >> From previous discussion on the topic (2014 topic at >> https://groups.google.com/forum/#!topic/julia-dev/5bgMvzJveWA) it seems >> that it has not been implemented yet. >> >> Thanks, >> >> >> >
Re: [julia-users] indexing over `zip(collection1, collection2)`
Most "iterator" types are not indexable, AFAIK. The typical recommendation/idiom is to just call `collect(itr)` if you need to specifically index. -Jacob On Thu, Jun 23, 2016 at 2:18 PM, Davide Lasagnawrote: > Is there any particular reason why `Zip` objects are iterable but not > indexable? Python allows that. > > From previous discussion on the topic (2014 topic at > https://groups.google.com/forum/#!topic/julia-dev/5bgMvzJveWA) it seems > that it has not been implemented yet. > > Thanks, > > >
[julia-users] indexing over `zip(collection1, collection2)`
Is there any particular reason why `Zip` objects are iterable but not indexable? Python allows that. >From previous discussion on the topic (2014 topic at https://groups.google.com/forum/#!topic/julia-dev/5bgMvzJveWA) it seems that it has not been implemented yet. Thanks,