Cargo fmt

This commit is contained in:
Andreas Longva 2021-05-03 13:50:48 +02:00
parent 08a77dd05e
commit 8552fc8385
6 changed files with 44 additions and 29 deletions

View File

@ -5,14 +5,14 @@
extern crate proc_macro; extern crate proc_macro;
use syn::{Expr};
use syn::parse::{Parse, ParseStream, Result, Error};
use syn::punctuated::{Punctuated};
use syn::{parse_macro_input, Token};
use quote::{quote, TokenStreamExt, ToTokens};
use proc_macro::TokenStream; use proc_macro::TokenStream;
use quote::{quote, ToTokens, TokenStreamExt};
use syn::parse::{Error, Parse, ParseStream, Result};
use syn::punctuated::Punctuated;
use syn::Expr;
use syn::{parse_macro_input, Token};
use proc_macro2::{TokenStream as TokenStream2, Delimiter, TokenTree, Spacing}; use proc_macro2::{Delimiter, Spacing, TokenStream as TokenStream2, TokenTree};
use proc_macro2::{Group, Punct}; use proc_macro2::{Group, Punct};
struct Matrix { struct Matrix {
@ -33,10 +33,9 @@ impl Matrix {
/// Produces a stream of tokens representing this matrix as a column-major nested array. /// Produces a stream of tokens representing this matrix as a column-major nested array.
fn to_col_major_nested_array_tokens(&self) -> TokenStream2 { fn to_col_major_nested_array_tokens(&self) -> TokenStream2 {
let mut result = TokenStream2::new(); let mut result = TokenStream2::new();
for j in 0 .. self.ncols() { for j in 0..self.ncols() {
let mut col = TokenStream2::new(); let mut col = TokenStream2::new();
let col_iter = (0 .. self.nrows()) let col_iter = (0..self.nrows()).map(move |i| &self.rows[i][j]);
.map(move |i| &self.rows[i][j]);
col.append_separated(col_iter, Punct::new(',', Spacing::Alone)); col.append_separated(col_iter, Punct::new(',', Spacing::Alone));
result.append(Group::new(Delimiter::Bracket, col)); result.append(Group::new(Delimiter::Bracket, col));
result.append(Punct::new(',', Spacing::Alone)); result.append(Punct::new(',', Spacing::Alone));
@ -48,8 +47,8 @@ impl Matrix {
/// (suitable for representing e.g. a `DMatrix`). /// (suitable for representing e.g. a `DMatrix`).
fn to_col_major_flat_array_tokens(&self) -> TokenStream2 { fn to_col_major_flat_array_tokens(&self) -> TokenStream2 {
let mut data = TokenStream2::new(); let mut data = TokenStream2::new();
for j in 0 .. self.ncols() { for j in 0..self.ncols() {
for i in 0 .. self.nrows() { for i in 0..self.nrows() {
self.rows[i][j].to_tokens(&mut data); self.rows[i][j].to_tokens(&mut data);
data.append(Punct::new(',', Spacing::Alone)); data.append(Punct::new(',', Spacing::Alone));
} }
@ -76,7 +75,8 @@ impl Parse for Matrix {
"Unexpected number of entries in row {}. Expected {}, found {} entries.", "Unexpected number of entries in row {}. Expected {}, found {} entries.",
row_idx, row_idx,
ncols, ncols,
row.len()); row.len()
);
return Err(Error::new(row_span, error_msg)); return Err(Error::new(row_span, error_msg));
} }
} else { } else {
@ -93,7 +93,7 @@ impl Parse for Matrix {
Ok(Self { Ok(Self {
rows, rows,
ncols: ncols.unwrap_or(0) ncols: ncols.unwrap_or(0),
}) })
} }
} }
@ -209,13 +209,13 @@ impl Parse for Vector {
// The syntax of a vector is just the syntax of a single matrix row // The syntax of a vector is just the syntax of a single matrix row
if input.is_empty() { if input.is_empty() {
Ok(Self { Ok(Self {
elements: Vec::new() elements: Vec::new(),
}) })
} else { } else {
let elements = MatrixRowSyntax::parse_separated_nonempty(input)?.into_iter().collect(); let elements = MatrixRowSyntax::parse_separated_nonempty(input)?
Ok(Self { .into_iter()
elements .collect();
}) Ok(Self { elements })
} }
} }
} }

View File

@ -1,5 +1,9 @@
use nalgebra::{
DMatrix, DVector, Matrix1x2, Matrix1x3, Matrix1x4, Matrix2, Matrix2x1, Matrix2x3, Matrix2x4,
Matrix3, Matrix3x1, Matrix3x2, Matrix3x4, Matrix4, Matrix4x1, Matrix4x2, Matrix4x3, SMatrix,
SVector, Vector1, Vector2, Vector3, Vector4, Vector5, Vector6,
};
use nalgebra_macros::{dmatrix, dvector, matrix, vector}; use nalgebra_macros::{dmatrix, dvector, matrix, vector};
use nalgebra::{DMatrix, DVector, SMatrix, Matrix3x2, Matrix1x2, Matrix1x3, Matrix1x4, Matrix2x1, Matrix2, Matrix2x3, Matrix2x4, Matrix3x1, Matrix3, Matrix3x4, Matrix4x1, Matrix4x2, Matrix4x3, Matrix4, Vector1, Vector2, Vector3, Vector4, Vector5, SVector, Vector6};
fn check_statically_same_type<T>(_: &T, _: &T) {} fn check_statically_same_type<T>(_: &T, _: &T) {}
@ -11,6 +15,8 @@ macro_rules! assert_eq_and_type {
}; };
} }
// Skip rustfmt because it just makes the test bloated without making it more readable
#[rustfmt::skip]
#[test] #[test]
fn matrix_small_dims_exhaustive() { fn matrix_small_dims_exhaustive() {
// 0x0 // 0x0
@ -52,6 +58,8 @@ fn matrix_const_fn() {
const _: SMatrix<i32, 2, 3> = matrix![1, 2, 3; 4, 5, 6]; const _: SMatrix<i32, 2, 3> = matrix![1, 2, 3; 4, 5, 6];
} }
// Skip rustfmt because it just makes the test bloated without making it more readable
#[rustfmt::skip]
#[test] #[test]
fn dmatrix_small_dims_exhaustive() { fn dmatrix_small_dims_exhaustive() {
// 0x0 // 0x0
@ -85,6 +93,8 @@ fn dmatrix_small_dims_exhaustive() {
DMatrix::from_row_slice(4, 4, &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])); DMatrix::from_row_slice(4, 4, &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]));
} }
// Skip rustfmt because it just makes the test bloated without making it more readable
#[rustfmt::skip]
#[test] #[test]
fn vector_small_dims_exhaustive() { fn vector_small_dims_exhaustive() {
assert_eq_and_type!(vector![], SVector::<i32, 0>::zeros()); assert_eq_and_type!(vector![], SVector::<i32, 0>::zeros());
@ -105,6 +115,8 @@ fn vector_const_fn() {
const _: Vector6<i32> = vector![1, 2, 3, 4, 5, 6]; const _: Vector6<i32> = vector![1, 2, 3, 4, 5, 6];
} }
// Skip rustfmt because it just makes the test bloated without making it more readable
#[rustfmt::skip]
#[test] #[test]
fn dvector_small_dims_exhaustive() { fn dvector_small_dims_exhaustive() {
assert_eq_and_type!(dvector![], DVector::<i32>::zeros(0)); assert_eq_and_type!(dvector![], DVector::<i32>::zeros(0));

View File

@ -13,9 +13,9 @@ use crate::base::storage::{
}; };
use crate::base::{Scalar, Vector}; use crate::base::{Scalar, Vector};
use crate::{DMatrix, DVector};
#[cfg(feature = "abomonation-serialize")] #[cfg(feature = "abomonation-serialize")]
use abomonation::Abomonation; use abomonation::Abomonation;
use crate::{DMatrix, DVector};
/* /*
* *
@ -412,8 +412,7 @@ impl<T> Extend<T> for VecStorage<T, Dynamic, U1> {
} }
} }
impl<T> DMatrix<T> impl<T> DMatrix<T> {
{
/// Creates a new heap-allocated matrix from the given [VecStorage]. /// Creates a new heap-allocated matrix from the given [VecStorage].
pub const fn from_vec_storage(storage: VecStorage<T, Dynamic, Dynamic>) -> Self { pub const fn from_vec_storage(storage: VecStorage<T, Dynamic, Dynamic>) -> Self {
// This is sound because the dimensions of the matrix and the storage are guaranteed // This is sound because the dimensions of the matrix and the storage are guaranteed
@ -422,8 +421,7 @@ impl<T> DMatrix<T>
} }
} }
impl<T> DVector<T> impl<T> DVector<T> {
{
/// Creates a new heap-allocated matrix from the given [VecStorage]. /// Creates a new heap-allocated matrix from the given [VecStorage].
pub const fn from_vec_storage(storage: VecStorage<T, Dynamic, U1>) -> Self { pub const fn from_vec_storage(storage: VecStorage<T, Dynamic, U1>) -> Self {
// This is sound because the dimensions of the matrix and the storage are guaranteed // This is sound because the dimensions of the matrix and the storage are guaranteed

View File

@ -1,4 +1,9 @@
#[cfg(not(all(feature = "debug", feature = "compare", feature = "rand", feature = "macros")))] #[cfg(not(all(
feature = "debug",
feature = "compare",
feature = "rand",
feature = "macros"
)))]
compile_error!( compile_error!(
"Please enable the `debug`, `compare`, `rand` and `macros` features in order to compile and run the tests. "Please enable the `debug`, `compare`, `rand` and `macros` features in order to compile and run the tests.
Example: `cargo test --features debug,compare,rand,macros`" Example: `cargo test --features debug,compare,rand,macros`"