int KCoreGraph::qcoloring(const std::pair<double, int>* boxes, int nboxes, int q) { assert(maxsize() == nboxes); /* Reinit the coloring vector, just in case */ for (int i=0; i<maxsize(); i++) { colors[i] = 0; } int vert; for (int i=0; i<nboxes; i++) { /* The current box to be colored */ vert = boxes[i].second; /* Find the smallest available color for "vert" */ if (!allid->contain(vert)) continue; if (neighbourhoods.at(vert)->empty()) { colors[vert] = 1; continue; } used->clear(); int val = neighbourhoods.at(vert)->head(); int preval = val-1; while (val != preval) { if (colors[val] != 0) { used->add(colors[val]); } preval = val; val = neighbourhoods.at(vert)->next(preval); } /* "used" now contains all the colors used in the neighbourhood of "vert" */ for (int j=1; j<q; j++) { if (!used->contain(j)) { colors[vert] = j; break; } /* Note : q-1 is actually the qth color */ if (j==q-1) return vert; } } return -1; };
static long ierelation(TYP **tp) /* non-eq relations */ { long val1 = ieshiftops(tp), val2; while (lastst == lt || lastst == gt || lastst == leq || lastst == geq) { long oper = lastst; TYP *tp1; getsym(); val2 = ieshiftops(&tp1); switch(oper) { case lt: val1 = val1 < val2; break; case gt: val1 = val1 > val2; break; case leq: val1 = val1 <= val2; break; case geq: val1 = val1 >= val2; break; } if (tp) *tp = maxsize(*tp,tp1); } return(val1); }
static void printsizes(void) { uvlong max = maxsize(); print("\tblock size = %d; ", RBUFSIZE); if (max == 0) print("max file size exceeds 2⁶⁴ bytes\n"); else { uvlong offlim = 1ULL << (sizeof(Off)*8 - 1); if (max >= offlim) max = offlim - 1; print("max file size = %,llu\n", (Wideoff)max); } if (INDPERBUF/INDPERBUF != INDPERBUF) print("overflow computing INDPERBUF\n"); if (INDPERBUF⁴/INDPERBUF != INDPERBUF) print("overflow computing INDPERBUF⁴\n"); print("\tINDPERBUF = %d, INDPERBUF^4 = %,lld, ", INDPERBUF, (Wideoff)INDPERBUF⁴); print("CEPERBK = %d\n", CEPERBK); print("\tsizeofs: Dentry = %d, Cache = %d\n", sizeof(Dentry), sizeof(Cache)); }
static long iemultops(TYP **tp) /* Multiply ops */ { long val1 = ieunary(tp),val2; while (lastst == star || lastst == divide || lastst == modop) { TYP *tp1; long oper = lastst; getsym(); val2 = ieunary(&tp1); switch(oper) { case star: val1 = val1 * val2; break; case divide: val1 = val1 / val2; break; case modop: val1 = val1 % val2; break; } if (tp) *tp = maxsize(*tp,tp1); } return(val1); }
graph_t *KCoreGraph::subgraph(IntStack *vset) { assert(!vset->empty()); graph_t *g = graph_new(maxsize()); IntStack *nb; int val,preval,val2,preval2; val = vset->head(); preval = val-1; while (val != preval) { nb = neighbourhoods.at(val); if (!nb->empty()) { val2 = nb->head(); preval2 = val2-1; while (val2 != preval2) { if ((val > val2) && vset->contain(val2)) GRAPH_ADD_EDGE(g,val,val2); preval2 = val2; val2 = nb->next(preval2); } } preval = val; val = vset->next(preval); } return g; };
/******************************************************************************* raw_omemstream *******************************************************************************/ raw_ios::pos_type raw_omemstream::seekoff(off_type offs, seekdir dir) { const pos_type from = dir == cur ? _pos : (dir == beg ? pos_type() : _endpos) ; const pos_type newpos = from + offs ; return newpos <= maxsize() || expand(newpos) ? (_pos = newpos) : pos_type(-1) ; }
size_t raw_omemstream::do_write(const void *buffer, size_t bufsize) { size_t newpos = _pos + bufsize ; if (newpos > _buffer.size()) { const bool toobig = newpos > maxsize() ; if (toobig) newpos = maxsize() ; if (!expand(newpos) || toobig) { setstate_nothrow(failbit, true) ; newpos = _buffer.size() ; NOXCHECK(newpos < _pos + bufsize) ; } } const size_t written_size = newpos - _pos ; memmove(pcomn::padd(data(), _pos), buffer, written_size) ; if ((_pos = newpos) > _endpos) _endpos = _pos ; return written_size ; }
static long ieorop(TYP **tp) /* or op */ { long val1 = iexorop(tp),val2; while (lastst == or) { TYP *tp1; getsym(); val2 = iexorop(&tp1); val1 = val1 | val2; if (tp) *tp = maxsize(*tp,tp1); } return(val1); }
static long iexorop(TYP **tp) /* xor op */ { long val1 = ieandop(tp),val2; while (lastst == uparrow) { TYP *tp1; getsym(); val2 = ieandop(&tp1); val1 = val1 ^ val2; if (tp) *tp = maxsize(*tp,tp1); } return(val1); }
static long ieandop(TYP **tp) /* and op */ { long val1 = ieequalops(tp),val2; while (lastst == and) { TYP *tp1; getsym(); val2 = ieequalops(&tp1); val1 = val1 & val2; if (tp) *tp = maxsize(*tp,tp1); } return(val1); }
static long ielorop(TYP **tp) /* logical or op */ { long val1 = ielandop(tp),val2; while (lastst == lor) { TYP *tp1; getsym(); val2 = ielandop(&tp1); val1 = val1 || val2; if (tp) *tp = maxsize(*tp,tp1); } return(val1); }
int maximalSquare(vector<vector<char>>& matrix) { if(matrix.empty()) return 0; int row = matrix.size(); int col = matrix[0].size(); vector<vector<int>> maxsize(row, vector<int>(col, -1)); int max = INT_MIN; for (int i = 0; i < row; ++i) { for (int j=0; j<col; ++j) { int val = SquareSize(i, j, matrix, maxsize); if (val > max) val = max; } } return max; }
static long ieequalops(TYP **tp) /* eq relations */ { long val1 = ierelation(tp),val2; while (lastst == eq || lastst == neq) { long oper = lastst; TYP *tp1; getsym(); val2 = ierelation(&tp1); if (oper == neq) val1 = val1 != val2; else val1 = val1 == val2; if (tp) *tp = maxsize(*tp,tp1); } return(val1); }
static long ieshiftops(TYP **tp) /* Shift ops */ { long val1 = ieaddops(tp), val2; while (lastst == lshift || lastst == rshift) { long oper = lastst; TYP *tp1; getsym(); val2 = ieaddops(&tp1); if (oper == lshift) val1 <<= val2; else val1 >>= val2; if (tp) *tp = maxsize(*tp,tp1); } return(val1); }
static long ieaddops(TYP **tp) /* Add ops */ { long val1 = iemultops(tp),val2; while (lastst == plus || lastst == minus) { long oper = lastst; TYP *tp1; getsym(); val2 = iemultops(&tp1); if (oper == plus) val1 = val1 + val2; else val1 = val1 - val2; if (tp) *tp = maxsize(*tp,tp1); } return(val1); }
static long iecondop(TYP **tp) /* Hook op */ { long val1 = ielorop(tp),val2, val3; if (lastst == hook) { TYP *tp1, *tp2; getsym(); val2 = iecondop(&tp1); needpunc(colon,0); val3 = iecondop(&tp2); if (val1) val1 = val2; else val1 = val3; if (tp) *tp = maxsize(tp2,tp1); } return(val1); }
QSize QtopiaCLItemDelegate::variantSize(QPaintDevice *device, const QStyleOptionViewItem &option, const QVariant &value) const { QSize maxsize(65535,65535); if (!value.isNull()) { switch (value.type()) { case QVariant::Invalid: break; case QVariant::Pixmap: return qvariant_cast<QPixmap>(value).size(); case QVariant::Image: return qvariant_cast<QImage>(value).size(); case QVariant::Icon: { QIcon icon = qvariant_cast<QIcon>(value); return icon.actualSize(maxsize); } case QVariant::List: { int maxh=0; int width=0; foreach(const QVariant &item, value.toList()) { QSize item_size = variantSize(device, option, item); width += item_size.width(); maxh = qMax(maxh, item_size.height()); } return QSize(width,maxh); } case QVariant::String: { QFontMetrics fm(option.font, device); return QSize(fm.width(value.toString()), fm.height()); } default: break; } } return QSize(0,0); }
//================================================================================================= void GameMenu::LoadLanguage() { txSave = Str("saveGame"); txSaveAndExit = Str("saveAndExit"); txExitToMenuDialog = Str("exitToMenuDialog"); cstring names[] = { "returnToGame", "saveGame", "loadGame", "options", "exitToMenu", "quit" }; Int2 maxsize(0, 0); for(int i = 0; i < 6; ++i) { bt[i].id = IdReturnToGame + i; bt[i].parent = this; bt[i].text = Str(names[i]); bt[i].size = GUI.default_font->CalculateSize(bt[i].text) + Int2(24, 24); maxsize = Int2::Max(maxsize, bt[i].size); } size = Int2(256 + 16, 128 + 16 + (maxsize.y + 8) * 6); Int2 offset((size.x - maxsize.x) / 2, 128 + 8); // ustaw przyciski for(int i = 0; i < 6; ++i) { bt[i].pos = offset; bt[i].size = maxsize; offset.y += maxsize.y + 8; } }
wxSize wxRadioBox::GetMaxButtonSize() const { int nWidthMax = 0; int nHeightMax = 0; for (unsigned int i = 0 ; i < m_nNoItems; i++) { int nWidth; int nHeight; if (m_pnRadioWidth[i] < 0L) { GetTextExtent( wxGetWindowText(m_ahRadioButtons[i]) ,&nWidth ,&nHeight ); // // Adjust the size to take into account the radio box itself // FIXME this is totally bogus! // nWidth += RADIO_SIZE; nHeight *= 3; nHeight /= 2; } else { nWidth = m_pnRadioWidth[i]; nHeight = m_pnRadioHeight[i]; } if (nWidthMax < nWidth ) nWidthMax = nWidth; if (nHeightMax < nHeight ) nHeightMax = nHeight; } wxSize maxsize( nWidthMax, nHeightMax); return maxsize; } // end of wxRadioBox::GetMaxButtonSize
void QWidgetResizeHandler::mouseMoveEvent(QMouseEvent *e) { QPoint pos = widget->mapFromGlobal(e->globalPos()); if (!moveResizeMode && !buttonDown) { if (pos.y() <= range && pos.x() <= range) mode = TopLeft; else if (pos.y() >= widget->height()-range && pos.x() >= widget->width()-range) mode = BottomRight; else if (pos.y() >= widget->height()-range && pos.x() <= range) mode = BottomLeft; else if (pos.y() <= range && pos.x() >= widget->width()-range) mode = TopRight; else if (pos.y() <= range) mode = Top; else if (pos.y() >= widget->height()-range) mode = Bottom; else if (pos.x() <= range) mode = Left; else if ( pos.x() >= widget->width()-range) mode = Right; else if (widget->rect().contains(pos)) mode = Center; else mode = Nowhere; if (widget->isMinimized() || !isActive(Resize)) mode = Center; #ifndef QT_NO_CURSOR setMouseCursor(mode); #endif return; } if (mode == Center && !movingEnabled) return; if (widget->testAttribute(Qt::WA_WState_ConfigPending)) return; QPoint globalPos = (!widget->isWindow() && widget->parentWidget()) ? widget->parentWidget()->mapFromGlobal(e->globalPos()) : e->globalPos(); if (!widget->isWindow() && !widget->parentWidget()->rect().contains(globalPos)) { if (globalPos.x() < 0) globalPos.rx() = 0; if (globalPos.y() < 0) globalPos.ry() = 0; if (sizeprotect && globalPos.x() > widget->parentWidget()->width()) globalPos.rx() = widget->parentWidget()->width(); if (sizeprotect && globalPos.y() > widget->parentWidget()->height()) globalPos.ry() = widget->parentWidget()->height(); } QPoint p = globalPos + invertedMoveOffset; QPoint pp = globalPos - moveOffset; // Workaround for window managers which refuse to move a tool window partially offscreen. if (QGuiApplication::platformName() == QLatin1String("xcb")) { const QRect desktop = QApplication::desktop()->availableGeometry(widget); pp.rx() = qMax(pp.x(), desktop.left()); pp.ry() = qMax(pp.y(), desktop.top()); p.rx() = qMin(p.x(), desktop.right()); p.ry() = qMin(p.y(), desktop.bottom()); } QSize ms = qSmartMinSize(childWidget); int mw = ms.width(); int mh = ms.height(); if (childWidget != widget) { mw += 2 * fw; mh += 2 * fw + extrahei; } QSize maxsize(childWidget->maximumSize()); if (childWidget != widget) maxsize += QSize(2 * fw, 2 * fw + extrahei); QSize mpsize(widget->geometry().right() - pp.x() + 1, widget->geometry().bottom() - pp.y() + 1); mpsize = mpsize.expandedTo(widget->minimumSize()).expandedTo(QSize(mw, mh)) .boundedTo(maxsize); QPoint mp(widget->geometry().right() - mpsize.width() + 1, widget->geometry().bottom() - mpsize.height() + 1); QRect geom = widget->geometry(); switch (mode) { case TopLeft: geom = QRect(mp, widget->geometry().bottomRight()) ; break; case BottomRight: geom = QRect(widget->geometry().topLeft(), p) ; break; case BottomLeft: geom = QRect(QPoint(mp.x(), widget->geometry().y()), QPoint(widget->geometry().right(), p.y())) ; break; case TopRight: geom = QRect(QPoint(widget->geometry().x(), mp.y()), QPoint(p.x(), widget->geometry().bottom())) ; break; case Top: geom = QRect(QPoint(widget->geometry().left(), mp.y()), widget->geometry().bottomRight()) ; break; case Bottom: geom = QRect(widget->geometry().topLeft(), QPoint(widget->geometry().right(), p.y())) ; break; case Left: geom = QRect(QPoint(mp.x(), widget->geometry().top()), widget->geometry().bottomRight()) ; break; case Right: geom = QRect(widget->geometry().topLeft(), QPoint(p.x(), widget->geometry().bottom())) ; break; case Center: geom.moveTopLeft(pp); break; default: break; } geom = QRect(geom.topLeft(), geom.size().expandedTo(widget->minimumSize()) .expandedTo(QSize(mw, mh)) .boundedTo(maxsize)); if (geom != widget->geometry() && (widget->isWindow() || widget->parentWidget()->rect().intersects(geom))) { if (mode == Center) widget->move(geom.topLeft()); else widget->setGeometry(geom); } }
Size FlowLayout::getMaxSize() const { Size max; for(auto it = _ctrls.begin(); it != _ctrls.end(); ++it) max = maxsize(max,(*it)->getPreferredSize()); return max; }
void LRUCacheH4<K, V>::dump_mru_to_lru(std::ostream & os) const { os << "LRUCacheH4(" << size() << "/" << maxsize() << "): MRU --> LRU: " << std::endl; for (const_iterator it = mru_begin(); it != end(); ++it) os << it.key() << ": " << it.value() << std::endl; }
void LayerJitt::Init(const mxArray *mx_layer, Layer *prev_layer) { //mexAssert(prev_layer->type_ == "i", "The 'j' type layer must be after the input one"); numdim_ = prev_layer->numdim_; outputmaps_ = prev_layer->outputmaps_; length_prev_ = prev_layer->length_prev_; mexAssert(mexIsField(mx_layer, "mapsize"), "The 'j' type layer must contain the 'mapsize' field"); std::vector<ftype> mapsize = mexGetVector(mexGetField(mx_layer, "mapsize")); mexAssert(mapsize.size() == numdim_, "Length of jitter mapsize vector and maps dimensionality must coincide"); mapsize_.resize(numdim_); length_ = outputmaps_; for (size_t i = 0; i < numdim_; ++i) { mexAssert(1 <= mapsize[i], "In 'j' layer mapsize must be positive"); mapsize_[i] = (size_t) mapsize[i]; length_ *= mapsize_[i]; } shift_.assign(numdim_, 0); if (mexIsField(mx_layer, "shift")) { shift_ = mexGetVector(mexGetField(mx_layer, "shift")); mexAssert(shift_.size() == numdim_, "Length of jitter shift vector and maps dimensionality must coincide"); for (size_t i = 0; i < numdim_; ++i) { mexAssert(0 <= shift_[i] && shift_[i] < mapsize_[i], "Shift in 'j' layer is out of range"); } } scale_.assign(numdim_, 1); if (mexIsField(mx_layer, "scale")) { scale_ = mexGetVector(mexGetField(mx_layer, "scale")); mexAssert(scale_.size() == numdim_, "Length of jitter scale vector and maps dimensionality must coincide"); for (size_t i = 0; i < numdim_; ++i) { mexAssert(1 <= scale_[i] && scale_[i] < mapsize_[i], "Scale in 'j' layer is out of range"); } } mirror_.assign(numdim_, false); if (mexIsField(mx_layer, "mirror")) { std::vector<ftype> mirror = mexGetVector(mexGetField(mx_layer, "mirror")); mexAssert(mirror.size() == numdim_, "Length of jitter scale vector and maps dimensionality must coincide"); for (size_t i = 0; i < numdim_; ++i) { mirror_[i] = (mirror[i] > 0); } } angle_ = 0; if (mexIsField(mx_layer, "angle")) { angle_ = mexGetScalar(mexGetField(mx_layer, "angle")); mexAssert(0 <= angle_ && angle_ <= 1, "Angle in 'j' layer must be between 0 and 1"); } defval_ = 0; if (mexIsField(mx_layer, "defval")) { defval_ = mexGetScalar(mexGetField(mx_layer, "defval")); } else { // check that the transformed image is always inside the original one std::vector<ftype> maxsize(numdim_, 0); for (size_t i = 0; i < numdim_; ++i) { maxsize[i] = (ftype) (mapsize_[i] - 1) * scale_[i]; } if (angle_ > 0) { ftype angle_inn = atan2((ftype) mapsize_[0], (ftype) mapsize_[1]) / kPi; ftype maxsin = 1; if (angle_inn + angle_ < 0.5) { maxsin = sin(kPi * (angle_inn + angle_)); } ftype maxcos = 1; if (angle_inn > angle_) { maxcos = cos(kPi * (angle_inn - angle_)); } ftype maxrad = sqrt(maxsize[0]*maxsize[0] + maxsize[1]*maxsize[1]); maxsize[0] = maxrad * maxsin; maxsize[1] = maxrad * maxcos; } std::vector<ftype> oldmapsize(numdim_, 0); for (size_t i = 0; i < numdim_; ++i) { oldmapsize[i] = (ftype) prev_layer->mapsize_[i]; } ftype min0 = (oldmapsize[0]/2 - 0.5) - maxsize[0]/2 - shift_[0]; ftype max0 = (oldmapsize[0]/2 - 0.5) + maxsize[0]/2 + shift_[0]; ftype min1 = (oldmapsize[1]/2 - 0.5) - maxsize[1]/2 - shift_[1]; ftype max1 = (oldmapsize[1]/2 - 0.5) + maxsize[1]/2 + shift_[1]; if (!(0 <= min0 && max0 < oldmapsize[0] && 0 <= min1 && max1 < oldmapsize[1])) { mexPrintMsg("min1", min0); mexPrintMsg("max1", max0); mexPrintMsg("min2", min1); mexPrintMsg("max2", max1); mexAssert(false, "For these jitter parameters the new image is out of the original image"); } } }
void KCoreGraph::add_vertex(const int idvert) { assert(neighbourhoods.at(idvert) == NULL); neighbourhoods.at(idvert) = new IntStack(0,maxsize()-1,false); };
////////////////// // Get size information for a single entry (WINRECT). Returns size info in // the SIZEINFO argument. For a group, calculate size info as aggregate of // subentries. // void CWinMgr::OnGetSizeInfo(SIZEINFO& szi, WINRECT* wrc, CWnd* pWnd) { szi.szMin = SIZEZERO; // default min size = zero szi.szMax = SIZEMAX; // default max size = infinite szi.szDesired = wrc->GetRect().Size(); // default desired size = current if (wrc->IsGroup()) { // For groups, calculate min, max, desired size as aggregate of children szi.szDesired = SIZEZERO; BOOL bRow = wrc->IsRowGroup(); CWinGroupIterator it; for (it=wrc; it; it.Next()) { WINRECT* wrc2 = it; SIZEINFO szi2; OnGetSizeInfo(szi2, wrc2, pWnd); if (bRow) { szi.szMin.cx = max(szi.szMin.cx, szi2.szMin.cx); szi.szMin.cy += szi2.szMin.cy; szi.szMax.cx = min(szi.szMax.cx, szi2.szMax.cx); szi.szMax.cy = min(szi.szMax.cy + szi2.szMax.cy, _INFINITY); szi.szDesired.cx = max(szi.szDesired.cx, szi2.szDesired.cx); szi.szDesired.cy += szi2.szDesired.cy; } else { szi.szMin.cx += szi2.szMin.cx; szi.szMin.cy = max(szi.szMin.cy, szi2.szMin.cy); szi.szMax.cx = min(szi.szMax.cx + szi2.szMax.cx, _INFINITY); szi.szMax.cy = min(szi.szMax.cy, szi2.szMax.cy); szi.szDesired.cx += szi2.szDesired.cx; szi.szDesired.cy = max(szi.szDesired.cy, szi2.szDesired.cy); } } // Add margins. int w2,h2; wrc->GetMargins(w2,h2); // get margins w2<<=1; h2<<=1; // double szi.szMin.cx += max(0,w2); // negative margins ==> don't include in min szi.szMin.cy += max(0,h2); // ditto szi.szDesired.cx += abs(w2); // for desired size, use abs vallue szi.szDesired.cy += abs(h2); // ditto } else { // not a group WINRECT* parent = wrc->Parent(); ASSERT(parent); CRect& rcParent = parent->GetRect(); BOOL bRow = parent->IsRowGroup(); int hw, hwMin, hwTotal, pct; switch (wrc->Type()) { case WRCT_FIXED: hw = hwMin = wrc->GetParam(); // ht/wid is parameter if (hw<0) { // if fixed val is negative: hw = -hw; // use absolute val for desired.. hwMin = 0; // ..and zero for minimum } if (bRow) { szi.szMax.cy = szi.szDesired.cy = hw; szi.szMin.cy = hwMin; } else { szi.szMax.cx = szi.szDesired.cx = hw; szi.szMin.cx = hwMin; } break; case WRCT_PCT: pct = wrc->GetParam(); ASSERT(0<pct && pct<100); hwTotal = bRow ? rcParent.Height() : rcParent.Width(); hw = (hwTotal * pct) / 100; szi.szDesired = bRow ? CSize(rcParent.Width(), hw) : CSize(hw, rcParent.Height()); break; case WRCT_TOFIT: if (wrc->HasToFitSize()) { szi.szDesired = wrc->GetToFitSize(); } break; case WRCT_REST: break; default: ASSERT(FALSE); } // If the entry is a window, send message to get min/max/tofit size. // Only set tofit size if type is TOFIT. // if (wrc->IsWindow() && pWnd) { CWnd* pChild = pWnd->GetDlgItem(wrc->GetID()); if (pChild) { if (!pChild->IsWindowVisible() && pWnd->IsWindowVisible()) { // parent visible but child not ==> tofit size is zero // important so hidden windows use no space szi.szDesired = SIZEZERO; } else { szi.szAvail = rcParent.Size(); SendGetSizeInfo(szi, pWnd, wrc->GetID()); } } } szi.szDesired = maxsize(minsize(szi.szDesired,szi.szMax), szi.szMin); } }
void LayerJitt::Init(const mxArray *mx_layer, const Layer *prev_layer) { dims_[1] = prev_layer->dims_[1]; std::vector<ftype> shift(2); shift[0] = 0; shift[1] = 0; if (mexIsField(mx_layer, "shift")) { shift = mexGetVector(mexGetField(mx_layer, "shift")); mexAssertMsg(shift.size() == 2, "Length of jitter shift vector and maps dimensionality must coincide"); for (size_t i = 0; i < 2; ++i) { mexAssertMsg(0 <= shift[i] && shift[i] < dims_[i+2], "Shift in 'jitt' layer is out of range"); } MatCPU shift_cpu(1, 2); shift_cpu.assign(shift); shift_ = shift_cpu; } std::vector<ftype> scale(2); scale[0] = 1; scale[1] = 1; if (mexIsField(mx_layer, "scale")) { scale = mexGetVector(mexGetField(mx_layer, "scale")); mexAssertMsg(scale.size() == 2, "Length of jitter scale vector and maps dimensionality must coincide"); for (size_t i = 0; i < 2; ++i) { mexAssertMsg(1 <= scale[i] && scale[i] < dims_[i+2], "Scale in 'j' layer is out of range"); } MatCPU scale_cpu(1, 2); scale_cpu.assign(scale); scale_ = scale_cpu; scale_.Log(); } if (mexIsField(mx_layer, "mirror")) { std::vector<ftype> mirror = mexGetVector(mexGetField(mx_layer, "mirror")); mexAssertMsg(mirror.size() == 2, "Length of jitter scale vector and maps dimensionality must coincide"); for (size_t i = 0; i < 2; ++i) { mexAssertMsg(mirror[i] == 0 || mirror[i] == 1, "Mirror must be either 0 or 1"); } MatCPU mirror_cpu(1, 2); mirror_cpu.assign(mirror); mirror_ = mirror_cpu; } if (mexIsField(mx_layer, "angle")) { angle_ = mexGetScalar(mexGetField(mx_layer, "angle")); mexAssertMsg(0 <= angle_ && angle_ <= 1, "Angle in 'j' layer must be between 0 and 1"); } if (mexIsField(mx_layer, "defval")) { defval_ = mexGetScalar(mexGetField(mx_layer, "defval")); } else { // check that the transformed image is always inside the original one std::vector<ftype> maxsize(2, 0); for (size_t i = 0; i < 2; ++i) { maxsize[i] = (ftype) (dims_[i+2] - 1) * scale[i]; } if (angle_ > 0) { ftype angle_inn = atan2((ftype) dims_[2], (ftype) dims_[3]) / kPi; ftype maxsin = 1; if (angle_inn + angle_ < 0.5) { maxsin = sin(kPi * (angle_inn + angle_)); } ftype maxcos = 1; if (angle_inn > angle_) { maxcos = cos(kPi * (angle_inn - angle_)); } ftype maxrad = (ftype) sqrt((double) (maxsize[0]*maxsize[0] + maxsize[1]*maxsize[1])); maxsize[0] = maxrad * maxsin; maxsize[1] = maxrad * maxcos; } std::vector<ftype> oldmapsize(2, 0); for (size_t i = 0; i < 2; ++i) { oldmapsize[i] = (ftype) prev_layer->dims_[i+2]; } ftype min0 = ((ftype) oldmapsize[0] / 2 - (ftype) 0.5) - (ftype) maxsize[0] / 2 - shift[0]; ftype max0 = ((ftype) oldmapsize[0] / 2 - (ftype) 0.5) + (ftype) maxsize[0] / 2 + shift[0]; ftype min1 = ((ftype) oldmapsize[1] / 2 - (ftype) 0.5) - (ftype) maxsize[1] / 2 - shift[1]; ftype max1 = ((ftype) oldmapsize[1] / 2 - (ftype) 0.5) + (ftype) maxsize[1] / 2 + shift[1]; if (!(0 <= min0 && max0 < oldmapsize[0] && 0 <= min1 && max1 < oldmapsize[1])) { mexPrintMsg("min1", min0); mexPrintMsg("max1", max0); mexPrintMsg("min2", min1); mexPrintMsg("max2", max1); mexAssertMsg(false, "For these jitter parameters the new image is out of the original image"); } } if (mexIsField(mx_layer, "eigenvectors")) { const mxArray* mx_ev = mexGetField(mx_layer, "eigenvectors"); std::vector<size_t> ev_dim = mexGetDimensions(mx_ev); mexAssertMsg(ev_dim.size() == 2, "The eigenvectors array must have 2 dimensions"); mexAssertMsg(ev_dim[0] == dims_[1] && ev_dim[1] == dims_[1], "The eigenvector matrix size is wrong"); MatCPU ev_cpu(dims_[1], dims_[1]); mexGetMatrix(mx_ev, ev_cpu); eigenvectors_.resize(dims_[1], dims_[1]); eigenvectors_ = ev_cpu; if (mexIsField(mx_layer, "noise_std")) { noise_std_ = mexGetScalar(mexGetField(mx_layer, "noise_std")); mexAssertMsg(noise_std_ >= 0, "noise_std must be nonnegative"); } else { mexAssertMsg(false, "noise_std is required with eigenvalues"); } } if (mexIsField(mx_layer, "randtest")) { randtest_ = (mexGetScalar(mexGetField(mx_layer, "randtest")) > 0); } }