Skip to content

Commit f20e17c

Browse files
committed
remove some python files
1 parent 44a6ce6 commit f20e17c

5 files changed

Lines changed: 476 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(DNLP_Diff_Engine C)
3+
set(CMAKE_C_STANDARD 99)
4+
5+
set(DIFF_ENGINE_VERSION_MAJOR 0)
6+
set(DIFF_ENGINE_VERSION_MINOR 0)
7+
set(DIFF_ENGINE_VERSION_PATCH 1)
8+
set(DIFF_ENGINE_VERSION "${DIFF_ENGINE_VERSION_MAJOR}.${DIFF_ENGINE_VERSION_MINOR}.${DIFF_ENGINE_VERSION_PATCH}")
9+
add_compile_definitions(DIFF_ENGINE_VERSION="${DIFF_ENGINE_VERSION}")
10+
11+
message(STATUS "Configuring DNLP Differentiation Engine (version ${DIFF_ENGINE_VERSION})")
12+
13+
14+
#Set default build type to Release if not specified
15+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
16+
message(STATUS "Setting build type to 'Release' as none was specified.")
17+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
18+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
19+
else()
20+
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
21+
endif()
22+
23+
# Warning flags (always enabled)
24+
add_compile_options(
25+
-Wall # Enable most warnings
26+
-Wextra # Extra warnings
27+
-Wpedantic # Strict ISO C compliance
28+
-Wshadow # Warn about variable shadowing
29+
-Wformat=2 # Extra format string checks
30+
-Wcast-qual # Warn about cast that removes qualifiers
31+
-Wcast-align # Warn about pointer cast alignment issues
32+
-Wunused # Warn about unused variables/functions
33+
-Wdouble-promotion # Warn about float->double promotion
34+
-Wnull-dereference # Warn about null pointer dereference
35+
)
36+
37+
# Include directories
38+
include_directories(${PROJECT_SOURCE_DIR}/include)
39+
40+
# Source files - automatically gather all .c files from src/
41+
file(GLOB_RECURSE SOURCES "src/*.c")
42+
43+
44+
# Create core library
45+
add_library(dnlp_diff ${SOURCES})
46+
target_link_libraries(dnlp_diff m)
47+
48+
# Config-specific compile options
49+
target_compile_options(dnlp_diff PRIVATE
50+
$<$<CONFIG:Debug>:-g -O0>
51+
$<$<CONFIG:Release>:-O3 -DNDEBUG>
52+
$<$<CONFIG:RelWithDebInfo>:-O2 -g -DNDEBUG>
53+
$<$<CONFIG:MinSizeRel>:-Os -DNDEBUG>
54+
)
55+
56+
# This is needed for clock_gettime on Linux without compiler extensions
57+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
58+
add_compile_definitions(_POSIX_C_SOURCE=200809L)
59+
endif()
60+
61+
# Enable position-independent code for shared library compatibility
62+
set_property(TARGET dnlp_diff PROPERTY POSITION_INDEPENDENT_CODE ON)
63+
64+
# =============================================================================
65+
# Python bindings (built when using scikit-build-core)
66+
# =============================================================================
67+
if(SKBUILD)
68+
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module NumPy)
69+
70+
# Create Python extension module
71+
Python3_add_library(_core MODULE python/bindings.c)
72+
target_include_directories(_core PRIVATE
73+
${PROJECT_SOURCE_DIR}/include
74+
${PROJECT_SOURCE_DIR}/python
75+
${Python3_NumPy_INCLUDE_DIRS}
76+
)
77+
target_link_libraries(_core PRIVATE dnlp_diff)
78+
79+
# Install to the package directory
80+
install(TARGETS _core LIBRARY DESTINATION dnlp_diff_engine)
81+
endif()
82+
83+
# =============================================================================
84+
# C tests (only for standalone builds)
85+
# =============================================================================
86+
if(NOT SKBUILD)
87+
include_directories(${PROJECT_SOURCE_DIR}/tests)
88+
enable_testing()
89+
90+
add_executable(all_tests
91+
tests/all_tests.c
92+
tests/test_helpers.c
93+
)
94+
target_link_libraries(all_tests dnlp_diff)
95+
add_test(NAME AllTests COMMAND all_tests)
96+
endif()

tests/utils/multiply_test.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import numpy as np
2+
import scipy.sparse as sp
3+
4+
# test 1
5+
A = np.array([[1.0, 0.0, 2.0], [0.0, 3.0, 0.0], [4.0, 0.0, 5.0], [0.0, 6.0, 0.0]])
6+
B = np.array([[1.0, 0.0, 4], [0.0, 2.0, 7], [3.0, 0.0, 2], [0.0, 4.0, -1]])
7+
w = np.array([1.0, 2.0, 3.0, 4.0])
8+
H = A.T @ np.diag(w) @ B + B.T @ np.diag(w) @ A
9+
print(H)
10+
H_csr = sp.csr_matrix(H)
11+
print("H in CSR format:")
12+
print("data:", H_csr.data)
13+
print("indices:", H_csr.indices)
14+
print("indptr:", H_csr.indptr)
15+
16+
# test 2
17+
m = 5
18+
n = 10
19+
density = 0.2
20+
A = sp.random(m, n, density=density, format="csr", data_rvs=np.random.randn)
21+
B = sp.random(m, n, density=density, format="csr", data_rvs=np.random.randn)
22+
w = np.random.rand(m)
23+
H = A.T @ sp.diags(w) @ B + B.T @ sp.diags(w) @ A
24+
H = H.tocsr()
25+
print("Random sparse H in CSR format:")
26+
print("data:", H.data)
27+
print("indices:", H.indices)
28+
print("indptr:", H.indptr)
29+
30+
print("A in csr:")
31+
print("data:", A.data)
32+
print("indices:", A.indices)
33+
print("indptr:", A.indptr)
34+
35+
print("B in csr:")
36+
print("data:", B.data)
37+
print("indices:", B.indices)
38+
print("indptr:", B.indptr)
39+
40+
print("w:", w)

tests/utils/python_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import scipy.sparse as sp
2+
import numpy as np
3+
4+
np.random.seed(42)
5+
m = 10
6+
n = 15
7+
# density = 0.1
8+
# A = sp.random(m, n, density=density, format="csc", dtype=float)
9+
10+
Ap = np.array([0, 1, 1, 1, 1, 4, 5, 6, 7, 8, 9, 11, 11, 11, 13, 15])
11+
Ai = np.array([5, 0, 6, 9, 0, 5, 1, 3, 6, 0, 6, 3, 6, 6, 8])
12+
Ax = np.random.randint(1, 10, size=len(Ai))
13+
d = np.random.randint(1, 10, size=m)
14+
A = sp.csc_matrix((Ax, Ai, Ap), shape=(m, n))
15+
16+
17+
C = A.T @ sp.diags(d) @ A
18+
19+
C.sort_indices()
20+
21+
import pdb
22+
23+
pdb.set_trace()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import numpy as np
2+
import scipy.sparse as sp
3+
4+
m = 20
5+
n = 30
6+
density = 0.2
7+
A = sp.random(m, n, density=density, format="csr", dtype=float)
8+
A.data = np.random.randint(1, 10, size=A.nnz)
9+
10+
Ap = A.indptr
11+
Ai = A.indices
12+
Ax = A.data
13+
14+
print("CSR matrix A:")
15+
print("Ap:", Ap)
16+
print("Ai:", Ai)
17+
print("Ax:", Ax)
18+
print("Annz:", A.nnz)
19+
20+
A_csc = A.tocsc()
21+
22+
Cp = A_csc.indptr
23+
Ci = A_csc.indices
24+
Cx = A_csc.data
25+
26+
print("CSC matrix A_csc:")
27+
print("Cp:", Cp)
28+
print("Ci:", Ci)
29+
print("Cx:", Cx)
30+
print("len(Ci):", len(Ci))
31+
print("len(Cp):", len(Cp))

0 commit comments

Comments
 (0)