Appending/Prepending Inf-values to Int64-array

I’m trying to initialize an array where a for-loop checks the iterated index value, the previous and the next index. In order to prevent uneccessary if-statements, I will use Inf-guards on both sides of the array.

I’m however not able to initialize the array correctly, as the different Inf-types does not come in Int64. How do i initialize an array of type Int64 like this: [Inf, …, Inf] ?

(The guards are used in a minimum()-expression, where Inf are not accepted in the underlying isless()-function used)

Hi @Jonas_Hjulstad,

I’m not sure what your background is, so apologies in advance if this is not relevant to you - in Julia looping through data elementwise is very fast, so you don’t need to try to vectorize all your operations like you would in Matlab or Python. That is to say, you might want to try a loop-based version of your code.

If it does turn out that you need to pre-populate an array as you describe, the problem (as you mention) is that Inf is a floating point value, not an integer, so it can’t be stored in an integer array. If you want to initialize the array to something that every other number will be less than, you can use typemax(Int) (or typemax(eltype(yourarray)) to be more flexible).

edit: re-reading your post it looks like you’re already looping over the array, and just trying to avoid the branches. So my first paragraph might not be relevant.

1 Like

Thanks! I was looking for a sort of “Inf” to put in my array, and typemax seems to solve this issue