Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 committed Feb 1, 2019
1 parent e57f591 commit 3e8086e
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 5 deletions.
4 changes: 4 additions & 0 deletions doc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_build
_static
doxyxml
tmp
19 changes: 19 additions & 0 deletions doc/Doxyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PROJECT_NAME = "DLR"
XML_OUTPUT = doxyxml
GENERATE_LATEX = NO
GENERATE_MAN = NO
GENERATE_RTF = NO
CASE_SENSE_NAMES = NO
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
PREDEFINED =
INPUT = ../include/ ../src/
EXAMPLE_PATH = ../
RECURSIVE = YES
QUIET = YES
JAVADOC_AUTOBRIEF = YES
SOURCE_BROWSER = YES
GENERATE_HTML = YES
GENERATE_XML = YES
HIDE_SCOPE_NAMES = YES
19 changes: 19 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
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)
7 changes: 7 additions & 0 deletions doc/c-api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=========
DLR C API
=========

.. doxygengroup:: c_api
:project: DLR
:content-only:
204 changes: 204 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- 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
from subprocess import call
import guzzle_sphinx_theme
sys.path.insert(0, os.path.abspath('../python'))


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

project = 'dlr'
copyright = '2019, AWS'
author = 'AWS'

# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = ''

# Run Doxygen first
call('doxygen; if [ -d tmp/dev ]; then rm -rf tmp; fi; mkdir tmp; mv html tmp/dev',
shell=True)

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

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# 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.intersphinx',
'sphinx.ext.imgmath',
'sphinx.ext.napoleon',
'breathe'
]

# Breathe extension variables
breathe_projects = {"DLR": "doxyxml/"}
breathe_default_project = "DLR"

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

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# 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 = ['_build', 'Thumbs.db', '.DS_Store']
html_extra_path = ['./tmp']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None


# -- 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_path = guzzle_sphinx_theme.html_theme_path()
html_theme = 'guzzle_sphinx_theme'

# Register the theme as an extension to generate a sitemap.xml
extensions.append("guzzle_sphinx_theme")

# Guzzle theme options (see theme.conf for more information)
html_theme_options = {
# Set the name of the project to appear in the sidebar
"project_nav_name": "DLR"
}

# 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']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
html_sidebars = {
'**': ['logo-text.html', 'globaltoc.html', 'searchbox.html']
}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'dlrdoc'


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'dlr.tex', 'dlr Documentation',
'AWS', 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'dlr', 'dlr Documentation',
[author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'dlr', 'dlr Documentation',
author, 'dlr', 'One line description of project.',
'Miscellaneous'),
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']


# -- Extension configuration -------------------------------------------------

# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'python': ('https://docs.python.org/3.7', None),
'numpy': ('http://docs.scipy.org/doc/numpy/', None),
'scipy': ('http://docs.scipy.org/doc/scipy/reference/', None)}
15 changes: 15 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
################################################
DLR: Compact Runtime for Machine Learning Models
################################################

********
Contents
********

.. toctree::
:maxdepth: 2
:titlesonly:

python-api
c-api
Internal docs <http://neo-ai-dlr.readthedocs.io/en/latest/dev/>
7 changes: 7 additions & 0 deletions doc/python-api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
==============
DLR Python API
==============

.. automodule:: dlr
:members:
:undoc-members:
7 changes: 7 additions & 0 deletions include/dlr.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ class DLRModel {

};

/*!
* \defgroup c_api
* C API of DLR
* \{
*/

/*!
\brief Handle for DLRModel.
Expand Down Expand Up @@ -229,6 +234,8 @@ extern "C" const char* DLRGetLastError();
*/
extern "C" int GetDLRBackend(DLRModelHandle* handle, const char** name);

/*! \} */

} // namespace dlr

#endif
9 changes: 9 additions & 0 deletions python/dlr/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# coding: utf-8
"""
DLR: Compact Runtime for Machine Learning Models
"""

from __future__ import absolute_import as _abs

from .api import DLRModel

__all__ = ['DLRModel']
48 changes: 43 additions & 5 deletions python/dlr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ class DLRError(Exception):


class DLRModel:
"""
Load a Neo-compiled model
Parameters
----------
model_path : str
Full path to the directory containing the compiled model
dev_type : str
Device type ('cpu', 'gpu', or 'opencl')
dev_id : int
Device ID
"""

def _check_call(self, ret):
"""
Expand Down Expand Up @@ -43,9 +55,9 @@ def _parse_backend(self):
byref(backend)))
return backend.value.decode('ascii')

def __init__(self, tar_path, dev_type='cpu', dev_id=0):
if not os.path.exists(tar_path):
raise ValueError("tar_path %s doesn't exist" % tar_path)
def __init__(self, model_path, dev_type='cpu', dev_id=0):
if not os.path.exists(model_path):
raise ValueError("model_path %s doesn't exist" % model_path)

self.handle = c_void_p()
libpath = os.path.join(os.path.dirname(
Expand All @@ -59,7 +71,7 @@ def __init__(self, tar_path, dev_type='cpu', dev_id=0):
}

self._check_call(self.lib.CreateDLRModel(byref(self.handle),
c_char_p(tar_path.encode()),
c_char_p(model_path.encode()),
c_int(device_table[dev_type]),
c_int(dev_id)))

Expand Down Expand Up @@ -87,7 +99,13 @@ def _get_num_inputs(self):
return num_inputs.value

def get_input_names(self):
"""Get all input_names"""
"""
Get all input names
Returns
-------
out : list of :py:class:`str`
"""
return self.input_names

def _get_input_name(self, index):
Expand Down Expand Up @@ -194,6 +212,26 @@ def _get_output(self, index):
return out

def run(self, input_values):
"""
Run inference with given input(s)
Parameters
----------
input_values : a single :py:class:`numpy.ndarray` or a dictionary
For decision tree models, provide a single :py:class:`numpy.ndarray`
to indicate a single input, as decision trees always accept only one
input.
For deep learning models, provide a dictionary where keys are input
names (of type :py:class:`str`) and values are input tensors (of type
:py:class:`numpy.ndarray`). Deep learning models allow more than one
input, so each input must have a unique name.
Returns
-------
out : :py:class:`numpy.ndarray`
Prediction result
"""
out = []
# set input(s)
if isinstance(input_values, (np.ndarray, np.generic)):
Expand Down

0 comments on commit 3e8086e

Please sign in to comment.