Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Vid201 committed Jul 15, 2024
1 parent 92d1843 commit 5a816b0
Show file tree
Hide file tree
Showing 43 changed files with 1,579 additions and 1,403 deletions.
319 changes: 169 additions & 150 deletions src/operators/matrix.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -90,66 +90,70 @@ impl MutMatrixImpl<

if axis == 0 {
let mut col: usize = 0;
while col != self.cols {
let mut max_value = self.get(0, col);
let mut max_value = match max_value {
Option::Some => { max_value.unwrap() },
Option::None => { NumberTrait::min_value() }
};
let mut max_index = 0;

let mut row: usize = 1;
while row != self.rows {
let mut value = self.get(row, col);
let mut value = match value {
Option::Some => { value.unwrap() },
while col != self
.cols {
let mut max_value = self.get(0, col);
let mut max_value = match max_value {
Option::Some => { max_value.unwrap() },
Option::None => { NumberTrait::min_value() }
};

if value > max_value {
max_value = value;
max_index = row;
}

row += 1;
let mut max_index = 0;

let mut row: usize = 1;
while row != self
.rows {
let mut value = self.get(row, col);
let mut value = match value {
Option::Some => { value.unwrap() },
Option::None => { NumberTrait::min_value() }
};

if value > max_value {
max_value = value;
max_index = row;
}

row += 1;
};

result.append(max_index);
col += 1;
};

result.append(max_index);
col += 1;
};

return result.span();
}

let mut row: usize = 0;
while row != self.rows {
let mut max_value = self.get(row, 0);
let mut max_value = match max_value {
Option::Some => { max_value.unwrap() },
Option::None => { NumberTrait::min_value() }
};
let mut max_index = 0;

let mut col: usize = 1;
while col != self.cols {
let mut value = self.get(row, col);
let mut value = match value {
Option::Some => { value.unwrap() },
while row != self
.rows {
let mut max_value = self.get(row, 0);
let mut max_value = match max_value {
Option::Some => { max_value.unwrap() },
Option::None => { NumberTrait::min_value() }
};
let mut max_index = 0;

if value > max_value {
max_value = value;
max_index = col;
}
let mut col: usize = 1;
while col != self
.cols {
let mut value = self.get(row, col);
let mut value = match value {
Option::Some => { value.unwrap() },
Option::None => { NumberTrait::min_value() }
};

if value > max_value {
max_value = value;
max_index = col;
}

col += 1;
};

col += 1;
result.append(max_index);
row += 1;
};

result.append(max_index);
row += 1;
};

result.span()
}

Expand All @@ -161,50 +165,56 @@ impl MutMatrixImpl<

if axis == 0 {
let mut col: usize = 0;
while col != self.cols {
let mut sum_exp = NumberTrait::zero();
let mut row: usize = 0;
while row != self.rows {
let value = self.get(row, col).unwrap().into();
sum_exp += value.exp();

row += 1;
};

row = 0;
while row != self.rows {
let value = self.get(row, col).unwrap().into();
let softmax_value = (value.exp() / sum_exp).into();
result.set(row, col, softmax_value);
while col != self
.cols {
let mut sum_exp = NumberTrait::zero();
let mut row: usize = 0;
while row != self
.rows {
let value = self.get(row, col).unwrap().into();
sum_exp += value.exp();

row += 1;
};

row = 0;
while row != self
.rows {
let value = self.get(row, col).unwrap().into();
let softmax_value = (value.exp() / sum_exp).into();
result.set(row, col, softmax_value);

row += 1;
};

row += 1;
col += 1;
};

col += 1;
};
} else {
let mut row: usize = 0;
while row != self.rows {
let mut sum_exp = NumberTrait::zero();
let mut col: usize = 0;
while col != self.cols {
let value = self.get(row, col).unwrap().into();
sum_exp += value.exp();

col += 1;
};
while row != self
.rows {
let mut sum_exp = NumberTrait::zero();
let mut col: usize = 0;
while col != self
.cols {
let value = self.get(row, col).unwrap().into();
sum_exp += value.exp();

col += 1;
};

col = 0;
while col != self
.cols {
let value = self.get(row, col).unwrap().into();
let softmax_value = (value.exp() / sum_exp).into();
result.set(row, col, softmax_value);

col += 1;
};

col = 0;
while col != self.cols {
let value = self.get(row, col).unwrap().into();
let softmax_value = (value.exp() / sum_exp).into();
result.set(row, col, softmax_value);

col += 1;
row += 1;
};

row += 1;
};
}

result
Expand All @@ -220,65 +230,71 @@ impl MutMatrixImpl<

if axis == 0 {
let mut col: usize = 0;
while col != self.cols {
let mut sum_exp = NumberTrait::zero();
let mut row: usize = 0;
while row != self.rows {
let value = self.get(row, col).unwrap().into();

if value != NumberTrait::zero() {
sum_exp += value.exp();
}
while col != self
.cols {
let mut sum_exp = NumberTrait::zero();
let mut row: usize = 0;
while row != self
.rows {
let value = self.get(row, col).unwrap().into();

if value != NumberTrait::zero() {
sum_exp += value.exp();
}

row += 1;
};

row = 0;
while row != self
.rows {
let value = self.get(row, col).unwrap().into();

if value != NumberTrait::zero() {
let softmax_value = (value.exp() / sum_exp).into();
result.set(row, col, softmax_value);
} else {
result.set(row, col, NumberTrait::zero());
}

row += 1;
};

row += 1;
};

row = 0;
while row != self.rows {
let value = self.get(row, col).unwrap().into();

if value != NumberTrait::zero() {
let softmax_value = (value.exp() / sum_exp).into();
result.set(row, col, softmax_value);
} else {
result.set(row, col, NumberTrait::zero());
}

row += 1;
col += 1;
};

col += 1;
};
} else {
let mut row: usize = 0;
while row != self.rows {
let mut sum_exp = NumberTrait::zero();
let mut col: usize = 0;
while col != self.cols {
let value = self.get(row, col).unwrap().into();
if value != NumberTrait::zero() {
sum_exp += value.exp();
}
while row != self
.rows {
let mut sum_exp = NumberTrait::zero();
let mut col: usize = 0;
while col != self
.cols {
let value = self.get(row, col).unwrap().into();
if value != NumberTrait::zero() {
sum_exp += value.exp();
}

col += 1;
};

col = 0;
while col != self
.cols {
let value = self.get(row, col).unwrap().into();

if value != NumberTrait::zero() {
let softmax_value = (value.exp() / sum_exp).into();
result.set(row, col, softmax_value);
} else {
result.set(row, col, NumberTrait::zero());
}

col += 1;
};

col += 1;
};

col = 0;
while col != self.cols {
let value = self.get(row, col).unwrap().into();

if value != NumberTrait::zero() {
let softmax_value = (value.exp() / sum_exp).into();
result.set(row, col, softmax_value);
} else {
result.set(row, col, NumberTrait::zero());
}

col += 1;
row += 1;
};

row += 1;
};
}

result
Expand All @@ -289,23 +305,26 @@ impl MutMatrixImpl<
let mut result = MutMatrixImpl::new(self.rows, self.cols);

let mut row: usize = 0;
while row != self.rows {
let mut col: usize = 0;
while col != self.cols {
let value = self.get(row, col);
while row != self
.rows {
let mut col: usize = 0;
while col != self
.cols {
let value = self.get(row, col);

if value.is_some() {
let value = NumberTrait::one()
/ (NumberTrait::one() + (value.unwrap() * NumberTrait::neg_one()).exp());
if value.is_some() {
let value = NumberTrait::one()
/ (NumberTrait::one()
+ (value.unwrap() * NumberTrait::neg_one()).exp());

result.set(row, col, value);
}
result.set(row, col, value);
}

col += 1;
};
col += 1;
};

row += 1;
};
row += 1;
};

result
}
Expand Down
9 changes: 5 additions & 4 deletions src/operators/ml/svm/core.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ fn squared_diff<
) -> T {
let mut i = 0;
let mut sum = NumberTrait::zero();
while i != pA.len() {
sum = sum + (*pA.at(i) - *pB.at(i)).pow(NumberTrait::one() + NumberTrait::one());
i += 1;
};
while i != pA
.len() {
sum = sum + (*pA.at(i) - *pB.at(i)).pow(NumberTrait::one() + NumberTrait::one());
i += 1;
};

sum
}
Loading

0 comments on commit 5a816b0

Please sign in to comment.