Revision 343657a5cdfa7b23c9ad0636fa5c7a5d4434532b authored by Viral B. Shah on 14 April 2015, 19:24:42 UTC, committed by Viral B. Shah on 14 April 2015, 19:26:00 UTC
squeeze of a sparse matrix throws an error. (cherry picked from commit f8e343eb80bb2936ffc81064d4bdc197ba26598f)
1 parent a18af00
ndgrid.jl
ndgrid(v::AbstractVector) = copy(v)
function ndgrid{T}(v1::AbstractVector{T}, v2::AbstractVector{T})
m, n = length(v1), length(v2)
v1 = reshape(v1, m, 1)
v2 = reshape(v2, 1, n)
(repmat(v1, 1, n), repmat(v2, m, 1))
end
function ndgrid_fill(a, v, s, snext)
for j = 1:length(a)
a[j] = v[div(rem(j-1, snext), s)+1]
end
end
function ndgrid{T}(vs::AbstractVector{T}...)
n = length(vs)
sz = map(length, vs)
out = ntuple(n, i->Array(T, sz))
s = 1
for i=1:n
a = out[i]::Array
v = vs[i]
snext = s*size(a,i)
ndgrid_fill(a, v, s, snext)
s = snext
end
out
end
meshgrid(v::AbstractVector) = meshgrid(v, v)
function meshgrid{T}(vx::AbstractVector{T}, vy::AbstractVector{T})
m, n = length(vy), length(vx)
vx = reshape(vx, 1, n)
vy = reshape(vy, m, 1)
(repmat(vx, m, 1), repmat(vy, 1, n))
end
function meshgrid{T}(vx::AbstractVector{T}, vy::AbstractVector{T},
vz::AbstractVector{T})
m, n, o = length(vy), length(vx), length(vz)
vx = reshape(vx, 1, n, 1)
vy = reshape(vy, m, 1, 1)
vz = reshape(vz, 1, 1, o)
om = ones(Int, m)
on = ones(Int, n)
oo = ones(Int, o)
(vx[om, :, oo], vy[:, on, oo], vz[om, on, :])
end
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...