GSoC 2022 openlibm project

Welcome @Sami_Ahmed and thanks for your interest in this project :wave:

I moved your post into this thread. Please read up what we have discussed so far and don’t hesitate to ask any questions, we are happy to get you on board :slightly_smiling_face:

1 Like

@siko1056 , I apologize for the delay.As I am having my mid term exams so,I delayed the task assigned. I learned about the test suite and I think I am somewhat confident in this topic. Please guide me what to do next(do I need to write any test function ).

Sorry for the delay reply, was caught up with my mid-sem :slightly_frowning_face:. Also thank you for your guidance :blush:. I will definitely start working on some projects regarding octave and share my progress with you so that you can guide me better. :grin:

@shreyaswikriti and @Riva_Malthiyar your university obligations always come first. There is lots of time, no need to apologize :wink:

@shreyaswikriti I think we stopped with the suggestion of @cdf

Such a list might be created by looking for “libm” as keyword:

For example, once openlibm becomes a build dependency of Octave we hope to resolve bugs like this:

This list can be collected here in Discourse, or if you like, you can start an Octave wiki page for this project:

1 Like

@siko1056 @cdf, I have created a wiki page for openlibm and have listed some bugs related to the implementation of C++/C math functions in octave and on different platforms. Kindly check the page to ensure that I’m going in the right direction.


3 posts were merged into an existing topic: GSoC 2022 Reading YAML files with Octave

Absolutely right direction @shreyaswikriti :slightly_smiling_face: :+1: This wiki list is a helpful guide for your task and in the end you can check how many issues could be resolved by your work. Please mention this is your application next month.

Regarding the last point for an overwhelming application, a small code contribution, maybe in form of a test case for the BIST. In the wiki two lists are “maintained” (“maturing”? :wink:):

Those are slightly out of date. I reviewed some of them and scripts/audio/lin2mu.m seems to me a suitable candidate to create a few simple test cases:

>> test lin2mu
????? /usr/share/octave/6.4.0/m/audio/lin2mu.m has no tests available

What we want to see in Octave 8 is something like this

>> test lin2mu
PASSES 5 out of 5 tests

Therefore, please study the m-file (it is not very long), try to understand what it should do, and think about a few useful BIST. Then implement and test the BISTs and make your first Octave contribution (see Mercurial - Octave). Please do not hesitate to ask any questions :slightly_smiling_face:

1 Like
Mu-law values use 8-bit unsigned integers.  Linear values use @var{n}-bit
 signed integers or floating point values in the range -1 @leq{} @var{x}
@leq{} 1 if @var{n} is 0.

@siko1056 , Can you please tell me what does this “the range -1 @leq{} @var{x}
@leq{} 1 if @var{n} is 0.” mean in the function lin2mu.
Also, what is the meaning of this (x (:)) ??

I am having problems while creating and submitting the patches. As my octave is built on octave-6.4.0 and this mercurial is cloned on the octave repository. So, I am unable to pull and update the repository and hence submit and test the BIST patches.
Please suggest to me any solution.

I have used the B step when building octave.
Here is my directory:

@siko1056 @cdf please review the patch

I made a comment on the patch tracker. The patch appears to have been generated correctly. Success!

some thoughts - the “## Tests of lin2mu must not actually return anything.” comment probably isn’t necessary. Also, it’s not wrong but you don’t have to include the function name in the error message, or even the entire error message as long as it’s a unique match. A good example of different types of tests can be found in mean.m. or see Tests - Octave

commit message is generally the right form, but the main line usually takes the ‘active voice’. see:

we would also append the patch or bug number to the main line as seen on that page.


Thank you very much for the patch @shreyaswikriti. I second @nrjank’s comments. One point I am missing are any functional test. You implemented two test cases, that check for bad input, which is great. To show us your coding skills, I would love to see at least one test checking for valid output for valid input. This requires understanding what this function does and we are happy to help you here :slightly_smiling_face:

Regarding your previous question: release vs. development build. I think that file hasn’t changed much in the past. Therefore, please create and test the patch with the Octave 6.4.0 release (your current sources you work on). If you start with Octave this summer, you should switch to the latest development sources for effective work on the project :wink:

This “@leq{}” and other similar markup in the documentation is Texinfo markup, which Octave uses since times when Markdown was not that popular yet. To get a readable version of Texinfo-Markup, run in an Octave session “help lin2mu” or see the online manual.

This is an index expression. Which means: get all elements as column vector, regardless of the array shape. Try in Octave:

x = rand (3)
1 Like

also adding to the last comment about x(:) - if you’re familiar with C/C++, it shouldn’t be hard to pick up the specifics of octave’s language. Much is similar, with some specifics for the focus on vectorized/matrix math. You could probably get started with a quick language tutorial like:


I have switched to the development source of the octave.

I’m glad that two test cases are ok. I’m still working on the function and I’ll implement the valid inputs BISTs soon.

Thank you for pointing it out. I’ll soon update with better BISTs and meaningful error messages.
I did read the commit guidelines still I made some mistakes since it’s the first time I’m committing to the octave. I’ll make sure next time it won’t repeat. Thank you for your guidance.

1 Like

Since Octave is written in C++ and aims to take advantage of C++ standard library features but (as I understand it) openlibm provides a replacement for the C language math library, how do you imagine we will be using openlibm in Octave?

We currently use C++ function overloading for things like calling std::exp for both float and double values. Does openlibm provide those function overloads for C++? If not, I don’t think we want to go back to calling exp and expf depending on the type of the argument. Do you envision writing our own octave::math::exp wrapper function so that we can ensure that the openlibm function is called? Or if we just link to openlibm, will that automatically make std::exp call the openlibm functions? If the latter, then this seems like a trivial project - we would just check for openlibm and link with it if it is available. It seems that no other change to Octave would be needed. But if we have to create octave::math wrappers to provide function overloads, that will be a lot of work and mean many changes to the Octave sources. And it would only fix Octave’s C++ code, not any other C++ libraries that we are using.

@siko1056 @nrjank, please have a look at my recent commit and patch file. I have added some errors and warning BISTs and some output/input validations.

1 Like

Thanks for the questions. The first sentence is a good summary of the projects vision. The hope is, that it is in the essence trivial :innocent: To my humble knowledge, the standard C++ library just forwards calls to std::exp to the “correct” libm function (that Octave is linked against) and this shall be replaced by openlibm during this project.

With the last sentence “no other change would be needed”, I do not know what all exactly is necessary. Next to testing and modifying configure, I think many BISTs have to be rewritten / revisited and this is where GSoC comes into play.

At the end of the summer we know if replacing libm with openlibm is that easy (nobody had the time to try it out yet) the BISTs are revisited, a few bugs are resolved, and Octave is more platform independent than ever before :slightly_smiling_face: The project is not intended to go in the direction of rewriting calls to exp, expf, etc. again. Things should become simpler and more platform independent. This project will show what is the use of openlibm for Octave.

@shreyaswikriti many thanks see Savannah :slightly_smiling_face:

1 Like

I believe things indeed work as described by @siko1056, and that would be how we should proceed with this project.

To make sure, I applied the attached patch to openlibm and tested the following code :

#include <cmath>
#include <iostream>

int main () {
  double x = 1.0325;
  std::cout << "x = " << x << " x^2 = "<< std::pow (x, 2.0) << std::endl;
  float xf = 1.0325;
  std::cout << "xf = " << xf << " xf^2 = "<< std::pow (xf, 2.0f) << std::endl;
  return 0;

the results are the following :

 $ clang++ pippo.cpp -o pippo -L. -lopenlibm
 $ ./pippo 
x = 1.0325 x^2 = invoking double __ieee754_pow(double x, double y)
xf = 1.0325 xf^2 = invoking float __ieee754_powf(float x, float y)
 $ clang++ pippo.cpp -o pippo 
 $ ./pippo 
x = 1.0325 x^2 = 1.06606
xf = 1.0325 xf^2 = 1.06606

so I am indeed confident that just using -lopenlibm as a drop-in replacement for -lm should work correctly …

openlibm_patch.txt (1.1 KB)

1 Like

Thanks. Maybe my concern is more theoretical than practical, but is it allowed for a C++ compiler to provide inline function definitions for things declared in <cmath> or to implement them as calls to built-in functions? I see lines like the following in /usr/include/c++/11/cmath on my system:

  using ::asin;

  inline _GLIBCXX_CONSTEXPR float
  asin(float __x)
  { return __builtin_asinf(__x); }

  inline _GLIBCXX_CONSTEXPR long double
  asin(long double __x)
  { return __builtin_asinl(__x); }

and from looking at the preprocessed source and stepping through the code with gdb, it does appear that __builtin_asinf is called when I call std::asin(float). Is there any guarantee that a function like __builtin_asinf will ultimately call a function from libopenlibm or could it really be a special function provided by the compiler?

In any case, I am in favor of having consistent platform-independent behavior for math functions. I’m just trying to understand whether it could be more complicated than linking with a replacement library. It would be great if that is guaranteed to always work. If not, I think we need to know under what circumstances it doesn’t.

1 Like