Skip to content

Commit 00b75b7

Browse files
committed
adding empty(a) to use instead of []
adding localize(SubDArray)
1 parent ade74a7 commit 00b75b7

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

j/abstractarray.j

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ similar{T}(a::AbstractArray{T}, dims::Dims) = similar(a, T, dims)
4343
similar{T}(a::AbstractArray{T}, dims::Size...) = similar(a, T, dims)
4444
similar (a::AbstractArray, T::Type, dims::Size...) = similar(a, T, dims)
4545

46+
empty(a::AbstractArray) = similar(a, 0)
47+
4648
reshape(a::AbstractArray, dims::Dims) = (b = similar(a, dims);
4749
for i=1:numel(a); b[i] = a[i]; end;
4850
b)
@@ -569,7 +571,7 @@ end
569571

570572
## Concatenation ##
571573

572-
cat(catdim::Int) = similar([], None, 0)
574+
cat(catdim::Int) = Array(None, 0)
573575

574576
vcat() = Array(None, 0)
575577
hcat() = Array(None, 0)

j/array.j

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ similar{T}(a::Array{T,2}) = Array(T, size(a,1), size(a,2))
6363
similar{T}(a::Array{T,1}, S::Type) = Array(S, size(a,1))
6464
similar{T}(a::Array{T,2}, S::Type) = Array(S, size(a,1), size(a,2))
6565

66+
empty(T::Type) = Array(T, 0)
67+
6668
zeros{T}(::Type{T}, dims::Dims) = fill(Array(T, dims), zero(T))
6769
zeros(T::Type, dims::Size...) = zeros(T, dims)
6870
zeros(dims::Dims) = zeros(Float64, dims)

j/darray.j

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ type DArray{T,N,distdim} <: AbstractArray{T,N}
4848
end
4949
end
5050

51+
typealias SubDArray{T,N} SubArray{T,N,DArray{T}}
52+
typealias SubOrDArray{T,N} Union(DArray{T,N}, SubDArray{T,N})
53+
5154
size(d::DArray) = d.dims
5255

5356
function serialize{T,N,dd}(s, d::DArray{T,N,dd})
@@ -76,7 +79,41 @@ end
7679

7780
# when we actually need the data, wait for it
7881
localize(r::RemoteRef) = localize(fetch(r))
79-
localize{T,N}(d::DArray{T,N}) = d.locl
82+
localize(d::DArray) = d.locl
83+
84+
function localize(s::SubDArray)
85+
d = s.parent
86+
lo = d.dist[d.localpiece]
87+
hi = d.dist[d.localpiece+1]-1
88+
sdi = s.indexes[d.distdim]
89+
l = localize(d)
90+
if isa(sdi,Int)
91+
if lo <= sdi <= hi
92+
return l[ntuple(ndims(l), i->(i==d.distdim ? sdi-lo+1 :
93+
1:size(l,i)))...]
94+
else
95+
return Array(eltype(l), ntuple(ndims(l),
96+
i->(i==d.distdim ? 0 :
97+
size(l,i))))
98+
end
99+
else
100+
sta = start(sdi)
101+
ste = step(sdi)
102+
sto = sdi[end]
103+
i0 = sta + ste*div((lo-sta), ste)
104+
i1 = sta + ste*div((hi-sta), ste)
105+
i0 = max(i0,sta)
106+
i1 = min(i1,sto)
107+
if i0 > sto || i1 < sta
108+
return Array(eltype(l), ntuple(ndims(l),
109+
i->(i==d.distdim ? 0 :
110+
size(l,i))))
111+
else
112+
return l[ntuple(ndims(l), i->(i==d.distdim ? i0:ste:i1 :
113+
1:size(l,i)))...]
114+
end
115+
end
116+
end
80117

81118
# find which piece holds index i in the distributed dimension
82119
function locate(d::DArray, i::Index)
@@ -132,6 +169,7 @@ function locate(d::DArray, I::AbstractVector{Index})
132169
end
133170
return (pmap, dist, perm)
134171
end
172+
135173
## Constructors ##
136174

137175
function maxdim(dims)

j/fft.j

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function fftw_transpose(X::Matrix{Complex128})
247247
(n1, n2) = size(X)
248248
plan = ccall(dlsym(libfftw, :fftw_plan_guru_dft), Ptr{Void},
249249
(Int32, Ptr{Int32}, Int32, Ptr{Int32}, Ptr{Complex128}, Ptr{Complex128}, Int32, Uint32),
250-
int32(0), int32([]),int32(2),int32([n1,n2,1,n2,1,n1]), X, P, FFTW_FORWARD, FFTW_PATIENT)
250+
int32(0), C_NULL, int32(2),int32([n1,n2,1,n2,1,n1]), X, P, FFTW_FORWARD, FFTW_PATIENT)
251251
jl_fftw_execute(Complex128, plan)
252252
jl_fftw_destroy_plan(Complex128, plan)
253253
return P
@@ -258,7 +258,7 @@ function fftw_transpose(X::Matrix{Complex64})
258258
(n1, n2) = size(X)
259259
plan = ccall(dlsym(libfftwf, :fftwf_plan_guru_dft), Ptr{Void},
260260
(Int32, Ptr{Int32}, Int32, Ptr{Int32}, Ptr{Complex64}, Ptr{Complex64}, Int32, Uint32),
261-
int32(0), int32([]),int32(2),int32([n1,n2,1,n2,1,n1]), X, P, FFTW_FORWARD, FFTW_PATIENT)
261+
int32(0), C_NULL, int32(2),int32([n1,n2,1,n2,1,n1]), X, P, FFTW_FORWARD, FFTW_PATIENT)
262262
jl_fftw_execute(Complex64, plan)
263263
jl_fftw_destroy_plan(Complex64, plan)
264264
return P

0 commit comments

Comments
 (0)