KrikNN is a library that includes various components for neural network operations and tensor manipulations. This README provides an overview of the `Tensor` class and its functionality, as well as instructions for running the tests.
Project description
KrikNN
KrikNN is a library that includes various components for neural network operations and tensor manipulations. This README provides an overview of the Tensor
class and its functionality, as well as instructions for running the tests.
Documentation: https://andykr1k.github.io/KrikNN/
Tensor Class
The Tensor
class is a fundamental component of the KrikNN library, allowing you to perform various operations on multidimensional arrays.
Features
- Initialization: Create tensors from data with support for different data types.
- Matrix Multiplication: Use the
@
operator to perform matrix multiplication. - Addition/Subtract: Use the
+
or the-
operator to perform element-wise addition and subtraction. - Shape: Retrieve the shape of the tensor.
Usage
Here’s a brief guide on how to use the Tensor
class:
import numpy as np
from kriknn.engine.tensor import Tensor
# Create tensors
tensor1 = Tensor([[1.0, 2.0], [3.0, 4.0]])
tensor2 = Tensor([[2.0, 0.0], [1.0, 2.0]])
# Matrix multiplication
result = tensor1 @ tensor2
print(result.data) # Output: [[4.0, 4.0], [10.0, 8.0]]
# Addition
tensor3 = Tensor([[5.0, 6.0], [7.0, 8.0]])
result_add = tensor1 + tensor3
print(result_add.data) # Output: [[6.0, 8.0], [10.0, 12.0]]
# Subtraction
tensor4 = Tensor([[5.0, 6.0], [7.0, 8.0]])
result_sub = tensor4 - tensor1
print(result_sub.data) # Output: [[4.0, 4.0], [4.0, 4.0]]
Running Tests
The KrikNN library includes tests for the Tensor
class to ensure its functionality. The tests are written using unittest
and can be run using the following command:
python -m tests/run.py
Test Cases
- Initialization Tests: Verify that tensors are initialized correctly with various data types.
- Shape Tests: Ensure that the shape property returns the correct dimensions.
- Matrix Multiplication Tests: Check that matrix multiplication is performed correctly.
- Addition/Subtraction Tests: Validate that tensor addition and subtraction is working as expected.
- Error Handling Tests: Ensure that appropriate errors are raised for invalid operations.
Examples
The KrikNN library provides several examples to help you get started with tensor operations:
- Basic Tensor Operations: Demonstrates basic tensor operations like matrix multiplication and addition/subtraction.
python examples/basic_tensor_operations.py
Contribution
Contributions to the KrikNN library are welcome. Please fork the repository, make your changes, and submit a pull request. Ensure that your changes are covered by tests and adhere to the existing code style.
License
This project is licensed under the MIT License. See the LICENSE file for 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
Built Distribution
File details
Details for the file kriknn-0.1.3.tar.gz
.
File metadata
- Download URL: kriknn-0.1.3.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee8e36aded304cb5e97c7e50ffee2b63db2e2bfe672d593e62e482b8c17a10b7 |
|
MD5 | f9b13a5c9f8cffcfe2f8a5338caca878 |
|
BLAKE2b-256 | 18f4ca166e7f60b0090ff2049ad9c2598683b0ff2564d1aae1705b9cb6fefaa0 |
File details
Details for the file kriknn-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: kriknn-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4074c1acef41027eb68085d01e858f6a4bdec479e4933bcf74341b39c38087e |
|
MD5 | 4f3c53a90478766d30eb4c86a4990547 |
|
BLAKE2b-256 | 70c26a677c927a4e27e8106bfbfcecc856ee4b0cd3c1c9b2607400633b420291 |