Skip to content

Commit

Permalink
Replace numpy.vectorize with numba.vectorize in src/qha/grid_inte…
Browse files Browse the repository at this point in the history
…rpolation.py

wiht `calculate_eulerian_strain` & `from_eulerian_strain`
  • Loading branch information
singularitti committed Dec 20, 2023
1 parent 70572c7 commit 28c7ed7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/qha/grid_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
from typing import Optional, Tuple

import numpy as np
from numba import float64, vectorize

from qha.fitting import polynomial_least_square_fitting, apply_finite_strain_fitting
from qha.type_aliases import Vector, Matrix
from qha.fitting import apply_finite_strain_fitting, polynomial_least_square_fitting
from qha.type_aliases import Matrix, Vector
from qha.unit_conversion import gpa_to_ry_b3

# ===================== What can be exported? =====================
Expand All @@ -25,7 +26,7 @@
]


@np.vectorize
@vectorize([float64(float64, float64)], nopython=True, cache=True)
def calculate_eulerian_strain(v0, vs):
"""
Calculate the Eulerian strain (:math:`f`s) of a given volume vector *vs* with respect to a reference volume *v0*,
Expand All @@ -42,7 +43,7 @@ def calculate_eulerian_strain(v0, vs):
return 1 / 2 * ((v0 / vs) ** (2 / 3) - 1)


@np.vectorize
@vectorize([float64(float64, float64)], nopython=True, cache=True)
def from_eulerian_strain(v0, fs):
"""
Calculate the corresponding volumes :math:`V`s from a vector of given Eulerian strains (*fs*)
Expand Down Expand Up @@ -157,9 +158,10 @@ class is created, unless user is clear what is being done.
# r = v_upper / v_max = v_min / v_lower
v_lower, v_upper = v_min / self._ratio, v_max * self._ratio
# The *v_max* is a reference value here.
s_upper, s_lower = calculate_eulerian_strain(
v_max, v_lower
), calculate_eulerian_strain(v_max, v_upper)
s_upper, s_lower = (
calculate_eulerian_strain(v_max, v_lower),
calculate_eulerian_strain(v_max, v_upper),
)
self._strains = np.linspace(s_lower, s_upper, self._out_volumes_num)
self._out_volumes = from_eulerian_strain(v_max, self._strains)

Expand Down

0 comments on commit 28c7ed7

Please sign in to comment.