@@ -55,7 +55,8 @@ mkoctfile --version
55
55
56
56
3 . Test the installation:
57
57
``` matlab
58
- test_bsp_hello()
58
+ test_binsparse_read()
59
+ test_binsparse_write()
59
60
```
60
61
61
62
#### Option 2: Octave (from within Octave)
@@ -72,7 +73,8 @@ mkoctfile --version
72
73
73
74
3 . Test the installation:
74
75
``` octave
75
- test_bsp_hello_octave()
76
+ test_binsparse_read()
77
+ test_binsparse_write()
76
78
```
77
79
78
80
#### Option 3: Octave (from command line)
@@ -89,23 +91,56 @@ mkoctfile --version
89
91
90
92
3 . Test the installation:
91
93
``` bash
92
- octave --eval " test_bsp_hello_octave()"
94
+ octave --eval " test_binsparse_read()"
95
+ octave --eval " test_binsparse_write()"
93
96
```
94
97
95
98
## Usage Examples
96
99
97
- ### Basic Usage
100
+ ### Reading Binsparse Files
98
101
99
102
** In MATLAB or Octave:**
100
103
101
104
``` matlab
102
- % Simple greeting
103
- result = bsp_hello()
104
- % Output: 'Binsparse MEX binding is working!'
105
+ % Read a Binsparse matrix file
106
+ matrix = binsparse_read('path/to/matrix.bsp.h5');
107
+
108
+ % Read from a specific group
109
+ matrix = binsparse_read('path/to/matrix.bsp.h5', 'group_name');
110
+
111
+ % Matrix will be a struct with fields:
112
+ % - values: array of matrix values
113
+ % - indices_0, indices_1: row/column indices
114
+ % - pointers_to_1: pointer array (for CSR/CSC formats)
115
+ % - nrows, ncols, nnz: matrix dimensions
116
+ % - is_iso: boolean for iso-value matrices
117
+ % - format: string ('COO', 'CSR', 'CSC', etc.)
118
+ % - structure: string ('general', 'symmetric', etc.)
119
+ ```
120
+
121
+ ### Writing Binsparse Files
105
122
106
- % Get Binsparse version
107
- [version, success] = bsp_hello('version')
108
- % Output: version = '0.1', success = true
123
+ ``` matlab
124
+ % Create a matrix struct (example: 3x3 COO matrix)
125
+ matrix = struct();
126
+ matrix.values = [1.0; 2.0; 3.0];
127
+ matrix.indices_0 = uint64([0; 1; 2]); % 0-based row indices
128
+ matrix.indices_1 = uint64([0; 1; 2]); % 0-based col indices
129
+ matrix.pointers_to_1 = uint64([]); % Empty for COO
130
+ matrix.nrows = 3;
131
+ matrix.ncols = 3;
132
+ matrix.nnz = 3;
133
+ matrix.is_iso = false;
134
+ matrix.format = 'COO';
135
+ matrix.structure = 'general';
136
+
137
+ % Write to file
138
+ binsparse_write('output.bsp.h5', matrix);
139
+
140
+ % Write with optional parameters
141
+ binsparse_write('output.bsp.h5', matrix, 'my_group');
142
+ binsparse_write('output.bsp.h5', matrix, 'my_group', '{"author": "me"}');
143
+ binsparse_write('output.bsp.h5', matrix, 'my_group', '{"author": "me"}', 6);
109
144
```
110
145
111
146
### Error Handling
@@ -114,7 +149,7 @@ The MEX functions include proper error handling:
114
149
115
150
``` matlab
116
151
try
117
- result = bsp_hello('invalid_mode ')
152
+ matrix = binsparse_read('nonexistent_file.bsp.h5 ')
118
153
catch ME
119
154
fprintf('Error: %s\n', ME.message)
120
155
end
@@ -124,25 +159,32 @@ end
124
159
125
160
| File | Description |
126
161
| ------| -------------|
127
- | ` bsp_hello.c ` | Simple MEX function demonstrating Binsparse integration |
162
+ | ` binsparse_read.c ` | MEX function for reading Binsparse matrix files |
163
+ | ` binsparse_write.c ` | MEX function for writing Binsparse matrix files |
128
164
| ` build_matlab_bindings.m ` | Main build script for MATLAB MEX functions |
129
165
| ` build_octave_bindings.m ` | Main build script for Octave MEX functions |
130
- | ` compile_bsp_hello.m ` | Simple compilation script for the demo function (MATLAB) |
166
+ | ` compile_binsparse_read.m ` | Simple compilation script for read function (MATLAB) |
167
+ | ` compile_binsparse_write.m ` | Simple compilation script for write function (MATLAB) |
168
+ | ` compile_binsparse_read_octave.m ` | Simple compilation script for read function (Octave) |
169
+ | ` compile_binsparse_write_octave.m ` | Simple compilation script for write function (Octave) |
131
170
| ` compile_octave.sh ` | Shell script for building Octave MEX functions |
132
- | ` test_bsp_hello.m ` | Test script to verify functionality (MATLAB) |
133
- | ` test_bsp_hello_octave.m ` | Test script to verify functionality (Octave) |
171
+ | ` test_binsparse_read.m ` | Test script for read functionality |
172
+ | ` test_binsparse_write.m ` | Test script for write functionality |
173
+ | ` bsp_matrix_create.m ` | Utility function for creating matrix structs |
174
+ | ` bsp_matrix_info.m ` | Utility function for displaying matrix information |
134
175
| ` README.md ` | This documentation file |
135
176
136
177
## Technical Details
137
178
138
179
### MEX Function Structure
139
180
140
- The ` bsp_hello ` MEX function demonstrates :
181
+ The Binsparse MEX functions demonstrate :
141
182
142
183
1 . ** Header inclusion** : Proper inclusion of ` <binsparse/binsparse.h> `
143
- 2 . ** Error handling** : Using Binsparse error types (` bsp_error_t ` )
144
- 3 . ** Memory management** : Safe allocation and cleanup
145
- 4 . ** MATLAB interface** : Proper MEX function structure
184
+ 2 . ** Type conversion** : Complete mapping between MATLAB and Binsparse types
185
+ 3 . ** Error handling** : Using Binsparse error types (` bsp_error_t ` )
186
+ 4 . ** Memory management** : Safe allocation and cleanup
187
+ 5 . ** MATLAB interface** : Proper MEX function structure with validation
146
188
147
189
### Build Process
148
190
@@ -222,14 +264,17 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
222
264
223
265
## Development Status
224
266
225
- This is a minimal demonstration of MATLAB/Octave bindings for Binsparse. Currently implemented:
267
+ This provides complete MATLAB/Octave bindings for Binsparse. Currently implemented:
226
268
227
- - ✅ Basic MEX function structure
228
- - ✅ Binsparse header inclusion
229
- - ✅ Error handling with Binsparse error types
269
+ - ✅ Matrix reading (`binsparse_read`)
270
+ - ✅ Matrix writing (`binsparse_write`)
271
+ - ✅ Complete type support (all Binsparse types including complex numbers)
272
+ - ✅ Optional parameters (groups, JSON metadata, compression)
273
+ - ✅ Comprehensive error handling
230
274
- ✅ Build system and testing framework
231
- - ⏳ Matrix reading/writing functions (future work)
232
- - ⏳ Advanced Binsparse features (future work)
275
+ - ✅ Round-trip compatibility (read → write → read)
276
+ - ⏳ Tensor support (future work)
277
+ - ⏳ Advanced sparse matrix operations (future work)
233
278
234
279
## License
235
280
0 commit comments