예제 #1
0
  void _TestDeepCopyDataArray()
  {
    size_t numTuples = 10;
    QVector<size_t> cDims(1, 5);
    QString name("Source Array");

    // First lets try it without allocating any memory
    typename DataArray<T>::Pointer src = DataArray<T>::CreateArray(numTuples, cDims, name, false);

    typename DataArray<T>::Pointer copy = std::dynamic_pointer_cast<DataArray<T> >(src->deepCopy());

    DREAM3D_REQUIRED(copy->getNumberOfTuples(), ==, src->getNumberOfTuples() );
    DREAM3D_REQUIRED(copy->isAllocated(), ==, src->isAllocated() );

    // Create the array again, this time allocating the data and putting in some known data
    src = DataArray<T>::CreateArray(numTuples, cDims, name, true);
    for(size_t i = 0; i < numTuples; i++)
    {
      for(size_t j = 0; j < cDims[0]; j++)
      {
        src->setComponent(i, j, static_cast<T>(i + j) );
      }
    }
    copy = std::dynamic_pointer_cast<DataArray<T> >(src->deepCopy());
    for(size_t i = 0; i < numTuples; i++)
    {
      for(size_t j = 0; j < cDims[0]; j++)
      {
        src->setComponent(i, j, static_cast<T>(i + j) );
        T cpy = copy->getComponent(i, j);
        T val = src->getComponent(i, j);
        DREAM3D_REQUIRE_EQUAL(cpy, val)
      }
    }
  }
예제 #2
0
void __TestReorderCopy()
{
    size_t numTuples = 10;
    QVector<size_t> cDims(1, 5);
    QString name("Source Array");

    //make sure that an incorrectly sized order returns a null pointer
    typename DataArray<T>::Pointer src = DataArray<T>::CreateArray(numTuples, cDims, name, false);
    QVector<size_t> wrongSize(numTuples + 1);
    typename DataArray<T>::Pointer copy = boost::dynamic_pointer_cast<DataArray<T> >(src->reorderCopy(wrongSize));
    DREAM3D_REQUIRE_EQUAL(copy.get(), 0);

    // fill reorder vector with same index (using this would be the same result as deep copy)
    QVector<size_t> newOrder(numTuples);
    for(size_t i = 0; i < numTuples; i++)
    {
        newOrder[i] = i;
    }

    //shuffle order
    std::random_shuffle(newOrder.begin(), newOrder.end());

    // First lets try it without allocating any memory
    copy = boost::dynamic_pointer_cast<DataArray<T> >(src->reorderCopy(newOrder));

    //if newOrder is inporperly size a null pointer is returned
    DREAM3D_REQUIRE_NE(copy.get(), 0);

    //check sizes
    DREAM3D_REQUIRED(copy->getNumberOfTuples(), ==, src->getNumberOfTuples() );
    DREAM3D_REQUIRED(copy->isAllocated(), ==, src->isAllocated() );

    // Create the array again, this time allocating the data and putting in some known data
    src = DataArray<T>::CreateArray(numTuples, cDims, name, true);
    for(size_t i = 0; i < src->getSize(); i++)
    {
        src->setValue(i, i);
    }

    for(size_t i = 0; i < numTuples; i++)
    {
        for(size_t j = 0; j < cDims[0]; j++)
        {
            src->setComponent(i, j, static_cast<T>(i * cDims[0] + j) );
        }
    }
    copy = boost::dynamic_pointer_cast<DataArray<T> >(src->reorderCopy(newOrder));
    for(size_t i = 0; i < numTuples; i++)
    {
        for(size_t j = 0; j < cDims[0]; j++)
        {
            T cpy = copy->getComponent(newOrder[i], j);
            T val = src->getComponent(i, j);
            DREAM3D_REQUIRE_EQUAL(cpy, val)
        }
    }
}
예제 #3
0
void reduceArrayOnly(IDataArray::Pointer inputData, IDataArray::Pointer reducedData, int compNumber)
{
  typename DataArray<T>::Pointer inputArrayPtr = boost::dynamic_pointer_cast<DataArray<T> >(inputData);
  typename DataArray<T>::Pointer reducedArrayPtr = boost::dynamic_pointer_cast<DataArray<T> >(reducedData);

  if (NULL == inputArrayPtr) { return; }

  T* inputArray = inputArrayPtr->getPointer(0);
  T* reducedArray = reducedArrayPtr->getPointer(0);

  size_t numPoints = inputArrayPtr->getNumberOfTuples();
  size_t numComps = inputArrayPtr->getNumberOfComponents();

  for (size_t i = 0; i < numPoints; i++)
  {
    for (size_t j = 0; j < numComps; j++)
    {

      if (j > compNumber)
      {
        reducedArray[(numComps - 1)*i + j - 1] = inputArray[numComps * i + j];
      }
      else if (j < compNumber)
      {
        reducedArray[(numComps - 1)*i + j] = inputArray[numComps * i + j];
      }
    }
  }
}
예제 #4
0
void fitData(IDataArray::Pointer inDataPtr, float* ensembleArray, int32_t* eIds, size_t numEnsembles, uint32_t dType, bool removeBiasedFeatures, bool* biasedFeatures)
{
  typename DataArray<T>::Pointer inputDataPtr = std::dynamic_pointer_cast<DataArray<T> >(inDataPtr);

  StatsData::Pointer sData = StatsData::New();

  std::vector<DistributionAnalysisOps::Pointer> distributionAnalysis;
  distributionAnalysis.push_back(BetaOps::New());
  distributionAnalysis.push_back(LogNormalOps::New());
  distributionAnalysis.push_back(PowerLawOps::New());

  QString distType;
  int32_t numComp = 1;

  // Determining number of components and name given distribution type
  if (dType == SIMPL::DistributionType::Beta) { distType = "Beta", numComp = SIMPL::DistributionType::BetaColumnCount; }
  else if (dType == SIMPL::DistributionType::LogNormal) { distType = "LogNormal", numComp = SIMPL::DistributionType::LogNormalColumnCount; }
  else if (dType == SIMPL::DistributionType::Power) { distType = "PowerLaw", numComp = SIMPL::DistributionType::PowerLawColumnCount; }

  T* fPtr = inputDataPtr->getPointer(0);

  std::vector<FloatArrayType::Pointer> dist;
  std::vector<std::vector<float > > values;

  size_t numfeatures = inputDataPtr->getNumberOfTuples();

  dist.resize(numEnsembles);
  values.resize(numEnsembles);

  for(size_t i = 1; i < numEnsembles; i++)
  {
    dist[i] = sData->CreateDistributionArrays(dType);
  }

  int32_t ensemble = 0;
  for (size_t i = 1; i < numfeatures; i++)
  {
    if (removeBiasedFeatures == false || biasedFeatures[i] == false)
    {
      ensemble = eIds[i];
      values[ensemble].push_back(static_cast<float>(fPtr[i]));
    }
  }
  for (size_t i = 1; i < numEnsembles; i++)
  {
    distributionAnalysis[dType]->calculateParameters(values[i], dist[i]);
    for (int32_t j = 0; j < numComp; j++)
    {
      FloatArrayType::Pointer data = dist[i];
      ensembleArray[numComp * i + j] = data->getValue(j);
    }
  }
}
void replaceValue(AbstractFilter* filter, IDataArray::Pointer inDataPtr, BoolArrayType::Pointer condDataPtr, double replaceValue)
{
  typename DataArray<T>::Pointer inputArrayPtr = std::dynamic_pointer_cast<DataArray<T> >(inDataPtr);

  T replaceVal = static_cast<T>(replaceValue);

  T* inData = inputArrayPtr->getPointer(0);
  bool* condData = condDataPtr->getPointer(0);
  size_t numTuples = inputArrayPtr->getNumberOfTuples();

  for (size_t iter = 0; iter < numTuples; iter++)
  {
    if (condData[iter] == true) { inData[iter] = replaceVal; }
  }
}
예제 #6
0
  int __ValidateArray(typename DataArray<T>::Pointer array, size_t numTuples, int numComp)
  {
    int err = 0;
    DREAM3D_REQUIRED(true, ==, array->isAllocated() );
    size_t nt = array->getNumberOfTuples();
    DREAM3D_REQUIRED(nt, ==, numTuples);
    int nc = array->getNumberOfComponents();
    DREAM3D_REQUIRED(nc, ==, numComp );

    size_t typeSize = array->getTypeSize();
    DREAM3D_REQUIRE_EQUAL(sizeof(T), typeSize);

    size_t numElements = array->getSize();
    DREAM3D_REQUIRED(numElements, ==, (nt * nc) );
    // initialize the array with zeros to get a baseline
    array->initializeWithZeros();
    // Get a pointer to the data and loop through the array making sure all values are Zero
    T* ptr = array->getPointer(0);
    for(size_t i = 0; i < numElements; i++)
    {
      DREAM3D_REQUIRE_EQUAL(0, ptr[i]);
    }
    //Splat another value across the array starting at an offset into the array
    //and test those values made it into the array correctly
    array->initializeWithValue(static_cast<T>(1), numComp);
    for(size_t i = numComp; i < numElements; i++)
    {
      DREAM3D_REQUIRE_EQUAL(static_cast<T>(1), ptr[i]);
    }
    // Initialize the entire array with a value (offset = 0);
    array->initializeWithValue(static_cast<T>(2), 0);
    for(size_t i = 0; i < numElements; i++)
    {
      DREAM3D_REQUIRE_EQUAL(static_cast<T>(2), ptr[i]);
    }

    // Initialize the entire array with a value (offset = 0), this time using the default value for the offset
    array->initializeWithValue(static_cast<T>(3));
    ptr = array->getPointer(0);
    for(size_t i = 0; i < numElements; i++)
    {
      DREAM3D_REQUIRE_EQUAL(static_cast<T>(3), ptr[i]);
      array->setValue(i, static_cast<T>(4));
      T val = array->getValue(i);
      DREAM3D_REQUIRE_EQUAL(val, static_cast<T>(4))
    }


    // Test setting of a Tuple with a value, which means all components of that tuple will have the same value
    size_t index = 0;
    array->initializeWithZeros();
    for(size_t t = 0; t < numTuples; t++)
    {
      array->initializeTuple(t, 6.0);
      for(int j = 0; j < numComp; j++)
      {
        T val = array->getComponent(t, j);
        DREAM3D_REQUIRE_EQUAL(val, (static_cast<T>(6)) )
      }
    }

    // Test setting individual components to a specific value
    index = 0;
    array->initializeWithZeros();
    for(size_t t = 0; t < numTuples; t++)
    {
      for(int j = 0; j < numComp; j++)
      {
        index = t * numComp + j;
        array->setComponent(t, j, static_cast<T>(t + j) );
        T val = array->getComponent(t, j);
        DREAM3D_REQUIRE_EQUAL(val, (static_cast<T>(t + j)))
        val = array->getValue(index);
        DREAM3D_REQUIRE_EQUAL(val, (static_cast<T>(t + j)))
      }
    }


    ///     virtual QVector<size_t> getComponentDimensions()
    // Test resizing the array based on a give number of tuples. The number of Components will stay the same at each tuple
    array->resize(numTuples * 2);
    array->initializeWithZeros(); // Init the grown array to all Zeros
    nt = array->getNumberOfTuples();
    DREAM3D_REQUIRED(nt, ==, (numTuples * 2) );
    nc = array->getNumberOfComponents();
    DREAM3D_REQUIRED(nc, ==, numComp );

    // Test resizing the array to a smaller size
    array->resize(numTuples);
    array->initializeWithZeros(); // Init the grown array to all Zeros
    nt = array->getNumberOfTuples();
    DREAM3D_REQUIRED(nt, ==, (numTuples) );
    nc = array->getNumberOfComponents();
    DREAM3D_REQUIRED(nc, ==, numComp );


    ////clear()

    // This resizes the array to Zero destroying all the data in the process.
    array->clear();
    DREAM3D_REQUIRED(false, ==, array->isAllocated() );
    nt = array->getNumberOfTuples();
    DREAM3D_REQUIRED(nt, ==, 0);
    nc = array->getNumberOfComponents();
    DREAM3D_REQUIRED(nc, ==, numComp);
    nt = array->getSize();
    DREAM3D_REQUIRED(nt, ==, 0);
    ptr = array->getPointer(0);
    DREAM3D_REQUIRED_PTR(ptr, ==, NULL);


    // Test resizing the array to a any larger size
    array->resize(numTuples);
    array->initializeWithZeros(); // Init the grown array to all Zeros
    nt = array->getNumberOfTuples();
    DREAM3D_REQUIRED(nt, ==, (numTuples) );
    nc = array->getNumberOfComponents();
    DREAM3D_REQUIRED(nc, ==, numComp );
    ptr = array->getPointer(0);
    DREAM3D_REQUIRED_PTR(ptr, !=, NULL);

    return err;
  }
예제 #7
0
void __TestEraseElements()
{
  // Test dropping of front elements only
  {
    typename DataArray<T>::Pointer array = DataArray<T>::CreateArray(NUM_ELEMENTS, "Test1");
    DREAM3D_REQUIRE_EQUAL(array->isAllocated(), true);
    for(size_t i = 0; i < NUM_ELEMENTS; ++i)
    {
      array->setComponent(i, 0, static_cast<T>(i) );
    }

    QVector<size_t> eraseElements;
    eraseElements.push_back(0);
    eraseElements.push_back(1);

    array->eraseTuples(eraseElements);

    DREAM3D_REQUIRE_EQUAL(array->getValue(0), 2);
    DREAM3D_REQUIRE_EQUAL(array->getValue(1), 3);
    DREAM3D_REQUIRE_EQUAL(array->getValue(2), 4);
    DREAM3D_REQUIRE_EQUAL(array->isAllocated(), true);
  }

  // Test Dropping of internal elements
  {
    QVector<size_t> dims(1, NUM_COMPONENTS_2);
    typename DataArray<T>::Pointer array = DataArray<T>::CreateArray(NUM_ELEMENTS_2, dims, "Test2");
    DREAM3D_REQUIRE_EQUAL(array->isAllocated(), true);
    for(size_t i = 0; i < NUM_TUPLES_2; ++i)
    {
      array->setComponent(i, 0, static_cast<T>(i));
      array->setComponent(i, 1, static_cast<T>(i));
    }

    QVector<size_t> eraseElements;
    eraseElements.push_back(3);
    eraseElements.push_back(6);
    eraseElements.push_back(8);

    array->eraseTuples(eraseElements);

    DREAM3D_REQUIRE_EQUAL(array->getComponent(3, 0), 4);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(3, 1), 4);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(5, 0), 7);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(5, 1), 7);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(6, 0), 9);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(6, 1), 9);
  }

  // Test Dropping of internal elements
  {
    QVector<size_t> dims(1, NUM_COMPONENTS_2);
    typename DataArray<T>::Pointer array = DataArray<T>::CreateArray(NUM_ELEMENTS_2, dims, "Test3");
    DREAM3D_REQUIRE_EQUAL(array->isAllocated(), true);
    for(size_t i = 0; i < NUM_TUPLES_2; ++i)
    {
      array->setComponent(i, 0, static_cast<T>(i));
      array->setComponent(i, 1, static_cast<T>(i));
    }

    QVector<size_t> eraseElements;
    eraseElements.push_back(3);
    eraseElements.push_back(6);
    eraseElements.push_back(9);
    array->eraseTuples(eraseElements);

    DREAM3D_REQUIRE_EQUAL(array->getComponent(3, 0), 4);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(3, 1), 4);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(5, 0), 7);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(5, 1), 7);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(6, 0), 8);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(6, 1), 8);
  }

  // Test Dropping of internal continuous elements
  {
    QVector<size_t> dims(1, NUM_COMPONENTS_2);
    typename DataArray<T>::Pointer array = DataArray<T>::CreateArray(NUM_ELEMENTS_2, dims, "Test4");
    DREAM3D_REQUIRE_EQUAL(array->isAllocated(), true);
    for(size_t i = 0; i < NUM_TUPLES_2; ++i)
    {
      array->setComponent(i, 0, static_cast<T>(i));
      array->setComponent(i, 1, static_cast<T>(i));
    }

    QVector<size_t> eraseElements;
    eraseElements.push_back(3);
    eraseElements.push_back(4);
    eraseElements.push_back(5);
    array->eraseTuples(eraseElements);

    DREAM3D_REQUIRE_EQUAL(array->getComponent(3, 0), 6);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(3, 1), 6);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(4, 0), 7);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(4, 1), 7);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(5, 0), 8);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(5, 1), 8);
  }

  // Test Dropping of Front and Back Elements
  {
    QVector<size_t> dims(1, NUM_COMPONENTS_2);
    typename DataArray<T>::Pointer array = DataArray<T>::CreateArray(NUM_ELEMENTS_2, dims, "Test5");
    DREAM3D_REQUIRE_EQUAL(array->isAllocated(), true);
    for(size_t i = 0; i < NUM_TUPLES_2; ++i)
    {
      array->setComponent(i, 0, static_cast<T>(i));
      array->setComponent(i, 1, static_cast<T>(i));
    }

    QVector<size_t> eraseElements;
    eraseElements.push_back(0);
    eraseElements.push_back(9);

    array->eraseTuples(eraseElements);

    DREAM3D_REQUIRE_EQUAL(array->getComponent(0, 0), 1);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(0, 1), 1);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(7, 0), 8);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(7, 1), 8);
  }

  // Test Dropping of Back Elements
  {
    QVector<size_t> dims(1, NUM_COMPONENTS_2);
    typename DataArray<T>::Pointer array = DataArray<T>::CreateArray(NUM_ELEMENTS_2, dims, "Test6");
    DREAM3D_REQUIRE_EQUAL(array->isAllocated(), true);
    for(size_t i = 0; i < NUM_TUPLES_2; ++i)
    {
      array->setComponent(i, 0, static_cast<T>(i));
      array->setComponent(i, 1, static_cast<T>(i));
    }

    QVector<size_t> eraseElements;
    eraseElements.push_back(7);
    eraseElements.push_back(8);
    eraseElements.push_back(9);
    array->eraseTuples(eraseElements);

    DREAM3D_REQUIRE_EQUAL(array->getComponent(4, 0), 4);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(4, 1), 4);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(5, 0), 5);
    DREAM3D_REQUIRE_EQUAL(array->getComponent(5, 1), 5);
  }

  // Test Dropping of indices larger than the number of tuples
  {
    QVector<size_t> dims(1, NUM_COMPONENTS_2);
    typename DataArray<T>::Pointer array = DataArray<T>::CreateArray(NUM_TUPLES_2, dims, "Test6");
    DREAM3D_REQUIRE_EQUAL(array->isAllocated(), true);
    for(size_t i = 0; i < NUM_TUPLES_2; ++i)
    {
      array->setComponent(i, 0, static_cast<T>(i));
      array->setComponent(i, 1, static_cast<T>(i));
    }

    QVector<size_t> eraseElements;
    eraseElements.push_back(10);
    int err = array->eraseTuples(eraseElements);
    DREAM3D_REQUIRE_EQUAL(err , -100)

    eraseElements.clear();
    err = array->eraseTuples(eraseElements);
    DREAM3D_REQUIRE_EQUAL(err , 0)

    eraseElements.resize(20);
    err = array->eraseTuples(eraseElements);
    DREAM3D_REQUIRE_EQUAL(err , 0)
    size_t nTuples = array->getNumberOfTuples();
    DREAM3D_REQUIRE_EQUAL(nTuples, 0)
  }

}