jacobian_t estimateJacobian(input_t const & x0) { // evaluate the function at the operating point: value_t fx0 = functor(x0); size_t N = x0.size(); size_t M = fx0.size(); //std::cout << "Size: " << M << ", " << N << std::endl; jacobian_t J; J.resize(M, N); SM_ASSERT_EQ(std::runtime_error,x0.size(),J.cols(),"Unexpected number of columns for input size"); SM_ASSERT_EQ(std::runtime_error,fx0.size(),J.rows(),"Unexpected number of columns for output size"); for(unsigned c = 0; c < N; c++) { // Calculate a central difference. // This step size was stolen from cminpack: temp = eps * fabs(x[j]); scalar_t rcEps = std::max(static_cast<scalar_t>(fabs(x0(c))) * eps,eps); value_t fxp = functor(functor.update(x0,c,rcEps)); value_t fxm = functor(functor.update(x0,c,-rcEps)); J.block(0, c, M, 1) = (fxp - fxm).template cast<typename jacobian_t::Scalar>()/(typename jacobian_t::Scalar)(rcEps*(scalar_t)2.0); } return J; }
compressed_data compress (const input_t& in) { size_t byte_size (in.size() * sizeof(typename input_t::value_type)); if (byte_size > 0xffff) throw std::runtime_error("too much data for compression"); auto in_ptr (reinterpret_cast<const char*>(&*in.begin())); compressed_data out; if (byte_size > 0) { out.resize(byte_size + 16); std::fill(out.begin(), out.end(), 0); out.unpacked_len = byte_size; int compressed_length (LZ4_compress(in_ptr, out.ptr(), byte_size)); if (compressed_length <= 0) throw std::runtime_error("lz4 compression failed"); out.resize(compressed_length); } return out; }
int main() { kb_init(&keyboard); stb_fake_model_init(&model); gl_view_init(&view); ctrl_init(&ctrl); ctrl_set_view(&view); ctrl_set_model(&model); kb_set_callback(ctrl.handler); view.start(); ctrl.start(); keyboard.start(); model.deinit(); puts("finish"); }