Skip to main content

A Cython-based tensor and autograd library

Project description

🔥 CGrad

⏭️🥅 Next goal:

  • Grad engine -> new task: matmul/div autograd. -> scaler part still remaining.
  • randn Generator -> with seed
  • Make the Tensor fast: Check the tensor.c and Tensorwrapper.pyx files again, and try to optimize them to make them faster.
  • stop using numpy -> add the reshape, and other stuff.
  • Build a Tensor for Int, Double, Long, etc.
  • Use the Fast matrix multiplication algorithm to reduce the time complexity.
  • Make loss dir and make loss like "Tenh, ReLU, sigmoid, softmax" in a more optimistic way. -> Make the loss folder, but you also need to make the backward pass for it.
  • Make Optimizer start with SGD in C not in pyx (aka cython) -> after SGD -> Adam ...

✨ Overview

Lightweight library for performing tensor operations. CGrad is a module designed to handle all gradient computations, and most matrix manipulation and numerical work generally required for tasks in machine learning and deep learning. 🤖📚

💡 Features

  • 🌀 Support for n-dimensional tensor operations.
  • 🤖 Automatic differentiation for gradient computation.
  • 🛠️ Built-in functions for common tensor operations like addition, multiplication, dot product, etc.

⚙️ Installation

For user:

pip install cgrad==0.0.1 

For Contributers

  1. install MinGW for Windows user install latest MinGW.

  2. install gcc for Mac or Linux user install latest gcc.

  3. clone the repository and install manually:

    git clone https://github.com/Ruhaan838/CGrad
    
    python setup.py build_ext --inplace
    pip install .
    

🚀 Getting Started

Here’s a simple guide to get you started with CGrad:

📥 Importing the module

import cgrad

📦 Creating Tensors

You can create a tensor from a Python list or NumPy array:

# Creating a tensor from a list
tensor = cgrad.Tensor([1.0, 2.0, 3.0])

# Creating a tensor with a specified shape
tensor = cgrad.Tensor([[1.0, 2.0], [3.0, 4.0]])

🔄 Basic Tensor Operations

CGrad supports basic operations like addition, multiplication, etc.:

# Tensor addition 
a = cgrad.Tensor([1.0, 2.0, 3.0])
b = cgrad.Tensor([4.0, 5.0, 6.0])
result = a + b  # Element-wise addition

# Tensor multiplication 
c = cgrad.Tensor([[1.0, 2.0], [3.0, 4.0]])
d = cgrad.Tensor([[5.0, 6.0], [7.0, 8.0]])
result = c * d  # Element-wise multiplication

📐 Advance Tensor Operations

CGrad supports advanced operations like matrix multiplication etc.:

a = cgrad.randn((1,2,3))
b = cgrad.randn((5,3,2))
result = a @ b

Note: cgrad.matmul is still underdevelopment.

🔥 Gradient Computation

CGrad automatically tracks operations and computes gradients for backpropagation:

# Defining tensors with gradient tracking 
x = cgrad.Tensor([2.0, 3.0], requires_grad=True)
y = cgrad.Tensor([1.0, 4.0], requires_grad=True)

# Performing operations 
z = x * y

# Backpropagation to compute gradients 
z.backward()

# Accessing gradients 
print(x.grad)  # Gradients of x
print(y.grad)  # Gradients of y

📖 Documentation

For more detailed information, please visit our documentation website.

🤝 Contributing

I ❤️ contributions! If you’d like to contribute to CGrad, please:

You can contribute to code improvement and documentation editing.
If any issue is found, report it on the GitHub issue
  1. 🍴 Clone the repository.
  2. 🌱 Create a new branch for your feature or bugfix.
  3. ✉️ Submit a pull request.

📖 Reading

  • Blog about how tensors work at the computer level. [link]
  • Cython Documentation. [link]

📝 License

📜 See LICENSE for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cgrad-0.0.2.tar.gz (269.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cgrad-0.0.2-cp312-cp312-macosx_11_0_arm64.whl (141.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file cgrad-0.0.2.tar.gz.

File metadata

  • Download URL: cgrad-0.0.2.tar.gz
  • Upload date:
  • Size: 269.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for cgrad-0.0.2.tar.gz
Algorithm Hash digest
SHA256 65f8979887aa95416dcbda90a0ea9c55ca8b1a2a86b37f2c6ca5ddf0d8d22ec2
MD5 e341ad89251ab0022269d9c5ea5c0892
BLAKE2b-256 61a5f3b82a756cf22313df9f01d61e8f159b17ec4cb2f1fafea9c64e7983e694

See more details on using hashes here.

File details

Details for the file cgrad-0.0.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cgrad-0.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a829de2a9e0f823f03c3b6f7f569560f9da6996443990fca395d906c9d948fc3
MD5 89244f9c4f8008947d92f6f2fd642587
BLAKE2b-256 3e82532c4f0285bda7f8c815d594a727334afa247ead1ee05213645f54e4b877

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page