Comments (6)
Note blocklengths
is allocating (at the moment), so if you only need the length of the K
-th block you can do
julia> K = 2; length(axes(X,2)[Block(K)])
1
from blockarrays.jl.
Fantastic, thanks for the quick response.
Perhaps we should better document this?
Please -- it wasn't clear to me that axes
gives you the thing to which you can apply blocklengths
. The docstring is currently
help?> blocklengths
search: blocklengths blocklength
blocklengths(a::AbstractUnitRange{Int})
returns the length of each block of a.
A doctest (or simply a doctest-like docstring) providing example usage in the context of a BlockArray
would be very helpful here :)
edit: In particular, I don't believe that axes
is documented as prominently as it could be in the docs.
from blockarrays.jl.
It's blocklengths
:
julia> using BlockArrays
julia> X = BlockArray(rand(4, 4), [2,2], [1,1,2])
2×3-blocked 4×4 BlockArray{Float64,2}:
0.127212 │ 0.429535 │ 0.803334 0.864513
0.770943 │ 0.307399 │ 0.329785 0.373277
──────────┼────────────┼─────────────────────
0.907816 │ 0.90384 │ 0.734343 0.73693
0.37784 │ 0.713481 │ 0.0596666 0.6767
julia> blocklengths(axes(X,1))
2-element Array{Int64,1}:
2
2
julia> blocklengths(axes(X,2))
3-element Array{Int64,1}:
1
1
2
Perhaps we should better document this?
from blockarrays.jl.
I'm quite swamped with exams and childcare at the moment so a PR on this (and the other issue) would be very appreciated!
from blockarrays.jl.
I'm also somewhat swamped at the minute I'm afraid. Will add this to my list of things to do once I've got a bit more bandwidth.
from blockarrays.jl.
This exists now thanks to @putianyi889:
julia> X = BlockArray(rand(4, 4), [2,2], [1,1,2])
2×3-blocked 4×4 BlockArray{Float64,2}:
0.711842 │ 0.376659 │ 0.211663 0.884155
0.238994 │ 0.84558 │ 0.622881 0.770471
──────────┼────────────┼────────────────────
0.246592 │ 0.651318 │ 0.751195 0.981173
0.297894 │ 0.200701 │ 0.396812 0.815768
julia> blocksizes(X)
([2, 2], [1, 1, 2])
from blockarrays.jl.
Related Issues (20)
- ldiv! ambiguous for fully blocked problem HOT 5
- Err multiplying block array with `Diagonal`
- Broadcasting `BlockedUnitRange` sometimes loses blocking information HOT 2
- Generalize `BlockedUnitRange` to element types besides `Int` HOT 6
- Potential issue with `findblock[index]` for `BlockUnitRange` with `first != 1` HOT 4
- There and back again: a block indexing tale HOT 2
- Functionality for slicing with unit ranges that preserves block information HOT 8
- Slicing a `BlockIndexRange` with unit ranges doesn't return a `BlockedIndexRange`
- Indexing with `Vector{<:BlockIndexRange{1}}` HOT 2
- More convenient syntax for merging blocks
- Generic interface for constructing `AbstractBlockArray`s: `blocked(a::AbstractArray, blocklengths...)`
- `getindex(::UnitRange, ::BlockedUnitRange)` isn't blocked HOT 1
- More convenient syntax for getting the size of a block HOT 5
- Definition of BlockUnitRange HOT 3
- Overload dot HOT 3
- Bug: Block indexing changed between 0.16.40 and 0.16.43 HOT 1
- Failing to compile on 1.12 nightly HOT 7
- Rename PseudoBlockArray to BlockedArray (v1.0) HOT 1
- Make `blocks(randn(2, 2))[1, 1]` return the original array
- `mortar([Block(1)[1:2], Block(2)[1:2]])[Block(1)]` has type `Vector{BlockIndex{1}}` instead of `BlockIndexRange{1}`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blockarrays.jl.