# The unit tests thread

**URL:** <https://igraph.discourse.group/t/the-unit-tests-thread/597>\
**Category:** Development\
**Tags:** C\
**Created:** [21 January 2021 11:22 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597 "2021-01-21T11:22:21Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [9 February 2021 21:01 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/21 "2021-02-09T21:01:33Z")

</div>

I think the only issue is what I noted [here](https://github.com/igraph/igraph/pull/1655/files#r573236924). Did I misunderstand something?

---

<div class="post-metadata">

**Author:** ![GroteGnoom](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/grotegnoom/32/428_2.png) [@GroteGnoom](https://igraph.discourse.group/u/GroteGnoom)\
**Post date:** [10 February 2021 08:41 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/22 "2021-02-10T08:41:42Z")

</div>

Thanks! No, I was just completely looking in the wrong direction. 🙂

---

<div class="post-metadata">

**Author:** ![GroteGnoom](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/grotegnoom/32/428_2.png) [@GroteGnoom](https://igraph.discourse.group/u/GroteGnoom)\
**Post date:** [11 February 2021 16:29 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/23 "2021-02-11T16:29:48Z")

</div>

I am working on arpack\_unpack\_complex. It’s supposed to make the output of igraph\_arpack\_rnsolve more readable. One thing rnsolve does is that when the eigenvalues are complex it does store the two complex conjugate eigenvalues, but only stores the eigenvector of the eigenvalue with the positive imaginary part. unpack\_complex doesn’t explicitly say what it’s supposed to output, but I guess it should output both eigenvectors for that complex case. What it actually does is output the eigenvector for the eigenvalue with negative imaginary part twice. You can see this here: [Add arpack\_unpack\_complex unit tests · GroteGnoom/igraph@540ae9b · GitHub](https://github.com/GroteGnoom/igraph/commit/540ae9bf1eac6698d48472ecaccf4bc7d1e61726). (For the outputs: First there’s a real column, then an imaginary column, then real, etc.)

Am I correct that it should output two different eigenvectors (the original one and it’s complex conjugate) ?

---

<div class="post-metadata">

**Author:** ![tamas](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/tamas/32/1261_2.png) [@tamas](https://igraph.discourse.group/u/tamas)\
**Post date:** [11 February 2021 20:22 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/24 "2021-02-11T20:22:39Z")

</div>

Yes, that is what it is supposed to do. The function has two goals:

- If you have `n` eigenvalues, then it should produce a matrix with 2\*n columns, real and imaginary columns interspersed, as you have observed.
- If ARPACK returned _more_ than `n` eigenvalues for some reason, it should discard the additional eigenvalues.

The main purpose of this function was to make it easier to write unit tests that involve complex eigenvectors. It is not used at the moment in the C core, but the R interface exposes it as `arpack.unpack.complex`, and its output actually matches what R requires to produce a list of complex vectors.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [17 February 2021 10:25 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/25 "2021-02-17T10:25:22Z")

</div>

@GroteGnoom On Monday I fixed a bunch of bugs in community detection functions when calling them on 0- or 1-vertex graphs. Having informative error messages (with `IGRAPH_ERRORF`) that included actual values was hugely helpful in this! Your work is bringing fruit.

---

<div class="post-metadata">

**Author:** ![GroteGnoom](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/grotegnoom/32/428_2.png) [@GroteGnoom](https://igraph.discourse.group/u/GroteGnoom)\
**Post date:** [17 February 2021 10:53 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/26 "2021-02-17T10:53:37Z")

</div>

🙂 That’s great to hear!

---

<div class="post-metadata">

**Author:** ![GroteGnoom](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/grotegnoom/32/428_2.png) [@GroteGnoom](https://igraph.discourse.group/u/GroteGnoom)\
**Post date:** [18 February 2021 11:24 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/27 "2021-02-18T11:24:45Z")

</div>

igraph\_zeroin is in /src/internal/, but it is not used internally (no usage found with grep -r igraph\_zeroin). Does that mean it isn’t used? Should it still be tested for possible later usage?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [18 February 2021 11:58 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/28 "2021-02-18T11:58:12Z")

</div>

Since it’s a public function, it’s not bad to have a test for it.

But since it is not directly graph related, not currently included in the documentation, and not used by any high-level interfaces, it is the lowest priority among such functions. Also, it seems to be borrowed from R, which borrowed it from NETLIB (?) so it’s unlikely to be buggy. I would focus on something else.

@Gabor Do you recall why this function was added in the first place, given that it is not even used by the R interface?

---

<div class="post-metadata">

**Author:** ![Gabor](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/gabor/32/15_2.png) [@Gabor](https://igraph.discourse.group/u/Gabor)\
**Post date:** [18 February 2021 14:27 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/29 "2021-02-18T14:27:39Z")

</div>

For some personal thing, that maybe never happened. Just ignore it. We can even remove it.

---

<div class="post-metadata">

**Author:** ![GroteGnoom](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/grotegnoom/32/428_2.png) [@GroteGnoom](https://igraph.discourse.group/u/GroteGnoom)\
**Post date:** [21 February 2021 10:10 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/30 "2021-02-21T10:10:08Z")

</div>

Is there a quick way to build only the docs needed to check them for a single function?

Also: in the docs, it seems like `\c A` and `<code>A</code>` are supposed to have the same end result, and `<code>` is just more practical for longer blocks, but they show up with two different fonts when I render it locally. Is that a bug? I notice that in the html the `<code>` blocks have class = literal, and `\c` has class = constant.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [21 February 2021 12:56 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/31 "2021-02-21T12:56:04Z")

</div>

@tamas would be able to answer these questions.

As for the slow doc build, I also find that painful, but I’m not sure that there’s an easy fix …

---

<div class="post-metadata">

**Author:** ![tamas](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/tamas/32/1261_2.png) [@tamas](https://igraph.discourse.group/u/tamas)\
**Post date:** [21 February 2021 19:10 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/32 "2021-02-21T19:10:53Z")

</div>

> [@GroteGnoom](#):
>
> Is there a quick way to build only the docs needed to check them for a single function?

Unfortunately there isn’t.

> [@GroteGnoom](#):
>
> I notice that in the html the `<code>` blocks have class = literal, and `\c` has class = constant.

The styles are provided by DocBook; I can fix the CSS so they look the same.

---

<div class="post-metadata">

**Author:** ![GroteGnoom](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/grotegnoom/32/428_2.png) [@GroteGnoom](https://igraph.discourse.group/u/GroteGnoom)\
**Post date:** [22 February 2021 08:46 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/33 "2021-02-22T08:46:11Z")

</div>

> [@tamas](#):
>
> The styles are provided by DocBook; I can fix the CSS so they look the same.

Maybe that does fix everything, but I notice now that the origin of my confusion is that in the [documentation wiki](https://github.com/igraph/igraph/wiki/Documentation-guidelines) it says

```auto
`\c` styles the following word as code. It will be rendered in a monospace font. Use `<code>...</code>`
for longer sections of inline code.

```

while in c-docbook.re it says

```auto
REPLACE ----- doxygen \c command is for <constant> ----------------------------

```

so maybe the wiki should just be changed and the tags used differently than I thought. Still, them having the same font could still be what everyone expects.

---

<div class="post-metadata">

**Author:** ![tamas](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/tamas/32/1261_2.png) [@tamas](https://igraph.discourse.group/u/tamas)\
**Post date:** [22 February 2021 09:05 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/34 "2021-02-22T09:05:02Z")

</div>

We have been using `\c` as an alias for any monospaced stuff for a long time (at least I did) so it’s okay. The whole documentation generation system is a hack anyway 🙂 Back in the early days of the Dark Ages, we used Doxygen (I almost wrote `\c Doxygen` now 🙂 ), but then we decided to migrate to DocBook so we can generate PDF, HTML and Texinfo docs from the same source. That was the time when `doxrox.py` was born, out of necessity, because we’ve had lots of comments written in Doxygen format and we did not want to lose them. None of us were experienced Python programmers back then, so `doxrox.py` is kinda ad-hoc and hacky, it’s terribly slow with the amount of code that we have, but it works and I can’t really see any better solution for building the docs even after so many years, so it’s likely to stay.

One thing that I can probably do is to implement some kind of an on-disk documentation chunk cache that maps SHA256 hashes of files to the documentation chunks in them so we don’t need to re-generate the chunks if the file did not change. This would probably speed up things when you are improving the docs iteratively.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [22 February 2021 10:23 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/35 "2021-02-22T10:23:46Z")

</div>

I’ll note this down for reference:

Parsing the chunks took 137 seconds on my machine, `xmlto` (last step) took 106 seconds. The rest is negligible.

Since `xmlto` must be run every time, and is outside of our control, it defines the absolute lowest limit to how fast the doc build process can be.

---

<div class="post-metadata">

**Author:** ![GroteGnoom](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/grotegnoom/32/428_2.png) [@GroteGnoom](https://igraph.discourse.group/u/GroteGnoom)\
**Post date:** [23 February 2021 09:28 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/36 "2021-02-23T09:28:21Z")

</div>

(Thanks again for all the background info, it really helps a lot 🙂 )

One crude thing that works is to comment out lots of .xxml files in doc/CMakeLists.txt and comment out the same files in docs/igraph-docs.xml. If there are external links I also have to add `--skip-validation` to the xmlto command in doc/CMakeLists.txt

```auto
COMMAND ${XMLTO_COMMAND} --skip-validation -x ${CMAKE_CURRENT_SOURCE_DIR}/gtk-doc.xsl -o html xhtml igraph-docs.xml

```

Of course checking if links are correct is important, but to just check your docs in a proper layout it can be nice, especially if you’re not familiar with all the tags.  
It’s really fast 🙂, only making the iterators docs takes 18s on my slow, old machine. You also have a bit nicer overview of the warnings, and this still shows you missing links as a warning.  
Maybe this is annoying to automate, but even doing it manually can speed things up. Are there other downsides I am missing?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [23 February 2021 10:51 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/37 "2021-02-23T10:51:12Z")

</div>

There seem to be some strange differences in how long each stage of the doc build takes on different systems, so let’s time them.

To get timings, I added this in the top-level `CMakeLists.txt`:

```auto
set_property(GLOBAL PROPERTY RULE_LAUNCH_CUSTOM "${CMAKE_COMMAND} -E time")

```

and I used `ninja -v html` (when building with ninja) or `make html VERBOSE=1` (if you prefer make).

On my machine (macOS 10.14, most tools from MacPorts), I get:

- 2 seconds for parsing documentation chunks (from from 137 s thanks to @tamas’s work yesterday)
- Basically no time at all for all following steps excluding the `xmlto` run (0 s or 1 s reported). @tamas mentioned that this stage is much slower for him.
- 100 s for “Generating HTML documentation with xmlto”, regardless of whether I add `--skip-validation` or not.

---

<div class="post-metadata">

**Author:** ![GroteGnoom](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/grotegnoom/32/428_2.png) [@GroteGnoom](https://igraph.discourse.group/u/GroteGnoom)\
**Post date:** [23 February 2021 11:29 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/38 "2021-02-23T11:29:52Z")

</div>

> [@szhorvat](#):
>
> 100 s for “Generating HTML documentation with xmlto”, regardless of whether I add `--skip-validation` or not.

Yes, the --skip-validation is only useful in enabling skipping xml files.

---

<div class="post-metadata">

**Author:** ![tamas](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/tamas/32/1261_2.png) [@tamas](https://igraph.discourse.group/u/tamas)\
**Post date:** [23 February 2021 15:37 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/39 "2021-02-23T15:37:34Z")

</div>

> [@szhorvat](#):
>
> Basically no time at all for all following steps excluding the `xmlto` run (0 s or 1 s reported). @tamas mentioned that this stage is much slower for him.

For me this is _much_ slower, and it is due to `source-highlight` being called on each of the examples that are to be embedded in the documentation. The part that slows it down is the `--gen-references=inline` switch; without the generation of cross-references it runs in almost no time. The `time` command reveals that the process is CPU-bound, not IO-bound.

`source-highlight` was installed from Homebrew; I’ll try to reinstall and see how it goes.

---

<div class="post-metadata">

**Author:** ![vtraag](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/vtraag/32/38_2.png) [@vtraag](https://igraph.discourse.group/u/vtraag)\
**Post date:** [24 February 2021 15:17 UTC](https://igraph.discourse.group/t/the-unit-tests-thread/597/40 "2021-02-24T15:17:57Z")

</div>

Split this topic on 24 February 2021 15:17 UTC

8 posts were split to a new topic: [Consistency of RNG\_BEGIN and RNG\_END](https://igraph.discourse.group/t/consistency-of-rng-begin-and-rng-end/641)

[Previous page](https://igraph.discourse.group/t/the-unit-tests-thread/597.md?page=1)

[Next page](https://igraph.discourse.group/t/the-unit-tests-thread/597.md?page=3)
