@@ -41,17 +41,11 @@ function TensorAlgebra.matricize(
4141 key (I) = Block (Tuple (I))
4242 value (I) = matricize (reshaped_blocks_a[I], length_codomain)
4343 Is = eachstoredindex (reshaped_blocks_a)
44- bs = if isempty (Is)
45- # Catch empty case and make sure the type is constrained properly.
46- # This seems to only be necessary in Julia versions below v1.11,
47- # try removing it when we drop support for those versions.
48- keytype = Base. promote_op (key, eltype (Is))
49- valtype = Base. promote_op (value, eltype (Is))
50- valtype′ = ! isconcretetype (valtype) ? AbstractMatrix{eltype (a)} : valtype
51- Dict {keytype, valtype′} ()
52- else
53- Dict (key (I) => value (I) for I in Is)
54- end
44+ # Constrain key/value types explicitly so empty cases are still typed.
45+ keytype = Base. promote_op (key, eltype (Is))
46+ valtype = Base. promote_op (value, eltype (Is))
47+ valtype′ = ! isconcretetype (valtype) ? AbstractMatrix{eltype (a)} : valtype
48+ bs = Dict {keytype, valtype′} (key (I) => value (I) for I in Is)
5549 return blocksparse (bs, ax)
5650end
5751
@@ -73,7 +67,12 @@ function TensorAlgebra.unmatricize(
7367 )
7468 return unmatricize (reshaped_blocks_m[I], block_axes_I)
7569 end
76- bs = Dict (key (I) => value (I) for I in eachstoredindex (reshaped_blocks_m))
70+ Is = eachstoredindex (reshaped_blocks_m)
71+ # Constrain key/value types explicitly so empty cases are still typed.
72+ keytype = Base. promote_op (key, eltype (Is))
73+ valtype = Base. promote_op (value, eltype (Is))
74+ valtype′ = ! isconcretetype (valtype) ? AbstractArray{eltype (m), length (ax)} : valtype
75+ bs = Dict {keytype, valtype′} (key (I) => value (I) for I in Is)
7776 return blocksparse (bs, ax)
7877end
7978
0 commit comments