Esempio n. 1
0
void testPynodeInputOutputAccess(Region * level2)
{
  // --- input/output access for level 2 (Python py.TestNode) ---
  SHOULDFAIL(level2->getOutputData("doesnotexist") );

  // getting access via zero-copy
  std::cout << "Getting output for zero-copy access" << std::endl;
  ArrayRef output = level2->getOutputData("bottomUpOut");
  std::cout << "Element count in bottomUpOut is " << output.getCount() << "" << std::endl;
  Real64 *data_actual = (Real64*)output.getBuffer();
  // set the actual output
  data_actual[12] = 54321;  
}
int main(int argc, const char * argv[])
{
    // Create network
    Network net = Network();

    // Add VectorFileSensor region to network
    Region* region = net.addRegion("region", "VectorFileSensor", "{activeOutputCount: 1}");

    // Set region dimensions
    Dimensions dims;
    dims.push_back(1);

    std::cout << "Setting region dimensions" << dims.toString() << std::endl;

    region->setDimensions(dims);

    // Load data
    std::string path = Path::makeAbsolute("../../src/examples/regions/Data.csv");

    std::cout << "Loading data from " << path << std::endl;

    std::vector<std::string> loadFileArgs;
    loadFileArgs.push_back("loadFile");
    loadFileArgs.push_back(path);
    loadFileArgs.push_back("2");

    region->executeCommand(loadFileArgs);

    // Initialize network
    std::cout << "Initializing network" << std::endl;

    net.initialize();

    ArrayRef outputArray = region->getOutputData("dataOut");

    // Compute
    std::cout << "Compute" << std::endl;

    region->compute();

    // Get output
    Real64 *buffer = (Real64*) outputArray.getBuffer();

    for (size_t i = 0; i < outputArray.getCount(); i++)
    {
        std::cout << "  " << i << "    " << buffer[i] << "" << std::endl;
    }

    // Serialize
    Network net2;
    {
      std::stringstream ss;
      net.write(ss);
      net2.read(ss);
    }
    net2.initialize();

    Region* region2 = net2.getRegions().getByName("region");
    region2->executeCommand(loadFileArgs);
    ArrayRef outputArray2 = region2->getOutputData("dataOut");
    Real64 *buffer2 = (Real64*)outputArray2.getBuffer();

    net.run(1);
    net2.run(1);

    NTA_ASSERT(outputArray2.getCount() == outputArray.getCount());
    for (size_t i = 0; i < outputArray.getCount(); i++)
    {
        std::cout << "  " << i << "    " << buffer[i] << "   " << buffer2[i]
                  << std::endl;
    }

    return 0;
}