1use super::*;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub(in crate::coating) struct IfaceKey<'a> {
8 pub(in crate::coating) coat: &'a str,
9 pub(in crate::coating) after: After<'a>,
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub(in crate::coating) enum After<'a> {
15 Medium(&'a str),
17 Mirror,
19 Reflect(&'a str),
21}
22
23impl<'a> IfaceKey<'a> {
24 pub(in crate::coating) fn parse(key: &'a str) -> IfaceKey<'a> {
25 let mut it = key.splitn(4, '|');
26 let coat = it.next().unwrap_or("");
27 let _before = it.next();
28 let m2 = it.next().unwrap_or("");
29 let after = if it.next() == Some("R") {
30 After::Reflect(m2)
31 } else if m2 == "MIRROR" {
32 After::Mirror
33 } else {
34 After::Medium(m2)
35 };
36 IfaceKey { coat, after }
37 }
38
39 pub(in crate::coating) fn is_reflect(&self) -> bool {
40 matches!(self.after, After::Reflect(_))
41 }
42
43 pub(in crate::coating) fn after_is_air(&self) -> bool {
45 matches!(self.after, After::Medium("AIR") | After::Reflect("AIR"))
46 }
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
51pub enum CoatKind {
52 Bare,
54 Ideal,
56 Stack,
58 Table,
60 Measured,
62 Model,
64 User,
66 Missing,
68}
69
70impl CoatKind {
71 pub fn name(self) -> &'static str {
72 match self {
73 CoatKind::Bare => "bare",
74 CoatKind::Ideal => "ideal",
75 CoatKind::Stack => "stack",
76 CoatKind::Table => "table",
77 CoatKind::Measured => "measured",
78 CoatKind::Model => "model",
79 CoatKind::User => "user",
80 CoatKind::Missing => "missing",
81 }
82 }
83
84 pub fn needs_table(self) -> bool {
86 matches!(self, CoatKind::Missing)
87 }
88}
89
90#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
92pub enum PhaseConvention {
93 #[default]
96 OpticStudio,
97 Physical,
101}
102
103#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
105pub enum TableNormal {
106 #[default]
109 OpticStudio,
110 Continuous,
112}
113
114#[derive(Debug, Clone, Default)]
116pub struct Coatings {
117 pub file: CoatingFile,
118 pub measured: HashMap<String, Measured>,
120 pub models: HashMap<String, CoatModel>,
122 pub user: HashMap<String, std::sync::Arc<dyn crate::usercoating::CoatingModel>>,
124 pub phase: PhaseConvention,
126 pub table_normal: TableNormal,
128 pub auto: Vec<(String, PathBuf)>,
131 pub auto_measured: Vec<String>,
133 pub registered: Vec<(String, String)>,
135 pub auto_stacks: Vec<String>,
138 pub notes: Vec<String>,
140}
141
142#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
146pub struct CoatChoice {
147 pub coat: String,
149 pub origin: String,
151}
152
153pub fn coat_choices(sys: &System) -> Vec<CoatChoice> {
155 let mut out: Vec<CoatChoice> = Vec::new();
156 let mut push = |coat: &str, origin: &str| {
157 if coat.is_empty() || out.iter().any(|c| c.coat.eq_ignore_ascii_case(coat)) {
158 return;
159 }
160 out.push(CoatChoice {
161 coat: coat.to_string(),
162 origin: origin.to_string(),
163 });
164 };
165 let mut keys: Vec<&String> = sys.coat_tables.keys().collect();
166 keys.sort();
167 for k in keys {
168 push(k, "system");
169 }
170 let ext = crate::ext::current();
171 for n in ext.coating_names() {
172 if let Some(c) = ext.find_coating(&n) {
173 push(&n, &c.name);
174 }
175 }
176 let Some(path) = sys.coating_file.as_ref() else {
177 return out;
178 };
179 let file_name = |p: &Path| {
180 p.file_name()
181 .map(|f| f.to_string_lossy().into_owned())
182 .unwrap_or_default()
183 };
184 if let Ok(f) = CoatingFile::load(path) {
185 let mut names: Vec<&String> = f.coat.keys().chain(f.table.keys()).collect();
186 names.sort();
187 let origin = file_name(path);
188 for n in names {
189 push(n, &origin);
190 }
191 }
192 let Some(dir) = path.parent().filter(|d| crate::vfs::is_dir(d)) else {
193 return out;
194 };
195 let mut exts: Vec<String> = ["lbcb", "lbcm", "lbct", "lbcs"]
196 .iter()
197 .map(|e| e.to_string())
198 .collect();
199 for s in ext.coating_sources() {
200 for e in s.extensions() {
201 let e = e.to_ascii_lowercase();
202 if !exts.contains(&e) {
203 exts.push(e);
204 }
205 }
206 }
207 let mut files: Vec<PathBuf> = crate::vfs::read_dir(dir).unwrap_or_default();
208 files.sort();
209 for p in files {
210 let (Some(stem), Some(e)) = (p.file_stem(), p.extension()) else {
211 continue;
212 };
213 if exts.contains(&e.to_string_lossy().to_ascii_lowercase()) {
214 push(&stem.to_string_lossy(), &file_name(&p));
215 }
216 }
217 if let Some(list) = super::remote::remote_lister() {
219 let mut names = list(dir);
220 names.sort();
221 for n in names {
222 push(&n, "store");
223 }
224 }
225 out
226}
227
228impl Coatings {
229 pub fn for_system(sys: &System) -> Result<Coatings> {
231 let mut file = match &sys.coating_file {
232 Some(p) => CoatingFile::load(p)?,
233 None => CoatingFile::default(),
234 };
235 for (k, t) in &sys.coat_tables {
237 file.table.insert(k.clone(), t.clone());
238 }
239 let mut c = Coatings {
240 file,
241 measured: HashMap::new(),
242 models: HashMap::new(),
243 user: HashMap::new(),
244 phase: PhaseConvention::default(),
245 table_normal: TableNormal::default(),
246 auto: Vec::new(),
247 auto_measured: Vec::new(),
248 registered: Vec::new(),
249 auto_stacks: Vec::new(),
250 notes: Vec::new(),
251 };
252 c.apply_registered(sys);
253 if let Some(dir) = sys.coating_file.as_ref().and_then(|p| p.parent()) {
254 c.load_dir_for(sys, dir)?;
255 }
256 Ok(c)
257 }
258
259 pub fn apply_registered(&mut self, sys: &System) -> usize {
263 let ext = crate::ext::current();
264 if ext.coating_catalogs().is_empty() {
265 return 0;
266 }
267 let mut n = 0;
268 for coat in used_coats(sys) {
269 if self.registered.iter().any(|(c, _)| *c == coat) {
270 continue;
271 }
272 let Some(cat) = ext.find_coating(&coat) else {
273 continue;
274 };
275 if sys.coat_tables.contains_key(&coat) {
276 let note = format!(
277 "coating {coat}: the table in the system is used; the registered coating catalog {} also has {coat}",
278 cat.name
279 );
280 if !self.notes.contains(¬e) {
281 self.notes.push(note);
282 }
283 continue;
284 }
285 if self.file.table.remove(&coat).is_some() | self.file.coat.remove(&coat).is_some() {
286 let note = format!(
287 "coating {coat}: the registered coating catalog {} is used; {coat} in the coating file is not used",
288 cat.name
289 );
290 if !self.notes.contains(¬e) {
291 self.notes.push(note);
292 }
293 }
294 if self.merge_set(&coat, cat.set(), &cat.name, true) {
295 self.registered.push((coat, cat.name.clone()));
296 n += 1;
297 }
298 }
299 n
300 }
301
302 pub(in crate::coating) fn merge_set(
305 &mut self,
306 coat: &str,
307 set: &crate::usercoating::CoatingSet,
308 origin: &str,
309 auto: bool,
310 ) -> bool {
311 if !auto {
312 self.registered.retain(|(c, _)| c != coat);
314 self.auto.retain(|(c, _)| c != coat);
315 }
316 let mut hit = false;
317 let stack = set
318 .coat
319 .iter()
320 .find(|(k, _)| k.eq_ignore_ascii_case(coat))
321 .map(|(_, l)| l.clone());
322 if let Some(mut ls) = stack {
323 for l in &mut ls {
324 let Some(rows) = set.mate.get(&l.mat) else {
325 continue; };
327 match self.file.mate.get(&l.mat) {
328 None => {
329 self.file.mate.insert(l.mat.clone(), rows.clone());
330 }
331 Some(r) if r == rows => {}
332 Some(_) => {
333 let m = format!("{}@{origin}", l.mat);
334 self.file.mate.insert(m.clone(), rows.clone());
335 l.mat = m;
336 }
337 }
338 }
339 self.file.coat.insert(coat.to_string(), ls);
340 if auto {
341 self.auto_stacks.push(coat.to_string());
342 }
343 hit = true;
344 }
345 if let Some((_, t)) = set.table.iter().find(|(k, _)| k.eq_ignore_ascii_case(coat)) {
346 self.file.table.insert(coat.to_string(), t.clone());
347 if auto && !self.auto_stacks.iter().any(|c| c == coat) {
348 self.auto_stacks.push(coat.to_string());
349 }
350 hit = true;
351 }
352 if let Some((_, m)) = set
353 .models
354 .iter()
355 .find(|(k, _)| k.eq_ignore_ascii_case(coat))
356 {
357 self.models.insert(coat.to_string(), m.clone());
358 hit = true;
359 }
360 if let Some((_, m)) = set.user.iter().find(|(k, _)| k.eq_ignore_ascii_case(coat)) {
361 self.user.insert(coat.to_string(), m.clone());
362 if auto && !self.auto_stacks.iter().any(|c| c == coat) {
364 self.auto_stacks.push(coat.to_string());
365 }
366 hit = true;
367 }
368 for (key, m) in &set.measured {
369 let mut it = key.splitn(2, '|');
370 let (c0, rest) = (it.next().unwrap_or(""), it.next().unwrap_or(""));
371 if c0.eq_ignore_ascii_case(coat) {
372 let k = format!("{coat}|{rest}");
373 self.measured.insert(k.clone(), m.clone());
374 if auto {
375 self.auto_measured.push(k);
376 } else {
377 self.auto_measured.retain(|a| *a != k);
378 }
379 hit = true;
380 }
381 }
382 hit
383 }
384
385 pub fn load_dir_for(&mut self, sys: &System, dir: &Path) -> Result<usize> {
392 let (keys, _) = media_keys(sys);
393 let mut want: Vec<&str> = Vec::new();
394 for k in keys.iter().flatten() {
395 let coat = IfaceKey::parse(k).coat;
396 if coat.is_empty()
397 || coat == "-"
398 || coat.starts_with("I.")
399 || self.file.table.contains_key(coat)
400 || self.file.coat.contains_key(coat)
401 || self.registered.iter().any(|(c, _)| c == coat)
402 || want.contains(&coat)
403 {
404 continue;
405 }
406 want.push(coat);
407 }
408 if (want.is_empty() && self.registered.is_empty()) || !crate::vfs::is_dir(dir) {
409 return Ok(0);
410 }
411 let ext = crate::ext::current();
412 let mut exts: Vec<String> = ["lbcb", "lbcm", "lbct", "lbcs"]
414 .iter()
415 .map(|e| e.to_string())
416 .collect();
417 for s in ext.coating_sources() {
418 for e in s.extensions() {
419 let e = e.to_ascii_lowercase();
420 if !exts.contains(&e) {
421 exts.push(e);
422 }
423 }
424 }
425 let files =
426 crate::vfs::read_dir(dir).map_err(|e| Error::Io(format!("{}: {e}", dir.display())))?;
427 let mut found: HashMap<String, (usize, PathBuf)> = HashMap::new();
429 for p in files {
430 let (Some(stem), Some(ext)) = (p.file_stem(), p.extension()) else {
431 continue;
432 };
433 let ext = ext.to_string_lossy().to_ascii_lowercase();
434 let Some(rank) = exts.iter().position(|e| *e == ext) else {
435 continue;
436 };
437 let name = stem.to_string_lossy().to_uppercase();
438 if found.get(&name).is_none_or(|(r, _)| rank < *r) {
439 found.insert(name, (rank, p));
440 }
441 }
442 for (coat, cat) in &self.registered {
444 if let Some((_, p)) = found.get(&coat.to_uppercase()) {
445 let note = format!(
446 "coating {coat}: the registered coating catalog {cat} is used; the file {} in the coating folder is not used",
447 p.display()
448 );
449 if !self.notes.contains(¬e) {
450 self.notes.push(note);
451 }
452 }
453 }
454 let mut n = 0;
455 for coat in want {
456 let remote;
458 let p = match found.get(&coat.to_uppercase()) {
459 Some((_, p)) => p,
460 None => match super::remote::remote_loader().and_then(|f| f(dir, coat)) {
461 Some(r) => {
462 remote = r;
463 &remote
464 }
465 None => continue,
466 },
467 };
468 let reader = p
470 .extension()
471 .and_then(|e| ext.coating_source_for(&e.to_string_lossy()).cloned());
472 if let Some(r) = reader {
473 let set = r.load(p)?;
474 let origin = p
475 .file_name()
476 .map(|f| f.to_string_lossy().into_owned())
477 .unwrap_or_default();
478 if !self.merge_set(coat, &set, &origin, true) {
479 let path = p.display();
480 invalid!("{path}: no coating {coat} (the file name and the coating name inside differ)");
481 }
482 self.auto.push((coat.to_string(), p.clone()));
483 n += 1;
484 continue;
485 }
486 let lbcs = p
487 .extension()
488 .is_some_and(|e| e.eq_ignore_ascii_case("lbcs"));
489 if lbcs {
490 let f = CoatingFile::load(p)?;
492 let Some(ls) = f
493 .coat
494 .iter()
495 .find(|(n, _)| n.eq_ignore_ascii_case(coat))
496 .map(|(_, l)| l.clone())
497 else {
498 let path = p.display();
499 invalid!("{path}: no COAT for coating {coat} (the file name and the coating name inside differ)");
500 };
501 for (m, rows) in f.mate {
502 self.file.mate.entry(m).or_insert(rows);
503 }
504 self.file.coat.insert(coat.to_string(), ls);
505 self.auto_stacks.push(coat.to_string());
506 self.auto.push((coat.to_string(), p.clone()));
507 n += 1;
508 continue;
509 }
510 let mut one = Coatings::default();
511 one.load_file(p)?;
512 let mut hit = false;
514 for (name, m) in one.models {
515 if name.eq_ignore_ascii_case(coat) {
516 self.models.insert(coat.to_string(), m);
517 hit = true;
518 }
519 }
520 for (key, m) in one.measured {
521 let mut it = key.splitn(2, '|');
522 let (c0, rest) = (it.next().unwrap_or(""), it.next().unwrap_or(""));
523 if c0.eq_ignore_ascii_case(coat) {
524 let k = format!("{coat}|{rest}");
525 self.measured.insert(k.clone(), m);
526 self.auto_measured.push(k);
527 hit = true;
528 }
529 }
530 if !hit {
531 let path = p.display();
532 invalid!("{path}: no model or measured table for coating {coat} (the file name and the coating name inside differ)");
533 }
534 self.auto.push((coat.to_string(), p.clone()));
535 n += 1;
536 }
537 Ok(n)
538 }
539
540 pub fn add_measured(&mut self, key: &str, m: Measured) -> Result<()> {
541 if m.data.len() != m.wavelengths.len()
542 || m.data.iter().any(|r| r.len() != m.angles_deg.len())
543 {
544 invalid!("size of measured table {key}");
545 }
546 if m.angles_deg.windows(2).any(|w| !(w[0] < w[1])) {
547 invalid!("the angles of measured table {key} are not ascending");
548 }
549 self.measured.insert(key.to_string(), m);
550 Ok(())
551 }
552
553 pub fn kind(&self, key: &str) -> CoatKind {
555 self.resolve(&IfaceKey::parse(key), key)
556 }
557
558 pub(in crate::coating) fn resolve(&self, k: &IfaceKey, key: &str) -> CoatKind {
561 let coat = k.coat;
562 if self.file.table.contains_key(coat) {
563 CoatKind::Table
564 } else if coat == "-" {
565 CoatKind::Bare
566 } else if coat.starts_with("I.") {
567 CoatKind::Ideal
568 } else if self.file.coat.contains_key(coat) {
569 CoatKind::Stack
570 } else if self.user.contains_key(coat) {
571 CoatKind::User
572 } else if !k.is_reflect() && self.measured.contains_key(key) {
573 CoatKind::Measured
574 } else if self.models.get(coat).is_some_and(|m| {
575 if k.after == After::Mirror {
576 m.mirror.is_some()
577 } else {
578 m.has_transmit()
579 }
580 }) {
581 CoatKind::Model
582 } else {
583 CoatKind::Missing
584 }
585 }
586
587 pub fn load_models(&mut self, path: &Path) -> Result<usize> {
589 let b =
590 crate::vfs::read(path).map_err(|e| Error::Io(format!("{}: {e}", path.display())))?;
591 let v = if is_models_bin(&b) {
592 parse_models_bin(&b)
593 } else {
594 std::str::from_utf8(&b)
595 .map_err(|_| Error::Invalid("not UTF-8".into()))
596 .and_then(parse_models)
597 }
598 .map_err(|e| match e {
599 Error::Invalid(m) => Error::Invalid(format!("{}: {m}", path.display())),
600 e => e,
601 })?;
602 let n = v.len();
603 let names: Vec<String> = v.iter().map(|(c, _)| c.clone()).collect();
605 self.models.extend(v);
606 self.registered.retain(|(c, _)| !names.contains(c));
607 let auto = std::mem::take(&mut self.auto_measured);
608 for k in auto {
609 let coat = IfaceKey::parse(&k).coat;
610 if names.iter().any(|c| c == coat) {
611 self.measured.remove(&k);
612 } else {
613 self.auto_measured.push(k);
614 }
615 }
616 self.drop_auto_stacks();
617 Ok(n)
618 }
619
620 fn drop_auto_stacks(&mut self) {
623 let mut keep = Vec::new();
624 for coat in std::mem::take(&mut self.auto_stacks) {
625 let pre = format!("{coat}|");
626 let from_catalog = self.registered.iter().any(|(c, _)| *c == coat);
628 let explicit = (self.models.contains_key(&coat) && !from_catalog)
629 || self
630 .measured
631 .keys()
632 .any(|k| k.starts_with(&pre) && !self.auto_measured.contains(k));
633 if explicit {
634 self.file.coat.remove(&coat);
635 self.file.table.remove(&coat);
636 self.user.remove(&coat);
637 } else {
638 keep.push(coat);
639 }
640 }
641 self.auto_stacks = keep;
642 }
643
644 pub fn load_file(&mut self, path: &Path) -> Result<usize> {
647 let reader = path.extension().and_then(|e| {
648 crate::ext::current()
649 .coating_source_for(&e.to_string_lossy())
650 .cloned()
651 });
652 if let Some(r) = reader {
653 let set = r.load(path)?;
654 let origin = path
655 .file_name()
656 .map(|f| f.to_string_lossy().into_owned())
657 .unwrap_or_default();
658 let names = set.names();
659 for c in &names {
660 self.merge_set(c, &set, &origin, false);
661 }
662 self.drop_auto_stacks();
663 return Ok(names.len());
664 }
665 let b =
666 crate::vfs::read(path).map_err(|e| Error::Io(format!("{}: {e}", path.display())))?;
667 if is_models_bin(&b) {
668 return self.load_models(path);
669 }
670 let txt = String::from_utf8_lossy(&b);
671 let first = txt
672 .lines()
673 .map(str::trim)
674 .find(|l| !l.is_empty() && !l.starts_with('#'))
675 .unwrap_or("");
676 if first == MODEL_HEADER {
677 self.load_models(path)
678 } else {
679 self.load_measured(path)
680 }
681 }
682
683 pub fn load_measured(&mut self, path: &Path) -> Result<usize> {
685 let txt = crate::vfs::read_to_string(path)
686 .map_err(|e| Error::Io(format!("{}: {e}", path.display())))?;
687 let v = parse_measured(&txt).map_err(|e| match e {
688 Error::Invalid(m) => Error::Invalid(format!("{}: {m}", path.display())),
689 e => e,
690 })?;
691 let n = v.len();
692 for (k, m) in v {
693 self.auto_measured.retain(|a| *a != k);
694 let coat = IfaceKey::parse(&k).coat;
695 self.registered.retain(|(c, _)| c != coat);
696 self.add_measured(&k, m)?;
697 }
698 self.drop_auto_stacks();
699 Ok(n)
700 }
701
702 pub(in crate::coating) fn mat_n(&self, sys: &System, name: &str, wl: f64) -> Result<C64> {
704 if let Some(m) = self.file.mate.get(name) {
705 if m.is_empty() {
706 invalid!("coating material {name} has no data");
707 }
708 let xs: Vec<f64> = m.iter().map(|r| r[0]).collect();
709 let n: Vec<f64> = m.iter().map(|r| r[1]).collect();
713 let k: Vec<f64> = m.iter().map(|r| r[2]).collect();
714 let kk = interp(wl, &xs, &k);
718 if kk > MATE_K_POS_TOL {
719 invalid!("coating material {name} has a positive k ({kk} at {wl} µm); write absorption as k < 0");
720 }
721 return Ok(C64::new(interp(wl, &xs, &n), interp(wl, &xs, &k)));
722 }
723 match sys.glasses.get(name) {
724 Some(g) => Ok(C64::new(
725 g.index(wl, sys.temperature, sys.pressure, sys.adjust_index),
726 0.0,
727 )),
728 None => invalid!(
729 "coating material {name} is neither in the coating file nor in the glass catalogs"
730 ),
731 }
732 }
733}
734
735fn used_coats(sys: &System) -> Vec<String> {
737 let (keys, _) = media_keys(sys);
738 let mut v: Vec<String> = Vec::new();
739 for k in keys.iter().flatten() {
740 let coat = IfaceKey::parse(k).coat;
741 if coat.is_empty() || coat == "-" || coat.starts_with("I.") || v.iter().any(|c| c == coat) {
742 continue;
743 }
744 v.push(coat.to_string());
745 }
746 v
747}
748
749pub fn media_keys(sys: &System) -> (Vec<Option<String>>, Vec<String>) {
751 let sf = &sys.surfaces;
752 let mut keys = vec![None; sf.len()];
753 let mut before = vec!["AIR".to_string(); sf.len()];
754 let mut prev = "AIR".to_string();
755 let mut nprev = sys.n(0)[0];
756 for (k, d) in sf.iter().enumerate() {
757 before[k] = prev.clone();
758 if d.ignore || d.is_coord_break() {
759 continue;
760 }
761 let after = if d.is_mirror() {
762 prev.clone()
763 } else {
764 d.mat.label()
765 };
766 if k > 0
769 && (!d.coat.is_empty()
770 || d.is_mirror()
771 || after != prev
772 || (sys.n(k)[0] - nprev).abs() > 1e-12
773 || d.bire.is_some())
774 {
775 let c = if d.coat.is_empty() { "-" } else { &d.coat };
776 keys[k] = Some(match &d.reflect {
777 Some(r) if d.is_mirror() => format!("{c}|{prev}|{}|R", r.mat),
779 _ => {
780 let a = if d.is_mirror() { "MIRROR" } else { &after };
781 format!("{c}|{prev}|{a}")
782 }
783 });
784 }
785 if !d.is_mirror() {
786 prev = after;
787 }
788 nprev = sys.n(k)[0];
789 }
790 (keys, before)
791}
792
793pub(crate) fn internal_t(g: &glass::Glass, wl: f64) -> Option<f64> {
795 if g.it.is_empty() {
796 return None;
797 }
798 let sorted;
800 let it: &[[f64; 3]] = if g.it.is_sorted_by(|a, b| a[0] <= b[0]) {
801 &g.it
802 } else {
803 let mut v = g.it.clone();
804 v.sort_by(|a, b| a[0].total_cmp(&b[0]));
805 sorted = v;
806 &sorted
807 };
808 let n = it.len();
809 if !(it[0][0] <= wl && wl <= it[n - 1][0]) {
810 return None;
811 }
812 let col = |k: usize| {
814 if n == 1 || wl <= it[0][0] {
815 return it[0][k];
816 }
817 if wl >= it[n - 1][0] {
818 return it[n - 1][k];
819 }
820 let i = it.partition_point(|r| r[0] <= wl) - 1;
821 let t = (wl - it[i][0]) / (it[i + 1][0] - it[i][0]);
822 it[i][k] + t * (it[i + 1][k] - it[i][k])
823 };
824 Some(col(1).powf(1.0 / col(2)))
825}