Skip to content

Commit

Permalink
Merge pull request #63 from ggebbie/scalar-estimate
Browse files Browse the repository at this point in the history
scalar constructor for `Estimate`
  • Loading branch information
ggebbie authored Nov 27, 2024
2 parents b238d12 + 4db030d commit 0f92cab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BLUEs"
uuid = "b3a7f272-e305-45d1-bcf3-14d22bb67726"
authors = ["G Jake Gebbie <ggebbie@whoi.edu>"]
version = "0.2.4"
version = "0.2.5"

[deps]
AlgebraicArrays = "8af735f6-f3e5-4048-bdaa-40a2355e9eea"
Expand Down
3 changes: 3 additions & 0 deletions src/BLUEs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ end
# if two vectors are provided, assume it is the standard error
Estimate(v::AbstractVector, sigma::AbstractVector) = Estimate(v, Diagonal(sigma.^2))

# allow scalar estimates and scalar standard errors to be `Estimate`s
Estimate(v::T, sigma::T) where T <: Number = Estimate([v], [sigma^2;;])

# translate Vector{Measurement} to Estimate
# let it error rather than restricting types at compile-time
function Estimate(v::AbstractVector{T}) where T <: Union{<:Measurement, Quantity{<:Measurement}}
Expand Down
4 changes: 4 additions & 0 deletions test/test_estimate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
E = randn(M,M)
aval = Measurements.value.(a)
aerr = Measurements.uncertainty.(a);

# allow scalar input to Estimate constructor
x9 = Estimate(first(aval), first(aerr))

x0 = Estimate(Measurements.value.(a),
Diagonal(aerr.^2))
x = Estimate(aval, aerr) # just provide standard error
Expand Down

0 comments on commit 0f92cab

Please sign in to comment.