Skip to main content

HomOps Reference

HomSlice

Take an index or range along one axis of an encrypted tensor.

SlShape
RunsServer
Changes shapeYes - sliced axis
Changes scaleNo - unchanged
Levels spentNone
RotatesNo
KeysNone

What it does

HomSlice extracts a single index or a range along one axis of a ciphertext - the encrypted counterpart of tensor[dim] or tensor[start:stop:step] on a chosen axis.
Use an integer key to select one position and drop that axis (for example, pick channel 1 from (C, H, W)). Use a slice to crop a range and keep the axis with its new length. HomValue indexing on a single active axis also maps onto HomSlice.
You cannot slice the n axis. That axis is reserved for how values sit inside the ciphertext; pick any other axis instead.

Signature

HomSlice(
    dim,                 # axis
    key,                 # int (drop dim) or slice (keep dim)
)
No set_data - HomSlice carries no weights, only the axis and key.

Parameters

ParameterTypeDefaultDescription
dimintrequiredAxis to slice (Python indexing).
keyint | slicerequiredInteger index (drops the axis) or slice (keeps the axis with the sliced length).
Rules that depend on the value
SettingRuleIf you break it
keyMust be an int or a slice.Raises TypeError.
key (int)The index must lie inside the axis length.Raises IndexError.
key (slice)step must not be 0, and the resulting length must not be empty.Rejected at compile / construction time.
dimMust name an existing axis that is not the n axis.Compilation fails: the n axis cannot be sliced.

Requirements

  • Valid axis. The axis must exist on the tensor shape and must not be the n axis.
  • No keys, no levels. Layout only - no mod-switch and nothing added to the evaluation key.

Shape effect - yes

Integer key: remove axis dim.
Slice key: keep axis dim, replace its size with the sliced length.
InputCallOutput
(C, H, W)HomSlice(0, 1)(H, W) - channel 1
(C, H, W)HomSlice(2, slice(10, 40, 2))(C, H, 15)
(B, N, D)HomSlice(1, slice(0, 8))(B, 8, D)
Shape and the n axis are covered on Concepts.

Scale effect - no

A slice is a layout view only. Scale is unchanged.

Level budget

None. Slicing does not drop a prime from the modulus chain.

Keys

None. No relinearization and no rotations.

Example

Crop every other entry along the last axis:
pipeline.pyPYTHON
from lattica_build.operators import HomSlice
from lattica_build.base_classes.hom_pipeline import HomomorphicPipeline
from lattica_build.operators.composite.sequential import SequentialHomOp

pipeline = HomomorphicPipeline(
    hom=SequentialHomOp(
        HomSlice(dim=2, key=slice(10, 40, 2)),
    ),
    input_shape=(3, 32, 64),
)

See also