Skip to content

Commit

Permalink
Fix of calc_sign_index (#85)
Browse files Browse the repository at this point in the history
* Fix of calc_sign_index
To get in line with initial Lepton implementation

* Formatting

* Some remarks (by review)
  • Loading branch information
Melirius committed May 29, 2024
1 parent a222605 commit fe0d1be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub const fn bitn(c: u16, n: u16) -> u8 {
}

#[inline(always)]
pub fn calc_sign_index(val: i32) -> usize {
pub fn calc_sign_index(val: i16) -> usize {
if val == 0 {
0
} else {
Expand Down
14 changes: 10 additions & 4 deletions src/structs/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ impl ModelPerColor {

let mut coef = 0;
if length != 0 {
let sign = &mut self.sign_counts[calc_sign_index(best_prior)][best_prior_bit_len];
// best_prior in the initial Lepton implementation is stored as i32,
// but the sign here is taken from its truncated i16 value
let sign =
&mut self.sign_counts[calc_sign_index(best_prior as i16)][best_prior_bit_len];

let neg = !bool_reader
.get(sign, ModelComponent::Edge(ModelSubComponent::Sign))
Expand Down Expand Up @@ -464,7 +467,10 @@ impl ModelPerColor {
)?;

if coef != 0 {
let sign = &mut self.sign_counts[calc_sign_index(best_prior)][best_prior_bit_len];
// best_prior in the initial Lepton implementation is stored as i32,
// but the sign here is taken from its truncated i16 value
let sign =
&mut self.sign_counts[calc_sign_index(best_prior as i16)][best_prior_bit_len];

bool_writer.put(
coef >= 0,
Expand Down Expand Up @@ -622,8 +628,8 @@ impl Model {

let exp = &mut self.counts_dc[len_abs_mxm_clamp].exponent_counts
[len_abs_offset_to_closest_edge as usize];
let sign = &mut self.per_color[color_index].sign_counts[0]
[calc_sign_index(uncertainty2 as i32) + 1]; // +1 to separate from sign_counts[0][0]
let sign =
&mut self.per_color[color_index].sign_counts[0][calc_sign_index(uncertainty2) + 1]; // +1 to separate from sign_counts[0][0]
let bits = &mut self.counts_dc[len_abs_mxm_clamp].residual_noise_counts;

(exp, sign, bits)
Expand Down

0 comments on commit fe0d1be

Please sign in to comment.