From e12049b6617397af690bd7b1278ddd75aca205f5 Mon Sep 17 00:00:00 2001 From: Daniel VandenHeuvel <95613936+DanielVandH@users.noreply.github.com> Date: Mon, 1 Jul 2024 14:23:22 +0100 Subject: [PATCH] Revert "Infinite random sequences (#181)" This reverts commit 8865985e7d241d3a1c1ab473d9f846b1aff79e94. --- Project.toml | 24 +++++++--------- src/InfiniteArrays.jl | 8 ++---- src/infrand.jl | 64 ------------------------------------------- test/runtests.jl | 7 ++--- test/test_infrand.jl | 32 ---------------------- 5 files changed, 15 insertions(+), 120 deletions(-) delete mode 100644 src/infrand.jl delete mode 100644 test/test_infrand.jl diff --git a/Project.toml b/Project.toml index a934843..7b681af 100644 --- a/Project.toml +++ b/Project.toml @@ -9,45 +9,41 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" Infinities = "e1ba4f0e-776d-440f-acd9-e1d2e9742647" LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" -[weakdeps] -DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2" -Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[extensions] -InfiniteArraysDSPExt = "DSP" -InfiniteArraysStatisticsExt = "Statistics" - [compat] Aqua = "0.8" ArrayLayouts = "1.8" BandedMatrices = "1.0" -Base64 = "1" BlockArrays = "1.0" +Base64 = "1" DSP = "0.7" -Distributions = "0.25" FillArrays = "1.0" Infinities = "0.1.1" LazyArrays = "2.0.2" LinearAlgebra = "1.6" -Random = "1" SparseArrays = "1" Statistics = "1" Test = "1" julia = "1.10" +[extensions] +InfiniteArraysDSPExt = "DSP" +InfiniteArraysStatisticsExt = "Statistics" + [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" BandedMatrices = "aae01518-5342-5314-be14-df237901396f" Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2" -Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua", "Test", "BandedMatrices", "BlockArrays", "Statistics", "SparseArrays", "Base64", "DSP", "Distributions"] +test = ["Aqua", "Test", "BandedMatrices", "BlockArrays", "Statistics", "SparseArrays", "Base64", "DSP"] + +[weakdeps] +DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/src/InfiniteArrays.jl b/src/InfiniteArrays.jl index 99d3a54..5854d31 100644 --- a/src/InfiniteArrays.jl +++ b/src/InfiniteArrays.jl @@ -10,7 +10,7 @@ import Base: *, +, -, /, <, ==, >, \, ≤, ≥, (:), @propagate_inbounds, cumsum, dataids, diff, div, eltype, fill, findfirst, first, floatrange, getindex, hcat, in, ind2sub_rs, intersect, inv, isempty, isinf, issorted, last, length, lt, max, maximum, minimum, mod, one, ones, parent, parentindices, permutedims, print_matrix, print_matrix_row, - print_matrix_vdots, promote_rule, rand, reinterpret, reshape, reverse, searchsorted, + print_matrix_vdots, promote_rule, reinterpret, reshape, reverse, searchsorted, searchsortedfirst, searchsortedlast, setindex!, show, show_circular, show_delim_array, sign, signbit, similar, size, sort, sort!, step, sum, tail, to_shape, transpose, unaliascopy, union, unitrange_last, unsafe_convert, unsafe_indices, unsafe_length, @@ -42,15 +42,12 @@ import FillArrays: AbstractFill, Eye, Fill, Ones, RectDiagonal, Zeros, fill_resh import Infinities: InfiniteCardinal, Infinity, ∞ import LazyArrays: AbstractCachedVector, ApplyLayout, CachedArray, CachedVector, InvColumnLayout, - LazyArrayStyle, LazyLayout, LazyMatrix, PaddedColumns, _padded_sub_materialize, resizedata!, - sub_paddeddata + LazyArrayStyle, LazyLayout, LazyMatrix, PaddedColumns, _padded_sub_materialize, sub_paddeddata import LinearAlgebra: AdjOrTrans, HermOrSym, diag, norm, norm1, norm2, normp import LazyArrays: AbstractPaddedLayout -import Random: default_rng - export ∞, ℵ₀, Hcat, Vcat, Zeros, Ones, Fill, Eye, BroadcastArray, cache import Base: unitrange, oneto @@ -59,7 +56,6 @@ import Base: unitrange, oneto include("infrange.jl") include("infarrays.jl") include("reshapedarray.jl") -include("infrand.jl") ## # Fill FillArrays diff --git a/src/infrand.jl b/src/infrand.jl deleted file mode 100644 index fe35f16..0000000 --- a/src/infrand.jl +++ /dev/null @@ -1,64 +0,0 @@ -""" - InfRandVector([rng=default_rng()], [dist=Float64]) - -Represents a random infinite sequence. The random number generator can be specified -by the first argument `rng`, which defaults to `Random.default_rng()`, and the distribution -to generate from can be specified using the `dist` argument, which defaults to `Float64`. - -```julia-repl -julia> using InfiniteArrays - -julia> seq = InfiniteArrays.InfRandVector(); - -julia> seq[1] -0.6947847847152157 - -julia> seq[1:5] -5-element Vector{Float64}: - 0.6947847847152157 - 0.49859004150722164 - 0.31559745572937126 - 0.5338596092137163 - 0.14792462133894646 - -julia> using Distributions, Random - -julia> seq = InfiniteArrays.InfRandVector(MersenneTwister(123), Normal(0.3, 1.7)) -ℵ₀-element InfRandVector{Float64, Normal{Float64}, MersenneTwister} with indices 1:∞: - 2.3234553976766703 - 3.7819055032417075 - 2.242506534874238 - 1.0810065546920364 - -0.3743544348018791 - -0.8300113268258689 - 1.967645305489507 - ⋮ -``` -""" -mutable struct InfRandVector{T,D,RNG} <: AbstractCachedVector{T} - const rng::RNG - const dist::D - const data::Vector{T} - datasize::Int -end -function InfRandVector(rng=default_rng(), dist=Float64) - T = typeof(rand(copy(rng), dist)) - _rng = copy(rng) - return InfRandVector{T,typeof(dist),typeof(_rng)}(_rng, dist, T[], 0) -end -Base.size(::InfRandVector) = (ℵ₀,) -Base.axes(::InfRandVector) = (1:ℵ₀,) -Base.length(::InfRandVector) = ℵ₀ -function resizedata!(seq::InfRandVector, inds) - newlen = maximum(inds) - curlen = length(seq.data) - newlen > curlen || return seq - resize!(seq.data, newlen) - # rand!(seq.rng, view(seq.data, curlen+1:newlen), seq.dist) - # ^ rand() is not actually sequential.. rand(Random.seed!(123), 1000) ≠ (rng = Random.seed!(123); [rand(rng) for _ in 1:1000]) - for i in (curlen+1):newlen - seq.data[i] = rand(seq.rng, seq.dist) - end - seq.datasize = newlen - return seq -end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 1907be5..6ddbc9f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ -using LinearAlgebra, SparseArrays, InfiniteArrays, Infinities, FillArrays, LazyArrays, Random, Statistics, Test, Base64 -using BandedMatrices, Distributions +using LinearAlgebra, SparseArrays, InfiniteArrays, Infinities, FillArrays, LazyArrays, Statistics, Test, Base64 +using BandedMatrices import InfiniteArrays: InfUnitRange, InfStepRange, OneToInf, NotANumber, oneto, unitrange import LazyArrays: CachedArray, MemoryLayout, LazyLayout, DiagonalLayout, LazyArrayStyle, colsupport, DualLayout import BandedMatrices: _BandedMatrix, BandedColumns @@ -1230,5 +1230,4 @@ end end include("test_infconv.jl") -include("test_block.jl") -include("test_infrand.jl") \ No newline at end of file +include("test_block.jl") \ No newline at end of file diff --git a/test/test_infrand.jl b/test/test_infrand.jl deleted file mode 100644 index 1019a8f..0000000 --- a/test/test_infrand.jl +++ /dev/null @@ -1,32 +0,0 @@ -@testset "InfRandVector" begin - @testset "Default constructor" begin - Random.seed!(123) - seq = InfiniteArrays.InfRandVector() - val = seq[1] - @test seq[1] == val # constant - @test seq[1:10000] == seq[1:10000] - @test seq[1] == val # didn't change after resizing - @inferred seq[1] - Random.seed!(123) - _seq = [rand() for _ in 1:1000] - @test seq[1:1000] == _seq[1:1000] - @test size(seq) == (ℵ₀,) - @test length(seq) == ℵ₀ - @test axes(seq) == (1:ℵ₀,) - end - - @testset "Providing an RNG and a distribution" begin - rng = MersenneTwister(123) - seq = InfiniteArrays.InfRandVector(rng, Float16) - rng2 = MersenneTwister(123) - @test seq[1:10000] == [rand(rng2, Float16) for _ in 1:10000] - end - - @testset "Distributions.jl" begin - dist = Normal(0.3, 1.7) # do Normal{Float32} for example if you want that number type - rng = Xoshiro(5) - seq = InfiniteArrays.InfRandVector(rng, dist) - rng2 = Xoshiro(5) - @test seq[1:100] == [0.3 + 1.7randn(rng2) for _ in 1:100] - end -end \ No newline at end of file