#ifndef LCF_SOFTMAX_LOST_IMG_H_
#define LCF_SOFTMAX_LOST_IMG_H_
#include "tensorOperate.h"
#include "readPixCnfClassify.h"

// Softmax Hot map
class SoftMaxLostImgLayer : public TensorOperate
{
    public:
        SoftMaxLostImgLayer(int ifType, int iID, int iMaxSeqNum, DevicesBatchDisptach *iDevicesBatchDisptach, SLTYPE lossType);
        virtual ~SoftMaxLostImgLayer();
        void ComputeAndCreateOutYInDTensorInfo();
        void InputTrainLabelData(float *inlableData);
        void InputTrainLabelData(int devID, float *inlableData, int i);
        void SetLostType(SLTYPE lossType);
        void SetFLAlpha(float *dCoff, int ch);
        void CompuateOutY(int devID, int seqNum);
        void CompuateOutD(int devID, int seqNum);
        void SaveLayerWeight(int n);
        void LoadLayerWeight();
        float GetThisBatchAveLost();
        int GetHotMap(float *hotMapBuff, int devID, int i);
        int GetHotMapPab(float *hotMapPabBuff, int devID, int i);
        void GetHotMap(float *hotMapBuff);
        void GetHotMapPab(float *hotMapPabBuff);
        int GetHotMapHW();
        void ComputerYMemRealease(int devID);
        void ComputerDMemRealease(int devID);
        void CreateParaAndInstance();
        void SetSrcLabelHW(int h, int w);
        void DebugReadPixClassify(const char *xmlCnfName);
        TensorData *GetLableData(int devID, int seqNum);
        TensorData *GetMaxMat(int devID, int seqNum);
        TensorData *GetMaxPabMat(int devID, int seqNum);
        TensorData *GetLost(int devID, int seqNum);
        void CompYEventAction(int devID, int seqNum);
        float GetThisBatchAveLost(int devID, int seqNum);

    private:
        void SetChildLayerMomeryPointInitStatus();
        void RealeaseChildLayerMemory();
        void ComputeYOutByYIn(MemoryHandle *resultYCMem, MemoryHandle *inYCMem);
        TensorData *mLableData;              // mLableData[batchNum][outHeight][outWidth]
        TensorData *maxMat;                  // softmax result maxMat[batchNum][outHeight][outWidth]
        TensorData *maxPabMat;               // softmax index matrix maxPabMat[batchNum][outHeight][outWidth]
        TensorData *mLost;                   // mLost[batchNum][outHeight][outWidth]
        float gamma;                         // Focas Loss coff
        SLTYPE mLostType;                    // SL or FL ...
        ReadPixCnfClassify mReadPixCnfClassify;
        int mSrcLabelH;
        int mSrcLabelW;
        int mIfReadPixCnfClassify;
        
        int inChannels, inHeight, inWidth;
        int outChannels, outHeight, outWidth;    
};

#endif
