Array multiplicities via sparse

6 February 2017 in matlab

Multiplicities of array elements can be efficiently computed using sparse. I’ve found this elegant solution in an old Newsgroup thread.

% generate some data
A = randi(10,1,100);
% construct the sparse matrix
S = sparse(A,1,1);
% get unique elements and multiplicities
[uA,~,mult] = find(S);
mult =
   (1,1)        8
   (2,1)       15
   (3,1)       11
   (4,1)        5
   (5,1)       10
   (6,1)        6
   (7,1)       10
   (8,1)       13
   (9,1)       13
  (10,1)        9

This method is faster than other solutions – almost twice as fast as histc.

% test array: 2000 random integers from the set 1:1000
% 1000 iterations
Elapsed time is 0.228704 seconds. % histc
Elapsed time is 1.838388 seconds. % bsxfun
Elapsed time is 0.128791 seconds. % sparse

Nvidia Optimus

19 October 2016 in fedora

Bumblebee on fedoraproject.com

Fedora 24 version, closed source solution from managed NVidia repo

dnf -y --nogpgcheck install http://install.linux.ncsu.edu/pub/yum/itecs/public/bumblebee/fedora24/noarch/bumblebee-release-1.2-1.noarch.rpm
dnf install bumblebee-nvidia bbswitch-dkms VirtualGL primus kernel-devel

And test

optirun glxgears

I wanted to test optirun with Matlab, so I ran

optirun /usr/local/MATLAB/R2016a/bin/matlab -desktop

which resulted in a bunch of errors

MATLAB is selecting SOFTWARE OPENGL rendering.
version `CXXABI_1.3.8' not found (required by /usr/lib64/VirtualGL/librrfaker.so)
version `CXXABI_1.3.9' not found (required by /usr/lib64/VirtualGL/librrfaker.so)
continue reading…

Forgotten tabs

9 October 2016 in music

Once upon a time, I heard a song. This one:


Naturally, I had to tab it. And it remained the only tab I’ve ever published.

Then I kind of forgot about it.

Recently, I was searching for some stuff on UG (Ultimate Guitar, not University of Grenoble…) and wondered what happened to my tab. To my surprise, not only did it have some views, it was also rated as excellent! That felt good.

Strange thing, this tabbing. Are you actually creating something new when tabbing somebody else’s song? To put it another way, are you inventing or discovering?

Anyway, I’ll try to post more of tabs from now on. Of this song, for instance.

And I definitely need to practice more.

Selecting extraordinary vertices in Blender

28 July 2016 in blender
selecting extraordinary vertices in blender

Extraordinary vertices in a polygon mesh are the ones which are not regular – their degree is other than 6 in a triangle mesh and other than 4 in a quad mesh. Here’s how to select all extraordinary mesh vertices in Blender:

  1. Select a regular vertex.
  2. Select->Select Similar->Amount of connecting edges.
    This will select all regular vertices.
  3. Hit Ctrl+I to invert the selection.

Bézier surfaces in Matlab

1 February 2016 in matlab

The following code is my attempt for a fast and compact Matlab implementation of Bézier surfaces using three-dimensional arrays. It runs in less than ones second for the teapot dataset with 32 cubic patches and 10 000 surface points per patch. The computation itself (4064 calls to the casteljau function) takes only ⅓ of a second.

continue reading…

Fixing Fujitsu UH572 touchpad on Fedora

12 October 2015 in fedora

…that’s a lot of F-words. Here’s the thing. Open the grub config file:

sudo su
vim /etc/default/grub

Find the line starting with GRUB_CMDLINE_LINUX. Add i8042.notimeout i8042.nomux to the parameters; save and close. Finally, update grub and reboot:

grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
#          NOT -o /boot/grub2/grub.cfg
reboot

And now the touchpad works as it should!

After a fresh OS install

6 October 2015 in fedora

In the past few months, I’ve experimented with various Linux distros, before sticking with Fedora-based Korora and Gnome 3 desktop. Korora comes with many pre-installed packages, including vlc, audacity, deluge, gimp, inkscape and git, which is great; still, each time I’m reinstalling my laptop, I spend too much time figuring out which additional applications, packages and libraries I need to install. To facilitate this rather tedious process in the future, I’ve compiled the following list, plus some pointers to useful web resources.

continue reading…

The perks of Matlab’s column-major order

17 September 2015 in matlab

When working with Matlab, it’s good to remember the data are stored in the column-major order; otherwise, the following (seemingly harmless) code might cause a lot of trouble.

% both Positions and Normals are n x 3 matrices
file = ""
fid = fopen(file,'w');
% print Positions and Normals to file
fprintf(fid, '%f %f %f \t %f %f %f \n', [Positions Normals] );
fclose(fid);

So what’s the problem?

continue reading…