本文整理汇总了C++中MatrixPtr::copyByRowIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixPtr::copyByRowIndex方法的具体用法?C++ MatrixPtr::copyByRowIndex怎么用?C++ MatrixPtr::copyByRowIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixPtr
的用法示例。
在下文中一共展示了MatrixPtr::copyByRowIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: forward
void ExpandLayer::forward(PassType passType) {
Layer::forward(passType);
// Expand layer should have exactly 2 input, one for data, one for size
CHECK_EQ(2U, inputLayers_.size());
// using two input:
// * first one for data;
// * second one only for sequence info
const Argument& shapeInput = getInput(1);
const Argument& dataInput = getInput(0);
size_t outputBatchSize = shapeInput.getBatchSize();
auto startPositions = type_ ? shapeInput.subSequenceStartPositions
: shapeInput.sequenceStartPositions;
size_t numSequences = startPositions->getSize() - 1;
const int* starts = startPositions->getData(false);
CHECK_EQ(starts[numSequences], shapeInput.getBatchSize());
if (type_) {
// when trans_type = seq, input[1] must hasSubseq
CHECK_EQ(shapeInput.hasSubseq(), 1UL);
CHECK_EQ(dataInput.getNumSequences(), shapeInput.getNumSequences());
} else {
CHECK_EQ(dataInput.getBatchSize(), shapeInput.getNumSequences());
}
// set output sequence info as shape sequence
output_.sequenceStartPositions = shapeInput.sequenceStartPositions;
if (shapeInput.hasSubseq()) {
output_.subSequenceStartPositions = shapeInput.subSequenceStartPositions;
}
// reserve output: Expand output to batchsize of sequence data.
reserveOutput(outputBatchSize, dataInput.value->getWidth());
MatrixPtr inputValue = getInputValue(0);
MatrixPtr outputValue = getOutputValue();
ICpuGpuVector::resizeOrCreate(expandStartsPos_, outputBatchSize, false);
int* expandStarts = expandStartsPos_->getMutableData(false);
for (size_t sequenceId = 0; sequenceId < numSequences; ++sequenceId) {
int sequenceLength = starts[sequenceId + 1] - starts[sequenceId];
for (int j = 0; j < sequenceLength; j++) {
expandStarts[starts[sequenceId] + j] = sequenceId;
}
}
outputValue->copyByRowIndex(*inputValue,
*expandStartsPos_->getVector(useGpu_));
if (biases_.get() != NULL) {
outputValue->addBias(*(biases_->getW()), 1);
}
}