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

Pedro/fixes numpy changes #342

Merged
merged 6 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions .github/workflows/build_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
pip install -r requirements.txt
pip install wheel twine

- name: Update numpy for python 3.10 only
if: ${{ matrix.python-version == '3.10'}}
run: pip install numpy --upgrade

- name: Compile library
run: |
cd aequilibrae/paths
Expand Down
8 changes: 4 additions & 4 deletions aequilibrae/distribution/gravity_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ def __check_inputs(self):
mats = [(self.matrix, "Observed matrix"), (self.impedance, "Impedance matrix")]
for matrix, title in mats:
if matrix.matrix_view is None:
raise ValueError(title + " needs to be set for computation")
raise ValueError("{title} needs to be set for computation")
jamiecook marked this conversation as resolved.
Show resolved Hide resolved
else:
if len(matrix.matrix_view.shape[:]) > 2:
jamiecook marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError(title + "' computational view needs to be set for a single matrix core")
raise ValueError("{title}' computational view needs to be set for a single matrix core")
jamiecook marked this conversation as resolved.
Show resolved Hide resolved

if np.nansum(matrix.matrix_view.data) == 0:
raise ValueError(title + "has only zero values")
raise ValueError(f"{title} has only zero values")
if np.nanmin(matrix.matrix_view.data) < 0:
raise ValueError(title + "has negative values")
raise ValueError(f"{title} has negative values")

# Augment parameters if we happen to have only passed one
default_parameters = self.__get_parameters()
Expand Down
3 changes: 1 addition & 2 deletions aequilibrae/matrix/aequilibrae_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,7 @@ def nan_to_num(self):
raise NotImplementedError("This operation does not make sense for OMX matrices")

if np.issubdtype(self.dtype, np.floating) and self.matrix_view is not None:
jamiecook marked this conversation as resolved.
Show resolved Hide resolved
for m in self.view_names:
self.matrix[m][:, :] = np.nan_to_num(self.matrix[m])[:, :]
self.matrices[:, :, :] = np.nan_to_num(self.matrices[:, :, :])

def __vector(self, axis: int):
if self.view_names is None:
Expand Down
2 changes: 1 addition & 1 deletion tests/aequilibrae/distribution/test_gravityApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
matrix.create_empty(**args)

# randoms = np.random.randint(5, size=(2, 4))
matrix.impedance[:, :] = np.random.rand(zones, zones)[:, :]
matrix.matrices[:, :, 0] = np.random.rand(zones, zones)[:, :]
matrix.index[:] = np.arange(matrix.zones) + 100
matrix.computational_view(["impedance"])

Expand Down
4 changes: 2 additions & 2 deletions tests/aequilibrae/distribution/test_gravityCalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

impedance = AequilibraeMatrix()
impedance.create_empty(**args)
impedance.impedance[:, :] = np.random.rand(zones, zones)[:, :] * 1000
impedance.matrices[:, :, 0] = np.random.rand(zones, zones)[:, :] * 1000
impedance.index[:] = np.arange(impedance.zones) + 100
impedance.computational_view(["impedance"])

args["matrix_names"] = ["base_matrix"]
args["file_name"] = AequilibraeMatrix().random_name()
matrix = AequilibraeMatrix()
matrix.create_empty(**args)
matrix.base_matrix[:, :] = np.random.rand(zones, zones)[:, :] * 1000
matrix.matrices[:, :, 0] = np.random.rand(zones, zones)[:, :] * 1000
matrix.index[:] = np.arange(matrix.zones) + 100
matrix.computational_view(["base_matrix"])

Expand Down
8 changes: 4 additions & 4 deletions tests/aequilibrae/matrix/test_aequilibraeMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def setUp(self) -> None:
self.matrix.create_empty(**args)

self.matrix.index[:] = np.arange(self.matrix.zones) + 100
self.matrix.mat[:, :] = np.random.rand(self.matrix.zones, self.matrix.zones)[:, :]
self.matrix.mat[:, :] = self.matrix.mat[:, :] * (1000 / np.sum(self.matrix.mat[:, :]))
self.matrix.matrices[:, :, 0] = np.random.rand(self.matrix.zones, self.matrix.zones)
self.matrix.matrices[:, :, 0] = self.matrix.mat[:, :] * (1000 / np.sum(self.matrix.mat[:, :]))
self.matrix.setName("Test matrix - " + str(random.randint(1, 10)))
self.matrix.setDescription("Generated at " + datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y"))
self.new_matrix = self.matrix
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_nan_to_num(self):
m = self.new_matrix.mat.sum() - self.new_matrix.mat[1, 1]
self.new_matrix.computational_view(["mat", "seed"])
self.new_matrix.nan_to_num()
self.new_matrix.mat[1, 1] = np.nan
self.new_matrix.matrices[1, 1, 0] = np.nan
self.new_matrix.computational_view(["mat"])
self.new_matrix.nan_to_num()

Expand Down Expand Up @@ -266,7 +266,7 @@ def test_matrix_reference_doesnt_prevent_resource_cleanup(tmp_path):
}
matrix = AequilibraeMatrix()
matrix.create_empty(**kwargs)
ref = matrix.mat
_ = matrix.mat
del matrix

try:
Expand Down