Created
April 4, 2020 03:15
-
-
Save maxwillzq/e7da9911abf9979f203b743f18e039e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int indexToLoc(const vector<int>& strides, vector<int> ids){ | |
int result = 0; | |
for(int i = 0; i < strides.size(); i++) { | |
result += ids[i] * strides[i]; | |
} | |
return result; | |
} | |
vector<int> locToIndex(const vector<int>& strides, int loc) { | |
vector<int> result; | |
for(int i = 0; i < strides.size(); i++) { | |
int tmp = loc / strides[i]; | |
result.push_back(tmp); | |
loc = loc % strides[i]; | |
} | |
return result; | |
} | |
int main() { | |
std::cout << "Hello World!\n"; | |
vector<int> strides = {5, 1}; | |
int loc = 13; | |
auto ids = locToIndex(strides, loc); | |
for(auto id: ids) { | |
std::cout <<id <<","; | |
} | |
std::cout <<"\n"; | |
int new_loc = indexToLoc(strides, ids); | |
std::cout <<"loc is: " << new_loc << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment