ublasのouter_prodの計算式
boostのublasにはouter_prodというベクトルとベクトルの転置の積を計算する関数が存在する。 どちらのベクトルが転置されているかちゃんと書いたものがなかったのでメモ。 直積の演算としては直感通りの式。 $$ x = \left( \begin{array}{c} x_{1} \\ x_{2} \\ \end{array} \right), y = \left( \begin{array}{c} y_{1} \\ y_{2} \\ \end{array} \right) $$ $$ \mathrm{outer\_prod}(x, y) = xy^{T} = \left( \begin{array}{cc} x_{1}y_{1} & x_{1}y_{2} \\ x_{2}y_{1} & x_{2}y_{2} \\ \end{array} \right) $$
#include <boost/numeric/ublas/vector.hpp> #include <boost/numeric/ublas/matrix.hpp> namespace ublas = boost::numeric::ublas; int main(int argc, char const* argv[]) { ublas::vector<double> x(2); x(0) = 1.0; x(1) = 2.0; ublas::vector<double> y(2); y(0) = 3.0; y(1) = 4.0; ublas::matrix<double> A = ublas::outer_prod(x, y); std::cout << A(0, 0) << ", " << A(0, 1) << std::endl;//3, 4 std::cout << A(1, 0) << ", " << A(1, 1) << std::endl;//6, 8 return 0; }
数式が使える最強のプレゼンテーション環境
うれしい
使うもの
サンプル
導入手順
- ローカルに適当にディレクトリ(
slides
とする)を作る。 slides
ディレクトリにindex.html
を作り、同じディレクトリにcontents.md
を配置する。index.html
をブラウザで開けばOKスライドが見れる。index.html
<DOCTYPE html> <html> <head><title>Presentation</title></head> <body> <script src="https://remarkjs.com/downloads/remark-latest.min.js" type="text/javascript"></script> <script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML&delayStartupUntil=configured" type="text/javascript"></script> </script> <script type="text/javascript"> var slideshow = remark.create({ sourceUrl: "contents.md" }); // Setup MathJax MathJax.Hub.Config({ tex2jax: { skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'] } }); MathJax.Hub.Queue(function() { $(MathJax.Hub.getAllJax()).map(function(index, elem) { return(elem.SourceElement()); }).parent().addClass('has-jax'); }); MathJax.Hub.Configured(); </script> </body> </html>
contents.md
# slide 1 - 1ページ目 --- # slide 2 - 2ページ目 $$ x = a_{1} + b^{2} $$ ## フーリエ変換 $$ F(u) = \int\_{-\infty}^{\infty} f(x)\mathrm{e}^{-j2\pi ux}dx $$ ## 2次元のフーリエ変換 $$ F(u,v) = \int\_{-\infty}^{\infty} \int\_{-\infty}^{\infty} f(x,y)\mathrm{e}^{-j2\pi (ux + vy )}dxdy $$
ここまでで、ローカルでスライドが見れる環境ができる。 次は、github pagesを作って、github上でスライドが見れるようにする。
4. slides
上でgitレポジトリを作り、全部コミット。
git init git add . git commit -m 'Initial commit.'
5. githubにレポジトリを作り、slides
のレポジトリをpushする。
git remote add https://github.com/username/repository_namae/ git push origin master
6. gh-pagesを使う為、gh-pages
ブランチを作って、githubにpushする。
git checkout -b gh-pages git push origin gh-pages
7. https://username.github.io/repository_name
にアクセスするとレポジトリトップのindex.html
のファイルが表示される。
- uploadしたデータが反映されるまで10分ほどかかるみたいなので気長にまつ。
username
はgithubのユーザ名reposiotry_name
はレポジトリの名前
キー操作
j
次のスライドk
前のスライドc
スライドのclone- スライドを clone すると、元のスライドでページ移動した際、clone 先のスライドも同期して移動する。
f
フルスクリーンp
プレゼンモードh
ヘルプの表示
補足
contents.md
では、普通にmarkdown中にmathjaxを書けばOK。 具体的には、$$
で数式を囲む。- mathjaxのURLに
delayStartupUntil=configured
オプションを含めると、markdownで問題になる_
のエスケープなどが不要になるので便利。
個人的には、スライドごとにレポジトリを作る気分にあんまりならないので、下記のように1つのレポジトリをまとめている。
特に工夫はないが、レポジトリのトップのcontents.md
はレポジトリ内のスライドへのリンクテーブルになっている個人的に便利。
# link * [directory_name](http://user_name.github.io/repository_name/directory_name/) * sample
3. レポジトリにスライドごとにディレクトリを作り、各ディレクトリにindex.html
とcontents.md
を作る。
参考
NeoBundleCleanが使えない
NeoBundleCleanはdangerousなので削除したとのこと。
How to Uninstall Packages? · Issue #356 · Shougo/neobundle.vim · GitHub
プラグインを読み込まないようにしたい場合は、NeoBundle hoge/fuga.vim
の記述を消せば読み込まれないとのこと。
プラグインを削除したい場合は、
call neobundle#begin(expand('~/.vim/bundle/'))
で指定しているディレクトリからpluginのディレクトリを手動で削除する。
C++で配列の型のtypedef
配列のtypedefをするときは次のようにする。
//int[2]のtypedef typedef int type[2];
windowsでgithubのrepositoryにpushするときにエラーがでる場合の対応
使用しているgitは以下。
$ git version git version 2.6.3.windows.1
次のコマンドを実行すると、
git remote add origin https://hogehoge.gihttps://github.com/user_id/hogehoge.git git push origin master
下記のエラーがでる。
!!!bash: /dev/tty: No such device or address!!! !!!error: failed to execute prompt script (exit code 1)!!! !!!fatal: could not read Username for 'https://github.com': Invalid argument!!! !!!vimshell: exit 128 "git push origin master"!
上記はvimshellでのエラーだが、cmdから直接実行しても同様のエラーがでる。
対処法?
1. 以下の方法によるが、試してない。 [Windows] bash: /dev/tty: No such a device or address · Issue #8984 · atom/atom · GitHub
以下のURLをremote repositoryのURLとして設定する。
https://<username>:<password>@github.com/<username>/<repo_name>.git
たとえば、次の場合、 * username:hoge * password:fuga * repo_name:hage
git remote add origin https://hoge:fuga@github.com/hage/hage.git
2. こちらは、cmd上で動作は確認。vimshell上では未確認。
https://hoge@github.com/hage/hage.git
とするとパスワードが求められるので、入力する。
cppunitのテンプレ
cppunitでテストコードを書くときのテンプレ。
まずは、main.cpp
。これはまるこぴでおっけ。
#include <cppunit/BriefTestProgressListener.h> #include <cppunit/CompilerOutputter.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/TestResult.h> #include <cppunit/TestResultCollector.h> #include <cppunit/TestRunner.h> int main(int argc, char* argv[]) { // Create the event manager and test controller CPPUNIT_NS::TestResult controller; // Add a listener that colllects test result CPPUNIT_NS::TestResultCollector result; controller.addListener(&result); // Add a listener that print dots as test run. CPPUNIT_NS::BriefTestProgressListener progress; controller.addListener(&progress); // Add the top suite to the test runner CPPUNIT_NS::TestRunner runner; runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest()); runner.run(controller); // Print test in a compiler compatible format. CPPUNIT_NS::CompilerOutputter outputter(&result, CPPUNIT_NS::stdCOut()); outputter.write(); { int a = 0; std::cin >> a; } return result.wasSuccessful() ? 0 : 1; }
テスト対象のクラスがNormalRandomGenerator
とする。
テスト用のクラスとしてNormalRandomGeneratorTest.h
及びNormalRandomGeneratorTest.cpp
を用意する。
テストクラスのsetUp
及びtearDown
メソッドは各テストメソッド(ここではtestOperatorParenthesis
)を実行する前と後に実行されるメソッド。
NormalRandomGeneratorTest.h
#pragma once //include test target hearder. #include "cva/random/NormalRandomGenerator.h" #include <cppunit/extensions/HelperMacros.h> #include <cppunit/TestFixture.h> namespace cva_test { class NormalRandomGeneratorTest : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE(NormalRandomGeneratorTest); //class name CPPUNIT_TEST(testOperatorParenthesis); //nane of test CPPUNIT_TEST_SUITE_END(); private: void testOperatorParenthesis(); //test metdho declaration NormalRandomGenerator *_generator; }; }
NormalRandomGeneratorTest.cpp
#include "NormalRandomGeneratorTest.h" namespace cva_test { CPPUNIT_TEST_SUITE_REGISTRATION(NormalRandomGeneratorTest); void NormalRandomGeneratorTest::setUp() { _generator = new NormalRandomGenerator(); } void NormalRandomGeneratorTest::tearDown() { delete _generator; } void NormalRandomGeneratorTest::testOperatorParenthesis() { //test here } }