summaryrefslogtreecommitdiff
path: root/modules/overloading/macros/%hm_and.sci
blob: a08083b4a7745dee5f298073f44e4253bfc22bb1 (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
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2010 - INRIA - Serge Steer
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

function x=%hm_and(m,d)
    if argn(2)==1|d=="*" then
        x=and(m.entries);
        return
    end
    dims=m.dims;
    if d=="m" then
        d=find(dims>1,1)
        if d==[] then
            x=and(m.entries);
            return
        end
    end
    if type(dims)==8 then
        flag=1;
        dims=double(dims);
    else
        flag=0;
    end
    N=size(dims,"*");
    p1=prod(dims(1:d-1));// step to build one vector on which and is applied
    p2=p1*dims(d);//step for beginning of next vectors
    ind=(0:p1:p2-1)';// selection for building one vector
    deb=(1:p1);
    I=ind*ones(deb)+ones(ind)*deb

    ind=(0:p2:prod(dims)-1);
    I=ones(ind).*.I+ind.*.ones(I)

    x=and(matrix(m.entries(I),dims(d),-1),1);

    dims(d)=1
    while  dims($)==1 then
        dims($)=[];
    end
    if d==N then
        dims=dims(1:$);
    else
        dims(d)=1;
    end
    if size(dims,"*")==2 then
        x=matrix(x,dims(1),dims(2));
    elseif dims<>[] then
        if flag==1 then
            dims=int32(dims);
        end
        x=hypermat(dims,x);
    end
endfunction