1+ #! /usr/bin/env bash
2+
3+ # Code to install a version of NumPy greater than 1.26.0. This si code which takes version of
4+ # NumPy as an argument and installs that version and validates that the version is greater than 1.26.0.
5+ # If the version is not greater than 1.26.0, the script will exit with a message. If no version is provided,
6+ # The script will default to the highest stable version of 1.26 and supply the use with a message warning
7+ # that version 1.26 will be installed and verify if this is what they want to do before proceeding.
8+
9+ DEFAULT_VERSION=" 1.26.*"
10+
11+ if [ -z " $1 " ]; then
12+ echo -e " No version specified. Would you like to install NumPy version ${DEFAULT_VERSION} ? [y/N]"
13+ read -r response
14+ if [[ " $response " =~ ^([yY][eE][sS]| [yY])+$ ]]; then
15+ VERSION=$DEFAULT_VERSION
16+ else
17+ echo " Installation cancelled. Please specify a version greater than 1.26.0"
18+ exit 1
19+ fi
20+ else
21+ VERSION=$1
22+ fi
23+
24+ # Function to compare semantic versions
25+ compare_versions () {
26+ local version1=$1
27+ local version2=$2
28+
29+ # Remove any wildcards and split into components
30+ local v1_clean=$( echo " $version1 " | sed ' s/\*//g' )
31+ local v2_clean=$( echo " $version2 " | sed ' s/\*//g' )
32+
33+ # Split versions into arrays
34+ IFS=' .' read -ra V1_PARTS <<< " $v1_clean"
35+ IFS=' .' read -ra V2_PARTS <<< " $v2_clean"
36+
37+ # Pad shorter array with zeros
38+ local max_len=${# V1_PARTS[@]}
39+ if [ ${# V2_PARTS[@]} -gt $max_len ]; then
40+ max_len=${# V2_PARTS[@]}
41+ fi
42+
43+ # Compare each component
44+ for (( i= 0 ; i< max_len; i++ )) ; do
45+ local v1_part=${V1_PARTS[i]:- 0}
46+ local v2_part=${V2_PARTS[i]:- 0}
47+
48+ if [ " $v1_part " -lt " $v2_part " ]; then
49+ return 1 # version1 < version2
50+ elif [ " $v1_part " -gt " $v2_part " ]; then
51+ return 0 # version1 > version2
52+ fi
53+ done
54+
55+ return 2 # versions are equal
56+ }
57+
58+ # Check if version is greater than or equal to 1.26.0
59+ MIN_VERSION=" 1.26.0"
60+
61+ # If version contains wildcard, treat it as equal to minimum version
62+ if [[ " $VERSION " == * " *" * ]]; then
63+ VERSION_CLEAN=$( echo " $VERSION " | sed ' s/\*//g' )
64+ compare_versions " $VERSION_CLEAN " " $MIN_VERSION "
65+ result=$?
66+ if [ $result -eq 1 ]; then
67+ echo " Error: Version must be greater than or equal to 1.26.0"
68+ echo " Specified version: $VERSION "
69+ exit 1
70+ fi
71+ else
72+ compare_versions " $VERSION " " $MIN_VERSION "
73+ result=$?
74+ if [ $result -eq 1 ]; then
75+ echo " Error: Version must be greater than or equal to 1.26.0"
76+ echo " Specified version: $VERSION "
77+ exit 1
78+ fi
79+ fi
80+
81+ echo " Installing NumPy version $VERSION ..."
82+ CFLAGS=" -I/System/Library/Frameworks/vecLib.framework/Headers -Wl,-framework -Wl,Accelerate -framework Accelerate" pip install numpy==" $VERSION " --force-reinstall --no-deps --no-cache --no-binary :all: --no-build-isolation --compile -Csetup-args=-Dblas=accelerate -Csetup-args=-Dlapack=accelerate -Csetup-args=-Duse-ilp64=true
0 commit comments