Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support syntax to construct zero, one, and fill BlockArrays #34

Closed
dlfivefifty opened this issue Oct 22, 2017 · 5 comments
Closed

Support syntax to construct zero, one, and fill BlockArrays #34

dlfivefifty opened this issue Oct 22, 2017 · 5 comments

Comments

@dlfivefifty
Copy link
Member

It would be nice to be able to construct Block arrays that are zeros.

A convention that could be copied is from GPUArrays.jl and override zeros, ones, and fill:

julia> zeros(CLArray{Float32}, 4, 4)
GPU: 4×4 Array{Float32,2}:
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

That is, support zeros(BlockArray{Float32}, 1:4, 1:4) to construct a 24 x 24 BlockMatrix.

I'm not that big a fan of this syntax as it is semantically the same as asking for a Matrix{CLArray{Float32}} (any comments @SimonDanisch ?).

An alternative would be to use zero instead of zeros, though then it would be inconsistent with GPUArrays.jl.

@dlfivefifty
Copy link
Member Author

After discussions with SimonDansch, we decided it is better use a special type to do this, and so created FillArrays.jl I'm getting this working now:

BlockArray(Zeros(6,6), 1:3, 1:3)

@KristofferC
Copy link
Collaborator

I think using Zeros, Ones etc has the same problem that is currently causes constructors in Base to change? What if I want oneunit instead of one. Is there a need for a new type in that case as well? Using types. to chose what value something should be filled with seems to be lifting up the value domain to the type domain.

@dlfivefifty
Copy link
Member Author

Then use Fill: BlockArray(Fill(oneunit(Dates.Day), 6,6), 1:3, 1:3)

@dlfivefifty
Copy link
Member Author

Only 0 and 1 have special types as Zeros and Ones, with the latter being questionable. But Zeros is distinguished because of sparse matrices.

@dlfivefifty
Copy link
Member Author

This almost works now that BlockArray(::AbstractArray, ...) works. The remaining issue will be resolved via #40.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants