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

Add compatibility for numpy 2 while preserving numpy 1 compatibility #1265

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
23 changes: 17 additions & 6 deletions outlines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@
from typing import Callable, Optional

import numpy as np
from numpy.lib.function_base import (
_calculate_shapes,
_parse_gufunc_signature,
_parse_input_dimensions,
_update_dim_sizes,
)

# Import required functions based on NumPy version
np_major_version = int(np.__version__.split(".")[0])
if np_major_version >= 2:
from numpy.lib._function_base_impl import (
_calculate_shapes,
_parse_gufunc_signature,
_parse_input_dimensions,
_update_dim_sizes,
)
else:
from numpy.lib.function_base import (
_calculate_shapes,
_parse_gufunc_signature,
_parse_input_dimensions,
_update_dim_sizes,
)

# Allow nested loops for running in notebook. We don't enable it globally as it
# may interfere with other libraries that use asyncio.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
"jinja2",
"lark",
"nest_asyncio",
"numpy<2.0.0",
"numpy",
"cloudpickle",
"diskcache",
"pydantic>=2.0",
Expand Down