Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
761c7e3
Replace `assert` with `bsp_error_t` for `bsp_array_t`.
BenBrock Aug 18, 2025
d1801b9
Add error handling to `bsp_matrix_t` functions.
BenBrock Aug 18, 2025
8405a28
Update `bsp_matrix_t` to have proper error handling, update parsing
BenBrock Aug 18, 2025
13a5471
Add option to use a specific allocator.
BenBrock Aug 19, 2025
b37c626
Add error handling for Binsparse matrix IO functions.
BenBrock Aug 19, 2025
355caa3
Add sanitizers build option, fix a few memory leaks.
BenBrock Aug 19, 2025
61f288f
Separate functions that depend on `cJSON` or `hdf5` into separate hea…
BenBrock Aug 20, 2025
4c406fa
Move hdf5 types into another file.
BenBrock Aug 20, 2025
23ac92d
Fix HDF5 inclusion.
BenBrock Aug 20, 2025
35bc5cb
Some Matlab files
BenBrock Aug 20, 2025
70426d4
Prevent `clang-format` from messing with Matlab files.
BenBrock Aug 20, 2025
a0898df
Update Matlab bindings, fine-tune `.gitignore`.
BenBrock Aug 20, 2025
7e18e4d
Add support for all types to Matlab.
BenBrock Aug 20, 2025
92194cd
Implement `binsparse_write` bindings.
BenBrock Aug 20, 2025
0f54f97
Update Matlab bindings to use zero-copy transfer.
BenBrock Sep 10, 2025
77c1015
matlab bindings, in progress
DrTimothyAldenDavis Sep 30, 2025
666b2d3
add empty build folder so Makefile can do "cd build ; cmake .."
DrTimothyAldenDavis Sep 30, 2025
3b279cb
Remove system call with `sprintf` to avoid compiler warning.
BenBrock Sep 29, 2025
e8ccc3f
Begin implementation to convert SSMC Matlab Problem struct to Binspar.
BenBrock Sep 30, 2025
7164564
Indentation updates
BenBrock Sep 30, 2025
ad5cf06
Make sure to use `allocator.free` to deallocate when reading matrix.
BenBrock Oct 3, 2025
2e84149
fix null pointer dereference (tests still fail however)
DrTimothyAldenDavis Oct 6, 2025
e763386
Add support for conversion to CSC
BenBrock Oct 29, 2025
eed9f79
tracking down a segfault
DrTimothyAldenDavis Nov 12, 2025
6877480
fix the segfault, tag other FIXMEs
DrTimothyAldenDavis Dec 9, 2025
7493bd6
Merge, fix formatting
BenBrock Nov 13, 2025
6471808
Add roundtrip test for `binsparse_read` and `binsparse_write`.
BenBrock Jan 7, 2026
37203f6
Update binsparse_read and binsparse_write roundtrip test with optional
BenBrock Jan 25, 2026
4b4d3f0
Begin implementing `generate_bsp_from_ssmc`, add support for
BenBrock Jan 25, 2026
e9fcce3
Some debugging/cleanup
BenBrock Jan 25, 2026
8ffd1a2
Update
BenBrock Jan 25, 2026
e4568b4
Update licensing
BenBrock Jan 25, 2026
ac121f3
Update
BenBrock Jan 25, 2026
a3494f1
Add some memory safety
BenBrock Jan 26, 2026
170fc8e
Remove accidentally added build files.
BenBrock Jan 26, 2026
b3ddc33
Harden parser and HDF5 error handling
BenBrock Jul 15, 2026
78355d5
Improve Matlab binding conversion stability
BenBrock Jul 15, 2026
1be8c95
Implement SuiteSparse Matlab writer entry point
BenBrock Jul 15, 2026
a963712
Add Matlab UTF-8 string dataset writer
BenBrock Jul 15, 2026
f68769f
Store SSMC text and metadata in BSP output
BenBrock Jul 15, 2026
d19d641
Test SSMC BSP text metadata output
BenBrock Jul 15, 2026
d0d7557
Preserve char row text in BSP output
BenBrock Jul 15, 2026
171bf85
Updates to please the linter.
BenBrock Jul 15, 2026
69c5359
Write MATLAB dense matrices as DMATC
BenBrock Jul 15, 2026
79e7943
Add Binsparse Problem struct conversion
BenBrock Jul 15, 2026
ba995b5
Clean up MATLAB bindings dead code and docs
BenBrock Jul 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

scripts
venv
build*
build/
build-*/
compile_flags.txt
._*
tensor_test_files

# MATLAB/Octave MEX files
*.mex
*.mexa64
*.mexw32
*.mexw64
*.mexmaci64
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repos:
rev: v16.0.6
hooks:
- id: clang-format
exclude: '\.m$'

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand Down
48 changes: 46 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ cmake_policy(SET CMP0079 NEW)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_FLAGS "-O3 -march=native")

# FIXME: -march=native is not portable
# set(CMAKE_C_FLAGS "-O3 -march=native")
set(CMAKE_C_FLAGS "-g ")
set(CMAKE_CXX_FLAGS "-g ")

option(ENABLE_SANITIZERS "Enable Clang sanitizers" OFF)

include(GNUInstallDirs)

add_library(binsparse STATIC)
add_library(binsparse_dynamic SHARED)

add_subdirectory(include)
add_subdirectory(src)
Expand All @@ -24,8 +31,15 @@ add_subdirectory(src)

find_package(HDF5 REQUIRED COMPONENTS C)
target_link_libraries(binsparse PUBLIC ${HDF5_C_LIBRARIES})
target_link_libraries(binsparse_dynamic PUBLIC ${HDF5_C_LIBRARIES})

include(FetchContent)

# Force cJSON to build as static library for MEX compatibility
set(BUILD_SHARED_LIBS_BACKUP ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Build cJSON as static library")
set(ENABLE_CJSON_TEST OFF CACHE INTERNAL "Disable cJSON tests")

FetchContent_Declare(
cJSON
# GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git
Expand All @@ -34,8 +48,12 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(cJSON)

# Restore original BUILD_SHARED_LIBS setting
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_BACKUP})

configure_file(${cJSON_SOURCE_DIR}/cJSON.h ${CMAKE_BINARY_DIR}/include/cJSON/cJSON.h)
target_link_libraries(${PROJECT_NAME} PUBLIC cjson)
target_link_libraries(binsparse PRIVATE cjson)
target_link_libraries(binsparse_dynamic PRIVATE cjson)

# Set up include directories properly for both build and install
target_include_directories(${PROJECT_NAME}
Expand All @@ -46,13 +64,27 @@ target_include_directories(${PROJECT_NAME}
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${HDF5_INCLUDE_DIRS})

target_include_directories(binsparse_dynamic
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${HDF5_INCLUDE_DIRS})

# Installation rules - these are always needed when the library is built
install(TARGETS binsparse
EXPORT binsparse-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS binsparse_dynamic
EXPORT binsparse-targets_dynamic
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# Install headers
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/binsparse
Expand All @@ -65,6 +97,10 @@ install(EXPORT binsparse-targets
FILE binsparse-targets.cmake
NAMESPACE binsparse::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/binsparse)
install(EXPORT binsparse-targets_dynamic
FILE binsparse-targets_dynamic.cmake
NAMESPACE binsparse::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/binsparse)

# Create and install package config files
include(CMakePackageConfigHelpers)
Expand All @@ -84,6 +120,14 @@ install(FILES
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/binsparse)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
if (ENABLE_SANITIZERS)
set(SANITIZER_FLAGS "-fsanitize=address,undefined")
target_compile_options(binsparse INTERFACE ${SANITIZER_FLAGS} -g -O1 -fno-omit-frame-pointer)
target_link_options(binsparse INTERFACE ${SANITIZER_FLAGS})
target_compile_options(binsparse_dynamic INTERFACE ${SANITIZER_FLAGS} -g -O1 -fno-omit-frame-pointer)
target_link_options(binsparse_dynamic INTERFACE ${SANITIZER_FLAGS})
endif()

add_subdirectory(examples)
add_subdirectory(test)
endif()
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ This library provides a C interface for reading and writing binsparse matrices.
#include <binsparse/binsparse.h>

int main(int argc, char** argv) {
bsp_matrix_t mat = bsp_read_matrix("chesapeake.bsp.hdf5");
bsp_matrix_t mat;
bsp_read_matrix(&mat, "chesapeake.bsp.hdf5", NULL);

if (mat.format == BSP_COO) {
float* values = mat.values.data;
Expand All @@ -33,6 +34,7 @@ int main(int argc, char** argv) {
bsp_get_matrix_format_string(mat.format));
}

bsp_destroy_matrix_t(&mat);
return 0;
}
```
Expand Down
35 changes: 35 additions & 0 deletions bindings/matlab/Contents.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
% Binsparse MATLAB/Octave bindings
%
% Core functions (MEX, with .m help stubs):
% binsparse_read - read a matrix from a Binsparse HDF5 file
% binsparse_write - write a matrix to a Binsparse HDF5 file
% binsparse_from_ssmc - convert SSMC A+Zeros to a Binsparse matrix struct
% binsparse_minimize_types - minimize value/index types in a Binsparse struct
% binsparse_write_string_dataset - write an HDF5 UTF-8 string dataset
% write_binsparse_from_matlab - write an SSMC Problem struct (delegates to generate_bsp_from_ssmc)
%
% MATLAB helpers:
% generate_bsp_from_ssmc - write an SSMC Problem to a Binsparse file
% convert_to_problem_struct - convert a Binsparse problem to an SSMC Problem
% bsp_matrix_create - create a Binsparse matrix struct
% bsp_matrix_info - display information about a Binsparse matrix struct
%
% Build scripts:
% build_matlab_bindings - build all MEX functions with MATLAB's mex
% build_octave_bindings - build all MEX functions with Octave's mkoctfile
% compile_octave.sh - build the Octave MEX functions from the shell
%
% Tests:
% test_binsparse_read - error-handling tests for binsparse_read
% test_binsparse_write - write and round-trip tests for binsparse_write
% test_binsparse_from_ssmc - basic test for binsparse_from_ssmc
% test_binsparse_minimize_roundtrip - SSMC conversion + type minimization test
% test_bsp_matrix_struct - tests for the Binsparse matrix struct helpers
% test_convert_to_problem_struct - tests for Binsparse Problem conversion
% test_generate_bsp_from_ssmc - end-to-end test for generate_bsp_from_ssmc
% test_write_binsparse_from_matlab - end-to-end test for the SSMC writer MEX
% test_binsparse_roundtrip_dir - round-trip every .h5 file in a directory

% SPDX-FileCopyrightText: 2024 Binsparse Developers
%
% SPDX-License-Identifier: BSD-3-Clause
Loading
Loading