Piecewise heterogeneous ranges?

Is there any object class for piecewise / disjoint ranges in Julia? For example, I can create a regular range:

a = UnitRange(1:5) 

But, if I would like to combine this with other ranges:

 b = UnitRange([1:5, 8:10, 4:7]) 

Currently, I cannot find an object or method. There is a PiecewiseIncreasingRanges module ( https://github.com/simonster/PiecewiseIncreasingRanges.jl ), which will be exactly what I want in this situation, except that, as the name implies, it requires ranges to increase monotonously.

The context for this is that I am looking for a way to create a compressed, memory-efficient version of SparseMatrixCSC for sparse matrices with duplicate rows. The RLEVectors module will work well to save space on a nonzero vector in a sparse matrix class. Now, although I am trying to find something to save space for the rowvalue vector, which also defines a sparse matrix, since a series of repeating rows will result in ranges of values โ€‹โ€‹in this vector (for example, if the first 10 rows or even certain columns in the first ten rows of sparse matrices are identical, then in the vector of row values โ€‹โ€‹there will be many patterns 1:10).

More generally, I need a range, such as an object b, which I am trying to create above, on which I could repeat the loop, getting:

 for (idx, item) in enumerate(hypothetical_object) println("idx: $idx, item: $item") end idx: 1, item: 1 idx: 2, item: 2 ... idx: 5, item: 5 idx: 6, item: 8 idx: 7, item: 9 idx: 8, item: 10 idx: 9, item: 4 idx: 10, item: 5 ... 

Update. One thing I'm considering, and probably trying to implement, if I don't hear the other sentences here, is just to create an array of PiecewiseIncreasingRange objects, one for each column in my sparse matrix. (I would probably also break the nonzero vector of values โ€‹โ€‹into an array of individual parts, one for each column of my sparse matrix). That would be at least relatively easy to implement. I have no good sense with a bat, how it will be compared in terms of computational efficiency to the object that I am looking for in this matter. I suspect that the memory requirements will be approximately the same.

+6
source share
1 answer

To iterate over a sequence of ranges (or other iterators), you can use the chain function in the Iterators.jl package.

For example: using Iterators b = chain(1:5, 8:10, 4:7) for i in b println(i) end displays the elements of each range.

+2
source

All Articles