From 486ccf86cc99df177221e7f19b21273b683de987 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sun, 17 Apr 2016 21:43:54 -0400 Subject: [PATCH 1/3] Revert "Remove throwing squeeze(::SparseMatrixCSC, ::Dims)." This reverts commit 45635268fe76e34eedf9b145dbd5a5d8380dcc0f. --- base/sparse/sparsematrix.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index dad4ea51eeae4..f7e04ac5f6346 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -2933,6 +2933,8 @@ function blkdiag(X::SparseMatrixCSC...) SparseMatrixCSC(m, n, colptr, rowval, nzval) end +squeeze(S::SparseMatrixCSC, dims::Dims) = throw(ArgumentError("squeeze is not available for sparse matrices")) + ## Structure query functions issymmetric(A::SparseMatrixCSC) = is_hermsym(A, IdFun()) From 8298eb1143057d6df7cd5f6bcd14dd09ba46d0fa Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sun, 17 Apr 2016 21:44:08 -0400 Subject: [PATCH 2/3] Revert "Add test for squeeze on sparse matrices." This reverts commit 7c54abdb275f260ad4005afa3d025316fafb3446. --- test/sparsedir/sparse.jl | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/sparsedir/sparse.jl b/test/sparsedir/sparse.jl index 93bbf69d769af..b1cafee51d79f 100644 --- a/test/sparsedir/sparse.jl +++ b/test/sparsedir/sparse.jl @@ -81,18 +81,6 @@ a116[p, p] = reshape(1:9, 3, 3) s116[p, p] = reshape(1:9, 3, 3) @test a116 == s116 -# squeeze -for i = 1:5 - am = sprand(20, 1, 0.2) - av = squeeze(am, 2) - @test ndims(av) == 1 - @test all(av.==am) - am = sprand(1, 20, 0.2) - av = squeeze(am, 1) - @test ndims(av) == 1 - @test all(av.'.==am) -end - # matrix-vector multiplication (non-square) for i = 1:5 a = sprand(10, 5, 0.5) From 0e2d6cc293b50250f9c910de57a806df1476899f Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sun, 17 Apr 2016 22:26:33 -0400 Subject: [PATCH 3/3] deprecate non-sharing forms of `reshape`. fixes #4211 --- NEWS.md | 5 +++++ base/abstractarray.jl | 6 ------ base/array.jl | 17 +++++++++++++---- base/deprecated.jl | 5 +++++ base/docs/helpdb/Base.jl | 4 +--- base/sparse/sparsematrix.jl | 16 ---------------- test/abstractarray.jl | 19 ++++++++----------- test/arrayops.jl | 17 ++++++++--------- test/dict.jl | 2 +- test/examples.jl | 4 ++-- test/fft.jl | 2 +- test/functional.jl | 2 +- test/linalg/matmul.jl | 10 +++++----- test/parallel_exec.jl | 2 +- test/reduce.jl | 12 ++++++------ test/reducedim.jl | 4 ++-- test/show.jl | 4 ++-- test/sparsedir/sparse.jl | 8 ++++---- test/subarray.jl | 18 +++++++++--------- 19 files changed, 74 insertions(+), 83 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3347b8f8a4dcf..18af4b33aa05f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -158,8 +158,12 @@ Deprecated or removed * `scale` is deprecated in favor of either `α*A`, `Diagonal(x)*A`, or `A*Diagonal(x)`. ([#15258]) + * `reshape` is now defined to always share data with the original array. + Uses like `reshape(1:10, (2,5))` should be replaced with `collect(1:10, (2,5))` ([#4211]). + [PkgDev]: https://github.com/JuliaLang/PkgDev.jl +[#4211]: https://github.com/JuliaLang/julia/issues/4211 [#8036]: https://github.com/JuliaLang/julia/issues/8036 [#8846]: https://github.com/JuliaLang/julia/issues/8846 [#9503]: https://github.com/JuliaLang/julia/issues/9503 @@ -190,6 +194,7 @@ Deprecated or removed [#15192]: https://github.com/JuliaLang/julia/issues/15192 [#15242]: https://github.com/JuliaLang/julia/issues/15242 [#15258]: https://github.com/JuliaLang/julia/issues/15258 +[#15409]: https://github.com/JuliaLang/julia/issues/15409 [#15550]: https://github.com/JuliaLang/julia/issues/15550 [#15609]: https://github.com/JuliaLang/julia/issues/15609 [#15763]: https://github.com/JuliaLang/julia/issues/15763 diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 68e85512e6df9..021714ad16c06 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -198,12 +198,6 @@ similar( a::AbstractArray, T::Type, dims::Integer...) = similar(a, T, dims) similar( a::AbstractArray, T::Type, dims::DimsInteger) = Array(T, dims...) similar( a::AbstractArray, T::Type, dims::Dims) = Array(T, dims) -function reshape(a::AbstractArray, dims::Dims) - if prod(dims) != length(a) - throw(ArgumentError("dimensions must be consistent with array size (expected $(length(a)), got $(prod(dims)))")) - end - copy!(similar(a, dims), a) -end reshape(a::AbstractArray, dims::Int...) = reshape(a, dims) ## from general iterable to any array diff --git a/base/array.jl b/base/array.jl index 5da33987fdcc6..560892e10bed9 100644 --- a/base/array.jl +++ b/base/array.jl @@ -208,16 +208,25 @@ _similar_for(c::AbstractArray, T, itr, ::HasShape) = similar(c, T, convert(Dims, _similar_for(c, T, itr, isz) = similar(c, T) """ - collect(element_type, collection) + collect(element_type, iterator) -Return an array of type `Array{element_type,1}` of all items in a collection. +Return an array of type `Array{element_type,1}` of all items from an iterator. """ collect{T}(::Type{T}, itr) = collect(Generator(T, itr)) +collect{T}(::Type{T}, itr::Dims) = collect(Generator(T, itr)) + +""" + collect(iterator, dims) + +Return an array with the given dimensions of all elements from an iterator. +""" +collect(itr, dims::Dims) = collect(IteratorND(itr, dims)) + """ - collect(collection) + collect(iterator) -Return an array of all items in a collection. For associative collections, returns Pair{KeyType, ValType}. +Return an array of all items from an iterator. For associative collections, returns Pair{KeyType, ValType}. """ collect(itr) = _collect(1:1 #= Array =#, itr, iteratoreltype(itr), iteratorsize(itr)) diff --git a/base/deprecated.jl b/base/deprecated.jl index 27a120ed1a2c2..0cc0c187f75ec 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1037,3 +1037,8 @@ function pmap(f, c...; err_retry=nothing, err_stop=nothing, pids=nothing) return pmap(p, f, c...) end + +# 4211 +@deprecate reshape(a::AbstractArray, dims::Dims) copy!(similar(a, dims), a) +@deprecate reshape{Tv,Ti}(a::SparseMatrixCSC{Tv,Ti}, dims::NTuple{2,Int}) copy!(similar(a, dims), a) +@deprecate reshape(r::Range, dims::Dims) collect(r, dims) diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index acba442d28a59..f614d3c18e564 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -1572,9 +1572,7 @@ ind2chr """ reshape(A, dims) -Create an array with the same data as the given array, but with different dimensions. An -implementation for a particular type of array may choose whether the data is copied or -shared. +Create an array with the same data as the given array, but with different dimensions. """ reshape diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index f7e04ac5f6346..f1f7a445a9c8b 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -172,22 +172,6 @@ function reinterpret{T,Tv,Ti,N}(::Type{T}, a::SparseMatrixCSC{Tv,Ti}, dims::NTup return SparseMatrixCSC(mS, nS, colptr, rowval, nzval) end -function reshape{Tv,Ti}(a::SparseMatrixCSC{Tv,Ti}, dims::NTuple{2,Int}) - if prod(dims) != length(a) - throw(DimensionMismatch("new dimensions $(dims) must be consistent with array size $(length(a))")) - end - mS,nS = dims - mA,nA = size(a) - numnz = nnz(a) - colptr = Array(Ti, nS+1) - rowval = similar(a.rowval) - nzval = copy(a.nzval) - - sparse_compute_reshaped_colptr_and_rowval(colptr, rowval, mS, nS, a.colptr, a.rowval, mA, nA) - - return SparseMatrixCSC(mS, nS, colptr, rowval, nzval) -end - ## Constructors copy(S::SparseMatrixCSC) = diff --git a/test/abstractarray.jl b/test/abstractarray.jl index e298a47b8dac6..17c642a612c2d 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -78,7 +78,7 @@ import Base: trailingsize const can_inline = Base.JLOptions().can_inline != 0 function test_scalar_indexing{T}(::Type{T}, shape, ::Type{TestAbstractArray}) N = prod(shape) - A = reshape(1:N, shape) + A = collect(1:N, shape) B = T(A) @test A == B # Test indexing up to 5 dimensions @@ -186,15 +186,15 @@ end function test_vector_indexing{T}(::Type{T}, shape, ::Type{TestAbstractArray}) N = prod(shape) - A = reshape(1:N, shape) + A = collect(1:N, shape) B = T(A) idxs = rand(1:N, 3, 3, 3) @test B[idxs] == A[idxs] == idxs @test B[vec(idxs)] == A[vec(idxs)] == vec(idxs) @test B[:] == A[:] == collect(1:N) @test B[1:end] == A[1:end] == collect(1:N) - @test B[:,:] == A[:,:] == reshape(1:N, shape[1], prod(shape[2:end])) - @test B[1:end,1:end] == A[1:end,1:end] == reshape(1:N, shape[1], prod(shape[2:end])) + @test B[:,:] == A[:,:] == collect(1:N, (shape[1], prod(shape[2:end]))) + @test B[1:end,1:end] == A[1:end,1:end] == collect(1:N, (shape[1], prod(shape[2:end]))) # Test with containers that aren't Int[] @test B[[]] == A[[]] == [] @test B[convert(Array{Any}, idxs)] == A[convert(Array{Any}, idxs)] == idxs @@ -202,7 +202,7 @@ end function test_primitives{T}(::Type{T}, shape, ::Type{TestAbstractArray}) N = prod(shape) - A = reshape(1:N, shape) + A = collect(1:N, shape) B = T(A) # last(a) @@ -221,9 +221,6 @@ function test_primitives{T}(::Type{T}, shape, ::Type{TestAbstractArray}) @test isassigned(B, length(B) + 1) == false end - # reshape(a::AbstractArray, dims::Dims) - @test_throws ArgumentError reshape(B, (0, 1)) - # copy!(dest::AbstractArray, src::AbstractArray) @test_throws BoundsError copy!(Array(Int, 10), [1:11...]) @@ -252,7 +249,7 @@ type UnimplementedArray{T, N} <: AbstractArray{T, N} end function test_getindex_internals{T}(::Type{T}, shape, ::Type{TestAbstractArray}) N = prod(shape) - A = reshape(1:N, shape) + A = collect(1:N, shape) B = T(A) @test getindex(A) == 1 @@ -272,7 +269,7 @@ end function test_setindex!_internals{T}(::Type{T}, shape, ::Type{TestAbstractArray}) N = prod(shape) - A = reshape(1:N, shape) + A = collect(1:N, shape) B = T(A) Base.unsafe_setindex!(B, 1) @@ -362,7 +359,7 @@ function test_ind2sub(::Type{TestAbstractArray}) n = rand(2:5) dims = tuple(rand(1:5, n)...) len = prod(dims) - A = reshape(1:len, dims...) + A = collect(1:len, dims) I = ind2sub(dims, [1:len...]) for i in 1:len idx = [ I[j][i] for j in 1:n ] diff --git a/test/arrayops.jl b/test/arrayops.jl index c4b8c80f5c195..6433ff4e3deb8 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -100,11 +100,11 @@ a = rand(1, 1, 8, 8, 1) @test_throws ArgumentError squeeze(a, 6) sz = (5,8,7) -A = reshape(1:prod(sz),sz...) +A = collect(1:prod(sz), sz) @test A[2:6] == [2:6;] @test A[1:3,2,2:4] == cat(2,46:48,86:88,126:128) @test A[:,7:-3:1,5] == [191 176 161; 192 177 162; 193 178 163; 194 179 164; 195 180 165] -@test A[:,3:9] == reshape(11:45,5,7) +@test A[:,3:9] == collect(11:45, (5,7)) rng = (2,2:3,2:2:5) tmp = zeros(Int,map(maximum,rng)...) tmp[rng...] = A[rng...] @@ -138,7 +138,7 @@ B[[3,1],[2,4]] = [21 22; 23 24] B[4,[2,3]] = 7 @test B == [0 23 1 24 0; 11 12 13 14 15; 0 21 3 22 0; 0 7 7 0 0] -@test isequal(reshape(1:27, 3, 3, 3)[1,:], [1, 4, 7, 10, 13, 16, 19, 22, 25]) +@test isequal(collect(1:27, (3, 3, 3))[1,:], [1, 4, 7, 10, 13, 16, 19, 22, 25]) a = [3, 5, -7, 6] b = [4, 6, 2, -7, 1] @@ -169,7 +169,7 @@ rt = Base.return_types(setindex!, Tuple{Array{Int32, 3}, UInt8, Vector{Int}, Int # get let - A = reshape(1:24, 3, 8) + A = collect(1:24, (3, 8)) x = get(A, 32, -12) @test x == -12 x = get(A, 14, -12) @@ -368,7 +368,7 @@ p = permutedims(s, [2,1]) @test p[2,1]==a[2,3] && p[2,2]==a[3,3] # of a non-strided subarray -a = reshape(1:60, 3, 4, 5) +a = collect(1:60, (3, 4, 5)) s = sub(a,:,[1,2,4],[1,5]) c = convert(Array, s) for p in ([1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]) @@ -553,7 +553,7 @@ let 3 3 4 4 3 3 4 4; 3 3 4 4 3 3 4 4] - A = reshape(1:8, 2, 2, 2) + A = collect(1:8, (2, 2, 2)) R = repeat(A, inner = [1, 1, 2], outer = [1, 1, 1]) T = reshape([1:4; 1:4; 5:8; 5:8], 2, 2, 4) @test R == T @@ -623,7 +623,7 @@ a[[true,false,true,false,true]] = 6 a[[true,false,true,false,true]] = [7,8,9] @test a == [7,2,8,4,9] @test_throws DimensionMismatch (a[[true,false,true,false,true]] = [7,8,9,10]) -A = reshape(1:15, 3, 5) +A = collect(1:15, (3, 5)) @test A[[true, false, true], [false, false, true, true, false]] == [7 10; 9 12] @test_throws BoundsError A[[true, false], [false, false, true, true, false]] @test_throws BoundsError A[[true, false, true], [false, true, true, false]] @@ -1092,7 +1092,7 @@ a = ones(5,0) b = sub(a, :, :) @test mdsum(b) == 0 -a = reshape(1:60, 3, 4, 5) +a = collect(1:60, (3, 4, 5)) @test a[CartesianIndex{3}(2,3,4)] == 44 a[CartesianIndex{3}(2,3,3)] = -1 @test a[CartesianIndex{3}(2,3,3)] == -1 @@ -1353,7 +1353,6 @@ C = copy(B) @test A == C @test B == C -@test vec(A) == vec(B) == vec(S) @test minimum(A) == minimum(B) == minimum(S) @test maximum(A) == maximum(B) == maximum(S) diff --git a/test/dict.jl b/test/dict.jl index 9c3df2ccd2c10..4f24fced8b7f0 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -262,7 +262,7 @@ end # show for d in (Dict("\n" => "\n", "1" => "\n", "\n" => "2"), [string(i) => i for i = 1:30], - [reshape(1:i^2,i,i) => reshape(1:i^2,i,i) for i = 1:24], + [collect(1:i^2,(i,i)) => collect(1:i^2,(i,i)) for i = 1:24], [utf8(Char['α':'α'+i;]) => utf8(Char['α':'α'+i;]) for i = (1:10)*10], Dict("key" => zeros(0, 0))) for cols in (12, 40, 80), rows in (2, 10, 24) diff --git a/test/examples.jl b/test/examples.jl index 9c8b4a7b543d6..d96410d42a2fc 100644 --- a/test/examples.jl +++ b/test/examples.jl @@ -22,10 +22,10 @@ y = inv(x) include(joinpath(dir, "ndgrid.jl")) r = repmat(1:10,1,10) -r1, r2 = ndgrid(1:10, 1:10) +r1, r2 = ndgrid(collect(1:10), collect(1:10)) @test r1 == r @test r2 == r' -r3, r4 = meshgrid(1:10,1:10) +r3, r4 = meshgrid(collect(1:10),collect(1:10)) @test r3 == r' @test r4 == r diff --git a/test/fft.jl b/test/fft.jl index 354964ec88324..0f46220d04a69 100644 --- a/test/fft.jl +++ b/test/fft.jl @@ -31,7 +31,7 @@ b = rand(17,14) b[3:6,9:12] = m4 sm4 = slice(b,3:6,9:12) -m3d = map(Float32,reshape(1:5*3*2, 5, 3, 2)) +m3d = map(Float32,collect(1:5*3*2, (5, 3, 2))) true_fftd3_m3d = Array(Float32, 5, 3, 2) true_fftd3_m3d[:,:,1] = 17:2:45 true_fftd3_m3d[:,:,2] = -15 diff --git a/test/functional.jl b/test/functional.jl index bbe480f5bb5cd..0727bd8f865a3 100644 --- a/test/functional.jl +++ b/test/functional.jl @@ -220,7 +220,7 @@ end @test collect((i+10j for i=1:2,j=3:4,k=1:1)) == reshape([31 41; 32 42], (2,2,1)) let I = Base.IteratorND(1:27,(3,3,3)) - @test collect(I) == reshape(1:27,(3,3,3)) + @test collect(I) == collect(1:27,(3,3,3)) @test size(I) == (3,3,3) @test length(I) == 27 @test eltype(I) === Int diff --git a/test/linalg/matmul.jl b/test/linalg/matmul.jl index 7885d850e0f85..a4b111711a2b0 100644 --- a/test/linalg/matmul.jl +++ b/test/linalg/matmul.jl @@ -114,7 +114,7 @@ C = zeros(Float64,6,6) @test Base.LinAlg.Ac_mul_B!(C,A,B) == A.'*B # matrix algebra with subarrays of floats (stride != 1) -A = reshape(map(Float64,1:20),5,4) +A = collect(1.0:20.0, (5,4)) Aref = A[1:2:end,1:2:end] Asub = sub(A, 1:2:5, 1:2:4) b = [1.2,-2.5] @@ -127,23 +127,23 @@ Asub = sub(Ai, 1:2:5, 1:2:4) @test Ac_mul_B(Asub, Asub) == Ac_mul_B(Aref, Aref) @test A_mul_Bc(Asub, Asub) == A_mul_Bc(Aref, Aref) # issue #15286 -let C = zeros(8, 8), sC = sub(C, 1:2:8, 1:2:8), B = reshape(map(Float64,-9:10),5,4) +let C = zeros(8, 8), sC = sub(C, 1:2:8, 1:2:8), B = collect(-9.0:10.0, (5,4)) @test At_mul_B!(sC, A, A) == A'*A @test At_mul_B!(sC, A, B) == A'*B end -let Aim = A .- im, C = zeros(Complex128,8,8), sC = sub(C, 1:2:8, 1:2:8), B = reshape(map(Float64,-9:10),5,4) .+ im +let Aim = A .- im, C = zeros(Complex128,8,8), sC = sub(C, 1:2:8, 1:2:8), B = collect(-9.0:10.0, (5,4)) .+ im @test Ac_mul_B!(sC, Aim, Aim) == Aim'*Aim @test Ac_mul_B!(sC, Aim, B) == Aim'*B end # syrk & herk -A = reshape(1:1503, 501, 3).-750.0 +A = collect(1:1503, (501, 3)).-750.0 res = Float64[135228751 9979252 -115270247; 9979252 10481254 10983256; -115270247 10983256 137236759] @test At_mul_B(A, A) == res @test A_mul_Bt(A',A') == res cutoff = 501 -A = reshape(1:6*cutoff,2*cutoff,3).-(6*cutoff)/2 +A = collect(1:6*cutoff, (2*cutoff,3)).-(6*cutoff)/2 Asub = sub(A, 1:2:2*cutoff, 1:3) Aref = A[1:2:2*cutoff, 1:3] @test At_mul_B(Asub, Asub) == At_mul_B(Aref, Aref) diff --git a/test/parallel_exec.jl b/test/parallel_exec.jl index 3910e9d52d649..dbedbaac90109 100644 --- a/test/parallel_exec.jl +++ b/test/parallel_exec.jl @@ -311,7 +311,7 @@ d = SharedArray(Float64, (2,3)) fn = tempname() write(fn, 1:30) sz = (6,5) -Atrue = reshape(1:30, sz) +Atrue = collect(1:30, sz) S = SharedArray(fn, Int, sz) @test S == Atrue diff --git a/test/reduce.jl b/test/reduce.jl index 3e4f0e3e8ec36..7787607d34c04 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -45,7 +45,7 @@ @test sum([3]) === 3 @test sum([3.0]) === 3.0 -z = reshape(1:16, (2,2,2,2)) +z = collect(1:16, (2,2,2,2)) fz = float(z) @test sum(z) === 136 @test sum(fz) === 136.0 @@ -167,9 +167,9 @@ prod2(itr) = invoke(prod, Tuple{Any}, itr) @test maximum(collect(Int16(1):Int16(100))) === Int16(100) @test maximum(Int32[1,2]) === Int32(2) -@test extrema(reshape(1:24,2,3,4),1) == reshape([(1,2),(3,4),(5,6),(7,8),(9,10),(11,12),(13,14),(15,16),(17,18),(19,20),(21,22),(23,24)],1,3,4) -@test extrema(reshape(1:24,2,3,4),2) == reshape([(1,5),(2,6),(7,11),(8,12),(13,17),(14,18),(19,23),(20,24)],2,1,4) -@test extrema(reshape(1:24,2,3,4),3) == reshape([(1,19),(2,20),(3,21),(4,22),(5,23),(6,24)],2,3,1) +@test extrema(collect(1:24,(2,3,4)),1) == reshape([(1,2),(3,4),(5,6),(7,8),(9,10),(11,12),(13,14),(15,16),(17,18),(19,20),(21,22),(23,24)],1,3,4) +@test extrema(collect(1:24,(2,3,4)),2) == reshape([(1,5),(2,6),(7,11),(8,12),(13,17),(14,18),(19,23),(20,24)],2,1,4) +@test extrema(collect(1:24,(2,3,4)),3) == reshape([(1,19),(2,20),(3,21),(4,22),(5,23),(6,24)],2,3,1) # any & all @@ -275,11 +275,11 @@ end @test sum(collect(map(UInt8,0:255))) == 32640 @test sum(collect(map(UInt8,254:255))) == 509 -A = reshape(map(UInt8, 101:109), (3,3)) +A = collect(UInt8(101):UInt8(109), (3,3)) @test @inferred(sum(A)) == 945 @test @inferred(sum(sub(A, 1:3, 1:3))) == 945 -A = reshape(map(UInt8, 1:100), (10,10)) +A = collect(UInt8(1):UInt8(100), (10,10)) @test @inferred(sum(A)) == 5050 @test @inferred(sum(sub(A, 1:10, 1:10))) == 5050 diff --git a/test/reducedim.jl b/test/reducedim.jl index 1c74fa5b3959c..9cc6c79edb51d 100644 --- a/test/reducedim.jl +++ b/test/reducedim.jl @@ -78,13 +78,13 @@ fill!(r, -1.1) @test_approx_eq sumabs2!(r, Breduc, init=false) safe_sumabs2(Breduc, 1)-1.1 # Small arrays with init=false -A = reshape(1:15, 3, 5) +A = collect(1:15, (3, 5)) R = ones(Int, 3) @test sum!(R, A, init=false) == [36,41,46] R = ones(Int, 1, 5) @test sum!(R, A, init=false) == [7 16 25 34 43] R = [2] -A = reshape(1:6, 3, 2) +A = collect(1:6, (3, 2)) @test prod!(R, A, init=false) == [1440] # Small integers diff --git a/test/show.jl b/test/show.jl index 16f3e47584792..b3900850d3ddb 100644 --- a/test/show.jl +++ b/test/show.jl @@ -347,7 +347,7 @@ end @test replstr(collect(1.:100.)) == "100-element Array{Float64,1}:\n 1.0\n 2.0\n 3.0\n 4.0\n 5.0\n 6.0\n 7.0\n 8.0\n 9.0\n 10.0\n ⋮ \n 92.0\n 93.0\n 94.0\n 95.0\n 96.0\n 97.0\n 98.0\n 99.0\n 100.0" @test replstr(collect(1.:100.)') == "1x100 Array{Float64,2}:\n 1.0 2.0 3.0 4.0 5.0 6.0 7.0 … 95.0 96.0 97.0 98.0 99.0 100.0" # too big in both directions to fit on screen: -@test replstr((1.:100.)*(1:100)') == "100x100 Array{Float64,2}:\n 1.0 2.0 3.0 4.0 5.0 6.0 … 97.0 98.0 99.0 100.0\n 2.0 4.0 6.0 8.0 10.0 12.0 194.0 196.0 198.0 200.0\n 3.0 6.0 9.0 12.0 15.0 18.0 291.0 294.0 297.0 300.0\n 4.0 8.0 12.0 16.0 20.0 24.0 388.0 392.0 396.0 400.0\n 5.0 10.0 15.0 20.0 25.0 30.0 485.0 490.0 495.0 500.0\n 6.0 12.0 18.0 24.0 30.0 36.0 … 582.0 588.0 594.0 600.0\n 7.0 14.0 21.0 28.0 35.0 42.0 679.0 686.0 693.0 700.0\n 8.0 16.0 24.0 32.0 40.0 48.0 776.0 784.0 792.0 800.0\n 9.0 18.0 27.0 36.0 45.0 54.0 873.0 882.0 891.0 900.0\n 10.0 20.0 30.0 40.0 50.0 60.0 970.0 980.0 990.0 1000.0\n ⋮ ⋮ ⋱ \n 92.0 184.0 276.0 368.0 460.0 552.0 8924.0 9016.0 9108.0 9200.0\n 93.0 186.0 279.0 372.0 465.0 558.0 9021.0 9114.0 9207.0 9300.0\n 94.0 188.0 282.0 376.0 470.0 564.0 9118.0 9212.0 9306.0 9400.0\n 95.0 190.0 285.0 380.0 475.0 570.0 9215.0 9310.0 9405.0 9500.0\n 96.0 192.0 288.0 384.0 480.0 576.0 … 9312.0 9408.0 9504.0 9600.0\n 97.0 194.0 291.0 388.0 485.0 582.0 9409.0 9506.0 9603.0 9700.0\n 98.0 196.0 294.0 392.0 490.0 588.0 9506.0 9604.0 9702.0 9800.0\n 99.0 198.0 297.0 396.0 495.0 594.0 9603.0 9702.0 9801.0 9900.0\n 100.0 200.0 300.0 400.0 500.0 600.0 9700.0 9800.0 9900.0 10000.0" +@test replstr(collect(1.:100.)*(1:100)') == "100x100 Array{Float64,2}:\n 1.0 2.0 3.0 4.0 5.0 6.0 … 97.0 98.0 99.0 100.0\n 2.0 4.0 6.0 8.0 10.0 12.0 194.0 196.0 198.0 200.0\n 3.0 6.0 9.0 12.0 15.0 18.0 291.0 294.0 297.0 300.0\n 4.0 8.0 12.0 16.0 20.0 24.0 388.0 392.0 396.0 400.0\n 5.0 10.0 15.0 20.0 25.0 30.0 485.0 490.0 495.0 500.0\n 6.0 12.0 18.0 24.0 30.0 36.0 … 582.0 588.0 594.0 600.0\n 7.0 14.0 21.0 28.0 35.0 42.0 679.0 686.0 693.0 700.0\n 8.0 16.0 24.0 32.0 40.0 48.0 776.0 784.0 792.0 800.0\n 9.0 18.0 27.0 36.0 45.0 54.0 873.0 882.0 891.0 900.0\n 10.0 20.0 30.0 40.0 50.0 60.0 970.0 980.0 990.0 1000.0\n ⋮ ⋮ ⋱ \n 92.0 184.0 276.0 368.0 460.0 552.0 8924.0 9016.0 9108.0 9200.0\n 93.0 186.0 279.0 372.0 465.0 558.0 9021.0 9114.0 9207.0 9300.0\n 94.0 188.0 282.0 376.0 470.0 564.0 9118.0 9212.0 9306.0 9400.0\n 95.0 190.0 285.0 380.0 475.0 570.0 9215.0 9310.0 9405.0 9500.0\n 96.0 192.0 288.0 384.0 480.0 576.0 … 9312.0 9408.0 9504.0 9600.0\n 97.0 194.0 291.0 388.0 485.0 582.0 9409.0 9506.0 9603.0 9700.0\n 98.0 196.0 294.0 392.0 490.0 588.0 9506.0 9604.0 9702.0 9800.0\n 99.0 198.0 297.0 396.0 495.0 594.0 9603.0 9702.0 9801.0 9900.0\n 100.0 200.0 300.0 400.0 500.0 600.0 9700.0 9800.0 9900.0 10000.0" # Issue 14121 @test_repr "(A'x)'" @@ -384,7 +384,7 @@ str_ex2a, str_ex2b = @strquote(begin x end), string(quote x end) # test structured zero matrix printing for select structured types -A = reshape(1:16,4,4) +A = collect(1:16,(4,4)) @test replstr(Diagonal(A)) == "4x4 Diagonal{$Int}:\n 1 ⋅ ⋅ ⋅\n ⋅ 6 ⋅ ⋅\n ⋅ ⋅ 11 ⋅\n ⋅ ⋅ ⋅ 16" @test replstr(Bidiagonal(A,true)) == "4x4 Bidiagonal{$Int}:\n 1 5 ⋅ ⋅\n ⋅ 6 10 ⋅\n ⋅ ⋅ 11 15\n ⋅ ⋅ ⋅ 16" @test replstr(Bidiagonal(A,false)) == "4x4 Bidiagonal{$Int}:\n 1 ⋅ ⋅ ⋅\n 2 6 ⋅ ⋅\n ⋅ 7 11 ⋅\n ⋅ ⋅ 12 16" diff --git a/test/sparsedir/sparse.jl b/test/sparsedir/sparse.jl index b1cafee51d79f..b9c5c833a95cc 100644 --- a/test/sparsedir/sparse.jl +++ b/test/sparsedir/sparse.jl @@ -63,7 +63,7 @@ for i = 1 : 10 end # sparse ref -a116 = reshape(1:16, 4, 4) +a116 = collect(1:16, (4, 4)) s116 = sparse(a116) p = [4, 1, 2, 3, 2] @test full(s116[p,:]) == a116[p,:] @@ -77,8 +77,8 @@ s116[p, p] = -1 @test a116 == s116 p = [2, 1, 4] -a116[p, p] = reshape(1:9, 3, 3) -s116[p, p] = reshape(1:9, 3, 3) +a116[p, p] = collect(1:9, (3, 3)) +s116[p, p] = collect(1:9, (3, 3)) @test a116 == s116 # matrix-vector multiplication (non-square) @@ -433,7 +433,7 @@ end # getindex tests ni = 23 nj = 32 -a116 = reshape(1:(ni*nj), ni, nj) +a116 = collect(1:(ni*nj), (ni, nj)) s116 = sparse(a116) ad116 = diagm(diag(a116)) diff --git a/test/subarray.jl b/test/subarray.jl index 8aed951ccc382..6844d968b8631 100644 --- a/test/subarray.jl +++ b/test/subarray.jl @@ -284,7 +284,7 @@ index25 = (3, 8, :, 2:11, 12:3:22, [4,1,5,9], sub(1:25,[13,22,24])) index125 = (113, :, 85:121, 2:15:92, [99,14,103], sub(1:125,[66,18,59])) if testfull - let A = reshape(1:5*7*11, 11, 7, 5) + let A = collect(1:5*7*11, (11, 7, 5)) runviews(A, index5, index25, index125) end end @@ -296,7 +296,7 @@ end oindex = (:, 6, 3:7, 13:-2:1, [8,4,6,12,5,7]) if testfull - let B = reshape(1:13^3, 13, 13, 13) + let B = collect(1:13^3, (13, 13, 13)) for o3 in oindex, o2 in oindex, o1 in oindex sliceB = slice(B, o1, o2, o3) runviews(sliceB, index5, index25, index125) @@ -307,7 +307,7 @@ if testfull end if !testfull - let B = reshape(1:13^3, 13, 13, 13) + let B = collect(1:13^3, (13, 13, 13)) for oind in ((:,:,:), (:,:,6), (:,6,:), @@ -340,7 +340,7 @@ x11289 = randn(5,5) ####### "Classical" tests ####### # sub -A = reshape(1:120, 3, 5, 8) +A = collect(1:120, (3, 5, 8)) sA = sub(A, 2, 1:5, :) @test strides(sA) == (1, 3, 15) @test parent(sA) == A @@ -379,13 +379,13 @@ sA = sub(A, 1:2:3, 1:3:5, 1:2:8) A = sub([1:10;], 5:8) @test A[A.<7] == [5, 6] @test Base.unsafe_getindex(A, A.<7) == [5, 6] -B = reshape(1:16, 4, 4) +B = collect(1:16, (4, 4)) sB = sub(B, 2:3, 2:3) @test sB[sB.>8] == [10, 11] @test Base.unsafe_getindex(sB, sB.>8) == [10, 11] # slice -A = reshape(1:120, 3, 5, 8) +A = collect(1:120, (3, 5, 8)) sA = slice(A, 2, :, 1:8) @test parent(sA) == A @test parentindexes(sA) == (2, :, 1:8) @@ -422,7 +422,7 @@ sA[msk] = 1.0 # bounds checking upon construction; see #4044, #10296 @test_throws BoundsError sub(1:10, 8:11) -A = reshape(1:20, 5, 4) +A = collect(1:20, (5, 4)) sA = sub(A, 1:2, 1:3) @test_throws BoundsError sub(sA, 1:3, 1:3) @test_throws BoundsError sub(sA, 1:2, 1:4) @@ -431,7 +431,7 @@ sub(sA, 1:2, 1:2) sub(A, 17:20) # Linear indexing by one multidimensional array: -A = reshape(1:120, 3, 5, 8) +A = collect(1:120, (3, 5, 8)) sA = sub(A, :, :, :) @test sA[[72 17; 107 117]] == [72 17; 107 117] @test sA[[99 38 119 14 76 81]] == [99 38 119 14 76 81] @@ -453,7 +453,7 @@ let a = [1,2,3], @test b == slice(a, UInt(1):UInt(2)) == slice(slice(a, :), UInt(1):UInt(2)) == [1,2] end -let A = reshape(1:4, 2, 2) +let A = collect(1:4, (2, 2)) B = sub(A, :, :) @test parent(B) === A @test parent(sub(B, 0x1, :)) === parent(slice(B, 0x1, :)) === A