Giter Club home page Giter Club logo

float's Introduction

float

float is a single precision (aka float) matrix framework for R. Base R has no single precision type. Its "numeric" vectors/matrices are double precision (or possibly integer, but you know what I mean). Floats have half the precision of double precision data, for a pretty obvious performance vs accuracy tradeoff.

A matrix of floats should use about half as much memory as a matrix of doubles, and your favorite matrix routines will generally compute about twice as fast on them as well. However, the results will not be as accurate, and are much more prone to roundoff error/mass cancellation issues. Statisticians have a habit of over-hyping the dangers of roundoff error in this author's opinion. If your data is well-conditioned, then using floats is "probably" fine for many applications.

⚠️ WARNING ⚠️ type promotion always defaults to the higher precision. So if a float matrix operates with an integer matrix, the integer matrix will be cast to a float first. Likewise if a float matrix operates with a double matrix, the float will be cast to a double first. Similarly, any float matrix that is explicitly converted to a "regular" matrix will be stored in double precision.

Installation

The package requires the single precision BLAS/LAPACK routines which are not included in the default libRblas and libRlapack shipped from CRAN. If your BLAS/LAPACK libraries do not have what is needed, then they will be built (note that a fortran compiler is required in this case). However, these can take a very long time to compile, and will have much worse performance than optimized libraries. The topic of which BLAS/LAPACK to use and how to use them has been written about many times.

To install the R package, run:

install.packages("float")

The development version is maintained on GitHub:

remotes::install_github("wrathematics/float")

Windows

If you are installing on Windows and wish to get the best performance, then you will need to install from source after editing some files. After installing high-performance BLAS and LAPACK libraries, delete the text $(LAPACK_OBJS) from line in src/Makevars.win beginning with OBJECTS = . You will also need to add the appropriate link line. This will ensure that on building, the package links with your high-performance libraries instead of compiling the reference versions. This is especially important for 32-bit Windows where the internal LAPACK and BLAS libraries are built without compiler optimization because of a compiler bug.

Also, if you are using Windows on big endian hardware (I'm not even sure if this is possible), then you will need to change the 0 in src/windows/endianness.h to a 1. Failure to do so will cause very bizarre things to happen with the NA handlers.

Creating, Casting, and Type

Before we get to the main usage of the package and its methods,

  • To cast TO a float (convert an existing numeric vector/matrix), use as.float() (or its shorthand fl()).
  • To cast FROM a float, use as.double() or as.integer() (or their shorthands, dbl() and int()).
  • To pre-allocate a float vector of 0's (like integer(5)), use float().
  • To construct a float32 object (developes only; see the vignette), use float32().

R has a generic number type "numeric" which encompasses integers and doubles. The function is.numeric() will FALSE for float vectors/matries. Similarly, as.numeric() will return the data cast as double.

Methods

The goal of the package is to recreate the matrix algebra facilities of the base package, but with floats. So we do not include higher statistical methods (like lm() and prcomp()).

Is something missing? Please let me know.

Basic utilities

Method Status
[ done
c() done
cbind() and rbind() done
diag() done
is.na() done
is.float() done
min() and max() done
na.omit(), na.exclude() done
nrow(), ncol(), dim() done
object.size() done
print() done
rep() done
scale() Available for logical center and scale
str() done
sweep() Available for FUN's "+", "-", "*", and "/". Others impossible(?)
typeof() and storage.mode() No storage.mode<- method.
which.min() and which.max() done

Binary Operations

Method Status
+ done
* done
- done
/ done
^ done
> done
>= done
== done
< done
<= done

Casters and Converters

Method Status
dbl() done
int() done
fl() done
as.vector() and as.matrix() done

Linear algebra

Method Status
%*% done
backsolve() and forwardsolve() done
chol(), chol2inv() done
crossprod() and tcrossprod() done
eigen() only for symmetric inputs
isSymmetric() done
La.svd() and svd() done
norm() done
qr(), qr.Q(), qr.R() done
rcond() done
solve() done
t() done

Math functions

Method Status
abs(), sqrt() done
ceiling(), floor(), trunc(), round() done
exp(), exp1m() done
gamma(), lgamma() done
is.finite(), is.infinite(), is.nan() done
log(), log10(), log2() done
sin(), cos(), tan(), asin(), acos(), atan() done
sinh(), cosh(), tanh(), asinh(), acosh(), atanh() done

Misc

Method Status
.Machine_float float analogue of .Machine. everything you'd actually want is there

Sums and Means

Method Status
colMeans() done
colSums() done
rowMeans() done
rowSums() done
sum() done

Package Use

Memory consumption is roughly half when using floats:

library(float)

m = 10000
n = 2500

memuse::howbig(m, n)
## 190.735 MiB

x = matrix(rnorm(m*n), m, n)
object.size(x)
## 200000200 bytes

s = fl(x)
object.size(s)
## 100000784 bytes

And the runtime performance is (generally) roughly 2x better:

library(rbenchmark)
cols <- cols <- c("test", "replications", "elapsed", "relative")
reps <- 5

benchmark(crossprod(x), crossprod(s), replications=reps, columns=cols)
##           test replications elapsed relative
## 2 crossprod(s)            5   3.185    1.000
## 1 crossprod(x)            5   7.163    2.249

However, the accuracy is better in the double precision version:

cpx = crossprod(x)
cps = crossprod(s)
all.equal(cpx, dbl(cps))
## [1] "Mean relative difference: 3.478718e-07"

For this particular example, the difference is fairly small; but for some operations/data, the difference could be significantly larger due to roundoff error.

A Note About Memory Consumption

Because of the use of S4 for the nice syntax, there is some memory overhead which is noticeable for small vectors/matrices. This cost is amortized quickly for reasonably large vectors/matrices. But storing many very small float vectors/matrices can be surprisingly costly.

For example, consider the cost for a single float vector vs a double precision vector:

object.size(fl(1))
## 632 bytes
object.size(double(1))
## 48 bytes

However once we get to 147 elements, the storage is identical:

object.size(fl(1:147))
## 1216 bytes
object.size(double(147))
## 1216 bytes

And for vectors/matrices with many elements, the size of the double precision data is roughly twice that of the float data:

object.size(fl(1:10000))
## 40624 bytes
object.size(double(10000))
## 80040 bytes

The above analysis assumes that your float and double values are conforming to the IEEE-754 standard (which is required to build this package). It specifies that a float requires 4 bytes, and a double requires 8. The size of an int is actually system dependent, but is probably 4 bytes. This means that for most, a float matrix should always be larger than a similarly sized integer matrix, because the overhead for our float matrix is simply larger. However, for objects with many elements, the sizes will be roughly equal:

object.size(fl(1:10000))
## 40624 bytes
object.size(1:10000)
## 40040 bytes

Q&A

Why would I want to do arithmetic in single precision?

It's (generally) twice as fast and uses half the RAM compared to double precision. For a some data analysis tasks, that's more important than having (roughly) twice as many decimal digits.

Why does floatmat + 1 produce a numeric (double) matrix but floatmat + 1L produce a float matrix?

Type promotion always defaults to the highest type available. If you want the arithmetic to be carried out in single precision, cast the 1 with fl(1) first.

Doesn't that make R's type system even more of a mess?

Yes.

How would I create my own methods?

If you can formulate the method in terms of existing functionality from the float package, then you're good. If not, you will likely have to write your own C/C++ code. See the For Developers section of the package vignette.

float's People

Contributors

crissthiandi avatar david-cortes avatar dselivanov avatar snoweye avatar wrathematics avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

float's Issues

[minor] compiler warning

NA.c:33:21: warning: unused function 'set_nan_float' [-Wunused-function]
static inline float set_nan_float() ^
1 warning generated.

float installation fails in R 4.1.3 on CentOs 7

Hi!
I am trying to install the text2vec which ultimately fails complaining about the float dependency. The culprit seems to be

undefined symbol: iparam2stage_

I have noticed the BLAS/LAPACK are available on my system, but I still get this message during the installation - perhaps it has something to do with configuration?

No single precision BLAS functions detected in your R BLAS library, so we are using the reference implementation shipped with the float package. If you believe you are seeing this message in error, please contact the package maintainer.

The complete log:

> install.packages("float")
Installing package into ‘/home/kdreval/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/float_0.3-0.tar.gz'
Content type 'application/x-gzip' length 1425826 bytes (1.4 MB)
==================================================
downloaded 1.4 MB

* installing *source* package ‘float’ ...
** package ‘float’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for sinf in -lm... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... no
checking size of int... 4
checking for gcc option to support OpenMP... -fopenmp
checking for echo... yes
checking for grep... yes
checking for sgemm_ in -lRblas... no
checking for sgetrf_ in -lRblas... no
checking for sgetrf_ in -lRlapack... no
checking for sgemm_ in -lopenblas... no
checking for sgemm_ in -lmkl... no
checking for sgemm_ in -latlas... no
checking for sgemm_ in -lblas... no
checking for sgetrf_ in -lopenblas... no
checking for sgetrf_ in -lmkl... no
checking for sgetrf_ in -latlas... no
checking for sgetrf_ in -llapack... no
 
******************* Results of float package configure *******************
* OpenMP Report:
    >> OPENMP_CFLAGS=-fopenmp
    >> OMPFLAGS_C=$(SHLIB_OPENMP_CFLAGS)
    >> OMPFLAGS_F=$(SHLIB_OPENMP_FFLAGS)
* byte order: little endian
* NOTE: no single precision BLAS symbols found. Building reference version
    >> BLAS_LIBFLAGS=
* NOTE: no single precision LAPACK symbols found. Building reference version
    >> LAPACK_LIBFLAGS=

No single precision BLAS functions detected in your R BLAS library, so we are using the reference implementation shipped with the float package. If you believe you are seeing this message in error, please contact the package maintainer.
*************************************************************************
 
configure: creating ./config.status
config.status: creating src/Makevars
config.status: creating src/endianness.h
config.status: creating R/02-libflags.r
config.status: creating src/config.h
config.status: src/config.h is unchanged
** libs
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c backsolve.c -o backsolve.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c binary.c -o binary.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c chol.c -o chol.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c chol2inv.c -o chol2inv.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c colSums.c -o colSums.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c cond.c -o cond.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c converters.c -o converters.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c crossprod.c -o crossprod.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c eigen.c -o eigen.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c extremes.c -o extremes.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c float_native.c -o float_native.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c isSymmetric.c -o isSymmetric.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c machine.c -o machine.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c math.c -o math.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c matmult.c -o matmult.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c NA.c -o NA.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c norm.c -o norm.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c qr.c -o qr.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c rand.c -o rand.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c scale.c -o scale.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c sign.c -o sign.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c solve.c -o solve.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c sum.c -o sum.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c svd.c -o svd.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c sweep.c -o sweep.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c xpose.c -o xpose.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c utils/matmult.c -o utils/matmult.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c utils/symmetrize.c -o utils/symmetrize.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -I"/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/include" -DNDEBUG   -I/usr/local/include  -fopenmp -I../inst/include/ -fpic  -g -O2  -c utils/xpose.c -o utils/xpose.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gfortran -fno-optimize-sibling-calls -fopenmp -g -O2 -msse2 -mfpmath=sse -fpic  -g -O2  -c slapack_wrap.f -o slapack_wrap.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gfortran -fno-optimize-sibling-calls -fopenmp -g -O2 -msse2 -mfpmath=sse -fpic  -g -O2  -c  lapack/la_constants.f90 -o lapack/la_constants.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gfortran -fno-optimize-sibling-calls -fopenmp -g -O2 -msse2 -mfpmath=sse -fpic  -g -O2  -c  lapack/la_xisnan.f90 -o lapack/la_xisnan.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gfortran -fno-optimize-sibling-calls -fopenmp -g -O2 -msse2 -mfpmath=sse -fpic  -g -O2  -c  lapack/sf90.f90 -o lapack/sf90.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gfortran -fno-optimize-sibling-calls -fopenmp -g -O2 -msse2 -mfpmath=sse -fpic  -g -O2  -c lapack/slapack1.f -o lapack/slapack1.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gfortran -fno-optimize-sibling-calls -fopenmp -g -O2 -msse2 -mfpmath=sse -fpic  -g -O2  -c lapack/slapack2.f -o lapack/slapack2.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gfortran -fno-optimize-sibling-calls -fopenmp -g -O2 -msse2 -mfpmath=sse -fpic  -g -O2  -c lapack/slapack3.f -o lapack/slapack3.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gfortran -fno-optimize-sibling-calls -fopenmp -g -O2 -msse2 -mfpmath=sse -fpic  -g -O2  -c lapack/slapack4.f -o lapack/slapack4.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gfortran -fno-optimize-sibling-calls -fopenmp -g -O2 -msse2 -mfpmath=sse -fpic  -g -O2  -c lapack/slamchf77.f -o lapack/slamchf77.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gfortran -fno-optimize-sibling-calls -fopenmp -g -O2 -msse2 -mfpmath=sse -fpic  -g -O2  -c lapack/ilas.f -o lapack/ilas.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gfortran -fno-optimize-sibling-calls -fopenmp -g -O2 -msse2 -mfpmath=sse -fpic  -g -O2  -c lapack/sblas.f -o lapack/sblas.o
/gsc/software/linux-x86_64-centos7/gcc-7.2.0/bin/gcc -shared -L/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/lib -L/gsc/software/linux-x86_64-centos7/gcc-7.2.0/lib64 -o float.so backsolve.o binary.o chol.o chol2inv.o colSums.o cond.o converters.o crossprod.o eigen.o extremes.o float_native.o isSymmetric.o machine.o math.o matmult.o NA.o norm.o qr.o rand.o scale.o sign.o solve.o sum.o svd.o sweep.o xpose.o utils/matmult.o utils/symmetrize.o utils/xpose.o slapack_wrap.o lapack/la_xisnan.o lapack/la_constants.o lapack/sf90.o lapack/slapack1.o lapack/slapack2.o lapack/slapack3.o lapack/slapack4.o lapack/slamchf77.o lapack/ilas.o lapack/sblas.o -lgfortran -lm -lquadmath -fopenmp -lgfortran -lm -lquadmath -L/gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/lib -lR
ar crs libfloat.a backsolve.o binary.o chol.o chol2inv.o colSums.o cond.o converters.o crossprod.o eigen.o extremes.o float_native.o isSymmetric.o machine.o math.o matmult.o NA.o norm.o qr.o rand.o scale.o sign.o solve.o sum.o svd.o sweep.o xpose.o utils/matmult.o utils/symmetrize.o utils/xpose.o slapack_wrap.o lapack/la_xisnan.o lapack/la_constants.o lapack/sf90.o lapack/slapack1.o lapack/slapack2.o lapack/slapack3.o lapack/slapack4.o lapack/slamchf77.o lapack/ilas.o lapack/sblas.o
ranlib libfloat.a
installing via 'install.libs.R' to /home/kdreval/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-float/00new/float
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
Creating a generic function for ‘backsolve’ from package ‘base’ in package ‘float’
Creating a generic function for ‘forwardsolve’ from package ‘base’ in package ‘float’
Creating a generic function for ‘chol2inv’ from ‘base’ in package ‘float’
    (from the saved implicit definition)
Creating a generic function for ‘chol2inv’ from package ‘base’ in package ‘float’
Creating a generic function for ‘colSums’ from package ‘base’ in package ‘float’
Creating a generic function for ‘rowSums’ from package ‘base’ in package ‘float’
Creating a generic function for ‘colMeans’ from package ‘base’ in package ‘float’
Creating a generic function for ‘rowMeans’ from package ‘base’ in package ‘float’
Creating a generic function for ‘rcond’ from ‘base’ in package ‘float’
    (from the saved implicit definition)
Creating a generic function for ‘rcond’ from package ‘base’ in package ‘float’
Creating a generic function for ‘typeof’ from package ‘base’ in package ‘float’
Creating a generic function for ‘storage.mode’ from package ‘base’ in package ‘float’
Creating a generic function for ‘crossprod’ from package ‘base’ in package ‘float’
Creating a generic function for ‘tcrossprod’ from package ‘base’ in package ‘float’
Creating a generic function for ‘diag’ from package ‘base’ in package ‘float’
Creating a generic function for ‘nrow’ from package ‘base’ in package ‘float’
Creating a generic function for ‘ncol’ from package ‘base’ in package ‘float’
Creating a generic function for ‘NROW’ from package ‘base’ in package ‘float’
Creating a generic function for ‘NCOL’ from package ‘base’ in package ‘float’
Creating a generic function for ‘eigen’ from package ‘base’ in package ‘float’
Creating a generic function for ‘which.min’ from package ‘base’ in package ‘float’
Creating a generic function for ‘which.max’ from package ‘base’ in package ‘float’
Creating a generic function for ‘rownames’ from package ‘base’ in package ‘float’
Creating a generic function for ‘rownames<-’ from package ‘base’ in package ‘float’
Creating a generic function for ‘colnames’ from package ‘base’ in package ‘float’
Creating a generic function for ‘colnames<-’ from package ‘base’ in package ‘float’
Creating a generic function for ‘norm’ from package ‘base’ in package ‘float’
Creating a generic function for ‘qr.Q’ from package ‘base’ in package ‘float’
Creating a generic function for ‘qr.R’ from package ‘base’ in package ‘float’
Creating a generic function for ‘qr.qy’ from package ‘base’ in package ‘float’
Creating a generic function for ‘qr.qty’ from package ‘base’ in package ‘float’
Creating a generic function for ‘La.svd’ from package ‘base’ in package ‘float’
Creating a generic function for ‘svd’ from ‘base’ in package ‘float’
    (from the saved implicit definition)
Creating a generic function for ‘svd’ from package ‘base’ in package ‘float’
Creating a generic function for ‘sweep’ from package ‘base’ in package ‘float’
** help
*** installing help indices
** building package indices
** installing vignettes
   ‘float.Rnw’ 
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘float’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/kdreval/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-float/00new/float/libs/float.so':
  /home/kdreval/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-float/00new/float/libs/float.so: undefined symbol: iparam2stage_
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/kdreval/R/x86_64-pc-linux-gnu-library/4.1/float’
Warning in install.packages :
  installation of package ‘float’ had non-zero exit status

The downloaded source packages are in
	‘/tmp/Rtmpv2XajD/downloaded_packages’

And the session info:

> sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/lib/libRblas.so
LAPACK: /gsc/software/linux-x86_64-centos7/R-4.1.3/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.1.3 tools_4.1.3  

I've seen in other issues that for older R versions installation of Rcpp helped to resolve the issue, but was not the solution in my case.
Any help will be greatly appreciated.

warnings about failed vectorization

Just FYI (compiled with clang 4.0):

scale.c:19:3: warning: loop not vectorized: failed explicitly specified loop vectorization [-Wpass-failed]
for (len_t i=0; i<m; i++)

eigen.c:13:3: warning: loop not vectorized: failed explicitly specified loop vectorization [-Wpass-failed]
for (len_t i=0; i<len/2; i++)

Interfacing with other packages

Very nice package. Thank you for fixing this significant drawback of R language. In my opinion, these two features would make float matrices even more useful:

  1. Wrapper for RcppArmadillo Mat<float> class. This would make float matrices suitable for performing in-place manipulations from the Rcpp side (e.g., SGD matrix decomposition).

  2. Being able to convert float matrix to NumPy equivalent to communicate with python libraries via reticulate (e.g., to reduce the memory requirements when preprocessing data for tensorflow or keras deep learning frameworks).

Minor issue - printing with str()

At the moment output is a bit confusing:

set.seed(1)
str(fl(x = matrix(runif(12), 4)))

Formal class 'float32' [package "float"] with 1 slot
..@ Data: int [1:4, 1:3] 1049096384 1052673798 1058186885 1063813198 1045333429 1063648478 1064425021 1059662347 1059130782 1031607194 ...

Subsetting issue

I've started to add float backend to some of my packages. So I believe I will discover some issues (and will report here). Here is first one:

library(float)
m = fl(matrix(1:4, 2, 2))
m[m < 2] = 0

Error in [<-(*tmp*, i, j, value = value) :
(subscript) logical subscript too long

However this is valid in base R.

Subsetting shenanigans

Something funky seems to be going on with subsetting:

library(spm)
m <- 10000
n <- 2500
x <- matrix(rnorm(m*n), m, n)
xs = mat2spm(x)
xs[1:10, 1:5] # works
xs[1:5, 1:10] # works
xs[1:10, 1:10] # wut?
# An spm (single precision matrix): 10x10
Error in dim(submat) <- c(toprow, topcol) :
  dims [product 50] do not match the length of object [100]

Any ideas?

PowerPC: Error in tester(s2, x2, colSums): test and truth are not equal: 'is.NA' value mismatch: 2 in current 1 in target

While I mentioned this error earlier here: #48
It is not caused by endianness misdetection (which is fixed by modifying configure to use right compiler).

R version 4.2.2 (2022-10-31) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: powerpc-apple-darwin10.8.0 (32-bit)

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> suppressPackageStartupMessages(library(float))
> set.seed(1234)
> 
> tester = function(s, x, fun)
+ {
+   test = dbl(fun(s, na.rm=TRUE))
+   truth = fun(x, na.rm=TRUE)
+   stopifnot(all.equal(test, truth, tol=tol))
+   
+   test = dbl(fun(s, na.rm=FALSE))
+   truth = fun(x, na.rm=FALSE)
+   stopifnot(all.equal(test, truth, tol=tol))
+ }
> 
> tol = 1e-6
> m = 5
> n = 3
> 
> x1 = matrix(stats::rnorm(m*n), m, n)
> x2 = x1
> x2[1, 1] = NA_real_
> x2[3, 2] = NaN
> 
> s1 = fl(x1)
> s2 = fl(x2)
> 
> 
> 
> tester(s1, x1, colSums)
> tester(s2, x2, colSums)
Error in tester(s2, x2, colSums) : test and truth are not equal:
  'is.NA' value mismatch: 2 in current 1 in target
Calls: tester -> stopifnot
Execution halted

Way to figure out size of spm in memory?

Say in the example in the README, is there a way to figure out the size of the spm, xs, is using in memory? A little helper function would be cool and appreciated as I bumble around trying to understand how this works.

Method as.matrix

The method as.matrix will convert a float32 vector into a float32 matrix.

However, as.matrix as used in other packages is meant to return a matrix object, which allows creating libraries that accept arbitrary objects from other packages without having to add them as dependencies - that is, one can create a library with a function that takes an input X, call as.matrix on it, and then pass it to a function that expects a matrix object, with the X potentially being a data.table, dgCMatrix, etc. (without adding dependencies on data.table or Matrix).

Would be nice if this package could follow this logic too, perhaps adding a different function as.float_matrix or the like that would do what as.matrix.float32 currently does.

'array' functionality

Have you given any thought to array functionality? This may be important if people want to work with float values for 3D datasets. I'm sure this would be a large undertaking but wasn't sure what previous thoughts you had on it.

gfortran warnings on macOS

Following from #2 (comment), here's the full output. I'm using Apple's Accelerate BLAS (without fully understanding why, except 'it'll be faster')

> devtools::install_github("wrathematics/spm", force = TRUE)
Using GitHub PAT from envvar GITHUB_PAT
Downloading GitHub repo wrathematics/spm@master
from URL https://api.github.com/repos/wrathematics/spm/zipball/master
Installing spm
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file  \
  --no-environ --no-save --no-restore --quiet CMD INSTALL  \
  '/private/var/folders/f1/6pjy5xbn0_9_7xwq6l7fj2yc0000gn/T/RtmpKUmZrY/devtools452cfdf648/wrathematics-spm-a504dec'  \
  --library='/Library/Frameworks/R.framework/Versions/3.4/Resources/library'  \
  --install-tests 

* installing *source* packagespm...
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to accept ISO C99... none needed
BLAS_LIBS=-L/Library/Frameworks/R.framework/Resources/lib -lRblas
LAPACK_LIBS=-L/Library/Frameworks/R.framework/Resources/lib -lRlapack
checking for echo... yes
checking for grep... yes
checking for g77... no
checking for xlf... no
checking for f77... no
checking for frt... no
checking for pgf77... no
checking for cf77... no
checking for fort77... no
checking for fl32... no
checking for af77... no
checking for xlf90... no
checking for f90... no
checking for pgf90... no
checking for pghpf... no
checking for epcf90... no
checking for gfortran... gfortran
checking whether we are using the GNU Fortran 77 compiler... yes
checking whether gfortran accepts -g... yes
Using internal single precision blas
Using internal single precision lapack
configure: creating ./config.status
config.status: creating src/Makevars
** libs
gfortran   -fPIC  -g -O2  -c lapack/slapack1.f -o lapack/slapack1.o
lapack/slapack1.f:41212:2:

 #if defined(_OPENMP)
  1
Warning: Illegal preprocessor directive
lapack/slapack1.f:41214:2:

 #endif
  1
Warning: Illegal preprocessor directive
lapack/slapack1.f:41414:2:

 #if defined(_OPENMP)
  1
Warning: Illegal preprocessor directive
lapack/slapack1.f:41422:2:

 #endif
  1
Warning: Illegal preprocessor directive
lapack/slapack1.f:41463:2:

 #if defined(_OPENMP)
  1
Warning: Illegal preprocessor directive
lapack/slapack1.f:41486:2:

 #else
  1
Warning: Illegal preprocessor directive
lapack/slapack1.f:41492:2:

 #endif
  1
Warning: Illegal preprocessor directive
lapack/slapack1.f:41503:2:

 #if defined(_OPENMP)
  1
Warning: Illegal preprocessor directive
lapack/slapack1.f:41506:2:

 #endif
  1
Warning: Illegal preprocessor directive
gfortran   -fPIC  -g -O2  -c lapack/slapack2.f -o lapack/slapack2.o
gfortran   -fPIC  -g -O2  -c lapack/slapack3.f -o lapack/slapack3.o
gfortran   -fPIC  -g -O2  -c lapack/slapack4.f -o lapack/slapack4.o
gfortran   -fPIC  -g -O2  -c lapack/slamchf77.f -o lapack/slamchf77.o
gfortran   -fPIC  -g -O2  -c lapack/ilas.f -o lapack/ilas.o
gfortran   -fPIC  -g -O2  -c lapack/sblas.f -o lapack/sblas.o
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c bracket.c -o bracket.o
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c chol.c -o chol.o
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c converters.c -o converters.o
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c crossprod.c -o crossprod.o
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c diag.c -o diag.o
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c dims.c -o dims.o
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c isSymmetric.c -o isSymmetric.o
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c matmult.c -o matmult.o
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c numbytes.c -o numbytes.o
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c solve.c -o solve.o
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c xpose.c -o xpose.o
/usr/local/clang4/bin/clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/clang4/lib -o spm.so lapack/slapack1.o lapack/slapack2.o lapack/slapack3.o lapack/slapack4.o lapack/slamchf77.o lapack/ilas.o lapack/sblas.o bracket.o chol.o converters.o crossprod.o diag.o dims.o isSymmetric.o matmult.o numbytes.o solve.o xpose.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm -fopenmp -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: warning: could not create compact unwind for _spbtrf_: stack subq instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _shseqr_: stack subq instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _sgbtrf_: stack subq instruction is too different from dwarf stack size
installing to /Library/Frameworks/R.framework/Versions/3.4/Resources/library/spm/libs
** R
** tests
** byte-compile and prepare package for lazy loading
Creating a generic function forcrossprodfrom packagebasein packagespmCreating a generic function fortcrossprodfrom packagebasein packagespmCreating a generic function fordiagfrom packagebasein packagespmCreating a generic function fornrowfrom packagebasein packagespmCreating a generic function forncolfrom packagebasein packagespmCreating a generic function forobject.sizefrom packageutilsin packagespm** help
No man pages found in packagespm*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (spm)
Reloading installed spm

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] spm_0.1-0          lubridate_1.6.0    bindrcpp_0.2      
[4] dplyr_0.7.2        readr_1.1.1        googlesheets_0.2.2
[7] colorout_1.1-2     repete_0.0.0.9008  devtools_1.13.2   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.12            git2r_0.19.0            compiler_3.4.0         
 [4] cellranger_1.1.0        pryr_0.1.2              plyr_1.8.4             
 [7] GenomeInfoDb_1.13.4     XVector_0.17.0          bindr_0.1              
[10] bitops_1.0-6            tools_3.4.0             zlibbioc_1.23.0        
[13] digest_0.6.12           evaluate_0.10.1         debugme_1.0.2          
[16] memoise_1.1.0           tibble_1.3.3            pkgconfig_2.0.1        
[19] rlang_0.1.1.9000        reprex_0.1.1            curl_2.8.1             
[22] yaml_2.1.14             parallel_3.4.0          GenomeInfoDbData_0.99.1
[25] knitr_1.16              withr_2.0.0             stringr_1.2.0          
[28] httr_1.2.1.9000         hms_0.3                 S4Vectors_0.15.5       
[31] IRanges_2.11.12         rprojroot_1.2           stats4_3.4.0           
[34] glue_1.1.1              R6_2.2.2                processx_2.0.0.1       
[37] rmarkdown_1.6           callr_1.0.0.9000        whisker_0.3-2          
[40] clipr_0.3.3             purrr_0.2.2.2           magrittr_1.5           
[43] backports_1.1.0         htmltools_0.3.6         scales_0.4.1           
[46] codetools_0.2-15        fortunes_1.5-4          BiocGenerics_0.23.0    
[49] GenomicRanges_1.29.12   assertthat_0.2.0        colorspace_1.3-2       
[52] stringi_1.1.5           RCurl_1.95-4.8          munsell_0.4.3          
[55] crayon_1.3.2 

pbdMPI + R 3.5 + Rocks 7

Hello,

pbdMPI needs float to get installed. float is not available for R 3.5 and I can not load R 3.6 on Rocks 7.

Is there a version of float which will work with R 3.5?

Integer overflow somewhere

I'm trying to create float matrix from integer representation and getting:

Error in if (len > 1) paste(len, " elements, ", sep = "") else "" :
missing value where TRUE/FALSE needed
In addition: Warning message:
In nrow(x) * ncol(x) : NAs produced by integer overflow

It seems it calculates size of array internally and it fails when it exceeds max int.

Simple reproducible example:

m = matrix(0L, 620000, 4096)
m = float32(m)

Error while linking with float on OS X

I'm getting linking error:

clang-6.0: error: no such file or directory: '/usr/local/lib/R/3.5/site-library/float/libs/float.dylib'
make: *** [rsparse.so] Error 1

I believe this is because of wrong negation here:

if (!file.exists(paste0(float_libs_dir, "/", libfile_test)))

Bug in eigen() and svd() on 32-bit Windows

Setup:

library(float)
set.seed(1234)
s = flrnorm(10, 3) # 10x3 float matrix

La.svd(s, nu=0, nv=0)

On everything but 32-bit Windows, I see:

$d
# A float32 vector: 3
[1] 3.412601 3.192742 2.107736

On 32-bit Windows, I see:

$d
# A float32 vector: 3
[1] NaN NaN NaN

This causes tests/svd.r and tests/norm.r to fail.

There is a reverse but possibly related problem for eigenvalues:

cp = crossprod(s)

eigen(cp, symmetric=TRUE, only.values=FALSE)

As before, most platforms give:

$values
# A float32 vector: 3
[1] 11.645850 10.193604  4.442551

$vectors
# A float32 matrix: 3x3
            [,1]       [,2]      [,3]
[1,]  0.75543672 -0.5654903 0.3309623
[2,] -0.64987493 -0.7110580 0.2684381
[3,] -0.08353428  0.4178721 0.9046574

while 32-bit Windows gives garbage values for the eigenvectors (whatever the os feels like using for uninitialized values), but it gives 7.594929 for each of the eigenvalues.

Machine_float not exported

I see the readme says that .Machine_float should show the information about float type for my machine, but it doesn't seem to be an exported function from the package. None of the following succeeds:

.Machine_float
float::.Machine_float
float:::.Machine_float
Machine_float
float::Machine_float
float:::Machine_float

configuration failure when R is built against external LAPACK/BLAS

The EPEL8 packages for RHEL8 etc. have this configuration, for which configure fails to find the right libraries (which I noticed because I'd deleted the lapack directory in the packaging for float):

$ R CMD config BLAS_LIBS
-lopenblas
$ R CMD config LAPACK_LIBS

$

I fixed it with a patch against the 0.2-4 source which is at

https://copr-dist-git.fedorainfracloud.org/cgit/loveshack/livhpc/R-float.git/plain/R-float-conf.patch?h=epel8

Configure test does not detect symbols with OpenBLAS in non-standard location

I've encountered two setups where the configure test is not able to detect single precision symbols, both with OpenBLAS installed in a non-standard location. The first is using OpenBLAS and R installed with Spack, and the second is using the software bundles for OpenBLAS and R on Clear Linux. The OpenBLAS libraries in these cases do contain single precision symbols. I'm pretty sure the issue is that they're installed in a non-standard location, so the linking test requires some extra linking flags. Details below.

R session info:

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /spack/apps2/linux-centos7-x86_64/gcc-11.2.0/openblas-0.3.18-42inqhyzn7ppf3me4pwbevs44hdltfse/lib/libopenblasp-r0.3.18.so

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_4.1.2 tools_4.1.2

Relevant output from configure:

checking for sgemm_ in -lRblas... no
checking for sgetrf_ in -lRblas... no
checking for sgetrf_ in -lRlapack... no

******************* Results of float package configure *******************
* OpenMP Report:
  >> OPENMP_CFLAGS=-fopenmp
  >> OMPFLAGS_C=$(SHLIB_OPENMP_CFLAGS)
* byte order: little endian
* NOTE: no single precision BLAS symbols found. Building reference version
  >> BLAS_LIBS=-L/spack/apps2/linux-centos7-x86_64/gcc-11.2.0/r-4.1.2-wcvt7hxo6vru3b2fhyapwbwibslyrqv7/rlib/R/lib -lRblas
* NOTE: no single precision LAPACK symbols found. Building reference version
  >> LAPACK_LIBS=-L/spack/apps2/linux-centos7-x86_64/gcc-11.2.0/r-4.1.2-wcvt7hxo6vru3b2fhyapwbwibslyrqv7/rlib/R/lib -lRlapack

No single precision BLAS functions detected in your R BLAS library, so we are using the reference implementation shipped with the float package. If you believe you are seeing this message in error, please contact the package maintainer.
*************************************************************************

The $R_ROOT/rlib/R/lib directory contains shared library files:

libR.so
libRblas.so
libRlapack.so

The libRblas.so file links to the external OpenBLAS library:

$ ldd libRblas.so
  linux-vdso.so.1 =>  (0x00007fffc2965000)
  libopenblas.so.0 => /spack/apps2/linux-centos7-x86_64/gcc-11.2.0/openblas-0.3.18-42inqhyzn7ppf3me4pwbevs44hdltfse/lib/libopenblas.so.0 (0x00007f2834c61000)
  libgomp.so.1 => /spack/apps2/gcc/11.2.0/lib64/libgomp.so.1 (0x00007f2834a1f000)
  libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2834803000)
  libc.so.6 => /lib64/libc.so.6 (0x00007f2834435000)
  libm.so.6 => /lib64/libm.so.6 (0x00007f2834133000)
  libgfortran.so.5 => /spack/apps2/gcc/11.2.0/lib64/libgfortran.so.5 (0x00007f2833c8c000)
  /lib64/ld-linux-x86-64.so.2 (0x00007f28376a1000)
  libdl.so.2 => /lib64/libdl.so.2 (0x00007f2833a88000)
  libquadmath.so.0 => /spack/apps/gcc/11.2.0/lib/../lib64/libquadmath.so.0 (0x00007f2833841000)
  libgcc_s.so.1 => /spack/apps/gcc/11.2.0/lib/../lib64/libgcc_s.so.1 (0x00007f2833629000)

And the libopenblas.so.0 file is actually a symlink to libopenblasp-r0.3.18.so in the same directory.

When I check config.log, I see the following:

configure:3930: checking for sgemm_ in -lRblas
configure:3955: /spack/apps2/gcc/11.2.0/bin/gcc -o conftest -O2 -mavx2 -march=x86-64 -I/usr/local/include -L/spack/apps2/linux-centos7-x86_64/gcc-11.2.0/r-4.1.2-wcvt7hxo6vru3b2fhyapwbwibslyrqv7/rlib/R/lib -Wl,-rpath,/spack/apps2/linux-centos7-x86_64/gcc-11.2.0/r-4.1.2-wcvt7hxo6vru3b2fhyapwbwibslyrqv7/rlib/R/lib -L/spack/apps2/linux-centos7-x86_64/gcc-11.2.0/r-4.1.2-wcvt7hxo6vru3b2fhyapwbwibslyrqv7/rlib/R/lib -lRblas conftest.c -lRblas  -lm  >&5
/usr/bin/ld: /tmp/cc54Bl5n.o: undefined reference to symbol 'sgemm_'
/spack/apps2/linux-centos7-x86_64/gcc-11.2.0/openblas-0.3.18-42inqhyzn7ppf3me4pwbevs44hdltfse/lib/libopenblas.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
configure:3955: $? = 1

I tried compiling the conftest program manually to see what was missing. This addition appears to be successful (adding $OPENBLAS_ROOT/lib -lopenblas):

/spack/apps2/gcc/11.2.0/bin/gcc -o conftest -O2 -mavx2 -march=x86-64 -I/usr/local/include -L/spack/apps2/linux-centos7-x86_64/gcc-11.2.0/r-4.1.2-wcvt7hxo6vru3b2fhyapwbwibslyrqv7/rlib/R/lib -Wl,-rpath,/spack/apps2/linux-centos7-x86_64/gcc-11.2.0/r-4.1.2-wcvt7hxo6vru3b2fhyapwbwibslyrqv7/rlib/R/lib -L/spack/apps2/linux-centos7-x86_64/gcc-11.2.0/r-4.1.2-wcvt7hxo6vru3b2fhyapwbwibslyrqv7/rlib/R/lib -lRblas -L/spack/apps2/linux-centos7-x86_64/gcc-11.2.0/openblas-0.3.18-42inqhyzn7ppf3me4pwbevs44hdltfse/lib -lopenblas conftest.c -lRblas -lm

I'm not sure if it's possible to generalize this in the configure script.

Alternatively, if I replace libRblas.so with a symlink from libRblas.so to libopenblas.so.0 or libopenblasp-r0.3.18.so, then the configure test does detect the single precision symbols.

Issue linking in CRAN M1 server

I'm having issues with the CRAN checks on apple M1 for a package that links to float:
https://www.stats.ox.ac.uk/pub/bdr/M1mac/recometrics.log
https://www.stats.ox.ac.uk/pub/bdr/M1mac/recometrics.out

Seems the linking is not working:

* installing *source* package ‘recometrics’ ...
** package ‘recometrics’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang++ -std=gnu++11 -I"/Users/ripley/R/R-devel/include" -DNDEBUG -D_FOR_R -I'/Users/ripley/R/Library/Rcpp/include' -I'/Users/ripley/R/Library/float/include' -I/opt/R/arm64/include   -fPIC  -g -O2  -c RcppExports.cpp -o RcppExports.o
clang++ -std=gnu++11 -I"/Users/ripley/R/R-devel/include" -DNDEBUG -D_FOR_R -I'/Users/ripley/R/Library/Rcpp/include' -I'/Users/ripley/R/Library/float/include' -I/opt/R/arm64/include   -fPIC  -g -O2  -c Rwrapper.cpp -o Rwrapper.o
clang++ -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Users/ripley/R/R-devel/lib -L/opt/R/arm64/lib -o recometrics.so RcppExports.o Rwrapper.o -L/Users/ripley/R/R-devel/lib -lRblas -L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm -L/Users/ripley/R/Library/float/libs /Users/ripley/R/Library/float/libs/float.so -Wl,-rpath /Users/ripley/R/Library/float/libs -L/Users/ripley/R/R-devel/lib -lR -Wl,-framework -Wl,CoreFoundation
installing to /Users/ripley/R/packages/tests-devel/recometrics.Rcheck/00LOCK-recometrics/00new/recometrics/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘recometrics’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/ripley/R/packages/tests-devel/recometrics.Rcheck/00LOCK-recometrics/00new/recometrics/libs/recometrics.so':
  dlopen(/Users/ripley/R/packages/tests-devel/recometrics.Rcheck/00LOCK-recometrics/00new/recometrics/libs/recometrics.so, 6): Library not loaded: float.so
  Referenced from: /Users/ripley/R/packages/tests-devel/recometrics.Rcheck/00LOCK-recometrics/00new/recometrics/libs/recometrics.so
  Reason: image not found
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Users/ripley/R/packages/tests-devel/recometrics.Rcheck/recometrics’
* using log directory ‘/Users/ripley/R/packages/tests-devel/recometrics.Rcheck’
* using R Under development (unstable) (2021-07-15 r80623)
* using platform: aarch64-apple-darwin20.5.0 (64-bit)
* using session charset: UTF-8
* using option ‘--no-stop-on-test-error’
* checking for file ‘recometrics/DESCRIPTION’ ... OK
* checking extension type ... Package
* this is package ‘recometrics’ version ‘0.1.2’
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking whether package ‘recometrics’ can be installed ... ERROR
Installation failed.
See ‘/Users/ripley/R/packages/tests-devel/recometrics.Rcheck/00install.out’ for details.
* DONE

Status: 1 ERROR
See
  ‘/Users/ripley/R/packages/tests-devel/recometrics.Rcheck/00check.log’
for details.

       12.06 real        10.47 user         1.09 sys

Works fine in other platforms though.

Windows build failing

Curiously, when I try to build float on Windows I keep getting the error on loading

Error: package or namespace load failed for 'float' in FUN(X[[i]], ...):
no such symbol R_init_NAf in package C:/Program Files/R/R-3.4.3/library/float/libs/x64/float.dll
Error: loading failed

Any idea why that would be that case?

Misdetection of endianness in Rosetta; opportunistic linking to OpenBLAS

Detection of endianness is broken in Rosetta (ppc is Big-endian):

* installing *source* package ‘float’ ...
** package ‘float’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for sinf in -lm... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /opt/local/bin/ggrep
checking for egrep... /opt/local/bin/ggrep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... no
checking size of int... 4
checking for gcc option to support OpenMP... -fopenmp
checking for echo... yes
checking for grep... yes
checking for sgemm_ in -lRblas... no
checking for sgetrf_ in -lRblas... no
checking for sgetrf_ in -lRlapack... no
checking for sgemm_ in -lopenblas... yes
checking for sgetrf_ in -lopenblas... yes
 
******************* Results of float package configure *******************
* OpenMP Report:
    >> OPENMP_CFLAGS=-fopenmp
    >> OMPFLAGS_C=$(SHLIB_OPENMP_CFLAGS)
    >> OMPFLAGS_F=$(SHLIB_OPENMP_FFLAGS)
* byte order: little endian
* using system OpenBLAS library
    >> BLAS_LIBFLAGS=-lopenblas
* using system OpenBLAS library
    >> LAPACK_LIBFLAGS=-lopenblas
*************************************************************************

In addition, it does not find Accelerate (with which R is built), but instead opportunistically links to OpenBLAS (generally undesirable behavior on older macOS).

Note: no visible binding for '<<-'

After package installation:

Note: no visible binding for '<<-' assignment to 'NA_float_'
Note: no visible binding for '<<-' assignment to '.Machine_float'

Quick googling points to this thread

Cannot use in ifelse

For some reason, it's not possible to use float32 vectors in an ifelse construct. The following line will get stuck without doing anything:

ifelse(TRUE, float::fl(1), 1)

support data.table?

Hey, thanks for making this!

I have an existing code base oriented around data.table, and I'd love to get the memory savings from using these instead of numeric. I'm wondering: would it be possible to add support for inserting vectors of these floats into a data.table as a column? It seems the class would probably have to inherit from an atomic such as vector or list to make that work.

Here's the very basic thing I have tried in R-3.3.1 with float==0.2-2 and data.table==1.9.6:

> library(float)
> library(data.table)

> ex <- fl(c(3.2, 1e7, -2.8e-4))
> dt <- data.table(foo=c('bar', 'baz', 'bar'))
> dt
   foo
1: bar
2: baz
3: bar
> dt[,float:=ex]
Error in X[[i]] : this S4 class is not subsettable

borrowing from your bracket.R:

> double_bracket_float32 = function(x, i, exact=TRUE)
{
  d = x@Data[[i, exact=exact]]
  float32(d)
}
> setMethod("[[", signature(x="float32"), double_bracket_float32)

but now:

> dt[,foo:=ex]
Error in `[.data.table`(dt, , `:=`(foo, ex)) :
  RHS of assignment is not NULL, not an an atomic vector (see ?is.atomic) and not a list column.

since data.table is running is.atomic, I think the class definition would have to inherit from an atomic to get past this.

Perhaps I could wrap your class with my own that inherits from vector or list in order to achieve my goal?

Please let me know your thoughts. Thanks!

qr.Q(float32) returns numeric

Hi here. Seems qr.Q on float32 matrix returns double matrix. Not sure if it is hard to calculate and integrate properly, but would be nice at least to convert it from double to float before returning (in order to have type-safe calculations).

Internal float representation

Don't you think that approach taken by bit64 package can be useful for float? Similarly we can store float32 as R's int but with additional attribute. This will allow to overcome some issues you described in readme. Also it will allow to easily serialize/deserialize objects..

dimnames()

library(float)
m = fl(matrix(1:4, 2, 2))
dimnames(m) = list(NULL, NULL)

Error in dimnames(m) = list(NULL, NULL) : 'dimnames' applied to non-array

Error when subsetting matrix with dimnames

float is latest from github.

m = matrix(1, 10, 10, dimnames = list(letters[1:10], NULL))
library(float)
m_fl = fl(m)
m_fl[1:5, ]

Error in dimnames(d) = dimnames(x) :
length of 'dimnames' [1] not equal to array extent

CRAN release

No an issue really, but a question. Do you have intention to release package on CRAN?
If so what is the plan? what help is needed (if any)?

Using Rcpp?

This is a particularly interesting package to me. I just glanced through the vignette and the section 'For Developers'. In it you are referring to the use of .Call() which it appears is the primary use in the package. From a development standpoint, have you tried to use Rcpp in any capacity to simplify your internal code?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.