Exemplo n.º 1
0
void Avx2Mat4x4TestF64(const Matrix<double>& m1, const Matrix<double>& m2)
{
    if (!Matrix<double>::IsConforming(m1, m2))
        throw runtime_error("Non-conforming operands - Avx2Mat4x4TestF64");

    const size_t nrows = m1.GetNumRows();
    const size_t ncols = m1.GetNumCols();

    if (nrows != 4 || ncols != 4)
        throw runtime_error("Invalid size - Avx2Mat4x4TestF64");

    Matrix<double> m3_a(nrows, ncols);
    Matrix<double> m3_b(nrows, ncols);

    Matrix<double>::Mul(m3_a, m1, m2);
    Avx2Mat4x4MulF64_(m3_b.Data(), m1.Data(), m2.Data());

    cout << "\nResults for Avx2Mat4x4TestF64\n";

    cout << "\nMatrix m3_a\n";
    cout << m3_a << endl;

    cout << "\nMatrix m3_b\n";
    cout << m3_b << endl;

    double tr_a = m1.Trace();
    double tr_b = Avx2Mat4x4TraceF64_(m1.Data());
    cout << "tr_a = " << tr_a << '\n';
    cout << "tr_b = " << tr_b << '\n';
}
Exemplo n.º 2
0
Matrix  SegmentorOTSU::DotDiv (const Matrix&  left,
                               const Matrix&  right
                              )
{
  kkint32  maxNumOfRows = Max (left.NumOfRows (), right.NumOfRows ());
  kkint32  maxNumOfCols = Max (left.NumOfCols (), right.NumOfCols ());
  
  kkint32  minNumOfRows = Min (left.NumOfRows (), right.NumOfRows ());
  kkint32  minNumOfCols = Min (left.NumOfCols (), right.NumOfCols ());

  Matrix  result (maxNumOfRows, maxNumOfCols);

  double const * const * leftData   = left.Data  ();
  double const * const * rightData  = right.Data ();
  double**               resultData = result.DataNotConst ();

  kkint32  r, c;

  for  (r = 0;  r < minNumOfRows;  ++r)
  {
    double const *  leftDataRow   = leftData[r];
    double const *  rightDataRow  = rightData[r];
    double*         resultDataRow = resultData[r];

    for  (c = 0;  c < minNumOfCols;  ++c)
      resultDataRow[c] = leftDataRow[c] / rightDataRow[c];
  }

  for  (r = minNumOfRows;  r < maxNumOfRows;  ++r)
  {
    double*  resultDataRow = resultData[r];
    for  (c = minNumOfCols;  c < maxNumOfCols;  ++c)
    {
      if  ((r >= right.NumOfRows ())  ||  (c >= right.NumOfCols ()))
        resultDataRow[c] = NaN;

      else if  (rightData[r][c] == 0.0)
        resultDataRow[c] = NaN;

      else
        resultDataRow[c] = 0.0;
    }
  }

  return  result;
}  /* DotDiv */
Exemplo n.º 3
0
void renderFrame(void)
{
	//glViewport(0, 0, 600, 800);
	// Get parameters from Effect
	Effect* effect = sprite.GetEffect();
	GLint u_MVPMatrix_handle = glGetUniformLocation(effect->GetProgramHandle(),"u_MVPMatrix");
	GLint a_Position_handle = glGetAttribLocation(effect->GetProgramHandle(), "a_Position");
	GLint a_TexCoordinate = glGetAttribLocation(effect->GetProgramHandle(), "a_TexCoordinate");
	GLint mTextureUniformHandle = glGetUniformLocation(effect->GetProgramHandle(), "u_Texture");

	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_TEXTURE_2D);

	glUseProgram(sprite.GetEffect()->GetProgramHandle());

	glActiveTexture(GL_TEXTURE0);
	// Bind the texture to this unit.
	Texture* texture = (Texture*)sprite.GetTexture();
	const GLuint thandle = texture->GetTextureHandle();
	glBindTexture(GL_TEXTURE_2D, thandle);  //sprite.GetTexture()->GetTextureHandle());
	// Tell the texture uniform sampler to use this texture in the shader by binding to texture unit 0.
	glUniform1i(mTextureUniformHandle, 0);



	// Set position attribute and MVP matrix uniform
	glVertexAttribPointer(a_Position_handle, 3, GL_FLOAT, false, 0, Sprite::GetVertexPosStatic());
	glEnableVertexAttribArray(a_Position_handle);

	glVertexAttribPointer(a_TexCoordinate, 2, GL_FLOAT, false, 0, Sprite::GetVertexTexStatic());
	glEnableVertexAttribArray(a_TexCoordinate);
	const Matrix *proj;
	proj = camera.GetProjection();
	std::string s;

	Matrix projworld;
	Matrix world;

	world = Matrix::Translation(0,0,zoom);
	Matrix::Multiply(*proj,world, projworld);
	glUniformMatrix4fv(u_MVPMatrix_handle, 1, false, projworld.Data());

	std::cout << std::flush;
	glDrawArrays(GL_TRIANGLES, 0, 6);
	//glFlush();
}
Exemplo n.º 4
0
void MatrixQuantizerCPU<ElemType>::QuantizeAsync(const Matrix<ElemType>& inMatrix, const Matrix<ElemType>& inResidual, QuantizedMatrix<ElemType>& outQMatrix, Matrix<ElemType>& outResidual, bool zeroThresholdFor1Bit)
{
    // The outQMatrix should be on the CPU
    // TODO: Support transferring the quantization output to a quantized matrix on the GPU
    assert(outQMatrix.GetDeviceId() == CPUDEVICE);

    size_t nBits = outQMatrix.GetNumBits();

    size_t nRow = inMatrix.GetNumRows();
    size_t nCol = inMatrix.GetNumCols();

    // Verify that the different matrix parameters have matching dimensions
    assert((outQMatrix.GetNumRows() == nRow) && (outQMatrix.GetNumCols() == nCol));
    assert((inResidual.GetNumRows() == nRow) && (inResidual.GetNumCols() == nCol));
    assert((outResidual.GetNumRows() == nRow) && (outResidual.GetNumCols() == nCol));

    const size_t ldNbits = ValueQuantizer<ElemType>::ld(nBits);
#ifdef QUANTUSEPPL
    Concurrency::parallel_for((size_t) 0, us.cols(), [&](size_t j)
#else
    for (size_t j = 0; j < nCol; j++)
#endif
    {
        auto& qcol = *(outQMatrix.GetQuantizedColumn(j));
        if (zeroThresholdFor1Bit)
        {
            // Explicit use of 'template' keyword is needed to compile with GCC
            ColumnQuantizer<ElemType>::template ComputeRangeStatColj<true>(inMatrix.Data(), inResidual.Data(), (long) nRow, j, nBits, qcol.lower, qcol.upper);
        }
        else
        {
            // Explicit use of 'template' keyword is needed to compile with GCC
            ColumnQuantizer<ElemType>::template ComputeRangeStatColj<false>(inMatrix.Data(), inResidual.Data(), (long) nRow, j, nBits, qcol.lower, qcol.upper);
        }

        ColumnQuantizer<ElemType> q(ldNbits, qcol.lower, qcol.upper);
        if (zeroThresholdFor1Bit)
        {
            // Explicit use of 'template' keyword is needed to compile with GCC
            q.template Quantize<true>(inMatrix.Data(), inResidual.Data(), (long) nRow, j, qcol.bits, outResidual.Data());
        }
        else
        {
            // Explicit use of 'template' keyword is needed to compile with GCC
            q.template Quantize<false>(inMatrix.Data(), inResidual.Data(), (long) nRow, j, qcol.bits, outResidual.Data());
        }
    }
#ifdef QUANTUSEPPL
    );
Exemplo n.º 5
0
Matrix  SegmentorOTSU::Power (const Matrix&  left,
                              double         right
                             )
{
  kkuint32 numOfRows = left.NumOfRows ();
  kkuint32 numOfCols = left.NumOfCols ();

  Matrix  result (numOfRows, numOfCols);
  double const * const *  leftData = left.Data ();
  double**  resultData = result.DataNotConst ();

  kkuint32  r, c;
  for  (r = 0;  r < numOfRows;  ++r)
  {
    double const *  leftDataRow = leftData[r];
    double*  resultDataRow = resultData[r];
    for  (c = 0;  c < numOfCols;  ++c)
      resultDataRow[c] = pow (leftDataRow[c], right);
  }
  return  result;
}  /* Power */
Exemplo n.º 6
0
void AvxMat4x4TransposeF32(Matrix<float>& m_src)
{
    const size_t nr = 4;
    const size_t nc = 4;
    Matrix<float> m_des1(nr ,nc);
    Matrix<float> m_des2(nr ,nc);

    Matrix<float>::Transpose(m_des1, m_src);
    AvxMat4x4TransposeF32_(m_des2.Data(), m_src.Data());

    cout << fixed << setprecision(1);
    m_src.SetOstream(12, "  ");
    m_des1.SetOstream(12, "  ");
    m_des2.SetOstream(12, "  ");

    cout << "Results for AvxMat4x4TransposeF32\n";
    cout << "Matrix m_src \n" << m_src << '\n';
    cout << "Matrix m_des1\n" << m_des1 << '\n';
    cout << "Matrix m_des2\n" << m_des2 << '\n';

    if (m_des1 != m_des2)
        cout << "\nMatrix compare failed - AvxMat4x4TransposeF32\n";
}