Skip to content

Commit

Permalink
Fixed logicle extension install - required generate-setup-file = true…
Browse files Browse the repository at this point in the history
… in toml
  • Loading branch information
burtonrj committed Jul 22, 2023
1 parent ea55592 commit 9f8ebc7
Show file tree
Hide file tree
Showing 11 changed files with 376 additions and 365 deletions.
24 changes: 24 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import Any, Dict

from setuptools_cpp import ExtensionBuilder, Pybind11Extension

ext_modules = [
Pybind11Extension(
"logicle_ext",
[
"cytotransform/logicle_ext/FastLogicle.cpp",
"cytotransform/logicle_ext/Logicle.cpp",
],
include_dirs=["cytotransform/logicle_ext"],
)
]


def build(setup_kwargs: Dict[str, Any]) -> None:
setup_kwargs.update(
{
"ext_modules": ext_modules,
"cmdclass": dict(build_ext=ExtensionBuilder),
"zip_safe": False,
}
)
24 changes: 15 additions & 9 deletions cytotransform/base.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from abc import ABC, abstractmethod
from typing import Callable
from joblib import Parallel, delayed, cpu_count
from typing import Any, Callable

import numpy as np
from joblib import Parallel, cpu_count, delayed


class Transform(ABC):
def __init__(
self,
transform_function: Callable,
inverse_transform_function: Callable,
parameters: dict,
n_jobs: int = -1
self,
transform_function: Callable,
inverse_transform_function: Callable,
parameters: dict,
n_jobs: int = -1,
):
self._transform_function = transform_function
self._inverse_transform_function = inverse_transform_function
Expand All @@ -28,7 +29,7 @@ def transform(self, data: np.ndarray) -> np.ndarray:
def inverse_transform(self, data: np.ndarray) -> np.ndarray:
return self._multiprocess_call(data, self._inverse_transform_function)

def _batches(self, data: np.ndarray) -> np.ndarray:
def _batches(self, data: np.ndarray) -> list[np.ndarray[Any, np.dtype[Any]]]:
"""
Split data into N batches, where N is the number of jobs to run in parallel.
Expand All @@ -47,4 +48,9 @@ def _batches(self, data: np.ndarray) -> np.ndarray:

def _multiprocess_call(self, data: np.ndarray, func: Callable) -> np.ndarray:
with Parallel(n_jobs=self.n_jobs) as parallel:
return np.concatenate(parallel(delayed(func)(batch, **self.parameters) for batch in self._batches(data)))
return np.concatenate(
parallel(
delayed(func)(batch, **self.parameters)
for batch in self._batches(data)
)
)
2 changes: 1 addition & 1 deletion cytotransform/logicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np

from cytotransform.logicle_ext import FastLogicle # type: ignore
from logicle_ext import FastLogicle # type: ignore

from .base import Transform

Expand Down
655 changes: 328 additions & 327 deletions poetry.lock

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cytotransform"
version = "0.1.11"
version = "0.1.12"
description = "Rapid transformations for cytometry data"
authors = ["Ross Burton <burtonrossj@gmail.com>"]
license = "MIT"
Expand Down Expand Up @@ -33,11 +33,15 @@ pytest-mock = "*"
pre-commit = "*"
mongomock = "*"
mypy = "*"
setuptools_cpp = "*"

[tool.poetry.build]
generate-setup-file = true
script = "build.py"

[build-system]
requires = ["pybind11", "setuptools"]
build-backend = "setuptools.build_meta"
requires = ["poetry>=0.12", "setuptools", "wheel", "setuptools-cpp"]
build-backend = "poetry.core.masonry.api"

##### isort configuration https://pycqa.github.io/isort/docs/configuration/config_files.html
[tool.isort]
Expand Down
24 changes: 0 additions & 24 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/report.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="6" time="0.967" timestamp="2023-06-24T17:40:18.399685" hostname="baymax"><testcase classname="tests.test_transformer" name="test_transforms[1-group0]" time="0.001" /><testcase classname="tests.test_transformer" name="test_transforms[-1-group1]" time="0.703" /><testcase classname="tests.test_transformer" name="test_transforms[1-group2]" time="0.001" /><testcase classname="tests.test_transformer" name="test_transforms[-1-group3]" time="0.028" /><testcase classname="tests.test_transformer" name="test_transforms[1-group4]" time="0.001" /><testcase classname="tests.test_transformer" name="test_transforms[-1-group5]" time="0.021" /></testsuite></testsuites>
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="6" time="1.260" timestamp="2023-07-22T15:57:12.881162" hostname="baymax"><testcase classname="tests.test_transformer" name="test_transforms[1-group0]" time="0.001" /><testcase classname="tests.test_transformer" name="test_transforms[-1-group1]" time="0.672" /><testcase classname="tests.test_transformer" name="test_transforms[1-group2]" time="0.001" /><testcase classname="tests.test_transformer" name="test_transforms[-1-group3]" time="0.131" /><testcase classname="tests.test_transformer" name="test_transforms[1-group4]" time="0.001" /><testcase classname="tests.test_transformer" name="test_transforms[-1-group5]" time="0.087" /></testsuite></testsuites>
Binary file added tmp/tmp2lq8hv_g.o
Binary file not shown.
Binary file added tmp/tmp4rzapw9v.o
Binary file not shown.
Binary file added tmp/tmpjhp18z0v.o
Binary file not shown.
Binary file added tmp/tmpwcrdgnlm.o
Binary file not shown.

0 comments on commit 9f8ebc7

Please sign in to comment.