Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make product iterator iterate in a more natural fashion. #1488

Merged
merged 1 commit into from
Nov 3, 2012

Conversation

kmsquire
Copy link
Member

@kmsquire kmsquire commented Nov 1, 2012

Before:

julia> f = ['A', 'B', 'C']
4-element Char Array:
 'A'
 'B'
 'C'

julia> [product(f, f)...]
9-element (Any...,) Array:
 ('A','A')
 ('B','A')
 ('C','A')
 ('A','B')
 ('B','B')
 ('C','B')
 ('A','C')
 ('B','C')
 ('C','C')

After:

julia> [product(f,f)...]
9-element (Any...,) Array:
 ('A','A')
 ('A','B')
 ('A','C')
 ('B','A')
 ('B','B')
 ('B','C')
 ('C','A')
 ('C','B')
 ('C','C')

@StefanKarpinski
Copy link
Sponsor Member

Makes more sense to me.

JeffBezanson added a commit that referenced this pull request Nov 3, 2012
Make product iterator iterate in a more natural fashion.
@JeffBezanson JeffBezanson merged commit 8d7686f into JuliaLang:master Nov 3, 2012
@JeffBezanson
Copy link
Sponsor Member

Wait a minute, I'm not so sure about this. I believe the old version was consistent with indexes and comprehensions, where the first index varies fastest.

@staticfloat
Copy link
Sponsor Member

I see it as an arbitrary decision: You just have to decide which is better, iteration over the first variable fastest, or slowest.

The only thing that tips things in one favor or the other is that we already have a corpus of code that uses the comprehensions one way, so I don't feel that we should change this as (Illustrated by #1492) it can cause unexpected problems.

I personally like the first variable being the slowest, but in the end, I don't believe there's a big difference between the two.

@JeffBezanson
Copy link
Sponsor Member

I agree it is arbitrary by itself, but I'm going for consistency here. For example product(1:size(a,1),1:size(a,2)) might as well iterate over an array in address order.

@staticfloat
Copy link
Sponsor Member

Right, so we can either revert this change to make product() consistent with array comprehensions, or make further changes to make comprehensions consistent with this product(). I'm in favor of the former.

@toivoh
Copy link
Contributor

toivoh commented Nov 3, 2012

I have a feeling that making everything consistent with the new product() order would need a change from column major to row major order for Array. I also think it would be best to revert.

@kmsquire
Copy link
Member Author

kmsquire commented Nov 3, 2012

I'm using product to exhaustively produce DNA sequences. For things that are presented to the user, iterating over the last element usually makes more sense, but I can certainly see the reasoning if it is used for iterating over array indices. The new order is consistent with Python, but Python also uses row-major order.

Right now, iterators.jl is in extras, and doesn't seem to have any other uses in the code base (outside of test--sorry, should have checked that). So I guess the question is, is it better to revert so it can iterate over arrays efficiently and maintain consistency with array comprehensions, or leave it for consistency with Python and my convenience. ;-)

@staticfloat
Copy link
Sponsor Member

Why not define an rproduct() or a product(..., :reverse) so that you can have your cake and eat it too?

@JeffBezanson
Copy link
Sponsor Member

I reverted it to be consistent with comprehensions and arrays. I would say anything that's related to presentation should just be handled at that level.

fredrikekre pushed a commit that referenced this pull request Dec 13, 2019
…34091)

git log --oneline 0c2dddd40e4d7492d2a7337be54c345011e5f1e1^..8e236a7f993f1e732ffd0ab5c15736b2594e4109

8e236a7 (HEAD -> master, origin/master, origin/HEAD) Merge pull request #1544 from JuliaLang/sk/telemetry
90b8482 telemetry: factor out telemetry file loading
228fb97 CI telemetry: send indicators for common CI env vars
246dbd0 Pkg protocol: basic anonymous opt-out telemetry
e66a75f Introduce special REPL syntax for shared environments (#1488)
afeb1ee Merge pull request #1538 from JuliaLang/sk/pkg-client-auth
9c357bb Pkg client auth: support connecting to authenticated Pkg servers
6dd7f34 PlatformEngines: revert API part of headers support (broken)
6825b48 Merge pull request #1539 from 00vareladavid/00/fixes
3f1cf40 it is invalid to `add` a package with no commits
0766765 test: default environment should be created when the primary depot does not exist
43f46f8 check no overwrite is occuring when resolving from a project file
37b6853 handle primary depot as relative path
53fdf24 Check for duplicate name/UUID input
8a6387c Remove redundant precompile statement
4d0901e Dont throw error when autocompleting faulty input (#1530)
d69f6d7 Refactor and test `Pkg.test` (#1427)
8ca8b6d PlatformEngines: use `tar -m` to ignore mtimes (#1537)
6797928 Make sure sandbox's temp Project.toml and Manifest.toml files are writable (#1534)
f968cc9 clarify: stacked envs only affect top-level loading (#1529)
0dfef59 PlatformEngines.download: add header support (#1531)
49ab53e Fix tree hashing with nested empty directories (#1522)
0c2dddd fix #1514: install_archive call in backwards_compatible_isolation (#1517)
KristofferC pushed a commit that referenced this pull request Apr 11, 2020
…34091)

git log --oneline 0c2dddd40e4d7492d2a7337be54c345011e5f1e1^..8e236a7f993f1e732ffd0ab5c15736b2594e4109

8e236a7 (HEAD -> master, origin/master, origin/HEAD) Merge pull request #1544 from JuliaLang/sk/telemetry
90b8482 telemetry: factor out telemetry file loading
228fb97 CI telemetry: send indicators for common CI env vars
246dbd0 Pkg protocol: basic anonymous opt-out telemetry
e66a75f Introduce special REPL syntax for shared environments (#1488)
afeb1ee Merge pull request #1538 from JuliaLang/sk/pkg-client-auth
9c357bb Pkg client auth: support connecting to authenticated Pkg servers
6dd7f34 PlatformEngines: revert API part of headers support (broken)
6825b48 Merge pull request #1539 from 00vareladavid/00/fixes
3f1cf40 it is invalid to `add` a package with no commits
0766765 test: default environment should be created when the primary depot does not exist
43f46f8 check no overwrite is occuring when resolving from a project file
37b6853 handle primary depot as relative path
53fdf24 Check for duplicate name/UUID input
8a6387c Remove redundant precompile statement
4d0901e Dont throw error when autocompleting faulty input (#1530)
d69f6d7 Refactor and test `Pkg.test` (#1427)
8ca8b6d PlatformEngines: use `tar -m` to ignore mtimes (#1537)
6797928 Make sure sandbox's temp Project.toml and Manifest.toml files are writable (#1534)
f968cc9 clarify: stacked envs only affect top-level loading (#1529)
0dfef59 PlatformEngines.download: add header support (#1531)
49ab53e Fix tree hashing with nested empty directories (#1522)
0c2dddd fix #1514: install_archive call in backwards_compatible_isolation (#1517)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants