cleanup
This commit is contained in:
@@ -349,7 +349,7 @@ impl FunctionEntry {
|
||||
if derivative_required {
|
||||
debug_assert!(derivative_data_1[0].is_some());
|
||||
self.derivative_data = derivative_data_1
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|ele| unsafe { ele.unwrap_unchecked() })
|
||||
.collect::<Vec<Value>>();
|
||||
} else {
|
||||
@@ -359,7 +359,7 @@ impl FunctionEntry {
|
||||
if do_nth_derivative {
|
||||
self.nth_derivative_data = Some(
|
||||
new_nth_derivative_data
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|c| unsafe { c.unwrap_unchecked() })
|
||||
.collect(),
|
||||
);
|
||||
@@ -371,8 +371,6 @@ impl FunctionEntry {
|
||||
self.invalidate_derivative();
|
||||
}
|
||||
|
||||
let threshold: f64 = resolution / 2.0;
|
||||
|
||||
if !partial_regen {
|
||||
if self.back_data.is_empty() {
|
||||
let data: Vec<Value> = dyn_iter(&resolution_iter)
|
||||
@@ -426,6 +424,8 @@ impl FunctionEntry {
|
||||
self.invalidate_integral();
|
||||
}
|
||||
|
||||
let threshold: f64 = resolution / 2.0;
|
||||
|
||||
// Calculates extrema
|
||||
if settings.do_extrema && (min_max_changed | self.extrema_data.is_empty()) {
|
||||
self.extrema_data = self.newtons_method_helper(&threshold, 1);
|
||||
|
||||
@@ -29,7 +29,6 @@ pub use crate::{
|
||||
math_app::AppSettings,
|
||||
misc::{
|
||||
// decimal_round,
|
||||
format_bytes,
|
||||
hashed_storage_create,
|
||||
hashed_storage_read,
|
||||
option_vec_printer,
|
||||
|
||||
@@ -156,7 +156,7 @@ impl MathApp {
|
||||
}
|
||||
|
||||
if commit == build::SHORT_COMMIT {
|
||||
tracing::info!("Reading decompression cache. Bytes: {}, or: {}", cached_data.len(), crate::misc::format_bytes(cached_data.len()));
|
||||
tracing::info!("Reading decompression cache. Bytes: {}", cached_data.len());
|
||||
return Some(cached_data.to_vec());
|
||||
} else {
|
||||
tracing::info!("Decompression cache are invalid (build: {}, previous: {})", build::SHORT_COMMIT, commit);
|
||||
@@ -176,7 +176,7 @@ impl MathApp {
|
||||
|
||||
tracing::info!("Setting decompression cache");
|
||||
let saved_data = &crate::misc::hashed_storage_create(&build::SHORT_COMMIT.as_bytes(), data);
|
||||
tracing::info!("Bytes: {}, or: {}", saved_data.len(), crate::misc::format_bytes(data.len()));
|
||||
tracing::info!("Bytes: {}", saved_data.len());
|
||||
get_localstorage().set_item(DATA_NAME, saved_data).expect("failed to set local storage cache");
|
||||
}
|
||||
|
||||
@@ -187,7 +187,6 @@ impl MathApp {
|
||||
debug_assert!(!commit.is_empty());
|
||||
debug_assert!(!func_data.is_empty());
|
||||
|
||||
|
||||
unsafe {
|
||||
assume(commit.len() > 0);
|
||||
assume(func_data.len() > 0);
|
||||
|
||||
14
src/misc.rs
14
src/misc.rs
@@ -173,6 +173,9 @@ impl<'a> From<&'a [f64]> for SteppedVector<'a> {
|
||||
// Calculate the step between elements
|
||||
let step = (max - min).abs() / (data.len() as f64);
|
||||
|
||||
debug_assert!(step.is_sign_positive());
|
||||
debug_assert!(step.is_finite());
|
||||
|
||||
// Create and return the struct
|
||||
SteppedVector { data, step }
|
||||
}
|
||||
@@ -224,7 +227,7 @@ pub fn newtons_method_helper(
|
||||
|
||||
data.iter()
|
||||
.tuple_windows()
|
||||
.filter(|(prev, curr)| !prev.y.is_nan() && !curr.y.is_nan())
|
||||
.filter(|(prev, curr)| prev.y.is_finite() && curr.y.is_finite())
|
||||
.filter(|(prev, curr)| prev.y.signum() != curr.y.signum())
|
||||
.map(|(start, _)| newtons_method(f, f_1, &start.x, range, threshold))
|
||||
.filter(|x| x.is_some())
|
||||
@@ -334,6 +337,7 @@ pub fn hashed_storage_read(data: String) -> (String, Vec<u8>) {
|
||||
debug_assert!(data.len() > HASH_LENGTH);
|
||||
unsafe {
|
||||
assume(!data.is_empty());
|
||||
assume(data.len() > HASH_LENGTH);
|
||||
}
|
||||
|
||||
// can't use data.as_bytes() here for some reason, seems to break on wasm?
|
||||
@@ -346,6 +350,7 @@ pub fn hashed_storage_read(data: String) -> (String, Vec<u8>) {
|
||||
unsafe {
|
||||
assume(!cached_data.is_empty());
|
||||
assume(!hash.is_empty());
|
||||
assume(hash.len() == HASH_LENGTH);
|
||||
}
|
||||
|
||||
(
|
||||
@@ -353,10 +358,3 @@ pub fn hashed_storage_read(data: String) -> (String, Vec<u8>) {
|
||||
cached_data.to_vec(),
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn format_bytes(bytes: usize) -> String {
|
||||
byte_unit::Byte::from_bytes(bytes as u64)
|
||||
.get_appropriate_unit(false)
|
||||
.to_string()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user