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.0.tar.gz (34.1 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.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bspmap-1.0.0.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":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.0.tar.gz
Algorithm Hash digest
SHA256 6f73751c3fe10ed9543f87ff02678bb4e7ea882cff715a90b7fc859851144768
MD5 daa2939658340ca7703a6e2ca3959338
BLAKE2b-256 a8812e32b852d3ae02bd80816f9f935a80db371e9551f230d8ea63bdce7afed0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bspmap-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 109a1226e31a64748090b5412acb6f01d784e3abcccf02efb7db49a3e3d722c8
MD5 13301c323541658c37ecccd3f63a79b7
BLAKE2b-256 752179f310ac47266f7130a9ed2d8a74543035f4c298e49064cd189b72b1335d

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