using System;
using CeresSharp.Enums;
using CeresSharp.Native;
using CeresSharp.Native.SafeHandles;
namespace CeresSharp.Advanced;
///
/// Options for covariance estimation.
///
public sealed class CovarianceOptions : IDisposable
{
private readonly CovarianceOptionsHandle _handle;
private bool _disposed;
///
/// Creates a new CovarianceOptions instance with default settings.
///
public CovarianceOptions()
{
_handle = CovarianceOptionsHandle.Create();
}
///
/// Gets the native handle.
///
internal CovarianceOptionsHandle Handle => _handle;
///
/// Gets or sets the number of threads to use.
///
public int NumThreads
{
get => CeresNative.ceres_wrapper_covariance_options_get_num_threads(_handle.DangerousGetHandle());
set => CeresNative.ceres_wrapper_covariance_options_set_num_threads(_handle.DangerousGetHandle(), value);
}
///
/// Gets or sets the sparse linear algebra library type.
///
public SparseLinearAlgebraLibraryType SparseLinearAlgebraLibraryType
{
get => (SparseLinearAlgebraLibraryType)CeresNative.ceres_wrapper_covariance_options_get_sparse_linear_algebra_library_type(_handle.DangerousGetHandle());
set => CeresNative.ceres_wrapper_covariance_options_set_sparse_linear_algebra_library_type(_handle.DangerousGetHandle(), (int)value);
}
///
/// Gets or sets the algorithm type.
///
public CovarianceAlgorithmType AlgorithmType
{
get => (CovarianceAlgorithmType)CeresNative.ceres_wrapper_covariance_options_get_algorithm_type(_handle.DangerousGetHandle());
set => CeresNative.ceres_wrapper_covariance_options_set_algorithm_type(_handle.DangerousGetHandle(), (int)value);
}
///
/// Gets or sets the minimum reciprocal condition number.
///
public double MinReciprocalConditionNumber
{
get => CeresNative.ceres_wrapper_covariance_options_get_min_reciprocal_condition_number(_handle.DangerousGetHandle());
set => CeresNative.ceres_wrapper_covariance_options_set_min_reciprocal_condition_number(_handle.DangerousGetHandle(), value);
}
///
/// Gets or sets the null space rank.
///
public int NullSpaceRank
{
get => CeresNative.ceres_wrapper_covariance_options_get_null_space_rank(_handle.DangerousGetHandle());
set => CeresNative.ceres_wrapper_covariance_options_set_null_space_rank(_handle.DangerousGetHandle(), value);
}
///
/// Gets or sets whether to apply loss function.
///
public bool ApplyLossFunction
{
get => CeresNative.ceres_wrapper_covariance_options_get_apply_loss_function(_handle.DangerousGetHandle()) != 0;
set => CeresNative.ceres_wrapper_covariance_options_set_apply_loss_function(_handle.DangerousGetHandle(), value ? 1 : 0);
}
public void Dispose()
{
if (!_disposed)
{
_handle?.Dispose();
_disposed = true;
}
}
}