| Crates.io | kunquant_rs |
| lib.rs | kunquant_rs |
| version | 0.3.0 |
| created_at | 2025-08-15 14:29:23.068647+00 |
| updated_at | 2025-08-22 04:43:44.908525+00 |
| description | Rust bindings for KunQuant financial factor computation library |
| homepage | |
| repository | https://github.com/ZhaorongDai/KunQuant_rust_api |
| max_upload_size | |
| id | 1796885 |
| size | 124,162 |
Rust bindings for the KunQuant financial factor computation library.
KunQuant-rs provides safe Rust bindings for KunQuant, a high-performance financial factor computation library. This crate wraps the C API with safe Rust abstractions while maintaining the performance characteristics of the underlying library.
This project depends on the KunRuntime library. Follow these steps to ensure proper linking:
libKunRuntime.soCompile with explicit library path:
cargo rustc -- -L /path/to/KunQuant/runner
Replace /path/to/KunQuant/runner with the actual path to libKunRuntime.so.
Permanent configuration via RUSTFLAGS:
export RUSTFLAGS="-L /path/to/KunQuant/runner"
cargo build
Runtime configuration:
Ensure the library is available at runtime by setting LD_LIBRARY_PATH:
export LD_LIBRARY_PATH=/path/to/KunQuant/runner:$LD_LIBRARY_PATH
use kunquant_rs::{Executor, Library, BufferNameMap, BatchParams, run_graph};
// Create executor and load library
let executor = Executor::single_thread()?;
let library = Library::load("test_libs/simple_test_lib.so")?;
let module = library.get_module("simple_test")?;
// Prepare data
let mut input_data = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0];
let mut output_data = vec![0.0; 8];
// Set up buffers
let mut buffers = BufferNameMap::new()?;
buffers.set_buffer_slice("input", &mut input_data)?;
buffers.set_buffer_slice("output", &mut output_data)?;
// Run computation
let params = BatchParams::full_range(8, 1)?;
run_graph(&executor, &module, &buffers, ¶ms)?;
// Results are now in output_data
println!("Results: {:?}", output_data);
Executor: Manages computation execution (single-thread or multi-thread)Library: Represents a loaded factor libraryModule: A specific factor module within a libraryBufferNameMap: Maps buffer names to data slicesBatchParams: Parameters for batch computationStreamContext: Context for streaming computationrun_graph(): Execute a factor computation graphExecutor::single_thread(): Create single-thread executorExecutor::multi_thread(n): Create multi-thread executor with n threadsLibrary::load(path): Load a factor library from fileRun tests with the provided script that sets up the correct library path:
./run_tests.sh
The library follows a layered architecture:
ffi.rs): Raw C bindingserror.rs): Rust error typesexecutor.rs, library.rs): Safe wrappersbuffer.rs): Memory-safe buffer handlingbatch.rs, stream.rs): High-level computation interfacesoutput_layout="STREAM"./run_tests.shMIT License - see LICENSE file for details.