PrevUpHomeNext

dlib::matrix - dlib Utxcpp


dlib::matrix

dlib::matrix<utx::fx32, 4, 3> M1; // 4x3: 4 rows, 3 columns
dlib::matrix<utx::fx32> M2;
M2.set_size(3, 1); // 3x1
dlib::matrix<utx::fx32> M3 = M1*M2;

auto can not get the matrix computing result type.

utx::fx32, utx::fx64, ..., can be used as dlib::matrix element type.

dlib::matrix<utx::fx32> M3 = M1*M2;
dlib::matrix<utx::fx32, 0, 1> a;
a.set_size(7); // 7x1 now

dlib::matrix<utx::fx32, 1, 0> b;
b.set_size(7); // 1x7 now

dlib::matrix can be printed by std::cout and utx::print

utx::print(a_dlib_matrix);
std::cout << dlib::csv << a_dlib_matrix;
utx::fx32 a = a_matrix(2,3); // If a_matrix is not single row or single column
utx::fx32 b = b_matrix(4); // If b_matrix is single row or single column

(dlib::matrix) (utx::print) (utx::fx32) (utx::fx64)

c++ example

[Note] Note

Copyright (c) 2023 Fas Xmut (fasxmut at protonmail dot com)

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <dlib/matrix.h>
#include <utxcpp/core.hpp>

int main()
{
	dlib::matrix<utx::fx32, 3, 3> M1; // 4x3: a row 4, colum 3 matrix, compile-time sized.
	M1 =
		1,2,3,
		4,5,6,
		7,8,9
	;

	dlib::matrix<utx::fx32> x1(3, 1); // 3x1: a row 3, colum 1 matrix, runtime sized.
	x1 =
		2,
		1,
		3
	;

	dlib::matrix<utx::fx32> x2 = M1 * x1;

	utx::print(M1, '\n', x1, '\n', x2); // print matrix

	dlib::matrix<utx::fx32, 0, 1> x3;
	x3.set_size(3); // 3x1 now

	dlib::matrix<utx::fx32, 1, 0> x4;
	x4.set_size(3); // 1x3 now

	dlib::matrix<utx::fx32> M2;
	M2.set_size(2, 2); // 2x2
	utx::print("M2=>\n", M2);

	utx::print(M1(2,1), x1(2)); // 8 3

	std::cout << "csv format:\n" << dlib::csv << M1 << "\n";
}

PrevUpHomeNext