All Projects → SciScala → NDScala

SciScala / NDScala

Licence: AGPL-3.0 license
N-dimensional arrays in Scala 3. Think NumPy ndarray, but type-safe over shapes, array/axis labels & numeric data types

Programming Languages

scala
5932 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to NDScala

Cloud Volume
Read and write Neuroglancer datasets programmatically.
Stars: ✭ 63 (+70.27%)
Mutual labels:  numpy, matrix, tensor
Mtensor
A C++ Cuda Tensor Lazy Computing Library
Stars: ✭ 115 (+210.81%)
Mutual labels:  numpy, tensor
Pytorch
Tensors and Dynamic neural networks in Python with strong GPU acceleration
Stars: ✭ 52,811 (+142632.43%)
Mutual labels:  numpy, tensor
saddle
SADDLE: Scala Data Library
Stars: ✭ 23 (-37.84%)
Mutual labels:  numpy, matrix
Drlkit
A High Level Python Deep Reinforcement Learning library. Great for beginners, prototyping and quickly comparing algorithms
Stars: ✭ 29 (-21.62%)
Mutual labels:  numpy, tensor
Tensorly
TensorLy: Tensor Learning in Python.
Stars: ✭ 977 (+2540.54%)
Mutual labels:  numpy, tensor
Einops
Deep learning operations reinvented (for pytorch, tensorflow, jax and others)
Stars: ✭ 4,022 (+10770.27%)
Mutual labels:  numpy, tensor
Pyrr
3D mathematical functions using NumPy
Stars: ✭ 282 (+662.16%)
Mutual labels:  numpy, matrix
scala-3-crash-course
Scala 3 workshop presenting the top new features of the language.
Stars: ✭ 34 (-8.11%)
Mutual labels:  dotty, scala3
GenericTensor
The only library allowing to create Tensors (matrices extension) with custom types
Stars: ✭ 42 (+13.51%)
Mutual labels:  matrix, tensor
numphp
PHP tools for matrix computation
Stars: ✭ 25 (-32.43%)
Mutual labels:  matrix, ndarray
Cupy
NumPy & SciPy for GPU
Stars: ✭ 5,625 (+15102.7%)
Mutual labels:  numpy, tensor
Tensor Sensor
The goal of this library is to generate more helpful exception messages for numpy/pytorch matrix algebra expressions.
Stars: ✭ 532 (+1337.84%)
Mutual labels:  numpy, matrix
Inkuire
Hoogle-like searches for Scala 3 and Kotlin
Stars: ✭ 70 (+89.19%)
Mutual labels:  dotty, scala3
Matrex
A blazing fast matrix library for Elixir/Erlang with C implementation using CBLAS.
Stars: ✭ 429 (+1059.46%)
Mutual labels:  numpy, matrix
Mars
Mars is a tensor-based unified framework for large-scale data computation which scales numpy, pandas, scikit-learn and Python functions.
Stars: ✭ 2,308 (+6137.84%)
Mutual labels:  numpy, tensor
python-twelve-tone
🎶 12-tone matrix to generate dodecaphonic melodies 🎶
Stars: ✭ 68 (+83.78%)
Mutual labels:  numpy, matrix
Megengine
MegEngine 是一个快速、可拓展、易于使用且支持自动求导的深度学习框架
Stars: ✭ 4,081 (+10929.73%)
Mutual labels:  numpy, tensor
eigen
Owl's OCaml Interface to Eigen3 C++ Library
Stars: ✭ 30 (-18.92%)
Mutual labels:  matrix, tensor
Tensor
A library and extension that provides objects for scientific computing in PHP.
Stars: ✭ 146 (+294.59%)
Mutual labels:  matrix, tensor

Training a (shape-safe) neural network in 10 lines:

In NDScala:

//After some setup
//Declaring types and their corresponding values
type Mat10kX10k = 10000 #: 10000 #:SNil
type AxisLabels = "AxisLabel" ##: "AxisLabel" ##: TSNil
val mat10kX10k = shapeOf[Mat10kX10k]
val axisLabels = tensorShapeDenotationOf[AxisLabels]

val ones = Tensor(Array.fill(100000000)(1.0f),"TensorLabel",axisLabels, mat10kX10k)

def train(x: Tensor[Float, ("TensorLabel", AxisLabels, Mat10kX10k)],
          y: Tensor[Float, ("TensorLabel", AxisLabels, Mat10kX10k)],
          w0: Tensor[Float, ("TensorLabel", AxisLabels, Mat10kX10k)],
          w1: Tensor[Float, ("TensorLabel", AxisLabels, Mat10kX10k)],
          iter: Int): Tuple2[Tensor[Float, ("TensorLabel", AxisLabels, Mat10kX10k)],
                             Tensor[Float, ("TensorLabel", AxisLabels, Mat10kX10k)]] =
    if iter == 0 then (w0, w1)
    else
        val l1 =  (x.matmul(w0)).sigmoid()
        val l2 = (l1.matmul(w1)).sigmoid()
        val error = y - l2
        val l2Delta = (error) * (l2 * (ones - l2))
        val l1Delta =  (l2Delta.matmul(w1.transpose))
        val w1New = w1 + (((l1.transpose).matmul(l2Delta)))
        val w0New = w0 + (((x.transpose).matmul(l1Delta)))
        train(x,y,w0New,w1New,iter-1)

And for reference, in NumPy, in 10 lines:

def train(X,Y,iter): 
    syn0 = 2*np.random.random((10000,10000)).astype('float32') - 1
    syn1 = 2*np.random.random((10000,1000)).astype('float32') - 1
    for j in range(iter): 
        l1 = 1/(1+np.exp(-(np.dot(X,syn0))))  
        l2 = 1/(1+np.exp(-(np.dot(l1,syn1)))) 
        error = y - l2
        l2_delta = (error)*(l2*(1-l2))
        l1_delta = l2_delta.dot(syn1.T) * (l1 * (1-l1))
        syn1 += l1.T.dot(l2_delta)
        syn0 += X.T.dot(l1_delta) 

The run time of the NDScala version is ~80% of that of NumPy w/MKL

The PyTorch equivalent is slightly faster, at ~85% of the NDScala version run time. This can be accounted for by the copy overhead of passing data between the JVM and native memory.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].