8000 GitHub - Laxman44/ndarray-vector-uint8c: Create a clamped unsigned 8-bit integer vector (i.e., a one-dimensional ndarray).
[go: up one dir, main page]

Skip to content

Laxman44/ndarray-vector-uint8c

πŸ› οΈ ndarray-vector-uint8c

Welcome to the ndarray-vector-uint8c repository! This project focuses on creating a clamped unsigned 8-bit integer vector, which is essentially a one-dimensional ndarray. This type of data structure is useful in various applications, especially in image processing, where pixel values are often represented as 8-bit integers.

πŸ“¦ Table of Contents

πŸ“œ Introduction

The ndarray-vector-uint8c library provides an efficient way to handle unsigned 8-bit integer vectors. These vectors can store values ranging from 0 to 255. The clamping feature ensures that any values outside this range are adjusted to fit within it. This makes the library particularly valuable for tasks involving graphics and data manipulation.

The library is built using JavaScript and is compatible with Node.js. It aims to provide a simple yet powerful API for developers who need to work with numeric data efficiently.

You can check the latest releases of this project here.

πŸš€ Installation

To install the ndarray-vector-uint8c library, you can use npm. Run the following command in your terminal:

npm install ndarray-vector-uint8c

This command will download the package and add it to your project's dependencies.

πŸ“– Usage

To use the library, you need to require it in your JavaScript file. Here’s a basic example:

const { VectorUint8C } = require('ndarray-vector-uint8c');

const vector = new VectorUint8C(10); // Create a vector of length 10
vector.set(0, 255); // Set the first element to 255
console.log(vector.get(0)); // Outputs: 255

Clamping Behavior

The clamping feature automatically adjusts any values that exceed the 0-255 range. For example:

vector.set(1, 300); // Attempt to set value outside the range
console.log(vector.get(1)); // Outputs: 255

πŸ“š API Documentation

Constructor

The main constructor for creating a new unsigned 8-bit integer vector is VectorUint8C.

Parameters

  • length (number): The desired length of the vector.

Example

const vector = new VectorUint8C(5);

Methods

set(index, value)

Sets the value at the specified index. The value is clamped between 0 and 255.

  • Parameters:
    • index (number): The index to set.
    • value (number): The value to set.

get(index)

Retrieves the value at the specified index.

  • Parameters:
    • index (number): The index to retrieve.

Example

vector.set(2, 128);
console.log(vector.get(2)); // Outputs: 128

🌟 Examples

Here are some examples of how to use the ndarray-vector-uint8c library in various scenarios.

Example 1: Basic Vector Operations

const { VectorUint8C } = require('ndarray-vector-uint8c');

const vector = new VectorUint8C(5);
vector.set(0, 100);
vector.set(1, 200);
vector.set(2, 300); // This will be clamped to 255

console.log(vector.get(0)); // Outputs: 100
console.log(vector.get(1)); // Outputs: 200
console.log(vector.get(2)); // Outputs: 255

Example 2: Iterating Over a Vector

You can iterate over the vector to perform operations on each element.

for (let i = 0; i < vector.length; i++) {
    console.log(vector.get(i));
}

Example 3: Creating a Vector from an Array

You can initialize a vector with values from an existing array.

const initialValues = [50, 150, 250];
const vector = new VectorUint8C(initialValues.length);

initialValues.forEach((value, index) => {
    vector.set(index, value);
});

console.log(vector.get(0)); // Outputs: 50
console.log(vector.get(1)); // Outputs: 150
console.log(vector.get(2)); // Outputs: 250

🀝 Contributing

We welcome contributions to the ndarray-vector-uint8c project. If you have ideas for improvements or new features, feel free to fork the repository and submit a pull request.

Steps to Contribute

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them.
  4. Push your changes to your forked repository.
  5. Submit a pull request.

πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.

πŸ“¬ Contact

For questions or feedback, you can reach out via GitHub issues or contact the maintainer directly.

For the latest releases, visit this link.


Thank you for checking out the ndarray-vector-uint8c repository! We hope you find it useful for your projects involving unsigned 8-bit integer vectors.

About

Create a clamped unsigned 8-bit integer vector (i.e., a one-dimensional ndarray).

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
0