Comments (4)
julia> foldl(index; init = a) do x, index x[index...] end 2-element Array{Float64,1}: 0.32155828770721984 0.14675284701717906
Now that's one ingenious fold! But yeah, I'll put a PR replacing the strings by @vinds
on my todo list, then. Although I fear that there's some code depending on the string indices in peculiar ways...
from dynamicppl.jl.
I would be happy if one could come up with a better alternative, actually I've thought about this a bit as well.
Would an equivalent of Tuple{Vararg{Union{Int, Colon}}} suffice?
To me it seemed the main issue would be nested indexing, e.g., it would not be sufficient for the third example here:
Lines 15 to 19 in 8028aaa
But actually, this example seems a bit weird - if x
is supposed to be a matrix of real numbers, one should just write x[2, 1]
instead. However, there might be a use case for matrices of vectors where one would want to write something like x[1, 2][3]
?
from dynamicppl.jl.
To me it seemed the main issue would be nested indexing.
It seems @vinds
already handles that and returns a tuple of Tuple{Vararg{Union{Int, Colon}}}
. However, it is used exactly nowhere in DPPL or Turing. @mohamed82008, have you inteded to use it in the future?
Perhaps we can also convert VarName
to the following, to have an intermediate layer of abstraction:
struct VarName{name, I, T}
indices::T
VarName(name::Symbol, indices::Vararg{<:Index, I}) where {I} =
new{name, I, typeof(indices)}(indices)
end
struct Index{N, T}
locations::T
Index(locations::Vararg{<:Union{Colon, Int}, N}) where {N} =
new{N, typeof(locations)}(locations)
end
But actually, this example seems a bit weird - if
x
is supposed to be a matrix of real numbers, one should just writex[2, 1]
instead. However, there might be a use case for matrices of vectors where one would want to write something likex[1, 2][3]
?
Maybe in nonparametric models?
One more thing: are arbitrary slices allowed, like x[2:4][begin+2:end-2]
?
from dynamicppl.jl.
It seems @vinds already handles that and returns a tuple of Tuple{Vararg{Union{Int, Colon}}}.
Ah, I did not know about @vinds
. In general, every iterable structure would be nice (but I guess a tuple is the most reasonable one here) since then one could perform, e.g.,
julia> a = [rand(2) for i in 1:5, j in 1:4]
5×4 Array{Array{Float64,1},2}:
[0.530985, 0.453194] [0.321558, 0.146753] [0.0247715, 0.334534] [0.0981353, 0.713722]
[0.521073, 0.817136] [0.972983, 0.438349] [0.0885043, 0.715975] [0.165333, 0.667311]
[0.0977404, 0.0194948] [0.913825, 0.584694] [0.227551, 0.477571] [0.524443, 0.0958542]
[0.583755, 0.328472] [0.259529, 0.397364] [0.917507, 0.169614] [0.0989215, 0.176417]
[0.930105, 0.362702] [0.262971, 0.38255] [0.54622, 0.692841] [0.317475, 0.106472]
julia> index = ((1, Colon()), (2,))
((1, Colon()), (2,))
julia> foldl(index; init = a) do x, index
x[index...]
end
2-element Array{Float64,1}:
0.32155828770721984
0.14675284701717906
without having to work with strings.
from dynamicppl.jl.
Related Issues (20)
- InferenceObjects integration HOT 12
- Adding StatsBase.predict to the API HOT 7
- `LogDensityFunction`: Temporary variable is captured as a model parameter? HOT 3
- Conditioning with Turing Chains `name_map` HOT 1
- Broken `init` for `MatrixDistribution` and `CholeskyVariate` with multiple samples
- Don't overload `rand` for test models HOT 3
- error with invlink!! and Dirichlet HOT 12
- Should we have a context to indicate that we're not performing inference?
- @model macro breaks on conditional branches with return values HOT 2
- MCMCChains for Julia < 1.9
- `logprior`, `loglikelihood`, `logjoint` are not working with `MCMCChains` in Julia 1.9 HOT 1
- Derived variables from data on the LHS of tilde HOT 10
- Decouple from Distributions.jl HOT 8
- ThreadSafeVarInfo(::SimpleVarInfo) bug with ForwardDiff HOT 1
- Need alternative to `NamedTuple` for `SimpleVarInfo` HOT 12
- Storing returned values in `VarInfo`.
- `BangBang.setindex!!(vi::SimpleVarInfo{<:AbstractDict}, val, vn::VarName)` returns eltype Any arrays when `vn` is multidimensional HOT 1
- Remove `tonamedtuple`
- Can't use `@info` in models HOT 1
- Move TestUtils to an extension
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dynamicppl.jl.