Skip to content

Commit

Permalink
[style] use parens in if/while/switch predicates, space after "!", "!…
Browse files Browse the repository at this point in the history
…=" instead of "~="
  • Loading branch information
apjanke committed Feb 4, 2024
1 parent 12c32e1 commit 2e46b2f
Show file tree
Hide file tree
Showing 113 changed files with 1,384 additions and 1,364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

price0 = price(1,:);

rel_price = price ./ repmat (price0, [size(price,1) 1]);
rel_price = price ./ repmat (price0, [size(price, 1) 1]);

figure;
plot (day, rel_price);
Expand Down
4 changes: 2 additions & 2 deletions inst/+tblish/+examples/+internal/+datasets/airquality_1.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
figure;
for i = 1:n_vars
for j = 1:n_vars
if i == j
if (i == j)
continue
endif
ix_subplot = (n_vars*(j - 1) + i);
ix_subplot = (n_vars * (j - 1) + i);
hax = subplot (n_vars, n_vars, ix_subplot);
var_x = vars{i};
var_y = vars{j};
Expand Down
4 changes: 2 additions & 2 deletions inst/+tblish/+examples/+internal/+datasets/anscombe_1.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@

# Fiddle with the plot axes parameters
linkaxes (haxs);
xlim(haxs(1), x_limits);
ylim(haxs(1), y_limits);
xlim (haxs(1), x_limits);
ylim (haxs(1), y_limits);
6 changes: 3 additions & 3 deletions inst/+tblish/+examples/+internal/+datasets/cars_1.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

figure;
plot (t.speed, t.dist, "o");
xlabel ("Speed (mph)"); ylabel("Stopping distance (ft)");
xlabel ("Speed (mph)"); ylabel ("Stopping distance (ft)");
title ("cars data");

figure;
loglog (t.speed, t.dist, "o");
xlabel ("Speed (mph)"); ylabel("Stopping distance (ft)");
xlabel ("Speed (mph)"); ylabel ("Stopping distance (ft)");
title ("cars data (logarithmic scales)");

# TODO: Do the linear model plot

# Polynomial regression
figure;
plot (t.speed, t.dist, "o");
xlabel ("Speed (mph)"); ylabel("Stopping distance (ft)");
xlabel ("Speed (mph)"); ylabel ("Stopping distance (ft)");
title ("cars polynomial regressions");
hold on
xlim ([0 25]);
Expand Down
4 changes: 2 additions & 2 deletions inst/+tblish/+examples/+internal/+datasets/cupcake_1.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
t = tblish.dataset.cupcake
plot(datenum(t.Month), t.Cupcake)
title ('“Cupcake” Google Searches'); xlabel ("Year"); ylabel ("Unknown popularity metric")
plot (datenum (t.Month), t.Cupcake)
title ('“Cupcake” Google Searches'); xlabel ("Year"); ylabel ("Unknown popularity metric");
2 changes: 1 addition & 1 deletion inst/+tblish/+examples/+internal/+datasets/freeny_1.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
t = tblish.dataset.freeny;

summary(t)
summary (t)

tblish.examples.plot_pairs (removevars (t, "date"))

Expand Down
2 changes: 1 addition & 1 deletion inst/+tblish/+examples/SpDb.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
'S4' 'P4' 300
'S4' 'P5' 400
}, 'VariableNames', {'SNum', 'PNum', 'Qty'});
if nargout == 1
if (nargout == 1)
varargout = { struct('S', S, 'P', P, 'SP', SP) };
else
varargout = { S, P, SP };
Expand Down
14 changes: 7 additions & 7 deletions inst/+tblish/+examples/coplot.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
##
## @end deftypefn

function [fig, hax] = coplot(varargin)
function [fig, hax] = coplot (varargin)
narginchk (4, Inf);
defaults = {
"PlotFcn" "plot"
Expand All @@ -70,10 +70,10 @@
"PlotArgs" {}
});
mustBeA (opts.PlotFcn, "function_handle", "opts.PlotFcn");
if ! iscell (opts.PlotArgs)
if (! iscell (opts.PlotArgs))
opts.PlotArgs = { opts.PlotArgs };
endif
if isnumeric (args{1})
if (isnumeric (args{1}))
fig = args{1};
mustBeScalar (fig);
figure (fig);
Expand All @@ -87,12 +87,12 @@
[X, x_name] = getvar (tbl, xvar);
[Y, y_name] = getvar (tbl, yvar);
[g_ix, g_names] = resolveVarRef (tbl, gvar);
if isscalar (g_ix)
if (isscalar (g_ix))
hax = coplot_one (fig, tbl, X, x_name, Y, y_name, g_ix, g_names, opts);
else
hax = coplot_two (fig, tbl, X, x_name, Y, y_name, g_ix, g_names, opts);
endif
if nargout < 1
if (nargout < 1)
clear fig
endif
endfunction
Expand All @@ -116,10 +116,10 @@
ix_row = ceil (i / n_cols);
ix_col = 1 + rem (i, n_rows);
ax = subplot (n_rows, n_cols, i);
if ix_col != 1
if (ix_col != 1)
set(ax, 'yticklabel', {});
endif
if ix_row != n_rows
if (ix_row != n_rows)
set(ax, 'xticklabel', {});
endif
set(ax, 'position', get(ax, 'outerposition'));
Expand Down
10 changes: 5 additions & 5 deletions inst/+tblish/+examples/peel_off_name_value_options.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@

#

if nargin < 3 || isempty (defaults); defaults = struct; endif
if (nargin < 3 || isempty (defaults)); defaults = struct; endif
defaults = parse_defaults (defaults);
opts = defaults;
peeled_args = {};
while numel (args) >= 2 && ischar (args{end-1}) && ismember (args{end-1}, known_opts)
while (numel (args) >= 2 && ischar (args{end-1}) && ismember (args{end-1}, known_opts))
peeled_args = [peeled_args args(end-1:end)];
opts.(args{end-1}) = args{end};
args(end-1:end) = [];
Expand All @@ -76,12 +76,12 @@
endfunction

function out = parse_defaults (defaults)
if isstruct (defaults)
if (isstruct (defaults))
out = struct;
return
endif
if iscell (defaults)
if size (defaults, 2) == 2
if (iscell (defaults))
if (size (defaults, 2) == 2)
# Convert cellrec to name/value list
defaults = defaults';
defaults = defaults(:)';
Expand Down
18 changes: 9 additions & 9 deletions inst/+tblish/+examples/plot_pairs.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,33 @@
function out = plot_pairs (varargin)
args = varargin;
fig = [];
if isnumeric (args{1})
if (isnumeric (args{1}))
fig = args{1};
args(1) = [];
endif
data = args{1};
if numel (args) > 1
if (numel (args) > 1)
plot_type = args{2};
else
plot_type = 'scatter';
endif

if isstruct (data)
if (isstruct (data))
data = struct2table (data);
endif
if ! istable (data)
if (! istable (data))
error ('plot_pairs: input data must be a table or struct');
endif
t = data;

if isempty (fig)
if (isempty (fig))
fig = figure;
endif
vars = t.Properties.VariableNames;
n_vars = numel (vars);
for i = 1:n_vars
for j = 1:n_vars
if i == j
if (i == j)
# TODO: Figure out how to put the variable name in big text in this axes
continue
endif
Expand All @@ -81,7 +81,7 @@
var_y = vars{j};
x = t.(var_x);
y = t.(var_y);
switch plot_type
switch (plot_type)
case "scatter"
scatter (hax, x, y, 10);
case "smooth"
Expand All @@ -92,7 +92,7 @@
endfor
endfor

if nargout > 0
if (nargout > 0)
out = fig;
endif
endfunction
Expand All @@ -103,7 +103,7 @@ function smooth (hax, x, y, marker_sz)
# port that. For now, just use a cubic.
hold on
p = polyfit (x, y, 3);
x_hat = unique(x);
x_hat = unique (x);
p_y = polyval (p, x_hat);
plot (hax, x_hat, p_y, "r");
hold off
Expand Down
2 changes: 1 addition & 1 deletion inst/+tblish/+examples/private/peelOffNameValueOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Peels off recognized name-value options from the end of an argument array.
opts = struct;
peeledArgs = {};
while numel (args) >= 2 && ischar (args{end-1}) && ismember (args{end-1}, knownOpts)
while (numel (args) >= 2 && ischar (args{end-1}) && ismember (args{end-1}, knownOpts))
peeledArgs = [peeledArgs args(end-1:end)];
opts.(args{end-1}) = args{end};
args(end-1:end) = [];
Expand Down
2 changes: 1 addition & 1 deletion inst/+tblish/+examples/run_all_example_scripts.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function run_all_example_scripts
function run_all_example_scripts ()
# Runs all example scripts in the inst/examples directory.
#
# This function is meant for use in BIST tests. It just ensures that all
Expand Down
18 changes: 9 additions & 9 deletions inst/+tblish/+internal/+chrono/+algo/binsearch.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
# inserted; that is, the index of the first element larger than it, or one past
# the end of the array if it is larger than all the elements in the haystack.

if !isvector (haystack) && !isempty (haystack)
if (! isvector (haystack) && !isempty (haystack))
error ('haystack must be a vector or empty');
endif
if !isequal (class (needles), class (haystack))
if (! isequal (class (needles), class (haystack)))
error ('needles and haystack must be same type; got %s and %s', ...
class (needles), class (haystack));
endif
Expand All @@ -34,8 +34,8 @@
'uint8' 'uint16' 'uint32' 'uint64'};
is_numeric = ismember (class (needles), numeric_types);

if is_numeric
if iscomplex (needles) || iscomplex (haystack)
if (is_numeric)
if (iscomplex (needles) || iscomplex (haystack))
error ('Complex values are not supported');
endif
loc = double (__tblish_time_binsearch__ (needles, haystack));
Expand All @@ -53,21 +53,21 @@
low = 1;
high = numel (arr);
found = false;
while low <= high
while (low <= high)
mid = floor ((low + high) / 2);
if arr(mid) > val
if (arr(mid) > val)
high = mid - 1;
elseif arr(mid) < val
elseif (arr(mid) < val)
low = mid + 1;
elseif arr(mid) == val
elseif (arr(mid) == val)
found = true;
out(i) = mid;
break;
else
error('Total ordering violation: neither <, >, nor == was true for this value.');
endif
endwhile
if !found
if (! found)
out(i) = -1 * low;
endif
endfor
Expand Down
15 changes: 10 additions & 5 deletions inst/+tblish/+internal/+chrono/+tzinfo/PosixZoneRule.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,38 @@
endproperties

methods (Static)

function out = parseZoneRule (str)
out = tblish.internal.chrono.algo.PosixZoneRule;
if !isrow (in)
if (! isrow (in))
error ('in must be charvec; got non-row char');
endif
els = strsplit (in, ',');
if numel (els ~= 3)
if (numel (els != 3))
error ('Invalid POSIX time zone rule specification: ''%s''', in);
endif
out.local_timezone = els{1};
out.dst_start_rule = els{2};
out.dst_end_rule = els{3};
tok = regexp (out.local_timezone, '^([A-Za-z]+)(\d+)([A-Za-z]+)$', 'tokens');
tok = tok{1};
if numel (tok) ~= 3
if (numel (tok) != 3)
error ('Failed parsing POSIX zone name: ''%s''', out.local_timezone);
endif
out.std_name = tok{1};
out.gmt_offset_hours = str2double(tok{2});
out.dst_name = tok{3};
endfunction

endmethods

methods

function this = PosixZoneRule(in)
if nargin == 0
if (nargin == 0)
return
endif
if ischar (in)
if (ischar (in))
this = tblish.internal.chrono.tzinfo.PosixZoneRule.parseZoneRule(in);
endif
endfunction
Expand All @@ -51,5 +54,7 @@
function out = localToGmtDatenum (this, dnums, isDst)
error ('Unimplemented');
endfunction

endmethods

endclassdef
Loading

0 comments on commit 2e46b2f

Please sign in to comment.