The end of Moore’s Law is looming. Engineers and designers can do only so much to miniaturize transistors and pack as many of them as possible into chips. So they’re turning to other approaches to chip design, incorporating technologies like AI into the process. Samsung, for instance, is adding AI to its memory chips to enable processing in memory, thereby saving energy and speeding up machine learning. Speaking of speed, Google’s TPU V4 AI chip has doubled its processing power compared...| IEEE Spectrum
The variable $var appears to change size on every loop iteration. Consider preallocating for speed. So sayeth Matlab. Let's try it: x_prealloc = cell(10000, 1); x_end = {}; x_append = {}; for n=1:10000 % variant 1: preallocate x_prealloc(n) = {42}; % variant 2: end+1 x_end(end+1) = {42}; % variant 3: append x_append = [x_append {42}]; end Which variant do you think is fastest? Unsurprisingly, preallocation is indeed faster than growing an array. What is surprising is that it is faster by a co...| bastibe.de
Why is it, that I find Matlab to be a fine teaching tool and a fine tool for solving engineering problems, but at the same time, extremely cumbersome for my own work? Recently, the answer struck me: metaprogramming in Matlab sucks. Matlab is marketed as a tool for engineers to solve engineering problems. There are convenient data structures for numerical data (arrays, tables), less convenient data structures for non-numeric data (cells, structs, chars), and a host of expensive but powerful fu...| bastibe.de
In a recent project, I tried to parse MATLAB code. During this trying exercise, I stumbled upon a few… unique design decisions of the MATLAB language: Use of apostrophes (') Apostrophes can mean one of two things: If applied as a unary postfix operator, it means transpose. If used as a unary prefix operator, it marks the start of a string. While not a big problem for human readers, this makes code surprisingly hard to parse. The interesting bit about this, though, is the fact that there wou...| bastibe.de
21 Jun 2016| bastibe.de
For a few years now, I have been teaching programming courses using notebooks. A notebook is an interactive document that can contain code, results, graphs, math, and prose. It is the perfect teaching tool: You can combine introductory resources with application examples, assignments, and results. And after the lecture, students can refer to these notebooks at their leisure, and re-run example code, or try different approaches with known data. The first time I saw this was with the Jupyter no...| bastibe.de
Sometimes, you just have to use C code. There's no way around it. C is the lingua franca and bedrock of our computational world. Even in Matlab, sometimes, you just have to call into a C library. So, you grab your towel, you bite the bullet, you strap into your K&R, and get down to it: You start writing a Mex file. And you curse, and you cry, because writing C is hard, and Mex doesn't exactly make it any better. But you know what? There is a better way! Because, unbeknownst to many, Matlab in...| bastibe.de
03 Nov 2015| bastibe.de
As of Matlab 2014b, Matlab includes a Python module for calling Matlab code from Python. This is how you use it: import numpy import matlab import matlab.engine eng = matlab.engine.start_matlab() random_data = numpy.random.randn(100) # convert Numpy data to Matlab: matlab_data = matlab.double(random_data.tolist()) data_sum = eng.sum(matlab_data) You can call any Matlab function on eng, and you can access any Matlab workspace variable in eng.workspace. As you can see, the Matlab Engine is not ...| bastibe.de
So I wanted to work with audio files in Matlab. In the past, Matlab could only do this with auread and wavread, which can read *.au and *.wav files. With 2012b, Matlab introduced audioread, which claims to support *.wav, *.ogg, *.flac, *.au, *.mp3, and *.mp4, and simultaneously deprecated auread and wavread. Of these file formats, only *.au is capable of storing more than 4 Gb of audio data. But the documentation is actually wrong: audioread can actually read more data formats than documented...| bastibe.de
As per the latest Stackoverflow Developer Survey, Matlab is one of the most dreaded tools out there. I run into Matlab-related trouble daily. In all honesty, I have never seen a programming language as user-hostile and as badly designed as this. So here is today's problem: When run from the command line, Matlab does not render unicode characters (on OSX). I say "(on OSX)", because on Windows, it does not print a damn thing. Nope, no disp output for Windows users. More analysis: It's not that ...| bastibe.de
19 Aug 2014| bastibe.de
In Matlab, the groups that are defined in parentheses are saved as tokens.| A Scripter's Notes