This commit is contained in:
Simon Gardling 2022-05-16 09:58:17 -04:00
parent de2a24e469
commit bc5b239e65
7 changed files with 12 additions and 46 deletions

16
Cargo.lock generated
View File

@ -192,15 +192,6 @@ version = "3.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
[[package]]
name = "byte-unit"
version = "4.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95ebf10dda65f19ff0f42ea15572a359ed60d7fc74fdc984d90310937be0014b"
dependencies = [
"utf8-width",
]
[[package]]
name = "bytemuck"
version = "1.9.1"
@ -2377,12 +2368,6 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "utf8-width"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1"
[[package]]
name = "uuid"
version = "0.8.2"
@ -2792,7 +2777,6 @@ dependencies = [
"async-lock",
"benchmarks",
"bincode",
"byte-unit",
"cfg-if 1.0.0",
"const_format",
"eframe",

View File

@ -56,7 +56,6 @@ static_assertions = "1.1"
uuid = { version = "1", features = ["v4", "fast-rng", "js"] }
bincode = "1.3"
serde = "1"
byte-unit = { version = "4", default-features = false }
unzip-n = "0.1"
[dev-dependencies]

View File

@ -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);

View File

@ -29,7 +29,6 @@ pub use crate::{
math_app::AppSettings,
misc::{
// decimal_round,
format_bytes,
hashed_storage_create,
hashed_storage_read,
option_vec_printer,

View File

@ -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);

View File

@ -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()
}

View File

@ -119,16 +119,3 @@ fn hashed_storage() {
assert_eq!(read.0.chars().map(|c| c as u8).collect::<Vec<u8>>(), commit);
assert_eq!(read.1, data);
}
#[test]
fn format_bytes() {
use std::collections::HashMap;
use ytbn_graphing_software::format_bytes;
let values: HashMap<usize, &str> =
HashMap::from([(1000, "1000 B"), (10000, "10.00 KB"), (1100000, "1.10 MB")]);
for (key, value) in values {
assert_eq!(format_bytes(key), value);
}
}