本文整理汇总了C++中Dimensions::isUnspecified方法的典型用法代码示例。如果您正苦于以下问题:C++ Dimensions::isUnspecified方法的具体用法?C++ Dimensions::isUnspecified怎么用?C++ Dimensions::isUnspecified使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dimensions
的用法示例。
在下文中一共展示了Dimensions::isUnspecified方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// Deserialize region
Region::Region(const std::string& name,
const std::string& nodeType,
const Dimensions& dimensions,
BundleIO& bundle,
Network * network) :
name_(name),
type_(nodeType),
initialized_(false),
enabledNodes_(NULL),
network_(network)
{
// Set region info before creating the RegionImpl so that the
// Impl has access to the region info in its constructor.
RegionImplFactory & factory = RegionImplFactory::getInstance();
spec_ = factory.getSpec(nodeType);
// Dimensions start off as unspecified, but if
// the RegionImpl only supports a single node, we
// can immediately set the dimensions.
if (spec_->singleNodeOnly)
if (!dimensions.isDontcare() && !dimensions.isUnspecified() &&
!dimensions.isOnes())
NTA_THROW << "Attempt to deserialize region of type " << nodeType
<< " with dimensions " << dimensions
<< " but region supports exactly one node.";
dims_ = dimensions;
impl_ = factory.deserializeRegionImpl(nodeType, bundle, this);
createInputsAndOutputs_();
}
示例2:
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());
}
示例3: testWithNodeType
void RegionTest::testWithNodeType(const std::string& nodeType)
{
Region *rP = NULL;
SHOULDFAIL ( rP = new Region("r1", "nosuchnode", "") );
Region r("r1", nodeType, "");
TEST(r.getName() == "r1");
TEST(r.getType() == nodeType);
Dimensions d = r.getDimensions();
TEST(d.isUnspecified());
d.clear();
d.push_back(3);
d.push_back(2);
r.setDimensions(d);
Dimensions d2 = r.getDimensions();
TEST(d2.size() == 2);
TEST(d2[0] == 3);
TEST(d2[1] == 2);
TEST(d2.getCount() == 6);
// Parameter testing
{
{
Int32 val = -(1 << 24);
TESTEQUAL((Int32)32, r.getParameterInt32("int32Param"));
r.setParameterInt32("int32Param", val);
TESTEQUAL(val, r.getParameterInt32("int32Param"));
}
{
UInt32 val = 1 << 24;
TESTEQUAL((UInt32)33, r.getParameterUInt32("uint32Param"));
r.setParameterUInt32("uint32Param", val);
TESTEQUAL(val, r.getParameterUInt32("uint32Param"));
}
{
Int64 val = -((Int64)1 << 44);
TESTEQUAL((Int64)64, r.getParameterInt64("int64Param"));
r.setParameterInt64("int64Param", val);
TESTEQUAL(val, r.getParameterInt64("int64Param"));
}
{
UInt64 val = (UInt64)1 << 45;
TESTEQUAL((UInt64)65, r.getParameterUInt64("uint64Param"));
r.setParameterUInt64("uint64Param", val);
TESTEQUAL(r.getParameterUInt64("uint64Param"), val);
}
{
Real32 val = 23456.7;
TESTEQUAL((Real32)32.1, r.getParameterReal32("real32Param"));
r.setParameterReal32("real32Param", val);
TESTEQUAL(r.getParameterReal32("real32Param"), val);
}
{
Real64 val = 23456.789;
TESTEQUAL((Real64)64.1, r.getParameterReal64("real64Param"));
r.setParameterReal64("real64Param", val);
TESTEQUAL(r.getParameterReal64("real64Param"), val);
}
{
Array a(NTA_BasicType_Int64);
r.getParameterArray("int64ArrayParam", a);
// check default values
TESTEQUAL((size_t)4, a.getCount());
Int64 *buf = (Int64*) a.getBuffer();
TEST(buf != NULL);
for (UInt64 i = 0; i < 4; i++)
TESTEQUAL((Int64)(i*64), buf[i]);
// set our own value
buf[0] = 100;
r.setParameterArray("int64ArrayParam", a);
// make sure we retrieve the value just set
buf[0] = 0;
r.getParameterArray("int64ArrayParam", a);
TEST(buf == a.getBuffer());
TESTEQUAL((Int64)100, buf[0]);
}
{
std::string s = r.getParameterString("stringParam");
TESTEQUAL("nodespec value", s);
s = "new value";
r.setParameterString("stringParam", s);
s = r.getParameterString("stringParam");
TESTEQUAL("new value", s);
}
//.........这里部分代码省略.........
示例4: 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)));
}
}
//.........这里部分代码省略.........