void ParameterComboBox::onChanged(int idx)
{
	if(!suppressUpdate){
		if (object->dvt == Value::ValueType::STRING) {
			const std::string v = comboBox->itemData(idx).toString().toStdString();
			object->value = ValuePtr(v);
		} else {
			const double v = comboBox->itemData(idx).toDouble();
			object->value = ValuePtr(v);
		}
		object->focus = true;
		emit changed();
	}
}
Exemple #2
0
/*!
  Insert Parameters in AST of given scad file
  form of annotations
*/
void CommentParser::collectParameters(const char *fulltext, FileModule *root_module)
{
	// Get all groups of parameters
	GroupList groupList = collectGroups(std::string(fulltext));
	int parseTill=getLineToStop(fulltext);
	// Extract parameters for all literal assignments
	for (auto &assignment : root_module->scope.assignments) {
		if (!assignment.expr.get()->isLiteral()) continue; // Only consider literals

		// get location of assignment node
		int firstLine = assignment.location().firstLine();
		if(firstLine>=parseTill ) continue;

		// making list to add annotations
		AnnotationList *annotationList = new AnnotationList();
 
		// Extracting the parameter comment
		std::string comment = getComment(std::string(fulltext), firstLine);
		// getting the node for parameter annnotataion
		shared_ptr<Expression> params = CommentParser::parser(comment.c_str());
		if (!params) {
			params = shared_ptr<Expression>(new Literal(ValuePtr(std::string(""))));
		}

		// adding parameter to the list
		annotationList->push_back(Annotation("Parameter", params));

		//extracting the description
		std::string descr = getDescription(std::string(fulltext), firstLine - 1);
		if (descr != "") {
			//creating node for description
			shared_ptr<Expression> expr(new Literal(ValuePtr(std::string(descr.c_str()))));
			annotationList->push_back(Annotation("Description", expr));
		}

		// Look for the group to which the given assignment belong
		int i=0;
		for (;i<groupList.size() && groupList[i].lineNo<firstLine;i++);
		i--;

		if (i >= 0) {
			//creating node for description
			shared_ptr<Expression> expr(new Literal(ValuePtr(groupList[i].commentString)));
			annotationList->push_back(Annotation("Group", expr));
		}
		assignment.addAnnotations(annotationList);
	}
}
Exemple #3
0
    /*static*/ ValuePtr Value::Create(size_t vocabularySize, const std::vector<std::vector<size_t>>& oneHotSequences, const DeviceDescriptor& device, bool readOnly/* = false*/)
    {
        NDMaskPtr deviceValueMask = CreateMask(1, oneHotSequences, device);
        size_t maxSequenceLength = (deviceValueMask == nullptr) ? oneHotSequences[0].size() : deviceValueMask->Shape()[0];

        size_t numSequences = oneHotSequences.size();
        NDShape sampleShape = { vocabularySize };
        NDShape valueDataShape = sampleShape.AppendShape({ maxSequenceLength, numSequences });
        size_t numCSCCols = valueDataShape.SubShape(1).TotalSize() + 1;
        std::vector<SparseIndexType> colStarts(numCSCCols);
        std::vector<ElementType> nonZeroValues;
        std::vector<SparseIndexType> rowIndices;
        for (size_t i = 0; i < numSequences; ++i)
        {
            size_t currentSequenceLength = oneHotSequences[i].size();
            size_t j = 0;
            for (; j < currentSequenceLength; ++j)
            {
                colStarts[(i * maxSequenceLength) + j] = (SparseIndexType)nonZeroValues.size();
                nonZeroValues.push_back(1);
                rowIndices.push_back((SparseIndexType)(oneHotSequences[i][j]));
            }

            for (; j < maxSequenceLength; ++j)
                colStarts[(i * maxSequenceLength) + j] = (SparseIndexType)(nonZeroValues.size());
        }

        colStarts[numSequences * maxSequenceLength] = (SparseIndexType)(nonZeroValues.size());
        NDArrayViewPtr deviceValueData(new NDArrayView(valueDataShape, colStarts.data(), rowIndices.data(), nonZeroValues.data(), nonZeroValues.size(), device, readOnly), [](ReferenceCount* ptr) { delete ptr; });
        return ValuePtr(new Value(deviceValueData, deviceValueMask), [](ReferenceCount* ptr) { delete ptr; });
    }
Exemple #4
0
    /*static*/ ValuePtr Value::Create(const NDShape& sampleShape, const std::vector<std::vector<ElementType>>& sequences, const DeviceDescriptor& device, bool readOnly/* = false*/)
    {
        size_t sampleSize = sampleShape.TotalSize();
        NDMaskPtr deviceValueMask = CreateMask(sampleSize, sequences, device);
        size_t maxSequenceLength = (deviceValueMask == nullptr) ? sequences[0].size() : deviceValueMask->Shape()[0];

        size_t numSequences = sequences.size();
        NDShape valueDataShape = sampleShape.AppendShape({ maxSequenceLength, numSequences });
        NDArrayViewPtr valueData(new NDArrayView(AsDataType<ElementType>(), valueDataShape, DeviceDescriptor::CPUDevice()), [](ReferenceCount* ptr) { delete ptr; });
        ElementType* dataBuffer = valueData->WritableDataBuffer<ElementType>();
        for (size_t i = 0; i < numSequences; ++i)
            std::copy(sequences[i].data(), sequences[i].data() + sequences[i].size(), dataBuffer + (maxSequenceLength * i * sampleSize));

        NDArrayViewPtr deviceValueData;
        if (device == DeviceDescriptor::CPUDevice())
        {
            if (readOnly)
                deviceValueData = valueData->Alias(true);
            else
                deviceValueData = valueData;
        }
        else
        {
            deviceValueData = NDArrayViewPtr(new NDArrayView(AsDataType<ElementType>(), valueDataShape, device), [](ReferenceCount* ptr) { delete ptr; });
            deviceValueData->CopyFrom(*valueData);
            if (readOnly)
                deviceValueData = deviceValueData->Alias(true);
        }

        return ValuePtr(new Value(deviceValueData, deviceValueMask), [](ReferenceCount* ptr) { delete ptr; });
    }
Exemple #5
0
void TEnvVar::ConstructL(const TDesC16& aName, const wchar_t* aValue)
	{
	TPtrC16 valueZ = ValuePtr(aValue);
	HBufC16* valueCopy = valueZ.AllocLC();
	iName = aName.AllocL();
	iValue = valueCopy;
	CleanupStack::Pop();
	}
Exemple #6
0
	ValuePtr Context::GetParam( std::string id ) const
	{
		ValueMap::const_iterator it = mValues.find(id);
		if (it == mValues.cend())
			return ValuePtr();

		ValuePtr v = it->second.top();
		return v;
	}
Exemple #7
0
 Result Symbol::EvaluateTemplate(BindingPtr binding)
 {
   if (mTemplate) {
     return ValuePtr(new Symbol(false, mToken));
   }
   else {
     ValuePtr value = binding->Get(mToken->String());
     if (value) return value;
     return Result("Unknown Reference", NULL); // TODO
   }
 }
Exemple #8
0
TInt TEnvVar::SetValue(const wchar_t* aValue)
//
// Change the value - if this returns an error then the original value is still intact
//
	{
	TPtrC16 valueZ = ValuePtr(aValue);
	HBufC16* valueCopy=valueZ.Alloc();
	if (valueCopy==0)
		return KErrNoMemory;
	delete iValue;
	iValue = valueCopy;
	return KErrNone;
	}
void ParameterSlider::onSliderChanged(int)
{
	double v = slider->value()*step;

	if (!this->suppressUpdate) {
		this->doubleSpinBox->setValue(v);
		
		if (this->pressed) {
			object->focus = true;
			object->value = ValuePtr(v);
			emit changed();
		}
	}
}
Exemple #10
0
void ParameterText::onChanged(QString)
{
	if (object->dvt == Value::STRING) {
		object->value = ValuePtr(lineEdit->text().toStdString());
	}
	else {
		ModuleContext ctx;
		shared_ptr<Expression> params = CommentParser::parser(lineEdit->text().toStdString().c_str());
		if (!params) return;
		ValuePtr newValue = params->evaluate(&ctx);
		if (object->dvt == newValue->type()) {
			object->value = newValue;
		}
	}
	object->focus = true;
	emit changed();
}
Exemple #11
0
void FieldTable::decode(Buffer& buffer){
    clear();
    uint32_t len = buffer.getLong();
    if (len) {
        uint32_t available = buffer.available();
        if (available < len)
            throw IllegalArgumentException(QPID_MSG("Not enough data for field table."));
        uint32_t count = buffer.getLong();
        uint32_t leftover = available - len;
        while(buffer.available() > leftover && count--){
            std::string name;
            ValuePtr value(new FieldValue);
            
            buffer.getShortString(name);
            value->decode(buffer);
            values[name] = ValuePtr(value);
        }    
    }
}
Exemple #12
0
void FieldTable::setFloat(const std::string& name, const float value){
    values[name] = ValuePtr(new FloatValue(value));
}
void ParameterCheckBox::onChanged()
{
	object->focus = true;
	object->value = ValuePtr(checkBox->isChecked());
	emit changed();
}
Exemple #14
0
 Result Integer::EvaluateTemplate(BindingPtr binding)
 {
   return ValuePtr(new Integer(false, mValue));
 }
Exemple #15
0
SsKeyframe::SsKeyframe(void)
	: _frameNo(0)
	, _value(ValuePtr())
	, _curve()
{
}
Exemple #16
0
 Result Value::Count(BindingPtr binding) 
 { 
   return Result("Unimplemented", ValuePtr(NULL)); 
 }
Exemple #17
0
 /*virtual*/ ValuePtr Value::Alias(bool readOnly/* = false*/) const
 {
     // TODO: Check if this is a derived type and throw an exception in that case
     return ValuePtr(new Value(Data()->Alias(readOnly), (Mask() != nullptr) ? Mask()->Alias() : nullptr), [](ReferenceCount* ptr) { delete ptr; });
 }
Exemple #18
0
void FieldTable::setUInt64(const std::string& name, const uint64_t value){
    values[name] = ValuePtr(new Unsigned64Value(value));
}
Exemple #19
0
void FieldTable::setTimestamp(const std::string& name, const uint64_t value){
    values[name] = ValuePtr(new TimeValue(value));
}
Exemple #20
0
void FieldTable::setInt64(const std::string& name, const int64_t value){
    values[name] = ValuePtr(new Integer64Value(value));
}
Exemple #21
0
void FieldTable::setString(const std::string& name, const std::string& value){
    values[name] = ValuePtr(new Str16Value(value));
}
Exemple #22
0
void FieldTable::setDouble(const std::string& name, double value){
    values[name] = ValuePtr(new DoubleValue(value));
}
Exemple #23
0
 Result Value::Insert(BindingPtr binding, std::vector<ValuePtr> &arguments) 
 { 
   return Result("Unimplemented", ValuePtr(NULL)); 
 }
Exemple #24
0
void FieldTable::setArray(const std::string& name, const Array& value)
{
    values[name] = ValuePtr(new ArrayValue(value));
}
Exemple #25
0
void FieldTable::setTable(const std::string& name, const FieldTable& value)
{
    values[name] = ValuePtr(new FieldTableValue(value));
}
Exemple #26
0
void CNTKEvalExtended<ElemType>::ForwardPassT(const std::vector<ValueBuffer<ElemType, ValueContainer> >& inputs, std::vector<ValueBuffer<ElemType, ValueContainer> >& outputs, bool resetRNN)
{
    if (!m_started)
        RuntimeError("ForwardPass() called before StartForwardEvaluation()");

    if (inputs.size() != (size_t)std::distance(m_inputMatrices.begin(), m_inputMatrices.end()))
        RuntimeError("Expected %d inputs, but got %d.", (int)std::distance(m_inputMatrices.begin(), m_inputMatrices.end()), (int)inputs.size());

    if (outputs.size() != m_outputNodes.size())
        RuntimeError("Expected %d outputs, but got %d.", (int)m_outputNodes.size(), (int)outputs.size());

    size_t i = 0;
    for (auto& inputNode : m_inputNodes)
    {
        // const cast: The matrix class takes this over without copying and could theoretically change the contents,
        // though it doesn't in this case.
        auto& buffer = const_cast<ValueBuffer<ElemType, ValueContainer>&>(inputs[i]);
        auto matrix = dynamic_pointer_cast<Matrix<ElemType>>(inputNode->ValuePtr());
        auto type = matrix->GetMatrixType();
        size_t numRows = inputNode->GetSampleLayout().GetNumElements();

        if (buffer.m_buffer.data() == nullptr)
            RuntimeError("Input %ls: Buffer is not allocated.", m_inputNodes[i]->GetName().c_str());
        if (type == MatrixType::DENSE)
        {
            if (buffer.m_buffer.size() % numRows != 0)
                RuntimeError("Input %ls: Expected input data to be a multiple of %" PRIu64 ", but it is %" PRIu64 ".", 
                             m_inputNodes[i]->GetName().c_str(), numRows, buffer.m_buffer.size());
            if (buffer.m_buffer.size() == 0)
                RuntimeError("Input %ls: Expected at least one element.", m_inputNodes[i]->GetName().c_str());
        }
        else if (type == MatrixType::SPARSE)
        {
            if (buffer.m_colIndices.data() == nullptr)
                RuntimeError("Input %ls: Due to sparse input format, expected colIndices array, but was nullptr.", m_inputNodes[i]->GetName().c_str());
            if (buffer.m_indices.data() == nullptr)
                RuntimeError("Input %ls: Due to sparse input format, expected Indices array, but was nullptr.", m_inputNodes[i]->GetName().c_str());
            if (buffer.m_colIndices.size() < 2)
                RuntimeError("Input %ls: Expected at least one element (2 entries in colIndices array).", m_inputNodes[i]->GetName().c_str());
            if (buffer.m_colIndices[0] != 0)
                RuntimeError("Input %ls: First element of column indices must be 0", m_inputNodes[i]->GetName().c_str());
            if (buffer.m_colIndices[buffer.m_colIndices.size() - 1] != buffer.m_indices.size())
                RuntimeError("Input %ls: Last element of column indices must be equal to the size of indices (%ld), but was %d", 
                             m_inputNodes[i]->GetName().c_str(), buffer.m_indices.size(), 
                             buffer.m_colIndices[buffer.m_colIndices.size() - 1]);
        }

        int numCols = type == MatrixType::DENSE ? buffer.m_buffer.size() / numRows : buffer.m_colIndices.size() - 1;
        if (numCols < 1)
            RuntimeError("Input: the number of column must be greater than or equal to 1.");
        inputNode->GetMBLayout()->Init(1, numCols);
        
        // SentinelValueIndicatingUnspecifedSequenceBeginIdx is used to specify the lower bound of look-back step of recurrent nodes
        inputNode->GetMBLayout()->AddSequence(0, 0, resetRNN ? 0 : SentinelValueIndicatingUnspecifedSequenceBeginIdx, numCols);

        if (type == MatrixType::DENSE)
            matrix->SetValue(numRows, numCols, matrix->GetDeviceId(), buffer.m_buffer.data(), matrixFlagNormal);
        else if (type == MatrixType::SPARSE)
        {
            // In the sparse case the m_data layout is identical to CUDA's CSC layout
            // (see http://docs.nvidia.com/cuda/cusparse/#compressed-sparse-column-format-csc).
            matrix->SetMatrixFromCSCFormat(buffer.m_colIndices.data(), buffer.m_indices.data(), buffer.m_buffer.data(),
                                           buffer.m_buffer.size(), numRows, numCols);
        }

        ++i;
    }

    ComputationNetwork::BumpEvalTimeStamp(m_inputNodes);
    this->m_net->ForwardProp(m_outputNodes);

    for (size_t i2 = 0; i2 < m_outputNodes.size(); ++i2)
    {
        auto node = m_outputNodes[i2];
        
        shared_ptr<Matrix<ElemType>> outputMatrix = dynamic_pointer_cast<Matrix<ElemType>>(node->ValuePtr());
        auto pMBLayout = node->GetMBLayout();
        if (!pMBLayout)
        {
            pMBLayout = make_shared<MBLayout>();
            pMBLayout->InitAsFrameMode(1); // treat this as if we have one single sample
        }

        const auto& seq = pMBLayout->GetAllSequences();
        if (seq.size() != 1)
            RuntimeError("Only 1 output sequence supported by this API");

        ValueContainer<ElemType>& vec = outputs[i2].m_buffer;

        size_t numElements = outputMatrix->GetNumElements();

        if (vec.capacity() < numElements)
        {
            // Bad luck - we can't reallocate memory of an external object at this point.
            RuntimeError("Not enough space in output buffer for output '%ls'.", node->GetName().c_str());
        }

        vec.resize(numElements);
        ElemType* data = const_cast<ElemType*>(vec.data());
        outputMatrix->CopyToArray(data, numElements);
    }
}