mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-13 01:50:41 +01:00
Added 'diag' function
This commit is contained in:
parent
2699ce8fee
commit
2bda63b058
@ -103,6 +103,7 @@ lazy_static! {
|
|||||||
pub static ref VECTOR_FUNCS: HashMap<&'static str, VectorFuncInfo> = {
|
pub static ref VECTOR_FUNCS: HashMap<&'static str, VectorFuncInfo> = {
|
||||||
let mut m = HashMap::new();
|
let mut m = HashMap::new();
|
||||||
m.insert("average", VectorFuncInfo(average, Other));
|
m.insert("average", VectorFuncInfo(average, Other));
|
||||||
|
m.insert("diag", VectorFuncInfo(diag, Other));
|
||||||
m.insert("max", VectorFuncInfo(max, Other));
|
m.insert("max", VectorFuncInfo(max, Other));
|
||||||
m.insert("min", VectorFuncInfo(min, Other));
|
m.insert("min", VectorFuncInfo(min, Other));
|
||||||
m
|
m
|
||||||
@ -537,6 +538,19 @@ pub mod funcs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn diag(x: KalkValue) -> KalkValue {
|
||||||
|
if let KalkValue::Vector(values) = x {
|
||||||
|
let mut result = vec![vec![KalkValue::from(0f64); values.len()]; values.len()];
|
||||||
|
for (i, value) in values.iter().enumerate() {
|
||||||
|
result[i][i] = value.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
KalkValue::Matrix(result)
|
||||||
|
} else {
|
||||||
|
KalkValue::nan()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn exp(x: KalkValue) -> KalkValue {
|
pub fn exp(x: KalkValue) -> KalkValue {
|
||||||
let has_imaginary = x.has_imaginary();
|
let has_imaginary = x.has_imaginary();
|
||||||
let (real, imaginary, unit) = as_number_or_return!(x);
|
let (real, imaginary, unit) = as_number_or_return!(x);
|
||||||
|
Loading…
Reference in New Issue
Block a user