lindahua / light-matrix Goto Github PK
View Code? Open in Web Editor NEWA Light-weight and Fast Template Matrix Library
License: BSD 2-Clause "Simplified" License
A Light-weight and Fast Template Matrix Library
License: BSD 2-Clause "Simplified" License
Reference: http://www.johndcook.com/math_h.html
light-matrix/light_mat/matrix/matrix_layout.h
Line 393 in 8ce65d1
dep/light-matrix/light_mat/matrix/matrix_layout.h: In member function ‘bool lmat::grid_layout<M, N>::is_percol_contiguous() const’:
dep/light-matrix/light_mat/matrix/matrix_layout.h:393:23: error: expression cannot be used as a function
return m_rowstride() == 1;
The above line causes a compilation error, due to the trailing brackets. Removing them gets rid of the error.
The overall goal is to clarify the modules
Utilizing the begin and end iterators, a set of algorithms can be introduced
The syntax should be like
B = cast(A, type_<T>());
Here,
Convenient functions
to_f32(A);
to_f64(A);
to_bool(A);
...
Argument wrapper allows some intermediate expression to be embedded into new expression.
This enables expression creation/transformation functions.
Introduce a set of random matrix expressions
template<class Engine, class Distribution> class random_expr;
Distr distr;
rand_mat( m, n, distr, eng ); // ==> random_expr<Eng, Distr>
rand_mat( shape, distr, eng );
randu<T> ( m, n, eng ); // ==> random_expr<Eng, uniform_real_distribution<T> >
randu<T> ( shape, eng );
randn<T> ( m, n, deg ); // ==> random_expr<Eng, normal_distribution<T> >
randn<T> ( shape, eng );
Notes:
random_expr
should implement IEWiseMatrix
Generalized the IRange concept:
rgn.num(); // --> the number of indices (const)
rgn[i]; // --> the i-th index (const)
range_traits<R>::compile_time_num;
An IMatrixView Class:
class reindexed_matrix<T, RI, RJ>;
ct_rows == range_traits<RI>::compile_time_num;
ct_cols == range_traits<RJ>::compile_time_num;
C(rg0, rg1) returns an instance of reindexed_matrix, except when rg0 and rg1 are some special range.
(no need to optimize at this point)
I think it would be good to allow building with -fno-exceptions, for better or worse this often is a requirement in practice. Would it be possible to make exception support optional?
implement and add this function to math_base.h
It is useful for various machine learning models, notably Latent Dirichlet Allocation.
as_col(A) // map the entire matrix as a column view
as_row(A) // map the entire matrix as a row view
appliable to all IDenseMatrix classes
Syntax:
R = cond(Z > 0, X, Y);
R = cond(X > a, a, X); // in MATLAB: X(X > a) = a;
full and partial reduction with the following functions
all(A, true);
all(A, false);
all(A); // equivalent to all(A, true);
any(A, true);
any(A, false);
any(A); // equivalent to any(A, true);
colwise_any(A, r, tf);
colwise_all(A, r, tf);
Example:
g = _x * _x + exp(_x - _y)
g( 1 ) --> yields a scalar
g( arr ) --> yields an array
Devices to inspect the structure of an expression
The implementation should be non-instrusive, relying on external template class with specializations.
// some declarations
template<class Expr>
class matexpr_typeinfo;
template<typename T, class Expr>
matexpr_typeinfo<Expr> get_matexpr_type(const IMatrixXpr<Expr, T>& )
{
return matexpr_typeinfo<Expr>();
}
// some usage: let a be an matrix expression instance
// return a type name (e.g. "unary_expr", "dense", etc) as std::string
get_matexpr_type( a ).name();
// return a short string (e.g. "add(dense, sqr(dense))") as std::string
get_matexpr_type( a ).short_repr();
Introduce a new module: random
Introduce a random stream concept
class IRandStream;
// a model based on std::random
template<class Engine> class std_randstream;
// a model based on SFMT
template<typename Kind> class sfmt_randstream;
// suppose s is an instance of IRandStream
s.rand_i32();
s.rand_u32();
s.rand_pack( simd_kind );
s.rand_seq( nbytes, buf );
Supports the following syntax
find_to(X > 0, it); // it is an output iterator
find_to(X > 0, v); // v is an instance of std::vector<index_t>
find_to(X > 0, I, J); // I and J are both instances of index_seq
idx = find( x > 0 ); // returns an instance of class dense_col<index_t>
Y = select( A, idx ); // idx is any random access container
Y = select( A, find(x > 0), colon(2, 3) );
Introduce begin and end to IRegularMatrix
a.begin()
a.end()
a.col_begin(j)
a.col_end(j)
begin(a); // equivalent to a.begin()
end(a); // equivalent to a.end()
Have both const and non-const versions
Syntax should be like:
f = poly(1, 2, 3) // f( x ) = x^2 + 2 * x + 3
f ( 1 ) --> produce a scalar
f ( arr ) --> produce an array through element-wise operation
matrix comparison functions, which can be implemented using the all
function.
is_equal(A, B); // equivalent to all(A == B);
is_approx(A, B, tol); // equivalent to all( abs(A - B) < tol );
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.