ypstruct


Nameypstruct JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://github.com/smkalami/ypstruct
SummaryA simple and easy-to-use C/C++/MATLAB-like structure type for Python
upload_time2020-10-18 20:21:17
maintainer
docs_urlNone
authorMostapha Kalami Heris
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/smkalami/ypstruct",
    "name": "ypstruct",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Mostapha Kalami Heris",
    "author_email": "sm.kalami@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/05/91/7300f279cd63f1b5e3444c765ec26c4027f34ee5d7124a5cb74ed0b0304c/ypstruct-0.0.2.tar.gz",
    "platform": "",
    "description": "# Yarpiz Structure (ypstruct)\n\nA simple and easy-to-use C/C++/MATLAB-like structure type for Python\n\n\n## Installation\n\nYou can use pip to install `ypstruct`:\n\n    pip install ypstruct\n\nIf you want to install from source code, you can download from github or simply use:\n\n    git clone https://github.com/smkalami/ypstruct\n\nand then, run this:\n\n    python setup.py install\n\n\n## Sample Usage\n\nThe structure is defined by `struct` class. Also an alias of this class is defined and available as `structure`.\n\nA simple usage code of `ypstruct.struct` follows.\n\n    from ypstruct import *\n\n    p = struct()\n    p.x = 3\n    p.y = 4\n    p.A = p.x * p.y\n    print(p)\n\nThe output will be:\n\n    struct({'x': 3, 'y': 4, 'A': 12})\n\nHere, 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.\n\nIn the previous code, you can simply use the following method to create and initialize the structure.\n\n    p = struct(x=3, y=4)\n    p.A = p.x * p.y\n\n## Merging Structures\n\nIt is possible to merge two `struct` objects. For example let's define two structures as:\n\n    a = struct(x=1, y=2, z=3)\n    b = struct(y=5, t=20, u=30)\n\nWe can merge these structure using `+` operator:\n\n    c = a + b\n    print(c)\n\nThe output will be:\n\n    struct({'x': 1, 'y': 5, 'z': 3, 't': 20, 'u': 30})\n\n## Repeating a Structure\n\nSometimes 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:\n\n    empty_individual = struct(pos=None, fval=None)\n\nThen we can initialize the population array using following code:\n\n    pop_size = 10\n    pop = empty_individual.repeat(pop_size)\n\nOr simply we can use `*` operator to perform replication:\n\n    pop = empty_individual * pop_size",
    "bugtrack_url": null,
    "license": "",
    "summary": "A simple and easy-to-use C/C++/MATLAB-like structure type for Python",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://github.com/smkalami/ypstruct"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "05917300f279cd63f1b5e3444c765ec26c4027f34ee5d7124a5cb74ed0b0304c",
                "md5": "ca2ac36539c8dd32ec4f4d5f2cbb5ba3",
                "sha256": "26143a45978083849bff2c373041c96ae9dbfa226164e82fb51ec966065f8361"
            },
            "downloads": -1,
            "filename": "ypstruct-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "ca2ac36539c8dd32ec4f4d5f2cbb5ba3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3006,
            "upload_time": "2020-10-18T20:21:17",
            "upload_time_iso_8601": "2020-10-18T20:21:17.630492Z",
            "url": "https://files.pythonhosted.org/packages/05/91/7300f279cd63f1b5e3444c765ec26c4027f34ee5d7124a5cb74ed0b0304c/ypstruct-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-10-18 20:21:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "smkalami",
    "github_project": "ypstruct",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ypstruct"
}
        
Elapsed time: 0.68798s