carat

A library for numerical and scientific computation.

carat

A library for numerical and scientific computation. (Work in progress)

Installation

  1. Add the dependency to your shard.yml:
dependencies:
  carat:
    github: your-github-user/carat
  1. Run shards install

Usage

require "carat"

Tensors

Carat defines class Tensor which is (numpy-style) n-dimensional tensor.

Create tensor

It can be created in a number of ways:

  • Tensor containing zeros
    Tensor.new(2, 2)
    # [[ 0.0 0.0 ]
    #  [ 0.0 0.0 ]]
    
  • With block
    Tensor.new(2, 2) do |i, j|
      (i + j).to_f
    end
    # [[ 0.0 1.0 ]
    #  [ 1.0 2.0 ]]
    
  • From a regular Array
    Tensor[2, 2].new([[0.0, 1.0], [1.0, 2.0]])
    # [[ 0.0 1.0 ]
    #  [ 1.0 2.0 ]]
    

Index tensor

  • By integer
    tensor = Tensor.new(3, 3) { |i, j| i + j }
    tensor[1, 1]
    # 2.0
    
    Or
    tensor[1]
    # [ 1.0 2.0 3.0 ]
    
  • By range
    tensor[0...2, 0...2]
    # [[ 0.0 1.0 ]
    #  [ 1.0 2.0 ]] 
    
  • By range with step
    tensor[0..2..4, 0..2..4]
    # [[ 0.0 2.0 ]
    #  [ 2.0 4.0 ]] 
    

Development

TODO: Write development instructions here

Contributing

  1. Fork it (https://github.com/your-github-user/carat/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

carat

Owner
Statistic
  • 1
  • 0
  • 0
  • 0
  • 0
  • almost 7 years ago
  • November 28, 2018
License

MIT License

Links
Synced at

Fri, 03 Oct 2025 20:42:30 GMT

Languages