Initial commit

This commit is contained in:
2022-11-26 20:06:40 +01:00
parent adffe6cca8
commit db19867779
7 changed files with 97 additions and 0 deletions

2
.gitignore vendored
View File

@@ -127,3 +127,5 @@ dmypy.json
# Pyre type checker # Pyre type checker
.pyre/ .pyre/
cfimdlp.cpp
.vscode/*

25
FImdlp.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include "FImdlp.h"
namespace FImdlp
{
FImdlp::FImdlp()
{
}
FImdlp::~FImdlp()
{
}
std::vector<float> FImdlp::cutPoints(std::vector<int> &X, std::vector<int> &y)
{
std::vector<float> 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;
}
}

15
FImdlp.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef FIMDLP_H
#define FIMDLP_H
#include <vector>
#include <Python.h>
namespace FImdlp
{
class FImdlp
{
public:
FImdlp();
~FImdlp();
std::vector<float> cutPoints(std::vector<int> &, std::vector<int> &);
};
}
#endif

16
cfimdlp.pyx Normal file
View File

@@ -0,0 +1,16 @@
# 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)

8
pyproject.toml Normal file
View File

@@ -0,0 +1,8 @@
# pyproject.toml
[build-system]
requires = ["setuptools", "cython"]
build-backend = "setuptools.build_meta"
[project]
name = "FImdlp"
version = "0.1.0"

14
sample.py Normal file
View File

@@ -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}")

17
setup.py Normal file
View File

@@ -0,0 +1,17 @@
"""
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++",
),
]
)