Beispiel #1
0
/***********************************************************************
 * block factory - make blocks from JSON object
 **********************************************************************/
static Pothos::Proxy makeBlock(
    const Pothos::Proxy &registry,
    const Pothos::Proxy &evaluator,
    const Poco::JSON::Object::Ptr &blockObj)
{
    const auto id = blockObj->getValue<std::string>("id");

    if (not blockObj->has("path")) throw Pothos::DataFormatException(
        "Pothos::Topology::make()", "blocks["+id+"] missing 'path' field");
    const auto path = blockObj->getValue<std::string>("path");

    //load up the constructor args
    Poco::JSON::Array::Ptr argsArray;
    if (blockObj->isArray("args")) argsArray = blockObj->getArray("args");
    const auto ctorArgs = evalArgsArray(evaluator, argsArray);

    //create the block
    auto block = registry.getHandle()->call(path, ctorArgs.data(), ctorArgs.size());

    //make the calls
    Poco::JSON::Array::Ptr callsArray;
    if (blockObj->isArray("calls")) callsArray = blockObj->getArray("calls");
    if (callsArray) for (size_t i = 0; i < callsArray->size(); i++)
    {
        const auto callArray = callsArray->getArray(i);
        auto name = callArray->getElement<std::string>(0);
        const auto callArgs = evalArgsArray(evaluator, callArray, 1/*offset*/);
        block.getHandle()->call(name, callArgs.data(), callArgs.size());
    }

    return block;
}
Beispiel #2
0
static Pothos::ProxyVector convertJObjectArrayToVector(const Pothos::Proxy &proxy)
{
    auto handle = std::dynamic_pointer_cast<JavaProxyHandle>(proxy.getHandle());
    auto jenv = std::dynamic_pointer_cast<JavaProxyEnvironment>(proxy.getEnvironment());

    auto ar = (jobjectArray) handle->value.l;
    Pothos::ProxyVector vec(jenv->env->GetArrayLength(ar));
    for (size_t i = 0; i < vec.size(); i++)
    {
        vec[i] = jenv->makeHandle(jenv->env->GetObjectArrayElement(ar, i));
    }
    return vec;
}
static Pothos::BufferChunk convertNumpyArrayToBufferChunk(const Pothos::Proxy &npArray)
{
    //extract shape and data type information
    const auto shape = npArray.get<Pothos::ProxyVector>("shape");
    const size_t numBytes = npArray.get<size_t>("nbytes");
    const size_t dimension = (shape.size() > 1)? shape.at(1).convert<size_t>() : 1;
    const auto dtypeName = npArray.get("dtype").get<std::string>("name");
    const Pothos::DType dtype(dtypeName, dimension);
    const size_t address = npArray.get("__array_interface__").call("get", "data").call("__getitem__", 0);

    //create a shared buffer that holds the numpy array
    auto sharedBuff = Pothos::SharedBuffer(address, numBytes, npArray.getHandle());

    //now create a buffer chunk of that shared buffer with matching dtype
    auto chunk = Pothos::BufferChunk(sharedBuff);
    chunk.dtype = dtype;
    return chunk;
}
Beispiel #4
0
static T convertJPrimitiveToNum(const Pothos::Proxy &proxy)
{
    auto handle = std::dynamic_pointer_cast<JavaProxyHandle>(proxy.getHandle());
    assert(sig == handle->sig);
    return jvalueToNum<sig, T>(handle->value);
}
Beispiel #5
0
static std::string convertJStringToString(const Pothos::Proxy &proxy)
{
    auto handle = std::dynamic_pointer_cast<JavaProxyHandle>(proxy.getHandle());
    auto env = std::dynamic_pointer_cast<JavaProxyEnvironment>(proxy.getEnvironment());
    return env->jstringToString(handle->value.l);
}