mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-02-08 04:29:29 +01:00
Add 'matrix' function
This commit is contained in:
parent
cf6dc88fc0
commit
bcb8b3e4c2
@ -109,6 +109,7 @@ lazy_static! {
|
|||||||
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("diag", VectorFuncInfo(diag, Other));
|
||||||
|
m.insert("matrix", VectorFuncInfo(matrix, 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.insert("perms", VectorFuncInfo(perms, Other));
|
m.insert("perms", VectorFuncInfo(perms, Other));
|
||||||
@ -760,6 +761,28 @@ pub mod funcs {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn matrix(x: KalkValue) -> Result<KalkValue, KalkError> {
|
||||||
|
let rows = as_vector_or_return!(x);
|
||||||
|
let column_width =
|
||||||
|
if let KalkValue::Vector(first_vec) = rows.first().unwrap_or(&KalkValue::nan()) {
|
||||||
|
first_vec.len()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut columns = Vec::new();
|
||||||
|
for value in rows {
|
||||||
|
let column = as_vector_or_return!(value);
|
||||||
|
if column.len() != column_width {
|
||||||
|
return Err(KalkError::InconsistentColumnWidths);
|
||||||
|
}
|
||||||
|
|
||||||
|
columns.push(column);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(KalkValue::Matrix(columns))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn max(x: KalkValue) -> Result<KalkValue, KalkError> {
|
pub fn max(x: KalkValue) -> Result<KalkValue, KalkError> {
|
||||||
let values = as_vector_or_return!(x);
|
let values = as_vector_or_return!(x);
|
||||||
let mut max = &values[0];
|
let mut max = &values[0];
|
||||||
|
Loading…
Reference in New Issue
Block a user