コード例 #1
0
ファイル: o3dgcTriangleFans.cpp プロジェクト: 1vanK/Urho3D
    O3DGCErrorCode    LoadUIntAC(Vector<long> & data,
                                 const unsigned long M,
                                 const BinaryStream & bstream,
                                 unsigned long & iterator) 
    {
        unsigned long sizeSize = bstream.ReadUInt32Bin(iterator) - 12;
        unsigned long size     = bstream.ReadUInt32Bin(iterator);
        if (size == 0)
        {
            return O3DGC_OK;
        }
        long minValue   = bstream.ReadUInt32Bin(iterator);
        unsigned char * buffer = 0;
        bstream.GetBuffer(iterator, buffer);
        iterator += sizeSize;
        data.Allocate(size);
        Arithmetic_Codec acd;
        acd.set_buffer(sizeSize, buffer);
        acd.start_decoder();
        Adaptive_Data_Model mModelValues(M+1);
#ifdef DEBUG_VERBOSE
        printf("-----------\nsize %i\n", size);
        fprintf(g_fileDebugTF, "size %i\n", size);
#endif //DEBUG_VERBOSE
        for(unsigned long i = 0; i < size; ++i)
        {
            data.PushBack(acd.decode(mModelValues)+minValue);
#ifdef DEBUG_VERBOSE
            printf("%i\t%i\n", i, data[i]);
            fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]);
#endif //DEBUG_VERBOSE
        }
        return O3DGC_OK;
    }
コード例 #2
0
ファイル: Pipe.cpp プロジェクト: dmead/sc2bot
bool Pipe::ReadMessage(Vector<BYTE> &Message)
{
    Assert(_Handle != NULL, "Pipe invalid in Pipe::ReadMessage");
    DWORD BytesReady  = 0;
    BOOL Success = PeekNamedPipe(
        _Handle,
        NULL,
        0,
        NULL,
        &BytesReady,
        NULL);
    Assert(Success != FALSE, "PeekNamedPipe failed in Pipe::ReadMessage");
    Message.Allocate(BytesReady);
    if(BytesReady == 0)
    {
        return false;
    }

    DWORD BytesRead;
    Success = ReadFile( 
        _Handle,                // handle to pipe 
        Message.CArray(),       // buffer to receive data 
        Message.Length(),       // size of buffer 
        &BytesRead,             // number of bytes read 
        NULL);                  // not overlapped I/O 
    Assert(Success != FALSE && BytesRead > 0, "ReadFile failed in Pipe::ReadMessage");
    return true;
}
コード例 #3
0
ファイル: Matrix.cpp プロジェクト: Msegade/pssolver
void MatVec(const Matrix<ValueType>& mat, const Vector<ValueType>& invec, 
                                const ValueType& val, Vector<ValueType>& outvec)
{
    DEBUGLOG(&mat, "MatVec()", "invec = " << &invec <<
                                    " outvec = "<< &outvec, 1);
    assert(invec.GetSize() == mat.GetNCols()); 
    if(invec.GetSize() != outvec.GetSize())
    {
        outvec.Allocate(invec.GetSize());
    }

    assert( (mat.IsHost() && invec.IsHost() ) ||
            (mat.IsDevice() && invec.IsDevice() ) );
    if ( mat.IsHost() )
    {
        if ( outvec.IsHost() ) {}
        else outvec.MoveToHost();
    }
    else if ( mat.IsDevice() )
    {
        if ( outvec.IsDevice() ) {}
        else outvec.MoveToDevice();
    }

    mat.pImpl->MatVec(*(invec.pImpl), *(outvec.pImpl), val);
    DEBUGEND();

}
コード例 #4
0
ファイル: D3D9Mesh.cpp プロジェクト: kbinani/dxrip
void D3D9Mesh::QueryHits(const Vec3f &Pos, const Vec3f &Dir, Vector<float> &Hits, DWORD &FirstHitFaceIndex, float &u, float &v) const
{
    D3DXVECTOR3 D3DPos = Pos;
    D3DXVECTOR3 D3DDir = Dir;
    BOOL Hit;
    DWORD HitCount;
    FLOAT Dist;
    LPD3DXBUFFER AllHits = NULL;

    D3DXIntersect(_Mesh, &D3DPos, &D3DDir, &Hit, &FirstHitFaceIndex, &u, &v, &Dist, &AllHits, &HitCount);

    Hits.Allocate(HitCount);
    if(HitCount)
    {
        LPD3DXINTERSECTINFO HitInfo = (LPD3DXINTERSECTINFO)AllHits->GetBufferPointer();
        for(UINT HitIndex = 0; HitIndex < HitCount; HitIndex++)
        {
            Hits[HitIndex] = HitInfo[HitIndex].Dist;
        }
        Hits.Sort();
    }

    if(AllHits != NULL)
    {
        AllHits->Release();
    }
}
コード例 #5
0
    O3DGCErrorCode    LoadBinAC(Vector<long> & data,
                                const BinaryStream & bstream,
                                unsigned long & iterator) 
    {
        size_t sizeSize = bstream.ReadUInt32Bin(iterator) - 8;
        size_t size     = bstream.ReadUInt32Bin(iterator);
        if (size == 0)
        {
            return O3DGC_OK;
        }
        unsigned char * buffer = 0;
        bstream.GetBuffer(iterator, buffer);
        iterator += sizeSize;
        data.Allocate(size);
        Arithmetic_Codec acd;
        acd.set_buffer(sizeSize, buffer);
        acd.start_decoder();
        Adaptive_Bit_Model bModel;
#ifdef DEBUG_VERBOSE
        printf("-----------\nsize %i\n", size);
        fprintf(g_fileDebugTF, "size %i\n", size);
#endif //DEBUG_VERBOSE
        for(size_t i = 0; i < size; ++i)
        {
            data.PushBack(acd.decode(bModel));
#ifdef DEBUG_VERBOSE
            printf("%i\t%i\n", i, data[i]);
            fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]);
#endif //DEBUG_VERBOSE
        }
        return O3DGC_OK;
    }
コード例 #6
0
ファイル: BlasMpi.cpp プロジェクト: marioyc/INF560
________________________________________________________________________________

//! @internal compute matrix-vector product
int MatrixVectorProductBandColumn (
        Vector<double,int>& y_global,
        const MatrixDense<double,int>& A_local,
        const Vector<double,int>& x_local,
        const int root,
        MPI_Comm& mpi_comm ) {

  // -- local matrix: number of rows
  int numb_rows_global    = A_local.GetNumbRows( );

  // -- global vector
  Vector<double,int> y_global_tmp( numb_rows_global );

  // -- perform local matrix vector product: A_local * x_local
  A_local.MatrixVectorProduct( y_global_tmp, x_local );

  // -- allocate global result
  y_global.Allocate( numb_rows_global );

  // reduce to root proc
  MPI_Reduce( y_global_tmp.GetCoef( ), y_global.GetCoef( ),
              numb_rows_global, MPI_DOUBLE, MPI_SUM, root, mpi_comm );

  return 0;
}
コード例 #7
0
ファイル: PCA.cpp プロジェクト: dmead/sc2bot
void PCA<T>::Transform(Vector<T> &Result, const Vector<T> &Input, UINT ReducedDimension)
{
    if(Result.Length() != ReducedDimension)
    {
	    Result.Allocate(ReducedDimension);
    }
	Transform(Result.CArray(), Input.CArray(), ReducedDimension);
}
コード例 #8
0
ファイル: Stdhdr.cpp プロジェクト: ElanHR/Provincial
 void GetFileData(const String &Filename, Vector<BYTE> &Output)
 {
     FILE *InputFile = Utility::CheckedFOpen(Filename.CString(), "rb");
     UINT FileSize = Utility::GetFileSize(Filename);
     Output.Allocate(FileSize);
     Utility::CheckedFRead(Output.CArray(), sizeof(BYTE), FileSize, InputFile);
     fclose(InputFile);
 }
コード例 #9
0
ファイル: Compression.cpp プロジェクト: ElanHR/Provincial
void Compression::DecompressStreamFromFile(const String &filename, Vector<BYTE> &stream)
{
    Vector<BYTE> input;
    Utility::GetFileData(filename, input);
    UINT32 decompressedByteCount = ((UINT32*)input.CArray())[0];
    stream.Allocate(decompressedByteCount);

    uLongf finalByteCount = decompressedByteCount;
    int result = uncompress(stream.CArray(), &finalByteCount, input.CArray() + sizeof(UINT32), input.Length() - sizeof(UINT32));
    PersistentAssert(result == Z_OK, "Decompression failed");
    PersistentAssert(finalByteCount == decompressedByteCount, "Decompression returned invalid length");
}
コード例 #10
0
 O3DGCErrorCode    LoadIntData(Vector<long> & data,
                               const BinaryStream & bstream,
                               unsigned long & iterator) 
 {
     bstream.ReadUInt32ASCII(iterator);
     const unsigned long size = bstream.ReadUInt32ASCII(iterator);
     data.Allocate(size);
     data.Clear();
     for(size_t i = 0; i < size; ++i)
     {
         data.PushBack(bstream.ReadIntASCII(iterator));
     }
     return O3DGC_OK;
 }
コード例 #11
0
    O3DGCErrorCode    LoadIntACEGC(Vector<long> & data,
                                   const unsigned long M,
                                   const BinaryStream & bstream,
                                   unsigned long & iterator) 
    {
        size_t sizeSize = bstream.ReadUInt32Bin(iterator) - 12;
        size_t size     = bstream.ReadUInt32Bin(iterator);
        if (size == 0)
        {
            return O3DGC_OK;
        }
        long minValue   = bstream.ReadUInt32Bin(iterator) - O3DGC_MAX_LONG;
        unsigned char * buffer = 0;
        bstream.GetBuffer(iterator, buffer);
        iterator += sizeSize;
        data.Allocate(size);
        Arithmetic_Codec acd;
        acd.set_buffer(sizeSize, buffer);
        acd.start_decoder();
        Adaptive_Data_Model mModelValues(M+2);
        Static_Bit_Model bModel0;
        Adaptive_Bit_Model bModel1;
        unsigned long value;

#ifdef DEBUG_VERBOSE
        printf("-----------\nsize %i\n", size);
        fprintf(g_fileDebugTF, "size %i\n", size);
#endif //DEBUG_VERBOSE
        for(size_t i = 0; i < size; ++i)
        {
            value = acd.decode(mModelValues);
            if ( value == M)
            {
                value += acd.ExpGolombDecode(0, bModel0, bModel1);
            }
            data.PushBack(value + minValue);
#ifdef DEBUG_VERBOSE
            printf("%i\t%i\n", i, data[i]);
            fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]);
#endif //DEBUG_VERBOSE
        }
#ifdef DEBUG_VERBOSE
        fflush(g_fileDebugTF);
#endif //DEBUG_VERBOSE
        return O3DGC_OK;
    }
コード例 #12
0
ファイル: Vector.cpp プロジェクト: Msegade/pssolver
void ScalarAdd(const Vector<ValueType>& vec1, const ValueType& val,
                    const Vector<ValueType>& vec2, Vector<ValueType>& outvec) 
{
    DEBUGLOG( &vec1, "SacalrAdd()", "vec1 =" << &vec1 << " vec2 = " << &vec2 
                            << " val =  " << val << " outvec = " << &outvec, 1);
    assert(( vec1.IsHost() && vec2.IsHost() )|| 
            (vec1.IsDevice() && vec2.IsDevice()) );
    assert(( vec1.IsHost() && outvec.IsHost() )|| 
            (vec1.IsDevice() && outvec.IsDevice()) );
    assert(vec1.GetSize() == vec2.GetSize()); 

    if ( outvec.GetSize() != vec1.GetSize()) 
        outvec.Allocate(vec1.GetSize());

    outvec.pImpl->ScalarAdd(*(vec1.pImpl), *(vec2.pImpl), val);
    DEBUGEND();

}
コード例 #13
0
 O3DGCErrorCode    LoadBinData(Vector<long> & data,
                               const BinaryStream & bstream,
                               unsigned long & iterator) 
 {
     bstream.ReadUInt32ASCII(iterator);
     const unsigned long size = bstream.ReadUInt32ASCII(iterator);
     long symbol;
     data.Allocate(size * O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0);
     data.Clear();
     for(size_t i = 0; i < size;)
     {
         symbol = bstream.ReadUCharASCII(iterator);
         for(unsigned long h = 0; h < O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0; ++h)
         {
             data.PushBack(symbol & 1);
             symbol >>= 1;
             ++i;
         }
     }
     return O3DGC_OK;
 }
コード例 #14
0
void SpectralClustering::Cluster(const DenseMatrix<double> &S, UINT kMeansClusters, UINT reducedDimensionCount, Method method, Vector<UINT> &clusterIDs, SpectralClusteringCache *cache)
{
    const UINT pointCount = S.RowCount();
    
    Console::WriteLine("Spectral clustering on " + String(pointCount) + " points, " + String(kMeansClusters) + " clusters, " + String(reducedDimensionCount) + String(" dimensions"));
    
    DenseMatrix<double> L(pointCount, pointCount);
    MakeLaplacian(S, method, L);

    Vector<double> eigenvalues;
    DenseMatrix<double> eigenvectors;
    {
        if(cache != NULL && cache->eigenvalues.Length() == pointCount)
        {
            Console::WriteString("Loading eigensystem from cache...");
            eigenvalues = cache->eigenvalues;
            eigenvectors = cache->eigenvectors;
        }
        else
        {
            Clock timer;
            Console::WriteString("Solving eigensystem...");
            L.EigenSystemTNT(eigenvalues, eigenvectors);
            Console::WriteLine(String(timer.Elapsed()) + "s");
        }
        if(cache != NULL)
        {
            cache->eigenvalues = eigenvalues;
            cache->eigenvectors = eigenvectors;
        }
    }

    //
    // Note that the eigensystem is sorted in decreasing order.
    //
    const bool useLargestEigenvector = (method == RandomWalk || method == Symmetric);
    
    Vector<VecNf> points(pointCount);
    for(UINT pointIndex = 0; pointIndex < pointCount; pointIndex++)
    {
        VecNf &curPoint = points[pointIndex];
        curPoint.v.Allocate(reducedDimensionCount);
        for(UINT dimensionIndex = 0; dimensionIndex < reducedDimensionCount; dimensionIndex++)
        {
            if(useLargestEigenvector)
            {
                curPoint[dimensionIndex] = float(eigenvectors(pointIndex, pointCount - dimensionIndex - 1));
            }
            else
            {
                curPoint[dimensionIndex] = float(eigenvectors(pointIndex, dimensionIndex));
            }
            
        }
    }

    if(method == Symmetric)
    {
        for(UINT pointIndex = 0; pointIndex < pointCount; pointIndex++)
        {
            points[pointIndex] = VecNf::Normalize(points[pointIndex]);
        }
    }

    KMeansClustering<VecNf, VecNfKMeansMetric> clustering;
    clustering.Cluster(points, kMeansClusters, 100);
    
    clusterIDs.Allocate(pointCount);
    for(UINT pointIndex = 0; pointIndex < pointCount; pointIndex++)
    {
        clusterIDs[pointIndex] = clustering.QuantizeToNearestClusterIndex(points[pointIndex]);
    }
}
コード例 #15
0
ファイル: D3D9Mesh.cpp プロジェクト: kbinani/dxrip
void D3D9Mesh::GenerateAdj(Vector<DWORD> &Adjacency)
{
    Adjacency.Allocate(IndexCount());
    D3DAlwaysValidate(_Mesh->GenerateAdjacency(0.0f, Adjacency.CArray()), "GenerateAdjacency");
}
コード例 #16
0
ファイル: PCA.cpp プロジェクト: dmead/sc2bot
void PCA<T>::InverseTransform(Vector<T> &Result, const Vector<T> &Input)
{
	const UINT Dimension = _Means.Length();
	Result.Allocate(Dimension);
	InverseTransform(Result.CArray(), Input.CArray(), Input.Length());
}
コード例 #17
0
ファイル: Stdhdr.cpp プロジェクト: ElanHR/Provincial
    void GetUnicodeFileLines(const String &Filename, Vector<UnicodeString> &Output, UINT LineLimit)
    {
        Vector<BYTE> Data;
        Utility::GetFileData(Filename, Data);

        const UINT Length = Data.Length() / 2;
        const unsigned short *CArray = (unsigned short *)Data.CArray();
        
        UINT StringCount = 0;
        if(LineLimit == 0)
        {
            for(UINT Index = 0; Index < Length; Index++)
            {
                unsigned short CurCharacter = CArray[Index];
                if(CurCharacter == 0x000D || CurCharacter == 0x000A)
                {
                    if(Index < Length - 1 && (CArray[Index + 1] == 0x000D || CArray[Index + 1] == 0x000A))
                    {
                        Index++;
                    }
                    StringCount++;
                }
            }
            Output.Allocate(StringCount);
        }
        else
        {
            Output.Allocate(LineLimit);
        }
        
        UINT StringIndex = 0;
        UnicodeString *CurString = &(Output[0]);

        bool Done = false;
        for(UINT Index = 0; Index < Length && !Done; Index++)
        {
            unsigned short CurCharacter = CArray[Index];
            if(CurCharacter == 0x000D || CurCharacter == 0x000A)
            {
                if(Index < Length - 1 && (CArray[Index + 1] == 0x000D || CArray[Index + 1] == 0x000A))
                {
                    Index++;
                }
                if(StringIndex == LineLimit - 1)
                {
                    Done = true;
                }
                else
                {
                    StringIndex++;
                    if(StringIndex != Output.Length())
                    {
                        CurString = &(Output[StringIndex]);
                    }
                }
            }
            else if(CurCharacter != 0xFEFF)
            {
                //Console::WriteString(String::UnsignedIntAsHex(CurCharacter) + String(" "));
                CurString->PushEnd(CurCharacter);
            }
        }
        if(LineLimit != 0)
        {
            Output.ReSize(StringIndex + 1);
        }
    }