MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / flip_msb

Function flip_msb

ciphercore-base/src/ops/comparisons.rs:331–336  ·  view source on GitHub ↗

- This function flips all values of the input Array's last component, which correspond to MSB bit (after `pull_out_bits`), to enable the signed comparisons. - Why bit flip is sufficient for obtaining signed comparisons given unsigned comparison functionality? Please see below example: |sign bit MSB| b1| b0| unsigned value| signed value| |------------|----|----|---------------|--------------

(ip: Node)

Source from the content-addressed store, hash-verified

329/// Here we xor the MSB bit with 1 to flip it. It is more efficient than do slice + concat.
330/// We rely on broadcasting to avoid the huge constants in graph.
331pub(super) fn flip_msb(ip: Node) -> Result<Node> {
332 ip.add(get_msb_flip_constant(
333 ip.get_type()?.get_shape(),
334 &ip.get_graph(),
335 )?)
336}
337
338fn get_msb_flip_constant(shape: ArrayShape, g: &Graph) -> Result<Node> {
339 let n = shape[shape.len() - 1] as usize;

Callers 3

preprocess_inputFunction · 0.85
integer_to_bitsFunction · 0.85
integer_from_bitsFunction · 0.85

Calls 5

get_msb_flip_constantFunction · 0.85
get_shapeMethod · 0.80
addMethod · 0.45
get_typeMethod · 0.45
get_graphMethod · 0.45

Tested by

no test coverage detected