Repository: fatiando/harmonica

Issue:
Raise error if masses array has not the same number of elements as points
**Description of the desired feature**

On the point mass forward model would be nice to check if the `masses` has the same number of elements as the points coordinates inside `points`. On the tesseroid forward model this is done, but for some reason we forgot to add it on the point mass case.


<!-- Please be as detailed as you can in your description. If possible, include an example of how you would like to use this feature (even better if it's a code example). -->


**Are you willing to help implement and maintain this feature?** Yes

<!-- Every feature we add is code that we will have to maintain and keep updated. This takes a lot of effort. If you are willing to be involved in the project and help maintain your feature, it will make it easier for us to accept it. -->


Discussion:
leouieda: :+1: merging!

Patch:
diff --git a/harmonica/forward/point_mass.py b/harmonica/forward/point_mass.py
index 353b57d..eff34cd 100644
--- a/harmonica/forward/point_mass.py
+++ b/harmonica/forward/point_mass.py
@@ -178,9 +178,15 @@ def point_mass_gravity(
     cast = np.broadcast(*coordinates[:3])
     result = np.zeros(cast.size, dtype=dtype)
     # Prepare arrays to be passed to the jitted functions
-    coordinates = (np.atleast_1d(i).ravel().astype(dtype) for i in coordinates[:3])
-    points = (np.atleast_1d(i).ravel().astype(dtype) for i in points[:3])
+    coordinates = tuple(np.atleast_1d(i).ravel().astype(dtype) for i in coordinates[:3])
+    points = tuple(np.atleast_1d(i).ravel().astype(dtype) for i in points[:3])
     masses = np.atleast_1d(masses).astype(dtype).ravel()
+    # Sanity checks
+    if masses.size != points[0].size:
+        raise ValueError(
+            "Number of elements in masses ({}) ".format(masses.size)
+            + "mismatch the number of points ({})".format(points[0].size)
+        )
     # Compute gravitational field
     dispatchers[coordinate_system](
         *coordinates, *points, masses, result, kernels[coordinate_system][field]


Test patch:
diff --git a/harmonica/tests/test_point_mass.py b/harmonica/tests/test_point_mass.py
index 79f3c4c..3735e5c 100644
--- a/harmonica/tests/test_point_mass.py
+++ b/harmonica/tests/test_point_mass.py
@@ -40,6 +40,23 @@ def test_invalid_field():
             )
 
 
+def test_invalid_masses_array():
+    "Check if error is raised when masses shape does not match points shape"
+    # Create a set of 3 point masses
+    points = [[-10, 0, 10], [-10, 0, 10], [-100, 0, 100]]
+    # Generate a two element masses
+    masses = [1000, 2000]
+    coordinates = [0, 0, 250]
+    with pytest.raises(ValueError):
+        point_mass_gravity(
+            coordinates,
+            points,
+            masses,
+            field="potential",
+            coordinate_system="cartesian",
+        )
+
+
 # ---------------------------
 # Cartesian coordinates tests
 # ---------------------------