How ready is NT2

304 views
Skip to first unread message

Lin Dahua

unread,
Apr 19, 2012, 8:30:13 PM4/19/12
to nt2-dev
I am new to this forum, and it seems to me that it is the only place
for me to get information from NT2 developers.

I am currently looking into finding a good numerical library as our
basis for developing a generic C++ library for probabilistic modeling
and inference. I compared several libraries: MTL4, Armadillo, and
Eigen, and now NT2, and actually did some programs with Eigen.
However, I found that NT2's basic design seems to be much better than
Eigen (IMHO), in terms of consistency, extensibility, and the beauty
of syntax.(I haven't done extensive benchmark, so I don't know which
would have better run-time performance)

The main concern with NT2 is the lack of documentation. And it takes
great efforts to trace into the source codes to figure out stuff.
Fortunately, I have many years of experience working with MATLAB, and
NT2 seems to have a similar interface, so I can guess a lot of things
from my MATLAB knowledge.

I understand that NT2 is still under development, and not completely
ready for release. However, I still would like to try it and not wait
until it is ready ( I can work around with the lacking functionalities
by myself.)

Here are some questions:

1. Are basic interfaces for table ready and stable?
e.g. numel, ndims, size, …

What if I want to get the number of rows and columns, size(A, 1) and
size(A, 2) ? or there are more direct method like nrows(A) and
ncols(A) ?

2. Are arithmetic and basic linear operations ready ? (+, -, *, /)

Particularly, how to write element-wise multiplication and matrix
multiplication respectively? (C++ doesn't allow things like (.*).

Are there an element-wise square function?

3. Are element-wise elementary evaluation functions ready ? (exp, log,
sin, cos, etc)

4. Does it have something like bsxfun (broadcast evaluation)?
Particularly, I often have to do things like adding/multiplying a
vector to each row/column of a matrix.

5. How to write range indexing, like A(1:2:5, :) and A(:, 1:4) ? Even
further, does it support indexing with a supplied index vector, say
A(:, [1, 4, 6, 7, 9]);

6. Does it support logical indexing ? like A( A > 0 )?

7. Are the following linear algebraic operations ready ? matrix
product, LU, QR, Cholesky, SVD, and eigenvalue/eigenvectors
(particularly those for symmetric matrices), log-determinant, and
linear solver.

8. Does it use BLAS/LAPACK back-end (such that I can link with MKL)?
(if it is optional, is there a macro to enable it?)

I am really serious looking into using NT2, and hope this doesn't seem
to be too many questions. (Perhaps you may set up a simple wiki page
or something that roughly sketches the basic functionalities and
whether they are ready, which would be greatly helpful )

Finally, I am wondering when it is going to be released (several
weeks? months, or a year?) I understand this might be too early to
tell, but is there a rough estimation?

Thank you very much.

Joel Falcou

unread,
Apr 20, 2012, 1:23:36 AM4/20/12
to nt2...@googlegroups.com
On 04/20/2012 02:30 AM, Lin Dahua wrote:
> I am new to this forum, and it seems to me that it is the only place
> for me to get information from NT2 developers.
Thanks for your interest in our software :) And yes, you're at the
correct spot.
We're also hanging on IRC #nt2 if you ever come by.


> I am currently looking into finding a good numerical library as our
> basis for developing a generic C++ library for probabilistic modeling
> and inference. I compared several libraries: MTL4, Armadillo, and
> Eigen, and now NT2, and actually did some programs with Eigen.
> However, I found that NT2's basic design seems to be much better than
> Eigen (IMHO), in terms of consistency, extensibility, and the beauty
> of syntax.(I haven't done extensive benchmark, so I don't know which
> would have better run-time performance)

Well, depending on code, we should be comparable to Eigen. Now, we have
a larger support for modern architecture (namely AVX instruction set and
a larger application of multi-core acceleration) that may play in our favor.

> The main concern with NT2 is the lack of documentation. And it takes
> great efforts to trace into the source codes to figure out stuff.
> Fortunately, I have many years of experience working with MATLAB, and
> NT2 seems to have a similar interface, so I can guess a lot of things
> from my MATLAB knowledge.

The documentation is an active topic at the moment and will be completed
during
upcoming weeks. And yes, we aims at having a 1:1 mapping with matlab
interface
as long as C++ syntax allows us.

> I understand that NT2 is still under development, and not completely
> ready for release. However, I still would like to try it and not wait
> until it is ready ( I can work around with the lacking functionalities
> by myself.)

Sure

> 1. Are basic interfaces for table ready and stable?

> e.g. numel, ndims, size, �
Yes

> What if I want to get the number of rows and columns, size(A, 1) and
> size(A, 2) ? or there are more direct method like nrows(A) and
> ncols(A) ?

size(A,n) works and we provide some shortcut for height(a) and width(a)

> 2. Are arithmetic and basic linear operations ready ? (+, -, *, /)

Yes

> Particularly, how to write element-wise multiplication and matrix
> multiplication respectively? (C++ doesn't allow things like (.*).

Matrix multiplication is still to be fixed interface-wise but the
gist will be something like :

* between scalars is an elementwise operation
* between scalar and matrix is also elementwise
In other case, we use our internal type categorization to figure out if
mtimes or times should be applied.

More over, we mimics the non-operator name from matlab, so times and
mtimes will be available
if you really want to enforce one or the other.


> Are there an element-wise square function?

sqr(x) yes

>
> 3. Are element-wise elementary evaluation functions ready ? (exp, log,
> sin, cos, etc)

Yes, we support more than 200 mathematical functions (see the various
modules contents).
basically all libm, ieee related functions, basic arithmetic and some
more niche operations like
bessel functor and some special exponentiation functions.

In most case we're on par or slightly better than MKL in terms of
performances and we're always
better in term of precision. We have an extensive test suite over
precision of functions.

> 4. Does it have something like bsxfun (broadcast evaluation)?
> Particularly, I often have to do things like adding/multiplying a
> vector to each row/column of a matrix.

Not yet but it's on our roadmap. Interface for the function object is
still to be decided.

>
> 5. How to write range indexing, like A(1:2:5, :) and A(:, 1:4) ? Even
> further, does it support indexing with a supplied index vector, say
> A(:, [1, 4, 6, 7, 9]);

Simply put, whenever you use : in matlab, nt2 will require you to use _.
So :

A(1:2:5, :)


becomes

A(_(1,2,5), _ )

Indexing is supported for scalar, _ and simple 1D indexer. Some bugs are
being fixed
at the moment for supporting the other cases. What we miss now is a
proper syntax for
[ 1 2 3 .. ]. This one is still in discussion and well, opinions welcomed ;)

> 6. Does it support logical indexing ? like A( A> 0 )?

Planned but not done yet.

> 7. Are the following linear algebraic operations ready ? matrix
> product, LU, QR, Cholesky, SVD, and eigenvalue/eigenvectors
> (particularly those for symmetric matrices), log-determinant, and
> linear solver.

Not yet, the linear algebra module is in active development at the
moment. Once some general interface
issues are fixed, we'll starts integrating them during upcoming weeks.

> 8. Does it use BLAS/LAPACK back-end (such that I can link with MKL)?
> (if it is optional, is there a macro to enable it?)

Yes. The Cmake build script takes care of detecting which BLAS/LAPACK
flavor is available
and use it transparently. In case you want to specify one special
back-end, the cmake script
can be fed with the direct path to your back end of choices.

Except for exotic platforms like embedded systems, we'll rely on
external libraries for such
specialized kernels.


> I am really serious looking into using NT2, and hope this doesn't seem
> to be too many questions.

No problems :)

> (Perhaps you may set up a simple wiki page
> or something that roughly sketches the basic functionalities and
> whether they are ready, which would be greatly helpful )

Yes this is something we consider. We'll probably starts using the
Milestones
tracking on github too.

> Finally, I am wondering when it is going to be released (several
> weeks? months, or a year?) I understand this might be too early to
> tell, but is there a rough estimation?

We're aiming at having some Release candidate at the beginning of
this summer with a significant subset of functionalities and architectural
support.

Thanks again and feel free to ask us any questions :)

Mathias Gaunard

unread,
Apr 20, 2012, 2:52:45 AM4/20/12
to nt2...@googlegroups.com
On 20/04/12 07:23, Joel Falcou wrote:

>> 2. Are arithmetic and basic linear operations ready ? (+, -, *, /)
> Yes

Actually, element-wise operations yes, matrix multiplication and
division (* and /) not completely usable yet.


>> 5. How to write range indexing, like A(1:2:5, :) and A(:, 1:4) ? Even
>> further, does it support indexing with a supplied index vector, say
>> A(:, [1, 4, 6, 7, 9]);
>
> Simply put, whenever you use : in matlab, nt2 will require you to use _.
> So :
>
> A(1:2:5, :)
>
>
> becomes
>
> A(_(1,2,5), _ )
>
> Indexing is supported for scalar, _ and simple 1D indexer. Some bugs are
> being fixed
> at the moment for supporting the other cases. What we miss now is a
> proper syntax for
> [ 1 2 3 .. ]. This one is still in discussion and well, opinions
> welcomed ;)

Things like 1:2:5 (which is not contiguous) probably has a few problems
still.

The problems are due to us trying to vectorize everything whenever
possible (AVX2 can perform a gather operation here), which is tricky to
do with indexing.

Lin Dahua

unread,
Apr 20, 2012, 11:51:26 AM4/20/12
to nt2-dev
Thanks Joel and Mathlas for the answers.

I have some follow-up questions, and please look below.


On Apr 20, 1:23 am, Joel Falcou <joel.fal...@gmail.com> wrote:
> On 04/20/2012 02:30 AM, Lin Dahua wrote:> I am new to this forum, and it seems to me that it is the only place
> > for me to get information from NT2 developers.

>
> The documentation is an active topic at the moment and will be completed
> during upcoming weeks. And yes, we aims at having a 1:1 mapping with matlab
> interface as long as C++ syntax allows us.

Great! I will keep an eye on this.


>
> Yes, we support more than 200 mathematical functions (see the various
> modules contents).
> basically all libm, ieee related functions, basic arithmetic and some
> more niche operations like
> bessel functor and some special exponentiation functions.
>
> In most case we're on par or slightly better than MKL in terms of
> performances and we're always
> better in term of precision. We have an extensive test suite over
> precision of functions.


I believe this. Also, I think using VML of MKL has several problems,
which are deal-breakers for me:

(1) When we want to process a large number of short vectors (say
length < 20),
it seem to have huge overhead, and it shows benefit only when it is
invoked to
process a large sum of elements each time.

(2) It is eager evaluation, meaning that it scans the entire vector
for each single operation.
In my domain, I often have to chain a series of arithmetic/exp/log
computation, and this would be
a performance penalty. That's why I am looking at C++ libraries that
make use of
expression template techniques to reduce such overhead.

I am impressed by the full set of functions provided by NT2, which
is unparalleled among C++ numeric libraries.


> > 4. Does it have something like bsxfun (broadcast evaluation)?
> > Particularly, I often have to do things like adding/multiplying a
> > vector to each row/column of a matrix.
>
> Not yet but it's on our roadmap. Interface for the function object is
> still to be decided.
>

For temporary use, I can roll my own (using simple direct
calculation),
while waiting for the time it is provided by NT2.

Whereas I think the syntax bsxfun(@plus, a, b) (as in MATLAB) is
useful
in general, this way may need to decide how to process a and b at run-
time
(i.e. to tell which dimensions need to be broadcasted/expanded)

Something like colwise_apply(a, b) and rowwise_apply(a, b) may reduce
such
overhead.

(well ... I realize that for some objects (column/row vector), part of
their dimension
information might be available at compile-time (e.g. a column vector
has just one column),
which may be used for compile-time dispatch. )

Still, I think the special colwise / rowwise functions are useful
(syntax is more clear,
semantics is more explicit, and may reduce run-time overhead for
dynamic table)



>
> > 5. How to write range indexing, like A(1:2:5, :) and A(:, 1:4) ?  Even
> > further, does it support indexing with a supplied index vector, say
> > A(:, [1, 4, 6, 7, 9]);
>
> Simply put, whenever you use : in matlab, nt2 will require you to use _.
> So :
>
> A(1:2:5, :)
>
> becomes
>
> A(_(1,2,5), _ )
>
> Indexing is supported for scalar, _ and simple 1D indexer. Some bugs are
> being fixed
> at the moment for supporting the other cases. What we miss now is a
> proper syntax for
> [ 1 2 3 .. ]. This one is still in discussion and well, opinions welcomed ;)
>

Ideally, I wish it can support such syntax:

A(I, J)

Here, I and J are anything that supports random access iteration (e.g.
std::vector),
then I can build up I and J in my own way (using whatever random-
access container
I see fit in my context).



> > 6. Does it support logical indexing ? like A( A>  0 )?
>
> Planned but not done yet.


Does it provide a find function at this point? say find(A > 0) and
returns
index vectors.



>
> > 7. Are the following linear algebraic operations ready ? matrix
> > product, LU, QR, Cholesky, SVD, and eigenvalue/eigenvectors
> > (particularly those for symmetric matrices), log-determinant, and
> > linear solver.
>
> Not yet, the linear algebra module is in active development at the
> moment. Once some general interface
> issues are fixed, we'll starts integrating them during upcoming weeks.
>
> > 8.  Does it use BLAS/LAPACK back-end (such that I can link with MKL)?
> > (if it is optional, is there a macro to enable it?)
>
> Yes. The Cmake build script takes care of detecting which BLAS/LAPACK
> flavor is available
> and use it transparently. In case you want to specify one special
> back-end, the cmake script
> can be fed with the direct path to your back end of choices.
>
> Except for exotic platforms like embedded systems, we'll rely on
> external libraries for such
> specialized kernels.

Oh, I did not notice the Cmake detects such (maybe I am missing
something).

I did have an MKL (ver 10.3) installed and MKLROOT set as environment
variable.
Is there a way for me to inspect which back-end the installed NT2 lib
is using
(e.g. looking at some header files to see which macros are defined ?)


>
> No problems :)
>
> > (Perhaps you may set up a simple wiki page
> > or something that roughly sketches the basic functionalities and
> > whether they are ready, which would be greatly helpful )
>
> Yes this is something we consider. We'll probably starts using the
> Milestones
> tracking on github too.
>
> > Finally, I am wondering when it is going to be released (several
> > weeks? months, or a year?) I understand this might be too early to
> > tell, but is there a rough estimation?
>
> We're aiming at having some Release candidate at the beginning of
> this summer with a significant subset of functionalities and architectural
> support.
>

Sounds great and expecting the RC version!



Joel Falcou

unread,
Apr 20, 2012, 12:37:46 PM4/20/12
to nt2...@googlegroups.com
I believe this. Also, I think using VML of MKL has several problems,
which are deal-breakers for me:

(1) When we want to process a large number of short vectors (say
length < 20),
it seem to have huge overhead, and it shows benefit only when it is
invoked to
process a large sum of elements each time.

hmm not sure how we fare on this. IIRC, as soon as we have more than 8 double or 16 float we starts having speed-up.
We still have to add proper unrolling for statically sized tables.

 

(2) It is eager evaluation, meaning that it scans the entire vector
for each single operation.
In my domain, I often have to chain a series of arithmetic/exp/log
computation, and this would be
a performance penalty. That's why I am looking at C++ libraries that
make use of expression template techniques to reduce such overhead.


Sure
 
I am impressed by the full set of functions provided by NT2, which
is unparalleled among C++ numeric libraries.

Thanks for the compliment, you have to thanks our resident mathematician for that ;)
 

Whereas I think the syntax bsxfun(@plus, a, b) (as in MATLAB) is
useful
in general,  this way may need to decide how to process a and b at run-
time
(i.e. to tell which dimensions need to be broadcasted/expanded)


bsxfun(f,a,b) is probably just f( repmat(a,size(b), repmat(b,size(a)) or something
but yeah some overhead can get in.
 

 
Ideally, I wish it can support such syntax:

A(I, J)

Here, I and J are anything that supports random access iteration (e.g.
std::vector),
then I can build up I and J in my own way (using whatever random-
access container
I see fit in my context).



We have a share function that allow a table to share a RandomAccessRange
So

table<float, shared_> x = share(myvector.begin(), myvector.end());

should be working right out of the box.
I guess proper overload on share for classic cases may be provided.

 

Does it provide a find function at this point? say find(A > 0) and
returns index vectors.


Not yet.


Oh, I did not notice the Cmake detects such (maybe I am missing
something).

It did in the algebra branch which will be started to be integrated 'soon'
 

I did have an MKL (ver 10.3) installed and MKLROOT set as environment
variable.
Is there a way for me to inspect which back-end the installed NT2 lib
is using (e.g. looking at some header files to see which macros are defined ?)


The script defines a NT2_BLAS_VENDOR containing the detected back end
 

Reply all
Reply to author
Forward
0 new messages