Skip to content

Commit

Permalink
version bump, more docs, closes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
bertiqwerty committed Aug 28, 2021
1 parent e8abafb commit d534b28
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "exmex"
version = "0.9.2" # check html document root in lib.rs and the Readme.md
version = "0.9.3" # check html document root in lib.rs and the Readme.md
authors = ["Behrang Shafei <https://github.com/bertiqwerty>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Add
```
[dependencies]
# ...
exmex = "0.9.2"
exmex = "0.9.3"
```
to your `Cargo.toml` for the latest relase. If you want to use the newest version, add
```
Expand Down
19 changes: 14 additions & 5 deletions src/expression/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ impl<'a, T: Copy + Debug> FlatEx<'a, T> {
}
/// Usually, a `FlatEx` instance keeps a nested, deep structure of the expression
/// that is not necessary for evaluation. This functions removes the deep expression
/// to reduce memory consumption. [`unparse`](FlatEx::unparse) and the
/// [`Display`](std::fmt::Display) implementation will stop working after calling this function.
/// to reduce memory consumption. The methods [`partial`](FlatEx::partial) and
/// [`unparse`](FlatEx::unparse) as well as the implementation of the
/// [`Display`](std::fmt::Display) trait will stop working after calling this function.
pub fn clear_deepex(&mut self) {
self.deepex = None;
}
Expand All @@ -188,6 +189,12 @@ impl<'a, T: Copy + Debug> Display for FlatEx<'a, T> {
}
}

/// This is another representation of a flattened expression besides [`FlatEx`](FlatEx).
/// The interface is identical. The difference is that [`OwnedFlatEx`](OwnedFlatEx) can be used without
/// a lifetime parameter. All the data that [`FlatEx`](FlatEx) borrowed is kept in a
/// buffer by [`OwnedFlatEx`](OwnedFlatEx). The drawback is that parsing takes longer, since
/// additional allocations are necessary. Evaluation time should be about the same for
/// [`FlatEx`](FlatEx) and [`OwnedFlatEx`](OwnedFlatEx).
pub struct OwnedFlatEx<T: Copy + Debug> {
deepex_buf: Option<DeepBuf<T>>,
nodes: FlatNodeVec<T>,
Expand All @@ -196,6 +203,7 @@ pub struct OwnedFlatEx<T: Copy + Debug> {
n_unique_vars: usize,
}
impl<T: Copy + Debug> OwnedFlatEx<T> {
/// see [`FlatEx::eval`](FlatEx::eval)
pub fn eval(&self, vars: &[T]) -> Result<T, ExParseError> {
flat_details::eval_flatex(
vars,
Expand All @@ -205,7 +213,7 @@ impl<T: Copy + Debug> OwnedFlatEx<T> {
self.n_unique_vars,
)
}

/// Creates an `OwnedFlatEx` instance from an instance of `FlatEx`.
pub fn from_flatex<'a>(flatex: FlatEx<'a, T>) -> Self {
Self {
deepex_buf: flatex.deepex.map(|d| DeepBuf::from_deepex(&d)),
Expand All @@ -215,7 +223,7 @@ impl<T: Copy + Debug> OwnedFlatEx<T> {
n_unique_vars: flatex.n_unique_vars,
}
}

/// See [`FlatEx::partial`](FlatEx::partial).
pub fn partial(self, var_idx: usize) -> Result<Self, ExParseError>
where
T: Float,
Expand All @@ -232,7 +240,7 @@ impl<T: Copy + Debug> OwnedFlatEx<T> {
let d_i = partial_derivatives::partial_deepex(var_idx, deepex, &ops)?;
Ok(Self::from_flatex(flatten(d_i)))
}

/// See [`FlatEx::unparse`](FlatEx::unparse).
pub fn unparse(&self) -> Result<String, ExParseError> {
match &self.deepex_buf {
Some(deepex) => Ok(deepex.unparsed.clone()),
Expand All @@ -241,6 +249,7 @@ impl<T: Copy + Debug> OwnedFlatEx<T> {
}),
}
}
/// Clears buffer with owned data, see also [`FlatEx::unparse`](FlatEx::unparse).
pub fn clear_deepex(&mut self) {
self.deepex_buf = None;
}
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc(html_root_url = "https://docs.rs/exmex/0.9.2")]
#![doc(html_root_url = "https://docs.rs/exmex/0.9.3")]
//! Exmex is a fast, simple, and **ex**tendable **m**athematical **ex**pression evaluator
//! with the ability to compute [partial derivatives](FlatEx::partial) of expressions.
//! ```rust
Expand Down Expand Up @@ -230,7 +230,10 @@
//!
//! To use [`serde`](https://serde.rs/) you can activate the feature `serde_support`.
//! Currently, this only works for default operators. The implementation
//! un-parses and re-parses the whole expression.
//! un-parses and re-parses the whole expression.
//! [`Deserialize`](https://docs.serde.rs/serde/de/trait.Deserialize.html) and
//! [`Serialize`](https://docs.serde.rs/serde/de/trait.Serialize.html) are implemented for
//! for both, [`FlatEx`](FlatEx) and [`OwnedFlatEx`](OwnedFlatEx).
//!
//! ## Unicode
//! Unicode input strings are currently not supported 😕 but might be added in the
Expand Down

0 comments on commit d534b28

Please sign in to comment.