Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*ipynb*
*build*
dist/*
*demo_2*
*dist*
perf.data
Expand Down
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include dadac/src/*
include dadac/bin/.placeholder
include dadac/include/*
include dadac/Makefile
include dadac/__init__.py
15 changes: 9 additions & 6 deletions benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,15 @@ def profileAndRun(dataset, dataset_name, k, Z, results, halo=False):
x2 = np.random.normal([2, 0, 0, 0, 0], 1, size=(n, 5))
x = np.concatenate([x1, x2])

profileAndRun(x, "5D Gaussian", k, Z, results)
#profileAndRun(x, "5D Gaussian", k, Z, results)

# ---------------------------------------------------------------------
#
# MNIST
#
# ---------------------------------------------------------------------


x, y = fetch_openml(
"mnist_784", version=1, return_X_y=True, as_frame=False, parser="pandas"
)
Expand All @@ -193,7 +194,7 @@ def profileAndRun(dataset, dataset_name, k, Z, results, halo=False):
x = x.astype(np.float64) / 255.0


profileAndRun(x, "MNIST", k, Z, results)
#profileAndRun(x, "MNIST", k, Z, results)

# ---------------------------------------------------------------------
#
Expand All @@ -203,9 +204,9 @@ def profileAndRun(dataset, dataset_name, k, Z, results, halo=False):

# trying to import from dadapy examples

for ds_name in example_names[:2]:
data = getFromUrl(base_url, ds_name)
profileAndRun(data, ds_name, k, Z, results)
#for ds_name in example_names[:2]:
# data = getFromUrl(base_url, ds_name)
# profileAndRun(data, ds_name, k, Z, results)

# ---------------------------------------------------------------------
#
Expand All @@ -214,13 +215,15 @@ def profileAndRun(dataset, dataset_name, k, Z, results, halo=False):
# ---------------------------------------------------------------------

data = get_example_from_drive()
profileAndRun(data[:100000], "Astro (sub)Set 1", k, Z, results)
#profileAndRun(data[:100000], "Astro (sub)Set 1", k, Z, results)


if run_big:
profileAndRun(data[:500000], "Astro (sub)Set 1", k, Z, results)
profileAndRun(data, "Astro (sub)Set 1", k, Z, results)



# ---------------------------------------------------------------------
#
# Generate tables
Expand Down
20 changes: 18 additions & 2 deletions dadac/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ COMPILING_INFO=@echo "[\e[36mCOMPILING\e[0m]: $@"
LINKING_INFO=@echo "[\e[34mLINKING\e[0m]: $@"


lib: bin/libdadac.so
CROSS_COMPILE_CFLAGS=${CFLAGS}
CROSS_COMPILE_CFLAGS+=-O3 -nostdlib -nostartfiles -nodefaultlibs

all: driver test
CFLAGS+=-O3 -march=native
all: driver test
@echo "[\e[31mFLAGS\e[0m]: ${CFLAGS}"

lib: bin/libdadac.so

arm: bin/libdadac.aarch64.so
x86: bin/libdadac.x86_64.so


test: test.o bin/libdadac.so
${CC} test.o -L./bin -ldadac ${LDFLAGS} ${DEBUG} -o test
Expand All @@ -53,5 +60,14 @@ bin/%.o : src/%.c
${CC} -c $< -o $@ ${CFLAGS} -fopenmp ${DEBUG} -fpic ${VERBOSE}
${COMPILING_INFO}

bin/libdadac.aarch64.so : ${SOURCES}
@aarch64-linux-gnu-gcc ${SOURCES} ${CROSS_COMPILE_FLAGS} ${LDFLAGS} ${VERBOSE} ${DEBUG} -fpic -shared -o $@
${COMPILING_INFO}

bin/libdadac.x86_64.so : ${SOURCES}
@gcc-11 ${SOURCES} ${CROSS_COMPILE_FLAGS} ${LDFLAGS} ${VERBOSE} ${DEBUG} -fpic -shared -o $@
${COMPILING_INFO}


clean:
rm bin/*.so bin/*.o *.o driver test
29 changes: 29 additions & 0 deletions dadac/dadac.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ class sparse_border_t(ct.Structure):
("density", ct_float_t),
("error", ct_float_t),
]
class _dadac_loader():
def __init__(self):
path = os.path.join(os.path.dirname(__file__), "bin/libdadac.so")
arch = platform.machine()
print(path)
if not os.path.exists(path):
#print("libdadac.so not found calling make for you")
#old_dir = os.getcwd()
#os.chdir(os.path.join(os.path.dirname(__file__)))
#if not os.path.exists(os.path.join(os.path.dirname(__file__), "bin")):
# os.system("mkdir bin")
#os.system("make lib")
#os.chdir(old_dir)

print(f"Loading binary for architecture: {arch}")
path = os.path.join(os.path.dirname(__file__), f"bin/libdadac.{arch}.so")
print(f"Loading: -> {path}")

try:
self.lib = ct.CDLL(path)
except:
print(f"Failed to load library please install dadac using:")
print(f" pip install git+https://github.com/lykos98/dadaC ")
raise()



class adj_list(ct.Structure):
Expand Down Expand Up @@ -304,6 +329,7 @@ def __init__(self, data: np.array, verbose=True):
Raises:
TypeError: Raises TypeError if a type different from a matrix is passed
"""

super().__init__()
# initialize class
if self._use_float32:
Expand Down Expand Up @@ -335,6 +361,8 @@ def __init__(self, data: np.array, verbose=True):
if len(self.data.shape) != 2:
raise TypeError("Please provide a 2d numpy array")

self.blas = self._blas_in_use() != 0

if verbose:
self._verbose = 1
else:
Expand All @@ -360,6 +388,7 @@ def __init__(self, data: np.array, verbose=True):
self._log_den = None
self._log_den_err = None
self.blas = self._blas_in_use() != 0

self._running_in_notebook = self._is_notebook()

def _is_notebook(self) -> bool:
Expand Down
31 changes: 14 additions & 17 deletions demo.ipynb

Large diffs are not rendered by default.

58 changes: 50 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import sys
from shutil import rmtree

from setuptools import find_packages, setup, Command
from setuptools import find_packages, setup, Command, Extension
from setuptools.command.install import install
from setuptools.command.build import build


# Package meta-data.
NAME = "dadac"
Expand All @@ -35,12 +37,10 @@
}


# compile everything
os.system("make -C $(pwd)/dadac")

EXT_DIR = os.path.join(os.path.dirname(__file__), "bin")



class RunMake(install):
"""Makefile on setuptools install."""

Expand All @@ -49,13 +49,36 @@ def run(self):
try:
os.chdir(EXT_DIR)
print("Building C library ...")
os.system("make")
# self.spawn(['make'])

os.system("make arm")
os.system("make x86")
#os.system("make lib")
#self.spawn(['make'])

finally:
os.chdir(old_dir)
install.run(self)


class RunMake_precompiled(build):
"""Makefile on setuptools install."""
user_options = []


def run(self):
old_dir = os.getcwd()
try:
if(os.path.exists("bin/libdadac.so")):
os.system("rm bin/libdadac.so")
os.chdir(EXT_DIR)
print("Building C library ...")
os.system("make arm")
os.system("make x86")
#self.spawn(['make'])
finally:
os.chdir(old_dir)
build.run(self)

# The rest you shouldn't have to touch too much :)
# ------------------------------------------------
# Except, perhaps the License and Trove Classifiers!
Expand Down Expand Up @@ -117,6 +140,14 @@ def run(self):

sys.exit()

dadac_module = Extension(
"dadac.core",
sources = ["dadac/src/dadac.c", "dadac/src/kdtree.c", "dadac/src/kdtreeV2.c", "dadac/src/heap.c", "dadac/src/vptree.c", "dadac/src/vptreeV2.c"],
include_dirs=["dadac/include"],
extra_compile_args=["-O3","-fopenmp"],
extra_link_args=["-fopenmp", "-lm"]
)


# Where the magic happens:
setup(
Expand All @@ -129,7 +160,11 @@ def run(self):
author_email=EMAIL,
python_requires=REQUIRES_PYTHON,
url=URL,
packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
#packages=find_packages(
# include=["dadac","dadac.src"],
# exclude=["tests", "*.tests", "*.tests.*", "tests.*","*src*","*include*","*src*"]
# ),
packages=["dadac"],
# If your package is a single module, use this instead of 'packages':
# py_modules=['mypackage'],
# entry_points={
Expand All @@ -138,6 +173,7 @@ def run(self):
install_requires=REQUIRED,
extras_require=EXTRAS,
include_package_data=True,

license="MIT",
package_data={"dadac": ["bin/*.so"]},
classifiers=[
Expand All @@ -151,5 +187,11 @@ def run(self):
"Programming Language :: Python :: Implementation :: PyPy",
],
# $ setup.py publish support.
cmdclass={"upload": UploadCommand, "intall": RunMake},
#ext_modules=[dadac_module],
cmdclass={
'install': RunMake,
'upload': UploadCommand,
'build': RunMake_precompiled,
},

)