diff --git a/src/ascii/src/integer.cairo b/src/ascii/src/integer.cairo index 47278237..49552136 100644 --- a/src/ascii/src/integer.cairo +++ b/src/ascii/src/integer.cairo @@ -72,6 +72,12 @@ impl SmallIntegerToAsciiTraitImpl< let val = *inverse_ascii_arr.pop_back().unwrap(); ascii = ascii * 256 + val; }; + loop { + match inverse_ascii_arr.pop_back() { + Option::Some(val) => { ascii = ascii * 256 + *val; }, + Option::None(_) => { break; }, + }; + }; ascii } diff --git a/src/bytes/src/utils.cairo b/src/bytes/src/utils.cairo index 93c747eb..48c9d676 100644 --- a/src/bytes/src/utils.cairo +++ b/src/bytes/src/utils.cairo @@ -8,11 +8,15 @@ use keccak::{u128_to_u64, u128_split as u128_split_to_u64, cairo_keccak}; fn keccak_u128s_be(mut input: Span, n_bytes: usize) -> u256 { let mut keccak_input = array![]; let mut size = n_bytes; - while !input.is_empty() { - let v = *input.pop_front().unwrap(); - let value_size = uint_min(size, 16); - keccak_add_uint128_be(ref keccak_input, v, value_size); - size -= value_size; + loop { + match input.pop_front() { + Option::Some(v) => { + let value_size = uint_min(size, 16); + keccak_add_uint128_be(ref keccak_input, *v, value_size); + size -= value_size; + }, + Option::None => { break; }, + }; }; let aligned = n_bytes % 8 == 0; diff --git a/src/linalg/src/kron.cairo b/src/linalg/src/kron.cairo index fc8d8f4e..7a2ad4cb 100644 --- a/src/linalg/src/kron.cairo +++ b/src/linalg/src/kron.cairo @@ -22,12 +22,18 @@ fn kron, +AddEq, +Zeroable, +Copy, +Drop,>( // [Compute] Kronecker product in a loop let mut array = array![]; - while !xs.is_empty() { - let x = *xs.pop_front().unwrap(); - let mut ys_copy = ys; - while !ys_copy.is_empty() { - let y = *ys_copy.pop_front().unwrap(); - array.append(x * y); + loop { + match xs.pop_front() { + Option::Some(x_value) => { + let mut ys_clone = ys; + loop { + match ys_clone.pop_front() { + Option::Some(y_value) => { array.append(*x_value * *y_value); }, + Option::None => { break; }, + }; + }; + }, + Option::None => { break; }, }; }; diff --git a/src/linalg/src/norm.cairo b/src/linalg/src/norm.cairo index 684cbdc1..50a0f31a 100644 --- a/src/linalg/src/norm.cairo +++ b/src/linalg/src/norm.cairo @@ -13,15 +13,19 @@ fn norm, +Zeroable, +Copy>( mut xs: Span, ord: u128, iter: usize ) -> u128 { let mut norm: u128 = 0; - while !xs.is_empty() { - let x = xs.pop_front().unwrap(); - if ord == 0 { - if (*x).is_non_zero() { - norm += 1; - } - } else { - norm += pow((*x).into(), ord); - } + loop { + match xs.pop_front() { + Option::Some(x_value) => { + if ord == 0 { + if (*x_value).is_non_zero() { + norm += 1; + } + } else { + norm += pow((*x_value).into(), ord); + } + }, + Option::None => { break; }, + }; }; if ord == 0 { diff --git a/src/math/src/lcm_of_n_numbers.cairo b/src/math/src/lcm_of_n_numbers.cairo index e9778fe8..a76177fa 100644 --- a/src/math/src/lcm_of_n_numbers.cairo +++ b/src/math/src/lcm_of_n_numbers.cairo @@ -19,10 +19,13 @@ fn lcm, +Into, +Mul, +Div, +Copy, +Drop>( return Result::Err(LCMError::EmptyInput); } let mut a = *n.pop_front().unwrap(); - while !n.is_empty() { - let b = *n.pop_front().unwrap(); - let gcd: T = gcd_two_numbers(a.into(), b.into()).into(); - a = (a * b) / gcd; - }; - Result::Ok(a) + loop { + match n.pop_front() { + Option::Some(b) => { + let gcd: T = gcd_two_numbers(a.into(), (*b).into()).into(); + a = (a * *b) / gcd; + }, + Option::None => { break Result::Ok(a); }, + }; + } } diff --git a/src/numeric/src/cumprod.cairo b/src/numeric/src/cumprod.cairo index 1007297a..5e91dc39 100644 --- a/src/numeric/src/cumprod.cairo +++ b/src/numeric/src/cumprod.cairo @@ -12,11 +12,15 @@ fn cumprod, +Copy, +Drop,>(mut sequence: Span) -> Array { // [Compute] Interpolation let mut prev_value = *sequence.pop_front().unwrap(); let mut array = array![prev_value]; - while !sequence.is_empty() { - let current_value = *sequence.pop_front().unwrap(); - let product = current_value * prev_value; - array.append(product); - prev_value = product; + loop { + match sequence.pop_front() { + Option::Some(current_value) => { + let prod = *current_value * prev_value; + array.append(prod); + prev_value = prod; + }, + Option::None => { break; }, + }; }; array } diff --git a/src/numeric/src/cumsum.cairo b/src/numeric/src/cumsum.cairo index 9575ceac..e36c4f0c 100644 --- a/src/numeric/src/cumsum.cairo +++ b/src/numeric/src/cumsum.cairo @@ -1,5 +1,3 @@ -use core::array::SpanTrait; -use core::option::OptionTrait; //! The cumulative sum of the elements. /// Compute the cumulative sum of a sequence. @@ -14,11 +12,15 @@ fn cumsum, +Copy, +Drop,>(mut sequence: Span) -> Array { // [Compute] Interpolation let mut prev_value = *sequence.pop_front().unwrap(); let mut array = array![prev_value]; - while !sequence.is_empty() { - let current_value = *sequence.pop_front().unwrap(); - let sum = current_value + prev_value; - array.append(sum); - prev_value = sum; + loop { + match sequence.pop_front() { + Option::Some(current_value) => { + let sum = *current_value + prev_value; + array.append(sum); + prev_value = sum; + }, + Option::None => { break; }, + }; }; array }