Skip to content
Snippets Groups Projects
Commit 3f24f857 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[data_loaders] Added missing doc and fixed doc related warnings

Also fixed import warnings
parent a5eb55f5
No related branches found
No related tags found
2 merge requests!17Merge development branch 1.5.x,!13Improve documentation
...@@ -25,28 +25,30 @@ ...@@ -25,28 +25,30 @@
# # # #
############################################################################### ###############################################################################
"""
============
data_loaders
============
import time This module implements all the data communication related classes
import logging """
logger = logging.getLogger(__name__)
from functools import reduce
import logging
import six import six
import zmq
from .data import mixDataIndices from .data import mixDataIndices
logger = logging.getLogger(__name__)
#---------------------------------------------------------- # ----------------------------------------------------------
class DataView(object): class DataView(object):
"""Provides access to a subset of data from a group of inputs synchronized """Provides access to a subset of data from a group of inputs synchronized
together together
Data views are created from a data loader (see :py:class:`DataLoader`), which are Data views are created from a data loader (see :py:class:`DataLoader`),
provided to the algorithms of types 'sequential' and 'autonomous' which are provided to the algorithms of types 'sequential' and 'autonomous'
(see :py:class:`DataLoaderList`). (see :py:class:`DataLoaderList`).
Example: Example:
...@@ -109,6 +111,18 @@ class DataView(object): ...@@ -109,6 +111,18 @@ class DataView(object):
def count(self, input_name=None): def count(self, input_name=None):
"""Returns the number of available data indexes for the given input
name. If none given the number of available data units.
Parameters:
input_name (str): Name of the input for which the count is
requested
Returns:
(int): Number of data indexes for the input given or the number of
data units.
"""
if input_name is not None: if input_name is not None:
try: try:
return len(self.infos[input_name]['data_indices']) return len(self.infos[input_name]['data_indices'])
...@@ -139,7 +153,7 @@ class DataView(object): ...@@ -139,7 +153,7 @@ class DataView(object):
return (result, indices[0], indices[1]) return (result, indices[0], indices[1])
#---------------------------------------------------------- # ----------------------------------------------------------
class DataLoader(object): class DataLoader(object):
...@@ -205,10 +219,25 @@ class DataLoader(object): ...@@ -205,10 +219,25 @@ class DataLoader(object):
def input_names(self): def input_names(self):
"""Returns the name of all inputs associated to this data loader"""
return self.infos.keys() return self.infos.keys()
def count(self, input_name=None): def count(self, input_name=None):
"""Returns the number of available data indexes for the given input
name. If none given the number of available data units.
Parameters:
input_name (str): Name of the input for which the count is
requested
Returns:
(int): Number of data indexes for the input given or the number of
data units.
"""
if input_name is not None: if input_name is not None:
try: try:
return len(self.infos[input_name]['data_indices']) return len(self.infos[input_name]['data_indices'])
...@@ -219,6 +248,17 @@ class DataLoader(object): ...@@ -219,6 +248,17 @@ class DataLoader(object):
def view(self, input_name, index): def view(self, input_name, index):
""" Returns the view associated with this data loader
Parameters:
input_name (str): Name of the input to get data from
index (int): Position of the data indexes to retrieve
Returns:
(:py:class:`DataView`) either a DataView matching the query or None
"""
if index < 0: if index < 0:
return None return None
...@@ -254,7 +294,7 @@ class DataLoader(object): ...@@ -254,7 +294,7 @@ class DataLoader(object):
return (result, indices[0], indices[1]) return (result, indices[0], indices[1])
#---------------------------------------------------------- # ----------------------------------------------------------
class DataLoaderList(object): class DataLoaderList(object):
...@@ -341,6 +381,8 @@ class DataLoaderList(object): ...@@ -341,6 +381,8 @@ class DataLoaderList(object):
def loaderOf(self, input_name): def loaderOf(self, input_name):
"""Returns the data loader matching the input name"""
try: try:
return [ k for k in self._loaders if input_name in k.input_names() ][0] return [ k for k in self._loaders if input_name in k.input_names() ][0]
except: except:
...@@ -348,6 +390,8 @@ class DataLoaderList(object): ...@@ -348,6 +390,8 @@ class DataLoaderList(object):
def secondaries(self): def secondaries(self):
"""Returns a list of all data loaders except the main one"""
secondaries_list = DataLoaderList() secondaries_list = DataLoaderList()
for data_loader in self._loaders: for data_loader in self._loaders:
if data_loader is not self.main_loader: if data_loader is not self.main_loader:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment