Sleipnir
src/example.cpp
00001 /*****************************************************************************
00002 * This file is provided under the Creative Commons Attribution 3.0 license.
00003 *
00004 * You are free to share, copy, distribute, transmit, or adapt this work
00005 * PROVIDED THAT you attribute the work to the authors listed below.
00006 * For more information, please see the following web page:
00007 * http://creativecommons.org/licenses/by/3.0/
00008 *
00009 * This file is a component of the Sleipnir library for functional genomics,
00010 * authored by:
00011 * Curtis Huttenhower (chuttenh@princeton.edu)
00012 * Mark Schroeder
00013 * Maria D. Chikina
00014 * Olga G. Troyanskaya (ogt@princeton.edu, primary contact)
00015 *
00016 * If you use this library, the included executable tools, or any related
00017 * code in your work, please cite the following publication:
00018 * Curtis Huttenhower, Mark Schroeder, Maria D. Chikina, and
00019 * Olga G. Troyanskaya.
00020 * "The Sleipnir library for computational functional genomics"
00021 *****************************************************************************/
00022 #include "stdafx.h"
00023 #include "examplei.h"
00024 #include "meta.h"
00025 
00026 namespace Sleipnir {
00027 
00028 CExampleImpl::CExampleImpl( ) {
00029 
00030     m_auData = NULL; }
00031 
00032 CExampleImpl::~CExampleImpl( ) {
00033 
00034     Reset( ); }
00035 
00036 void CExampleImpl::Reset( ) {
00037 
00038     if( !m_auData )
00039         return;
00040 
00041     delete[] m_auData;
00042     m_auData = NULL; }
00043 
00044 void CExampleImpl::Set( size_t iLoc, float dValue, const CDataPair& Datum, size_t iMax ) {
00045     size_t  i;
00046 
00047     if( !m_auData ) {
00048         if( !iMax )
00049             return;
00050         m_auData = new UDatum[ iMax ];
00051         for( i = 0; i < iMax; ++i )
00052             m_auData[ i ].m_d = CMeta::GetNaN( ); }
00053 
00054     if( Datum.IsContinuous( ) || CMeta::IsNaN( dValue ) )
00055         m_auData[ iLoc ].m_d = dValue;
00056     else
00057         m_auData[ iLoc ].m_i = Datum.Quantize( dValue ); }
00058 
00059 bool CExampleImpl::Equals( const CExampleImpl& Example, size_t iSize ) const {
00060     size_t  i;
00061 
00062     for( i = 0; i < iSize; ++i )
00063         if( m_auData[ i ].m_i != Example.m_auData[ i ].m_i )
00064             return false;
00065 
00066     return true; }
00067 
00068 bool CExampleImpl::IsEvidence( size_t iMax ) const {
00069     size_t  i;
00070 
00071     if( !m_auData )
00072         return false;
00073 
00074     for( i = 1; i < iMax; ++i )
00075         if( !CMeta::IsNaN( m_auData[ i ].m_d ) )
00076             break;
00077 
00078     return ( i < iMax ); }
00079 
00080 }