Skip to content

Commit

Permalink
add docs/ with skeleton API
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinedaurat committed May 27, 2021
1 parent d878ca9 commit b3299ee
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
*.ipynb_checkpoints*
dist/*
build/*
docs/_build/
*egg-info*
.idea
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
8 changes: 8 additions & 0 deletions docs/audios.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
audios
======

this package exposes helper classes for processing, interacting & modeling audio data

.. automodule:: mimikit.audios.fmodules

.. automodule:: mimikit.audios.features
79 changes: 79 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('../mimikit'))


# -- Project information -----------------------------------------------------

project = 'mimikit'
copyright = '2021, k-tonal'
author = 'k-tonal'

# The full version, including alpha/beta/rc tags
release = 'v0.1.6'


# -- General configuration ---------------------------------------------------

import sphinx_rtd_theme

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
"sphinx.ext.viewcode",
'sphinx_rtd_theme',
"numpydoc",
# "sphinx.ext.napoleon",
# "sphinx.ext.autosummary"
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

autoclass_content = "class"

# autodoc_default_options = ['no-undoc-members', 'no-inherited-members']

autodoc_typehints = 'description'
autodoc_class_signature = 'separated'
autodoc_typehints_description_target = 'documented'
autosummary_generate = True

numpydoc_show_class_members = False

napoleon_use_ivar = False

napoleon_use_admonition_for_examples = False
37 changes: 37 additions & 0 deletions docs/data.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
data
====

.. py:currentmodule:: mimikit.data.database
.. autoclass:: Database
:members:

.. autoclass:: FeatureProxy
:members:

.. py:currentmodule:: mimikit.data.datamodule
.. autoclass:: Getter
:members:
:special-members: __call__


.. autoclass:: AsSlice
:members:

.. autoclass:: AsFramedSlice
:members:

.. autoclass:: Input
:members:

.. autoclass:: Target
:members:

.. autoclass:: DefaultDataset
:members:

.. autoclass:: DataModule
:no-inherited-members:


29 changes: 29 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. mimikit documentation master file, created by
sphinx-quickstart on Fri Jan 8 04:24:18 2021.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
mimikit
=======

.. toctree::
:maxdepth: 2
:caption: Contents:

.. toctree::
:maxdepth: 1
:caption: User Guides


.. toctree::
:maxdepth: 1
:caption: API Reference

audios
data
models
networks

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
13 changes: 13 additions & 0 deletions docs/models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
models
======

exposes well-known and experimental models as :class:`pytorch_lightning.LightningModule`

.. py:currentmodule:: mimikit.models
.. autoclass:: SampleRNN
:no-inherited-members:


.. autoclass:: FreqNet
:no-inherited-members:
15 changes: 15 additions & 0 deletions docs/networks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
networks
========

exposes networks as pure :class:`torch.nn.Module`.

.. py:currentmodule:: mimikit.networks
.. autoclass:: FreqNetNetwork
:no-inherited-members:

.. autoclass:: SampleRNNNetwork
:no-inherited-members:

.. autoclass:: WNNetwork
:no-inherited-members:
3 changes: 3 additions & 0 deletions mimikit/audios/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

@dtc.dataclass
class AudioSignal(Feature):
"""
audio signal managers
"""
__ext__ = 'audio'

sr: int = 22050
Expand Down
12 changes: 8 additions & 4 deletions mimikit/data/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ def get_regions(self, regions):
Examples
--------
>>>from mimikit import Database
>>>X = Database("my-db.h5").fft
# only get files 0, 3 & 7
>>>X.get_regions(X.regions.iloc[[0, 3, 7]])
.. code-block::
from mimikit import Database
X = Database("my-db.h5").fft
# only get files 0, 3 & 7
X.get_regions(X.regions.iloc[[0, 3, 7]])
"""
slices = regions.slices(0)
return np.concatenate(tuple(self[slice_i] for slice_i in slices), axis=0)
Expand Down Expand Up @@ -300,6 +302,8 @@ def __getitem__(self, item):

def split(self, splits):
"""
performs random splits on self
Parameters
----------
splits: Sequence of floats or ints possibly containing None.
Expand Down
64 changes: 63 additions & 1 deletion mimikit/data/datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,76 @@

@dtc.dataclass
class Getter:
"""
base class for implementing data getter
Parameters
----------
Attributes
----------
n : int or None
the length of the underlying data
"""
n: Optional[int] = dtc.field(default=None, init=False)

def __call__(self, feat_data, item):
"""
apply this instance's logic to get data from ``feat_data`` for a given ``item``
Parameters
----------
feat_data: [np.ndarray, torch.Tensor, mimikit.FeatureProxy]
item: int
the index emitted from a sampler
Returns
-------
data: Any
the examples corresponding to this item
"""
return feat_data[item]

def __len__(self):
return self.n


@dtc.dataclass
@dtc.dataclass()
class AsSlice(Getter):
"""
maps an ``item`` to a slice of data
Parameters
----------
shift : int
the slice will start at the index `item + shift`
length : int
the length of the slice
stride : int
sub-sampling factor. Every `stride` datapoints `item` increases of `1`
Examples
--------
.. testcode::
import mimikit as mmk
slicer = mmk.AsSlice(shift=2, length=3)
data, item = list(range(10)), 2
# now use it like a function :
sliced = slicer(data, item)
print(sliced)
will output:
.. testoutput::
[4, 5, 6]
"""
shift: int = 0
length: int = 1
stride: int = 1
Expand Down Expand Up @@ -170,6 +229,9 @@ def __post_init__(self):
self.full_ds, self.train_ds, self.val_ds, self.test_ds = None, None, None, None

def prepare_data(self, *args, **kwargs):
"""
creates a db if necessary, instantiates a dataset and performs splits
"""
# get a db object (create it if necessary)
if isinstance(self.db, (str, os.PathLike)):
if not os.path.exists(self.db):
Expand Down
Loading

0 comments on commit b3299ee

Please sign in to comment.