@@ -13,22 +13,47 @@ Indices{N} = NTuple{N,AbstractUnitRange}
13
13
# # Traits for array types ##
14
14
15
15
abstract type IndexStyle end
16
+ """
17
+ IndexLinear()
18
+
19
+ Subtype of [`IndexStyle`](@ref) used to describe arrays which
20
+ are optimally indexed by one linear index.
21
+
22
+ A linear indexing style uses one integer to describe the position in the array
23
+ (even if it's a multidimensional array) and column-major
24
+ ordering is used to access the elements. For example,
25
+ if `A` were a `(2, 3)` custom matrix type with linear indexing,
26
+ and we referenced `A[5]` (using linear style), this would
27
+ be equivalent to referencing `A[1, 3]` (since `2*1 + 3 = 5`).
28
+ See also [`IndexCartesian`](@ref).
29
+ """
16
30
struct IndexLinear <: IndexStyle end
31
+ """
32
+ IndexCartesian()
33
+
34
+ Subtype of [`IndexStyle`](@ref) used to describe arrays which
35
+ are optimally indexed by a Cartesian index.
36
+
37
+ A cartesian indexing style uses multiple integers/indices to describe the position in the array.
38
+ For example, if `A` were a `(2, 3, 4)` custom matrix type with cartesian indexing,
39
+ we could reference `A[2, 1, 3]` and Julia would automatically convert this into the
40
+ correct location in the underlying memory. See also [`IndexLinear`](@ref).
41
+ """
17
42
struct IndexCartesian <: IndexStyle end
18
43
19
44
"""
20
45
IndexStyle(A)
21
46
IndexStyle(typeof(A))
22
47
23
48
`IndexStyle` specifies the "native indexing style" for array `A`. When
24
- you define a new `AbstractArray` type, you can choose to implement
25
- either linear indexing or cartesian indexing. If you decide to
26
- implement linear indexing, then you must set this trait for your array
49
+ you define a new [ `AbstractArray`](@ref) type, you can choose to implement
50
+ either linear indexing (with [`IndexLinear`](@ref)) or cartesian indexing.
51
+ If you decide to implement linear indexing, then you must set this trait for your array
27
52
type:
28
53
29
54
Base.IndexStyle(::Type{<:MyArray}) = IndexLinear()
30
55
31
- The default is `IndexCartesian()`.
56
+ The default is [ `IndexCartesian()`](@ref) .
32
57
33
58
Julia's internal indexing machinery will automatically (and invisibly)
34
59
convert all indexing operations into the preferred style. This allows users
0 commit comments