FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Corrected field example (#3369) by willyborn · Pull Request #3375 · arrayfire/arrayfire · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 11 additions & 2 deletions examples/graphics/field.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int main(int, char**) {
af::info();
af::Window myWindow(1024, 1024, "2D Vector Field example: ArrayFire");

myWindow.grid(1, 2);
myWindow.grid(2, 2);

array dataRange = seq(MINIMUM, MAXIMUM, STEP);

Expand All @@ -38,12 +38,21 @@ int main(int, char**) {
array saddle = join(1, flat(x), -1.0f * flat(y));

array bvals = sin(scale * (x * x + y * y));
array hbowl = join(1, constant(1, x.elements()), flat(bvals));
array hbowl = join(1, constant(1., x.elements()), flat(bvals));
hbowl.eval();

// 2D points
myWindow(0, 0).vectorField(points, saddle, "Saddle point");
myWindow(0, 1).vectorField(
points, hbowl, "hilly bowl (in a loop with varying amplitude)");

// 2D coordinates
myWindow(1, 0).vectorField(2.0 * flat(x), flat(y), flat(x),
Comment thread
christophe-murphy marked this conversation as resolved.
-flat(y), "Saddle point");
myWindow(1, 1).vectorField(
2.0 * flat(x), flat(y), constant(1., x.elements()), flat(bvals),
"hilly bowl (in a loop with varying amplitude)");

myWindow.show();

scale -= 0.0010f;
Expand Down
27 changes: 14 additions & 13 deletions src/api/c/vector_field.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,21 @@ fg_chart setup_vector_field(fg_window window, const vector<af_array>& points,
vector<Array<T>> pnts;
vector<Array<T>> dirs;

for (unsigned i = 0; i < points.size(); ++i) {
pnts.push_back(getArray<T>(points[i]));
dirs.push_back(getArray<T>(directions[i]));
}

// Join for set up vector
dim4 odims(3, points.size());
Array<T> out_pnts = createEmptyArray<T>(odims);
Array<T> out_dirs = createEmptyArray<T>(odims);
detail::join(out_pnts, 1, pnts);
detail::join(out_dirs, 1, dirs);
Comment thread
christophe-murphy marked this conversation as resolved.
Array<T> pIn = out_pnts;
Array<T> dIn = out_dirs;
Array<T> pIn = getArray<T>(points[0]);
Array<T> dIn = getArray<T>(directions[0]);
if (points.size() > 1) {
for (unsigned i = 0; i < points.size(); ++i) {
pnts.push_back(getArray<T>(points[i]));
dirs.push_back(getArray<T>(directions[i]));
}

// Join for set up vector
const dim4 odims(pIn.dims()[0], points.size());
pIn = createEmptyArray<T>(odims);
dIn = createEmptyArray<T>(odims);
detail::join<T>(pIn, 1, pnts);
detail::join<T>(dIn, 1, dirs);
}
// do transpose if required
if (transpose_) {
pIn = transpose<T>(pIn, false);
Expand Down

Back | FazBrowse Home | New Git URL