// File: /workspace/github_cpp_makefile_star2_O2/xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::InitFilters()
void ConstructLayer::InitFilters()
{
    // clear previous filter
    __activeFlag.clear();

    // init filter 2d matrix, fill true value to all elements
    if(__type == LayerType::input)
    {
        if(__layerDimension == LayerDimension::_1D)
        {
            assert(__neurons.size() == 1); // only one kernel
            auto dim = __neurons[0].Dimension();
            Filter2D f(dim.first, dim.second); // default to true
            __activeFlag.push_back(f);
        }
        else if(__layerDimension == LayerDimension::_2D)
        {
            // 2D input layer need a fake filter with dimension (number_of_fake_neurons, 1), similar like 1D
            // this is just in case one directly connect a 2D input layer to a 1D fc layer
            //
            // since filters in 2D middle layers are not used, so it is safe to code like 1D case
            assert(__neurons.size() == 1); // only one kernel
            auto dim = __neurons[0].Dimension(); // for 2D layer, the fake neurons has also been initialized
            Filter2D f(dim.first, dim.second); // default to true
            __activeFlag.push_back(f);
        }
    }
    else if(__type == LayerType::output)
    {
        assert(__neurons.size() == 1); // only one kernel
        auto dim = __neurons[0].Dimension();
        assert(dim.second == 1); // only one collum
        Filter2D f(dim.first, dim.second); // default to true
        __activeFlag.push_back(f);
    }
    else if(__type == LayerType::fullyConnected)
    {
        assert(__neurons.size() == 1);
        auto dim = __neurons[0].Dimension();
        Filter2D f(dim.first, dim.second); // default to true
        __activeFlag.push_back(f);
    }
    else if(__type == LayerType::cnn || __type == LayerType::pooling)
    {
        size_t nKernels = __weightMatrix.size();
        for(size_t i=0;i<nKernels;i++)
        {
            auto dim = __weightMatrix[i].Dimension();
            Filter2D f(dim.first, dim.second); // default to true
            __activeFlag.push_back(f);
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %r14
leaq 0x108(%rdi), %rbx
movq %rbx, %rdi
callq 0x112de
movl 0xc(%r14), %eax
cmpq $0x4, %rax
ja 0x690c
leaq 0x1a8fe(%rip), %rcx     # 0x210a8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x68(%r14), %rax
subq 0x60(%r14), %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
movq %rax, %r15
xorl %r13d, %r13d
leaq 0x8(%rsp), %r12
subq $0x1, %r15
jb 0x690c
movq 0x60(%r14), %rdi
addq %r13, %rdi
callq 0x17a6a
movq %r12, %rdi
movq %rax, %rsi
callq 0x112e6
movq %rbx, %rdi
movq %r12, %rsi
callq 0x11368
movq %r12, %rdi
callq 0x11e36
addq $0x18, %r13
jmp 0x67ce
movq 0x40(%r14), %rdi
movq 0x48(%r14), %rax
subq %rdi, %rax
cmpq $0x18, %rax
jne 0x691a
callq 0x111fe
cmpq $0x1, %rdx
jne 0x6958
leaq 0x8(%rsp), %r14
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x112e6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11368
jmp 0x6902
movq 0x40(%r14), %rdi
movq 0x48(%r14), %rax
subq %rdi, %rax
cmpq $0x18, %rax
jne 0x6939
callq 0x111fe
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x112e6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11368
jmp 0x6902
movl 0x408(%r14), %eax
cmpl $0x1, %eax
je 0x68cd
testl %eax, %eax
jne 0x690c
movq 0x40(%r14), %rdi
movq 0x48(%r14), %rax
subq %rdi, %rax
cmpq $0x18, %rax
jne 0x6977
callq 0x111fe
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x112e6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11368
jmp 0x6902
movq 0x40(%r14), %rdi
movq 0x48(%r14), %rax
subq %rdi, %rax
cmpq $0x18, %rax
jne 0x6996
callq 0x111fe
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x112e6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11368
leaq 0x8(%rsp), %rdi
callq 0x11e36
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x1af6f(%rip), %rdi     # 0x21890
leaq 0x1adb2(%rip), %rsi     # 0x216da
leaq 0x1af77(%rip), %rcx     # 0x218a6
movl $0x21b, %edx            # imm = 0x21B
callq 0x4180
leaq 0x1af50(%rip), %rdi     # 0x21890
leaq 0x1ad93(%rip), %rsi     # 0x216da
leaq 0x1af58(%rip), %rcx     # 0x218a6
movl $0x223, %edx            # imm = 0x223
callq 0x4180
leaq 0x1b6ac(%rip), %rdi     # 0x2200b
leaq 0x1ad74(%rip), %rsi     # 0x216da
leaq 0x1af39(%rip), %rcx     # 0x218a6
movl $0x21d, %edx            # imm = 0x21D
callq 0x4180
leaq 0x1af12(%rip), %rdi     # 0x21890
leaq 0x1ad55(%rip), %rsi     # 0x216da
leaq 0x1af1a(%rip), %rcx     # 0x218a6
movl $0x208, %edx            # imm = 0x208
callq 0x4180
leaq 0x1aef3(%rip), %rdi     # 0x21890
leaq 0x1ad36(%rip), %rsi     # 0x216da
leaq 0x1aefb(%rip), %rcx     # 0x218a6
movl $0x213, %edx            # imm = 0x213
callq 0x4180
jmp 0x69bd
jmp 0x69bd
jmp 0x69bd
jmp 0x69bd
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x11e36
movq %rbx, %rdi
callq 0x43b0