mirror of
https://github.com/eternal-flame-AD/unitdc-rs.git
synced 2024-11-27 21:06:43 -06:00
Add SPDX header to rs files
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
parent
c951072c35
commit
69df7400c7
11 changed files with 159 additions and 8 deletions
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2024 eternal-flame-AD <yume@yumechi.jp>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
io::{BufReader, Read},
|
io::{BufReader, Read},
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2024 eternal-flame-AD <yume@yumechi.jp>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
use num_rational::BigRational;
|
use num_rational::BigRational;
|
||||||
use num_traits::{FromPrimitive, ToPrimitive};
|
use num_traits::{FromPrimitive, ToPrimitive};
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2024 eternal-flame-AD <yume@yumechi.jp>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
use crate::quantity::units::{BaseUnit, DerivedUnit};
|
use crate::quantity::units::{BaseUnit, DerivedUnit};
|
||||||
|
|
||||||
use super::{Interpreter, InterpreterError, InterpreterResult};
|
use super::{Interpreter, InterpreterError, InterpreterResult};
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2024 eternal-flame-AD <yume@yumechi.jp>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
use super::{Interpreter, InterpreterError, InterpreterResult};
|
use super::{Interpreter, InterpreterError, InterpreterResult};
|
||||||
|
|
||||||
impl<'a> Interpreter<'a> {
|
impl<'a> Interpreter<'a> {
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2024 eternal-flame-AD <yume@yumechi.jp>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
/// Interpreter for UnitDC expressions.
|
/// Interpreter for UnitDC expressions.
|
||||||
pub mod interpreter;
|
pub mod interpreter;
|
||||||
/// A module for evaluating linear systems of equations.
|
/// A module for evaluating linear systems of equations.
|
||||||
|
|
|
@ -1,5 +1,18 @@
|
||||||
use log::debug;
|
// Copyright 2024 eternal-flame-AD <yume@yumechi.jp>
|
||||||
use num_traits::Signed;
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
use num_traits::{One, Zero};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::{Add, Div, Mul, Neg, Sub},
|
ops::{Add, Div, Mul, Neg, Sub},
|
||||||
|
@ -26,7 +39,8 @@ where
|
||||||
+ Div<Output = T>
|
+ Div<Output = T>
|
||||||
+ Neg<Output = T>
|
+ Neg<Output = T>
|
||||||
+ Clone
|
+ Clone
|
||||||
+ Signed,
|
+ Zero
|
||||||
|
+ One,
|
||||||
{
|
{
|
||||||
matrix: Vec<Vec<T>>,
|
matrix: Vec<Vec<T>>,
|
||||||
}
|
}
|
||||||
|
@ -40,8 +54,8 @@ where
|
||||||
+ Neg<Output = T>
|
+ Neg<Output = T>
|
||||||
+ PartialOrd
|
+ PartialOrd
|
||||||
+ Clone
|
+ Clone
|
||||||
+ Signed
|
+ Zero
|
||||||
+ Debug,
|
+ One,
|
||||||
{
|
{
|
||||||
pub fn n(&self) -> usize {
|
pub fn n(&self) -> usize {
|
||||||
self.matrix.len()
|
self.matrix.len()
|
||||||
|
@ -126,15 +140,12 @@ where
|
||||||
self.n_pivoted() < self.m() - 1
|
self.n_pivoted() < self.m() - 1
|
||||||
}
|
}
|
||||||
pub fn solve(&mut self) -> Option<Vec<T>> {
|
pub fn solve(&mut self) -> Option<Vec<T>> {
|
||||||
debug!("starting matrix: {:?}", self.matrix);
|
|
||||||
for col in 0..if self.n() < self.m() {
|
for col in 0..if self.n() < self.m() {
|
||||||
self.n()
|
self.n()
|
||||||
} else {
|
} else {
|
||||||
self.m()
|
self.m()
|
||||||
} {
|
} {
|
||||||
debug!("col: {}", col);
|
|
||||||
self.reduce_column(col);
|
self.reduce_column(col);
|
||||||
debug!("matrix: {:?}", self.matrix);
|
|
||||||
}
|
}
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
for row in 0..self.n() {
|
for row in 0..self.n() {
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2024 eternal-flame-AD <yume@yumechi.jp>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
ops::{Add, Div, Mul, Sub},
|
ops::{Add, Div, Mul, Sub},
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2024 eternal-flame-AD <yume@yumechi.jp>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fmt::{Debug, Display},
|
fmt::{Debug, Display},
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2024 eternal-flame-AD <yume@yumechi.jp>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
io::{BufReader, Read},
|
io::{BufReader, Read},
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2024 eternal-flame-AD <yume@yumechi.jp>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
use super::TokenizerError;
|
use super::TokenizerError;
|
||||||
use num_bigint::{BigInt, BigUint};
|
use num_bigint::{BigInt, BigUint};
|
||||||
use num_rational::BigRational;
|
use num_rational::BigRational;
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2024 eternal-flame-AD <yume@yumechi.jp>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
use num_rational::BigRational;
|
use num_rational::BigRational;
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue