text:
function N = tangentspherefactory(M, x)
% Returns a manifold struct. for the sphere on the tangent space to M at x.
%
% N = tangentspherefactory(M, x)
%
% N defines a manifold that is the unit sphere on the tangent space to M
% at x. Points are represented as tangent vectors of unit norm. Tangent
% vectors are represented as tangent vectors orthogonal to the root point,
% with respect to the Riemannian metric on the tangent space.
%
% This is chiefly useful to solve optimization problems involving unit norm
% tangent vectors to M at x, which notably comes up when looking for
% extreme eigenvectors of the Hessian of a cost function on M at x, for
% example. The Riemannian structure on this sphere is that of a Riemannian
% submanifold of the (Euclidean) tangent space, equipped with the
% Riemannian metric of M at that point.
%
% See also: hessianextreme

% This file is part of Manopt: www.manopt.org.
% Original author: Nicolas Boumal, March 16, 2015.
% Contributors:
% Change log:
%
%   Nov 27, 2015 (NB):
%       Extra projection added in the retraction, to prevent numerical
%       drift.
%
%   Jun 23, 2021 (QR):
%       Extra projection in retraction changed to M.tangent.
%
%   Jun 23, 2021 (NB):
%       Several fixes to the logic of this factory that should help for
%       more sophisticated manifolds where representations of points,
%       tangent vectors and ambient vectors are not straightforward.

    % N is the manifold we build.
    % y is a point on N, thus also a tangent vector to M at x.
    % This is a typical Riemannian submanifold of a Euclidean space,
    % hence it is easy to describe in terms of the tools available for M.
    N = struct();
    N.name = @() sprintf('Sphere in a tangent space of [%s]', M.name());

    % u, u1 and u2 are tangent vectors to N at y.
    % The tangent space to N at y is a subspace of the tangent space to M
    % at x, thus u, u1 and u2 are also tangent vectors to M at x.

    N.dim   = @() M.dim() - 1;
    N.inner = @(y, u1, u2) M.inner(x, u1, u2);
    N.norm  = @(y, u)      M.norm(x, u);
    N.proj  = @(y, v) M.lincomb(x, 1, v, -M.inner(x, v, y), y);
    N.typicaldist = @() 1;
    N.tangent = N.proj;
    N.egrad2rgrad = N.proj;
    N.retr = @retraction;
    N.exp = N.retr;
    function yy = retraction(y, u, t)
        if nargin == 2
            t = 1;
        end
        y_plus_tu = M.lincomb(x, 1, y, t, u);
        % Mathematically, y_plus_tu is exactly in the tangent space to M at
        % x. However, numerically, it may 'leave' the tangent space
        % slightly. The extra 'projection' on the next line is not required
        % mathematically but helps prevent numerical issues sometimes.
        % If this proves to be a huge slow down, one could consider adding
        % a type of counter that only executes this extra step every so
        % often, instead of at every call.
        y_plus_tu = M.tangent(x, y_plus_tu);
        nrm = M.norm(x, y_plus_tu);
        yy = M.lincomb(x, 1/nrm, y_plus_tu);
    end
    N.rand = @random;
    function y = random()
        y = M.randvec(x);
        nrm = M.norm(x, y);
        y = M.lincomb(x, 1/nrm, y);
    end
    N.randvec = @randvec;
    function u = randvec(y)
        u = N.proj(y, M.randvec(x));
        nrm = N.norm(y, u);
        u = M.lincomb(x, 1/nrm, u);
    end
    N.zerovec = @(y) M.zerovec(x);
    N.transp = @(y1, y2, u) N.proj(y2, u);
    N.hash = @(y) ['z' hashmd5(M.vec(x, y))];

    N.lincomb = @Nlincomb;
    function v = Nlincomb(y, a1, d1, a2, d2) %#ok<INUSL>
        if nargin == 3
            v = M.lincomb(x, a1, d1);
        elseif nargin == 5
            v = M.lincomb(x, a1, d1, a2, d2);
        else
            error('lincomb takes either 3 or 5 inputs.');
        end
    end

end

author: NicolasBoumal

repo: manopt


text:
function index = findNameInList(list, name)
%
%
%        index = findNameInList(list, name)
%
%
%       Input:
%           -list: a list of name; i.e. a result of dir call
%           -name: a string
%
%       Output:
%           -index: the index where name is found in list. It is set to -1
%           if not found.
%
%     Copyright (C) 2015  Francesco Banterle
%
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
%
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
%

index = -1;

for i=1:n
    if(strcmp(name, list(i).name) == 1)
        index = i;
    end
end

end

author: banterle


text:
% -*- INTERNAL UNDOCUMENTED FUNCTION -*-
function [geometry, msh, sp, u, gnum] = ...
                    mp_solve_plane_strain_2d (problem_data, method_data)

warning ('geopdes:obsolete', 'Function MP_SOLVE_PLANE_STRAIN_2D is obsolete. Using MP_SOLVE_LINEAR_ELASTICITY instead')

[geometry, msh, sp, u, gnum] = mp_solve_linear_elasticity (problem_data, method_data);

author: rafavzqz

repo: geopdes

save_path: github-repos/MATLAB/rafavzqz-geopdes


text:
function varargout=lpcar2am(varargin)
%
% For calling details please see v_lpcar2am.m
%
% This dummy routine is included for backward compatibility only
% and will be removed in a future release of voicebox. Please use
% v_lpcar2am.m in future and/or update with v_voicebox_update.m
%
%      Copyright (C) Mike Brookes 2018
%      Version: $Id: lpcar2am.m 10863 2018-09-21 15:39:23Z dmb $
%
if nargout
    varargout=cell(1,nargout);
    [varargout{:}]=v_lpcar2am(varargin{:});
else
    v_lpcar2am(varargin{:});
end

author: ImperialCollegeLondon

repo: sap-voicebox


text:
function NewFiles = import_raw_to_db( DataFile )
% IMPORT_RAW_TO_DB: Import in the database some blocks of recordings from a continuous file already linked to the database.
%
% USAGE:  NewFiles = import_raw_to_db( DataFile )

% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
%
% Copyright (c) University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
%
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
%
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Authors: Francois Tadel, 2011-2022

% ===== GET FILE INFO =====
% Get study description
[sStudy, iStudy, iData] = bst_get('DataFile', DataFile);
if isempty(sStudy)
    error('File is not registered in the database.');
end
% Is it a "link to raw file" or not
isRaw = strcmpi(sStudy.Data(iData).DataType, 'raw');
% Get subject index
[sSubject, iSubject] = bst_get('Subject', sStudy.BrainStormSubject);
% Progress bar
bst_progress('start', 'Import raw file', 'Processing file header...');
% Read file descriptor
DataMat = in_bst_data(DataFile);
% Read channel file
ChannelFile = bst_get('ChannelFileForStudy', DataFile);
ChannelMat = in_bst_channel(ChannelFile);
% Get sFile structure
if isRaw
    sFile = DataMat.F;
else
    sFile = in_fopen(DataFile, 'BST-DATA');
end
% Import file
[NewFiles, iStudyImport] = import_data(sFile, ChannelMat, sFile.format, [], iSubject, [], sStudy.DateOfStudy);

% If only one file imported: Copy linked videos in destination folder
if (length(NewFiles) == 1) && ~isempty(sStudy.Image)
    process_import_data_event('CopyVideoLinks', NewFiles{1}, sStudy);
end

% Copy noise covariance, if any
if ~isempty(iStudyImport) && ~isempty(sStudy.NoiseCov) && ~isempty(sStudy.NoiseCov(1).FileName)
    iStudyCopy = unique(iStudyImport);
    for i = 1:length(iStudyCopy)
        sStudyCopy = bst_get('Study', iStudyCopy(i));
        if isempty(sStudyCopy.NoiseCov) || isempty(sStudyCopy.NoiseCov(1).FileName)
            db_set_noisecov(iStudy, iStudyCopy(i), 0, 0);
        end
    end
end

% Save database
db_save();

author: brainstorm-tools


text:
function [] = gDiscrPdfRnd();

% generic Discrete Pdf Random numbers generator
%
% this function extracts numbers that are randomly distributed over a discrete set of N elements,
% the probability distribution function is user-defined.
%
%
% syntax:
%
% Y = gDiscrPdfRnd(pdf)
% Y = gDiscrPdfRnd(pdf,n)
% Y = gDiscrPdfRnd(pdf,n,m)
%
% pdf is a vector; the i-th component of pdf is the
% probability for the i-th element to be extracted
%
% REMARK: the value sum(pdf) does NOT have to be equal to one. Due to the limited
% precision of double numbers, such condition is often hard to be verified. For this
% reason, THE ONLY CONDITION FOR THE ELEMENT OF pdf IS TO BE NONNEGATIVE
% (i.e. pdf(i) >= 0 , for each 1 <= i <= length(pdf))
%
%
%
% Y = gDiscrPdfRnd(pdf)
% Y is a integer from 1 to length(pdf), randomly generated, according to pdf
%
% Y = gDiscrPdfRnd(pdf,n)
% Y is a  n-by-n  matrix of intergers from 1 to length(pdf), randomly generated, according to pdf
%
% Y = gDiscrPdfRnd(pdf,n,m)
% Y is a  n-by-m  matrix of intergers  from 1 to length(pdf), randomly generated, according to pdf
%
%
%
% examples 1
%
% The following line creates a 3-by-2 matrix of intergers equally distributed from 1 to 6
% gDiscrPdfRnd([1/6 1/6 1/6 1/6 1/6 1/6],3,2)
%
% which is identical to the following
% gDiscrPdfRnd([1 1 1 1 1 1],3,2)
%
%
%
%
%
% example 2
%
% the following example generates 10000 samples
% a triangular pdf and displys the frequencies
%
% ^
% |
% |           *
% |       *   *   *
% |___*___*___*___*___*______
%     1   2   3   4   5
%
%
% pdf = [1/9 2/9 3/9 2/9 1/9];  % or simply pdf = [1 2 3 2 1];
% Y = gDiscrPdfRnd(pdf,10000,1);
% hist(Y,[1:length(pdf)]);
%
%
%
%
% example 3
% similar to the previous, but this time pdf look
% rather sinusoidal...
%
% t = [1:.2:3*pi]; pdf = 1 + t.*sin(t); pdf = pdf - min(pdf);
%
% figure
% bar(pdf,'r');
%
% Y = gDiscrPdfRnd(pdf,100000,1);
%
% figure;
% hist(Y,[1:length(pdf)]);
%
%
%
% author Gianluca Dorini
%
% g.dorini@ex.ac.uk
%
% for compiling type
%
% mex gDiscrPdfRnd.c

error('gDiscrPdfRnd mex file absent, type mex gDiscrPdfRnd.c to compile');

author: Sable

repo: mcbench-benchmarks


text:
function ft_compile_forward(force)
% FT_COMPILE_FORWARD  This script/function is used for compiling the various MEX files used in FieldTrip 'forward'
%
% Please note that this script does NOT set up your MEX environment for you, so in case
% you haven't selected the C compiler on Windows yet, you need to type 'mex -setup' first
% to choose either the Borland or Microsoft compiler. If you want to use MinGW, you also
% need to install Gnumex (http://gnumex.sourceforget.net), which comes with its own
% procedure for setting up the MEX environment.

% The logic in this script is to first build a list of files that actually need compilation for the
% particular platform that Matlab is running on, and then to go through that list.
% Functions are added to the list by giving their destination directory and (relative to that) the
% name of the source file (without the .c). Optionally, you can specify a list of platform this
% file needs to be compiled on only, and a list of platforms where you don't compile it on.
% Finally, you can give extra arguments to the MEX command, e.g., for including other c-sources or
% giving compiler flags.
% (C) 2010 S. Klanke

if nargin<1
   force=false;
end

%Possible COMPUTER types
%GLNX86
%GLNXA64
%PCWIN
%PCWIN64
%MAC
%MACI
%MACI64

L = [];
L = add_mex_source(L,'private','plgndr');
L = add_mex_source(L,'private','meg_leadfield1');
L = add_mex_source(L,'private','lmoutr',[],[],'geometry.c -I.');
L = add_mex_source(L,'private','solid_angle',[],[],'geometry.c -I.');
L = add_mex_source(L,'private','ptriproj',[],[],'geometry.c -I.');

oldDir = pwd;
[baseDir, myName] = fileparts(mfilename('fullpath'));
try
  compile_mex_list(L, baseDir, force);
catch me
  cd(oldDir);
  rethrow(me);
end
cd(oldDir);

author: PatternRecognition

repo: OpenBMI


text:
function r8_cscd_test ( )

%*****************************************************************************80
%
%% R8_CSCD_TEST tests R8_CSCD.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    12 January 2015
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'R8_CSCD_TEST\n' );
  fprintf ( 1, '  R8_CSCD computes the cosecant of an angle\n' );
  fprintf ( 1, '  given in degrees.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  ANGLE    R8_CSCD(ANGLE)\n' );
  fprintf ( 1, '\n' );

  for i = 0 : 15 : 360
    angle = i;
    if ( mod ( i, 180 ) == 0 )
      fprintf ( 1, '  %8.2f    Undefined\n', angle );
    else
      fprintf ( 1, '  %8.2f  %14.6g\n', angle, r8_cscd ( angle ) );
    end
  end

  return
end

author: johannesgerer

repo: jburkardt-m