void TMetaProtoSerial::DuplicateSingleRepeated(ui32 duplicateFactor) { if (IsOutput()) return; TProtoSerial serial(Message, Mode); for (int fi=0; fi < Descr->field_count(); ++fi) { auto* fd = Descr->field(fi); if (fd->is_repeated()) { serial.DuplicateSingleRepeated(fd->number(), duplicateFactor); } } }
void IRShaderParam::WriteDecl(std::ostream& out, unsigned int indent) const { out << std::setw(indent) << ""; if (IsOutput()) out << "output "; out << IRDetailToString(GetDetail()) << " " << *GetType() << " " << GetShortName(); IRStmt* init = GetInitStmt(); assert(init != NULL && "Initializer should never be NULL"); if (!init->IsEmpty()) { out << " = "; init->WriteInit(out, this, indent+4); } }
/*virtual*/ Dictionary Variable::Serialize() const { if (IsOutput()) { LogicError("Output variables cannot be saved"); } Dictionary dict; dict[versionKey] = CurrentVersion(); dict[typeKey] = s_variableTypeValue; dict[uidKey] = Uid(); dict[kindKey] = static_cast<size_t>(Kind()); dict[dataTypeKey] = static_cast<size_t>(GetDataType()); const auto& dynamicAxes = DynamicAxes(); vector<DictionaryValue> dictionaryValueVector; dictionaryValueVector.reserve(dynamicAxes.size()); for (const auto& axis : dynamicAxes) dictionaryValueVector.push_back(axis); dict[dynamicAxisKey] = dictionaryValueVector; dict[isSparseKey] = IsSparse(); if (!Name().empty()) dict[nameKey] = Name(); dict[needsGradientKey] = NeedsGradient(); dict[shapeKey] = Shape(); if (IsParameter() || IsConstant()) { NDArrayView* value = Value().get(); if (value == nullptr) { LogicError("Uninitialized Parameter variable cannot be saved"); } // TODO: add a dictionary value constructor with an rvalue parameter. dict[valueKey] = DictionaryValue(*value); } return dict; }
void TProtoSerial::DuplicateSingleRepeated(int protoField, ui32 size, bool allow_zero) { if (IsOutput()) return; auto* fd = GetFieldDescr(protoField); ENSURE(fd->is_repeated(), "Can't duplicate non repeated field"); ui32 actual_size = Refl->FieldSize(Message, fd); ENSURE((actual_size > 0) || allow_zero, "Can't duplicate field without elements, zero are not allowed"); if ((actual_size == 0) || (actual_size == size)) { return; } if (actual_size != 1) { L_DEBUG << "Size of repeated field must equal to " << size << " or be 1 so we can duplicate this message " << size << " times for you (now it's " << actual_size << "), so we skipping duplicating"; return; } L_DEBUG << "Duplicating " << fd->name() << " " << size << " times"; auto* baseMessage = Refl->MutableRepeatedPtrField<NPb::Message>(&Message, fd)->Mutable(0); while (Refl->FieldSize(Message, fd) < size) { NPb::Message* newMessage = Refl->AddMessage(&Message, fd); newMessage->CopyFrom(*baseMessage); } }