.. _program_listing_file_src_translator_helpers.cpp: Program Listing for File helpers.cpp ==================================== |exhale_lsh| :ref:`Return to documentation for file ` (``src/translator/helpers.cpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* All or part of this file was contributed by Intel under license: * Copyright (C) 2017-2018 Intel Corporation * SPDX-License-Identifier: MIT */ #include #include "data/types.h" #include "tensors/tensor.h" #include "translator/helpers.h" namespace marian { namespace cpu { void SetColumns(Tensor in, Tensor indices, float value) { int nRows = in->shape().elements() / in->shape()[-1]; int nColumns = in->shape()[-1]; int nSuppress = indices->shape()[-1]; for(int rowNumber = 0; rowNumber < nRows; ++rowNumber) { float* row = in->data() + rowNumber * nColumns; for(int i = 0; i < nSuppress; ++i) row[indices->data()[i]] = value; } } void suppressWords(Expr logProbs, Expr wordIndices) { SetColumns(logProbs->val(), wordIndices->val(), std::numeric_limits::lowest()); } } // namespace cpu void suppressWords(Expr logProbs, Expr wordIndices) { if(logProbs->val()->getBackend()->getDeviceId().type == DeviceType::cpu) { cpu::suppressWords(logProbs, wordIndices); } #ifdef CUDA_FOUND else { gpu::suppressWords(logProbs, wordIndices); } #endif } } // namespace marian