77arguments
88 fileName (1 ,1 ) string
99end
10+ if ismember(version(' -release' ),[" 2020a" ," 2020b" ])
11+ filePath = legacySupportFilePath(fileName );
12+ return
13+ end
1014sd = matlab .internal .examples .utils .getSupportFileDir();
1115localFileDir = {" data" ," networks" };% #ok
1216localFile = fullfile(sd ," nnet" ,localFileDir{: },fileName );
1519end
1620fileURL = strjoin([localFileDir ,fileName ]," /" );
1721filePath = matlab .internal .examples .downloadSupportFile(" nnet" ,fileURL );
22+ end
23+
24+ function filePath = legacySupportFilePath(fileName )
25+ % For releases before matlab.internal.examples.downloadSupportFile,
26+ % use manual download code. We save to the repo's root directory instead of
27+ % the userpath.
28+ % Create directories for the model.
29+ modelType = ' gpt2-355M' ;
30+ modelDirectory = fullfile(fileparts(mfilename(' fullpath' )),' ..' ,' ..' ,modelType );
31+ filePath = fullfile(modelDirectory ,fileName );
32+ iCreateDirectoryIfItDoesNotExist(modelDirectory );
33+
34+ iDownloadFileIfItDoesNotExist( ...
35+ filePath , ...
36+ " https://ssd.mathworks.com/supportfiles/nnet/data/networks/" +fileName );
37+ end
38+
39+ function iCreateDirectoryIfItDoesNotExist(directory )
40+ if ~exist(directory , ' dir' )
41+ fprintf(' Creating directory ''%s'' ...\n ' , directory );
42+ mkdir(directory );
43+ else
44+ fprintf(' Skipped creating directory ''%s'' as it already exists\n ' , directory );
45+ end
46+ end
47+
48+ function iDownloadFileIfItDoesNotExist(destination , source )
49+ if ~exist(destination , ' file' )
50+ fprintf(' Downloading file ''%s'' ...\n ' , destination );
51+ websave(destination , source );
52+ else
53+ fprintf(' Skipped downloading file ''%s'' as it already exists\n ' , destination );
54+ end
1855end
0 commit comments