forked from ITensor/BlockSparseArrays.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefaults.jl
42 lines (36 loc) · 1.3 KB
/
defaults.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using BlockArrays: Block
using Dictionaries: Dictionary
using SparseArraysBase: SparseArrayDOK
# Construct the sparse structure storing the blocks
function default_blockdata(
block_data::Dictionary{<:CartesianIndex{N},<:AbstractArray{<:Any,N}},
axes::Tuple{Vararg{AbstractUnitRange,N}},
) where {N}
return error()
end
function default_blocks(
block_indices::Vector{<:Block{N}},
block_data::Vector{<:AbstractArray{<:Any,N}},
axes::Tuple{Vararg{AbstractUnitRange,N}},
) where {N}
return default_blocks(Dictionary(block_indices, block_data), axes)
end
function default_blocks(
block_data::Dictionary{<:Block{N},<:AbstractArray{<:Any,N}},
axes::Tuple{Vararg{AbstractUnitRange,N}},
) where {N}
return default_blocks(blocks_to_cartesianindices(block_data), axes)
end
function default_arraytype(elt::Type, axes::Tuple{Vararg{AbstractUnitRange}})
return Array{elt,length(axes)}
end
function default_blocks(blocktype::Type, axes::Tuple{Vararg{AbstractUnitRange}})
block_data = Dictionary{Block{length(axes),Int},blocktype}()
return default_blocks(block_data, axes)
end
function default_blocks(
block_data::Dictionary{<:CartesianIndex{N},<:AbstractArray{<:Any,N}},
axes::Tuple{Vararg{AbstractUnitRange,N}},
) where {N}
return SparseArrayDOK(block_data, blocklength.(axes), GetUnstoredBlock(axes))
end