-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jl
64 lines (41 loc) · 1.29 KB
/
index.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#define cartesian index
using Base: LinearIndices, CartesianIndices #LinearIndex, CartesianIndex #,
# Pyramid #1
##1. Unit Range (::Int64 : ::Int64)
##2. Array
##3. View
##4. SubArray
##Pyramid #2
##1. Unit Range (::Int64 : ::Int64)
##2. cartesianIndex
##3.Index
##3.1. LinearIndices
println("LinearIndices(1:9) = ", Base.LinearIndices(1:9) )
a=1 :: Int64
b=9 :: Int64
unitRange = a:b
##3.2. cartesianIndex
function getCartesianIndex( unitRange ) #::Base.AbstracUnitRange)
CartesianIndex(unitRange )
end
cartesianIndex(index::Integer...) = Base.CartesianIndex(index)
#l
# :: Base.CartesianIndices
function getIndex(inds, arr)
# LinearIndices(inds ) -> R
iter = Base.CartesianIndices(axes(arr))
#NI = inc(i.I, iter.indices)
#I = #Base.inc
#I = (iter.I, CartesianIndices.indices) # caretesian has no field I
#I = (iter, CartesianIndices.indices) #UnionAll
I = iter
I
end
function getindices2(a :: Int64 , b :: Int64, arr )
firstIndex = getIndex(a , arr ) #firstIndex(findall(x -> x == a, arr ))
lastIndex = getIndex(b , arr ) #lastindex(findall(x -> x == b, arr ))
idxA, idxB = firstIndex, lastIndex
idxA, idxB
end
ar = [3,2,1]
println( CartesianIndices(axes(ar) ))