Changeset 23d43bc in tol


Ignore:
Timestamp:
Nov 9, 2009, 10:19:41 AM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
3affc27
Parents:
883e960
Message:

Fixes #778

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

Location:
tol/btol/vmatrix_type
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/vmatrix_type/tol_bvmat.h

    r883e960 r23d43bc  
    426426                    double minSparse = 0.5,
    427427                    double drop = 0.0);
     428  void DMat2tripletUnique(const BMatrix<double>& d, int nrow, int columns);
    428429  void DMat2triplet(const BMatrix<double>& d, int nrow, int columns);
    429430  void DMat2triplet(const BMatrix<double>& d, int nrow, int columns,
  • tol/btol/vmatrix_type/tol_bvmat_impl.h

    r883e960 r23d43bc  
    3232#include "cholmod.h"
    3333#pragma pack(4)
    34 typedef hash_map_by_BIntPair<double>::sparse_ BHashPairs;
     34typedef hash_map_by_BIntPair<double>::sparse_ BHashDoubleByIntPair;
     35typedef hash_map_by_BIntPair<bool>::sparse_ BHashBoolByIntPair;
    3536
    3637BEGIN_DECLS
  • tol/btol/vmatrix_type/vmat_convert.cpp

    r883e960 r23d43bc  
    457457  }
    458458};
     459
     460
     461////////////////////////////////////////////////////////////////////////////////
     462  void BVMat::DMat2tripletUnique(const BMatrix<double>& ijx, int nrow, int ncol)
     463//Importing method
     464//Converts a row major BMatrix<double> to a column major cholmod dense matrix
     465////////////////////////////////////////////////////////////////////////////////
     466{
     467  BHashBoolByIntPair hashPairs;
     468  BIntPair p;
     469  double x;
     470  static BText fName = "TripletUnique";
     471  Delete();
     472  int h, k, n = ijx.Rows();
     473  code_  = ESC_chlmRtriplet;
     474  s_.chlmRtriplet_ = cholmod_allocate_triplet
     475    (nrow,ncol,n,0,CHOLMOD_REAL,common_);
     476  int*    r_ = (int*)   s_.chlmRtriplet_->i;
     477  int*    c_ = (int*)   s_.chlmRtriplet_->j;
     478  double* x_ = (double*)s_.chlmRtriplet_->x;
     479  bool ok = true;
     480  k=-1;
     481  for(h=0; h<n; h++)
     482  {
     483    p.r_ = (int)ijx(h,0)-1;
     484    p.c_ = (int)ijx(h,1)-1;
     485    x = ijx(h,2);
     486    if(x==0.0) { continue; }
     487    BHashBoolByIntPair::const_iterator fc = hashPairs.find(p);
     488    if(fc!=hashPairs.end()) { continue; }
     489    hashPairs[p] = true;
     490    k++;
     491    r_[k] = p.r_;
     492    c_[k] = p.c_;
     493    x_[k] = x;
     494
     495    if((r_[k]<0)||(r_[k]>=nrow))
     496    {
     497      err_cannot_apply(fName,
     498        BText("Row index ")+(r_[k]+1)+" out of range 1..."+(nrow+1),
     499        *this);
     500      ok = false;
     501      break;
     502    }
     503    else if((c_[k]<0)||(c_[k]>=ncol))
     504    {
     505      err_cannot_apply(fName,
     506        BText("Columns index ")+(c_[k]+1)+" out of range 1..."+(ncol+1),
     507        *this);
     508      ok = false;
     509      break;
     510    }
     511    s_.chlmRtriplet_->nnz++;
     512  }
     513  if(!ok) { Delete(); }
     514};
     515
    459516
    460517
  • tol/btol/vmatrix_type/vmatgra.cpp

    r883e960 r23d43bc  
    485485}
    486486
    487 
    488487//--------------------------------------------------------------------
    489488DeclareContensClass(BVMat, BVMatTemporary, BVMatTriplet);
    … …  
    500499     "It's posible to remap row and column indexes of cells by specifying it "
    501500     "with rowIdx and colIdx arguments, that must be row or column matrices "
    502      "of integer numbers.",
     501     "of integer numbers."
     502     "CAUTION: Repeated cells will be summed!. To avoid this use "
     503     "TripletUnique" ,
    503504     "Construye una VMatrix Cholmod.R.Triplet T con la sdimensiones dadas a "
    504505     "partir de una lista de tripletas ijx que pueden expresarse bien "
    … …  
    509510     "Es posible reubicar los índices de las filas y columnas de las celdas "
    510511     "especificándolo con los argumentos rowIdx y colIdx, que deben ser "
    511      "matrices fila o columna de números enteros."),
     512     "matrices fila o columna de números enteros.\n"
     513     "CUIDADO: ¡Las celdas repetidas serán sumadas! Para evitarlo use "
     514     "TripletUnique"),
    512515BOperClassify::MatrixAlgebra_);
    513516//--------------------------------------------------------------------
    … …  
    612615
    613616//--------------------------------------------------------------------
     617DeclareContensClass(BVMat, BVMatTemporary, BVMatTripletUnique);
     618DefExtOpr(1, BVMatTripletUnique, "TripletUnique", 3, 3,
     619  "Matrix Real Real",
     620  "(Matrix ijx, Real nrow, Real ncol)",
     621  I2("Creates a Cholmod.R.Triplet VMatrix T of given dimensions from a list "
     622     "of triplets ijx that can be expressed as a matrix with three columns. "
     623     "Each triplet (i,j,x) defines an stored cell T[i,j]=x. Non listed ones are "
     624     "assumed as zero. If row i or columns j index are not integers will be "
     625     "truncated.\n"
     626     "It's posible to remap row and column indexes of cells by specifying it "
     627     "with rowIdx and colIdx arguments, that must be row or column matrices "
     628     "of integer numbers.",
     629     "Construye una VMatrix Cholmod.R.Triplet T con la sdimensiones dadas a "
     630     "partir de una lista de tripletas ijx que pueden expresarse bien "
     631     "como un conjunto de conjuntos de tres números cada uno, bien como "
     632     "una matriz con tres columnas. Cada tripleta (i,j,x) define una celda "
     633     "almacenada T(i,j)=x. Las celdas no listadas se asumen como cero.\n"
     634     "Si los índices de fila i ó columna j no son enteros serán truncados.\n"
     635     "Es posible reubicar los índices de las filas y columnas de las celdas "
     636     "especificándolo con los argumentos rowIdx y colIdx, que deben ser "
     637     "matrices fila o columna de números enteros."),
     638BOperClassify::MatrixAlgebra_);
     639//--------------------------------------------------------------------
     640void BVMatTripletUnique::CalcContens()
     641//--------------------------------------------------------------------
     642{
     643  BMatrix<double>& ijx = (BMatrix<double>&)Mat(Arg(1));
     644  int nrow = (int)Real(Arg(2));
     645  int ncol = (int)Real(Arg(3));
     646  contens_.DMat2tripletUnique(ijx,nrow,ncol);
     647}
     648
     649//--------------------------------------------------------------------
    614650DeclareContensClass(BMat, BMatTemporary, BMatVMat2Triplet);
    615651DefExtOpr(1, BMatVMat2Triplet, "VMat2Triplet", 1, 2,
    … …  
    628664  V.GetTriplet((BMatrix<double>&)contens_);
    629665}
     666
    630667
    631668//--------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.