diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..152f4c3 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include fimdlp/FImdlp.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..80acec7 --- /dev/null +++ b/Makefile @@ -0,0 +1,40 @@ +SHELL := /bin/bash +.DEFAULT_GOAL := help +.PHONY: coverage deps help lint push test doc build + +clean: ## Clean up + rm -rf build dist *.egg-info + for name in fimdlp/cfimdlp.cpp fimdlp/fimdlp.cpython-310-darwin.so;do if [ -f $name ]; then rm $name; fi; done + +lint: ## Lint and static-check + black fimdlp + flake8 fimdlp + +push: ## Push code with tags + git push && git push --tags + +build: ## Build package + rm -fr dist/* + rm -fr build/* + #python setup.py build_ext + python -m build + +audit: ## Audit pip + pip-audit + +help: ## Show help message + @IFS=$$'\n' ; \ + help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \ + printf "%s\n\n" "Usage: make [task]"; \ + printf "%-20s %s\n" "task" "help" ; \ + printf "%-20s %s\n" "------" "----" ; \ + for help_line in $${help_lines[@]}; do \ + IFS=$$':' ; \ + help_split=($$help_line) ; \ + help_command=`echo $${help_split[0]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \ + help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \ + printf '\033[36m'; \ + printf "%-20s %s" $$help_command ; \ + printf '\033[0m'; \ + printf "%s\n" $$help_info; \ + done diff --git a/FImdlp.cpp b/fimdlp/FImdlp.cpp similarity index 100% rename from FImdlp.cpp rename to fimdlp/FImdlp.cpp diff --git a/FImdlp.h b/fimdlp/FImdlp.h similarity index 100% rename from FImdlp.h rename to fimdlp/FImdlp.h diff --git a/fimdlp/__init__.py b/fimdlp/__init__.py new file mode 100644 index 0000000..7df9f7a --- /dev/null +++ b/fimdlp/__init__.py @@ -0,0 +1 @@ +from ._version import __version__ \ No newline at end of file diff --git a/fimdlp/_version.py b/fimdlp/_version.py new file mode 100644 index 0000000..c12f34c --- /dev/null +++ b/fimdlp/_version.py @@ -0,0 +1 @@ +__version__ = '0.1.1' \ No newline at end of file diff --git a/cfimdlp.pyx b/fimdlp/cfimdlp.pyx similarity index 99% rename from cfimdlp.pyx rename to fimdlp/cfimdlp.pyx index 0e5c886..cfa00b2 100644 --- a/cfimdlp.pyx +++ b/fimdlp/cfimdlp.pyx @@ -1,6 +1,7 @@ # distutils: language = c++ # cython: language_level = 3 from libcpp.vector cimport vector + cdef extern from "FImdlp.h" namespace "FImdlp": cdef cppclass FImdlp: FImdlp() except + diff --git a/prueba/FImdlp.cpp b/prueba/FImdlp.cpp new file mode 100644 index 0000000..19241c7 --- /dev/null +++ b/prueba/FImdlp.cpp @@ -0,0 +1,25 @@ +#include "FImdlp.h" +namespace FImdlp +{ + FImdlp::FImdlp() + { + } + FImdlp::~FImdlp() + { + } + std::vector FImdlp::cutPoints(std::vector &X, std::vector &y) + { + std::vector cutPts; + int i, ant = X.at(0); + int n = X.size(); + for (i = 1; i < n; i++) + { + if (X.at(i) != ant) + { + cutPts.push_back(float(X.at(i) + ant) / 2); + ant = X.at(i); + } + } + return cutPts; + } +} \ No newline at end of file diff --git a/prueba/FImdlp.h b/prueba/FImdlp.h new file mode 100644 index 0000000..d15cf8b --- /dev/null +++ b/prueba/FImdlp.h @@ -0,0 +1,15 @@ +#ifndef FIMDLP_H +#define FIMDLP_H +#include +#include +namespace FImdlp +{ + class FImdlp + { + public: + FImdlp(); + ~FImdlp(); + std::vector cutPoints(std::vector &, std::vector &); + }; +} +#endif \ No newline at end of file diff --git a/prueba/LICENSE b/prueba/LICENSE new file mode 100644 index 0000000..9508008 --- /dev/null +++ b/prueba/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Doctorado-ML + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/prueba/Makefile b/prueba/Makefile new file mode 100644 index 0000000..2c47f19 --- /dev/null +++ b/prueba/Makefile @@ -0,0 +1,42 @@ +SHELL := /bin/bash +.DEFAULT_GOAL := help +.PHONY: coverage deps help lint push test doc build + +clean: ## Clean up + rm -rf build dist *.egg-info + for name in fimdlp/cfimdlp.cpp fimdlp/fimdlp.cpython-310-darwin.so + do + if [ -f $name ]; then rm $name; fi + done + +lint: ## Lint and static-check + black fimdlp + flake8 fimdlp + +push: ## Push code with tags + git push && git push --tags + +build: ## Build package + rm -fr dist/* + rm -fr build/* + python setup.py build_ext + +audit: ## Audit pip + pip-audit + +help: ## Show help message + @IFS=$$'\n' ; \ + help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \ + printf "%s\n\n" "Usage: make [task]"; \ + printf "%-20s %s\n" "task" "help" ; \ + printf "%-20s %s\n" "------" "----" ; \ + for help_line in $${help_lines[@]}; do \ + IFS=$$':' ; \ + help_split=($$help_line) ; \ + help_command=`echo $${help_split[0]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \ + help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \ + printf '\033[36m'; \ + printf "%-20s %s" $$help_command ; \ + printf '\033[0m'; \ + printf "%s\n" $$help_info; \ + done diff --git a/prueba/README.md b/prueba/README.md new file mode 100644 index 0000000..e249e1c --- /dev/null +++ b/prueba/README.md @@ -0,0 +1,10 @@ +# FImdlp + +Fayyad - Irani MDLP discretization algorithm + +## Build and usage sample + +```bash +python setup.py build_ext --inplace +python sample.py +``` diff --git a/prueba/__init__.py b/prueba/__init__.py new file mode 100644 index 0000000..7df9f7a --- /dev/null +++ b/prueba/__init__.py @@ -0,0 +1 @@ +from ._version import __version__ \ No newline at end of file diff --git a/prueba/_version.py b/prueba/_version.py new file mode 100644 index 0000000..c12f34c --- /dev/null +++ b/prueba/_version.py @@ -0,0 +1 @@ +__version__ = '0.1.1' \ No newline at end of file diff --git a/prueba/cfimdlp.pyx b/prueba/cfimdlp.pyx new file mode 100644 index 0000000..cfa00b2 --- /dev/null +++ b/prueba/cfimdlp.pyx @@ -0,0 +1,17 @@ +# distutils: language = c++ +# cython: language_level = 3 +from libcpp.vector cimport vector + +cdef extern from "FImdlp.h" namespace "FImdlp": + cdef cppclass FImdlp: + FImdlp() except + + vector[float] cutPoints(vector[int]&, vector[int]&) + +cdef class CFImdlp: + cdef FImdlp *thisptr + def __cinit__(self): + self.thisptr = new FImdlp() + def __dealloc__(self): + del self.thisptr + def cut_points(self, X, y): + return self.thisptr.cutPoints(X, y) diff --git a/prueba/pyproject.toml b/prueba/pyproject.toml new file mode 100644 index 0000000..6c20890 --- /dev/null +++ b/prueba/pyproject.toml @@ -0,0 +1,38 @@ +# pyproject.toml +[build-system] +requires = ["setuptools", "cython", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +license-files = ["LICENSE"] + +[tool.setuptools.dynamic] +version = { attr = "fimdlp.__version__" } + +[project] +name = "FImdlp" +readme = "README.md" +authors = [ + { name = "Ricardo MontaƱana", email = "ricardo.montanana@alu.uclm.es" }, +] +dynamic = ['version'] +dependencies = ["numpy"] +requires-python = ">=3.8" +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", + "Topic :: Software Development", + "Topic :: Scientific/Engineering", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", +] + +[project.urls] +Home = "https://github.com/doctorado-ml/FImdlp" diff --git a/prueba/sample.py b/prueba/sample.py new file mode 100644 index 0000000..43df59e --- /dev/null +++ b/prueba/sample.py @@ -0,0 +1,14 @@ +import numpy as np +from sklearn.datasets import load_iris +from fimdlp import CFImdlp + +data = load_iris() +X = data.data +y = data.target +features = data.feature_names +test = CFImdlp() +print("Cut points for each feature in Iris dataset:") +for i in range(0, X.shape[1]): + data = np.sort(X[:, i]) + Xcutpoints = test.cut_points(data, y) + print(f"{features[i]:20s}: {Xcutpoints}") diff --git a/prueba/setup.py b/prueba/setup.py new file mode 100644 index 0000000..e5da331 --- /dev/null +++ b/prueba/setup.py @@ -0,0 +1,32 @@ +""" + Calling + $python setup.py build_ext --inplace + will build the extension library in the current file. +""" + +from setuptools import Extension, setup + +setup( + ext_modules=[ + Extension( + name="fimdlp", + sources=["cfimdlp.pyx", "FImdlp.cpp"], + language="c++", + include_dirs=["fimdlp"], + ), + ] +) + +# from Cython.Build import cythonize +# setup( +# ext_modules=cythonize( +# Extension( +# "fimdlp", +# sources=["fimdlp/cfimdlp.pyx", "fimdlp/FImdlp.cpp"], +# language="c++", +# include_dirs=["fimdlp"], +# ), +# include_path=["./fimdlp"], +# ) +# ) + diff --git a/pyproject.toml b/pyproject.toml index b80d296..a706dee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,39 @@ # pyproject.toml [build-system] -requires = ["setuptools", "cython"] +requires = ["setuptools", "cython", "wheel"] build-backend = "setuptools.build_meta" +[tool.setuptools] +packages = ["fimdlp"] +license-files = ["LICENSE"] + +[tool.setuptools.dynamic] +version = { attr = "fimdlp.__version__" } + [project] name = "FImdlp" -version = "0.1.0" +readme = "README.md" +authors = [ + { name = "Ricardo MontaƱana", email = "ricardo.montanana@alu.uclm.es" }, +] +dynamic = ['version'] +dependencies = ["numpy"] +requires-python = ">=3.8" +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", + "Topic :: Software Development", + "Topic :: Scientific/Engineering", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", +] + +[project.urls] +Home = "https://github.com/doctorado-ml/FImdlp" diff --git a/setup.py b/setup.py index b38b4b4..66d5539 100644 --- a/setup.py +++ b/setup.py @@ -10,8 +10,23 @@ setup( ext_modules=[ Extension( name="fimdlp", - sources=["cfimdlp.pyx", "FImdlp.cpp"], - language="c++", + sources=["fimdlp/cfimdlp.pyx", "fimdlp/FImdlp.cpp"], + language="c++", + include_dirs=["fimdlp"], ), ] ) + +# from Cython.Build import cythonize +# setup( +# ext_modules=cythonize( +# Extension( +# "fimdlp", +# sources=["fimdlp/cfimdlp.pyx", "fimdlp/FImdlp.cpp"], +# language="c++", +# include_dirs=["fimdlp"], +# ), +# include_path=["./fimdlp"], +# ) +# ) +