Skip to content

Commit

Permalink
Migrated to numpy 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sm00thix committed Jun 17, 2024
1 parent ea43314 commit b134752
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
34 changes: 11 additions & 23 deletions benchmarks/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,25 @@
E-mail: ole.e@di.ku.dk
"""
import os
import sys

# Add the parent directory of 'CVMatrix' to sys.path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# Set the number of threads to 1. This must be done before importing numpy.
os.environ["OMP_NUM_THREADS"] = "1"

from itertools import product
from timeit import timeit
from typing import Hashable, Iterable, Union

import numpy as np

import cvmatrix
from cvmatrix.__init__ import __version__
from cvmatrix.cvmatrix import CVMatrix
from tests.naive_cvmatrix import NaiveCVMatrix


def set_env_vars():
value = 1
str_value = str(value)
os.environ['OMP_NUM_THREADS'] = str_value # Set number of threads to 1
os.environ['OPENBLAS_NUM_THREADS'] = str_value # Set number of threads to 1
os.environ['MKL_NUM_THREADS'] = str_value # Set number of threads to 1
os.environ['VECLIB_MAXIMUM_THREADS'] = str_value # Set number of threads to 1
os.environ['NUMEXPR_NUM_THREADS'] = str_value # Set number of threads to 1
os.environ['OPENBLAS_MAIN_FREE'] = str_value # Set number of threads to 1
print_env_vars()

def print_env_vars():
print("OMP_NUM_THREADS:", os.environ['OMP_NUM_THREADS'])
print("OPENBLAS_NUM_THREADS:", os.environ['OPENBLAS_NUM_THREADS'])
print("MKL_NUM_THREADS:", os.environ['MKL_NUM_THREADS'])
print("VECLIB_MAXIMUM_THREADS:", os.environ['VECLIB_MAXIMUM_THREADS'])
print("NUMEXPR_NUM_THREADS:", os.environ['NUMEXPR_NUM_THREADS'])
print()

def save_result_to_csv(
model,
P,
Expand Down Expand Up @@ -130,7 +119,6 @@ def execute_algorithm(
model.training_XTX_XTY(fold)

if __name__ == '__main__':
set_env_vars()
seed = 42 # Seed for reproducibility
rng = np.random.default_rng(seed=seed)
N = 100000 # 100k samples
Expand Down Expand Up @@ -179,7 +167,7 @@ def execute_algorithm(
scale_X,
scale_Y,
time,
cvmatrix.__version__
__version__
)

if (center_X == center_Y == scale_X == scale_Y or
Expand Down Expand Up @@ -212,5 +200,5 @@ def execute_algorithm(
scale_X,
scale_Y,
time,
cvmatrix.__version__
__version__
)
2 changes: 1 addition & 1 deletion cvmatrix/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.0.post1'
__version__ = '1.0.1'
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cvmatrix"
version = "1.0.0.post1"
version = "1.0.1"
description = "Fast computation of possibly centered/scaled training set kernel matrices in a cross-validation setting."
authors = ["Sm00thix <oleemail@icloud.com>"]
maintainers = ["Sm00thix <oleemail@icloud.com>"]
Expand All @@ -11,7 +11,7 @@ repository = "https://github.com/Sm00thix/CVMatrix"

[tool.poetry.dependencies]
python = ">=3.9, <3.13"
numpy = "^1.26.4"
numpy = "^2.0.0"

[build-system]
requires = ["poetry-core"]
Expand Down
2 changes: 1 addition & 1 deletion tests/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def load_spectra():
resp_byte_array = resp.read()
byte_contents = io.BytesIO(resp_byte_array)
npz_arr = np.load(byte_contents)
spectra = np.row_stack([npz_arr[k] for k in npz_arr.keys()])
spectra = np.vstack([npz_arr[k] for k in npz_arr.keys()])
spectra = spectra.astype(np.float64)
spectra = -np.log10(spectra)
return spectra
8 changes: 4 additions & 4 deletions tests/test_cvmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ class tests for equivalency between the naive, straight-forward algorithms
csv = load_data.load_csv()
raw_spectra = load_data.load_spectra()

def load_X(self) -> npt.NDArray[np.float_]:
def load_X(self) -> npt.NDArray[np.float64]:
"""
Loads the raw spectral data.
Returns
-------
npt.NDArray[np.float_]
npt.NDArray[np.float64]
A copy of the raw spectral data.
"""
return np.copy(self.raw_spectra)

def load_Y(self, names: list[str]) -> npt.NDArray[np.float_]:
def load_Y(self, names: list[str]) -> npt.NDArray[np.float64]:
"""
Loads target values based on the specified column names.
Expand All @@ -67,7 +67,7 @@ def load_Y(self, names: list[str]) -> npt.NDArray[np.float_]:
Returns
-------
npt.NDArray[np.float_]
npt.NDArray[np.float64]
A copy of the target values.
"""
return self.csv[names].to_numpy()
Expand Down

0 comments on commit b134752

Please sign in to comment.