@@ -90,7 +90,8 @@ function embed(basis_l::CompositeBasis, basis_r::CompositeBasis,
9090 (opsb. basis_r == basis_r. bases[idxsb]) || throw (IncompatibleBases ())
9191 end
9292
93- embed_op = tensor ([i ∈ indices_sb ? ops_sb[indexin (i, indices_sb)[1 ]] : identityoperator (T, basis_l. bases[i], basis_r. bases[i]) for i= 1 : N]. .. )
93+ S = length (operators) > 1 ? mapreduce (eltype, promote_type, operators) : Any
94+ embed_op = tensor ([i ∈ indices_sb ? ops_sb[indexin (i, indices_sb)[1 ]] : identityoperator (T, S, basis_l. bases[i], basis_r. bases[i]) for i= 1 : N]. .. )
9495
9596 # Embed all joint-subspace operators.
9697 idxop_comp = [x for x in zip (indices, operators) if x[1 ] isa Array]
@@ -116,7 +117,7 @@ function embed(basis_l::CompositeBasis, basis_r::CompositeBasis,
116117 reduce (tensor, basis_r. bases[indices]) == op. basis_r || throw (IncompatibleBases ())
117118
118119 index_order = [idx for idx in 1 : length (basis_l. bases) if idx ∉ indices]
119- all_operators = AbstractOperator[identityoperator (T, basis_l. bases[i], basis_r. bases[i]) for i in index_order]
120+ all_operators = AbstractOperator[identityoperator (T, eltype (op), basis_l. bases[i], basis_r. bases[i]) for i in index_order]
120121
121122 for idx in indices
122123 pushfirst! (index_order, idx)
@@ -209,21 +210,22 @@ function embed(basis_l::CompositeBasis, basis_r::CompositeBasis,
209210 end
210211 indices, operator_list = zip (operators... )
211212 operator_list = [operator_list... ;]
213+ S = mapreduce (eltype, promote_type, operator_list)
212214 indices_flat = [indices... ;]:: Vector{Int} # type assertion to help type inference
213215 start_indices_flat = [i[1 ] for i in indices]
214216 complement_indices_flat = Int[i for i= 1 : N if i ∉ indices_flat]
215217 operators_flat = AbstractOperator[]
216218 if all ([minimum (I): maximum (I);]== I for I in indices)
217219 for i in 1 : N
218220 if i in complement_indices_flat
219- push! (operators_flat, identityoperator (T, basis_l. bases[i], basis_r. bases[i]))
221+ push! (operators_flat, identityoperator (T, S, basis_l. bases[i], basis_r. bases[i]))
220222 elseif i in start_indices_flat
221223 push! (operators_flat, operator_list[indexin (i, start_indices_flat)[1 ]])
222224 end
223225 end
224226 return tensor (operators_flat... )
225227 else
226- complement_operators = [identityoperator (T, basis_l. bases[i], basis_r. bases[i]) for i in complement_indices_flat]
228+ complement_operators = [identityoperator (T, S, basis_l. bases[i], basis_r. bases[i]) for i in complement_indices_flat]
227229 op = tensor ([operator_list; complement_operators]. .. )
228230 perm = sortperm ([indices_flat; complement_indices_flat])
229231 return permutesystems (op, perm)
0 commit comments