numpy-fn


Namenumpy-fn JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/ywatanabe1989/numpy_fn
SummaryA decorator for seamless numpy calculations from torch.tensor and pd.DataFrame.
upload_time2024-04-07 10:58:06
maintainerNone
docs_urlNone
authorywatanabe1989
requires_python>=3.6
licenseMIT
keywords numpytorch pandas
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![CI](https://github.com/ywatanabe1989/torch_fn/actions/workflows/pip_install.yml/badge.svg)
![CI](https://github.com/ywatanabe1989/torch_fn/actions/workflows/run_example.yml/badge.svg)

## Installation
``` bash
$ pip install numpy_fn
```

## Usage

``` python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Time-stamp: "2024-04-07 21:56:35 (ywatanabe)"

from numpy_fn import numpy_fn

import numpy as np
import pandas as pd
import scipy
import torch


@numpy_fn
def numpy_softmax(*args, **kwargs):
    return scipy.special.softmax(*args, **kwargs)


def custom_print(x):
    print(type(x), x)


# Test the decorator with different input types
x = [1, 2, 3]
x_list = x
x_array = np.array(x)
x_df = pd.DataFrame({"col1": x})
x_tensor = torch.tensor(x).float()
if torch.cuda.is_available():
    x_tensor_cuda = torch.tensor(x).float().cuda()

custom_print(numpy_softmax(x_list, axis=-1))
# <class 'numpy.ndarray'> [0.09003057 0.24472847 0.66524096]

custom_print(numpy_softmax(x_array, axis=-1))
# <class 'numpy.ndarray'> [0.09003057 0.24472847 0.66524096]

custom_print(numpy_softmax(x_df, axis=-1))
# <class 'numpy.ndarray'> [0.09003057 0.24472847 0.66524096]

custom_print(numpy_softmax(x_tensor, axis=-1))
# /home/ywatanabe/proj/numpy_fn/src/numpy_fn/_numpy_fn.py:57: UserWarning: Converted from  <class 'numpy.ndarray'> to <class 'torch.Tensor'> (cpu)
#   warnings.warn(
# <class 'torch.Tensor'> tensor([0.0900, 0.2447, 0.6652])

if torch.cuda.is_available():
    custom_print(numpy_softmax(x_tensor_cuda, axis=-1))
# /home/ywatanabe/proj/numpy_fn/src/numpy_fn/_numpy_fn.py:57: UserWarning: Converted from  <class 'numpy.ndarray'> to <class 'torch.Tensor'> (cuda:0)
#   warnings.warn(
# <class 'torch.Tensor'> tensor([0.0900, 0.2447, 0.6652], device='cuda:0')
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ywatanabe1989/numpy_fn",
    "name": "numpy-fn",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "numpytorch, pandas",
    "author": "ywatanabe1989",
    "author_email": "ywata1989@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a9/6a/a1e646a6dfe39b70570b64565430a43702b13d9ae1a04012f0b001565016/numpy_fn-1.0.0.tar.gz",
    "platform": null,
    "description": "![CI](https://github.com/ywatanabe1989/torch_fn/actions/workflows/pip_install.yml/badge.svg)\n![CI](https://github.com/ywatanabe1989/torch_fn/actions/workflows/run_example.yml/badge.svg)\n\n## Installation\n``` bash\n$ pip install numpy_fn\n```\n\n## Usage\n\n``` python\n#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n# Time-stamp: \"2024-04-07 21:56:35 (ywatanabe)\"\n\nfrom numpy_fn import numpy_fn\n\nimport numpy as np\nimport pandas as pd\nimport scipy\nimport torch\n\n\n@numpy_fn\ndef numpy_softmax(*args, **kwargs):\n    return scipy.special.softmax(*args, **kwargs)\n\n\ndef custom_print(x):\n    print(type(x), x)\n\n\n# Test the decorator with different input types\nx = [1, 2, 3]\nx_list = x\nx_array = np.array(x)\nx_df = pd.DataFrame({\"col1\": x})\nx_tensor = torch.tensor(x).float()\nif torch.cuda.is_available():\n    x_tensor_cuda = torch.tensor(x).float().cuda()\n\ncustom_print(numpy_softmax(x_list, axis=-1))\n# <class 'numpy.ndarray'> [0.09003057 0.24472847 0.66524096]\n\ncustom_print(numpy_softmax(x_array, axis=-1))\n# <class 'numpy.ndarray'> [0.09003057 0.24472847 0.66524096]\n\ncustom_print(numpy_softmax(x_df, axis=-1))\n# <class 'numpy.ndarray'> [0.09003057 0.24472847 0.66524096]\n\ncustom_print(numpy_softmax(x_tensor, axis=-1))\n# /home/ywatanabe/proj/numpy_fn/src/numpy_fn/_numpy_fn.py:57: UserWarning: Converted from  <class 'numpy.ndarray'> to <class 'torch.Tensor'> (cpu)\n#   warnings.warn(\n# <class 'torch.Tensor'> tensor([0.0900, 0.2447, 0.6652])\n\nif torch.cuda.is_available():\n    custom_print(numpy_softmax(x_tensor_cuda, axis=-1))\n# /home/ywatanabe/proj/numpy_fn/src/numpy_fn/_numpy_fn.py:57: UserWarning: Converted from  <class 'numpy.ndarray'> to <class 'torch.Tensor'> (cuda:0)\n#   warnings.warn(\n# <class 'torch.Tensor'> tensor([0.0900, 0.2447, 0.6652], device='cuda:0')\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A decorator for seamless numpy calculations from torch.tensor and pd.DataFrame.",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/ywatanabe1989/numpy_fn"
    },
    "split_keywords": [
        "numpytorch",
        " pandas"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5fcea7462156327392f82a3e075cd055823e6daa1743a11d0922f5393aa59c25",
                "md5": "d3130657242a08ef1ab4314e436da9e1",
                "sha256": "0ac08fed655529a1214248d4db19fe168333b2d7b27937e46874bfb19bbeaf72"
            },
            "downloads": -1,
            "filename": "numpy_fn-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d3130657242a08ef1ab4314e436da9e1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4758,
            "upload_time": "2024-04-07T10:58:04",
            "upload_time_iso_8601": "2024-04-07T10:58:04.237535Z",
            "url": "https://files.pythonhosted.org/packages/5f/ce/a7462156327392f82a3e075cd055823e6daa1743a11d0922f5393aa59c25/numpy_fn-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a96aa1e646a6dfe39b70570b64565430a43702b13d9ae1a04012f0b001565016",
                "md5": "adee53e9d47ba7a667639d9102b02836",
                "sha256": "abfd4b6b118ccc4087b8fef3c40b85daab094081ee2818b69dd464df7230f44f"
            },
            "downloads": -1,
            "filename": "numpy_fn-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "adee53e9d47ba7a667639d9102b02836",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4482,
            "upload_time": "2024-04-07T10:58:06",
            "upload_time_iso_8601": "2024-04-07T10:58:06.170830Z",
            "url": "https://files.pythonhosted.org/packages/a9/6a/a1e646a6dfe39b70570b64565430a43702b13d9ae1a04012f0b001565016/numpy_fn-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-07 10:58:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ywatanabe1989",
    "github_project": "numpy_fn",
    "github_not_found": true,
    "lcname": "numpy-fn"
}
        
Elapsed time: 0.40908s