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 17See ./random_fourier_features.py for a concrete instantiation of this class. 18""" 19from __future__ import absolute_import 20from __future__ import division 21from __future__ import print_function 22 23import abc 24 25import six 26 27 28class InvalidShapeError(Exception): 29 """Exception thrown when a tensor's shape deviates from an expected shape.""" 30 31 32@six.add_metaclass(abc.ABCMeta) 33class 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 39 @abc.abstractmethod 40 def map(self, input_tensor): 41 """Main Dense-Tensor-In-Dense-Tensor-Out (DTIDTO) map method. 42 43 Should be implemented by subclasses. 44 Args: 45 input_tensor: The dense input tensor to be mapped using the (approximate) 46 kernel mapper. 47 """ 48 raise NotImplementedError('map is not implemented for {}.'.format(self)) 49 50 @abc.abstractproperty 51 def name(self): 52 """Returns the name of the kernel mapper.""" 53 pass 54 55 @abc.abstractproperty 56 def output_dim(self): 57 """Returns the output dimension of the mapping.""" 58 pass 59