← HomOps Reference
HomSqueeze
Remove a size-1 axis from an encrypted tensor's shape.
SzShape
RunsServer
Changes shapeYes - removes a size-1 axis
Changes scaleNo - unchanged
Levels spentNone
RotatesNo
KeysNone
What it does
HomSqueeze removes a size-1 dimension at a chosen axis. It is layout-only: no arithmetic on the encrypted values, matching PyTorch's squeeze(dim) on encrypted tensors. Compilation fails if the target axis is not size 1.Use it to undo an HomUnsqueeze, or to drop a kept dim after a reduction that left a trailing size-1 axis.
Signature
HomSqueeze(dim)No
set_data.Parameters
ParameterTypeDefaultDescription
dimintrequiredAxis to remove; it must currently have size 1.Rules that depend on the value
SettingRuleIf you break it
dimshape[dim] must be 1.Raises ValueError.n axisIf the removed axis sits before the n axis, that axis index may decrement in the new shape.Not an error - but see Concepts.Requirements
- Size-1 axis. The named axis must have length 1.
- No keys, no levels. Layout only.
Shape effect - yes
Rule: remove axis
dim after confirming it has size 1.InputdimOutput
(1, 128, 512)0(128, 512)
(16, 1, 128)1(16, 128)
Scale effect - no
Scale is unchanged.
Level budget
None. Squeeze does not drop a prime from the modulus chain.
Keys
None.
Example
Drop a leading size-1 axis after an unsqueeze or a keep-dim reduction:
pipeline.pyPYTHON
from lattica_build.operators import HomSqueeze from lattica_build.base_classes.hom_pipeline import HomomorphicPipeline from lattica_build.operators.composite.sequential import SequentialHomOp pipeline = HomomorphicPipeline( hom=SequentialHomOp( HomSqueeze(0), # (1, 128, 512) → (128, 512) ), input_shape=(1, 128, 512), )
See also
- HomUnsqueeze - insert a size-1 axis
- HomReshape - full reshape of the layout
- HomAxisSum - axis sum that can leave a keep-dim size-1 axis