Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix use of acceleration helper #72

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/galax/potential/_potential/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def potential_energy(
E : Array[float, *batch]
The potential energy per unit mass or value of the potential.
"""
return self._potential_energy(q, t)
return self._potential_energy(q, xp.asarray(t))

@partial_jit()
def __call__(
Expand Down Expand Up @@ -160,7 +160,7 @@ def gradient(self, q: BatchVec3, /, t: BatchableFloatOrIntScalarLike) -> BatchVe
grad : Array[float, (*batch, 3)]
The gradient of the potential.
"""
return self._gradient(q, t) # vectorize doesn't allow kwargs
return self._gradient(q, xp.asarray(t)) # vectorize doesn't allow kwargs

# ---------------------------------------
# Density
Expand Down Expand Up @@ -192,7 +192,7 @@ def density(
rho : Array[float, *batch]
The potential energy or value of the potential.
"""
return self._density(q, t)
return self._density(q, xp.asarray(t))

# ---------------------------------------
# Hessian
Expand Down Expand Up @@ -222,17 +222,11 @@ def hessian(
Array[float, (*batch, 3, 3)]
The Hessian matrix of second derivatives of the potential.
"""
return self._hessian(q, t)
return self._hessian(q, xp.asarray(t))

###########################################################################
# Convenience methods

@partial_jit()
@vectorize_method(signature="(3),()->(3)")
def _acceleration(self, q: Vec3, /, t: FloatScalar) -> Vec3:
"""See ``acceleration``."""
return -self.gradient(q, t)

def acceleration(
self, q: BatchVec3, /, t: BatchableFloatOrIntScalarLike
) -> BatchVec3:
Expand All @@ -251,7 +245,7 @@ def acceleration(
The acceleration. Will have the same shape as the input
position array, ``q``.
"""
return -self.gradient(q, t)
return -self._gradient(q, xp.asarray(t))

@partial_jit()
def tidal_tensor(
Expand Down