@@ -1938,6 +1938,46 @@ using TestHelpers.OAs
19381938 @test accumulate (op, [10 20 30 ], 2 ) == [10 op (10 , 20 ) op (op (10 , 20 ), 30 )] == [10 40 110 ]
19391939end
19401940
1941+ @testset " zeros and ones" begin
1942+ @test ones ([1 ,2 ], Float64, (2 ,3 )) == ones (2 ,3 )
1943+ @test ones (2 ) == ones (Int, 2 ) == ones ([2 ,3 ], Float32, 2 ) == [1 ,1 ]
1944+ @test isa (ones (2 ), Vector{Float64})
1945+ @test isa (ones (Int, 2 ), Vector{Int})
1946+ @test isa (ones ([2 ,3 ], Float32, 2 ), Vector{Float32})
1947+
1948+ function test_zeros (arr, T, s)
1949+ @test all (arr .== 0 )
1950+ @test isa (arr, T)
1951+ @test size (arr) == s
1952+ end
1953+ test_zeros (zeros (), Array{Float64, 0 }, ())
1954+ test_zeros (zeros (2 ), Vector{Float64}, (2 ,))
1955+ test_zeros (zeros (2 ,3 ), Matrix{Float64}, (2 ,3 ))
1956+ test_zeros (zeros ((2 ,3 )), Matrix{Float64}, (2 ,3 ))
1957+
1958+ test_zeros (zeros (Int, 6 ), Vector{Int}, (6 ,))
1959+ test_zeros (zeros (Int, 2 , 3 ), Matrix{Int}, (2 ,3 ))
1960+ test_zeros (zeros (Int, (2 , 3 )), Matrix{Int}, (2 ,3 ))
1961+
1962+ test_zeros (zeros ([1 2 ; 3 4 ]), Matrix{Int}, (2 , 2 ))
1963+ test_zeros (zeros ([1 2 ; 3 4 ], Float64), Matrix{Float64}, (2 , 2 ))
1964+
1965+ zs = zeros (SparseMatrixCSC ([1 2 ; 3 4 ]), Complex{Float64}, (2 ,3 ))
1966+ test_zeros (zs, SparseMatrixCSC{Complex{Float64}}, (2 , 3 ))
1967+
1968+ @testset " #19265" begin
1969+ @test_throws MethodError zeros (Float64, [1. ])
1970+ x = [1. ]
1971+ test_zeros (zeros (x, Float64), Vector{Float64}, (1 ,))
1972+ @test x == [1. ]
1973+ end
1974+
1975+ # exotic indexing
1976+ oarr = zeros (randn (3 ), UInt16, 1 : 3 , - 1 : 0 )
1977+ @test indices (oarr) == (1 : 3 , - 1 : 0 )
1978+ test_zeros (oarr. parent, Matrix{UInt16}, (3 , 2 ))
1979+ end
1980+
19411981# issue #11053
19421982type T11053
19431983 a:: Float64
0 commit comments