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.3.tar.gz
(46.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
bspmap-1.0.3-py3-none-any.whl
(34.6 kB
view details)
File details
Details for the file bspmap-1.0.3.tar.gz.
File metadata
- Download URL: bspmap-1.0.3.tar.gz
- Upload date:
- Size: 46.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2177b08301741643e5b83044a3526de8431f37b258319693e6fe702fb5fc218c
|
|
| MD5 |
7e27212f2ae0f877e19f99980113a891
|
|
| BLAKE2b-256 |
52f762080a17159b22c9cd4be79cab1e7a1586d068727f74290ad9e9f469a041
|
File details
Details for the file bspmap-1.0.3-py3-none-any.whl.
File metadata
- Download URL: bspmap-1.0.3-py3-none-any.whl
- Upload date:
- Size: 34.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b92351fd2019291ba614a96784b1512c6a79d98499fa2a598a83046f201a21f
|
|
| MD5 |
baf17ad4da668c11a217b5160c6dd158
|
|
| BLAKE2b-256 |
c67e49d5adbc772635426337073a80c8d6575f6c8efdaf0029806b8efff7f83d
|