void MinEig ( const AbstractDistMatrix<Real>& xPre, AbstractDistMatrix<Real>& minEigsPre, const AbstractDistMatrix<Int>& orders, const AbstractDistMatrix<Int>& firstIndsPre, Int cutoff ) { EL_DEBUG_CSE AssertSameGrids( xPre, minEigsPre, orders, firstIndsPre ); ElementalProxyCtrl ctrl; ctrl.colConstrain = true; ctrl.colAlign = 0; DistMatrixReadProxy<Real,Real,VC,STAR> xProx( xPre, ctrl ); DistMatrixWriteProxy<Real,Real,VC,STAR> minEigsProx( minEigsPre, ctrl ); DistMatrixReadProxy<Int,Int,VC,STAR> firstIndsProx( firstIndsPre, ctrl ); auto& x = xProx.GetLocked(); auto& minEigs = minEigsProx.Get(); auto& firstInds = firstIndsProx.GetLocked(); const Int height = x.Height(); const Int localHeight = x.LocalHeight(); EL_DEBUG_ONLY( if( x.Width() != 1 || orders.Width() != 1 || firstInds.Width() != 1 ) LogicError("x, orders, and firstInds should be column vectors"); if( orders.Height() != height || firstInds.Height() != height ) LogicError("orders and firstInds should be of the same height as x"); )
void PushInto ( ElementalMatrix<Real>& xPre, const ElementalMatrix<Int>& ordersPre, const ElementalMatrix<Int>& firstIndsPre, Real minDist, Int cutoff ) { DEBUG_ONLY(CSE cse("soc::PushInto")) AssertSameGrids( xPre, ordersPre, firstIndsPre ); ElementalProxyCtrl ctrl; ctrl.colConstrain = true; ctrl.colAlign = 0; DistMatrixReadWriteProxy<Real,Real,VC,STAR> xProx( xPre, ctrl ); DistMatrixReadProxy<Int,Int,VC,STAR> ordersProx( ordersPre, ctrl ), firstIndsProx( firstIndsPre, ctrl ); auto& x = xProx.Get(); auto& orders = ordersProx.GetLocked(); auto& firstInds = firstIndsProx.GetLocked(); DistMatrix<Real,VC,STAR> d(x.Grid()); soc::LowerNorms( x, d, orders, firstInds, cutoff ); const Int localHeight = x.LocalHeight(); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { const Int i = x.GlobalRow(iLoc); const Real x0 = x.GetLocal(iLoc,0); const Real lowerNorm = d.GetLocal(iLoc,0); if( i == firstInds.GetLocal(iLoc,0) && x0-lowerNorm < minDist ) x.UpdateLocal( iLoc, 0, minDist - (x0-lowerNorm) ); } }
void Dets ( const ElementalMatrix<Real>& xPre, ElementalMatrix<Real>& dPre, const ElementalMatrix<Int>& ordersPre, const ElementalMatrix<Int>& firstIndsPre, Int cutoff ) { DEBUG_CSE AssertSameGrids( xPre, dPre, ordersPre, firstIndsPre ); ElementalProxyCtrl ctrl; ctrl.colConstrain = true; ctrl.colAlign = 0; DistMatrixReadProxy<Real,Real,VC,STAR> xProx( xPre, ctrl ); DistMatrixWriteProxy<Real,Real,VC,STAR> dProx( dPre, ctrl ); DistMatrixReadProxy<Int,Int,VC,STAR> ordersProx( ordersPre, ctrl ), firstIndsProx( firstIndsPre, ctrl ); auto& x = xProx.GetLocked(); auto& d = dProx.Get(); auto& orders = ordersProx.GetLocked(); auto& firstInds = firstIndsProx.GetLocked(); auto Rx = x; soc::Reflect( Rx, orders, firstInds ); soc::Dots( x, Rx, d, orders, firstInds, cutoff ); }
void Apply ( const ElementalMatrix<Real>& xPre, const ElementalMatrix<Real>& yPre, ElementalMatrix<Real>& zPre, const ElementalMatrix<Int>& ordersPre, const ElementalMatrix<Int>& firstIndsPre, Int cutoff ) { DEBUG_ONLY(CSE cse("soc::Apply")) AssertSameGrids( xPre, yPre, zPre, ordersPre, firstIndsPre ); ElementalProxyCtrl ctrl; ctrl.colConstrain = true; ctrl.colAlign = 0; DistMatrixReadProxy<Real,Real,VC,STAR> xProx( xPre, ctrl ), yProx( yPre, ctrl ); DistMatrixWriteProxy<Real,Real,VC,STAR> zProx( zPre, ctrl ); DistMatrixReadProxy<Int,Int,VC,STAR> ordersProx( ordersPre, ctrl ), firstIndsProx( firstIndsPre, ctrl ); auto& x = xProx.GetLocked(); auto& y = yProx.GetLocked(); auto& z = zProx.Get(); auto& orders = ordersProx.GetLocked(); auto& firstInds = firstIndsProx.GetLocked(); soc::Dots( x, y, z, orders, firstInds ); auto xRoots = x; auto yRoots = y; cone::Broadcast( xRoots, orders, firstInds ); cone::Broadcast( yRoots, orders, firstInds ); const Int localHeight = x.LocalHeight(); const Real* xBuf = x.LockedBuffer(); const Real* xRootBuf = xRoots.LockedBuffer(); const Real* yBuf = y.LockedBuffer(); const Real* yRootBuf = yRoots.LockedBuffer(); Real* zBuf = z.Buffer(); const Int* firstIndBuf = firstInds.LockedBuffer(); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { const Int i = x.GlobalRow(iLoc); const Int firstInd = firstIndBuf[iLoc]; if( i != firstInd ) zBuf[iLoc] += xRootBuf[iLoc]*yBuf[iLoc] + yRootBuf[iLoc]*xBuf[iLoc]; } }
void PushPairInto ( ElementalMatrix<Real>& sPre, ElementalMatrix<Real>& zPre, const ElementalMatrix<Real>& wPre, const ElementalMatrix<Int>& ordersPre, const ElementalMatrix<Int>& firstIndsPre, Real wMaxNormLimit, Int cutoff ) { DEBUG_ONLY(CSE cse("soc::PushPairInto")) AssertSameGrids( sPre, zPre, wPre, ordersPre, firstIndsPre ); ElementalProxyCtrl ctrl; ctrl.colConstrain = true; ctrl.colAlign = 0; DistMatrixReadWriteProxy<Real,Real,VC,STAR> sProx( sPre, ctrl ), zProx( zPre, ctrl ); DistMatrixReadProxy<Real,Real,VC,STAR> wProx( wPre, ctrl ); DistMatrixReadProxy<Int,Int,VC,STAR> ordersProx( ordersPre, ctrl ), firstIndsProx( firstIndsPre, ctrl ); auto& s = sProx.Get(); auto& z = zProx.Get(); auto& w = wProx.GetLocked(); auto& orders = ordersProx.GetLocked(); auto& firstInds = firstIndsProx.GetLocked(); DistMatrix<Real,VC,STAR> sLower(s.Grid()), zLower(z.Grid()); soc::LowerNorms( s, sLower, orders, firstInds, cutoff ); soc::LowerNorms( z, zLower, orders, firstInds, cutoff ); const Int localHeight = s.LocalHeight(); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { const Int i = s.GlobalRow(iLoc); const Real w0 = w.GetLocal(iLoc,0); if( i == firstInds.GetLocal(iLoc,0) && w0 > wMaxNormLimit ) { // TODO: Switch to a non-adhoc modification s.UpdateLocal( iLoc, 0, Real(1)/wMaxNormLimit ); z.UpdateLocal( iLoc, 0, Real(1)/wMaxNormLimit ); } } }
Int Degree( const ElementalMatrix<Int>& firstIndsPre ) { DEBUG_CSE DistMatrixReadProxy<Int,Int,VC,STAR> firstIndsProx( firstIndsPre ); auto& firstInds = firstIndsProx.GetLocked(); Int localDegree = 0; const Int localHeight = firstInds.LocalHeight(); auto& firstIndsLoc = firstInds.LockedMatrix(); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { const Int i = firstInds.GlobalRow(iLoc); if( i == firstIndsLoc(iLoc) ) ++localDegree; } return mpi::AllReduce( localDegree, firstInds.DistComm() ); }
void Inverse ( const ElementalMatrix<Real>& xPre, ElementalMatrix<Real>& xInvPre, const ElementalMatrix<Int>& ordersPre, const ElementalMatrix<Int>& firstIndsPre, Int cutoff ) { DEBUG_CSE AssertSameGrids( xPre, xInvPre, ordersPre, firstIndsPre ); ElementalProxyCtrl ctrl; ctrl.colConstrain = true; ctrl.colAlign = 0; DistMatrixReadProxy<Real,Real,VC,STAR> xProx( xPre, ctrl ); DistMatrixWriteProxy<Real,Real,VC,STAR> xInvProx( xInvPre, ctrl ); DistMatrixReadProxy<Int,Int,VC,STAR> ordersProx( ordersPre, ctrl ), firstIndsProx( firstIndsPre, ctrl ); auto& x = xProx.GetLocked(); auto& xInv = xInvProx.Get(); auto& orders = ordersProx.GetLocked(); auto& firstInds = firstIndsProx.GetLocked(); DistMatrix<Real,VC,STAR> dInv(x.Grid()); soc::Dets( x, dInv, orders, firstInds, cutoff ); cone::Broadcast( dInv, orders, firstInds ); auto entryInv = [=]( Real alpha ) { return Real(1)/alpha; }; EntrywiseMap( dInv, function<Real(Real)>(entryInv) ); auto Rx = x; soc::Reflect( Rx, orders, firstInds ); Hadamard( dInv, Rx, xInv ); }