7
7
arguments
8
8
fileName (1 ,1 ) string
9
9
end
10
+ if ismember(version(' -release' ),[" 2020a" ," 2020b" ])
11
+ filePath = legacySupportFilePath(fileName );
12
+ return
13
+ end
10
14
sd = matlab .internal .examples .utils .getSupportFileDir();
11
15
localFileDir = {" data" ," networks" };% #ok
12
16
localFile = fullfile(sd ," nnet" ,localFileDir{: },fileName );
15
19
end
16
20
fileURL = strjoin([localFileDir ,fileName ]," /" );
17
21
filePath = 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
18
55
end
0 commit comments