summaryrefslogtreecommitdiff
path: root/src/stk_isdominated_mex.c
blob: cbcc6e730e7cb7c819c5a9b803d2a5eb82dbdd62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*****************************************************************************
 *                                                                           *
 *                  Small (Matlab/Octave) Toolbox for Kriging                *
 *                                                                           *
 * Copyright Notice                                                          *
 *                                                                           *
 *    Copyright (C) 2014 SUPELEC                                             *
 *                                                                           *
 *    Author:  Julien Bect  <julien.bect@centralesupelec.fr>                 *
 *                                                                           *
 * Copying Permission Statement                                              *
 *                                                                           *
 *    This file is part of                                                   *
 *                                                                           *
 *            STK: a Small (Matlab/Octave) Toolbox for Kriging               *
 *               (https://github.com/stk-kriging/stk/)                   *
 *                                                                           *
 *    STK is free software: you can redistribute it and/or modify it under   *
 *    the terms of the GNU General Public License as published by the Free   *
 *    Software Foundation,  either version 3  of the License, or  (at your   *
 *    option) any later version.                                             *
 *                                                                           *
 *    STK is distributed  in the hope that it will  be useful, but WITHOUT   *
 *    ANY WARRANTY;  without even the implied  warranty of MERCHANTABILITY   *
 *    or FITNESS  FOR A  PARTICULAR PURPOSE.  See  the GNU  General Public   *
 *    License for more details.                                              *
 *                                                                           *
 *    You should  have received a copy  of the GNU  General Public License   *
 *    along with STK.  If not, see <http://www.gnu.org/licenses/>.           *
 *                                                                           *
 ****************************************************************************/

#include "stk_mex.h"

typedef double SCALAR;
typedef mxLogical LOGICAL;
#include "pareto.h"

/* mimic ismember's syntax */
#define ARGIN_A       prhs[0]  /* n x d, double  */
#define ARGIN_B       prhs[1]  /* k x d, double  */
#define ARGOUT_ISDOM  plhs[0]  /* n x 1, logical */
#define ARGOUT_DRANK  plhs[1]  /* n x 1, double  */

/* IMPORTANT: the rows of B are assumed to be    */
/*            SORTED in the LEXICAL ORDER        */

void mexFunction
(
    int nlhs, mxArray *plhs[],
    int nrhs, const mxArray *prhs[]
)
{
    int i, n, k, d, *tmp_drank;
    double *xa, *xb, *drank;
    mxLogical *isdom;

    /*--- Check number of input/output arguments --------------------*/

    if (nrhs != 2)  /* Check number of input arguments */
        mexErrMsgTxt ("Incorrect number of input arguments.");

    if (nlhs > 2)   /* Check number of output arguments */
        mexErrMsgTxt ("Too many output arguments.");

    /*--- Check input types -----------------------------------------*/

    if (! stk_is_realmatrix (ARGIN_A))
        mexErrMsgTxt ("The first input argument should be a "
                      "real-valued double-precision array.");
    xa = mxGetPr (ARGIN_A);

    if (! stk_is_realmatrix (ARGIN_B))
        mexErrMsgTxt ("The second input argument should be a "
                      "real-valued double-precision array.");
    xb = mxGetPr (ARGIN_B);

    /*--- Read dimensions -------------------------------------------*/

    n = (int) mxGetM (ARGIN_A);
    d = (int) mxGetN (ARGIN_A);
    k = (int) mxGetM (ARGIN_B);

    if (d != mxGetN (ARGIN_B))
        mexErrMsgTxt ("The two input arguments should have the "
                      "same number of columns");

    /*--- Create arrays ---------------------------------------------*/

    ARGOUT_ISDOM = mxCreateLogicalMatrix (n, 1);
    isdom = mxGetLogicals (ARGOUT_ISDOM);

    tmp_drank = (int *) mxCalloc (n, sizeof (int));

    /*--- Find dominated rows ---------------------------------------*/

    is_dominated (xa, xb, isdom, tmp_drank, n, k, d);

    if (nlhs > 1) {
        ARGOUT_DRANK = mxCreateDoubleMatrix (n, 1, mxREAL);
        drank = mxGetPr (ARGOUT_DRANK);
        for (i = 0; i < n; i++)
            drank[i] = (double) (1 + tmp_drank[i]);
    }

    /*--- Cleanup --------------------------------------------------*/

    mxFree (tmp_drank);
}