sparse implementation