This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Accepts a list and a key function to apply to each item, | |
# and then uses a decorate-sort-undecorate pattern to actually | |
# do the sorting. Returns a new list. Keeps track of the index | |
# to make sure the sort is stable. | |
sort_by = (list, key) -> | |
cmp = ({key: k_a, index: i_a}, {key: k_b, index: i_b}) -> | |
if k_a == k_b then i_a - i_b else if k_a < k_b then -1 else 1 | |
decorated = ({item, index, key: key item} for item, index in list) | |
item for {item} in decorated.sort cmp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
decode_macroman = do -> | |
high_chars_unicode = ''' | |
ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü | |
†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø | |
¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl | |
‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ | |
'''.replace /\n/g, '' | |
(mac_roman_bytestring) -> | |
char_array = for idx in [0...mac_roman_bytestring.length] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local random = math.random | |
local function uuid() | |
local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' | |
return string.gsub(template, '[xy]', function (c) | |
local v = (c == 'x') and random(0, 0xf) or random(8, 0xb) | |
return string.format('%x', v) | |
end) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function out = feval(F, x, varargin) | |
%FEVAL Evaluate a CHEBFUN. | |
% FEVAL(F, X) evaluates a CHEBFUN F at the points in X. If F is a quasimatrix | |
% with columns F1, ..., FN, then the result will be [F1(X), ..., FN(X)], the | |
% horizontal concatenation of the results of evaluating each column at the | |
% points in X. | |
% | |
% FEVAL(F, 'left'), FEVAL(F, 'start'), and FEVAL(F, '-') return the value of F | |
% at the left endpoint of its domain. FEVAL(F, 'right'), FEVAL(F, 'end'), and | |
% FEVAL(F, '+') do the same for the right endpoint. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function out = feval(F, x, varargin) | |
%FEVAL Evaluate a CHEBFUN. | |
% FEVAL(F, X) evaluates a CHEBFUN F at the points in X. If F is a quasimatrix | |
% with columns F1, ..., FN, then the result will be [F1(X), ..., FN(X)], the | |
% horizontal concatenation of the results of evaluating each column at the | |
% points in X. | |
% | |
% FEVAL(F, 'left'), FEVAL(F, 'start'), and FEVAL(F, '-') return the value of F | |
% at the left endpoint of its domain. FEVAL(F, 'right'), FEVAL(F, 'end'), and | |
% FEVAL(F, '+') do the same for the right endpoint. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function varargout = subsref(f, index) | |
%SUBSREF CHEBFUN subsref. | |
% ( ) | |
% F(X) returns the values of the CHEBFUN F evaluated on the array X. If X | |
% falls on a breakpoint of F, the corresponding value from F.POINTVALUES is | |
% returned. F(X, 'left') or F(X, 'right') will evaluate F at breakpoints | |
% using left- or right-hand limits, respectively. See CHEBFUN/FEVAL for | |
% further details. F(:) returns F. | |
% | |
% If F is an array-valued column CHEBFUN, and X is an array of arbitrary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% All lengths up to 16, plus an additional 8 random sizes for each power of two larger than that. | |
coeff_lengths = [ | |
1 2 3 4 5 6 7 8, ... | |
9 10 11 12 13 14 15 16, ... | |
17 20 23 25 26 29 30 32, ... | |
34 37 42 43 49 52 59 64, ... | |
65 66 67 71 76 89 97 128, ... | |
129 146 165 171 176 203 233 256, ... | |
267 276 292 331 378 413 482 512, ... | |
522 536 709 754 784 909 921 1024, ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [Q, R] = qr(A, econ) | |
%QR QR factorization of an array-valued CHEBFUN. | |
% [Q, R] = QR(A) or QR(A, 0), where A is a column CHEBFUN with n columns, | |
% produces a column CHEBFUN Q with n orthonormal columns and an n x n upper | |
% triangular matrix R such that A = Q*R. | |
% | |
% The algorithm used is described in L.N. Trefethen, "Householder | |
% triangularization of a quasimatrix", IMA J. Numer. Anal. (30), 887-897 | |
% (2010). | |
% |