Ejemplo n.º 1
0
double Vector<ValueType>::Norm(void) const
{
    DEBUGLOG( this, "Vector::Norm()", "Empty" , 1);
    if (GetSize()>0)
    {
        DEBUGEND();
        return pImpl->Norm();
    }
    else
    {
        DEBUGEND();
        return 0.0;
    }

}
Ejemplo n.º 2
0
void Vector<ValueType>::Allocate(int size)
{
    DEBUGLOG( this, "Vector::Allocate()", "Size = " << size, 1);

    assert(size>0);
    if ( pImpl == pImplHost )
    {
        pImplHost.reset();
        pImpl.reset();
        pImplHost = std::shared_ptr<HostVector<ValueType>>
                                    (new HostVector<ValueType>());
        assert(pImplHost != NULL);
        pImplHost->Allocate(size);
        pImpl = pImplHost;
    }
    else if (pImpl == pImplDevice )
    {
        pImplDevice.reset();
        pImpl.reset();
        pImplDevice = std::shared_ptr<DeviceVector<ValueType>>
                                    (new DeviceVector<ValueType>());
        assert(pImplDevice != NULL);
        pImplDevice->Allocate(size);
        pImpl = pImplDevice;

    }
    DEBUGEND();

}
Ejemplo n.º 3
0
// This is a template function for the reader library.
// Copy this one and change the name and fill in the code.
void OdfReader::readElementNamespaceTagname(KoXmlStreamReader &reader)
{ 
   DEBUGSTART();

    // <namespace:tagname> has the following children in ODF 1.2:
    //   FILL IN THE CHILDREN LIKE THIS EXAMPLE (taken from office:document-content):
    //          <office:automatic-styles> 3.15.3
    //          <office:body> 3.3
    //          <office:font-face-decls> 3.14
    //          <office:scripts> 3.12.
    while (reader.readNextStartElement()) {
        QString tagName = reader.qualifiedName().toString();
        
        if (tagName == "office:automatic-styles") {
            // FIXME: NYI
            reader.skipCurrentElement();
        }
        else if (tagName == "office:body") {
            readElementOfficeBody(reader);
        }
        ...  MORE else if () HERE
        else {
            reader.skipCurrentElement();
        }
    }

    m_backend->elementNamespaceTagname(reader, m_context);
    DEBUGEND();
}
Ejemplo n.º 4
0
void OdfReader::readElementOfficeBody(KoXmlStreamReader &reader)
{
    DEBUGSTART();
    m_backend->elementOfficeBody(reader, m_context);

    // <office:body> has the following children in ODF 1.2:
    //          <office:chart> 3.8,
    //          <office:database> 12.1
    //          <office:drawing> 3.5
    //          <office:image> 3.9
    //   [done] <office:presentation> 3.6
    //   [done] <office:spreadsheet> 3.7
    //   [done] <office:text> 3.4
    //
    // Of those only <office:text> is present in a text document (odf).
    while (reader.readNextStartElement()) {
        QString tagName = reader.qualifiedName().toString();
        
        if (tagName == "office:text") {
            readElementOfficeText(reader);
        }
        else if (tagName == "office:spreadsheet") {
            readElementOfficeSpreadsheet(reader);
        }
        else if (tagName == "office:presentation") {
            readElementOfficePresentation(reader);
        }
        else {
            reader.skipCurrentElement();
        }
    }

    m_backend->elementOfficeBody(reader, m_context);
    DEBUGEND();
}
Ejemplo n.º 5
0
void HostVector<ValueType>::ReadFile(const std::string filename)
{
    DEBUGLOG(this, "HostVector::ReadFile()", "filename = " << filename, 2);
    
    std::ifstream mFile(filename);
    std::string line;
    std::getline(mFile, line);
    if ( !std::regex_match (line, std::regex("^[0-9]+")))
    {
        std::cerr << "Bad syntax line 1" << std::endl;
    }
    int size = std::stoi(line);
    this->Allocate(size);

    std::getline(mFile, line);
    int index = 0;
    if (!regex_match (line, std::regex("^(-?[0-9.]+e(?:\\+|\\-)[0-9]+)")))
    {
        std::cerr << "Bad syntax in line: " << index+2 << std::endl;
    }
    GoToLine(mFile, 2);
    while   (std::getline(mFile, line))
    {
        mData[index] = std::stod(line);
        index++;
    }
    DEBUGEND();

}
Ejemplo n.º 6
0
void Matrix<ValueType>::Allocate(int nRows, int nCols, int nnz, MatrixType format)
{
    DEBUGLOG(this, "Matrix::Allocate()", "nRows = " << nRows << " nCols = " << nCols
                            << " nnz = " << nnz  << " format = " << format, 1);
    assert(nRows > 0 && nCols > 0 && nnz > 0);
    if (pImpl == pImplHost )
    {
        pImplHost.reset();
        pImpl.reset();
        if(format == CSR)
            pImplHost = std::shared_ptr<HostMatrix<ValueType>>
                            (new HostCsrMatrix<ValueType>());
        if(format == COO)
            pImplHost = std::shared_ptr<HostMatrix<ValueType>>
                            (new HostCOOMatrix<ValueType>());
        pImplHost->Allocate(nRows, nCols, nnz);
        pImpl = pImplHost;
    }
    else if (pImpl == pImplDevice)
    {
        pImplDevice.reset();
        pImpl.reset();
        if(format == CSR)
            pImplDevice = std::shared_ptr<DeviceMatrix<ValueType>>
                            (new DeviceCsrMatrix<ValueType>());
        pImplDevice->Allocate(nRows, nCols, nnz);
        pImpl = pImplDevice;
        
    }
    DEBUGEND();
    
}
Ejemplo n.º 7
0
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();

}
Ejemplo n.º 8
0
void OdfChartReader::readElementChartAxis(KoXmlStreamReader &reader)
{
    DEBUGSTART();
    m_backend->elementChartAxis(reader, m_context);

    // <chart:axis> has the following children in ODF 1.2:
    //   [done] <chart:categories> 11.9
    //   [done] <chart:grid> 11.10
    //   [done] <chart:title> 11.2.1

    while (reader.readNextStartElement()) {
        QString tagName = reader.qualifiedName().toString();
        
        if (tagName == "chart:categories") {
	    readElementChartCategories(reader);
        }
        else if (tagName == "chart:grid") {
	    readElementChartGrid(reader);
        }
        else if (tagName == "chart:title") {
	    readElementChartTitle(reader);
        }
        else {
            reader.skipCurrentElement();
        }
    }

    m_backend->elementChartAxis(reader, m_context);
    DEBUGEND();
}
Ejemplo n.º 9
0
HostVector<ValueType>::~HostVector()
{
    DEBUGLOG(this, "HostVector::~HostVector()", "Empty", 2);
    delete[] mData;
    //std::cout << "HostVector Destructor" << std::endl;
    DEBUGEND();

}
Ejemplo n.º 10
0
ValueType Vector<ValueType>::operator*(const Vector<ValueType>& otherVector) const 
{
    DEBUGLOG( this, "Vector::operator*", "Vec =" << &otherVector, 1);
    assert(GetSize() == otherVector.GetSize()); 
    DEBUGEND();
    return pImpl->Dot(*(otherVector.pImpl));
    
}
Ejemplo n.º 11
0
void HostVector<ValueType>::SetVal(const ValueType val)
{
    DEBUGLOG(this, "HostVector::SetVal()", "val = " << val, 2);
    for (int i=0; i<mSize; i++)
        mData[i] = val;
    DEBUGEND();
    
}
Ejemplo n.º 12
0
void Vector<ValueType>::operator-=(
                                const Vector<ValueType>& otherVector)
{
    DEBUGLOG( this, "Vector::operator-=", "Vec =" << &otherVector, 1);
    assert(GetSize() == otherVector.GetSize());
    pImpl->Substract(*(otherVector.pImpl));
    DEBUGEND();
}
Ejemplo n.º 13
0
void OdfReader::readElementOfficePresentation(KoXmlStreamReader &reader)
{
    DEBUGSTART();

    errorOdfReader << "Unimplemented function";
    reader.skipCurrentElement();  

    DEBUGEND();
}
Ejemplo n.º 14
0
Vector<ValueType> Vector<ValueType>::operator*(const ValueType& val) const 
{
    DEBUGLOG( this, "Vector::operator*", "Scalar =" << val, 1);
    Vector<ValueType> result(*this);
    result.pImpl->ScalarMul(val);
    DEBUGEND();
    return result;
    
}
Ejemplo n.º 15
0
void HostVector<ValueType>::ScalarMul(const ValueType& val)
{
    DEBUGLOG(this, "HostVector::ScalarMul()", "val = " << val, 2);
    for (int i=0; i<this->mSize; i++)    
    {
        mData[i] = mData[i]*val;
    }
    DEBUGEND();
}
Ejemplo n.º 16
0
Matrix<ValueType>::Matrix()
{
    DEBUGLOG(this, "Matrix::Matrix()", "Empty", 1);
    // Empty CSR matrix on host
    pImplHost = std::shared_ptr<HostMatrix<ValueType>>
                        (new HostCsrMatrix<ValueType>());
    pImpl = pImplHost;
    DEBUGEND();
}
Ejemplo n.º 17
0
Vector<ValueType>& Vector<ValueType>::operator=(
                                const Vector<ValueType>& otherVector)
{
    DEBUGLOG( this, "Vector::operator=", "Vector = " << &otherVector, 1);
    assert(&otherVector != NULL);
    if (this == &otherVector)
    {
       DEBUGEND();
       return *this;
    }
    
    if((pImpl == pImplHost) && (otherVector.pImpl == otherVector.pImplHost))
    {
        int size = otherVector.GetSize();
        //this->Allocate(size);
        // we need to pass a reference (BaseVector&)
        // otherVector.pImpl is BaseVector*
        pImpl->CopyFromHost(*(otherVector.pImpl));

        // Returning a Vector object allows chaining assigment
        // a = b = c;
        // Returning by reference makes that no copy of the object is created
        // and destroyed
        DEBUGEND();
        return *this;
    }
    else if((pImpl == pImplDevice) && (otherVector.pImpl == otherVector.pImplDevice))
    {
        int size = otherVector.GetSize();
        //this->Allocate(size);
        pImpl->CopyFromDevice(*(otherVector.pImpl));
        DEBUGEND();
        return *this;
    }
    else
    {
        std::cerr << "Objects must be on the same place (device or host)"
                  << std::endl;
        DEBUGEND();
        return *this;
    }


}
Ejemplo n.º 18
0
void Vector<ValueType>::MoveToHost(void)
{
    DEBUGLOG( this, "Vector::MoveToHost()", "Empty", 1);
    assert(this->IsDevice());
    pImplHost = std::shared_ptr<HostVector<ValueType>>
                                (new HostVector<ValueType>());
    pImplDevice->CopyToHost(*pImplHost);
    pImpl = pImplHost;
    DEBUGEND();
}
Ejemplo n.º 19
0
void Vector<ValueType>::MoveToDevice(void)
{
    DEBUGLOG( this, "Vector::MoveToDevice()", "Empty", 1);
    assert(this->IsHost());
    pImplDevice = std::shared_ptr<DeviceVector<ValueType>>
                                (new DeviceVector<ValueType>());
    pImplDevice->CopyFromHost(*pImplHost);
    pImpl = pImplDevice;
    DEBUGEND();
}
Ejemplo n.º 20
0
Vector<ValueType>::Vector()
{
    DEBUGLOG( this, "Vector::Vector()", "Empty", 1);
    // Create empty vector on host
    pImplHost = std::shared_ptr<HostVector<ValueType>>
                                (new HostVector<ValueType>());
    pImpl = pImplHost;
    DEBUGEND();

}
Ejemplo n.º 21
0
void HostVector<ValueType>::CopyFromDevice(
                        const BaseVector<ValueType> &deviceVector)
{
    DEBUGLOG(this, "HostVector::CopyFromDevice()", "Vec = " << &deviceVector, 2);
    const DeviceVector<ValueType> *cast_vec = 
        dynamic_cast<const DeviceVector<ValueType>*> (&deviceVector);

    cast_vec->CopyToHost(*this);
    DEBUGEND();

}
Ejemplo n.º 22
0
Matrix<ValueType>::Matrix(int nRows, int nCols, int nnz)
{
    DEBUGLOG(this, "Matrix::Matrix()", "nRows" << nRows << " nCols " << nCols
           << " nnz " << nnz , 1);
    // Empty CSR matrix on host
    pImplHost = std::shared_ptr<HostMatrix<ValueType>>
                        (new HostCsrMatrix<ValueType>());
    pImplHost->Allocate(nRows, nCols, nnz);
    pImpl = pImplHost;
    DEBUGEND();
}
Ejemplo n.º 23
0
void HostVector<ValueType>::Allocate(const int size)
{
    DEBUGLOG(this, "HostVector::Allocate()", "size = " << size, 2);
    assert(size > 0);
    this->mSize = size;
    this->mData = new ValueType[size];      
    // Set to 0
    memset(mData, 0, size*sizeof(ValueType));
    DEBUGEND();
    
}
Ejemplo n.º 24
0
void HostVector<ValueType>::ScalarMul(const ValueType& val, BaseVector<ValueType>& outvec)
{
    DEBUGLOG(this, "HostVector::ScalarMul()", "val = " << val << 
                " outvec = " << &outvec, 2);
    const HostVector<ValueType> *cast_v = 
        dynamic_cast<const HostVector<ValueType>*> (&outvec);
    for (int i=0; i<this->mSize; i++)    
    {
        cast_v->mData[i] = mData[i]*val;
    }
    DEBUGEND();
}
Ejemplo n.º 25
0
Vector<ValueType>::Vector(int size)
{
    DEBUGLOG( this, "Vector::Vector()", "size = " << size, 1);
    assert(size>0);
    pImplHost = std::shared_ptr<HostVector<ValueType>>
                                (new HostVector<ValueType>());
    pImplHost->Allocate(size);
    pImpl = pImplHost;
    DEBUGEND();


}
Ejemplo n.º 26
0
void ScalarMul(const Vector<ValueType>& invec, const ValueType& val,
                     Vector<ValueType>& outvec) 
{
    DEBUGLOG( &invec, "SacalrMul()", "invec =" << &invec << " outvec = " << &outvec 
                                    << "val" << val, 1);
    assert(( invec.IsHost() && outvec.IsHost() )|| 
            (invec.IsDevice() && outvec.IsDevice()) );
    assert(invec.GetSize() == outvec.GetSize()); 
    invec.pImpl->ScalarMul(val, *(outvec.pImpl));
    DEBUGEND();

}
Ejemplo n.º 27
0
void HostVector<ValueType>::Substract(
                        const BaseVector<ValueType> &otherVector)
{
    DEBUGLOG(this, "HostVector::Substract()", "Vec = " << &otherVector, 2);
    const HostVector<ValueType> *cast_vec = 
        dynamic_cast<const HostVector<ValueType>*> (&otherVector);
    for (int i=0; i<this->mSize; i++)
    {
        mData[i] = mData[i] - cast_vec->mData[i];
    }
    DEBUGEND();

}
Ejemplo n.º 28
0
double HostVector<ValueType>::Norm(void) const
{
    DEBUGLOG(this, "HostVector::Norm()", "Empty" , 2);
    double result = 0.0;
    for (int i=0; i<mSize; ++i)
    {
       result += mData[i]*mData[i];
    }

    DEBUGEND();
    return std::sqrt((double)result);

}
Ejemplo n.º 29
0
Vector<ValueType>::Vector(int size, const ValueType val)
{
    DEBUGLOG( this, "Vector::Vector()", 
            "size = " << size << " val = " <<val, 1);
    assert(size>0);
    pImplHost = std::shared_ptr<HostVector<ValueType>>
                                (new HostVector<ValueType>());
    pImplHost->Allocate(size);
    pImpl = pImplHost;
    pImpl->SetVal(val);
    DEBUGEND();

}
Ejemplo n.º 30
0
void OdfChartReader::readElementChartPlotArea(KoXmlStreamReader &reader)
{
    DEBUGSTART();
    m_backend->elementChartPlotArea(reader, m_context);

    // <chart:plot-area> has the following children in ODF 1.2:
    //   [done] <chart:wall> 11.6
    //   [done] <chart:floor> 11.7
    //   [done] <chart:axis> 11.8
    //   [done] <chart:series> 11.11
    //   [done] <chart:stock-gain-marker> 11.19
    //   [done] <chart:stock-loss-marker> 11.20
    //   [done] <chart:stock-range-line> 11.21
    //          <dr3d:light> 10.5.3
    while (reader.readNextStartElement()) {
        QString tagName = reader.qualifiedName().toString();
        
	if (tagName == "chart:wall") {
	    readElementChartWall(reader);
        }
        else if (tagName == "chart:floor") {
	    readElementChartFloor(reader);
        }
        else if (tagName == "chart:axis") {
	    readElementChartAxis(reader);
        }
        else if (tagName == "chart:series") {
	    readElementChartSeries(reader);
        }
        else if (tagName == "chart:stock-gain-marker") {
	    readElementChartStockGainMarker(reader);
        }
        else if (tagName == "chart:stock-loss-marker") {
	    readElementChartStockLossMarker(reader);
        }
        else if (tagName == "chart:stock-range-line") {
	    readElementChartStockRangeLine(reader);
        }
        else if (tagName == "dr3d:light") {
            // FIXME: NYI
            reader.skipCurrentElement();
        }
        else {
            reader.skipCurrentElement();
        }
    }

    m_backend->elementChartPlotArea(reader, m_context);
    DEBUGEND();
}