void RowMaxNorms( const DistMultiVec<F>& A, DistMultiVec<Base<F>>& norms ) { DEBUG_CSE norms.SetComm( A.Comm() ); norms.Resize( A.Height(), 1 ); RowMaxNorms( A.LockedMatrix(), norms.Matrix() ); }
void Apply ( const DistMultiVec<Real>& x, const DistMultiVec<Real>& y, DistMultiVec<Real>& z, const DistMultiVec<Int>& orders, const DistMultiVec<Int>& firstInds, Int cutoff ) { DEBUG_ONLY(CSE cse("soc::Apply")) 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 firstLocalRow = x.FirstLocalRow(); const Int localHeight = x.LocalHeight(); const Real* xBuf = x.LockedMatrix().LockedBuffer(); const Real* xRootBuf = xRoots.LockedMatrix().LockedBuffer(); const Real* yBuf = y.LockedMatrix().LockedBuffer(); const Real* yRootBuf = yRoots.LockedMatrix().LockedBuffer(); Real* zBuf = z.Matrix().Buffer(); const Int* firstIndBuf = firstInds.LockedMatrix().LockedBuffer(); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { const Int i = iLoc + firstLocalRow; const Int firstInd = firstIndBuf[iLoc]; if( i != firstInd ) zBuf[iLoc] += xRootBuf[iLoc]*yBuf[iLoc] + yRootBuf[iLoc]*xBuf[iLoc]; } }
void EntrywiseMap ( const DistMultiVec<S>& A, DistMultiVec<T>& B, function<T(S)> func ) { DEBUG_CSE B.SetComm( A.Comm() ); B.Resize( A.Height(), A.Width() ); EntrywiseMap( A.LockedMatrix(), B.Matrix(), func ); }
void NesterovTodd ( const DistMultiVec<Real>& s, const DistMultiVec<Real>& z, DistMultiVec<Real>& w ) { DEBUG_CSE w.SetComm( s.Comm() ); w.Resize( s.Height(), 1 ); const Real* sBuf = s.LockedMatrix().LockedBuffer(); const Real* zBuf = z.LockedMatrix().LockedBuffer(); Real* wBuf = w.Matrix().Buffer(); const Int localHeight = w.LocalHeight(); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) wBuf[iLoc] = Sqrt(sBuf[iLoc]/zBuf[iLoc]); }
void QP ( const DistSparseMatrix<Real>& A, const DistMultiVec<Real>& B, DistMultiVec<Real>& X, const qp::direct::Ctrl<Real>& ctrl ) { DEBUG_CSE const Int m = A.Height(); const Int n = A.Width(); const Int k = B.Width(); mpi::Comm comm = A.Comm(); DistSparseMatrix<Real> Q(comm), AHat(comm); DistMultiVec<Real> bHat(comm), c(comm); Herk( LOWER, ADJOINT, Real(1), A, Q ); MakeHermitian( LOWER, Q ); Zeros( AHat, 0, n ); Zeros( bHat, 0, 1 ); Zeros( X, n, k ); DistMultiVec<Real> q(comm), y(comm), z(comm); auto& qLoc = q.Matrix(); auto& XLoc = X.Matrix(); auto& BLoc = B.LockedMatrix(); for( Int j=0; j<k; ++j ) { auto xLoc = XLoc( ALL, IR(j) ); auto bLoc = BLoc( ALL, IR(j) ); Zeros( c, n, 1 ); Zeros( q, m, 1 ); qLoc = bLoc; Multiply( ADJOINT, Real(-1), A, q, Real(0), c ); Zeros( q, n, 1 ); qLoc = xLoc; El::QP( Q, AHat, bHat, c, q, y, z, ctrl ); xLoc = qLoc; } }
void RowMaxNorms( const DistSparseMatrix<F>& A, DistMultiVec<Base<F>>& norms ) { DEBUG_CSE typedef Base<F> Real; const Int localHeight = A.LocalHeight(); const F* valBuf = A.LockedValueBuffer(); const Int* offsetBuf = A.LockedOffsetBuffer(); norms.SetComm( A.Comm() ); norms.Resize( A.Height(), 1 ); auto& normsLoc = norms.Matrix(); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { Real rowMax = 0; const Int offset = offsetBuf[iLoc]; const Int numConn = offsetBuf[iLoc+1] - offset; for( Int e=offset; e<offset+numConn; ++e ) rowMax = Max(rowMax,Abs(valBuf[e])); normsLoc(iLoc) = rowMax; } }
void RowTwoNorms( const DistSparseMatrix<F>& A, DistMultiVec<Base<F>>& norms ) { DEBUG_CSE typedef Base<F> Real; const Int localHeight = A.LocalHeight(); const F* valBuf = A.LockedValueBuffer(); const Int* offsetBuf = A.LockedOffsetBuffer(); norms.SetComm( A.Comm() ); norms.Resize( A.Height(), 1 ); auto& normLoc = norms.Matrix(); for( Int iLoc=0; iLoc<localHeight; ++iLoc ) { Real scale = 0; Real scaledSquare = 1; const Int offset = offsetBuf[iLoc]; const Int numConn = offsetBuf[iLoc+1] - offset; for( Int e=offset; e<offset+numConn; ++e ) UpdateScaledSquare( valBuf[e], scale, scaledSquare ); normLoc(iLoc) = scale*Sqrt(scaledSquare); } }
void GetMappedDiagonal ( const DistSparseMatrix<T>& A, DistMultiVec<S>& d, function<S(const T&)> func, Int offset ) { EL_DEBUG_CSE const Int m = A.Height(); const Int n = A.Width(); const T* valBuf = A.LockedValueBuffer(); const Int* colBuf = A.LockedTargetBuffer(); if( m != n ) LogicError("DistSparseMatrix GetMappedDiagonal assumes square matrix"); if( offset != 0 ) LogicError("DistSparseMatrix GetMappedDiagonal assumes offset=0"); d.SetGrid( A.Grid() ); d.Resize( El::DiagonalLength(m,n,offset), 1 ); Fill( d, S(1) ); S* dBuf = d.Matrix().Buffer(); const Int dLocalHeight = d.LocalHeight(); for( Int iLoc=0; iLoc<dLocalHeight; ++iLoc ) { const Int i = d.GlobalRow(iLoc); const Int thisOff = A.RowOffset(iLoc); const Int nextOff = A.RowOffset(iLoc+1); auto it = std::lower_bound( colBuf+thisOff, colBuf+nextOff, i ); if( *it == i ) { const Int e = it-colBuf; dBuf[iLoc] = func(valBuf[e]); } else dBuf[iLoc] = func(0); } }
void Round( DistMultiVec<T>& A ) { Round( A.Matrix() ); }
void Fill( DistMultiVec<T>& A, T alpha ) { EL_DEBUG_CSE Fill( A.Matrix(), alpha ); }
void SafeScale ( Base<Field> numerator, Base<Field> denominator, DistMultiVec<Field>& A ) { EL_DEBUG_CSE SafeScale( numerator, denominator, A.Matrix() ); }
void EntrywiseMap( DistMultiVec<T>& A, function<T(T)> func ) { EntrywiseMap( A.Matrix(), func ); }