Code Monkey home page Code Monkey logo

raggedarrays.jl's Introduction

RaggedArrays

Build Status Coverage Status

RaggedArrays.jl is an experimental package that tries to make a valid contiguous ragged (or jagged) array behave as normally as possible. The array "pretends" to have a size that spans the maximum extent of the ragged lengths, but accessing beyond a ragged length is a BoundsError. Specify the ragged dimension's sizes as an array argument to the constructor:

julia> R = RaggedArray(Int, [3,1,2,4], 4) # Varying column lengths
??x4 RaggedArrays.RaggedArray{Int64,2,1,1}:
 4593457072     4590781776     4590781776      4590781776
 4592320176            #undef  4590780624      4590780624
 4592320176            #undef         #undef   4590781776
        #undef         #undef         #undef  13197973264

julia> [R[i]=i for i=eachindex(R)]; R
??x4 RaggedArrays.RaggedArray{Int64,2,1,1}:
   1       4       5      7
   2     #undef    6      8
   3     #undef  #undef   9
 #undef  #undef  #undef  10

julia> R = RaggedArray(Int, 3, [3,1,2,4], 4); # Varying row lengths
       [R[i]=i for i=eachindex(R)];
       R
3x??x4 RaggedArrays.RaggedArray{Int64,3,2,1}:
[:, :, 1] =
 1  4  7  #undef
 2  5  8  #undef
 3  6  9  #undef

[:, :, 2] =
 10  #undef  #undef  #undef
 11  #undef  #undef  #undef
 12  #undef  #undef  #undef

[:, :, 3] =
 13  16  #undef  #undef
 14  17  #undef  #undef
 15  18  #undef  #undef

[:, :, 4] =
 19  22  25  28
 20  23  26  29
 21  24  27  30

julia> R[1:3, 1:3, 1] # Indexing a non-ragged subsection returns an Array
3x3 Array{Int64,2}:
 1  4  7
 2  5  8
 3  6  9

julia> R[2, :, 2:4] # Indexing with a : in the ragged dimension returns a RaggedArray
1x??x3 RaggedArrays.RaggedArray{Int64,3,2,1}:
[:, :, 1] =
 11  #undef  #undef  #undef

[:, :, 2] =
 14  17  #undef  #undef

[:, :, 3] =
 20  23  26  29

julia> R[2:3, :, 3] # But only if it spans more than one of the outer dimensions
2x2 Array{Int64,2}:
 14  17
 15  18

There is also a specialized RaggedRangeMatrix type that allows collections of ranges to behave like a ragged matrix. It depends upon RangeArrays.jl in order to return a rectangular RangeMatrix when possible:

julia> RR = RaggedRangeMatrix(1:3,3:6,7:12,-2:1)
??x4 RaggedArrays.RaggedRangeMatrix{Int64,Array{UnitRange{Int64},1}}:
   1       3      7   -2
   2       4      8   -1
   3       5      9    0
 #undef    6     10    1
 #undef  #undef  11  #undef
 #undef  #undef  12  #undef

julia> RR[1:3,2:4]
3x3 RangeArrays.RangeMatrix{Int64,Array{UnitRange{Int64},1}}:
 3  7  -2
 4  8  -1
 5  9   0

julia> RR[:, 3]
7:12

raggedarrays.jl's People

Contributors

mbauman avatar

Watchers

Gustavo Goretkin avatar James Cloos avatar Sheehan Olver avatar Alex Townsend  avatar Marcus Webb avatar Mikael Slevinsky avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.