nalgebra/nalgebra-sparse/src/ops/mod.rs

59 lines
1.1 KiB
Rust
Raw Normal View History

2020-12-02 23:56:22 +08:00
//! TODO
2020-12-10 20:30:37 +08:00
mod impl_std_ops;
2020-12-02 23:56:22 +08:00
pub mod serial;
/// TODO
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Op<T> {
/// TODO
NoOp(T),
/// TODO
Transpose(T),
}
impl<T> Op<T> {
/// TODO
pub fn inner_ref(&self) -> &T {
2020-12-21 22:13:31 +08:00
self.as_ref().unwrap()
}
/// TODO
pub fn as_ref(&self) -> Op<&T> {
match self {
Op::NoOp(obj) => Op::NoOp(&obj),
Op::Transpose(obj) => Op::Transpose(&obj)
}
}
2020-12-02 23:56:22 +08:00
/// TODO
pub fn convert<U>(self) -> Op<U>
where T: Into<U>
{
2020-12-21 22:13:31 +08:00
self.map_same_op(T::into)
}
/// TODO
/// TODO: Rewrite the other functions by leveraging this one
pub fn map_same_op<U, F: FnOnce(T) -> U>(self, f: F) -> Op<U> {
match self {
Op::NoOp(obj) => Op::NoOp(f(obj)),
Op::Transpose(obj) => Op::Transpose(f(obj))
}
2020-12-02 23:56:22 +08:00
}
2020-12-21 22:13:31 +08:00
/// TODO
pub fn unwrap(self) -> T {
match self {
Op::NoOp(obj) | Op::Transpose(obj) => obj,
}
}
2020-12-10 20:30:37 +08:00
}
impl<T> From<T> for Op<T> {
fn from(obj: T) -> Self {
Self::NoOp(obj)
}
}
2020-12-10 20:30:37 +08:00