Skip to content

Commit

Permalink
Merge branch 'main' into python-3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman authored Oct 9, 2024
2 parents 92d5945 + 054d148 commit bfcec3a
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

# Install Micromamba with conda-forge dependencies
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1.9.0
uses: mamba-org/setup-micromamba@v2.0.0
with:
environment-name: pygmt
condarc: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cache_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

# Install Micromamba with conda-forge dependencies
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1.9.0
uses: mamba-org/setup-micromamba@v2.0.0
with:
environment-name: pygmt
condarc: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:

# Install Micromamba with conda-forge dependencies
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1.9.0
uses: mamba-org/setup-micromamba@v2.0.0
with:
environment-name: pygmt
condarc: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_doctests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

# Install Micromamba with conda-forge dependencies
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1.9.0
uses: mamba-org/setup-micromamba@v2.0.0
with:
environment-name: pygmt
condarc: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:

# Install Micromamba with conda-forge dependencies
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1.9.0
uses: mamba-org/setup-micromamba@v2.0.0
with:
environment-name: pygmt
condarc: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:

# Install Micromamba with conda-forge dependencies
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1.9.0
uses: mamba-org/setup-micromamba@v2.0.0
with:
environment-name: pygmt
condarc: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

# Install Micromamba with conda-forge dependencies
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1.9.0
uses: mamba-org/setup-micromamba@v2.0.0
with:
environment-name: pygmt
condarc: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ jobs:
ls -lh dist/
- name: Publish to Test PyPI
uses: pypa/[email protected].2
uses: pypa/[email protected].3
with:
repository-url: https://test.pypi.org/legacy/

- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/[email protected].2
uses: pypa/[email protected].3
46 changes: 2 additions & 44 deletions pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def dataarray_to_matrix(grid):
inc = [abs(i) for i in inc]
grid = grid.sortby(variables=list(grid.dims), ascending=True)

matrix = as_c_contiguous(grid[::-1].to_numpy())
matrix = np.ascontiguousarray(grid[::-1].to_numpy())
region = [float(i) for i in region]
inc = [float(i) for i in inc]
return matrix, region, inc
Expand Down Expand Up @@ -200,53 +200,11 @@ def vectors_to_arrays(vectors):
for vector in vectors:
vec_dtype = str(getattr(vector, "dtype", ""))
array = np.asarray(a=vector, dtype=dtypes.get(vec_dtype))
arrays.append(as_c_contiguous(array))
arrays.append(np.ascontiguousarray(array))

return arrays


def as_c_contiguous(array):
"""
Ensure a numpy array is C contiguous in memory.
If the array is not C contiguous, a copy will be necessary.
Parameters
----------
array : 1-D array
The numpy array
Returns
-------
array : 1-D array
Array is C contiguous order.
Examples
--------
>>> import numpy as np
>>> data = np.array([[1, 2], [3, 4], [5, 6]])
>>> x = data[:, 0]
>>> x
array([1, 3, 5])
>>> x.flags.c_contiguous
False
>>> new_x = as_c_contiguous(x)
>>> new_x
array([1, 3, 5])
>>> new_x.flags.c_contiguous
True
>>> x = np.array([8, 9, 10])
>>> x.flags.c_contiguous
True
>>> as_c_contiguous(x).flags.c_contiguous
True
"""
if not array.flags.c_contiguous:
return array.copy(order="C")
return array


def sequence_to_ctypes_array(
sequence: Sequence | None, ctype, size: int
) -> ctp.Array | None:
Expand Down
3 changes: 1 addition & 2 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import xarray as xr
from pygmt.clib.conversion import (
array_to_datetime,
as_c_contiguous,
dataarray_to_matrix,
sequence_to_ctypes_array,
strings_to_ctypes_array,
Expand Down Expand Up @@ -1499,7 +1498,7 @@ def virtualfile_from_matrix(self, matrix):
# collected and the memory freed. Creating it in this context manager
# guarantees that the copy will be around until the virtual file is
# closed.
matrix = as_c_contiguous(matrix)
matrix = np.ascontiguousarray(matrix)
rows, columns = matrix.shape

family = "GMT_IS_DATASET|GMT_VIA_MATRIX"
Expand Down

0 comments on commit bfcec3a

Please sign in to comment.