SicLib
A Scientific Computing Library
SicLib is an experimental C++ library for numerical methods, linear algebra, statistics, and simple machine learning models. pysiclib exposes the library to Python.
Navigation
Use the sidebar to browse the modules.
Source Code and Installation
The source code and installation instructions are on GitHub.
Project Scope and Purpose
I built SicLib to learn how scientific computing systems work below the Python API. It gives me a place to implement algorithms as I study them and to examine the tradeoffs behind tensor storage, numerical methods, and language bindings. It is a research project, not a production replacement for established libraries.
Implementation Notes
The tensor is the library's main data structure. Tensors use shared buffers and strided views, which make operations such as transpose inexpensive. The current implementation favors generality and clear composition over performance. For production tensor work, use an established library such as PyTorch.
Operations are composed from pure functions and views where possible. That design leaves room to identify independent work and parallelize it on a CPU or GPU later.
I have also explored SYCL as a possible GPU backend because it supports a wider range of hardware than CUDA, including integrated GPUs. That work remains experimental.
Neural Network Module Example
The PySicLib neural network demo compares the library's output with an equivalent NumPy implementation.
Example Functionality
>>> import pysiclib >>> my_matrix = [[[0, 1, 2],[ 3, 4, 5]], ... [[6, 7, 8],[ 9, 10, 11]]] >>> # Tensors can be constructed by arbitrary python arrays >>> my_tensor = pysiclib.linalg.Tensor(my_matrix) >>> print(my_tensor) Tensor: [[[0, 1, 2] [3, 4, 5]] [[6, 7, 8] [9, 10, 11]]] Tensor Shape: [2, 2, 3] >>> # Note Tensors are views so we can do things like >>> # transpose in constant time >>> # Below we will print the address in memory to show this >>> transposed_my_tensor = my_tensor.transpose() >>> print(transposed_my_tensor) Tensor: [[[0, 6] [3, 9]] [[1, 7] [4, 10]] [[2, 8] [5, 11]]] Tensor Shape: [3, 2, 2] >>> print(hex(id(my_tensor.get_buffer())) 0x7fcfe02891c0 >>> print(hex(id(transposed_my_tensor.get_buffer())) 0x7fcfe02891c0 >>> # Example of extensibility for generalized statistics >>> # as mean is a convenience function over the >>> # Moment Generating Function. >>> t_col_means = pysiclib.stats.find_mean( ... transposed_my_tensor, 1) >>> print(t_col_means) Tensor: [[[1.5, 2.5, 3.5]] [[7.5, 8.5, 9.5]]] Tensor Shape: [2, 1, 3]