00001
00002
00003 __copyright__ = """
00004 Copyright 2008 Sean Ross-Ross
00005 """
00006 __license__ = """
00007 This file is part of SLIMpy .
00008
00009 SLIMpy is free software: you can redistribute it and/or modify
00010 it under the terms of the GNU Lesser General Public License as published by
00011 the Free Software Foundation, either version 3 of the License, or
00012 (at your option) any later version.
00013
00014 SLIMpy is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 GNU Lesser General Public License for more details.
00018
00019 You should have received a copy of the GNU Lesser General Public License
00020 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00021 """
00022
00023
00024 from slimpy_base.api.linearops.MatMult import MatMult
00025 from slimpy_base.api.functions.scalar_functions import real_if_close
00026
00027
00028
00029
00030
00031
00032
00033 def inner_product( vec1, vec2 ):
00034 """
00035 inner_product( vec1, vec2 ) -> scalar
00036 take the inner product of two vectors
00037 """
00038 l1 = len( vec1.space )
00039 l2 = len( vec2.space )
00040
00041 tmp_vec1 = vec1.reshape( l1, 1 )
00042 tmp_vec2 = vec2.reshape( l2, 1 )
00043
00044 mat = MatMult(tmp_vec1.space, tmp_vec2)
00045
00046 inner_prod = mat * tmp_vec1
00047
00048
00049 return real_if_close( inner_prod[0] )
00050
00051
00052
00053
00054
00055
00056
00057
00058 def outer_product(vec1,vec2):
00059 """
00060 inner_product( vec1, vec2 ) -> scalar
00061 take the inner product of two vectors
00062 """
00063 raise NotImplementedError()