Skip to main content

B-spline library with C++ backend

Project description

bspmap - 高性能 B-Spline 映射库

bspmap 是一个利用 C++ 后端加速的 B-Spline 计算库,通过 Python 的 ctypes 库提供易用的接口。适用于需要高效执行 B-Spline 插值、映射和基函数计算的场景。

主要特性 (Features)

  • 高性能: 核心计算逻辑(如 Cox-de Boor 递归、基函数求导)由 C++ 实现,显著快于纯 Python 实现。
  • 多维支持: 支持任意维度的输入和输出空间映射。
  • 灵活的 Python 接口: 基于 ctypes 封装,提供直观的面向对象 API (BSP, Basis)。
  • 跨平台: 支持 Windows, Linux 和 macOS (需编译对应的动态库)。
  • 张量积结构: 自动处理多维基函数的张量积组合。

项目结构 (Structure)

bspmap/
├── src/
│   ├── cpp/                # C++ 核心源码
│   │   ├── include/        # 头文件 (.h)
│   │   └── src/            # 源文件 (.cpp)
│   └── python/             # Python 包源码
│       └── bspmap/
│           ├── __init__.py
│           ├── bsp.py      # B-Spline 映射类
│           ├── basis.py    # 基函数定义
│           └── capi.py     # Ctypes 绑定层
├── tests/                  # 测试用例
├── docs/                   # 文档
└── CMakeLists.txt          # CMake 构建配置

快速开始 (Quick Start)

1. 安装 (Installation)

由于本项目包含 C++ 扩展,建议通过源码编译安装。

详细步骤请参考 安装指南

简述:

# 1. 编译 C++ 后端
mkdir build
cd build
cmake ..
cmake --build . --config Release

# 2. 将编译好的 bspmap.dll (或 libbspmap.so) 放入 src/python/bspmap/bin/

# 3. 安装 Python 包
cd ..
pip install -e .

2. 基本使用 (Usage)

创建一个简单的 2D -> 1D B-Spline 映射:

import numpy as np
from bspmap import BSP, Basis

# 1. 定义每个维度的基函数 (Basis)
#    参数: 控制点数量 (num_cps), 阶数 (degree)
basis_x = Basis(num_cps=5, degree=2)
basis_y = Basis(num_cps=5, degree=2)

# 2. 准备控制点 (Control Points)
#    输入维度为2,每个维度大小为5,所以总共有 5x5=25 个控制点
#    输出维度假设为1
size = [5, 5]
# 随机生成控制点数据,形状 (25, 1) 或者展平
control_points = np.random.rand(25, 1)

# 3. 初始化 BSP 对象
bsp = BSP(
    basis=[basis_x, basis_y],
    size=size,
    control_points=control_points
)

# 4. 执行映射
#    输入数据 x 形状: (N, input_dim) -> (10, 2)
input_data = np.random.rand(10, 2)
output_data = bsp.map(input_data)

print("Input shape:", input_data.shape)
print("Output shape:", output_data.shape)

文档 (Documentation)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bspmap-1.0.2.tar.gz (611.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bspmap-1.0.2-py3-none-any.whl (602.8 kB view details)

Uploaded Python 3

File details

Details for the file bspmap-1.0.2.tar.gz.

File metadata

  • Download URL: bspmap-1.0.2.tar.gz
  • Upload date:
  • Size: 611.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for bspmap-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1919c3eaafd7de38daf4cd3ca6a32846c3f1a03d8c590dca57e4fc8942b756c7
MD5 2a4315aed4535d1d3558fe78f7123794
BLAKE2b-256 03810b20a8291ecd165d6a83181499e55430a3b585dfe210d3f5ce710151ebd9

See more details on using hashes here.

File details

Details for the file bspmap-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: bspmap-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 602.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for bspmap-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 40e715c988ace51d1371e121b391fcb84246beb38d8f63bdaef3cc49e2d8bc22
MD5 fa01bb6f7a35bc458d0ca71b139b34bf
BLAKE2b-256 7fc048d92c4d60ef39298c96949aba6f2131f8053fda2a93fb6b88da8e9c1982

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page