Skip to content

Commit

Permalink
Further changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkofod committed May 25, 2016
1 parent 68d6eb8 commit 9866e93
Show file tree
Hide file tree
Showing 54 changed files with 166 additions and 174 deletions.
12 changes: 6 additions & 6 deletions base/sharedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function SharedArray(T::Type, dims::NTuple; init=false, pids=Int[])

func_mapshmem = () -> shm_mmap_array(T, dims, shm_seg_name, JL_O_RDWR)

refs = Array(Future, length(pids))
refs = Array{Future}(length(pids))
for (i, p) in enumerate(pids)
refs[i] = remotecall(func_mapshmem, p)
end
Expand Down Expand Up @@ -159,7 +159,7 @@ function SharedArray{T,N}(filename::AbstractString, ::Type{T}, dims::NTuple{N,In
mode == "r" && !isfile(filename) && throw(ArgumentError("file $filename does not exist, but mode $mode cannot create it"))

# Create the file if it doesn't exist, map it if it does
refs = Array(Future, length(pids))
refs = Array{Future}(length(pids))
func_mmap = mode -> open(filename, mode) do io
Mmap.mmap(io, Array{T,N}, dims, offset; shared=true)
end
Expand Down Expand Up @@ -224,7 +224,7 @@ function finalize_refs{T,N}(S::SharedArray{T,N})
empty!(S.refs)
init_loc_flds(S)
finalize(S.s)
S.s = Array(T, ntuple(d->0,N))
S.s = Array{T}(ntuple(d->0,N))
end
S
end
Expand All @@ -238,7 +238,7 @@ linearindexing{S<:SharedArray}(::Type{S}) = LinearFast()

function reshape{T,N}(a::SharedArray{T}, dims::NTuple{N,Int})
(length(a) != prod(dims)) && throw(DimensionMismatch("dimensions must be consistent with array size"))
refs = Array(Future, length(a.pids))
refs = Array{Future}(length(a.pids))
for (i, p) in enumerate(a.pids)
refs[i] = remotecall(p, a.refs[i], dims) do r,d
reshape(fetch(r),d)
Expand Down Expand Up @@ -339,7 +339,7 @@ function init_loc_flds{T,N}(S::SharedArray{T,N})
S.loc_subarr_1d = sub_1dim(S, S.pidx)
else
S.pidx = 0
S.loc_subarr_1d = sub(Array(T, ntuple(d->0,N)), 1:0)
S.loc_subarr_1d = sub(Array{T}(ntuple(d->0,N)), 1:0)
end
end

Expand Down Expand Up @@ -506,7 +506,7 @@ function shm_mmap_array(T, dims, shm_seg_name, mode)
local A = nothing

if prod(dims) == 0
return Array(T, dims)
return Array{T}(dims)
end

try
Expand Down
2 changes: 1 addition & 1 deletion base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ map(f, t::Tuple) = (f(t[1]), map(f,tail(t))...)
function map(f, t::Tuple{Any,Any,Any,Any,Any,Any,Any,Any,
Any,Any,Any,Any,Any,Any,Any,Any,Vararg{Any}})
n = length(t)
A = Array(Any,n)
A = Array{Any}(n)
for i=1:n
A[i] = f(t[i])
end
Expand Down
2 changes: 1 addition & 1 deletion doc/devdocs/subarrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ parent array, whereas for ``S2`` one needs to apply them to the
second and third. The simplest approach to indexing would be to do
the type-analysis at runtime::

parentindexes = Array(Any, 0)
parentindexes = Array{Any}(0)
for i = 1:ndims(S.parent)
...
if isa(thisindex, Int)
Expand Down
2 changes: 1 addition & 1 deletion doc/manual/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dimension sizes passed as a variable number of arguments.
=================================================== =====================================================================
Function Description
=================================================== =====================================================================
:func:`Array(type, dims...) <Array>` an uninitialized dense array
:func:`Array{type}(dims...) <Array>` an uninitialized dense array
:func:`cell(dims...) <cell>` an uninitialized cell array (heterogeneous array)
:func:`zeros(type, dims...) <zeros>` an array of all zeros of specified type, defaults to ``Float64`` if
``type`` not specified
Expand Down
6 changes: 3 additions & 3 deletions doc/manual/calling-c-and-fortran-code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Here is a slightly more complex example that discovers the local
machine's hostname::

function gethostname()
hostname = Array(UInt8, 128)
hostname = Array{UInt8}(128)
ccall((:gethostname, "libc"), Int32,
(Ptr{UInt8}, Csize_t),
hostname, sizeof(hostname))
Expand Down Expand Up @@ -879,7 +879,7 @@ Here is a third example passing Julia arrays::
# double result_array[])
function sf_bessel_Jn_array(nmin::Integer, nmax::Integer, x::Real)
if nmax<nmin throw(DomainError()) end
result_array = Array(Cdouble, nmax-nmin+1)
result_array = Array{Cdouble}(nmax-nmin+1)
errorcode = ccall(
(:gsl_sf_bessel_Jn_array, :libgsl), #name of C function and library
Cint, #output type
Expand Down Expand Up @@ -999,7 +999,7 @@ conventions are: ``stdcall``, ``cdecl``, ``fastcall``, and ``thiscall``.
For example (from ``base/libc.jl``) we see the same ``gethostname`` :func:`ccall` as above,
but with the correct signature for Windows::

hn = Array(UInt8, 256)
hn = Array{UInt8}(256)
err = ccall(:gethostname, stdcall, Int32, (Ptr{UInt8}, UInt32), hn, length(hn))

For more information, please see the `LLVM Language Reference`_.
Expand Down
2 changes: 1 addition & 1 deletion doc/manual/constructors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ to another, you should probably define a ``convert`` method instead.
On the other hand, if your constructor does not represent a lossless
conversion, or doesn't represent "conversion" at all, it is better
to leave it as a constructor rather than a ``convert`` method. For
example, the ``Array(Int)`` constructor creates a zero-dimensional
example, the ``Array{Int}`` constructor creates a zero-dimensional
``Array`` of the type ``Int``, but is not really a "conversion" from
``Int`` to an ``Array``.

Expand Down
3 changes: 1 addition & 2 deletions doc/manual/interfaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ Methods to implement
:func:`similar(A) <similar>` ``similar(A, eltype(A), size(A))`` Return a mutable array with the same shape and element type
:func:`similar(A, ::Type{S}) <similar>` ``similar(A, S, size(A))`` Return a mutable array with the same shape and the specified element type
:func:`similar(A, dims::NTuple{Int}) <similar>` ``similar(A, eltype(A), dims)`` Return a mutable array with the same element type and the specified dimensions
:func:`similar(A, ::Type{S}, dims::NTuple{Int}) <similar>` ``Array(S, dims)`` Return a mutable array with the specified element type and dimensions
:func:`similar(A, ::Type{S}, dims::NTuple{Int}) <similar>` ``Array{S}(dims)`` Return a mutable array with the specified element type and dimensions
============================================================================ ============================================ =======================================================================================

If a type is defined as a subtype of ``AbstractArray``, it inherits a very large set of rich behaviors including iteration and multidimensional indexing built on top of single-element access. See the :ref:`arrays manual page <man-arrays>` and :ref:`standard library section <stdlib-arrays>` for more supported methods.

A key part in defining an ``AbstractArray`` subtype is :func:`Base.linearindexing`. Since indexing is such an important part of an array and often occurs in hot loops, it's important to make both indexing and indexed assignment as efficient as possible. Array data structures are typically defined in one of two ways: either it most efficiently accesses its elements using just one index (linear indexing) or it intrinsically accesses the elements with indices specified for every dimension. These two modalities are identified by Julia as ``Base.LinearFast()`` and ``Base.LinearSlow()``. Converting a linear index to multiple indexing subscripts is typically very expensive, so this provides a traits-based mechanism to enable efficient generic code for all array types.
Expand Down
4 changes: 2 additions & 2 deletions doc/manual/metaprogramming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ objects:
julia> dump(ex2)
Expr
head: Symbol call
args: Array(Any,(3,))
args: Array{Any}((3,))
1: Symbol +
2: Int64 1
3: Int64 1
Expand Down Expand Up @@ -619,7 +619,7 @@ Compare:
julia> dump(:("a ($a) should equal b ($b)!"))
Expr
head: Symbol string
args: Array(Any,(5,))
args: Array{Any}((5,))
1: String "a ("
2: Symbol a
3: String ") should equal b ("
Expand Down
12 changes: 6 additions & 6 deletions doc/manual/performance-tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ adapted accordingly). We could conceivably do this in at least four ways

function copy_cols{T}(x::Vector{T})
n = size(x, 1)
out = Array(eltype(x), n, n)
out = Array{eltype(x)}(n, n)
for i=1:n
out[:, i] = x
end
Expand All @@ -836,7 +836,7 @@ adapted accordingly). We could conceivably do this in at least four ways

function copy_rows{T}(x::Vector{T})
n = size(x, 1)
out = Array(eltype(x), n, n)
out = Array{eltype(x)}(n, n)
for i=1:n
out[i, :] = x
end
Expand All @@ -845,7 +845,7 @@ adapted accordingly). We could conceivably do this in at least four ways

function copy_col_row{T}(x::Vector{T})
n = size(x, 1)
out = Array(T, n, n)
out = Array{T}(n, n)
for col=1:n, row=1:n
out[row, col] = x[row]
end
Expand All @@ -854,7 +854,7 @@ adapted accordingly). We could conceivably do this in at least four ways

function copy_row_col{T}(x::Vector{T})
n = size(x, 1)
out = Array(T, n, n)
out = Array{T}(n, n)
for row=1:n, col=1:n
out[row, col] = x[col]
end
Expand Down Expand Up @@ -920,7 +920,7 @@ with
end

function loopinc_prealloc()
ret = Array(Int, 3)
ret = Array{Int}(3)
y = 0
for i = 1:10^7
xinc!(ret, i)
Expand Down Expand Up @@ -1146,7 +1146,7 @@ evaluates the L2-norm of the result::

function main()
n = 2000
u = Array(Float64, n)
u = Array{Float64}(n)
init!(u)
du = similar(u)

Expand Down
2 changes: 1 addition & 1 deletion doc/manual/style-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Avoid elaborate container types

It is usually not much help to construct arrays like the following::

a = Array(Union{Int,AbstractString,Tuple,Array}, n)
a = Array{Union{Int,AbstractString,Tuple,Array}}(n)

In this case :func:`cell(n) <cell>` is better. It is also more helpful to the compiler
to annotate specific uses (e.g. ``a[i]::Int``) than to try to pack many
Expand Down
6 changes: 3 additions & 3 deletions doc/manual/variables-and-scoping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ has been introduced. Therefore it makes sense to write something like
``let x = x`` since the two ``x`` variables are distinct and have separate
storage. Here is an example where the behavior of ``let`` is needed::

Fs = Array(Any,2)
Fs = Array{Any}(2)
i = 1
while i <= 2
Fs[i] = ()->i
Expand All @@ -415,7 +415,7 @@ However, it is always the same variable ``i``, so the two closures
behave identically. We can use ``let`` to create a new binding for
``i``::

Fs = Array(Any,2)
Fs = Array{Any}(2)
i = 1
while i <= 2
let i = i
Expand Down Expand Up @@ -462,7 +462,7 @@ are freshly allocated for each loop iteration. This is in contrast to
iterations. Therefore these constructs are similar to ``while`` loops
with ``let`` blocks inside::

Fs = Array(Any,2)
Fs = Array{Any}(2)
for i = 1:2
Fs[i] = ()->i
end
Expand Down
3 changes: 1 addition & 2 deletions doc/stdlib/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Constructors
Create an uninitialized mutable array with the given element type and size, based upon the given source array. The second and third arguments are both optional, defaulting to the given array's ``eltype`` and ``size``\ . The dimensions may be specified either as a single tuple argument or as a series of integer arguments.

Custom AbstractArray subtypes may choose which specific array type is best-suited to return for the given element type and dimensionality. If they do not specialize this method, the default is an ``Array(element_type, dims...)``\ .
Custom AbstractArray subtypes may choose which specific array type is best-suited to return for the given element type and dimensionality. If they do not specialize this method, the default is an ``Array{element_type}(dims...)``\ .

For example, ``similar(1:10, 1, 4)`` returns an uninitialized ``Array{Int,2}`` since ranges are neither mutable nor support 2 dimensions:

Expand Down Expand Up @@ -995,4 +995,3 @@ dense counterparts. The following functions are specific to sparse arrays.
# perform sparse wizardry...
end
end
4 changes: 2 additions & 2 deletions examples/lru.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type UnboundedLRU{K,V} <: LRU{K,V}
ht::Dict
q::Vector{CacheItem}

UnboundedLRU() = new(Dict(), similar(Array(CacheItem,1), 0))
UnboundedLRU() = new(Dict(), similar(Array{CacheItem}(1), 0))
end
UnboundedLRU() = UnboundedLRU{Any, Any}()

Expand All @@ -48,7 +48,7 @@ type BoundedLRU{K,V} <: LRU{K,V}
q::Vector{CacheItem}
maxsize::Int

BoundedLRU(m) = new(Dict(), similar(Array(CacheItem,1), 0), m)
BoundedLRU(m) = new(Dict(), similar(Array{CacheItem}(1), 0), m)
BoundedLRU() = BoundedLRU(__MAXCACHE)
end
BoundedLRU(m) = BoundedLRU{Any, Any}(m)
Expand Down
2 changes: 1 addition & 1 deletion examples/ndgrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end
function ndgrid{T}(vs::AbstractVector{T}...)
n = length(vs)
sz = map(length, vs)
out = ntuple(i->Array(T, sz), n)
out = ntuple(i->Array{T}(sz), n)
s = 1
for i=1:n
a = out[i]::Array
Expand Down
2 changes: 1 addition & 1 deletion examples/queens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ addqueen(queens::Array{Vector{Int}}, queen::Vector{Int}) = push!(copy(queens), q
hitsany(queen::Vector{Int}, queens::Array{Vector{Int}}) = any(x->hits(queen, x), queens)
hits(a::Array{Int}, b::Array{Int}) = any(a .== b) || abs(a-b)[1] == abs(a-b)[2]

function solve(x, y, n, d=Array(Vector{Int}, 0))
function solve(x, y, n, d=Array{Vector{Int}}(0))
if n == 0
return d
end
Expand Down
8 changes: 4 additions & 4 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function test_primitives{T}(::Type{T}, shape, ::Type{TestAbstractArray})
@test_throws DimensionMismatch reshape(B, (0, 1))

# copy!(dest::AbstractArray, src::AbstractArray)
@test_throws BoundsError copy!(Array(Int, 10), [1:11...])
@test_throws BoundsError copy!(Array{Int}(10), [1:11...])

# convert{T, N}(::Type{Array}, A::AbstractArray{T, N})
X = [1:10...]
Expand Down Expand Up @@ -320,14 +320,14 @@ function test_cat(::Type{TestAbstractArray})
A = T24Linear([1:24...])
b_int = reshape([1:27...], 3, 3, 3)
b_float = reshape(Float64[1:27...], 3, 3, 3)
b2hcat = Array(Float64, 3, 6, 3)
b2hcat = Array{Float64}(3, 6, 3)
b1 = reshape([1:9...], 3, 3)
b2 = reshape([10:18...], 3, 3)
b3 = reshape([19:27...], 3, 3)
b2hcat[:, :, 1] = hcat(b1, b1)
b2hcat[:, :, 2] = hcat(b2, b2)
b2hcat[:, :, 3] = hcat(b3, b3)
b3hcat = Array(Float64, 3, 9, 3)
b3hcat = Array{Float64}(3, 9, 3)
b3hcat[:, :, 1] = hcat(b1, b1, b1)
b3hcat[:, :, 2] = hcat(b2, b2, b2)
b3hcat[:, :, 3] = hcat(b3, b3, b3)
Expand Down Expand Up @@ -442,7 +442,7 @@ function test_map(::Type{TestAbstractArray})
end

# AbstractArray map for N-arg case
A = Array(Int, 10)
A = Array{Int}(10)
f(x, y, z) = x + y + z
D = Float64[1:10...]

Expand Down
Loading

0 comments on commit 9866e93

Please sign in to comment.