TYPED_TEST(RandomNumberGeneratorTest, TestRngBernoulliTimesBernoulli) { // Sample from Bernoulli with p = 0.5. const TypeParam p_a = 0.5; int* bernoulli_data_a = static_cast<int*>(this->int_data_->mutable_cpu_data()); this->RngBernoulliFill(p_a, bernoulli_data_a); // Sample from Bernoulli with p = 0.3. const TypeParam p_b = 0.3; int* bernoulli_data_b = static_cast<int*>(this->int_data_2_->mutable_cpu_data()); this->RngBernoulliFill(p_b, bernoulli_data_b); // Multiply Bernoullis. for (int i = 0; i < this->sample_size_; ++i) { bernoulli_data_a[i] *= bernoulli_data_b[i]; } int num_ones = 0; for (int i = 0; i < this->sample_size_; ++i) { if (bernoulli_data_a[i] != TypeParam(0)) { EXPECT_EQ(TypeParam(1), bernoulli_data_a[i]); ++num_ones; } } // Check that resulting product has roughly p_a * p_b ones. const TypeParam sample_p = this->sample_mean(bernoulli_data_a); const TypeParam true_mean = p_a * p_b; const TypeParam true_std = sqrt(true_mean * (1 - true_mean)); const TypeParam bound = this->mean_bound(true_std); EXPECT_NEAR(true_mean, sample_p, bound); }
TYPED_TEST(TypedVectorTest, PushBack3) { capu::vector<TypeParam> vector(0); vector.push_back(TypeParam(42u)); EXPECT_EQ(TypeParam(42u), vector[0]); }
TYPED_TEST(TypedVectorTest, ConstructorWithCapacityAndValue) { capu::vector<TypeParam> vector(3, 5); EXPECT_EQ(TypeParam(5u), vector[0]); EXPECT_EQ(TypeParam(5u), vector[1]); EXPECT_EQ(TypeParam(5u), vector[2]); }
TYPED_TEST(TypedVectorTest, insertSingleValueAtEndPosition) { capu::vector<TypeParam> capuVector(2, TypeParam(0)); capuVector.insert(capuVector.end(), TypeParam(123)); EXPECT_EQ(TypeParam(0u), capuVector[0]); EXPECT_EQ(TypeParam(0u), capuVector[1]); EXPECT_EQ(TypeParam(123u), capuVector[2]); }
TYPED_TEST(TypedVectorTest, insertSingleValueIntoMiddle) { capu::vector<TypeParam> capuVector(2, TypeParam(0)); capuVector.insert(capuVector.begin()+1u, TypeParam(123)); EXPECT_EQ(TypeParam(0u), capuVector[0]); EXPECT_EQ(TypeParam(123u), capuVector[1]); EXPECT_EQ(TypeParam(0u), capuVector[2]); }
TYPED_TEST(IntegerSerializationTest, DoTest) { testSerializationExactEquality(std::numeric_limits<TypeParam>::min()); testSerializationExactEquality(std::numeric_limits<TypeParam>::max()); testSerializationExactEquality(TypeParam()); for (int i = 0; i < std::numeric_limits<TypeParam>::digits; i ++) { testSerializationExactEquality(TypeParam(1) << i); testSerializationExactEquality(~(TypeParam(1) << i)); } }
TYPED_TEST(TypedVectorTest, PopBack) { capu::vector<TypeParam> vector(0); vector.push_back(TypeParam(42u)); capu::status_t status = vector.pop_back(); EXPECT_EQ(capu::CAPU_OK, status); EXPECT_EQ(TypeParam(0u), vector.size()); }
TYPED_TEST(TypedVectorTest, PushBack2) { capu::vector<TypeParam> vector(2); vector[0] = TypeParam(42u); vector[1] = TypeParam(47u); EXPECT_EQ(TypeParam(42u), vector[0]); EXPECT_EQ(TypeParam(47u), vector[1]); }
TYPED_TEST(AlignedMemAllocator_fixture,regression) { std::vector<TypeParam,lv::AlignedMemAllocator<TypeParam,16>> vVec16a(100); EXPECT_EQ(((uintptr_t)vVec16a.data()%16),size_t(0)); ASSERT_EQ(vVec16a[0],TypeParam(0)); ASSERT_TRUE(std::equal(vVec16a.begin()+1,vVec16a.end(),vVec16a.begin())); std::vector<TypeParam,lv::AlignedMemAllocator<TypeParam,32>> vVec32a(100); EXPECT_EQ(((uintptr_t)vVec32a.data()%32),size_t(0)); ASSERT_EQ(vVec32a[0],TypeParam(0)); ASSERT_TRUE(std::equal(vVec32a.begin()+1,vVec32a.end(),vVec32a.begin())); }
TYPED_TEST (HoursTest, AddSameType) { ASSERT_EQ ( ( Hours<TypeParam> (TypeParam (1)) + Hours<TypeParam> (TypeParam (1)) ).getRawValue(), TypeParam (2) ); }
TYPED_TEST (HoursTest, AddSecondsSameStorageType) { ASSERT_EQ ( ( Hours<TypeParam> (TypeParam (1)) + Seconds<TypeParam> (TypeParam (3600)) ).getRawValue(), TypeParam (2) ); }
TYPED_TEST (HoursTest, DivideSameType) { ASSERT_EQ ( ( Hours<TypeParam> (TypeParam (10)) / Hours<TypeParam> (TypeParam (2)) ).getRawValue(), TypeParam (5) ); }
TYPED_TEST(MathScale2FloatTest, LerpTest) { using T = TypeParam; using Scale2 = bksge::math::Scale2<T>; BKSGE_CONSTEXPR_EXPECT_EQ(Scale2( 0.0, 0.0), Lerp(Scale2(0, 0), Scale2(10, 20), TypeParam(0.00))); BKSGE_CONSTEXPR_EXPECT_EQ(Scale2( 2.5, 5.0), Lerp(Scale2(0, 0), Scale2(10, 20), TypeParam(0.25))); BKSGE_CONSTEXPR_EXPECT_EQ(Scale2( 5.0, 10.0), Lerp(Scale2(0, 0), Scale2(10, 20), TypeParam(0.50))); BKSGE_CONSTEXPR_EXPECT_EQ(Scale2( 7.5, 15.0), Lerp(Scale2(0, 0), Scale2(10, 20), TypeParam(0.75))); BKSGE_CONSTEXPR_EXPECT_EQ(Scale2(10.0, 20.0), Lerp(Scale2(0, 0), Scale2(10, 20), TypeParam(1.00))); }
TYPED_TEST (HoursTest, MultiplyMinutesSameStorageType) { ASSERT_EQ ( ( Hours<TypeParam> (TypeParam (1)) * Minutes<TypeParam> (TypeParam (60)) ).getRawValue(), TypeParam (1) ); }
TYPED_TEST (HoursTest, MultiplySameType) { ASSERT_EQ ( ( Hours<TypeParam> (TypeParam (2)) * Hours<TypeParam> (TypeParam (4)) ).getRawValue(), TypeParam (8) ); }
TYPED_TEST (HoursTest, SubtractMinutesSameStorageType) { ASSERT_EQ ( ( Hours<TypeParam> (TypeParam (2)) - Minutes<TypeParam> (TypeParam (60)) ).getRawValue(), TypeParam (1) ); }
TYPED_TEST (HoursTest, SubtractSecondsSameStorageType) { ASSERT_EQ ( ( Hours<TypeParam> (TypeParam (3)) - Seconds<TypeParam> (TypeParam (7200)) ).getRawValue(), TypeParam (1) ); }
TYPED_TEST (HoursTest, AddMinutesSameStorageType) { ASSERT_EQ ( ( Hours<TypeParam> (TypeParam (2)) + Minutes<TypeParam> (TypeParam (60)) ).getRawValue(), TypeParam (3) ); }
TYPED_TEST (HoursTest, SubtractSameType) { ASSERT_EQ ( ( Hours<TypeParam> (TypeParam (3)) - Hours<TypeParam> (TypeParam (1)) ).getRawValue(), TypeParam (2) ); }
TYPED_TEST (HoursTest, DivideSecondsSameStorageType) { ASSERT_EQ ( ( Hours<TypeParam> (TypeParam (4)) / Seconds<TypeParam> (TypeParam (7200)) ).getRawValue(), TypeParam (2) ); }
TYPED_TEST(aligned_cast_load_fixture,regression) { constexpr size_t nVals = sizeof(__m128i)/sizeof(TypeParam); std::vector<TypeParam,lv::AlignedMemAllocator<TypeParam,16>> vData(nVals); std::iota(vData.begin(),vData.end(),TypeParam(1)); union { TypeParam n[nVals]; __m128i a; } uData = {0}; std::iota(uData.n,uData.n+nVals,TypeParam(1)); ASSERT_EQ(((uintptr_t)vData.data()%16),uintptr_t(0)); ASSERT_TRUE(lv::cmp_eq_128i(_mm_load_si128((__m128i*)vData.data()),uData.a)); ASSERT_TRUE(lv::cmp_eq_128i(*(__m128i*)vData.data(),uData.a)); }
TYPED_TEST(TypedVectorTest, insertRangeWhileNeedingToGrow) { capu::vector<TypeParam> source(3); source[0] = 1; source[1] = 2; source[2] = 3; capu::vector<TypeParam> capuVector(0); capuVector.insert(capuVector.begin(), source.begin(), source.end()); EXPECT_EQ(TypeParam(1u), capuVector[0]); EXPECT_EQ(TypeParam(2u), capuVector[1]); EXPECT_EQ(TypeParam(3u), capuVector[2]); }
TYPED_TEST(TypedVectorTest, ForEach) { capu::vector<TypeParam> vector; vector.push_back(TypeParam(32)); vector.push_back(TypeParam(43)); vector.push_back(TypeParam(44)); capu::vector<TypeParam> testVector; capu_foreach(typename capu::vector<TypeParam>, vector, iter) { testVector.push_back(*iter); }
TYPED_TEST(TypedVectorTest, IteratorBigger) { capu::vector<TypeParam> vector; vector.push_back(TypeParam(1u)); vector.push_back(TypeParam(2u)); vector.push_back(TypeParam(3u)); vector.push_back(TypeParam(4u)); typename capu::vector<TypeParam>::Iterator start = vector.begin(); typename capu::vector<TypeParam>::Iterator end = vector.end(); EXPECT_TRUE(end > start); EXPECT_FALSE(start > end); }
TYPED_TEST(AccuracyLayerTest, TestForwardCPUPerClassWithIgnoreLabel) { LayerParameter layer_param; Caffe::set_mode(Caffe::CPU); const TypeParam kIgnoreLabelValue = -1; layer_param.mutable_accuracy_param()->set_ignore_label(kIgnoreLabelValue); AccuracyLayer<TypeParam> layer(layer_param); // Manually set some labels to the ignore label value (-1). this->blob_bottom_label_->mutable_cpu_data()[2] = kIgnoreLabelValue; this->blob_bottom_label_->mutable_cpu_data()[5] = kIgnoreLabelValue; this->blob_bottom_label_->mutable_cpu_data()[32] = kIgnoreLabelValue; layer.SetUp(this->blob_bottom_vec_, this->blob_top_per_class_vec_); layer.Forward(this->blob_bottom_vec_, this->blob_top_per_class_vec_); TypeParam max_value; int max_id; int num_correct_labels = 0; const int num_class = this->blob_top_per_class_->num(); vector<int> correct_per_class(num_class, 0); vector<int> num_per_class(num_class, 0); int count = 0; for (int i = 0; i < 100; ++i) { if (kIgnoreLabelValue == this->blob_bottom_label_->data_at(i, 0, 0, 0)) { continue; } ++count; max_value = -FLT_MAX; max_id = 0; for (int j = 0; j < 10; ++j) { if (this->blob_bottom_data_->data_at(i, j, 0, 0) > max_value) { max_value = this->blob_bottom_data_->data_at(i, j, 0, 0); max_id = j; } } ++num_per_class[this->blob_bottom_label_->data_at(i, 0, 0, 0)]; if (max_id == this->blob_bottom_label_->data_at(i, 0, 0, 0)) { ++num_correct_labels; ++correct_per_class[max_id]; } } EXPECT_EQ(count, 97); EXPECT_NEAR(this->blob_top_->data_at(0, 0, 0, 0), num_correct_labels / TypeParam(count), 1e-4); for (int i = 0; i < 10; ++i) { EXPECT_NEAR(this->blob_top_per_class_->data_at(i, 0, 0, 0), TypeParam(correct_per_class[i]) / num_per_class[i], 1e-4); } }
TYPED_TEST(GaussianFillerTest, TestFill2D) { vector<int_tp> blob_shape; blob_shape.push_back(8); blob_shape.push_back(15); const TypeParam tolerance = TypeParam(3); this->test_params(blob_shape, tolerance); }
TYPED_TEST(ImageDataLayerTest, TestShuffle) { LayerParameter param; ImageDataParameter* image_data_param = param.mutable_image_data_param(); image_data_param->set_batch_size(5); image_data_param->set_source(this->filename_->c_str()); image_data_param->set_shuffle(true); ImageDataLayer<TypeParam> layer(param); layer.SetUp(this->blob_bottom_vec_, &this->blob_top_vec_); EXPECT_EQ(this->blob_top_data_->num(), 5); EXPECT_EQ(this->blob_top_data_->channels(), 3); EXPECT_EQ(this->blob_top_data_->height(), 360); EXPECT_EQ(this->blob_top_data_->width(), 480); EXPECT_EQ(this->blob_top_label_->num(), 5); EXPECT_EQ(this->blob_top_label_->channels(), 1); EXPECT_EQ(this->blob_top_label_->height(), 1); EXPECT_EQ(this->blob_top_label_->width(), 1); // Go through the data twice for (int iter = 0; iter < 2; ++iter) { layer.Forward(this->blob_bottom_vec_, &this->blob_top_vec_); map<TypeParam, int> values_to_indices; int num_in_order = 0; for (int i = 0; i < 5; ++i) { TypeParam value = this->blob_top_label_->cpu_data()[i]; // Check that the value has not been seen already (no duplicates). EXPECT_EQ(values_to_indices.find(value), values_to_indices.end()); values_to_indices[value] = i; num_in_order += (value == TypeParam(i)); } EXPECT_EQ(5, values_to_indices.size()); EXPECT_GT(5, num_in_order); } }
TYPED_TEST(TypedVectorTest, Resize) { capu::vector<TypeParam> vector(0); vector.push_back(TypeParam(1)); vector.push_back(TypeParam(2)); vector.resize(19); EXPECT_EQ(TypeParam(1u), vector[0]); EXPECT_EQ(TypeParam(2u), vector[1]); vector.resize(1); EXPECT_EQ(TypeParam(1u), vector[0]); }
TYPED_TEST(TypedVectorTest, IteratorNotEqual) { capu::vector<TypeParam> vector; vector.push_back(TypeParam(1u)); vector.push_back(TypeParam(2u)); vector.push_back(TypeParam(3u)); vector.push_back(TypeParam(4u)); typename capu::vector<TypeParam>::Iterator start = vector.begin(); typename capu::vector<TypeParam>::Iterator end = vector.end(); EXPECT_TRUE(start != end); end = start; EXPECT_FALSE(start != end); }
TYPED_TEST(TypedVectorTest, Iterator) { capu::vector<TypeParam> vector; vector.push_back(TypeParam(42u)); vector.push_back(TypeParam(47u)); capu::vector<TypeParam> vector2; for (typename capu::vector<TypeParam>::Iterator iter = vector.begin(); iter != vector.end(); ++iter) { vector2.push_back(*iter); } EXPECT_EQ(TypeParam(42u), vector2[0]); EXPECT_EQ(TypeParam(47u), vector2[1]); }