Skip to content

Instantly share code, notes, and snippets.

View manodeep's full-sized avatar
👋

Manodeep Sinha manodeep

👋
View GitHub Profile
@manodeep
manodeep / Timings.py
Last active August 10, 2023 04:11 — forked from synapticarbors/Timings.py
Attempt to create a faster version of a Euclidean pairwise distance method in cython using BLAS. Strategy for including BLAS taken from the Tokyo project.
import numpy as np
from scipy.spatial.distance import cdist
from distlib import pairwise_cython_blas, pairwise_cython, pairwise_cython_blas2
import timeit
a = np.random.random(size=(10000,3))
loop = 1
repeat = 1
funcs = ['cdist(a,a)', 'pairwise_cython(a)', 'pairwise_cython_blas(a)', 'pairwise_cython_blas2(a)']
@manodeep
manodeep / compute_joint_wp_and_gmf_correlation_matrix_from_theory_with_ngal_from_mocks.pro
Created November 8, 2021 04:54
IDL code to create the enormous correlation matrix plot from Sinha et al 2018
function return_left_edge, axis, index, value
common tick_block, fixed_value_left_x, fixed_value_right_x
if value lt n_elements(fixed_value_left_x) then begin
tickmark = string_logexp(fixed_value_left_x[value])
endif else begin
if value eq n_elements(fixed_right_x) then begin
tickmark = string_logexp(fixed_value_right_x[-1])
endif else begin
tickmark = 'N!Dgal!N'
endelse
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@manodeep
manodeep / Compiling + output
Last active March 30, 2020 04:58
Code to find next highest power of 2
[~/temp/astropy-64bit-power-of-2 @Manodeeps-MacBook-Pro] gcc -std=gnu11 -O2 -Wall -Wextra test.c
test.c: In function 'naive_p2':
test.c:227:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(result < n) {
^
[~/temp/astropy-64bit-power-of-2 @Manodeeps-MacBook-Pro] ./a.out
Running in 64 bit mode
Checking overflow bug
nbytes = 9223372036854775807 nextp2 = -9223372036854775808 (unsigned) nextp2 = 9223372036854775808
nbytes = -1 nextp2 = 1 (unsigned) nextp2 = 1
@manodeep
manodeep / h5_dtype_sizes.c
Created November 20, 2019 06:31
Getting size (in bytes) for some of the common HDF5 native datatypes
/* A code to print out the data size (in bytes) corresponding to the
common HDF5 native datatypes
Author: Manodeep Sinha
Date: 20/11/2019
Compile with `
@manodeep
manodeep / test_id_concat.c
Created November 13, 2019 05:19
Concatenating two sets of distinct IDs into one combined ID
/*
Author: Manodeep Sinha
Date: 13th Nov, 2019
Purpose: For the Uchuu collaboration
*** The code combines two distinct ids into one (32 bit or 64 bit) ID using bitshifts, and a bitwise OR ***
- Define the macro "USE_64BITS" to work with 64 bits for destination size of the combined ID. If "USE_64BITS"
is undefined, then the destination size will be 32 bits.
@manodeep
manodeep / read_sage_hdf5.py
Last active August 27, 2019 23:26
An utility function to read specific properties for all SAGE galaxies at a given snapshot from the SAGE hdf5 output file
def read_all_sage_galaxies_from_hdf5(h5file, snapnum=63, wanted_fields=None):
import h5py
import numpy as np
if wanted_fields == None:
wanted_fields = ['StellarMass', 'EjectedMass', 'ColdGas', 'BlackHoleMass', 'BulgeMass', 'CentralMvir', 'SfrDisk', 'Mvir', 'Rvir',
'infallVmax', 'TimeOfLastMajorMerger', 'TimeOfLastMinorMerger', 'SAGETreeIndex', 'Type']
with h5py.File(h5file, 'r') as hf:
if hf['Header/Misc'].attrs['sage_data_version'] == b'1.00':
ncores = hf['Header/Misc'].attrs['num_cores']
@manodeep
manodeep / test_hdf5_partial_access.c
Created June 27, 2019 22:58
OpenMP parallel reads of 1-D arrays from HDF5 files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <omp.h>
#include "hdf5.h"
#include "sglib.h"
/*
@manodeep
manodeep / output.txt
Created May 18, 2019 01:42
Passing strings to functions
## compiled with gcc -Wall -std=c99 xx.c -o xx -Wextra
## and then run. Produces the following output:
Printing mystring_fixed...
In print_string_fixed_len_array> string = `Fixed len array with (50) elements'
In print_string_pointer> string = `Fixed len array with (50) elements'
Printing mystring_fixed......done
Printing mystring...
In print_string_fixed_len_array> string = `Fixed (unspecified) length array'
@manodeep
manodeep / convert_uchuu_ascii_to_h5.py
Last active July 14, 2020 03:17
Utilities for Uchuu Converter (ascii -> hdf5)
#!/usr/bin/env python
from __future__ import print_function
__author__ = "Manodeep Sinha"
__all__ = ["convert_single_ascii_halocat", "convert_ascii_halocat_files"]
import os
from uchuu_utils import get_parser, get_approx_totnumhalos, generic_reader,\
get_metadata, resize_halo_datasets, write_halos