Ah, that makes sense. I've mostly been working with Floats, so I didn't
realise there was an Int type.

On Thu, 7 Jan 2016 at 23:02 Kristoffer Carlsson <[email protected]>
wrote:

> Just an unsolicited tip here.
>
> Try not to "over type" your functions. Your function here would be
> cumbersome to use for someone on a 32-bit system for example. Unless you
> have a good reason, prefer Int instead of explicit Int32 / Int64.
>
>
> On Thursday, January 7, 2016 at 7:18:31 PM UTC+1, Asbjørn Nilsen Riseth
> wrote:
>>
>> For future reference, I used the following:
>>
>> function traverse(numpoints::Int64, β::Array{Int64}, level::Int64 = 1)
>>     N = length(β)
>>     @assert 0 < level < N
>>
>>     for i = 0:numpoints-sum(β[1:level-1])
>>         β[level] = i
>>         if level < N-2
>>             traverse(numpoints, β, level+1)
>>         else
>>             for j = 0:numpoints-sum(β[1:N-2])
>>                 β[N-1] = j
>>                 β[N] = numpoints - sum(β[1:N-1])
>>                 @show β/numpoints
>>             end
>>         end
>>     end
>> end
>> traverse(5, Array{Int64}(4))
>>
>> Asbjørn
>>
>>
>> On Thursday, 7 January 2016 17:14:03 UTC, Asbjørn Nilsen Riseth wrote:
>>>
>>> Thank you both. I'll have a look at a recursion approach.
>>>
>>>
>>> On Thursday, 7 January 2016 13:47:02 UTC, Tim Holy wrote:
>>>>
>>>> This is a problem for recursion. See, for example, the LightGraphs or
>>>> Graphs
>>>> packages.
>>>>
>>>> Best,
>>>> --Tim
>>>>
>>>> On Thursday, January 07, 2016 02:10:18 AM Asbjørn Nilsen Riseth wrote:
>>>> > I would like to loop over all the \beta_i values of the following
>>>> tree.
>>>> >
>>>> > <
>>>> https://lh3.googleusercontent.com/-EBjanFs-BC4/Vo409IFAiTI/AAAAAAAAMEw/U7iq
>>>> > Ev9nPmU/s1600/tree.png>
>>>> >
>>>> > What is the best Julia way of doing this? I'm also interested in
>>>> > generalising this to N levels.
>>>> >
>>>> >
>>>> > For the given tree, the following works. *Is there a way to use
>>>> @nloops to
>>>> > shorten this?*
>>>> > n = Int(1/0.2)
>>>> > for i_3 = 0:n
>>>> >     for i_2 = 0:n-i_3
>>>> >         for i_1 = 0:n-i_2-i_3
>>>> >             i_0 = n-sum(@ntuple 3 i)
>>>> >             β = [i_3, i_2, i_1, i_0]/n
>>>> >             @show β
>>>> >         end
>>>> >     end
>>>> > end
>>>>
>>>>

Reply via email to