@@ -51,7 +51,7 @@ baremodule pybuiltins end
5151# Wrap
5252
5353"""
54- PyArray{T,N,M,L,R }(x; copy=true, array=true, buffer=true)
54+ PyArray{T,N,F }(x; copy=true, array=true, buffer=true)
5555
5656Wrap the Python array `x` as a Julia `AbstractArray{T,N}`.
5757
@@ -62,31 +62,34 @@ If `copy=false` then the resulting array is guaranteed to directly wrap the data
6262The type parameters are all optional, and are:
6363- `T`: The element type.
6464- `N`: The number of dimensions.
65- - `M`: True if the array is mutable.
66- - `L`: True if the array supports fast linear indexing.
67- - `R`: The element type of the underlying buffer. Often equal to `T`.
65+ - `F`: Tuple of symbols, including:
66+ - `:mutable`: The array is mutable.
67+ - `:linear`: Supports fast linear indexing.
68+ - `:contiguous`: Data is F-contiguous. Implies `:linear`.
6869"""
69- struct PyArray{T,N,M,L,R } <: AbstractArray{T,N}
70- ptr:: Ptr{R} # pointer to the data
70+ struct PyArray{T,N,F } <: AbstractArray{T,N}
71+ ptr:: Ptr{Cvoid} # pointer to the data
7172 length:: Int # length of the array
7273 size:: NTuple{N,Int} # size of the array
7374 strides:: NTuple{N,Int} # strides (in bytes) between elements
7475 py:: Py # underlying python object
7576 handle:: Py # the data in this array is valid as long as this handle is alive
76- function PyArray {T,N,M,L,R } (
77+ function PyArray {T,N,F } (
7778 :: Val{:new} ,
78- ptr:: Ptr{R} ,
79+ ptr:: Ptr ,
7980 size:: NTuple{N,Int} ,
8081 strides:: NTuple{N,Int} ,
8182 py:: Py ,
8283 handle:: Py ,
83- ) where {T,N,M,L,R }
84+ ) where {T,N,F }
8485 T isa Type || error (" T must be a Type" )
8586 N isa Int || error (" N must be an Int" )
86- M isa Bool || error (" M must be a Bool" )
87- L isa Bool || error (" L must be a Bool" )
88- R isa DataType || error (" R must be a DataType" )
89- new {T,N,M,L,R} (ptr, prod (size), size, strides, py, handle)
87+ F isa Tuple{Vararg{Symbol}} || error (" F must be a tuple of Symbols" )
88+ for flag in F
89+ flag in (:mutable , :linear , :contiguous , :copy , :nocopy ) ||
90+ error (" invalid entry of F: $(repr (flag)) " )
91+ end
92+ new {T,N,F} (ptr, prod (size), size, strides, py, handle)
9093 end
9194end
9295
0 commit comments