Absolute value in HL API

Hi.

I was wondering if you have any easy way of implementing absolute value function?
It is not supported as far as I can see in the HL API.

Cheers

Hello, in tfhe-rs there are only unsigned integers which are supported.

And so the value of an unsigned integer is always absolute, so there is no need for such a function

What if i want to for example implement an operation |x-y|? abs() function works in the python api, but not in the tfhe api… I am very confused :slight_smile:

On that note (i embedded this question into one post instead), is there a simple way of using tfhe on an array of integers? I tried a simple vec representation, but it was not in scope… So i turned to your latin letters example for inspiration…

Cheers

Only Unsigned Integers are avaiable at the moment in tfhe-rs.

Unlike signed integer, the value cannot be less than 0. What will happen if you do x -y where y > x is that the value will overflow. The behaviour for our integers is the same as rust: wrap_around

You can think of if as “once i reached -1, I instead take the max value and start subtracting what is left to subtract”.

For example, if you have an 8 bits unsigned integer type, the range of value is [0..255].
Examples: 0u8 - 1u8 = 255, 0u8 - 2u8 = 254, etc

Many if not all typed languages that have distinct unsigned and signed types (rust , c, c++, java, etc) have this behaviour (subtracting 2 unsigned number still yields an unsigned number, so a positive number)

You can see it for yourself in rust with this example: Rust Playground

Unsigned integers of tfhe-rs have the same behaviour as unsigned types in rust.

We do not have signed numbers support for now, but should come in the seconf half of the year

1 Like