Skip to content

Commit f3c5ad2

Browse files
committed
Merge pull request arrayfire#1274 from pavanky/gfx_fixes
Fixes to memory leaks, and performance improvements in graphics functions
2 parents fa0f6e7 + 213c8e6 commit f3c5ad2

3 files changed

Lines changed: 33 additions & 28 deletions

File tree

src/api/c/plot.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,19 @@ fg::Plot* setup_plot(const af_array X, const af_array Y, fg::PlotType type, fg::
3939

4040
dim4 rdims(1, 0, 2, 3);
4141

42-
Array<T> Z = join(1, xIn, yIn);
43-
Array<T> P = reorder(Z, rdims);
42+
dim_t elements = xIn.elements();
43+
dim4 rowDims = dim4(1, elements, 1, 1);
4444

45-
ArrayInfo Xinfo = getInfo(X);
46-
af::dim4 X_dims = Xinfo.dims();
45+
// Force the vectors to be row vectors
46+
// This ensures we can use join(0,..) and skip reorder
47+
xIn.modDims(rowDims);
48+
yIn.modDims(rowDims);
49+
50+
// join along first dimension, skip reorder
51+
Array<T> P = join(0, xIn, yIn);
4752

4853
ForgeManager& fgMngr = ForgeManager::getInstance();
49-
fg::Plot* plot = fgMngr.getPlot(X_dims.elements(), getGLType<T>(), type, marker);
54+
fg::Plot* plot = fgMngr.getPlot(elements, getGLType<T>(), type, marker);
5055
plot->setColor(1.0, 0.0, 0.0);
5156
plot->setAxesLimits(xmax, xmin, ymax, ymin);
5257
plot->setAxesTitles("X Axis", "Y Axis");

src/api/c/plot3.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ fg::Plot3* setup_plot3(const af_array P, fg::PlotType ptype, fg::MarkerType mtyp
4646
P_dims = pIn.dims();
4747
}
4848

49-
T max[3], min[3];
50-
if(P_dims[0] == 3) {
51-
af_get_data_ptr(max, getHandle(reduce<af_max_t, T, T>(pIn, 1)));
52-
af_get_data_ptr(min, getHandle(reduce<af_min_t, T, T>(pIn, 1)));
49+
if(P_dims[1] == 3){
50+
pIn = transpose(pIn, false);
5351
}
5452

55-
if(P_dims[1] == 3) {
56-
af_get_data_ptr(max, getHandle(reduce<af_max_t, T, T>(pIn, 0)));
57-
af_get_data_ptr(min, getHandle(reduce<af_min_t, T, T>(pIn, 0)));
58-
}
53+
T max[3], min[3];
54+
copyData(max, reduce<af_max_t, T, T>(pIn, 1));
55+
copyData(min, reduce<af_min_t, T, T>(pIn, 1));
5956

6057
ForgeManager& fgMngr = ForgeManager::getInstance();
6158
fg::Plot3* plot3 = fgMngr.getPlot3(P_dims.elements()/3, getGLType<T>(), ptype, mtype);
@@ -64,12 +61,7 @@ fg::Plot3* setup_plot3(const af_array P, fg::PlotType ptype, fg::MarkerType mtyp
6461
max[1], min[1],
6562
max[2], min[2]);
6663
plot3->setAxesTitles("X Axis", "Y Axis", "Z Axis");
67-
68-
if(P_dims[1] == 3){
69-
pIn = transpose(pIn, false);
70-
}
7164
copy_plot3<T>(pIn, plot3);
72-
7365
return plot3;
7466
}
7567

src/api/c/surface.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,29 @@ fg::Surface* setup_surface(const af_array xVals, const af_array yVals, const af_
4949
af::dim4 Y_dims = Yinfo.dims();
5050
af::dim4 Z_dims = Zinfo.dims();
5151

52-
dim4 rdims(1, 0, 2, 3);
53-
dim4 x_tdims(1, Y_dims[0], 1, 1);
54-
dim4 y_tdims(1, X_dims[0], 1, 1);
5552
if(Xinfo.isVector()){
53+
// Convert xIn is a column vector
54+
xIn.modDims(xIn.elements());
55+
// Now tile along second dimension
56+
dim4 x_tdims(1, Y_dims[0], 1, 1);
5657
xIn = tile(xIn, x_tdims);
58+
59+
// Convert yIn to a row vector
60+
yIn.modDims(af::dim4(1, yIn.elements()));
61+
// Now tile along first dimension
62+
dim4 y_tdims(X_dims[0], 1, 1, 1);
5763
yIn = tile(yIn, y_tdims);
58-
yIn = reorder(yIn, rdims);
5964
}
6065

61-
xIn.modDims(xIn.elements());
62-
yIn.modDims(yIn.elements());
63-
zIn.modDims(zIn.elements());
64-
Array<T> Z = join(1, join(1, xIn, yIn), zIn);
65-
Z = reorder(Z, rdims);
66-
Z.modDims(Z.elements());
66+
// Flatten xIn, yIn and zIn into row vectors
67+
dim4 rowDims = dim4(1, zIn.elements());
68+
xIn.modDims(rowDims);
69+
yIn.modDims(rowDims);
70+
zIn.modDims(rowDims);
71+
72+
// Now join along first dimension, skip reorder
73+
std::vector<Array<T> > inputs{xIn, yIn, zIn};
74+
Array<T> Z = join(0, inputs);
6775

6876
ForgeManager& fgMngr = ForgeManager::getInstance();
6977
fg::Surface* surface = fgMngr.getSurface(Z_dims[0], Z_dims[1], getGLType<T>());

0 commit comments

Comments
 (0)