-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic fallback for each (supports dense arrays)
This changes the API so that the inner "each" loop returns a complete iterator, rather than just a dimensional iterator. This seems a little more self-consistent, but it could present generalization problems later.
- Loading branch information
Showing
5 changed files
with
86 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
A = [1 5 -5; | ||
0 3 2] | ||
|
||
@test each(index(A)) == CartesianRange((1:2, 1:3)) | ||
@test each(index(A, :, 1:2)) == CartesianRange((1:2, 1:2)) | ||
@test each(index(A, :, 2:3)) == CartesianRange((1:2, 2:3)) | ||
|
||
k = 0 | ||
for j in inds(A, 2) | ||
for v in each(A, :, j) | ||
@test v == A[k+=1] | ||
end | ||
end | ||
|
||
k = 0 | ||
for j in inds(A, 2) | ||
for I in each(index(A, :, j)) | ||
@test A[I] == A[k+=1] | ||
end | ||
end | ||
|
||
k = 0 | ||
for j in inds(A, 2) | ||
for I in eachindex(stored(A, :, j)) | ||
@test A[I] == A[k+=1] | ||
end | ||
end | ||
|
||
k = 0 | ||
for j in inds(A, 2) | ||
for v in each(stored(A, :, j)) | ||
@test v == A[k+=1] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
using ArrayIterationPlayground | ||
using Base.Test | ||
|
||
A = zeros(2,3) | ||
@test inds(A, 1) == 1:2 | ||
@test inds(A, 2) == 1:3 | ||
@test inds(A, 3) == 1:1 | ||
@test inds(A) == (1:2, 1:3) | ||
|
||
include("dense.jl") | ||
include("sparse.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters