Skip to content

Commit

Permalink
Added new localColorInnerProduct within PETE and associated support
Browse files Browse the repository at this point in the history
routines.
  • Loading branch information
grokqcd committed Nov 1, 2018
1 parent 721956a commit f44cd1a
Show file tree
Hide file tree
Showing 16 changed files with 468 additions and 13 deletions.
10 changes: 10 additions & 0 deletions PETE/QDPOps.in
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,16 @@ binaryOps
@return (real(trace(adj(l)*r))
@ingroup group1
@relates QDPType */"
-----
TAG = "FnLocalColorInnerProduct"
FUNCTION = "localColorInnerProduct"
EXPR = "return (localColorInnerProduct(a,b));"
COMMENTA = "//! InnerProduct on only color fiber indices"
COMMENTB = "/*! L2 norm only color fiber indices
@sa adj(), trace()
@return (traceColor(adj(l)*r)
@ingroup group1
@relates QDPType */"
-----
TAG = "FnQuarkContract13"
FUNCTION = "quarkContract13"
Expand Down
35 changes: 32 additions & 3 deletions examples/t_basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ int main(int argc, char *argv[])
LatticeFermion lftmp1;
LatticeFermion lftmp2;
LatticeFermion lftmp3;
LatticeColorVectorSpinMatrix lcvsp1;
LatticeColorVectorSpinMatrix lcvsp2;
LatticeReal R1;
LatticeReal Rtmp;
LatticeComplex c;
Expand Down Expand Up @@ -147,7 +149,7 @@ int main(int argc, char *argv[])
pop(xml_out);


#if 0
#if 1

mu = 0;
nu = 1;
Expand Down Expand Up @@ -181,7 +183,7 @@ int main(int argc, char *argv[])
pop(xml_out);

/* test 5 */
rtmp = real(trace(lctmp1 * u));
LatticeReal rtmp = real(trace(lctmp1 * u));
push(xml_out,"TRACE_MULTIPLY_MATRIX_realpart");
write(xml_out, "rtmp", rtmp);
pop(xml_out);
Expand Down Expand Up @@ -391,7 +393,7 @@ int main(int argc, char *argv[])

/* test 27 */
gaussian(lqtmp1);
r = real(trace(adj(q) * lqtmp1));
LatticeReal r = real(trace(adj(q) * lqtmp1));
push(xml_out,"TRACE_MULT_PROP");
write(xml_out, "r", r);
pop(xml_out);
Expand All @@ -406,6 +408,33 @@ int main(int argc, char *argv[])
write(xml_out, "lqtmp24", quarkContract24(lqtmp1, lqtmp2));
pop(xml_out);

#if 1
/* test 29 */
gaussian(lcvsp1);
gaussian(lcvsp2);
//LatticeSpinMatrix spm = localColorInnerProduct(lcvsp1, lcvsp2);
auto spm = localColorInnerProduct(lcvsp1, lcvsp2);
push(xml_out,"LOCAL_COLOR_INNER_PRODUCT");
write(xml_out, "spm", spm);
pop(xml_out);

/* test 30 */
gaussian(lcvsp1);
gaussian(lcvsp2);
multi1d<SpinMatrixD> fred1 = sumMulti(spm, QDP::rb);
push(xml_out,"SUMMULTI_LOCAL_COLOR_INNER_PRODUCT1");
write(xml_out, "fred1", fred1);
pop(xml_out);

/* test 31 */
gaussian(lcvsp1);
gaussian(lcvsp2);
multi1d<SpinMatrixD> fred2 = sumMulti(localColorInnerProduct(lcvsp1, lcvsp2), QDP::rb);
push(xml_out,"SUMMULTI_LOCAL_COLOR_INNER_PRODUCT2");
write(xml_out, "fred2", fred2);
pop(xml_out);
#endif

#endif


Expand Down
146 changes: 146 additions & 0 deletions include/QDPOperators.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// -*- C++ -*-
// $Id: Header.h,v 1.3 2002-10-14 02:06:56 edwards Exp $

/*! @file
* @brief Bulk of QDP operators produced by PETE
Expand Down Expand Up @@ -461,6 +462,17 @@ struct FnLocalInnerProductReal
}
};

struct FnLocalColorInnerProduct
{
PETE_EMPTY_CONSTRUCTORS(FnLocalColorInnerProduct)
template<class T1, class T2>
inline typename BinaryReturn<T1, T2, FnLocalColorInnerProduct >::Type_t
operator()(const T1 &a, const T2 &b) const
{
return (localColorInnerProduct(a,b));
}
};

struct FnQuarkContract13
{
PETE_EMPTY_CONSTRUCTORS(FnQuarkContract13)
Expand Down Expand Up @@ -1635,6 +1647,28 @@ localInnerProductReal(const QDPType<T1,C1> & l,const QDPType<T2,C2> & r)
CreateLeaf<QDPType<T2,C2> >::make(r)));
}

//! InnerProduct on only color fiber indices
/*! L2 norm only color fiber indices
@sa adj(), trace()
@return (traceColor(adj(l)*r)
@ingroup group1
@relates QDPType */
template<class T1,class C1,class T2,class C2>
inline typename MakeReturn<BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPType<T1,C1> >::Leaf_t,
typename CreateLeaf<QDPType<T2,C2> >::Leaf_t>,
typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t >::Expression_t
localColorInnerProduct(const QDPType<T1,C1> & l,const QDPType<T2,C2> & r)
{
typedef BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPType<T1,C1> >::Leaf_t,
typename CreateLeaf<QDPType<T2,C2> >::Leaf_t> Tree_t;
typedef typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t Container_t;
return MakeReturn<Tree_t,Container_t>::make(Tree_t(
CreateLeaf<QDPType<T1,C1> >::make(l),
CreateLeaf<QDPType<T2,C2> >::make(r)));
}

//! Contraction for quark propagators
/*!
epsilon contract 2 quark propagators and return a quark propagator.
Expand Down Expand Up @@ -2401,6 +2435,22 @@ localInnerProductReal(const QDPType<T1,C1> & l,const QDPExpr<T2,C2> & r)
CreateLeaf<QDPExpr<T2,C2> >::make(r)));
}

template<class T1,class C1,class T2,class C2>
inline typename MakeReturn<BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPType<T1,C1> >::Leaf_t,
typename CreateLeaf<QDPExpr<T2,C2> >::Leaf_t>,
typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t >::Expression_t
localColorInnerProduct(const QDPType<T1,C1> & l,const QDPExpr<T2,C2> & r)
{
typedef BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPType<T1,C1> >::Leaf_t,
typename CreateLeaf<QDPExpr<T2,C2> >::Leaf_t> Tree_t;
typedef typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t Container_t;
return MakeReturn<Tree_t,Container_t>::make(Tree_t(
CreateLeaf<QDPType<T1,C1> >::make(l),
CreateLeaf<QDPExpr<T2,C2> >::make(r)));
}

template<class T1,class C1,class T2,class C2>
inline typename MakeReturn<BinaryNode<FnQuarkContract13,
typename CreateLeaf<QDPType<T1,C1> >::Leaf_t,
Expand Down Expand Up @@ -2945,6 +2995,22 @@ localInnerProductReal(const QDPExpr<T1,C1> & l,const QDPType<T2,C2> & r)
CreateLeaf<QDPType<T2,C2> >::make(r)));
}

template<class T1,class C1,class T2,class C2>
inline typename MakeReturn<BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPExpr<T1,C1> >::Leaf_t,
typename CreateLeaf<QDPType<T2,C2> >::Leaf_t>,
typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t >::Expression_t
localColorInnerProduct(const QDPExpr<T1,C1> & l,const QDPType<T2,C2> & r)
{
typedef BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPExpr<T1,C1> >::Leaf_t,
typename CreateLeaf<QDPType<T2,C2> >::Leaf_t> Tree_t;
typedef typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t Container_t;
return MakeReturn<Tree_t,Container_t>::make(Tree_t(
CreateLeaf<QDPExpr<T1,C1> >::make(l),
CreateLeaf<QDPType<T2,C2> >::make(r)));
}

template<class T1,class C1,class T2,class C2>
inline typename MakeReturn<BinaryNode<FnQuarkContract13,
typename CreateLeaf<QDPExpr<T1,C1> >::Leaf_t,
Expand Down Expand Up @@ -3489,6 +3555,22 @@ localInnerProductReal(const QDPType<T1,C1> & l,const typename WordType<C1>::Type
CreateLeaf<typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t >::make(typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t(r))));
}

template<class T1,class C1>
inline typename MakeReturn<BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPType<T1,C1> >::Leaf_t,
typename CreateLeaf<typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t >::Leaf_t>,
typename BinaryReturn<C1,typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t,FnLocalColorInnerProduct>::Type_t >::Expression_t
localColorInnerProduct(const QDPType<T1,C1> & l,const typename WordType<C1>::Type_t & r)
{
typedef BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPType<T1,C1> >::Leaf_t,
typename CreateLeaf<typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t >::Leaf_t> Tree_t;
typedef typename BinaryReturn<C1,typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t,FnLocalColorInnerProduct>::Type_t Container_t;
return MakeReturn<Tree_t,Container_t>::make(Tree_t(
CreateLeaf<QDPType<T1,C1> >::make(l),
CreateLeaf<typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t >::make(typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t(r))));
}

template<class T1,class C1>
inline typename MakeReturn<BinaryNode<FnQuarkContract13,
typename CreateLeaf<QDPType<T1,C1> >::Leaf_t,
Expand Down Expand Up @@ -4033,6 +4115,22 @@ localInnerProductReal(const typename WordType<C2>::Type_t & l,const QDPType<T2,C
CreateLeaf<QDPType<T2,C2> >::make(r)));
}

template<class T2,class C2>
inline typename MakeReturn<BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t >::Leaf_t,
typename CreateLeaf<QDPType<T2,C2> >::Leaf_t>,
typename BinaryReturn<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t,C2,FnLocalColorInnerProduct>::Type_t >::Expression_t
localColorInnerProduct(const typename WordType<C2>::Type_t & l,const QDPType<T2,C2> & r)
{
typedef BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t >::Leaf_t,
typename CreateLeaf<QDPType<T2,C2> >::Leaf_t> Tree_t;
typedef typename BinaryReturn<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t,C2,FnLocalColorInnerProduct>::Type_t Container_t;
return MakeReturn<Tree_t,Container_t>::make(Tree_t(
CreateLeaf<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t >::make(typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t(l)),
CreateLeaf<QDPType<T2,C2> >::make(r)));
}

template<class T2,class C2>
inline typename MakeReturn<BinaryNode<FnQuarkContract13,
typename CreateLeaf<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t >::Leaf_t,
Expand Down Expand Up @@ -5547,6 +5645,22 @@ localInnerProductReal(const QDPExpr<T1,C1> & l,const QDPExpr<T2,C2> & r)
CreateLeaf<QDPExpr<T2,C2> >::make(r)));
}

template<class T1,class C1,class T2,class C2>
inline typename MakeReturn<BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPExpr<T1,C1> >::Leaf_t,
typename CreateLeaf<QDPExpr<T2,C2> >::Leaf_t>,
typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t >::Expression_t
localColorInnerProduct(const QDPExpr<T1,C1> & l,const QDPExpr<T2,C2> & r)
{
typedef BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPExpr<T1,C1> >::Leaf_t,
typename CreateLeaf<QDPExpr<T2,C2> >::Leaf_t> Tree_t;
typedef typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t Container_t;
return MakeReturn<Tree_t,Container_t>::make(Tree_t(
CreateLeaf<QDPExpr<T1,C1> >::make(l),
CreateLeaf<QDPExpr<T2,C2> >::make(r)));
}

template<class T1,class C1,class T2,class C2>
inline typename MakeReturn<BinaryNode<FnQuarkContract13,
typename CreateLeaf<QDPExpr<T1,C1> >::Leaf_t,
Expand Down Expand Up @@ -6129,6 +6243,22 @@ localInnerProductReal(const QDPExpr<T1,C1> & l,const typename WordType<C1>::Type
CreateLeaf<typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t >::make(typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t(r))));
}

template<class T1,class C1>
inline typename MakeReturn<BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPExpr<T1,C1> >::Leaf_t,
typename CreateLeaf<typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t >::Leaf_t>,
typename BinaryReturn<C1,typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t,FnLocalColorInnerProduct>::Type_t >::Expression_t
localColorInnerProduct(const QDPExpr<T1,C1> & l,const typename WordType<C1>::Type_t & r)
{
typedef BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<QDPExpr<T1,C1> >::Leaf_t,
typename CreateLeaf<typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t >::Leaf_t> Tree_t;
typedef typename BinaryReturn<C1,typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t,FnLocalColorInnerProduct>::Type_t Container_t;
return MakeReturn<Tree_t,Container_t>::make(Tree_t(
CreateLeaf<QDPExpr<T1,C1> >::make(l),
CreateLeaf<typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t >::make(typename SimpleScalar<typename WordType<C1>::Type_t>::Type_t(r))));
}

template<class T1,class C1>
inline typename MakeReturn<BinaryNode<FnQuarkContract13,
typename CreateLeaf<QDPExpr<T1,C1> >::Leaf_t,
Expand Down Expand Up @@ -6673,6 +6803,22 @@ localInnerProductReal(const typename WordType<C2>::Type_t & l,const QDPExpr<T2,C
CreateLeaf<QDPExpr<T2,C2> >::make(r)));
}

template<class T2,class C2>
inline typename MakeReturn<BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t >::Leaf_t,
typename CreateLeaf<QDPExpr<T2,C2> >::Leaf_t>,
typename BinaryReturn<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t,C2,FnLocalColorInnerProduct>::Type_t >::Expression_t
localColorInnerProduct(const typename WordType<C2>::Type_t & l,const QDPExpr<T2,C2> & r)
{
typedef BinaryNode<FnLocalColorInnerProduct,
typename CreateLeaf<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t >::Leaf_t,
typename CreateLeaf<QDPExpr<T2,C2> >::Leaf_t> Tree_t;
typedef typename BinaryReturn<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t,C2,FnLocalColorInnerProduct>::Type_t Container_t;
return MakeReturn<Tree_t,Container_t>::make(Tree_t(
CreateLeaf<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t >::make(typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t(l)),
CreateLeaf<QDPExpr<T2,C2> >::make(r)));
}

template<class T2,class C2>
inline typename MakeReturn<BinaryNode<FnQuarkContract13,
typename CreateLeaf<typename SimpleScalar<typename WordType<C2>::Type_t>::Type_t >::Leaf_t,
Expand Down
45 changes: 45 additions & 0 deletions include/qdp_globalfuncs_subtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,51 @@ namespace QDP
#endif


template<class T1,class C1,class T2,class C2>
typename QDPSubTypeTrait< typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t >::Type_t
localColorInnerProduct(const QDPSubType<T1,C1> & l,const QDPType<T2,C2> & r)
{
if (!l.getOwnsMemory())
QDP_error_exit("localColorInnerProduct with subtype view called");

typename QDPSubTypeTrait< typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t >::Type_t ret;
ret.setSubset( l.subset() );

//QDP_info("localColorInnerProduct %d sites",l.subset().numSiteTable());

const int *tab = l.subset().siteTable().slice();
for(int j=0; j < l.subset().numSiteTable(); ++j)
{
int i = tab[j];
FnLocalColorInnerProduct op;
ret.getF()[j] = op( l.getF()[j] , r.elem(i) );
}

return ret;
}

template<class T1,class C1,class T2,class C2>
typename QDPSubTypeTrait< typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t >::Type_t
localColorInnerProduct(const QDPType<T1,C1> & l,const QDPSubType<T2,C2> & r)
{
if (!r.getOwnsMemory())
QDP_error_exit("localColorInnerProduct with subtype view called");

typename QDPSubTypeTrait< typename BinaryReturn<C1,C2,FnLocalColorInnerProduct>::Type_t >::Type_t ret;
ret.setSubset( r.subset() );

const int *tab = r.subset().siteTable().slice();
for(int j=0; j < r.subset().numSiteTable(); ++j)
{
int i = tab[j];
FnLocalColorInnerProduct op;
ret.getF()[j] = op( l.elem(i) , r.getF()[j] );
}

return ret;
}



template<class T>
typename UnaryReturn<OLattice<T>, FnSum>::Type_t
Expand Down
26 changes: 21 additions & 5 deletions include/qdp_inner.h
Original file line number Diff line number Diff line change
Expand Up @@ -833,11 +833,6 @@ struct UnaryReturn<IScalar<T>, FnPeekSite> {
typedef IScalar<typename UnaryReturn<T, FnPeekSite>::Type_t> Type_t;
};

template<class T>
struct UnaryReturn<IScalar<T>, FnSumMulti> {
typedef IScalar<typename UnaryReturn<T, FnSumMulti>::Type_t> Type_t;
};


// Gamma algebra
template<int N, int m, class T2, class OpGammaConstMultiply>
Expand Down Expand Up @@ -1759,6 +1754,12 @@ globalMin(const IScalar<T>& s1)
}


// sumMulti
template<class T>
struct UnaryReturn<IScalar<T>, FnSumMulti> {
typedef IScalar<typename UnaryReturn<T, FnSumMulti>::Type_t> Type_t;
};

// InnerProduct (norm-seq) global sum = sum(tr(adj(s1)*s1))
template<class T>
struct UnaryReturn<IScalar<T>, FnNorm2> {
Expand Down Expand Up @@ -1798,6 +1799,21 @@ localInnerProduct(const IScalar<T1>& s1, const IScalar<T2>& s2)
}


//! IScalar = localColorInnerProduct(adj(IScalar)*IScalar)
template<class T1, class T2>
struct BinaryReturn<IScalar<T1>, IScalar<T2>, FnLocalColorInnerProduct> {
typedef IScalar<typename BinaryReturn<T1, T2, FnLocalColorInnerProduct>::Type_t> Type_t;
};

template<class T1, class T2>
inline typename BinaryReturn<IScalar<T1>, IScalar<T2>, FnLocalColorInnerProduct>::Type_t
localColorInnerProduct(const IScalar<T1>& s1, const IScalar<T2>& s2)
{
return localColorInnerProduct(s1.elem(), s2.elem());
}



//! IScalar = where(IScalar, IScalar, IScalar)
/*!
* Where is the ? operation
Expand Down
Loading

0 comments on commit f44cd1a

Please sign in to comment.