Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize uninitialized BigFloat array #9

Merged
merged 2 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
matrix:
version:
- '1'
- '~1.11.0-0'
os:
- ubuntu-latest
- macOS-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/Downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
@info "Not compatible with this release. No problem." exception=err
exit(0) # Exit immediately, as a success
end
env:
RETESTITEMS_NWORKERS: 4
RETESTITEMS_NWORKER_THREADS: 2
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MaybeInplace"
uuid = "bb5d69b7-63fc-4a16-80bd-7e42200c7bdb"
authors = ["Avik Pal <[email protected]> and contributors"]
version = "0.1.2"
version = "0.1.3"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
5 changes: 5 additions & 0 deletions src/MaybeInplace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ used by `@bangbang` to determine if an array can be setindex-ed or not.

@inline __similar(::CannotSetindex, x) = x
@inline __similar(::CanSetindex, x) = similar(x)
@inline function __similar(::CanSetindex, x::AbstractArray{<:BigFloat})
y = similar(x)
fill!(y, zero(eltype(y)))
return y
end

const OP_MAPPING = Dict{Symbol, Function}(:copyto! => __copyto!!, :.-= => __sub!!,
:.+= => __add!!, :.*= => __mul!!, :./= => __div!!, :copy => __copy)
Expand Down
17 changes: 17 additions & 0 deletions test/basictests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ function matmul!!(y, x, z)
return y
end

function get_similar(x)
@bb z = similar(x)
return z
end

@testset "copyto!" begin
x = [1.0, 1.0]
y = [0.0, 0.0]
Expand Down Expand Up @@ -88,3 +93,15 @@ end
@test matmul!!(y, x, z) == @SVector[2.0, 2.0]
@test y == @SVector[0.0, 0.0]
end

@testset "similar" begin
x = [1.0, 1.0]
z = get_similar(x)

@test_nowarn z[1]

x = BigFloat[1.0, 1.0]
z = get_similar(x)

@test_nowarn z[1] # Without correct similar this would throw UndefRefError
end
Loading