Re: [julia-users] Re: julia style to resize array with initialization?

2015-10-27 Thread Cameron McBride
Yeah, looks like very similar arguments to 9147. Although not as easy to
circumvent as using zeros() or the like.

One potential "fix" could be a potential third argument to resize with the
"default / fill" value, which doesn't seem like a viable solution to the
constructors discussed in that thread.

Cameron

p.s. Thanks, Josh, but I think that solution would create a temporary array
(from zeros() call) on every resize. Perhaps successive push!(vec, 0.0)
might also be a good way (I know push allocates in chunks, resize might not
-- I haven't looked).


On Tue, Oct 27, 2015 at 10:36 AM, Stefan Karpinski 
wrote:

> I've encountered this too – it might make sense to zero out the grown
> memory. Of course there's the whole "to zero out uninitialized memory or
> not" discussion: https://github.com/JuliaLang/julia/issues/9147. I feel
> like this falls into that same category of questions.
>
> On Mon, Oct 26, 2015 at 3:59 PM, Josh Langsfeld  wrote:
>
>> You could do 'append!(vec, zeros(i-n))'.
>>
>>
>> On Monday, October 26, 2015 at 3:32:56 PM UTC-4, Cameron McBride wrote:
>>>
>>> Hi All,
>>>
>>> What's the best julian way to do the following:
>>>
>>> function vecadd!(vec, i, v)
>>> n = length(vec)
>>> if n < i
>>> resize!(vec, i)
>>> vec[n+1:i] = 0.0
>>> end
>>> vec[i] += v
>>> end
>>>
>>> This seems somewhat typical for a growing array that's not just
>>> incremental (i.e. not just a push!() operation), so I feel like I missed
>>> something. Better suggestions?
>>>
>>> Thanks!
>>>
>>> Cameron
>>>
>>
>


Re: [julia-users] Re: julia style to resize array with initialization?

2015-10-27 Thread Stefan Karpinski
I've encountered this too – it might make sense to zero out the grown
memory. Of course there's the whole "to zero out uninitialized memory or
not" discussion: https://github.com/JuliaLang/julia/issues/9147. I feel
like this falls into that same category of questions.

On Mon, Oct 26, 2015 at 3:59 PM, Josh Langsfeld  wrote:

> You could do 'append!(vec, zeros(i-n))'.
>
>
> On Monday, October 26, 2015 at 3:32:56 PM UTC-4, Cameron McBride wrote:
>>
>> Hi All,
>>
>> What's the best julian way to do the following:
>>
>> function vecadd!(vec, i, v)
>> n = length(vec)
>> if n < i
>> resize!(vec, i)
>> vec[n+1:i] = 0.0
>> end
>> vec[i] += v
>> end
>>
>> This seems somewhat typical for a growing array that's not just
>> incremental (i.e. not just a push!() operation), so I feel like I missed
>> something. Better suggestions?
>>
>> Thanks!
>>
>> Cameron
>>
>


[julia-users] Re: julia style to resize array with initialization?

2015-10-26 Thread Josh Langsfeld
You could do 'append!(vec, zeros(i-n))'.

On Monday, October 26, 2015 at 3:32:56 PM UTC-4, Cameron McBride wrote:
>
> Hi All, 
>
> What's the best julian way to do the following: 
>
> function vecadd!(vec, i, v)
> n = length(vec)
> if n < i
> resize!(vec, i)
> vec[n+1:i] = 0.0
> end
> vec[i] += v
> end
>
> This seems somewhat typical for a growing array that's not just 
> incremental (i.e. not just a push!() operation), so I feel like I missed 
> something. Better suggestions?
>
> Thanks!
>
> Cameron
>