1pub mod auto_init;
133pub mod cycle_slip;
134mod fixed;
135mod float;
136mod kinematic;
137mod model;
138mod normal;
139mod prep;
140pub mod raim;
141mod rows;
142pub mod tec;
143mod types;
144pub mod velocity;
145
146pub use auto_init::{
147 solve_ppp_auto_init_fixed, solve_ppp_auto_init_fixed_with_strategy, solve_ppp_auto_init_float,
148 solve_ppp_auto_init_float_with_strategy, PppAutoInitError, PppAutoInitOptions,
149 PppAutoInitStrategy, PppInitialGuess,
150};
151pub use cycle_slip::{
152 detect_cycle_slips, geometry_free_m, melbourne_wubbena_cycles, update_geometry_free,
153 update_melbourne_wubbena, CycleSlipConfig, CycleSlipConfigError, CycleSlipDetectorState,
154 CycleSlipError, CycleSlipFlagEpoch, CycleSlipFlagObservation, CycleSlipStateKey,
155 GeometryFreeUpdate, MelbourneWubbenaUpdate, RunningMeanVariance, SatelliteCycleSlipState,
156 DEFAULT_MINIMUM_ARC_LENGTH, DEFAULT_RUNNING_STATISTIC_K_FACTOR,
157};
158pub(crate) use fixed::run_fixed_from_float;
159pub use fixed::solve_fixed_from_float;
160#[cfg(test)]
161use float::initial_ambiguities;
162pub(crate) use float::run_float_epochs;
163pub use float::{solve_float_epoch, solve_float_epochs};
164pub use kinematic::{
165 correct_kinematic_state, predict_kinematic_state, solve_kinematic_ppp, KinematicConfig,
166 KinematicEpochSolution, KinematicEpochStatus, KinematicMotionModel,
167 KinematicPositionProcessNoise, KinematicProcessNoise, KinematicSolveError, KinematicState,
168 KinematicUpdateSummary,
169};
170pub use prep::{
171 prepare_widelane_fixed_epochs, split_float_cycle_slip_epochs, DualFrequencyEpoch,
172 DualFrequencyObservation, FloatCycleSlipEpoch, FloatCycleSlipObservation,
173 FloatCycleSlipTaggedEpoch, FloatCycleSlipTaggedObservation, PppSplitArc, PreparedFloatEpoch,
174 PreparedFloatObservation, WideLanePrepError, WideLanePrepOptions, WideLanePrepResult,
175};
176pub use raim::{
177 solve_float_epoch_with_raim, ProtectionLevels, RaimConfig, RaimError, RaimFdeError,
178 RaimFdeResult, RaimFdeStatus, RaimGeometryRow, RaimIdentification, RaimResult, RaimStatus,
179 SatelliteTestStatistic,
180};
181pub use tec::{
182 code_geometry_free_m, estimate_code_slant_tec, estimate_phase_slant_tec, estimate_tec,
183 ionospheric_pierce_point, level_slant_tec_arc, phase_geometry_free_m,
184 slant_tec_from_code_geometry_free_m, slant_tec_from_phase_geometry_free_m,
185 thin_shell_mapping_function, vertical_tec_from_slant_tec, CodeSlantTecEstimate,
186 IonosphericPiercePoint, LeveledTecSample, PhaseSlantTecEstimate, TecConfig, TecEpoch, TecError,
187 TecEstimate, TecEstimateSample, TecLevelingResult, TecLevelingSample, TecObservation,
188 TecSatelliteArc, DEFAULT_IONOSPHERIC_SHELL_HEIGHT_M, ELECTRONS_PER_TECU_M2,
189 TEC_GROUP_DELAY_COEFFICIENT,
190};
191pub use types::*;
192pub use velocity::{
193 predict_range_rate_m_s, solve_velocity, RangeRatePrediction, ReceiverVelocityState,
194 VelocityConfig, VelocityObservation, VelocityRobustConfig, VelocitySolution,
195 VelocitySolveError,
196};
197
198pub use crate::ambiguity::CycleSlipPolicy;
199
200pub mod defaults {
214 pub const POSITION_TOLERANCE_M: f64 = 1.0e-4;
218
219 pub const CLOCK_TOLERANCE_M: f64 = 1.0e-4;
223
224 pub const AMBIGUITY_TOLERANCE_M: f64 = 1.0e-4;
228
229 pub const ZTD_TOLERANCE_M: f64 = 1.0e-4;
233
234 pub const MAX_ITERATIONS: usize = 8;
239
240 pub const RATIO_THRESHOLD: f64 = 3.0;
246}
247
248use std::collections::BTreeMap;
249
250use crate::constants::F_L1_HZ;
251use crate::estimation::recipe::NormalRecipe;
252use crate::observables::{ObservableEphemerisSource, ObservablesError, PredictOptions};
253use crate::ppp_corrections::{
254 self, PppCorrectionEpoch, PppCorrectionObservation, PppCorrectionsError, PppCorrectionsOptions,
255};
256use crate::sp3::Sp3;
257use crate::validate::{self, FieldError};
258
259const MAX_PPP_ITERATIONS: usize = 10_000;
260
261pub fn build_ppp_lookup(
263 sp3: &Sp3,
264 epochs: &[FloatEpoch],
265 receiver_ecef_m: [f64; 3],
266 options: &PppCorrectionsOptions,
267) -> Result<PppCorrectionLookup, PppCorrectionsError> {
268 let ppp_epochs: Vec<PppCorrectionEpoch> = epochs
269 .iter()
270 .map(|epoch| PppCorrectionEpoch {
271 epoch: epoch.epoch,
272 t_rx_j2000_s: epoch.t_rx_j2000_s,
273 observations: epoch
274 .observations
275 .iter()
276 .map(|obs| PppCorrectionObservation {
277 sat: obs.sat,
278 freq1_hz: obs.freq1_hz,
279 freq2_hz: obs.freq2_hz,
280 glonass_channel: obs.glonass_channel,
281 })
282 .collect(),
283 })
284 .collect();
285 let corrections = ppp_corrections::build(sp3, &ppp_epochs, receiver_ecef_m, options)?;
286 Ok(PppCorrectionLookup::from_options(corrections, options))
287}
288
289impl FloatState {
290 fn default_for_epochs(epochs: &[FloatEpoch]) -> Self {
291 Self {
292 position_m: [0.0; 3],
293 clocks_m: vec![0.0; epochs.len()],
294 ambiguities_m: BTreeMap::new(),
295 ztd_m: 0.0,
296 }
297 }
298}
299
300#[derive(Clone, Copy)]
308struct ModelContext<'a> {
309 source: &'a dyn ObservableEphemerisSource,
310 weights: MeasurementWeights,
311 tropo: TroposphereOptions,
312 corrections: &'a RangeCorrections,
313 normal: NormalRecipe,
314}
315
316fn predict_default(
317 _source: &dyn ObservableEphemerisSource,
318 _obs: &FloatObservation,
319) -> Result<PredictOptions, FloatSolveError> {
320 Ok(PredictOptions {
321 carrier_hz: F_L1_HZ,
322 light_time: true,
323 sagnac: true,
324 })
325}
326
327fn no_ephemeris(obs: &FloatObservation, error: ObservablesError) -> FloatSolveError {
328 FloatSolveError::NoEphemeris {
329 satellite_id: obs.satellite_id.clone(),
330 reason: match error {
331 ObservablesError::NoEphemeris => NoEphemerisReason::NoEphemeris,
332 ObservablesError::InvalidInput { .. } => NoEphemerisReason::Reason(error.to_string()),
333 ObservablesError::Ephemeris(err) => NoEphemerisReason::Reason(err.to_string()),
334 },
335 }
336}
337
338fn missing_satellite_clock(obs: &FloatObservation) -> FloatSolveError {
339 FloatSolveError::NoEphemeris {
340 satellite_id: obs.satellite_id.clone(),
341 reason: NoEphemerisReason::MissingSatelliteClock,
342 }
343}
344
345fn missing_correction(obs: &FloatObservation, correction: MissingCorrection) -> FloatSolveError {
346 FloatSolveError::MissingCorrection {
347 satellite_id: obs.satellite_id.clone(),
348 correction,
349 }
350}
351
352fn invalid_clock_count(expected: usize, actual: usize) -> FloatSolveError {
353 FloatSolveError::InvalidClockCount { expected, actual }
354}
355
356fn invalid_solve_option(field: &'static str, reason: &'static str) -> FloatSolveError {
357 FloatSolveError::InvalidSolveOption { field, reason }
358}
359
360pub(super) fn invalid_input(error: FieldError) -> FloatSolveError {
361 invalid_input_field(error.field(), error.reason())
362}
363
364fn invalid_input_field(field: &'static str, reason: &'static str) -> FloatSolveError {
365 FloatSolveError::InvalidInput { field, reason }
366}
367
368fn invalid_fixed_input(error: FieldError) -> FixedSolveError {
369 FixedSolveError::Float(invalid_input(error))
370}
371
372pub(super) fn validate_float_solve_boundary(
373 epochs: &[FloatEpoch],
374 state: &FloatState,
375 config: &FloatSolveConfig,
376) -> Result<(), FloatSolveError> {
377 validate_epochs(epochs)?;
378 validate_float_state(state, epochs.len())?;
379 validate_float_config(config)
380}
381
382pub(super) fn validate_fixed_solve_boundary(
383 epochs: &[FloatEpoch],
384 solution: &FloatSolution,
385 config: &FixedSolveConfig,
386) -> Result<(), FixedSolveError> {
387 validate_epochs(epochs).map_err(FixedSolveError::Float)?;
388 validate_float_solution(solution, epochs.len())?;
389 validate_fixed_config(config)
390}
391
392fn validate_epochs(epochs: &[FloatEpoch]) -> Result<(), FloatSolveError> {
393 for epoch in epochs {
394 validate_epoch(epoch)?;
395 }
396 Ok(())
397}
398
399fn validate_epoch(epoch: &FloatEpoch) -> Result<(), FloatSolveError> {
400 validate::civil_datetime_with_second_policy(
401 epoch.epoch.year as i64,
402 epoch.epoch.month as i64,
403 epoch.epoch.day as i64,
404 epoch.epoch.hour as i64,
405 epoch.epoch.minute as i64,
406 epoch.epoch.second,
407 validate::CivilSecondPolicy::Continuous,
408 )
409 .map_err(invalid_input)?;
410 validate::finite(epoch.jd_whole, "ppp epoch jd_whole").map_err(invalid_input)?;
411 validate::finite(epoch.jd_fraction, "ppp epoch jd_fraction").map_err(invalid_input)?;
412 validate::finite(epoch.t_rx_j2000_s, "ppp epoch t_rx_j2000_s").map_err(invalid_input)?;
413 for obs in &epoch.observations {
414 validate_observation(obs)?;
415 }
416 Ok(())
417}
418
419fn validate_observation(obs: &FloatObservation) -> Result<(), FloatSolveError> {
420 validate::finite(obs.code_m, "ppp observation code_m").map_err(invalid_input)?;
421 validate::finite(obs.phase_m, "ppp observation phase_m").map_err(invalid_input)?;
422 validate::finite(obs.freq1_hz, "ppp observation freq1_hz").map_err(invalid_input)?;
423 validate::finite(obs.freq2_hz, "ppp observation freq2_hz").map_err(invalid_input)?;
424 Ok(())
425}
426
427fn validate_float_state(state: &FloatState, n_epochs: usize) -> Result<(), FloatSolveError> {
428 validate_state_clock_count(state, n_epochs)?;
429 validate::finite_vec3(state.position_m, "ppp state position_m").map_err(invalid_input)?;
430 validate::finite_slice(&state.clocks_m, "ppp state clocks_m").map_err(invalid_input)?;
431 for value in state.ambiguities_m.values() {
432 validate::finite(*value, "ppp state ambiguities_m").map_err(invalid_input)?;
433 }
434 validate::finite(state.ztd_m, "ppp state ztd_m").map_err(invalid_input)?;
435 Ok(())
436}
437
438fn validate_float_solution(
439 solution: &FloatSolution,
440 n_epochs: usize,
441) -> Result<(), FixedSolveError> {
442 validate_solution_clock_count(solution, n_epochs)?;
443 validate::finite_vec3(solution.position_m, "ppp float_solution position_m")
444 .map_err(invalid_fixed_input)?;
445 validate::finite_slice(
446 &solution.epoch_clocks_m,
447 "ppp float_solution epoch_clocks_m",
448 )
449 .map_err(invalid_fixed_input)?;
450 for value in solution.ambiguities_m.values() {
451 validate::finite(*value, "ppp float_solution ambiguities_m")
452 .map_err(invalid_fixed_input)?;
453 }
454 if let Some(ztd_m) = solution.ztd_residual_m {
455 validate::finite(ztd_m, "ppp float_solution ztd_residual_m")
456 .map_err(invalid_fixed_input)?;
457 }
458 for residual in &solution.residuals_m {
459 validate::finite(residual.code_m, "ppp float_solution residual code_m")
460 .map_err(invalid_fixed_input)?;
461 validate::finite(residual.phase_m, "ppp float_solution residual phase_m")
462 .map_err(invalid_fixed_input)?;
463 validate::finite(
464 residual.code_weight,
465 "ppp float_solution residual code_weight",
466 )
467 .map_err(invalid_fixed_input)?;
468 validate::finite(
469 residual.phase_weight,
470 "ppp float_solution residual phase_weight",
471 )
472 .map_err(invalid_fixed_input)?;
473 }
474 validate::finite_nonneg(solution.code_rms_m, "ppp float_solution code_rms_m")
475 .map_err(invalid_fixed_input)?;
476 validate::finite_nonneg(solution.phase_rms_m, "ppp float_solution phase_rms_m")
477 .map_err(invalid_fixed_input)?;
478 validate::finite_nonneg(solution.weighted_rms_m, "ppp float_solution weighted_rms_m")
479 .map_err(invalid_fixed_input)?;
480 Ok(())
481}
482
483pub(super) fn validate_float_solution_output(
484 solution: &FloatSolution,
485 n_epochs: usize,
486) -> Result<(), FloatSolveError> {
487 validate_float_solution_clock_count(solution, n_epochs)?;
488 validate::finite_vec3(solution.position_m, "ppp float_solution position_m")
489 .map_err(invalid_input)?;
490 validate::finite_slice(
491 &solution.epoch_clocks_m,
492 "ppp float_solution epoch_clocks_m",
493 )
494 .map_err(invalid_input)?;
495 for value in solution.ambiguities_m.values() {
496 validate::finite(*value, "ppp float_solution ambiguities_m").map_err(invalid_input)?;
497 }
498 if let Some(ztd_m) = solution.ztd_residual_m {
499 validate::finite(ztd_m, "ppp float_solution ztd_residual_m").map_err(invalid_input)?;
500 }
501 for residual in &solution.residuals_m {
502 validate::finite(residual.code_m, "ppp float_solution residual code_m")
503 .map_err(invalid_input)?;
504 validate::finite(residual.phase_m, "ppp float_solution residual phase_m")
505 .map_err(invalid_input)?;
506 validate::finite(
507 residual.code_weight,
508 "ppp float_solution residual code_weight",
509 )
510 .map_err(invalid_input)?;
511 validate::finite(
512 residual.phase_weight,
513 "ppp float_solution residual phase_weight",
514 )
515 .map_err(invalid_input)?;
516 }
517 validate::finite_nonneg(solution.code_rms_m, "ppp float_solution code_rms_m")
518 .map_err(invalid_input)?;
519 validate::finite_nonneg(solution.phase_rms_m, "ppp float_solution phase_rms_m")
520 .map_err(invalid_input)?;
521 validate::finite_nonneg(solution.weighted_rms_m, "ppp float_solution weighted_rms_m")
522 .map_err(invalid_input)?;
523 Ok(())
524}
525
526fn validate_float_config(config: &FloatSolveConfig) -> Result<(), FloatSolveError> {
527 validate_common_config(
528 config.weights,
529 config.tropo,
530 &config.corrections,
531 config.opts,
532 )
533}
534
535fn validate_fixed_config(config: &FixedSolveConfig) -> Result<(), FixedSolveError> {
536 validate_common_config(
537 config.weights,
538 config.tropo,
539 &config.corrections,
540 config.opts,
541 )
542 .map_err(FixedSolveError::Float)?;
543 validate_fixed_ambiguity_options(&config.ambiguity)
544}
545
546fn validate_common_config(
547 weights: MeasurementWeights,
548 tropo: TroposphereOptions,
549 corrections: &RangeCorrections,
550 opts: FloatSolveOptions,
551) -> Result<(), FloatSolveError> {
552 validate_measurement_weights(weights)?;
553 validate_troposphere_options(tropo)?;
554 validate_range_corrections(corrections)?;
555 validate_float_solve_options(opts)
556}
557
558fn validate_measurement_weights(weights: MeasurementWeights) -> Result<(), FloatSolveError> {
559 validate::finite_positive(weights.code, "ppp measurement weight code")
560 .map_err(invalid_input)?;
561 validate::finite_positive(weights.phase, "ppp measurement weight phase")
562 .map_err(invalid_input)?;
563 Ok(())
564}
565
566fn validate_troposphere_options(tropo: TroposphereOptions) -> Result<(), FloatSolveError> {
567 if !tropo.enabled {
568 return Ok(());
569 }
570 validate::finite_positive(tropo.met.pressure_hpa, "ppp tropo pressure_hpa")
571 .map_err(invalid_input)?;
572 validate::finite_positive(tropo.met.temperature_k, "ppp tropo temperature_k")
573 .map_err(invalid_input)?;
574 validate::fraction(tropo.met.relative_humidity, "ppp tropo relative_humidity")
575 .map_err(invalid_input)?;
576 Ok(())
577}
578
579fn validate_range_corrections(corrections: &RangeCorrections) -> Result<(), FloatSolveError> {
580 if let Some(receiver) = &corrections.receiver_antenna {
581 validate::finite_positive(receiver.freq1_hz, "ppp receiver antenna freq1_hz")
582 .map_err(invalid_input)?;
583 validate::finite_positive(receiver.freq2_hz, "ppp receiver antenna freq2_hz")
584 .map_err(invalid_input)?;
585 if receiver.freq1_hz == receiver.freq2_hz {
586 return Err(invalid_input_field(
587 "ppp receiver antenna frequency pair",
588 "must differ",
589 ));
590 }
591 for frequency in &receiver.frequencies {
592 validate_receiver_antenna_frequency(frequency)?;
593 }
594 }
595 if let Some(clock) = &corrections.satellite_clock {
596 for records in clock.series.values() {
597 validate::require_strictly_increasing(
598 records.iter().map(|&(t_gps_s, _)| t_gps_s),
599 "ppp satellite clock epoch_s",
600 )
601 .map_err(invalid_input)?;
602 for &(t_gps_s, bias_s) in records {
603 validate::finite(t_gps_s, "ppp satellite clock epoch_s").map_err(invalid_input)?;
604 validate::finite(bias_s, "ppp satellite clock bias_s").map_err(invalid_input)?;
605 }
606 }
607 }
608 for vector in corrections.ppp.tide.values() {
609 validate::finite_vec3(*vector, "ppp correction tide vector_m").map_err(invalid_input)?;
610 }
611 for vector in corrections.ppp.pole_tide.values() {
612 validate::finite_vec3(*vector, "ppp correction pole_tide vector_m")
613 .map_err(invalid_input)?;
614 }
615 for vector in corrections.ppp.ocean_loading.values() {
616 validate::finite_vec3(*vector, "ppp correction ocean_loading vector_m")
617 .map_err(invalid_input)?;
618 }
619 for value in corrections.ppp.windup_m.values() {
620 validate::finite(*value, "ppp correction windup_m").map_err(invalid_input)?;
621 }
622 for vector in corrections.ppp.sat_pco_ecef.values() {
623 validate::finite_vec3(*vector, "ppp correction sat_pco_ecef").map_err(invalid_input)?;
624 }
625 for value in corrections.ppp.sat_pcv_m.values() {
626 validate::finite(*value, "ppp correction sat_pcv_m").map_err(invalid_input)?;
627 }
628 Ok(())
629}
630
631fn validate_receiver_antenna_frequency(
632 frequency: &ReceiverAntennaFrequency,
633) -> Result<(), FloatSolveError> {
634 validate::finite_vec3(frequency.pco_m, "ppp receiver antenna pco_m").map_err(invalid_input)?;
635 for sample in &frequency.pcv_samples {
636 validate_pcv_sample(sample)?;
637 }
638 Ok(())
639}
640
641fn validate_pcv_sample(sample: &PcvSample) -> Result<(), FloatSolveError> {
642 if let Some(azimuth_deg) = sample.azimuth_deg {
643 validate::finite(azimuth_deg, "ppp receiver antenna pcv azimuth_deg")
644 .map_err(invalid_input)?;
645 }
646 validate::finite_in_range(
647 sample.zenith_deg,
648 0.0,
649 180.0,
650 "ppp receiver antenna pcv zenith_deg",
651 )
652 .map_err(invalid_input)?;
653 validate::finite(sample.value_m, "ppp receiver antenna pcv value_m").map_err(invalid_input)?;
654 Ok(())
655}
656
657fn validate_fixed_ambiguity_options(
658 ambiguity: &FixedAmbiguityOptions,
659) -> Result<(), FixedSolveError> {
660 validate::finite_nonneg(
661 ambiguity.ratio_threshold,
662 "ppp fixed ambiguity ratio_threshold",
663 )
664 .map_err(invalid_fixed_input)?;
665 for value in ambiguity.wavelengths_m.values() {
666 validate::finite_positive(*value, "ppp fixed ambiguity wavelength_m")
667 .map_err(invalid_fixed_input)?;
668 }
669 for value in ambiguity.offsets_m.values() {
670 validate::finite(*value, "ppp fixed ambiguity offset_m").map_err(invalid_fixed_input)?;
671 }
672 Ok(())
673}
674
675fn validate_float_solve_options(opts: FloatSolveOptions) -> Result<(), FloatSolveError> {
676 if opts.max_iterations == 0 {
677 return Err(invalid_solve_option("max_iterations", "must be positive"));
678 }
679 if opts.max_iterations > MAX_PPP_ITERATIONS {
680 return Err(invalid_solve_option(
681 "max_iterations",
682 "exceeds the PPP iteration cap",
683 ));
684 }
685 validate_tolerance("position_tolerance_m", opts.position_tolerance_m)?;
686 validate_tolerance("clock_tolerance_m", opts.clock_tolerance_m)?;
687 validate_tolerance("ambiguity_tolerance_m", opts.ambiguity_tolerance_m)?;
688 validate_tolerance("ztd_tolerance_m", opts.ztd_tolerance_m)
689}
690
691fn validate_tolerance(field: &'static str, value: f64) -> Result<(), FloatSolveError> {
692 if validate::finite(value, field).is_err() {
693 return Err(invalid_solve_option(field, "must be finite"));
694 }
695 if value <= 0.0 {
696 return Err(invalid_solve_option(field, "must be positive"));
697 }
698 Ok(())
699}
700
701fn validate_state_clock_count(state: &FloatState, n_epochs: usize) -> Result<(), FloatSolveError> {
702 if state.clocks_m.len() == n_epochs {
703 Ok(())
704 } else {
705 Err(invalid_clock_count(n_epochs, state.clocks_m.len()))
706 }
707}
708
709fn validate_solution_clock_count(
710 solution: &FloatSolution,
711 n_epochs: usize,
712) -> Result<(), FixedSolveError> {
713 if solution.epoch_clocks_m.len() == n_epochs {
714 Ok(())
715 } else {
716 Err(FixedSolveError::Float(invalid_clock_count(
717 n_epochs,
718 solution.epoch_clocks_m.len(),
719 )))
720 }
721}
722
723fn validate_float_solution_clock_count(
724 solution: &FloatSolution,
725 n_epochs: usize,
726) -> Result<(), FloatSolveError> {
727 if solution.epoch_clocks_m.len() == n_epochs {
728 Ok(())
729 } else {
730 Err(invalid_clock_count(n_epochs, solution.epoch_clocks_m.len()))
731 }
732}
733
734fn state_from_solution(solution: &FloatSolution, prior: &FloatState) -> FloatState {
735 FloatState {
736 position_m: solution.position_m,
737 clocks_m: solution.epoch_clocks_m.clone(),
738 ambiguities_m: solution.ambiguities_m.clone(),
739 ztd_m: solution.ztd_residual_m.unwrap_or(prior.ztd_m),
740 }
741}
742
743fn estimates_ztd(tropo: TroposphereOptions) -> bool {
744 tropo.enabled && tropo.estimate_ztd
745}
746
747fn ztd_unknown_count(tropo: TroposphereOptions) -> usize {
748 usize::from(estimates_ztd(tropo))
749}
750
751fn rms(values: &[f64]) -> f64 {
752 if values.is_empty() {
753 return 0.0;
754 }
755 (values.iter().map(|v| v * v).sum::<f64>() / values.len() as f64).sqrt()
756}
757
758fn weighted_rms(rows: &[FloatResidual], weights: MeasurementWeights) -> f64 {
759 let mut values = Vec::with_capacity(rows.len() * 2);
760 for row in rows {
761 values.push(row.code_m * row.code_weight);
762 values.push(row.phase_m * row.phase_weight);
763 }
764 if values.is_empty() {
765 rms(&[0.0 * weights.code, 0.0 * weights.phase])
766 } else {
767 rms(&values)
768 }
769}
770
771fn max_abs(xs: &[f64]) -> f64 {
772 xs.iter().map(|x| x.abs()).fold(0.0, f64::max)
773}
774
775#[cfg(test)]
776mod tests;