Skip to content

Commit c9459b8

Browse files
committed
style: run fmt
1 parent d12849d commit c9459b8

File tree

8 files changed

+247
-122
lines changed

8 files changed

+247
-122
lines changed

src/coordinate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ impl Coordinate {
2222
pub fn insert(&self, index: usize, axis: usize) -> Self {
2323
let mut new_indices = self.indices.clone();
2424
new_indices.insert(index, axis);
25-
Self { indices: new_indices }
25+
Self {
26+
indices: new_indices,
27+
}
2628
}
2729
}
2830

src/iter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ impl Iterator for IndexIterator {
4545
}
4646
}
4747

48-
4948
#[cfg(test)]
5049
mod tests {
5150
use super::*;
@@ -84,4 +83,4 @@ mod tests {
8483

8584
assert_eq!(iter.next(), None);
8685
}
87-
}
86+
}

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
pub mod shape;
2-
pub mod iter;
3-
pub mod error;
1+
pub mod axes;
42
pub mod coordinate;
3+
pub mod error;
4+
pub mod iter;
5+
pub mod matrix;
6+
pub mod shape;
57
pub mod storage;
68
pub mod tensor;
79
pub mod vector;
8-
pub mod matrix;
9-
pub mod axes;

src/matrix.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use std::ops::{Add, Sub, Mul, Div, Deref, Index, IndexMut, DerefMut};
1+
use std::ops::{Add, Deref, DerefMut, Div, Index, IndexMut, Mul, Sub};
22

3-
use num::{Num, Float};
3+
use crate::axes::Axes;
4+
use crate::coord;
5+
use crate::coordinate::Coordinate;
46
use crate::error::ShapeError;
57
use crate::shape;
6-
use crate::coord;
78
use crate::shape::Shape;
89
use crate::tensor::DynamicTensor;
910
use crate::vector::DynamicVector;
10-
use crate::axes::Axes;
11-
use crate::coordinate::Coordinate;
11+
use num::{Float, Num};
1212

1313
pub struct DynamicMatrix<T: Num> {
1414
tensor: DynamicTensor<T>,
@@ -17,9 +17,11 @@ pub type Matrix<T> = DynamicMatrix<T>;
1717

1818
impl<T: Num + PartialOrd + Copy> DynamicMatrix<T> {
1919
pub fn new(shape: &Shape, data: &[T]) -> Result<DynamicMatrix<T>, ShapeError> {
20-
Ok(DynamicMatrix { tensor: DynamicTensor::new(shape, data)? })
20+
Ok(DynamicMatrix {
21+
tensor: DynamicTensor::new(shape, data)?,
22+
})
2123
}
22-
24+
2325
pub fn from_tensor(tensor: DynamicTensor<T>) -> Result<DynamicMatrix<T>, ShapeError> {
2426
if tensor.shape().order() != 2 {
2527
return Err(ShapeError::new("Shape must have order of 2"));
@@ -38,8 +40,12 @@ impl<T: Num + PartialOrd + Copy> DynamicMatrix<T> {
3840
}
3941
Ok(result)
4042
}
41-
pub fn zeros(shape: &Shape) -> Result<DynamicMatrix<T>, ShapeError> { Self::fill(shape, T::zero()) }
42-
pub fn ones(shape: &Shape) -> Result<DynamicMatrix<T>, ShapeError> { Self::fill(shape, T::one()) }
43+
pub fn zeros(shape: &Shape) -> Result<DynamicMatrix<T>, ShapeError> {
44+
Self::fill(shape, T::zero())
45+
}
46+
pub fn ones(shape: &Shape) -> Result<DynamicMatrix<T>, ShapeError> {
47+
Self::fill(shape, T::one())
48+
}
4349

4450
pub fn sum(&self, axes: Axes) -> DynamicVector<T> {
4551
let result = self.tensor.sum(axes);
@@ -597,7 +603,7 @@ mod tests {
597603
assert_eq!(result[coord![1, 1]], 2.0);
598604
assert_eq!(result.shape(), &shape);
599605
}
600-
606+
601607
#[test]
602608
fn test_div_matrix_tensor() {
603609
let shape = shape![2, 2].unwrap();
@@ -648,4 +654,4 @@ mod tests {
648654
assert_eq!(result[coord![1, 1]], 25.0);
649655
assert_eq!(result.shape(), &shape);
650656
}
651-
}
657+
}

src/shape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ mod tests {
111111
let extended_shape = shape1.stack(&shape2);
112112
assert_eq!(extended_shape.dims, vec![2, 3, 4, 5]);
113113
}
114-
}
114+
}

src/storage.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::ops::{Index, IndexMut};
22

33
use crate::coordinate::Coordinate;
4-
use crate::shape::Shape;
54
use crate::error::ShapeError;
5+
use crate::shape::Shape;
66

77
#[derive(Debug, PartialEq)]
88
pub struct DynamicStorage<T> {
@@ -23,13 +23,15 @@ impl<T> DynamicStorage<T> {
2323

2424
for (i, &dim) in coord.iter().enumerate() {
2525
if dim >= shape[i] {
26-
return Err(ShapeError::new(format!("out of bounds for dimension {}", i).as_str()));
26+
return Err(ShapeError::new(
27+
format!("out of bounds for dimension {}", i).as_str(),
28+
));
2729
}
2830
}
2931

3032
let mut index = 0;
3133
for k in 0..shape.order() {
32-
let stride = shape[k+1..].iter().product::<usize>();
34+
let stride = shape[k + 1..].iter().product::<usize>();
3335
index += coord[k] * stride;
3436
}
3537
Ok(index)
@@ -54,7 +56,6 @@ impl<T> Index<usize> for DynamicStorage<T> {
5456
fn index(&self, index: usize) -> &Self::Output {
5557
&self.data[index]
5658
}
57-
5859
}
5960

6061
impl<T> Index<std::ops::Range<usize>> for DynamicStorage<T> {

0 commit comments

Comments
 (0)