bottle

The fundamental shard for scientific computing with Crystal.

bottle

Build Status Join the chat at https://gitter.im/crystal-data/bottle

Bottle is the core shard needed for scientific computing with Crystal

It provides:

  • An n-dimensional Tensor data structure
  • sophisticated reduction and accumulation routines
  • data structures that can easily be passed to C libraries
  • powerful linear algebra routines backed by LAPACK and BLAS

Prerequisites

Bottle relies on OpenBLAS and LAPACK for many underlying computations, and the development packages must be present for Bottle to work correctly.

For Debian, use libopenblas-dev and liblapack-dev. For other operating systems review the relevant installation instructions for that OS.

Usage

Bottle provides data structures that facilitate element-wise operations, accumulations, and reductions. While some operations are backed by BLAS and LaPACK, many vectorized operations use iteration written in Crystal. The primary goal of this library was to provide a NumPy like interface in Crystal, and performance will be revisited constantly as the library is improved.

Include Bottle to add Tensor to the top level namespace, as well as provide access to B, Bottle's public API, which provides many powerful numerical methods.

include Bottle
t = Tensor.new([2, 2, 3]) { |i| i }
Tensor([[[ 0,  1],
         [ 2,  3]],

        [[ 4,  5],
         [ 6,  7]],

        [[ 8,  9],
         [10, 11]]])
t + t
Tensor([[[ 0,  2],
         [ 4,  6]],

        [[ 8, 10],
         [12, 14]],

        [[16, 18],
         [20, 22]]])

Bottle provides an n-dimensional Tensor for efficient data storage. Slice and index these containers to return views into their data.

t[1...]
Tensor([[[ 4,  5],
         [ 6,  7]],

        [[ 8,  9],
         [10, 11]]])
t[0]
Tensor([[0, 1],
        [2, 3]])
t[..., 1] # =>
Tensor([[ 2,  3],
        [ 6,  7],
        [10, 11]])
t[..., 1...2, 1...2]
Tensor([[[ 3]],

        [[ 7]],

        [[11]]])

Make use of elementwise, outer, and accumulation operations.

t[0] / t[-1]
Tensor([[    0.0,   0.111],
        [    0.2,   0.273]])
B.multiply.outer(t[...2, 1], t[1..., -1])
Tensor([[[[12, 14],
          [18, 21]],

         [[20, 22],
          [30, 33]]],


        [[[36, 42],
          [42, 49]],

         [[60, 66],
          [70, 77]]]])

Use Linear Algebra Routines backed by BLAS and LAPACK

B.matmul(t[0], t[1]) # =>
Tensor([[   6.0,    7.0],
        [  26.0,   31.0]])
B.inv(t[0, ..., ...2])
Tensor([[ -1.5,   0.5],
        [  1.0,   0.0]])

Contributing

Bottle requires help in many different ways to continue to grow as a shard. Contributions such as high level documentation and code quality checks are needed just as much as API enhancements. If you are considering larger scale contributions that extend beyond minor enhancements and bug fixes, contact Crystal Data in order to be added to the organization to gain access to review and merge permissions.

Github statistic:
  • 25
  • 0
  • 2
  • 3
  • 0
  • about 17 hours ago

License:

MIT License

Links: