Skip to content

Commit

Permalink
Support IndexStyle, IndexLinear, IndexCartesian
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Feb 17, 2017
1 parent fa0053b commit 07c4e8a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `bytestring` has been replaced in most cases with additional `String` construction methods; for 0.4 compatibility, the usage involves replacing `bytestring(args...)` with `Compat.String(args...)`. However, for converting a `Ptr{UInt8}` to a string, use the new `unsafe_string(...)` method to make a copy or `unsafe_wrap(String, ...)` to avoid a copy.

* In 0.6, older non-exported indexing traits were renamed and exported as `IndexStyle`, `IndexLinear`, and `IndexCartesian`. Any code specializing `Base.linearindexing(::Type{T})` should switch to `Compat.IndexStyle(::Type{T})`.

## New functions, macros, and methods

* `@views` takes an expression and converts all slices to views ([#20164]), while
Expand Down
8 changes: 8 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,14 @@ else
using Base: Iterators
end

if !isdefined(:IndexStyle)
export IndexStyle, IndexLinear, IndexCartesian
eval(Expr(:typealias, :IndexStyle, :(Base.LinearIndexing)))
eval(Expr(:typealias, :IndexLinear, :(Base.LinearFast)))
eval(Expr(:typealias, :IndexCartesian, :(Base.LinearSlow)))
IndexStyle{T}(::Type{T}) = Base.linearindexing(T)
end

include("to-be-deprecated.jl")

end # module Compat
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1745,4 +1745,18 @@ f20500_2() = A20500_2
@inferred f20500()
@inferred f20500_2()

module CompatArray
using Compat
immutable CartesianArray{T,N} <: AbstractArray{T,N}
parent::Array{T,N}
end
immutable LinearArray{T,N} <: AbstractArray{T,N}
parent::Array{T,N}
end
@compat Compat.IndexStyle(::Type{<:LinearArray}) = IndexLinear()
end
@test IndexStyle(Array{Float32,2}) === IndexLinear()
@test IndexStyle(CompatArray.CartesianArray{Float32,2}) === IndexCartesian()
@test IndexStyle(CompatArray.LinearArray{Float32,2}) === IndexLinear()

include("to-be-deprecated.jl")

0 comments on commit 07c4e8a

Please sign in to comment.