Repository navigation
Commit 204c99f
fix: restore inferrable return type for block tensor slicing (#73)
`_slice_getindex` chose between returning a single block and a sliced block tensor with a
runtime `inds isa NTuple{M, Int}` check, and `_slice_getindex_single` reached that check with
an index tuple of element type `Union{Int, UnitRange{Int}}`, so the check could not be
resolved statically. `blocktensor[2:(end - 1)]` on a tensor with a single nontrivial
dimension therefore inferred as `Union{BlockTensorMap{...}, TensorMap{...}}` rather than
`BlockTensorMap{...}`, and a logical mask inferred as `Any`.
Make the choice by dispatch instead, and fill the trivial dimensions with `1:1` so that `Int`
stays out of the index tuple. A mask is normalized up front, since it may consume several
dimensions and `Base.to_indices` cannot infer one mixed with the fillers.
Runtime behaviour is unchanged: slicing was verified to give identical types and values to
v0.3.16 across every index form (`Int`, ranges, step ranges, `Colon`, index vectors, logical
masks; single-index and full-rank) on dense and sparse tensors of one and three dimensions.
Downstream this widened MPSKit's Jordan-form derivative operators to their abstract type,
which in turn made `excitations` with `ChepigaAnsatz`/`ChepigaAnsatz2` uninferrable.
The new tests cover the single-index path on a multi-index tensor, which had none: the
existing single-index tests use a genuinely one-dimensional tensor and so take the
`M == numind(t)` fast path.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 230cec7 commit 204c99f
3 files changed
Lines changed: 56 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
105 | 111 | | |
106 | 112 | | |
107 | 113 | | |
108 | 114 | | |
109 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
110 | 121 | | |
111 | 122 | | |
112 | 123 | | |
113 | 124 | | |
114 | 125 | | |
115 | 126 | | |
116 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
117 | 130 | | |
118 | 131 | | |
119 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
95 | 134 | | |
96 | 135 | | |
97 | 136 | | |
| |||
0 commit comments