Changeset 20f76bc in tol


Ignore:
Timestamp:
Aug 13, 2010, 11:08:53 PM (16 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
aebb9ee
Parents:
15ee97c
Message:

New built-in function Matrix InversePermutation

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@2468 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/matrix_type/matgra.cpp

    r15ee97c r20f76bc  
    17131713  }
    17141714  PivotByRows(contens_,pivots);
     1715}
     1716
     1717//--------------------------------------------------------------------
     1718DeclareContensClass(BMat, BMatTemporary, BMatInversePermutation);
     1719DefExtOpr(1, BMatInversePermutation, "InversePermutation", 1, 1, "Matrix",
     1720  "(Matrix p)",
     1721  I2("Given a column or row of any realignment of integers numbers "
     1722     "1 ... N returns the inverse permutation. ",
     1723     "Dada una fila o columna con una reordenación cualquiera de "
     1724     "los enteros 1 ... N, devuelve la permutación inversa."),
     1725    BOperClassify::MatrixAlgebra_);
     1726//--------------------------------------------------------------------
     1727void BMatInversePermutation::CalcContens()
     1728//--------------------------------------------------------------------
     1729{
     1730  BMat& P  = Mat(Arg(1));
     1731  int i, k, n = P.Data().Size();
     1732  int pr = P.Rows();
     1733  int pc = P.Columns();
     1734  if((pr!=1) && (pc!=1))
     1735  {
     1736    Error(I2("Cannot apply InversePermutation to non vectorial matriz ",
     1737               "No se puede aplicar InversePermutation a la matriz no vectorial ")+
     1738            "p("+pr+"x"+pc+") ");
     1739    return;
     1740  }
     1741  contens_.Alloc(pr,pc);
     1742  const double* p = (const double*)P.Data().Buffer();
     1743  double* c = (double*)contens_.GetData().GetBuffer();
     1744  for(i=1; i<=n; i++, p++)
     1745  {
     1746    k = (int)(*p);
     1747    c[k-1] = i;
     1748  //Std(BText("\n[InversePermutation] ")+k+" -> "+i)
     1749  }
    17151750}
    17161751
Note: See TracChangeset for help on using the changeset viewer.