Yarpiz Structure (ypstruct)
A simple and easy-to-use C/C++/MATLAB-like structure type for Python
Installation
You can use pip to install ypstruct:
pip install ypstruct
If you want to install from source code, you can download from github or simply use:
git clone https://github.com/smkalami/ypstruct
and then, run this:
python setup.py install
Sample Usage
The structure is defined by struct class. Also an alias of this class is defined and available as structure.
A simple usage code of ypstruct.struct follows.
from ypstruct import *
p = struct()
p.x = 3
p.y = 4
p.A = p.x * p.y
print(p)
The output will be:
struct({'x': 3, 'y': 4, 'A': 12})
Here, after importing the struct (and its alias structure) from ypstruct, an instance of struct is created and then fields x and y are defined. Then, a new field A is added to the structure. Finally, the string representation of the struct is printed.
In the previous code, you can simply use the following method to create and initialize the structure.
p = struct(x=3, y=4)
p.A = p.x * p.y
Merging Structures
It is possible to merge two struct objects. For example let's define two structures as:
a = struct(x=1, y=2, z=3)
b = struct(y=5, t=20, u=30)
We can merge these structure using + operator:
c = a + b
print(c)
The output will be:
struct({'x': 1, 'y': 5, 'z': 3, 't': 20, 'u': 30})
Repeating a Structure
Sometimes we need to repeat/replicate a structure. For example, assume that we are going to implement an Evolutionary Algorithm and we defined the individuals as struct objects. First we need to create a template:
empty_individual = struct(pos=None, fval=None)
Then we can initialize the population array using following code:
pop_size = 10
pop = empty_individual.repeat(pop_size)
Or simply we can use * operator to perform replication:
pop = empty_individual * pop_size
Metadata
Release files for ypstruct 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ypstruct-0.0.2.tar.gz | 3.0 kB | Details |
Release files / ypstruct-0.0.2.tar.gz
| Download URL | ypstruct-0.0.2.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26143a45978083849bff2c373041c96ae9dbfa226164e82fb51ec966065f8361
|
|
BLAKE2b-256 checksum How to use checksums |
05917300f279cd63f1b5e3444c765ec26c4027f34ee5d7124a5cb74ed0b0304c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0
|