[ Date Prev][ Date Next][ Thread Prev][ Thread Next][ Date Index][ Thread Index]
[patch] External data access example
- To: VSIPL++ Developers List <vsipl++@xxxxxxxxxxxxxxxx>
- Subject: [patch] External data access example
- From: Don McCoy <don@xxxxxxxxxxxxxxxx>
- Date: Mon, 23 Jul 2007 13:15:50 -0600
This patch adds an example where the values of a VSIPL++ Matrix are
altered using a direct pointer to the underlying data. This is useful
for performing operations on data outside the VSIPL++ library.
Regards,
--
Don McCoy
don (at) CodeSourcery
(888) 776-0262 / (650) 331-3385, x712
2007-06-26 Don McCoy <don@xxxxxxxxxxxxxxxx>
* examples/extdata.cpp: New file. Example demonstrating the
use of the Ext_data interface to access a view's underlying
data via a pointer.
Index: examples/extdata.cpp
===================================================================
--- examples/extdata.cpp (revision 0)
+++ examples/extdata.cpp (revision 0)
@@ -0,0 +1,48 @@
+/* Copyright (c) 2007 by CodeSourcery. All rights reserved.
+*/
+/** @file examples/extdata.cpp
+ @author Don McCoy
+ @date 2007-07-23
+ @brief VSIPL++ Library: Simple example for external data access.
+*/
+
+#include <iostream>
+#include <vsip/initfin.hpp>
+#include <vsip/matrix.hpp>
+#include <vsip/opt/extdata.hpp>
+
+
+int
+main(int argc, char **argv)
+{
+ vsip::vsipl init(argc, argv);
+
+ const vsip::length_type M = 128;
+ const vsip::length_type N = 64;
+
+ typedef vsip::scalar_f T;
+ typedef vsip::Dense<2, T, vsip::row2_type> block_type;
+ typedef vsip::Matrix<T, block_type> view_type;
+
+ view_type grid(M, N, 1.234f);
+
+ std::cout << "first and last values (before): " << grid.get(0,0)
+ << ", " << grid.get(M-1,N-1) << std::endl;
+
+ // Control the scope of the Ext_data object. Synchronization is forced
+ // when the object is destroyed in accordance with the SYNC_OUT parameter.
+ {
+ vsip::impl::Ext_data<block_type> ext(grid.block(), vsip::impl::SYNC_OUT);
+
+ T* ptr = ext.data();
+ for (vsip::length_type i = 0; i < M; ++i)
+ for (vsip::length_type j = 0; j < N; ++j)
+ *(ptr + i*N + j) = i*N + j;
+ std::cout << "ptr = " << ptr << std::endl;
+ }
+
+ std::cout << "first and last values (after): " << grid.get(0,0)
+ << ", " << grid.get(M-1,N-1) << std::endl;
+
+ return 0;
+}
|