Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Syntax for type stability in Turing.jl

$
0
0

@sudete wrote:

Turing.jl recommends to replace

@model tmodel(x, y) = begin
    p,n = size(x)
    params = Vector{Real}(undef, n)
    for i = 1:n
        params[i] ~ truncated(Normal(), 0, Inf)
    end

    a = x * params
    y ~ MvNormal(a, 1.0)
end

with

@model tmodel(x, y, ::Type{T}=Vector{Float64}) where {T} = begin
    ...
    params = T(undef, n)
    ...
end

This looks overly complicated to me… Why not simply:

@model tmodel(x, y) = begin
    ...
    params = Vector{Float64}(undef, n)
    ...
end

This doesn’t allow specifying a non-default type, but neither does the original version?

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles