Skip to content

B0RJA/spar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 

Repository files navigation

spar

spar is a 3D sparse matrix implementation written in C designed for fast memory read/write. Data is divided into blocks that are compressed when uniform. This allows the representation of matrices with large uniform aggregates (not only sparse). Maximum compression ratio using blocks of size (4x4x4) is 32x with approx 50M/25M read/write access per second for any matrix size. The following matrix data types are supported: char, int, long, float, double.

Use

#include "spar.h"

main()
{
	// Declare 3D sparse integer matrix
	sparInt *data;
	// Supported data types: char int long float double

	// Init data size, block size and default value
	data = sparIntInit( 1000, 1000, 1000, 4, 0 );

	// Set element
	sparIntSet( data, 999, 999, 999, 123456 );
	
	// Get element
	printf("data(999,999,999) = %d\n", sparIntGet( data, 999, 999, 999 ));

	// Memory usage
	printf("Memory usage of data() = %.1fMB\n", sparIntMemory( data ) / 1024. / 1024. );

	// Change block size
	sparIntChangeBs( data, 8 );
	
	// Resize
	sparIntResize( data, 2000, 2000, 2000 );

	// Optimize block size
	sparIntOptimizeBs( data );
	
	// Duplicate
	sparInt *data2;
	data2 = sparIntDuplicate( data );

	// Free memory
	sparIntFree( data );
	sparIntFree( data2 );
}

Contribute

The source file build\sparTemplate.h is based on an arbitrary data type. Run the script build\build.pl to obtain the library functions for all data types.

Any problems?

Feel free to write an issue if you have any questions or problems.

Copyright and license

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

About

3D sparse matrix implementation in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published