← HomOps Reference
HomUnsqueeze
Insert a size-1 axis into an encrypted tensor's shape.
UqShape
RunsServer
Changes shapeYes - adds a size-1 axis
Changes scaleNo - unchanged
Levels spentNone
RotatesNo
KeysNone
What it does
HomUnsqueeze inserts a size-1 dimension at a chosen axis of the ciphertext's logical shape. It is layout-only: no arithmetic on the encrypted values, matching PyTorch's unsqueeze(dim) on encrypted tensors.Reach for it when a later op expects an extra axis for broadcasting, or when you want to pair with HomSqueeze around a reduction that keeps or drops dims.
Signature
HomUnsqueeze(dim)No
set_data.Parameters
ParameterTypeDefaultDescription
dimintrequiredAxis index where size 1 is inserted. Negative indexing is supported.Rules that depend on the value
SettingRuleIf you break it
dimMust be a valid insert position for the current rank.Compilation fails.n axisIf you insert at or before the n axis, that axis index may shift in the new shape.Not an error - but see Concepts.Requirements
- Valid insert position.
dimmust be legal for the current rank. - No keys, no levels. Layout only.
Shape effect - yes
Rule: insert
1 at dim.InputdimOutput
(128, 512)0(1, 128, 512)
(1, 128, 512)2(1, 128, 1, 512)
Scale effect - no
Scale is unchanged.
Level budget
None. Unsqueeze does not drop a prime from the modulus chain.
Keys
None.
Example
Insert a size-1 axis before a later broadcast or reduction:
pipeline.pyPYTHON
from lattica_build.operators import HomUnsqueeze from lattica_build.base_classes.hom_pipeline import HomomorphicPipeline from lattica_build.operators.composite.sequential import SequentialHomOp pipeline = HomomorphicPipeline( hom=SequentialHomOp( HomUnsqueeze(2), # (1, 128, 512) → (1, 128, 1, 512) ), input_shape=(1, 128, 512), )
See also
- HomSqueeze - remove a size-1 axis
- HomSlice - index or crop along an axis
- HomReshape - full reshape of the layout