Home | History | Annotate | Download | only in mappers
      1 # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #     http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 # ==============================================================================
     15 """API class for dense (approximate) kernel mappers.
     16 
     17 See ./random_fourier_features.py for a concrete instantiation of this class.
     18 """
     19 from __future__ import absolute_import
     20 from __future__ import division
     21 from __future__ import print_function
     22 
     23 import abc
     24 
     25 import six
     26 
     27 
     28 class InvalidShapeError(Exception):
     29   """Exception thrown when a tensor's shape deviates from an expected shape."""
     30 
     31 
     32 @six.add_metaclass(abc.ABCMeta)
     33 class DenseKernelMapper(object):
     34   """Abstract class for a kernel mapper that maps dense inputs to dense outputs.
     35 
     36   This class is abstract. Users should not create instances of this class.
     37   """
     38   __metaclass__ = abc.ABCMeta
     39 
     40   @abc.abstractmethod
     41   def map(self, input_tensor):
     42     """Main Dense-Tensor-In-Dense-Tensor-Out (DTIDTO) map method.
     43 
     44     Should be implemented by subclasses.
     45     Args:
     46       input_tensor: The dense input tensor to be mapped using the (approximate)
     47       kernel mapper.
     48     """
     49     raise NotImplementedError('map is not implemented for {}.'.format(self))
     50 
     51   @abc.abstractproperty
     52   def name(self):
     53     """Returns the name of the kernel mapper."""
     54     pass
     55 
     56   @abc.abstractproperty
     57   def output_dim(self):
     58     """Returns the output dimension of the mapping."""
     59     pass
     60