Example #1
0
constexpr
array<T, I1 + I2> append( array<T,I1> a1, indices<Is1...>
                        , array<T,I2> a2, indices<Is2...> )
{
    return array<T,I1+I2>( a1.data()[Is1]...
                         , a2.data()[Is2]... );
}
Example #2
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    const array<T,6> x = {{  -1, -555, 3, 0, 2, -555 }};
    const long incx = 2;
    const size_t N = x.size() / incx;

    BOOST_CHECK_EQUAL( 1, blas::iamax(N, x.data(), incx));
    BOOST_CHECK_EQUAL( 0, blas::iamin(N, x.data(), incx));

    BOOST_CHECK_EQUAL(-1, blas::iamax(0, x.data(), incx));
    BOOST_CHECK_EQUAL(-1, blas::iamin(0, x.data(), incx));
}
Example #3
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    const array<T,6> x = {{ 1, -1, 2, -1, 3, -1 }};
    const int incx = 2;
    const array<T,3> y = {{ 4, 5, 6 }};
    const long incy = 1;

    BOOST_REQUIRE_EQUAL(x.size()/incx, y.size()/incy);
    const T result = blas::dot(x.size()/incx, x.data(), incx, y.data(), incy);

    const T expected = (1*4) + (2*5) + (3*6);
    BOOST_CHECK_EQUAL(result, expected);
}
int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        char* app_name = strrchr(argv[0], '/');
        app_name = app_name ? app_name + 1 : argv[0];
        if(0 == strncmp(app_name, "lt-", 3))
            app_name += 3; // remove libtool prefix
        usage(cerr, app_name);
        return EXIT_FAILURE;
    }

    try
    {
        // Example:
        // "Driver={ODBC Driver 11 for SQL Server};Server=xxx.sqlserver.net;Database=mydb;UID=joe;PWD=secret;"
        auto const connection_string(convert(argv[1]));
        connection conn(connection_string);

        // Create table
        {
            try
            {
                // XXX: SQL Server <=2014 does not support "if exists"
                execute(conn, NANODBC_TEXT("drop table rowset_iteration;"));
            } catch (runtime_error const&) {}

            execute(conn, NANODBC_TEXT("create table rowset_iteration (i int);"));
        }

        // Insert data
        {
            statement stmt(conn);
            prepare(stmt, NANODBC_TEXT("insert into rowset_iteration (i) values (?);"));
            array<int, 5> const numbers {{ 100, 80, 60, 40, 20 }};
            stmt.bind(0, numbers.data(), numbers.size());
            transact(stmt, static_cast<long>(numbers.size()));
        }

        // Select and fetch
        long batch_size = 1; // tweak to play with number of ODBC fetch calls
        result result = execute(
            conn
            , NANODBC_TEXT("SELECT i FROM rowset_iteration ORDER BY i DESC;")
            , batch_size);
        for (int i = 1; result.next(); ++i)
        {
            cout << i
                << "(" << result.rows()
                << "/" << result.rowset_size()
                << ":"
                << result.get<int>(0)
                << endl;
        }
    }
    catch (runtime_error const& e)
    {
        cerr << e.what() << endl;
    }
}
Example #5
0
void initRemap(const array<double, 6> & params1, const array<double, 3> & params2,
    Mat32f & mapX, Mat32f & mapY, const array<double, 3> & rot)
{
    EnhancedCamera cam1(params1.data());
    Pinhole cam2(params2[0], params2[1], params2[2]);
    Vector2dVec imagePoints;
    mapX.create(params2[1]*2, params2[0]*2);
    mapY.create(params2[1]*2, params2[0]*2);
    for (unsigned int i = 0; i < mapX.rows; i++)
    {
        for (unsigned int j = 0; j < mapX.cols; j++)
        {
            imagePoints.push_back(Vector2d(j, i));
        }
    }
    Vector3dVec pointCloud;
    cam2.reconstructPointCloud(imagePoints, pointCloud);
    Transformation<double> T(0, 0, 0, rot[0], rot[1], rot[2]);
    T.transform(pointCloud, pointCloud);
    cam1.projectPointCloud(pointCloud, imagePoints);
    
    auto pointIter = imagePoints.begin();
    for (unsigned int i = 0; i < mapX.rows; i++)
    {
        for (unsigned int j = 0; j < mapX.cols; j++)
        {
            mapX(i, j) = (*pointIter)[0];
            mapY(i, j) = (*pointIter)[1];
            ++pointIter;
        }
    }
}
Example #6
0
constexpr
array<T, I + 1> push_back( array<T, I> arr
                         , T t
                         , indices<Is...>)
{
    return array<T, I + 1>(arr.data()[Is]..., t);
}
Example #7
0
File: test.cpp Project: 8l/kalmar
bool test_feature()
{
    int edata[_rank];
    for (int i = 0; i < _rank; i++)
        edata[i] = i+1;
    extent<_rank> e1(edata);

    std::vector<_type> data(e1.size());
    for (unsigned int i = 0; i < e1.size(); i++)
        data[i] = static_cast<_type>(i+1);

    accelerator device(accelerator::cpu_accelerator);

    {
        array<_type, _rank> src(e1, data.begin(), data.end(), device.get_default_view());

        _type* dst_data = src.data();

        if (dst_data == NULL)
            return false;

        for(unsigned int i = 0; i < src.get_extent().size(); i++)
        {
            if (dst_data[i] != data[i])
                return false;
        }
    }

    {
        array<_type, _rank> src(e1, data.begin(), data.end(), device.get_default_view());

        const _type* dst_data = src.data();

        if (dst_data == NULL)
            return false;

        for(unsigned int i = 0; i < src.get_extent().size(); i++)
        {
            if (dst_data[i] != data[i])
                return false;
        }
    }

    {
        const array<_type, _rank> src(e1, data.begin(), data.end(), device.get_default_view());
        
        const _type* dst_data = src.data();

        if (dst_data == NULL)
            return false;

        for(unsigned int i = 0; i < src.get_extent().size(); i++)
        {
            if (dst_data[i] != data[i])
                return false;
        }
    }

    return true;
}
Example #8
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    const array<T,6> x = {{ -1, -555, 2, -555, -3, -555 }};
    const long inc = 2;
    const T result = blas::asum(x.size()/inc, x.data(), inc);

    const T expected = 1 + 2 + 3;
    BOOST_CHECK_EQUAL(result, expected);
}
Example #9
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    const array<T,6> x = {{   1, -555,   2, -555,   3, -555 }};
    array<T,3> y       = {{ 555,  555, 555 }};
    const long incx = 2, incy = 1;

    BOOST_REQUIRE_EQUAL(x.size()/incx, y.size()/incy);
    blas::copy(x.size()/incx, x.data(), incx, y.c_array(), incy);

    const array<T,3> expected = {{ 1, 2, 3 }};
    BOOST_CHECK_EQUAL_COLLECTIONS(
            y.begin(), y.end(), expected.begin(), expected.end());
}
Example #10
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    const array<T,6> x = {{ 1, -1, 2, -1, 3, -1 }};
    const long incx = 2;
    array<T,3> y = {{ 4, 5, 6 }};
    const int incy = 1;

    BOOST_REQUIRE_EQUAL(x.size()/incx, y.size()/incy);
    blas::axpby(x.size()/incx, 3, x.data(), incx, 7, y.c_array(), incy);

    const array<T,3> expected = {{ 1*3+7*4, 2*3+7*5, 3*3+7*6 }};
    BOOST_CHECK_EQUAL_COLLECTIONS(
            y.begin(), y.end(), expected.begin(), expected.end());
}
Example #11
0
void XCBBackend::initializeRoot() {
  using std::array;
  using std::stringstream;

  static array<uint32_t, 1> values{{XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
                                    XCB_EVENT_MASK_STRUCTURE_NOTIFY |
                                    XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY}};
  auto mask = XCB_CW_EVENT_MASK;

  cookie = xcb_change_window_attributes_checked(
      connection, screen->root, mask, values.data());

  auto error = xcb_request_check(connection, cookie);

  xcb_flush(connection);

  if(NULL != error) {
    stringstream ss;
    ss << "Can't redirect root window: " << error->error_code << ". Another Window Manager Running?";
    throwAndLogError(ss.str());
  }
}
Example #12
0
   for( int i = 1; i < DIM + 1; ++i )
      res += coeffs[i] * std::pow( x, i );

   return res;
}

TEST_CASE( "Horner scheme evaluates correctly", "[spline]" )
{
   array<double, 5> coeffs = {1, 2, 3, 4, 5};
   array<double, 4> dcoeffs =  {coeffs[1], 2 * coeffs[2], 3 * coeffs[3], 4 * coeffs[4]};
   array<double, 3> d2coeffs =  {dcoeffs[1], 2 * dcoeffs[2], 3 * dcoeffs[3]};
   double x = M_PI;
   SECTION( "evaluation works for polynomial itself" )
   {
      double value = spline::evaluatePolynomial<4>( coeffs.data(), x );
      double reference = polynomial_evaluation_reference<4>( coeffs, x );
      REQUIRE( value == Approx( reference ) );
   }

   SECTION( "evaluation works for first derivative" )
   {
      double value = spline::evaluatePolynomial<4, 1>( coeffs.data(), x );
      double reference = polynomial_evaluation_reference<3>( dcoeffs, x );

      REQUIRE( value == Approx( reference ) );
   }

   SECTION( "evaluation works for second derivative" )
   {
      double value = spline::evaluatePolynomial<4, 2>( coeffs.data(), x );
Example #13
0
void Sec256Signature::AssignCompact(const array<uint8_t, 64>& ar) {
	int over1, over2;
	secp256k1_scalar_set_b32(&m_r, ar.data(), &over1);
	secp256k1_scalar_set_b32(&m_s, ar.data()+32, &over2);
	ASSERT(!over1 && !over2);
}
Example #14
0
 void sort(array<float>& a)
 {
   //      komrade::stable_sort(a.data(), a.data()+a.linear_size(), 
   //			   komrade::random_access_device_iterator_tag());
   komrade::sorting::detail::device::cuda::stable_radix_sort_key_dev<float>(a.data(), a.linear_size());
 }
Example #15
0
    cout << i << " ";           // 0 0 0
});
cr;

END_TEST;




//----------------------- array as c-style array ----------------------
BEGIN_TEST(ArrayTest, CStyleArray, @);

// use array<char> as a fix sized c-string.
array<char, 100> str = {{ 0 }};

char *p = str.data();

strcpy(p, "hello world");
printf("%s\n", p);              // hello world


END_TEST;




//----------------------- normal example ----------------------
BEGIN_TEST(ArrayTest, NormalExample, @);

array<int, 5> a = {{ 1, 2, 3 }};
psln(a.size());                     // a.size() = 5;
Example #16
0
 data_type(const array &index) : data_type(index.get_dim_size(), reinterpret_cast<int *>(index.data())) {}
Example #17
0
 static void write_impl(OStream & ost, array<typename OStream::char_type, N> const & s) {
     ost.write(s.data(), N);
 }