本文整理汇总了C++中Shape函数的典型用法代码示例。如果您正苦于以下问题:C++ Shape函数的具体用法?C++ Shape怎么用?C++ Shape使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Shape函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LogicError
void Variable::SetValue(const NDArrayViewPtr& value)
{
if (!IsParameter())
LogicError("Variable::SetValue can be only invoked on a Parameter variable!");
else if (GetDataType() != value->GetDataType())
LogicError("Variable::SetValue: 'source' and 'destination' have different data types!");
else if (Shape() != value->Shape() && (AsTensorShape(Shape()) != AsTensorShape(value->Shape())))
LogicError("Variable::SetValue: 'source' and 'destination' have different shapes!");
bool alreadySet = false;
if (m_dataFields->m_initValueFlag)
{
// In the case of lazy initialization, try to avoid the redundant call to the initializer.
std::call_once(*m_dataFields->m_initValueFlag, [=, &value, &alreadySet] {
// If the variable hasn't been initialized yet, clone the content of the supplied value and delete the initializer.
m_dataFields->m_value = value->DeepClone(*m_dataFields->m_valueInitializationDevice, false);
m_dataFields->m_valueInitializer = nullptr;
m_dataFields->m_valueInitializationDevice = nullptr;
alreadySet = true;
});
}
assert(m_dataFields->m_value != nullptr);
if (!alreadySet)
{
// alreadySet is false, the lambda above wasn't called and the variable has been initialized before,
// get a pointer to its value and simply copy the content of the supplied value.
m_dataFields->m_value->CopyFrom(*value);
}
}
示例2: LogicError
NDArrayViewPtr Variable::Value() const
{
if (!IsConstant() && !IsParameter())
LogicError("Only Variables of kind Parameter and Constant have a Value!");
if (m_dataFields->m_value == nullptr)
{
assert(m_dataFields->m_valueInitializer);
assert(m_dataFields->m_valueInitializationDevice);
switch (GetDataType())
{
case DataType::Float:
{
m_dataFields->m_value = CreateValueFromParameterInitializer<float>(Shape(), *m_dataFields->m_valueInitializer, *m_dataFields->m_valueInitializationDevice);
break;
}
case DataType::Double:
{
m_dataFields->m_value = CreateValueFromParameterInitializer<double>(Shape(), *m_dataFields->m_valueInitializer, *m_dataFields->m_valueInitializationDevice);
break;
}
default:
LogicError("Unsupported DataType %s", DataTypeName(GetDataType()));
break;
}
m_dataFields->m_valueInitializer = nullptr;
m_dataFields->m_valueInitializationDevice = nullptr;
}
assert(m_dataFields->m_value != nullptr);
return m_dataFields->m_value;
}
示例3: MatrixVectorConvolution_FFT
AntisymmetricMatrixVectorConvolution_FFT::AntisymmetricMatrixVectorConvolution_FFT(const Matrix &lhs, int dim_x, int dim_y, int dim_z)
: MatrixVectorConvolution_FFT(dim_x, dim_y, dim_z, lhs.getShape().getDim(1), lhs.getShape().getDim(2), lhs.getShape().getDim(3))
{
assert(lhs.getShape().getDim(0) == 3);
// Allocate buffers
for (int e=0; e<3; ++e) {
if (!is_2d) {
N.re[e] = Matrix(Shape(exp_z, exp_x/2+1, exp_y));
N.im[e] = Matrix(Shape(exp_z, exp_x/2+1, exp_y));
} else {
N.re[e] = Matrix(Shape(exp_y, exp_z, exp_x/2+1));
N.im[e] = Matrix(Shape(exp_y, exp_z, exp_x/2+1));
}
}
// Setup tensor field
TensorFieldSetup setup(3, dim_x, dim_y, dim_z, exp_x, exp_y, exp_z);
ComplexMatrix lhs2 = setup.transformTensorField(lhs);
Matrix *foo1[3] = {&N.re[0], &N.re[1], &N.re[2]};
Matrix *foo2[3] = {&N.im[0], &N.im[1], &N.im[2]};
if (!is_2d) {
setup.unpackTransformedTensorField_xyz_to_zxy(lhs2, foo1, foo2);
} else {
setup.unpackTransformedTensorField_xyz_to_yzx(lhs2, foo1, foo2);
}
}
示例4: size_x
Neighborhood::Neighborhood(unsigned int size_x, unsigned int size_y) : size_x(size_x), size_y(size_y)
{
for (double i = 0; (i / (size_x*size_y)) < RATIO_FILLED; i++)
{
neighborhood_ = new Shape[size_x * size_y];
// fill with non-empty shapes so that the ratio of non-empty to empty
// shapes is `RATIO_FILLED` (from `constants.h`)
for (int filled = 0; filled < size_x*size_y*RATIO_FILLED; )
{
unsigned int x = mtrand(0, size_x - 1);
unsigned int y = mtrand(0, size_y - 1);
if (this->get(x, y).getType() == "empty") {
this->set(x, y, mtrand(0, 1) ? Shape("triangle")
: Shape("square"));
filled++;
}
}
}
}
示例5: TensorDescriptorHandle
FreeWill::TensorDescriptorHandle FreeWill::Model::addTensor(const std::string &name, const Shape &shape, DataType dataType, bool isBatchTensor, bool isRandomlyInitialized)
{
if (m_tensors.find(name) != m_tensors.end())
{
return TensorDescriptorHandle(this, std::string(), Shape());
}
m_tensors[name] = new FreeWill::TensorDescriptor(name, shape, dataType, isBatchTensor, isRandomlyInitialized);
return TensorDescriptorHandle(this, name, Shape());
}
示例6: printf
void VigraRFclassifier::learn(std::vector< std::vector<double> >& pfeatures, std::vector<int>& plabels){
if (_rf)
delete _rf;
int rows = pfeatures.size();
int cols = pfeatures[0].size();
printf("Number of samples and dimensions: %d, %d\n",rows, cols);
if ((rows<1)||(cols<1)){
return;
}
// clock_t start = clock();
std::time_t start, end;
std::time(&start);
MultiArray<2, float> features(Shape(rows,cols));
MultiArray<2, int> labels(Shape(rows,1));
int numzeros=0;
for(int i=0; i < rows; i++){
labels(i,0) = plabels[i];
numzeros += (labels(i,0)==-1?1:0);
for(int j=0; j < cols ; j++){
features(i,j) = (float)pfeatures[i][j];
}
}
printf("Number of merge: %d\n",numzeros);
int tre_count = 255;
printf("Number of trees: %d\n",tre_count);
RandomForestOptions rfoptions = RandomForestOptions().tree_count(tre_count).use_stratification(RF_EQUAL); //RF_EQUAL, RF_PROPORTIONAL
_rf= new RandomForest<>(rfoptions);
// construct visitor to calculate out-of-bag error
visitors::OOB_Error oob_v;
visitors::VariableImportanceVisitor varimp_v;
_rf->learn(features, labels);
_nfeatures = _rf->column_count();
_nclass = _rf->class_count();
std::time(&end);
printf("Time required to learn RF: %.2f sec\n", (difftime(end,start))*1.0);
// printf("Time required to learn RF: %.2f\n", ((double)clock() - start) / CLOCKS_PER_SEC);
printf("with oob :%f\n", oob_v.oob_breiman);
}
示例7: createShape
void createShape(shape_type st)
{
Shape s = Shape(st, idCounter, TransformTranslate(vec3(0.0,0.0,0.0)), TransformRotate(vec3(0.0,0.0,0.0)), TransformScale(vec3(1.0,1.0,1.0)));
listOfShapes.push_back(s);
selected = idCounter;
idCounter++;
}
示例8: Place
void MAS::Window::Maximize() {
if (extraFlags & W_MINIMIZED) {
return;
}
if (!(extraFlags & W_MAXIMIZED)) {
restoreRect = (*this);
extraFlags |= W_MAXIMIZED;
iconMax.SetBitmap(Skin::ICONRESTORE);
Place(GetParent()->topLeft());
Resize(GetParent()->size());
iconMax.SetSample(Skin::SAMPLE_CLOSE, Skin::SAMPLE_ACTIVATE);
iconMin.SetSample(Skin::SAMPLE_ACTIVATE, Skin::SAMPLE_ACTIVATE);
}
else {
extraFlags &= ~W_MAXIMIZED;
iconMax.SetBitmap(Skin::ICONMAX);
Shape(restoreRect);
iconMax.SetSample(Skin::SAMPLE_OPEN, Skin::SAMPLE_ACTIVATE);
iconMin.SetSample(Skin::SAMPLE_ACTIVATE, Skin::SAMPLE_ACTIVATE);
}
MsgShape();
}
示例9: Shape
void TestShape::testPopFromPointArray()
{
this->testInit(__func__);
Shape shape = Shape();
Point *points = new Point[2];
points[0] = Point(1,2,3);
points[1] = Point(-1.2,-3.4,-5.6);
shape.pushToPointArray(points[0]);
shape.pushToPointArray(points[1]);
Point point = shape.popFromPointArray();
if (shape.getPointCount() != 1) {
this->testFailed();
}
if (point.getX() != points[1].getX()) {
this->testFailed();
}
if (point.getY() != points[1].getY()) {
this->testFailed();
}
if (point.getZ() != points[1].getZ()) {
this->testFailed();
}
this->testInterpret();
}
示例10: CalculateStrayfieldForCuboid
VectorMatrix CalculateStrayfieldForCuboid(
int dim_x, int dim_y, int dim_z,
double delta_x, double delta_y, double delta_z,
int mag_dir,
Vector3d pos,
Vector3d size,
int infinity)
{
// Check arguments.
if ((infinity & INFINITE_POS_X || infinity & INFINITE_NEG_X) && size.x != 0.0) throw std::runtime_error("CalculateStrayfieldForCuboid: cuboid size in x-direction must be zero for infinite extents in x direction");
if ((infinity & INFINITE_POS_Y || infinity & INFINITE_NEG_Y) && size.y != 0.0) throw std::runtime_error("CalculateStrayfieldForCuboid: cuboid size in y-direction must be zero for infinite extents in y direction");
if ((infinity & INFINITE_POS_Z || infinity & INFINITE_NEG_Z) && size.z != 0.0) throw std::runtime_error("CalculateStrayfieldForCuboid: cuboid size in z-direction must be zero for infinite extents in z direction");
if (size.x < 0.0 || size.y < 0.0 || size.z < 0.0) throw std::runtime_error("CalculateStrayfieldForCuboid: cuboid size must be positive");
if (dim_x < 1 || dim_y < 1 || dim_z < 1) throw std::runtime_error("CalculateStrayfieldForCuboid: dim_x,y,z must be positive");
if (!(delta_x > 0.0 && delta_y > 0.0 && delta_z > 0.0)) throw std::runtime_error("CalculateStrayfieldForCuboid: delta_x,y,z must be positive");
if (mag_dir < 0 || mag_dir > 2) throw std::runtime_error("CalculateStrayfieldForCuboid: cuboid_mag_dir must be 0, 1, or 2");
Vector3d p0 = pos;
Vector3d p1 = pos + size;
VectorMatrix H(Shape(dim_x, dim_y, dim_z));
H.clear();
VectorMatrix::accessor H_acc(H);
H_acc.set(0,0,0, Vector3d(1,2,3));
assert(0);
}
示例11: Shape
Shape Shape::map(Transform t) const
{
return Shape("m" + (t.x_forward.length() ? t.x_forward : " ")
+ (t.y_forward.length() ? t.y_forward : " ")
+ (t.z_forward.length() ? t.z_forward : " ") + math,
bounds.map(t));
}
示例12: Q_D
/*!
\since 5.5
Initializes \a option with the values from this QFrame. This method is
useful for subclasses when they need a QStyleOptionFrame but don't want to
fill in all the information themselves.
\sa QStyleOption::initFrom()
*/
void QFrame::initStyleOption(QStyleOptionFrame *option) const
{
if (!option)
return;
Q_D(const QFrame);
option->initFrom(this);
int frameShape = d->frameStyle & QFrame::Shape_Mask;
int frameShadow = d->frameStyle & QFrame::Shadow_Mask;
option->frameShape = Shape(int(option->frameShape) | frameShape);
option->rect = frameRect();
switch (frameShape) {
case QFrame::Box:
case QFrame::HLine:
case QFrame::VLine:
case QFrame::StyledPanel:
case QFrame::Panel:
option->lineWidth = d->lineWidth;
option->midLineWidth = d->midLineWidth;
break;
default:
// most frame styles do not handle customized line and midline widths
// (see updateFrameWidth()).
option->lineWidth = d->frameWidth;
break;
}
if (frameShadow == Sunken)
option->state |= QStyle::State_Sunken;
else if (frameShadow == Raised)
option->state |= QStyle::State_Raised;
}
示例13: Intersects
RNBoolean R3SceneElement::
Intersects(const R3Ray& ray, R3Shape **hit_shape,
R3Point *hit_point, R3Vector *hit_normal, RNScalar *hit_t) const
{
// Variables
RNScalar closest_t = FLT_MAX;
R3Point point;
R3Vector normal;
RNScalar t;
// Intersect with shapes
for (int i = 0; i < NShapes(); i++) {
R3Shape *shape = Shape(i);
if (shape->Intersects(ray, &point, &normal, &t)) {
if (t < closest_t) {
if (hit_shape) *hit_shape = shape;
if (hit_point) *hit_point = point;
if (hit_normal) *hit_normal = normal;
if (hit_t) *hit_t = t;
closest_t = t;
}
}
}
// Return whether hit any shape
return (closest_t == FLT_MAX) ? FALSE : TRUE;
}
示例14: mtrand
void Neighborhood::move(unsigned int old_x, unsigned int old_y)
{
//unsigned int new_x = mtrand(0, (size_x - 1));
//unsigned int new_y = mtrand(0, (size_y - 1));
//
// while (neighborhood_[new_x, new_y].getType() != "empty")
// {
// new_x = mtrand(0, (size_x - 1));
// new_y = mtrand(0, (size_y - 1));
// }
//
// neighborhood_[new_x, new_y].getType() = neighborhood_[old_x, old_y].getType();
// neighborhood_[old_x, old_y].getType() = "empty";
for (;;)
{
unsigned int x = mtrand(0, size_x - 1);
unsigned int y = mtrand(0, size_y - 1);
// not my code, borrowed from HyrekanDragon because mine^^ wouldnt work
if (get(x, y).getType() == "empty")
{
set(x, y, get(old_x, old_y));
set(old_x, old_y, Shape("empty"));
break;
}
}
}
示例15: Q_D
/*!
\internal
Mostly for the sake of Q3Frame
*/
void QFrame::drawFrame(QPainter *p)
{
Q_D(QFrame);
QStyleOptionFrameV3 opt;
opt.init(this);
int frameShape = d->frameStyle & QFrame::Shape_Mask;
int frameShadow = d->frameStyle & QFrame::Shadow_Mask;
opt.frameShape = Shape(int(opt.frameShape) | frameShape);
opt.rect = frameRect();
switch (frameShape) {
case QFrame::Box:
case QFrame::HLine:
case QFrame::VLine:
case QFrame::StyledPanel:
case QFrame::Panel:
opt.lineWidth = d->lineWidth;
opt.midLineWidth = d->midLineWidth;
break;
default:
// most frame styles do not handle customized line and midline widths
// (see updateFrameWidth()).
opt.lineWidth = d->frameWidth;
break;
}
if (frameShadow == Sunken)
opt.state |= QStyle::State_Sunken;
else if (frameShadow == Raised)
opt.state |= QStyle::State_Raised;
style()->drawControl(QStyle::CE_ShapedFrame, &opt, p, this);
}