Skip to content

Commit

Permalink
Merge pull request #52 from ashvardanian/main-dev
Browse files Browse the repository at this point in the history
5x swifter CPython bindings and first NodeJS bindings
  • Loading branch information
ashvardanian authored Oct 10, 2023
2 parents eaa53b6 + 9a575ce commit e5ef92b
Show file tree
Hide file tree
Showing 29 changed files with 3,736 additions and 1,572 deletions.
10 changes: 4 additions & 6 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortIfStatementsOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakTemplateDeclarations: Yes
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakAfterReturnType: None
PenaltyReturnTypeOnItsOwnLine: 200

Expand All @@ -47,7 +45,7 @@ BraceWrapping:
IndentBraces: false


SortIncludes: false
SortIncludes: true
SortUsingDeclarations: true

SpaceAfterCStyleCast: false
Expand Down
26 changes: 22 additions & 4 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --no-cache-dir --upgrade pip
python -m pip install --no-cache-dir --upgrade pip numpy
pip install --no-cache-dir pytest
- name: Build locally
run: python -m pip install .
- name: Test with PyTest
run: pytest scripts/test.py
run: pytest scripts/


test_python_37:
Expand All @@ -61,13 +61,31 @@ jobs:

- name: Install dependencies
run: |
python -m pip install --no-cache-dir --upgrade pip
python -m pip install --no-cache-dir --upgrade pip numpy
pip install --no-cache-dir pytest
- name: Build locally
run: python -m pip install .

- name: Test with PyTest
run: pytest scripts/test.py
run: pytest scripts/

test_javascript:
name: Test JavaScript
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:

- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'

- name: Build locally
run: npm i

- name: Test
run: npm test
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ jobs:
- run: npm test
- uses: JS-DevTools/npm-publish@v2
with:
token: ${{ secrets.NPM_TOKEN }}
token: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ substr_search_cpp
*.so
*.egg-info
*.whl
*.pyd
node_modules/

leipzig1M.txt
8 changes: 8 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
{
"preset": "eslint",
"releaseRules": [
{
"tag": "Break",
"release": "major"
},
{
"tag": "Add",
"release": "minor"
Expand All @@ -35,6 +39,10 @@
{
"preset": "eslint",
"releaseRules": [
{
"tag": "Break",
"release": "major"
},
{
"tag": "Add",
"release": "minor"
Expand Down
35 changes: 34 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,62 @@
"stop_token": "cpp",
"__verbose_abort": "cpp",
"strstream": "cpp",
"filesystem": "cpp"
"filesystem": "cpp",
"stringzilla.h": "c",
"__memory": "c",
"charconv": "c"
},
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cSpell.words": [
"abababab",
"allowoverlap",
"basicsize",
"bigram",
"cibuildwheel",
"endregion",
"endswith",
"getitem",
"getslice",
"initproc",
"intp",
"itemsize",
"keeplinebreaks",
"keepseparator",
"kwargs",
"kwds",
"kwnames",
"levenstein",
"maxsplit",
"memcpy",
"MODINIT",
"napi",
"nargsf",
"ndim",
"newfunc",
"NOARGS",
"NOMINMAX",
"NOTIMPLEMENTED",
"numpy",
"octogram",
"pytest",
"Pythonic",
"quadgram",
"readlines",
"releasebuffer",
"richcompare",
"SIMD",
"splitlines",
"startswith",
"stringzilla",
"Strs",
"strzl",
"substr",
"SWAR",
"TPFLAGS",
"unigram",
"Vardanian",
"vectorcallfunc",
"XDECREF",
"Zilla"
]
}
138 changes: 71 additions & 67 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,105 +1,109 @@
# This CMake file is heavily inspired by following `stringzilla` CMake:
# https://github.com/nlohmann/json/blob/develop/CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
project(stringzilla VERSION 0.1.0 LANGUAGES C CXX)
project(
stringzilla
VERSION 0.1.0
LANGUAGES C CXX)

set (CMAKE_C_STANDARD 11)
set (CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Determine if USearch is built as a subproject (using `add_subdirectory`) or if it is the main project
# Determine if USearch is built as a subproject (using `add_subdirectory`) or if
# it is the main project
set(STRINGZILLA_IS_MAIN_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(STRINGZILLA_IS_MAIN_PROJECT ON)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(STRINGZILLA_IS_MAIN_PROJECT ON)
endif()

# Options
option(STRINGZILLA_INSTALL "Install CMake targets" OFF)
option(STRINGZILLA_BUILD_TEST "Compile a native unit test in C++" ${STRINGZILLA_IS_MAIN_PROJECT})
option(STRINGZILLA_BUILD_BENCHMARK "Compile a native benchmark in C++" ${STRINGZILLA_IS_MAIN_PROJECT})
option(STRINGZILLA_BUILD_TEST "Compile a native unit test in C++"
${STRINGZILLA_IS_MAIN_PROJECT})
option(STRINGZILLA_BUILD_BENCHMARK "Compile a native benchmark in C++"
${STRINGZILLA_IS_MAIN_PROJECT})
option(STRINGZILLA_BUILD_WOLFRAM "Compile Wolfram Language bindings" OFF)

# Includes
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
include(ExternalProject)

# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory
if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif ()
# Allow CMake 3.13+ to override options when using FetchContent /
# add_subdirectory
if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()

# Configuration
include(GNUInstallDirs)
set(STRINGZILLA_TARGET_NAME ${PROJECT_NAME})
set(STRINGZILLA_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
set(STRINGZILLA_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(STRINGZILLA_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(STRINGZILLA_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
set(STRINGZILLA_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(STRINGZILLA_CMAKE_VERSION_CONFIG_FILE "${STRINGZILLA_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(STRINGZILLA_CMAKE_PROJECT_CONFIG_FILE "${STRINGZILLA_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
set(STRINGZILLA_CMAKE_PROJECT_TARGETS_FILE "${STRINGZILLA_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
set(STRINGZILLA_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/pkgconfig")

set(STRINGZILLA_TARGET_NAME ${PROJECT_NAME})
set(STRINGZILLA_CONFIG_INSTALL_DIR
"${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}"
CACHE INTERNAL "")
set(STRINGZILLA_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(STRINGZILLA_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(STRINGZILLA_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
set(STRINGZILLA_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(STRINGZILLA_CMAKE_VERSION_CONFIG_FILE
"${STRINGZILLA_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(STRINGZILLA_CMAKE_PROJECT_CONFIG_FILE
"${STRINGZILLA_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
set(STRINGZILLA_CMAKE_PROJECT_TARGETS_FILE
"${STRINGZILLA_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
set(STRINGZILLA_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/pkgconfig")

# Define our header-only library
add_library(${STRINGZILLA_TARGET_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${STRINGZILLA_TARGET_NAME} ALIAS ${STRINGZILLA_TARGET_NAME})
add_library(${PROJECT_NAME}::${STRINGZILLA_TARGET_NAME} ALIAS
${STRINGZILLA_TARGET_NAME})
set(STRINGZILLA_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")

target_compile_definitions(
${STRINGZILLA_TARGET_NAME}
INTERFACE
$<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:STRINGZILLA_USE_OPENMP=0>
)
${STRINGZILLA_TARGET_NAME}
INTERFACE $<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:STRINGZILLA_USE_OPENMP=0>)
target_include_directories(
${STRINGZILLA_TARGET_NAME}
${STRINGZILLA_SYSTEM_INCLUDE} INTERFACE
$<BUILD_INTERFACE:${STRINGZILLA_INCLUDE_BUILD_DIR}>
$<INSTALL_INTERFACE:include>
)
${STRINGZILLA_TARGET_NAME} ${STRINGZILLA_SYSTEM_INCLUDE}
INTERFACE $<BUILD_INTERFACE:${STRINGZILLA_INCLUDE_BUILD_DIR}>
$<INSTALL_INTERFACE:include>)

if(STRINGZILLA_INSTALL)
install(
DIRECTORY ${STRINGZILLA_INCLUDE_BUILD_DIR}
DESTINATION ${STRINGZILLA_INCLUDE_INSTALL_DIR}
)
install(
FILES ${STRINGZILLA_CMAKE_PROJECT_CONFIG_FILE} ${STRINGZILLA_CMAKE_VERSION_CONFIG_FILE}
DESTINATION ${STRINGZILLA_CONFIG_INSTALL_DIR}
)
export(
TARGETS ${STRINGZILLA_TARGET_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE ${STRINGZILLA_CMAKE_PROJECT_TARGETS_FILE}
)
install(
TARGETS ${STRINGZILLA_TARGET_NAME}
EXPORT ${STRINGZILLA_TARGETS_EXPORT_NAME}
INCLUDES DESTINATION ${STRINGZILLA_INCLUDE_INSTALL_DIR}
)
install(
EXPORT ${STRINGZILLA_TARGETS_EXPORT_NAME}
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${STRINGZILLA_CONFIG_INSTALL_DIR}
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION ${STRINGZILLA_PKGCONFIG_INSTALL_DIR}
)
install(DIRECTORY ${STRINGZILLA_INCLUDE_BUILD_DIR}
DESTINATION ${STRINGZILLA_INCLUDE_INSTALL_DIR})
install(FILES ${STRINGZILLA_CMAKE_PROJECT_CONFIG_FILE}
${STRINGZILLA_CMAKE_VERSION_CONFIG_FILE}
DESTINATION ${STRINGZILLA_CONFIG_INSTALL_DIR})
export(
TARGETS ${STRINGZILLA_TARGET_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE ${STRINGZILLA_CMAKE_PROJECT_TARGETS_FILE})
install(
TARGETS ${STRINGZILLA_TARGET_NAME}
EXPORT ${STRINGZILLA_TARGETS_EXPORT_NAME}
INCLUDES
DESTINATION ${STRINGZILLA_INCLUDE_INSTALL_DIR})
install(
EXPORT ${STRINGZILLA_TARGETS_EXPORT_NAME}
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${STRINGZILLA_CONFIG_INSTALL_DIR})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION ${STRINGZILLA_PKGCONFIG_INSTALL_DIR})
endif()

if(${STRINGZILLA_BUILD_TEST} OR ${STRINGZILLA_BUILD_BENCHMARK})
add_executable(stringzilla_test scripts/test.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -O3 -flto -march=native -finline-functions -funroll-loops"
)

target_include_directories(stringzilla_test PRIVATE stringzilla)
set_target_properties(stringzilla_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set_target_properties(stringzilla_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR})

if(${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER 3.13)
include(CTest)
enable_testing()
add_test(NAME stringzilla_test COMMAND stringzilla_test)
if(${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER
3.13)
include(CTest)
enable_testing()
add_test(NAME stringzilla_test COMMAND stringzilla_test)
endif()
endif()

Loading

0 comments on commit e5ef92b

Please sign in to comment.