fg::Plot3* setup_plot3(const af_array P, fg::PlotType ptype, fg::MarkerType mtype) { Array<T> pIn = getArray<T>(P); ArrayInfo Pinfo = getInfo(P); af::dim4 P_dims = Pinfo.dims(); DIM_ASSERT(0, Pinfo.ndims() == 1 || Pinfo.ndims() == 2); DIM_ASSERT(0, (P_dims[0] == 3 || P_dims[1] == 3) || (Pinfo.isVector() && P_dims[0]%3 == 0)); if(Pinfo.isVector()){ dim4 rdims(P_dims.elements()/3, 3, 1, 1); pIn.modDims(rdims); P_dims = pIn.dims(); } if(P_dims[1] == 3){ pIn = transpose(pIn, false); } T max[3], min[3]; copyData(max, reduce<af_max_t, T, T>(pIn, 1)); copyData(min, reduce<af_min_t, T, T>(pIn, 1)); ForgeManager& fgMngr = ForgeManager::getInstance(); fg::Plot3* plot3 = fgMngr.getPlot3(P_dims.elements()/3, getGLType<T>(), ptype, mtype); plot3->setColor(1.0, 0.0, 0.0); plot3->setAxesLimits(max[0], min[0], max[1], min[1], max[2], min[2]); plot3->setAxesTitles("X Axis", "Y Axis", "Z Axis"); copy_plot3<T>(pIn, plot3); return plot3; }
af_err af_draw_hist(const af_window wind, const af_array X, const double minval, const double maxval, const af_cell* const props) { #if defined(WITH_GRAPHICS) if(wind==0) { std::cerr<<"Not a valid window"<<std::endl; return AF_SUCCESS; } try { ArrayInfo Xinfo = getInfo(X); af_dtype Xtype = Xinfo.getType(); ARG_ASSERT(0, Xinfo.isVector()); fg::Window* window = reinterpret_cast<fg::Window*>(wind); window->makeCurrent(); fg::Histogram* hist = NULL; switch(Xtype) { case f32: hist = setup_histogram<float >(X, minval, maxval); break; case s32: hist = setup_histogram<int >(X, minval, maxval); break; case u32: hist = setup_histogram<uint >(X, minval, maxval); break; case s16: hist = setup_histogram<short >(X, minval, maxval); break; case u16: hist = setup_histogram<ushort >(X, minval, maxval); break; case u8 : hist = setup_histogram<uchar >(X, minval, maxval); break; default: TYPE_ERROR(1, Xtype); } if (props->col>-1 && props->row>-1) window->draw(props->col, props->row, *hist, props->title); else window->draw(*hist); } CATCHALL; return AF_SUCCESS; #else return AF_ERR_NO_GFX; #endif }
af_err af_assign_gen(af_array *out, const af_array lhs, const dim_t ndims, const af_index_t* indexs, const af_array rhs_) { af_array output = 0; af_array rhs = rhs_; // spanner is sequence index used for indexing along the // dimensions after ndims af_index_t spanner; spanner.idx.seq = af_span; spanner.isSeq = true; try { ARG_ASSERT(2, (ndims>0)); ARG_ASSERT(3, (indexs!=NULL)); int track = 0; vector<af_seq> seqs(4, af_span); for (dim_t i = 0; i < ndims; i++) { if (indexs[i].isSeq) { track++; seqs[i] = indexs[i].idx.seq; } } if (track==(int)ndims) { // all indexs are sequences, redirecting to af_assign return af_assign_seq(out, lhs, ndims, &(seqs.front()), rhs); } ARG_ASSERT(1, (lhs!=0)); ARG_ASSERT(4, (rhs!=0)); ArrayInfo lInfo = getInfo(lhs); ArrayInfo rInfo = getInfo(rhs); dim4 lhsDims = lInfo.dims(); dim4 rhsDims = rInfo.dims(); af_dtype lhsType= lInfo.getType(); af_dtype rhsType= rInfo.getType(); ARG_ASSERT(2, (ndims == 1) || (ndims == (dim_t)lInfo.ndims())); if (ndims == 1 && ndims != (dim_t)lInfo.ndims()) { af_array tmp_in = 0, tmp_out = 0; AF_CHECK(af_flat(&tmp_in, lhs)); AF_CHECK(af_assign_gen(&tmp_out, tmp_in, ndims, indexs, rhs_)); AF_CHECK(af_moddims(out, tmp_out, lInfo.ndims(), lInfo.dims().get())); AF_CHECK(af_release_array(tmp_in)); AF_CHECK(af_release_array(tmp_out)); return AF_SUCCESS; } ARG_ASSERT(1, (lhsType==rhsType)); ARG_ASSERT(3, (rhsDims.ndims()>0)); ARG_ASSERT(1, (lhsDims.ndims()>=rhsDims.ndims())); ARG_ASSERT(2, (lhsDims.ndims()>=ndims)); if (*out != lhs) { int count = 0; AF_CHECK(af_get_data_ref_count(&count, lhs)); if (count > 1) { AF_CHECK(af_copy_array(&output, lhs)); } else { AF_CHECK(af_retain_array(&output, lhs)); } } else { output = lhs; } dim4 oDims = toDims(seqs, lhsDims); // if af_array are indexs along any // particular dimension, set the length of // that dimension accordingly before any checks for (dim_t i=0; i<ndims; i++) { if (!indexs[i].isSeq) { oDims[i] = getInfo(indexs[i].idx.arr).elements(); } } for (dim_t i = ndims; i < (dim_t)lInfo.ndims(); i++) { oDims[i] = 1; } bool is_vector = true; for (int i = 0; is_vector && i < oDims.ndims() - 1; i++) { is_vector &= oDims[i] == 1; } //TODO: Move logic out of this is_vector &= rInfo.isVector() || rInfo.isScalar(); if (is_vector) { if (oDims.elements() != (dim_t)rInfo.elements() && rInfo.elements() != 1) { AF_ERROR("Size mismatch between input and output", AF_ERR_SIZE); } if (rInfo.elements() == 1) { AF_CHECK(af_tile(&rhs, rhs_, oDims[0], oDims[1], oDims[2], oDims[3])); } else { // If both out and rhs are vectors of equal elements, reshape rhs to out dims AF_CHECK(af_moddims(&rhs, rhs_, oDims.ndims(), oDims.get())); } } else { for (int i = 0; i < 4; i++) { if (oDims[i] != rhsDims[i]) { AF_ERROR("Size mismatch between input and output", AF_ERR_SIZE); } } } af_index_t idxrs[4]; // set all dimensions above ndims to spanner index for (dim_t i=ndims; i<4; ++i) idxrs[i] = spanner; for (dim_t i=0; i<ndims; ++i) { if (!indexs[i].isSeq) { // check if all af_arrays have atleast one value // to enable indexing along that dimension ArrayInfo idxInfo = getInfo(indexs[i].idx.arr); af_dtype idxType = idxInfo.getType(); ARG_ASSERT(3, (idxType!=c32)); ARG_ASSERT(3, (idxType!=c64)); ARG_ASSERT(3, (idxType!=b8 )); idxrs[i].idx.arr = indexs[i].idx.arr; idxrs[i].isSeq = indexs[i].isSeq; } else { // af_seq is being used for this dimension // just copy the index to local variable idxrs[i] = indexs[i]; } } try { switch(rhsType) { case c64: genAssign<cdouble>(output, idxrs, rhs); break; case f64: genAssign<double >(output, idxrs, rhs); break; case c32: genAssign<cfloat >(output, idxrs, rhs); break; case f32: genAssign<float >(output, idxrs, rhs); break; case u64: genAssign<uintl >(output, idxrs, rhs); break; case u32: genAssign<uint >(output, idxrs, rhs); break; case s64: genAssign<intl >(output, idxrs, rhs); break; case s32: genAssign<int >(output, idxrs, rhs); break; case u8: genAssign<uchar >(output, idxrs, rhs); break; case b8: genAssign<char >(output, idxrs, rhs); break; default: TYPE_ERROR(1, rhsType); } } catch(...) { if (*out != lhs) { AF_CHECK(af_release_array(output)); if (is_vector) { AF_CHECK(af_release_array(rhs)); } } throw; } if (is_vector) { AF_CHECK(af_release_array(rhs)); } } CATCHALL; std::swap(*out, output); return AF_SUCCESS; }