Skip to content

Commit

Permalink
Merge pull request #230 from gizatechxyz/develop
Browse files Browse the repository at this point in the history
Merge Develop into Main
  • Loading branch information
raphaelDkhn authored Oct 6, 2023
2 parents 0d31f88 + 5865ac3 commit 68952a5
Show file tree
Hide file tree
Showing 1,552 changed files with 3,298 additions and 3,305 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "0.7.0"
- run: scarb test --workspace
- run: scarb test --workspace && scarb fmt --workspace
18 changes: 9 additions & 9 deletions src/numbers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl FP8x23Number of NumberTrait<FP8x23, u32> {

fn sign(self: FP8x23) -> FP8x23 {
core_fp8x23::sign(self)
}
}
}

use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16};
Expand Down Expand Up @@ -541,7 +541,7 @@ impl FP64x64Number of NumberTrait<FP64x64, u128> {

fn sign(self: FP64x64) -> FP64x64 {
FP64x64Impl::sign(self)
}
}
}

use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32};
Expand Down Expand Up @@ -707,7 +707,7 @@ impl FP32x32Number of NumberTrait<FP32x32, u64> {

fn sign(self: FP32x32) -> FP32x32 {
FP32x32Impl::sign(self)
}
}
}

use orion::numbers::signed_integer::i8 as i8_core;
Expand Down Expand Up @@ -879,7 +879,7 @@ impl I8Number of NumberTrait<i8, u8> {

fn sign(self: i8) -> i8 {
i8_core::i8_sign(self)
}
}
}

use orion::numbers::signed_integer::i16 as i16_core;
Expand Down Expand Up @@ -1051,7 +1051,7 @@ impl i16Number of NumberTrait<i16, u16> {

fn sign(self: i16) -> i16 {
i16_core::i16_sign(self)
}
}
}

use orion::numbers::signed_integer::i32 as i32_core;
Expand Down Expand Up @@ -1223,7 +1223,7 @@ impl i32Number of NumberTrait<i32, u32> {

fn sign(self: i32) -> i32 {
i32_core::i32_sign(self)
}
}
}

use orion::numbers::signed_integer::i64 as i64_core;
Expand Down Expand Up @@ -1395,7 +1395,7 @@ impl i64Number of NumberTrait<i64, u64> {

fn sign(self: i64) -> i64 {
i64_core::i64_sign(self)
}
}
}

use orion::numbers::signed_integer::i128 as i128_core;
Expand Down Expand Up @@ -1568,7 +1568,7 @@ impl i128Number of NumberTrait<i128, u128> {

fn sign(self: i128) -> i128 {
i128_core::i128_sign(self)
}
}
}

impl u32Number of NumberTrait<u32, u32> {
Expand Down Expand Up @@ -1746,5 +1746,5 @@ impl u32Number of NumberTrait<u32, u32> {

fn sign(self: u32) -> u32 {
panic(array!['not supported!'])
}
}
}
2 changes: 1 addition & 1 deletion src/numbers/fixed_point.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Fixed-Point implemented from https://github.com/influenceth/cubit and adjusted to Q8.23
mod core;
mod implementations;
mod utils;
mod utils;
1 change: 0 additions & 1 deletion src/numbers/fixed_point/core.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/// Trait
///
/// new - Constructs a new fixed point instance.
Expand Down
2 changes: 1 addition & 1 deletion src/numbers/fixed_point/implementations.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod fp8x23;
mod fp16x16;
mod fp64x64;
mod fp32x32;
mod fp32x32;
2 changes: 1 addition & 1 deletion src/numbers/fixed_point/implementations/fp16x16.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod core;
mod math;
mod helpers;
mod helpers;
2 changes: 1 addition & 1 deletion src/numbers/fixed_point/implementations/fp16x16/core.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl FP16x16Impl of FixedTrait<FP16x16, u32> {

fn sign(self: FP16x16) -> FP16x16 {
return core::sign(self);
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ fn assert_precise(result: FP16x16, expected: felt252, msg: felt252, custom_preci
}
}

fn assert_relative(result: FP16x16, expected: felt252, msg: felt252, custom_precision: Option<u32>) {
fn assert_relative(
result: FP16x16, expected: felt252, msg: felt252, custom_precision: Option<u32>
) {
let precision = match custom_precision {
Option::Some(val) => val,
Option::None(_) => DEFAULT_PRECISION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,9 @@ fn sub(a: FP16x16, b: FP16x16) -> FP16x16 {
}

fn sign(a: FP16x16) -> FP16x16 {

if a.mag == 0 {
FixedTrait::new(0, false)
}
else {
} else {
FixedTrait::new(ONE, a.sign)
}
}
Expand Down Expand Up @@ -636,7 +634,6 @@ fn test_tan() {
#[test]
#[available_gas(2000000)]
fn test_sign() {

let a = FixedTrait::<FP16x16>::new(0, false);
assert(a.sign().mag == 0 && !a.sign().sign, 'invalid sign (0, true)');

Expand All @@ -646,13 +643,11 @@ fn test_sign() {
let a = FixedTrait::<FP16x16>::new(HALF, false);
assert(a.sign().mag == ONE && !a.sign().sign, 'invalid sign (HALF, false)');


let a = FixedTrait::<FP16x16>::new(ONE, true);
assert(a.sign().mag == ONE && a.sign().sign, 'invalid sign (ONE, true)');

let a = FixedTrait::<FP16x16>::new(ONE, false);
assert(a.sign().mag == ONE && !a.sign().sign, 'invalid sign (ONE, false)');

}

#[test]
Expand All @@ -661,4 +656,4 @@ fn test_sign() {
fn test_sign_fail() {
let a = FixedTrait::<FP16x16>::new(HALF, true);
assert(a.sign().mag != ONE && !a.sign().sign, 'invalid sign (HALF, true)');
}
}
2 changes: 1 addition & 1 deletion src/numbers/fixed_point/implementations/fp32x32.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod core;
mod comp;
mod comp;
2 changes: 1 addition & 1 deletion src/numbers/fixed_point/implementations/fp32x32/core.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl FP32x32Impl of FixedTrait<FP32x32, u64> {

fn sign(self: FP32x32) -> FP32x32 {
panic(array!['not supported!'])
}
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/numbers/fixed_point/implementations/fp64x64.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod core;
mod comp;
mod comp;
2 changes: 1 addition & 1 deletion src/numbers/fixed_point/implementations/fp64x64/core.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl FP64x64Impl of FixedTrait<FP64x64, u128> {

fn sign(self: FP64x64) -> FP64x64 {
panic(array!['not supported!'])
}
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/numbers/fixed_point/implementations/fp8x23/core.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl FP8x23Impl of FixedTrait<FP8x23, u32> {

fn sign(self: FP8x23) -> FP8x23 {
return core::sign(self);
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,9 @@ fn sub(a: FP8x23, b: FP8x23) -> FP8x23 {
}

fn sign(a: FP8x23) -> FP8x23 {

if a.mag == 0 {
FixedTrait::new(0, false)
}
else {
} else {
FixedTrait::new(ONE, a.sign)
}
}
Expand Down Expand Up @@ -646,7 +644,6 @@ fn test_sign() {
let a = FixedTrait::<FP8x23>::new(HALF, false);
assert(a.sign().mag == ONE && !a.sign().sign, 'invalid sign (HALF, false)');


let a = FixedTrait::<FP8x23>::new(ONE, true);
assert(a.sign().mag == ONE && a.sign().sign, 'invalid sign (ONE, true)');

Expand All @@ -660,4 +657,4 @@ fn test_sign() {
fn test_sign_fail() {
let a = FixedTrait::<FP8x23>::new(HALF, true);
assert(a.sign().mag != ONE && !a.sign().sign, 'invalid sign (HALF, true)');
}
}
7 changes: 3 additions & 4 deletions src/numbers/signed_integer/i128.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl i128Impl of IntegerTrait<i128, u128> {

fn sign(self: i128) -> i128 {
i128_sign(self)
}
}
}

// Implements the Into trait for i128.
Expand Down Expand Up @@ -465,8 +465,7 @@ fn ensure_non_negative_zero(mag: u128, sign: bool) -> i128 {
fn i128_sign(a: i128) -> i128 {
if a.mag == 0 {
IntegerTrait::<i128>::new(0, false)
}
else {
} else {
IntegerTrait::<i128>::new(1, a.sign)
}
}
}
7 changes: 3 additions & 4 deletions src/numbers/signed_integer/i16.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl i16Impl of IntegerTrait<i16, u16> {

fn sign(self: i16) -> i16 {
i16_sign(self)
}
}
}

// Implements the Into trait for i16.
Expand Down Expand Up @@ -465,8 +465,7 @@ fn ensure_non_negative_zero(mag: u16, sign: bool) -> i16 {
fn i16_sign(a: i16) -> i16 {
if a.mag == 0 {
IntegerTrait::<i16>::new(0, false)
}
else {
} else {
IntegerTrait::<i16>::new(1, a.sign)
}
}
}
7 changes: 3 additions & 4 deletions src/numbers/signed_integer/i32.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl i32Impl of IntegerTrait<i32, u32> {

fn sign(self: i32) -> i32 {
i32_sign(self)
}
}
}

// Implements the Into trait for i32.
Expand Down Expand Up @@ -497,8 +497,7 @@ fn ensure_non_negative_zero(mag: u32, sign: bool) -> i32 {
fn i32_sign(a: i32) -> i32 {
if a.mag == 0 {
IntegerTrait::<i32>::new(0, false)
}
else {
} else {
IntegerTrait::<i32>::new(1, a.sign)
}
}
}
7 changes: 3 additions & 4 deletions src/numbers/signed_integer/i64.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl i64Impl of IntegerTrait<i64, u64> {

fn sign(self: i64) -> i64 {
i64_sign(self)
}
}
}

// Implements the Into trait for i64.
Expand Down Expand Up @@ -465,8 +465,7 @@ fn ensure_non_negative_zero(mag: u64, sign: bool) -> i64 {
fn i64_sign(a: i64) -> i64 {
if a.mag == 0 {
IntegerTrait::<i64>::new(0, false)
}
else {
} else {
IntegerTrait::<i64>::new(1, a.sign)
}
}
}
5 changes: 2 additions & 3 deletions src/numbers/signed_integer/i8.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl i8Impl of IntegerTrait<i8, u8> {

fn sign(self: i8) -> i8 {
i8_sign(self)
}
}
}

// Implements the Into trait for i8.
Expand Down Expand Up @@ -542,8 +542,7 @@ fn ensure_non_negative_zero(mag: u8, sign: bool) -> i8 {
fn i8_sign(a: i8) -> i8 {
if a.mag == 0 {
IntegerTrait::<i8>::new(0, false)
}
else {
} else {
IntegerTrait::<i8>::new(1, a.sign)
}
}
2 changes: 1 addition & 1 deletion src/numbers/signed_integer/integer_trait.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,6 @@ trait IntegerTrait<T, MAG> {
/// >>> {mag: 1, sign: true}
/// ```
///
fn sign(self: T) -> T;
fn sign(self: T) -> T;
}

2 changes: 1 addition & 1 deletion src/operators.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod tensor;
mod nn;
mod ml;
mod ml;
2 changes: 1 addition & 1 deletion src/operators/ml/tree_regressor.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod implementations;
mod core;
mod core;
12 changes: 9 additions & 3 deletions src/operators/ml/tree_regressor/core.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ trait TreeRegressorTrait<T> {
/// }
/// ```
///
fn fit(data: Span<Span<T>>, target: Span<T>, max_depth: usize, random_state: usize) -> TreeNode<T>;
fn fit(
data: Span<Span<T>>, target: Span<T>, max_depth: usize, random_state: usize
) -> TreeNode<T>;
/// # TreeRegressorTrait::predict
///
/// ```rust
Expand Down Expand Up @@ -413,10 +415,14 @@ fn fit<

TreeNode {
left: Option::Some(
BoxTrait::new(fit(left_data.span(), left_target.span(), depth + 1, max_depth, random_state))
BoxTrait::new(
fit(left_data.span(), left_target.span(), depth + 1, max_depth, random_state)
)
),
right: Option::Some(
BoxTrait::new(fit(right_data.span(), right_target.span(), depth + 1, max_depth, random_state))
BoxTrait::new(
fit(right_data.span(), right_target.span(), depth + 1, max_depth, random_state)
)
),
split_feature,
split_value,
Expand Down
2 changes: 1 addition & 1 deletion src/operators/ml/tree_regressor/implementations.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod tree_regressor_fp16x16;
mod tree_regressor_fp8x23;
mod tree_regressor_fp32x32;
mod tree_regressor_fp64x64;
mod tree_regressor_fp64x64;
Loading

0 comments on commit 68952a5

Please sign in to comment.