Skip to content

Getting Started with RustyNum

Welcome to RustyNum! This guide will help you quickly get up and running with RustyNum, from basic operations to a comparison with NumPy. If you're familiar with NumPy, you'll feel right at home.


๐Ÿ”ฅ Why Use RustyNum?

RustyNum is a high-performance alternative to NumPy. With Rustโ€™s SIMD optimization, RustyNum can significantly speed up your numerical computations, all while maintaining a familiar interface.


๐Ÿ“˜ Basic Usage

Hereโ€™s a quick example to demonstrate RustyNum's simplicity and performance:

Example: Compute the Mean of an Array

import rustynum as rnp

# Create a NumArray
a = rnp.NumArray([1.0, 2.0, 3.0, 4.0], dtype="float32")

# Add a scalar
a = a + 2

# Compute the mean
mean_value = a.mean().item()

print(mean_value)  # Output: 4.5

โšก RustyNum vs NumPy

RustyNum is designed to be a faster alternative to NumPy for many operations. Letโ€™s compare the syntax:

Creating Arrays

NumPy

import numpy as np

a = np.array([1.0, 2.0, 3.0], dtype="float32")

RustyNum

import rustynum as rnp

a = rnp.NumArray([1.0, 2.0, 3.0], dtype="float32")

Adding Scalars

NumPy

a = a + 2

RustyNum

a = a + 2

Computing the Mean

NumPy

mean_value = a.mean()

RustyNum

mean_value = a.mean().item()

๐Ÿ› ๏ธ Basic Operations

RustyNum supports a variety of operations. Here are a few examples to get you started:

1. Creating Arrays

import rustynum as rnp

# Create an array of zeros
zeros_array = rnp.zeros([3, 3])

# Create an array with evenly spaced values
arange_array = rnp.arange(0, 10, 2)

# Create an array with evenly spaced values over a specified interval
linspace_array = rnp.linspace(0, 1, 5)

print(zeros_array)
print(arange_array)
print(linspace_array)

2. Element-Wise Operations

# Perform element-wise addition
result = arange_array + 2

# Perform element-wise multiplication
result = arange_array * 2

3. Matrix Operations

# Create a 2D NumArray
matrix = rnp.NumArray([[1.0, 2.0], [3.0, 4.0]], dtype="float32")

# Compute the dot product
vector = rnp.NumArray([1.0, 2.0], dtype="float32")
dot_product = matrix.dot(vector)

print(dot_product)

๐Ÿ”— Learn More

Once youโ€™re comfortable with the basics, dive deeper into RustyNum with these resources:

  • Tutorials: Explore real-world applications of RustyNum.
  • API Reference: Detailed documentation of RustyNumโ€™s Python bindings.

๐Ÿ“ฉ Need Help?

If you have any questions, check out the GitHub Discussions or file an issue on the GitHub Repository.