hmmer-3.3/easel/esl_vectorops.c
/* Function:  esl_vec_{DF}LogValidate(), esl_vec_{DF}Log2Validate()
 * Synopsis:  Verify that vector is a log (or log_2) p-vector.           
 * Incept:    ER,  Tue Dec  5 09:46:51 EST 2006 [janelia]
 *
 * Purpose:   Validate a log probability vector <vec> of length <n>.
 *            The exp of each element has to be between 0 and 1, and
 *            the sum of all elements has to be 1.
 *
 * Args:      vec    - log p vector to validate.
 *            n      - dimensionality of v
 *            tol    - convergence criterion applied to sum of exp v
 *            errbuf - NULL, or a failure message buffer allocated
 *                     for at least p7_ERRBUFSIZE chars. 
 *
 * Returns:   <eslOK> on success, or <eslFAIL> on failure; upon failure,
 *            if caller provided a non-<NULL> <errbuf>, an informative
 *            message is left there.
 *            
 * Throws:    <eslEMEM> on allocation failure.           
 */


Validate a log probability vector  of length .
The exp of each element has to be between 0 and 1, and
the sum of all elements has to be 1.

vec    - log p vector to validate.
n      - dimensionality of v
tol    - convergence criterion applied to sum of exp v
errbuf - NULL, or a failure message buffer allocated
for at least p7_ERRBUFSIZE chars.

 on success, or  on failure; upon failure,
if caller provided a non- , an informative
message is left there.

 on allocation failure.
Validate a log probability vector of length . The exp of each element has to be between 0 and 1 and the sum of all elements has to be 1 . vec - log p vector to validate . n - dimensionality of v tol - convergence criterion applied to sum of exp v errbuf - NULL or a failure message buffer allocated for at least p7_ERRBUFSIZE chars . on success or on failure ; upon failure if caller provided a non - an informative message is left there . on allocation failure .
int
esl_vec_DLogValidate(const double *vec, int n, double tol, char *errbuf)
{
  int     status;
  double *expvec = NULL;
  if (errbuf) *errbuf = 0;
  if (n == 0) return eslOK;
  ESL_ALLOC(expvec, sizeof(double)*n);
  esl_vec_DCopy(vec, n, expvec);
  esl_vec_DExp(expvec, n); 
  if ((status = esl_vec_DValidate(expvec, n, tol, errbuf)) != eslOK) goto ERROR;
  free(expvec);
  return eslOK;
 ERROR:
  if (expvec != NULL) free(expvec);
  return status;
}
int esl_vec_DLogValidate ( const double * vec , int n , double tol , char * errbuf ) { int status ; double * expvec = NULL ; if ( errbuf ) * errbuf = 0 ; if ( n == 0 ) return eslOK ; ESL_ALLOC ( expvec , sizeof ( double ) * n ) ; esl_vec_DCopy ( vec , n , expvec ) ; esl_vec_DExp ( expvec , n ) ; if ( ( status = esl_vec_DValidate ( expvec , n , tol , errbuf ) ) != eslOK ) goto ERROR ; free ( expvec ) ; return eslOK ; ERROR : if ( expvec != NULL ) free ( expvec ) ; return status ; }
Function:  esl_vec_{DF}LogValidate(), esl_vec_{DF}Log2Validate()
 Synopsis:  Verify that vector is a log (or log_2) p-vector.
Function : esl_vec_ { DF } LogValidate () esl_vec_ { DF } Log2Validate () Synopsis : Verify that vector is a log ( or log_2 ) p - vector .