# Shape Commentator
[![CircleCI](https://circleci.com/gh/shiba6v/shape_commentator.svg?style=svg)](https://circleci.com/gh/shiba6v/shape_commentator)
## About
You can easily add numpy.ndarray.shape, torch.Size, other shape and type information at runtime to your script code as comments.
NumPyやPyTorchなどの配列のshape属性や,変数の型の実行時の情報を,スクリプトにコメントとして貼り付けるツールです.
## Install
```
pip install -U shape_commentator
```
-U means upgrading.
## Usage
This tool has two types of usage.
このツールには2つの使い方があります.
### Usage 1. Execute this as a Module
![Sample_Module](https://user-images.githubusercontent.com/13820488/70629620-9f6daf00-1c6d-11ea-95d1-e4b8adc31a4d.png)
#### Create Commented Script
1. Run this script as a module with argument of script name. Command line arguments to the target script are available.
Pythonのモジュールとしてshape_commentatorを実行してください.引数は,スクリプト名の後にスクリプトに渡したい引数を続けることもできます.
```bash
python -m shape_commentator src.py
```
```bash
python -m shape_commentator src.py arg1 arg2 arg3
```
2. You get the commented script. For example, you execute shape_commentator to `src.py`, you get `src.py.commented.py`.
`src.py`というスクリプトに対して実行すると,`src.py.commented.py`が生成されます.
`src.py`
```python
import numpy as np
a = np.array([1,2,3,4,5,6])
b = np.array([0,1,2,3,4,5])
ab_h = np.hstack((a,b))
ab_v = np.vstack((a,b))
ab = np.dot(a,b)
AA, BB = np.meshgrid(a,b)
i = 1
f = 1.0
c = 1 + 1j
s = "string1"
class A():
pass
a = A()
```
`src.py.commented.py`
```python
import numpy as np
a = np.array([1,2,3,4,5,6]) #_ (6,)
b = np.array([0,1,2,3,4,5]) #_ (6,)
ab_h = np.hstack((a,b)) #_ (12,)
ab_v = np.vstack((a,b)) #_ (2, 6)
ab = np.dot(a,b) #_ ()
AA, BB = np.meshgrid(a,b) #_ [(6, 6),(6, 6),]
i = 1 #_ int
f = 1.0 #_ float
c = 1 + 1j #_ complex
s = "string1" #_ str
class A():
pass
a = A() #_ A
```
### Usage 2. IPython / Jupyter Notebook (Magic Command)
![Sample_IPython](https://user-images.githubusercontent.com/13820488/70638063-91268f80-1c7b-11ea-94c3-d00d32133636.png)
To use IPython / Jupyter Notebook magic command,
IPythonやJupyter Notebookでのマジックコマンドの使い方
```python
import shape_commentator
```
#### Create Commented Script
コメントを付ける
```python
%%shape
a = np.array([1,2,3,4,5,6])
```
output
```
a = np.array([1,2,3,4,5,6]) #_ (6,)
```
#### Delete Comments
コメントを消す
```python
%%shape -d
a = np.array([1,2,3,4,5,6]) #_ (6,)
```
output
```
a = np.array([1,2,3,4,5,6])
```
## Tested Python Version
Test scripts are written in these version of Python.
以下のバージョンがテストされています.
- 3.11.3
- 3.10.11
- 3.9.16
- 3.8.16
- 3.7.16
- 3.6.15
- 3.5.10
- 2.7.17
## Blog
作った経緯などを書いた解説ブログはこちらにあります.
[NumPyやPyTorchで使える超便利ツールを作った](http://shiba6v.hatenablog.com/entry/shape_commentator_release)
Raw data
{
"_id": null,
"home_page": "https://github.com/shiba6v/shape_commentator",
"name": "shape-commentator",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "numpy,ndarray,shape comment,tool",
"author": "shiba6v",
"author_email": "shiba6v@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b2/89/48a99d438168ea08665ac4eb9118dfdc42345688850e4eb1ae0330f57005/shape_commentator-0.8.0.tar.gz",
"platform": null,
"description": "# Shape Commentator\n[![CircleCI](https://circleci.com/gh/shiba6v/shape_commentator.svg?style=svg)](https://circleci.com/gh/shiba6v/shape_commentator)\n\n## About \nYou can easily add numpy.ndarray.shape, torch.Size, other shape and type information at runtime to your script code as comments. \nNumPy\u3084PyTorch\u306a\u3069\u306e\u914d\u5217\u306eshape\u5c5e\u6027\u3084\uff0c\u5909\u6570\u306e\u578b\u306e\u5b9f\u884c\u6642\u306e\u60c5\u5831\u3092\uff0c\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u30b3\u30e1\u30f3\u30c8\u3068\u3057\u3066\u8cbc\u308a\u4ed8\u3051\u308b\u30c4\u30fc\u30eb\u3067\u3059\uff0e\n\n## Install\n```\npip install -U shape_commentator\n```\n-U means upgrading.\n\n## Usage\nThis tool has two types of usage. \n\u3053\u306e\u30c4\u30fc\u30eb\u306b\u306f2\u3064\u306e\u4f7f\u3044\u65b9\u304c\u3042\u308a\u307e\u3059\uff0e\n\n### Usage 1. Execute this as a Module\n![Sample_Module](https://user-images.githubusercontent.com/13820488/70629620-9f6daf00-1c6d-11ea-95d1-e4b8adc31a4d.png)\n\n#### Create Commented Script\n1. Run this script as a module with argument of script name. Command line arguments to the target script are available. \nPython\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3057\u3066shape_commentator\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\uff0e\u5f15\u6570\u306f\uff0c\u30b9\u30af\u30ea\u30d7\u30c8\u540d\u306e\u5f8c\u306b\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u6e21\u3057\u305f\u3044\u5f15\u6570\u3092\u7d9a\u3051\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\uff0e\n\n```bash\npython -m shape_commentator src.py\n```\n\n```bash\npython -m shape_commentator src.py arg1 arg2 arg3\n```\n\n2. You get the commented script. For example, you execute shape_commentator to `src.py`, you get `src.py.commented.py`. \n`src.py`\u3068\u3044\u3046\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u5bfe\u3057\u3066\u5b9f\u884c\u3059\u308b\u3068\uff0c`src.py.commented.py`\u304c\u751f\u6210\u3055\u308c\u307e\u3059\uff0e\n\n`src.py`\n```python\nimport numpy as np\na = np.array([1,2,3,4,5,6])\nb = np.array([0,1,2,3,4,5])\nab_h = np.hstack((a,b))\nab_v = np.vstack((a,b))\nab = np.dot(a,b)\nAA, BB = np.meshgrid(a,b)\ni = 1\nf = 1.0\nc = 1 + 1j\ns = \"string1\"\nclass A():\n pass\na = A()\n```\n\n`src.py.commented.py`\n```python\nimport numpy as np\na = np.array([1,2,3,4,5,6]) #_ (6,)\nb = np.array([0,1,2,3,4,5]) #_ (6,)\nab_h = np.hstack((a,b)) #_ (12,)\nab_v = np.vstack((a,b)) #_ (2, 6)\nab = np.dot(a,b) #_ ()\nAA, BB = np.meshgrid(a,b) #_ [(6, 6),(6, 6),]\ni = 1 #_ int\nf = 1.0 #_ float\nc = 1 + 1j #_ complex\ns = \"string1\" #_ str\nclass A():\n pass\na = A() #_ A\n```\n\n### Usage 2. IPython / Jupyter Notebook (Magic Command)\n![Sample_IPython](https://user-images.githubusercontent.com/13820488/70638063-91268f80-1c7b-11ea-94c3-d00d32133636.png)\n\nTo use IPython / Jupyter Notebook magic command, \nIPython\u3084Jupyter Notebook\u3067\u306e\u30de\u30b8\u30c3\u30af\u30b3\u30de\u30f3\u30c9\u306e\u4f7f\u3044\u65b9\n```python\nimport shape_commentator\n```\n\n#### Create Commented Script\n\u30b3\u30e1\u30f3\u30c8\u3092\u4ed8\u3051\u308b\n```python\n%%shape\na = np.array([1,2,3,4,5,6])\n```\n\noutput\n```\na = np.array([1,2,3,4,5,6]) #_ (6,)\n```\n\n#### Delete Comments\n\u30b3\u30e1\u30f3\u30c8\u3092\u6d88\u3059\n```python\n%%shape -d\na = np.array([1,2,3,4,5,6]) #_ (6,)\n```\n\noutput\n```\na = np.array([1,2,3,4,5,6])\n```\n\n## Tested Python Version \nTest scripts are written in these version of Python. \n\u4ee5\u4e0b\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u30c6\u30b9\u30c8\u3055\u308c\u3066\u3044\u307e\u3059\uff0e\n- 3.11.3\n- 3.10.11\n- 3.9.16\n- 3.8.16\n- 3.7.16\n- 3.6.15\n- 3.5.10\n- 2.7.17\n\n## Blog\n\u4f5c\u3063\u305f\u7d4c\u7def\u306a\u3069\u3092\u66f8\u3044\u305f\u89e3\u8aac\u30d6\u30ed\u30b0\u306f\u3053\u3061\u3089\u306b\u3042\u308a\u307e\u3059\uff0e \n[NumPy\u3084PyTorch\u3067\u4f7f\u3048\u308b\u8d85\u4fbf\u5229\u30c4\u30fc\u30eb\u3092\u4f5c\u3063\u305f](http://shiba6v.hatenablog.com/entry/shape_commentator_release)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "You can easily add numpy.ndarray.shape information to your script as comments.",
"version": "0.8.0",
"project_urls": {
"Homepage": "https://github.com/shiba6v/shape_commentator"
},
"split_keywords": [
"numpy",
"ndarray",
"shape comment",
"tool"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b28948a99d438168ea08665ac4eb9118dfdc42345688850e4eb1ae0330f57005",
"md5": "b0dad755e796a073efb904c17f556ca8",
"sha256": "e536e39ca967151209e62b8fb4a236bf5ce080e828038dbac9e960587a560f71"
},
"downloads": -1,
"filename": "shape_commentator-0.8.0.tar.gz",
"has_sig": false,
"md5_digest": "b0dad755e796a073efb904c17f556ca8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8306,
"upload_time": "2023-05-28T12:47:43",
"upload_time_iso_8601": "2023-05-28T12:47:43.947847Z",
"url": "https://files.pythonhosted.org/packages/b2/89/48a99d438168ea08665ac4eb9118dfdc42345688850e4eb1ae0330f57005/shape_commentator-0.8.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-28 12:47:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "shiba6v",
"github_project": "shape_commentator",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"circle": true,
"lcname": "shape-commentator"
}