当前位置: 首页>>代码示例>>C++>>正文


C++ Dimensions::getDimensionCount方法代码示例

本文整理汇总了C++中Dimensions::getDimensionCount方法的典型用法代码示例。如果您正苦于以下问题:C++ Dimensions::getDimensionCount方法的具体用法?C++ Dimensions::getDimensionCount怎么用?C++ Dimensions::getDimensionCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dimensions的用法示例。


在下文中一共展示了Dimensions::getDimensionCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

TEST_F(DimensionsTest, DontCareDimensions) {
  // dontcare dimensions [0]
  Dimensions d;
  d.push_back(0);
  ASSERT_TRUE(!d.isUnspecified());
  ASSERT_TRUE(d.isDontcare());
  ASSERT_TRUE(d.isValid());
  EXPECT_STREQ("[dontcare]", d.toString().c_str());
  ASSERT_ANY_THROW(d.getIndex(zero));
  ASSERT_ANY_THROW(d.getCount());
  ASSERT_EQ((unsigned int)0, d.getDimension(0));
  ASSERT_EQ((unsigned int)1, d.getDimensionCount());
}
开发者ID:breznak,项目名称:nupic.core,代码行数:13,代码来源:DimensionsTest.cpp

示例2: RunTests

  void DimensionsTest::RunTests()
  {
    Coordinate zero; // [0];
    zero.push_back(0);

    Coordinate one_two; // [1,2]
    one_two.push_back(1);
    one_two.push_back(2);

    Coordinate three_four; // [3,4]
    three_four.push_back(3);
    three_four.push_back(4);
    

    {
      // empty dimensions (unspecified)
      Dimensions d;
      TEST(d.isUnspecified());
      TEST(d.isValid());
      TEST(!d.isDontcare());
      SHOULDFAIL(d.getCount());
      SHOULDFAIL(d.getDimension(0));
      TESTEQUAL("[unspecified]", d.toString());
      SHOULDFAIL(d.getIndex(one_two));
      SHOULDFAIL(d.getCount());
      SHOULDFAIL(d.getDimension(0));
      TESTEQUAL((unsigned int)0, d.getDimensionCount());
    }

    {
      // dontcare dimensions [0]
      Dimensions d;
      d.push_back(0);
      TEST(!d.isUnspecified());
      TEST(d.isDontcare());
      TEST(d.isValid());
      TESTEQUAL("[dontcare]", d.toString());
      SHOULDFAIL(d.getIndex(zero));
      SHOULDFAIL(d.getCount());
      TESTEQUAL((unsigned int)0, d.getDimension(0));
      TESTEQUAL((unsigned int)1, d.getDimensionCount());
    }


    {
      // invalid dimensions
      Dimensions d;
      d.push_back(1);
      d.push_back(0);
      TEST(!d.isUnspecified());
      TEST(!d.isDontcare());
      TEST(!d.isValid());
      TESTEQUAL("[1 0] (invalid)", d.toString());
      SHOULDFAIL(d.getIndex(one_two));
      SHOULDFAIL(d.getCount());
      TESTEQUAL((unsigned int)1, d.getDimension(0));
      TESTEQUAL((unsigned int)0, d.getDimension(1));
      SHOULDFAIL(d.getDimension(2));
      TESTEQUAL((unsigned int)2, d.getDimensionCount());
    }

    {
      // valid dimensions [2,3]
      // two rows, three columns
      Dimensions d;
      d.push_back(2);
      d.push_back(3);
      TEST(!d.isUnspecified());
      TEST(!d.isDontcare());
      TEST(d.isValid());
      TESTEQUAL("[2 3]", d.toString());
      TESTEQUAL((unsigned int)2, d.getDimension(0));
      TESTEQUAL((unsigned int)3, d.getDimension(1));
      SHOULDFAIL(d.getDimension(2));
      TESTEQUAL((unsigned int)6, d.getCount());
      TESTEQUAL((unsigned int)5, d.getIndex(one_two));
      TESTEQUAL((unsigned int)2, d.getDimensionCount());
    }

    {
      //check a two dimensional matrix for proper x-major ordering
      std::vector<size_t> x;
      x.push_back(4);
      x.push_back(5);
      Dimensions d(x);
      size_t testDim1 = 4;
      size_t testDim2 = 5;
      for(size_t i = 0; i < testDim1; i++)
      {
        for(size_t j = 0; j < testDim2; j++)
        {
          Coordinate testCoordinate;
          testCoordinate.push_back(i);
          testCoordinate.push_back(j);

          TESTEQUAL(i+j*testDim1, d.getIndex(testCoordinate));
          TESTEQUAL(vecToString(testCoordinate),
                    vecToString(d.getCoordinate(i+j*testDim1)));
        }
      }
//.........这里部分代码省略.........
开发者ID:AndreCAndersen,项目名称:nupic,代码行数:101,代码来源:DimensionsTest.cpp


注:本文中的Dimensions::getDimensionCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。