Skip to content

Commit

Permalink
🎨 Apply pre-commit hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbriol committed Sep 8, 2024
1 parent 445b658 commit b88e8d6
Show file tree
Hide file tree
Showing 54 changed files with 261 additions and 288 deletions.
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
level of experience, education, socioeconomic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards
Expand Down
3 changes: 1 addition & 2 deletions scripts/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Generates stubs for the core modules.
=====================================
"""
from typing import List
import os
import pathlib
import re
Expand Down Expand Up @@ -62,7 +61,7 @@ def fix_core_geodetic(src: pathlib.Path):
stream.writelines(lines)


def fix_core_fill(src: pathlib.Path, grids: List[str]):
def fix_core_fill(src: pathlib.Path, grids: list[str]):
core = src / 'pyinterp' / 'core' / 'fill.pyi'
with core.open('r') as stream:
lines = stream.readlines()
Expand Down
2 changes: 1 addition & 1 deletion src/pyinterp/backends/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
from __future__ import annotations

from typing import Hashable
from collections.abc import Hashable
import pickle

import numpy
Expand Down
2 changes: 1 addition & 1 deletion src/pyinterp/core/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ class Period:


Array1DPeriod = numpy.ndarray[
Literal['N'],
tuple[int],
numpy.dtype[Period] # type: ignore[type-var]
]

Expand Down
8 changes: 4 additions & 4 deletions src/pyinterp/core/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ from typing import Any, Literal

import numpy

_1D = Literal['N']
_2D = Literal['N', 'M']
_3D = Literal['N', 'M', 'O']
_4D = Literal['N', 'M', 'O', 'P']
_1D = tuple[int]
_2D = tuple[int, int]
_3D = tuple[int, int, int]
_4D = tuple[int, int, int, int]

Array1DBool = numpy.ndarray[_1D, numpy.dtype[numpy.bool_]]
Array1DFloat32 = numpy.ndarray[_1D, numpy.dtype[numpy.float32]]
Expand Down
4 changes: 2 additions & 2 deletions src/pyinterp/core/include/pyinterp/axis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class Axis : public detail::Axis<T>,
/// points on the axis or the value -1 if the *bounded* parameter is set
/// to false and the index looked for is located outside the limits of the
/// axis.
auto find_index(const pybind11::array_t<T> &coordinates, bool bounded) const
-> pybind11::array_t<int64_t> {
auto find_index(const pybind11::array_t<T> &coordinates,
bool bounded) const -> pybind11::array_t<int64_t> {
detail::check_array_ndim("coordinates", 1, coordinates);

auto size = coordinates.size();
Expand Down
8 changes: 4 additions & 4 deletions src/pyinterp/core/include/pyinterp/bivariate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ template <template <class> class Point, typename Coordinate, typename Type>
auto bivariate(const Grid2D<Type> &grid, const pybind11::array_t<Coordinate> &x,
const pybind11::array_t<Coordinate> &y,
const BivariateInterpolator<Point, Coordinate> *interpolator,
const bool bounds_error, const size_t num_threads)
-> pybind11::array_t<Coordinate> {
const bool bounds_error,
const size_t num_threads) -> pybind11::array_t<Coordinate> {
pyinterp::detail::check_array_ndim("x", 1, x, "y", 1, y);
pyinterp::detail::check_ndarray_shape("x", x, "y", y);

Expand Down Expand Up @@ -167,8 +167,8 @@ void implement_bivariate_interpolator(pybind11::module &m,
using CoordinateSystem::CoordinateSystem;

auto evaluate(const Point<T> &p, const Point<T> &p0, const Point<T> &p1,
const T &q00, const T &q01, const T &q10, const T &q11) const
-> T override {
const T &q00, const T &q01, const T &q10,
const T &q11) const -> T override {
PYBIND11_OVERLOAD_PURE(T, CoordinateSystem, "evaluate", p, p0, // NOLINT
p1, // NOLINT
q00, q01, q10, q11); // NOLINT
Expand Down
9 changes: 4 additions & 5 deletions src/pyinterp/core/include/pyinterp/dateutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,8 @@ class FractionalSeconds {
return static_cast<int>(std::log10(order_of_magnitude_));
}

[[nodiscard]] constexpr auto cast(const int64_t frac,
const int64_t scale) const noexcept
-> int64_t {
[[nodiscard]] constexpr auto cast(
const int64_t frac, const int64_t scale) const noexcept -> int64_t {
return order_of_magnitude_ <= scale ? (scale / order_of_magnitude_) * frac
: frac / (order_of_magnitude_ / scale);
}
Expand Down Expand Up @@ -473,8 +472,8 @@ constexpr auto datetime_from_minutes(const int64_t minutes)
}

/// Convert a datetime64 to a string
inline auto datetime64_to_string(const int64_t value, const DType &dtype)
-> std::string {
inline auto datetime64_to_string(const int64_t value,
const DType &dtype) -> std::string {
auto date = Date{};
auto time = Time{};
auto ss = std::stringstream{};
Expand Down
14 changes: 6 additions & 8 deletions src/pyinterp/core/include/pyinterp/detail/axis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ class Axis {
/// @param start index of the first element to include in the slice
/// @param count number of elements to include in the slice
/// @return a slice of the axis
[[nodiscard]] constexpr auto slice(int64_t start, int64_t count) const
-> Vector<T> {
[[nodiscard]] constexpr auto slice(int64_t start,
int64_t count) const -> Vector<T> {
if (start < 0 || start + count > size()) {
throw std::out_of_range("axis index out of range");
}
Expand Down Expand Up @@ -248,9 +248,8 @@ class Axis {

/// Returns the normalized value of the coordinate with the respect to the
/// axis definition.
[[nodiscard]] constexpr auto normalize_coordinate(const T coordinate,
const T min) const noexcept
-> T {
[[nodiscard]] constexpr auto normalize_coordinate(
const T coordinate, const T min) const noexcept -> T {
if (is_angle() && (coordinate >= min + circle_ || coordinate < min)) {
return math::normalize_angle(coordinate, min, circle_);
}
Expand Down Expand Up @@ -290,9 +289,8 @@ class Axis {
/// is located before, or the value of the last element of this container if
/// the requested value is located after.
/// @return index of the grid point containing it or -1 if outside grid area
[[nodiscard]] constexpr auto find_nearest_index(T coordinate,
const bool bounded) const
-> int64_t {
[[nodiscard]] constexpr auto find_nearest_index(
T coordinate, const bool bounded) const -> int64_t {
coordinate = normalize_coordinate(coordinate);
auto result = axis_->find_index(coordinate, bounded);
if (result == -1 && is_circle_) {
Expand Down
28 changes: 12 additions & 16 deletions src/pyinterp/core/include/pyinterp/detail/axis/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class Abstract {
/// @param start index of the first element to include in the slice
/// @param count number of elements to include in the slice
/// @return a slice of the axis
[[nodiscard]] virtual auto slice(int64_t start, int64_t count) const
-> Vector<T> = 0;
[[nodiscard]] virtual auto slice(int64_t start,
int64_t count) const -> Vector<T> = 0;

/// Get the minimum coordinate value.
///
Expand Down Expand Up @@ -107,8 +107,8 @@ class Abstract {
/// the requested value is located after.
/// @return index of the requested value it or -1 if outside this coordinate
/// system area.
[[nodiscard]] virtual auto find_index(T coordinate, bool bounded) const
-> int64_t = 0;
[[nodiscard]] virtual auto find_index(T coordinate,
bool bounded) const -> int64_t = 0;

/// compare two variables instances
///
Expand Down Expand Up @@ -281,9 +281,8 @@ class Irregular : public Abstract<T> {
}

/// @copydoc Abstract::slice(const int64_t, const int64_t) const
[[nodiscard]] constexpr auto slice(const int64_t start,
const int64_t count) const noexcept
-> Vector<T> override {
[[nodiscard]] constexpr auto slice(const int64_t start, const int64_t count)
const noexcept -> Vector<T> override {
return points_.segment(start, count);
}

Expand Down Expand Up @@ -313,9 +312,8 @@ class Irregular : public Abstract<T> {
}

/// @copydoc Abstract::find_index(double,bool) const
[[nodiscard]] constexpr auto find_index(const T coordinate,
const bool bounded) const
-> int64_t override {
[[nodiscard]] constexpr auto find_index(
const T coordinate, const bool bounded) const -> int64_t override {
if (this->is_ascending_) {
return this->find_index(coordinate, bounded, size(), std::less<T>());
}
Expand Down Expand Up @@ -435,9 +433,8 @@ class AbstractRegular : public Abstract<T> {
}

/// @copydoc Abstract::slice(const int64_t, const int64_t) const
[[nodiscard]] constexpr auto slice(const int64_t start,
const int64_t count) const noexcept
-> Vector<T> override {
[[nodiscard]] constexpr auto slice(const int64_t start, const int64_t count)
const noexcept -> Vector<T> override {
auto result = Vector<T>(count);
for (int64_t ix = 0; ix < count; ++ix) {
result[ix] = coordinate_value(start + ix);
Expand Down Expand Up @@ -551,9 +548,8 @@ class Regular<T, typename std::enable_if<std::is_integral_v<T>>::type>
: AbstractRegular<T>(start, stop, num), step_2_(this->step_ >> 1) {}

/// @copydoc Abstract::find_index(double,bool) const
[[nodiscard]] constexpr auto find_index(T coordinate,
bool bounded) const noexcept
-> int64_t override {
[[nodiscard]] constexpr auto find_index(
T coordinate, bool bounded) const noexcept -> int64_t override {
auto index =
static_cast<int64_t>(round((coordinate - this->start_), this->step_));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ constexpr auto is_retrograde(const T& x1, const T& x2, const T& x3) -> bool {
/// @param point the point to search.
/// @return the index of the nearest point.
template <typename T>
auto nearest_point(const LineString<T>& line, const Point2D<T>& point)
-> size_t {
auto nearest_point(const LineString<T>& line,
const Point2D<T>& point) -> size_t {
auto min_distance = std::numeric_limits<T>::max();
auto index = size_t(0);
for (auto it = line.begin(); it != line.end(); ++it) {
Expand Down
34 changes: 16 additions & 18 deletions src/pyinterp/core/include/pyinterp/detail/geometry/rtree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class RTree {
/// @overload query(const Point &, const Strategy &, const uint32_t) const
///
/// Overload of the query method with the default strategy.
auto query(const Point &point, const uint32_t k) const
-> std::vector<result_t> {
auto query(const Point &point,
const uint32_t k) const -> std::vector<result_t> {
return query(point, boost::geometry::default_strategy(), k);
}

Expand Down Expand Up @@ -162,8 +162,8 @@ class RTree {
/// @overload query_ball(const Point &, const Strategy &, const coordinate_t)
///
/// Overload of the query_ball method with the default strategy.
auto query_ball(const Point &point, const coordinate_t radius) const
-> std::vector<result_t> {
auto query_ball(const Point &point,
const coordinate_t radius) const -> std::vector<result_t> {
return query_ball(point, boost::geometry::default_strategy(), radius);
}

Expand Down Expand Up @@ -203,8 +203,8 @@ class RTree {
/// @overload query_within(const Point &, const Strategy &, const uint32_t)
///
/// Overload of the query_within method with the default strategy.
auto query_within(const Point &point, const uint32_t k) const
-> std::vector<result_t> {
auto query_within(const Point &point,
const uint32_t k) const -> std::vector<result_t> {
return query_within(point, boost::geometry::default_strategy(), k);
}

Expand Down Expand Up @@ -259,8 +259,8 @@ class RTree {
///
/// Overload of the value method with the default strategy.
auto value(const Point &point, const std::optional<coordinate_t> &radius,
const uint32_t k, const bool within) const
-> std::vector<value_t> {
const uint32_t k,
const bool within) const -> std::vector<value_t> {
return value(point, boost::geometry::default_strategy(), radius, k, within);
}

Expand Down Expand Up @@ -516,11 +516,10 @@ class RTree {
/// math::RBF<promotion_t> &, const coordinate_t, const uint32_t, const bool)
///
/// Overload of the radial_basis_function method with the default strategy.
auto radial_basis_function(const Point &point,
const math::RBF<promotion_t> &rbf,
const coordinate_t radius, const uint32_t k,
const bool within) const
-> std::pair<promotion_t, uint32_t> {
auto radial_basis_function(
const Point &point, const math::RBF<promotion_t> &rbf,
const coordinate_t radius, const uint32_t k,
const bool within) const -> std::pair<promotion_t, uint32_t> {
return radial_basis_function(point, boost::geometry::default_strategy(),
rbf, radius, k, within);
}
Expand Down Expand Up @@ -582,11 +581,10 @@ class RTree {
/// coordinate_t, const uint32_t, const bool)
///
/// Overload of the window_function method with the default strategy.
auto window_function(const Point &point,
const math::WindowFunction<coordinate_t> &wf,
const coordinate_t arg, const coordinate_t radius,
const uint32_t k, const bool within) const
-> std::pair<coordinate_t, uint32_t> {
auto window_function(
const Point &point, const math::WindowFunction<coordinate_t> &wf,
const coordinate_t arg, const coordinate_t radius, const uint32_t k,
const bool within) const -> std::pair<coordinate_t, uint32_t> {
return window_function(point, boost::geometry::default_strategy(), wf, arg,
radius, k, within);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Akima : public Interpolator1D<T> {
/// @brief Compute the coefficients of the interpolation
/// @param xa X-coordinates of the data points.
/// @param ya Y-coordinates of the data points.
auto compute_coefficients(const Vector<T>& xa, const Vector<T>& ya)
-> void override;
auto compute_coefficients(const Vector<T>& xa,
const Vector<T>& ya) -> void override;

/// Interpolation
/// @param xa X-coordinates of the data points.
Expand All @@ -55,8 +55,8 @@ class Akima : public Interpolator1D<T> {
};

template <typename T>
auto Akima<T>::compute_coefficients(const Vector<T>& xa, const Vector<T>& ya)
-> void {
auto Akima<T>::compute_coefficients(const Vector<T>& xa,
const Vector<T>& ya) -> void {
Interpolator1D<T>::compute_coefficients(xa, ya);
auto size = xa.size();
if (m_.size() < size + 4) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Bicubic : public Interpolator2D<T> {
/// @param y The point where the interpolation must be calculated.
/// @return The interpolated value at the coordinates x, y.
constexpr auto interpolate_(const Vector<T> &xa, const Vector<T> &ya,
const Matrix<T> &za, const T &x, const T &y) const
-> T override;
const Matrix<T> &za, const T &x,
const T &y) const -> T override;

/// Compute the coefficients of the bicubic interpolation
/// @param xa X-coordinates of the data points.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Bilinear : public Interpolator2D<T> {
/// @param x The point where the interpolation must be calculated.
/// @param y The point where the interpolation must be calculated.
constexpr auto interpolate_(const Vector<T> &xa, const Vector<T> &ya,
const Matrix<T> &za, const T &x, const T &y) const
-> T override;
const Matrix<T> &za, const T &x,
const T &y) const -> T override;
};

template <typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class CSpline : public CSplineBase<T> {
/// @brief Compute the coefficients of the interpolation
/// @param xa X-coordinates of the data points.
/// @param ya Y-coordinates of the data points.
inline auto compute_coefficients(const Vector<T> &xa, const Vector<T> &ya)
-> void override;
inline auto compute_coefficients(const Vector<T> &xa,
const Vector<T> &ya) -> void override;

/// @brief Solve a symmetric tridiagonal system
/// @param x The solution of the system
Expand Down Expand Up @@ -63,8 +63,8 @@ constexpr auto CSpline<T>::solve_symmetric_tridiagonal(T *x) -> void {
}

template <typename T>
auto CSpline<T>::compute_coefficients(const Vector<T> &xa, const Vector<T> &ya)
-> void {
auto CSpline<T>::compute_coefficients(const Vector<T> &xa,
const Vector<T> &ya) -> void {
Interpolator1D<T>::compute_coefficients(xa, ya);
const auto size = xa.size();
const auto size_m2 = size - 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class CSplineCoefficients {
/// Constructor
/// @param c0 The first derivative at the first point
/// @param c1 The first derivative at the last point
constexpr CSplineCoefficients(const T &c0, const T &c1) : c0_(c0), c1_(c1){};
constexpr CSplineCoefficients(const T &c0, const T &c1) : c0_(c0), c1_(c1) {};

/// Compute the coefficients of the cubic spline interpolation
/// @param dx The distance between the two points
/// @param dy The difference between the two points
/// @return The coefficients of the cubic spline interpolation
constexpr auto operator()(const T &dx, const T &dy) const
-> std::tuple<T, T, T> {
constexpr auto operator()(const T &dx,
const T &dy) const -> std::tuple<T, T, T> {
constexpr auto third = T(1) / T(3);
return {(dy / dx) - dx * (c1_ + 2 * c0_) * third, c0_,
(c1_ - c0_) / (3 * dx)};
Expand Down
Loading

0 comments on commit b88e8d6

Please sign in to comment.