Changeset 59dc492 in tol


Ignore:
Timestamp:
Nov 12, 2009, 9:04:47 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
3fd5f8b
Parents:
a8b5f73
Message:

Separating match and select methods

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol_pkg/MatQuery/MatQuery.tol

    ra8b5f73 r59dc492  
    1414   "vdebuen@tol-project.org"   ]];
    1515
     16
     17//////////////////////////////////////////////////////////////////////////////
     18Text _.autodoc.member.SelectMatch =
     19"Returns the rows where thecolumn matrix 'match' has non zero value";
     20Set SelectMatch(VMatrix match)
     21//////////////////////////////////////////////////////////////////////////////
     22{
     23  Matrix select = VMat2Triplet(Convert(match,"Cholmod.R.Triplet"));
     24  If(!Rows(select),Copy(Empty), MatSet(Tra(SubCol(select,[[1]])))[1])
     25};
     26
     27
     28//////////////////////////////////////////////////////////////////////////////
     29Text _.autodoc.member.MatchRowsWithValue =
     30"Returns a column matrix with True in rows where given column matrix M has "
     31"exactly the specified value";
     32VMatrix MatchRowsWithValue(VMatrix M, Real value)
     33//////////////////////////////////////////////////////////////////////////////
     34{
     35  Real r = VRows(M);
     36  VMatrix V = Rand(r,1,value,value);
     37  EQ(M,V)
     38};
     39
    1640//////////////////////////////////////////////////////////////////////////////
    1741Text _.autodoc.member.SelectRowsWithValue =
    … …  
    2044//////////////////////////////////////////////////////////////////////////////
    2145{
     46  SelectMatch(MatchRowsWithValue(M,value))   
     47};
     48
     49//////////////////////////////////////////////////////////////////////////////
     50Text _.autodoc.member.MatchRowsInInterval =
     51"Returns a column matrix with True in rows where given column matrix M is "
     52"inside the interval defined as: \n"
     53"  [min,max]: if minIncluded=True  and minIncluded=True\n"
     54"  (min,max]: if minIncluded=False and minIncluded=True\n"
     55"  [min,max): if minIncluded=True  and minIncluded=False\n"
     56"  (min,max): if minIncluded=False and minIncluded=False\n";
     57VMatrix MatchRowsInInterval(
     58  VMatrix M,
     59  Real minIncluded,
     60  Real min,
     61  Real max,
     62  Real maxIncluded )
     63//////////////////////////////////////////////////////////////////////////////
     64{
    2265  Real r = VRows(M);
    23   VMatrix V = Rand(r,1,value,value);
    24   VMatrix match = EQ(M,V);
    25   Matrix select = VMat2Triplet(Convert(match,"Cholmod.R.Triplet"));
    26   If(!Rows(select),Copy(Empty), MatSet(Tra(SubCol(select,[[1]])))[1])
     66  VMatrix Min = Rand(r,1,min,min);
     67  VMatrix Max = Rand(r,1,max,max);
     68  Case(
     69     minIncluded &  maxIncluded, And(LE(Min,M),LE(M,Max)),
     70    !minIncluded &  maxIncluded, And(LT(Min,M),LE(M,Max)),
     71     minIncluded & !maxIncluded, And(LE(Min,M),LT(M,Max)),
     72    !minIncluded & !maxIncluded, And(LT(Min,M),LT(M,Max))
     73  )
    2774};
    2875
    … …  
    4390//////////////////////////////////////////////////////////////////////////////
    4491{
     92  SelectMatch(MatchRowsInInterval(M,minIncluded,min,max,maxIncluded))   
     93};
     94
     95//////////////////////////////////////////////////////////////////////////////
     96Text _.autodoc.member.MatchRowsInHyperCube = "Returns a column matrix with "
     97"True in rows of matrix M which are inside the hipercube whose side length "
     98"is 2*d and is centered in point given by row matrix P ";
     99VMatrix MatchRowsInHyperCube(VMatrix M, VMatrix P, Real d)
     100//////////////////////////////////////////////////////////////////////////////
     101{
    45102  Real r = VRows(M);
    46   VMatrix Min = Rand(r,1,min,min);
    47   VMatrix Max = Rand(r,1,max,max);
    48   VMatrix match =
    49   Case(
    50      minIncluded &  maxIncluded, And(LE(Min,M),LE(M,Max)),
    51     !minIncluded &  maxIncluded, And(LT(Min,M),LE(M,Max)),
    52      minIncluded & !maxIncluded, And(LE(Min,M),LT(M,Max)),
    53     !minIncluded & !maxIncluded, And(LT(Min,M),LT(M,Max))
    54   );
    55   Matrix select = VMat2Triplet(Convert(match,"Cholmod.R.Triplet"));
    56   If(!Rows(select),Copy(Empty), MatSet(Tra(SubCol(select,[[1]])))[1])
     103  Real c = VColumns(M);
     104  VMatrix D = Rand(r,1,d,d);
     105  Group("And",For(1,c, VMatrix(Real k)
     106  {
     107    LE(Abs(SubCol(M,[[k]])-VMatDat(P,1,k)),D)
     108  }))
    57109};
    58110
    … …  
    64116//////////////////////////////////////////////////////////////////////////////
    65117{
    66   Real r = VRows(M);
    67   Real c = VColumns(M);
    68   VMatrix D = Rand(r,1,d,d);
    69   VMatrix match = Group("And",For(1,c, VMatrix(Real k)
    70   {
    71     LE(Abs(SubCol(M,[[k]])-VMatDat(P,1,k)),D)
    72   }));
    73   Matrix select = VMat2Triplet(Convert(match,"Cholmod.R.Triplet"));
    74   If(!Rows(select),Copy(Empty), MatSet(Tra(SubCol(select,[[1]])))[1])
     118  SelectMatch(MatchRowsInHyperCube(M,P,d))   
    75119};
    76120
    77121//////////////////////////////////////////////////////////////////////////////
    78 Text _.autodoc.member.SelectRowsInHyperSphere = "Selects rows of "
    79 "matrix M that are inside the hipersphere with specified  ratio and is "
    80 "centered in point given by row matrix P";
    81 Set SelectRowsInHyperSphere(VMatrix M, VMatrix P, Real ratio)
     122Text _.autodoc.member.MatchRowsInHyperSphere = "Returns a column matrix with "
     123"True in rows of matrix M which are inside the hipersphere with specified "
     124"ratio and is centered in point given by row matrix P";
     125VMatrix MatchRowsInHyperSphere(VMatrix M, VMatrix P, Real ratio)
    82126//////////////////////////////////////////////////////////////////////////////
    83127{
    … …  
    90134    RPow(SubCol(M,[[k]])-VMatDat(P,1,k),2)
    91135  }));
    92   VMatrix match = LE(dist2,R2);
    93   Matrix select = VMat2Triplet(Convert(match,"Cholmod.R.Triplet"));
    94   If(!Rows(select),Copy(Empty), MatSet(Tra(SubCol(select,[[1]])))[1])
     136  LE(dist2,R2)
     137};
     138
     139//////////////////////////////////////////////////////////////////////////////
     140Text _.autodoc.member.SelectRowsInHyperSphere = "Selects rows of "
     141"matrix M that are inside the hipersphere with specified  ratio and is "
     142"centered in point given by row matrix P";
     143Set SelectRowsInHyperSphere(VMatrix M, VMatrix P, Real ratio)
     144//////////////////////////////////////////////////////////////////////////////
     145{
     146  SelectMatch(MatchRowsInHyperSphere(M,P,ratio))   
    95147};
    96148
Note: See TracChangeset for help on using the changeset viewer.