Commit 91570d04 authored by Paul's avatar Paul
Browse files

Add some documentation

parent e55dd8e9
...@@ -97,4 +97,5 @@ rocm_clang_tidy_check(rtg) ...@@ -97,4 +97,5 @@ rocm_clang_tidy_check(rtg)
target_include_directories(rtg PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>) target_include_directories(rtg PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
add_subdirectory(onnx) add_subdirectory(onnx)
add_subdirectory(doc)
add_subdirectory(test) add_subdirectory(test)
################################################################################
#
# MIT License
#
# Copyright (c) 2017 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################
include(CMakeParseArguments)
include(MainDoc)
find_program(DOXYGEN_EXECUTABLE NAMES doxygen
PATH_SUFFIXES bin
DOC "Doxygen documentation generator"
)
mark_as_advanced(DOXYGEN_EXECUTABLE)
find_path(DOT_EXECUTABLE NAMES dot
PATH_SUFFIXES bin
DOC "Graphviz"
)
mark_as_advanced(DOT_EXECUTABLE)
set(DOXYGEN_ARGS
ABBREVIATE_BRIEF
ALIASES
ALLEXTERNALS
ALLOW_UNICODE_NAMES
ALPHABETICAL_INDEX
ALWAYS_DETAILED_SEC
AUTOLINK_SUPPORT
BINARY_TOC
BRIEF_MEMBER_DESC
BUILTIN_STL_SUPPORT
CALLER_GRAPH
CALL_GRAPH
CASE_SENSE_NAMES
CHM_FILE
CHM_INDEX_ENCODING
CITE_BIB_FILES
CLANG_ASSISTED_PARSING
CLANG_OPTIONS
CLASS_DIAGRAMS
CLASS_GRAPH
COLLABORATION_GRAPH
COLS_IN_ALPHA_INDEX
COMPACT_LATEX
COMPACT_RTF
CPP_CLI_SUPPORT
CREATE_SUBDIRS
DIAFILE_DIRS
DIA_PATH
DIRECTORY_GRAPH
DISABLE_INDEX
DISTRIBUTE_GROUP_DOC
DOCBOOK_OUTPUT
DOCBOOK_PROGRAMLISTING
DOCSET_BUNDLE_ID
DOCSET_FEEDNAME
DOCSET_PUBLISHER_ID
DOCSET_PUBLISHER_NAME
DOTFILE_DIRS
DOT_CLEANUP
DOT_FONTNAME
DOT_FONTPATH
DOT_FONTSIZE
DOT_GRAPH_MAX_NODES
DOT_IMAGE_FORMAT
DOT_MULTI_TARGETS
DOT_NUM_THREADS
# DOT_PATH
DOT_TRANSPARENT
DOXYFILE_ENCODING
ECLIPSE_DOC_ID
ENABLED_SECTIONS
ENABLE_PREPROCESSING
ENUM_VALUES_PER_LINE
EXAMPLE_PATH
EXAMPLE_PATTERNS
EXAMPLE_RECURSIVE
EXCLUDE
EXCLUDE_PATTERNS
EXCLUDE_SYMBOLS
EXCLUDE_SYMLINKS
EXPAND_AS_DEFINED
EXPAND_ONLY_PREDEF
EXTENSION_MAPPING
EXTERNAL_GROUPS
EXTERNAL_PAGES
EXTERNAL_SEARCH
EXTERNAL_SEARCH_ID
EXTRACT_ALL
EXTRACT_ANON_NSPACES
EXTRACT_LOCAL_CLASSES
EXTRACT_LOCAL_METHODS
EXTRACT_PACKAGE
EXTRACT_PRIVATE
EXTRACT_STATIC
EXTRA_PACKAGES
EXTRA_SEARCH_MAPPINGS
EXT_LINKS_IN_WINDOW
FILE_PATTERNS
FILE_VERSION_FILTER
FILTER_PATTERNS
FILTER_SOURCE_FILES
FILTER_SOURCE_PATTERNS
FORCE_LOCAL_INCLUDES
FORMULA_FONTSIZE
FORMULA_TRANSPARENT
FULL_PATH_NAMES
GENERATE_AUTOGEN_DEF
GENERATE_BUGLIST
GENERATE_CHI
GENERATE_DEPRECATEDLIST
GENERATE_DOCBOOK
GENERATE_DOCSET
GENERATE_ECLIPSEHELP
GENERATE_HTML
GENERATE_HTMLHELP
GENERATE_LATEX
GENERATE_LEGEND
GENERATE_MAN
GENERATE_PERLMOD
GENERATE_QHP
GENERATE_RTF
GENERATE_TAGFILE
GENERATE_TESTLIST
GENERATE_TODOLIST
GENERATE_TREEVIEW
GENERATE_XML
GRAPHICAL_HIERARCHY
GROUP_GRAPHS
GROUP_NESTED_COMPOUNDS
# HAVE_DOT
HHC_LOCATION
HIDE_COMPOUND_REFERENCE
HIDE_FRIEND_COMPOUNDS
HIDE_IN_BODY_DOCS
HIDE_SCOPE_NAMES
HIDE_UNDOC_CLASSES
HIDE_UNDOC_MEMBERS
HIDE_UNDOC_RELATIONS
HTML_COLORSTYLE_GAMMA
HTML_COLORSTYLE_HUE
HTML_COLORSTYLE_SAT
HTML_DYNAMIC_SECTIONS
HTML_EXTRA_FILES
HTML_EXTRA_STYLESHEET
HTML_FILE_EXTENSION
HTML_FOOTER
HTML_HEADER
HTML_INDEX_NUM_ENTRIES
HTML_OUTPUT
HTML_STYLESHEET
HTML_TIMESTAMP
IDL_PROPERTY_SUPPORT
IGNORE_PREFIX
IMAGE_PATH
INCLUDED_BY_GRAPH
INCLUDE_FILE_PATTERNS
INCLUDE_GRAPH
INCLUDE_PATH
INHERIT_DOCS
INLINE_GROUPED_CLASSES
INLINE_INFO
INLINE_INHERITED_MEMB
INLINE_SIMPLE_STRUCTS
INLINE_SOURCES
INPUT
INPUT_ENCODING
INPUT_FILTER
INTERACTIVE_SVG
INTERNAL_DOCS
JAVADOC_AUTOBRIEF
LATEX_BATCHMODE
LATEX_BIB_STYLE
LATEX_CMD_NAME
LATEX_EXTRA_FILES
LATEX_EXTRA_STYLESHEET
LATEX_FOOTER
LATEX_HEADER
LATEX_HIDE_INDICES
LATEX_OUTPUT
LATEX_SOURCE_CODE
LATEX_TIMESTAMP
LAYOUT_FILE
LOOKUP_CACHE_SIZE
MACRO_EXPANSION
MAKEINDEX_CMD_NAME
MAN_EXTENSION
MAN_LINKS
MAN_OUTPUT
MAN_SUBDIR
MARKDOWN_SUPPORT
MATHJAX_CODEFILE
MATHJAX_EXTENSIONS
MATHJAX_FORMAT
MATHJAX_RELPATH
MAX_DOT_GRAPH_DEPTH
MAX_INITIALIZER_LINES
MSCFILE_DIRS
MSCGEN_PATH
MULTILINE_CPP_IS_BRIEF
OPTIMIZE_FOR_FORTRAN
OPTIMIZE_OUTPUT_FOR_C
OPTIMIZE_OUTPUT_JAVA
OPTIMIZE_OUTPUT_VHDL
OUTPUT_DIRECTORY
OUTPUT_LANGUAGE
PAPER_TYPE
PDF_HYPERLINKS
PERLMOD_LATEX
PERLMOD_MAKEVAR_PREFIX
PERLMOD_PRETTY
PERL_PATH
PLANTUML_CFG_FILE
PLANTUML_INCLUDE_PATH
PLANTUML_JAR_PATH
PREDEFINED
PROJECT_BRIEF
PROJECT_LOGO
PROJECT_NAME
PROJECT_NUMBER
QCH_FILE
QHG_LOCATION
QHP_CUST_FILTER_ATTRS
QHP_CUST_FILTER_NAME
QHP_NAMESPACE
QHP_SECT_FILTER_ATTRS
QHP_VIRTUAL_FOLDER
QT_AUTOBRIEF
QUIET
RECURSIVE
REFERENCED_BY_RELATION
REFERENCES_LINK_SOURCE
REFERENCES_RELATION
REPEAT_BRIEF
RTF_EXTENSIONS_FILE
RTF_HYPERLINKS
RTF_OUTPUT
RTF_SOURCE_CODE
RTF_STYLESHEET_FILE
SEARCHDATA_FILE
SEARCHENGINE
SEARCHENGINE_URL
SEARCH_INCLUDES
SEPARATE_MEMBER_PAGES
SERVER_BASED_SEARCH
SHORT_NAMES
SHOW_FILES
SHOW_GROUPED_MEMB_INC
SHOW_INCLUDE_FILES
SHOW_NAMESPACES
SHOW_USED_FILES
SIP_SUPPORT
SKIP_FUNCTION_MACROS
SORT_BRIEF_DOCS
SORT_BY_SCOPE_NAME
SORT_GROUP_NAMES
SORT_MEMBERS_CTORS_1ST
SORT_MEMBER_DOCS
SOURCE_BROWSER
SOURCE_TOOLTIPS
STRICT_PROTO_MATCHING
STRIP_CODE_COMMENTS
STRIP_FROM_INC_PATH
STRIP_FROM_PATH
SUBGROUPING
TAB_SIZE
TAGFILES
TCL_SUBST
TEMPLATE_RELATIONS
TOC_EXPAND
TOC_INCLUDE_HEADINGS
TREEVIEW_WIDTH
TYPEDEF_HIDES_STRUCT
UML_LIMIT_NUM_FIELDS
UML_LOOK
USE_HTAGS
USE_MATHJAX
USE_MDFILE_AS_MAINPAGE
USE_PDFLATEX
VERBATIM_HEADERS
WARNINGS
WARN_AS_ERROR
WARN_FORMAT
WARN_IF_DOC_ERROR
WARN_IF_UNDOCUMENTED
WARN_LOGFILE
WARN_NO_PARAMDOC
XML_OUTPUT
XML_PROGRAMLISTING
)
set(DOXYGEN_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/doxygen/doxygen.conf" CACHE PATH "Path to generated doxygen configuration file")
function(add_doxygen_doc)
set(options)
set(oneValueArgs)
set(multiValueArgs DEPENDS ${DOXYGEN_ARGS})
cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
file(WRITE ${DOXYGEN_CONFIG_FILE} "# Auto-generated doxygen configuration file\n")
foreach(ARG ${DOXYGEN_ARGS})
if(PARSE_${ARG})
string(REPLACE ";" " " ARG_VALUE "${PARSE_${ARG}}")
file(APPEND ${DOXYGEN_CONFIG_FILE} "\n${ARG} = ${ARG_VALUE}\n")
endif()
endforeach()
if(PARSE_OUTPUT_DIRECTORY)
if(NOT EXISTS ${PARSE_OUTPUT_DIRECTORY})
file(MAKE_DIRECTORY ${PARSE_OUTPUT_DIRECTORY})
endif()
endif()
if(DOT_EXECUTABLE)
file(APPEND ${DOXYGEN_CONFIG_FILE} "\nDOT_PATH = \"${DOT_EXECUTABLE}\"\n")
file(APPEND ${DOXYGEN_CONFIG_FILE} "\nHAVE_DOT = YES\n")
else()
file(APPEND ${DOXYGEN_CONFIG_FILE} "\nHAVE_DOT = NO\n")
endif()
add_custom_target(doxygen
${DOXYGEN_EXECUTABLE} ${DOXYGEN_CONFIG_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building documentation with doxygen"
)
if(PARSE_OUTPUT_DIRECTORY)
clean_doc_output(${PARSE_OUTPUT_DIRECTORY})
endif()
mark_as_doc(doxygen)
if(PARSE_DEPENDS)
add_dependencies(doxygen ${PARSE_DEPENDS})
endif()
endfunction()
################################################################################
#
# MIT License
#
# Copyright (c) 2017 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################
if(NOT TARGET doc)
add_custom_target(doc)
endif()
function(mark_as_doc)
add_dependencies(doc ${ARGN})
endfunction()
function(clean_doc_output DIR)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${DIR})
endfunction()
################################################################################
#
# MIT License
#
# Copyright (c) 2017 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################
include(CMakeParseArguments)
include(MainDoc)
include(DoxygenDoc)
find_program(SPHINX_EXECUTABLE NAMES sphinx-build
HINTS
$ENV{SPHINX_DIR}
PATH_SUFFIXES bin
DOC "Sphinx documentation generator"
)
mark_as_advanced(SPHINX_EXECUTABLE)
set(BINARY_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/sphinx/_build")
# Sphinx cache with pickled ReST documents
set(SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/sphinx/_doctrees")
# HTML output directory
set(SPHINX_DEFAULT_HTML_DIR "${CMAKE_CURRENT_BINARY_DIR}/sphinx/html")
function(add_sphinx_doc SRC_DIR)
set(options)
set(oneValueArgs BUILDER OUTPUT_DIR)
set(multiValueArgs DEPENDS VARS TEMPLATE_VARS)
cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
string(TOUPPER ${PARSE_BUILDER} BUILDER)
set(ADDITIONAL_ARGS)
foreach(VAR ${PARSE_VARS})
list(APPEND ADDITIONAL_ARGS -D ${VAR})
endforeach()
foreach(VAR ${PARSE_TEMPLATE_VARS})
list(APPEND ADDITIONAL_ARGS -A ${VAR})
endforeach()
if(PARSE_OUTPUT_DIR)
get_filename_component(OUTPUT_DIR ${PARSE_OUTPUT_DIR} ABSOLUTE)
set(SPHINX_${BUILDER}_DIR ${OUTPUT_DIR} CACHE PATH "Path to ${PARSE_BUILDER} output")
else()
set(SPHINX_${BUILDER}_DIR "${CMAKE_CURRENT_BINARY_DIR}/sphinx/${PARSE_BUILDER}" CACHE PATH "Path to ${PARSE_BUILDER} output")
endif()
add_custom_target(sphinx-${BUILDER}
${SPHINX_EXECUTABLE}
-b ${PARSE_BUILDER}
-d "${SPHINX_CACHE_DIR}"
${ADDITIONAL_ARGS}
"${SRC_DIR}"
"${SPHINX_${BUILDER}_DIR}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building ${PARSE_BUILDER} documentation with Sphinx"
)
clean_doc_output(${SPHINX_${BUILDER}_DIR})
clean_doc_output(${SPHINX_CACHE_DIR})
clean_doc_output(${BINARY_BUILD_DIR})
mark_as_doc(sphinx-${BUILDER})
if(PARSE_DEPENDS)
add_dependencies(sphinx-${BUILDER} ${PARSE_DEPENDS})
endif()
endfunction()
...@@ -7,14 +7,22 @@ ...@@ -7,14 +7,22 @@
namespace rtg { namespace rtg {
/**
* @brief Arguments passed to instructions
*
* An `argument` can represent a raw buffer of data that either be referenced from another element or it can be owned by the argument.
*
*/
struct argument : raw_data<argument> struct argument : raw_data<argument>
{ {
argument() {} argument() {}
argument(shape s, std::function<char*()> d) : data(d), m_shape(s) {} argument(shape s, std::function<char*()> d) : data(d), m_shape(s) {}
/// Provides a raw pointer to the data
std::function<char*()> data; std::function<char*()> data;
/// Whether data is available
bool empty() const { return not data; } bool empty() const { return not data; }
const shape& get_shape() const { return this->m_shape; } const shape& get_shape() const { return this->m_shape; }
......
...@@ -3,12 +3,26 @@ ...@@ -3,12 +3,26 @@
namespace rtg { namespace rtg {
/**
* @brief Erase all elements from a container
*
* @param r The container to erase elements from
* @param value The value to be erased
* @return Returns iterator to erased element
*/
template <class R, class T> template <class R, class T>
auto erase(R&& r, const T& value) auto erase(R&& r, const T& value)
{ {
return r.erase(std::remove(r.begin(), r.end(), value), r.end()); return r.erase(std::remove(r.begin(), r.end(), value), r.end());
} }
/**
* @brief Erase all elements from a container
*
* @param r The container to erase elements from
* @param pred Predicate function that selects which elements should be erased.
* @return Returns iterator to erased element
*/
template <class R, class P> template <class R, class P>
auto erase_if(R&& r, P&& pred) auto erase_if(R&& r, P&& pred)
{ {
......
...@@ -7,21 +7,40 @@ ...@@ -7,21 +7,40 @@
namespace rtg { namespace rtg {
/// Represents exceptions that can be thrown by rtglib
struct exception : std::runtime_error struct exception : std::runtime_error
{ {
exception(std::string msg = "") : std::runtime_error(msg) {} exception(std::string msg = "") : std::runtime_error(msg) {}
}; };
/**
* @brief Create an exception object
*
* @param context A message that says where the exception occurred
* @param message
* @return Exceptions
*/
inline exception make_exception(std::string context, std::string message = "") inline exception make_exception(std::string context, std::string message = "")
{ {
return {context + ": " + message}; return {context + ": " + message};
} }
/**
* @brief Create a message of a file location
*
* @param file The filename
* @param line The line number
*
* @return A string that represents the file location
*/
inline std::string make_source_context(const std::string& file, int line) inline std::string make_source_context(const std::string& file, int line)
{ {
return file + ":" + std::to_string(line); return file + ":" + std::to_string(line);
} }
/**
* @brief Throw an exception with context information
*/
#define RTG_THROW(...) \ #define RTG_THROW(...) \
throw rtg::make_exception(rtg::make_source_context(__FILE__, __LINE__), __VA_ARGS__) throw rtg::make_exception(rtg::make_source_context(__FILE__, __LINE__), __VA_ARGS__)
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
namespace rtg { namespace rtg {
/**
* @brief Represents a raw literal
* @details This stores the literal has a raw buffer that is owned by this class
*/
struct literal : raw_data<literal> struct literal : raw_data<literal>
{ {
literal() {} literal() {}
...@@ -44,12 +48,15 @@ struct literal : raw_data<literal> ...@@ -44,12 +48,15 @@ struct literal : raw_data<literal>
literal(shape s, const char* x) : buffer(x, x + s.bytes()), m_shape(s) {} literal(shape s, const char* x) : buffer(x, x + s.bytes()), m_shape(s) {}
/// Whether data is available
bool empty() const { return this->buffer.empty(); } bool empty() const { return this->buffer.empty(); }
/// Provides a raw pointer to the data
const char* data() const { return this->buffer.data(); } const char* data() const { return this->buffer.data(); }
const shape& get_shape() const { return this->m_shape; } const shape& get_shape() const { return this->m_shape; }
/// Convert the data to an argument
argument get_argument() const argument get_argument() const
{ {
auto b = buffer; auto b = buffer;
......
...@@ -14,6 +14,9 @@ namespace rtg { ...@@ -14,6 +14,9 @@ namespace rtg {
struct program_impl; struct program_impl;
/**
* @brief Stores the instruction stream
*/
struct program struct program
{ {
program(); program();
......
...@@ -6,6 +6,13 @@ ...@@ -6,6 +6,13 @@
namespace rtg { namespace rtg {
/**
* @brief Provides a base class for common operations with raw buffer
*
* For classes that handle a raw buffer of data, this will provide common operations such as equals, printing, and visitors.
* To use this class the derived class needs to provide a `data()` method to retrieve a raw pointer to the data, and `get_shape` method that provides the shape of the data.
*
*/
template <class Derived> template <class Derived>
struct raw_data struct raw_data
{ {
...@@ -37,6 +44,12 @@ struct raw_data ...@@ -37,6 +44,12 @@ struct raw_data
return os; return os;
} }
/**
* @brief Visits a single data element at a certain index.
*
* @param v A function which will be called with the type of data
* @param n The index to read from
*/
template <class Visitor> template <class Visitor>
void visit_at(Visitor v, std::size_t n = 0) const void visit_at(Visitor v, std::size_t n = 0) const
{ {
...@@ -45,6 +58,13 @@ struct raw_data ...@@ -45,6 +58,13 @@ struct raw_data
s.visit_type([&](auto as) { v(*(as.from(buffer) + s.index(n))); }); s.visit_type([&](auto as) { v(*(as.from(buffer) + s.index(n))); });
} }
/**
* @brief Visits the data
*
* This will call the visitor function with a `tensor_view<T>` based on the shape of the data.
*
* @param v A function to be called with `tensor_view<T>`
*/
template <class Visitor> template <class Visitor>
void visit(Visitor v) const void visit(Visitor v) const
{ {
...@@ -59,6 +79,14 @@ struct raw_data ...@@ -59,6 +79,14 @@ struct raw_data
return s.elements() == 1; return s.elements() == 1;
} }
/**
* @brief Retrieves a single element of data
* @details [long description]
*
* @param n The index to retrieve the data from
* @tparam T The type of data to be retrieved
* @return The element as `T`
*/
template <class T> template <class T>
T at(std::size_t n = 0) const T at(std::size_t n = 0) const
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment