RcppArmadillo/0000755000176000001440000000000012267661346013050 5ustar ripleyusersRcppArmadillo/inst/0000755000176000001440000000000012267623072014017 5ustar ripleyusersRcppArmadillo/inst/examples/0000755000176000001440000000000012253723621015631 5ustar ripleyusersRcppArmadillo/inst/examples/fastLm.r0000644000176000001440000001013312253723621017240 0ustar ripleyusers#!/usr/bin/r ## ## fastLm.r: Benchmarking lm() via RcppArmadillo and directly ## ## Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates ## ## This file is part of RcppArmadillo. ## ## RcppArmadillo is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 2 of the License, or ## (at your option) any later version. ## ## RcppArmadillo is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with RcppArmadillo. If not, see . library(RcppArmadillo) library(rbenchmark) src <- ' Rcpp::List fLmTwoCasts(Rcpp::NumericMatrix Xr, Rcpp::NumericVector yr) { int n = Xr.nrow(), k = Xr.ncol(); arma::mat X(Xr.begin(), n, k, false); arma::colvec y(yr.begin(), yr.size(), false); int df = n - k; // fit model y ~ X, extract residuals arma::colvec coef = arma::solve(X, y); arma::colvec res = y - X*coef; double s2 = std::inner_product(res.begin(), res.end(), res.begin(), 0.0)/df; // std.errors of coefficients arma::colvec sderr = arma::sqrt(s2 * arma::diagvec(arma::pinv(arma::trans(X)*X))); return Rcpp::List::create(Rcpp::Named("coefficients")=coef, Rcpp::Named("stderr") =sderr, Rcpp::Named("df") =df); } ' cppFunction(code=src, depends="RcppArmadillo") src <- ' Rcpp::List fLmOneCast(arma::mat X, arma::colvec y) { int df = X.n_rows - X.n_cols; // fit model y ~ X, extract residuals arma::colvec coef = arma::solve(X, y); arma::colvec res = y - X*coef; double s2 = std::inner_product(res.begin(), res.end(), res.begin(), 0.0)/df; // std.errors of coefficients arma::colvec sderr = arma::sqrt(s2 * arma::diagvec(arma::pinv(arma::trans(X)*X))); return Rcpp::List::create(Rcpp::Named("coefficients")=coef, Rcpp::Named("stderr") =sderr, Rcpp::Named("df") =df); } ' cppFunction(code=src, depends="RcppArmadillo") src <- ' Rcpp::List fLmConstRef(const arma::mat & X, const arma::colvec & y) { int df = X.n_rows - X.n_cols; // fit model y ~ X, extract residuals arma::colvec coef = arma::solve(X, y); arma::colvec res = y - X*coef; double s2 = std::inner_product(res.begin(), res.end(), res.begin(), 0.0)/df; // std.errors of coefficients arma::colvec sderr = arma::sqrt(s2 * arma::diagvec(arma::pinv(arma::trans(X)*X))); return Rcpp::List::create(Rcpp::Named("coefficients")=coef, Rcpp::Named("stderr") =sderr, Rcpp::Named("df") =df); } ' cppFunction(code=src, depends="RcppArmadillo") fastLmPureDotCall <- function(X, y) { .Call("RcppArmadillo_fastLm", X, y, PACKAGE = "RcppArmadillo") } y <- log(trees$Volume) X <- cbind(1, log(trees$Girth)) frm <- formula(log(Volume) ~ log(Girth)) res <- benchmark(fLmOneCast(X, y), # inline'd above fLmTwoCasts(X, y), # inline'd above fLmConstRef(X, y), # inline'd above fastLmPure(X, y), # similar, but with 2 error checks fastLmPureDotCall(X, y), # now without the 2 error checks fastLm(frm, data=trees), # using model matrix lm.fit(X, y), # R's fast function, no stderr lm(frm, data=trees), # R's standard function columns = c("test", "replications", "relative", "elapsed", "user.self", "sys.self"), order="relative", replications=5000) print(res[,1:4]) RcppArmadillo/inst/examples/kalman/0000755000176000001440000000000012253723621017074 5ustar ripleyusersRcppArmadillo/inst/examples/kalman/kalmanM.m0000644000176000001440000000177012253723621020637 0ustar ripleyusersfunction Y = kalmanM(pos) dt=1; %% Initialize state transition matrix A=[ 1 0 dt 0 0 0;... % [x ] 0 1 0 dt 0 0;... % [y ] 0 0 1 0 dt 0;... % [Vx] 0 0 0 1 0 dt;... % [Vy] 0 0 0 0 1 0 ;... % [Ax] 0 0 0 0 0 1 ]; % [Ay] H = [ 1 0 0 0 0 0; 0 1 0 0 0 0 ]; % Initialize measurement matrix Q = eye(6); R = 1000 * eye(2); x_est = zeros(6, 1); % x_est=[x,y,Vx,Vy,Ax,Ay]' p_est = zeros(6, 6); numPts = size(pos,1); Y = zeros(numPts, 2); for idx = 1:numPts z = pos(idx, :)'; %% Predicted state and covariance x_prd = A * x_est; p_prd = A * p_est * A' + Q; %% Estimation S = H * p_prd' * H' + R; B = H * p_prd'; klm_gain = (S \ B)'; %% Estimated state and covariance x_est = x_prd + klm_gain * (z - H * x_prd); p_est = p_prd - klm_gain * H * p_prd; %% Compute the estimated measurements Y(idx, :) = H * x_est; end % of the function end % of the function RcppArmadillo/inst/examples/kalman/kalmanExample.m0000644000176000001440000000012312253723621022025 0ustar ripleyusersfunction x = kalmanExample load pos.txt; # renamed here x = kalmanM(pos); endRcppArmadillo/inst/examples/kalman/pos.txt0000644000176000001440000002327212253723621020444 0ustar ripleyusers -4.76074274e-01 8.27344982e-01 -4.66073333e-01 8.25346801e-01 -4.56071632e-01 8.21349631e-01 -4.46068539e-01 8.15353570e-01 -4.36063422e-01 8.07358714e-01 -4.26055649e-01 7.97365162e-01 -4.16044587e-01 7.85373011e-01 -4.06029604e-01 7.71382359e-01 -3.96010067e-01 7.55393303e-01 -3.85985344e-01 7.37405941e-01 -3.75954804e-01 7.17420370e-01 -3.65917812e-01 6.95436687e-01 -3.55873738e-01 6.71454991e-01 -3.45821948e-01 6.45475379e-01 -3.35761811e-01 6.17497948e-01 -3.25692694e-01 5.87522796e-01 -3.15613964e-01 5.55550021e-01 -3.05524990e-01 5.21579720e-01 -2.95425138e-01 4.85611990e-01 -2.85313778e-01 4.47646929e-01 -2.75190275e-01 4.07684635e-01 -2.65053998e-01 3.65725205e-01 -2.54904315e-01 3.21768737e-01 -2.44740592e-01 2.75815328e-01 -2.34562199e-01 2.27865076e-01 -2.24368501e-01 1.77918079e-01 -2.14158868e-01 1.25974433e-01 -2.03932667e-01 7.20342366e-02 -1.93689265e-01 1.60975872e-02 -1.83428030e-01 -4.18354177e-02 -1.73148329e-01 -1.01764681e-01 -1.62849531e-01 -1.63690104e-01 -1.52531002e-01 -2.27611590e-01 -1.42192111e-01 -2.93529041e-01 -1.31832225e-01 -3.61442361e-01 -1.21450712e-01 -4.31351450e-01 -1.11046940e-01 -5.03256212e-01 -1.00620275e-01 -5.77156550e-01 -9.01700865e-02 -6.53052365e-01 -7.96957410e-02 -7.30943560e-01 -6.91966066e-02 -8.10830038e-01 -5.86720509e-02 -8.92711700e-01 -4.81214414e-02 -9.68723398e-01 -3.75441458e-02 -8.82849846e-01 -2.69395318e-02 -7.98971187e-01 -1.63069671e-02 -7.17087322e-01 -5.64581912e-03 -6.37198155e-01 5.04454433e-03 -5.59303588e-01 1.57647557e-02 -4.83403523e-01 2.65154472e-02 -4.09497862e-01 3.72972513e-02 -3.37586509e-01 4.81108004e-02 -2.67669365e-01 5.89567268e-02 -1.99746334e-01 6.98356629e-02 -1.33817317e-01 8.07482410e-02 -6.98822165e-02 9.16950935e-02 -7.94093586e-03 1.02676853e-01 5.20066229e-02 1.13694151e-01 1.09960557e-01 1.24747621e-01 1.65920965e-01 1.35837894e-01 2.19887943e-01 1.46965604e-01 2.71861590e-01 1.58131383e-01 3.21842002e-01 1.69335862e-01 3.69829278e-01 1.80579674e-01 4.15823514e-01 1.91863452e-01 4.59824809e-01 2.03187829e-01 5.01833260e-01 2.14553435e-01 5.41848965e-01 2.25960904e-01 5.79872020e-01 2.37410868e-01 6.15902524e-01 2.48903960e-01 6.49940575e-01 2.60440811e-01 6.81986269e-01 2.72022055e-01 7.12039704e-01 2.83648323e-01 7.40100978e-01 2.95320248e-01 7.66170188e-01 3.07038462e-01 7.90247432e-01 3.18803597e-01 8.12332807e-01 3.30616287e-01 8.32426411e-01 3.42477163e-01 8.50528342e-01 3.54386857e-01 8.66638696e-01 3.66346003e-01 8.80757573e-01 3.78355232e-01 8.92885068e-01 3.90415176e-01 9.03021280e-01 4.02526469e-01 9.11166306e-01 4.14689742e-01 9.17320243e-01 4.26905628e-01 9.21483190e-01 4.39174759e-01 9.23655244e-01 4.51497768e-01 9.23836502e-01 4.63875286e-01 9.22027062e-01 4.76307947e-01 9.18227021e-01 4.88796383e-01 9.12436477e-01 5.01341225e-01 9.04655528e-01 5.13943106e-01 8.94884271e-01 5.26602660e-01 8.83122803e-01 5.39320517e-01 8.69371222e-01 5.52097311e-01 8.53629626e-01 5.64933673e-01 8.35898112e-01 5.77830237e-01 8.16176778e-01 5.90787634e-01 7.94465721e-01 6.03806497e-01 7.70765039e-01 6.16887458e-01 7.45074829e-01 6.16887458e-01 7.45074829e-01 2.43647025e-01 3.48142367e-01 -1.29593408e-01 -4.87900946e-02 -5.02833841e-01 -4.45722556e-01 -8.76074274e-01 -8.42655018e-01 -8.76074274e-01 -8.42655018e-01 -8.66073333e-01 -8.14653199e-01 -8.56071632e-01 -7.88650369e-01 -8.46068539e-01 -7.64646430e-01 -8.36063422e-01 -7.42641286e-01 -8.26055649e-01 -7.22634838e-01 -8.16044587e-01 -7.04626989e-01 -8.06029604e-01 -6.88617641e-01 -7.96010067e-01 -6.74606697e-01 -7.85985344e-01 -6.62594059e-01 -7.75954804e-01 -6.52579630e-01 -7.65917812e-01 -6.44563313e-01 -7.55873738e-01 -6.38545009e-01 -7.45821948e-01 -6.34524621e-01 -7.35761811e-01 -6.32502052e-01 -7.25692694e-01 -6.32477204e-01 -7.15613964e-01 -6.34449979e-01 -7.05524990e-01 -6.38420280e-01 -6.95425138e-01 -6.44388010e-01 -6.85313778e-01 -6.52353071e-01 -6.75190275e-01 -6.62315365e-01 -6.65053998e-01 -6.74274795e-01 -6.54904315e-01 -6.88231263e-01 -6.44740592e-01 -7.04184672e-01 -6.34562199e-01 -7.22134924e-01 -6.24368501e-01 -7.42081921e-01 -6.14158868e-01 -7.64025567e-01 -6.03932667e-01 -7.87965763e-01 -5.93689265e-01 -8.13902413e-01 -5.83428030e-01 -8.41835418e-01 -5.73148329e-01 -8.71764681e-01 -5.62849531e-01 -9.03690104e-01 -5.52531002e-01 -9.37611590e-01 -5.42192111e-01 -9.71782807e-01 -5.31832225e-01 -9.33867676e-01 -5.21450712e-01 -8.97948315e-01 -5.11046940e-01 -8.64024627e-01 -5.00620275e-01 -8.32096515e-01 -4.90170086e-01 -8.02163879e-01 -4.79695741e-01 -7.74226624e-01 -4.69196607e-01 -7.48284652e-01 -4.58672051e-01 -7.24337865e-01 -4.48121441e-01 -7.02386165e-01 -4.37544146e-01 -6.82429455e-01 -4.26939532e-01 -6.64467637e-01 -4.16306967e-01 -6.48500614e-01 -4.05645819e-01 -6.34528289e-01 -3.94955456e-01 -6.22550563e-01 -3.84235244e-01 -6.12567339e-01 -3.73484553e-01 -6.04578520e-01 -3.62702749e-01 -5.98584009e-01 -3.51889200e-01 -5.94583707e-01 -3.41043273e-01 -5.92577517e-01 -3.30164337e-01 -5.92565341e-01 -3.19251759e-01 -5.94547083e-01 -3.08304907e-01 -5.98522644e-01 -2.97323147e-01 -6.04491926e-01 -2.86305849e-01 -6.12454834e-01 -2.75252379e-01 -6.22411268e-01 -2.64162106e-01 -6.34361131e-01 -2.53034396e-01 -6.48304326e-01 -2.41868617e-01 -6.64240755e-01 -2.30664138e-01 -6.82170321e-01 -2.19420326e-01 -7.02092926e-01 -2.08136548e-01 -7.24008473e-01 -1.96812171e-01 -7.47916863e-01 -1.85446565e-01 -7.73818000e-01 -1.74039096e-01 -8.01711787e-01 -1.62589132e-01 -8.31598124e-01 -1.51096040e-01 -8.63476915e-01 -1.39559189e-01 -8.97348063e-01 -1.27977945e-01 -9.33211470e-01 -1.16351677e-01 -9.71067037e-01 -1.04679752e-01 -9.34397179e-01 -9.29615383e-02 -8.92555770e-01 -8.11964026e-02 -8.52706229e-01 -6.93837130e-02 -8.14848460e-01 -5.75228372e-02 -7.78982364e-01 -4.56131427e-02 -7.45107844e-01 -3.36539972e-02 -7.13224802e-01 -2.16447683e-02 -6.83333142e-01 -9.58482365e-03 -6.55432765e-01 2.52646905e-03 -6.29523574e-01 1.46897422e-02 -6.05605471e-01 2.69056281e-02 -5.83678358e-01 3.91747593e-02 -5.63742139e-01 5.14977679e-02 -5.45796716e-01 6.38752864e-02 -5.29841991e-01 7.63079472e-02 -5.15877866e-01 8.87963825e-02 -5.03904245e-01 1.01341225e-01 -4.93921029e-01 1.13943106e-01 -4.85928121e-01 1.26602660e-01 -4.79925423e-01 1.39320517e-01 -4.75912839e-01 1.52097311e-01 -4.73890270e-01 1.64933673e-01 -4.73857618e-01 1.77830237e-01 -4.75814787e-01 1.90787634e-01 -4.79761679e-01 2.03806497e-01 -4.85698196e-01 2.16887458e-01 -4.93624240e-01 2.16887458e-01 -4.93624240e-01 4.01147025e-01 -1.33381935e-01 5.85406592e-01 2.26860371e-01 7.69666159e-01 5.87102676e-01 9.53925726e-01 9.47344982e-01 9.53925726e-01 9.47344982e-01 9.43926667e-01 9.15346801e-01 9.33928368e-01 8.81349631e-01 9.23931461e-01 8.45353570e-01 9.13936578e-01 8.07358714e-01 9.03944351e-01 7.67365162e-01 8.93955413e-01 7.25373011e-01 8.83970396e-01 6.81382359e-01 8.73989933e-01 6.35393303e-01 8.64014656e-01 5.87405941e-01 8.54045196e-01 5.37420370e-01 8.44082188e-01 4.85436687e-01 8.34126262e-01 4.31454991e-01 8.24178052e-01 3.75475379e-01 8.14238189e-01 3.17497948e-01 8.04307306e-01 2.57522796e-01 7.94386036e-01 1.95550021e-01 7.84475010e-01 1.31579720e-01 7.74574862e-01 6.56119899e-02 7.64686222e-01 -2.35307073e-03 7.54809725e-01 -7.23153647e-02 7.44946002e-01 -1.44274795e-01 7.35095685e-01 -2.18231263e-01 7.25259408e-01 -2.94184672e-01 7.15437801e-01 -3.72134924e-01 7.05631499e-01 -4.52081921e-01 6.95841132e-01 -5.34025567e-01 6.86067333e-01 -6.17965763e-01 6.76310735e-01 -7.03902413e-01 6.66571970e-01 -7.91835418e-01 6.56851671e-01 -8.81764681e-01 6.47150469e-01 -9.71621744e-01 6.37468998e-01 -8.77698446e-01 6.27807889e-01 -7.85771114e-01 6.18167775e-01 -6.95839649e-01 6.08549288e-01 -6.07903955e-01 5.98953060e-01 -5.21963934e-01 5.89379725e-01 -4.38019487e-01 5.79829914e-01 -3.56070518e-01 5.70304259e-01 -2.76116929e-01 5.60803393e-01 -1.98158623e-01 5.51327949e-01 -1.22195502e-01 5.41878559e-01 -4.82274683e-02 5.32455854e-01 2.37455755e-02 5.23060468e-01 9.37237269e-02 5.13693033e-01 1.61707083e-01 5.04354181e-01 2.27695743e-01 4.95044544e-01 2.91689802e-01 4.85764756e-01 3.53689360e-01 4.76515447e-01 4.13694512e-01 4.67297251e-01 4.71705358e-01 4.58110800e-01 5.27721993e-01 4.48956727e-01 5.81744517e-01 4.39835663e-01 6.33773026e-01 4.30748241e-01 6.83807619e-01 4.21695093e-01 7.31848392e-01 4.12676853e-01 7.77895442e-01 4.03694151e-01 8.21948869e-01 3.94747621e-01 8.64008769e-01 3.85837894e-01 9.04075239e-01 3.76965604e-01 9.42148378e-01 3.68131383e-01 9.78228282e-01 3.59335862e-01 1.01231505e+00 3.50579674e-01 1.01027937e+00 3.41863452e-01 9.80180397e-01 3.33187829e-01 9.48088578e-01 3.24553435e-01 9.14004012e-01 3.15960904e-01 8.77926796e-01 3.07410868e-01 8.39857030e-01 2.98903960e-01 7.99794810e-01 2.90440811e-01 7.57740233e-01 2.82022055e-01 7.13693397e-01 2.73648323e-01 6.67654401e-01 2.65320248e-01 6.19623340e-01 2.57038462e-01 5.69600313e-01 2.48803597e-01 5.17585418e-01 2.40616287e-01 4.63578752e-01 2.32477163e-01 4.07580412e-01 2.24386857e-01 3.49590496e-01 2.16346003e-01 2.89609102e-01 2.08355232e-01 2.27636326e-01 2.00415176e-01 1.63672267e-01 1.92526469e-01 9.77170229e-02 1.84689742e-01 2.97706900e-02 1.76905628e-01 -4.01666337e-02 1.69174759e-01 -1.12094851e-01 1.61497768e-01 -1.86013863e-01 1.53875286e-01 -2.61923574e-01 1.46307947e-01 -3.39823885e-01 1.38796383e-01 -4.19714700e-01 1.31341225e-01 -5.01595920e-01 1.23943106e-01 -5.85467448e-01 1.16602660e-01 -6.71329186e-01 1.09320517e-01 -7.59181037e-01 1.02097311e-01 -8.49022904e-01 9.49336734e-02 -9.40854688e-01 8.78302370e-02 -9.10635555e-01 8.07876341e-02 -8.14822416e-01 7.38064970e-02 -7.20998902e-01 6.68874582e-02 -6.29164916e-01 RcppArmadillo/inst/examples/kalman/KalmanRimp.R0000644000176000001440000000244412253723621021256 0ustar ripleyusers## Improved version supplied by one referee, not shown in paper KalmanRimp <- function(pos) { kalmanfilter <- function(z) { ## predicted state and covriance xprd <- xest %*% A pprd <- crossprod(pest %*% A, A) + Q ## estimation B <- crossprod(H, pprd) S <- B %*% H + R ## kalmangain <- (S \ B)' kalmangain <- solve(S, B) ## estimated state and covariance, assign to vars in parent env xest <<- xprd + (z - xprd %*% H) %*% kalmangain pest <<- pprd - pprd %*% H %*% kalmangain ## compute the estimated measurements y <- xest %*% H } dt <- 1 A <- matrix( c( 1, 0, dt, 0, 0, 0, # x 0, 1, 0, dt, 0, 0, # y 0, 0, 1, 0, dt, 0, # Vx 0, 0, 0, 1, 0, dt, # Vy 0, 0, 0, 0, 1, 0, # Ax 0, 0, 0, 0, 0, 1), # Ay 6, 6, byrow=FALSE) H <- matrix( c(1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), 6, 2, byrow=FALSE) Q <- diag(6) R <- 1000 * diag(2) N <- nrow(pos) y <- matrix(NA, N, 2) xest <- matrix(0, 1, 6) pest <- matrix(0, 6, 6) for (i in 1:N) { y[i,] <- kalmanfilter(pos[i,,drop=FALSE]) } invisible(y) } RcppArmadillo/inst/examples/kalman/kalmanfilter.m0000644000176000001440000000173012253723621021724 0ustar ripleyusers% Copyright 2010 The MathWorks, Inc. function y = kalmanfilter(z) dt=1; % Initialize state transition matrix A=[ 1 0 dt 0 0 0; 0 1 0 dt 0 0;... % [x ], [y ] 0 0 1 0 dt 0; 0 0 0 1 0 dt;... % [Vx], [Vy] 0 0 0 0 1 0 ; 0 0 0 0 0 1 ]; % [Ax], [Ay] H = [ 1 0 0 0 0 0; 0 1 0 0 0 0 ]; % Init. measuremnt mat Q = eye(6); R = 1000 * eye(2); persistent x_est p_est % Init. state cond. if isempty(x_est) x_est = zeros(6, 1); % x_est=[x,y,Vx,Vy,Ax,Ay]' p_est = zeros(6, 6); end x_prd = A * x_est; % Predicted state and covariance p_prd = A * p_est * A' + Q; S = H * p_prd' * H' + R; % Estimation B = H * p_prd'; klm_gain = (S \ B)'; % Estimated state and covariance x_est = x_prd + klm_gain * (z - H * x_prd); p_est = p_prd - klm_gain * H * p_prd; y = H * x_est; % Compute the estimated measurements end % of the function RcppArmadillo/inst/examples/kalman/benchmark.R0000644000176000001440000000225112253723621021151 0ustar ripleyusers suppressMessages(library(utils)) suppressMessages(library(RcppArmadillo)) suppressMessages(library(rbenchmark)) suppressMessages(library(compiler)) source("FirstKalmanR.R") source("KalmanR.R") source("KalmanRimp.R") sourceCpp("Kalman.cpp") FirstKalmanRC <- cmpfun(FirstKalmanR) KalmanRC <- cmpfun(KalmanR) KalmanRimpC <- cmpfun(KalmanRimp) ## Read data, ensure identical results pos <- as.matrix(read.table("pos.txt", header=FALSE, col.names=c("x","y"))) stopifnot(all.equal(KalmanR(pos), KalmanRC(pos)), all.equal(KalmanRC(pos), KalmanCpp(pos)), all.equal(KalmanCpp(pos), FirstKalmanRC(pos)), all.equal(KalmanCpp(pos), FirstKalmanR(pos)), all.equal(KalmanCpp(pos), KalmanRimp(pos)), all.equal(KalmanCpp(pos), KalmanRimpC(pos))) res <- benchmark(KalmanR(pos), KalmanRC(pos), KalmanRimp(pos), KalmanRimpC(pos), FirstKalmanR(pos), FirstKalmanRC(pos), KalmanCpp(pos), columns = c("test", "replications", "elapsed", "relative"), order="relative", replications=500) print(res[,1:4]) RcppArmadillo/inst/examples/kalman/firstExample.R0000644000176000001440000000045712253723621021670 0ustar ripleyusers library(RcppArmadillo) cppFunction(code=' Rcpp::List g(arma::colvec v) { arma::mat op = v * v.t(); double ip = arma::as_scalar(v.t() * v); return Rcpp::List::create(Rcpp::Named("outer")=op, Rcpp::Named("inner")=ip); } ', depends="RcppArmadillo") g(7:11) RcppArmadillo/inst/examples/kalman/FirstKalmanR.R0000644000176000001440000000221412253723621021553 0ustar ripleyusersFirstKalmanR <- function(pos) { kalmanfilter <- function(z) { dt <- 1 A <- matrix(c( 1, 0, dt, 0, 0, 0, 0, 1, 0, dt, 0, 0, # x, y 0, 0, 1, 0, dt, 0, 0, 0, 0, 1, 0, dt, # Vx, Vy 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1), # Ax, Ay 6, 6, byrow=TRUE) H <- matrix( c(1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), 2, 6, byrow=TRUE) Q <- diag(6) R <- 1000 * diag(2) xprd <- A %*% xest # predicted state and covriance pprd <- A %*% pest %*% t(A) + Q S <- H %*% t(pprd) %*% t(H) + R # estimation B <- H %*% t(pprd) kalmangain <- t(solve(S, B)) ## estimated state and covariance, assign to vars in parent env xest <<- xprd + kalmangain %*% (z - H %*% xprd) pest <<- pprd - kalmangain %*% H %*% pprd ## compute the estimated measurements y <- H %*% xest } xest <- matrix(0, 6, 1) pest <- matrix(0, 6, 6) N <- nrow(pos) y <- matrix(NA, N, 2) for (i in 1:N) { y[i,] <- kalmanfilter(t(pos[i,,drop=FALSE])) } invisible(y) } RcppArmadillo/inst/examples/kalman/KalmanR.R0000644000176000001440000000232212253723621020543 0ustar ripleyusersKalmanR <- function(pos) { kalmanfilter <- function(z) { ## predicted state and covariance xprd <- A %*% xest pprd <- A %*% pest %*% t(A) + Q ## estimation S <- H %*% t(pprd) %*% t(H) + R B <- H %*% t(pprd) kalmangain <- t(solve(S, B)) ## estimated state and covariance ## assigned to vars in parent env xest <<- xprd + kalmangain %*% (z - H %*% xprd) pest <<- pprd - kalmangain %*% H %*% pprd ## compute the estimated measurements y <- H %*% xest } dt <- 1 A <- matrix( c( 1, 0, dt, 0, 0, 0, # x 0, 1, 0, dt, 0, 0, # y 0, 0, 1, 0, dt, 0, # Vx 0, 0, 0, 1, 0, dt, # Vy 0, 0, 0, 0, 1, 0, # Ax 0, 0, 0, 0, 0, 1), # Ay 6, 6, byrow=TRUE) H <- matrix( c(1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), 2, 6, byrow=TRUE) Q <- diag(6) R <- 1000 * diag(2) N <- nrow(pos) Y <- matrix(NA, N, 2) xest <- matrix(0, 6, 1) pest <- matrix(0, 6, 6) for (i in 1:N) { Y[i,] <- kalmanfilter(t(pos[i,,drop=FALSE])) } invisible(Y) } RcppArmadillo/inst/examples/kalman/Kalman.cpp0000644000176000001440000000255212253723621021007 0ustar ripleyusers // [[Rcpp::depends(RcppArmadillo)]] #include using namespace arma; class Kalman { private: mat A, H, Q, R, xest, pest; double dt; public: // constructor, sets up data structures Kalman() : dt(1.0) { A.eye(6,6); A(0,2) = A(1,3) = A(2,4) = A(3,5) = dt; H.zeros(2,6); H(0,0) = H(1,1) = 1.0; Q.eye(6,6); R = 1000 * eye(2,2); xest.zeros(6,1); pest.zeros(6,6); } // sole member function: estimate model mat estimate(const mat & Z) { unsigned int n = Z.n_rows, k = Z.n_cols; mat Y = zeros(n, k); mat xprd, pprd, S, B, kalmangain; colvec z, y; for (unsigned int i = 0; i. ## load Rcpp to be able to use cppFunction() below suppressMessages(library(Rcpp)) ## parameter and error terms used throughout a <- matrix(c(0.5,0.1,0.1,0.5),nrow=2) e <- matrix(rnorm(10000),ncol=2) ## Let's start with the R version rSim <- function(coeff, errors) { simdata <- matrix(0, nrow(errors), ncol(errors)) for (row in 2:nrow(errors)) { simdata[row,] = coeff %*% simdata[(row-1),] + errors[row,] } return(simdata) } rData <- rSim(a, e) # generated by R ## Now let's load the R compiler (requires R 2.13 or later) suppressMessages(require(compiler)) compRsim <- cmpfun(rSim) compRData <- compRsim(a,e) # generated by R 'compiled' stopifnot(all.equal(rData, compRData)) # checking results ## C++ variant: code passed as a text variable ... code <- ' arma::mat rcppSim(const arma::mat& coeff, const arma::mat& errors) { int m = errors.n_rows; int n = errors.n_cols; arma::mat simdata(m,n); simdata.row(0) = arma::zeros(1,n); for (int row=1; row extern "C" SEXP fastLm(SEXP ys, SEXP Xs) { Rcpp::NumericVector yr(ys); // creates Rcpp vector from SEXP Rcpp::NumericMatrix Xr(Xs); // creates Rcpp matrix from SEXP int n = Xr.nrow(), k = Xr.ncol(); arma::mat X(Xr.begin(), n, k, false); // reuses memory and avoids extra copy arma::colvec y(yr.begin(), yr.size(), false); arma::colvec coef = arma::solve(X, y); // fit model y ~ X arma::colvec res = y - X*coef; // residuals double s2 = std::inner_product(res.begin(), res.end(), res.begin(), double())/(n - k); // std.errors of coefficients arma::colvec stderr = arma::sqrt(s2 * arma::diagvec( arma::inv(arma::trans(X)*X) )); return Rcpp::List::create(Rcpp::Named("coefficients") = coef, Rcpp::Named("stderr") = stderr, Rcpp::Named("df") = n - k ); } Note however that you may not want to compute a linear regression fit this way in order to protect from numerical inaccuracies on rank-deficient problems. The help page for fastLm() provides an example. ===== Using RcppArmadillo in other packages ===== RcppArmadillo is designed so that its classes can be used from other packages. Using RcppArmadillo requires: - Using the header files provided by Rcpp and RcppArmadillo. This is typically achieved by adding this line in the DESCRIPTION file of the client package: LinkingTo : Rcpp, RcppArmadillo and the following line in the package code: #include - Linking against Rcpp dynamic or shared library and librairies needed by Armadillo, which is achieved by adding this line in the src/Makevars file of the client package: PKG_LIBS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" ) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) and this line in the file src/Makevars.win: PKG_LIBS = $(shell Rscript.exe -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) RcppArmadillo contains a function RcppArmadillo.package.skeleton, modelled after package.skeleton from the utils package in base r, that creates a skeleton of a package using RcppArmadillo, including example code. ===== Quality Assurance ===== RcppArmadillo uses the RUnit package by Matthias Burger et al to provide unit testing. RcppArmadillo currently has 19 unit tests (called from 8 unit test functions). Source code for unit test functions are stored in the unitTests directory of the installed package and the results are collected in the "RcppArmadillo-unitTests" vignette. We run unit tests before sending the package to CRAN on as many systems as possible, including Mac OSX (Snow Leopard), Debian, Ubuntu, Fedora 12 (64bit), Win 32 and Win64. Unit tests can also be run from the installed package by executing RcppArmadillo:::test() where an output directory can be provided as an optional first argument. ===== Links ===== Armadillo : http://arma.sourceforge.net/ RcppArmadillo main page: http://dirk.eddelbuettel.com/code/rcpp.armadillo.html R-forge Rcpp project page: http://r-forge.r-project.org/projects/rcpp/ Dirk's blog : http://dirk.eddelbuettel.com/blog/code/rcpp/ Romain's blog : http://romainfrancois.blog.free.fr/index.php?category/R-package/RcppArmadillo ===== Support ===== Questions about RcppArmadillo should be directed to the Rcpp-devel mailing list at https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel Questions about Armadillo itself should be directed to its forum http://sourceforge.net/apps/phpbb/arma/ -- Romain Francois, Montpellier, France Dirk Eddelbuettel, Chicago, IL, USA Doug Bates, Madison, WI, USA May 2010 RcppArmadillo/inst/NEWS.Rd0000644000176000001440000010677012267622326015076 0ustar ripleyusers\name{NEWS} \title{News for Package 'RcppArmadillo'} \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} \section{Changes in RcppArmadillo version 0.4.000.2 (2014-01-21)}{ \itemize{ \item Upgraded to Armadillo release Version 4.000.2 \itemize{ \item fix for \code{randi()} generating out-of-interval values \item workaround for a bug in the Intel compiler } } } \section{Changes in RcppArmadillo version 0.4.000 (2014-01-05)}{ \itemize{ \item Upgraded to Armadillo release Version 4.000 (Feral Steamroller) \itemize{ \item added eigen decompositions of sparse matrices: \code{eigs_sym()} and \code{eigs_gen()} [ but this requires linking against ARPACK which \cpkg{RcppArmadillo} as a pure-template package does not do, and R is not linked against ARPACK either. ] \item added eigen decomposition for pair of matrices: \code{eig_pair()} \item added simpler forms of \code{eig_gen()} \item added condition number of matrices: \code{cond()} \item expanded \code{find()} to handle cubes \item expanded subcube views to access elements specified in a vector \item template argument for \code{running_stat_vec} expanded to accept vector types \item more robust fast inverse of 4x4 matrices \item faster divide-and-conquer decompositions are now used by default for \code{eig_sym()}, \code{pinv()}, \code{princomp()}, \code{rank()}, \code{svd()}, \code{svd_econ()} \item the form \code{inv(sympd(X))} no longer assumes that X is positive definite; use \code{inv_sympd()} instead \item added MEX connector for interfacing Octave/Matlab with Armadillo matrices (contributed by George Yammine) } } } \section{Changes in RcppArmadillo version 0.3.930.1 (2013-12-09)}{ \itemize{ \item Upgraded to Armadillo release Version 3.930.1 \itemize{ \item Armadillo falls back to standard complex svd if the more performant divide-and-conquer variant is unavailable } \item Added detection for Lapack library and distinguish between R's own version (withhout zgesdd) and system Lapack; a preprocessor define is set accordingly } } \section{Changes in RcppArmadillo version 0.3.930.0 (2013-12-06)}{ \itemize{ \item Upgraded to Armadillo release Version 3.930 ("Dragon's Back") \itemize{ \item added divide-and-conquer variant of \code{svd_econ()}, for faster SVD \item added divide-and-conquer variant of \code{pinv()}, for faster pseudo-inverse \item added element-wise variants of \code{min()} and \code{max()} \item added \code{size()} based specifications of submatrix view sizes \item added \code{randi()} for generating matrices with random integer values \item added more intuitive specification of sort direction in \code{sort()} and \code{sort_index()} \item added more intuitive specification of method in \code{det()}, \code{.i()}, \code{inv()} and \code{solve()} \item added more precise timer for the \code{wall_clock} class when using C++11 } \item New unit tests for complex matrices and vectors } } \section{Changes in RcppArmadillo version 0.3.920.3 (2013-11-20)}{ \itemize{ \item Upgraded to Armadillo release Version 3.920.3 \itemize{ \item fix for handling of tiny matrices by \code{.swap()} } } } \section{Changes in RcppArmadillo version 0.3.920.1 (2013-09-27)}{ \itemize{ \item Upgraded to Armadillo release Version 3.920.1 (Agencia Nacional Stasi) \itemize{ \item faster \code{.zeros()} \item faster \code{round()}, \code{exp2()} and \code{log2()} when using C++11 \item added signum function: \code{sign()} \item added move constructors when using C++11 \item added 2D fast Fourier transform: \code{fft2()} \item added \code{.tube()} for easier extraction of vectors and subcubes from cubes \item added specification of a fill type during construction of Mat, Col, Row and Cube classes, eg. \code{mat X(4, 5, fill::zeros)} } \item Initial implementation of \code{wrap} \item Improved implementation of \code{as<>()} and \code{wrap()} for sparse matrices \item Converted main vignette from \code{LaTeX} style \code{minted} to \code{lstlisting} which permits builds on CRAN; removed set \code{BuildVignettes: FALSE}. } } \section{Changes in RcppArmadillo version 0.3.910.0 (2013-08-12)}{ \itemize{ \item Upgraded to Armadillo release Version 3.910.0 (Pyrenees) \itemize{ \item faster multiplication of a matrix with a transpose of itself, ie. \code{X*X.t()} and \code{X.t()*X} \item added \code{vectorise()} for reshaping matrices into vectors \item added \code{all()} and \code{any()} for indicating presence of elements satisfying a relational condition } \item Added conversion support for sparse matrices (of type double) created by the \cpkg{Matrix} package as class \code{dgCMatrix} \item Moved vignette sources from \code{inst/doc} to \code{vignettes}; set \code{BuildVignettes: FALSE} as the \code{minted} mode for \code{LaTeX} upsets the CRAN builders. } } \section{Changes in RcppArmadillo version 0.3.900.7 (2013-08-02)}{ \itemize{ \item Upgraded to Armadillo release Version 3.900.7 (Bavarian Sunflower) \itemize{ \item minor fix for inplace \code{reshape()} \item minor corrections for compilation issues under GCC 4.8+ and MSVC } \item Corrected setting of \code{vec_stats} in intialization of row, vector and matrix objects \item The \pkg{inline} package is no longer used in the examples and unit tests which have all been converted to using Rcpp attributes } } \section{Changes in RcppArmadillo version 0.3.900 (2013-06-04)}{ \itemize{ \item Upgraded to Armadillo release Version 3.900.0 (Bavarian Sunflower) \itemize{ \item added automatic SSE2 vectorisation of elementary expressions (eg. matrix addition) when using GCC 4.7+ with -O3 optimisation \item added support for saving & loading of cubes in HDF5 format, contributed by Szabolcs Horvat \item faster \code{median()}, contributed by Ruslan Shestopalyuk \item faster handling of compound expressions with transposes of submatrix rows \item faster handling of compound expressions with transposes of complex vectors } \item Kalman filter example switched from inline to \code{sourceCpp}, which simplifies / streamlines the C++ side a little } } \section{Changes in RcppArmadillo version 0.3.820 (2013-05-12)}{ \itemize{ \item Upgraded to Armadillo release Version 3.820 (Mt Cootha) \itemize{ \item faster \code{as_scalar()} for compound expressions \item faster transpose of small vectors \item faster matrix-vector product for small vectors \item faster multiplication of small fixed size matrices } } } \section{Changes in RcppArmadillo version 0.3.810.2 (2013-04-30)}{ \itemize{ \item Upgraded to Armadillo release Version 3.810.2 \itemize{ \item minor fix for initialisation of sparse matrices } } } \section{Changes in RcppArmadillo version 0.3.810.0 (2013-04-19)}{ \itemize{ \item Upgraded to Armadillo release Version 3.810.0 (Newell Highway) \itemize{ \item added fast Fourier transform: \code{fft()} \item added handling of \code{.imbue()} and \code{.transform()} by submatrices and subcubes \item added batch insertion constructors for sparse matrices \item minor fix for multiplication of complex sparse matrices } \item Updated sample() function and test again contributed by Christian Gunning } } \section{Changes in RcppArmadillo version 0.3.800.1 (2013-03-12)}{ \itemize{ \item Upgraded to Armadillo release Version 3.800.1 (Miami Beach) \itemize{ \item workaround for a bug in ATLAS 3.8 on 64 bit systems \item faster matrix-vector multiply for small matrices } \item Added new sample() function and tests contributed by Christian Gunning \item Refactored unit testing code for faster unit test performance } } \section{Changes in RcppArmadillo version 0.3.800.0 (2013-03-01)}{ \itemize{ \item Upgraded to Armadillo release Version 3.800.0 (Miami Beach) \itemize{ \item Armadillo is now licensed using the Mozilla Public License 2.0 \item added \code{.imbue()} for filling a matrix/cube with values provided by a functor or lambda expression \item added \code{.swap()} for swapping contents with another matrix \item added \code{.transform()} for transforming a matrix/cube using a functor or lambda expression \item added \code{round()} for rounding matrix elements towards nearest integer \item faster \code{find()} \item fixes for handling non-square matrices by \code{qr()} and \code{qr_econ()} \item minor fixes for handling empty matrices \item reduction of pedantic compiler warnings } \item Updated vignette to paper now in press at CSDA \item Added CITATION file with reference to CSDA paper } } \section{Changes in RcppArmadillo version 0.3.6.3 (2013-02-20)}{ \itemize{ \item Upgraded to Armadillo release Version 3.6.3 \itemize{ \item faster \code{find()} \item minor fix for non-contiguous submatrix views to handle empty vectors of indices \item reduction of pedantic compiler warnings } } } \section{Changes in RcppArmadillo version 0.3.6.2 (2013-01-29)}{ \itemize{ \item Upgraded to Armadillo release Version 3.6.2 \itemize{ \item faster determinant for matrices marked as diagonal or triangular \item more fine-grained handling of 64 bit integers } \item Added a new example of a Kalman filter implementation in R, and C++ using Armadillo via RcppArmadillo, complete with timing comparison } } \section{Changes in RcppArmadillo version 0.3.6.1 (2012-12-17)}{ \itemize{ \item Upgraded to Armadillo release Version 3.6.1 (Piazza del Duomo) \itemize{ \item faster \code{trace()} \item fix for handling sparse matrices by \code{dot()} \item fixes for interactions between sparse and dense matrices } \item Now throws compiler error if \code{Rcpp.h} is included before \code{RcppArmadillo.h} (as the former is included automatically by the latter anyway, but template logic prefers this ordering). } } \section{Changes in RcppArmadillo version 0.3.4.3 (2012-10-04)}{ \itemize{ \item Upgraded to Armadillo release 3.4.3 \itemize{ \item fix for aliasing issue in \code{diagmat()} \item fix for \code{speye()} signature } } } \section{Changes in RcppArmadillo version 0.3.4.2 (2012-09-25)}{ \itemize{ \item Upgraded to Armadillo release 3.4.2 \itemize{ \item minor fixes for handling sparse submatrix views \item minor speedups for sparse matrices } } } \section{Changes in RcppArmadillo version 0.3.4.1 (2012-09-18)}{ \itemize{ \item Upgraded to Armadillo release 3.4.1 \itemize{ \item workaround for a bug in the Mac OS X accelerate framework \item fixes for handling empty sparse matrices \item added documentation for saving & loading matrices in HDF5 format \item faster dot() and cdot() for complex numbers } } } \section{Changes in RcppArmadillo version 0.3.4.0 (2012-09-06)}{ \itemize{ \item Upgraded to Armadillo release 3.4.0 (Ku De Ta) \itemize{ \item added economical QR decomposition: qr_econ() \item added .each_col() & .each_row() for vector operations repeated on each column or row \item added preliminary support for sparse matrices, contributed by Ryan Curtin et al. (Georgia Institute of Technology) \item faster singular value decomposition via divide-and-conquer algorithm \item faster .randn() } \item NEWS file converted to Rd format } } \section{Changes in RcppArmadillo version 0.3.3.91 (2012-08-30)}{ \itemize{ \item Upgraded to Armadillo release 3.3.91 \itemize{ \item faster singular value decomposition via "divide and conquer" algorithm \item added economical QR decomposition: qr_econ() \item added .each_col() & .each_row() for vector operations repeated on each column or row \item added preliminary support for sparse matrices, contributed by Ryan Curtin, James Cline and Matthew Amidon (Georgia Institute of Technology) } \item Corrected summary method to deal with the no intercept case when using a formula; also display residual summary() statistics \item Expanded unit tests for fastLm } } \section{Changes in RcppArmadillo version 0.3.2.4 (2012-07-11)}{ \itemize{ \item Upgraded to Armadillo release 3.2.4 \itemize{ \item workaround for a regression (bug) in GCC 4.7.0 and 4.7.1 } } } \section{Changes in RcppArmadillo version 0.3.2.3 (2012-07-01)}{ \itemize{ \item Upgraded to Armadillo release 3.2.3 \itemize{ \item minor correction for declaration of fixed size vectors and matrices \item Reverted three header files \{Mat,Row,Col\}_bones.hpp back to previous release due to compilation failures under g++-4.7 \item Added new vignette 'RcppArmadillo-intro' based on a just-submitted introductory paper (by Eddelbuettel and Sanderson) about RcppArmadillo \item Change from release 3.2.2 which we skipped as it did not really affect builds under R: \itemize{ \item minor fix for compiling without debugging enabled (aka release mode) \item better detection of ATLAS during installation on Fedora and Red Hat systems } \item Small enhancement to fastLm } } } \section{Changes in RcppArmadillo version 0.3.2.0 (2012-05-21)}{ \itemize{ \item Upgraded to Armadillo release 3.2.0 "Creamfields" \itemize{ \item faster eigen decomposition via "divide and conquer" algorithm \item faster transpose of vectors and compound expressions \item faster handling of diagonal views \item faster handling of tiny fixed size vectors (≤ 4 elements) \item added unique(), for finding unique elements of a matrix } } } \section{Changes in RcppArmadillo version 0.3.1.94 (2012-05-15)}{ \itemize{ \item Upgraded to Armadillo release 3.1.94 "v3.2 beta 2" \itemize{ \item added unique(), for finding unique elements of a matrix \item faster eigen decomposition via "divide and conquer" algorithm \item faster transpose of vectors and compound expressions \item faster handling of tiny fixed size vectors (≤ 4 elements) } } } \section{Changes in RcppArmadillo version 0.3.1.92 (2012-05-10)}{ \itemize{ \item Upgraded to Armadillo release 3.1.92 "v3.2 beta 2" \itemize{ \item added unique(), for finding unique elements of a matrix \item faster eigen decomposition via optional use of "divide and conquer" by eig_sym() \item faster transpose of vectors and compound expressions } } } \section{Changes in RcppArmadillo version 0.3.0.3 (2012-05-03)}{ \itemize{ \item Upgraded to Armadillo release 3.0.3 \itemize{ \item fixes for inplace transpose of complex number matrices \item fixes for complex number version of svd_econ() \item fixes for potential aliasing issues with submatrix views } \item New example script fastLm } } \section{Changes in RcppArmadillo version 0.3.0.2 (2012-04-19)}{ \itemize{ \item Upgraded to Armadillo release 3.0.2 \itemize{ \item fixes for handling diagonal matrices } \item Undefine NDEBUG if it has been set (as R does) as this prevents a number of useful debugging checks. Users can still define it or define ARMA_NO_DEBUG if they want a 'non-development' build } } \section{Changes in RcppArmadillo version 0.3.0.1 (2012-04-12)}{ \itemize{ \item Upgraded to Armadillo release 3.0.1 \itemize{ \item fixes for compilation errors \item fixes for potential aliasing issues } } } \section{Changes in RcppArmadillo version 0.3.0 (2012-04-10)}{ \itemize{ \item Upgraded to Armadillo release 3.0.0 "Antarctic Chilli Ranch" \itemize{ \item added non-contiguous submatrix views \item added shorthand for inverse: .i() \item added hist() and histc() \item faster repmat() \item faster handling of submatrix views with one row or column \item faster generation of random numbers \item faster element access in fixed size matrices \item better detection of vector expressions by sum(), cumsum(), prod(), min(), max(), mean(), median(), stddev(), var() \item expressions X=A.i()*B and X=inv(A)*B are automatically converted to X=solve(A,B) } } } \section{Changes in RcppArmadillo version 0.2.40 (2012-04-04)}{ \itemize{ \item Upgraded to Armadillo release 2.99.4 "Antarctic Chilli Ranch (Beta 4)" \itemize{ \item fixes for handling expressions with fixed size matrices } } } \section{Changes in RcppArmadillo version 0.2.39 (2012-04-02)}{ \itemize{ \item Upgraded to Armadillo release 2.99.3 "Antarctic Chilli Ranch (Beta 3)" \itemize{ \item faster repmat() \item workarounds for braindead compilers (eg. Visual Studio) } } } \section{Changes in RcppArmadillo version 0.2.38 (2012-03-28)}{ \itemize{ \item Upgraded to Armadillo release 2.99.2 "Antarctic Chilli Ranch (Beta 2)" \itemize{ \item added .i() \item much faster handling of .col() and .row() \item expressions X=A.i()*B and X=inv(A)*B are automatically converted to X=solve(A,B) } } } \section{Changes in RcppArmadillo version 0.2.37 (2012-03-19)}{ \itemize{ \item Upgraded to Armadillo release 2.99.1 "Antarctic Chilli Ranch (Beta 1)" \itemize{ \item added non-contiguous submatrix views \item added hist() and histc() \item faster handling of submatrix views \item faster generation of random numbers \item faster element access in fixed size matrices \item better detection of vector expressions by sum(), cumsum(), prod(), min(), max(), mean(), median(), stddev(), var() } } } \section{Changes in RcppArmadillo version 0.2.36 (2012-03-05)}{ \itemize{ \item Upgraded to Armadillo release 2.4.4 \itemize{ \item fixes for qr() and syl() \item more portable wall_clock class \item faster relational operators on submatrices } } } \section{Changes in RcppArmadillo version 0.2.35 (2012-02-17)}{ \itemize{ \item Upgraded to Armadillo release 2.4.3 \itemize{ \item Support for ARMA_DEFAULT_OSTREAM using Rcpp::Rcout added \item Minor bug fix release improving corner cases affecting builds: \itemize{ \item Missing semicolon added in Mat_meat (when in C++0x mode), with thanks to Teo Guo Ci \item Armadillo version vars now instantiated in RcppArmadillo.cpp which helps older g++ versions, with thanks to Gershon Bialer \item Thanks also to Martin Renner for testing these changes \item Unit tests output fallback directory changed per Brian Ripley's request to not ever use /tmp \item Minor update to version numbers in RcppArmadillo-package.Rd } } } } \section{Changes in RcppArmadillo version 0.2.34 (2011-12-12)}{ \itemize{ \item Upgraded to Armadillo release 2.4.2 \itemize{ \item clarified documentation for .reshape() \item fix for handling of empty matrices by .resize() } } } \section{Changes in RcppArmadillo version 0.2.33 (2011-12-07)}{ \itemize{ \item Upgraded to Armadillo release 2.4.1 \itemize{ \item added .resize() \item fix for vector initialisation } } } \section{Changes in RcppArmadillo version 0.2.32 (2011-12-04)}{ \itemize{ \item Upgraded to Armadillo test release 2.4.0 "Loco Lounge Lizard" \item Minimal changes relative to 0.2.31 based on 2.3.92, next section is relative to the previous stable release series 2.2.* of Armadillo \itemize{ \item added shorter forms of transposes: .t() and .st() \item added optional use of 64 bit indices, allowing matrices to have more than 4 billion elements \item added experimental support for C++11 initialiser lists \item faster pinv() \item faster inplace transpose \item faster handling of expressions with diagonal views \item fixes for handling expressions with aliasing and submatrices \item fixes for linking on Ubuntu and Debian systems \item fixes for inconsistencies in interactions between matrices and cubes \item refactored code to eliminate warnings when using the Clang C++ compiler \item .print_trans() and .raw_print_trans() are deprecated } } } \section{Changes in RcppArmadillo version 0.2.31 (2011-11-28)}{ \itemize{ \item Upgraded to Armadillo test release 2.3.92 "Loco Lounge Lizard (Beta 2)" \itemize{ \item fixes for linking on Ubuntu and Debian systems \item fixes for inconsistencies in interactions between matrices and cubes } } } \section{Changes in RcppArmadillo version 0.2.30 (2011-11-19)}{ \itemize{ \item Upgraded to Armadillo test release 2.3.91 "Loco Lounge Lizard (Beta 1)" \itemize{ \item added shorter forms of transposes: .t() and .st() \item added optional use of 64 bit indices, allowing matrices to have more than 4 billion elements \item added experimental support for C++11 initialiser lists \item faster pinv() \item faster inplace transpose \item bugfixes for handling expressions with aliasing and submatrices \item refactored code to eliminate warnings when using the Clang C++ compiler \item .print_trans() and .raw_print_trans() are deprecated } } } \section{Changes in RcppArmadillo version 0.2.29 (2011-09-01)}{ \itemize{ \item Upgraded to Armadillo release 2.2.3 \itemize{ \item Release fixes a speed issue in the as_scalar() function. } } } \section{Changes in RcppArmadillo version 0.2.28 (2011-08-02)}{ \itemize{ \item Upgraded to Armadillo release 2.2.1 "Blue Skies Debauchery" \itemize{ \item faster multiplication of small matrices \item faster trans() \item faster handling of submatrices by norm() \item added economical singular value decomposition: svd_thin() \item added circ_toeplitz() \item added .is_colvec() & .is_rowvec() \item fixes for handling of complex numbers by cov(), cor(), running_stat_vec } } } \section{Changes in RcppArmadillo version 0.2.27 (2011-07-22)}{ \itemize{ \item Upgraded to Armadillo release 2.1.91 "v2.2 beta 1" \itemize{ \item faster multiplication of small matrices \item faster trans() \item faster handling of submatrices by norm() \item added economical singular value decomposition: svd_thin() \item added circ_toeplitz() \item added .is_colvec() & .is_rowvec() } } } \section{Changes in RcppArmadillo version 0.2.26 (2011-07-17)}{ \itemize{ \item Upgraded to Armadillo release 2.0.2 \itemize{ \item fix for handling of conjugate transpose by as_scalar() \item fix for handling of aliasing by diagmat() \item fix for handling of empty matrices by symmatu()/symmatl() } } } \section{Changes in RcppArmadillo version 0.2.25 (2011-06-30)}{ \itemize{ \item Upgraded to Armadillo 2.0.1 which fixes two minor compilation issues } } \section{Changes in RcppArmadillo version 0.2.24 (2011-06-29)}{ \itemize{ \item Upgraded to Armadillo release 2.0.0 "Carnivorous Sugar Glider" \itemize{ \item faster multiplication of tiny matrices (≤ 4x4) \item faster compound expressions containing submatrices \item faster inverse of symmetric positive definite matrices \item faster element access for fixed size matrices \item added handling of arbitrarily sized empty matrices (eg. 5x0) \item added loading & saving of matrices as CSV text files \item added .count() member function to running_stat and running_stat_vec \item added syl(), strans(), symmatu()/symmatl() \item added submatrices of submatrices \item det(), inv() and solve() can be forced to use more precise \item algorithms for tiny matrices (≤ 4x4) \item htrans() has been deprecated; use trans() instead \item API change: trans() now takes the complex conjugate when transposing a complex matrix \item API change: .is_vec() now outputs true for empty vectors (eg. 0x1) \item API change: forms of chol(), eig_sym(), eig_gen(), inv(), lu(), pinv(), princomp(), qr(), solve(), svd(), syl() that do not return a bool indicating success now throw std::runtime_error exceptions when failures are detected \item API change: princomp_cov() has been removed; princomp() in conjunction with cov() can be used instead \item API change: set_log_stream() & get_log_stream() have been replaced by set_stream_err1() & get_stream_err1() } } } \section{Changes in RcppArmadillo version 0.2.23 (2011-06-23)}{ \itemize{ \item Upgraded to Armadillo release 1.99.5 "v2.0 beta 5" \itemize{ \item Forms of chol(), eig_sym(), eig_gen(), inv(), lu(), pinv(), princomp(), qr(), solve(), svd(), syl() that do not return a bool indicating success now throw std::runtime_error exceptions when failures are detected \item princomp_cov() has been removed; princomp() in conjunction with cov() can be used instead \item set_log_stream() & get_log_stream() have been replaced by set_stream_err1() & get_stream_err1() \item det(), inv() and solve() can be forced to use more precise algorithms for tiny matrices (≤ 4x4) \item Added loading & saving of matrices as CSV text files } \item fastLmPure() now uses same argument order as R's lm.fit() \item Export and document S3 methods in NAMESPACE and manual page as such } } \section{Changes in RcppArmadillo version 0.2.22 (2011-06-06)}{ \itemize{ \item Upgraded to Armadillo release 1.99.4 "v2.0 beta 4" \itemize{ \item fixes for handling of tiny matrices } } } \section{Changes in RcppArmadillo version 0.2.21 (2011-05-27)}{ \itemize{ \item Upgraded to Armadillo release 1.99.3 "v2.0 beta 3" \itemize{ \item stricter size checking for row and column vectors \item added .count() member function to running_stat and running_stat_vec } } } \section{Changes in RcppArmadillo version 0.2.20 (2011-05-25)}{ \itemize{ \item Upgraded to Armadillo release 1.99.2 "v2.0 beta 2" (and 1.99.1 before) \itemize{ \item faster inverse of symmetric matrices \item faster element access for fixed size matrices \item faster multiplication of tiny matrices (eg. 4x4) \item faster compund expressions containing submatrices \item added handling of arbitrarily sized empty matrices (eg. 5x0) \item added syl() \item added strans() \item added symmatu()/symmatl() \item added submatrices of submatrices \item htrans() has been deprecated; use trans() instead \item trans() now takes the complex conjugate when transposing a complex matrix \item .is_vec() now outputs true for empty matrices \item most functions with matrix inputs no longer throw exceptions when given empty matrices (eg. 5x0) } \item Added a new subdirectory examples/ seeded with a nice Vector Autoregression simulation simulation example by Lance Bachmeier \item Rewrote armadillo_version as to no longer require an instance of arma::arma_version, with tanks to Conrad for the suggestion } } \section{Changes in RcppArmadillo version 0.2.19 (2011-04-18)}{ \itemize{ \item Upgraded to Armadillo version 1.2.0 "Unscrupulous Carbon Emitter" \itemize{ \item Added ability to use Blas & Lapack libraries with capitalised function names \item Reduction of pedantic compiler warnings } } } \section{Changes in RcppArmadillo version 0.2.18 (2011-04-03)}{ \itemize{ \item Upgraded to Armadillo version 1.1.92 "Jurassic Barbecue" \itemize{ \item Bugfix in cor() \item Automatic installation now requires CMake >= 2.6 } } } \section{Changes in RcppArmadillo version 0.2.17 (2011-03-22)}{ \itemize{ \item Upgraded to Armadillo version 1.1.90 "Inside Job" \itemize{ \item Added .min() & .max(), which can provide the extremum's location \item More robust mean(), var(), stddev() } } } \section{Changes in RcppArmadillo version 0.2.16 (2011-03-10)}{ \itemize{ \item Upgraded to Armadillo version 1.1.8 "Kangaroo Steak" \itemize{ \item Added floor() and ceil() \item Added “not a number”: math::nan() \item Added infinity: math::inf() \item Added standalone is_finite() \item Faster min(), max(), mean() \item Bugfix for a corner case with NaNs in min() and max() } } } \section{Changes in RcppArmadillo version 0.2.15 (2011-03-04)}{ \itemize{ \item Upgraded to Armadillo version 1.1.6 “Baby Carpet Shark” \itemize{ \item fixed size matrices and vectors can use auxiliary (external) memory \item .in_range() can use span() arguments \item subfields can use span() arguments } } } \section{Changes in RcppArmadillo version 0.2.14 (2011-03-02)}{ \itemize{ \item Support Run-Time Type Information (RTTI) on matrices by setting the state variable vec_state in Row and Col instantiation, with thanks to Conrad Sanderson for the hint \item fastLm code simplified further by instantiating the Armadillo matrix and vector directly from the SEXP coming from R \item inst/doc/Makefile now respects $R_HOME environment variable } } \section{Changes in RcppArmadillo version 0.2.13 (2011-02-18)}{ \itemize{ \item Upgraded to Armadillo version 1.1.4 “Manta Lodge” \itemize{ \item Faster sort() \item Updated installation to detect recent versions of Intel's MKL \item Added interpretation of arbitrary "flat" subcubes as matrices } } } \section{Changes in RcppArmadillo version 0.2.12 (2011-02-15)}{ \itemize{ \item Upgraded to Armadillo version 1.1.2 “Flood Kayak” \itemize{ \item Faster prod() \item Faster solve() for compound expressions \item Fix for compilation using GCC's C++0x mode \item Fix for matrix handling by subcubes } } } \section{Changes in RcppArmadillo version 0.2.11 (2011-01-06)}{ \itemize{ \item Upgraded to Armadillo version 1.1.0 “Climate Vandal” \itemize{ \item Extended submatrix views, including access to elements whose indices are specified in a separate vector \item Added handling of raw binary files by save/load functions \item Added cumsum() \item Added interpretation of matrices as triangular via trimatu()/trimatl() \item Faster solve(), inv() via explicit handling of triangular matrices \item The stream for logging of errors and warnings can now be changed } \item New unexported R function SHLIB, a small wrapper around R CMD SHLIB, which can be used as Rscript -e "RcppArmadillo:::SHLIB('foo.cpp')" } } \section{Changes in RcppArmadillo version 0.2.10 (2010-11-25)}{ \itemize{ \item Upgraded to Armadillo 1.0.0 "Antipodean Antileech" \itemize{ \item After 2 1/2 years of collaborative development, we are proud to release the 1.0 milestone version. \item Many thanks are extended to all contributors and bug reporters. } \item R/RcppArmadillo.package.skeleton.R: Updated to no longer rely on GNU make for builds of packages using RcppArmadillo \item summary() for fastLm() objects now returns r.squared and adj.r.squared } } \section{Changes in RcppArmadillo version 0.2.9 (2010-11-11)}{ \itemize{ \item Upgraded to Armadillo 0.9.92 "Wall Street Gangster": \itemize{ \item Fixes for compilation issues under the Intel C++ compiler \item Added matrix norms } } } \section{Changes in RcppArmadillo version 0.2.8 (2010-10-16)}{ \itemize{ \item Upgraded to Armadillo 0.9.90 "Water Dragon": \itemize{ \item Added unsafe_col() \item Speedups and bugfixes in lu() \item Minimisation of pedantic compiler warnings } \item Switched NEWS and ChangeLog between inst/ and the top-level directory so that NEWS (this file) gets installed with the package } } \section{Changes in RcppArmadillo version 0.2.7 (2010-09-25)}{ \itemize{ \item Upgraded to Armadillo 0.9.80 "Chihuahua Muncher": \itemize{ \item Added join_slices(), insert_slices(), shed_slices() \item Added in-place operations on diagonals \item Various speedups due to internal architecture improvements } } } \section{Changes in RcppArmadillo version 0.2.6 (2010-09-12)}{ \itemize{ \item Upgraded to Armadillo 0.9.70 "Subtropical Winter Safari" \item arma::Mat, arma::Row and arma::Col get constructor that take vector or matrix sugar expressions. See the unit test "test.armadillo.sugar.ctor" and "test.armadillo.sugar.matrix.ctor" for examples. } } \section{Changes in RcppArmadillo version 0.2.5 (2010-08-05)}{ \itemize{ \item Upgraded to Armadillo 0.9.60 "Killer Bush Turkey" } } \section{Changes in RcppArmadillo version 0.2.4 (2010-07-27)}{ \itemize{ \item Upgraded to Armadillo 0.9.52 'Monkey Wrench' \item src/fastLm.cpp: Switch from inv() to pinv() as inv() now tests for singular matrices and warns and returns an empty matrix which stops the example fastLm() implementation on the manual page -- and while this is generally reasonably it makes sense here to continue which the Moore-Penrose pseudo-inverse allows us to do this } } \section{Changes in RcppArmadillo version 0.2.3 (2010-06-14)}{ \itemize{ \item Better configuration to detect suncc (which does not have std::isfinite) } } \section{Changes in RcppArmadillo version 0.2.2 (2010-06-09)}{ \itemize{ \item Added RcppArmadillo:::CxxFlags for cases where RcppArmadillo is not used via a package \item Upgraded to Armadillo 0.9.10 'Chilli Espresso' \item Wrap support for mtOp, i.e. operations involving mixed types such as a complex and an arma::mat, which have been introduced in armadillo 0.9.10 \item Wrap support for mtGlue, i.e. operations involving matrices of mixed types such as an arma::mat and an arma::imat, which have been introduced in armadillo 0.9.10 \item Included an inline plugin to support the plugin system introduced in inline 0.3.5. The unit tests have moved from the src directory to the unit test directory (similar to Rcpp) using cxxfunction with the RcppArmadillo plugin. } } \section{Changes in RcppArmadillo version 0.2.1 (2010-05-19)}{ \itemize{ \item Bug-fix release permitting compilation on Windows } } \section{Changes in RcppArmadillo version 0.2.0 (2010-05-18)}{ \itemize{ \item fastLm() is now generic and has a formula interface as well as methods for print, summary, predict to behave like a standard model fitting function \item Armadillo sources (using release 0.9.8) are now included in the package using a standardized build suitable for our purposes (not assuming Boost or Atlas) -- see ?RcppArmadillo for details \item New R function RcppArmadillo.package.skeleton, similar to Rcpp::Rcpp.package.skeleton, but targetting use of RcppArmadillo } } \section{Changes in RcppArmadillo version 0.1.0 (2010-03-11)}{ \itemize{ \item the fastLm() implementation of a bare-bones lm() fit (using Armadillo's solve() function) provides an example of how efficient code can be written compactly using the combination of Rcpp, RcppAramadillo and Armadillo \item support for Rcpp implicit wrap of these types : Mat, Col, Row, Cube where T is one of : int, unsigned int, double, float \item support for Rcpp implicit as of these types : Mat, Col, Row where R is one of : int, unsigned int, double, float } } RcppArmadillo/inst/doc/0000755000176000001440000000000012267623072014564 5ustar ripleyusersRcppArmadillo/inst/doc/RcppArmadillo-intro.pdf0000644000176000001440000122162712267623072021154 0ustar ripleyusers%PDF-1.5 % 34 0 obj << /Length 3033 /Filter /FlateDecode >> stream xڭYK 0Udn{&dv'YxfAKDPs_U|B}|uyMxOY)D&Ó,0*8 t{[Rு_ ~Ze6Qn6%~*7vucX txkys%S2˃< $8R^0e3 [Gq"B֏[IiJ_`%AFL3|$*E2I@fA]{l Ʌ@1{A0LS 3zDv,@k*b},Fѐ+:"Sc7ņԇyk:4Vl|d D!"dhl*kh34/O[˗3nka;=\.YF{$Sm (HTK{Xeڿ}XWo e,5O( ͏oyy c-zҩu]o x7-t> Śe?1z| I6[{~ I-}V=&nxB'躸HV7nQb*!$ $ @OUA .=!I,ܡd6R8@'q(S|(儆zv֌ͦGCJ#Ł<;J5[x o- e 8]ؼH.H&` s@]4isIw(;ANK5G9˦ epۅ,Y7QF@N2|6 )cm'F /{+w`?fM] y̛!9y"Pŝ`k8 +0Hʠb=6Z1BUZe8P'ng-7m77AGG0UaFA29CN@%l"%s66~ྻO?إe@wBR]3w f }C4`qŻkq86| px#7Wz#b4m= ۏMQ9$'rd)ds%O56$DG.yYřcK_۹@ũ "iM!<9>pڛh G`曢tbJg˂9vDYi;+ޥ̾T|"Wy)CJJ( F5:~ e7CѳKS+ ٜz-CӌE>Jia4=ҰuSvȒ~ yyC1bEu&6֮zżK.PzoZJ]-MiTrx98X믤`lJ,6 ˹y6dDY*d׆fIϑ}I&~v{c8OK\i ilwvSÛ($cޞI **x`՞x8|~/Mv[cJnљb.&uE#Ph4?v_eESIa=SQL[\:B+c,6,\H-ԡͤZ!)uwa(J/mLW]Ox_iرp1OhF5UX\V4+D |wջ@P[C ù_e#(6C!f:JuD$r˹#Z՟šw'.q>CڨL`E\(DBRB{aOQr[yHWi {/ ؖQBj,ߔRa6]8r=7]@f[ ,u93pf^CtJ?H菶5EfTn > stream xڽZK-TKor؎]Jj=S΁8lITDɳ_~ EivW. 4@яMVhͫHݿzu9*7a'IX$ϊ$~94iOM:빙Ҥ _H@Wc?ig$}yw5}A:N'yl{xY3z6wYU&{|*"};HP1S-NOa>mp=cط<Ц,ϭKC<>wB_^hR˱]ҧV,# oӠ(Nܵ9}(oMǽr>%1Fb?'5.@ײd]xZ>SsCRK8K@kwܚ,nQtx8KK̖a$w3Ȍz/IOLo (Ѻ-Oq6HKu8Sck1 2` [,`*|)rGuͿ5wJJcMxKAֳ(9xc w7Fښ$^|eT 9={2r xk]~n'PLUy3WJ_lԆ6/1 nHz|Ǚ1yy  i8qܚp-u.%9.!?K)U99Ո7}%pYvZS {7!2#jqFo]{{lW EĐlxs=Fz,hѬ)86zD8Vdaʱח,$'xTE0Gr9GFxLXnEx(Eٍdx\qBҡ;6󝺏bb>(/(,bs㎷i&i|#nR}jC}VQ;/ γMAD1X\3r` vWHh8Rl̄'ye2c%}\4Y,`h3Dpȕ4 9 2,TǚC ,e!g Yg莸Pq֑ݛ&eaYQ), AX_&&Q9 qi 38c\h:tP<G"דL# #q}ym,E߿E{$D@`uFə8.zzzZQv+e:cTk4KQyXl"tbffn•: jn}cp1:&qAu<0cg',+ bB1)0M-HV-܎6,RL؎2\ ,[\h`k0>mrqvOT JF{ETy:uP PqԨAȅ:n<YRciR:o%2 vTxMn<_JT(&m6ޜ~T I"ۺ:R$XB ()rO2ArRm3uM3Yk +yr3 ݝj5Tw8skXX@5H$Y**_Bx$?+~b zE#q`oչ&-{T SMֳdiE=z WpJ7N4iɗ;V+0pa,GK8ۇMX%~1aNi$սM|ՓԲq#ғgQk?S[#ڌ\$Nv%Z$)i# 9ndr!H)DJq idY܆=O +OWVګ}ERjiBRÖּD. (Ut+_+X 7δ8XVr0{\s6^ o 8`R_I*?.R%qUW, ̸rت:E窮:o80M =*ܓq+X&>4 H='O+tu\ onwS@YLr &|t,FlV$^S+QHZbdK6VԃS)V{?w;P҄݅jI.Q3M *]9}k(w1~M|(i3#wuW. QF/Bt\L;VVysX//.q=+7\VP;wF8:aRF [-sqyZQnvrU {. v=쒀dк%! L{I#goa|bW<_r=F ]ҔˌGn,DS^mJϹ4J{sY]`>*!N6z֌>\w8_#TGKj8x1}%.|v.Asc-'U5JOQMTEca6K<%|Ol#.a Ӱdw0=, ޫboɔri/'`[ɰTUV9Wqm}U='(?ػ%l%Ϣ"Z]jۻYzp kl yc2VriRxcpuvBGZZ'{{*Ll23UX 4_ݿ/- endstream endobj 117 0 obj << /Length 3405 /Filter /FlateDecode >> stream xڭZ[o~ϯ#rxGч$ P8F4EKjDQ% eRn>̹~f.> ݛw?rUf&[=,8^Y|etq^niq*zL,W#M_ZahI}c`{߹qN]ilQ_kkpHͲL#kAu-2:ۤny0`E2[, yy{1 &p7$psg*0Lv{G| iBܳ`깧…U;2zU\bsC?cG-9-Ed iYp+zvV"b@ qǶ"[]ZZ#|WTD0w='ir. >YAq~<@]սj .#Rgi Raqʂ;"7J? ΃I&PpW^Bj6v[~`ZpR[/nr'.]dU&"[|&h‰EёaӛKS08dd/,GQ5ӓ/RSG~I-veҚ޳<2 u$ QH ؘ#>yJOcE?s<1FsME _ `I/axNrz~ZN LNuȾVi>rٟu#3ÜҠDTkf=:NTGpN8Pܘd qBgSMrɅ{ !E vpd" teJZ VѰ}EL|ϑ2atYLnv+%J7b/^M˻(ɔ(M5?%\#44xfvn`Bho'<0ꦛGzGhpIpb R{'BPnl%LCX;^'/@q ސiQUkdmz!; F'S΄zA&/c{1Xc`>nl_1,tkYT).ڛB2x8 K1!˜=Dd:|5A%i0 /2 cVkuQqĢalbʩq2mN,cf ^Y9nN"OyiTqa]?2;?P= / slh<0Sz >Z PSkpX1jXթlըcYxw{& YlNdN u#xPj')jiN{OG`-[Q&N4`;]pS LѵFIKw!vyz!nU׎2YzEPByؠ&sPdW$#$}ϻ"Ȯx.]B\A:A=vALiՁ%'=c _mb*^ڋ[KwC)crLDdfm\PwrӒm#dPyv^'X^OBICFg&v6VAga"\'U<ZyfwEbLzqfΛх8c5<~y7わ?+O[.cUFu8.*|>o>+CLF$ \7[#F/驪)9fU)N>oh,wZФ)USN*Lhi}*h;\JFBJ(qgD(>˸L% @C^f鎣o`񚎧x 0X=yV'b]U#63L\WPLCKrp"nsVZQW{+j;:^Ny b R3ά{}2q24S7캗z+3KZŲkV3F^JW\k㢫 .rOhRȞgŚg4,Mѽˏ)tFOg/M̆3uAuMMF'n,?00ɪlK#{?x۸W~?N_z0Rה26SV ^T\2I s1UFFT@7f/Sų- #ZC7'}뎦Q+I1l=z-HynQv. .,HU;*kb-Y(ʶS Pj`6-f-plMhD(HU-eA5" 1J Y<[yD ;\u) 8I3dFZOi81{0|Zpm ;m 4Re.vX>+~cەw@Hn y .8d, 8oU'z48B0JCpZu:oUjM9zߤ&2N\E1Cp6/kiR78 l2[EQ>vRarm>,2NZZ݂Oi);3l9H>R\D{*U}[?(Jx4R<7+0C?'^„_xĻP==>:VXX6\ـFR&ISz#+ә7\2V^%hg&+G:KS*abe6oҎr0K)>YDL[Lmg4).n"w{Nl 47+F+Tݻ6Q%QKsMA^$ dnJ8z>~iB_(!{ B?y:h^Ѱ,*_0%ʯ!/Q'OWLL-Pj9Qܒ',B<^&b~0Qr2R/dECEpEw6e2WNyTO|i)6_@"m/DNz^CԅN۔Rzz5/ *7(OA)\HHWhb$K~)ɵ.w ZXOQ"YbrL+5ܰ'%ѕ\Lbxn}m.d$\jZ$b " }/33Ub/q Ho$rml_Qa (:dA}ӊou:?^Po_BG\JdLw2BIy {Tc${QSmZC]`:?s-)~j7E Bg x(MhΟ-]d endstream endobj 125 0 obj << /Length 3563 /Filter /FlateDecode >> stream xYݿBK58&AMaRĕTK,JHQr }%97}|~xGO/F(3.GRkg(Kst:ޏBSxCK/.T.]`_{Ut@D N5/Q(-n.&_8X1XXD73)>^?zf4-+QEG"KxL-*9}i1~ 1k@AHU9(42]g0$8Q2Ÿ/{kK:%Щ4*#r)޹%y}>:+^΂B!I!((-z9I!TxFtЫceͅ MSpklibϭS"g(D,)AY2ª.D+Rh ;<[f }nxpȔw!lVsu]u&H&eV,.^=NCdMʠ{v %_&:I K^604vR89l1p&'Zo>ByamaE7ph0n-L{7] mej 1{z 03ʔȹ]Ŷ{n8D0˅6DDd(mt# 6J^ Fh˩Id?ZcY92yN1Ywjy/096ڟ:DU4^J ֙>RJ~@]./bq0Ր%f8/IxWt?0::'hlEX[BY?Y̺7)meLߜ+StԞΫ=2a@­H$It8nljc|)=[Q*ʃU8.b*dA[ElizuO$ 7TkEC뱳ξHO/ ,2ܢµkre4Sc5#I#҈Ҙ]: [*7SE VYÈ JeiTT.]|K)s H5,/l,d1RABWEJS= (gqNgA>W+یyW* yS;p]Sɏ?CB0,ڝJX35i/B Úwj98i"2GiڕڻN SXÎO:uJ0rj+gY&Eg!Z9_稄/aaXKwc?[ȿs~#_/eg&z ,>B6w>=BY&#[h~d4ɟ|tKKװjkn<.&A!\ $_#q(r=35Sm4׋:BqWfwCmlD>QZ]cHŀR)2B }r2 :Paf ԴYCRcyΔD@zHR4PtX%$yzԕ93*Q"MJaH=YL:?uUP0i DlEmpoO43 kÌ: j jtjc<-r:trl0ďAHz rMk}容eǍ rcJ`r'L91?pQgrFROkr)43+?r )V J 0eB`ې]-#/?c >X1I۶gRKpw%՜ C>z=O,ސM6R.]m5?-JH;K7S<׈?]:9;or>`ѹ:B$ƻΥ )XlAF}D~[-X\IN8RCXKf g?6[ R_Xf5%ǻrSy)<\EIqT+ Z;+tj(?D{q H˯xMvĢw/nEBE SȎSm>:6׼H$q?d>*dRۘ `ukeM)yr4aφa%/rwtuYBDF[8P̊7Z}u\tIb]MQ Z=a7@w.*\b'2KT.Tױ<$ޘ?ce۸RBU`bvI-dN NkС+61WAV2<->  tB^}[~@Vfn{ *U)fT{5v:]Pn%),ɹ( U( ˍIM@lIa~0ß$DyH>`Ilm]ާ2m}xȮ|sZ6ծ>+,CtLEǸ)|am[#޳f¼O%Aڕ=9c$gYfï!FKϰ巐WSjn)n._`Вoc? \6f2p9xLZr7nB46:<É,"5awO[,3'\U: ȏ노Ths_2vmFg-(oke % H|E(&feka\ƠCR?Tկ2fϊ5:,<TSq6!@k$ Ү nLAȾ!ܥATcmt- Wx"$#!0r>۟a҂Tp:0j\ ڵމvumkyӂ.@Vu=IGk?}Zqg#h{-駳VٯWV`!*;)bm⛕/5vlJrIz$A5[%g @ veXn~X_zCýkP;rw?dCG6m6 L ~(J7ٻR=ӿ7]d= endstream endobj 147 0 obj << /Length 3325 /Filter /FlateDecode >> stream x[[~ jp&cA @]/J]ՒP8=^z7m>ps|s:wOD|~Wo,)ʤօwe/yv|`2JzcTY'2Tڶ0n2R{,82]cz9*kɼXdn*u3&TV_Kڟ TB!SkA棂E&{}w_H;9`[."5)j^d~8.B}+lJK;]H'0 } j-@M,[haQ/I^LF E"'0YW[W )|!*ʺY(IDl~b4}+wh|`2[-ef( (] KOd7i+lCa jg=^m]3g+`1nP^oؠP]m!a%b;(Z]V DdSXhō<3]cܜ8oTXk̯>csa +6]o&42sv ps-ԭG`taqߊ-sWsnk֓3(<? ]|a#>#0>psdL:Po#A.q7]B%4U()KY`Esα?!M6zFF9rO#z@nR;WK=ZBzU8)PA<})yCޞ n!!3n5$:ؒA(4|]dQֽ24-jbŎK;Rօpk!,H~D6-]!!hŭ,V:OҽTFY+xA+IScTdC c(ͶuteLXyG, $j\8̯5u [t. vqtw,ݲGKK@4::d$P"o'&4),SZ)ܡ<Ĵzf:twG|Gb :״51{L_::o9#6E"%zlKu LI"mw%AR]:[F-ZR^%dc/x3wqtT@sgO+4 +q<ɬf}$.D32#46⾐H{W%(:=&̕`ň#I8#*bT8I_ztg'Jt]0ۈ=. >\l aqWq{|Q(ugx x`wYeT)촭8 VqnC`Yh11pվxaiiG1v!%Q#>GojW^VM tlvHFu$F춺LGz OB<>H(n l!y/ԗy.{Gqq]%::/#:懗S{SC"&ޮmŹ]`.`:w k>üzCPb|viiBbu7͢ K.FqP<td~ziUl`QfjbuNB~bf^ӸAB94!FQqLmhȠ;fo 3$ڸ'BttTE*Y?E@ߩpy'2=߆EQz@.tf]=[_*[rD66XC}V^#FsprI} C_+~gp0z [y[L{]0bd@(`J?,;wf!8q"Òoy195!z?%!gX endstream endobj 2 0 obj << /Type /ObjStm /N 100 /First 826 /Length 2629 /Filter /FlateDecode >> stream x[n9}W1A6, cLvvv1H=fdɐܾ~O[%#;r:[aXu!eWΨTV"ɇ٬(*h0VY/)r8$l7*$5rC8ڔbbT"m2Y%tѳ6Li>Ȩ0 S.5 "O x.!0 bmļQbUzD@` "+1(<y MΌU&1P>`0q CdR$w0 Lb`qeMOKf@EC-DOX`1I%`U#̎ȫl YVdYaٶ/XsY>3.fCZC9b/I,Ő2G a`oC,D2I^ R#LHX|ed0?~,_2UYJKNLXUzhlk;ڶ'枮y4<;ۢ7'T'f>Q?ԧgf}x>u|4#tvzVNjt}l:/_ #U'yPx֨M3척.،qP5|,dǗ;/Ѹ~2^HXxRyv;NgJ .M.7q]C9\AT$ 'I).`'nĤR-lC{AђGKȬ~OAQ[u\g=ZT@]wGfY.ɣck'{޻Ԯ4eFuh%OAkdr+]|f>cNU[M hKyx֑NW‰b;KW}\[خ/[]".;/@Vr Η \oI <;Tǿ]A1-̈́ۦoI~hShV)}cإC#*B{CwGvb ?0e!7Fooa"f2p#K]f ad=BZ9jeD,3 y>]ޥMHrp ne3eˁk#b@:rx RG9 me69] QAhs1Wx,ed ?<~Z:R@A( &LFoǟLO;ąIj+\ pqYfóbׁt)z-Cl,$; tQ$u#!@cXvd/t1V%[W,r5+ʁ?\l5J=Ci0$9XoCLJf*ӥJEjFY%뒋 *]h+M$)b/, V-7@:KlHj{"-[/Kw)m{yowr/2׻RR?Vo\uuoFއ/B-tJRv \WAegWNST]y~u{ww{χ\]]]itHn%ǴSΙYřǦ.=mm ֫g:d}GHLpkHlc_t_M \m_xRT kx&1gPJɝw5l/9s$y_!pI=X8#Qc PRw",QR2 g(\.:h.P.kB('r^ 7%rС)!_ExkIR ,)kyVں*C|RA1 u [0c3VZ@LZƺs endstream endobj 187 0 obj << /Length 3752 /Filter /FlateDecode >> stream xڭZ[s~[D-yr3v&i;;-DBkPҲ}uwr< ˽s9-_Mڔ\-rWUneQ~';\-3q+-|c$=!N\7e|q bi\y밯j*|?\:d*%V;7LܚrifO羇"O#FjҬ;9Vz(Y,mVYQ.y6P$';y۷WKS%=mk(tI#MؤPRp]tWKÛ[n&uuavu*ʤz"ۥ̓S>"S6fik~Kgx,7!ty\иϱʵIJpruGtԩ+= };R(b{<-R{o'\e\b֖VIqmLWxσiAM3+Ḿ̓ツWܴ %O<1Wnq10t̴eh@Ĺ(iZ"PpGfqVxtl e\՘\ҿUA=B'⠸ZVT $tP߆3zZj'Ŋ*;PpЇ#wLʒT{˦ec}\%}5ak ̲o X(`Q؞֗^{)ݰ "|Zx'p]ވ*چVVx6%zk{PՅKGLsićNķH+ˉve@,3f<'"yrGz猲[/3˴ ҊyV݁&~ǫ^Zy|ԑvUe?ɮ"CzEAG.[nc)j`69󘦬&f*-kl?Ffڟo<*,)\YvC?ɘA% +x.`;t&;崍#FeGxNq> 1βxd *r#c,vx!nȊ qxP x|yL1:4R,ӄ#v#\\ t&c L { (S3 _DZ{rK SxyЙxK,*t0Ttee;|Lo ׿YVi [Eunn )*uD;cP],Ӭc*6 T;i;M1"nUTծAf,܄=進B4-4$P?{Ǔl 峠.( &-+2!^+7P)Uv2t'nSIgXyǺVXiQNXChIwʘoˀ)ɂg*:sDxNۜgͯAhFT"n+RaBv;(q 51ߗ#9xZ2񹛰̬TBef&w=L>@R\p|\1v]PNjIk9.?>vLj~1ldA[u^œBs=,#r}%|Bhd|I[kANNerCCɒaLp&$;pӃ7 :.{忼 ~C kY>ˍU+9 -Pc#q+7ޑx%Ŝ>L[v9E=(</Z~}#QӬ0I/`79f1V[syPf۳:E#ƈ˕+p;6͕S&66I#cib[s-C9Cf'#7'1& $'\HTP'b;! Z TUhgH9حֺyZSMCtxzy$hJA!X)=w԰␰@ ':j|][:1@ 6]bh̤Yd>Dt,oV, fwcK|Z:7mVLyԄ՟z^_Up'}@݊Jf$oj+JͮF ٤?ȹ 1VkNWE{0{A*."Fpi%?'Z Sm@k15CyM6Lp/@ Ĕ`m@T=KNa@Њ> }t۽u(kC Lʗ#ʨ\ZHB㽒S}䝐MIƎ 29/a)X*R`8F%sMjBkbZDSg mL-g]0xdOfQXlyRuP4})Suk|Bkg)a]lEg.4e W:ʳuGm|NascX{5*q=L|2x*;?77i'P^?>kNM`N҇_4A\&2dio{6JUi\P}7;sϷev",I/$ʿ]v#clEnBVEQ$!X\T+.K1+z1ϬN[?a][b| I\ȥjRg0qwD,4eP@P`/'A3럕3R#I+h5m.`CL!3}$6KKu$> uEk2&NyV^~KOSuk;ǖ kK^ y A9of:y^ *;>Zr鎴0>&.<53 itZ@4s;5zfxZ .q_/|~4|_5 /O%mEVA <zT;EaϬ|%K`Ĭ<`ɅO0T̯=;mzOn4> stream xnG]_EMH, q։lMRaX|VU3C6E˱H>hz]}]⽫==ŷX_RY߳1L?VLi C܏ e) qzt֞3)L'7n1'Dupq%Zayqgj%IoYq\hD[E.q8t)+331(`߻i=gSrw`wfA6@/ìP L⣟ν$Tk"55U1 s Գ1K^vֱ%5N kb-.Bq"Z8%4bQx&.&L<0%x[CL8HMH L em(2S ^RT6g@EzCv1[۞mLx2IJ*/p?ױqڃMmlfT8"6Yw4Bv),MEEYHcR0⡼O2Ӗ-QqfX("|J([Z^g]D=>YEQG}Wmc^YL@h&@yG3Lfo|f[`jolh?ԮaFK~pPW|gio!WSLoC{U|yM%iHFu4P ӑ8Xd'u|F{.!Ѝr0á , };Zs:&EtoN[ΓBg7judM6 ] 0 򪁘ֱga-jWLAuI{ 7Fmˮ(ulƑo6Al~6F&@׷e[cǡ5FywKi3+Mw}gWPasܑG]^Ba,xw2#à뼍Y1 VLujYGP`qS#ldTثXsA'YߤIB Cdm#s4*3b^&X᫬D(|J{ ,rXul4FO҆Ͱ×7 OR:uė?f6ɘt=8nHHdsGukFDTl3nWr&Q! AwO 010jyc7×&Tպ2(n8)z+̑O.um_M.$SU5-v3_6R!Sie}ԡ9rpeZOS |?g"!no4jpyD7.Ϟ9}ܣ6c}ů7FStV{7pO=* =BHEqPR֢w!GSaR$" 䊂 n|l/I| 8,Xpki,bqAlLyF҃ _A'z_]j_i9=G̼Gy9|G, HIw9P{} m@YRtj<%m^-!vv'{"GڰR3%O 'R>x#[bǂ W$A#1FyIP="L['8BHBKMY~1jk4),үa,n:5@ȨunN:c ۞9)OʒPsE)=ߜ1]rMAVi׋xU$N$~DuY;UAkX.FYK\ۂ `_/IF&zŶނģ rV3kП3-DNHjet)IEH}sҚ(j&W~c!gR x7R1hʷsN2pK&!Ĩ`݊ T)0(yW>! Ֆ$UKrkUXt|Lݽ?v\cww̐ bPʔh%ȶPYg)sJRS"#©ra`A?Ω2C\0%=8P΄F{TCu^3A{jo'Lz \.X[Hӹ1ϟb x}?[| x2vXl&<;&)@#}L yEp=ن+Ni^<2Gbf[X3?|݂3JX14]c釷5*0oáUɝON?ųB.RGW1dÉczRPSNJ=nlM%m %g5)XO {jb}K At/wNieֱ0 [ޤgZ\+'N'Ӡ2qU\J"[uCj'ق+J)cN=CJt|Y48j*0t74C]2roF4dufqSp3ҭzZa^֕.%Ǥg֯A!8G"gUn %_ endstream endobj 238 0 obj << /Length 2597 /Filter /FlateDecode >> stream x\[oܸ~Pd3\/ěnΠ;3k'-{.ıeNҢ>#);XV~ڑͯHU\V7׎'d*e>Vmw0XHV2PfΛhy=+ ޻:̟9buEEwYl>>?~Oi]hN: }!zW2Q|/N'SLLmCXϏ0֯S!= a 7H:`bv 8Sv:71tޚ~:6 QK߮F1E$)cA% Z$HڛL b$7$_Q!]U=wlƱKգТRb tes 3kg%} N06MKAfTڡ)Häp0}<5"QIZkpIյ=$(t=I[۰--9p?bO'L=6&^^Yz3Y$Ly92?fxReR^!_ r탕aXuˊ!\mꍊ>˕-`K|"ZKCInZ_hM 8.aIC͐}98%<6fc !JĴؽ)ޥG0]F{qL)޹cm~=O tJT+E%lwҶ {D?$}'0(gv5mNٖsVEq= #ˡ!c_A9ϻl%Cn@4t> stream xX]oSG}н;( P *PBQ7 =!4jԇޝ;=;3;{f) hB#*l˰*2 gO2f㓌 .(Bj3eM,2.&Icʄq&'coJ#RC2<& l=0C!+e22ZaTpNY Å1E)k/Uj֍29!0V#E a^&Y$'qDnL'.` !MH,XNY$I$H`8x9 aX& %ěH,[bD(;x * Nw&pV(( $J)9`ՉFhZEMrAt^!D^$6"Aɚ8: $O"aDxe8 XH,kK12eEʼn rcgg=6?B{{O؊Ktʑ,#7tYꔹZgꔩ؀)l¨R&r6"u9بEM J)*ceW欌 -*-QTw[2&V G+1y2 fgtOge'(i3%l=*%qc&^,~0{^˿z|8~ӏGφ%Цu{r~v4ѯ9p$\/[4vg9,sR1ٞay,{q'k;ecg++iWC?ލIha{=:65dk= nJ"Pm7s@7]rX'!< 2֐Qr+بa+dOfɬ=4H@Kd64tMB%4co;CS 9!{hggE08 C` w;XR)I?}uC? oXv6 `z'F PF{aaϿ<_xzz9zxHwp@[P "ta7#|,y =*[_g ׸^:"$~On.j]Ԥbo_uMj\?W@[ߒ*/' 56z|>`уOHp FVK<r]%dĠybBM/0Ϻga8uxx{1_[;[Oòxzto鏯'jK|;9;⺕z/_޵s wůyQF= l۵okQ|*2)UV>)oJe^NE+FʥZ+9jRa+c"+RH QE~vJYX]ʠb}NʘHNmT^hŲ2쳭NFELh6&h "22~Tk YbeLOkі]|θ¼)ةn\_w$W\-xoq)w*N I˕9h@rm]a og[c{)t.+ZR]ˤTFCQ鍈㙪fT.hruSQ*t]j緟ە@FVz9HUMJBSzٗlSPzdSQ&O8DYe2Ax_M endstream endobj 284 0 obj << /Length 3039 /Filter /FlateDecode >> stream x[[۶~LSml!iNild\D\QksHJ8; sP[LN7O|y˯$蔛\^O»0q r1y3]^i}13Lv𷬡x{埀a1-roLN<03kV\@\WKS[\(?â! oeCa xBy6UGSyjlvZnv.ĢZWL⩭fRh<+xxM[bk~")7x >l^+qz:\]A8$-&1I8jZAytJi8h55-ݶ8@D U՞[4$P 7}4(}5?r"+vܰ]'"2\p vvnͳܶyؗ4{BήSg^Q)M5_"Q#?7_d8Y'5ͬ 4K9BHV'ߵs>~L108ߛ:AUB0v d5?yS ,f P HltЍ R8UV5S ĂZNgp\2"{ İ|#@lkf4STϩ>iMO1G81FoX*ޡFrA9,7He٫ -6A DeIEg<m;]nHJxi҉°쐣Y#Wޓཥ{ [ O `?ErCEeC|v#ɻGy]cOdi + J݀D)~=a_0SD;nBՋPnX͙@G#R?=-;BA q|Jk Q&q$`o`E{%Tq0j 9~!`PP=@XskYFi BwLɈsEt}AZfc\LxCʻ ; =!Š+b,Td/0rǯ=#Zj`tvK-0Vvk{Z}{1'wko+ELg߮i (ZEVhGQN& b ܍E"ƨ*3PhGB2PwX Vy`f㳥67ZJZCx?T`|wnUu~xe GZ ',!f}{xeBxNxirrKлJ>xF~ N nRCKdz {Fֽ/HFkNiN9:;Ƒ&{v71pѳT>}2l:ɿGba-Sc49Xx`\rPc}U۟AG$֞"T*R IEƥtkzRޑ6p߾ =N]CSF-7gANu0 Qaվ:FO_~O'4`YX4a$ S8e0VB~_?s'{]'#A}['HjMusxjOqΞxFoMt'y1(>YSZ- :'|$uDg)NX OFJsD:Oe{({$ bzv7RȢΒ~-3vbrE=Bt4 qTQQB /! <ޏ`8Cv> stream x\YoG~ׯ(Z}Iq@ F$%)KI}똣) LOSUW-JV?_q}Y=<;}YJ#wF$^0\[\ֳO|o_ʊ.*p]ڸlZ͡ξ?~lH[Z-pG:}x<< Trx}+^xE-2~|}s>;t ! X IO{Ru^D^Y'(FWC:)IhN.\FiIXQ08k0*uC5VD[Xhe7ZqgJs + ХA@3H?wE[xEn;[x$kR%E BSJfe^I"z{x$I>xS}µ@ s~'. W;\d[/P|˸ۼQdGǖKJب{tAt9!kuG;#pmR oo0iǛk$lX:\:f8 K-0Ӆ!B"_,v_Z&pqWsa<9 /mkĘv9CeN[x((0-d߃i0-Gsܘ%$j` >zA ͯ9-3iu_ajߎA8M;^g/q,؀I? QB vl@); m̛vm{E`QNh\5^wWM}^262N,&L |]Z_F 93d˼ơm 9N۟4Nfx^+ctf0T`aAFƎWÒ\O]DHLX-iI(P̊,meĨe(Z͙7ԒB ]RMSi՘j㸡*p_rrv0S d W"yJECǿи*.FܠROZ54raRVË{|\:Lp}fιQȻXgbV;87Lt) ]oh;eFgK4(AAaz1R}M%nRQV[ze2%U#*"?Ss櫪{_p}&̞M@g@AM4r샆fuʻ}̙̙AgP>XcV E=P.q_0zu:_ D)س[f6ﴈN?HxXw,eX{]RjeWʒ$M4 w1\шu΀pYIoӲiƪTieDLj⽒@*4N2XmMM*]?tZ3mXPyV*@ԛ.3[b5MYgs*'_)Bb[&}I?'Y$G=a܎n*T,U&+$/ԁ-RH J *@)~XM{ڹN5W Jv]ylʤ? WIQϑu 7\f3v^T"28ͨtdγr)>,bY4U~es(%dlс<:ǝ6wjj2Lw[={W0@755]l5#gQSҏ] q F詓F%x26>7o^N'%\2*ۮ^/ S Yur+Rӷu>i֍GyUl삁=ƌ$oYM9"}r=.Kۢ> q K])x&OU^S]SN E< gѨ4эh{Cd(\tomv[t0<'ER lZ cC֙fqW;_ kxAm#tiRr + endstream endobj 278 0 obj << /Type /ObjStm /N 100 /First 879 /Length 1417 /Filter /FlateDecode >> stream xڽXKkGϯcrz 0I8>_ڎ-qm>Nw=_Uu=fZIjIVpi%V#`.I 5Mmfm1ך`5*kpĹ8$'mIz6Ήk ^1t8, d`%XKdhƙk?p?rn 4.`S.fЌ N`{nLuIu\>.q0$]7Hx,NN'eu}>vW AwIť.i~fp `PI `y/UյpյP,hlwU\WRݧ 2)n9aP1Ns$csFL|Wc JcSRiu2I3d\W\Օ &knPV][Gz,F8ɎÍPz*ٍc k‹IEU1.1DB4H8B4~Щ-a8ɓsc8348M1pa681pQ#Aj$X܁10 yOpDڃ>69tݧ42tlj^2"q3$T'r}r*ˁ4ݽ>e_8M>}$q_c9vo6 |584?e_C[7Z*T Lj-Tb4%z{ݣA:$T! RB{<&\8UqtQPJ_+ߐlйFӒAUkD#靼v'DDP ul z u_cR?eYYH,r>2Uԧ° nZ[A{X, +~nʷakoܕx򭂛@9O"Y|rX% }m̍,j\`d#J* ʨO UD }"`P /;%7 נO9sO}у>AGY>7rs'L/4O[4æ?iUۿ`Z; ( -_1U/ J\K3 -EAΥtAkZK!O(1-qѝQs̆Z[ۆZZ)##|Dz@Gpj="jGP(~D jynR9)B}":X4\O&l endstream endobj 382 0 obj << /Length 3482 /Filter /FlateDecode >> stream xZIsFWr02۽70QIEX39$DaEI˚yK7 8dj6~ArѷOdEpn[/F_??Q0CH#GQ|4[=°0]?8WO#+\Hi-$t B7~Xev^(F(H0JDv9c/;1}v;&56'L~#O|3x9"!Wd/ȾOZ_¨vB NSiocCNv<)\6v V5HE40BHb++-Hgh;jKW bbErA k%dP =c.=Cqx2fKڪ%8Δ`ER$/v@X!'4ClF]G9fӾ1}y"QPǷFemm1?`|oJp[:3 ?cs|hˮ#=[ (ٲGvt9I+ 9azG'U,ۏr0x@vⓈ/C";\,]5ɂaʏŮy?ERQBg{EKIBϳjiHI}5o%mУ\S?R\  M30>iB8o[7W-N3 4}CBzނFEU0#*p-s,1D 76H[]L r|x*t &<&9/rdᴚ]A& fJ JJ2|mU vzx?ǟh/yGwDj Gew"i= TĞ܀EqjրD3xbΞ/Wخq erLfvL(>UΞ7[6Ա^S{I-)fC{tY4B1 d EnUgTUv\Vf{h^9W)]7` W.4AZ?-?6X Pe# Iw †Tذ  8+k&Ʋz6-Q%?Vz +LNK )W{hv7k}a8;1}E6/zqUuwнI8צQ9VfpZ} Bvlw!v՘]9ѭkZTZ j$z|Ώ~;nƊ(MG:@iw-;8'v8TA} ib(z\nBD=GQ0C?p WXXPp-EFUn2+b ,j*b=FUr[M ݆wnC|T?w0Zn~ً|TW ':hl> 6VsX+ PX]e8ڀy##Jg= V\ut%jC.Q!>I"ջāo%UFx,$pH2+rBw7`?)QIW'JAںL|j/iăNjW-dybqJ9YxY(:9U LWEbbh٪4% /sKd< 0]o#,U33F# ࡗf\df:iRB5 .z1Eaa)rЦxgy2oQ7II*u`'4&WdI˾R(ـ=)%׳k'<' tc}6Q<(5:G!}kA "kub F 85.$E1[wYI~c7['ή'.AW GbMgJbO@+>􄀬rc>9V5~qF¥cS!:H<0ݣ@Ȭz j%dzVݘoدxU빦"/Q`bJ3$ k|&D 7dq:1 >&C[KF)@SyǻD]<ʞe7UjEmjEײ IlDHwCtqEu3=~Ly:mտH4B:"u.g[QUP:*LUj:UpaR"Nlb0#C>"ze(C9mj TRTe香^mWj%~BCD Z$5Xa7Ƽ\Ei#dtBM>'m#j*>2]2 w%%i,Dy^xwXif#ɜ>`oå]jOD9k%o2M=oQ^d&)/!qNa7C OcgΓJ\؅ƹn>^`8{k< gh%àh?ZEeZ*5T4(OtAŊ7Z)efw׃sf` endstream endobj 427 0 obj << /Length 3612 /Filter /FlateDecode >> stream x[[۶~и&BNݙ'Mv[r%&Iim @^ljԾ .~$|,OQz;Ivrxͳ7$'r"gPNgء 4K9B~R/'7։3Fs0Jz?Oe1yKC7z#.~Cʻ!C$LsϾx%tL^F䅆Kai1)ΤRߦ3uVOgʖP *WTҘXlk*Tn4ٜwTnW\ 9w(~=&m*71,&++ Z[f“ w%1lGS5՗T<"QFh`lBy9`e 5əR::7e Ǔ:/YTʊ5eK9Rff@IRg%-7rV[qV\lV\G[qt4 tAȕ0F^r+*Els`ORQWTs B4$Ғc[T^^BbPgS[კe8T2;"B $L ֤@{cG7 %ѻ51ZXY9Y>$ c1bt;* VyGJZ+'G*W4 (ŚzTzQ GAPhuTtG[zG= ]F4,ṉD\OFDI{la~*>}D&(N\xT O9u(ՂM]dݧ]iTelS}Znl/S23:kt.DnCwy9!9+' Dg.{9}bKi8-)9:52A|2|*88])Kkҫx( :C$)HQSS'0o3i_F;<'0g"VΌܓT2/)wǣLe:>Yq,{>>erqkQz}*OOX/d(gyĊ'["O:"Ce?M wH`{{m;Co $Or 6yblS.0痕f}2RhcDk: $&_3}{WnpxAy(gA ]kWC͢VCH.y%$Fh D% Da6:>G$%I\9CuqJWZQs8r$a8YC91h?}j{;i3xB:n+DJ[9ٮ~<tmUR:}mMןsi~V4y,i.,n_*&rxBPa0YPh Qm ,GP2 ^fRh`?Gt7-NY8+2zklQ?lFޯ; )0 m*krėp 88<i <%T= <.G$5x'dsqV8MbA"(K N n9-i1N*XE(ãa`OC>*tFfJVXtCpMDsxʇSO9v[ w\mh}a4N dޚ0QN"tܫx"S'oBWbz=zLmP;<[䨉R1=G̳d!(ٲH4S4;ؤmdGeOlNxGn}B䃲z(l_ Ax0׏4B;X6n[W9$8pݡ{nH pe5,ݞO@#a0b {rvq(]N9Ny\2upE;Q7uvj1L9S(oUo~1PH=y /< KɦYN#.Պ~趰>vha@!+D<ǥ+~<5+/R `2IƭѶٳHr&M̎8G葷!, Cy|3ga$jH;NTC<`=BXmrcV BOd%Yby>?j9ʼY”q@RcJcO8*& |ڰY׼rB+ӟnwc ax1hl:]T PT>q[ާ՛]2 'j߂SAgŮC_W5W) Wm<[_ (.HSmBkA 1'}Zu1\5!\E$k}!Eak0x^Vbb1%i2AO?V JG>ٿP٣Zn[ř+\K]O[vUHD@2\uv=-?.zji7q8)gf^c$JbskXMn;_@aJJN:4  ƿsUEIOHs&(`V!͙Ev[ct6ZnwmL6พ@n5O{ V$iUEKMz!1^;"M۾fuG\~$(P2 f%] H|i)]pS҉q/Y\ h<ӪfT܁>H&&\.Q pc qκhNH/Rnub>Sd`Ihc7}ZILml?CsFQuԁ7NPqt$D@)lj;jvk֤z!l5 R 09[ED3С2!DAM->gobպ^P8["¨rO'Q?!I3PVSY h0.%dx ΗO(cDa պL.6FH;/i<`X;釩nV񺛮3zUeÃFޯI7W{' C oa_ռWnkvIΤʜQSYc\ Õ8yOΉn B/ endstream endobj 459 0 obj << /Length 2817 /Filter /FlateDecode >> stream xڕY[w~ׯ[c[z +$i9@DM Ju}gE譽x~EDЋF /M _CoEC?xa;/6IYK?.^\}˃"Mw{O *R/Mƻ]yOүߎrf}amXE72uqE?__8:-oUL^ y%/J&seoN"Mǃ/ ,qL{IbUa2ݖ1|y$=['ƨt hQvM=?S ծiq)v[='l`JygPO@Ͽn't,10}aSKàzxfB0ժa2 B+,A|vyCoHߴ,ɔX \ݭˏgp谤tq-4j>*I|xJ`dT hkYG8&]zf6n/* QHe\ItM|;׵t=˦xFhەa7 bP:ްUUiPЅf\Wܬ-r8tad]6O'_$֦j:0H2ZURر-/)].93v}h4ԈаAEۍ>b^<෼jC~bĉ_Cw'~g8/:$ ZWz#<5amn]FQRne 'VIϷts8ua_ ^b?9p8Ү~؜orEgW6ۆ`-}4VeWxj!} ^%A)y),Ʊ<^\@K3R ៙5UԮ=b kPfnIP]^ iLR$^^vJc8" -ӁIÂ/fI`rLYqごeMrJA=R+c *驄x A"]OA"#{[x#\u6S\w@;, r*Mi&Au6ɐLWu4b>^AI;* 'g:l  k:4yl]}>ѓN W[Z:ZR-&w#4 ~`(k ϵ`LÓ7|3;t^DOi )'JBAG4bjp=r|񤉞չ`Z|{"g`#Ǚ`ՈV=hfSlGqWW'dQå~FBRCGNz%Qy"y1/ܖQߛ)!D=gtӲj~׮t݉b"jg dR^g`(hAOGK)M,8 /*s]Ϣ֝zVÏ:&-fd]N\ɸe'l| q3䜈_$pF ]]X~耐GJrbq"Λr W)i@z/L⼢Oxԣ/cw٦&c3U 1#faUd9/T) G-sFҭ'SA!EE+3??nċ9E`XgK%]nmtOY<9cg4Z靄0Mݞj. t;q^4BvOhvzB9wi' ZtM8pwcG),ԃ]$ЁL (x+/Yj'/Ocb0\?zOV.z4V/wLyܘ$P@KuY]xbrt;F# A2]cv6.eQyS ,7ދ5!l&qsIQ/) YPt^Weo&ro͘i>3!y8*ܗ40eteZL]eŜAp= 23<RS[*So1D kX#gr*v)`S 2|4dGfpKɞUj, (; V1`AQf3z%FYz3ُ(g,{`qsX5`]h=蠟 "k}B|Y`ssсB8Ɔ 7G {vD PzJ~+7Q6sV_]ַǡnA'@qa}/zy3&4!\\\^ %:ssGEiLG ŧ?6 endstream endobj 473 0 obj << /Length 2157 /Filter /FlateDecode >> stream xXKsFWE3U9Hc.R+L#`2~C&(e3==3_?b {ًW $L2?5 S?v6w>XGjhZ55;mUtvazQc%=3tjK9=̙V560&F~W b ."Z}=ϣc=`jNБ*'_W7+˹lGZ*b3F&gY`X b,"کDimh[Ơ*Q`'8y?3ZKr{ۻch+Cb{*%ľා^2&`Vs?2Y}SEF`4%)Ѭ$~G`ЭkzcMo}wPD[(ҫ8oYA$\ڷÌ`*X5bPΦPEPȑ mLHq,:I@SHe+L$aXTdW^T/_Uuh漧\a :\~boD͆Xp }`yk%2޳͏-dMrB}CՖ\hk E=Q ZȃtR͹[B]ڋ Q ߟ8ތl20~z fñv\{6i9}A,R@G=f{ |$'3?Aidi%%KMz AG0@t 0 80ã0|Rap,CT,B@ b8waGsN[?G^R)WU^ r*/#i-2Y/߉*[sӚc:3}M)FQ Ad]t|9]88zp0-Ijе0׹؅B"WLiʥ_St8b8v·d {u;keJQ ݤV KlP/Л37A}6Ab1C~W07 NDѱ:vj_'! ԾYǃKĔBr1Qj3`gpԩz qX^TZ&hW-M0GvWy FktydPʸя8ss<TbY!tqHHdlb' Q4&zbűO4Jr̐ͣ qւN_%_T' \[hT]lSՕsEG:e+az5+5N~.ݰ)Vד 4#k;Xeialb\<)锳_ݸ}naqLtX\gy{ᡉKUXK#۫9GRyhj~ٙX>w6 ^lQRNV8%2 aGJKɩf\IR8&V {zM[w7 9w|űd.5s%qMg %Xn Zvڇĉ#Ǒ摬I%}? endstream endobj 372 0 obj << /Type /ObjStm /N 100 /First 879 /Length 2108 /Filter /FlateDecode >> stream xZo~_q9CN+'AT9EkrZ;Xp%CBƙሇl(h3ޣ/d< ~&^߳I&A̦H y؁*G4;44 #c(bj(d(GCt+ V#QV#J(̓PE:Rw ;/;U1h#@:j|pz,L &z1;1>ׅcDfRN2^331bv+G#AD9uH 0OЉO#`zRC,DVV<+gG+:C)YGH@C#E"h2aN&zpY`.-G,XE# 1 08!䒪!DE׉&=NXIQh@(%t6OЗ+ I 1 .+3`"g5 ɤXR`P켟Mͩ̉AT5:X].o&?t7qj$K`rq`mđNj6bփm!~ѯ6t/`qVKz*rqj C'Öju/|cNM{=1|>Nj{Mfו&\oYɜ@%KotPajc4:Sg3܂TOWojY>MKkjGpJJdxo%Tia%A݀ܿ b\\lw6>Qdag(TH?㳁1H/9ܳ&c(w빥@)N*UI6sQbR0[l||.?LW$F Xu馥j"+nBJ"t7Gr #@Y)7{ii$&E#Vpq,aİC#qF֞\H-H`GYڈͭ+#ρj%F\qY|127 ,Q5Yp0ȍD&(m b1^1R C=$17^/1Ah}= ' O?< !Ғ>@ E"Ădi6I/8IPcTA(j0Xo6ZI6y6DQP<4 y/o~.Pj28m *ȸDb1_5O}̟ظآ{Mfv`` vPP-1u-6νFJI:gD)Ӛ[%lҸRo/аC-cARơ~=]M7V9`)mfWi(b}8>>£<VhE{U4BBn%}ljy<'8}lji<'ė6X H Dn}#qo.27$DiI qb7~A7Jս6qb'Nsq~n/1 fFw^hEBazJU&5ޑ_|U@Di* 8   ?1tȂ Uwj}b >ty̤@u޷"IHZ$%#CM&d _#ICBK6Z͔W'OtOuȾv"NYVDY1;>:;tdz͢_u?g9u3,vm~םOgt2;??^-n:s{:C )pf {`-bn#F=מr;z~3+){\sm%|mۦ& 5i7- AUbjԏwuǏfnU캅ݓ!(hU9 3''?cNP:R@+b}vgY QԢzPOۛ YMowSNJhwl3jmwqb$o|Q endstream endobj 483 0 obj << /Length 1761 /Filter /FlateDecode >> stream xX]sF}ϯhlAf(JƉdd%}hHBƮO6LZv~{ٳYx'~O<}[DAdMo;b+ n`Bk:~'=cEϷsxzAlk( m(Ɍ>yFPvˍgC2݂ٲNҙ\wP lZ~S/5oI~}7 ewdOo6;օ yًvQ SUQc:a՚M`:چ3.]}ϳ?ؿj}{Zpw^wg8+8y@7py\b1iY AZȟBVVڊjٞ'XwzBeZf:ZDR#JɋHzí?A!d7)1hi&T{/ !dU;$ tzT&VgY#|$2x.gi{".`PO[Ы5{NY9aZ $\'=>W3l Fj8U/ VH,5(:J|a{"G䵊rܨb6^w@ez],)To0It]A#N@ [#~7O" cO Vi@؊.:]a JM + #H9QZWy~lOo8h(7ucҜź>$}jt ͋kfw :nyպ C[II{`_ITeQNXJ9-BzKQnѕ^3PȽckdƻ)[W2)Vr5NgjGE>qڽ5R]6'jv3{l + nN! U;%s͐o/JX֛<*D]uDԉ7|JXeAG2bՇ7X0퇅[`<1iK&}ωBb:Ѡ h#7A ;V?lյ endstream endobj 487 0 obj << /Length 272 /Filter /FlateDecode >> stream xeQMO0W̱h7bԓ 7,>VMxk3UP{2RTHj6 Z(ZdY)gj[Cp۳g:bRtV!d0Fq,C^xZW DG Dd5&(ay{,=q?Kso~멜n>Y슞a(O@hYVw*/x&vȫ¨'it ޲NjX.MIgbBCcұ wok endstream endobj 376 0 obj << /Type /XObject /Subtype /Form /FormType 1 /PTEX.FileName (./kalmanExample.pdf) /PTEX.PageNumber 1 /PTEX.InfoDict 489 0 R /BBox [0 0 504 504] /Resources << /ProcSet [ /PDF /Text ] /Font << /F2 490 0 R>> /ExtGState << /GS1 491 0 R /GS2 492 0 R /GS257 493 0 R /GS258 494 0 R >>/ColorSpace << /sRGB 495 0 R >>>> /Length 21298 /Filter /FlateDecode >> stream x}I-Inl-t;ca[,@ ]Ƶl#CjNvYHF10>cV?>族Ïsc<3m7?>ˏ?([h?8?>5ϫ~?(TS!߄s+xϱ v~zM'߅8<7Q>} g߅ c ޅg,g8?ۄyos"Y8[?l;5m<>KhYǻl!,;oG;.gywqQ?,;!}ސu6puk}>Joym>&Pxuގ>-!|+urisvի,<ճIXE?=]xGfY^-% |0>O~m[{Xmulθy#V~:xiOgOWElA1-c8/̱͗ ^.g^ue^WgxnmoBtBn?4_xTq_|n1;3yO|8|h|G[4/?<6΋Z]/^|s0_vw~^|>m(׻!͋]f/[}HkoۣWmmW1ie99 J]IŇ1~3f1?egg!`il>}〶=r>C!9~~nSGӓ0ߠ쳧zy♜m5 ~I vG6Xx[>w1t8qumv5B{;;3xZB-^7ac2;k{y`ٛl>< :/#>M ͗p=臎|獬ɡ2w9Б$Gv ~KbooB|4z;^|줮:,_~+]]xxR`dӵUbfo7S՜Oٰt~Fa cS0=;FMA1C ޅї!RyuƓno l\t~c=n{>jv~~mӟa^)B :w̎zz1{V6b> fy9?I}1䙸1\ߥ9oCcr}\ɗid>mx16?;aU1,sp~_x:~ķ_vq}xb bw6gq폓=OoO sƄ9ώnK? `XG9a?>G|Ѓ`;,rӣ tq*at >ZՔ ?D\َԂ 9ۓPgR<̡ > `PLxrzgۚ=|Da6Ɨ=,`OqAך_f FS SX|:zW;;iP4VbNnsk]SSo:P`} ^OEEqb9zԇWy^jtNOI,bVkߢ7yP[o]TLH][XH}_ |m1YLHXٮOX+I&x{Ç͡CSbxNv40UO߰YlVm?t|G3ZKF}x{\F$}^1Ǧ|i><}Ƭӗ#ٻ{nq~Uúk;6bP5_#VO-)Y+ Ck< ec/^xj%p8T*v3O},m{S|Ʊ| taa-j cm>#X=cO o=zOR7͞ajr縵O{-6ZV|OCm,p_uiHZlihZqie;&Jh#Uq!{8VB;o*>4q?8fjez ɻs:|\ySks:T,>tÓ0'F[|Y×53ToOkzl ?Ty_bݑ]691}\Go]b1FO¥io 1z `tA GT.AǶ&'~~Ida+ !z޾/Ɩ߼4ַd W;x`>&D<roؙS6M̈!:>1ǃ$?MbT{`ɔn,7oo)Ws_zh韾ͼ\׏#KhO4(; eewDd1Gmh{?w6?7NwpLyEJTE}ט;|>>{uiry*׏_{ܱ^qf)%ܶ|Gn |bwMKWun92vmG9Ikf+E~l|VG,$VtYoû KW%_®~-c1"99++#VG5r+4aMAgLb~m۔/bs|wj8q\ ?U\Q[`9ogi,9R7/yے/aWՖHZʶ T,ET쵎)H(kb-Mݠ lK.]V[6[,뾘X+0)mMubcEA Ύ m嗰lK]F,AkTwNnW1# Xo|`f"9ֳ4fݤkڶ\~ R†w?9-搱A9sK8A vX~`XQ_ cnPlK.]V[vbDXr(-P(łg,#r C+*9I,ԝXږ\~ t,rX|Mkxp=lXQ_aJv&%O¶KoT;REK\+Kl5|jv[7(%_®~}a,XǺk.G~J p!tY1JbEA7-M -ے/aWՖ/V7Qq%(;]@bE| [!lݤkڶ\~ ڦwߜ Tw ?+/-g ;{Ka,Sw~Ŷ)_~ߗ=N}_F.cn;&ў7Dž%%9'ř-a;Top#6?ŜH lYs9)zGӺbs>%_®~-\sc9|-snX>bTRB(30NyCI[7)IOc܈k<& 6b4gg E=L{g,\&Vt`'&XJݠkٖ\~ *Mdsecx*ƪHrk kq0-,BR7(DarE7ՖN-֊b,0E:ޖ#%λ ?;&hֽ-m嗰nK ! b:X$E{ϭ;pcIQ7-ɖ[OIu*\u~oKmaϷ 4Z' _)ÁΔc!Dל- %_®~-|J8׶J~V wXQ/4^[atv}۲#%"{vqQa=FRq&W b59شL,u{r%rD۱Y-' ]\i+"l%%8<6N[y=n<%nˉշ8~Lʓx&t]=nyEg]$62nRD^)_E9 k\zN ~wha9_zcE\3aACr}̶)_~[ma`y4[iNj}'mz&e*yb+|$E>[Ysr%ۢ>VNŒ(wl/=tYĊFlXMvaɶKocKc`Z9j%^qRK3xsŧ؎uu ۖ/cWDEɹb:naeyc$ p؆M)l[.]v[p@}sQ ;FGi)zW _rs:քuumz2J V^+q+*uwN9&a^}mnx"lK.]v[/Pu[HYovD푢凧M:s`gؘ^-- p嗰n ηbLv sa=); j9%Vt ;t|m[r%rb#"}_ȉݨ3ň>9Lw-XVu (M-ےSbtDǹSJs:v ;]C|1ƊnZʖ [umWUݿȗcUs8Ѻ•X\%E{{)GRĊn/0~M-/-_®~-MdszY㒑43L|/D+ kqʙ ura[r%ۂ/1rlh c΁B+a =X6hU[7()_~{^'bNq 5~D;G"8ʟzNFVn/e#nchuC]8pf5\8⢥8mE18P4i-QMIpv|@EC {)0ٛ!tb`1pd8dVniؔjqbCsd 7O90ek$R'ERR 'Z w2 - V_>m5s8ّ"5d)GE-V]Ó^\f6ӰIo.!:9ך]sihvA>͓γ󨮱j>v Zb7AOmK.]v[8ǁ]osvݴ '~c`ߑӀqrq+؛ӱclcЍt{n vmf Vvs13Fḯ1=2,Iˌ(Mi/\~ 0s) g}pR k krZnRNa[r%7ՖCrb*aa$晤)ك+j8n8cݤzrep+_+d a-c AގrS ~Q؝ҝi[t~maX;v !FdYkTl#[bE 3bf,+a-vm9Ԅa+8ŧs/XhcMlΎcȶM"jˉ Ģ߀= N2|O;J<(,)91vLǭSض\ p355/ 'DRe8Kp&6nݤRo92vm84 A. CX+mvQ@#ebEe`9Ŷ;nRnyض~0Aueh.9{AEp08ӫ`G/<ƒnZӱq" "uuo~-cCJɹ^ )Rd[Ɗ:>=L@jݤ6nvm_aGq!֢qW-|9S7&=^Ċ:r%v`ݺA:KoE[{noTRar{9&e/\2g`؎quڶKo`@EXCvcbnZĶܝ|`[rwٖL3ۅ8<\wȐĊj>\:cTpEږ\~ T<̉Z9̈Tz|DȣXQW:9i؍{ҽy%_®~-xp v-v<g+5S%3J(O'PnRno92vm9VU"4B;607{[ik kqp؝IL[-_~[m<. "]_+'QQW0X6ҸDvjCބux99H(=%_®~-/֙a-AhJXkw"l%Hi%H*XQ֒$a+;ZҶKoq]40×h9RpbEUǒS{#h<Kۛcʂ]v[jFI ?<+>g-)r5KJpֈ1$ViD[[pVjK {}둸 Θ[Ċ}(-9_˥^ږ\~ GE7RË' H&Ja/RLb8)H YMĊp8mHw.pm嗰n ,r:t*9xnRw"ǚ'rS+79AbHݤr%ۂ^Prr0mQZRwئ)]O_ۘiJnyJے/aW&~8Z9'>s,&XW58镀 ̲cݑsisF~{޼VsKg+֨"[QcE91gd, ۖ\~ }]G5G]lұw4sCq_F|K4ű18.#͕d8# ]Hx('-#mзe :q&vS2ePCOkNa`.eC j (_8\Ή;7S˓r$u R؎ZwMm婰n }D_EO-gZTcEݪ,d÷:mSn=٘.iC8ONb"aEh'vCF2mK.]v[0(#CbEݙi }gNmW.Ѥb?>9 0e{/Q7+}cKl$Gury\OqM%g itͽr/{ԔWU&T,9O,[w$-mK.]bZrX̳QY͛c-ǟ59ޒSV`-ug-vmP-᫡A6ƚ:sfk [wJT[.'21 8\,.5SŔ{YtI76BXQ1ƴ.CcѝirE71|^+۴?;co[u- \ʍa*~闱nKgGm':wy]䇻n`ðGbq0$u-yw ۂ 1$\`*ERnMy,H$t\m嗰n 'Qۙ5A8Ԭ)cV1ct$W.1[]u  q/ݤ-:{Yt"1ِ r)5H"#QNYDIQ$Zf7YFe^>ȑ%_®~-%Nx3' EkNO$OęP1t ^#$iR:$[WˁX+LxqMIp!y&$XND! W0RkUڔ*MDka{6}^53hk^jKQu8y 5npZwdlsƍ[|Ub 0^䜻wm>t/C$2)4#9e'ĩ$pKMKqvB4fL 󢑠#LXz H46zq"{uk-Y E6%7-}:OS392+XŤiSIlD4[5bL,niOݿ-DZga.LHЧ!K[0f qgbc/mRyCgs8ǎ8Į3N̑!XJƑ#0Æ|dSRz#GOw]$n)^L Ȍi$h}蛍3? WcC5;)ٔj_3:Hr9/ TNS4vqX蹱ZoZ8hhږ\~ TD<335tmwAL99kÙY=˳mV[vĨܳa)Lr.a+̔ 1ur˷/aWģ*t{Hꍝ #0u\YXQ-SB碌dYۖ\~ tDZz9X Ⱦ2_0E{'w/?;y9kb &t۶Kox=9,V9p;Nŵ۲v=~aMeWbSSضo~-,4-ԒgXs#;f12ۆ֚;)]1jQĢka\,+L5d{T#q:RYS+ 4t%7-#d.y1K3ljc)"h ,ŗ8%ȋ#pyS+ tڴj18`ck"`#BCҎs‰hY.CNX·ZKʐMI qreA =QO}YRKQ"8.G \upv=qdMW1U8UVy aARDGzKb sqiYlI6%7-}\bz}D]̙GZk)bc<7myZ3mJJo[|qZX"AXD CZ%*݉8`\V㻪_))!nU|&,J Ε9si{F՛ڳ9K,Rwʖ-vmi<uĖk y0qbyRMH>w +;,,`QaMے/aWݖ᱿b idT9)\46Ϳǖ;tWFk*ϯ%Om,&-gTM"jKTcWC!os6RE,\sVTU`0<"n%Eۖ\~ S3&`H nJ`IQ7- Cv}Q-oU~mٹBݳ3ds6'׬ '#kg?fW ul[r%r$F*df6τ:2hrwXSO%V%ݤ|3o~-b8˞1aUw(9CF }ts| '"7ZL)u-vmab<.&@OE,Fn Z7E{Lb);Fa3mc'229%_ԝqi[r%rfsP'^בP"^C 0HXQ5b[ʗֽe[l[r%YP0n+3".);J΢f_gQxxe^.Yζ-®~Pޚ_+KoE@ ~u- QVUuOݶ=}ۖ\~ShKYQk\o$1)b @cE^N8P7)-_kQE7۲JEMmkgcbTQFr{1VTu䨞7Yti[r%vFam-_Zk`]vFyG0|9XyuӶKoGc49rrpQ#J92J[ĊkdSˤkdے/aWݖʪw~5&XHћ)C aY=XQ˝6W)m[r]b_t-ba-~1G9IVɢ4s+*Sg'u܌e6i[r%ݖr`dl 8:XF, [Ċ擜!银%_®~-66,[VZY۲[$leruXV,[%_®~mHLr^IĚ )E-ueyE|N-v[mŖ Sm9lCng j>XHĊ9"@irE7ﶔ *]UE=|g:H@XQK%gt]ڦ~oaX}goEBtm)C aƚ>-h5jz:mK.ۂROɩl? NED`TcT/1Rc0v~ǭuӶKoe (£"'JPEul/}-?d9u{x9mK.]v[pfޥ꓃,EZ.Ue9K+*K'Zb,U%_®~-gMMCQiꦾr|+śVotgMMے/aWՖz'*V+/*{nlkXoˍ58l { ֺIײ-nˎݝi/9x cڙAPOE+k{/9͵š]Ǘ%_®~-C)@lo+{%=9(L؎uwm嗰nKavıVE U  ;YHug >cEe‰Wa5_e>!ۖ~{Yls\A^t^ i H^\'t9n[7)%_~m*..FcYCa۱ )ǐoTcAp"j~࢖pHCn[~dSRz#*\ҌΊmX?)D*†ө$Z<&f ,۔j+/ Ih̍i t;DPS,Ƒ9 GUQk))ncsL3p2jM'N^vy03 R#2ͨ"|ԚG2m_q{XKl*Ca`ȳQiÈZԗZIʊSPX!Qpi ~-LgTwgFMz3b1Ewr-vmaQ9/hXU"A"rTdKe㭛Mۖ/aW99v")vehت)XHc l;b씺Vi[r%r^Nˡsɩ|j6&\l*"{Ɗ*%gb<ңnQ5l[nےǢK>N](֋HBj*핔sXS- cSYUX<Ð%?|9v[&VONCsAƎ,:,0ĊgE]2 ζ%>E ³nr :?FF7-_cEXÜkcuireR07J9;3O.5 rqM1‰؎ܺ{FZڶ)jK媢˛3f(G#Tvxr4y2˛sD9ZU-=%nˁV[iEQ}q5$>Z+YS98=uM[~+m[rE7ݖOOrvB/fl][YN8=3Iږ\~ `-3x50X\ cE^%h+{.9妣u-mK.]v[X,=msY}qACHJ{+gOaNChcq/u)l[r%c.lvo'Aesи:?[l^Ċ6m敱M"nˁOAl;P;x:l/3%?drr8.0#˶%_~mɲh {0-GDbEbrmܶ%_®~-%ě}s/xKɻn9";+jx29|QG2u7;m嗰n Y;", aTګ|0zDXQI'961TB3Nږ\~ Tc_c3D^ 7V9؆u6o~-Gb8>VTk)i*很k+,uŶ%_~mX)Z9X. q-Fj ՖѢX*Jݙ 0mK.]v[gh6nt꫗wr+ScNcpHk-vm)gЙt_)hT+9+*#`Sc&KM%_®~-q` 4za.!H75/sp fa7{Y-mSnۂ3fNSGUH\M^jI> XS%lv ۱k=hmrE7n|- Tv -XQi6u鞃su0HMm婰n ^Ft}1xŷCC8``9'{%99XLy3mK.]v[Wyrpu3u& qc+דш]r=ٶ%_®~0^N;rb\/a/B,A&9ؤO,r)_~m9}hliΎƤNj,l/6s$Nn#QsXL-G-"n1z ?mH^ڋ/^[aI홊+9cU3m[.O]v[:D;1V!#ؼrhiSBaUr$1vuir%Rѳ$}+ͩ m + -ÔEXO_?s\2Ly焄s0 }wk3%Or e C'%\N1(ҹp9rxaȺXQO'gGcq-yw]&FҘ0l̹GRəXQ{ j\-v9EP7xfPxjuQ[i#lI)ni۔/b}G>|vb΃G;4\l/AßkOrP(&{)-vmAu-W!boH*͆ !עt~O&xuN"6{@nR5m[.O]v[9N6ggV,E,N }7e{}r,$Vq9c]c;HwqmK.]v[/Y@|_ĩr6d72ٸXQY:9v$ʺm嗰n Av} LJaARԗTʬA Lbk6ugV۴-v^+'uWD"e{ydy)&b958XK[C<$8;/'99ڂDQ4$.uJV {cCN3Խf %v0Fs-mK.]v[P3sSac&h8Xne $O9A+dQsXۀ؈S/]Ո\~ }SQzg},w)S ō=\Wk lc˥b?o]v[;yGa IC2=)䈸I).b#'խԗ<9-_®~l(^ON;\бƖԗ"JάƊ31%bfKwQٶ\~ }DyerSmYYkqqr5=LBU8t׼維9ӥn(ؑ#.dl:R~1v&={ݳ6mK.ʢ۹]~q!8( b`=l-G$5x^y]f-C-| -f(,ĉ'؊ O49JKL=_D'><L+>$mޑ)*{>KfG`|p&۝L6%7-} xu3xyyD:zJ(lj% K \N$Sش z(bH}b^qʉ."t"͠Gh,"@]iYC6)7ĭٿ4gjNŤ3v]BQLرd~HaEIɜdGSlryJ7-?q|-_v`/Â,BF+ȏ=K2fԎ:A=}h~:SHONDV!hZ36)7ĭeh_m̋WS=Z_>~wO폿U A տ?~ҳ%d endstream endobj 497 0 obj << /Alternate /DeviceRGB /N 3 /Length 2596 /Filter /FlateDecode >> stream xwTSϽ7PkhRH H.*1 J"6DTpDQ2(C"QDqpId߼y͛~kg}ֺLX Xňg` lpBF|،l *?Y"1P\8=W%Oɘ4M0J"Y2Vs,[|e92<se'9`2&ctI@o|N6(.sSdl-c(2-yH_/XZ.$&\SM07#1ؙYrfYym";8980m-m(]v^DW~ emi]P`/u}q|^R,g+\Kk)/C_|Rax8t1C^7nfzDp 柇u$/ED˦L L[B@ٹЖX!@~(* {d+} G͋љς}WL$cGD2QZ4 E@@A(q`1D `'u46ptc48.`R0) @Rt CXCP%CBH@Rf[(t CQhz#0 Zl`O828.p|O×X ?:0FBx$ !i@ڐH[EE1PL ⢖V6QP>U(j MFkt,:.FW8c1L&ӎ9ƌaX: rbl1 {{{;}#tp8_\8"Ey.,X%%Gщ1-9ҀKl.oo/O$&'=JvMޞxǥ{=Vs\x ‰N柜>ucKz=s/ol|ϝ?y ^d]ps~:;/;]7|WpQoH!ɻVsnYs}ҽ~4] =>=:`;cܱ'?e~!ańD#G&}'/?^xI֓?+\wx20;5\ӯ_etWf^Qs-mw3+?~O~ endstream endobj 522 0 obj << /Length1 1920 /Length2 14489 /Length3 0 /Length 15671 /Filter /FlateDecode >> stream xڍt GN۶Ummwl;m~9sfZ깶{}?ENB'dbgucg k21YaU-Ò,le!4t:]L,&vn&nFF3## &9z- \#T&..?B6@G cC[9#5@?!(y͝ mhneh2@5zXr*vn@hbkt|dH쁶1-03/?Ylhllgcohaak0eݝi&Z;}ZX}Y!@\H `/~NƎNNpd#1ٚm`Ohq 5&. j.@)ѿl>D̀6FFFvNt76g#=O%>^v@ S+,`4'hG w611a&vb/*Z*4Q[),lcc11Y>/?URv8qk2(Z*fg adc4b?HO= 6Y|̳n}l5gMNcClͬ>F 'q w]nma Ts112[}\*NSXM)fklg1 &@?g@ok 0sl?DAAo`}>,F Ao `0}D1q &LGӿ!GS l\ab/A_.¬?*~,GevCۏf@so/jLUQ?L>NW??;;E:g79|ps/Q??gΌ]??o!/݁ưˋv.xW2;uhaߢPx |Z*)[戈^ O\Q!Uv ./ۅF֝fZxJ@+D4tD? @%QԄGaəZwb67SI;>,_GHr O) + *y>b#N1 ^yEtaE6:pXF I积]#ڍ5A\o,IMRXˆYi 6Nj`JO&'3sYeJg'@(8ݹHt{? |̀_gvj.IZ6z Æsk~Ѝ7É {βD!n\f=JݖU3T!N$C!/nOZ2~ xŤ3xf}Kjeig-v`߾,@^(9'J -=rv@o|8m Uo/|tqn,ʷƓ-_ CCr=\*)ѹ(OR= ^5\8Ư'Bf< hNn+kr\`mr0ܝqc 8395N&@Ϙ-N&\†[Qȁ!+ڱ d__LtRa8N P(3^d,QHLjm6ImɼgTQOet5 ޟX%RК*~z+>0 5]YudWZĚ[аy=ޢP?nѪ(Bd.j\b[cP}nchjqqI{̰RRW&@M,t%Z.Oa^e[z [z[sqt {Qsdd'ʔ +:l7a+Jԑ84djDg;Cᾧ0읅Zߣ/hwc ohH+ҮKNH>iC\n[^졨UNI(r0Jt}?GPDQq4|u|q$fK+na#F"8Y9⭉Lm6IN85zw3E{oN ^-}L;b" F C pqvo(9Ob_]cFO]?t+WGT*(`i[-E&@ёwk`ѻ| ^}l+W:S8 M?WouNy2FkG 5.*Q "'m[9P~Pavfcs$F |NR@ifh_#PA >>^e+@HjF|cpiG$ c2׏sh3ٕPT$X#QڿtƖk).~/T9 t%4ˀܺǎgQ>E2Upu!sZO[șD`Ԑ]RJ\`K6H[N*ѬM#ݡlw 5J۟ ̩QثF,wnUk:a%´;hC;;/!_Oᘭ]|biό39Fp<T 5d>ؾmX%H۵lR1heYͷUĻVc*UaRpÆIv#U&NjR|Osrs2Lt)#Kx#5P"ox`Z?Dt8a@/olo)W|:5ďo}MFӭ3r5?+QZnEQ 9Zg΀]ˀ3֛c/3͢U춟,񾨲Plh!䷀ o3gkQ :7hem3;d5Dv,2kuN|א4S5ַl%HħHH0"M5br5\5,ARN}WmP~1-`a+tx⤾@pOk |#ɾ2~zoU7Rob:L=s3vɅh T:+fS61NVřќ&|.݂iʑoZ t+q߰/s55 mwMrmɦ^&^/uo[G~=Ue0ey+*D8`K.OP'ݗ?byxxKybZw]|JG9sZ]j?՟隨6b TŎAmNZ09 6pY)j sApҳ >< hpMn (LQL4{$ YAPbÊ *{ 4R:CF% ot;\w}&âg=JsXxi0qB*}t)՞2ISB #]dvy0"K$gYGj7ܑ(kiK >{{UTtE  [2ӏ/(.*- qTQ qo7DWã-T5q+]Yxaa3g=FpIe SM05s=%r.WVu\PCT,˒d^Xg//z?N)}|4,1 f@݂q}3Y+gg<#ž S46Mt*篡ԗbCv<] S (mG%ȋgv-=xͪWkХyu|ȗ?9/"sL(Hf]&ƟԆt6ޯ*O5bBє8aNyݭ)ao*|w7IuZui :)KSD~xYYiPWk"@b= }i!9ˁ42mۈ84S̺m`t&MUeZr.A`/KBS᜴ mp&S8Uި4uגXk7V7`!czzq+6Խfc7~\b C埵3iv5X&׮b 4ׁ,Ǩ [CHCk]z'}F"Mf_z`_2 ğג @3rA%-;i)@0(&U*T*':uv[z#ӏg h9ЉGY}> 䥝/Jw|/"jH+?E:#u)˖$^ըLaPԛNafp6L3^%}(gF2KyiV.,A+-=>9EκD kV CH8KoD3!U/Wvd*KC @!k^n,fj-r.^^>+I7K Eo|;L?o'N>Ԛ}?e,ӯu|9yw{X[1grqO^yDr{D@ ^D&A:MYcg4[[H =]Ohw,*'~+bl$CRqBϝC'/+NG.~sь._^!Jڹ #72ksDǛ=Mu@4-y؊">R*w B:FLb]N JME"&gJMrE/3PC S6ٖzČ|^7kYvfP5pAC~\8Pyiz"m&ҽEOj1 l;r'Be rL,2MT9҉G,RS a[: ' vSg}o/6Iw'ĔsY_ϕE:u@)^R}>q}a*V) ?qGt#L4͞V$Xrh~MJ^jV۲KXCW`_ @5ڡJ4D1j^,2a,ѵK$],(]Xu`U 1T8Y=T4I`2=ޝtPPZg94u`AM SڳCy Gő ]r8ٸUUgx]SsL.# .n eaDx{F+z`oX Ar2KZiu}ګ {qf0{ o]vdh.fճA!#MET& K~{x>7V"d͝Aχ4J*.(So6,K721N.QӉ&Q|"A)~&lH3Vknj3p*m*2bZ0>/=F4Zm;]ռysKy5PT@lsOO'L/am" d`2b{!BR!XA8T '`AQKҔUZdF'X_@Yaz4{ PQAnx7%a߿4r@?ſXVW#t^YU0Ӈme :\x?N3OtHX4tX͌5/Ym JY#Zp"kTwds\ɳ*M@PO]iC`컍VAstwԧi_BƩJ&HWwve"qkגaʆk7Cs/uߗ"F3Eߢ'ybJ^C<`ZG7q4!VfS1A3XɆBHj/j:7aw_pNO/? +y"I]JTJ"V:v4"WK6vHKa,f:4ˤV$zZ@s|ζ1Mhe.ٷx )Es!CYO椃 2O0|(XAM#~Aظ={Mevۖ^:,oZW(>_ZCOBuUm1c 9 Uy *? 3Z(}Vh-8Qe-([3C] /'b=L|ڷK#I%JRK:;op$ 6H<{Jb!<4 ٦޼_^ -Blv2Td*u&l|+8 8C:͟ "vQ*‰~NsecGLM;=R&9Zne)]~aJpg/J+L8dCS ./5W닰@Z+C;H^CbqJց}VƬA1;KY{IGMc?m@^"G(߃t;MVQMz(t>u.~{O(B*.o)q6bj8]v^sFҫ3u~gKgCq߸:$y7&TM,BjCԭdH5Rz?M9k%1G!DŽj, -2Y"2OrcW/ZDB*c21t6<;uNKB6J섴U1,Gm)WJ ਃl] Wst/ "$|//6م}/yᱴZKzBiݣz8j<tjrqL!n[8)k5iP\gNP 13E॔;lLdYuZx*9Lj nb>yʖƇנ rn+G}4kVPЯ2ǤN4ZSz旨(;@2k Q^Sp|lOQ$QPvGFayR/HcP%;ӨxKX~P }kY(Fԯuyg!;UnW'_\HmpuU4Ն{|0XiD!r|nNuhc_Qa]8~ƗX̐d?PZ68:M]g xD#j6;k?O&wǃwfX5KElc I@0NfG 9R*qyV:@y…~^D<$Ds nMhG% e1 ˞t(EATqaF{ T }oXGdzIJij Gwcضyb6`zyʙex'Xl8t={:B%^nFq:ѝ=ܞ[aTmF^FtYyO.Pld>_7@Sl)ӷ%_׼yX蟴\vߩU#BlU댗*ga}:BbO$[LӒξo;I!F񽵇H2͋v+y,_{đ/~*tsiUk筲+X W=ӈ#-&5[9z+7n1܍bq 2 }Nk%"6'Jg+joWM^~( }t~9vWhf3<3V#V,c/ WU8 W+V|KOo6 j_ q1fsby& UsFeSއ(X@"I{i;YɍTUjڿ $MKW)p_ 1crO[2Kzg aJ 9 @TRB.wMi9hb%{@=uҖn5OF ҵTh=^ȥr^7HkW$[P:Qj hnY]2?jdriƒX".<9=y5ӵ)Ixx]O]cX'$YP]V=QG>P7AG%Vൕedr~u`g3ONPSNQ\u9d J4tT)ɒ}'#]vGԎr{ؾmg4"UPL:e}e%Ӛ17#4Ė3# 5 %y=?e5j!^7);%kQ7U&*\vemO*-WF1ȇGEPcTgRAg/wG}F Qo[Y`&UVKl1U'".ځb.Yi?Qz6*ن>N[iqm2Nt&5'h7Q[sܶi-.CC_B  Ui[^v'q8 xX<9?߬{I!]Nfu;~uUx|8S )}~I%*tzHlUI8DxH;vp2~|R*yEo6 c}[?" 3깺lZAK:۷8 UWʖ{掝h$aM6m]|S{NuO5Hl~R38۵zHjԍjy,NdnLblXoH5'ӏ=RcyXfY-1Wǫw攢 W{2Q#c_dk $G6UHHx!w(},:~tFYa0eCj:.!0eod-Z2צ,5K\DŽH{v;!.jA1]IthШ70-4p!=bA:9Hݑ)5 ,Y [*TXJ=;;jO[^(kJR'µwdkI*&C|%:c4>)ۚ/>D$[%+~9πCa*bˡ8@fi[axG_ Zvi:whX@ؕ! j_DXP:0`! gѝm~2x#]A9`X\sB AHm /@d*j}ADFgT&!]P&{badNp`(&Ni|imn!J^%šOݎ'0w_ >.onPqguj `o觷Z94x=ɱ[Wb֬R|]ۭ4>qA"HQ=G7i#q3dv;&1R-6_A1" v?J[ʦ> !Vsߋjk FsXfq6Qcn~~ 9Z9%!d`1G>?s4ZA76Jjv X jd^d\HN|m'3>k}jB3hfePļa*杓3<24\u]=x-qE0K,3ǔ=4UωpcJnze~;!q+BD&HrbӼ=49׾)ٻtL;e"X$2c5*^޼ h=s%i6vt ⽆4e:"x1,Kͻò-wFH-%mD#mv EbK#4akIeIR^ Txi~3thĿzEz@ba}T[ll1Q٨ 274ߝsRughQb%6Zgyf ?XMkVBd1"%5KZV$cʹ!w[/a)%9A~?5Mmta:]ZF{s;r@RW75R<9x%/Uc`D6Ws h-FwP: 5 |&kAR{HQPR>eݷ35Q,DU=oi0o0 "Skp˄ndu<|5MW{pG9ʳ_zY\LV%M{3|mpzn6#y$b۪?5K: Tp{`D$ވ xREc9CCr0b%Yfwl7l |*u6~{m8V&,f6§ɍr{+g5B~g-\[ \Bֻ5 Ó[ @ޔOymv_DH9*l̻ɵt+^pq+@O0_rj?~8_ BPPS9 Ә=L>w1XqP?f^#945cA22mZC9'lZ^Bc |;56cf 5.u07MUקR1!tͅpϹǵ7\?%r A8M暎S"Gc0G8J?c2¼l6R/2KMZP%gy,0Tc>UɈj(og4s<:ά<*'<᷒r҉q`3)Wd~w3ҤHdvsflט+}T7s5wy)%? ZͷW5>6(!feEϞt,\-wy͓\/O'ib*ޔs+V6UJB^)ϏXk枂>|7 Cn%B7rQJ2+rDs}R,SpҌRx)ĺaDkRF[UgȔ&:4j oμ+ew(̮CHfzC6zE}9mr!8Bdޘ^6lkа&(b qt_&nR<9W1}E,0C2 UZb{㐇K3$nqЯ\7P^Ij'/Җ[tVPlG#&6yy&*du?* ,HbM؄xbV0W<$G,!P1Pľ;.%%nd٬ xNΫA~da9 Ԅ eRxӨZsM)ˌz,!O$2nA5@)zlse{Xg99;Ql" `uʗmt# Ns]nu-x'n>yj+:Q`5:P)AmbJDS|KvCjuc-&D<:= gV9 ˣ59k֟e#  tpZ?7,'i_qbڒ`[P~lHEDa!][Crkj=inJWeQ 0F,xj VQ6b ,_KB͈O`)7_B&%8ȡPXZ c7povȸ0f@M% yĵ8=r0^>mQ sm\oiҢ<AB v:-4 WS w K^vӾgC8/zͨ{B*av,"ܫ3@WsK|'{ g2[|?%B-c&`9;&aznM,R4shmooMʿ%Uui TLTtװ\O #y!4# Vg]r\.'eX˜/@F=7Klu k]6#\G: /;ȔK tFr@dQwfi@ uC ՖDA/ܨ [.Tw)хs䀪as8=7=K#$XS o$GGI, ܛy@:Dj =!Y!f sTAmMxUa]!1&۹qUMN*%k=F_/%$SCGk \P;g Qe&h)`I;qz^kG0rB2]ǯkI|f$ w#'Y!)d2%\.rdrw 1IGA/C5~d-b-5 2s2_iҲʔz^^ ԳN@7#1 endstream endobj 524 0 obj << /Length1 1620 /Length2 8445 /Length3 0 /Length 9488 /Filter /FlateDecode >> stream xڍPj6 ) KIwKww7 ,.,]ݍtKKJ#%R"t?}3uu?w=3KK"n 5@!.,zvv.VvvNTZZ-=o1* B^a ]eR@G;e(jp{dg! t[Y PV [۸<@ocw@@brxhhB- qqq| tpf¬E`sY~% P:ʌevK rq@G=q~pX`My%#_̀k`o_D`ogCV`{@UFÅX2;Cn@=́qu1s]YRdEXei$qqFu?)0 dXvO:kCV`կ$,]ٴ!`'W&"e ;;;//yXذtVr?fuX=&[Pn *l0Y!?AVCs2~/K(_eSW`+tP7 {<7?Oj@ߗcQbccA0; qAG߈y~/d\?joQvuy\ er@T*K@-W'|\q?E;ˀ=@j` &?=x$C@jPg?u{|N;[zܦ) ZZ;N^z>69{lˣ 19_<6_?M$`l_wer@@N1 /xdGf? 7 | r 0{ <@sP ڠqw1i4EX &r2Cu֛5؅xn-is%{ȡ-ꭷ>w; u}d(,Zb_||t> BwQ@Dq4ւfDR3f̗Ψn;lG7\&yE\qyǩ'VJK`T+s$6nG'>sX.eN="Pa*UTwhA4 TUqKY". . 1qEE$r51[[C<&}󠆥wVϹ_Z ;%3s2*&Fb9ZZǠH>#QuU .u uR_W) B[RCm[w/ZgcHQ,Eӷ'&{=:njގ##Y 3O[T(5jhLQHhU[BUDfN*7%sx* ņ6!FQTŋ =hptMUnQGg~6&{ ]Y لB\7;b޸蝘@ʪݜ܏sR&uoMo^)=-m#p9^,`E ؙ7kM֭-'ReneHb1vjk~bOScE+j.d.Sb0j}QSj{+3ǮT \?cԢgY?נ}>h!$o_RY[|7⸏KV|Z F1$Cgtۘsqg L[#q9CܩD߈˗(;Q>wNGv GJ]"\ay Ik5l%>~=7 o>[fKҧG~Csw';E_ކpoNa*0e%tō6GK S4'f(i[vdLc/dߔ2y˄G9@kZt{WŒ.3[*MH V},Iԋ4y3U܃p63ŃZ+#`-LhV@z Z"$2g5|SyǠ3@nֳ֓);߂JOWR*ϾwmWҞi 녮QфӍVVG)/j"v,IPq_3-Oy4 \D tjn[ǣ?&m$m̙" 6YH+ffZ 8䌠BcD7ʨ󘴁BI6sLˑVܛ+]R>czNBw&2K 3j޼=2N׊Z "?IxؗAzBhhcm+ׁ5ÂyoC匧gϤ>lc#Sz2P b~ip&yʜ g:1A&J_o%-!\P֫,!U;S9;h"K~;IԼȶ\x s>O"_R}ƞk>& ow/Àm>!#2T4?*@z*mCuhAMpY#,ӠTNOn; U#-[@~: 99۳|q-,ZoZ)>Z_%;JgW0軎u[eM:wtE+ֻCLYH| )u5ȔAt}E: I!.. 9*rX)v>}!bN*G$3I_jo;;Wl͆:ϝANhV ;_[r{#TjsQö4yg|.v}PvVT^+wDIpf0Şxfٗվ9a\vwodgdD|ǼZhj!͚Z' \(ʣJt90)|NyorE"|ߚ5Ǭ#!GsWԲ7T 0h$R#g?j74ૣ_Os{|S-'/;GxLǾ=ǁk,Tm1Vd= тIVX<1";CHMa^c>Ehmq)ҿqjrx)HK+T[@En ]YNIa9 -T01uЦxx@#f RcyE55^а#tf[zxL{R^eJfϲ,Eln=@ l5a=߼:+)fm8%1jm0FTw-za+T-ӳf d\r 8r>u1g*kCjCJ2_ H~f[NLa<,;hsvњ^\aݘ'TC/qā>!eNWe*Ly.OyI^yz+İL\(IMߛgr[e]><c%̋Ϫs =9S| \~p;zx= +*j/|d FVo~ G S Nbi}ðEj1Vx[0L \!Gi\KGttǃ0D<x|$%mW;|,-rlЋHڢ5T>N%&Π\j޺J$dL,{4r*Mh o;%.k!;hiZ' !0d3Ell /4$Q!Ǽμ] :#w |[ޤ7\tuü|^_̈́ul3_RF .]4`5JzMv{v}x;ǦLP5C>%8;WowtWj1t.kb-W0ktC(!j,P$\$͎MYՍp AzY]ux퐐 .չNf9rh b+k/QA2^4#ov/Z+NJM0."eC.&v Ɍϫma+ٵx,G@ cv%9U xu}qBtV!!yY2:[#&bE|gE4S`P[r8e5G hyuB[$HF59 js'C U_ܬT(N 5֩1p0kf䶴3uR;Iz)ܕ5ݎ:*} Ęa:.k%A{g.NQ2VjX =tb{Xz s/7t?YџC󦴕c:ǫ}qYT{ u7ds5xDNyʎ:/0o{&G]9iv݀;`Pa=@|GSsdɥjcpӬQrV1әc;+J(0Aiby. E(PVOE;g-fNԶa0Cy{?S36(cO^ rWU4o3`$0Qki5v[~YTWҩrKib^i3c5>8#=1Q/ yQR=jx_k*> Wo^niId075E3IOiq$bB'CY]crFd6nfW1pQX^aNhRuH 1p*X 3- 7zcnǐ ̜}LDd&ؕ P%t`N}QpfW2)P:zq٪LcA.w_SEV d|WueѮ# ]I)'frUFA5X˙CV^C/Nٗ>j`DTv4{. HTojz~cq_J=iŧpn# >>vԨR뙋kY7h=iH5ĸ O:;;2׆/E縡Ips5X0{w[}1ڲ03f,Ȓ~-NXӧ*5=E69>, >Cf* Tǎ̢3a?z,ځ"dD_Z n/ ^_ˍsjzǝ|>C O+1嵆>Nsɓ- ;hy"l3XJ@TAvV!<*lLp_ͽcR5`qG~B];z4 ~> u@7#0Q~]"4ߔSRoC195ӉlkF??%r4Dμ :"K׾ 큠H{G,gG x212Y[,ܭ"3Ȟoq2v).|X9 #V[ۜsIiorF/!rR^^0o /)4Ӑ(VNE}E%VY$~m޶g^r\CrOLJ yr^oT2.|\IA{ȓΉH) _sħ:A_4j/v|P᳍A8i#C8IyA]K2% ׋ )cT]%gn(6~o5SonO"nssm hGnDS؛v'W垁Iݘ,p5 ؈г= P&B~[gkPʞ} ~XתyVJYk 8-V'?/7$_@\G7ƴ|jWǞy<8%]î+P-淫ܬ읝pցIr |D<4wN) endstream endobj 526 0 obj << /Length1 1633 /Length2 8789 /Length3 0 /Length 9843 /Filter /FlateDecode >> stream xڍP.; ]'l`d]; <8 Gv_^MLt0kpʀE8̕[ .R̬͋ uebև8@09C@6yc:PqxEyD" ;AP0@ A\^Pke3ZxDD8q8C-A0:%B\UQ9p%8PW6~ h *b@]\=@j [5A6*+LO^#gq)APqdOaAhwl"5J<䍫<_?пNb{M5Q-F!UO^3Ɨ+ 8ylrhZs8}[k0"B[쏉*C?Rq,?~\ 1RZ8*.\y*Q'+Pl0SIB7KJD3C2{N  D>SyNAQl@^i>JhiAIamĻCOn|~C):Ԝ ܧpTil.o[;t!x|p F48:*T+MOߒ*ukL$z֓ڥoDoAvT0qͭ睮1] $ǂBJFlmI@vn:dZ`0LX'_¾NMdwD$*z$=0b{mUd !.ҍΫ)hI:3>e6y۞+T >6ʽ^^єGL{l$˝N/ r#)x,_1_mWftr2d;#jm-Tѩc( 3b ]S Q9E3g/xXIO5ǁPy%+Ƹ:ZZݱ<' l˗V,a$mW 36~Bxv <~*)[U}y_-xBi'5{>D.: G;&NNv'NcnLKOgʊMhޭ.L:F 3ȗ'$3!9@-epzǐ~s|J$.#CI7ºmlVs7&Sn0Rz~jrX8J_qe)1YR<:0d]5UkoLLi}U43vBda 0цR$6.MH!EY;ߒh/'E:QxB:ciCԍ:JbVqy@ ;"98'0"hD%C 0z>_#[c۝U329|S_]KJ*Vuķj19a26{nרJj/ lbRA=Um-PfbL tK0ba/qj# I֪-;m2 7-}9ې.p^  rxtŽ-p.vǰO;=XG0I fzLS[` gsh-8[uz{Uf{6LI K3W>Gx<9qF@f1z׷ћQ!C>oB&IOMƨrR-<}񢒳,EpcC!2V3#x6-T2Ұa'8GWA&f:t:Ql?y"gt(%򵘎հYÕTS/}Mih^*ehWCxCg"kbp5Sw(搓‹Pez{Az$;3a r/b;IP\xE1۾}JXz$7pd8-D(Wi9)F&T?A H !'rJLoYk qE](2zeފ([?A_{v|/$Gef%*mUZƑ݄ LH%ErHݐUv?<IJEryW/=UG`z݊no}/,t;^ eV/DX-hTpߕ͡r1j\w]?ƏW=nфLnpjUj`u4;)üo 1> L5}'M|Z'8("C1RփȦltfGF_y u5^Ԍ9X)Dщ"j+[ArV2%V~֨[,9?o_rs9,GD|!>?좽EdJlȊ'1 g˧s9͋_%6 _ɨĚlO8Lwd1kܷ=tcofym Aj',#f+V-O|ZqDRQ$ΖlnخoN N֨HPrsD=$+ÌXS6 =n'w! GU3ky&661z&sFRѣBS̅ k+[ZE9$" 5? *{mH˺+6[ DjدoX/En Joɽ#8k}[Z" z(Xv2 KDf&Pfe'K' aP1;ttF&zEmi] Cz"Is-槔4HW# y.~`f4~^m;"+z+{wd 鼶- l=2f+jM Pv]nANGKMqTi7i.EA0|dApp8D7FYxt{YCA5$dI%Q ERzs|:V.nwge3Sb[j1Њd\Y~RD{PHJ8w*&g]3;'< i'ʅ?kdDGW xj-n>`D F/|BKEX>sY9_DAjx)R7..s69( i)!]S,%6F'~eAnh‘C11DuОri9>&ǘ!Te0-Hb@Zvο . ⋗R;6!(dmr';7"X q+xP˷Lת8"c9]LY()׺S򀋫h}8싊BsO9lb( cP?L(1ODQ37``%Iۃ8U'fb N<.4=ٚ~W(Avn/:a02U֭7`j&-U3g13ؗF6a_n7͌nU'İ͓6YorLv:ޑ"Zǡ`y:Kft6I>I }) Zܝ>4(կITsܵw\ٗ~;g/eFK}5ܑevO8tfi3@;qx_ 'ij)s e) M3_磑ŌH Sא!mYj>Y!"چ˄^hK^ c"17\2)1]k0?lB6C귳w$4|z5 ~dHo\Q+7Ÿt)x\"|tLV]Vqhs$ښku㝞LI)42* Uua|^m]P)ac(~&fp|fۊqY R$ DFyq\*AdC0B&]kJoyYG>U JQ)4ڪ[lJ5Ͷ|)xAy_ztʲK7c\>ڴ 8`Wh*ZF{:8V7liQTԩRe>T;Vl2!!Y 21s\K|ݛB༞{aܬR%d_XD7O4gMD#{{0ZՄ’^z`pUKj0nl~G/iu\j2 +9G⯃cŖjrEf״Yp;~ˡcڽT$T’4Vw_)JD2œN-fG,?F=+Ȟ)YIE>N30 SϤsB@iz.If|렅4vO͘&!nY^9s N<)yc湘۷l(2WCDH2 |3MАeuDYͼwYؑBUXNCpn+nw)WwCR V7qo*/^H)OTSEΐnf) h`f\b;oH^ϜpM;q3oˊy]}`r{F(]m$p5ZEsz2W՜ .ɨ\e$9ѡ98Sˮah+kaڽ4%G/rzP<%ˢ+"GR ݤ]"5iͲhPS{9'1Ҕja{e~.r>A^VVK:K]yKgeϼι8KʼnG߱sC~o.SB2d ֆ{L^# JZH eMOb]R tVS%4Te endstream endobj 528 0 obj << /Length1 1637 /Length2 3711 /Length3 0 /Length 4731 /Filter /FlateDecode >> stream xڍt 8m~v%R+6}le5ތ}3? fFXBYCdK,QR.7]wu}}yyH7RǓ]Ac2µCS5*P8\"%eMy)[B%IZQ ) ưai )н PBhh2E$S#/B2 B >Q_@' H ŭp@R8, 0<@"" Xq:4 P2]ON#<K R|A<4_A!RcEva) 0xp ʈ `G3|A9EN3z3D,)@r `f|J)X~X_, l [XF?(J%xo6 LØ37$ Flψ@q~ݯG $f#x̆D8IF?I jp8\C ',an9fF>dLp?@*h:@xOvt'8Cυ!2<u0¯{ @ ԑ@淬XMr#=0ߟҐ8r+` Epq/y B/dL"d?,4XS2cIHځ?z4,cMI +!Tpv՘ 4ǖr~7ͧX>y2l2veQ$jB@ )1V<%q%ib0F@6oHFj #{3˲yB/`_PU_P @~aefF *0PU!UN`AR`H5@Ba2[RgLz@Az8ϲ}?v6}oa(sF+_D4#Vb'Ss" ?/A_,?rgNsWO4_ gY0DlqlxaVxr33fGO[hw5?0{mG:=j!]Che]E5<գC)\Ȑ[Pi^;rפ)K{2 cy4?;F+*zuǂJ)ỊoE:e9k>0[mG7² ~L{! ͋,gGC^IңwRG돘OCϵ3tW)ˡ z Y Y?O@T.Ţ(P>'4]cݗtآ&)[wSО#aTe5OhO`]0۝-r߸Y{!LR# A=- n_)!M 0!tE^NY{>6PgՖC Bc"m'X3NOm۽ܞwµ٧"ޤ 0މEgG5.Dv{~[ٱ<5s$%5ݖ9^g*dr38?vKCU{cz U3|$㴥a/`W7M6yjW@*n]?PZZĹw۰q4ݕcZVsg,xtH^YT Y4= oqPjX 0Z&|Ai͟V#BR5(:B?m9Ϙɼlv~oGq|tK\\f#\&^WY5/ųAeltZ@bc('m꽪dF-tD(aΣ"B!Gevd/B7})}}GeEk^PWpO%}pLV!QʬJŭFRXߣȘ*ZK~%i̟/ 6D_̌IVy56~ML<[o1cs׹+q1$%PT_DNj5 BijٮɟydXlˆ}Wy7~N!|1f>nUVkU>s)8t2@2M+g.iȡlCrmףt넞7csźّ:s 4V?,#q}}񇎮6I+X%bn#09oO!b|C?gYo=v+FYZ~wcx7=ڋ%(YvjrǔsW'/܅ۇ쫏W$M̞Eo0.cyڞ`-_Ȫkxc2o_;Qy1[ r%ygP>anu7v^+SiZmb+ƭ|4q1Zw>XgusMFGݫU~ٹozzܛҜ.[w\fr9{t5W[Q]'d xNIx[JEIJ [pJABΉ >Ν9\Q S>&~gytgv}N| jn>e'@ʣUMZ2$ KUMnvux{}׍+K)n{nwv1#79)mBӝ8i!?GY8,|-c/Z2ښM'fCLJܨD(GF䑂;Ѹzl坭~.N{ޓ!Lx1jLoc1K?W'zlS|pcu-< >۳F2s$T4ߚb Kl[-~Qm)hO/oF SW_ .Joe+~1$0Pb(I˛Gn(7?<`dGo#+w6&KeQʋ\K׿r2n01~奤t'P_:ϟm ǰtOL6ËOf[:%+^9g |/i%1-_,7W;rfǮ̸IQ wT=8r&kSEuLJqm7)~YmF,O(oD]1LUlX~B9yvnKlzVLnP _y~fHiyWӼ\o ZN {GD J!õ;K<|\!>e.Mt*e(r^qݽV'PBTs|Oܱ1[hmz4mWd7S['٬|.QJ:s <rƱ2Nh#^}3G5:9.1;kP~EC8F endstream endobj 530 0 obj << /Length1 2623 /Length2 22559 /Length3 0 /Length 24035 /Filter /FlateDecode >> stream xڌP"% 0 !ww >$ޢ*^rEz!S{c =3@DN ONjb\lioA hxrviW3+ _@ :Ó;x:Y[#ʄI9@dibd3rڂ"TM,.rAg`d`dOMpt(Nn@S_lTOPtGbon6&@;g) P(8!C7f_,6621u03Y ..t#;ӿF6 {#7#K#c̍BJ#P)řr겘-D-&{23Yk;{w;3K;S0uu`TttJ]LLLܬ#ab{UOJĠ |f"f@/xog#7 `ji0[;Yzt@ `@ejog|%TT$i:aa{7= גq>*Y'?= @P~'t'ԿKW'\:@9{`j!|wݱ)ދNO0UNwB=(+bTK/-0_Z~<*O/L` #WyqQl.Mʅ O£GHܮ^ s}Zn@ yq,hzBX 3whoұ',Q^,]d8h#I+ -|Ht+( ,UvM5n#;9`J~&  Um.5@ƒN3;n3d%7 űsz~ևn_"4b:a+Q 36hzAoAoߓ/.q-X 3BrźES*fJ/6*DKz X_oYj;3PV3!I :/_UTzmOn OnyT5x#R!mb)HӮ?RE5 /ԤO~&`e;PfbgYmye >G7t֭]ø\QK l]T Tnb#1{C"Wn ?- wDz|.!d~^ F'+ f$f j8,6,%KetEV\`zTJԍ !dU P}"c`.`ޜ15]dzs%C/UB|ǒ& ?5e13ڞ7=.d Z\W64TW  \s&c!@$v^sy(1^t[zˑ$|+MM 2 ^ҥvrh 㹿nkNTg=pӆ{ uAN:l8X X0}jw*6ՎЫt+AlYN~ǽK1q.c&%qB#'i{9 /:o^~ph6ez+ԅ5 |թcޭ\ĥ=X+:WFj*h,Pd8}7@gLS={F) IU-(8DguaHk{T14`œ\W4rU4.c&)D0v^- Pb:PW]m FFBT`Pڰk*# : lQ'\_)Q6T6ݙKS$Iú/FlJ#e[E#8g}oΦQv^ݰ0yylpJ{隟k~޾j='Ss O\4 fq񳙃umldmd=RO8EnWH!w ?a5kT0? sMX ϙ: FX+,0}-u WN_=ҹA"ID7>rL1{ŎI ?Ҙ'ڑ_) +N4y N~:O$4 B!fj~`asG+B#a8Gu_mA0}hTFMoг4B.t0AW)_tR2@_pgj'gBZ'*]K:wTS#зf ~A 8ط׈i Jc7\vޒ2t9(:s,2kp(gzU{/)5fS !es`ks'+ e֗/Ӎz>aV.傷~Es:]_iÜBd+v月}eI~>X;sDD8AOh a᳹b)]L:,whm}Z>s<1 %5Қ xyo {U}api8nҫ nG…;o }sWNKSElԊG{x8L7ǃ0@u#@E69>G0Ds(ZXo6%u?L@?0'?p:pJ \783B5Sݔx`*!TnqK8h!V&}l s<(S'T6~Qg3S.WTn}l< =}_/F?sI| ΎE)4)iAKqʯh9˰Ep)`Y攄bpsbԩ"$E/d,eoy#SV4o!Qi `_c qUl3<w%o~]! W0*-<;.k0<Ĩ$xZ1!JU)[.Pxbv\\ldE5x}S;^"*]y̽*,eIrKC6T dDA]F[yvNp`ušQdRņvtk}7jI$ē#Gp)l\_GUӭ#:J!ZT^=rZ%D" ޕLbkad[]ƒȈG j e 3c% ~ib*w:rɦ"o) Cm6#n4$m[LPE" = = S<@w[ǵQg64-F ITRMF3_%IfrΓ03Ěj/w MZ} 3V$ oQ_jǮbrkVHaJ/SXWw_ Wd¥c kQ]EC;5.Oiy[-@VRJmԐ?N+ x'|J98`t`q` itXBtz okKeUo6 Y%zϒG*Ss2UP!P\q`^'t+(s.yکB҄׶>ưp'Vs#GJ v[ ,i{ByIfe7J[4QѶEgbxoZs"u?l$\ $a waAx݈ٺ`Z\ajKvϬԜۂܣT/{tqۻ)'sbV3u-TKr՝ޫ)4-'CB;%S"U@ *1}i VQi`8L>Ln0jL&َ`|BG8@P;)v+v٢R._ .X/-t6Hڎrm߯l]x>O1VB8<']D ө C1q:1"Gڳ5 F޹F#L&;do*!p}SbzIy e =IV: >Ü{Q,76L޹e.rH k|h'*Ƶ^GQݾ@$I7/)J?y=HYUFxJQOɛ]car2zp=[γm2!;Qts'yQ))-Ktk䕺$gFo&TyNϱ`T4Wjʩ,64:ZE,T!U&>۹!j7aNT#h!D*Czf.Xۧt\N__6 ?{tGAeSj5 | |6!Kr3n bFkA&9ڒWxb[!jPjOԕaØ3<V-U+0H-q2*|&@>}>֫ڶG] }čө3mZ]" 29Y~|=i<ٟ.Y5Y;"C'CwUy9])^geO[]Ҳ F ܩ|ۊ ;wCPwxdiև޹:}T4dwj̰$NZ^|!NɼBR"Vp/a#/a2lx42*ᣕBA}X}+OuS#b, UDZ;hbrzi?ne])m}ڃ$>9 ]6-tp &|<"vUPѻh}AЮT Sv`Q`ڿY'H?| W/P"K22jOYI=th=&)Lj<OIA7g;)v̮SG "MJv[#;t#:X"Hp?,}^_.A_II+C7BJ# 2D"$ο]5̎L޽^NWjΧ7QPN-4є]G3PȒ\}^ٿ/~7yzC@J ۾ ,t)(͎{fŊ @f51dtgUX9E+RxL]הyTIM>|5^&p"X=#/Y6Kecwí Nj2ED 6U ݃SO)V^1jY0 ·M9==CYGkvDtUS̭]<5;ؼ[O?iMN;_( 㠙5fl4GbP:g] U 4ASsEF pu5u)tWZ Nhw5h˿2(&ō&+D@^h"A>Q|a=J'Ęi4+ē)`QcX(5Q~Z1ɓPi> zxq}F5nsp/ݩR j%~jV=[Z!fz8d#/ {'I%<BK3 $`["GP9 `z"8p@VE!ܾzu%TFhT 7Eqִ|Ṫ旁R5z}m0VMwwwou|U'_ۋMӮ~T _-CtL $!WLލ#+'?sW@r]E!D~d' %5>FquKde=W절.ld^vDWs(+y ydP7.љ:sQ̤ЂPyOBی!IWFxg>p V#Kz]6^gYBcwS$_d,j&?~ʀ*Co-^Vry_HXRэb8g% Zb *{QU8^حL>JCǔO /BS}2O' *[9ڐҧԥUSo>ҿ'vp!q'yžuMX.w$гeLC=<UP N<\ٴ\=%Bêrh o#nX@N&%1ͫº,RX2nJvۂnS5וj􋱉|5:}餳6;D6=BDoL?Bخh5s tJ*jk]txz#'7-ɉ\HgԒ93"b+.)^p;F8aG[5UoDEەE+w)T6ϋ+۹OXO=]^-_; Nʘ't!&O=3Xp4z EG49笠6iqN|"c6eS ybTya6(b o;Ȼv+PcsoThGɾp.ԑhp 5L2Mp!ek=+CDv4]?tBSL3d2YKw@Se0STV|Eg9n /R3:0ENbܝlzɚz"e! P s4&t$MkcKXs6w3L}zO(?wHytCFpvT4FeL,3`QUV6 M/?S9sQe{wpE&: 7HmS$w2 ^ "m$Wq΄2/08 x$1F7|홒|b1҈}r~#P k[T3 [iBM&U@L; @c(E9*#pS ©],5$QmښJ#[h߈>pUS>XV yCmMևPGA"ꑧg"%g,,L)ջu ]tpM,V9Ǜ}Z&ݜbR-!GX3rl$_ZX}a&'lwwƠL̎¨~/Fyby\ڞa=Ɖ[L|!}gc#QĨdvlUDuj-FI%NBC\iK+0 鹱^ŅUI55w!]̆G+mc<`G$3tFI40me-rK~ yɸH.m0.vz`>Wp F.OoG=Kbi"5NUZtFD7)ik0 gn"*pjHyQE*&C܄\}.inD6GȂJTÜ&ImQh׿i.>|Cq&t|2 e/$Xԭ@0 ]mygoldEHP"!HaQjŤAw"\MEdPFDR7 :yDUac>P=\Y!ᅹ U2fqqir/ }hmL21-n]/F{QAR:+~KmǍGA{ fS*+ [RDf~4" `5߅ߗc V1e?]]ky΅SB{pEӏ(LTgc"ݟ͛;ăAFThBR %/)go+I6 #4k맘JuUlc~\V*NV'Y|Z1LR?5h?ךܢP6]ޖp7ue>–г1L:6uߦ@L /"fAYWm-Y~:EY"2n;Y2 axF*F6vhFew>.]o?^ATm';׃`7**J<4LoR62^ E?}Զ,/wg52bANGY8 sD*.tL8yd{yXbM/=!'h[Q c2~}JQo$۰EQ@mq蘽Evi!6e^g<%|Rg${`AB̜3M&Ics2'u^ׂ|w=r5zg6-lt1'_OW& !{;Z#W?8)>DоH|ˈ^pOY6,z:sŵз {t\_[w1 k{KX18v!4WJ3yS0 7p[/>oRuXaN9.&7@$5߁άu!u" v\ ]g7U(@20Vn cJ;3nf4SlK=_Dݍ?-wV8yϊs/c#i%&φp ǦQTf̊S&DL,n6\zHrI :O$=тDu1O[Qf1OΚ1!d15ЕۻG.=ĭstUxY7Z_) Io/GǁvJb[h} [@/?&3PXg6j $' ѰJuu3EqtFr}+YQ g:L)(KlҵX)d{ |y^}F0D@ԘӍw8F%-нi'ta7ierRS匽ceSsG>X2}9e5Ugz;7K_}GXn44ү (M5iet~pRT"9j"%\,h*,c/ʆ! ?uzKb;#YC*UwkYe>ӻ [X<åq)&$%s6)?ms0.&02ؾV>Ov&^5 1+U6v1G qXTٵ\vo~DckC4fL )g\Zt_jdvپw,?ְSc~ջi<DŽ-w!)ʲ㙍4puӆBGDOJ-^OAJ;o>a.<?s$6nàb:/lRI=ؐ[i3C7ydS8^.t/Gn|llYdB\x'Q#cT$]$/?n *Y:}_܍6m8VV_`LPBmr\&mY L켼DX? Fo,ͨ4xO؊x3gpJ}=Kӭݷ_z7wQqV]#E caοIF,EzJ 0U6jhNf@fYMk!TvHkGZMA鯯-eK'uӨL^.R8_,EEJ{U&>6N;v&ܺ|E/l96J'rُ 'u>._qn ڿ15[8mO~鍯~4 Ob nY{,[wuaAY1)uz2R !V&D0ao '?$Z~ m-uգ7ҬصںJcĊ8Z~$Mv5eym"m_}ap3(X=2@gkA&^w"zb/*e#K0nkKvTAh"m!y~o@H3B=B7i~67McBMlFl#H h+(iP 1gpgzu۲xZ:oaKZJpMrGŋ9<5r07áĠ8,y&&bqDs- 'UHM n;O;qf0w? -_79yuQ/d;^3;Q'XF3֎jIU1N[{U >^Sy,eٽW{`%[b! I &IoX'M}Qݬ(t .RDiUa6.ԿGfC9*l6Bͱj'^m{|W`)Q*<+37AxtA}OqY5ծrgqJ!$ʙzP[(xgO0;UMO3Q]xэE0Ɖ~r6P4qKoCƢ#T 3_DO~fO*%a\  rH*hxrebL>,QkqU,}kƳҠC,̒7zzux@gdXleQ&#C>b_E @faw ifVR=bʶ L{~;-](I "h>Xn2rrim'#?Y'xW)# 5CKkH=x!Fqb O2XY_e>3|)C(emRq+M|9`(TݷNMd'+ ث !700OzRn8K˽>)}'>0o]cHd]opLaD=_H2pGm=鼉8E oyNb,i˷YqU&5%%+ d+ hHdlj.̸ E5Ux>T)Wũv׶̱2ȒivLc:Wh{+y*lmJ"XH6YBa9s0gt!x ꐅqpR d޶sקpx676|`BӅGrhpҲg5(<&Z}tR>^%wHqX\O{ÕGS τyA㻿 s.g/:=(O1xAs RZ#OJ͔4Xɨj}̤ńq,l|˜?otۜ+݁]{5a<ז|qk$6bپYEe&/ ) ^#yTQ:ޣ]eq<;L_zt`~Rx)d0P3:iTaPhzT9Ykxr6no=|@!=]aJ.1&ʷ,A52 剔@X,-޵QK CХQc)>~^:ZFRK "Zt&q,]Ŝb*OwI 1>#- zQ6-\KpKiCL;rDFWǗwJs5#e8]Fxb6bWb^)o ;A^ⳗ}"(DJ?n1gR PʾE:3$w$O+OE!LNI?MP6O^yp\ɹ-[_V(Zx1h0WT@kKzy)J㊍0&h(ٕeiqFt.JfgJ[1d8aDbq^ceş Ɗ`i;K!&P'kVIe`$2urQ|#f!{T_VQȂ/qScؔW**Ljb{}^بRߙc8TUs7'<1O_M0 ^PLM 'ܫ:4\E5<`SԬhd&|lR_WDV;W!0#{=B2=HuZCu`a3$,>Pjc@W!eM3.1 !xG3ںYlmJrn7K%UN/n)Z6/Ntm0cCl+>z[?PEék+SoIw㙒QOTbtPrt^nɫaT`Hy#{lS_RaeB+@DBk_][ql,3n?J 0 j裌6M|HG 1 A2@&R0ZMzWrzulE9#~ez|Cq{yD :J 9tJiȹZ(~&%bqH}w;{ծ[>Vs-0A ÿ-; X]@ ڈ8|lrqZЉR'zp% '#s}0&Xj7;6/<L{q~ m` Șao!N3GI5=;ZxwjzdM`x!. /Ĭ!o1N=Nׁ K]5dHq@b03@xT'jⴂpq*GU }r)>ԡXf 9CZP5cfi_~;rS}$! gޛ$ȟP[~g-sgP w6aEy]GdpJ V*g Ic&V_-2k;Fe+ע%ear&{W_1W]>a^akQ1#ʷlIinBwG!9H9i7A͔zXVb厩k$EKR>f(@C\(`ڿ\>#mgU-3KX3H,A=:$ L3dk]7LXD8-1k F:; tз5Q;|i4EEpc ڵ23q{eO?OݚޯcX>G{Wtt *5l.Pr#+ tϤUg<%(PhMt{rF砅,{=hȋZJ=m<`+(G` ژu=M ۄ}YYR^j*K6 +Hg)gӘ<"ow4(誓vNp{V۾#gAABR~o"RCtYgX3D?exi\׼_(bNZ Bp_"C&TbvGYM?18R`1zm'ջ\6߆ ̛Շ=`bIJ؉ ϟ6$XIz2h)ѹJ|y0Q%iUK#ae5be)2SRPOa9u~;ʹ7vY0"%cH^@ZC4$?x d 'A;ue o^؁,Cf+Q2&jff{_)T@+1 Jd9Hho[5Ybݓ4&WG` ϘY0h=oYp+~KnϻR Ov=AE78 _^mdրqK\#S dֵңiɸHH`"}U,ɎG]Rzˊxnp+]x7.iCigŌ:VQt47QqanW~#E\zNwIAřГ_mm,=)79T"g^s5uy=IhKfaPQfDpu1FȘ,1H4tmKN+Du9ܫS*IQ~I8& ?'um*8fdsB Z[;3 e迦^CV #t.6GVKAx*$b(6)*4/ƽQ={|8lc$&be|._#=y<x֩8bR_XG0/ŎN<,Se]\/f_c/H82ӱR_WJGfs=RowsOY2VjFjy Lk!; K UXj,(|'_fewٓ^iA2SE;%3ucjvz8 s[ ( )c7A땹{rgTs"۷RCAɻb`B[:,r4/6̂lDq(+3 %#VFYozԋ@&j2B5zp:1aiᖲ!ZXn۸ߗ4Me`odoBdUa]?TtsTQ(S7:ۣ<[+4_ew _)}HK+\UVC-?y@S)cyΑ\cxVlI˞ ڒKc +r glhP<-!w'7T^|Zy9̕EsKu 5UbR&ͻ Xp/7_-ad28'21B?AOͽP7D<1C,f{RW19uzxNrr9,JĪgl%È9~U`pu=,]7m,H ZĻ9!PGw+jzcQUX?mNLSZ|.LWg^82ùa >S6R*&40DYA=TBӝ鍷6J@ã¨cL67ZHp)^kFPzr$: x{h<=o{צ決p# oPQ@I n^ڍ.IWL\ _%zSZ3'%טKZQ3mV!(NhNvWaOX`3Y6DK7tYHF#PRXgYZ/ z-9tk5H=zK8 45g#]o J;Nav5?eܔF_.ƤǭzWW"qt,oƒ~}>Rwn7|f;/uDD7ջJ:xIza5ÈJ}{[_d['.ߧr` ߋKE=]R+#G8 u(%f_^ c^ƁYkm6 #jUbC>9ljrO=1vvQg^sC ivfmbϣ00ؑ8GCV@rԼg[N -tq9::!T PqA"NYPֳ'* e?zHu;Ћ,M9~I0jK r/DM wo5R1v0ɹ ["CG߫wl!k[(WIOH;O{=?ɋ' MRf tm'$Lw(-(@G66"DK3*D6B)V5̷s b]sR?CL_~p:z&-bVFVf'o $~fo?I u 40H2!+mǍpaSz)\0 kqƦ] mĥ*3G)[\&lBOh]O7uC^5Aޜ1;FPK+{R5F[xۍxu >oym$XEXDXDs U+,r/IG4G8|CXfP p2]{[/7-' CCI{9idhf]Rѣ C%wmaoWhQXd,O^&XxHtkw% _!˹ưۣ-&rJgL,̴\F'mW*B[TR~TXajĿ>=6OD1/mQ42k2!ʻ,lCzF_ìFR>E WD|VV6S+T&ai#_DM)R3ϯ0y&N+jH9/Kj@C΢c "'Z '_ ci+obe~-"vti vH+b**g Fj@R{qEh ]mpC Y^0<-5ZF&>~8 WM;(Lv4#oQnM j|&yMQmFkцd PESH|1 k٘ˆM=uSls^_pX›aZȵI.Yy2%YYH<x!_i0ɣA%\,*0au"Ӻƍ Ba_-8iӍ^ej&ch^]P%@[4D(^#'IufteGŭ)om5h  иu~w7#@ q랟Ǒ\Qڲ¹M YߥNQ؞+ "iuG)[TsateJM@v2#.+*?pU[d(DF7ͥ wѷ DZّua@AB :C*pڣ5,Ձ"ay@B9Lityh3:6HV^_p׉]HG0N;MCL9!Mq2$?6tVa_OJ-^V;4iaAݥٝLFû@Hx< o:c`b f>xOԙκf?ILW B1ES2u{M-Nm ϯ -2y M9/$j{u 7ך'FWRe`  ˝-x{3mxqRi&~G/;j³WwRyZS]8K&lhy$H-pbyGļ]tQa >.ԚX6$p-^Hᓨjf@u ?H$8VPsTuo+s|0$-Cʺ -TR0v##`Qt1r#?+9מ6łtmEg6) ]X$Mxh%{sܽe6Pٌ] LpKue.K'j +gBͬ9yPBW#馅,Tz\:ڂ?R3WnGV_'@躦'm,k'~| XZ5m{/j8C?I-wL*6aD7fLUM <'# RSeԃ{JFwǂ茎:w *58 i-glқWTX^$UxaŮiSmۛoވ~Xo̬ySf._ S>PW⪇A?Տ~M)WęҪDE:POAx2) {MX,wv{ +g9 endstream endobj 532 0 obj << /Length1 1760 /Length2 10530 /Length3 0 /Length 11648 /Filter /FlateDecode >> stream xڍP.ݥ;E Cq(šxq-RܥsL畏ZMMdg9qs 5<윜httZg(/1 b#$:?).P_K@)C;Ga (``'4:i;{GS03XpHڂ!@@l}h4!`g (bl/ubscbA`'+MɌeqSigtP9O JU{0Oc? Xwpa%T؝ݝY@!dtB@'?*$'s2w;;;A)reYH svB] lv?'ksy, 0o {m ɓ%) ;Vky؃Pr?1񲷳X<@,O?h^N@W0o#4..b 0[B`hD-Ow 8v ?1_E7:,2['%ebqq|7pCU?`v?) ;GpH#n?Co$ P=YjAo3>w8@\S"A /oD O2ȿS~Sq@RtvO{ӿO8 >_)iqpOMh3v毂kڮ%ضNm2y;`&1Ue8^H& u,n2K,P{4ף$zߙko}#+8xNΦ%}o ߡH"w+^W}$dfK} ][v]Y41 33ܱ/&_d=R)Ƴ)zs=Q۩%[b #^RɊD^%+#)ӄk﹠[*W{'tcŒ$ Q+-lPx~-*+49&@Uu|B[]7uz̡VIuTP :z-ˁhe%&!,SYvuZ7%-EAcEω0׽ f(3 Q'-1|]CCnuKR : Y$a]˅P32i4mRfzN3OQ:SFnkUX~v٣dUE`&nר1׍k.քe_)<0Vt~>=2ga/ԔP{A5Nh27XAM 3O9GpB_ٌ, ɇ[6"vkNZC߽6 +CjMHyb5s;\:>EeSUﬗ-4HvMA%_;Ā#8@r2!+wcSL"<Ęr"%J: 7'ScOQp2{5amo~$zNfܲgiF&*Q1|jz6iG+¥@jT;(wiRݳqHhj%11!-fZ9;F,=7Ōv8j4B|̰U)1eNzD9=h FW^bz*=a/B)p[^%27#J?[I10^Pz9&J{Shy΢y0Gʕ]Z"U:?soqToW]סmjtL:MXZf˳(^o|$WLli7̲ʑ{2/F!}Rmهchb|3@Ƌ#{=}iK >fSl%Z_BUהN[]MǒU:i:l|#Q{ܥ=Uz&O_A,jz.nB +QXcR"pg2{2f`)\ +H #rde>p5sx_KNB$"˯PRn]EQ7%Bֆb*)\|Uo* q%'%vᰤ߬@L NI,0ka|b,5Ѓϧ1f([CRI,?lP֩^e<ʶ[1;k1ɓL1PfʭfOX*VGXtI.|} C*s= 5m#3YWqaByz24j7 #V9vI,/ҵW钜Jq^<},)Ux}9/dƉ{اǾFYWkm&Ýҗ nMe{eۅ uLU\i็z6& 9}̌%0Ty@v{7V;^՘@Zz]q !8f2T[Ja QJ@{Im{Nu]}oXzqǦvfe f4e@Hs28~Jc BVFT~B1\h^UHZc>;ևg:[lԊ o?{K21%q)3aVὟĬp" S|y[36_։)ߙu# PARWaT]2jb-9 7;ebWy6n]=k=k Y;Mm Z;Fkĉܧ؞0\/=NڕoYȨ I+7q)IUUܬoysDaODI0 7[%`~ҙŶW sÐ0cT$TL@R U9k/aUB[= ?9U:T%ÓyQ^YSF) D]r|\%?~=dp4E3^V!_91>4Z6ӁHUʮ+uNQ_1*{-iaPD7 ch>&nʎ${;n ֲa5]q hg/A2Zogp1&z{W!ު;Bnf-N}Rqk3 ܖ fKpV;R5|%Ys5PtJH Y0">.|Zp$Q>QzQ^HAGb~q$vy5n裨Oݢ 9>A?+plrBUT;EGK[*`juoDog`~DxTS>V *ѽtM͖^e״{Xc*uW"JtW^s r<5^}dj8Qo<7~%<18RX+[)cު'%,/EC*`q;|#IkS_ ST A rob/2i=9zTKndwHFJ~7N傱HJߨ+[%2\li2WN^$T|3/@Q"8$B 1>̲]gQ|+FwۄZ(Z)Aj5GSaQ^ aG, h_D~8&w@^S,9e9GG.| 2GVw*5F;1[K̽p-\ Ҳ+k8ҏXo,T^'P[`߉Ha0z_0 សɊ-nYwѸLaEE56_1D}:eQzStS_+ѬC>B\휝Na(.gD;NaD'p9L+tdH9#H]FN?+(Tj<=xwo*0⹫:|Ɩ1v]ol1ԢMu=LvZ'0ڍGS]|&d믳~Q3,D/⸷!&iRYHGF{F,~Q-Á [dm!(vTOcNm[tJY NQgAG }1 94L2u1-~+<ƫl?2\ۋ-SxT8) ;*a!'- h:JE]^ʳG8rm{BY㦑4l w_vK}KA Ѯmeߒ4 *-k&/ Pŏs Liƭ g^@4 6K4_$jxNagt#uYi q%;V}?3wL\UKD]VΚN2ipH A^?.i)+R>%NT@M<#2FzyC. 8`$M?&2i $ \ ٗ#jG'ʇz5Pʻjs(F^5--3,Zw4s66ܒb[ƵK${LW֒K fRj BIj\-9tEfZnQ!= Ƶeykd®m7UCݺT]Ul#u򧺄>v*9zr2;q2H$Ao;nԙeK\h?Oə`]NDcۣJ; WRnMPA߄_m C$֞k|ը@ePvuz>:/ප[O"ͭ`L}Ƀ:j c2pfEDd1;į#rI,eU_`& ]z;] 6h7}'Oy(*hJZ5ib]E[[3HG GQ+a9y~ԕeځ$g*^!>TuSZJ&]KgkV>&tU5]Q")TQG7'm⿧n '+8P i00l`9t w _8_NK-FAKcj$3ys +$ бPĵ{ffeajFD@qz<  1' JR6p]\PQ[!n@HצmLfW@{rtITrXȕW΁{}*%0jVzyzpv}w^<!P1ꂫ`m w r((Y]kFo6oGJ5 D.~SK4a5N `_؜g(Ȁ׶YLjiw-ԻI꫖o6s+}i;˓t%~CnW"x,}b+V3c>6&7h._6(4ri߻ay9t܁^צ-m=rm^ؕxcy8(? }ZjS+x{>Z K>ݥ4=v El^/3 _"{zAQ1z$J~2J`dj[s@ُz2Q}sCld(yDNba'Wv%<&t^k 'p-SVE9o&Lz(O 3ٺV9`xxB7po0ɰۻP&4ϫiCIs}{+#3cKuokv :Т/Nc%|/_d }BrY_Orys&d%@t甘F{ĸlw FBgGq\%Θved5ln:r>J`d,n˺6eDMv:-4A5ԏg%F `&(y8MLdjU?]]!P,/50rQ+Mtء+S7V|J}ľ߇Dn/}QշQCzL%/9 q8)~77C\[YoB41BM_0ߤK”gl^[yз|{|'Rv(:t{ҙ Ο&B'MGO0 Zu-TOa7qgzl_6䦾özfʩJ6٤>a>*ky~̹7ӦwC",blRV[ X=fŽn\Wa=PL*ϗo7]܊.B/{nykCnv០/zw+ev,H4E N}/nM4@bhͪ6A) bХI*0-cyR:+bU P擿i~T{liׯ!NlWKg-u`=SoM:F$NcF#Md>GLbcZ`ˬRu+% UW1YXjy#BL{ le^$E~Ȁ-{qa`uC=f՝Up6Mfʗ纾[!wp߸VQ;| Per׫]FRq=`Ηg6#"x`bQD t]ٻn仫͑doMlt6 }]~|.}6bpF7^S ~tMxg"dcb#^^╮\@=&xK]r͜yd6)ryH= ꁞR|5neѰQD}T)g XlG bxG{WѪz[GM?=K>[ ОfW W%im?Kju2=IR_^]FK ʼƸUqgf-cO%L*:+2M`J9s̜wM+w`_iYL4l֚5  5l`b~wo*Ƽ/^Vr,Ofav† I~`F7e;=H;^נX\u')yja'spNX4E,hCzgSgE/3csbGSM*ѩJER-9ue*bpdt[uDVOƖzRWT~21lyuc<YSrs'$ -О)\™'qL!9|Su{}}ؼ4>m|Wk.¦yU>jG^n3a0:ں j' #ک fӹ4f&' ZWV-,bī+ jDC8L-)x]tu8ŷS晲a^sx%X;4Ѫߡ4-yoe#w \qxU#ec6I;ꬹjg̥/ڎT^Pג߲acѬ8-O@z~%F̓iQ2f"ydvhm q 8WAHM4{ S,6xH$ eJL- a)D QWMNF1}/%ě@ ?W<DoM$cο'*'Ti}_,M-(VRCEތϳ& ;A׏BX J WI9t{᯵A#f]} xf[!Zb/Y:us`]@{2"^YlŶ`]# ,Ir8<{aK78ՏGKohFǿHQ,fe30D+2h`I G f^lYI g1JoQ13d7p4 [;= YF}5zeYbZ T)KxH*ehQd[H jK4I8g4'Mfb\.#_>ZA;U| { :b1F:DZk\3 d%Kׁ6߽d(J t֎mľ-twG?x(cUٓB8UlcP@-<8 IϩOdE_i h}׷Da= 90 g Wן+o@\1aaT%#o RJnJ艧 ]lN x &}`NJؐGK(3yыPiH,~s1#NUUO :7iܞ5OϒoT$?B .Ox*Yv6S[w߽Uc2oj m+Sd=X N'RАs or!T^}X?l=hׇ0mpY8A4nSu=BG?KlV.ʿ3|b֫N2wܖSe&,?)Ҍ$2l:Rx{A/8ukw#H!H)jQ\d*NeG2oVw8pQ GjLXD:medGaAgӅF>S#-H?YsߣDվ_ j'>s CseYF}겇l?Ś_)RZ( *p]}M'zu8Bq}EZp*bd'H|4 n'vLhيΒGxg%=o˴-K! endstream endobj 534 0 obj << /Length1 1533 /Length2 7501 /Length3 0 /Length 8520 /Filter /FlateDecode >> stream xڍT\. "!)04H %t0 1tItH4ҍtJw(]w7]9Ϯ쳆FC]j B`\@a1t0GAB. 1Y M (;x\\@ * [8P A 0[~@`+ @frWphC `99===9,8,lO0rz[8~`؁P+V <b rkT g?lO%C~[XYA- `-˫r`l /G G7(<ha w}p &/vnV`gC_i,:9 07_' EݙSvq)0lA0\ /+;_uA\`}8?u` 4 ` ,A`ƿ0yW-k(_RQbM4 sZ F5, oF%  &Wx`W@>YC4+E{ywGV_ bw|"Ԡ П!VYݝתOKɃ@`xzG0uzf5+So>J]Rb5s| WW o x;>/|8A^u @a? ?iK@]xks=P+DZbFqY.v '3$D:'gMV&-_j͖ͧĎDZ \1<Ƶe%J*'2sURlIqQH/kpğg|h#Dbꉍ|=։EE}B|>aZ3H@ mVր]MҷRW 7Ey7&OOoG=|NPF7D<ı-8߃Bm+󴑔/x!!9~dq<ݰHƷ&z_q"0 Fl5H~">Z awjHbVxO2*iNEb+YF4Ț[ܤmd2&\\PۅdG!7XZν#zҏcքʒ9m:SVaܼڴr;p偵Ӊs祣mpHJޘY/ W>.}R)]b VdA͉&ʠl"Ȅč6kc&DpWc\(ZwGz,Gc3-|oYr2Xo׌6/873[,F#!_COT%^Px5eȸ{Zuc$(-xjEm:.sBVZ{ Hb!QIl v$ H[>KO\; QWl,hiҩUrv34S#sF(@#"*W52MMHyԌ{ ڽ QF< ] Wv uײn#D-_ƪcKvoT˜t!ZeHh .п1U`Y2Zts~ RvgGg%?CbD bwh)ҍI/t pOQ7'a\YTOR ExLO?Vz*7ԎƜv ;{;(78x}TH&|MK>vQhwݨ?eVc'>/%U):=EȍU>!K o_P KhFXő=eVaܮviCƇUvޮT02jJ 1cC>Y` _wh93DZ@GwUNRj=iq Scʼne\O󄩈Wtz{/E) &=gyGݥV҉yqXKs7ƬiRU*drR24V^:/wEsnKpKsotW ے41t YL8MTZ{Q3|̿bmf֡^A 䭋y,{Kj2(p?UteäՇ0E#ð*Vqez=SE@qn<|]4L仢$?c܆I XU}+>N}xQU󬨈vcv:|JцGjBu@Džz "R5T~g^-|[NT1>xƹh=".ۥ^b^k'RwX`ӚeYdNmA:hPܖ|[ M -(Dius[-O$X6}1<%j4WևSֻ$T_pgXa74/rI^O/Z_s1H>!&)n4MK85uʼh97سǷDhfqT/sL͚m'` :dTR qKt =!dO9jc GfK~~'ydwQwM+]} 5=L淈6*G4/m ذ&?2^F&4:$da=nծZ9-lLH}YPz=Vʦ5Q5f)~th8Sé|nj$wp\bb?h` 8#m:@ё*\nQ"8 _GX, ѠHd]3-8R0y! cj.e0A_74)j0XI,>y兾A0Tě%tUb'Aibk m6 :@LsL_ࠆT]x)T@a!q?$åD]v3!wr(L@3qRgٱcVvDvELpӄTb'{J\1e~ΛDs2e7+\sV>OV?p;U~T@U ebh-G/07r}͋UAFes@5˄GpQ[k!pJV'5jn+19fv&KF&>,ɤȀgj٬ymhC+FϤzK۴JbvK˓U7T EojFtM1F٣Ej>=kptNŒL+]\Zx6Tȫo&]d͐R2IAd;Fl铼O+22m}yPJ+'mI@qڍV*(c[BŠKԠ×3o=tuF}l(F!I}Mj(T-&]x*goȳCC Oo,41➽h>v6/{ҟ<2(2M{"!ӼXd(dr^GlrN >L9O݁)+%%ڨCq0W %X3VQ|ڽҏ|s٤9xfF. HU]"v u|_~3D2:x֦D+ZzI߭YDqzxٷ꯾}MQu^NUTWmiF <7H9ImGT=dKkENlXryxqбzGؾ`^׵Q.<_Ep_5kWȹE|K{22YZl^F5未"fqTXHbKB穩*豵LHvl23[1 /v|Zhc%#^ :L;fȏoFxB;KR YhDywONg]Z_jfxW쫂 mn1Rׇ7)֔^r;/^{yc+Q)=ݚ&5PkR# n˦ 񝽒VX Mp^Nt8kjmtyVxa1˴ z;b5UXK4L^^ rCF /v:q1A+䧴t3Gǹ5Q^iUm:m5m)x/ˇ[ם#OX%/Pvxa_Cu5Czbd|E5%Ps t٨y)I^ v'+W!E=z" z찞|ETK#>rO4%{\1r4bRP?uZE%i> j,:?:mc07ne}_Ha5*}hs$hoCnKW?1Q3*;fgKo4 ['hc8lXrM4 $бѴ`{5 Br"HVL_K߲vN<u$wL?Uqj۴29JmWo$wȏWb> &'IG=Niy.:6?tT &}v@! L|]nULsɐƃd Rr&bJOR/M!ZI?ub+Fc%R{5"5T`8I:%g ǮXWż$\vaP鰻[ ޅM rۈ>(eX[y!b*rQ\sZEE-A&;dqEB/qK5[wp: xWVE%Sgr䍹NJd1=s $TC {!KFX`:TÝZIĈȚuƪ꿗 s*4p'lݮKZ8VX2D&{)l@*IEB6pKPkf5v/Z5}b0?J L28ґP8|I4[R8}nZؼOd,g,oXqй>gbxJPF``HZԵ?SV1MVu",/}5\7WlesM@ZC {:'Q^:ȔQ]9+l8zxvoUMW+d+vamF,zIg:%vvj^QBNOD샋 ~ ^7526rJ⚍?۶}`,6-hTx0٥Ab֖?i{<>Ϟ$P*T,3OHycZnO$',fWJ.<ɏK&QOaA%fA.4x<K/ O\u~{D}*ɨ ִ4jZ1߼dbȥ_P`Hvj~iV)$~T:\Q>AݹҫE+^/QlV,()4q>᪸KB:jK 9J#פ b8 GE9Ebj $m~eJ4}[?+8gpqR^B ׼t4 C} KhGY=x ~bAKR0Bu8H?\-_c@{tR p|k!VPc%f -(IgcD,*}23{G3kmo(jN'Ccё$׾uLPG- !ifgϱi1y]*;h#cia)8ulK4@V(%0$8 **Ն?/Wm\2 nT%lE4c;ɣy Wϋ%& ~0<,9,VXc'#?m&\5uDa)ĭ<4qg=ǖ(e&Sҙ+O~e/rNtK(>`ҏ-8s쮚5u݄LVIT XG2{^rZlOF+,e =5S"%s{;Wd:sicB)(:nVAZd֒[}QwY¾nYEDBòf6M\%~n4Q*U{<3]4D!qG]}=n1LERv*y  GmF ~|K! |>E,,u>RLQa")R}Ow[YTH]ħJOc$cݎZϓ+qSHtcV8ȿ$4lmXc;L>ڝα)^r8ן^ endstream endobj 536 0 obj << /Length1 1430 /Length2 6441 /Length3 0 /Length 7410 /Filter /FlateDecode >> stream xڍwT6 #F)a l86"H "Rt# %! !N=;g{xOnQÐ| )@( J 4 l0cfJ< RR~|B ( (() oq'& vs&8\.oЃcgA ̗yfWe;5o-/C|cl.65ĺG(H0f3anEC H?`»Aa'3K5WSoJRwsBb0!4#1Ak? ĸ0Np~ (/7 " ^˘ ]@@.(g_ACfNkxN̟r!Qd\١ˈon-r+|dni lM5|6hb5qޱmw(_>7 qm?BIRzߕG̬Wi\MśYLӱ G?1E7vͤC/\g"p6Xa"EFoIwrxOiYˈiOinkzF؁cRtԚq˭)%)"9 Zh-)k}7:wwil/O4mʑ d֤*ḓ/V-lyJQ ei]Hg: ,O Lj#PP$Y4GI5D*6⃭-|궋֟j|Գur.Ӳ"$ΝHm-,p0@͉ԞxE!"kZQ}k'tL]5o=7qd8گ\XoF}ҏD͢;R7 v`AlZ{>_D˕zp|a~v?1>ސd`=c/V&if?Kb L񑽊p1X>[S}ceoWu[K*ʆ弼GQ9T x;kWgt%kԸ"(\i? Wm)L2c)h0U@y9f 2 NޓdN5cdL@ʧͣOo [r"WiU}9XCu>rϪJt^+V,vr8zR/2V#ZPgri]z\*_;}1>/nnR+8'kidGQ(NK#c{KS?-Z Ⅱ ݫR^]=qTO7덤#YSylk,S<"{znpe7IVc>+>yɡ{{4BlasX!{L AȬA񊛓mtQBN9ʹ uwA|hih'6_?>vV ^pߢ"l6&wiΟg.r$2W-} k2KNOVZŽU6H&kq|pNC$}~&nQArWs>mǻ &;.q<+ܩ|L=weU.x'\/Ru2eD^ fVP߭jw[m HJz3]Awר&`Fux2P祇u?G"=0+78-7*}Q͚zXosm+F>B6w[\1Fi-A2܂h{lFF֘‚:rOnN?m9bl:!/l '$"XZ@. 7˪lֱ̥r&A7^&Uʿys%JP#Yeu6' sݵM|v IO_\XZ*Cٙ~붍Off&;_tE'xkWLw]s GƓ^LxnM̮N>hn[:YlޙEҷ\{綕TCDlbc}\;޸MH0.~ˠXI5:8Nli(HW2bL7 x^w5x&kHaQm>D*kz%um3i&H P7_:EzkͰSnqQ/eKhj9Xe3]DL%<:YI%sWessgJr'dq7H ExgJ =2fR^i}BVz( cYDQ:s^ZKхsԶ%%~1-b;Wd:8O.ݓtY/oZ< jh.`ߩ ދ8»B%ӟi-3?Q=Z3ɮpߒ=#4KW^*Wc(V JaRʭsz2Z{<Nn3D"Bv[*<# bJPng$jzh<ox,,AУ",gBJϚ߉c^`[`HtڠFpV_Z17R7kV.3 wؑRrtZZ{ZE) eJ|X>m1ثQ+3ՎH)|ΗV$qwq6xRicӝ24K#""6ɦ[S:N=4i7L{ u3'q36g^ۼ8+}.J<eE̡: !f/NJda'r'8+ g{8yi^ylʈ[|9|ĵ ~[YW-`EQ7߱lq]3%:NI fEŷQUvaM)mOnp.VDd7=: {ql6Q;[4دDÎFacli盰[V̊&Gǜ9R礸vCi&쯐_w7s x%^aWd1-nb=k EB&zg^!*®GV]< u3oxpo|.GSip\U&ljMƻwQ=[%۲ͤUc'fAfݼ~X RE[ omWژLg/5:]F u<{Km7mǽuiVmBʋ?kH)Yz|TʵyYGD[GqOH& yKiri1'L <{%q O4(1n35~nGF.tFGbΩZRy~me4ljtЩp!Fa:I[H- ݝ1,@P kvw{?5qb~e' eAڦ)O=J0O3G/)^,M΋Gw@pkGjuN%hj|5Vq\a)(8pʙ* \]%H%4̒>mΜb-8lsV]t K>6g@1qp%CͳsĆa4Li> Ū4]?:+8#DH]H͂3x7&Lۅi;/rldGçTvxJ\hCd>A5jFnp4]--bԆW串StrKG덏XH JOX'oPē",n:S=cSqd4/߯6$&t9/ܽ{&Wa|tˌ5%%d7Fb1{ud(>CJ9\籙h4UJqZ|[=xR4Є]PJ;-<ꮆנCqűDtIHby"b nFcòCv/++Gq=Jb#vwxV·~ouRzqBv"ImQ93^!ESeDtLhYG ~p|ĕHpR ^EB z0xn;զ5 $ + G)[^b"Kl_^9^ԃk7=(_>:I?L#й".;A/( cql`#NQ۝6ogoXp5PXP endstream endobj 538 0 obj << /Length1 1474 /Length2 6841 /Length3 0 /Length 7827 /Filter /FlateDecode >> stream xڍVT$Fw$FtJ`nPJ@$A@ZB:%TI9}= c!%=\ A2@]#I ,* xxLXW(.Dd_b0U(*Ljy!@ DR 12@U7+ B脽%HKK N*1HԅbnW; @c4 .C<Gy>A4{1p/@=71a lF`}8 pE(ϫ/hw#@!; ܡ(?$@:X_ ruD_CHWUCJ@?y0Hw'CЯ2WrPAQXO"1pխ~AF Q_A(\Sψ+`4}aN_M῝_@xxB@,  HW0}y x|%<J[h?Ί 23P44Mo2 $" !"UߨTD!@?(\_4z+Á ,]}AiWCyu/W^_ᅺ!]_ {5諹@g!օ; ӫ^MKDz#}H,ՃH `f rx^u ~5JR C;9q e Wk H^h W?% /K ǒ`[bbW-.!^u +׹a^, 'Ѱ=TbZY3{'0i: J{9RJ렚[U=TjxC՘ltxnd4ax7bKMDq=#n ~nOAOouw@+ mBqVaE<'8 B4Gc4×ZIxт% r6fnfK&vCћʛZ ǭ cDp5'WH$eIRzo;.n%G jDW̤X, p_8fPLVqT9~N"uEN}oԊ rCru 7uV\C,Ȓlv8sx$.7mB~Eîs& &̢S'rж ĻtǦ[{ :xdLCN?RC $dͬݒt1ʾ)al[}AIac-g}^tS Gi̖?/1ͬbߎQٟq)+.)c ): cZRT+-䶒yylA"w[XwqmLt(AdSgv=dH=[8.kS$6'j?5|9Jٶw4}~A{:!;Qں%>J`Od)'bBoǚ@F1i pelB9ľj;@ù yO-z§5ѷrz4:(NOwTxeH8$@TN|ƹb OpRաv0OXO\or" KYn(]{fGA*4gSŪ9#r7MP+>ǐG~?*^pHQjPwjQvnxi.ʆٙ@u7 "%@ڂH= [lw?");J.ðkɢrHߣИzVt/so:tPZgSLRlgCl,CI7̅X01R?Qr$VXJdS}: :* `ƕaY9ڽiK7ޔˀu;F:x(z>{AdQOum>2^V9"N樬M~LBYx/7\?o+9ܦUxXxJ^//[Z'/Aө}4kSݨ[4_kovK)|ZB*4dfUs6C2Ԏ'|Ę]yp|h3\E'TٳVj8&ޛECA< "zRPjpO5L8u;IImy4:,}qKDrق]-!PzP)=Hf^?mW>;/+ͨm5=,a-RQY\>߹|ډbR37aHGO+P9JnLIq ~Nqj]km+=qݵ{2*2UzT1(˧niJXElYһ]wr FD帻9 ZL$7j?0޻k"\m~%3Q` 1S<2Cqq@Cw0x\.OuӁ{;w#2h[؂sEϫŋ2~+qisQs,QƢ#GMe}qjS~X =?ά*g.^ɀ'!~))#͔Dž,>jwϾ_kZ[:odkj-w+^od#RҒpAEMM9|[bsKÛ MX–\)5W=衸 UP~:AQQGeD~+gOf_pw:a>5pbIcoi&U]fs<ߵ*ʛ%6FԕvG>ڳj@z`8D6R<~@,b  o|Ngu3Yr0@${XQBn {5CtB} f}ܗd䪲~g듘%R㔜y/ٿҩd+^aGйߵcSuboJcqHr1ӵ = LJ 2r60PB;;9.#J;Ȝ$O_y g N@ 'R=T%β3wq9I؆#֏&3]ᝲ~֔RL?]y__PRYl8'Ž8Eo }\zK"0:I|Z?YUA;ګ6ڙx ^*xf5]q&0.ޖQW 0R8S.0'ō/bO3Ō`hkvIȗQ_I:c5&=2 dTfV?]+dd4Xy=w]\6~%R'{RNP3$(}{28ɘHz[^k0XBcrT~dԡ!mlOW N^k)X(Ve|ZYvEqK[:6ع5k#pTQ~ș+*M)d!4d`WSkga&~%.o͇V;RmPC-ϣ7hɚGB;u^J%=[6i-S,XlXzW9D/GFJxy=(l:Eqdm*jEz+D,:K]ҧ*̰%x^52Jgy" m"VK31c@gO %yQܨ!O*ĆYr}?yQ/J8"MdV46 SpTW]is#43Y=sg*ycV'L"|ZF{*^7I.@\Zg? 3eYX#{@ワmj *בqq_ݷ+ڹ P6S#bqgItxr~@9waRˏf33,x & 7L^@j^0G;qGkL}u.S]@`5 |{h=X`G7z" SC?ɚJoTõ`|wD?7}xI->@ϔ"Nt4I{KtMn2hFr/ujwZ 6܆4c <=rV[6'$= d&p2uV}Hx$γhY(=6R0.r(H\hmW'N޿b7 Xn;̙1 [dYm}ӆ6dija^mZ7J = K 1%iJ͸w wMB(ԫ7Tgi)Ka%"?ǩy3>gӃΊ~ۉe`Wa{$P) U'M/)(Г߂$V BǤ u6rB TW,$U?r/E~2<>~g^B$rOk81*(O ֣cèR5Y2(w?V8gAbɉr N^LPT#m-wJx*tgc}v#q'yN\Cwͼ+_’DQO퇿;U@#iB>9Z1P;5:*yDS'p<>׉o3DohxaT[\-]%/"Kl5()xRɴG Er͔*Yu4R``A 6+3!b[ 6#A6J$~pv/vJ2erBTxC!oa(=Hp$H&]VO8kƳnEa<7RXwD}(EZ!b[ufGp>޳somɷQڙ:aqtevBP2*Gf|nnFV•y{eK)!WU.hXquLlH>e[]b-+MT\M#OJBs伬>Vӭ̳Vz[3B2_&{GF̈@Zf]>#V?tq^ޚsCp>f(^| ._PhvT7ْ@=Ui&l&<_FλΥE3gOAFi#{D;'@Kbӓ;I8 lCHExYKujx<7Z\ˈAM08'0;P|»ݝZFc`8T@QYD'πu%dΪ>ܹ#mlpX[_TXX.Q'gS ƭ?`j =io ^sXΤ"N9Rt",lF6ؼ,@[=ơTiQk/ؿ9 RMV&4=3U6lr1㝒Y F6w cb_{hdqŃ h'|vA N;f4]u~ [0+uq=߁YG ß=TϚHMWb:ψت=57R9jъ%G\av;r 'QL9XӔҥ݀:Zkb#YӅbOx?vl!]e:`Jp5ŀ'˃BQe axdoߌ|o6MOct#E?fìQΓw{vM_s9sQ*,xe''ŹObwۡ0|OGgY.QEp0AGۑ .nbߡN܁>:b,iyEٺPhݸk{[s]X2$ =pgFzQIF=Ƹj.IcRsy7w\I _#α. M%zPTюEUzI:~N;u( z-jCgKʥlǯא)p8Щh:+Ȍ|M~}s*]*DPC:<(ٗ󥆟kaB<@:-PࣄΦscELrP10{~ EIYð'oʕ[tf/ʙz͘ntF3gkϕk懸5\Qq#Ke%4lνӍjHc$`6/'hI ɣvZ; GW7NM|+>x@* u<|nW!kϬ njay:{)w` ]6#!wUy^a'hgӄ o*r/xwImoF."A,4TƄGՒ=5VBHr =FQ_(V2ۼ QxEY*S-O2x%~ew{?(u}&Vh*ҕ氥Mj;K,׻YU'ctyP {l+mrIem,%t7ŕ )?kzYr]`ʉ q'g~xG§7'5Jğ{롢@ީ4 ة>9(ǡWN]30~Y $P endstream endobj 540 0 obj << /Length1 2402 /Length2 17564 /Length3 0 /Length 18963 /Filter /FlateDecode >> stream xڌP\Bp޸k݃ xp]{d|:窦 QVc15J8102Tl̬N ?Rx M z1ӛLL X8yYx<5uX6@Gx 1[;w 3s(}PXxxvX, m N@뷈Ɔ (͝x\]] miNU#h\5)lM\ 7hlct6c@Ok,,/" m m-l @IR͉`hc!dhfwI[}ɑWLѼ5YDhW~@㷮3=V+M-lLL*َI(#7o nLV-~`Vh898=T/gaX;f6@,:o`nڀ=\&5 mM W%*jd`0r0X\ooorc(ccj  #(ھ1@{u9߾X?/.v/H:@kRh -@ѿmۉP};6C4pZ'÷!bcn@e 'c3xYm-f ,Gv֌ޮǷI )aclkיc:8ÿ qiY[ >i8Qjxe&ǤW4_cjw2TFk>^ʝvXJU_DJhlҨO苡"KVvOr^۶l' Pn2\FMJ44@Է8&|rggIrm[ zVhC!*ARH)wcO3| %8BSbe^D1Hﴛr+:?T@z@,t ZC6\43 XuPv%clv%H&J@j9L)i47cH_q+A[s_V~/]Q!!KFS x+icY+h!\<|`:Y b1ݒ?LG:[˷CLkX¯Ia!\plM+Mf# |́v6;䉓bB`)kwleATa߶J5Q&T}ű '\<Ќ oY\z:V0%ͨ#B?h [ڄG ND+:c-l!l#*W-i-CX59uD+}xʔ59{&D젷ݺ%eU=3o3j9bpľF Jl8JqV,GʯCly Gz[;[v᫹-;2 3~w;khzcvAsLCcsLS2+{!ciB>  ٨|Zȥy+GR.(,7 s Ȫz/=-ZS:QZ9VA:-יԠ6]QB`,#GPXig :UwNW#}Bp6N= vŧ?Sxq`%&$;Ͱ ^v/0Oث+CucfMUBO)%^+$VɷtDO8LM-#cL2 4G2ށdː|@+YdM_|O3 #-:1 FFR3"FLBM6RҺ8ȜWk"`v241p0r0s12ظvt(d>Ҭ|G.b@')bСdtWNq٤P!B6=Px:R^ɇ~B{eP=bX|=nBYIwo \O ĥrd/d^Sַ c #7n+H9bNџcIY/[݆d R!324_IO,v2%hBQC0[ E] $0nxncұW:k!V}N,'p J_5̭1FgG~cxH%Z #8hzvn vٯnxWN6&(oRf2)Qz05HYM~mԡ#a;r7Rz m+ ?A{ylaQVzoÓ% ?:*s*LIt1 #ߦU }0>LҠ]uc̗'#o{%8\$`~YhwєRűB@(94Q|^.! H8-0w]ٺ7HjjHVa}SєŸQңx#)5!CSXƙ6";;OI i_J!<0{!>SBO[EЊ ˠeb9=:Z3N`q'#cAoo9S%~e N|'w U7 I'G:Gp/C,t! '>5T _p:4vC-$yGVL tHQX WBu5x| $\YJdՒY}Qi& 61asf+'3/֞A)ڧǷܸFT2vtI{H?qWŹ>Of$>*͚aMXiNVp(EXEt{tQwK6Y9QUQ6$alXo+,lB[4vܶ\b**v e'WiV"\x3.O IDenPHR}h9P"|2kӋAxR}pdž)hB# Nv3|tLO6Eɳh2 :}i?^5d\4 |}LpM.u+B1p9}?i Ѻ<{na*l4YL꥚csL0$̕e9EAnlMg\m@ r[][*O+Шj^T$\:7sڔ~.r<>cTIؠ{Qf=6jȔ',ZYB|҃J3c*:vk|cjAr•) UH]Ph_WFƴd`L}s?! c*XFܔ|D}SdGR¤y)Hfoe$-@SZhBxWle+?[ w-+!=EJyq6ͩQ,=iS zR"|J^=Be2UpZMsk~?v̱#Lk=~kߪ} u6Rx^щ/0*Nb&U+?{=lP/[e=~ W>J]z#b2UH>9Wxfi wv*m%7*]%j,n,a:RzncɨV9[8$J?yHZ>} ?_V0OcӎL=@TԅGěg5k{ޭ#}VjЧ+w& ΂yTqmt&":-q.uC{Vf-IpXN( /B>\Res)!#i5F ^\Gh}"XOb(mv|Y9f"'hK\6r Ih}gSG534ڴL셻)Fd?!{nG^mUp2 |F*c;k"mDžӳc)|ӖrAem(\;A870Xsz=8ҟX0ojfcѤF\%¡NjbRjYݔ뽐_hlu|6I ;a4Jgn2^n#3y"/= /k]V L#B/ 0^{m닅`!@fr‚HKȞre+ Wϫ ed*Δpǘ2pXvstWV"4hӳ~UdX~?x;4JQr&|9|N[lIHt:dɜ G=aV/tUbMs)= '9掊V _# FL";R[:!z^[!9䔴٤%#!8J%0@K q[C)VMtWz.S%e0 83!{nl,q{>܁d]dPU8wE~5F_7j]*t\>ΥߍA0HDkGĩ?pGk۰ [=eֶTӀ4hy>.&j>Q] WA%^!֔)f2b\>x#wPuy2tGSǷ1]4u?Ch!*"lPVBF ӷƪ;.?J)סIE ,DgzJԬ|]kb]K_YKFs!RcTr1n̓MJĢX}p;sшe#cw0`U:J7!wD%nƛaV[)wRG~좎,îo4?AK58iygIgX d)=/mzokzE/QBrA%kj ֌Չdن쩫VRyIש)3[hR* a=tas9Fb\. ,>HwkK>?&QS u7P8L{Pk*e`X0/E%21eɟ@P }^_MZ9l-;ݱ6׍vY'3#TM#4A "$|Y'`g 4Q7;1 yA8 p+2V }uЋ"ǀ1g]vr):&GAf.zd?xb}(Ʋ{" U]Swzj=Bz~ٝch(s|rD-Z8CfG:b_bƀZc$DI ILh4c@Be3/`L5QH$_!|r|q0?AQT +nIrF.rvDj~[gҁ摶7(]K/]St|)evr K@lShr:uarSGpv&h.] Ko՘F@;u)%ȋ{帆 %~pbKqQ1zqYT,7ḦJ>(Jڋ&CV&kI[ĔO.I[r,sX/)l g}*^< 5c32 N6 XQmՄW>v5uv4LW̬95,Z8_d{Ԥ)Y]Ns/@EոZ<ĊGTb#zjA !T8Y MtZ|?߷?mm _/MXT lOcU/]~\\cȒ'EdDS)l%) >sSҘ}a;~VG 1 RG[MwމݎZǮ{j|'p2g ֩<w{6$畆 ̠DPn*p9XYUSbYyj߻ӄr|~xdOY*F|r=Q74 |Vl,y6})cuFp ǟU P8*>f#~D$ChQOtpBDfeWQ9"y=nq]O7NE6OvGHs1"YkQ486 +힧b!Dp[a>hn63ɛlQ2WW0f=_9tn,YڇY*LZE`ʾnZA)Y(V"GL>fl1 6Y *J?Iax'|0+ezLg;:G,veb~n)7PiUvAQ%:,T*qsRzt/Ⓧm8MQMo-6-e|98=@IEN|5%bQ ykHmc> ߬F}KZ,W @ZiR:EF3Lb`>EP7WJowZk<'M4$ۡې%G;?h \W$,G |ִ;]s BzlsT0C.< }YHeL|dO8cBs6Pytm 7'3C|:Qy[^]Я+ hf%Qp!Aq{I[׀S$F_V- #J&%3d im ԣ+pr|" JٓQ|hQ|Q3N.c)NU졛VhG~w1[ L瘸CWވ2;BX)`Taڊ̕K?b-5zd/O 4y>TFԳwcD&[O{ugV|4h%6>kD\"[OOӸ |-=!xN<ρ_:{[+> 9t.[_>&2H4Ш6 u9@~B JnSQ2 "47 i i%,-vVf@)O&X8pΈ"D1}7:I=8{zNm|܄i,֣a/F +KIM_&Ă M.5 Ŕ*` .TEOيnsV /Ah,3}J+$ Qz$hj6颧I+AvhAv4`HcIdY 23J[hjR׌R;9|ty/$n1:Wzmdsske_Nz|X/3E,#HNkϿ,{}5+Ū[ *>d zЕּҌ+-oC* %?$,dڜ.4:u՝,//TVLMfOC?oRW?hυIRs$:/@Y0es"e;xLfD#pY>~#Oa8WIX2%3ޏU**wg4!F-T!^-ύz,_bY98p6 YB)AC_*[Did(o{)Z{;w`d+G YFc3yA׵cgwd}A%46цz#09BK4 +żrr;=}_C: Z-I٤ܿzM5-pwOP0[?ZYɛÓ  `_ 췝TXYk `y?M~I xN 09߸0eWU֋Spc@$>M8RގӻE|=mKl *ƘMNQ]/S;iJYszԐ30_n/Ϻ1NgФy0zǣgkN Ie"9o[RoǓ2.η-x-G2:Ly5j fꙕrߴwx:P @L/C-Y=J.Ŧ0 9]~F?T"uC@Eo[rw]5X>Ue[n]$EH*[w3E&C4[Z]zk].p$&|b9q=Jar e;!ŗv[6ݕúO[h 40UHT&1  )@VD{fPqɷEbUv+7.X6ݽ5G4SaAIځ.drh>|8 [eµ᣾,W ˄]áy~ݑMm_?5^[L\ na:#GSPH'~8{{|z'#VA,!|6)&ڲ Rabg! =ʏ2u}pC零!|unKIl&MG#><_!~#1hkݥ̯_dyt_?CHvwf\};u˓RvHLNB l+ѳħ75Z2aDMTѩ~|yzՖՎ2խwZ;sR SϩRǻ1EJ~ʢ$ o=>7i0!zT0nA<14ؑ4:Cr}]wRorzռE)C-"cz}fɺTiw0 I̢X–BQj%7:{:t*V\lw@ [=7o0m3RG|~5ϐL+pSG8ZaB Fn{qW }JO6diΉ2,UҬ-ή3Xrjleh6AezksP?m9EH9@aW-EHC5C6C1ibMuDcAu΍uIÅ)K6kGAEG01akgEb"WPϠCLA&E\) SAtv}yae?";M>g'6o%HK9`Gف8%{z.A2?g8J9KAfxM-C)n?0|a-+LQ˔ԴnC\Izlc.Ox\B9tFV4V+@myZHwݱvk9!__W7#/n .2k +@XNlze> 3J+9AXd/G`KlYBStLy!#S@@4ɫ\X(cx_!ܷ'NW#haעdX?/M~h-;z)Gf̹%D͸gN^{/v"DQ1 =GpU$2~͡\b^OC̋ENC;R \SlZ.<xHCiǹ*YB!JᰲvsWrw!,֥+&i<\V54ZI,F*-b*l$ï%ǤlZ1^.%aWE~Ebs\/)—|fg&D -Ys؛HlU13C`ċ 6Ϩ+[cyPD}pFS,9&ԮFJ1ʂ9 R| J s%8BK<\tvTcڏVj{1^7hvK2x1Ώ~wv^ &.=6Kྌ vϭAedʦKoݭ_{[6Qg\}jwH8I20 Ȏ|6)@USpJ* ㈒9T 5 0I*|X/8V( $ؓ9BVGJMQ:cҨy V#7ͩ)8{S> w 4kgASS]}yUՎfM2gh~ݰ 1^Si:Dc3988I&.{뱰u&eD2 ]O搸T$?ZЅ$$ 7!ٛ$:"kٞh~U! 7RQXRkm_BU͢UJ AG?MF;$lܴ%I3˛&v#OJGϝ#00ħL.|j] WuJ҈Fݵ.9)տWt˙dS-sX0Yyp5 ?P!E+e>伡nTr2T2oA#rD롐Rn]tjo 1R x>^3G}6qM}-G~*[)V"u{Vn _B{hv#r gޗ\aX)yᲰϊ?3x."MYڪ|7u"J}z aec8W|FHcC&oZǜ);1%ԩĠAi%?/sm*PjeX 5 ~jpt}wJI:tw&qKx% &bB1pb/*6QvQ/Pu|-Y]QR3[Qf؎2j ^8nTopKƈN Ӄ(5YA1 ?rBX"2j?\KV\HXw : e*HWnl[F~C%:Yo.ݺH#`Ssȇp~1%̲6p-`׺AJ;Yw%uģُ!Y`J)CsV6vU 捔W :5vw(SǎUiڜ}+wjХ6÷H!FK"4U#f"jص2$M~mR<({7.B6B%,"]#D작kT:"X浥D~y.C!6'~%  ^aM)R k[(4~:̲#-i!)k"8kEf.NzAfL tO gñP%PfvC&$6H'!'TLstm٬n]Rq;Xd#& eW3@v(Ÿ_7ESvɲŊBc| qua_%Pt$ uCQ;cYюQqJ=?! 1O_cF}G6{DI}_:1th^ GJ֕Bj :r(/fzR^@RU`!.mE G",rBhu4)[)El.͞:Ƹ0V%?1\izvqZIdVDX][;K:>8Z"2[Tyڼ4S`j-4!&NFxwex{4_= ]mTBr> dF9sTpbPLg\|LɦQ B]xlb4Hîpj3o-~ {' "M7l lƌn}("rǙ芛U7)XJO@=ylyeoE$FПjEZp1Ozї x}=Jm= ጣ:KٍBcP> stream xڍP-ݽݭ;!4hp!@pdf̜^սUھWPi[-2`'7VvAF SLNKBn/2)s3e@dgp  H{ʬF غd#ޒ! ;@Y;l/-`KB ٺ9 yzz;!6" O-@ xTcEhق\kb5]婋+Y5JbLH575q?RV+*uV!%Lѹɇ)kt:!ωߓH5?ٯwn VHewBoDf輛cap|^#pruk=`e-_H!8Eȯ~%ܞ!VhpKr:}vj')~2ۻ褪|059/=WǃP"w~*ZQXSL4]i96J<:]fJkח_z3MXdӊ!,_IblN>%,V5\'g~j9OWS j5 OOUC;Kl_Y4?Z؟O(FɫEgޱ>ADO'#hK~9Q*ٍkࡱg@|ܽ3uS b #w@e-)e)'YCNCkM]k o$b&H]mjXJ8b<=iejV~[XY7wf % gloHFZ^WT#CcZ#2IU(?.]rr([p#XSkTXxRK a}ڑ8Aa4|> `/Rq`h\Tf!tˎJJ *2K TRd1^!.כjɱҔzbڙGQ5CA 1~,uz@:_ 5-H6CO9*!RT /YD3$unVb?!:SH7JHӀ@O)Z4 TTj"%NYy[xbșf}K/^yM ִVۊzP&T+1wkJ*a  >;u{m>84-ɖMxIhUХ ͡MK![ZZi-NzmuiȖ,j@fUxma*zrA'xX 5{BKߋ2FFpeХ'>]~} uֻ gy떖aagJU9oر@CKVB&HMx+gOa+:]Zգc!lvJ,kEB3]Ưjot:ͯ^QW{o q1h%77&ո{s9$5XlHb ]sJ3Øf%N*:-z$*1#`QNi*[^◨*W\͌Wu+ma@®\m4?b{u8_sNv˶v[#*&~ TVق+;3'f}pL.l{ĉVrB~8ͬk~Z_Ϊ56Sjy ͚I{"Sh&i4dueߍ¢k•Mln/W4Y 5 D)r~cB'2"{cc&^S[ܙKǚA!Wb)jjXlM +9_|QW=ۘSm4gLS+:z>Bs4@gjaASʏu".mr!t\oz%&j쪸;AƠ@GA&Vxd->FRW_mwFM 5`]By6j L4gҋRtR:yu9Gj֖:*ujxHOx'Xer,Eu8J2ʣ,:I zpgr# NC4RAKڇ}]FjMkK֫i('f٘iK E1h7B#e RSA.kne tg>K ʊS5RM Hh2 aOH|oY@M3%zGzRIUD3cqߥY+,_dhN &@IazTg.aU)**}mAe 8(e #p3 WrHb<aTgOnT܆+nh+!NXP \8݋jfRSTFa1WG7gJNc~cB@Dž7?Ł-$bȅi2ٝ쀈B\R$$1dg* $@;ז sO6 p҆d0o1i3(E"h_Q::L߼P厚.𑢿^OnU[ȩa˿tVNȥTw&Yo%*{ rУ؅z!^͟~[d$=KFc_S("t]P R.CzU,KPkT' Nv0 $e(E)뾥q w>)37m`*-T:s@!/Kf8O,!;;5 D6onPcE$Iύbx, t[1۳Ev4V6&"O߄hN7/Z_tw7;38"4|5s@6V)sO?z=h(J|بËz3oy\7Eӓѳ|laIvfT[v.@rF!U3BC'89т]Z_I|*%dox:3SmSoXγ03 Vt=lla=q!i{ ) c#Nh۷a. m1gOYؙ8iqJR5 b*Q< _=n3;R)/+0+%gCcRk$M);K uk2wb -9fic;GMB8II $ukJ'KW^%2gYS4O6,&˻y~A!%L,s*Ty`SwWE؎(I_b r}zpY3G>E9F@ h o1#YI[.ӆكcc0cY* K}9&Eg `L-wPAyγ"2v{Ϫ9!u&%OayS.bRIw馘3B-D$ρ'mb4d%CoIb(rҰK̶١% 1_A3%lpcc'La!f%T]l2Ek+*2ؔ_)KYʯ4t!HV+=y>Ӱ֝lFx>Wcǎ-gj;j-b8g; +/蜌gzz]k9& ͺ, a ̄g"N42α]/,TY+v^3;aONpHXujACmtF! < v +[c9M$0䉎 -oZݞHs +d6èsS J 'NwDc/t`z5x#K W@ʝ[qo 5^Sr1Is޹yJ8Aiϡ;I|P=a^I@ i8RƔqyC~֓IO~$ݜ繩vst?Uy~U++K kT^)^!qpI#׃yT謇W 9+?M[jEjݫ)PaBvǐ~HR2=dnB1[9[6q5Ԍ˝^ƼxLFkCяBe?v#{0\crkaGWS,9w )姬Υ[߯}i1AX&{uF29٧4wYq?ʅ=Ojf{90 ?yK@-zA]k9q^, vJ^&kR p:)5;.֬xϑ" s-p:sH.r:h.~[#*it_淏9 s>|X¸"ތ,ό"4ZW[伞]!`i69i|$QpHEZ%<6F I{fQ{8#$ղ<IۦIk:ºZn;S+R:W 2FϳʀqѷC<ՏpB(=NzJ kB.J:{b"WE(/F| Ѻ%~3Pf)Tqӥ{in?A`/$AŒV *x;1uGHx掾㼊c]IwLS/n0j%uXfl%N,i8 ~͸Nq8v2$5$0m$hqۘkǺ^Ac뗌 y9'i,YD$;|p>~2םR2$ }jMכ􊌾&5i͒WeEĒӄK)lfn"^}7 N(º`:++Ibѫמ :!&C [lOMve{2nK}keT }I}0gg@\n@B+i97gςD|.ٖU\I3j|.ȘE/^ : q_tNH33)E3%s80#Ţd:60׫sc65P=_%brNvǹ\jrي|u+mNW^ފ9>΋\0@D,Y/#k|Պq7S"9AO454L@azy FDZ)u ³8vGmO TFD0K0rniW|T/>bPx AmSzv dǓiF51df74E:(܃чXcŽpG\R_+[Zϓ}-Zz[AЉѢfb Pn+kU2!kH?u֠SٲŹ͂/}#c~-8or~e)!hz? [^GN.QX9I?Zq[lԇWN=2'!u;X",:t%吩Lݠ=PFBW|mނɱC^xvI8?xmq##3xx  Fd:{#A!TYrӽK}QY*yzxU"B{,8|Dg uk )HMTooՂ@OJՅ}1jk%~Zo 8Z6RxN%:rqY mr-8zGj\#JPOZCشMeC%/) >5z5qCDGbffﶍbJ\: B~;n;PsYFg'4 w9r{d?`EMu;{ŁC~Zn_O-9<[*=Cן+fn*ƂQWtIX{iv"zKmn;*y }4qy >eW. ~o~] P{额@oھ2cykm-ա%!0'ZCXyʡSɆKa94+/<ς)}T@39,$S2h+39+yVV[ĔYVkws` /fX%.U$h Aӌ,p]Do9MA m/iOT$~d8v`ApĮBxrbFEHk%N%YQ4+P9Z,~,rsmUIaI<;4Kb*nlB.|CF;ᱪl -g#ڝ@.Fɨ^xsiX=Ưfyx*Dc i[ droBjJUWRz]\lJҍe^ׄ]a6g³mh)T!Qb s6CrpW3b6fAsj uZP P!hl!cb00mv71=I0P]]UऐtiU= GqBa`FxV܏ k2}*r)Wzu4?SEvxt{F?x'sHsg)^2^_!yIכQȅR!T -j:,&`J֣/a̓5ܾny?WAGN |!1z5v;…G9fM{iĥ}_Rka q#PNǑ aOO 42CKϢ .mJ6YnM̪U램t$}4c⓴*kxe>(~= X}>/iY%KwʠߤwL*e&X6x0)n3 N*;`پ_9*D_>mJ~j'B(Aȗd.¨0=+Egݮp>q=֕JR(gGQ󔐅F!r"3.z}'*S'/eFƸ?<ŔՕv] Q䱮DKDG{j^ڥ̮lħhY`}gAի# 4&̽٢dhe+(t [+t ~#\q Gcez[1*wj:B#b2>qzd+h5W= >gms^SqqOV/!dȆ5Pשw =`橼agxޕɖ1̮z]-MPse_3g`ɭ[$sYK@ŗzaXm̹XG1[0eTHg 5(c/ʗXrz,Skl/kN'`˚U2Ee{|w`u*Yy2_xSP_]85Ѯc ]>Jy)sUCLDRk(@QqvRO5ɢ3xJH ÚL3'.,J1a* 6S( ߌ!JB`=,;pȮd9ɂhš6i6Ck`.BG%)} WT1"YC@GȔYbe!KoɈ灡|WNb[$.UeMo~E(:7>B%KG U $To:R;Niʟۜ; %m03y D,F =p}CV)) 7X&ek2KFW@ c?'A2\Hl6_F٧5[NW Ԍ endstream endobj 544 0 obj << /Length1 2101 /Length2 12745 /Length3 0 /Length 14011 /Filter /FlateDecode >> stream xڍeT.{)^@qwwww)wť8E^][}>~ܑ1<ӟ\oBE$r0K;ػ21$455X̬(TTV?*m=l$+T f `qYYk4u`* G/g+ KWH~l||<V@S{%hj pZ]'#?  0#v;Aߴʦv1P4-\Vi8z:lqr 9E#ocſ ip/gS `ne H+2z2LA Mm] Vf7HL!lbe%0FKك$.(듴r!bm<}`s+{o* 7G-{+'7 "?2 +r`'h;#/%o1{GG9 9b:[ V(C`1d <!d~2g {[?4$?Q;x|YLn677T?+oƃ?C hl!++ ([$fkM?vV^ +dI bm%0ʹBE2L|̜\< U+W_d:XLl=t @.ȡCJ@7`l 5v..deA`Ͽl q@;8>Zn.o߈"XA<?be`Q8,7EDA`1s6ڀ!9?\?rO ,AHd@x B[ BX Bi/b/ `wdHv dYHnvf_V <T'$#rwid"ˬ4$dll]!Cf_jH1nf{_B_BOWo߱gnY-/{( s@ujĈ\UǏP,24Ԍ$s|2R T>g8Zƕ #Ѷ#ش)1ԫ뽛^º5JyQuj3w) z€⚊I( 7 7,</[p#!KU7Bߗ2 8).}Thm'iz.B* vyY%мn2 `tH8e]}&k>F2"yUS<$|*]FĀ7EA]{6Y{NG"^'cV<^^G[x/ kswU~K|{'Sf*G)%% B? (ȦsE.k7`RNE~絻O*_Ҋ= 2(9鐆'n gq`ra~ͻu?ޫbikŎ3ktŬ˩杯ǨZ,>lXKs5h9G;JUTotqǛOI<wao NLO^7p.h_:v'{)-{c&wK?YӐ h 5ѲaQ=KJPa]{ ,#gu0Eo]Ӟ!=TM+kE\ k\fiR:,G\7"Y@7aR2DyJ]TFt]VD.696zOzgBϫL"ȌHZb7b $V)GP?G̷>K7XA&kȐ"Tp(:C$`4/|%&#|Hgw%1'J}`R8|tF#| 2.qafKUק&kCM&i SͰ"O:!i6QMa)^*uR#GxD*6fY\[^լ;0}'X6peu-oI}tZ\%u@R 1qdHJ{?]a(a=8"ݗT渇n OvQسtO WĊLĖu ~ vlW:=0]̱S5]p!:C1hy:Fy|aO)S(wƆN4f])IW+Dq90e_-:n_ ed2 se-Fή`[ߖڿf55 TrEḾ bAሇj3W|"4-$e\&4=`r&ҳJ^`T)Al"йs1̵*CEoNi v%Y S>_XVZ;܈9ؕ5.4Da! Ox8z:PT5Z0,q(t2)#Y8 ڙT#Y+MNe,E  ElK41E="_NK{?#MK,iXaNX֖1ƸȺS +9:yp|LWwA< ȀW:/lE_1%zo|2+A\Juň'L^$%u! S|]j[uQFaJ

H q+_LQ 91sKDWhwΣ>+Z$U _Z~O'‰?^f| iTjM#J'Plj@Bv_r}4NAMM ( Gxs]{(2C--sL5ͰQnGJwd ] OOVRA?Uc4w"/8aL3pDX[Opz';qm@y ШPME(;D ǀDw;'ܹdK5!M+ۀ#+/X+ mwnV8<:g#~6A$pp:BI- Gq{ٹWZVaWL젍bOt(nLM?qawپ36a 6p;.V!9e*C?['$^v/sFG=, 6a".Sozz^Ja$\sY=,\8Cx/n΄!Cg &Z,}D"w;;K1[rg'Z%NP?ܦ0z&Xe4+z[_gb\VJz 7?~k(k"꪿*K/n'>js3GI$ xd\,W~.\Y$@ŵ!y (5)^sU+takVGo}4*2=|$pNK FAnA~%tM8BBWwǷoqOWP^a[5 Fsfd<:Qyd{Lע땧TV.B}"S_v؀`ZV?kwJL@Yn*!`.)ݧ }xaΝH#' arML@@h9cQ0I%2Xrv 7o02 x=M?Xkٶ\SP }bWl-|I1)Oq {G?ʹ27ZV3YclNAj?o[JD L*ibs/!Gg7ݧI^ٓ͘TC@䱳]2XAC&}p,'F.,?} Qcgז}Qr@,W! Que25g"㣵:i(0N8o3qx iVahvq5Ia=Pc9t{ tY;{"w+|xs_C{@ঢHeyP&ǙtZ^6~b O'/[.n7 mdI\q^@oy1tmߓtb=6DV ԓKEi ϜD ZX6¹|U,h-^?z^|uXQ'+s[ 4iĕo8lk 0.x 5=3TԼۊYtxdH8s=2SZh>$5j8r^/0:~Ё}EfӉ'jĠg¬S\XfGD=F\C [Mr!}ݯ޼DOE|p Djc?~va_gM藽F!@d&>2f (;ʿO7XU+>mhoHzt? ԍMvXw  T4D.V.ٯNg6M Ǚ#6Ks4Lg`+IXJ˔򽭷Y h^۰RbHz X5 y~iDB^) #? 6\ q'>\Qf"MMG#Lh. ԭ,A#ńc EY.^%I^qp#$2-s߹X&HW<=4PCF>᰼_r0[2O_ y(&ֽcjhШgbK57(f%\ e3cDKB\]ތK@y8fmגm,^ywYӧՀWYJ)C'+rn)]ƔVot[26kFo$@5C   D?+C~. kt9xQ+u(^3~i.Hlp ukΔrƃ IjO0Nǎ}q,(_8jĽ,RHrH47y\uMfL*`%KG4L=Q|$Op4Cڋee2EyR1({Dv2LqSu ݑ6mY-IMT25Lj`C*hFЄh!' l3HTcQF$ l~@7*(5vC7!*~G&]ĎS-E컉aVlm*ԏt0*q΀RqaтѶz 3tݏYN(zQwŊ5(fL'"SG<҇K2jJmrOEw7ɷIBCk哗fMJCݕӋּIoREB?z]u9nXwRFH06ϟ'! 䝇{U-RiP8xŠgQ/h&(v < Gl(c]ʎ` Lp| JU`Yw%jK*lj'ړYL~0bBiJxd^(l; Z5-`ܰZWl$-jbg42/(('Nk6O*LxxR7H[nŖl}>t!:|< CS]VIGX/#Q(U5Wkz/H[4(h"1nD:)?38J2iYll74;5jC^-)Yg!k)<)3tT VrxGx*bUrfUwƚ/\"hϜٲ " @MZ%8#~p¸w95LgY gy_ \ +("[ڎrFݪR 3ˏij?wYy?/K{s1\D|Z1^|Okq\yz۠/ \t)}_Zk"[r7>#ѡs>G¦|8SHV=X,+dQ[R:.cD3Yr SG=mYs;oO)$/ZZ{44 .@0*hN$i˖FBVstAslg@x"۷x J CEM.B1.T/x0[xDxn28+߷4z=CѿbY),ts "FSE; ^tueH٤Cݍ@՛rѸ$n=v᳚ǥp;'CGP2mtL%oo.=z>f:Xca7yM+#iAu|Gj#ɰ]UX<aw8Gl \4\([Qa\( Ydjv{ʻ>(s8\B L36ʣ /`ީ)oFqYQA.l}R6>kO("#3B ,DKZ]brWU=H~< e#>HY")-kF0FM&hYHϭ<*٣Lڧϵ+@E5OkolBaueڡ{J*}6/G'Zx|\fK/ō޾m)+1gֻ$TCUHl}G)$[Lm]XoE&fas,\;ϸMa9(/) 4T(LWĿLP=˅ l `fn3^rYp-(Tm1@aKi^qYYZ} 7z/T4s#ǾU׭4g,fI UiƊ ڢW[ǻf|*N"[As{ɌrD:aP^>wR+,zg|{[u;YDOuSDK`]g鰽JaBZ?]j%.J0hu>٢Έ#W*Ӕԝ9թDs2^AH?zzxu-ZF Gl4Re:Y2plx{T!ȫ:3ln[)?,Co2LnKL鰢.'V^7QGiW?7]MgNV۴! <)b4IW,J”uo<'M4DeloBVcY57UMqI:YA(K!hRcuʦOvz3 zlb_2)H8,{v1Ov%gV#F0KۛZv{:{KF\BϥHIuIDNۢx69Q)\ܓ]-W.> ?o:! C]33A#IetC&nS7^u }eK`6V^${ՁKkX^U๲s1Ѧ6fDi.%w/"}#h8q0=|?N:I3bXZ566H;uMN> VГmpżT W1n}XSBK[s\l4'o8O@*<4T٬Fm] >E4G=Lem:W"aUbژq+$ D،6Nʽ޼c.zHt|NCfdS@T !VE=u8lphq1^Kџ#,z0 ]g+ I}+.?๚xG48.ߎhq"'K„i Lq}7Rkɨ||)),:c} >Ќʿv2j((0FUEs ul=7oFԢx *Q7=0%'οdIhܧ%x$#p<ܸ"ѓݥb.)(ᱧ\coL[Mo@RZLq H[5bKk>o=s&hG6jN%c\råD/b2Mtqϯ1P:Xcˎ[KJ-DOS*펈_Nx#}?Z˥;WZ.^!bf#_+[u z4 o5T &\ w*S C6/J9w\2$Rb3.i;K@1HA-~y\Lanz[G etVMJp_Xb&{`}1 c,M;X&s&+\s"*,l A\1Jjܓf%R<"N4LkM<8lHN䔂d(/XK?i|*Ҫuyq҇Bo`PK%7-Q{.FLt2o>l1L1}fs?efJRfpn"}muj}Rp7el2z7 $a e+vĀ红5aYy'-td7.IYE/_Th}PiHiIW7AvE+֟%צONvSGbp8c:Ij/U]۾@;XprTg\nh?˓]G|mGN Ge=iO'ڜ9޶'P#$7gK bTjmӄ$3~e R\.d]cduʁG~ǒQnW~hə~5m@o@z{X&A,=>C^C!,00K(6VmYZU Z>_t].|nLVKxsYOO(BEtX2ߛ>t.$q4Fb:*"R03 afƅa{0C -'$GeLJV?J-o#ػr9ej|5&#sbk<:Կ<$\"o͉x% fDVbJލ#g,oqoy4?Sh#'Cns^n.`TQg H?P~w,rZ yTja+O/It!*Lvb MKgl;Opx;v> stream xڍTZ. )V.ݭx$Xp-֢-)ZXq/nݽܙ_뽕mR]U$rqT89l\`=_rTZ]+" )9E&m}1TqN>Aη.:6#J+dp e r!s %#^A udg`3wpestedx6M+d 2@756TZ /x؃ 닋xRP9 +erl?́@G'sb ۃjlPO( b㋿9sl`?8e R . ˽{\;_ RE5  O  @*9pqrtX@/?> O#TNN%XD/w{q'ϿO/f-fT֔Sb򿕒Vn^+/q}bTwurEE`{mAeA/y t?_+uSGoeݠ/!5* Kj/;"~sVN6`WY'R 5KjK{0 y^חl畁-XA.^> ^ˮZ<q;xrtAoyJDoAv/ r)_?e ,Χ[Si{rt%6H_DG"s iHk.lQq=9Fv6{wgLt/uDl 0A!Ct!)=됖Pؙfu|*\wgUo&BL?#y:DdQкfQdT}QU3vMHHcLūU: FĀY$lhdD#؛.B+tr:h)"Nts|FYICM }q0GĽwӜ=]zrQ;3*ݕY 򉲭wj?A} &.P}]qV dC_}$~ ~NMO?Kz}S1dV7md jxE,BQ&\EEsZBMwN#Vfi 7_[.lnNe:yFNeVgHD_I@#zAYTJ9wߊ FUL-' LpB]r<$ 4#{S$LzQOsR'!I-uc鲉f?,MbBEpTW(VTpZ *B-!%CR"|pe};[R_TҔY wON t:7F;ƉF⺻LlEPU (˥rt0ŵ14~|SMH@vʜa#Y,&yFѓU"Kj,g7IԕDG~gޏ]U/-} bLn1 ޚhOШ<A\3eB@bʥ[m^c]THK/91$R`a$@QF%HeZ),R+[=b`E2Kt|<B@'By.ٕ)Vn9]״V4;0Mul#[@ؤz롂AGWےؗ]J4f8޵KgXMozGnO :wi۴b19٪=ja%O{RѬf"$JQTȅx JUpv%FMnw(TIx1&gD3 8v}F %Mz Hߎ'f1E>KXe r=Q1yjo%0*F:J0 Ώ˄Wr'a}&KMP, t/Di @}pez5z<((Ԑ2qUf1- =(;cgƨ`W*HuJOϮ,CоK<4ae!>D L0}4X-93e|j}Wb!0P|Y҈LˡDz˶ۂK;;Y'EP 'wk'΅I‚wCM۵JBVdY׀E'1V8ɉ34Q$3"I5*{YsVCgݪa9mIm8cc:9~CvkW`&[!F9OsOp}^ܿ0ts}q(0v7$X9mQ CkAYpӭ%MHbpGj/ؐ73K3񌡑,}:==&l3yjUTmj3:j~~.n[/2j w]ѩ1OvR_!v #wxJ33=‚<@ 5y G#(&  5FÄI/;޼ /cc}̄x,#.bj:A0luuSNGJj@zN1*pLR=aU&05#WﯷޑcHh9)raz3k˫F.+.xRL0kϚ&">SX֒UTS+V7+"q3p_ZQEtD$|+VG&`?!A:ljCY۞O]Fp\vhp3<|hԠP\/9;ڑOn:oWʰh{ݥ$lvizxD$8or1ˋó%"3W^m4ڹػ[,4j69UP%JGMDvYw۬u֑>a^Co|MX)bW#Md̮p7IZ(5U16fI{grv#<0o J@٧c&cXĵC<ў 'y5M{"޽'曷fSf4xpPG#WqLzz;#ndLpHDpte~uLȋoDv>HsNQzH$&V .mS".n+=/ lip*׬*aI돘=PRYf H@4U-xUw(HUeHG5RX@R nJ7镊qb Ylء}Sy0?j ]nVq)µLC^Ds].Uy`]!j[gsCD01Ӕ<Rk JlXL}czttP~{p7x& pZ2Ên} Aiӗ Z+wwi49}N] ?] 5ޡFhwV/d\4dl\u*cOo.4mG<3;{(M'[XgatytrӌyбFΏۛst>6"EFnY(dO 5 vdV,x1)2AG Ű+SN,nr)C{Z"'qW@4k>`jjM`%}s.;T87C, nꍡݙuLƞ0eȹ飉*N5#3p0r4O'`Kb ]7r 1Yb#-]g-γ毛5Kzm9wiF q-ܞGz{L AZ]&ђ@͟WtZ`w3dCq~ Gu8CxY?zU9 sDǗW {#穇EHI4f3*OHcw,:&q$Y i_w_vQD^BŤW[ɾοJDYd3?Ld]hD&JE)$=788V{cMNHOx_;MH)#klU/,֝%7v"~k'H\{Afn$ha[>2@s{89sȫۢ;EU^!)XNDSC;ELe9Iy.?x$83Rܓx$U/S:0c9}-3j+Qҷ[xKQY/o5IaD(ethB5CGֽOAw]LU} [P맵yf͂ޯJD>*ojϕt>ds?aaǏ[vӤVZT#̑nRu0o";)9c:Fp$K58ʘMj^ud")#mNvfG}+>gar@X-Qcy"_k+ribUY*` ioF} r;dq@%؛k-O.ٔm&93=(^%| [!7xsnêH1MD[HV{QO>) O岶?Ts{v6dmmĊ&ʪDV,No>njRp Cq򷆛g/F˼5nf$ypaiYA?0L iQssi8FdE2k^9謏-(IF2U^pzaG"aGmrKR}#|m(nKt]{nKYymYEP'8VObnA\>k}% Q(ٶw|&+)xd_1EC=dj;sdWU}4ťZCps-FAiABYnJ0Mb_1Q'(İzތٝ㣌J' zM̩Bʨ߱fhY3S&J,y XY*,{o=ÍFj5JЗT4oFk!aeZV8MY%z1{ !'*|[/T`S~u,gMShuX;55|aWd뭤yNQ-Z|LĀLot%#-]Vb , !n6K+;S?TSp"ӷ6zKp(etkEĕ1@K&ڌ2 E!V\WCA4>p^#iB'Z!+S bJ\FL*@{n 9Fy=*R6AIrR $\//|y a6k&g[uszrwf欚X+q-gJJNM[ѫNft|&ʢlHIyUb Zd#6OSVRkEEC} =``%395Go4 dF^# cZ\0P}Qu*F"{SooyLokm+f,¨O*BAB>?;V9c{Mm߃H6th/IR]>?Ȉ FV+8mh^ Wr/Έ:15)0nsNs o$E}zxxyhf#|c&PྭcB--4l Jy&aU_&2;h?KUӾ/ Iy[wr ,,n$>]ۋSf$7?S#dk4Zz󬘝7Q\e]>y9L /O;B*-VŶJmW~$S<(O\ rz2uJZhC}ֆW~`Q^h ޹tXoKV=qpnV)G{mޏ61Q1EIN9M-xNYBM]ThoOaDQ L o^" hX&1M"YzmUA')_YTj9\eLN ^ r,̏ujSd0_I:Pc-g9A*r/=WP$H6H~Onrxx&\pjCQk(3 Иk1B1u]m9nGK:2R۱A0s;3t4QA0<ʹnuboWѬf(bO&ga5m#rYZ:ǎw4-߯Ȩ WH_)pHYfj{o< BrYlSkj1SLp7v9z!4>Q÷RV.7ճB2yꁞ_mJnmKV?Yt 'bnwd5hCWUS `?x*Px`Uy*ﳰ2ahVeW8gOCt~KlМ(1vnLiE̙ Q/-aw}7X (o:ρ u#ֻJ2־[tk3JO0T'1JKc/9?jm ;0]O3wxkF_r!5BH[ZjA_vѣ_a2}hUo|'?FE:ZBBj˩ 5׈57z^K5UR 1$O8mIV0G=f,`bt^fM!o}AtOEd >Lٱl!TKXg$lW]KwSXr;꠼/_|!niehlg6[Mcq4Z}?ӂ'iVь\~4P\yS)Yѯ]3|QJG/M/:FNXj;!*7Ƴ6VBi*neVRdHUJbh9i '`ysV6~)5/7E(vo;pMLD/T޴>5c:KQo־ LӖDlKWg6I ,|$ <ay89)-)μ'K:KǂrIt%B7p2].4\ݹ*I sGd'M˲N<,D"ҲNdg^:Qׁ-ߙ8Xl(K$q#s޾SxC|yq7]: <+!YqYA)D>Npɩ5%@t5`5YŏAIEOnu*3b {Pu>;(ZY5kvoDl[ZaipÔ% Z[(x.뭛w`Vbލc-T>~ =b^ݬ<=Te:Bn=':^r :; yaw LB'tM镵 m }Sym"zBfXpRn3p7N$Q< `Nc%VY{D~ـF 󀕹ǜ*u$3_vudMtյQHn/C/n : ZvVJ9P7|߾HTGƶ, ݦG./){b7̩k.a4\u endstream endobj 548 0 obj << /Length1 1418 /Length2 6556 /Length3 0 /Length 7516 /Filter /FlateDecode >> stream xڍwTk.CRJ3twI7H 00ЍtKw)!ҥR"HJ]{9kfzz6&]y; TKZj,  ap_n1DHE7(Sx@ "`0 t ^0;@PG" 6E=Gݖ]Ȼ@`p'BW v)GW >>ooo^;/Ay8PwІ@ 0?~7 p-ᎮDAp@Mq"$kI?] EB0`CM^n#/ A'>9P hsuz jee"p: jv_?uF 0/v|FW `0EP[G_ }]hHW @/( ߁[ ~~f@`?n|7`Fs!^vHbb HG@"b(!msՅ:j{$ -  H4?Է m_]./TQ+6{AGiÆ=O~$e:k6L2EL)hc=È#UJC]L'U 8M\a= Ⱦ;zjuèo nءSXyݞmT8Ua19_9_!m藳=THGU?ljؙ95E(wtNw8x e4ۀ.7ڈ>7<žsr .nYWWڃ$1xY+~Y\Ԯ5J#4­5-VN'򇱦_kHC"3rCTzޛ]RĶPWE7\< 9oF|G=cf"6XUez2jdv4**OVqUƟ8}ZyfaRǖ,[>%2,cQz& Wu;<3ťpI]S@kK.r='v/OwcGwS .ՊV/$4:Xb>6z!%T5elfsgXn*&*#bvKYIMӒp}(٧M ݨ9n~pn-f ZyaB-֢};SOP;QQH.J76)JMA=A?ts2bƉ q TQ#'j\7juJg8_L) 4'ۚ2~`9F^EeÊaD%t<SM$+Afd)9-Ѿ@i5"(rX04_y@–L/if1EKI|:=ԫȉQ1"6ʮ$֬%.yLbVԁ@sZ}>68PlcXT6 Rr|$ci\6)T6׃4V.lƚ)O`~N_ N Yu-qUmo2 =!Thav8kŋ95bPx +*m'iV]8B#$䫣G6՘(!O&|tEFYZoJم!x҉k##sf $->WxBp؈yr\:&E 䔈R p'$[(",o|6N>a$6F &})p zlאSywT_ I0s{p]~-`YѼmH/qCN~ubDzKs c=keZ@[liCf ᆵb7+9g Ⱦu):s-\C]Fexjݏm,EGG8G.tl!jiV՘->yrK͗( >*4Uo&ʢ_6B.%6"pw!VChKa/ kP8~۱-OI j}KMj䢚4XQ;"bQh;{i٠ڶK~p,3V@q=_G6=:,j?K,I},~2s)&AFJ`Npx~ujI]F-^ }QJP;P6_Ke=y2t~ⷚyV˩8lU* )L(c 3 qJa75˔T)e\)7g'Vo%k =, ϣ RLoQ7[%&2UF Hq蒋'5u2&w$P1(xFiG)G ;D03:@ڹ>dΊ1&=#?JW|K1/SFhjJJÊ_ #,iw,YD]]Q;kήDZܦAiqsOd9F}W]:N#דWaH0ZM)WfVWy=7l*j!m3K=ijbtr+3{3 iC(UjPՙѝmo涵]Y籤D>1AQM1R3RႺU,wB16ԙڮF˫&oKZ< }ѱrjMuqwqk> e۟jgoBx%_;3XFaM- v`/X pC p"FSYY$)wi'|mN²sxoa7=2-Naؚ7o4W 9ku} Źs8X\3bM>EnXPjj52+wor|e )\o8+#h19[J}qFQ?˒?-B̞G荣lrb"E2WN doѭ T +󲍳gcεC{ևNϷұiy$g qJ=t,SXJ؂Y~`mn(T5}m˜zƠ0|Y c0d(KYHdEW&;F2vv\Xb%"U gu< Ѭc2EVoW?5k>ז7RktK"ŝ.*>.K|궂)1/l RU"/d<LMlĀɤ"՜B^)SA6f3<QF`~їp蕟E`Jb}/M8d%|?EbTmUЫDpHSDX/_QnDyۗTδUV``*鰿C<> snGH@?s~ьe%>S3L+gB:BT"$Qzq|/C{y1\%YbG45Mi;,>ckSkr/i:kweD :Im(mҫB[IA, -rpXbsqwme#XrbfR_~*8oTB.o]hWmή4k"~d?7e=*kǿ<(nɁWE}NOOܸ/op6뙄wʻ45@~ +Z_Ce9w g8u=Ōv"LߒL{އR]I%Wħ,X +>Sblq(ΨF7Bbo팘b;:`.g^<|4tZ}!sM\[2N]pg dL׃-Klur}T\9/Wft)+ p" V6720;):6I!K2މgxKP')eL?v)w2v=zYtS[uҗt:me kŮLcB4K |[RP铰gڟtkȘxh+39g -VE pwwۿb17k@Ӱ&C.}:U1m7ڥ ti[\̫+?9.өdPX CHy,-w{^ew43m -ܪKu'㋒ 4huد'q.}2YX5d؈PHF3Ǫ.{̑v0gHbm2<>N*}9X1o~ɏ,il$kL&żlc3gL"ӫ4jh HP?a ڠGJ]P$)۟*?7F❳FA8K3U~)FYw*!llt'ՠ"ayo; فͽ@ҧ[dht8B\`7*->BE+90~/9[b)~=mR[~Ɵ}Q CruH-9^!u&S/!:LUsiz2;gP[r덄jҟ0'Z:7Jl5\aOyxxШV2mI"[+|ji n73yiߓvlF?wK+;A;iP$V]g#~Ȕ7]Z?YlzL)OfB0@[H @ 9\ rlG.U k%Lɪd@QMB-T?Fh0Pְkh1t endstream endobj 550 0 obj << /Length1 2104 /Length2 15314 /Length3 0 /Length 16581 /Filter /FlateDecode >> stream xڍP\۶ ܵqw.{p. wc}ɾޫ^o1jrbEz!S{c =37@DNUGNjb\lio/'ˇLN j`f0ffb01q7@ :Ñ;x:Y[|G 5ow- gbhbdP7xT..܌ F NtwK 24E od 9@!49xڙ*R?Ʋs6f_,v621u03Y ..t#;ӿ l?܌,m?  .0 z&N. Ζ6Qd+)ٙ\O hq잌t?/jv@)|́.v&&&N#abWxUOJ |f$f8og#7 oFpSK1O1|'K1IcLl<_F-me -W',lgeг3;-U4OqL"Jٙqx?cA  P}]&v&/ +߂]mlVSQZxc]]>Bc9UZ_zٙ8=3?rKgqK??aciTwbb?3U? T;_`d fXSS `dwp|p;FDF?(qE8+Qb0JAd GL? _Ab0*A,F?#]Ȯ_n}d7/bq;?J2/d ٻ:KQG|2-?N_PJm@揺?/Ge;)lߏEh?B@7R?̝?.?iFw?/d0W,=Tat'ZW".c?w4lobP'N0i:Fc_ R kUş_QOX[51|ҿpc~o43ޣE{:que)۫mjgjyѦ<~+@Exuu$KVl: 46''+XHPVwpbYc ZN:'۬cÁϸ21xۮ@*cI6e8$cwpgr&پ_;?җH79'3}e /( X1p8ǧGL)m^ "y` g=Sbk!|q;pptMG6"=~4r~n zM-([PU.^p̡Z_y L<YSE^&34OsF7iTEaS3 \ LF@buY 4j"iZ?Sg7#qm'i 묍8FYܺ+ K{u8H߹r"m?ÅHIkHXQ$!ޓkI.BX:R#D{4t ͜kWz"m޴]ic:$t@JgTn-S/<+(,"z"YH3$Rnl rId'=u zrp/rw݌GB\%BFU04d9l=)$ ]A!/cѤK~ [b8FYZ\ q#Ƿ/ ̱ߛV8$oz}SQ!IWQA*ht},,wOeqenn=CCnWQg%wKZɔN l"s6'@ NWV )q'<-ZU:&PP-{iA9: 6wUd?'up=f[PC ^sX򆰐Rn,;zkR;b$FQa;iê2d>: BWm\qM&=Q޷(:= a=5'7BekLN;ZYF8-o8r7!YzFɟOwC%*_X#Y/i6D@qr)|Xkܜ;C$Zڌ{C=oţp=[Ju "F+)lŇwp8R/dHꆐF:TJ2b<߯o:%F*WY%;d+f-ketag]wj.wWi&//~/ $8,Z%k50q  @Q]Lea#*dy:DAtP*(IQKաq)8?ۯDFg>;mE(?)^+}3.nUڹVBdur0'Qd~18@`1QCŹ &DD~m/ᇽO bQ>0d%M"aꨉhF_vi_B@I2٩lXeU*eb(,sОúl 'T?7ܘu7jȴICͳ}$-Z4e3<|㈖9qj,0ťx9H*a.fGs)*`Lo㺆\- ſ[FQhďzyeXOjݛmP0 Xנ[%:Ĝg-H 8wÐ})FGE5S7Rx "B #6]$ޱ-uћj?N}sulY!7+)dBlAc-qrV-1a'JW!Lst`wpը+U|-Ɂm|;+ݠ!ŘOQs;vM{\#RoJOJպE棊,@R\Hg([ٗ9Y׃ {Z} UujҨ?SA/yHoD!ij_,yC3%dh^]\sgQg;)̨݉<_+Bqu)ћ X4#GnİJw(|V ܱھ߭0"QWUH <&Ə'p ƾKɟX=aٮjSMR^~ ` QO0ƅ Qa|ڈ9[2ZWLUٙ[f,$=O=Ov#tLY~P:ujCѱ:/C2^S lgc~KZ9Aϼ䩌|]أj&ĔKoǍUi BJ\E[q#nt]0 :AgpVUv%2%C8F+Uۛ16i\׮L{6 zIA aGh7'Ͻ6"cOL2ɉ.J6f jkU&נi2E% o*м7̹)lKۚ;]#S:uR~~ʟ `qI,Rf z ]h{Gt8vxtt=&L?} Ep~e0PoрhpfK} :eRe/n:jKsV(htE*eˬpN"Ao)`tU~`~\>nAyTPO gd@G7F*<6Sj[>9Nc?5.!%9ه* 6.sVHHJc=//OiG Cê%R Mo_;qzg7#GҺ."T=u!^I (jPX=J eU^f+Aڃ$^ 3_ZI3؆C7~شnt1圭6QnE Y m8/bwjF~rBKtPV3ZF'yשBPM 篋c*1 L2 gf**bb Q2LtiwPf-= p(ڏwvaMFmhI<>cNJ5E*M Pm LxjnWEo c# o: QTAޒ%@ 7I{q+RA?^Ҝƻp^M)bi!OC SJtʧO,KȲ&h^h+sE8;Gu8c#<(NѥgS-e}(Yd`@T*8!I>XHƌkzj+0 +xtתbv*={G8<}]DN*(#͗zOaA,MpRx bj7f;86Z:Pzt}Џ14Pgvn4cP-6ڋRK鮟 .i9p4_\Gb#*{QU ˜f.h51Z5"ɝB“*y)1g _G$[1#ѧa-eK~[Wn |MsxeRωБ[բk iz'GgE\ m[g01^*'(st9,`%JT*:w0r0 sIm<7bs&M#1iˀl)FMWڷeXub3bH-0!= §ScIyP!H\HK~Ɔv3eϦyK-H,uRi?-at(3 pKT}0 Sx ?Q.Oy&9$<}(˝}6_tv)t޴򰃦f@>>Qޡ ê碰? o17/}w-Y!.'Ɂ1,:+aN )HFϼ TE]GGPdF!cr.3sk'}n+-'ݹn "ARqzsb1APWR37qhx>E ""䞸]]+P.qH,6~kTݞ.R8Q^j@BDp>mO[Fn' \ٖk\'^s%Cٷ_2g-EqSHv3 *kTJRRuL&{h!"j5rG67} <6kݡ 3ǺcսuĮ1qSf 0~8U#cZb >{G"1' ϟ⸈*LxzT԰bI[a^+lqZ64&1O449Epa5.~jCtƺ)&=UMwbU=8ی=q,"LT-[.|/൜Fv|<=H60oDv^k .vYzYG/%ө|ڂVpͿv`qڛBhqGj\KBL~*W+FF6',+*m/JecIg)(^ZU>*g(`$TFUFoOCc5^3 ;3wbѺks*QIرf1$K0LEW~4EDᱳ)K\ 8L/R@{3@0>1g{^k,g@Xq²U =:Iw'i%rqk|peC|Z3܇N~kx-cOXMGƔvTqQ'SM)8P䌌~҄y$Wq-$>i$ LO k}Zu~e~*2e=^V &S! y}w%hC֖qIg?Gq_J|84ڞkc L\fQX{rw%FpSne!_eo'Yb'˖. )x[}nV`GeS 7x6ԭ1FJWߪ-k0g Kl[α!| 4Nok!5¾ՙ(5=/0cF>&/kh W(fA&Gݮ84>i*9/r[;iaO4| Oqk]V" {{ QEH6ߔ>B-IFxbk \er }fnXl:i2a6 (hhTIqQܬ0\T1.n<6l(BNUa eu0/!p{Epp ΃4z>9(T}w(,ADzT^MպVHuhmdes$+1n2ҥVq#om^k JOq~(oB~DGe?k k^e·#LbTG\tu PGLns GT wLߋYnvB</dgsN`)ت úq@Ȗ'_ ӡ3t"Qu&Ξm7Ѓ3,py~b$ g>HuI:*d칟k*랅jT?a& WL*^=^<k.Vq9ښz}ku%nA #ap+s\CcK#6<$koUzX(7-'ϒWE̐ 4jFNB ^ `XuZ@hUfap`19q_i1۹Go268I֪[J>ܭgb[ k3kE2}A,u?g%au2XsWbS6Sˉؚ?ԤSX-V(ꪆqڮ+'%q>:%R*r%тAZ5*6ɍE9dSRHwS,s. fR~Xm|\]U1CᄅZ22)9)Ӱl, |8Fy o~>5D/u0-Ɨ<%[xM'P[9mTZjUW&ޚ\*jXY㿵zRZP/Dp5 6h͔<%m$ȧ I_JcD-1SnɗԵGxĄ>(_Z2 $s5υK5Z$A/᥶#$ a6ȅڲ\! ±zƒ 1,q~_lCw Sc R"K }}KX{a+k~a=5YBtOl{ 1Cvg]D hjz͏(Cp% $)bGg࣯z$wV =ZIG?E\,+` ;m ;3P2؝jޣ%#j3GqK>ʝL?BA +ixO- b, z,6DI;O[36?=rP/Y#!5f 3{R7 +Pԋq&#L{]q].I46,QcLyoZ5 ml}1-ő_-d(ȷiZl st^ e0oz0aOdZ9a2ZdX8.rЯϐn"[ЫI#]SUN4|OUΫ\e, ǖB&BhG <'y+HOnSTKPRy{ XB! FGmo:'`weW[ KZ3[.x/&冻vn97ZU ;@yO,Naw(GqL; Cz]O قPIWY= +iI%zu r!y[܍$Ѡ>Okj I:wU P 峈59%6+P)↼.igqڒ +ZɯιJCNȩ`a/[x?lӪnLPqCUÍq+M@0R QeRZ¨f7u=?d쾆Ru%:w6x+ػurq;&Vp}3`εh|u N|X2n4_6{j{o6b3BUv[R䱂%:KE޳%N.(2#{ ;vMH~I2 $đLz\)O3_]FWYe UsX!w{YdM|!N _g.'h*5U/5PKw>dP]H7@-ʮ*Mh3"^JO)zW:eĮ!"x+Z12I1}J~GO@̬#EofɋEEJA, Ri3W@3+̸oŗYBEz[zV/#jl8(׆U1^6xL5ess:-|!,{z7)Ū3ݩU^S74b> CfX0FMcw#)Cv.5x(Vq/7 llccѶs(m,7O-cşh+l1#x!(`:L8(>dcl/!X%6PP WCV8(k 3>/:>2? Br[{z c4Dxʝ Cy'Co 6ޢQd%D+1&xޜo"=z|fB򉽐l9M\X_lu*#9TOIy3\Q3FT_&Fħpg<f]I)G/:Pl黓b֏q[ڭhJ˝$]vfK}cC)s˔]P^4{]ZRG6:AUɯ79oFNX-fu' D)KmYÓ*u%"NOm` 0ƕydO^horowk YYNT&DƴIjP9E掎`є$5L-/K} Qtf҂z"1:?S e\VctBE˭FL,e~8oˌBlNH y,,#& *U,1 [Z'ᖩT:E|šF–EBF`A" $Hoy@u{ Zw]W~%,ٍn#%n%[ADyHk@ˈ;l*<͚׸@Iz~B99azNkQ.nlVfNLsW6 Pv4گrPǻ"Ea?xJR(κu{UWg8AKbÖhj;rf&dٲߡ57=:8 Uㅱ*3.D\8~."܏aa()%A"'R|g撴g(hg ϗL0|ltsGR^X(נ֦7HpZQJXpv.J@,taA 'e۪oqyܼ,(:*ŝFPx cJ\*!w w}p;3|@0C2i l;od»M~5(! ]XWKiwnݣ1 |)ËhBiŲ5pPlYZP:Dz%4$y&O:{ wm(}-Ȏzi<_:ebsWn?vt l!'94mCx$0EN۾v0*Dɖ ^jk+H@|ܥ}WL-\T}uSEg(+N4DM݆2efHHn@U6D7]]J8<5V}$NQa\'MFɶF`_ף[6Qgh`|&|K2©iqj DR#6&!Nj\*JtMb/ic ,8 V /ϱN}G?FqCZ뛝1xUH s@p~OQKu<\#dεǪx19n3YKa]yB /ĢLDߊ; QyGJDXH<9Ggn5&FizS4Owl}o/u|FQE-O5x8hIJ{yGxaV[~&i=tqB :, >6VͪU2G\2#!'v1myR=ec|j 7Gp!֎E,WǝmfC.]d,ʙ(rf/5% &pB6z@3;F 6iL #"o+H.T.#C8E3yU6~`dNBēcp{ָ%x(.PBYk?qޒ.ڸhPMUI u;!lek/Ph$F,\,t`n~/X@+Y3g x=.mdm0iaVtQ RO,G 0qs7PXO|Uxm%28CI&^ |gb"r:~4}~45$ɩT" YkUb:AdYLSU q&ǰP;20lh Ԍc8Ocp: 퉎̠̳ C\sb5KgkK'خrnVNߜ^<7 @-8Y&qoɜM ( GsDkUo H,/w1NҮ7YZ2v!/C; NnHtS 5:=zC@ ؾN)LZof _ jq]^-jT`@iX4 0/I[S<9 *5k~wRx 9L8~]_ => E^j9PJVL}?exvp/?{as]W&'wF,ܧ; HU!:ÝָdXjP,Q?` `p2/Tآ-=7-@DL2D9NXiē1:MFG0s_j>^JA)=_\P8a;ǰm'{ly@K u7A=:t9hĶ=\SS͛A4ąb]gYNnR{Dq>,,ؓ.!t׍ gG0{YlvZ+PƖG>sjjz,MD[ 8C)A6=62큏brL14o滛zV_H hM$ςAb ~ᙵdW wS f"ѸO:0|Q'VS3nnl]ݑP4]Aͼrzz:P+y@] n{R W?;!U 5fyOd㧟WdʽlJAx~?r3hT^ڴRp` 'U=8 ~f=r%j͑Mh.E^G^v^v)dVzO~nt,>7\aBsc*Zwv[ۼinwX,Wu) żg1f(SX%:MN}1fCe7C5l̡~gL >>G endstream endobj 552 0 obj << /Length1 2448 /Length2 16831 /Length3 0 /Length 18267 /Filter /FlateDecode >> stream xڌP cA{m{p1sNrz}9+ $lxrL&&V&&xrrUsGK {sk?,DA@7P d `f0s0s01Xkhc:6 xrQ[7{sS3Ƿ< 20sssٛr@G3[F#%@?!my]\\V 6tsG32d 2E Cjf xX\A)Y-?Ʋ13+@##+[)Peptu2Z:ؼ@7K$7s07ut`p0#_a,nm,jcevt>1s{[gkk"skch;2Y9yLLL\,jdWU7[Jo}0ckK񓔘*?Uظ<,vVN7*xR&6Pxi8Tjfyf03a|vE][zVnXmɐy;T,26wZ)G 6 cEsG#7cxnin Rq0331ۑ3v8 oDoFqk#㿎 ;hotgz/vv5Fk7;/=_#`0 %0FF'Q7b0JFoQd~7?߈ (/z#Vo/~ 1 t02뜥1_9_;|׷,@#%1?l9=7 `46|%%o)Sz*#2psz;+]xvympx31MokPe dśVmbo]1e˿oV۵;[, 6{s#`oϟ퍆 [l-9o8wo.o7A89Xw!o%=9pt-{GfVwo u o@ #y#@*a<q]Tjz%v$$L ᤡnqkeg:G'8VIc>8|zU=g;OuϐvN\H\z%]kJVFw*9dJ"u gs @;Ҡ"^̠eMI{D{|ds_+Seq%Cy6:E!r,QT𕉚lcs'6(Wk-f{][cZ o Mz{!pr10n{[KPZ2?k&݇M1WEĞC0:=,2ɪ=z,&Nlg\\UK9!%!7p]WUrtQk.K0؝ー%_f8Q nHdafRZ8]gVPL5qT \m~IΣ1*)m1q8/!@ pkZ;|jrBG)no#@'#~6i .$y4UN) SQo|E).IXҭ"N4imu2&zOBL;n,~e5H{FGzނAy<*{y#Q^]KЌ\ U֞VE ƨ*".zYX'P~^#f wPCU2V7zkΞ$z?|K[Kb R^{TPD g^8LkY׫&+ƞES)Q[.@JT[VN 8V=cۙ V{Or/,mڎC˹ufWiM[/4KddŠAa<~($ŞjSǑ&byw()݅ecm>x y,8ȏͅ^SQqBGT&B?NJV63':OO7}B͌ۓ[#,L%EwV ^&c$ >KgcAvVkPN h:a3/B_e=Tȇ;vA V_,)ݐ.&9ūG GE&'9|D T1s5#H./*{* J.)Z=/[r_"zP])>dA#/R&Ŗ#+xLI24&x2gi׆s3Bp XT)>TUt*+gBU?s^ ܢ9&_>)Ҡܣ {,yKo?4e (B d>x8IyCꔞ!XUR %U % "@j<܁G $2N֦ ٜfYjϻ[-GK`I|XAyvw5} iiCm~êӉ`bC<vĺ>9. yP0fzUUcJ?,4|Cm6@[KYXPچn QCj17ݔeuL1(0 C` @}~ " Hozq9K\iQ"X23;Q?EVΉ9e'vΗ`gETzԡD4qg{@O85WpmʸQ"lE9o;O9bx_ ! Q .n% 2oKo~<\k?`&'r/c6g=em"FF*l_{[OAcD<υ@DIWw̃?--ʍqEmFB σ𨔵]GU&GG:<xj$j&~ʣK+xIdŖS 1F-C$ Ln2NsAWIC' Ǡ4N8|ϟe=`M`MM-=K)|q4d7aΤ 'j'F>c= 0`!Mȓȋ/0EKS坠i_8Q#$_66;I݇l=ˌ>໋5~&Z~)& c&huʜ;T-0B_V{8$AӶFX~7l;nؕ=_t;1]6X"P&!G|T31l1pvNB8]dp^Z C^'qfԔ\3$B9la9REa~8_UH(Amʋf!E^c"Yߣ^0f\"@b3GF9HM&pv 22FG? f]mNgl Z~.xҁM3AxHՎCBGe4:5#VDo.6ZPy32xKAR$]"ɠ`ƗC.ɉk:-[oAnTiCcd3 lbn6'`9lb 7O&tӳ@c`A^ 3A' NyBp}puFk+hHR'Gh11~*G*pv~Pu_O, Ցp;)!U,cX*L|I<[+,2CwWe1#]m2Ǐ  $Im?]{2 FPY{D_~Ά22J]u=MCɃ7 QpywGvI1 Kq)>x;e PC$M i_PUw mL*-ˌ%.W7(NҗaX8ԅĨqr&˾;4%]RfOe\^(4W}æ*fvKgu5=>9P(,&w+;69q3&=bp\MrG87f:oTPf}sm>6ϟ1hϔSsW0掷#5SN\B6CO_t˜} wG! U6$vy–Ki^eLZբˣi݂·槶':)%2a%xKWAհ\w:>k_uxlʇ$1Xy5Gg[HH6)]͞&? 테s+ iD.p+W˱8`8ҐB.l[pKKg2[CI!Kh8EWi`MɅ94XR^AA|6% 9C{ /)'7UJ&QKtL3d奼.|WW`7Auz.ىBя!ZxsT;۫+`} 5N/1 0eLsmͩ?"xa* CɯKK FF/̭pꩲ(gs[ U݄XcPqxtјU&U1BAl5Slq_Ȟ%jU#.ߋ%w~hml sBKR+1j!Z2Ab&ʴF+q\/鳓VV+啲G=UC׃0gw#uU%H5xi;ۢ@$3PޯbVp_X-UST(ej/,U`xhV fƬiVA˙f>c"s S&6jȓ;[{ۿha쇴 'φ.wdS i[ǚX=%n4`U?Jo~=~ ,4@U9Rv h/g$;W!+ "QR8@%CI#f49S2+j{'C]}ؚ?MD 5d6}iሑoYI6;G2q ֑2)I5Wq@Rmu@[)~v$,7=a=kWrZ~p ]:g1(ަSV]0 wla 䀷zG튊^} Hf&OsW؃v~=8GL_LV..*E/5( 9Ę4MET di5`4zUsUB8XkBY)Pѿ9}HPT3'^5EY&?%fBPRwL?Bs7 Bf-C l ǷYX!G{vXW$UQs ˅Њ8G‡B6͔l% \x'GZE]:l ~d=LS ʯ6_y,l(7fտ=̢ܖ1(a-7aaU@v&  z`<<ȍ7PxY;})g[RݤedxTDxS|54?0e4T񣔏/vik}*a G=?=+ڇH1O$QPF#?_cC9` v|g J`5x-g?l?}W vhE`spxƧ0 qTS8v0bqo=Rv#"ҡX$i8׺ɍ8g4S@jh7 ًIPTG!zcO<}H';zҭٗtpSZz2&wDmqr;efϝ\y^K2iϘgd!{ԁVJ; 嵦7~ qcq $ m&Pgmx*lNkVK) :0X]1z~B =]KshKOkʇZq[ =pXcF֝~r%.x$e:wʥ{ $gnCi~'N,|$]la6ciDhHtFU^."!0A]Ksy&ؓ.~-KOU.RO{709c/CtjpgPZ|فr/sHFEqk`0^#zxT#= RO`K=,bK!9_ *9 ;Bp{zSC0Gx@疋87d_bUTS ο4ف|&u^jW6 NN!)ˆ$GV1AAF4{u+'\Qf%!&i?*#񌦅:N&}i8΁j9S:M>b-jR$LK;'@gg6V\b$K{C3Ȅ;B\H_pg<I|NZ%d{PẦrq]mړT Z+zEb_ѵ턛{#ȹ>PD(^2߂:KdUb7jʓMY 4[Q0[]aF}i|m>^N쾝XAjFWJvykG9Ko*0s0* :LsL-0:~J OMU{ bx[&/ sn8RDK0ġ?%7 >u}/4i zw492nʅaϲ AI$=UuwXf¯?4ZD7-HYg/Dm׳5_8)kWYU҅dd*:η`KF㽥ٶ#28;cOM!PO7NPrxq$EØ>kK 9օjZ}/qVߧӿ7i꾖i\7eiIe 7Hwn磌">f/E.`(r_}T5dl4ȕ1Ė8:EȋmUKVK3A "6nLA]/ ;u+>U~oCj^sޜ%H=ڌ_ZwnH'i67nU6OpO¶SE;@&8q>bƓ<Ҷ+SJfc &ܮCaW\!/j/%4}T#פ/ռ6f~8=14tzp"4=.!t!fevΦd3ۺ]ȡ;@M=|7l[[O1tKf+IkkHΠՖ#өeufQ.w/OjBAԻUݻeKƓ븃M0cZ\$xeyk{B$8Y%a;"ɛo.ߙ-6'SQ_,¾ˁh5ԞHP?5'6u>W9dRxD~}*5F4 92x(k ~$o)!\N١k@+6 ?1/k)źTWdg8 M{nhI7&cV2nE| )Qnۥ`"K2\3z̘} Cb*>o,e嬭L OSj ɊU*?O󏿏3.ڇ ڿZ]Z<2&c<ҥe}B]fnAMD''S6SإKǩ\Sm;## 3;ʔ0a*E]Y '[DKDec,7`-X' Oj3ߔVZ:DNٗ|{(,v3 {fLW&ODsWܞlb/]-|2 ƮUC~}/H@_Ee+RyfyxLa ?||Z(zT RʁFֲۙmbmHv˺aUx֞NhIrj+Y u+䣺@%flKT-'qH01}FDj \Н{V;If=Ig2[㥼 ᫁ՀtJS1BxJÙe>HY.53O0OB_Kvv*ܰ' ?we|L++sY@4{;v^|`W81rjK-Cw%Tf] DGۭs$& kޕ殰؋]8:M.޸B/ K lSf*4A^8{'Fl4N)ý4Y=/Wj  ^]T!,YG}(sdPZA5qN-/JunOvHxv۪)n5f%{6Գ_=#BȻ tp坿rxM]Xi2*͏2֦Wy۰rg:BWKv>BYd5n4icyi^`4/c,Eg Lr6rVC $&2>õ5>DO8gfe?*g[qx*zߣFv%C']$9|[3OaZ;R8.rP/('{ P[@XTw_XN? }_{pXF)tY+N#۔dٳ"˄]/?;lZ'AS)5KMȪ3C8~A3 f󌶤&72~sZhi^aN}*9? p50DhDĪvQ$:*e*®N5|O*j4Z-bӴ+W擅E8N͉b~d{6%֕E\·礞&9?Kz* -lx1*G~gCYpQ+z(f-A **KzC Tg*tj1`fzlLNQ kփU3 $qZ/6vAM-.m+jjmj ܩ@\dE-x!$RЖ [B^$gULC`ӂ{2W.M71O ̰6U1]ZKI>÷C~o<p[T"ZzA&_Zh^*p󩙱ϰ qL:#PKW$3wن1i^H*u* Ene ZP6;1؜TؒjxT 8y)<5O9l9D'_\y#::ۜsjU$z8aYu |{v~g߅1 /Z;`t#&ScPUʾ)pZ1Ṁm8߽CC+0y!2vN[,Vw1X$I獙퇁ؿ,LLڨ7%39b@~&h<0h)a$rM gӪ010˹+ןAM+:Fg=>!,N[,>^{Hw(R8~3T{ޏmR%0_-O8!w\Wmޝ0G6~̯cr|>#ga"|7|V2sxլ8b]vۊOfƣ>;$9e%à/c^ N̠<:6vfu4|MEA+R }9@["ga#P_y(՚Z7FP\%wFcKUI.vH7~ 3;llI1ަn,hRE)P>ófo9ABKE:ꛅK+rZF>#'뙏Tߓ.v9!J#n)DS1=(aGra[%ȸao8$rPgN?4 VB|1Ĉ!f1ӫ R0$޸].֥VQ@G׵띐D]:T\#cƴrp٤)0gF s{2:t3]mxkBOl!D#.!HSM冎?xI*4V2 W]ii&Ʃ!}3 |kP&BJFI|d2*?„Us+o{l\SN/ƀ [1,쑧*p{=#&)LxKb/O *o+A~CBZ!ul]a@o:'oNI6--k=lӼA51Hrs]E},-(vύՎkz*LY`(wClv*H0%-deG`A"Og.q?)4r5r17v4xJ6 yxF.ٗ5Ry;{;NvL?ZT^VyLv&HdCP1xpa˂dۧIx aEl .ne=t)VlkP i5PpI}h 8 E'׿Ok5}E@/09U`ik,1kxpק0Ζ&&';4V+Ym#>-԰b85n=%yh8a~e3^Wcm'>Jbf2aF+cn*2|vJ݆~z pԫe:Ƣ ߖ}Okwc'i_-6هYcC7W[W.j"X%3hop?:dThj wL5u/X"DKG<9R_v ACfl#,ɉ ᲅЉFa BÛiƂ.Ԣ8_7teʑitE~}+]YE5>%Fva3/Jb*{zOGqەWܱ.רbKP/n} U!F_b6Fٖ$r,{#Тs]5l~bL]$ ͔6{qbXmu\*mL59ZF7]Ce/`4xuk֯{߿A?YsCmy[ȭ`+V Q W Q/W͝RhoD%JȆ {-{a _ g[ͬU 7 sW4Mz3Lޭ.⤀<4Vg:!J'S4=IL 3ڛR_'d˂PvpIH%Le.^6ӿ E6##D뚍 W 6tXn؇,󷃙\S뵘1PHiw Q`9W<Y:Bh!' 5(ƨ):ScBxNa^_4Keyj? `yMŲʵ [s1o҄U?SaM)VK-O}Ui`8?ɬv.,zDp%W ]brdqZ$kqx㿖®NtxNמF RjWdx n=dqYknHʃxD5V2^sR! `&Ǫ.#@O_#iftuK|$B$>^iSkg ;-1!QmI6B r*;3@䱈B-:(:IVа,|ۼKi0 "N;&j,q9&jtǖ/lBQÕdef H|T8\abaBp|e#IA20-.*M j/G]4vY!qX-г %AӔVzgˤČ̉`d )E,[L;2Á&rLnU="_`6mM#\cYbL_m<WT,fzT;bѷCN㻒vewhyYQW#n+1EU:۩}%TPeׇ,kxF ;dʛf,%Chkue44`6Ȱ;pϧiv`-ng wTu>#jz f>Wmj<{thb nhQ-Zi3Mt>o.K fVi,3{_yz,Q?x-n:\ch/"'.x7Pp 6PB|m($V-9I=^ŒLڋ"):qV :@sͤ~l+e N7%V&[KA"ٟ&K)58_nWr$_0a;G ς(aw " HJx:y]kx79y:I45J`֨ϭ%q[a؊u>[>ߟX$Љk_ պ] sO wu/]_EmNkT~5wUBd$3#Mth {S*{A*O$#V35,bbiN oy-> stream xڍT|6Lt#(;F FKtKIKtK#- H7");} 4RPs<- Qpsqrsb10耝AX A08 CA:#8Y3BO (x<qL[t[oOmg!J:S| J[ҚATrhm"}KA>S.'6pT}raa>l2JV%z^#O+=%௩8*OS6;V;ȯbN(Tha+z*:*x_")&Yqs+gϋZ0'%-KeGw-Pxl E 򒥵89NiWDF$RV=jf\΀9nhC)'1\rTEhX\^EF| 0`k6&px>tT`(@w{-Dl\lKgPk[Q7AaA$daN[G_|&Z % a͑TDswOg(LŶve&6%ӠC$=V%bU,qTu6Y Zm*ۣg}j/ .X/>8UD4Y6iqRvg]h+w<\U(lepS9uOfvb8uO=`[1i:;cTmVO"?V_5g :)8 hð vXQP!%9m Kw7Wp|j%@Hp H=lTlhA%?؊x z~kRcCVwN ۪W!Ej QN2x}dlXՊTC>O/H%`KXDt6L}>|lnyu].1C86.eX% .mvܶC 'TqZ;lISp@_g ouf13 F,ot`%Z2,ؠ ZI+E}(vk|θf>_:my[e 'MsEGZXl%n&]1A9y q$u"oFtE*acGPb<)VYq coUcFdN;⢎{21[F4P)d*?s{<oPE]}<8k̼r pJdb&v5ORvټݯQ52ux;eWf_|bzNzCpgiR9ͤ`n·,m.WTxV]}AC G~xY(85x>|.6r敵^5qdۚu5>lg]rPg;#ׅ %Rv9QOT&6/\WM+Ba>r 90Y5jcmJ=3'&:fn2aqP[5 6v:mmxF,csbmhJz}#Esl_T@K4-#,x(O9ު m@+㓝HagEX  n ^)hRqpdG|Ns HA#>7H6q~^$vd+6B^1;X_['ܾ݊-OYqwֺFMYilɔt(_09-+V`cl{Ųς-Q*>/> ;fĤV C4V#{^N+RDResm- bI )|h4W2GcݰR$]",e]G~YAq[} !t< zo%ga8S=~?&uQj305nƠXm@I~1̺f@$V)8-@uUY0} s5ū<7SkN\lFQӾzuW}_- . #ħ404AMöۥߞu(5&G*XޠH7w.CEsMt ig 4LH,~H'(^ ^}j9 @e2~Ĭ8J?U$u2h\NY4 α{V BRQoN%>ZfT\`>2HW_a2z0nCo<%ugԒ릔KR/m-a:z熌k9&moǝ"掷 /R^^HrƢ4كm1kxM&L(C%)!@r R<)k4,y땹70>FHHƎf^8!U e m+vmF~_ : `&9Uξ`bެ3׍'^תp=յݝE>k6=H[d>$;jKYPJ=f7 FTgqZC!N5?c<#+x͛;tyuv4u&~)ܲ´5͖R:*e3VݚC1j d41E4-OfW.  6O7)=eiYUsciͮC 8zslLOuHO4̌/P#z\cwϟ|bFkj7dA",[}wP:OPn#ih5[W蓜H9d?_ѳaW6XcLOr;wpԗx (SY=+KOL}Y  z?a.~sVMdv2%eE`ihp"`̳ׅ0Vlүz)Rc;k;u9M\̸s`b&8']GOCZTnna ke>C3|e&58nu^ե(LݐQ8*YIsmA^-E~c[TE`Ijѣ4f"nlBB8ŽUqiK ΛN%qsZzB4 *v |3g;;R=e>j/V6N585d:@r"S鏎*\u4Q8%Hnh$]#0;CWO3FADtF3+m1iz?=WM719v:.'K˾ؿK4^u7y!f]T,Sv-a֠˹ԐkQ7V*8ߧ<#,\'77BG5^yD~;$MTZ&DD. sq #d\ϖ{IǺ_U_%NM<{{ ћ ̍e*gqMr%=!UwupCULOax!Yr8Q>ZaE-UЮwG}ڲﵦB^Fs DcF+^%|{qs:5ǧ%MqtNp8 Ae)S?kKO5TU)~)j#q^5> %1'&UN$$e]^i#>v :S J5r jn]nMUrT&V9Q= 0GpZu"߷Q8]߫H̤5jrv =ַo躹>t^^A3 {M侌tؔLUc($M%QF3^T"X07>nWUek \ndc6* }*@Tue'M XC[DEͲ"CQs'}-h9rW2k]yV}cn#W$D+&@ !KT='xic^~ Nyx>?>ڸ7`V Y-ո*"Ұ!^Xƴ,zoF F#]FaDp+LLH!GQڰkީdB %5$LL@?.y:+GP6s^l3 -W Ԑ?/n5p{Q:aszs]jNF >zJ#Bl.AQq[*aHӖ58ċS[-c{= $Yϭݚ?PqzVpvTxjx_̷Fp;Н|ckJgUD!2vhVfup1J_kkAT8Tp:;2aS+A:RSfQזn[F }AIWZMTb2Y1K޲:z'^y/W,+mZR[G{EՏS\+lr^%7TZ;xH>򎾿mf/kRs#0K ~+>V.hn^|*Įz]F(HKt-9_;D¡o܂7=JZE/ 1Cs}'["|H+7ː~ N_? tfjJ2A%}2|'< !;ALtVW3bW;vxSv\t_.7a `5 'F|3nMIIGs435ͣ)<'0C5=( 9 Wߡ!@!Zˣehfw~]Y4 k sZ yg#OBE`sH۲Bl 7͇AK< |?eEп?6mI5=ܫHͨe# fstCS[G5i.{˙'Yh/iҊtYs|P>X'$1h~ϦA$_/"O+dRdA̓-NXg9g*Toy|8VRY 'ac鞗GJ~qq ' #,Sz-B:A *n:C b>x|9"1ڠ%BkA=.6+ǚfH~enMi|ӭ1걏]iicL(|ήt J)6U܊Dw^L):#ynBlwM};"GO>wQ alh25Eab{bJeHotu7a[u)vgw[fq0zi"47/ +*PkYV.x*Mنm!s38U QEmRLжxE39b#{ҧrK+B>N'm( ?")l񋤞fU9/D&AW_W -2`B_"FCU~vot߫ 0Ec(<‘w; qFQRec3 ?(7ő^)мuz6$GoJIIo(lJVWcjD f= pNL~4a썄~e,X'𡓑>4F E։e\)1NFO#_딸Lhg"R`n*(S9m4\bv\%Y=O'[:a^6Xmwt3 Wd[Z*|1@:dD&ɔfNe#Q z<4)6sn&-B%-*͜`I_39ܥ! J.'grM(t M gvAR4+=GZ|~+J:l/IF3镝iMv&-?j>%_$p\fO% !G=f bw*|6}m86 ;ohD|U;O{ $Ϩ{}j.!L\ņK>܊Q?6Gޮ~Z0`ıDKE?ҁ%B1_K iF_FYv5Ur9-.u)Vo kzkPX*YWR2{'5vCC[/I",ck1>dˇ-Rq-KK:/C7+8qOLӰ۹L>nۣ߷[F&3V O[GFMW|&I uKoudZN`b6~zT Ֆ9hjdžGe7=tfWP`GI2[:Nu ;v߂ '<Ԟy`ݜr:p6Ta!Y?:+`mHe]nA[}8lިGݴ[cHY)54Lkg-3qC[K)4yhӷANFd53ÈE^Jb߫N; ItO7'+LN:XչvʺlX3> #二'Z8c<^f6=,`X+>M"q[auz'J8Tg<yxΒv-%uQZ=Njvz ZzTSzdk^6 ECS,ISI0K2)q@4XK/7ﭑ69qZDF_.Z4ւ=Ӯj0 pHM).jNgæ>ԏ:ؔ"L٤)/%սv~H@(cŌ5]tɯnZ#^ P:(T`KC*J+nU'_u_$v4iyS>6~0Ѿ&Qs#'M61i&X aL2:VwE̿ʮRIhJpκPTͮ7W6ߍۦNyDhwВIcox;tZF;+cĤv"`6؛i: &M_H?^6B5\DW@+UT}Y;_\taMDqsֺ^?Uˑh`]T4ȥEN2Ym"lZmg鞤xOpd@IFȮ;Pxϔ=G endstream endobj 556 0 obj << /Length1 2610 /Length2 16483 /Length3 0 /Length 17986 /Filter /FlateDecode >> stream xڌP\ $4wwHpw;44܂CNp݂=Mf-^[sLIQ(aobdebʫXXؙXXؐ(),A6H@'gK{;:@`l'ooqXXXXl,,3wZ2v@g$JQ{'Ks 8hLh mN&Fvy#job yFrcfvssc2ufw2eY,*@g+G#[_1!Q,,ڛ܌h p3:rE_r0  `fi(J1A #;? lFF6F`?37H+]șwYThrF#?1K' Mo`figjG.,]bEHe@tM,WpS `.miCt6r@N.@o+XY& 17;X 4 da+叿eVTUVQt""OF.#;; /??JFOW ׿7=xߋb`?X&$bcOo"G!o> k偦.W+ 2?mtt*YL,\ nciTwI`dea?:X&QLM:6N. x894f&;{`f@8B\f߈,A,f߈ ,9e#0o`V#0o`V8j8?ond?J.Vvkf/?.61֛BJp,_܍)r˶"~ Y9\vK\tQKp9ߙv# [wLYk-sqW̎irtM!YY5+9N@[6@ L ~!g#ggY8Fpp6wwu' z 'w`O@2# <*П0_)@;iiބ?Ȫ&JЍqw\prW#sɩ >[zӭpP8͇eg:xG'XVIc>bD"F{^ώ^͐2َ.Sf3j}M cE!dA9vwA`:4#Eos$_Ogb4_ڏ:ۂ\z|{\(ҏu&_* %boÛ2~̛᝸].xClTԚSvH>xK:#.*N0{ۮ;BOV@om1Bejw.yʼe%ڽxF]dV] *yG+gzN{In:S jmי"1c(' C"۟mk=z~|"7лҺ>IuG~8K#o;vkT` =v4މKxEu`jqXÝ؟6 ՙ>xYzZhaՔ< 7_s4jl7NgҜ7U?O;Qo*<}͖+A$2]z-'Ʊ\m0 E`MBZ\pnJfB ?<V<+ssEokḊ2Gkh .J'K̅$~MRySIUhw0pWP ]53.Ӟ׬qR͡o}VyˈXGx,RD>}␊\ ]vIIOt Of.7Mx>gؼ !#O f=im@h(>VqC/6 ah$Mr1YZ& uџYu껸/qo s蜿YG"0c@Y܏+VM+4 фi1e㛌`'أ: kJ>b۔J^ A PmnRvw|x|O\>T:#TOVR;$A^!x}%@EJR+4cH~+nElV>>px tQ_0ӆj_=@ Ѷ6gt>[EN&S .nƆ'S-B522(U,?5^ ;f范6I`\H) oX|sP`=IsF :ZG?&?wM`Z|(|S~F-*i'F,?Vӎ!$yd# U)eqHO -Tݓ x܌H#tCin#G$ G y~ΐ@ً伷Cʇ,RX$`3U 7mh$d˧;N8|.;9?7u4oV fXbH†-f<)^l+[OoD:} VIʘA JdܒheGy#t 'c?l<c&C_b0H˳v)vVY-M1Cf=[ _tudFp w 4"q@~>Yʙ|&< ^MT~u_Y:),YWLU'GKgOh>W,ȥ \{%-t0e۷V~%哭q)%V9tuO1 o*Bc={ lOZ%#Ox>2 \1%I/X@*F ¾WO[;&GbZW:HcdHZyn9@$PVM0x|}WQز?SF %FDR!UIJrjւ.Lav_]+WYT ] Ntvͳ!싐|G$V]j!{s>c[H@~ڙU<݂F]Nf-g!kg:xI1jVߴ<%["gaKzBhyy)O d]o+#AN+l~ro6S !]CK5fU3 *ಚ8?6FCKQkYK+??[l="J5yAuhx]kQPC֮X*!o= n#3[|CgD@o6/obp*ъ[xΤX8N4Z3(Z]seWg XK}Dj }^14JDiX,@c<-$ȍ^0Ѯٶ/EZݾOo-NPu*)X?5DDڪF(ouG'],=\?;t'C3ڡPz y׫XK0s(ƕ_5xFBi~iF޼lo>_-/8)Wsa8BgmM3x1ܭJHى4jA|B\pmgʮ6(2ƽ,x ]2}"!fNTf!:UȮԨ=O5=d!rU%!)*ӥo24 fkufynh\ª>fR|]k9^W9kJ jPM~~$,1wo"eH9Q>@62R^ثixIz9J = CRn(FF/U||Q]AܟﮉquzHU`˴B?$Ζre EAT7٠s}Xr^B]Q ׁ\IOϚ Їg >]dMr.m4",.,'v+oYua>f'_ *" 9)sv3V#UILۗ@ػ/BB%wzНjr|hQ(`/ < \-((a{ >IX"3+iUO͐(VؗU}P} H7S&at*KI2 igYzc]Gx6f7 aTqfb)4@JuZMWFxrO;*~t77"g1aB<Ў662충EUVR=L+,UT DimB[hxNX]71aCLDې`Sw0nPK>TBc->Ʀx8|o_qQ"qJ)R%CIWmGM1ئ4=9XRAݔ.n3|!@seaioa4$/JR>>U@#/r}gF`>7EwNV뎪]z衛E1}r1a1ao%-zuػ!#Fـ/>6VS"gg>2k8 6XPq\HT/>@6fc˧G?8 R%I%008=wqo^=b%h(di8&A=g=Wh;톧rMw뢽V/Pf?謖!J:-;š-F^0_Q*Hg#Dxc{{pp}Y./AGEI}͜*~Mа~Gx6y(97'-.W(vIZD^ LD 5`=]f$%":":U1]ryt Qiqóy*)$!m;GΦzؔBNπ~aH~,*1axٓT-:R_fESsNu'_ /U&=%J ҞBy8 Qŵ'``*KAL{:j2 ;+Rtd ^ʏ9Ur&TRvqÿ,xP/Ҥ['~"$h]С3jo0zۺΦ_a 1kHcUnjAyR+)P0d%\7 >ֲ#`"& )ځ5GnvŢXmyfIn  /`N#ͯVŝ&BDYٍ~\\I.ljd\kr]Y]XVr$PP7X 0uZt[D!x*nG+tg$B9p`@QEnڵŅ /m~7OiKC52Ww\ -}}&(d!?bLRx%'YjkIܭŎrJl cGPe3^D~{Dݹ|UGp$ 2 \6^\Jb~D»lSH( Br:|eQ*Yg8YT/ (u Py Ms *A)Bځ59-jFX!o. q䥔_Jȍs6,}o!Eڝ={p/wu%>b\N '~RY_v$.8c@:4D;5囏e=sn=SqI3PF[6B|P |d9D0h=~ktFݘ$͋Ps-;3 =dayElhihnfWI,Aߌ4s\lrEVM>dzu ?4N)y_Q[̱Z<>E26%iwOxw76n봺zp9g|%Jo+ [Y/7\qP:`dgs{p!"gp^tx2wUsV^>KU{N&OլY$1[#o Z^ڱq틻\뜡-Cjz_菴#g cSE!9 aDuDODX& qXY;5'Ʈ3g VUl0/`A*Tv'$!DM29-rp(Wrч.#q oPr qa}w[x>n>);K27hXkE!N|PyߛdcplC`ުAOiř2 ũ_0k CD47i }|͟p4a ,/.I2Ţ_ 붅 z.DdnRsr7VuF.޸"uH#8I7V>?]q" **.{ɳEBR t-L)](/dl T:Fl!H{=eOoq ˗1[O )cqSPs7UP ]ӳ\N~Mry2i C}7Q>|i؊{ |:cj9 3pzET2@XPNc b93٥fzV#ʖ$APw(#/e[GRz߾)hy`\Edtluw\DCBؿ,)ҷj ^DVq4`y;e<]~ޯp !LrRU0ۃ{kJLj/fTݏKwMMõzF5skI礭[DD]0!J83$n[1\_;N%s[zOa"X^ݻ&#Y_3Yn.%-'fHv:{6GΜRb26܅12:?/-Hj|9MI םc'}Io;i+*_~f7".I_ e>0!(D$Qhx.o &3ci=i̭zO7wEHS<5e~vHZdYs9tW{z?T T=M}2=TsvF쯼`MAߗ8H2+'zmctyڋ} Ae0'pn6-B5i%(?7>z8ҵ1QӟR|ufx5m 4^M)\/8"(j=zfqXK$T\/CXE!oW#hEl_7j:Fr$7b'GT.xOR2SPsi#].QXf?)̊&#g̽@ 6ew ⟥swʸk(c^25gOw؝N虤HSHV$@##Qc,&܏a͸Yt̐f-%;'l >W9efǷdCy.ZGYVPoxٷ: gN& q&?C>L>oLjQ#OxinC/B;юm j7ڹj̦\Զ3uwxfQ\ѧ>7KڴᾥT}+՝g]~q[)VF?ѳf|u5'\} c =MQ5zb@=B)P]c2+ uݖ!aޑL\{yD `ex]b>fm^NăӋ2ʈsz_xtzRݖ$Rϋojh,ڂ;5Ԧ`9C^g2 TS@ҏ!;q .yHAĻq~>1k~i 3mub;dVvH7"ÞV6MGS#m.;d$P0OӞ17}e14i>M]. r[?K]B,^(@w[!h)X ȜUP٥)M}5wXO5b5^C]ѫ^ӥǞ#+Hr¢=8髲cFN{`Q?Ѳ/Pm-\Vܴ)n $FR_?n +h?z]Zn8|JwO_pޜsj%[ʈ$8Db2-'"*|5ݖ(ݬ N4Yn1Tզ7g,V_@ c)~$1>ت1dQB؇Q{p~ fL^:-kI¾[Y/Qߕƈ-9gC#]K9l v2; pSGTfZZyF- d17|8ɖgǯ ɐI.x#n(t19&hra*,`2j;WwĄWO ]hHGz̵|ii+ |˙?څBT;&9HzNW񐭢%F`y4㍦%j/Y!Cn(vhFs^XIͣ=)˂ة6>l-/CE}6z@G˷&dTucj~†)W?,u8qٯq + =ΜArzVw8d*?lzڅsyWX* 7y5T7aI/,b\$WtIb}q6g;U3M匾yh4eObMW)9`𗺟B.+c&v>oOiJ]XϦ=`ѷ<`pH3`x ?\k#c_~~ 16d"'Q'.ڨs.7SHَ̘ jRӎ9ئ<2ng^:7Jy;<KDZ?|V.6ls a|׵&IHYV70ɯ?V >f܉SvVDKpݛcx'U> A\\_9oòq'`P]cbC MQPgaۉ{/ȗ~gniVXq\{&̕vȒe-nJ~g9'gENzG!ϸB6}!3nE#բՇ4)fͿTYdY[>U`1X:07˱$'?Y3oM.iV'٤.#.S|J?R%pM.IVrHKe| }1~i',vGwNu=<_i߫?<уn a_w,-}w0wXZj Kgjv(ۻ}A^QZ"o8/SZmv)f]EEA`N@M:`yye`JSVA08Y.ٛb?m8b(]( B)-6M1+KpL >[‰ފ.:}R,) 1VDM% ΄'p%a=MupLӌ[/ςc{8>Ƶᗽ L:˖uߌ:59C,GkcXXxO~[͠$Wuҥ`"b z'7o>ׯ(8qZi='l1wyxJLèT^?! pY.)lc9ìx?XơUwmqhss뿺?f{h.F)< s:ۺL\‚UVSw~n᭭]@PB~-"[ TEiM BXMu mY|]'4jslk`,A9+%ҵl37j5ԱJϫcpZqcz (҇]QOhMt|+c'ӤDg~{_gOW=Jlz{gv` K.wj<B*N|)떒DZC6s8W+A46nTYsC/~6{2qW4yl\&x8o1{ic-p9>ki+!g'A @30T@w8MW=]ter.a: 8i`*iE-@ib0lS:$r&ÁfnUfUh')-S47kfzɶ^=j ˣ$sE!]dF: @"@AIjKۙ (3zK=_`LZ3!Ђb 9&}Lqe_BpHGbY/fDž昿|(ٕ;w#"V5K: _=5ѧGz_u%Z(r<bXB 5ͼ>O[\m޵0 05]ƞ-02rA7c]%kOX|PM.G@" Yq3[,+Kb|LEp YC.^t(|s#/XtTGI+UПUk9}F~U^\V챏RauX02E f9XcQ^pٶW[RPkJ=g)\`Hl,Ľ*â|ޢ?Q=-e{-wڟ]37߀7ge/cA^߷2NX HAȏ ȹ/pN?%Cq}y#hJ,zMGERת#. /@&MM]cN6\|!!CvENIZlW|R*eC>Ho"VEf C`Ĉ#DmxD!FDB`ND#mpn`VLmpȞgEDs/-5AsGnhzǷLIzr 4*#Lk<>uxϟ!XV>,G}5.ʁ $@ANFW!qu k~[\;b1LBjUnE(**D؜wLz풮ªd[6%PO1 +R>=dGoopQy+璏UB38asMyÍqP/"Yۏ,Xz~2R*Y9Xec85TЖ+ݗSՊIqEj>{X ;P"XA6#j҃J4jX S9'>HThDqFq8d5aQkH18[8򨑨ܾAϦBZ0bm36nU=8;I ) A8:hŲI/c4jDqjGYIa$ymh_?/K7> pҰOOBRi&J:F.~6^͎OOYo5X橽R7i DRk'K8}];rʠbxXo u"gL΀? F 䖵 ,Ħ{[{xp5,:f71XIcۭdg0^Xp 4 WUc&Ӣ[M:˞"0s^$*kuHki.εI܀՚$58A#HIO 2-e|4o. M7ּ %OsXq4}}{j+y'nL [D4'f=C>mDJވ(ۓgOaG8su̇)Œvp Ȇ9lA/v%p6XKS?Vl9߽W-' ]4\q"O*dQ4wE.2YrQR8uLuR#\#EܜzB*r2R T>gks6@iVTQ$Gkfd0ueؽssdTJ5haHC$X|M1W鹃ϚD֗%e;TB6"ڭGXIM@] &(F밎qt9hg͛rKcm 4T|@8lu0E^ZN>0|MA> stream x}RkPWEDN80JnHCK (y&KXdAdf@A ZEi**8DP)KT@@4EűXvT?kg+ѭN2aG (IN0S"$F[u0sYlBRȍTY@B$`ģ! D$؍J0ƚ&<ˋՊ9-U&jP-.b4:9 g|}$#rL?(&!cj|՗DdPRj+ABŀhDBg`\*e 6 `4O DRUO2~FjD-S݇D(N9,Fg {sIag4/\D1\\g(H 0 ]P 5-'HPM(iӏu,!#,X TC'Bɠ8ſN[,A* )ɘRi" G)Zs>'4LlL6 J%g(AE_;{ɕ=l17JKk~gݶ%1WYr?ƛ4Is|N^u3 oǪ%gbZMX2ӨFVhd i๩*P796TՈ05aʈ4iz8PVn͸(v2ê{h-(xzDj}psIC^i OНX־΄f?wv괦꽗.?2t/cmbtGޑ$ .ڹ\ےHnr^ZTP*i57v뛡% _v\_#^Qֻ39 2tV_+>x > stream xuRkPWD_)! B F% []l0`HQF¡jC@@ALD*-h7 ?|kk% f{"D4)6r$&Ĵ]M07Lnp8<Lȍ>tYPe D ȨNkPWV9u}F{"l:ڈIq*oC㨑F`=7w]|n)TSCNcMᢩaS) /o.ab{\&uSVen;%6/X!',/zsr;>#3׭S3-o^؞J4~V:H9im'_e{ձF Sj\{BQew}|֎:v&bVsѵF%TYkնLJ.Քj=Wj\F"A_;D{J+=/7`ƒFyX^gJۯu鰷e|nv?9g endstream endobj 562 0 obj << /Length1 786 /Length2 1019 /Length3 0 /Length 1579 /Filter /FlateDecode >> stream xuR{8Ti^ Q*mIO6 TRM1ddƈ30ќ35RIѲ<خdE]LUlvvϐ}}{X2lC G<8;A66T@0t:Fg AEGSb0pg3 C+Ԙ1@g2uԨVd`O6 C@sj+$QF#02D!$JDFJ@#@40 (qx@eJ0}"Ai0D8\>H\@&$t+y;#FR%(#c _M~ab2U HT*I1$r1t5֐ҜP (51iU)!0Z$$J"=O $J>w<#؟Pap "#{OBr :ɓkt1M#ݙL{2\BZ"dX_5Ըzćŗ -:U1"+G QY4Z YFm^{ɪs+>Dj2L7;ٞ7E{=v#Z$AE̿ C},EU^;)!qow vT˿߯o1hd{c;P?ƄJ[`4aH8M_yb<eXmq lŽLklKcoA`EWr$}hCWeJrsZIm.*˟Wm.]x42]۾JĶGgҸ I=8%ka+wy-ףMTcҸBǚt3i`Qha7wh^*w$rBSܾg(ĺ"k򜼴tDWOb${ҙm6 >^ /k6)tvŻUAE>ә&fZfW6 %tX8\~WexK5ľ));w>^K~*N-u֛0/Dq2Ev*|loCu1-,[sj1ݝv|cqtwGDzNXmÉa|M@yqk=c/ߴ^\suXI$ڞR0w5FunI 9ŽuK=x>nCgwHgN\ذq [q:mJs,hOhNm4ڔ/Y{q G?5(z?C1}~ v<4c(Uo~u3ҜKޗ O*g|%~n(%u`= ^A endstream endobj 564 0 obj << /Length1 1630 /Length2 1995 /Length3 0 /Length 2779 /Filter /FlateDecode >> stream xڭTy<Gmb[R6=Ì{[ICn0gvgrEtшrt -Ȳ.mJnn<ޟ~U 6LC`@%nP$z nBY<ɨqA!=  ؃ @_ dur!Vhzyhik|]z<X0Dl 7 @( T?g7G@ paKcT 1 aB., fBP]h0@Фp@n$?K1|@0c \A.{D6B R} a($d" 9[1`\t`B(Ms`.4W`֗ t.ȢqlEq[8/}c碑9?k0dʐ ͂`=8á@"~3y?lQ wn@‹1 0P=7SeoG7Mo~_}_CnH|>?24 @M_ -bS>rcY85D]g%b@&a@(lN3A.A۹3 bDB>@u8]s9Sm9RE2s6Q٧ÜO\^l蠺dyf[dz.47v. i~@*ϩIWi x,תu^>>Wk۸x\`jPq@#ʫ0¤*w!:"\}uiJvˤw Qfz}&vLtoA 'MC3(5**ނ2zwo]wx *%0{oX1=Q'[\tgeyS1Q1S<[HQI7wݪXT;{mӹ#eFr;N'TrSQ1 HET*3yW~Ѹͫbwe+K6DJ[K1 ~x OF a4 6o2,õ-_䈳BزLBYۦCqO%8ߝVe'qhx_1'#CLҪ^mݬ~ } *\^z鈷?RLƎS>bw>3ģ"vgJeOh}\ϊ}k6* T9PE216/z[z:s:q$6Q-&@w8<?];n?fkV2[/1=#*)9a=tUׂ]YxKWyS'ҝ-QlD|ۋ&:4]ER畫%u-f,U#6a+8E5ε6. 93Q0̸} R R]s!n)!kw\t+B|zgRa!8"G nU^,թ)<|MP/X/J` v"q  x,R{{E0Y*79(a׺} 25ͱ)7ۍƞewZw0=e>oUYX`ep;+ OyQŢ3ZgtΨQgݻ-VZYwld tVLn 9XwҽI&hc-f뉇s݂zZ}4@̚W}$\F%CE?llvz(=g>x v* ;A$>;)+\d6_" *B*, ^-Z!ĵPf+g$Op9V?¦7 #9jfu4l3U8gk%"3[U0~ta1rX`3(TepzUQ1U# R'vtE[M%eJ񃔏:9(z%κ28!^Vz~|$0XSbL{xL,)w :Mq?m_pSk^0κWU8(Հoc< ?[w+4w;Xo)f+n2Jz"Ɏ9Cf *S[^ߩ#<,+Ͷ*v[3}foxRӬ5#7<)PT]ڹS0}L.dl~[pȤ|[FTN4,.tFAkV}ָX `_4~!ŻLw:po/m2]~1ި!}+L\ endstream endobj 566 0 obj << /Length1 1647 /Length2 7224 /Length3 0 /Length 8065 /Filter /FlateDecode >> stream xڭTuXmFFCFA[a.)F .awv?fssss0>0(G qruс9jD9u6*K&([" 0%,0` +**9y!6+;;ǿ,]V@"] 6PÇ"(ρ`0a XC9-m#M%@ vr fX nͅK` pq!a` 7p!.. n E<@<حa r<2m 8!Yak` wKa `\V`` S j 8p%vqyy};_trr  5/CN ! {^T0/_v?070և",A0'ք!RXo*sD7Ho"Oܿk_=ZAa3Ec <:q~/Z:B<{?9Bj' _f" ҆ kKc׃p }VC/ tl?Sxg& 蟇T07'(O1>!"5,p߿NfQasF0P6x? g`@TDYvﰼIg^Pڗ*`)᫢\ubw=~mm&u`nORҳv|ejf 6/|oǔcc!͵:h4-pny N~OuHUw.Ιz{vlPg`2[%=K@xZOkwn®ORBR`r^W|,-'.u<^?zOm¨Coӄ}_otP'.ꥵ%=QfO;P814mW\`YI=u}ѰOI9oQ͇*0۹CX!uQ.{9OH.z.Sk-WSPj7VXoT(h׼[OOFކyUQNw<|ʭ)yœ<TBȼE)|di}~GQ¨Q>N\?w =5ܟR"OhuJ#ם52cuxd3jJD}T79z/}ӱJ݃R]{ޔ(כO!b4O!?!JM|l\سuSRSw!hN{T՜(HQ:mG i[w?٫ Ʈջ.z:`tDSO]j]DžLM+T(+R-^LF:bY ׂO4u/]Vs?m?g.~v;8!C⾙7fmkF2bsM( E`MHW @ǚ~ЏM;¦$4W68DuM 'zR |I8n~V";/mjog7՝atM&뼴/Wؔ2Q^V.ƒ?h{6QxxGXja:yWvW<(RVC^ӓ"\Gkl=c$0mgHcum;.䜽X^I'#0~:twi3CEy-퓢K`MiqoC/7dJ dpN;k5 $/qDF a§ǽvސqsZՁ*34{ޖ\ܺ˩}Lw_C7Zr7fLq8%r@13 7Q i.$,& s"RjOs~Fgb =^(`+$bh|;*ʴԬ dQ<.U9e 9_֐c}VЭ3o&1k^ꝾMa,Jg =niJ`v>90f+:FQT<6L I`~B I$Hٛ11ںm…c4y7$ t]wVK I}Rn^5q*,aOKØ 1*Ms",g#V^^ƦsQ cg)+է;~Dr΋xhϯ&OzBYf!ܖtŒg}"7g+g__,#X{45%6[J%NQ@>R=؂^.eը՜b@u0Ť;paz:Qꢼ'NZ&&f!KA=2Ҧi ^"h1(SFT)ǟU1IY}ٚrW%;bp;@*#^rpz7 &i 0JY{PFeŻ:Ν7mЖ -Zlp6Wȯ:կsf4 ^3c4N89G8*%M㢳\UB B]ti/LY+\8y eka*Q*^v%e:m~]t뽺eȮzapG,*DQ94̷ERaY݇l4(o mbPvJ@6=xC,S/P=Jx+hz7ҜH[ tCǏ,4xۮWݺO3L/ Җ\{Jr(yY#p"; ElI.&mGcd q+{cnnDq08zk0A_u=f>G0d̫J+m%ޗoW!2Hgx#j6Ud>QZlNN: @{TE,8kXr<43FU&MM#Mris-?OA 6 Ҭ,ܲA2Y'G] sxl֪:)Ib_b(_[]x@hg ~R p`T+{d>"b`,'~bd2jZG\7!+4PO-V:}:ďo [4kѨ2RY>[_ظwj4O s]Qg~4 6=SO_('Sbgč}"t*YqҞ$50+tNի#ڧr͔,'o)>aPYwєo#I =lǀ]:ݤ_)K;4V±[PqwLT2KNA?r\!S[cqe,x,z E8kT v I{8sZmϰJqbC0/[I[m닿޵R \'E,sgDοAEcVZz55W _/^~>Y*@ka$HfO9\X韮 ]6* yޙ޵qHN>=08,IJa?uzi[ssGxpJ+޹0b u#R c?,qk.|9yUO}#c-43"-ҟ(UL|[ƅ j۵C zʘz7 +i ;# AI:oG16~ZO@Az\zբcq*3=ڏ5&睏vmq|JǺ!\Dmµj_dxM.DN~YF?҇X@w t;&E\--/T=yrB䭸,D0t0q62h~fZoZ奛_:@K!tU'oj ARkޕj xG $#~pݠ !-܃\78K['Hjȼbyd$rCx6Cb:J#"G+4IE7WĀ5̠&.}8m>cRo!jcj:tBjP`JuQklg@T$gx蹴e@]e(L1~]"?p1fZ3)A3/b`>XGVqC̓FQ"_7z"!.c2Ԓ>nn1L@@1sʇ ~g9"U#iXpΩ{Ol߿ jԎH!cWskYMaQnFRo_ ۑȵݣ%ܯϺ-_FxcЌ3Ѩ)9Mۍ3iu*nчqE +le|δy;/uc)yoMiz߈Z}w~Hs˶{Ȫs3Eʆv{aܯ-X1 %[7h+t0,Ry錴Ob?Ք69yb?w-Cnxfn1sj"* Sƣqai Rz#Ofh[R!pAYTTKgՆ]2ld˅N,ac 85Lt=ADiwEmDX -D#MpQx8~#LLZ}#'3GV{Yɯ),2;?   &,%.y1ryȑ(U*#Ɖ Jf7,RV:6č/pl "ݣQM2@l{C6T`$kB(||Ly9N3øǁc%ҺT:y#R w.h:%`crqGnc{k dS|4>DDYWC( ~HK^4:]1'5JJj鑁!LGw4 AI1!ï c1c߆^)5>^5μ|MxYYDLZ7!(r+T}pԹB⅕#zSa'rvy Ǝ3gIjظk&X"οjpw \͚D[b?(]R/q eD#kBW'pj_ט rXd&$YhSjƳ3P L*5"д4mE(+\Rz̼+3FK0ɣJqY+E7^Cu7ہiVLTuC~DJV?% )0~{Z]at|>7$\Y K:.\*)kaԄ|\[/-pdyΎΪl|$?eUT^\{ C_DXsJ>jiWWZ~F:.; ]G8Gr]h^*Oжܫ??nwT}Әq)r6aO^$Iᨖ 'UOC5XEb5KZpP^N]%$YrΌEJ ?]axB*os¬I:LLJwf{>UCPeAc5MUKNOǨ{$uVC;lP_ pbXM*( >zzULh ]+潱gɛ_1  Y{n,Yk_J "GW%]R8, aD؂(6z-?N")*/k%rS&ax?pkd1X jWzug˵#^!Dv{gFs?R40GIX2TJdR{j/!БKmcqB|_jZQ.@J[yjfzrtNYcmH}7_$VO z6hy8iOϖQ0+ñG9ِCwDcm<ט@WԱe( uPwb/,5!+q+fm]T=2CJ9<4I<+ Ox|͍uxXe'ǟYz_ y1rrJkp/tVkrCy/HbvʄMcJ0o?  (I%-ЅG&IW$dcO`F 70s> stream x\YSɲ~W8&ڗ>s"0xaa7~z,$F9/ZR@&΋cFꪬ*jg2Cf]LL)֙xu+TeF|{٨3kŔ@B,B2̇p8sd)ڃ|`3\xpX"tGV'aTitDϓ]x.21Ch92Y8 ΓЁ"%r> tv,,I&4g!Gv~ق|3 d[ѓVL/;ִ$yK>7f #XoCm f| ~:LG24ySgtCOX$GQ1>gpi&lbGw14CwDn1f_C^y<}ila-p nw0NB5};O1/wWx/E<b0/D]l)(@`bK%Ć5#hue9&v= nwRHk_B~x9 L<]w#ٲ{HK|k:N+iA1;utD= er ٚk&NL_{ Q=Bif %vǓΤ5-?:7ן~+D[te;I6yl0Gc|Ki"]neiwRIbݓ pAE+y2̀fxXVfpM MlI66m!떱jw}:zhY~gRdKKGJ@7쭝;.'}̴gygo3՛vꖂ>6؃&{$xPם 8oqϋbRv;;ɠ;앃3{k,%O~Nἐv3 n9`o(%U&f洋`w0.iUR>(q{t8)!?l^Nw:)Du⧘^!.:Q,t+ŸY8#-0~3<:E3pP|DŽo ^4τakEH$Ut6N0+;op>ZT ܩMxm@h- oZFؿ_mS'KmGj50rJCm '_iOuUXcD (m\!bGmS5S.mVHMSF`Ŷ(N&76 =iy&7λ~L ڗ[%s63QghiF\iohV)VIKTO0VYV`>Wc}61<<|}zȁ”T8K1` @R!j8dt1@Lp&E>Jbi* c^Xj48eJ;$Hns,m KT<Ku=X} jGTDX?l#50>MJ͘f''QO(1?iE"ܦ"6PKG0G''-$55I__sxeCMHdק9&زʯJz;Qm;QkeoMSCMU+LL14!/kf+ ²]>d_eq59rCpmKswi+6TI#!;2pe^ݫ=Jve*SMan(\h% Nμ2kCͲ5J#13Vm}$kӸ0rUx*̎XL*3v1fs!p~AeAKLkUma,۷Z˿"1|-=sV,*jL`~!IX ˅O*cQ!i9o5C`߀,9u>VyJ#ɐ S52%S:ϳWqJWHw svJjֵ):a?ZF_wM+T$)Jm!ւ ŁHY3>~|5_ {zUDd.2cJ.j"`d6jxSQ5Iw+fڹM4@^k?!#'`=sFӉ |jor|E^W$W­n2t?8:X㒋zߧ,y9Yi>Z;Js&Jn=?sLŸ;*/'Qzi:zrޫDs6lxn:=<ځA\>/ʳs* 11S]?$ iv>}bkWRݏFJL.\DLmX}ӗj83XUa-0ԙeV&~+~c0{p||АJ59Wg!}b5ns|z&ouah񫣣`[YXt| ӻ1N>g?p_W5!cNħf?H/.:,2@ ./OΣ?b9w%dOW*1J X~gCB" LD؟|L+K-+[ ]{ֵZ׈bеGUA/Y"~T☳G+&oRP370'7C\oJ,> XªN?><$Ռk9w^O`kgn9{Mζrk8 3δ rDGvO]uYn&-x;wSpJ\?yiMdfɡ4~dתigr!i//u~np}xaB9z6J;%WFilSR:kuߊ QOԭgM;*@-*k1g"ذԦuNַrWg/ uBFA2s.WOaZ1ʤĮ,wV!`'Ob7d7!n5>_O'gx2syO FtSJk~ɯoW9{L\lr@wwp@9;_pi `g-+Θ|Jިʃ\뮮,*Ugbgܷp;-Q+*|8tjջV`{Cv*t6\ȧ+䱍fj\̪kr-w ^o޶Xk2'_O>wWxRrrt 'I1PǝANiowFjR%\=oh[{OO~M~^ktM[^/,B^k ۰$&C[ׇC +z)b̎܄' lU'~P^>9{M#wEM?ӨRmL:^L_%iR^ɤ*lg5I/Bq\3tu{Tq{pstUOO^~uD: Tժe>cJ^wx sW!f啒ldC v]"YTDP8 0&*DITyKz&&8.p=]C'OxB2,S=`M\\imkyw;]/v;ݥ~WR˻ݩ?5=ϯkfiwwTy][p|}ݙuk[Wnuz{{oaͫW v {o^:/mo2:z*uyoʕ2+g:-eF^Մo~6my:𗮾6w+vgZ/-oon? ^ endstream endobj 629 0 obj << /Author()/Title()/Subject()/Creator(LaTeX with hyperref package)/Producer(pdfTeX-1.40.14)/Keywords() /CreationDate (D:20140121195958-06'00') /ModDate (D:20140121195958-06'00') /Trapped /False /PTEX.Fullbanner (This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) kpathsea version 6.1.1) >> endobj 568 0 obj << /Type /ObjStm /N 76 /First 677 /Length 3088 /Filter /FlateDecode >> stream xڭZmo7_3ZrHEI^b7uCQ(&N IRj9/}yy!g/(e,VŠ QyT*HV2r1gٰV@m:et )*ʸ,$ЈE0Q&EHiđ1W6hAe՘@ >$Q (Hz#OZy Z\ /O.oouzeᶎ+GF=[[_-Vh_hpeuy(Ab()^U'ٓ'wf7F}z19+Gi\#8@~WoZr攵~v; -T;:M0aAaJ}P6+oʖI0Ұc~aV0^ήWN*E/ PxA,:m@\ QiݥAbm΀2`r9p24il{!ۜl/$s\sq`tqP@7h,ce{)H0Vp0 Jn|y @AXAdA r:M@z n@/vk,):AɴvJ`,`,`,`0F㻩J Ƣ, E Pz2Ui7i!9 0lj/ybWu˃aS{+8翮0lM fou]]bvu]au)55[5zoēw5 <]R <]yo'&b 5]qI>GRH8sKpGHIs#FRځo\CC?t/%N}C'۞; 8!p?xBW4VR 7#P [ goXaZy 242#-, ],;/!塼~E |(f~:~oiZ޳n\ sDs`.Th?eM:uH{/[qz endstream endobj 630 0 obj << /Type /XRef /Index [0 631] /Size 631 /W [1 3 1] /Root 628 0 R /Info 629 0 R /ID [<7A2819682141DFC3245C4A9DB2635C69> <7A2819682141DFC3245C4A9DB2635C69>] /Length 1422 /Filter /FlateDecode >> stream x%oUUR 톾}Q~Q ƁBuƄhNāq"Ƙ8pb_8[L~9g}<˄ j3!Sb%%bc[%<l;}PZXmf[ˠml;+a8yuB_5?%݄pm=v-UF}lCmpNBpZ ,t@'tA7 p.A^j?4y(dw;~J~"M¶X!1 )yXeP"_^.Ê^*Om \ >p}p"0nd]Bm;p'ƍ8F>eMV Tl@FFFFF%dl;·UAV֬F;6"4?/IJ4"4r4&cѤѤy/~¨ӨӨӨӨӨӨӨӨӨH@Qp9W09]іlVa ցI55555555555z{@/F/(r d!yʋ\я p*$|b50XJ Ղd_ljQrO}$7|,3Z܏7JҚ~W%_]_]Gǰa8P1uP ߎ 8 Mp - m?gA'tA7 p.AC``F``&``f```$_9$X endstream endobj startxref 335113 %%EOF RcppArmadillo/inst/doc/RcppArmadillo-unitTests.R0000644000176000001440000000335212267623072021443 0ustar ripleyusers### R code from vignette source 'RcppArmadillo-unitTests.Rnw' ################################################### ### code chunk number 1: RcppArmadillo-unitTests.Rnw:12-16 ################################################### require(RcppArmadillo) prettyVersion <- packageDescription("RcppArmadillo")$Version prettyDate <- format(Sys.Date(), "%B %e, %Y") library(RUnit) ################################################### ### code chunk number 2: unitTesting ################################################### pkg <- "RcppArmadillo" if (file.exists("unitTests-results")) unlink("unitTests-results", recursive = TRUE) dir.create("unitTests-results") pathRcppArmadilloTests <<- system.file("unitTests", package = pkg) path <- system.file("unitTests", package=pkg) testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs=path) tests <- runTestSuite(testSuite) err <- getErrors(tests) if (err$nFail > 0) stop(sprintf("unit test problems: %d failures", err$nFail)) if (err$nErr > 0) stop( sprintf("unit test problems: %d errors", err$nErr)) printHTMLProtocol(tests, fileName=sprintf("unitTests-results/%s-unitTests.html", pkg)) printTextProtocol(tests, fileName=sprintf("unitTests-results/%s-unitTests.txt" , pkg)) if (file.exists("/tmp")) { invisible(sapply(c("txt", "html"), function(ext) { fname <- sprintf("unitTests-results/%s-unitTests.%s", pkg, ext) file.copy(fname, "/tmp", overwrite=TRUE) })) } ################################################### ### code chunk number 3: importResults ################################################### results <- "unitTests-results/RcppArmadillo-unitTests.txt" if (file.exists(results)) { writeLines(readLines(results)) } else{ writeLines( "unit test results not available" ) } RcppArmadillo/inst/doc/RcppArmadillo-unitTests.Rnw0000644000176000001440000000402712267623072022010 0ustar ripleyusers\documentclass[10pt]{article} %\VignetteIndexEntry{RcppArmadillo-unitTests} %\VignetteKeywords{R,Armadillo,Rcpp,unit tests} %\VignettePackage{RcppArmadillo} \usepackage{vmargin} \setmargrb{0.75in}{0.75in}{0.75in}{0.75in} \RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave \RequirePackage[T1]{fontenc} <>= require(RcppArmadillo) prettyVersion <- packageDescription("RcppArmadillo")$Version prettyDate <- format(Sys.Date(), "%B %e, %Y") library(RUnit) @ \usepackage[colorlinks]{hyperref} \author{Dirk Eddelbuettel, Romain Fran\c{c}ois and Douglas Bates} \title{\textbf{RcppArmadillo}: Unit testing results} \date{\textbf{RcppArmadillo} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}} \begin{document} \maketitle \section*{Test Execution} <>= pkg <- "RcppArmadillo" if (file.exists("unitTests-results")) unlink("unitTests-results", recursive = TRUE) dir.create("unitTests-results") pathRcppArmadilloTests <<- system.file("unitTests", package = pkg) path <- system.file("unitTests", package=pkg) testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs=path) tests <- runTestSuite(testSuite) err <- getErrors(tests) if (err$nFail > 0) stop(sprintf("unit test problems: %d failures", err$nFail)) if (err$nErr > 0) stop( sprintf("unit test problems: %d errors", err$nErr)) printHTMLProtocol(tests, fileName=sprintf("unitTests-results/%s-unitTests.html", pkg)) printTextProtocol(tests, fileName=sprintf("unitTests-results/%s-unitTests.txt" , pkg)) if (file.exists("/tmp")) { invisible(sapply(c("txt", "html"), function(ext) { fname <- sprintf("unitTests-results/%s-unitTests.%s", pkg, ext) file.copy(fname, "/tmp", overwrite=TRUE) })) } @ \section*{Test Results} \begin{verbatim} <>= results <- "unitTests-results/RcppArmadillo-unitTests.txt" if (file.exists(results)) { writeLines(readLines(results)) } else{ writeLines( "unit test results not available" ) } @ \end{verbatim} \end{document} RcppArmadillo/inst/doc/RcppArmadillo-unitTests.pdf0000644000176000001440000014446312267623072022024 0ustar ripleyusers%PDF-1.5 % 5 0 obj << /Length 525 /Filter /FlateDecode >> stream xWMk0цZHl4B=5=kbͿ,w@ihKy,Ȏ0uŞ^e7BH(XlK 4Q@4)r=۽˪j٭e%,Ωd`:Oa$#/w~ӆE7T}wT1cE5M$i,y]<}Es(>x]7e7LS~q ʠؚ0HϨD|_&Tzjhz1F9Vޚz0p8y.NR!j*ju\4YVPz},6C?w$Mj3 㞹!8Z(-j b.itܱ3mѻFj Xq#B47O) `2qg~ _FnSI#..mJ&{۷ ޙp<7o?nơT-E旬Eqy!fE-贼ny_)>v_4

> stream xWMo0 WX M Ni v@-&!ؿ8^Pzxj؎I 0Mrz>I"9fPP0aZT2xzF%D! ;UM[ ^;k)CH31"ϥv:/Wp6 yYKBo2z'|P3" 2?N 7^⻡)%v|^@zN6dЎ|G{=%{}OD|EYZwmO{G.y}sLWwx;g?V} w'}sq3d3#FbǸH@ endstream endobj 19 0 obj << /Length 872 /Filter /FlateDecode >> stream xY[S@~W6nnoUGkvBLAgwϒ UhL6seNxvɚ9q ,͸\T2J:@S _uCW[%UVQHݨ=0 )&{'@#LqO*~Wx4ܜL(A2SToTJzPc m<,lM F@nѻ䅃#'05"A\4J+II*gE+gЯp>϶Rr-}fqaf !RdKWaE"`0A$K0a57bVnͺ!Zb<0&Sh竇eaړG,҈Ђ*9j *X6?[-r HϺĻ_22QRO.Mſdan\q OpRL7ۏK^IH'>^g4GϯwK#&K[9r)o/U~øNT&I1yZPYtאќ5t5H$HJ8^=yRHmrz=O8-W8.dډD^Rb:hzeZ2[l#Bu g$%y'MY9M<{]N T^:dFNo!fm!oqvg0J¦$R%ɂq,ũ$Sgѫ9f=FYy{JBzC uD ~Wj endstream endobj 24 0 obj << /Length 391 /Filter /FlateDecode >> stream xVJ0}W{h6Q]u iOGmdLpH{snNzV'yG=M;A/&ĄFб84-ju"i4g֜c c1ZIJ`ܘrvN endstream endobj 30 0 obj << /Length1 2425 /Length2 16967 /Length3 0 /Length 18386 /Filter /FlateDecode >> stream xڌP w 6[pwwg5% 9WN꽢 f{Td*Lf@)GW&6fV~+J_9"b q,0u*::l6n~6~VV;++ A Sw "3@H%vG9_Q{ hj g47;]'?  ##t܁(LƌHаqBv6@g*6V#?1?qPR`vte:Xehj7u735tS*?\A6N..6vqd+ ͒@WĿꓰ}b:8z8Y8XXE͉E (+ bee`@Oskhx9dK X}\L݁W矊Ell sWOtho >'@<~lֿ~d0 G;?:bu5]-%P[)& a0sp8x|7rT?##/  ~V.Vs/+/WIKOo, EG~8_SmYhaf u6.R6@ WsMb}`bce?:ʙۂaKoft0wkع "+xع>lzk,`בrsXDX ^`X  ` nΧ)A|#^VήX p-?\Π7bL]mlm@n91p?lbfjnbgbG . 9 pu#.p sG;] _{?55?,Cp-LAWj'K?zԎnXkC]k/'k?,2@pm | vu?`2G  :O9#s[>c?3wssG|0 /tG+.`>;"llߖ, ?nv;=Tvns7?z^z hh.>NЃioRhjO;g>6;xt+2ҋ+I{#Bs֞l6ׁ4;8Ut"0@@Ĥ!d %GƋRu/0P:_-\1mT:OoODmv3wT.4Go=a{Jݥ@s|G0UOYIЏ/tc]dg xve>qJ >d=u'z Rʭ%Faw  E8x%/eݓ)}Q}u0g?lE8}nߢY_}>N:y{=}O1Yl22&Cڴct|?722Giߺ[=t Ud*-Ry{#`xRwjTMfcN~>hZ{-/j}ȇ^Jƴ.•x)yYb\ 5'eHfhQP_`չVIY5/&Y}.qRj)1y/5^{hJatcuFdY+21e `I$%@3 trr_͙_'іxpXMEiyBUY\;?P؈` c@΄i@L;\:zƖ*9<۲^ 2SFWX/e&ʔs[oM EfqwޝR%RcPj}!6|]2LX;\${qyϑ_J-vh֝SenIuJJwzWn$-C__X=[@C1;Kn6vkBd;sD 8M#~EqDȉ*hvi=WRyIc<O\BǃY6$C|sBkT޻R0_7bL>+uWzJ2f0M:/'F mOPmJ_3aqO*Kd5:ef}ߘ .+6ק%^t"g o>kg&IɄ?BP޼YZehQD,Cd,)Nm ꡏBUpӢ>]rX,E 4\{㓬]vK[eH}%hs'5No%*nKfa1OKi3gfmxb M>|שּׁ!|+; gQM )o#)֚?hL5WBд@a9*MgLEgho V—-i!+1𽭠q`DyInnvGW{:*'Vyi %]%bZL#4?@>6y"^đFX r Ա\09a/ ӤuROdwbe&oBwwPG$g~(|7qʥ0~<>F)#LIE95ZHn}& 3N/]ŦZhwgX* D0WRDC'He ǡ0ȗt8,b薟nSYÛ.\[uX!mRrS=i n}ܳ>xY8(WctpS=tl_#nl+U`eNꪍe۠CxD{TnB#PHedkaJ,4c2pVNRX^ߵU/ e7k=Iu&Ȅp1Rq])HpfRB"ջޙ ~MkGSdL߅*pxŋ}B@l4\7bRPPeO0Vڌ?` BaS?VӥPb{;*P},(iR~7P1+]-\ p!͛;2K'z[QDf.4]{Sڢ8_J6H4dq yt[pZ|2u?6|ڏSP*ِcxNhugmM'ꨍ'<3O!8TI5j*%OڶǮok6Wᵁ]Ң*SlW]j]e6vYP) c)6 cdfi2= jV$he+-KV~J(H}Q$(kAe+f gj=jVhmg@K~9 ]tCmfAOhŒ08#&}ȏF]>m'fMs*f YݗLxUh|jRc,& .;e;(: LizVDм>L[Zg޲) 5l.28_+&ѷv{ nxiOJmڻNr?)H2k5a,gbsDj45rO7_l;ʥjPwj>O( MX(8kG&\ԮU}ww''W#I:OI6}+za );"f]O?*˼UUYГ)-řa} +džf

%W |n6.?=|{a)ŇgHl"/>!͒AfY3! VW= 1 jߝ1.*i!e W m5b7O?&sՖ(z)S3HG#F@U*N2-E5iG:9ec{=Q⾲,h8mW%ǧNC[nZ#lm.  `KvD&~qxeQwrQa>09aGű[j?}b\--fel~#Cs=3ϵ>?+OZ7qǽ& .S !ApMAf^GZCT뻬_0nHU[G""6.O.v|Lc~7?ԓE*+^6*7@+C:&.)vg\.צċ]=) B/ #fG#m/I3K"jƅPO3͝qU=[e133NlhǏaf dkT-I]1ڽg<~ XC b$.Vq⸴]P\3_yB6UQvxn[BNHh&g|Kf )||o\ADSӅO(9#8q_7pi5JSLh!Yu\Ѧ8ivYEHE7R};$m633<N5p~hP"hkbYLGpbz }1)SdKyyp~'ZKT҄rH= dm4ݙ?h6VSt+0ݿU_/lDJ -IBb&[t audg}@U :gxo8]TAj1>D˝"U}gx0a WM#< ]~+@ jj9=AQB^O99V0Ce FT,pZhFgs;bGe9񐯡O6)NKJ+ىsGuHQ_ #Fuޜ'"X򃝇QNAiʏP4+$! #w2u8*M]֘5_.ŇyύPU8}C}]UHVdΔR. 8;d\tf;ԟh=\I *9Pxd7 jz/TE mX8ʶwsi0YcqT{̖"ydgsVjZP`ʂ$ wιU~ *%kz,޺ZhZdTYkY./5Zb M8%,| wkr}oi2>Nj*ڝ zII7{ұǭw:~H0xucss\]EޒwzF% CݳS=&h`!>K:[$kr7R}㠛:h=NU, ~BE-9/:5*'2ͬ}R ? Rc5*ZY} }\݂&g%׭ n+ؐ/XPO.A$-ZA?+᭸#;2`縡 gvAv'+)W`Iߴ8jW{"F>O1%Ϭj9HU#&BLLx4)e-:~=S;jej& "rs3bpA":\s-M3q;cpoK# 1zF6Onș'^NwQs?yd/pme/ڸ^O;3`7JK&8/nE@>YCZ.k W~1<ǻ]E.nLn& `)uɓ6~JMpXNWR g=O#c h6|6[u1ODk薇^ͱ mrnTc>RLZ@N633!'h~PufjvP\Hov^ŃohloS(v]}mXښ$ vI <Ãh˲sro3H>(WcɸTI$di^<ń6c=K1冕*uK^!4"ep(BBU!{QK` # DJykǓ>\+rYJ?#$H;Em}SZ:27DGfu 'GQNrhhx,Kv)Հz=fxza[Mfe}\=g) VJ3G2SKY@UTy/X(?'YFPxPb\φ)hJ!j5$ !wJ cF'1&WT':]gK'?O5'Xi 6ɧ}j+&[ǴC10/ n2EUE MkɥbV^LA-%mۜt HBK~>K"p@J$CˌE q5q"&'`ILjMOb#_!1$DsOLRwtAn qwv‹{)vKDN? v "z2]W7I|˯x:'}J=ϼW2u>n/i4 !⧏[eB7A;h@Ǐ冪I_C6H~wbPA' ^ỳ= BiLf7ToCh#OVDNi)NC 9SA^Mk !4K;}oTE}6eϙ_u1Cs iA* ٨ p8?0< -\,0oGTT -L"=/3]GI/=T9[ev牲8! E)ż;Hjh儾lk`)Ʌbkw7q rJmN7'cbɼxS6O(?#Q־ :;J^  )4{Cr[J, ,X=ة-eEpiؒC>f|I|* 0#豬<¦MޘnjZ':5>sSccBäGbȬAYݸI&g(R@ UCCV^m=M{2P aˀMiHBy𞫝!CRH q`dP Tw^gLv8Y/PkX$1!VYHtzB/8: PyGj* @+<鯤Z(%l{)~"@)L85A+W Ҧ,uZԷhGxG/?^>,?|}/ڇMD,NF"3e111 i؎+B"bRvSFz}y8v垲9a<͋n=;bfX-9!X0ٞ,nu_cE'a毤;X1pĄC~3kCw yԄU b! ÅDkf!Ю _C.,͸Ҕdt_ZSyWLe T.eG4]譍\eey2`j'O!kjiȉ(L[eP2):"2ts /ԏbV:PҹЖnl3`1|kA.ݳl.BȪ <voKL&oĬvvyxW6^lں֟Ϣ(e*Ldeb2w[Jsy,ށ>*3ѶZW4NPWh4hݱ CX#1P\(]^OŚtcp6P+%ncŴ;^ymzwte{=S7(ZK'u{kQ'X_|e~M$)T +?K`{y儉er #uN%ڰڏk9YJ,| O6^i\, $#] n{f"М}e ׭xX2(p:"+gPQHV8 N\zx͎u|処Jg-1G,3վ[{bG_v=^[qX@k/Y z=[zGaal5O@8:c6%8<{gE Nle LZƈպdu Ń[ÁCsf#]XټBTؚ64qƫqiWrUu_2z7#$ [(w&\ Ǐ gegn]KAZn;yE8W&0~*r^ٹ:8.\A369[c7 =5,˒zI?eIU+!Y2Tf8Ե6UF9,orA27٬yŊD:HtRڪ1\AA)!pv wbs΀@W,ZCjRawdSո~M EiuT$}<"|$gQ}l*'y3qR fo;5>~7]a`\xXr>&& Uv5J2 H :*YkEj2ے:.m pIfJ,@JHX%]5jW!׫إ!o oe _qrAjZr6[5++b>C#[.HJ+^Z}F3hꁏ2F- ,iQT\Hk.@ޫ' Mbw ;C`G0>⠛в;/`2~/-&'tg/N%OL qla O<}rEڗ G7 db%Ó^K9#jQI@L0a5>D~G'䪨;WD=hMrʜpePyW~hI9pRYqw4㌊F&܋Ym`v1EnUet7p6nC)v޺m 绾n<0Q3:دc!^^4iRT+8؂Vz7w&!L\ie /R[x%Dh؝uN96)";&H^'Gr/>=0n{:pMeD~0) vhN8 .j~[p'S(,lNihSNairgGԽodْ(a~{YTo$@H*j)40Wz7- Sxk!yfz髾d`mE:٩B[ݎ|?J -([R+ +Ba00*e9 !e6U[cQԞΞqMlug=8p ȧUijW +]i ofo}$M:-|$9 u<ϟqI7BN?']xD)i"T/C}-Q0;]*^[\'Sĭxۉ8W멟+YZ;t+NtD-yщBB <`ͺֳ7\? "8No֋~%Wh QN!q{'SwI[|m`q?Ou?_ L>Ng*1>MOEflUy LQ?*߹w[uFAŕC䟘P$nIKgFM*4G¬:Ev|6ݠeLF3JhC~%EN[-v4GzP]2 ;m;+`V4.ne˿5?]%OA(U'2|p ZSߘ'a_)qTB.6Ҿ}ȩȒ8YaeĠ|D%Z#ΰD n)VxYMD xba^^CCbVU;}XEspbeɑط$g3Yī]#胏S(. |A71OM#_y{9\F" G*omxf7F s)gホ*'Ň8;Ac57"9upX#^f 'ˤ1h!*3tVgN JQ􈮵_uFI7v}[f]5$KR<ȣ ;*%"|e!t$eV@31bKj|)QYr;,=%.% bZj";wc cZ p:܂A^=@IrJ)*TYYm,s@Gc>>x3Ke0y-z-?:zVF`8}V|HI-U'')X~T"J,ZB; 7?b/Iq_za=,5}Uj`.<߿NGm$}STSRz dZ=fa#?W߸m+_6$k]zΏg^myh=cƤ{(rSK`|D~t:wl3뀌먟}Ҩb }=A<JvG.@gڹr+s8vvѴsx2`|佀so_OQm'nM Fq0!uH6Y\O')'($mqOfe R I6__"1TYvɼOYhdٚ'pU1F(B^dr%Hgݬx\7Om9n!qn shԪ >exn9ԐaM[3k…94@iB W6-Gqce{;n$w}&V< Tb:GY9\F|(w3嬢R+Xͮᅾm 7-'XaO{-/Gʿ[]3X}Jƫ\sҀ۵rҶF65I-$?Qbҟ-Y;RtJg}4#'^^q=6c[+1WfcK@Obf/yv˹ Nb/e}|n|s^:AGE~Kfߗ"{vЊ'6WKphX)9fKlr 4f YRTf,"/4.yЁZX>MJ|ˇ?6JdG Ք KLGZ]v?m\i܌l`Vl{Rɱ5yMVV endstream endobj 32 0 obj << /Length1 1614 /Length2 11256 /Length3 0 /Length 12080 /Filter /FlateDecode >> stream xڭxeP]ۖ5];5  8www{_~]WcW5e1XkծTIA dكXy*JƶfV 9Q́l7y@38 `A 9x8YYX4tt0=@ 9DU ̭l1E%m):@ ht2(ZL@9 `dofWkΌX"c= n tEp:Y9;NA+{S[ArpGؽ@`gS'+0ཪ?x-vzw@f SZ[;@w_L3+g[c`NVpqzt'to`w6`vښ3"4׶G`k؛,8 t{@wf {[I~/ ߩ'''k_ywhI[[c;I19_ 6=R }"b032h,i4SZ̍mߧ] dke|WAXͧfiejc9ڛ;w&Τ #.*GoԿޕy8SNAf ETb``01w>CſX7;Yt~x7 {S_{Ello]տO{\с@w)Ȕ/:5= \?*P\V_K _)7zal}m=txB3؅cKՙ <%!C_EdPvu[n'ƨA3 O6';r<,[_Ӕ86#ʯwT}C:/ ?~;$M{9]כB?r$+qҭ(D@ek|0"/%(kAp|Q|c̋丌dr Cn֚)2 .@%ZI'覒㼣&f:%6$ 0OV+8tjgn׶طRFP1nu0BHrZ mdwy+)5V݃fT?ui%ׅHGرaƚ| ٣%UbNAW_ghqA Hd1(γ 4AEUOVfb:h3&EKYnuSDbEie٥+gɿPߌ`I%V[Ӣ%FmP@ @ӇoXEK6޲(% 3"Px8sKzM8͐7@^lF '[2t<oiARP(?kg}N˟$-1dYԿILJ&oDDT%q-x;"䡟uŠf{2"ͷ3lvCiYUԊCAe[kX*m'.zuY~x5>4l M<ذ%v#)wbIq(9BKkv脗U 3:a[ ~&3רzC2VDf$aUCStM`>ҡLާ9jNb||[ANEGѣqL\elWUl}l rOğRƶBMPё u¯617b1i/0ZIIקwаuqze`KIjH5L#-(12ZW5z8wEjӭDHj8F6ܳT":7ɧk=(w=KgӃeI֣A3|>a0>b@PՋ̿g-YcoQrxJ5xuݒ5:Wq7<dCZESzIlr^Z铥=m7KđI8Ѧ|GRK3Ke2IjŁ%\>"&K xN3ohfD 5SOLۚ{[uWA .:&*p"vlW9ôyΔS ~gZeSD7Z2,%LY2~NI\.bh;V*D]y3@, 8ɠ#KA9{= ٕ""bL4d/WJϒqT'CFN|bjYΪ7>=\DE_{7۰8fs7j_tJ#<*Ĩ Z>>)X2$`L9qtbΈP-<tN}͢/#3rv˥B 1i멵gQꖀs z!%-$_#NLV/+7:DDt >XȻeZMC'ṍ\g(%mIIyu]&À'W.~_@OLLYSYs1z㺵wG G|u,=֝%TOY3R4il &v4bPW4;$sN #nToL܄jle$^uu?s:<ʲə@SqPgA/ŴNd/K&6*-`ڑ06 ܔ~RbRV_1< 7Ki"cyx1[ҕ$&uWNu>OUmkޞc~v`d768:Ƞ5#^`2 li xp/R䧄CJ986SI`v?1*N8u7<~T:ñ)9mcM@&0];4ǟGRw]5R5oޔ2U&r#R)4X jLG1 @ +[%vi)QÝiG?T!sݶ[KV@W62,i"!+ }Xhk|^3Dg.0t#V]e呋P ]LhD)o2O -wLnL f}"i7f } ;m5Ts(2f&Jk/8|[c\m-⻴flW- /1%gMnd6ݭ]LM܀J!_^}kңAaFq4QAs~I3:7PDf&-R)JrQ1 Wܓʍ$D.9^:9]XD=m >*Aɥw/jW)FzjĈ~WNLbl]fީkv}.WkU*4ɦު%*c'I:Mn񕶎 &û$/!%8gj:~hYK^&OseZ^y-84 G< mxQX*D:3\z0zj5vB,%do>y[7bZA~d5b!Qö:7ƾ&3MRlo+XYp 1oCtd׻꛶ tي]c>nl?"U] 1^C_~&|K/pf+aGRc\?ZЭn@W]C-O {yKvZJ/A-b5ZvrWpa[+cLQauuikl'=O?__!,nG?nzO(VYEY5EHUcUԂF þQ؍m=!Nv9@˵@vkpG?>8&I›YtD)#`@ՑmfN6r& [gnP,3)M_,XOd3%w鴬00J\J%#[-c2쒪z&9MJDϥGӕ(c0zB=CVhWۏګ)4TE5:/c8.1Ӆ-sj2O΂0aVz8@d"5zq/ |"Fca4 k }wdԕFY]_.5ּI*42r5ML<ưuaͦpm%9C)g$?%"K%oJE)]my|٘@ހ2E `7&Qn%Q>2w[ζoT9S)ʓK.dqO0XQAhN/1G W;`K 9Ă 呒#{'gpԔgmeD]@Lu*Mu,[_uNK1L_—FF=A? Ka{3pjQ5Z/#Ր0)sQ)(upUwyFc*z5K橻=~B Y{|:3kooZ٫ǟ{j'1*2ZIγP<=WOG = 6aPcʖMX}_ڏkC$ڤWoaiH/uȖm>D +`Exrfl@;$냺R~oTm rIvuh8~TdM,5Ԅ_<Ң>?2Yc.b̒nCmzG9@nkQy~xZDxv,y 꾛'rk4F.;~vIE;$ȹ23W,= cDk@yr܀%ePu ` NT R]%P܇$bt/Z k!*2і@ 31xjfL>m`hI`౎;j.l/in'’Ńʿ4Fa?1u_f3qQ UΥ燆#,q8eY(DS~6k ͈A٬fS珨I}y'Vݕ3bܣu}9)Z=+;jneCD'>?yl ) FNeK_AH,~ W&Ws@nȒu8_=[}֚j#N4Yba<5F%D*a݇|a Lj ,=Gt'"LhhM4kW6*-eݷF)&nj mhҝY# kb|a\'  7$U\"èTX->A fYB1Yͯg=@0RvEu1a)D "7sθIC3qsxY;Qm[6W҂1MmH2c=j[FL{!~T\B ,O2^0#]g:=@Uw=n?_7Ygn/ړrء`R)`T6w)|Ri):Ɛю 2&W>|Ԁk7"dxtZ_8%z݌'0׽㟏Fir5怉ȯ#qŇĈ}:IZ8VeL4Q;=.c;@LnqaO^ynQ }F)S4 mSBA|m4*/$ouҤFes;!}>0XRa(^<վ2m 20Nh뱋ه_jQDE锎R @^\}"PGf/~"vEuJ$JYEyX4XJnztwQo| &gLk)r܀x}$ޜ{T=-Q=v8!G$4FF9@ ;| "N1y?W-8^#z /9H w|WY"&Q*2;S6*Sճc9EYcY> $ Nǟ+ KK.0L'+[n~p4-_{`VeGk$ϞWBj5xq=f b+D 3W{i"bRlRBdRcfyYcCb8խм^N7jH5 3&nY,M6?ԣxE7"NjU_@n^}2H52aձ>dĿLր7=Q^&j-5ȘI -c2ܗPoe/j暈 =.`}ESnuZ5Fh$ w6AA#%*Uc[\ Y2 nfQRf!*sA1HAp>YHM  QƋGO"h:Fz¨њ,*$g:7BJM0 %Ooؿ-FZߍbN\@FQOs7sq O>әC/yIUqSo xc"/a) b\=D5(^,q75Bw&s^ gY[Ro \DȆXrO,z>t7x 7/+Y˛#4 =C F{q4IJL *@,ZU|4hVJ>$ЎC'=;]T M="{M3֨#Mβkafg .c\7'>LE\ mhpˈW^xYxƇ?pF<<Ȋd+ZD5F/Y? b'u/.v,( \ S?f*0{'s\/c Ux1>D~ף_ޠ1U4ڕf8bp&P̧NV! cSz 7]Ax嫚DX0|C3u=v.,/>æ=0]m;#_|zE>ܸvN'֙_XLiJ^%l$0rt@I95!&/ =WDfuu/e0nuH:^:NׂB:/L :XvŌB0&C[([E&)G^6]mR<{\3g(  Sy>5R@_VF"V*U@İ'(VJ,-ݜxca:XZUJB(%E5yԛ"2Z. z05nHn Q۩/JS+]Zb32Gh}P@ rUr'O?SB1E>̔;}}$@f ^s(aTSPo4 ʊ_^!ݗ[uYnRa4\/`VNuVlo7]` ۳ }!:erE%ԬV ءeP{<ث#ˮSfJ>]EʔY9$=47 ! z,qh;Ik{?xY8QUm..:qIϖ}_YPsn.C$Hs?1 3}A:?>Y[UMgvp!?oX O``=Gg?>vtJ;\~B+zln$a*d ywDD^Mi !HoDZp7NQMA<- G<62J;;sՄYyr@[Ry?xm!8D\}f^kG?ܹ +FmdaLv@(o,ҍ9i ώԕa(ok^(j`H[O&>a_ >TDJwG[4E4#Rh2g 灁^Z~iQtFyb]aJ̼k4 Z"8*T^\wIM BIEqM:(NbXPܟ[8ϛL]c<ő+^v}aLH.9<5hMnGHhP`U8'Rrrm ' |31rn*\qh=  ;ݲۀG>_˹ġ9V"ی@~8+rW8GHV3̺+hS7EN";KP4LxMYD2l8{E^ZM $}5F㥥 Zkc3aD".ߌc a\G (?0z6k2.a,FU HƟ<\1G 22L#a˼+E9Mfq5Z!h1h5T̺ 8MH'X8~A2IR3sg"h :ܚc=G)8լ#O-0NOO/nj'&Hv|q=Ca]Vo LCVJݨ |!I5Q-tq-ŝ9HA}5My=rMV}F\:e-gn~OcD[2wE wxڗ{_t=uQ!*jXCQt@ct ^I.3 qsҗU*f<u_|&Ad\IfA 6315s0xx zJ5}(|f-HniT YS endstream endobj 34 0 obj << /Length1 1616 /Length2 15070 /Length3 0 /Length 15893 /Filter /FlateDecode >> stream xڭct]&'`DQ5Jڵy3q]A7hO-\TW;Mv֩oJ#zD;o߲yڎiO9 9t?v:y1/*I>-"{ƒX̀4i9o`&Sڕ~Fn"-zy(GN|})NG8iF':;" z0e[8-拋(,lQP"TωR_Z;T78uFpDw%ץJ냯S7R1hǢDwB}% J7xEpͧs9m ~<ϒ\vzV%!9{bF3B ;.8}:jWAlS0fuˡ4u +覎nAuYp'3N<$ 'ؤc[}gcB\tә2h9t's? ;jTx`|1xdomSR 4Z/ӭ2MvmdgitX`s^!GCEsks$A}q6ɚrNƌUv Og* 5:1kvcQԝ4#d{BZF]b><6YhQu(U"娡sb^L4xȣ@mۀԺ}}U5f[JzQḁNƞ/$@!b.ݛ NHx?"kTyȝ0s(ojK&ɖ7w-Ξ s_c[\ Q;`LX;YZsW"QfCsD )U=ڸf}6#2]!h+7<0bNMcDhT{AW Xҝ64k[ KSb.FYvx@l$߬8j"̓YE8Nk6"Zk!|_U![uDI? v@]U]I l/ݼi}ʸ/d>nugc\(p^ot}A%0뙝jvuNNʲ)|ɠ/3qa2IDI'y݉ 4H[&" ep.\gOXߖ{0=6i`t%ƳadUX=e, u 9 K倲%i&׬8)g[9{6\]fR}!g;&vbg |gϚ$ w| r+j~N;L(0{y0 |-Aq~`ko)H\;gA 5f!AĻk(J:pÀҶIT <:n]%(iM}7G!#7#lzX?UAeЛ泤|Ivv) (_b#$tr$Hnm.v*,s(BN B|qE5FߞI\}<m#7;\3O i+g˿$O5ϺII#A(y9Zq0!Φ~r'*i]*AmF w<]_&ГGU!oCS)f *Z7(@xv*)mb@5<3m+1EӚJLo9 RxFi^*, D(f<*֎]QZ6׍mv˸ZL McG~V/-lJ9G~Zby W\*% (-OIVKWA#2{GҒHX~~Z4^- ]Zqjq#!v~Wl*V?,.DVBXLUw7"HմaB@N:nz tM3 $s:e耩BJw9 8oФye܃πCj~$! 0n^$c4dKk٫|9Bz˟|I:KBʬAu`1i (DYBC7׍ܔ4dzLF1DJ }cBFKI=ԑ@Ky:|8?ZOYO|)j3fJ有!'YPj5wO_4_ 7"hl{s1]m̀9jnb>UgToqP1chKSy*M%xw&Alf'՜Y=YJ"XK>q^@|V&a{t_hPb!Gυ'Οn{P\)Kp6C+ISK%etۣ8|9leW7;jwoÚI ]P4JEJI *`eZj*!!,@5귒rMgϳ]xf;֘/fQꏑPay MH V:luqu SaL;SId +Sı&i9ABPHA<]G׮dHtKUl+:0>:o8й) Ώ[.J5w&T 4}n,n@}˕lܸHt]m[ xDoN{w&_]3iFĢ9[{P]rc%HJwbx` \g3Px G1\O^J)M!X N⅛t;w"rޡޭirZ~[dR!-nRE[eJxxOAMm*+'G*U,%!!QnTɱz PGD݀YN'[f_5naֱۖ;P 9HgLBಽx^m%3o:Ao6E&@.|XSbLl_j~B?fC)(ޟ53T/PnH; =vit"y80]P1Gb!x>&P#W Ue?CvaЍyh|06) դoƧ!<3SL`;;G!E>X<Ǚ5ٽcB3[Aam{^+j=ǏɶM X7U:&o 2 vib SGׯcK^e{@x,>9aF]`M;6`lRS+u>cnS睗wOJeS.qJ#my g-B'/7Z*4L?M+O=gU5p +k,jK N猤)[aʲV!AbK#dBŞ }EMZD[otDP_C!P9 4Y<{ֿ,mU7O\b($͠ ϾՀ,(o:&MM<'#pPwg'rUMgDjG6l{]c:][qV}YLRij8⺤|f`h^#HjPDBb,6ZTD G&E Iiܻj6>A_Ey{q&idKjl(2bZ:sh7!láVHUjj|~6q %_CdpܘgHk¡S!7oz)85|yŴBNQεQ7g;͈>s~o*Zw6[=ߏmjR/)!XS!aK)^sIf_$ X fi?A (p`0I#6&‹b3ne=-^6ǝ;/p9n Hn;kIL3KR~ofM4V&6kߜg4oxւZzTi4u2ě*zdEh3 dƺtO@sD>6[ Q\MOߴB9M5J'-0-&93A);cv~62-k8l؈ج Qtk9oT¬L~0"]k#Qރ*D3K09b%t":s_=tƤfvcXEQg }X]͔ImUfyuQЦ/2yg9NYm#X2DE$ep .ݾ1ӕۣ3!$3K}k:c99yMXz|ģ|8g/}C./1#- flVA2 I͛RAg_xI^qшUY>n!Lw]T*-Ov .jV *$F}0V-Kb5{BʽY'Zlx$"~y^BaWU$I֏]MgooV^Ý[ʍ'b|7lz,0?B^7$&;Kۋ4+81JXdK<cc&UR4մ+d`^ l.:<'ӿ 1WrIΟlz9rz_Yuw4cLz@fWU"h}PEF']4@9x3Tw~KL kC P}ojyLjc[9sh9? P-LAʿ 4pJ-@SbVLtOƽ6v4>ͮd3[!wBvXV>梵 tqyh=/B.{x5 y+v{fyVሔRxNg5IjF!@b^$|70b>tN~\IpK19Ք`}e3SjNJg~1ܱq S{ƆkJPJ]Y5=~x. I)^tZ*qcM]%R>0  Kb(WSay!V]5TA lӗ723.LDqEN*$7BDA bZbR=JeZ ccʙ$C } 6kEo'PmHV Q]nF: aJ멌TwN6oRm)dn5!q؀DxbTI3ӺmpOs̱Q`eY!0D<B\H™y#3#u ߗņS5Lb$'m` s!}hbèSsTZ(P&8P=znK랷֩s[8tcjx>^M'X\nIU(۔UFùB,ǗySϢYe>Qp*mQtSJABq(h]i\l #W$ǻӘnߕkG٥;v|D3(9+k6{b@ qj GТ靘/ٶCD.Zh=yqK[S`@rg<׿yEmalKϰ1ҙ kψQn8:/.Nѐ(+BEBMyrvI`,Iڼ E7İN'Bv]T̢މ 3KM~##@<lg?ݛH:)wJKsP#8ѝ0X1g쭣:z*b&3L-C~,:G$jkٻLwgIac* ^*):AU[=ҕ~"ͼBĶL$bJmޑqj*E-9JBku,')7+kI6FdG^SN-c霛Oif0Q8Ù&4t{n& K.UU{k$/w,Vly 5zwxHA')*qlm97/ YU^/ՆR#]UP$WgIhT^az< DR+\/$U0 r\ʻ,`_+Җ:< S6f0|"/VprR,2kZ. HGJ"'&tIʞQMOHYLz3H[_}9}ASK`月4?1ruȱzy'u#IEͰХydHrʬ:2 oj߁{>R '5hC|RBU/ա}(ݢTh( Τ&HNZPZ.[fj{OK ֍ }[tnr[!@ݠ 'q)DIqsk81͒%U6x }[~z@.N:"1{,4faFkVG>X?裄 G3aRa__<[,^_ wSw|T*X>VhMFok1&70<zWB^ V} lOIDc,t9(4λ Nw(|M:'$'Q&nϐٹm[)M[vtнKnťdU{kJ1*i߾ Z{C5b9\ʺF7ܴL氜/cOV4[0|͸3vgKUąNe] c ڈ ~j)Tmo,įn_pK$:%Jߵ&wU95a࿊DZ${v8e-T*M_zoŁUɲ) 0R |>yfGJ"1- 1fdVVdBu鍜7''(<:wM& c'X' j0;MB "U 8uy9*AtXJ}߇AI|%_ЯD=K PXx`ݽ !%@ K?B0.w #$k:*Gu+FQV[ !qN#cM+odZM(2'M7KL4 mHhĒ2uV?TI]К:iv\z@`:πh&%s9[{_ECf}cσ;X푲ē^ݬO4.7?-`"7Eъay}ȯlS-jbx2}tp]X԰Ewc W4=08}\Zr5 QF‘߶#タp%|GY2q:䴵, ]m}ɎL@GemXX[Ϫ<7ߩH6ypR񆬑+}kD;}M.<ډCkޯ"=)UԕevxXϢn/P$?#S.;\'2QOA{/z9 $ǵԻ#r-َwBes9PJ[0!̅o2rX:`73RW(@87pB~H܈Ɓ'e,f?Ayf!myNš3&/ 08tC>M1Ps l Aϙ+1HG~LqP"ֈ{6  ȯnc?ɲy}RiwAPJvl y)y8(7@>Ȫ0dbNddsx^t"3yB_%Xb+"'| = a,mt3r0I5^Rrve~fo+3$MZo/;Je 178 ?bd++z)~{RPܺв}/~|Y\{9Sj~@USװ8wv+"q2"ԕfk˯'!fP ʚpz҆Ћ|VZb:!pEӈ3=jFzB\G|؟8+sq8{PaUj>65 tsP ]I+)A&Z1L3XBuΧ0"0 X^Q /\G jQɄPޑd#XfSsJM+EԂ]:19TZrAĐ>gXUIT4ltFYDn$u|WPSm7(EӾaeASM!lwޢ -Sa@N1)LeSM5˴-5xLɟnR:JvU7dÒ,X8T.4ysx߮VBC$"tOJRQئ5Z%f- ܺX@_fXRM< U 4ZPûX*]/pQ 5^Xy*5̆Tx8B^U`MH_ LP)_GsEG= Z 0T]>eP8X)Jƴ׳lVb$w_G,I7Q Pnw|r|Uĕ-+֪eB#c8*̧˗gv^-싧vHH']u&=5dwDwtunU[9_ 5AKZѭN&,څH\HKdt+堹>{c =2}Kߒn;,`87>!*V{$[]*skNZ.KTQٍN1SKa› LߩjC3{v"z|-ϤGЁtBG C`܎G,sN* [2pw+/Y~ r|vO }E:͚0a:0̶%)VHyp &v#ᥛ_;qȘ{fU>G`j18|+;\esW!3o5<<6pnӷjV:2lkPRb:LGD[#J,o+qө,pX|]:*bw}>$6xPl\ʛ쫳mE``k~q RF#I{^Y1_S㷥)Wт\XIFC ēzZK )'myE +~ritPeƃ\z@l 6]וͯ Ra;,h_ܬM~v$پAӺinb7P@/p~;G_. 9|,Tm0f0p+˛O^) 3s3Hc \-$ ׫2Sv*spG&Q3ȳOctY;C WJV5$i]""\ 9a!/^F/L 14k9h^\H~ON&jk%sCTkY2EabZDـ:Ӳag" yA{a=:I1/H^_V~2rt)NYCwX)K`>|7B H 夽جͳxeZq|C&lUr?-HK~[z6K~/:43R̾O_]iGA!wuN/GI+pJZk<)7*t.I/=cg"yA)<h2IٖV)Cc8U*ta)][^{{VH#eK |)Rqs=b޴_BQĚB#OZU]қTwYf/ÍBMyRSW.zC9t^Af48|A3%}ytӋHk2˚U+#:Toh9fpB_MXN>4lOXdqR`A~]}"B=~*~afEeݭUғ@MljM dNYPDŸ!! 6 wUh}5*ݮyL`ܲ5GET=GkcVPT<}R˱J?H¨z @NRiI|&w~/D$N kd {Wɥ[ֶm $t~}*R[eVetR2 ;EDI-򽕔GL* / %BF3ԍ@ I;si@C2?BS= Xu7mqg*)A?f;`u}I=~T487n(]Sb/=Bt8ȗG988):wʿ\2_n hbZ92)/&ͺ/\(Ye1Ww4ojjwĹ>ചUUN-[L}.{rCgj5󫮬?C endstream endobj 41 0 obj << /Author()/Title()/Subject()/Creator(LaTeX with hyperref package)/Producer(pdfTeX-1.40.14)/Keywords() /CreationDate (D:20140121200025-06'00') /ModDate (D:20140121200025-06'00') /Trapped /False /PTEX.Fullbanner (This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) kpathsea version 6.1.1) >> endobj 2 0 obj << /Type /ObjStm /N 32 /First 229 /Length 1557 /Filter /FlateDecode >> stream xXYSH~ǰ)ӚCWU*U#!c),lUl%Ʉ߯G-IHִ)RC1eRu_hLMB{0 ͪ:F0I`3p$FI!>p M AW^eLБp/$-o˗X<tf2pYCy`N'4e!x mZrlg,]X/k'!/fvko}]:=?MA1 .V>6eWI)n@щAX-z-~1A+V[n++<)m1l:o9_oO8Oj,i1|~ʄol{H&ag>t^ (~zLғҁa󗍕iA؂tZr QcaT!WE3HAQzg˾c,fbR;pl|yWl ouc-Ǧoϙfej7y~]5kˎbԷ[UhWnz,C6>dw5}n?&pf',l.xOM:m\`QTjOprxn[<GIȽXz` ,Lm*=FtM?(b>a#NѸ^*:tZF4>&2}*Q·3:C:czEKtEOQTiy_&yZ|;$*tl9lw:hHl2rJ <9CF8BE29B5C6A5B443DEFF51A4C6CA3B>] /Length 115 /Filter /FlateDecode >> stream x ἠn(+Xuxnc7V 9|yɛYB_VH=lG)ȕ|bmtS̰{ ՟ȥ[ q?e; z endstream endobj startxref 51142 %%EOF RcppArmadillo/inst/doc/RcppArmadillo-intro.Rnw0000644000176000001440000012041712267623072021143 0ustar ripleyusers \documentclass[preprint,authoryear,times]{elsarticle} %\VignetteIndexEntry{RcppArmadillo-introduction} %\VignetteKeywords{R, C++, Armadillo, linear algebra, kalman filter} %\VignettePackage{RcppArmadillo} \usepackage{url} % break URLs \usepackage{booktabs} % fancier tables \usepackage{color} % color use \usepackage{listings} \definecolor{darkgray}{rgb}{0.975,0.975,0.975} \lstset{ % %basicstyle=\small, % the size of the fonts that are used for the code numbers=left, % where to put the line-numbers numberstyle=\tiny, % the size of the fonts that are used for the line-numbers stepnumber=2, % the step between two line-numbers. If it's 1, each line % will be numbered numbersep=5pt, % how far the line-numbers are from the code backgroundcolor=\color{darkgray}, % choose the background color. Must add \usepackage{color} showspaces=false, % show spaces adding particular underscores showstringspaces=false, % underline spaces within strings showtabs=false, % show tabs within strings adding particular underscores %frame=single, % adds a frame around the code tabsize=2, % sets default tabsize to 2 spaces captionpos=b, % sets the caption-position to bottom breaklines=true, % sets automatic line breaking breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace %title=\lstname, % show the filename of files included with \lstinputlisting; % also try caption instead of title %escapeinside={\%*}{*)}, % if you want to add a comment within your code %morekeywords={*,...} % if you want to add more keywords to the set % basicstyle=\ttfamily\small, commentstyle=\textsl, keywordstyle=\ttfamily\small %keywordstyle=\color{black}\bfseries\tt } \usepackage[colorlinks]{hyperref}% for \href \definecolor{link}{rgb}{0,0,0.3} % next few lines courtesy of RJournal.sty \hypersetup{ colorlinks,% citecolor=link,% filecolor=link,% linkcolor=link,% urlcolor=link } %%% from jss.cls defs \makeatletter \newcommand\code{\bgroup\@makeother\_\@makeother\~\@makeother\$\@codex} \def\@codex#1{{\normalfont\ttfamily\hyphenchar\font=-1 #1}\egroup} \makeatother %\newcommand{\proglang}[1]{\textsf{#1}} \newcommand{\proglang}[1]{#1} % also neutering the proglang macro \newcommand{\R}{\proglang{R}\ } % NB forces a space so not good before % fullstop etc. \newcommand{\Rns}{\proglang{R}} % without the space \newcommand{\Cpp}{\proglang{C++}\ } %\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}\index{#1}} %\newcommand{\pkg}[1]{{\it #1}} \newcommand{\pkg}[1]{{#1}} % null op for now \journal{Computational Statistics and Data Analysis} <>= prettyVersion <- packageDescription("RcppArmadillo")$Version #$ prettyDate <- format(Sys.Date(), "%B %e, %Y") @ \begin{document} \begin{frontmatter} \title{RcppArmadillo: Accelerating R \\with High-Performance C++ Linear Algebra\footnote{ This vignette corresponds to a \href{http://dx.doi.org/10.1016/j.csda.2013.02.005}{paper published} in \href{http://www.journals.elsevier.com/computational-statistics-and-data-analysis/}{Computational Statistics and Data Analysis}. Currently still identical to the paper, this vignette version may over time receive minor updates. For citations, please use \citet{Eddelbuettel+Sanderson:2014:RcppArmadillo} as provided by \code{citation("RcppArmadillo")}. % This version corresponds to \pkg{RcppArmadillo} version \Sexpr{prettyVersion} and was typeset on \Sexpr{prettyDate}. } } \author[de]{Dirk Eddelbuettel}%\corref{cor}} %\ead[de]{edd@debian.org} % \ead[de,url]{http://dirk.eddelbuettel.com} %\cortext[cor]{Corresponding author. Email: \url{edd@debian.org}.}% Postal address: 711 Monroe Avenue, %River Forest, IL 60305, USA. } %he \pkg{RcppArmadillo} package is available %with the electronic version of this article, as well as via every CRAN mirror.} \address[de]{Debian Project, \url{http://www.debian.org}} \author[cs1,cs2]{Conrad Sanderson} %\ead[cs1]{nowhere} % CS i'd prefer to leave out my email address %\ead[cs1,url]{http://www.nicta.com.au/people/sandersonc} %\ead[cs2,url]{http://itee.uq.edu.au/~conrad/} \address[cs1]{NICTA, PO Box 6020, St Lucia, QLD 4067, Australia} \address[cs2]{Queensland University of Technology (QUT), Brisbane, QLD 4000, Australia} \begin{abstract} \noindent The \proglang{R} statistical environment and language has demonstrated particular strengths for interactive development of statistical algorithms, as well as data modelling and visualisation. Its current implementation has an interpreter at its core which may result in a performance penalty in comparison to directly executing user algorithms in the native machine code of the host CPU. In contrast, the \proglang{C++} language has no built-in visualisation capabilities, handling of linear algebra or even basic statistical algorithms; however, user programs are converted to high-performance machine code, ahead of execution. % A new method avoids possible speed penalties in \proglang{R} by using the \pkg{Rcpp} extension package in conjunction with the \pkg{Armadillo} \Cpp matrix library. In addition to the inherent performance advantages of compiled code, \pkg{Armadillo} provides an easy-to-use template-based meta-programming framework, allowing the automatic pooling of several linear algebra operations into one, which in turn can lead to further speedups. With the aid of \pkg{Rcpp} and \pkg{Armadillo}, conversion of linear algebra centered algorithms from \proglang{R} to \proglang{C++} becomes straightforward. The algorithms retains the overall structure as well as readability, all while maintaining a bidirectional link with the host R environment. Empirical timing comparisons of \proglang{R} and \proglang{C++} implementations of a Kalman filtering algorithm indicate a speedup of several orders of magnitude. \end{abstract} \begin{keyword} Software \sep R \sep C++ \sep linear algebra \end{keyword} \end{frontmatter} \section{Overview} Linear algebra is a cornerstone of statistical computing and statistical software systems. Various matrix decompositions, linear program solvers, and eigenvalue / eigenvector computations are key to many estimation and analysis routines. As generally useful procedures, these are often abstracted and regrouped in specific libraries for linear algebra which statistical programmers have provided for various programming languages and environments. One such environment and statistical programming language is R \citep{R:Main}. It has become a tool of choice for data analysis and applied statistics \citep{Morandat_2012}. While R has particular strengths at fast prototyping and easy visualisation of data, its implementation has an interpreter at its core. In comparison to running user algorithms in the native machine code of the host CPU, the use of an interpreter often results in a performance penalty for non-trivial algorithms that perform elaborate data manipulation \citep{Morandat_2012}. With user algorithms becoming more complex and increasing in functionality, as well as with data sets which continue to increase in size, the issue of execution speed becomes more important. The \Cpp language offers a complementary set of attributes: while it has no built-in visualisation capabilities nor handling of linear algebra or statistical methods, user programs are converted to high-performance machine code ahead of execution. It is also inherently flexible. One key feature is \textit{operator overloading} which allows the programmer to define custom behaviour for mathematical operators such as $+$, $-$, $*$ \citep{Meyers:2005:EffectiveC++}. \Cpp also provides language constructs known as {\it templates}, originally intended to easily allow the reuse of algorithms for various object types, and later extended to a programming construct in its own right called \textit{template meta-programming} \citep{Vandevoorde_2002,Abrahams_2004} Operator overloading allows mathematical operations to be extended to user-defined objects, such as matrices. This in turn allows linear algebra expressions to be written in a more natural manner (eg.~\mbox{$X = 0.1*A + 0.2*B$}), rather than the far less readable traditional function call syntax, eg.~\mbox{$X = \mbox{\it add}(\mbox{\it multiply}(0.1,A), \mbox{\it multiply}(0.2,B))$}. Template meta-programming is the process of inducing the \Cpp compiler to execute, at compile time, Turing-complete programs written in a somewhat opaque subset of the \Cpp language~\citep{Vandevoorde_2002,Abrahams_2004}. These meta-programs in effect generate further \Cpp code (often specialised for particular object types), which is finally converted into machine code. An early and influential example of exploiting both meta-programming and overloading of mathematical operators was provided by the Blitz++ library \citep{Veldhuizen:1998:Blitz}, targeted for efficient processing of arrays. Blitz++ employed elaborate meta-programming to avoid the generation of temporary array objects during the evaluation of mathematical expressions. However, the library's capabilities and usage were held back at the time by the limited availability of compilers correctly implementing all the necessary features and nuances of the \Cpp language. We present a new method of avoiding the speed penalty in R by using the Rcpp extension package \citep{Eddelbuettel+Francois:2011:Rcpp, CRAN:Rcpp,Eddelbuettel:2013:Rcpp} in conjunction with the \pkg{Armadillo} \Cpp linear algebra library \citep{Sanderson:2010:Armadillo}. Similar to Blitz++, \pkg{Armadillo} uses operator overloading and various template meta-programming techniques to attain efficiency. However, it has been written to target modern \Cpp compilers as well as providing a much larger set of linear algebra operations than Blitz++. R programs augmented to use \pkg{Armadillo} retain the overall structure as well as readability, all while retaining a bidirectional link with the host R environment. Section~\ref{sec:arma} provides an overview of \pkg{Armadillo}, followed by its integration with the Rcpp extension package. Section~\ref{sec:kalman} shows an example of an R program and its conversion to \Cpp via Rcpp and \pkg{Armadillo}. Section~\ref{sec:speed} discusses an empirical timing comparison between the R and \Cpp versions before Section~\ref{sec:conclusion} concludes. \section{Armadillo} \label{sec:arma} The \pkg{Armadillo} \Cpp library provides vector, matrix and cube types (supporting integer, floating point and complex numbers) as well as a subset of trigonometric and statistics functions~\citep{Sanderson:2010:Armadillo}. In addition to elementary operations such as addition and matrix multiplication, various matrix factorisations and submatrix manipulation operations are provided. The corresponding application programming interface (syntax) enables the programmer to write code which is both concise and easy-to-read to those familiar with scripting languages such as \proglang{Matlab} and \proglang{R}. Table~\ref{tab:arma} lists a few common \pkg{Armadillo} functions. Matrix multiplication and factorisations are accomplished through integration with the underlying operations stemming from standard numerical libraries such as BLAS and LAPACK~\citep{Demmel_1997}. Similar to how environments such as R are implemented, these underlying libraries can be replaced in a transparent manner with variants that are optimised to the specific hardware platform and/or multi-threaded to automatically take advantage of the now-common multi-core platforms~\citep{Kurzak_2010}. \begin{table}[!b] \centering \footnotesize \begin{tabular}{ll} \toprule \textbf{Armadillo function} \phantom{XXXXXXX} & \textbf{Description} \\ \midrule \code{X(1,2) = 3} & Assign value 3 to element at location (1,2) of matrix $X$ \\ % DE shortened to fit on \textwidth \code{X = A + B} & Add matrices $A$ and $B$ \\ \code{X( span(1,2), span(3,4) )} & Provide read/write access to submatrix of $X$ \\ \code{zeros(rows [, cols [, slices]))} & Generate vector (or matrix or cube) of zeros\\ \code{ones(rows [, cols [, slices]))} & Generate vector (or matrix or cube) of ones\\ \code{eye(rows, cols)} & Matrix diagonal set to 1, off-diagonal elements set to 0 \\ %\code{linspace(start, end, N=100)} & $N$ element vector with elements from start to end \\ \code{repmat(X, row_copies, col_copies)} & Replicate matrix $X$ in block-like manner \\ \code{det(X)} & Returns the determinant of matrix $X$\\ %\code{dot(A, B)} & Dot-product of confirming vectors $A$ and $B$ \\ \code{norm(X, p)} & Compute the $p$-norm of matrix or vector $X$\\ \code{rank(X)} & Compute the rank of matrix $X$ \\ %\code{trace(X)} & Compute the trace of matrix $X$ \\ %\code{diagvec(X, k=0)} & Extracts the $k$-th diagnonal from matrix $X$\\ \code{min(X, dim=0)};~ \code{max(X, dim=0)} & Extremum value of each column~of $X$~(row if \code{dim=1}) \\ \code{trans(X)} ~or~ \code{X.t()} & Return transpose of $X$ \\ \code{R = chol(X)} & Cholesky decomposition of $X$ such that $R^{T} R = X$ \\ \code{inv(X)} ~or~ \code{X.i()} & Returns the inverse of square matrix $X$ \\ \code{pinv(X)} & Returns the pseudo-inverse of matrix $X$ \\ \code{lu(L, U, P, X)} & LU decomp.~with partial pivoting; also \code{lu(L, U, X)} \\ %\code{lu(L, U, P, X)} & LU decomposition with partial pivoting \\ \code{qr(Q, R, X)} & QR decomp.~into orthogonal $Q$ and right-triangular $R$\\ \code{X = solve(A, B)} & Solve system $AX = B$ for $X$ \\ \code{s = svd(X); svd(U, s, V, X)} & Singular-value decomposition of $X$ \\ \bottomrule \end{tabular} \caption{Selected \pkg{Armadillo} functions with brief descriptions; see \texttt{http://arma.sf.net/docs.html} for more complete documentation. Several optional additional arguments have been omitted here for brevity.\label{tab:arma}} \end{table} \pkg{Armadillo} uses a delayed evaluation approach to combine several operations into one and reduce (or eliminate) the need for temporary objects. In contrast to brute-force evaluations, delayed evaluation can provide considerable performance improvements as well as reduced memory usage. The delayed evaluation machinery is accomplished through template meta-programming~\citep{Vandevoorde_2002,Abrahams_2004}, where the \Cpp compiler is induced to reason about mathematical expressions at {\it compile time}. Where possible, the \Cpp compiler can generate machine code that is tailored for each expression. As an example of the possible efficiency gains, let us consider the expression \mbox{$X = A - B + C$}, where $A$, $B$ and $C$ are matrices. A brute-force implementation would evaluate $A-B$ first and store the result in a temporary matrix $T$. The next operation would be \mbox{$T + C$}, with the result finally stored in $X$. The creation of the temporary matrix, and using two separate loops for the subtraction and addition of matrix elements is suboptimal from an efficiency point of view. Through the overloading of mathematical operators, \pkg{Armadillo} avoids the generation of the temporary matrix by first converting the expression into a set of lightweight \code{Glue} objects, which only store references to the matrices and \pkg{Armadillo}'s representations of mathematical expressions (eg.~other \code{Glue} objects). To indicate that an operation comprised of subtraction and addition is required, the exact type of the \code{Glue} objects is automatically inferred from the given expression through template meta-programming. More specifically, given the expression \mbox{$X = A - B + C$}, \pkg{Armadillo} automatically induces the compiler to generate an instance of the lightweight \code{Glue} storage object with the following \Cpp {\it type}: \centerline{~} \centerline{\code{Glue< Glue, Mat, glue\_plus>}} \centerline{~} \noindent where \code{Glue<...>} indicates that \code{Glue} is a C++ template class, with the items between `\code{<}' and `\code{>}' specifying template parameters; the outer \code{Glue<..., Mat, glue\_plus>} is the \code{Glue} object indicating an addition operation, storing a reference to a matrix as well as a reference to another \code{Glue} object; the inner \code{Glue} stores references to two matrices and indicates a subtraction operation. In both the inner and outer \code{Glue}, the type \code{Mat} specifies that a reference to a matrix object is to be held. The expression evaluator in \pkg{Armadillo} is then automatically invoked through the ``\code{=}'' operation, which interprets (at compile time) the template parameters of the compound \code{Glue} object and generates \Cpp code equivalent to: \centerline{~} \centerline{\code{for(int i=0; i library(inline) R> R> g <- cxxfunction(signature(vs="numeric"), + plugin="RcppArmadillo", body=' + arma::vec v = Rcpp::as(vs); + arma::mat op = v * v.t(); + double ip = arma::as_scalar(v.t() * v); + return Rcpp::List::create(Rcpp::Named("outer")=op, + Rcpp::Named("inner")=ip); +') R> g(7:11) $outer [,1] [,2] [,3] [,4] [,5] [1,] 49 56 63 70 77 [2,] 56 64 72 80 88 [3,] 63 72 81 90 99 [4,] 70 80 90 100 110 [5,] 77 88 99 110 121 $inner [1] 415 \end{lstlisting} Consider the simple example in Listing~\ref{code:RcppArmaEx}. Given a vector, the \code{g()} function returns both the outer and inner products. We load the inline package \citep{CRAN:inline}, which provides \code{cxxfunction()} that we use to compile, link and load the \Cpp code which is passed as the \code{body} argument. We declare the function signature to contain a single argument named `\code{vs}'. On line five, this argument is used to instantiate an \pkg{Armadillo} column vector object named `\code{v}' (using the templated conversion function \code{as()} from Rcpp). In lines six and seven, the outer and inner product of the column vector are calculated by appropriately multiplying the vector with its transpose. This shows how the \code{*} operator for multiplication has been overloaded to provide the appropriate operation for the types implemented by \pkg{Armadillo}. The inner product creates a scalar variable, and in contrast to \R where each object is a vector type (even if of length one), we have to explicitly convert using \code{as_scalar()} to assign the value to a variable of type \code{double}. Finally, the last line creates an \R named list type containing both results. As a result of calling \code{cxxfunction()}, a new function is created. It contains a reference to the native code, compiled on the fly based on the \Cpp code provided to \code{cxxfunction()} and makes it available directly from \R under a user-assigned function name, here \code{g()}. The listing also shows how the \code{Rcpp} and \code{arma} namespaces are used to disambiguate symbols from the two libraries; the \code{::} operator is already familiar to R programmers who use the NAMESPACE directive in \R in a similar fashion. The listing also demonstrates how the new function \code{g()} can be called with a suitable argument. Here we create a vector of five elements, containing values ranging from 7 to 11. The function's output, here the list containing both outer and inner product, is then displayed as it is not assigned to a variable. This simple example illustrates how \R objects can be transferred directly into corresponding \pkg{Armadillo} objects using the interface code provided by \pkg{Rcpp}. It also shows how deployment of \pkg{RcppArmadillo} is straightforward, even for interactive work where functions can be compiled on the fly. Similarly, usage in packages is also uncomplicated and follows the documentation provided with \pkg{Rcpp}~\citep{CRAN:Rcpp,Eddelbuettel:2013:Rcpp}. \section{Kalman Filtering Example} \label{sec:kalman} The Kalman filter is ubiquitous in many engineering disciplines as well as in statistics and econometrics~\citep{Tusell:2010:Kalman}. A recent example of an application is volatility extraction in a diffusion option pricing model~\citep{Li_CSDA_2013}. Even in its simplest linear form, the Kalman filter can provide simple estimates by recursively applying linear updates which are robust to noise and can cope with missing data. Moreover, the estimation process is lightweight and fast, and consumes only minimal amounts of memory as few state variables are required. % We discuss a standard example below. The (two-dimensional) position of an object is estimated based on past values. A $6 \times 1$ state vector includes $X$ and $Y$ coordinates determining the position, two variables for speed (or velocity) $V_X$ and $V_Y$ relative to the two coordinates, as well as two acceleration variables $A_X$ and $A_Y$. We have the positions being updated as a function of the velocity \begin{displaymath} X = X_0 + V_X dt \mbox{\phantom{XX} and \phantom{XX}} Y = Y_0 + V_Y dt, \end{displaymath} \noindent and the velocity being updated as a function of the (unobserved) acceleration: \begin{displaymath} V_x = V_{X,0} + A_X dt \mbox{\phantom{XX} and \phantom{XX}} V_y = V_{Y,0} + A_Y dt. \end{displaymath} % \begin{eqnarray*} % X & = & X_0 + V_x dt \\ % Y & = & Y_0 + V_y dt \\ % V_x & = & V_{x,0} + A_x dt \\ % V_y & = & V_{y,0} + A_y dt \\ % \end{eqnarray*} With covariance matrices $Q$ and $R$ for (Gaussian) error terms, the standard Kalman filter estimation involves a linear prediction step resulting in a new predicted state vector, and a new covariance estimate. This leads to a residuals vector and a covariance matrix for residuals which are used to determine the (optimal) Kalman gain, which is then used to update the state estimate and covariance matrix. All of these steps involve only matrix multiplication and inversions, making the algorithm very suitable for an implementation in any language which can use matrix expressions. An example for \proglang{Matlab} is provided on the Mathworks website\footnote{See \url{http://www.mathworks.com/products/matlab-coder/demos.html?file=/products/demos/shipping/coder/coderdemo_kalman_filter.html}.} and shown in Listing~\ref{code:matlabkalman}. \lstset{ language=matlab, basicstyle=\ttfamily\footnotesize, caption={Basic Kalman filter in \proglang{Matlab}.}, label={code:matlabkalman} } \begin{lstlisting}[frame=tb] % Copyright 2010 The MathWorks, Inc. function y = kalmanfilter(z) dt=1; % Initialize state transition matrix A=[ 1 0 dt 0 0 0; 0 1 0 dt 0 0;... % [x ], [y ] 0 0 1 0 dt 0; 0 0 0 1 0 dt;... % [Vx], [Vy] 0 0 0 0 1 0 ; 0 0 0 0 0 1 ]; % [Ax], [Ay] H = [ 1 0 0 0 0 0; 0 1 0 0 0 0 ]; % Init. measuremnt mat Q = eye(6); R = 1000 * eye(2); persistent x_est p_est % Init. state cond. if isempty(x_est) x_est = zeros(6, 1); % x_est=[x,y,Vx,Vy,Ax,Ay]' p_est = zeros(6, 6); end x_prd = A * x_est; % Predicted state + covar. p_prd = A * p_est * A' + Q; S = H * p_prd' * H' + R; % Estimation B = H * p_prd'; klm_gain = (S \ B)'; % Estimated state and covariance x_est = x_prd + klm_gain * (z - H * x_prd); p_est = p_prd - klm_gain * H * p_prd; y = H * x_est; % Comp. estim. measurements end % of the function \end{lstlisting} % function x = kalmanExample % load pos.txt; % renamed here % x = kalmanM(pos); \lstset{ language=R, basicstyle=\ttfamily\small, caption={Basic Kalman filter in \Rns ~ (referred to as {\it FirstKalmanR}).}, label={code:FirstKalmanR} } \begin{lstlisting}[frame=tb] FirstKalmanR <- function(pos) { kalmanfilter <- function(z) { dt <- 1 A <- matrix(c( 1, 0, dt, 0, 0, 0, 0, 1, 0, dt, 0, 0, # x, y 0, 0, 1, 0, dt, 0, 0, 0, 0, 1, 0, dt, # Vx, Vy 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1), # Ax, Ay 6, 6, byrow=TRUE) H <- matrix( c(1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), 2, 6, byrow=TRUE) Q <- diag(6) R <- 1000 * diag(2) xprd <- A %*% xest # predicted state and covriance pprd <- A %*% pest %*% t(A) + Q S <- H %*% t(pprd) %*% t(H) + R # estimation B <- H %*% t(pprd) kalmangain <- t(solve(S, B)) ## estimated state and covariance, assign to vars in parent env xest <<- xprd + kalmangain %*% (z - H %*% xprd) pest <<- pprd - kalmangain %*% H %*% pprd ## compute the estimated measurements y <- H %*% xest } xest <- matrix(0, 6, 1) pest <- matrix(0, 6, 6) N <- nrow(pos) y <- matrix(NA, N, 2) for (i in 1:N) { y[i,] <- kalmanfilter(t(pos[i,,drop=FALSE])) } invisible(y) } \end{lstlisting} A straightforward \R implementation can be written as a close transcription of the \proglang{Matlab} version; we refer to this version as \code{FirstKalmanR}. It is shown in Listing~\ref{code:FirstKalmanR}. A slightly improved version (where several invariant statements are moved out of the repeatedly-called function) is provided in Listing~\ref{code:Rkalman} on page~\pageref{code:Rkalman} showing the function \code{KalmanR}. The estimates of the state vector and its covariance matrix are updated iteratively. The \proglang{Matlab} implementation uses two variables declared `persistent' for this. In \Rns, which does not have such an attribute for variables, we store them in the enclosing environment of the outer function \code{KalmanR}, which contains an inner function \code{kalmanfilter} that is called for each observation. \pkg{Armadillo} provides efficient vector and matrix classes to implement the Kalman filter. In Listing~\ref{code:CppKalmanClass} on page~\pageref{code:CppKalmanClass}, we show a simple \Cpp class containing a basic constructor as well as one additional member function. The constructor can be used to initialise all variables as we are guaranteed that the code in the class constructor will be executed exactly once when this class is instantiated. A class also makes it easy to add `persistent' local variables, which is a feature we need here. Given such a class, the estimation can be accessed from \R via a short and simple routine such as the one shown in Listing~\ref{code:InlineKalman}. \lstset{ language=R, basicstyle=\ttfamily\small, caption={An improved Kalman filter implemented in \Rns ~ (referred to as {\it KalmanR}).}, label={code:Rkalman} } \begin{lstlisting}[frame=tb] KalmanR <- function(pos) { kalmanfilter <- function(z) { ## predicted state and covariance xprd <- A %*% xest pprd <- A %*% pest %*% t(A) + Q ## estimation S <- H %*% t(pprd) %*% t(H) + R B <- H %*% t(pprd) kalmangain <- t(solve(S, B)) ## estimated state and covariance ## assigned to vars in parent env xest <<- xprd + kalmangain %*% (z - H %*% xprd) pest <<- pprd - kalmangain %*% H %*% pprd ## compute the estimated measurements y <- H %*% xest } dt <- 1 A <- matrix( c( 1, 0, dt, 0, 0, 0, # x 0, 1, 0, dt, 0, 0, # y 0, 0, 1, 0, dt, 0, # Vx 0, 0, 0, 1, 0, dt, # Vy 0, 0, 0, 0, 1, 0, # Ax 0, 0, 0, 0, 0, 1), # Ay 6, 6, byrow=TRUE) H <- matrix( c(1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), 2, 6, byrow=TRUE) Q <- diag(6) R <- 1000 * diag(2) N <- nrow(pos) Y <- matrix(NA, N, 2) xest <- matrix(0, 6, 1) pest <- matrix(0, 6, 6) for (i in 1:N) { Y[i,] <- kalmanfilter(t(pos[i,,drop=FALSE])) } invisible(Y) } \end{lstlisting} \lstset{ language=C++, basicstyle=\ttfamily\small, caption={A Kalman filter class in \proglang{C++}, using \pkg{Armadillo} classes.}, label={code:CppKalmanClass} } \begin{lstlisting}[frame=tb] using namespace arma; class Kalman { private: mat A, H, Q, R, xest, pest; double dt; public: // constructor, sets up data structures Kalman() : dt(1.0) { A.eye(6,6); A(0,2) = A(1,3) = A(2,4) = A(3,5) = dt; H.zeros(2,6); H(0,0) = H(1,1) = 1.0; Q.eye(6,6); R = 1000 * eye(2,2); xest.zeros(6,1); pest.zeros(6,6); } // sole member function: estimate model mat estimate(const mat & Z) { unsigned int n = Z.n_rows, k = Z.n_cols; mat Y = zeros(n, k); mat xprd, pprd, S, B, kalmangain; colvec z, y; for (unsigned int i = 0; i kalmanSrc <- ' + mat Z = as(ZS); // passed from R + Kalman K; + mat Y = K.estimate(Z); + return wrap(Y);' R> KalmanCpp <- cxxfunction(signature(ZS="numeric"), + body=kalmanSrc, include=kalmanClass, + plugin="RcppArmadillo") \end{lstlisting} The content of Listing~\ref{code:CppKalmanClass} is assigned to a variable \code{kalmanClass} which (on line seven) is passed to the \code{include=} argument. This provides the required class declaration and definition. The four lines of code in lines two to five, assigned to \code{kalmanSrc}, provide the function body required by \code{cxxfunction()}. From both these elements and the function signature argument, \code{cxxfunction()} creates a very simple yet efficient \Cpp implementation of the Kalman filter which we can access from \Rns. Given a vector of observations $Z$, it estimates a vector of position estimates $Y$. \begin{figure}[H]%[!tb] \centerline{\includegraphics[width=0.75\columnwidth]{kalmanExample.pdf}} % for eps: \centerline{\includegraphics[width=0.85\columnwidth]{kalmanExample}} \caption{An example of object trajectory and the corresponding Kalman filter estimate.\label{fig:kalmanexample} } \end{figure} This is illustrated in Figure~\ref{fig:kalmanexample} which displays the original object trajectory (using light-coloured square symbols) as well as the position estimates provided by the Kalman filter (using dark-coloured circles). This uses the same dataset provided by the Mathworks for their example; the data is believed to be simulated. We note that this example is meant to be illustrative and does not attempt to provide a reference implementation of a Kalman filter. \proglang{R} contains several packages providing various implementations, as discussed in the survey provided by \cite{Tusell:2010:Kalman}. \section{Empirical Speed Comparison} \label{sec:speed} \lstset{ language=R, basicstyle=\ttfamily\small, caption={R code for timing comparison of Kalman filter implementations.}, label={code:BenchmarkKalman} } \begin{lstlisting}[frame=tb] R> require(rbenchmark) R> require(compiler) R> R> FirstKalmanRC <- cmpfun(FirstKalmanR) R> KalmanRC <- cmpfun(KalmanR) R> R> ## Read data, ensure identical results R> pos <- as.matrix(read.table("pos.txt", header=FALSE, + col.names=c("x","y"))) R> stopifnot(all.equal(KalmanR(pos), KalmanRC(pos)), + all.equal(KalmanR(pos), KalmanCpp(pos)), + all.equal(FirstKalmanR(pos), FirstKalmanRC(pos)), + all.equal(KalmanR(pos), FirstKalmanR(pos))) R> R> res <- benchmark(KalmanR(pos), KalmanRC(pos), + FirstKalmanR(pos), FirstKalmanRC(pos), + KalmanCpp(pos), + columns = c("test", "replications", + "elapsed", "relative"), + order="relative", + replications=100) \end{lstlisting} Listing~\ref{code:BenchmarkKalman} contains the code for creating a simple benchmarking exercise. It compares several functions for implementing the Kalman filter, all executed within the \R environment. Specifically, we examine the initial \R version \code{FirstKalmanR} shown in Listing~\ref{code:FirstKalmanR}, a refactored version \code{KalmanR} shown in Listing~\ref{code:Rkalman}, an improved version\footnote{The improved version replaces explicit transpose and multiplication with the \code{crossprod} function.} due to an anonymous referee (not shown, but included in the package), as well as byte-compiled versions (designated with a trailing `C') created by using the byte-code compiler introduced with \R version 2.13.0 \citep{Tierney:2012:ByteCompiler}. Finally, the \Cpp version shown in Listings~\ref{code:CppKalmanClass} and \ref{code:InlineKalman} is used. Also shown are the \R statements for creating the byte-compiled variants via calls to \code{cmpfun()}. This is followed by a test to ensure that all variants provide the same results. Next, the actual benchmark is executed before the result is displayed. %R> print(res) % test replications elapsed relative %5 KalmanCpp(pos) 100 0.087 1.0000 %2 KalmanRC(pos) 100 5.774 66.3678 %1 KalmanR(pos) 100 6.448 74.1149 %4 FirstKalmanRC(pos) 100 8.153 93.7126 %3 FirstKalmanR(pos) 100 8.901 102.3103 % more recent results: % test replications elapsed relative %6 KalmanCpp3(pos) 100 0.098 1.000000 %5 KalmanCpp(pos) 100 0.104 1.061224 %2 KalmanRC(pos) 100 5.579 56.928571 %1 KalmanR(pos) 100 5.807 59.255102 %4 FirstKalmanRC(pos) 100 8.196 83.632653 %3 FirstKalmanR(pos) 100 8.686 88.632653 \begin{table}[t!] \begin{center} \begin{small} \begin{tabular}{lrr} \toprule {\bf Implementation \phantom{XXX}} & {\bf Time in seconds} & {\bf Relative to best solution} \\ \cmidrule(r){1-3} KalmanCpp & 0.73 & 1.0 \\ KalmanRimpC & 21.10 & 29.0 \\ KalmanRimp & 22.01 & 30.2 \\ KalmanRC & 28.64 & 39.3 \\ KalmanR & 31.30 & 43.0 \\ FirstKalmanRC & 49.40 & 67.9 \\ FirstKalmanR & 64.00 & 88.0 \\ \bottomrule \end{tabular} \end{small} \caption{Performance comparison of various implementations of a Kalman filter. KalmanCpp is the \mbox{\pkg{RcppArmadillo}} based implementation in \Cpp shown in Listings~\ref{code:CppKalmanClass} and \ref{code:InlineKalman}. KalmanRimp is an improved version supplied by an anonymous referee which uses the \code{crossprod} function instead of explicit transpose and multiplication. KalmanR is the \R implementation shown in Listing~\ref{code:Rkalman}; FirstKalmanR is a direct translation of the original Matlab implementation shown in Listing~\ref{code:FirstKalmanR}. In all cases, the trailing `C' denotes a byte-compiled variant of the corresponding R code. Timings are averaged over 500 replications. The comparison was made using \proglang{R} version 2.15.2, \pkg{Rcpp} version 0.10.2 and \pkg{RcppArmadillo} version 0.3.6.1 on Ubuntu 12.10 running in 64-bit mode on a 2.67 GHz Intel i7 processor. \label{tab:benchmark} } \end{center} \end{table} The results are shown in Table~\ref{tab:benchmark}. Optimising and improving the \proglang{R} code has merits: we notice a steady improvement from the slowest \proglang{R} version to the fastest \proglang{R} version. Byte-compiling R code provides an additional performance gain which is more pronounced for the slower variant than the fastest implementation in \proglang{R}. However, the \code{KalmanCpp} function created using \mbox{\pkg{RcppArmadillo}} clearly outperforms all other variants, underscoring the principal point of this paper. These results are consistent with the empirical observations made by \cite{Morandat_2012}, who also discuss several reasons for the slow speed of R compared to the C language, a close relative of C++. \section{Conclusion} \label{sec:conclusion} This paper introduced the \pkg{RcppArmadillo} package for use within the R statistical environment. By using the \pkg{Rcpp} interface package, \pkg{RcppArmadillo} brings the speed of \Cpp along with the highly expressive \pkg{Armadillo} linear algebra library to the \R language. % A small example implementing a Kalman filter illustrated two key aspects. First, orders of magnitude of performance gains can be obtained by deploying \Cpp code along with \Rns. Second, the ease of use and readability of the corresponding C++ code is similar to the \R code from which it was derived. This combination makes \pkg{RcppArmadillo} a compelling tool in the arsenal of applied researchers deploying computational methods in statistical computing and data analysis. As of early-2013, about 30 \proglang{R} packages on CRAN deploy \pkg{RcppArmadillo}\footnote{See \url{http://cran.r-project.org/package=RcppArmadillo} for more details.}, showing both the usefulness of \proglang{Armadillo} and its acceptance by the \proglang{R} community. \section*{Acknowledgements} NICTA is funded by the Australian Government as represented by the Department of Broadband, Communications and the Digital Economy, as well as the Australian Research Council through the ICT Centre of Excellence program. Adam M.~Johansen provided helpful comments on an earlier draft. Comments by two anonymous referees and one editor further improved the paper and are gratefully acknowledged. \bibliographystyle{elsarticle-harv} \bibliography{RcppArmadillo} \end{document} %%% Local Variables: %%% mode: latex %%% TeX-master: t %%% End: RcppArmadillo/inst/doc/RcppArmadillo-intro.R0000644000176000001440000000051212267623072020567 0ustar ripleyusers### R code from vignette source 'RcppArmadillo-intro.Rnw' ################################################### ### code chunk number 1: RcppArmadillo-intro.Rnw:68-70 ################################################### prettyVersion <- packageDescription("RcppArmadillo")$Version #$ prettyDate <- format(Sys.Date(), "%B %e, %Y") RcppArmadillo/inst/unitTests/0000755000176000001440000000000012253723621016015 5ustar ripleyusersRcppArmadillo/inst/unitTests/runit.fastLm.R0000644000176000001440000001133012253723621020524 0ustar ripleyusers#!/usr/bin/r -t # # Copyright (C) 2010 - 2012 Dirk Eddelbuettel, Romain Francois and Douglas Bates # # This file is part of RcppArmadillo. # # RcppArmadillo is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # RcppArmadillo is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with RcppArmadillo. If not, see . .setUp <- RcppArmadillo:::unit_test_setup( packages = c("RcppArmadillo", "datasets" ) ) test.fastLm <- function() { data(trees, package="datasets") flm <- .Call( "RcppArmadillo_fastLm", cbind(1, log(trees$Girth)), log(trees$Volume), PACKAGE = "RcppArmadillo" ) fit <- lm(log(Volume) ~ log(Girth), data=trees) checkEquals(as.numeric(flm$coefficients), as.numeric(coef(fit)), msg="fastLm.coef") checkEquals(as.numeric(flm$stderr), as.numeric(coef(summary(fit))[,2]), msg="fastLm.stderr") checkEquals(as.numeric(flm$df.residual), as.numeric(fit$df.residual), msg="fastLm.df.residual") } test.fastLm.default <- function() { data(trees, package="datasets") flm <- RcppArmadillo:::fastLm.default(cbind(1, log(trees$Girth)), log(trees$Volume)) fit <- lm(log(Volume) ~ log(Girth), data=trees) checkEquals(as.numeric(flm$coefficients), as.numeric(coef(fit)), msg="fastLm.default.coef") checkEquals(as.numeric(flm$stderr), as.numeric(coef(summary(fit))[,2]), msg="fastLm.default.stderr") checkEquals(as.numeric(flm$df.residual), as.numeric(fit$df.residual), msg="fastLm.default.df.residual") checkEquals(as.numeric(flm$residuals), as.numeric(fit$residuals), msg="fastLm.default.residuals") checkEquals(as.numeric(flm$fitted.values), as.numeric(fit$fitted.values), msg="fastLm.default.fitted.values") } test.summary.fastLm <- function() { data(trees, package="datasets") sflm <- summary(fastLm(log(Volume) ~ log(Girth), data=trees)) sfit <- summary(lm(log(Volume) ~ log(Girth), data=trees)) checkEquals(as.numeric(coef(sflm)), as.numeric(coef(sfit)), msg="summary.fastLm.coef") checkEquals(sflm$r.squared, sfit$r.squared, msg="summary.fastLm.r.squared") checkEquals(sflm$adj.r.squared, sfit$adj.r.squared, msg="summary.fastLm.r.squared") checkEquals(sflm$sigma, sfit$sigma, msg="summary.fastLm.sigma") ## no intercept case sflm <- summary(fastLm(log(Volume) ~ log(Girth) - 1, data=trees)) sfit <- summary(lm(log(Volume) ~ log(Girth) - 1, data=trees)) checkEquals(as.numeric(coef(sflm)), as.numeric(coef(sfit)), msg="summary.fastLm.coef.noint") checkEquals(sflm$r.squared, sfit$r.squared, msg="summary.fastLm.r.squared.noint") checkEquals(sflm$adj.r.squared, sfit$adj.r.squared, msg="summary.fastLm.r.squared.noint") checkEquals(sflm$sigma, sfit$sigma, msg="summary.fastLm.sigma.noint") ## non-formula use sflm <- summary(fastLm(log(trees$Girth), log(trees$Volume))) sfit <- summary(lm(log(Volume) ~ log(Girth) - 1, data=trees)) checkEquals(as.numeric(coef(sflm)), as.numeric(coef(sfit)), msg="summary.fastLm.coef.nonform") checkEquals(sflm$r.squared, sfit$r.squared, msg="summary.fastLm.r.squared.nonform") checkEquals(sflm$adj.r.squared, sfit$adj.r.squared, msg="summary.fastLm.r.squared.nonform") checkEquals(sflm$sigma, sfit$sigma, msg="summary.fastLm.sigma.nonform") } test.fastLm.formula <- function() { data(trees, package="datasets") flm <- fastLm(log(Volume) ~ log(Girth), data=trees) fit <- lm(log(Volume) ~ log(Girth), data=trees) checkEquals(flm$coefficients, coef(fit), msg="fastLm.formula.coef") checkEquals(as.numeric(flm$stderr), as.numeric(coef(summary(fit))[,2]), msg="fastLm.formula.stderr") checkEquals(as.numeric(flm$df.residual), as.numeric(fit$df.residual), msg="fastLm.formula.df.residual") checkEquals(as.numeric(flm$residuals), as.numeric(fit$residuals), msg="fastLm.formula.residuals") checkEquals(as.numeric(flm$fitted.values), as.numeric(fit$fitted.values), msg="fastLm.formula.fitted.values") } RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R0000644000176000001440000001422312253723621022033 0ustar ripleyusers#!/usr/bin/r -t # # Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates # # This file is part of RcppArmadillo. # # RcppArmadillo is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # RcppArmadillo is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with RcppArmadillo. If not, see . .setUp <- RcppArmadillo:::unit_test_setup( "armadillo.cpp", "RcppArmadillo" ) test.wrap.R <- function(){ fx <- wrap_ res <- fx() checkEquals( res[[1]][[1]], matrix(as.integer((diag(3))),nr=3), msg = "eye(3,3)" ) checkEquals( res[[1]][[2]], diag(3), msg = "eye(3,3)" ) checkEquals( res[[1]][[3]], diag(3), msg = "eye(3,3)" ) checkEquals( res[[1]][[4]], matrix(as.integer((diag(3))),nr=3), msg = "eye(3,3)" ) checkEquals( res[[2]][[1]], matrix(0, ncol = 5, nrow=1), msg = "zeros(5,1)" ) checkEquals( res[[2]][[2]], matrix(0, ncol = 5, nrow=1), msg = "zeros(5,1)" ) checkEquals( res[[3]][[1]], matrix(0, ncol = 1, nrow=5), msg = "zeros(1,5)" ) checkEquals( res[[3]][[2]], matrix(0, ncol = 1, nrow=5), msg = "zeros(1,5)" ) checkEquals( res[[4]][[1]], matrix(0:3, ncol = 2, nrow=2), msg = "field" ) checkEquals( res[[4]][[2]], matrix(letters[1:4], ncol = 2, nrow=2), msg = "field" ) } test.wrap.Glue <- function(){ fx <- wrapGlue_ res <- fx() checkEquals( res[[1]], 2*diag(3), msg = "wrap(Glue)" ) } test.wrap.Op <- function(){ fx <- wrapOp_ res <- fx() checkEquals( res[[1]], -1*diag(3), msg = "wrap(Op)" ) } test.as.Mat <- function(){ fx <- asMat_ integer_mat <- matrix( as.integer(diag(4)), ncol = 4, nrow = 4 ) numeric_mat <- diag(5) res <- fx( list( integer_mat, numeric_mat ) ) checkEquals( unlist( res), c(4L, 5L, 4L, 5L ), msg = "as" ) } test.as.Col <- function(){ fx <- asCol_ res <- fx( list( 1:10, as.numeric(1:10) ) ) checkEquals( unlist( res ), rep(55.0, 4 ), msg = "as" ) } test.as.Row <- function(){ fx <- asRow_ res <- fx( list( 1:10, as.numeric(1:10) ) ) checkEquals( unlist( res ), rep(55.0, 4 ), msg = "as" ) } test.cxmat <- function(){ fx <- cxMat_ checkEquals(fx(), list( double = (1+0i)*diag(3), float = (1+0i)*diag(3) ), msg = "support for complex matrices" ) } test.mtOp <- function(){ fx <- mtOp_ checkEquals(fx(), (1+2i)*diag(3), msg = "support for mtOp" ) } test.mtGlue <- function(){ fx <- mtGlue_ checkEquals(fx(), 2.0 * diag(3) , msg = "support for mtGlue" ) } test.sugar <- function(){ fx <- sugar_ checkEquals(fx(1:10), matrix( 2*(1:10), nrow = 10 ) , msg = "RcppArmadillo and sugar" ) } test.sugar.cplx <- function(){ fx <- sugarCplx_ x <- 1:10*(1+1i) checkEquals(fx(x), matrix( exp(x), nrow = 10 ) , msg = "RcppArmadillo and sugar (complex)" ) } test.armadillo.sugar.ctor <- function(){ fx <- sugarCtor_ checkEquals(fx(1:10), list(mat = matrix( 4*(1:10), nrow = 10 ), rowvec = matrix( 1:10, nrow = 1 ), colvec = matrix( 1:10, ncol = 1 )) , msg = "Mat( sugar expression )" ) } test.armadillo.sugar.matrix.ctor <- function(){ fx <- sugarMatrixCtor_ res <- fx(1:10) norm <- function(x, y) sqrt( x*x + y*y ) checkEquals(res, list(mat = diag(2*(1:10)), rowvec = outer( 1, 1:10, norm ), colvec = outer( 1:10, 1, norm )), msg = "Mat( sugar expression )" ) } ## test.armadillo.rtti.check <- function() { ## inc <- ' ## void blah(arma::mat& X) { ## X.set_size(5,5); ## } ## ' ## src <- ' ## arma::vec V; ## blah(V); // if blah() worked, we have a problem ## ' ## fun <- cxxfunction(signature(), body=src, inc=inc, plugin = "RcppArmadillo") ## checkException(fun(), msg="RTTI check on matrix constructor exception") ## } test.armadillo.mat.plain <- function() { fx <- mat_plain m <- matrix(1:9, 3, 3) checkEquals(fx(m), 9, msg = "Plain Matrix function signature" ) } test.armadillo.mat.const <- function() { fx <- mat_const m <- matrix(1:9, 3, 3) checkEquals(fx(m), 9, msg = "Const Matrix function signature" ) } test.armadillo.mat.ref <- function() { fx <- mat_ref m <- matrix(1:9, 3, 3) checkEquals(fx(m), 9, msg = "Reference Matrix function signature" ) } test.armadillo.mat.const.ref <- function() { fx <- mat_const_ref m <- matrix(1:9, 3, 3) checkEquals(fx(m), 9, msg = "Const Reference Matrix function signature" ) } test.armadillo.vec.plain <- function() { fx <- vec_plain m <- 1:9 checkEquals(fx(m), 9, msg = "Plain Vector function signature" ) } test.armadillo.vec.const <- function() { fx <- vec_const m <- 1:9 checkEquals(fx(m), 9, msg = "Const Vector function signature" ) } test.armadillo.vec.ref <- function() { fx <- vec_ref m <- 1:9 checkEquals(fx(m), 9, msg = "Reference Vector function signature" ) } test.armadillo.vec.const.ref <- function() { fx <- vec_const_ref m <- 1:9 checkEquals(fx(m), 9, msg = "Const Reference Vector function signature" ) } test.armadillo.mat.plain <- function() { fx <- cx_mat_plain m <- matrix(1:9, 3, 3) checkEquals(fx(m), 9, msg = "Plain Matrix function signature" ) } test.armadillo.mat.const <- function() { fx <- cx_mat_const m <- matrix(1:9, 3, 3) checkEquals(fx(m), 9, msg = "Const Matrix function signature" ) } test.armadillo.mat.ref <- function() { fx <- cx_mat_ref m <- matrix(1:9, 3, 3) checkEquals(fx(m), 9, msg = "Reference Matrix function signature" ) } test.armadillo.mat.const.ref <- function() { fx <- cx_mat_const_ref m <- matrix(1:9, 3, 3) checkEquals(fx(m), 9, msg = "Const Reference Matrix function signature" ) } RcppArmadillo/inst/unitTests/runit.sample.R0000644000176000001440000000771312253723621020571 0ustar ripleyusers#!/usr/bin/r -t # # Copyright (C) 2012 - 2013 Christian Gunning # Copyright (C) 2013 Romain Francois # # This file is part of RcppArmadillo. # # RcppArmadillo is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # RcppArmadillo is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with RcppArmadillo. If not, see . .setUp <- RcppArmadillo:::unit_test_setup( "sample.cpp" ) test.sample <- function() { ## set up S3 dispatching, ## simplifies lapply(tests, ...) below csample <- function(x, ...) UseMethod("csample") csample.numeric <- csample_numeric csample.integer <- csample_integer csample.complex <- csample_complex csample.character <- csample_character csample.logical <- csample_logical ## Seed needs to be reset to compare R to C++ seed <- 441 ## Input vectors to sample N <- 100 ## Number of samples ## works for size == N?! size <- N%/%2 ## all atomic vector classes except raw ## for each list element, check that sampling works ## with and without replacement, with and without prob tests <- list() tests <- within(tests, { int <- 1:N num <- (1:N)/10 cpx <- (1:N)/10 + 1i char <-rep(letters, 4)[1:N] bool <- rep(c(T,F), times=N/2) }) ## Un-normalized probs probs <- seq(from=0, to=1, length.out=N) #probs <- probs/sum(probs) ## Run the S3 generic function csample ## and associated R function on each data type ## ReplaceYN.ProbsYN lapply(tests, function(dat) { .class <- class(dat) set.seed(seed) ## R r.no.no <- sample(dat, size, replace=F) set.seed(seed) r.yes.no <- sample(dat, size, replace=T) set.seed(seed) r.no.yes <- sample(dat, size, replace=F, prob=probs) set.seed(seed) r.yes.yes <- sample(dat, size, replace=T, prob=probs) ## C set.seed(seed) c.no.no <- csample(dat, size, replace=F) set.seed(seed) c.yes.no <- csample(dat, size, replace=T) set.seed(seed) c.no.yes <- csample(dat, size, replace=F, prob=probs) set.seed(seed) c.yes.yes <- csample(dat, size, replace=T, prob=probs) ## comparisons checkEquals(r.no.no, c.no.no, msg=sprintf("sample.%s.no_replace.no_prob",.class)) checkEquals(r.yes.no, c.yes.no, msg=sprintf("sample.%s.replace.no_prob",.class)) ## the following don't pass checkEquals(r.no.yes, c.no.yes, msg=sprintf("sample.%s.no_replace.prob",.class)) checkEquals(r.yes.yes, c.yes.yes, msg=sprintf("sample.%s.replace.prob",.class)) }) ## Walker Alias method test ## With replacement, >200 "nonzero" probabilities ## Not implemented, see below walker.N <- 1e3 walker.sample <- (1:walker.N)/10 walker.probs <- rep(0.1, walker.N) ## uncomment following 5 lines if/when walker alias method is implemented #set.seed(seed) #r.walker <- sample( walker.sample, walker.N, replace=T, prob=walker.probs) #set.seed(seed) #c.walker <- csample( walker.sample, walker.N, replace=T, prob=walker.probs) #checkEquals(r.walker, c.walker, msg=sprintf("Walker Alias method test")) ## Walker Alias method is not implemented. ## For this problem (replace, >200 non-zero probs) R is much faster ## So throw an error and refuse to proceed walker.error <- try( csample( walker.sample, walker.N, replace=T, prob=walker.probs), TRUE) checkEquals(inherits(walker.error, "try-error"), TRUE, msg=sprintf("Walker Alias method test")) } RcppArmadillo/inst/unitTests/runTests.R0000644000176000001440000000633412253723621017775 0ustar ripleyusersrequire(Rcpp) pkg <- "RcppArmadillo" if (require("RUnit", quietly = TRUE)) { is_local <- function(){ if (exists( "argv", globalenv() ) && "--local" %in% argv) return(TRUE) if ("--local" %in% commandArgs(TRUE)) return(TRUE) FALSE } if (is_local()) path <- getwd() library(package=pkg, character.only = TRUE) if (!(exists("path") && file.exists(path))) path <- system.file("unitTests", package = pkg) ## --- Testing --- ## Define tests testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs = path) if(interactive()) { cat("Now have RUnit Test Suite 'testSuite' for package '", pkg, "' :\n", sep='') str(testSuite) cat('', "Consider doing", "\t tests <- runTestSuite(testSuite)", "\nand later", "\t printTextProtocol(tests)", '', sep="\n") } else { ## run from shell / Rscript / R CMD Batch / ... ## Run tests <- runTestSuite(testSuite) output <- NULL process_args <- function(argv){ if (!is.null(argv) && length(argv) > 0 ){ rx <- "^--output=(.*)$" g <- grep( rx, argv, value = TRUE ) if( length(g) ){ sub( rx, "\\1", g[1L] ) } } } # R CMD check uses this if (exists("RcppArmadillo.unit.test.output.dir", globalenv())) { output <- RcppArmadillo.unit.test.output.dir } else { ## give a chance to the user to customize where he/she wants ## the unit tests results to be stored with the --output= command ## line argument if (exists( "argv", globalenv())) { ## littler output <- process_args(argv) } else { ## Rscript output <- process_args(commandArgs(TRUE)) } } if (is.null(output)) { # if it did not work, use parent dir output <- ".." # as BDR does not want /tmp to be used } ## Print results output.txt <- file.path( output, sprintf("%s-unitTests.txt", pkg)) output.html <- file.path( output, sprintf("%s-unitTests.html", pkg)) printTextProtocol(tests, fileName=output.txt) message( sprintf( "saving txt unit test report to '%s'", output.txt ) ) ## Print HTML version to a file ## printHTMLProtocol has problems on Mac OS X if (Sys.info()["sysname"] != "Darwin"){ message( sprintf( "saving html unit test report to '%s'", output.html ) ) printHTMLProtocol(tests, fileName=output.html) } ## stop() if there are any failures i.e. FALSE to unit test. ## This will cause R CMD check to return error and stop err <- getErrors(tests) if ((err$nFail + err$nErr) > 0) { stop( sprintf( "unit test problems: %d failures, %d errors", err$nFail, err$nErr) ) } else{ success <- err$nTestFunc - err$nFail - err$nErr - err$nDeactivated cat( sprintf( "%d / %d\n", success, err$nTestFunc ) ) } } } else { cat("R package 'RUnit' cannot be loaded -- no unit tests run\n", "for package", pkg,"\n") } RcppArmadillo/inst/unitTests/cpp/0000755000176000001440000000000012253723621016577 5ustar ripleyusersRcppArmadillo/inst/unitTests/cpp/sample.cpp0000644000176000001440000000471012253723621020566 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- // // sample.cpp: RcppArmadillo unit test code for sample() function // // Copyright (C) 2012 - 2013 Christian Gunning and Dirk Eddelbuettel // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . // [[Rcpp::depends(RcppArmadillo)]] #include #include using namespace Rcpp; // function defns exported to R -- instantiate templated sample // functions are identical except for class of sampled vector and return val // [[Rcpp::export]] IntegerVector csample_integer( IntegerVector x, int size, bool replace, NumericVector prob = NumericVector::create()) { RNGScope scope; IntegerVector ret = RcppArmadillo::sample(x, size, replace, prob); return ret; } // [[Rcpp::export]] NumericVector csample_numeric( NumericVector x, int size, bool replace, NumericVector prob = NumericVector::create()) { RNGScope scope; NumericVector ret = RcppArmadillo::sample(x, size, replace, prob); return ret; } // [[Rcpp::export]] ComplexVector csample_complex( ComplexVector x, int size, bool replace, NumericVector prob = NumericVector::create()) { RNGScope scope; ComplexVector ret = RcppArmadillo::sample(x, size, replace, prob); return ret; } // [[Rcpp::export]] CharacterVector csample_character( CharacterVector x, int size, bool replace, NumericVector prob = NumericVector::create()) { RNGScope scope; CharacterVector ret = RcppArmadillo::sample(x, size, replace, prob); return ret; } // [[Rcpp::export]] LogicalVector csample_logical( LogicalVector x, int size, bool replace, NumericVector prob = NumericVector::create()) { RNGScope scope; LogicalVector ret = RcppArmadillo::sample(x, size, replace, prob); return ret; } RcppArmadillo/inst/unitTests/cpp/armadillo.cpp0000644000176000001440000001625412253723621021257 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- // // armadillo.cpp: RcppArmadillo unit test code // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . // [[Rcpp::depends(RcppArmadillo)]] #include using namespace Rcpp; // [[Rcpp::export]] List wrap_() { // using the Named(.) = . notation List cols = List::create(Named( "Col" ) = arma::zeros(5,1), Named( "Col" ) = arma::zeros(5,1)); // using the Named(., .) notation List rows = List::create(Named( "Row", arma::zeros(1,5) ), Named( "Row" , arma::zeros(1,5) )); // using the _[.] = . notation List matrices = List::create(_["Mat"] = arma::eye( 3,3 ), _["Mat"] = arma::eye( 3,3 ), _["Mat"] = arma::eye( 3, 3 ), _["Mat"] = arma::eye( 3, 3 )); // creating an empty list and grow it on demand List fields; arma::field f1( 2, 2 ); f1( 0, 0 ) = 0; f1( 1, 0 ) = 1; f1( 0, 1 ) = 2; f1( 1, 1 ) = 3; fields["field"] = f1; arma::field f2(2,2); f2( 0, 0 ) = "a"; f2( 1, 0 ) = "b"; f2( 0, 1 ) = "c"; f2( 1, 1 ) = "d"; fields["field"] = f2; arma::field f3(2,2); f3(0,0) = arma::zeros(5,1); f3(1,0) = arma::zeros(4,1); f3(0,1) = arma::zeros(3,1); f3(1,1) = arma::zeros(2,1); fields["field"] = f3; List output = List::create(_["matrices : Mat"] = matrices, _["rows : Row"] = rows, _["columns : Col"] = cols, _["fields : field"] = fields ); return output; } // [[Rcpp::export]] List wrapGlue_() { arma::mat m1 = arma::eye( 3, 3 ); arma::mat m2 = arma::eye( 3, 3 ); List res; res["mat+mat"] = m1 + m2; return res; } // [[Rcpp::export]] List wrapOp_() { arma::mat m1 = arma::eye( 3, 3 ); List res; res["- mat"] = - m1; return res; } // [[Rcpp::export]] List asMat_(List input) { arma::imat m1 = input[0]; /* implicit as */ arma::mat m2 = input[1]; /* implicit as */ arma::umat m3 = input[0]; /* implicit as */ arma::fmat m4 = input[1]; /* implicit as */ List res = List::create(arma::accu( m1 ), arma::accu( m2 ), arma::accu( m3 ), arma::accu( m4 ) ); return res; } // [[Rcpp::export]] List asCol_(List input) { arma::icolvec m1 = input[0]; /* implicit as */ arma::colvec m2 = input[1]; /* implicit as */ arma::ucolvec m3 = input[0]; /* implicit as */ arma::fcolvec m4 = input[1]; /* implicit as */ List res = List::create(arma::accu( m1 ), arma::accu( m2 ), arma::accu( m3 ), arma::accu( m4 ) ); return res; } // [[Rcpp::export]] List asRow_(List input) { arma::irowvec m1 = input[0]; /* implicit as */ arma::rowvec m2 = input[1]; /* implicit as */ arma::urowvec m3 = input[0]; /* implicit as */ arma::frowvec m4 = input[1]; /* implicit as */ List res = List::create(arma::accu( m1 ), arma::accu( m2 ), arma::accu( m3 ), arma::accu( m4 ) ); return res; } // [[Rcpp::export]] List cxMat_() { arma::cx_mat m1 = arma::eye ( 3, 3 ); arma::cx_fmat m2 = arma::eye( 3, 3 ); return List::create( _["double"] = m1, _["float"] = m2 ); } // [[Rcpp::export]] ComplexMatrix mtOp_() { std::complex x( 1.0, 2.0 ); arma::mat m1 = arma::eye ( 3, 3 ); return wrap( x * m1 ); } // [[Rcpp::export]] NumericMatrix mtGlue_() { arma::imat m2 = arma::eye ( 3, 3 ); arma::mat m1 = arma::eye ( 3, 3 ); return wrap( m1 + m2 ); } // [[Rcpp::export]] NumericMatrix sugar_(NumericVector xx) { arma::mat m = xx + xx; return wrap( m ); } // [[Rcpp::export]] ComplexMatrix sugarCplx_(ComplexVector xx) { arma::cx_mat m = exp( xx ); return wrap( m ); } // [[Rcpp::export]] List sugarCtor_(NumericVector xx) { arma::mat m = xx + xx; arma::colvec co = xx; arma::rowvec ro = xx; return List::create(_["mat"] = m + m, _["rowvec"] = ro, _["colvec"] = co); } double norm( double x, double y){ return ::sqrt( x*x + y*y ); } // [[Rcpp::export]] List sugarMatrixCtor_(NumericVector xx) { NumericVector yy = NumericVector::create( 1 ); arma::mat m = diag( xx ); arma::colvec co = outer( xx, yy, ::norm ); arma::rowvec ro = outer( yy, xx, ::norm ); return List::create(_["mat"] = m + m , _["rowvec"] = ro, _["colvec"] = co); } // test.armadillo.rtti.check <- function() { // inc <- ' // void blah(arma::mat& X) { // X.set_size(5,5); // } // ' // src <- ' // arma::vec V; // blah(V); // if blah() worked, we have a problem // ' // fun <- cxxfunction(signature(), body=src, inc=inc, plugin = "RcppArmadillo") // checkException(fun(), msg="RTTI check on matrix constructor exception") // } // [[Rcpp::export]] int mat_plain(arma::mat x) { return x.n_elem; } // [[Rcpp::export]] int mat_const(const arma::mat x) { return x.n_elem; } // [[Rcpp::export]] int mat_ref(arma::mat & x) { return x.n_elem; } // [[Rcpp::export]] int mat_const_ref(const arma::mat & x) { return x.n_elem; } // [[Rcpp::export]] int vec_plain(arma::vec x) { return x.n_elem; } // [[Rcpp::export]] int vec_const(const arma::vec x) { return x.n_elem; } // [[Rcpp::export]] int vec_ref(arma::vec & x) { return x.n_elem; } // [[Rcpp::export]] int vec_const_ref(const arma::vec & x) { return x.n_elem; } // [[Rcpp::export]] int cx_mat_plain(arma::cx_mat x) { return x.n_elem; } // [[Rcpp::export]] int cx_mat_const(const arma::cx_mat x) { return x.n_elem; } // [[Rcpp::export]] int cx_mat_ref(arma::cx_mat & x) { return x.n_elem; } // [[Rcpp::export]] int cx_mat_const_ref(const arma::cx_mat & x) { return x.n_elem; } RcppArmadillo/inst/unitTests/cpp/complex.cpp0000644000176000001440000000431412253723621020754 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- // // complex.cpp: RcppArmadillo unit tests for complex vectors and matrices // // Copyright (C) 2013 Baptiste Auguie and Dirk Eddelbuettel // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #include using namespace Rcpp; using namespace arma; // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::export]] List complexCppTests(const arma::mat& A, const arma::mat& B, const arma::cx_colvec& V, const arma::mat& S) { arma::cx_mat C(A, B); // create complex matrix arma::cx_mat Cst = strans(C), Ct = trans(C); // transpose arma::cx_mat conjC = conj(C); // conjugate arma::mat absC = abs(C); // modulus arma::cx_colvec CV = C * V; // multiply matrix-vector arma::cx_mat CS = C * S; // multiply matrix-matrix arma::cx_mat CC = C % C; // element-wise multiplication arma::cx_mat CdC = C / C; // division arma::cx_mat CpC = C + C; // addition arma::cx_mat CmC = C - C; // subtraction return List::create(_["C"] = C, _["Cst"] = Cst, _["Ct"] = Ct, _["conjC"] = conjC, _["absC"] = absC, _["CV"] = CV, _["CS"] = CS, _["CC"] = CC, _["CdC"] = CdC, _["CpC"] = CpC, _["CmC"] = CmC ); } RcppArmadillo/inst/unitTests/runit.complex.R0000644000176000001440000000364612253723621020760 0ustar ripleyusers#!/usr/bin/r -t # # Copyright (C) 2013 Baptiste Auguie and Dirk Eddelbuettel # # This file is part of RcppArmadillo. # # RcppArmadillo is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # RcppArmadillo is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with RcppArmadillo. If not, see . .setUp <- RcppArmadillo:::unit_test_setup("complex.cpp") test.complex <- function() { set.seed(123) ## create variables A <- matrix(rnorm(9), 3) B <- matrix(rnorm(9), 3) C <- A + 1i * B V <- rnorm(3) + 1i * rnorm(3) S <- matrix(rnorm(5*3), nrow=3) ## Basic operations rl <- complexCppTests(A, B, V, S) # returns results list from C++ checkEquals(rl[["C"]], C, msg="complex matrix") checkEquals(rl[["Cst"]], t(C), msg="complex matrix transpose") checkEquals(rl[["Ct"]], Conj(t(C)), msg="complex matrix transpose conjugated") checkEquals(rl[["conjC"]], Conj(C), msg="complex matrix conjugated") checkEquals(rl[["absC"]], Mod(C), msg="complex matrix mod") checkEquals(rl[["CV"]], C %*% V, msg="complex matrix product") checkEquals(rl[["CS"]], C %*% S, msg="complex matrix times vector") checkEquals(rl[["CC"]], C * C, msg="complex matrix ops mult") checkEquals(rl[["CdC"]], C / C, msg="complex matrix ops div") checkEquals(rl[["CpC"]], C + C, msg="complex matrix ops plus") checkEquals(rl[["CmC"]], C - C, msg="complex matrix ops minus") } RcppArmadillo/inst/skeleton/0000755000176000001440000000000012253723621015637 5ustar ripleyusersRcppArmadillo/inst/skeleton/Makevars0000644000176000001440000000025312253723621017333 0ustar ripleyusers## Use the R_HOME indirection to support installations of multiple R version PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) RcppArmadillo/inst/skeleton/rcpparma_hello_world.R0000644000176000001440000000013412253723621022157 0ustar ripleyusers rcpparma_hello_world <- function(){ .Call( "rcpparma_hello_world", PACKAGE = "@PKG@" ) } RcppArmadillo/inst/skeleton/rcpparma_hello_world.h0000644000176000001440000000022212253723621022203 0ustar ripleyusers#ifndef _@PKG@_RCPP_HELLO_WORLD_H #define _@PKG@_RCPP_HELLO_WORLD_H #include RcppExport SEXP rcpparma_hello_world() ; #endif RcppArmadillo/inst/skeleton/rcpparma_hello_world.cpp0000644000176000001440000000046612253723621022550 0ustar ripleyusers#include "rcpparma_hello_world.h" using namespace Rcpp ; SEXP rcpparma_hello_world(){ arma::mat m1 = arma::eye( 3, 3 ) ; arma::mat m2 = arma::eye( 3, 3 ) ; List res ; res["mat+mat"] = m1 + 3 * ( m1 + m2 ); return res ; } RcppArmadillo/inst/skeleton/Makevars.win0000644000176000001440000000050012253723621020122 0ustar ripleyusers## This assumes that we can call Rscript to ask Rcpp about its locations ## Use the R_HOME indirection to support installations of multiple R version PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()") PKG_CPPFLAGS = -I../inst/include -I. PKG_LIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) RcppArmadillo/inst/include/0000755000176000001440000000000012267623072015442 5ustar ripleyusersRcppArmadillo/inst/include/armadillo_bits/0000755000176000001440000000000012267621603020425 5ustar ripleyusersRcppArmadillo/inst/include/armadillo_bits/Cube_bones.hpp0000644000176000001440000005237412256553754023226 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Cube //! @{ struct Cube_prealloc { static const uword mat_ptrs_size = 4; static const uword mem_n_elem = 64; }; //! Dense cube class template class Cube : public BaseCube< eT, Cube > { public: typedef eT elem_type; //!< the type of elements stored in the cube typedef typename get_pod_type::result pod_type; //!< if eT is non-complex, pod_type is same as eT. otherwise, pod_type is the underlying type used by std::complex const uword n_rows; //!< number of rows in each slice (read-only) const uword n_cols; //!< number of columns in each slice (read-only) const uword n_elem_slice; //!< number of elements in each slice (read-only) const uword n_slices; //!< number of slices in the cube (read-only) const uword n_elem; //!< number of elements in the cube (read-only) const uword mem_state; // mem_state = 0: normal cube that can be resized; // mem_state = 1: use auxiliary memory until change in the number of elements is requested; // mem_state = 2: use auxiliary memory and don't allow the number of elements to be changed; // mem_state = 3: fixed size (e.g. via template based size specification). arma_aligned const Mat** const mat_ptrs; //!< pointer to an array containing pointers to Mat instances (one for each slice) arma_aligned const eT* const mem; //!< pointer to the memory used by the cube (memory is read-only) protected: arma_align_mem Mat* mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ]; arma_align_mem eT mem_local[ Cube_prealloc::mem_n_elem ]; public: inline ~Cube(); inline Cube(); inline Cube(const uword in_rows, const uword in_cols, const uword in_slices); template inline Cube(const uword in_rows, const uword in_cols, const uword in_slices, const fill::fill_class& f); #if defined(ARMA_USE_CXX11) inline Cube(Cube&& m); inline const Cube& operator=(Cube&& m); #endif inline Cube( eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices, const bool copy_aux_mem = true, const bool strict = true); inline Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices); arma_inline const Cube& operator=(const eT val); arma_inline const Cube& operator+=(const eT val); arma_inline const Cube& operator-=(const eT val); arma_inline const Cube& operator*=(const eT val); arma_inline const Cube& operator/=(const eT val); inline Cube(const Cube& m); inline const Cube& operator=(const Cube& m); inline const Cube& operator+=(const Cube& m); inline const Cube& operator-=(const Cube& m); inline const Cube& operator%=(const Cube& m); inline const Cube& operator/=(const Cube& m); template inline explicit Cube(const BaseCube& A, const BaseCube& B); inline Cube(const subview_cube& X); inline const Cube& operator=(const subview_cube& X); inline const Cube& operator+=(const subview_cube& X); inline const Cube& operator-=(const subview_cube& X); inline const Cube& operator%=(const subview_cube& X); inline const Cube& operator/=(const subview_cube& X); arma_inline Mat& slice(const uword in_slice); arma_inline const Mat& slice(const uword in_slice) const; arma_inline subview_cube slices(const uword in_slice1, const uword in_slice2); arma_inline const subview_cube slices(const uword in_slice1, const uword in_slice2) const; arma_inline subview_cube subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2); arma_inline const subview_cube subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) const; inline subview_cube subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s); inline const subview_cube subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const; inline subview_cube subcube(const span& row_span, const span& col_span, const span& slice_span); inline const subview_cube subcube(const span& row_span, const span& col_span, const span& slice_span) const; inline subview_cube operator()(const span& row_span, const span& col_span, const span& slice_span); inline const subview_cube operator()(const span& row_span, const span& col_span, const span& slice_span) const; inline subview_cube operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s); inline const subview_cube operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const; arma_inline subview_cube tube(const uword in_row1, const uword in_col1); arma_inline const subview_cube tube(const uword in_row1, const uword in_col1) const; arma_inline subview_cube tube(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); arma_inline const subview_cube tube(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; arma_inline subview_cube tube(const uword in_row1, const uword in_col1, const SizeMat& s); arma_inline const subview_cube tube(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline subview_cube tube(const span& row_span, const span& col_span); inline const subview_cube tube(const span& row_span, const span& col_span) const; template arma_inline subview_elem1 elem(const Base& a); template arma_inline const subview_elem1 elem(const Base& a) const; template arma_inline subview_elem1 operator()(const Base& a); template arma_inline const subview_elem1 operator()(const Base& a) const; inline void shed_slice(const uword slice_num); inline void shed_slices(const uword in_slice1, const uword in_slice2); inline void insert_slices(const uword slice_num, const uword N, const bool set_to_zero = true); template inline void insert_slices(const uword row_num, const BaseCube& X); template inline Cube(const GenCube& X); template inline const Cube& operator=(const GenCube& X); template inline const Cube& operator+=(const GenCube& X); template inline const Cube& operator-=(const GenCube& X); template inline const Cube& operator%=(const GenCube& X); template inline const Cube& operator/=(const GenCube& X); template inline Cube(const OpCube& X); template inline const Cube& operator=(const OpCube& X); template inline const Cube& operator+=(const OpCube& X); template inline const Cube& operator-=(const OpCube& X); template inline const Cube& operator%=(const OpCube& X); template inline const Cube& operator/=(const OpCube& X); template inline Cube(const eOpCube& X); template inline const Cube& operator=(const eOpCube& X); template inline const Cube& operator+=(const eOpCube& X); template inline const Cube& operator-=(const eOpCube& X); template inline const Cube& operator%=(const eOpCube& X); template inline const Cube& operator/=(const eOpCube& X); template inline Cube(const mtOpCube& X); template inline const Cube& operator=(const mtOpCube& X); template inline const Cube& operator+=(const mtOpCube& X); template inline const Cube& operator-=(const mtOpCube& X); template inline const Cube& operator%=(const mtOpCube& X); template inline const Cube& operator/=(const mtOpCube& X); template inline Cube(const GlueCube& X); template inline const Cube& operator=(const GlueCube& X); template inline const Cube& operator+=(const GlueCube& X); template inline const Cube& operator-=(const GlueCube& X); template inline const Cube& operator%=(const GlueCube& X); template inline const Cube& operator/=(const GlueCube& X); template inline Cube(const eGlueCube& X); template inline const Cube& operator=(const eGlueCube& X); template inline const Cube& operator+=(const eGlueCube& X); template inline const Cube& operator-=(const eGlueCube& X); template inline const Cube& operator%=(const eGlueCube& X); template inline const Cube& operator/=(const eGlueCube& X); template inline Cube(const mtGlueCube& X); template inline const Cube& operator=(const mtGlueCube& X); template inline const Cube& operator+=(const mtGlueCube& X); template inline const Cube& operator-=(const mtGlueCube& X); template inline const Cube& operator%=(const mtGlueCube& X); template inline const Cube& operator/=(const mtGlueCube& X); arma_inline arma_warn_unused const eT& at_alt (const uword i) const; arma_inline arma_warn_unused eT& operator[] (const uword i); arma_inline arma_warn_unused const eT& operator[] (const uword i) const; arma_inline arma_warn_unused eT& at(const uword i); arma_inline arma_warn_unused const eT& at(const uword i) const; arma_inline arma_warn_unused eT& operator() (const uword i); arma_inline arma_warn_unused const eT& operator() (const uword i) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col, const uword in_slice) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col, const uword in_slice) const; arma_inline const Cube& operator++(); arma_inline void operator++(int); arma_inline const Cube& operator--(); arma_inline void operator--(int); arma_inline arma_warn_unused bool is_finite() const; arma_inline arma_warn_unused bool is_empty() const; arma_inline arma_warn_unused bool in_range(const uword i) const; arma_inline arma_warn_unused bool in_range(const span& x) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const uword in_slice) const; inline arma_warn_unused bool in_range(const span& row_span, const span& col_span, const span& slice_span) const; inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const uword in_slice, const SizeCube& s) const; arma_inline arma_warn_unused eT* memptr(); arma_inline arma_warn_unused const eT* memptr() const; arma_inline arma_warn_unused eT* slice_memptr(const uword slice); arma_inline arma_warn_unused const eT* slice_memptr(const uword slice) const; arma_inline arma_warn_unused eT* slice_colptr(const uword in_slice, const uword in_col); arma_inline arma_warn_unused const eT* slice_colptr(const uword in_slice, const uword in_col) const; inline void impl_print(const std::string& extra_text) const; inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const; inline void impl_raw_print(const std::string& extra_text) const; inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const; inline void set_size(const uword in_rows, const uword in_cols, const uword in_slices); inline void reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim = 0); inline void resize(const uword in_rows, const uword in_cols, const uword in_slices); template inline void copy_size(const Cube& m); template inline const Cube& transform(functor F); template inline const Cube& imbue(functor F); inline const Cube& fill(const eT val); inline const Cube& zeros(); inline const Cube& zeros(const uword in_rows, const uword in_cols, const uword in_slices); inline const Cube& ones(); inline const Cube& ones(const uword in_rows, const uword in_cols, const uword in_slices); inline const Cube& randu(); inline const Cube& randu(const uword in_rows, const uword in_cols, const uword in_slices); inline const Cube& randn(); inline const Cube& randn(const uword in_rows, const uword in_cols, const uword in_slices); inline void reset(); template inline void set_real(const BaseCube& X); template inline void set_imag(const BaseCube& X); inline arma_warn_unused eT min() const; inline arma_warn_unused eT max() const; inline eT min(uword& index_of_min_val) const; inline eT max(uword& index_of_max_val) const; inline eT min(uword& row_of_min_val, uword& col_of_min_val, uword& slice_of_min_val) const; inline eT max(uword& row_of_max_val, uword& col_of_max_val, uword& slice_of_max_val) const; inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const; inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const; inline bool load(const std::string name, const file_type type = auto_detect, const bool print_status = true); inline bool load( std::istream& is, const file_type type = auto_detect, const bool print_status = true); inline bool quiet_save(const std::string name, const file_type type = arma_binary) const; inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const; inline bool quiet_load(const std::string name, const file_type type = auto_detect); inline bool quiet_load( std::istream& is, const file_type type = auto_detect); // iterators typedef eT* iterator; typedef const eT* const_iterator; typedef eT* slice_iterator; typedef const eT* const_slice_iterator; inline iterator begin(); inline const_iterator begin() const; inline const_iterator cbegin() const; inline iterator end(); inline const_iterator end() const; inline const_iterator cend() const; inline slice_iterator begin_slice(const uword slice_num); inline const_slice_iterator begin_slice(const uword slice_num) const; inline slice_iterator end_slice(const uword slice_num); inline const_slice_iterator end_slice(const uword slice_num) const; inline void clear(); inline bool empty() const; inline uword size() const; inline void swap(Cube& B); inline void steal_mem(Cube& X); //!< don't use this unless you're writing code internal to Armadillo template class fixed; protected: inline void init_cold(); inline void init_warm(const uword in_rows, const uword in_cols, const uword in_slices); template inline void init(const BaseCube& A, const BaseCube& B); inline void delete_mat(); inline void create_mat(); friend class glue_join; friend class op_reshape; friend class op_resize; public: #ifdef ARMA_EXTRA_CUBE_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_PROTO) #endif }; template template class Cube::fixed : public Cube { private: static const uword fixed_n_elem = fixed_n_rows * fixed_n_cols * fixed_n_slices; static const uword fixed_n_elem_slice = fixed_n_rows * fixed_n_cols; static const bool use_extra = (fixed_n_elem > Cube_prealloc::mem_n_elem); arma_aligned Mat* mat_ptrs_local_extra[ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? fixed_n_slices : 1 ]; arma_align_mem eT mem_local_extra [ use_extra ? fixed_n_elem : 1 ]; arma_inline void mem_setup(); public: inline fixed(); inline fixed(const fixed& X); template inline fixed(const fill::fill_class& f); template inline fixed(const BaseCube& A); template inline fixed(const BaseCube& A, const BaseCube& B); using Cube::operator=; using Cube::operator(); inline const Cube& operator=(const fixed& X); arma_inline arma_warn_unused eT& operator[] (const uword i); arma_inline arma_warn_unused const eT& operator[] (const uword i) const; arma_inline arma_warn_unused eT& at (const uword i); arma_inline arma_warn_unused const eT& at (const uword i) const; arma_inline arma_warn_unused eT& operator() (const uword i); arma_inline arma_warn_unused const eT& operator() (const uword i) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col, const uword in_slice) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col, const uword in_slice) const; }; class Cube_aux { public: template arma_inline static void prefix_pp(Cube& x); template arma_inline static void prefix_pp(Cube< std::complex >& x); template arma_inline static void postfix_pp(Cube& x); template arma_inline static void postfix_pp(Cube< std::complex >& x); template arma_inline static void prefix_mm(Cube& x); template arma_inline static void prefix_mm(Cube< std::complex >& x); template arma_inline static void postfix_mm(Cube& x); template arma_inline static void postfix_mm(Cube< std::complex >& x); template inline static void set_real(Cube& out, const BaseCube& X); template inline static void set_imag(Cube& out, const BaseCube& X); template inline static void set_real(Cube< std::complex >& out, const BaseCube< T,T1>& X); template inline static void set_imag(Cube< std::complex >& out, const BaseCube< T,T1>& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/cond_rel_bones.hpp0000644000176000001440000000137012111344723024103 0ustar ripleyusers// Copyright (C) 2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup cond_rel //! @{ // // for preventing pedantic compiler warnings template class cond_rel { public: template arma_inline static bool lt(const eT A, const eT B); template arma_inline static bool gt(const eT A, const eT B); template arma_inline static bool leq(const eT A, const eT B); template arma_inline static bool geq(const eT A, const eT B); }; //! @} RcppArmadillo/inst/include/armadillo_bits/Mat_bones.hpp0000644000176000001440000007640312236560701023054 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Mat //! @{ //! Dense matrix class template class Mat : public Base< eT, Mat > { public: typedef eT elem_type; //!< the type of elements stored in the matrix typedef typename get_pod_type::result pod_type; //!< if eT is non-complex, pod_type is same as eT. otherwise, pod_type is the underlying type used by std::complex const uword n_rows; //!< number of rows in the matrix (read-only) const uword n_cols; //!< number of columns in the matrix (read-only) const uword n_elem; //!< number of elements in the matrix (read-only) const uhword vec_state; //!< 0: matrix layout; 1: column vector layout; 2: row vector layout const uhword mem_state; // mem_state = 0: normal matrix that can be resized; // mem_state = 1: use auxiliary memory until change in the number of elements is requested; // mem_state = 2: use auxiliary memory and don't allow the number of elements to be changed; // mem_state = 3: fixed size (e.g. via template based size specification). arma_aligned const eT* const mem; //!< pointer to the memory used by the matrix (memory is read-only) protected: arma_align_mem eT mem_local[ arma_config::mat_prealloc ]; public: static const bool is_col = false; static const bool is_row = false; inline ~Mat(); inline Mat(); inline Mat(const uword in_rows, const uword in_cols); template inline Mat(const uword in_rows, const uword in_cols, const fill::fill_class& f); inline Mat(const char* text); inline const Mat& operator=(const char* text); inline Mat(const std::string& text); inline const Mat& operator=(const std::string& text); inline Mat(const std::vector& x); inline const Mat& operator=(const std::vector& x); #if defined(ARMA_USE_CXX11) inline Mat(const std::initializer_list& list); inline const Mat& operator=(const std::initializer_list& list); inline Mat(Mat&& m); inline const Mat& operator=(Mat&& m); #endif inline Mat( eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const bool copy_aux_mem = true, const bool strict = true); inline Mat(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols); arma_inline const Mat& operator=(const eT val); arma_inline const Mat& operator+=(const eT val); arma_inline const Mat& operator-=(const eT val); arma_inline const Mat& operator*=(const eT val); arma_inline const Mat& operator/=(const eT val); inline Mat(const Mat& m); inline const Mat& operator=(const Mat& m); inline const Mat& operator+=(const Mat& m); inline const Mat& operator-=(const Mat& m); inline const Mat& operator*=(const Mat& m); inline const Mat& operator%=(const Mat& m); inline const Mat& operator/=(const Mat& m); template inline Mat(const BaseCube& X); template inline const Mat& operator=(const BaseCube& X); template inline const Mat& operator+=(const BaseCube& X); template inline const Mat& operator-=(const BaseCube& X); template inline const Mat& operator*=(const BaseCube& X); template inline const Mat& operator%=(const BaseCube& X); template inline const Mat& operator/=(const BaseCube& X); template inline explicit Mat(const Base& A, const Base& B); inline Mat(const subview& X); inline const Mat& operator=(const subview& X); inline const Mat& operator+=(const subview& X); inline const Mat& operator-=(const subview& X); inline const Mat& operator*=(const subview& X); inline const Mat& operator%=(const subview& X); inline const Mat& operator/=(const subview& X); inline Mat(const subview_row_strans& X); // subview_row_strans can only be generated by the Proxy class inline Mat(const subview_row_htrans& X); // subview_row_htrans can only be generated by the Proxy class inline Mat(const xvec_htrans& X); // xvec_htrans can only be generated by the Proxy class //inline explicit Mat(const subview_cube& X); inline Mat(const subview_cube& X); inline const Mat& operator=(const subview_cube& X); inline const Mat& operator+=(const subview_cube& X); inline const Mat& operator-=(const subview_cube& X); inline const Mat& operator*=(const subview_cube& X); inline const Mat& operator%=(const subview_cube& X); inline const Mat& operator/=(const subview_cube& X); //inline explicit Mat(const diagview& X); inline Mat(const diagview& X); inline const Mat& operator=(const diagview& X); inline const Mat& operator+=(const diagview& X); inline const Mat& operator-=(const diagview& X); inline const Mat& operator*=(const diagview& X); inline const Mat& operator%=(const diagview& X); inline const Mat& operator/=(const diagview& X); template inline Mat(const subview_elem1& X); template inline const Mat& operator= (const subview_elem1& X); template inline const Mat& operator+=(const subview_elem1& X); template inline const Mat& operator-=(const subview_elem1& X); template inline const Mat& operator*=(const subview_elem1& X); template inline const Mat& operator%=(const subview_elem1& X); template inline const Mat& operator/=(const subview_elem1& X); template inline Mat(const subview_elem2& X); template inline const Mat& operator= (const subview_elem2& X); template inline const Mat& operator+=(const subview_elem2& X); template inline const Mat& operator-=(const subview_elem2& X); template inline const Mat& operator*=(const subview_elem2& X); template inline const Mat& operator%=(const subview_elem2& X); template inline const Mat& operator/=(const subview_elem2& X); // Operators on sparse matrices (and subviews). template inline explicit Mat(const SpBase& m); template inline const Mat& operator=(const SpBase& m); template inline const Mat& operator+=(const SpBase& m); template inline const Mat& operator-=(const SpBase& m); template inline const Mat& operator*=(const SpBase& m); template inline const Mat& operator%=(const SpBase& m); template inline const Mat& operator/=(const SpBase& m); inline mat_injector operator<<(const eT val); inline mat_injector operator<<(const injector_end_of_row<>& x); arma_inline subview_row row(const uword row_num); arma_inline const subview_row row(const uword row_num) const; inline subview_row operator()(const uword row_num, const span& col_span); inline const subview_row operator()(const uword row_num, const span& col_span) const; arma_inline subview_col col(const uword col_num); arma_inline const subview_col col(const uword col_num) const; inline subview_col operator()(const span& row_span, const uword col_num); inline const subview_col operator()(const span& row_span, const uword col_num) const; inline Col unsafe_col(const uword col_num); inline const Col unsafe_col(const uword col_num) const; arma_inline subview rows(const uword in_row1, const uword in_row2); arma_inline const subview rows(const uword in_row1, const uword in_row2) const; arma_inline subview cols(const uword in_col1, const uword in_col2); arma_inline const subview cols(const uword in_col1, const uword in_col2) const; inline subview rows(const span& row_span); inline const subview rows(const span& row_span) const; arma_inline subview cols(const span& col_span); arma_inline const subview cols(const span& col_span) const; arma_inline subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); arma_inline const subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; arma_inline subview submat(const uword in_row1, const uword in_col1, const SizeMat& s); arma_inline const subview submat(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline subview submat (const span& row_span, const span& col_span); inline const subview submat (const span& row_span, const span& col_span) const; inline subview operator()(const span& row_span, const span& col_span); inline const subview operator()(const span& row_span, const span& col_span) const; inline subview operator()(const uword in_row1, const uword in_col1, const SizeMat& s); inline const subview operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const; template arma_inline subview_elem1 elem(const Base& a); template arma_inline const subview_elem1 elem(const Base& a) const; template arma_inline subview_elem1 operator()(const Base& a); template arma_inline const subview_elem1 operator()(const Base& a) const; template arma_inline subview_elem2 elem(const Base& ri, const Base& ci); template arma_inline const subview_elem2 elem(const Base& ri, const Base& ci) const; template arma_inline subview_elem2 submat(const Base& ri, const Base& ci); template arma_inline const subview_elem2 submat(const Base& ri, const Base& ci) const; template arma_inline subview_elem2 operator()(const Base& ri, const Base& ci); template arma_inline const subview_elem2 operator()(const Base& ri, const Base& ci) const; template arma_inline subview_elem2 rows(const Base& ri); template arma_inline const subview_elem2 rows(const Base& ri) const; template arma_inline subview_elem2 cols(const Base& ci); template arma_inline const subview_elem2 cols(const Base& ci) const; arma_inline subview_each1< Mat, 0 > each_col(); arma_inline subview_each1< Mat, 1 > each_row(); template inline subview_each2< Mat, 0, T1 > each_col(const Base& indices); template inline subview_each2< Mat, 1, T1 > each_row(const Base& indices); arma_inline diagview diag(const sword in_id = 0); arma_inline const diagview diag(const sword in_id = 0) const; inline void swap_rows(const uword in_row1, const uword in_row2); inline void swap_cols(const uword in_col1, const uword in_col2); inline void shed_row(const uword row_num); inline void shed_col(const uword col_num); inline void shed_rows(const uword in_row1, const uword in_row2); inline void shed_cols(const uword in_col1, const uword in_col2); inline void insert_rows(const uword row_num, const uword N, const bool set_to_zero = true); inline void insert_cols(const uword col_num, const uword N, const bool set_to_zero = true); template inline void insert_rows(const uword row_num, const Base& X); template inline void insert_cols(const uword col_num, const Base& X); template inline Mat(const Gen& X); template inline const Mat& operator=(const Gen& X); template inline const Mat& operator+=(const Gen& X); template inline const Mat& operator-=(const Gen& X); template inline const Mat& operator*=(const Gen& X); template inline const Mat& operator%=(const Gen& X); template inline const Mat& operator/=(const Gen& X); template inline Mat(const Op& X); template inline const Mat& operator=(const Op& X); template inline const Mat& operator+=(const Op& X); template inline const Mat& operator-=(const Op& X); template inline const Mat& operator*=(const Op& X); template inline const Mat& operator%=(const Op& X); template inline const Mat& operator/=(const Op& X); template inline Mat(const eOp& X); template inline const Mat& operator=(const eOp& X); template inline const Mat& operator+=(const eOp& X); template inline const Mat& operator-=(const eOp& X); template inline const Mat& operator*=(const eOp& X); template inline const Mat& operator%=(const eOp& X); template inline const Mat& operator/=(const eOp& X); template inline Mat(const mtOp& X); template inline const Mat& operator=(const mtOp& X); template inline const Mat& operator+=(const mtOp& X); template inline const Mat& operator-=(const mtOp& X); template inline const Mat& operator*=(const mtOp& X); template inline const Mat& operator%=(const mtOp& X); template inline const Mat& operator/=(const mtOp& X); template inline Mat(const Glue& X); template inline const Mat& operator=(const Glue& X); template inline const Mat& operator+=(const Glue& X); template inline const Mat& operator-=(const Glue& X); template inline const Mat& operator*=(const Glue& X); template inline const Mat& operator%=(const Glue& X); template inline const Mat& operator/=(const Glue& X); template inline const Mat& operator+=(const Glue& X); template inline const Mat& operator-=(const Glue& X); template inline Mat(const eGlue& X); template inline const Mat& operator=(const eGlue& X); template inline const Mat& operator+=(const eGlue& X); template inline const Mat& operator-=(const eGlue& X); template inline const Mat& operator*=(const eGlue& X); template inline const Mat& operator%=(const eGlue& X); template inline const Mat& operator/=(const eGlue& X); template inline Mat(const mtGlue& X); template inline const Mat& operator=(const mtGlue& X); template inline const Mat& operator+=(const mtGlue& X); template inline const Mat& operator-=(const mtGlue& X); template inline const Mat& operator*=(const mtGlue& X); template inline const Mat& operator%=(const mtGlue& X); template inline const Mat& operator/=(const mtGlue& X); arma_inline arma_warn_unused const eT& at_alt (const uword ii) const; arma_inline arma_warn_unused eT& operator[] (const uword ii); arma_inline arma_warn_unused const eT& operator[] (const uword ii) const; arma_inline arma_warn_unused eT& at (const uword ii); arma_inline arma_warn_unused const eT& at (const uword ii) const; arma_inline arma_warn_unused eT& operator() (const uword ii); arma_inline arma_warn_unused const eT& operator() (const uword ii) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const; arma_inline const Mat& operator++(); arma_inline void operator++(int); arma_inline const Mat& operator--(); arma_inline void operator--(int); arma_inline arma_warn_unused bool is_empty() const; arma_inline arma_warn_unused bool is_vec() const; arma_inline arma_warn_unused bool is_rowvec() const; arma_inline arma_warn_unused bool is_colvec() const; arma_inline arma_warn_unused bool is_square() const; inline arma_warn_unused bool is_finite() const; arma_inline arma_warn_unused bool in_range(const uword ii) const; arma_inline arma_warn_unused bool in_range(const span& x ) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const SizeMat& s) const; arma_inline arma_warn_unused eT* colptr(const uword in_col); arma_inline arma_warn_unused const eT* colptr(const uword in_col) const; arma_inline arma_warn_unused eT* memptr(); arma_inline arma_warn_unused const eT* memptr() const; inline void impl_print(const std::string& extra_text) const; inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const; inline void impl_raw_print(const std::string& extra_text) const; inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const; template inline void copy_size(const Base& X); inline void set_size(const uword in_elem); inline void set_size(const uword in_rows, const uword in_cols); inline void resize(const uword in_elem); inline void resize(const uword in_rows, const uword in_cols); inline void reshape(const uword in_rows, const uword in_cols, const uword dim = 0); template inline const Mat& transform(functor F); template inline const Mat& imbue(functor F); arma_hot inline const Mat& fill(const eT val); template arma_hot inline const Mat& fill(const fill::fill_class& f); inline const Mat& zeros(); inline const Mat& zeros(const uword in_elem); inline const Mat& zeros(const uword in_rows, const uword in_cols); inline const Mat& ones(); inline const Mat& ones(const uword in_elem); inline const Mat& ones(const uword in_rows, const uword in_cols); inline const Mat& randu(); inline const Mat& randu(const uword in_elem); inline const Mat& randu(const uword in_rows, const uword in_cols); inline const Mat& randn(); inline const Mat& randn(const uword in_elem); inline const Mat& randn(const uword in_rows, const uword in_cols); inline const Mat& eye(); inline const Mat& eye(const uword in_rows, const uword in_cols); inline void reset(); template inline void set_real(const Base& X); template inline void set_imag(const Base& X); inline arma_warn_unused eT min() const; inline arma_warn_unused eT max() const; inline eT min(uword& index_of_min_val) const; inline eT max(uword& index_of_max_val) const; inline eT min(uword& row_of_min_val, uword& col_of_min_val) const; inline eT max(uword& row_of_max_val, uword& col_of_max_val) const; inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const; inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const; inline bool load(const std::string name, const file_type type = auto_detect, const bool print_status = true); inline bool load( std::istream& is, const file_type type = auto_detect, const bool print_status = true); inline bool quiet_save(const std::string name, const file_type type = arma_binary) const; inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const; inline bool quiet_load(const std::string name, const file_type type = auto_detect); inline bool quiet_load( std::istream& is, const file_type type = auto_detect); // for container-like functionality typedef eT value_type; typedef uword size_type; typedef eT* iterator; typedef const eT* const_iterator; typedef eT* col_iterator; typedef const eT* const_col_iterator; class row_iterator { public: inline row_iterator(Mat& in_M, const uword in_row); inline eT& operator* (); inline row_iterator& operator++(); inline void operator++(int); inline row_iterator& operator--(); inline void operator--(int); inline bool operator!=(const row_iterator& X) const; inline bool operator==(const row_iterator& X) const; arma_aligned Mat& M; arma_aligned uword row; arma_aligned uword col; }; class const_row_iterator { public: const_row_iterator(const Mat& in_M, const uword in_row); const_row_iterator(const row_iterator& X); inline eT operator*() const; inline const_row_iterator& operator++(); inline void operator++(int); inline const_row_iterator& operator--(); inline void operator--(int); inline bool operator!=(const const_row_iterator& X) const; inline bool operator==(const const_row_iterator& X) const; arma_aligned const Mat& M; arma_aligned uword row; arma_aligned uword col; }; inline iterator begin(); inline const_iterator begin() const; inline const_iterator cbegin() const; inline iterator end(); inline const_iterator end() const; inline const_iterator cend() const; inline col_iterator begin_col(const uword col_num); inline const_col_iterator begin_col(const uword col_num) const; inline col_iterator end_col (const uword col_num); inline const_col_iterator end_col (const uword col_num) const; inline row_iterator begin_row(const uword row_num); inline const_row_iterator begin_row(const uword row_num) const; inline row_iterator end_row (const uword row_num); inline const_row_iterator end_row (const uword row_num) const; inline void clear(); inline bool empty() const; inline uword size() const; inline void swap(Mat& B); inline void steal_mem(Mat& X); //!< don't use this unless you're writing code internal to Armadillo template class fixed; protected: inline void init_cold(); inline void init_warm(uword in_rows, uword in_cols); inline void init(const std::string& text); #if defined(ARMA_USE_CXX11) inline void init(const std::initializer_list& list); #endif template inline void init(const Base& A, const Base& B); inline Mat(const char junk, const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols); inline Mat(const arma_vec_indicator&, const uhword in_vec_state); inline Mat(const arma_vec_indicator&, const uword in_n_rows, const uword in_n_cols, const uhword in_vec_state); inline Mat(const arma_fixed_indicator&, const uword in_n_rows, const uword in_n_cols, const uhword in_vec_state, const eT* in_mem); friend class Cube; friend class glue_join; friend class op_strans; friend class op_htrans; friend class op_resize; public: #ifdef ARMA_EXTRA_MAT_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_PROTO) #endif }; template template class Mat::fixed : public Mat { private: static const uword fixed_n_elem = fixed_n_rows * fixed_n_cols; static const bool use_extra = (fixed_n_elem > arma_config::mat_prealloc); arma_align_mem eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ]; public: typedef fixed Mat_fixed_type; typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_col = (fixed_n_cols == 1) ? true : false; static const bool is_row = (fixed_n_rows == 1) ? true : false; static const uword n_rows = fixed_n_rows; static const uword n_cols = fixed_n_cols; static const uword n_elem = fixed_n_elem; arma_inline fixed(); arma_inline fixed(const fixed& X); template inline fixed(const fill::fill_class& f); template inline fixed(const Base& A); template inline fixed(const Base& A, const Base& B); inline fixed(const eT* aux_mem); inline fixed(const char* text); inline fixed(const std::string& text); using Mat::operator=; using Mat::operator(); #if defined(ARMA_USE_CXX11) inline fixed(const std::initializer_list& list); inline const Mat& operator=(const std::initializer_list& list); #endif arma_inline const Mat& operator=(const fixed& X); arma_inline const Op< Mat_fixed_type, op_htrans > t() const; arma_inline const Op< Mat_fixed_type, op_htrans > ht() const; arma_inline const Op< Mat_fixed_type, op_strans > st() const; arma_inline arma_warn_unused const eT& at_alt (const uword i) const; arma_inline arma_warn_unused eT& operator[] (const uword i); arma_inline arma_warn_unused const eT& operator[] (const uword i) const; arma_inline arma_warn_unused eT& at (const uword i); arma_inline arma_warn_unused const eT& at (const uword i) const; arma_inline arma_warn_unused eT& operator() (const uword i); arma_inline arma_warn_unused const eT& operator() (const uword i) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT* colptr(const uword in_col); arma_inline arma_warn_unused const eT* colptr(const uword in_col) const; arma_inline arma_warn_unused eT* memptr(); arma_inline arma_warn_unused const eT* memptr() const; arma_inline arma_warn_unused bool is_vec() const; arma_hot inline const Mat& fill(const eT val); arma_hot inline const Mat& zeros(); arma_hot inline const Mat& ones(); }; class Mat_aux { public: template arma_inline static void prefix_pp(Mat& x); template arma_inline static void prefix_pp(Mat< std::complex >& x); template arma_inline static void postfix_pp(Mat& x); template arma_inline static void postfix_pp(Mat< std::complex >& x); template arma_inline static void prefix_mm(Mat& x); template arma_inline static void prefix_mm(Mat< std::complex >& x); template arma_inline static void postfix_mm(Mat& x); template arma_inline static void postfix_mm(Mat< std::complex >& x); template inline static void set_real(Mat& out, const Base& X); template inline static void set_real(Mat< std::complex >& out, const Base< T,T1>& X); template inline static void set_imag(Mat& out, const Base& X); template inline static void set_imag(Mat< std::complex >& out, const Base< T,T1>& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_randn.hpp0000644000176000001440000000526712246034243022730 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_randn //! @{ inline double randn() { return double(arma_rng::randn()); } template inline typename arma_scalar_only::result randn() { return eT(arma_rng::randn()); } //! Generate a vector with all elements set to random values with a gaussian distribution (zero mean, unit variance) arma_inline const Gen randn(const uword n_elem) { arma_extra_debug_sigprint(); return Gen(n_elem, 1); } template arma_inline const Gen randn(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only::result* junk2 = 0) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_Row::value == true) { return Gen(1, n_elem); } else { return Gen(n_elem, 1); } } //! Generate a dense matrix with all elements set to random values with a gaussian distribution (zero mean, unit variance) arma_inline const Gen randn(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return Gen(n_rows, n_cols); } template arma_inline const Gen randn(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_Col::value == true) { arma_debug_check( (n_cols != 1), "randn(): incompatible size" ); } else if(is_Row::value == true) { arma_debug_check( (n_rows != 1), "randn(): incompatible size" ); } return Gen(n_rows, n_cols); } arma_inline const GenCube randn(const uword n_rows, const uword n_cols, const uword n_slices) { arma_extra_debug_sigprint(); return GenCube(n_rows, n_cols, n_slices); } template arma_inline const GenCube randn(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(n_rows, n_cols, n_slices); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_symmat.hpp0000644000176000001440000000134012200375542023124 0ustar ripleyusers// Copyright (C) 2011 Conrad Sanderson // Copyright (C) 2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_symmat //! @{ template arma_inline const Op symmatu(const Base& X) { arma_extra_debug_sigprint(); return Op(X.get_ref(), 0, 0); } template arma_inline const Op symmatl(const Base& X) { arma_extra_debug_sigprint(); return Op(X.get_ref(), 1, 0); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_toeplitz.hpp0000644000176000001440000000176412200375542023476 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_toeplitz //! @{ template inline Op toeplitz(const Base& X) { arma_extra_debug_sigprint(); return Op( X.get_ref() ); } template inline Op circ_toeplitz(const Base& X) { arma_extra_debug_sigprint(); return Op( X.get_ref() ); } template inline Glue toeplitz(const Base& X, const Base& Y) { arma_extra_debug_sigprint(); return Glue( X.get_ref(), Y.get_ref() ); } //! @} RcppArmadillo/inst/include/armadillo_bits/xvec_htrans_bones.hpp0000644000176000001440000000177312154035132024647 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup xvec_htrans //! @{ template class xvec_htrans : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = false; arma_aligned const eT* const mem; const uword n_rows; const uword n_cols; const uword n_elem; inline explicit xvec_htrans(const eT* const in_mem, const uword in_n_rows, const uword in_n_cols); inline void extract(Mat& out) const; inline eT operator[](const uword ii) const; inline eT at_alt (const uword ii) const; inline eT at (const uword in_row, const uword in_col) const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/typedef_mat.hpp0000644000176000001440000000553012246641052023437 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup typedef_mat //! @{ typedef Mat uchar_mat; typedef Col uchar_vec; typedef Col uchar_colvec; typedef Row uchar_rowvec; typedef Cube uchar_cube; typedef Mat u32_mat; typedef Col u32_vec; typedef Col u32_colvec; typedef Row u32_rowvec; typedef Cube u32_cube; typedef Mat s32_mat; typedef Col s32_vec; typedef Col s32_colvec; typedef Row s32_rowvec; typedef Cube s32_cube; #if defined(ARMA_USE_U64S64) typedef Mat u64_mat; typedef Col u64_vec; typedef Col u64_colvec; typedef Row u64_rowvec; typedef Cube u64_cube; typedef Mat s64_mat; typedef Col s64_vec; typedef Col s64_colvec; typedef Row s64_rowvec; typedef Cube s64_cube; #endif typedef Mat umat; typedef Col uvec; typedef Col ucolvec; typedef Row urowvec; typedef Cube ucube; typedef Mat imat; typedef Col ivec; typedef Col icolvec; typedef Row irowvec; typedef Cube icube; typedef Mat fmat; typedef Col fvec; typedef Col fcolvec; typedef Row frowvec; typedef Cube fcube; typedef Mat mat; typedef Col vec; typedef Col colvec; typedef Row rowvec; typedef Cube cube; typedef Mat cx_fmat; typedef Col cx_fvec; typedef Col cx_fcolvec; typedef Row cx_frowvec; typedef Cube cx_fcube; typedef Mat cx_mat; typedef Col cx_vec; typedef Col cx_colvec; typedef Row cx_rowvec; typedef Cube cx_cube; typedef SpMat sp_umat; typedef SpCol sp_uvec; typedef SpCol sp_ucolvec; typedef SpRow sp_urowvec; typedef SpMat sp_imat; typedef SpCol sp_ivec; typedef SpCol sp_icolvec; typedef SpRow sp_irowvec; typedef SpMat sp_fmat; typedef SpCol sp_fvec; typedef SpCol sp_fcolvec; typedef SpRow sp_frowvec; typedef SpMat sp_mat; typedef SpCol sp_vec; typedef SpCol sp_colvec; typedef SpRow sp_rowvec; typedef SpMat sp_cx_fmat; typedef SpCol sp_cx_fvec; typedef SpCol sp_cx_fcolvec; typedef SpRow sp_cx_frowvec; typedef SpMat sp_cx_mat; typedef SpCol sp_cx_vec; typedef SpCol sp_cx_colvec; typedef SpRow sp_cx_rowvec; //! @} RcppArmadillo/inst/include/armadillo_bits/op_relational_bones.hpp0000644000176000001440000000603612200631217025146 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_relational //! @{ class op_rel_lt_pre { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_lt_post { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_gt_pre { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_gt_post { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_lteq_pre { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_lteq_post { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_gteq_pre { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_gteq_post { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_eq { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_noteq { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/arrayops_meat.hpp0000644000176000001440000004344012260435137024007 0ustar ripleyusers// Copyright (C) 2011-2013 Conrad Sanderson // Copyright (C) 2011-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup arrayops //! @{ template arma_hot arma_inline void arrayops::copy(eT* dest, const eT* src, const uword n_elem) { if(n_elem <= 16) { arrayops::copy_small(dest, src, n_elem); } else { std::memcpy(dest, src, n_elem*sizeof(eT)); } } template arma_hot inline void arrayops::copy_small(eT* dest, const eT* src, const uword n_elem) { switch(n_elem) { case 16: dest[15] = src[15]; case 15: dest[14] = src[14]; case 14: dest[13] = src[13]; case 13: dest[12] = src[12]; case 12: dest[11] = src[11]; case 11: dest[10] = src[10]; case 10: dest[ 9] = src[ 9]; case 9: dest[ 8] = src[ 8]; case 8: dest[ 7] = src[ 7]; case 7: dest[ 6] = src[ 6]; case 6: dest[ 5] = src[ 5]; case 5: dest[ 4] = src[ 4]; case 4: dest[ 3] = src[ 3]; case 3: dest[ 2] = src[ 2]; case 2: dest[ 1] = src[ 1]; case 1: dest[ 0] = src[ 0]; default: ; } } template arma_hot inline void arrayops::copy_forwards(eT* dest, const eT* src, const uword n_elem) { // can't use std::memcpy(), as we don't know how it copies data uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { dest[i] = src[i]; dest[j] = src[j]; } if(i < n_elem) { dest[i] = src[i]; } } // template // arma_hot // inline // void // arrayops::copy_backwards(eT* dest, const eT* src, const uword n_elem) // { // // can't use std::memcpy(), as we don't know how it copies data // // switch(n_elem) // { // default: // for(uword i = (n_elem-1); i >= 1; --i) { dest[i] = src[i]; } // // NOTE: the 'break' statement has been deliberately omitted // case 1: // dest[0] = src[0]; // case 0: // ; // } // } template arma_hot inline void arrayops::copy_backwards(eT* dest, const eT* src, const uword n_elem) { // can't use std::memcpy(), as we don't know how it copies data switch(n_elem) { default: { uword i, j; for(i = (n_elem-1), j = (n_elem-2); j >= 2; i-=2, j-=2) { const eT tmp_i = src[i]; const eT tmp_j = src[j]; dest[i] = tmp_i; dest[j] = tmp_j; } // j is less than 2: it can be 1 or 0 // i is j+1, ie. less than 3: it can be 2 or 1 if(i == 2) { dest[2] = src[2]; } } // NOTE: the 'break' statement has been deliberately omitted case 2: dest[1] = src[1]; case 1: dest[0] = src[0]; case 0: ; } } template arma_hot inline void arrayops::fill_zeros(eT* dest, const uword n_elem) { typedef typename get_pod_type::result pod_type; if( (n_elem >= 16) && (std::numeric_limits::is_integer || (std::numeric_limits::is_iec559 && is_real::value)) ) { std::memset(dest, 0, sizeof(eT)*n_elem); } else { arrayops::inplace_set(dest, eT(0), n_elem); } } template arma_hot arma_inline void arrayops::convert_cx_scalar ( out_eT& out, const in_eT& in, const typename arma_not_cx::result* junk1, const typename arma_not_cx< in_eT>::result* junk2 ) { arma_ignore(junk1); arma_ignore(junk2); out = out_eT(in); } template arma_hot arma_inline void arrayops::convert_cx_scalar ( out_eT& out, const std::complex& in, const typename arma_not_cx::result* junk ) { arma_ignore(junk); out = out_eT( in.real() ); } template arma_hot arma_inline void arrayops::convert_cx_scalar ( std::complex& out, const std::complex< in_T>& in ) { typedef std::complex out_eT; out = out_eT(in); } template arma_hot inline void arrayops::convert(out_eT* dest, const in_eT* src, const uword n_elem) { uword i,j; for(i=0, j=1; j::value) ? out_eT( tmp_i ) : ( cond_rel< is_signed::value >::lt(tmp_i, in_eT(0)) ? out_eT(0) : out_eT(tmp_i) ); dest[j] = (is_signed::value) ? out_eT( tmp_j ) : ( cond_rel< is_signed::value >::lt(tmp_j, in_eT(0)) ? out_eT(0) : out_eT(tmp_j) ); } if(i < n_elem) { const in_eT tmp_i = src[i]; // dest[i] = out_eT( tmp_i ); dest[i] = (is_signed::value) ? out_eT( tmp_i ) : ( cond_rel< is_signed::value >::lt(tmp_i, in_eT(0)) ? out_eT(0) : out_eT(tmp_i) ); } } template arma_hot inline void arrayops::convert_cx(out_eT* dest, const in_eT* src, const uword n_elem) { uword i,j; for(i=0, j=1; j arma_hot inline void arrayops::inplace_plus(eT* dest, const eT* src, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_plus_base(dest, src, n_elem); } else { arrayops::inplace_plus_base(dest, src, n_elem); } } else { if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_plus_base(dest, src, n_elem); } else { arrayops::inplace_plus_base(dest, src, n_elem); } } } template arma_hot inline void arrayops::inplace_minus(eT* dest, const eT* src, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_minus_base(dest, src, n_elem); } else { arrayops::inplace_minus_base(dest, src, n_elem); } } else { if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_minus_base(dest, src, n_elem); } else { arrayops::inplace_minus_base(dest, src, n_elem); } } } template arma_hot inline void arrayops::inplace_mul(eT* dest, const eT* src, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_mul_base(dest, src, n_elem); } else { arrayops::inplace_mul_base(dest, src, n_elem); } } else { if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_mul_base(dest, src, n_elem); } else { arrayops::inplace_mul_base(dest, src, n_elem); } } } template arma_hot inline void arrayops::inplace_div(eT* dest, const eT* src, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_div_base(dest, src, n_elem); } else { arrayops::inplace_div_base(dest, src, n_elem); } } else { if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_div_base(dest, src, n_elem); } else { arrayops::inplace_div_base(dest, src, n_elem); } } } template arma_hot inline void arrayops::inplace_plus_base(eT* dest, const eT* src, const uword n_elem) { uword i,j; for(i=0, j=1; j arma_hot inline void arrayops::inplace_minus_base(eT* dest, const eT* src, const uword n_elem) { uword i,j; for(i=0, j=1; j arma_hot inline void arrayops::inplace_mul_base(eT* dest, const eT* src, const uword n_elem) { uword i,j; for(i=0, j=1; j arma_hot inline void arrayops::inplace_div_base(eT* dest, const eT* src, const uword n_elem) { uword i,j; for(i=0, j=1; j arma_hot inline void arrayops::inplace_set(eT* dest, const eT val, const uword n_elem) { if(n_elem <= 16) { arrayops::inplace_set_small(dest, val, n_elem); } else { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); uword i,j; for(i=0, j=1; j arma_hot inline void arrayops::inplace_set_small(eT* dest, const eT val, const uword n_elem) { switch(n_elem) { case 16: dest[15] = val; case 15: dest[14] = val; case 14: dest[13] = val; case 13: dest[12] = val; case 12: dest[11] = val; case 11: dest[10] = val; case 10: dest[ 9] = val; case 9: dest[ 8] = val; case 8: dest[ 7] = val; case 7: dest[ 6] = val; case 6: dest[ 5] = val; case 5: dest[ 4] = val; case 4: dest[ 3] = val; case 3: dest[ 2] = val; case 2: dest[ 1] = val; case 1: dest[ 0] = val; default:; } } template arma_hot inline void arrayops::inplace_set_fixed(eT* dest, const eT val) { for(uword i=0; i arma_hot inline void arrayops::inplace_plus(eT* dest, const eT val, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); uword i,j; for(i=0, j=1; j arma_hot inline void arrayops::inplace_minus(eT* dest, const eT val, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); uword i,j; for(i=0, j=1; j arma_hot inline void arrayops::inplace_mul(eT* dest, const eT val, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); uword i,j; for(i=0, j=1; j arma_hot inline void arrayops::inplace_div(eT* dest, const eT val, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); uword i,j; for(i=0, j=1; j arma_hot arma_pure inline eT arrayops::accumulate(const eT* src, const uword n_elem) { uword i,j; eT acc1 = eT(0); eT acc2 = eT(0); for(i=0, j=1; j arma_hot arma_pure inline eT arrayops::product(const eT* src, const uword n_elem) { eT val1 = eT(1); eT val2 = eT(1); uword i,j; for(i=0, j=1; j arma_hot arma_pure inline bool arrayops::is_finite(const eT* src, const uword n_elem) { uword i,j; for(i=0, j=1; j arma_hot arma_pure inline typename get_pod_type::result arrayops::norm_1(const eT* src, const uword n_elem) { typedef typename get_pod_type::result T; T acc = T(0); uword i,j; for(i=0, j=1; j arma_hot arma_pure inline eT arrayops::norm_2(const eT* src, const uword n_elem, const typename arma_not_cx::result* junk) { arma_ignore(junk); eT acc = eT(0); uword i,j; for(i=0, j=1; j arma_hot arma_pure inline T arrayops::norm_2(const std::complex* src, const uword n_elem) { T acc = T(0); uword i,j; for(i=0, j=1; j arma_hot arma_pure inline typename get_pod_type::result arrayops::norm_k(const eT* src, const uword n_elem, const int k) { typedef typename get_pod_type::result T; T acc = T(0); uword i,j; for(i=0, j=1; j arma_hot arma_pure inline typename get_pod_type::result arrayops::norm_max(const eT* src, const uword n_elem) { typedef typename get_pod_type::result T; T max_val = std::abs(src[0]); uword i,j; for(i=1, j=2; j arma_hot arma_pure inline typename get_pod_type::result arrayops::norm_min(const eT* src, const uword n_elem) { typedef typename get_pod_type::result T; T min_val = std::abs(src[0]); uword i,j; for(i=1, j=2; j tmp_i) { min_val = tmp_i; } if(min_val > tmp_j) { min_val = tmp_j; } } if(i < n_elem) { const T tmp_i = std::abs(src[i]); if(min_val > tmp_i) { min_val = tmp_i; } } return min_val; } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_histc_bones.hpp0000644000176000001440000000075612256562725024471 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Boris Sabanin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. class glue_histc { public: template inline static void apply(Mat& out, const mtGlue& in); }; RcppArmadillo/inst/include/armadillo_bits/arma_rng.hpp0000644000176000001440000001337012246630413022724 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup arma_rng //! @{ #if defined(ARMA_USE_CXX11_RNG) extern thread_local arma_rng_cxx11 arma_rng_cxx11_instance; // thread_local arma_rng_cxx11 arma_rng_cxx11_instance; #endif class arma_rng { public: #if defined(ARMA_USE_CXX11_RNG) typedef arma_rng_cxx11::seed_type seed_type; #else typedef arma_rng_cxx98::seed_type seed_type; #endif #if defined(ARMA_USE_CXX11_RNG) static const int rng_method = 1; #else static const int rng_method = 0; #endif inline static void set_seed(const seed_type val); inline static void set_seed_random(); template struct randi; template struct randu; template struct randn; }; inline void arma_rng::set_seed(const arma_rng::seed_type val) { #if defined(ARMA_USE_CXX11_RNG) { arma_rng_cxx11_instance.set_seed(val); } #else { arma_rng_cxx98::set_seed(val); } #endif } inline void arma_rng::set_seed_random() { seed_type seed1 = seed_type(0); seed_type seed2 = seed_type(0); seed_type seed3 = seed_type(0); seed_type seed4 = seed_type(0); seed_type seed5 = seed_type(0); bool rd_ok = false; #if defined(ARMA_USE_CXX11) { try { std::random_device rd; seed1 = static_cast( rd() ); rd_ok = true; } catch(...) {} } #endif if(rd_ok == false) { try { unsigned char buffer = 0; std::ifstream f("/dev/urandom", std::ifstream::binary); f.read((char*)(&buffer), 1); seed2 = static_cast(buffer); } catch(...) {} // get better-than-nothing seeds in case reading /dev/urandom failed #if defined(ARMA_HAVE_GETTIMEOFDAY) { struct timeval posix_time; gettimeofday(&posix_time, 0); seed3 = static_cast(posix_time.tv_usec); } #endif seed4 = static_cast( std::time(NULL) & 0xFFFF ); union { uword* a; unsigned char b[sizeof(uword*)]; } address; uword junk = 0; address.a = &junk; seed5 = seed_type(address.b[0]) + seed_type(address.b[sizeof(uword*)-1]); } arma_rng::set_seed( seed1 + seed2 + seed3 + seed4 + seed5 ); } template struct arma_rng::randi { arma_inline operator eT () { #if defined(ARMA_USE_CXX11_RNG) { return eT( arma_rng_cxx11_instance.randi_val() ); } #else { return eT( arma_rng_cxx98::randi_val() ); } #endif } inline static int max_val() { #if defined(ARMA_USE_CXX11_RNG) { return arma_rng_cxx11::randi_max_val(); } #else { return arma_rng_cxx98::randi_max_val(); } #endif } inline static void fill(eT* mem, const uword N, const int a, const int b) { #if defined(ARMA_USE_CXX11_RNG) { return arma_rng_cxx11_instance.randi_fill(mem, N, a, b); } #else { return arma_rng_cxx98::randi_fill(mem, N, a, b); } #endif } }; template struct arma_rng::randu { arma_inline operator eT () { #if defined(ARMA_USE_CXX11_RNG) { return eT( arma_rng_cxx11_instance.randu_val() ); } #else { return eT( arma_rng_cxx98::randu_val() ); } #endif } inline static void fill(eT* mem, const uword N) { uword i,j; for(i=0, j=1; j < N; i+=2, j+=2) { const eT tmp_i = eT( arma_rng::randu() ); const eT tmp_j = eT( arma_rng::randu() ); mem[i] = tmp_i; mem[j] = tmp_j; } if(i < N) { mem[i] = eT( arma_rng::randu() ); } } }; template struct arma_rng::randu< std::complex > { arma_inline operator std::complex () { return std::complex( T( arma_rng::randu() ), T( arma_rng::randu() ) ); } inline static void fill(std::complex* mem, const uword N) { for(uword i=0; i < N; ++i) { mem[i] = std::complex( T( arma_rng::randu() ), T( arma_rng::randu() ) ); } } }; template struct arma_rng::randn { inline operator eT () const { #if defined(ARMA_USE_CXX11_RNG) { return eT( arma_rng_cxx11_instance.randn_val() ); } #else { return eT( arma_rng_cxx98::randn_val() ); } #endif } arma_inline static void dual_val(eT& out1, eT& out2) { #if defined(ARMA_USE_CXX11_RNG) { arma_rng_cxx11_instance.randn_dual_val(out1, out2); } #else { arma_rng_cxx98::randn_dual_val(out1, out2); } #endif } inline static void fill(eT* mem, const uword N) { uword i, j; for(i=0, j=1; j < N; i+=2, j+=2) { arma_rng::randn::dual_val( mem[i], mem[j] ); } if(i < N) { mem[i] = eT( arma_rng::randn() ); } } }; template struct arma_rng::randn< std::complex > { inline operator std::complex () const { T a, b; arma_rng::randn::dual_val(a, b); return std::complex(a, b); } inline static void fill(std::complex* mem, const uword N) { for(uword i=0; i < N; ++i) { mem[i] = std::complex( arma_rng::randn< std::complex >() ); } } }; //! @} RcppArmadillo/inst/include/armadillo_bits/compiler_setup.hpp0000644000176000001440000002020612265635355024177 0ustar ripleyusers// Copyright (C) 2008-2014 Conrad Sanderson // Copyright (C) 2008-2014 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #define arma_hot #define arma_cold #define arma_pure #define arma_const #define arma_aligned #define arma_align_mem #define arma_warn_unused #define arma_deprecated #define arma_malloc #define arma_inline inline #define arma_noinline #define arma_ignore(variable) ((void)(variable)) #if defined(ARMA_BLAS_UNDERSCORE) #define arma_fortran2_noprefix(function) function##_ #define arma_fortran2_prefix(function) wrapper_##function##_ #else #define arma_fortran2_noprefix(function) function #define arma_fortran2_prefix(function) wrapper_##function #endif #if defined(ARMA_USE_WRAPPER) #define arma_fortran(function) arma_fortran2_prefix(function) #define arma_atlas(function) wrapper_##function #else #define arma_fortran(function) arma_fortran2_noprefix(function) #define arma_atlas(function) function #endif #define arma_fortran_prefix(function) arma_fortran2_prefix(function) #define arma_fortran_noprefix(function) arma_fortran2_noprefix(function) #define ARMA_INCFILE_WRAP(x) #if (__cplusplus >= 201103L) #if !defined(ARMA_USE_CXX11) #define ARMA_USE_CXX11 #endif #endif #if defined(ARMA_USE_CXX11) #if !defined(ARMA_USE_U64S64) #define ARMA_USE_U64S64 #endif #endif #if defined(ARMA_64BIT_WORD) #if !defined(ARMA_USE_U64S64) #define ARMA_USE_U64S64 #endif #endif #if (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) #define ARMA_HAVE_GETTIMEOFDAY #if defined(__GNUG__) #define ARMA_HAVE_SNPRINTF #define ARMA_HAVE_ISFINITE #define ARMA_HAVE_LOG1P #endif #endif // posix_memalign() is part of IEEE standard 1003.1 // http://pubs.opengroup.org/onlinepubs/009696899/functions/posix_memalign.html // http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html // http://sourceforge.net/p/predef/wiki/Standards/ #if ( defined(_POSIX_ADVISORY_INFO) && (_POSIX_ADVISORY_INFO >= 200112L) ) #define ARMA_HAVE_POSIX_MEMALIGN #endif #if defined(__APPLE__) #define ARMA_BLAS_SDOT_BUG #undef ARMA_HAVE_POSIX_MEMALIGN #endif #if defined(__MINGW32__) #undef ARMA_HAVE_POSIX_MEMALIGN #endif #if defined (__GNUG__) #define ARMA_FNSIG __PRETTY_FUNCTION__ #elif defined (_MSC_VER) #define ARMA_FNSIG __FUNCSIG__ #elif defined(__INTEL_COMPILER) #define ARMA_FNSIG __FUNCTION__ #elif defined(ARMA_USE_CXX11) #define ARMA_FNSIG __func__ #else #define ARMA_FNSIG "(unknown)" #endif #if defined(__INTEL_COMPILER) #if (__INTEL_COMPILER_BUILD_DATE < 20090623) #error "*** Need a newer compiler ***" #endif #define ARMA_HAVE_ICC_ASSUME_ALIGNED #endif #if defined(__GNUG__) #define ARMA_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #if (ARMA_GCC_VERSION < 40200) #error "*** Need a newer compiler ***" #endif #if ( (ARMA_GCC_VERSION >= 40700) && (ARMA_GCC_VERSION <= 40701) ) && !defined(__INTEL_COMPILER) #error "gcc versions 4.7.0 and 4.7.1 are unsupported; use 4.7.2 or later" // due to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53549 #endif #define ARMA_GOOD_COMPILER #undef ARMA_HAVE_TR1 #undef arma_pure #undef arma_const #undef arma_aligned #undef arma_align_mem #undef arma_warn_unused #undef arma_deprecated #undef arma_malloc #undef arma_inline #undef arma_noinline #define arma_pure __attribute__((__pure__)) #define arma_const __attribute__((__const__)) #define arma_aligned __attribute__((__aligned__)) #define arma_align_mem __attribute__((__aligned__(16))) #define arma_warn_unused __attribute__((__warn_unused_result__)) #define arma_deprecated __attribute__((__deprecated__)) #define arma_malloc __attribute__((__malloc__)) #define arma_inline inline __attribute__((__always_inline__)) #define arma_noinline __attribute__((__noinline__)) #define ARMA_HAVE_ALIGNED_ATTRIBUTE #if defined(__GXX_EXPERIMENTAL_CXX0X__) #if !defined(ARMA_USE_CXX11) #define ARMA_USE_CXX11 #endif #endif #if defined(ARMA_USE_CXX11) #if (ARMA_GCC_VERSION < 40700) && !defined(__clang__) #pragma message ("Your C++ compiler is in C++11 mode, but it has incomplete support for C++11 features") #endif #endif #if !defined(ARMA_USE_CXX11) #if defined(_GLIBCXX_USE_C99_MATH_TR1) && defined(_GLIBCXX_USE_C99_COMPLEX_TR1) #define ARMA_HAVE_TR1 #endif #endif #if (ARMA_GCC_VERSION >= 40300) #undef arma_hot #undef arma_cold #define arma_hot __attribute__((__hot__)) #define arma_cold __attribute__((__cold__)) #endif #if (ARMA_GCC_VERSION >= 40700) #define ARMA_HAVE_GCC_ASSUME_ALIGNED #endif #if defined(__clang__) #undef ARMA_HAVE_TR1 #undef ARMA_HAVE_GCC_ASSUME_ALIGNED // TODO: future versions of clang may also have __builtin_assume_aligned #endif #if defined(__INTEL_COMPILER) #undef ARMA_HAVE_TR1 #undef ARMA_HAVE_GCC_ASSUME_ALIGNED #endif #undef ARMA_GCC_VERSION #endif #if defined(_MSC_VER) #if (_MSC_VER < 1600) #error "*** Need a newer compiler ***" #endif #undef ARMA_GOOD_COMPILER #undef ARMA_HAVE_SNPRINTF #undef ARMA_HAVE_ISFINITE #undef ARMA_HAVE_LOG1P #undef ARMA_HAVE_TR1 // #undef arma_inline // #define arma_inline inline __forceinline #pragma warning(push) #pragma warning(disable: 4127) // conditional expression is constant #pragma warning(disable: 4510) // default constructor could not be generated #pragma warning(disable: 4511) // copy constructor can't be generated #pragma warning(disable: 4512) // assignment operator can't be generated #pragma warning(disable: 4513) // destructor can't be generated #pragma warning(disable: 4514) // unreferenced inline function has been removed #pragma warning(disable: 4522) // multiple assignment operators specified #pragma warning(disable: 4623) // default constructor can't be generated #pragma warning(disable: 4624) // destructor can't be generated #pragma warning(disable: 4625) // copy constructor can't be generated #pragma warning(disable: 4626) // assignment operator can't be generated #pragma warning(disable: 4710) // function not inlined #pragma warning(disable: 4711) // call was inlined #pragma warning(disable: 4714) // __forceinline can't be inlined // #if (_MANAGED == 1) || (_M_CEE == 1) // // // don't do any alignment when compiling in "managed code" mode // // #undef arma_aligned // #define arma_aligned // // #undef arma_align_mem // #define arma_align_mem // // #elif (_MSC_VER >= 1700) // // #undef arma_align_mem // #define arma_align_mem __declspec(align(16)) // // #define ARMA_HAVE_ALIGNED_ATTRIBUTE // // // disable warnings: "structure was padded due to __declspec(align(16))" // #pragma warning(disable: 4324) // // #endif #endif #if defined(__SUNPRO_CC) // http://www.oracle.com/technetwork/server-storage/solarisstudio/training/index-jsp-141991.html // http://www.oracle.com/technetwork/server-storage/solarisstudio/documentation/cplusplus-faq-355066.html #if (__SUNPRO_CC < 0x5100) #error "*** Need a newer compiler ***" #endif #undef ARMA_HAVE_SNPRINTF #undef ARMA_HAVE_ISFINITE #undef ARMA_HAVE_LOG1P #undef ARMA_HAVE_TR1 #endif #if defined(__CUDACC__) #undef ARMA_HAVE_SNPRINTF #undef ARMA_HAVE_ISFINITE #undef ARMA_HAVE_LOG1P #undef ARMA_HAVE_TR1 #endif #if defined(log2) #undef log2 #pragma message ("detected 'log2' macro and undefined it") #endif // // whoever defined macros with the names "min" and "max" should be permanently removed from the gene pool #if defined(min) || defined(max) #undef min #undef max #pragma message ("detected 'min' and/or 'max' macros and undefined them; you may wish to define NOMINMAX before including any windows header") #endif RcppArmadillo/inst/include/armadillo_bits/eOpCube_meat.hpp0000644000176000001440000000644412176655102023476 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup eOpCube //! @{ template eOpCube::eOpCube(const BaseCube& in_m) : P (in_m.get_ref()) { arma_extra_debug_sigprint(); } template eOpCube::eOpCube(const BaseCube& in_m, const typename T1::elem_type in_aux) : P (in_m.get_ref()) , aux (in_aux) { arma_extra_debug_sigprint(); } template eOpCube::eOpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : P (in_m.get_ref()) , aux_uword_a (in_aux_uword_a) , aux_uword_b (in_aux_uword_b) { arma_extra_debug_sigprint(); } template eOpCube::eOpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : P (in_m.get_ref()) , aux_uword_a (in_aux_uword_a) , aux_uword_b (in_aux_uword_b) , aux_uword_c (in_aux_uword_c) { arma_extra_debug_sigprint(); } template eOpCube::eOpCube(const BaseCube& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : P (in_m.get_ref()) , aux (in_aux) , aux_uword_a (in_aux_uword_a) , aux_uword_b (in_aux_uword_b) , aux_uword_c (in_aux_uword_c) { arma_extra_debug_sigprint(); } template eOpCube::~eOpCube() { arma_extra_debug_sigprint(); } template arma_inline uword eOpCube::get_n_rows() const { return P.get_n_rows(); } template arma_inline uword eOpCube::get_n_cols() const { return P.get_n_cols(); } template arma_inline uword eOpCube::get_n_elem_slice() const { return P.get_n_elem_slice(); } template arma_inline uword eOpCube::get_n_slices() const { return P.get_n_slices(); } template arma_inline uword eOpCube::get_n_elem() const { return P.get_n_elem(); } template arma_inline typename T1::elem_type eOpCube::operator[] (const uword i) const { return eop_core::process(P[i], aux); } template arma_inline typename T1::elem_type eOpCube::at(const uword row, const uword col, const uword slice) const { return eop_core::process(P.at(row, col, slice), aux); } template arma_inline typename T1::elem_type eOpCube::at_alt(const uword i) const { return eop_core::process(P.at_alt(i), aux); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_sort.hpp0000644000176000001440000000444512254740076022621 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_sort //! @{ //! kept for compatibility with old code template arma_inline typename enable_if2 < ( (is_arma_type::value == true) && (resolves_to_vector::value == false) ), const Op >::result sort ( const T1& X, const uword sort_type = 0, const uword dim = 0 ) { arma_extra_debug_sigprint(); return Op(X, sort_type, dim); } template arma_inline typename enable_if2 < ( (is_arma_type::value == true) && (resolves_to_vector::value == false) && (is_same_type::value) ), const Op >::result sort ( const T1& X, const T2* sort_direction, const uword dim = 0 ) { arma_extra_debug_sigprint(); const char sig = sort_direction[0]; arma_debug_check( (sig != 'a') && (sig != 'd'), "sort(): unknown sort direction"); const uword sort_type = (sig == 'a') ? 0 : 1; return Op(X, sort_type, dim); } //! kept for compatibility with old code template arma_inline typename enable_if2 < ( (is_arma_type::value == true) && (resolves_to_vector::value == true) ), const Op >::result sort ( const T1& X, const uword sort_type = 0 ) { arma_extra_debug_sigprint(); const uword dim = (T1::is_col) ? 0 : 1; return Op(X, sort_type, dim); } template arma_inline typename enable_if2 < ( (is_arma_type::value == true) && (resolves_to_vector::value == true) && (is_same_type::value) ), const Op >::result sort ( const T1& X, const T2* sort_direction ) { arma_extra_debug_sigprint(); const char sig = sort_direction[0]; arma_debug_check( (sig != 'a') && (sig != 'd'), "sort(): unknown sort direction"); const uword sort_type = (sig == 'a') ? 0 : 1; const uword dim = (T1::is_col) ? 0 : 1; return Op(X, sort_type, dim); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_log_det.hpp0000644000176000001440000000347712200375542023244 0ustar ripleyusers// Copyright (C) 2010-2011 Conrad Sanderson // Copyright (C) 2010-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_log_det //! @{ //! log determinant of mat template inline bool log_det ( typename T1::elem_type& out_val, typename T1::pod_type& out_sign, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return auxlib::log_det(out_val, out_sign, X); } template inline void log_det ( typename T1::elem_type& out_val, typename T1::pod_type& out_sign, const Op& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; const diagmat_proxy A(X.m); const uword N = A.n_elem; if(N == 0) { out_val = eT(0); out_sign = T(1); return; } eT x = A[0]; T sign = (is_complex::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1; eT val = (is_complex::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x); for(uword i=1; i::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1; val += (is_complex::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x); } out_val = val; out_sign = sign; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_cor_bones.hpp0000644000176000001440000000146312200631217023576 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_cor //! @{ class op_cor { public: template inline static void direct_cor(Mat& out, const Mat& X, const uword norm_type); template inline static void direct_cor(Mat< std::complex >& out, const Mat< std::complex >& X, const uword norm_type); template inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/GlueCube_bones.hpp0000644000176000001440000000163212176655102024021 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup GlueCube //! @{ //! analog of the Glue class, intended for Cube objects template class GlueCube : public BaseCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; arma_inline GlueCube(const BaseCube& in_A, const BaseCube& in_B); arma_inline ~GlueCube(); const T1& A; //!< first operand const T2& B; //!< second operand }; //! @} RcppArmadillo/inst/include/armadillo_bits/spop_htrans_bones.hpp0000644000176000001440000000145112111344723024656 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_htrans //! @{ //! 'hermitian transpose' operation class spop_htrans { public: // handling of sparse matrices template arma_hot inline static void apply(SpMat& out, const SpOp& in, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply(SpMat& out, const SpOp& in, const typename arma_cx_only::result* junk = 0); }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_mean_bones.hpp0000644000176000001440000000316412200631217023733 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_mean //! @{ //! Class for finding mean values of a matrix class op_mean { public: template inline static void apply(Mat& out, const Op& in); // template inline static eT direct_mean(const eT* const X, const uword N); template inline static eT direct_mean_robust(const eT* const X, const uword N); // template inline static eT direct_mean(const Mat& X, const uword row); template inline static eT direct_mean_robust(const Mat& X, const uword row); // template inline static eT mean_all(const subview& X); template inline static eT mean_all_robust(const subview& X); // template inline static eT mean_all(const diagview& X); template inline static eT mean_all_robust(const diagview& X); // template inline static typename T1::elem_type mean_all(const Base& X); // template arma_inline static eT robust_mean(const eT A, const eT B); template arma_inline static std::complex robust_mean(const std::complex& A, const std::complex& B); }; //! @} RcppArmadillo/inst/include/armadillo_bits/glue_max_bones.hpp0000644000176000001440000000144612244135164024127 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_max //! @{ class glue_max { public: template inline static void apply(Mat< eT >& out, const Proxy& PA, const Proxy& PB); template inline static void apply(Mat< std::complex >& out, const Proxy& PA, const Proxy& PB); template inline static void apply(Mat& out, const Glue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/operator_schur.hpp0000644000176000001440000001415412176400754024203 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_schur //! @{ // operator %, which we define it to do a schur product (element-wise multiplication) //! element-wise multiplication of user-accessible Armadillo objects with same element type template arma_inline typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value, const eGlue >::result operator% ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return eGlue(X, Y); } //! element-wise multiplication of user-accessible Armadillo objects with different element types template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_same_type::no)), const mtGlue::result, T1, T2, glue_mixed_schur> >::result operator% ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlue( X, Y ); } //! element-wise multiplication of two sparse matrices template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_sparse_type::value && is_same_type::value), SpMat >::result operator% ( const SpBase& x, const SpBase& y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(x.get_ref()); const SpProxy pb(y.get_ref()); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "element-wise multiplication"); SpMat result(pa.get_n_rows(), pa.get_n_cols()); if( (pa.get_n_nonzero() != 0) && (pb.get_n_nonzero() != 0) ) { // Resize memory to correct size. result.mem_resize(n_unique(x, y, op_n_unique_mul())); // Now iterate across both matrices. typename SpProxy::const_iterator_type x_it = pa.begin(); typename SpProxy::const_iterator_type y_it = pb.begin(); typename SpProxy::const_iterator_type x_end = pa.end(); typename SpProxy::const_iterator_type y_end = pb.end(); uword cur_val = 0; while((x_it != x_end) || (y_it != y_end)) { if(x_it == y_it) { const eT val = (*x_it) * (*y_it); if (val != eT(0)) { access::rw(result.values[cur_val]) = val; access::rw(result.row_indices[cur_val]) = x_it.row(); ++access::rw(result.col_ptrs[x_it.col() + 1]); ++cur_val; } ++x_it; ++y_it; } else { const uword x_it_row = x_it.row(); const uword x_it_col = x_it.col(); const uword y_it_row = y_it.row(); const uword y_it_col = y_it.col(); if((x_it_col < y_it_col) || ((x_it_col == y_it_col) && (x_it_row < y_it_row))) // if y is closer to the end { ++x_it; } else { ++y_it; } } } // Fix column pointers to be cumulative. for(uword c = 1; c <= result.n_cols; ++c) { access::rw(result.col_ptrs[c]) += result.col_ptrs[c - 1]; } } return result; } //! element-wise multiplication of one dense and one sparse object template inline typename enable_if2 < (is_arma_type::value && is_arma_sparse_type::value && is_same_type::value), SpMat >::result operator% ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy pa(x); const SpProxy pb(y); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "element-wise multiplication"); SpMat result(pa.get_n_rows(), pa.get_n_cols()); // count new size uword new_n_nonzero = 0; typename SpProxy::const_iterator_type it = pb.begin(); typename SpProxy::const_iterator_type it_end = pb.end(); while(it != it_end) { if( ((*it) * pa.at(it.row(), it.col())) != eT(0) ) { ++new_n_nonzero; } ++it; } // Resize memory accordingly. result.mem_resize(new_n_nonzero); uword cur_val = 0; typename SpProxy::const_iterator_type it2 = pb.begin(); while(it2 != it_end) { const uword it2_row = it2.row(); const uword it2_col = it2.col(); const eT val = (*it2) * pa.at(it2_row, it2_col); if(val != eT(0)) { access::rw(result.values[cur_val]) = val; access::rw(result.row_indices[cur_val]) = it2_row; ++access::rw(result.col_ptrs[it2_col + 1]); ++cur_val; } ++it2; } // Fix column pointers. for(uword c = 1; c <= result.n_cols; ++c) { access::rw(result.col_ptrs[c]) += result.col_ptrs[c - 1]; } return result; } //! element-wise multiplication of one sparse and one dense object template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_type::value && is_same_type::value), SpMat >::result operator% ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); // This operation is commutative. return (y % x); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_hist_bones.hpp0000644000176000001440000000073712200631217023765 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_hist //! @{ class op_hist { public: template inline static void apply(Mat& out, const mtOp& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/SpSubview_bones.hpp0000644000176000001440000004031212111344723024244 0ustar ripleyusers// Copyright (C) 2011-2012 Ryan Curtin // Copyright (C) 2011 Matthew Amidon // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpSubview //! @{ template class SpSubview : public SpBase > { public: const SpMat& m; typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = false; const uword aux_row1; const uword aux_col1; const uword n_rows; const uword n_cols; const uword n_elem; const uword n_nonzero; // So that SpValProxy can call add_element() and delete_element(). friend class SpValProxy >; protected: arma_inline SpSubview(const SpMat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); arma_inline SpSubview( SpMat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); public: inline ~SpSubview(); inline const SpSubview& operator+= (const eT val); inline const SpSubview& operator-= (const eT val); inline const SpSubview& operator*= (const eT val); inline const SpSubview& operator/= (const eT val); inline const SpSubview& operator=(const SpSubview& x); template inline const SpSubview& operator= (const Base& x); template inline const SpSubview& operator+=(const Base& x); template inline const SpSubview& operator-=(const Base& x); template inline const SpSubview& operator*=(const Base& x); template inline const SpSubview& operator%=(const Base& x); template inline const SpSubview& operator/=(const Base& x); template inline const SpSubview& operator= (const SpBase& x); template inline const SpSubview& operator+=(const SpBase& x); template inline const SpSubview& operator-=(const SpBase& x); template inline const SpSubview& operator*=(const SpBase& x); template inline const SpSubview& operator%=(const SpBase& x); template inline const SpSubview& operator/=(const SpBase& x); /* inline static void extract(SpMat& out, const SpSubview& in); inline static void plus_inplace(Mat& out, const subview& in); inline static void minus_inplace(Mat& out, const subview& in); inline static void schur_inplace(Mat& out, const subview& in); inline static void div_inplace(Mat& out, const subview& in); */ inline void fill(const eT val); inline void zeros(); inline void ones(); inline void eye(); arma_hot inline SpValProxy > operator[](const uword i); arma_hot inline eT operator[](const uword i) const; arma_hot inline SpValProxy > operator()(const uword i); arma_hot inline eT operator()(const uword i) const; arma_hot inline SpValProxy > operator()(const uword in_row, const uword in_col); arma_hot inline eT operator()(const uword in_row, const uword in_col) const; arma_hot inline SpValProxy > at(const uword i); arma_hot inline eT at(const uword i) const; arma_hot inline SpValProxy > at(const uword in_row, const uword in_col); arma_hot inline eT at(const uword in_row, const uword in_col) const; inline bool check_overlap(const SpSubview& x) const; inline bool is_vec() const; inline SpSubview row(const uword row_num); inline const SpSubview row(const uword row_num) const; inline SpSubview col(const uword col_num); inline const SpSubview col(const uword col_num) const; inline SpSubview rows(const uword in_row1, const uword in_row2); inline const SpSubview rows(const uword in_row1, const uword in_row2) const; inline SpSubview cols(const uword in_col1, const uword in_col2); inline const SpSubview cols(const uword in_col1, const uword in_col2) const; inline SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); inline const SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; inline SpSubview submat(const span& row_span, const span& col_span); inline const SpSubview submat(const span& row_span, const span& col_span) const; inline SpSubview operator()(const uword row_num, const span& col_span); inline const SpSubview operator()(const uword row_num, const span& col_span) const; inline SpSubview operator()(const span& row_span, const uword col_num); inline const SpSubview operator()(const span& row_span, const uword col_num) const; inline SpSubview operator()(const span& row_span, const span& col_span); inline const SpSubview operator()(const span& row_span, const span& col_span) const; /* not yet inline SpSubview_row row(const uword row_num); inline const SpSubview_row row(const uword row_num) const; inline SpSubview_row operator()(const uword row_num, const span& col_span); inline const SpSubview_row operator()(const uword row_num, const span& col_span) const; inline SpSubview_col col(const uword col_num); inline const SpSubview_col col(const uword col_num) const; inline SpSubview_col operator()(const span& row_span, const uword col_num); inline const SpSubview_col operator()(const span& row_span, const uword col_num) const; inline Col unsafe_col(const uword col_num); inline const Col unsafe_col(const uword col_num) const; inline SpSubview rows(const uword in_row1, const uword in_row2); inline const SpSubview rows(const uword in_row1, const uword in_row2) const; inline SpSubview cols(const uword in_col1, const uword in_col2); inline const SpSubview cols(const uword in_col1, const uword in_col2) const; inline SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); inline const SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; inline SpSubview submat (const span& row_span, const span& col_span); inline const SpSubview submat (const span& row_span, const span& col_span) const; inline SpSubview operator()(const span& row_span, const span& col_span); inline const SpSubview operator()(const span& row_span, const span& col_span) const; inline diagview diag(const s32 in_id = 0); inline const diagview diag(const s32 in_id = 0) const; */ inline void swap_rows(const uword in_row1, const uword in_row2); inline void swap_cols(const uword in_col1, const uword in_col2); // Forward declarations. class iterator_base; class const_iterator; class iterator; class const_row_iterator; class row_iterator; // Similar to SpMat iterators but automatically iterates past and ignores values not in the subview. class iterator_base { public: inline iterator_base(const SpSubview& in_M); inline iterator_base(const SpSubview& in_M, const uword col, const uword pos, const uword skip_pos); inline eT operator*() const; // Don't hold location internally; call "dummy" methods to get that information. arma_inline uword row() const { return M.m.row_indices[internal_pos + skip_pos] - M.aux_row1; } arma_inline uword col() const { return internal_col; } arma_inline uword pos() const { return internal_pos; } arma_aligned const SpSubview& M; arma_aligned uword internal_col; arma_aligned uword internal_pos; arma_aligned uword skip_pos; // not used in row_iterator or const_row_iterator // So that we satisfy the STL iterator types. typedef std::bidirectional_iterator_tag iterator_category; typedef eT value_type; typedef uword difference_type; // not certain on this one typedef const eT* pointer; typedef const eT& reference; }; class const_iterator : public iterator_base { public: inline const_iterator(const SpSubview& in_M, uword initial_pos = 0); inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col); inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col, uword in_pos, uword skip_pos); inline const_iterator(const const_iterator& other); inline const_iterator& operator++(); inline const_iterator operator++(int); inline const_iterator& operator--(); inline const_iterator operator--(int); inline bool operator!=(const const_iterator& rhs) const; inline bool operator==(const const_iterator& rhs) const; inline bool operator!=(const typename SpMat::const_iterator& rhs) const; inline bool operator==(const typename SpMat::const_iterator& rhs) const; inline bool operator!=(const const_row_iterator& rhs) const; inline bool operator==(const const_row_iterator& rhs) const; inline bool operator!=(const typename SpMat::const_row_iterator& rhs) const; inline bool operator==(const typename SpMat::const_row_iterator& rhs) const; }; class iterator : public const_iterator { public: inline iterator(SpSubview& in_M, const uword initial_pos = 0) : const_iterator(in_M, initial_pos) { } inline iterator(SpSubview& in_M, const uword in_row, const uword in_col) : const_iterator(in_M, in_row, in_col) { } inline iterator(SpSubview& in_M, const uword in_row, const uword in_col, const uword in_pos, const uword in_skip_pos) : const_iterator(in_M, in_row, in_col, in_pos, in_skip_pos) { } inline iterator(const iterator& other) : const_iterator(other) { } inline SpValProxy > operator*(); // overloads needed for return type correctness inline iterator& operator++(); inline iterator operator++(int); inline iterator& operator--(); inline iterator operator--(int); // This has a different value_type than iterator_base. typedef SpValProxy > value_type; typedef const SpValProxy >* pointer; typedef const SpValProxy >& reference; }; class const_row_iterator : public iterator_base { public: inline const_row_iterator(const SpSubview& in_M, uword initial_pos = 0); inline const_row_iterator(const SpSubview& in_M, uword in_row, uword in_col); inline const_row_iterator(const const_row_iterator& other); inline const_row_iterator& operator++(); inline const_row_iterator operator++(int); inline const_row_iterator& operator--(); inline const_row_iterator operator--(int); uword internal_row; // Hold row internally because we use internal_pos differently. uword actual_pos; // Actual position in subview's parent matrix. arma_inline eT operator*() const { return iterator_base::M.m.values[actual_pos]; } arma_inline uword row() const { return internal_row; } inline bool operator!=(const const_iterator& rhs) const; inline bool operator==(const const_iterator& rhs) const; inline bool operator!=(const typename SpMat::const_iterator& rhs) const; inline bool operator==(const typename SpMat::const_iterator& rhs) const; inline bool operator!=(const const_row_iterator& rhs) const; inline bool operator==(const const_row_iterator& rhs) const; inline bool operator!=(const typename SpMat::const_row_iterator& rhs) const; inline bool operator==(const typename SpMat::const_row_iterator& rhs) const; }; class row_iterator : public const_row_iterator { public: inline row_iterator(SpSubview& in_M, uword initial_pos = 0) : const_row_iterator(in_M, initial_pos) { } inline row_iterator(SpSubview& in_M, uword in_row, uword in_col) : const_row_iterator(in_M, in_row, in_col) { } inline row_iterator(const row_iterator& other) : const_row_iterator(other) { } inline SpValProxy > operator*(); // overloads needed for return type correctness inline row_iterator& operator++(); inline row_iterator operator++(int); inline row_iterator& operator--(); inline row_iterator operator--(int); // This has a different value_type than iterator_base. typedef SpValProxy > value_type; typedef const SpValProxy >* pointer; typedef const SpValProxy >& reference; }; inline iterator begin(); inline const_iterator begin() const; inline iterator begin_col(const uword col_num); inline const_iterator begin_col(const uword col_num) const; inline row_iterator begin_row(const uword row_num = 0); inline const_row_iterator begin_row(const uword row_num = 0) const; inline iterator end(); inline const_iterator end() const; inline row_iterator end_row(); inline const_row_iterator end_row() const; inline row_iterator end_row(const uword row_num = 0); inline const_row_iterator end_row(const uword row_num = 0) const; private: friend class SpMat; SpSubview(); // For use by SpValProxy. We just update n_nonzero and pass the call on to the matrix. inline arma_hot arma_warn_unused eT& add_element(const uword in_row, const uword in_col, const eT in_val = 0.0); inline arma_hot void delete_element(const uword in_row, const uword in_col); }; /* template class SpSubview_col : public SpSubview { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline void operator= (const SpSubview& x); inline void operator= (const SpSubview_col& x); template inline void operator= (const Base& x); inline SpSubview_col rows(const uword in_row1, const uword in_row2); inline const SpSubview_col rows(const uword in_row1, const uword in_row2) const; inline SpSubview_col subvec(const uword in_row1, const uword in_row2); inline const SpSubview_col subvec(const uword in_row1, const uword in_row2) const; protected: inline SpSubview_col(const Mat& in_m, const uword in_col); inline SpSubview_col( Mat& in_m, const uword in_col); inline SpSubview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); inline SpSubview_col( Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); private: friend class Mat; friend class Col; friend class SpSubview; SpSubview_col(); }; template class SpSubview_row : public SpSubview { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline void operator= (const SpSubview& x); inline void operator= (const SpSubview_row& x); template inline void operator= (const Base& x); inline SpSubview_row cols(const uword in_col1, const uword in_col2); inline const SpSubview_row cols(const uword in_col1, const uword in_col2) const; inline SpSubview_row subvec(const uword in_col1, const uword in_col2); inline const SpSubview_row subvec(const uword in_col1, const uword in_col2) const; protected: inline SpSubview_row(const Mat& in_m, const uword in_row); inline SpSubview_row( Mat& in_m, const uword in_row); inline SpSubview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); inline SpSubview_row( Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); private: friend class Mat; friend class Row; friend class SpSubview; SpSubview_row(); }; */ //! @} RcppArmadillo/inst/include/armadillo_bits/fn_eig_pair.hpp0000644000176000001440000001364112254240234023376 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_eig_pair //! @{ //! eigenvalues for pair of N-by-N general real matrices (A,B) template inline Col< std::complex > eig_pair ( const Base& A, const Base& B, const typename arma_blas_type_only::result* junk1 = 0, const typename arma_not_cx::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); Mat l_eigvec; Mat r_eigvec; Col< std::complex > eigval; const bool status = auxlib::eig_pair(eigval, l_eigvec, r_eigvec, A, B, 'n'); if(status == false) { eigval.reset(); arma_bad("eig_pair(): failed to converge"); } return eigval; } //! eigenvalues for pair of N-by-N general complex matrices (A,B) template inline Col< std::complex > eig_pair ( const Base< std::complex, T1>& A, const Base< std::complex, T1>& B, const typename arma_blas_type_only< std::complex >::result* junk1 = 0, const typename arma_cx_only< std::complex >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); Mat< std::complex > l_eigvec; Mat< std::complex > r_eigvec; Col< std::complex > eigval; const bool status = auxlib::eig_pair(eigval, l_eigvec, r_eigvec, A, B, 'n'); if(status == false) { eigval.reset(); arma_bad("eig_pair(): failed to converge"); } return eigval; } //! eigenvalues for pair of N-by-N general real matrices (A,B) template inline bool eig_pair ( Col< std::complex >& eigval, const Base< eT, T1 >& A, const Base< eT, T2 >& B, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Mat l_eigvec; Mat r_eigvec; const bool status = auxlib::eig_pair(eigval, l_eigvec, r_eigvec, A, B, 'n'); if(status == false) { eigval.reset(); arma_bad("eig_pair(): failed to converge", false); } return status; } //! eigenvalues for pair of N-by-N general complex matrices (A,B) template inline bool eig_pair ( Col< std::complex >& eigval, const Base< std::complex, T1 >& A, const Base< std::complex, T2 >& B, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Mat< std::complex > l_eigvec; Mat< std::complex > r_eigvec; const bool status = auxlib::eig_pair(eigval, l_eigvec, r_eigvec, A, B, 'n'); if(status == false) { eigval.reset(); arma_bad("eig_pair(): failed to converge", false); } return status; } //! eigenvalues and eigenvectors for pair of N-by-N general real matrices (A,B) template inline bool eig_pair ( Col< std::complex >& eigval, Mat< std::complex >& eigvec, const Base< eT, T1 >& A, const Base< eT, T2 >& B, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( ( ((void*)(&eigval)) == ((void*)(&eigvec)) ), "eig_pair(): eigval is an alias of eigvec" ); Mat dummy_eigvec; Mat tmp_eigvec; const bool status = auxlib::eig_pair(eigval, dummy_eigvec, tmp_eigvec, A, B, 'r'); if(status == false) { eigval.reset(); eigvec.reset(); arma_bad("eig_pair(): failed to converge", false); } else { const uword n = eigval.n_elem; if(n > 0) { eigvec.set_size(n,n); // from LAPACK docs: // If the j-th and (j+1)-th eigenvalues form a complex conjugate pair, then // v(j) = VR(:,j)+i*VR(:,j+1) and v(j+1) = VR(:,j)-i*VR(:,j+1). for(uword j=0; j >( tmp_eigvec.col(j), tmp_eigvec.col(j+1) ); // eigvec.col(j+1) = Mat< std::complex >( tmp_eigvec.col(j), -tmp_eigvec.col(j+1) ); for(uword i=0; i( tmp_eigvec.at(i,j), tmp_eigvec.at(i,j+1) ); eigvec.at(i,j+1) = std::complex( tmp_eigvec.at(i,j), -tmp_eigvec.at(i,j+1) ); } ++j; } else { // eigvec.col(i) = tmp_eigvec.col(i); for(uword i=0; i(tmp_eigvec.at(i,j), eT(0)); } } } } } return status; } //! eigenvalues and eigenvectors for pair of N-by-N general complex matrices (A,B) template inline bool eig_pair ( Col< std::complex >& eigval, Mat< std::complex >& eigvec, const Base< std::complex, T1 >& A, const Base< std::complex, T2 >& B, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( ( ((void*)(&eigval)) == ((void*)(&eigvec)) ), "eig_pair(): eigval is an alias of eigvec" ); Mat< std::complex > dummy_eigvec; const bool status = auxlib::eig_pair(eigval, dummy_eigvec, eigvec, A, B, 'r'); if(status == false) { eigval.reset(); eigvec.reset(); arma_bad("eig_pair(): failed to converge", false); } return status; } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_conv_meat.hpp0000644000176000001440000000451212200375542024122 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_conv //! @{ //! rudimentary implementation of the convolution operation template inline void glue_conv::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check A_tmp(X.A, out); const unwrap_check B_tmp(X.B, out); const Mat& A = A_tmp.M; const Mat& B = B_tmp.M; arma_debug_check ( ( ((A.is_vec() == false) && (A.is_empty() == false)) || ((B.is_vec() == false) && (B.is_empty() == false)) ), "conv(): given object is not a vector" ); const Mat& h = (A.n_elem <= B.n_elem) ? A : B; const Mat& x = (A.n_elem <= B.n_elem) ? B : A; const uword h_n_elem = h.n_elem; const uword x_n_elem = x.n_elem; const uword out_n_elem = h_n_elem + x_n_elem - 1; if( (h_n_elem == 0) || (x_n_elem == 0) ) { out.reset(); return; } (A.n_cols == 1) ? out.set_size(out_n_elem, 1) : out.set_size(1, out_n_elem); const eT* h_mem = h.memptr(); const eT* x_mem = x.memptr(); eT* out_mem = out.memptr(); for(uword out_i = 0; out_i < (h_n_elem-1); ++out_i) { eT acc = eT(0); uword h_i = out_i; for(uword x_i = 0; x_i <= out_i; ++x_i, --h_i) { acc += h_mem[h_i] * x_mem[x_i]; } out_mem[out_i] = acc; } for(uword out_i = h_n_elem-1; out_i < out_n_elem - (h_n_elem-1); ++out_i) { eT acc = eT(0); uword h_i = h_n_elem - 1; for(uword x_i = out_i - h_n_elem + 1; x_i <= out_i; ++x_i, --h_i) { acc += h_mem[h_i] * x_mem[x_i]; } out_mem[out_i] = acc; } for(uword out_i = out_n_elem - (h_n_elem-1); out_i < out_n_elem; ++out_i) { eT acc = eT(0); uword h_i = h_n_elem - 1; for(uword x_i = out_i - h_n_elem + 1; x_i < x_n_elem; ++x_i, --h_i) { acc += h_mem[h_i] * x_mem[x_i]; } out_mem[out_i] = acc; } } //! @} RcppArmadillo/inst/include/armadillo_bits/injector_bones.hpp0000644000176000001440000000407012202101406024121 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup injector //! @{ template class mat_injector_row { public: inline mat_injector_row(); inline void insert(const eT val) const; mutable uword n_cols; mutable podarray A; mutable podarray B; }; template class mat_injector { public: typedef typename T1::elem_type elem_type; inline void insert(const elem_type val) const; inline void end_of_row() const; inline ~mat_injector(); private: inline mat_injector(T1& in_X, const elem_type val); inline mat_injector(T1& in_X, const injector_end_of_row<>& x); T1& X; mutable uword n_rows; mutable podarray< mat_injector_row* >* AA; mutable podarray< mat_injector_row* >* BB; friend class Mat; friend class Row; friend class Col; }; // template class field_injector_row { public: inline field_injector_row(); inline ~field_injector_row(); inline void insert(const oT& val) const; mutable uword n_cols; mutable field* AA; mutable field* BB; }; template class field_injector { public: typedef typename T1::object_type object_type; inline void insert(const object_type& val) const; inline void end_of_row() const; inline ~field_injector(); private: inline field_injector(T1& in_X, const object_type& val); inline field_injector(T1& in_X, const injector_end_of_row<>& x); T1& X; mutable uword n_rows; mutable podarray< field_injector_row* >* AA; mutable podarray< field_injector_row* >* BB; friend class field; }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_hist_meat.hpp0000644000176000001440000000340512200631217023600 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_hist //! @{ template inline void op_hist::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_bins = X.aux_uword_a; const unwrap_check_mixed tmp(X.m, out); const Mat& A = tmp.M; uword A_n_elem = A.n_elem; const eT* A_mem = A.memptr(); eT min_val = priv::most_pos(); eT max_val = priv::most_neg(); uword i,j; for(i=0, j=1; j < A_n_elem; i+=2, j+=2) { const eT val_i = A_mem[i]; const eT val_j = A_mem[j]; if(min_val > val_i) { min_val = val_i; } if(min_val > val_j) { min_val = val_j; } if(max_val < val_i) { max_val = val_i; } if(max_val < val_j) { max_val = val_j; } } if(i < A_n_elem) { const eT val_i = A_mem[i]; if(min_val > val_i) { min_val = val_i; } if(max_val < val_i) { max_val = val_i; } } if(arma_isfinite(min_val) == false) { min_val = priv::most_neg(); } if(arma_isfinite(max_val) == false) { max_val = priv::most_pos(); } if(n_bins >= 1) { Col c(n_bins); eT* c_mem = c.memptr(); for(uword ii=0; ii < n_bins; ++ii) { c_mem[ii] = (0.5 + ii) / double(n_bins); // TODO: may need to be modified for integer matrices } c = ((max_val - min_val) * c) + min_val; out = hist(A, c); } else { out.reset(); } } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_kron_bones.hpp0000644000176000001440000000177312200375542024314 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_kron //! @{ class glue_kron { public: template inline static void direct_kron(Mat& out, const Mat& A, const Mat& B); template inline static void direct_kron(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat& B); template inline static void direct_kron(Mat< std::complex >& out, const Mat& A, const Mat< std::complex >& B); template inline static void apply(Mat& out, const Glue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/operator_minus.hpp0000644000176000001440000001307412177612510024206 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_minus //! @{ //! unary - template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator- (const T1& X) { arma_extra_debug_sigprint(); return eOp(X); } //! cancellation of two consecutive negations: -(-T1) template arma_inline const T1& operator- (const eOp& X) { arma_extra_debug_sigprint(); return X.m; } //! Base - scalar template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator- ( const T1& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOp(X, k); } //! scalar - Base template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator- ( const typename T1::elem_type k, const T1& X ) { arma_extra_debug_sigprint(); return eOp(X, k); } //! complex scalar - non-complex Base template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_minus_pre> >::result operator- ( const std::complex& k, const T1& X ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_minus_pre>('j', X, k); } //! non-complex Base - complex scalar template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_minus_post> >::result operator- ( const T1& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_minus_post>('j', X, k); } //! subtraction of Base objects with same element type template arma_inline typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value, const eGlue >::result operator- ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return eGlue(X, Y); } //! subtraction of Base objects with different element types template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_same_type::no)), const mtGlue::result, T1, T2, glue_mixed_minus> >::result operator- ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlue( X, Y ); } //! subtraction of two sparse objects template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_sparse_type::value && is_same_type::value), const SpGlue >::result operator- ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return SpGlue(X,Y); } //! subtraction of one sparse and one dense object template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_type::value && is_same_type::value), Mat >::result operator- ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); const SpProxy pa(x); Mat result(-y); arma_debug_assert_same_size( pa.get_n_rows(), pa.get_n_cols(), result.n_rows, result.n_cols, "subtraction" ); typename SpProxy::const_iterator_type it = pa.begin(); typename SpProxy::const_iterator_type it_end = pa.end(); while(it != it_end) { result.at(it.row(), it.col()) += (*it); ++it; } return result; } //! subtraction of one dense and one sparse object template inline typename enable_if2 < (is_arma_type::value && is_arma_sparse_type::value && is_same_type::value), Mat >::result operator- ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); Mat result(x); const SpProxy pb(y.get_ref()); arma_debug_assert_same_size( result.n_rows, result.n_cols, pb.get_n_rows(), pb.get_n_cols(), "subtraction" ); typename SpProxy::const_iterator_type it = pb.begin(); typename SpProxy::const_iterator_type it_end = pb.end(); while(it != it_end) { result.at(it.row(), it.col()) -= (*it); ++it; } return result; } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_accu.hpp0000644000176000001440000001367312200375542022541 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_accu //! @{ template arma_hot inline typename T1::elem_type accu_proxy_linear(const Proxy& P) { typedef typename T1::elem_type eT; typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); const uword n_elem = P.get_n_elem(); eT val1 = eT(0); eT val2 = eT(0); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { val1 += A[i]; val2 += A[j]; } if(i < n_elem) { val1 += A[i]; // equivalent to: val1 += A[n_elem-1]; } return (val1 + val2); } template arma_hot inline typename T1::elem_type accu_proxy_at(const Proxy& P) { typedef typename T1::elem_type eT; const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); eT val = eT(0); if(n_rows != 1) { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { val += P.at(row,col); } } else { for(uword col=0; col < n_cols; ++col) { val += P.at(0,col); } } return val; } //! accumulate the elements of a matrix template arma_hot inline typename enable_if2< is_arma_type::value, typename T1::elem_type >::result accu(const T1& X) { arma_extra_debug_sigprint(); const Proxy P(X); return (Proxy::prefer_at_accessor == false) ? accu_proxy_linear(P) : accu_proxy_at(P); } //! explicit handling of Hamming norm (also known as zero norm) template inline arma_warn_unused uword accu(const mtOp& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const eT val = X.aux; const Proxy P(X.m); uword n_nonzero = 0; if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); const uword n_elem = P.get_n_elem(); for(uword i=0; i arma_hot arma_pure arma_warn_unused inline eT accu(const subview& X) { arma_extra_debug_sigprint(); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; eT val = eT(0); if(X_n_rows == 1) { const Mat& A = X.m; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_col_p1 = start_col + X_n_cols; uword i,j; for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2) { val += A.at(start_row, i); val += A.at(start_row, j); } if(i < end_col_p1) { val += A.at(start_row, i); } } else if(X_n_cols == 1) { val = arrayops::accumulate( X.colptr(0), X_n_rows ); } else { for(uword col=0; col < X_n_cols; ++col) { val += arrayops::accumulate( X.colptr(col), X_n_rows ); } } return val; } template arma_hot arma_pure arma_warn_unused inline eT accu(const subview_col& X) { arma_extra_debug_sigprint(); return arrayops::accumulate( X.colptr(0), X.n_rows ); } //! accumulate the elements of a cube template arma_hot arma_warn_unused inline typename T1::elem_type accu(const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename ProxyCube::ea_type ea_type; const ProxyCube A(X.get_ref()); if(ProxyCube::prefer_at_accessor == false) { ea_type P = A.get_ea(); const uword n_elem = A.get_n_elem(); eT val1 = eT(0); eT val2 = eT(0); uword i,j; for(i=0, j=1; j arma_inline arma_warn_unused const typename arma_scalar_only::result & accu(const T& x) { return x; } //! accumulate values in a sparse object template arma_hot inline arma_warn_unused typename enable_if2::value, typename T1::elem_type>::result accu(const T1& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy p(x); if(SpProxy::must_use_iterator == false) { // direct counting return arrayops::accumulate(p.get_values(), p.get_n_nonzero()); } else { typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); eT result = eT(0); while(it != it_end) { result += (*it); ++it; } return result; } } //! @} RcppArmadillo/inst/include/armadillo_bits/operator_cube_schur.hpp0000644000176000001440000000313212177612753025200 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_cube_schur //! @{ // operator %, which we define it to do a schur product (element-wise multiplication) //! element-wise multiplication of BaseCube objects with same element type template arma_inline const eGlueCube operator% ( const BaseCube& X, const BaseCube& Y ) { arma_extra_debug_sigprint(); return eGlueCube(X.get_ref(), Y.get_ref()); } //! element-wise multiplication of BaseCube objects with different element types template inline const mtGlueCube::result, T1, T2, glue_mixed_schur> operator% ( const BaseCube< typename force_different_type::T1_result, T1>& X, const BaseCube< typename force_different_type::T2_result, T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } //! @} RcppArmadillo/inst/include/armadillo_bits/SpValProxy_bones.hpp0000644000176000001440000000373212156062240024411 0ustar ripleyusers// Copyright (C) 2011-2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpValProxy //! @{ /** * Sparse value proxy class, meant to prevent 0s from being added to sparse * matrices. T1 should be either SpMat or SpSubview, and if it's not, bad news * is probably coming. This class only uses T1::add_element() and * T1::delete_element(). */ template class SpValProxy { public: typedef typename T1::elem_type eT; // Convenience typedef friend class SpMat; friend class SpSubview; /** * Create the sparse value proxy. * Otherwise, pass a pointer to a reference of the value. */ arma_inline SpValProxy(uword row, uword col, T1& in_parent, eT* in_val_ptr = NULL); //! For swapping operations. arma_inline SpValProxy& operator=(const SpValProxy& rhs); template arma_inline SpValProxy& operator=(const SpValProxy& rhs); //! Overload all of the potential operators. //! First, the ones that could modify a value. arma_inline SpValProxy& operator=(const eT rhs); arma_inline SpValProxy& operator+=(const eT rhs); arma_inline SpValProxy& operator-=(const eT rhs); arma_inline SpValProxy& operator*=(const eT rhs); arma_inline SpValProxy& operator/=(const eT rhs); arma_inline SpValProxy& operator++(); arma_inline SpValProxy& operator--(); arma_inline eT operator++(const int); arma_inline eT operator--(const int); //! This will work for any other operations that do not modify a value. arma_inline operator eT() const; private: // Deletes the element if it is zero. Does not check if val_ptr == NULL! arma_inline arma_hot void check_zero(); uword row; uword col; eT* val_ptr; T1& parent; // We will call this object if we need to insert or delete an element. }; //! @} RcppArmadillo/inst/include/armadillo_bits/operator_cube_times.hpp0000644000176000001440000000350312177612753025177 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_cube_times //! @{ //! BaseCube * scalar template arma_inline const eOpCube operator* ( const BaseCube& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! scalar * BaseCube template arma_inline const eOpCube operator* ( const typename T1::elem_type k, const BaseCube& X ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! non-complex BaseCube * complex scalar (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_times> operator* ( const BaseCube& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_times>('j', X.get_ref(), k); } //! complex scalar * non-complex BaseCube (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_times> operator* ( const std::complex& k, const BaseCube& X ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_times>('j', X.get_ref(), k); } //! @} RcppArmadillo/inst/include/armadillo_bits/memory.hpp0000644000176000001440000001153112242621312022435 0ustar ripleyusers// Copyright (C) 2012-2013 Conrad Sanderson // Copyright (C) 2012-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup memory //! @{ class memory { public: arma_inline static uword enlarge_to_mult_of_chunksize(const uword n_elem); template inline arma_malloc static eT* acquire(const uword n_elem); template inline arma_malloc static eT* acquire_chunked(const uword n_elem); template arma_inline static void release(eT* mem); template arma_inline static bool is_aligned(const eT* mem); template arma_inline static void mark_as_aligned( eT*& mem); template arma_inline static void mark_as_aligned(const eT*& mem); }; arma_inline uword memory::enlarge_to_mult_of_chunksize(const uword n_elem) { const uword chunksize = arma_config::spmat_chunksize; // this relies on integer division const uword n_elem_mod = ((n_elem % chunksize) != 0) ? ((n_elem / chunksize) + 1) * chunksize : n_elem; return n_elem_mod; } template inline arma_malloc eT* memory::acquire(const uword n_elem) { eT* out_memptr; #if defined(ARMA_USE_TBB_ALLOC) { out_memptr = (eT *) scalable_malloc(sizeof(eT)*n_elem); } #elif defined(ARMA_USE_MKL_ALLOC) { out_memptr = (eT *) mkl_malloc( sizeof(eT)*n_elem, 128 ); } #elif defined(ARMA_HAVE_POSIX_MEMALIGN) { eT* memptr; const size_t alignment = 16; // change the 16 to 64 if you wish to align to the cache line int status = posix_memalign((void **)&memptr, ( (alignment >= sizeof(void*)) ? alignment : sizeof(void*) ), sizeof(eT)*n_elem); out_memptr = (status == 0) ? memptr : NULL; } #elif defined(_MSC_VER) { out_memptr = (eT *) _aligned_malloc( sizeof(eT)*n_elem, 16 ); // lives in malloc.h } #else { //return ( new(std::nothrow) eT[n_elem] ); out_memptr = (eT *) malloc(sizeof(eT)*n_elem); } #endif // TODO: for mingw, use __mingw_aligned_malloc if(n_elem > 0) { arma_check_bad_alloc( (out_memptr == NULL), "arma::memory::acquire(): out of memory" ); } return out_memptr; } //! get memory in multiples of chunks, holding at least n_elem template inline arma_malloc eT* memory::acquire_chunked(const uword n_elem) { const uword n_elem_mod = memory::enlarge_to_mult_of_chunksize(n_elem); return memory::acquire(n_elem_mod); } template arma_inline void memory::release(eT* mem) { #if defined(ARMA_USE_TBB_ALLOC) { scalable_free( (void *)(mem) ); } #elif defined(ARMA_USE_MKL_ALLOC) { mkl_free( (void *)(mem) ); } #elif defined(ARMA_HAVE_POSIX_MEMALIGN) { free( (void *)(mem) ); } #elif defined(_MSC_VER) { _aligned_free( (void *)(mem) ); } #else { //delete [] mem; free( (void *)(mem) ); } #endif // TODO: for mingw, use __mingw_aligned_free } template arma_inline bool memory::is_aligned(const eT* mem) { #if (defined(ARMA_HAVE_ICC_ASSUME_ALIGNED) || defined(ARMA_HAVE_GCC_ASSUME_ALIGNED)) && !defined(ARMA_DONT_CHECK_ALIGNMENT) { return ((std::ptrdiff_t(mem) & 0x0F) == 0); } #else { arma_ignore(mem); return false; } #endif } template arma_inline void memory::mark_as_aligned(eT*& mem) { #if defined(ARMA_HAVE_ICC_ASSUME_ALIGNED) { __assume_aligned(mem, 16); } #elif defined(ARMA_HAVE_GCC_ASSUME_ALIGNED) { mem = (eT*)__builtin_assume_aligned(mem, 16); } #else { arma_ignore(mem); } #endif // TODO: MSVC? __assume( (mem & 0x0F) == 0 ); // // http://comments.gmane.org/gmane.comp.gcc.patches/239430 // GCC __builtin_assume_aligned is similar to ICC's __assume_aligned, // so for lvalue first argument ICC's __assume_aligned can be emulated using // #define __assume_aligned(lvalueptr, align) lvalueptr = __builtin_assume_aligned (lvalueptr, align) // // http://www.inf.ethz.ch/personal/markusp/teaching/263-2300-ETH-spring11/slides/class19.pdf // http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/cpp/lin/index.htm // http://d3f8ykwhia686p.cloudfront.net/1live/intel/CompilerAutovectorizationGuide.pdf } template arma_inline void memory::mark_as_aligned(const eT*& mem) { #if defined(ARMA_HAVE_ICC_ASSUME_ALIGNED) { __assume_aligned(mem, 16); } #elif defined(ARMA_HAVE_GCC_ASSUME_ALIGNED) { mem = (const eT*)__builtin_assume_aligned(mem, 16); } #else { arma_ignore(mem); } #endif } //! @} RcppArmadillo/inst/include/armadillo_bits/podarray_meat.hpp0000644000176000001440000001415112260430535023762 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup podarray //! @{ template arma_hot inline podarray::~podarray() { arma_extra_debug_sigprint_this(this); if(n_elem > podarray_prealloc_n_elem::val ) { memory::release( mem ); } } template inline podarray::podarray() : n_elem(0) , mem (0) { arma_extra_debug_sigprint_this(this); } template inline podarray::podarray(const podarray& x) : n_elem(x.n_elem) { arma_extra_debug_sigprint(); const uword x_n_elem = x.n_elem; init_cold(x_n_elem); arrayops::copy( memptr(), x.memptr(), x_n_elem ); } template inline const podarray& podarray::operator=(const podarray& x) { arma_extra_debug_sigprint(); if(this != &x) { const uword x_n_elem = x.n_elem; init_warm(x_n_elem); arrayops::copy( memptr(), x.memptr(), x_n_elem ); } return *this; } template arma_hot arma_inline podarray::podarray(const uword new_n_elem) : n_elem(new_n_elem) { arma_extra_debug_sigprint_this(this); init_cold(new_n_elem); } template arma_inline podarray::podarray(const eT* X, const uword new_n_elem) : n_elem(new_n_elem) { arma_extra_debug_sigprint_this(this); init_cold(new_n_elem); arrayops::copy( memptr(), X, new_n_elem ); } template template inline podarray::podarray(const Proxy& P) : n_elem(P.get_n_elem()) { arma_extra_debug_sigprint_this(this); const uword P_n_elem = P.get_n_elem(); init_cold(P_n_elem); eT* out_mem = (*this).memptr(); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j < P_n_elem; i+=2, j+=2) { const eT val_i = A[i]; const eT val_j = A[j]; out_mem[i] = val_i; out_mem[j] = val_j; } if(i < P_n_elem) { out_mem[i] = A[i]; } } else { const uword P_n_rows = P.get_n_rows(); const uword P_n_cols = P.get_n_cols(); if(P_n_rows != 1) { uword count = 0; for(uword col=0; col < P_n_cols; ++col) for(uword row=0; row < P_n_rows; ++row, ++count) { out_mem[count] = P.at(row,col); } } else { for(uword col=0; col < P_n_cols; ++col) { out_mem[col] = P.at(0,col); } } } } template arma_inline eT podarray::operator[] (const uword i) const { return mem[i]; } template arma_inline eT& podarray::operator[] (const uword i) { return access::rw(mem[i]); } template arma_inline eT podarray::operator() (const uword i) const { arma_debug_check( (i >= n_elem), "podarray::operator(): index out of bounds"); return mem[i]; } template arma_inline eT& podarray::operator() (const uword i) { arma_debug_check( (i >= n_elem), "podarray::operator(): index out of bounds"); return access::rw(mem[i]); } template inline void podarray::set_min_size(const uword min_n_elem) { arma_extra_debug_sigprint(); if(min_n_elem > n_elem) { init_warm(min_n_elem); } } template inline void podarray::set_size(const uword new_n_elem) { arma_extra_debug_sigprint(); init_warm(new_n_elem); } template inline void podarray::reset() { arma_extra_debug_sigprint(); init_warm(0); } template inline void podarray::fill(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_set(memptr(), val, n_elem); } template inline void podarray::zeros() { arma_extra_debug_sigprint(); arrayops::fill_zeros(memptr(), n_elem); } template inline void podarray::zeros(const uword new_n_elem) { arma_extra_debug_sigprint(); init_warm(new_n_elem); arrayops::fill_zeros(memptr(), n_elem); } template arma_inline eT* podarray::memptr() { return mem; } template arma_inline const eT* podarray::memptr() const { return mem; } template arma_hot inline void podarray::copy_row(const Mat& A, const uword row) { const uword cols = A.n_cols; // note: this function assumes that the podarray has been set to the correct size beforehand eT* out = memptr(); switch(cols) { default: { uword i,j; for(i=0, j=1; j < cols; i+=2, j+=2) { const eT tmp_i = A.at(row, i); const eT tmp_j = A.at(row, j); out[i] = tmp_i; out[j] = tmp_j; } if(i < cols) { out[i] = A.at(row, i); } } break; case 8: out[7] = A.at(row, 7); case 7: out[6] = A.at(row, 6); case 6: out[5] = A.at(row, 5); case 5: out[4] = A.at(row, 4); case 4: out[3] = A.at(row, 3); case 3: out[2] = A.at(row, 2); case 2: out[1] = A.at(row, 1); case 1: out[0] = A.at(row, 0); case 0: ; } } template arma_hot inline void podarray::init_cold(const uword new_n_elem) { arma_extra_debug_sigprint(); if(new_n_elem <= podarray_prealloc_n_elem::val ) { mem = mem_local; } else { mem = memory::acquire(new_n_elem); } } template inline void podarray::init_warm(const uword new_n_elem) { arma_extra_debug_sigprint(); if(n_elem == new_n_elem) { return; } if(n_elem > podarray_prealloc_n_elem::val ) { memory::release( mem ); } if(new_n_elem <= podarray_prealloc_n_elem::val ) { mem = mem_local; } else { mem = memory::acquire(new_n_elem); } access::rw(n_elem) = new_n_elem; } //! @} RcppArmadillo/inst/include/armadillo_bits/spglue_plus_meat.hpp0000644000176000001440000000767612111344723024517 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spglue_plus //! @{ template arma_hot inline void spglue_plus::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(X.A); const SpProxy pb(X.B); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_plus::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_plus::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } } template arma_hot inline void spglue_plus::apply_noalias(SpMat& out, const SpProxy& pa, const SpProxy& pb) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "addition"); if( (pa.get_n_nonzero() != 0) && (pb.get_n_nonzero() != 0) ) { out.set_size(pa.get_n_rows(), pa.get_n_cols()); // Resize memory to correct size. out.mem_resize(n_unique(pa, pb, op_n_unique_add())); // Now iterate across both matrices. typename SpProxy::const_iterator_type x_it = pa.begin(); typename SpProxy::const_iterator_type y_it = pb.begin(); typename SpProxy::const_iterator_type x_end = pa.end(); typename SpProxy::const_iterator_type y_end = pb.end(); uword cur_val = 0; while( (x_it != x_end) || (y_it != y_end) ) { if(x_it == y_it) { const eT val = (*x_it) + (*y_it); if (val != eT(0)) { access::rw(out.values[cur_val]) = val; access::rw(out.row_indices[cur_val]) = x_it.row(); ++access::rw(out.col_ptrs[x_it.col() + 1]); ++cur_val; } ++x_it; ++y_it; } else { const uword x_it_row = x_it.row(); const uword x_it_col = x_it.col(); const uword y_it_row = y_it.row(); const uword y_it_col = y_it.col(); if((x_it_col < y_it_col) || ((x_it_col == y_it_col) && (x_it_row < y_it_row))) // if y is closer to the end { access::rw(out.values[cur_val]) = (*x_it); access::rw(out.row_indices[cur_val]) = x_it_row; ++access::rw(out.col_ptrs[x_it_col + 1]); ++cur_val; ++x_it; } else { access::rw(out.values[cur_val]) = (*y_it); access::rw(out.row_indices[cur_val]) = y_it_row; ++access::rw(out.col_ptrs[y_it_col + 1]); ++cur_val; ++y_it; } } } const uword out_n_cols = out.n_cols; uword* col_ptrs = access::rwp(out.col_ptrs); // Fix column pointers to be cumulative. for(uword c = 1; c <= out_n_cols; ++c) { col_ptrs[c] += col_ptrs[c - 1]; } } else { if(pa.get_n_nonzero() == 0) { out = pb.Q; return; } if(pb.get_n_nonzero() == 0) { out = pa.Q; return; } } } // // // spglue_plus2: scalar*(A + B) template arma_hot inline void spglue_plus2::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(X.A); const SpProxy pb(X.B); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_plus::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_plus::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } out *= X.aux; } //! @} RcppArmadillo/inst/include/armadillo_bits/subview_each_bones.hpp0000644000176000001440000000533012111344723024762 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup subview_each //! @{ template class subview_each_common { public: typedef typename parent::elem_type eT; protected: parent& p; arma_inline subview_each_common(parent& in_p); arma_inline const Mat& get_mat_ref_helper(const Mat & X) const; arma_inline const Mat& get_mat_ref_helper(const subview& X) const; arma_inline const Mat& get_mat_ref() const; inline void check_size(const Mat& A) const; arma_cold inline const std::string incompat_size_string(const Mat& A) const; private: subview_each_common(); }; template class subview_each1 : public subview_each_common { protected: arma_inline subview_each1(parent& in_p); public: typedef typename parent::elem_type eT; inline ~subview_each1(); // deliberately returning void template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); private: friend class Mat; friend class subview; subview_each1(); }; template class subview_each2 : public subview_each_common { protected: const Base& base_indices; inline subview_each2(parent& in_p, const Base& in_indices); inline void check_indices(const Mat& indices) const; public: typedef typename parent::elem_type eT; inline ~subview_each2(); // deliberately returning void template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); // TODO: add handling of scalars private: friend class Mat; friend class subview; subview_each2(); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_trace.hpp0000644000176000001440000001174212200375542022717 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_trace //! @{ //! Immediate trace (sum of diagonal elements) of a square dense matrix template arma_hot arma_warn_unused inline typename enable_if2::value, typename T1::elem_type>::result trace(const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy A(X); arma_debug_check( (A.get_n_rows() != A.get_n_cols()), "trace(): matrix must be square sized" ); const uword N = A.get_n_rows(); eT val1 = eT(0); eT val2 = eT(0); uword i,j; for(i=0, j=1; j arma_hot arma_warn_unused inline typename T1::elem_type trace(const Op& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const diagmat_proxy A(X.m); const uword N = A.n_elem; eT val = eT(0); for(uword i=0; i arma_hot inline typename T1::elem_type trace_mul_unwrap(const T1& XA, const T2& XB) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy PA(XA); const unwrap tmpB(XB); const Mat& B = tmpB.M; arma_debug_assert_mul_size(PA.get_n_rows(), PA.get_n_cols(), B.n_rows, B.n_cols, "matrix multiplication"); arma_debug_check( (PA.get_n_rows() != B.n_cols), "trace(): matrix must be square sized" ); const uword N1 = PA.get_n_rows(); // equivalent to B.n_cols, due to square size requirements const uword N2 = PA.get_n_cols(); // equivalent to B.n_rows, due to matrix multiplication requirements eT val = eT(0); for(uword i=0; i arma_hot inline typename T1::elem_type trace_mul_proxy(const T1& XA, const T2& XB) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy PA(XA); const Proxy PB(XB); if(is_Mat::stored_type>::value == true) { return trace_mul_unwrap(PA.Q, PB.Q); } arma_debug_assert_mul_size(PA.get_n_rows(), PA.get_n_cols(), PB.get_n_rows(), PB.get_n_cols(), "matrix multiplication"); arma_debug_check( (PA.get_n_rows() != PB.get_n_cols()), "trace(): matrix must be square sized" ); const uword N1 = PA.get_n_rows(); // equivalent to PB.get_n_cols(), due to square size requirements const uword N2 = PA.get_n_cols(); // equivalent to PB.get_n_rows(), due to matrix multiplication requirements eT val = eT(0); for(uword i=0; i arma_hot arma_warn_unused inline typename T1::elem_type trace(const Glue& X) { arma_extra_debug_sigprint(); return (is_Mat::value) ? trace_mul_unwrap(X.A, X.B) : trace_mul_proxy(X.A, X.B); } //! trace of sparse object template arma_hot arma_warn_unused inline typename enable_if2::value, typename T1::elem_type>::result trace(const T1& x) { arma_extra_debug_sigprint(); const SpProxy p(x); arma_debug_check( (p.get_n_rows() != p.get_n_cols()), "trace(): matrix must be square sized" ); typedef typename T1::elem_type eT; eT result = eT(0); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { if(it.row() == it.col()) { result += (*it); } ++it; } return result; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_resize_meat.hpp0000644000176000001440000000602612256571476024161 0ustar ripleyusers// Copyright (C) 2011-2013 Conrad Sanderson // Copyright (C) 2011-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_resize //! @{ template inline void op_resize::apply(Mat& actual_out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword out_n_rows = in.aux_uword_a; const uword out_n_cols = in.aux_uword_b; const unwrap tmp(in.m); const Mat& A = tmp.M; const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const bool alias = (&actual_out == &A); if(alias) { if( (A_n_rows == out_n_rows) && (A_n_cols == out_n_cols) ) { return; } if(actual_out.is_empty()) { actual_out.zeros(out_n_rows, out_n_cols); return; } } Mat B; Mat& out = alias ? B : actual_out; out.set_size(out_n_rows, out_n_cols); if( (out_n_rows > A_n_rows) || (out_n_cols > A_n_cols) ) { out.zeros(); } if( (out.n_elem > 0) && (A.n_elem > 0) ) { const uword end_row = (std::min)(out_n_rows, A_n_rows) - 1; const uword end_col = (std::min)(out_n_cols, A_n_cols) - 1; out.submat(0, 0, end_row, end_col) = A.submat(0, 0, end_row, end_col); } if(alias) { actual_out.steal_mem(B); } } template inline void op_resize::apply(Cube& actual_out, const OpCube& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword out_n_rows = in.aux_uword_a; const uword out_n_cols = in.aux_uword_b; const uword out_n_slices = in.aux_uword_c; const unwrap_cube tmp(in.m); const Cube& A = tmp.M; const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword A_n_slices = A.n_slices; const bool alias = (&actual_out == &A); if(alias) { if( (A_n_rows == out_n_rows) && (A_n_cols == out_n_cols) && (A_n_slices == out_n_slices) ) { return; } if(actual_out.is_empty()) { actual_out.zeros(out_n_rows, out_n_cols, out_n_slices); return; } } Cube B; Cube& out = alias ? B : actual_out; out.set_size(out_n_rows, out_n_cols, out_n_slices); if( (out_n_rows > A_n_rows) || (out_n_cols > A_n_cols) || (out_n_slices > A_n_slices) ) { out.zeros(); } if( (out.n_elem > 0) && (A.n_elem > 0) ) { const uword end_row = (std::min)(out_n_rows, A_n_rows) - 1; const uword end_col = (std::min)(out_n_cols, A_n_cols) - 1; const uword end_slice = (std::min)(out_n_slices, A_n_slices) - 1; out.subcube(0, 0, 0, end_row, end_col, end_slice) = A.subcube(0, 0, 0, end_row, end_col, end_slice); } if(alias) { actual_out.steal_mem(B); } } //! @} RcppArmadillo/inst/include/armadillo_bits/lapack_wrapper.hpp0000644000176000001440000006135512254015653024141 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2009 Edmund Highcock // Copyright (C) 2011 James Sanders // Copyright (C) 2012 Eric Jon Sundstrom // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifdef ARMA_USE_LAPACK //! \namespace lapack namespace for LAPACK functions namespace lapack { template inline void getrf(blas_int* m, blas_int* n, eT* a, blas_int* lda, blas_int* ipiv, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sgetrf)(m, n, (T*)a, lda, ipiv, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dgetrf)(m, n, (T*)a, lda, ipiv, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_cgetrf)(m, n, (T*)a, lda, ipiv, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_zgetrf)(m, n, (T*)a, lda, ipiv, info); } } template inline void getri(blas_int* n, eT* a, blas_int* lda, blas_int* ipiv, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sgetri)(n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dgetri)(n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_cgetri)(n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_zgetri)(n, (T*)a, lda, ipiv, (T*)work, lwork, info); } } template inline void trtri(char* uplo, char* diag, blas_int* n, eT* a, blas_int* lda, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_strtri)(uplo, diag, n, (T*)a, lda, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dtrtri)(uplo, diag, n, (T*)a, lda, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_ctrtri)(uplo, diag, n, (T*)a, lda, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_ztrtri)(uplo, diag, n, (T*)a, lda, info); } } template inline void syev(char* jobz, char* uplo, blas_int* n, eT* a, blas_int* lda, eT* w, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_ssyev)(jobz, uplo, n, (T*)a, lda, (T*)w, (T*)work, lwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dsyev)(jobz, uplo, n, (T*)a, lda, (T*)w, (T*)work, lwork, info); } } template inline void syevd(char* jobz, char* uplo, blas_int* n, eT* a, blas_int* lda, eT* w, eT* work, blas_int* lwork, blas_int* iwork, blas_int* liwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_ssyevd)(jobz, uplo, n, (T*)a, lda, (T*)w, (T*)work, lwork, iwork, liwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dsyevd)(jobz, uplo, n, (T*)a, lda, (T*)w, (T*)work, lwork, iwork, liwork, info); } } template inline void heev ( char* jobz, char* uplo, blas_int* n, eT* a, blas_int* lda, typename eT::value_type* w, eT* work, blas_int* lwork, typename eT::value_type* rwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value == true) { typedef float T; typedef typename std::complex cx_T; arma_fortran(arma_cheev)(jobz, uplo, n, (cx_T*)a, lda, (T*)w, (cx_T*)work, lwork, (T*)rwork, info); } else if(is_supported_complex_double::value == true) { typedef double T; typedef typename std::complex cx_T; arma_fortran(arma_zheev)(jobz, uplo, n, (cx_T*)a, lda, (T*)w, (cx_T*)work, lwork, (T*)rwork, info); } } template inline void heevd ( char* jobz, char* uplo, blas_int* n, eT* a, blas_int* lda, typename eT::value_type* w, eT* work, blas_int* lwork, typename eT::value_type* rwork, blas_int* lrwork, blas_int* iwork, blas_int* liwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value == true) { typedef float T; typedef typename std::complex cx_T; arma_fortran(arma_cheevd)(jobz, uplo, n, (cx_T*)a, lda, (T*)w, (cx_T*)work, lwork, (T*)rwork, lrwork, iwork, liwork, info); } else if(is_supported_complex_double::value == true) { typedef double T; typedef typename std::complex cx_T; arma_fortran(arma_zheevd)(jobz, uplo, n, (cx_T*)a, lda, (T*)w, (cx_T*)work, lwork, (T*)rwork, lrwork, iwork, liwork, info); } } template inline void geev ( char* jobvl, char* jobvr, blas_int* n, eT* a, blas_int* lda, eT* wr, eT* wi, eT* vl, blas_int* ldvl, eT* vr, blas_int* ldvr, eT* work, blas_int* lwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sgeev)(jobvl, jobvr, n, (T*)a, lda, (T*)wr, (T*)wi, (T*)vl, ldvl, (T*)vr, ldvr, (T*)work, lwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dgeev)(jobvl, jobvr, n, (T*)a, lda, (T*)wr, (T*)wi, (T*)vl, ldvl, (T*)vr, ldvr, (T*)work, lwork, info); } } template inline void cx_geev ( char* jobvl, char* jobvr, blas_int* n, eT* a, blas_int* lda, eT* w, eT* vl, blas_int* ldvl, eT* vr, blas_int* ldvr, eT* work, blas_int* lwork, typename eT::value_type* rwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value == true) { typedef float T; typedef typename std::complex cx_T; arma_fortran(arma_cgeev)(jobvl, jobvr, n, (cx_T*)a, lda, (cx_T*)w, (cx_T*)vl, ldvl, (cx_T*)vr, ldvr, (cx_T*)work, lwork, (T*)rwork, info); } else if(is_supported_complex_double::value == true) { typedef double T; typedef typename std::complex cx_T; arma_fortran(arma_zgeev)(jobvl, jobvr, n, (cx_T*)a, lda, (cx_T*)w, (cx_T*)vl, ldvl, (cx_T*)vr, ldvr, (cx_T*)work, lwork, (T*)rwork, info); } } template inline void ggev ( char* jobvl, char* jobvr, blas_int* n, eT* a, blas_int* lda, eT* b, blas_int* ldb, eT* alphar, eT* alphai, eT* beta, eT* vl, blas_int* ldvl, eT* vr, blas_int* ldvr, eT* work, blas_int* lwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sggev)(jobvl, jobvr, n, (T*)a, lda, (T*)b, ldb, (T*)alphar, (T*)alphai, (T*)beta, (T*)vl, ldvl, (T*)vr, ldvr, (T*)work, lwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dggev)(jobvl, jobvr, n, (T*)a, lda, (T*)b, ldb, (T*)alphar, (T*)alphai, (T*)beta, (T*)vl, ldvl, (T*)vr, ldvr, (T*)work, lwork, info); } } template inline void cx_ggev ( char* jobvl, char* jobvr, blas_int* n, eT* a, blas_int* lda, eT* b, blas_int* ldb, eT* alpha, eT* beta, eT* vl, blas_int* ldvl, eT* vr, blas_int* ldvr, eT* work, blas_int* lwork, typename eT::value_type* rwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value == true) { typedef float T; typedef typename std::complex cx_T; arma_fortran(arma_cggev)(jobvl, jobvr, n, (cx_T*)a, lda, (cx_T*)b, ldb, (cx_T*)alpha, (cx_T*)beta, (cx_T*)vl, ldvl, (cx_T*)vr, ldvr, (cx_T*)work, lwork, (T*)rwork, info); } else if(is_supported_complex_double::value == true) { typedef double T; typedef typename std::complex cx_T; arma_fortran(arma_zggev)(jobvl, jobvr, n, (cx_T*)a, lda, (cx_T*)b, ldb, (cx_T*)alpha, (cx_T*)beta, (cx_T*)vl, ldvl, (cx_T*)vr, ldvr, (cx_T*)work, lwork, (T*)rwork, info); } } template inline void potrf(char* uplo, blas_int* n, eT* a, blas_int* lda, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_spotrf)(uplo, n, (T*)a, lda, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dpotrf)(uplo, n, (T*)a, lda, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_cpotrf)(uplo, n, (T*)a, lda, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_zpotrf)(uplo, n, (T*)a, lda, info); } } template inline void potri(char* uplo, blas_int* n, eT* a, blas_int* lda, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_spotri)(uplo, n, (T*)a, lda, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dpotri)(uplo, n, (T*)a, lda, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_cpotri)(uplo, n, (T*)a, lda, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_zpotri)(uplo, n, (T*)a, lda, info); } } template inline void geqrf(blas_int* m, blas_int* n, eT* a, blas_int* lda, eT* tau, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sgeqrf)(m, n, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dgeqrf)(m, n, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_cgeqrf)(m, n, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_zgeqrf)(m, n, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } } template inline void orgqr(blas_int* m, blas_int* n, blas_int* k, eT* a, blas_int* lda, eT* tau, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sorgqr)(m, n, k, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dorgqr)(m, n, k, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } } template inline void ungqr(blas_int* m, blas_int* n, blas_int* k, eT* a, blas_int* lda, eT* tau, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value == true) { typedef float T; arma_fortran(arma_cungqr)(m, n, k, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } else if(is_supported_complex_double::value == true) { typedef double T; arma_fortran(arma_zungqr)(m, n, k, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } } template inline void gesvd ( char* jobu, char* jobvt, blas_int* m, blas_int* n, eT* a, blas_int* lda, eT* s, eT* u, blas_int* ldu, eT* vt, blas_int* ldvt, eT* work, blas_int* lwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sgesvd)(jobu, jobvt, m, n, (T*)a, lda, (T*)s, (T*)u, ldu, (T*)vt, ldvt, (T*)work, lwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dgesvd)(jobu, jobvt, m, n, (T*)a, lda, (T*)s, (T*)u, ldu, (T*)vt, ldvt, (T*)work, lwork, info); } } template inline void cx_gesvd ( char* jobu, char* jobvt, blas_int* m, blas_int* n, std::complex* a, blas_int* lda, T* s, std::complex* u, blas_int* ldu, std::complex* vt, blas_int* ldvt, std::complex* work, blas_int* lwork, T* rwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); arma_type_check(( is_supported_blas_type< std::complex >::value == false )); if(is_float::value == true) { typedef float bT; arma_fortran(arma_cgesvd) ( jobu, jobvt, m, n, (std::complex*)a, lda, (bT*)s, (std::complex*)u, ldu, (std::complex*)vt, ldvt, (std::complex*)work, lwork, (bT*)rwork, info ); } else if(is_double::value == true) { typedef double bT; arma_fortran(arma_zgesvd) ( jobu, jobvt, m, n, (std::complex*)a, lda, (bT*)s, (std::complex*)u, ldu, (std::complex*)vt, ldvt, (std::complex*)work, lwork, (bT*)rwork, info ); } } template inline void gesdd ( char* jobz, blas_int* m, blas_int* n, eT* a, blas_int* lda, eT* s, eT* u, blas_int* ldu, eT* vt, blas_int* ldvt, eT* work, blas_int* lwork, blas_int* iwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sgesdd)(jobz, m, n, (T*)a, lda, (T*)s, (T*)u, ldu, (T*)vt, ldvt, (T*)work, lwork, iwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dgesdd)(jobz, m, n, (T*)a, lda, (T*)s, (T*)u, ldu, (T*)vt, ldvt, (T*)work, lwork, iwork, info); } } template inline void cx_gesdd ( char* jobz, blas_int* m, blas_int* n, std::complex* a, blas_int* lda, T* s, std::complex* u, blas_int* ldu, std::complex* vt, blas_int* ldvt, std::complex* work, blas_int* lwork, T* rwork, blas_int* iwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); arma_type_check(( is_supported_blas_type< std::complex >::value == false )); if(is_float::value == true) { typedef float bT; arma_fortran(arma_cgesdd) ( jobz, m, n, (std::complex*)a, lda, (bT*)s, (std::complex*)u, ldu, (std::complex*)vt, ldvt, (std::complex*)work, lwork, (bT*)rwork, iwork, info ); } else if(is_double::value == true) { typedef double bT; arma_fortran(arma_zgesdd) ( jobz, m, n, (std::complex*)a, lda, (bT*)s, (std::complex*)u, ldu, (std::complex*)vt, ldvt, (std::complex*)work, lwork, (bT*)rwork, iwork, info ); } } template inline void gesv(blas_int* n, blas_int* nrhs, eT* a, blas_int* lda, blas_int* ipiv, eT* b, blas_int* ldb, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sgesv)(n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dgesv)(n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_cgesv)(n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_zgesv)(n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info); } } template inline void gels(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, eT* a, blas_int* lda, eT* b, blas_int* ldb, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sgels)(trans, m, n, nrhs, (T*)a, lda, (T*)b, ldb, (T*)work, lwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dgels)(trans, m, n, nrhs, (T*)a, lda, (T*)b, ldb, (T*)work, lwork, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_cgels)(trans, m, n, nrhs, (T*)a, lda, (T*)b, ldb, (T*)work, lwork, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_zgels)(trans, m, n, nrhs, (T*)a, lda, (T*)b, ldb, (T*)work, lwork, info); } } template inline void trtrs(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const eT* a, blas_int* lda, eT* b, blas_int* ldb, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_strtrs)(uplo, trans, diag, n, nrhs, (T*)a, lda, (T*)b, ldb, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dtrtrs)(uplo, trans, diag, n, nrhs, (T*)a, lda, (T*)b, ldb, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_ctrtrs)(uplo, trans, diag, n, nrhs, (T*)a, lda, (T*)b, ldb, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_ztrtrs)(uplo, trans, diag, n, nrhs, (T*)a, lda, (T*)b, ldb, info); } } template inline void gees(char* jobvs, char* sort, blas_int* select, blas_int* n, eT* a, blas_int* lda, blas_int* sdim, eT* wr, eT* wi, eT* vs, blas_int* ldvs, eT* work, blas_int* lwork, blas_int* bwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sgees)(jobvs, sort, select, n, (T*)a, lda, sdim, (T*)wr, (T*)wi, (T*)vs, ldvs, (T*)work, lwork, bwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dgees)(jobvs, sort, select, n, (T*)a, lda, sdim, (T*)wr, (T*)wi, (T*)vs, ldvs, (T*)work, lwork, bwork, info); } } template inline void cx_gees(char* jobvs, char* sort, blas_int* select, blas_int* n, std::complex* a, blas_int* lda, blas_int* sdim, std::complex* w, std::complex* vs, blas_int* ldvs, std::complex* work, blas_int* lwork, T* rwork, blas_int* bwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); arma_type_check(( is_supported_blas_type< std::complex >::value == false )); if(is_float::value == true) { typedef float bT; typedef std::complex cT; arma_fortran(arma_cgees)(jobvs, sort, select, n, (cT*)a, lda, sdim, (cT*)w, (cT*)vs, ldvs, (cT*)work, lwork, (bT*)rwork, bwork, info); } else if(is_double::value == true) { typedef double bT; typedef std::complex cT; arma_fortran(arma_zgees)(jobvs, sort, select, n, (cT*)a, lda, sdim, (cT*)w, (cT*)vs, ldvs, (cT*)work, lwork, (bT*)rwork, bwork, info); } } template inline void trsyl(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const eT* a, blas_int* lda, const eT* b, blas_int* ldb, eT* c, blas_int* ldc, eT* scale, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_strsyl)(transa, transb, isgn, m, n, (T*)a, lda, (T*)b, ldb, (T*)c, ldc, (T*)scale, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dtrsyl)(transa, transb, isgn, m, n, (T*)a, lda, (T*)b, ldb, (T*)c, ldc, (T*)scale, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_ctrsyl)(transa, transb, isgn, m, n, (T*)a, lda, (T*)b, ldb, (T*)c, ldc, (float*)scale, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_ztrsyl)(transa, transb, isgn, m, n, (T*)a, lda, (T*)b, ldb, (T*)c, ldc, (double*)scale, info); } } template inline void sytrf(char* uplo, blas_int* n, eT* a, blas_int* lda, blas_int* ipiv, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_ssytrf)(uplo, n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dsytrf)(uplo, n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_csytrf)(uplo, n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_zsytrf)(uplo, n, (T*)a, lda, ipiv, (T*)work, lwork, info); } } template inline void sytri(char* uplo, blas_int* n, eT* a, blas_int* lda, blas_int* ipiv, eT* work, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_ssytri)(uplo, n, (T*)a, lda, ipiv, (T*)work, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dsytri)(uplo, n, (T*)a, lda, ipiv, (T*)work, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_csytri)(uplo, n, (T*)a, lda, ipiv, (T*)work, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_zsytri)(uplo, n, (T*)a, lda, ipiv, (T*)work, info); } } } #endif RcppArmadillo/inst/include/armadillo_bits/spop_strans_bones.hpp0000644000176000001440000000115012111344723024665 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_strans //! @{ //! 'matrix transpose' operation class spop_strans { public: template arma_hot inline static void apply(SpMat& out, const SpOp& in); template arma_hot inline static void apply_proxy(SpMat& out, const T1& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/arma_rng_cxx98.hpp0000644000176000001440000000552112265172471023774 0ustar ripleyusers// Copyright (C) 2013-2014 Conrad Sanderson // Copyright (C) 2013-2014 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup arma_rng_cxx98 //! @{ class arma_rng_cxx98 { public: typedef unsigned int seed_type; inline static void set_seed(const seed_type val); arma_inline static int randi_val(); arma_inline static double randu_val(); inline static double randn_val(); template inline static void randn_dual_val(eT& out1, eT& out2); template inline static void randi_fill(eT* mem, const uword N, const int a, const int b); inline static int randi_max_val(); }; inline void arma_rng_cxx98::set_seed(const arma_rng_cxx98::seed_type val) { std::srand(val); } arma_inline int arma_rng_cxx98::randi_val() { return std::rand(); } arma_inline double arma_rng_cxx98::randu_val() { return double( double(std::rand()) * ( double(1) / double(RAND_MAX) ) ); } inline double arma_rng_cxx98::randn_val() { // polar form of the Box-Muller transformation: // http://en.wikipedia.org/wiki/Box-Muller_transformation // http://en.wikipedia.org/wiki/Marsaglia_polar_method double tmp1; double tmp2; double w; do { tmp1 = double(2) * double(std::rand()) * (double(1) / double(RAND_MAX)) - double(1); tmp2 = double(2) * double(std::rand()) * (double(1) / double(RAND_MAX)) - double(1); w = tmp1*tmp1 + tmp2*tmp2; } while ( w >= double(1) ); return double( tmp1 * std::sqrt( (double(-2) * std::log(w)) / w) ); } template inline void arma_rng_cxx98::randn_dual_val(eT& out1, eT& out2) { // make sure we are internally using at least floats typedef typename promote_type::result eTp; eTp tmp1; eTp tmp2; eTp w; do { tmp1 = eTp(2) * eTp(std::rand()) * (eTp(1) / eTp(RAND_MAX)) - eTp(1); tmp2 = eTp(2) * eTp(std::rand()) * (eTp(1) / eTp(RAND_MAX)) - eTp(1); w = tmp1*tmp1 + tmp2*tmp2; } while ( w >= eTp(1) ); const eTp k = std::sqrt( (eTp(-2) * std::log(w)) / w); out1 = eT(tmp1*k); out2 = eT(tmp2*k); } template inline void arma_rng_cxx98::randi_fill(eT* mem, const uword N, const int a, const int b) { if( (a == 0) && (b == RAND_MAX) ) { for(uword i=0; i inline const Glue conv(const Base& A, const Base& B) { arma_extra_debug_sigprint(); return Glue(A.get_ref(), B.get_ref()); } //! @} RcppArmadillo/inst/include/armadillo_bits/SpCol_meat.hpp0000644000176000001440000002723212136352767023201 0ustar ripleyusers// Copyright (C) 2011-2012 Ryan Curtin // Copyright (C) 2011 Matthew Amidon // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpCol //! @{ //! construct an empty column vector template inline SpCol::SpCol() : SpMat(0, 1) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; } //! construct a column vector with the specified number of elements template inline SpCol::SpCol(const uword in_n_elem) : SpMat(in_n_elem, 1) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; } template inline SpCol::SpCol(const uword in_n_rows, const uword in_n_cols) : SpMat(in_n_rows, in_n_cols) { arma_extra_debug_sigprint(); arma_debug_check((in_n_cols != 1), "SpCol::SpCol(): must have only one column"); access::rw(SpMat::vec_state) = 1; } //! construct a column vector from specified text template inline SpCol::SpCol(const char* text) : SpMat(text) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; arma_debug_check((SpMat::n_cols != 1), "SpCol::SpCol(): must have only one column"); } //! construct a column vector from specified text template inline const SpCol& SpCol::operator=(const char* text) { arma_extra_debug_sigprint(); SpMat::init(std::string(text)); access::rw(SpMat::vec_state) = 1; return *this; } //! construct a column vector from specified text template inline SpCol::SpCol(const std::string& text) : SpMat(text) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; arma_debug_check((SpMat::n_cols != 1), "SpCol::SpCol(): must have only one column"); } //! construct a column vector from specified text template inline const SpCol& SpCol::operator=(const std::string& text) { arma_extra_debug_sigprint(); SpMat::init(std::string(text)); return *this; } template inline const SpCol& SpCol::operator=(const eT val) { arma_extra_debug_sigprint(); SpMat::operator=(val); return *this; } template template inline SpCol::SpCol(const Base& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; SpMat::operator=(X.get_ref()); } template template inline const SpCol& SpCol::operator=(const Base& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; SpMat::operator=(X.get_ref()); return *this; } template template inline SpCol::SpCol(const SpBase& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; SpMat::operator=(X.get_ref()); } template template inline const SpCol& SpCol::operator=(const SpBase& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; SpMat::operator=(X.get_ref()); return *this; } template template inline SpCol::SpCol ( const SpBase::pod_type, T1>& A, const SpBase::pod_type, T2>& B ) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; SpMat::init(A,B); } template inline SpValProxy< SpMat > SpCol::row(const uword row_num) { arma_debug_check( (row_num >= SpMat::n_rows), "SpCol::row(): out of bounds" ); return SpMat::at(row_num, 0); } template inline eT SpCol::row(const uword row_num) const { arma_debug_check( (row_num >= SpMat::n_rows), "SpCol::row(): out of bounds" ); return SpMat::at(row_num, 0); } /* template arma_inline subview_col SpCol::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= SpMat::n_rows) ), "Col::rows(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline const subview_col SpCol::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= SpMat::n_rows) ), "Col::rows(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline subview_col SpCol::subvec(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= SpMat::n_rows) ), "Col::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline const subview_col SpCol::subvec(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= SpMat::n_rows) ), "Col::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline subview_col SpCol::subvec(const span& row_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = SpMat::n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subvec_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ), "Col::subvec(): indices out of bounds or incorrectly used"); return subview_col(*this, 0, in_row1, subvec_n_rows); } template arma_inline const subview_col SpCol::subvec(const span& row_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = SpMat::n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subvec_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ), "Col::subvec(): indices out of bounds or incorrectly used"); return subview_col(*this, 0, in_row1, subvec_n_rows); } */ //! remove specified row template inline void SpCol::shed_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( row_num >= SpMat::n_rows, "SpCol::shed_row(): out of bounds"); shed_rows(row_num, row_num); } //! remove specified rows template inline void SpCol::shed_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= SpMat::n_rows), "SpCol::shed_rows(): indices out of bounds or incorrectly used" ); const uword diff = (in_row2 - in_row1 + 1); // This is easy because everything is in one column. uword start = 0, end = 0; bool start_found = false, end_found = false; for(uword i = 0; i < SpMat::n_nonzero; ++i) { // Start position found? if (SpMat::row_indices[i] >= in_row1 && !start_found) { start = i; start_found = true; } // End position found? if (SpMat::row_indices[i] > in_row2) { end = i; end_found = true; break; } } if (!end_found) { end = SpMat::n_nonzero; } // Now we can make the copy. if (start != end) { const uword elem_diff = end - start; eT* new_values = memory::acquire_chunked (SpMat::n_nonzero - elem_diff); uword* new_row_indices = memory::acquire_chunked(SpMat::n_nonzero - elem_diff); // Copy before the section we are dropping (if it exists). if (start > 0) { arrayops::copy(new_values, SpMat::values, start); arrayops::copy(new_row_indices, SpMat::row_indices, start); } // Copy after the section we are dropping (if it exists). if (end != SpMat::n_nonzero) { arrayops::copy(new_values + start, SpMat::values + end, (SpMat::n_nonzero - end)); arrayops::copy(new_row_indices + start, SpMat::row_indices + end, (SpMat::n_nonzero - end)); arrayops::inplace_minus(new_row_indices + start, diff, (SpMat::n_nonzero - end)); } memory::release(SpMat::values); memory::release(SpMat::row_indices); access::rw(SpMat::values) = new_values; access::rw(SpMat::row_indices) = new_row_indices; access::rw(SpMat::n_nonzero) -= elem_diff; access::rw(SpMat::col_ptrs[1]) -= elem_diff; } access::rw(SpMat::n_rows) -= diff; access::rw(SpMat::n_elem) -= diff; } // //! insert N rows at the specified row position, // //! optionally setting the elements of the inserted rows to zero // template // inline // void // SpCol::insert_rows(const uword row_num, const uword N, const bool set_to_zero) // { // arma_extra_debug_sigprint(); // // arma_debug_check(set_to_zero == false, "SpCol::insert_rows(): cannot set nonzero values"); // // arma_debug_check((row_num > SpMat::n_rows), "SpCol::insert_rows(): out of bounds"); // // for(uword row = 0; row < SpMat::n_rows; ++row) // { // if (SpMat::row_indices[row] >= row_num) // { // access::rw(SpMat::row_indices[row]) += N; // } // } // // access::rw(SpMat::n_rows) += N; // access::rw(SpMat::n_elem) += N; // } // // // // //! insert the given object at the specified row position; // //! the given object must have one column // template // template // inline // void // SpCol::insert_rows(const uword row_num, const Base& X) // { // arma_extra_debug_sigprint(); // // SpMat::insert_rows(row_num, X); // } template inline typename SpCol::row_iterator SpCol::begin_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= SpMat::n_rows), "begin_row(): index out of bounds"); return row_iterator(*this, row_num, 0); } template inline typename SpCol::const_row_iterator SpCol::begin_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= SpMat::n_rows), "begin_row(): index out of bounds"); return const_row_iterator(*this, row_num, 0); } template inline typename SpCol::row_iterator SpCol::end_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= SpMat::n_rows), "end_row(): index out of bounds"); return row_iterator(*this, row_num + 1, 0); } template inline typename SpCol::const_row_iterator SpCol::end_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= SpMat::n_rows), "end_row(): index out of bounds"); return const_row_iterator(*this, row_num + 1, 0); } #ifdef ARMA_EXTRA_SPCOL_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPCOL_MEAT) #endif //! @} RcppArmadillo/inst/include/armadillo_bits/op_all_meat.hpp0000644000176000001440000002236312201107550023404 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_all //! @{ template inline bool op_all::all_vec_helper(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); uword count = 0; if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i inline bool op_all::all_vec_helper ( const mtOp& X, const typename arma_op_rel_only::result junk1, const typename arma_not_cx::result junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); typedef typename T1::elem_type eT; const eT val = X.aux; const Proxy P(X.m); const uword n_elem = P.get_n_elem(); uword count = 0; if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < n_elem; ++i) { const eT tmp = Pea[i]; if(is_same_type::yes) { if(val < tmp) { ++count; } } else if(is_same_type::yes) { if(tmp < val) { ++count; } } else if(is_same_type::yes) { if(val > tmp) { ++count; } } else if(is_same_type::yes) { if(tmp > val) { ++count; } } else if(is_same_type::yes) { if(val <= tmp) { ++count; } } else if(is_same_type::yes) { if(tmp <= val) { ++count; } } else if(is_same_type::yes) { if(val >= tmp) { ++count; } } else if(is_same_type::yes) { if(tmp >= val) { ++count; } } else if(is_same_type::yes) { if(tmp == val) { ++count; } } else if(is_same_type::yes) { if(tmp != val) { ++count; } } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT tmp = P.at(row,col); if(is_same_type::yes) { if(val < tmp) { ++count; } } else if(is_same_type::yes) { if(tmp < val) { ++count; } } else if(is_same_type::yes) { if(val > tmp) { ++count; } } else if(is_same_type::yes) { if(tmp > val) { ++count; } } else if(is_same_type::yes) { if(val <= tmp) { ++count; } } else if(is_same_type::yes) { if(tmp <= val) { ++count; } } else if(is_same_type::yes) { if(val >= tmp) { ++count; } } else if(is_same_type::yes) { if(tmp >= val) { ++count; } } else if(is_same_type::yes) { if(tmp == val) { ++count; } } else if(is_same_type::yes) { if(tmp != val) { ++count; } } } } return (n_elem == count); } template inline bool op_all::all_vec_helper ( const mtGlue& X, const typename arma_glue_rel_only::result junk1, const typename arma_not_cx::result junk2, const typename arma_not_cx::result junk3 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); arma_ignore(junk3); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "relational operator"); const uword n_elem = A.get_n_elem(); uword count = 0; const bool prefer_at_accessor = Proxy::prefer_at_accessor || Proxy::prefer_at_accessor; if(prefer_at_accessor == false) { ea_type1 PA = A.get_ea(); ea_type2 PB = B.get_ea(); for(uword i=0; i::yes) { if(tmp1 < tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 > tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 <= tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 >= tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 == tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 != tmp2) { ++count; } } } } else { const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT1 tmp1 = A.at(row,col); const eT2 tmp2 = B.at(row,col); if(is_same_type::yes) { if(tmp1 < tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 > tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 <= tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 >= tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 == tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 != tmp2) { ++count; } } } } return (n_elem == count); } template inline bool op_all::all_vec(T1& X) { arma_extra_debug_sigprint(); return op_all::all_vec_helper(X); } template inline void op_all::apply_helper(Mat& out, const Proxy& P, const uword dim) { arma_extra_debug_sigprint(); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); typedef typename Proxy::elem_type eT; if(dim == 0) // traverse rows (ie. process each column) { out.zeros(1, n_cols); if(out.n_elem == 0) { return; } uword* out_mem = out.memptr(); if(is_Mat::stored_type>::value == true) { const unwrap::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); uword count = 0; for(uword row=0; row < n_rows; ++row) { if(colmem[row] != eT(0)) { ++count; } } out_mem[col] = (n_rows == count) ? uword(1) : uword(0); } } else { for(uword col=0; col < n_cols; ++col) { uword count = 0; for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { ++count; } } out_mem[col] = (n_rows == count) ? uword(1) : uword(0); } } } else { out.zeros(n_rows, 1); uword* out_mem = out.memptr(); // internal dual use of 'out': keep the counts for each row if(is_Mat::stored_type>::value == true) { const unwrap::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); for(uword row=0; row < n_rows; ++row) { if(colmem[row] != eT(0)) { ++out_mem[row]; } } } } else { for(uword col=0; col < n_cols; ++col) { for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { ++out_mem[row]; } } } } // see what the counts tell us for(uword row=0; row < n_rows; ++row) { out_mem[row] = (n_cols == out_mem[row]) ? uword(1) : uword(0); } } } template inline void op_all::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); const uword dim = X.aux_uword_a; const Proxy P(X.m); if(P.is_alias(out) == false) { op_all::apply_helper(out, P, dim); } else { Mat out2; op_all::apply_helper(out2, P, dim); out.steal_mem(out2); } } //! @} RcppArmadillo/inst/include/armadillo_bits/op_sum_bones.hpp0000644000176000001440000000110312200631217023606 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_sum //! @{ //! Class for finding sums of values in a matrix (e.g. along rows or columns) class op_sum { public: template arma_hot inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/subview_each_meat.hpp0000644000176000001440000003427212111570631024610 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup subview_each //! @{ // // // subview_each_common template inline subview_each_common::subview_each_common(parent& in_p) : p(in_p) { arma_extra_debug_sigprint(); } template arma_inline const Mat& subview_each_common::get_mat_ref_helper(const Mat& X) const { return X; } template arma_inline const Mat& subview_each_common::get_mat_ref_helper(const subview& X) const { return X.m; } template arma_inline const Mat& subview_each_common::get_mat_ref() const { return get_mat_ref_helper(p); } template inline void subview_each_common::check_size(const Mat& A) const { if(arma_config::debug == true) { if(mode == 0) { if( (A.n_rows != p.n_rows) || (A.n_cols != 1) ) { arma_stop( incompat_size_string(A) ); } } else { if( (A.n_rows != 1) || (A.n_cols != p.n_cols) ) { arma_stop( incompat_size_string(A) ); } } } } template arma_cold inline const std::string subview_each_common::incompat_size_string(const Mat& A) const { std::stringstream tmp; if(mode == 0) { tmp << "each_col(): incompatible size; expected " << p.n_rows << "x1" << ", got " << A.n_rows << 'x' << A.n_cols; } else { tmp << "each_row(): incompatible size; expected 1x" << p.n_cols << ", got " << A.n_rows << 'x' << A.n_cols; } return tmp.str(); } // // // subview_each1 template inline subview_each1::~subview_each1() { arma_extra_debug_sigprint(); } template inline subview_each1::subview_each1(parent& in_p) : subview_each_common::subview_each_common(in_p) { arma_extra_debug_sigprint(); } template template inline void subview_each1::operator= (const Base& in) { arma_extra_debug_sigprint(); parent& p = subview_each_common::p; const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { arrayops::copy( p.colptr(i), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_set( p.colptr(i), A_mem[i], p_n_rows); } } } template template inline void subview_each1::operator+= (const Base& in) { arma_extra_debug_sigprint(); parent& p = subview_each_common::p; const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_plus( p.colptr(i), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_plus( p.colptr(i), A_mem[i], p_n_rows); } } } template template inline void subview_each1::operator-= (const Base& in) { arma_extra_debug_sigprint(); parent& p = subview_each_common::p; const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_minus( p.colptr(i), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_minus( p.colptr(i), A_mem[i], p_n_rows); } } } template template inline void subview_each1::operator%= (const Base& in) { arma_extra_debug_sigprint(); parent& p = subview_each_common::p; const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_mul( p.colptr(i), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_mul( p.colptr(i), A_mem[i], p_n_rows); } } } template template inline void subview_each1::operator/= (const Base& in) { arma_extra_debug_sigprint(); parent& p = subview_each_common::p; const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_div( p.colptr(i), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_div( p.colptr(i), A_mem[i], p_n_rows); } } } // // // subview_each2 template inline subview_each2::~subview_each2() { arma_extra_debug_sigprint(); } template inline subview_each2::subview_each2(parent& in_p, const Base& in_indices) : subview_each_common::subview_each_common(in_p) , base_indices(in_indices) { arma_extra_debug_sigprint(); } template inline void subview_each2::check_indices(const Mat& indices) const { if(mode == 0) { arma_debug_check( ((indices.is_vec() == false) && (indices.is_empty() == false)), "each_col(): list of indices must be a vector" ); } else { arma_debug_check( ((indices.is_vec() == false) && (indices.is_empty() == false)), "each_row(): list of indices must be a vector" ); } } template template inline void subview_each2::operator= (const Base& in) { arma_extra_debug_sigprint(); parent& p = subview_each_common::p; const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const unwrap_check_mixed tmp_indices( base_indices.get_ref(), (*this).get_mat_ref() ); const Mat& indices = tmp_indices.M; check_indices(indices); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword* indices_mem = indices.memptr(); const uword N = indices.n_elem; if(mode == 0) // each column { for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col > p_n_cols), "each_col(): index out of bounds" ); arrayops::copy( p.colptr(col), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row > p_n_rows), "each_row(): index out of bounds" ); for(uword col=0; col < p_n_cols; ++col) { p.at(row,col) = A_mem[col]; } } } } template template inline void subview_each2::operator+= (const Base& in) { arma_extra_debug_sigprint(); parent& p = subview_each_common::p; const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const unwrap_check_mixed tmp_indices( base_indices.get_ref(), (*this).get_mat_ref() ); const Mat& indices = tmp_indices.M; check_indices(indices); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword* indices_mem = indices.memptr(); const uword N = indices.n_elem; if(mode == 0) // each column { for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col > p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_plus( p.colptr(col), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row > p_n_rows), "each_row(): index out of bounds" ); for(uword col=0; col < p_n_cols; ++col) { p.at(row,col) += A_mem[col]; } } } } template template inline void subview_each2::operator-= (const Base& in) { arma_extra_debug_sigprint(); parent& p = subview_each_common::p; const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const unwrap_check_mixed tmp_indices( base_indices.get_ref(), (*this).get_mat_ref() ); const Mat& indices = tmp_indices.M; check_indices(indices); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword* indices_mem = indices.memptr(); const uword N = indices.n_elem; if(mode == 0) // each column { for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col > p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_minus( p.colptr(col), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row > p_n_rows), "each_row(): index out of bounds" ); for(uword col=0; col < p_n_cols; ++col) { p.at(row,col) -= A_mem[col]; } } } } template template inline void subview_each2::operator%= (const Base& in) { arma_extra_debug_sigprint(); parent& p = subview_each_common::p; const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const unwrap_check_mixed tmp_indices( base_indices.get_ref(), (*this).get_mat_ref() ); const Mat& indices = tmp_indices.M; check_indices(indices); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword* indices_mem = indices.memptr(); const uword N = indices.n_elem; if(mode == 0) // each column { for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col > p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_mul( p.colptr(col), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row > p_n_rows), "each_row(): index out of bounds" ); for(uword col=0; col < p_n_cols; ++col) { p.at(row,col) *= A_mem[col]; } } } } template template inline void subview_each2::operator/= (const Base& in) { arma_extra_debug_sigprint(); parent& p = subview_each_common::p; const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const unwrap_check_mixed tmp_indices( base_indices.get_ref(), (*this).get_mat_ref() ); const Mat& indices = tmp_indices.M; check_indices(indices); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword* indices_mem = indices.memptr(); const uword N = indices.n_elem; if(mode == 0) // each column { for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col > p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_div( p.colptr(col), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row > p_n_rows), "each_row(): index out of bounds" ); for(uword col=0; col < p_n_cols; ++col) { p.at(row,col) /= A_mem[col]; } } } } //! @} RcppArmadillo/inst/include/armadillo_bits/subview_elem2_bones.hpp0000644000176000001440000000574212176655102025104 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup subview_elem2 //! @{ template class subview_elem2 : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = false; arma_aligned const Mat& m; arma_aligned const Base& base_ri; arma_aligned const Base& base_ci; const bool all_rows; const bool all_cols; protected: arma_inline subview_elem2(const Mat& in_m, const Base& in_ri, const Base& in_ci, const bool in_all_rows, const bool in_all_cols); public: inline ~subview_elem2(); template inline void inplace_op(const eT val); template inline void inplace_op(const Base& x); inline void fill(const eT val); inline void zeros(); inline void ones(); inline void operator+= (const eT val); inline void operator-= (const eT val); inline void operator*= (const eT val); inline void operator/= (const eT val); // deliberately returning void template inline void operator_equ(const subview_elem2& x); template inline void operator= (const subview_elem2& x); inline void operator= (const subview_elem2& x); template inline void operator+= (const subview_elem2& x); template inline void operator-= (const subview_elem2& x); template inline void operator%= (const subview_elem2& x); template inline void operator/= (const subview_elem2& x); template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); inline static void extract(Mat& out, const subview_elem2& in); inline static void plus_inplace(Mat& out, const subview_elem2& in); inline static void minus_inplace(Mat& out, const subview_elem2& in); inline static void schur_inplace(Mat& out, const subview_elem2& in); inline static void div_inplace(Mat& out, const subview_elem2& in); private: friend class Mat; subview_elem2(); }; //! @} RcppArmadillo/inst/include/armadillo_bits/constants_compat.hpp0000644000176000001440000001265512236716467024537 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup constants_compat //! @{ // the Math and Phy classes are kept for compatibility with old code; // for new code, use the Datum class instead // eg. instead of math::pi(), use datum::pi template class Math { public: // the long lengths of the constants are for future support of "long double" // and any smart compiler that does high-precision computation at compile-time //! ratio of any circle's circumference to its diameter static eT pi() { return eT(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679); } //! base of the natural logarithm static eT e() { return eT(2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274); } //! Euler's constant, aka Euler-Mascheroni constant static eT euler() { return eT(0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495); } //! golden ratio static eT gratio() { return eT(1.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374); } //! square root of 2 static eT sqrt2() { return eT(1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727); } //! the difference between 1 and the least value greater than 1 that is representable static eT eps() { return std::numeric_limits::epsilon(); } //! log of the minimum representable value static eT log_min() { static const eT out = std::log(std::numeric_limits::min()); return out; } //! log of the maximum representable value static eT log_max() { static const eT out = std::log(std::numeric_limits::max()); return out; } //! "not a number" static eT nan() { return priv::Datum_helper::nan(); } //! infinity static eT inf() { return priv::Datum_helper::inf(); } }; //! Physical constants taken from NIST and WolframAlpha on 2009-06-23 //! http://physics.nist.gov/cuu/Constants //! http://www.wolframalpha.com //! See also http://en.wikipedia.org/wiki/Physical_constant template class Phy { public: //! atomic mass constant (in kg) static eT m_u() { return eT(1.660538782e-27); } //! Avogadro constant static eT N_A() { return eT(6.02214179e23); } //! Boltzmann constant (in joules per kelvin) static eT k() { return eT(1.3806504e-23); } //! Boltzmann constant (in eV/K) static eT k_evk() { return eT(8.617343e-5); } //! Bohr radius (in meters) static eT a_0() { return eT(0.52917720859e-10); } //! Bohr magneton static eT mu_B() { return eT(927.400915e-26); } //! characteristic impedance of vacuum (in ohms) static eT Z_0() { return eT(3.76730313461771e-2); } //! conductance quantum (in siemens) static eT G_0() { return eT(7.7480917004e-5); } //! Coulomb's constant (in meters per farad) static eT k_e() { return eT(8.9875517873681764e9); } //! electric constant (in farads per meter) static eT eps_0() { return eT(8.85418781762039e-12); } //! electron mass (in kg) static eT m_e() { return eT(9.10938215e-31); } //! electron volt (in joules) static eT eV() { return eT(1.602176487e-19); } //! elementary charge (in coulombs) static eT e() { return eT(1.602176487e-19); } //! Faraday constant (in coulombs) static eT F() { return eT(96485.3399); } //! fine-structure constant static eT alpha() { return eT(7.2973525376e-3); } //! inverse fine-structure constant static eT alpha_inv() { return eT(137.035999679); } //! Josephson constant static eT K_J() { return eT(483597.891e9); } //! magnetic constant (in henries per meter) static eT mu_0() { return eT(1.25663706143592e-06); } //! magnetic flux quantum (in webers) static eT phi_0() { return eT(2.067833667e-15); } //! molar gas constant (in joules per mole kelvin) static eT R() { return eT(8.314472); } //! Newtonian constant of gravitation (in newton square meters per kilogram squared) static eT G() { return eT(6.67428e-11); } //! Planck constant (in joule seconds) static eT h() { return eT(6.62606896e-34); } //! Planck constant over 2 pi, aka reduced Planck constant (in joule seconds) static eT h_bar() { return eT(1.054571628e-34); } //! proton mass (in kg) static eT m_p() { return eT(1.672621637e-27); } //! Rydberg constant (in reciprocal meters) static eT R_inf() { return eT(10973731.568527); } //! speed of light in vacuum (in meters per second) static eT c_0() { return eT(299792458.0); } //! Stefan-Boltzmann constant static eT sigma() { return eT(5.670400e-8); } //! von Klitzing constant (in ohms) static eT R_k() { return eT(25812.807557); } //! Wien wavelength displacement law constant static eT b() { return eT(2.8977685e-3); } }; typedef Math fmath; typedef Math math; typedef Phy fphy; typedef Phy phy; //! @} RcppArmadillo/inst/include/armadillo_bits/op_fft_bones.hpp0000644000176000001440000000265212127513551023603 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_fft //! @{ class op_fft_real { public: template inline static void apply( Mat< std::complex >& out, const mtOp,T1,op_fft_real>& in ); }; class op_fft_cx { public: template inline static void apply( Mat& out, const Op& in ); template inline static void apply_noalias(Mat& out, const Proxy& P, const uword a, const uword b); template arma_hot inline static void copy_vec (typename Proxy::elem_type* dest, const Proxy& P, const uword N); template arma_hot inline static void copy_vec_proxy (typename Proxy::elem_type* dest, const Proxy& P, const uword N); template arma_hot inline static void copy_vec_unwrap(typename Proxy::elem_type* dest, const Proxy& P, const uword N); }; class op_ifft_cx { public: template inline static void apply( Mat& out, const Op& in ); }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_pinv_meat.hpp0000644000176000001440000000516112224726163023621 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // Copyright (C) 2011 Stanislav Funiak // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_pinv //! @{ template inline void op_pinv::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const bool use_divide_and_conquer = (in.aux_uword_a == 1); T tol = access::tmp_real(in.aux); arma_debug_check((tol < T(0)), "pinv(): tolerance must be >= 0"); const Proxy P(in.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if( (n_rows*n_cols) == 0 ) { out.set_size(n_cols,n_rows); return; } // economical SVD decomposition Mat U; Col< T> s; Mat V; bool status = false; if(use_divide_and_conquer) { status = (n_cols > n_rows) ? auxlib::svd_dc_econ(U, s, V, trans(P.Q)) : auxlib::svd_dc_econ(U, s, V, P.Q); } else { status = (n_cols > n_rows) ? auxlib::svd_econ(U, s, V, trans(P.Q), 'b') : auxlib::svd_econ(U, s, V, P.Q, 'b'); } if(status == false) { out.reset(); arma_bad("pinv(): svd failed"); return; } const uword s_n_elem = s.n_elem; const T* s_mem = s.memptr(); // set tolerance to default if it hasn't been specified as an argument if( (tol == T(0)) && (s_n_elem > 0) ) { tol = (std::max)(n_rows, n_cols) * eop_aux::direct_eps( op_max::direct_max(s_mem, s_n_elem) ); } // count non zero valued elements in s uword count = 0; for(uword i = 0; i < s_n_elem; ++i) { if(s_mem[i] > tol) { ++count; } } if(count > 0) { Col s2(count); T* s2_mem = s2.memptr(); uword count2 = 0; for(uword i=0; i < s_n_elem; ++i) { const T val = s_mem[i]; if(val > tol) { s2_mem[count2] = T(1) / val; ++count2; } } if(n_rows >= n_cols) { out = ( (V.n_cols > count) ? V.cols(0,count-1) : V ) * diagmat(s2) * trans( (U.n_cols > count) ? U.cols(0,count-1) : U ); } else { out = ( (U.n_cols > count) ? U.cols(0,count-1) : U ) * diagmat(s2) * trans( (V.n_cols > count) ? V.cols(0,count-1) : V ); } } else { out.zeros(n_cols, n_rows); } } //! @} RcppArmadillo/inst/include/armadillo_bits/field_bones.hpp0000644000176000001440000002703412245546626023424 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Ian Cullinan // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup field //! @{ struct field_prealloc_n_elem { static const uword val = 16; }; //! A lightweight 2D container for arbitrary objects //! (the objects must have a copy constructor) template class field { public: typedef oT object_type; const uword n_rows; //!< number of rows in the field (read-only) const uword n_cols; //!< number of columns in the field (read-only) const uword n_elem; //!< number of elements in the field (read-only) private: arma_aligned oT** mem; //!< pointer to memory used by the object arma_aligned oT* mem_local[ field_prealloc_n_elem::val ]; //!< Internal memory, to avoid calling the 'new' operator for small amounts of memory public: inline ~field(); inline field(); inline field(const field& x); inline const field& operator=(const field& x); inline field(const subview_field& x); inline const field& operator=(const subview_field& x); inline explicit field(const uword n_elem_in); inline field(const uword n_rows_in, const uword n_cols_in); inline void set_size(const uword n_obj_in); inline void set_size(const uword n_rows_in, const uword n_cols_in); template inline void copy_size(const field& x); arma_inline oT& operator[](const uword i); arma_inline const oT& operator[](const uword i) const; arma_inline oT& at(const uword i); arma_inline const oT& at(const uword i) const; arma_inline oT& operator()(const uword i); arma_inline const oT& operator()(const uword i) const; arma_inline oT& at(const uword row, const uword col); arma_inline const oT& at(const uword row, const uword col) const; arma_inline oT& operator()(const uword row, const uword col); arma_inline const oT& operator()(const uword row, const uword col) const; inline field_injector operator<<(const oT& val); inline field_injector operator<<(const injector_end_of_row<>& x); inline subview_field row(const uword row_num); inline const subview_field row(const uword row_num) const; inline subview_field col(const uword col_num); inline const subview_field col(const uword col_num) const; inline subview_field rows(const uword in_row1, const uword in_row2); inline const subview_field rows(const uword in_row1, const uword in_row2) const; inline subview_field cols(const uword in_col1, const uword in_col2); inline const subview_field cols(const uword in_col1, const uword in_col2) const; inline subview_field subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); inline const subview_field subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; inline subview_field subfield(const uword in_row1, const uword in_col1, const SizeMat& s); inline const subview_field subfield(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline subview_field subfield (const span& row_span, const span& col_span); inline const subview_field subfield (const span& row_span, const span& col_span) const; inline subview_field operator()(const span& row_span, const span& col_span); inline const subview_field operator()(const span& row_span, const span& col_span) const; inline subview_field operator()(const uword in_row1, const uword in_col1, const SizeMat& s); inline const subview_field operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline void print(const std::string extra_text = "") const; inline void print(std::ostream& user_stream, const std::string extra_text = "") const; inline void fill(const oT& x); inline void reset(); inline void reset_objects(); arma_inline bool is_empty() const; arma_inline arma_warn_unused bool in_range(const uword i) const; arma_inline arma_warn_unused bool in_range(const span& x) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const SizeMat& s) const; inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const; inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const; inline bool load(const std::string name, const file_type type = auto_detect, const bool print_status = true); inline bool load( std::istream& is, const file_type type = auto_detect, const bool print_status = true); inline bool quiet_save(const std::string name, const file_type type = arma_binary) const; inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const; inline bool quiet_load(const std::string name, const file_type type = auto_detect); inline bool quiet_load( std::istream& is, const file_type type = auto_detect); // for container-like functionality typedef oT value_type; typedef uword size_type; class iterator { public: inline iterator(field& in_M, const bool at_end = false); inline oT& operator* (); inline iterator& operator++(); inline void operator++(int); inline iterator& operator--(); inline void operator--(int); inline bool operator!=(const iterator& X) const; inline bool operator==(const iterator& X) const; arma_aligned field& M; arma_aligned uword i; }; class const_iterator { public: const_iterator(const field& in_M, const bool at_end = false); const_iterator(const iterator& X); inline const oT& operator*() const; inline const_iterator& operator++(); inline void operator++(int); inline const_iterator& operator--(); inline void operator--(int); inline bool operator!=(const const_iterator& X) const; inline bool operator==(const const_iterator& X) const; arma_aligned const field& M; arma_aligned uword i; }; inline iterator begin(); inline const_iterator begin() const; inline const_iterator cbegin() const; inline iterator end(); inline const_iterator end() const; inline const_iterator cend() const; inline void clear(); inline bool empty() const; inline uword size() const; private: inline void init(const field& x); inline void init(const uword n_rows_in, const uword n_cols_in); inline void delete_objects(); inline void create_objects(); friend class field_aux; friend class subview_field; public: #ifdef ARMA_EXTRA_FIELD_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_FIELD_PROTO) #endif }; class field_aux { public: template inline static void reset_objects(field< oT >& x); template inline static void reset_objects(field< Mat >& x); template inline static void reset_objects(field< Col >& x); template inline static void reset_objects(field< Row >& x); template inline static void reset_objects(field< Cube >& x); inline static void reset_objects(field< std::string >& x); template inline static bool save(const field< oT >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool save(const field< oT >& x, std::ostream& os, const file_type type, std::string& err_msg); template inline static bool load( field< oT >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool load( field< oT >& x, std::istream& is, const file_type type, std::string& err_msg); template inline static bool save(const field< Mat >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool save(const field< Mat >& x, std::ostream& os, const file_type type, std::string& err_msg); template inline static bool load( field< Mat >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool load( field< Mat >& x, std::istream& is, const file_type type, std::string& err_msg); template inline static bool save(const field< Col >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool save(const field< Col >& x, std::ostream& os, const file_type type, std::string& err_msg); template inline static bool load( field< Col >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool load( field< Col >& x, std::istream& is, const file_type type, std::string& err_msg); template inline static bool save(const field< Row >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool save(const field< Row >& x, std::ostream& os, const file_type type, std::string& err_msg); template inline static bool load( field< Row >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool load( field< Row >& x, std::istream& is, const file_type type, std::string& err_msg); template inline static bool save(const field< Cube >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool save(const field< Cube >& x, std::ostream& os, const file_type type, std::string& err_msg); template inline static bool load( field< Cube >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool load( field< Cube >& x, std::istream& is, const file_type type, std::string& err_msg); inline static bool save(const field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg); inline static bool save(const field< std::string >& x, std::ostream& os, const file_type type, std::string& err_msg); inline static bool load( field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg); inline static bool load( field< std::string >& x, std::istream& is, const file_type type, std::string& err_msg); }; //! @} RcppArmadillo/inst/include/armadillo_bits/diagview_meat.hpp0000644000176000001440000005025412246034243023744 0ustar ripleyusers// Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // Copyright (C) 2008-2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup diagview //! @{ template inline diagview::~diagview() { arma_extra_debug_sigprint(); } template arma_inline diagview::diagview(const Mat& in_m, const uword in_row_offset, const uword in_col_offset, const uword in_len) : m(in_m) , row_offset(in_row_offset) , col_offset(in_col_offset) , n_rows(in_len) , n_elem(in_len) { arma_extra_debug_sigprint(); } //! set a diagonal of our matrix using a diagonal from a foreign matrix template inline void diagview::operator= (const diagview& x) { arma_extra_debug_sigprint(); diagview& d = *this; arma_debug_check( (d.n_elem != x.n_elem), "diagview: diagonals have incompatible lengths"); Mat& d_m = const_cast< Mat& >(d.m); const Mat& x_m = x.m; if(&d_m != &x_m) { const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const uword x_row_offset = x.row_offset; const uword x_col_offset = x.col_offset; uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_m.at(ii + x_row_offset, ii + x_col_offset); const eT tmp_j = x_m.at(jj + x_row_offset, jj + x_col_offset); d_m.at(ii + d_row_offset, ii + d_col_offset) = tmp_i; d_m.at(jj + d_row_offset, jj + d_col_offset) = tmp_j; } if(ii < d_n_elem) { d_m.at(ii + d_row_offset, ii + d_col_offset) = x_m.at(ii + x_row_offset, ii + x_col_offset); } } else { const Mat tmp = x; (*this).operator=(tmp); } } template inline void diagview::operator+=(const eT val) { arma_extra_debug_sigprint(); Mat& t_m = const_cast< Mat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword ii=0; ii < t_n_elem; ++ii) { t_m.at( ii + t_row_offset, ii + t_col_offset) += val; } } template inline void diagview::operator-=(const eT val) { arma_extra_debug_sigprint(); Mat& t_m = const_cast< Mat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword ii=0; ii < t_n_elem; ++ii) { t_m.at( ii + t_row_offset, ii + t_col_offset) -= val; } } template inline void diagview::operator*=(const eT val) { arma_extra_debug_sigprint(); Mat& t_m = const_cast< Mat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword ii=0; ii < t_n_elem; ++ii) { t_m.at( ii + t_row_offset, ii + t_col_offset) *= val; } } template inline void diagview::operator/=(const eT val) { arma_extra_debug_sigprint(); Mat& t_m = const_cast< Mat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword ii=0; ii < t_n_elem; ++ii) { t_m.at( ii + t_row_offset, ii + t_col_offset) /= val; } } //! set a diagonal of our matrix using data from a foreign object template template inline void diagview::operator= (const Base& o) { arma_extra_debug_sigprint(); diagview& d = *this; Mat& d_m = const_cast< Mat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d.n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "diagview: given object has incompatible size" ); const bool is_alias = P.is_alias(d_m); arma_extra_debug_warn(is_alias, "aliasing detected"); if( (is_Mat::stored_type>::value == true) || (Proxy::prefer_at_accessor == true) || (is_alias == true) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_mem[ii]; const eT tmp_j = x_mem[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) = tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) = tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) = x_mem[ii]; } } else { typename Proxy::ea_type Pea = P.get_ea(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = Pea[ii]; const eT tmp_j = Pea[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) = tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) = tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) = Pea[ii]; } } } template template inline void diagview::operator+=(const Base& o) { arma_extra_debug_sigprint(); diagview& d = *this; Mat& d_m = const_cast< Mat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d.n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "diagview: given object has incompatible size" ); const bool is_alias = P.is_alias(d_m); arma_extra_debug_warn(is_alias, "aliasing detected"); if( (is_Mat::stored_type>::value == true) || (Proxy::prefer_at_accessor == true) || (is_alias == true) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_mem[ii]; const eT tmp_j = x_mem[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) += tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) += tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) += x_mem[ii]; } } else { typename Proxy::ea_type Pea = P.get_ea(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = Pea[ii]; const eT tmp_j = Pea[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) += tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) += tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) += Pea[ii]; } } } template template inline void diagview::operator-=(const Base& o) { arma_extra_debug_sigprint(); diagview& d = *this; Mat& d_m = const_cast< Mat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d.n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "diagview: given object has incompatible size" ); const bool is_alias = P.is_alias(d_m); arma_extra_debug_warn(is_alias, "aliasing detected"); if( (is_Mat::stored_type>::value == true) || (Proxy::prefer_at_accessor == true) || (is_alias == true) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_mem[ii]; const eT tmp_j = x_mem[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) -= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) -= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) -= x_mem[ii]; } } else { typename Proxy::ea_type Pea = P.get_ea(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = Pea[ii]; const eT tmp_j = Pea[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) -= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) -= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) -= Pea[ii]; } } } template template inline void diagview::operator%=(const Base& o) { arma_extra_debug_sigprint(); diagview& d = *this; Mat& d_m = const_cast< Mat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d.n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "diagview: given object has incompatible size" ); const bool is_alias = P.is_alias(d_m); arma_extra_debug_warn(is_alias, "aliasing detected"); if( (is_Mat::stored_type>::value == true) || (Proxy::prefer_at_accessor == true) || (is_alias == true) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_mem[ii]; const eT tmp_j = x_mem[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) *= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) *= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) *= x_mem[ii]; } } else { typename Proxy::ea_type Pea = P.get_ea(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = Pea[ii]; const eT tmp_j = Pea[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) *= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) *= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) *= Pea[ii]; } } } template template inline void diagview::operator/=(const Base& o) { arma_extra_debug_sigprint(); diagview& d = *this; Mat& d_m = const_cast< Mat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d.n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "diagview: given object has incompatible size" ); const bool is_alias = P.is_alias(d_m); arma_extra_debug_warn(is_alias, "aliasing detected"); if( (is_Mat::stored_type>::value == true) || (Proxy::prefer_at_accessor == true) || (is_alias == true) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_mem[ii]; const eT tmp_j = x_mem[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) /= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) /= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) /= x_mem[ii]; } } else { typename Proxy::ea_type Pea = P.get_ea(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = Pea[ii]; const eT tmp_j = Pea[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) /= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) /= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) /= Pea[ii]; } } } //! extract a diagonal and store it as a column vector template inline void diagview::extract(Mat& out, const diagview& in) { arma_extra_debug_sigprint(); // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const Mat& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] = tmp_i; out_mem[j] = tmp_j; } if(i < in_n_elem) { out_mem[i] = in_m.at( i + in_row_offset, i + in_col_offset ); } } //! X += Y.diag() template inline void diagview::plus_inplace(Mat& out, const diagview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "addition"); const Mat& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] += tmp_i; out_mem[j] += tmp_j; } if(i < in_n_elem) { out_mem[i] += in_m.at( i + in_row_offset, i + in_col_offset ); } } //! X -= Y.diag() template inline void diagview::minus_inplace(Mat& out, const diagview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "subtraction"); const Mat& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] -= tmp_i; out_mem[j] -= tmp_j; } if(i < in_n_elem) { out_mem[i] -= in_m.at( i + in_row_offset, i + in_col_offset ); } } //! X %= Y.diag() template inline void diagview::schur_inplace(Mat& out, const diagview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "element-wise multiplication"); const Mat& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] *= tmp_i; out_mem[j] *= tmp_j; } if(i < in_n_elem) { out_mem[i] *= in_m.at( i + in_row_offset, i + in_col_offset ); } } //! X /= Y.diag() template inline void diagview::div_inplace(Mat& out, const diagview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "element-wise division"); const Mat& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] /= tmp_i; out_mem[j] /= tmp_j; } if(i < in_n_elem) { out_mem[i] /= in_m.at( i + in_row_offset, i + in_col_offset ); } } template arma_inline eT diagview::at_alt(const uword ii) const { return m.at(ii+row_offset, ii+col_offset); } template arma_inline eT& diagview::operator[](const uword ii) { return (const_cast< Mat& >(m)).at(ii+row_offset, ii+col_offset); } template arma_inline eT diagview::operator[](const uword ii) const { return m.at(ii+row_offset, ii+col_offset); } template arma_inline eT& diagview::at(const uword ii) { return (const_cast< Mat& >(m)).at(ii+row_offset, ii+col_offset); } template arma_inline eT diagview::at(const uword ii) const { return m.at(ii+row_offset, ii+col_offset); } template arma_inline eT& diagview::operator()(const uword ii) { arma_debug_check( (ii >= n_elem), "diagview::operator(): out of bounds" ); return (const_cast< Mat& >(m)).at(ii+row_offset, ii+col_offset); } template arma_inline eT diagview::operator()(const uword ii) const { arma_debug_check( (ii >= n_elem), "diagview::operator(): out of bounds" ); return m.at(ii+row_offset, ii+col_offset); } template arma_inline eT& diagview::at(const uword row, const uword) { return (const_cast< Mat& >(m)).at(row+row_offset, row+col_offset); } template arma_inline eT diagview::at(const uword row, const uword) const { return m.at(row+row_offset, row+col_offset); } template arma_inline eT& diagview::operator()(const uword row, const uword col) { arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator(): out of bounds" ); return (const_cast< Mat& >(m)).at(row+row_offset, row+col_offset); } template arma_inline eT diagview::operator()(const uword row, const uword col) const { arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator(): out of bounds" ); return m.at(row+row_offset, row+col_offset); } template arma_inline const Op,op_htrans> diagview::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> diagview::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> diagview::st() const { return Op,op_strans>(*this); } template inline void diagview::fill(const eT val) { arma_extra_debug_sigprint(); Mat& x = const_cast< Mat& >(m); const uword local_n_elem = n_elem; for(uword ii=0; ii < local_n_elem; ++ii) { x.at(ii+row_offset, ii+col_offset) = val; } } template inline void diagview::zeros() { arma_extra_debug_sigprint(); (*this).fill(eT(0)); } template inline void diagview::ones() { arma_extra_debug_sigprint(); (*this).fill(eT(1)); } template inline void diagview::randu() { arma_extra_debug_sigprint(); Mat& x = const_cast< Mat& >(m); const uword local_n_elem = n_elem; for(uword ii=0; ii < local_n_elem; ++ii) { x.at(ii+row_offset, ii+col_offset) = eT(arma_rng::randu()); } } template inline void diagview::randn() { arma_extra_debug_sigprint(); Mat& x = const_cast< Mat& >(m); const uword local_n_elem = n_elem; for(uword ii=0; ii < local_n_elem; ++ii) { x.at(ii+row_offset, ii+col_offset) = eT(arma_rng::randn()); } } //! @} RcppArmadillo/inst/include/armadillo_bits/op_prod_meat.hpp0000644000176000001440000000754012200631217023601 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_prod //! @{ //! \brief //! Immediate product of elements of a matrix along a specified dimension (either rows or columns). //! The result is stored in a dense matrix that has either one column or one row. //! See the prod() function for more details. template inline void op_prod::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "prod(): incorrect usage. dim must be 0 or 1"); const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) // traverse across rows (i.e. find the product in each column) { out.set_size(1, X_n_cols); eT* out_mem = out.memptr(); for(uword col=0; col inline eT op_prod::prod(const subview& X) { arma_extra_debug_sigprint(); eT val = eT(1); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(X_n_rows == 1) { const Mat& A = X.m; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_col_p1 = start_col + X_n_cols; uword i,j; for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2) { val *= A.at(start_row, i); val *= A.at(start_row, j); } if(i < end_col_p1) { val *= A.at(start_row, i); } } else { for(uword col=0; col < X_n_cols; ++col) { val *= arrayops::product( X.colptr(col), X_n_rows ); } } return val; } template inline typename T1::elem_type op_prod::prod(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); eT val = eT(1); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; const ea_type A = P.get_ea(); const uword n_elem = P.get_n_elem(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { val *= A[i]; val *= A[j]; } if(i < n_elem) { val *= A[i]; } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { val *= P.at(0,i); val *= P.at(0,j); } if(i < n_cols) { val *= P.at(0,i); } } else { for(uword col=0; col < n_cols; ++col) { uword i,j; for(i=0, j=1; j < n_rows; i+=2, j+=2) { val *= P.at(i,col); val *= P.at(j,col); } if(i < n_rows) { val *= P.at(i,col); } } } } return val; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_flip_bones.hpp0000644000176000001440000000121012200631217023733 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_flip //! @{ class op_flipud { public: template inline static void apply(Mat& out, const Op& in); }; class op_fliplr { public: template inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_strans.hpp0000644000176000001440000000340612200375542023131 0ustar ripleyusers// Copyright (C) 2011-2012 Conrad Sanderson // Copyright (C) 2011-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_strans //! @{ template arma_inline const Op strans ( const T1& X, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename arma_cx_only::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X); } // NOTE: for non-complex objects, deliberately returning op_htrans instead of op_strans, // NOTE: due to currently more optimisations available when using op_htrans, especially by glue_times template arma_inline const Op strans ( const T1& X, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename arma_not_cx::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X); } //! two consecutive transpose operations cancel each other template arma_inline const T1& strans(const Op& X) { arma_extra_debug_sigprint(); arma_extra_debug_print("strans(): removing op_strans"); return X.m; } // // handling of sparse matrices template inline typename enable_if2 < is_arma_sparse_type::value, const SpOp >::result strans(const T1& x) { arma_extra_debug_sigprint(); return SpOp(x); } //! @} RcppArmadillo/inst/include/armadillo_bits/unwrap_cube.hpp0000644000176000001440000000312412256511734023451 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup unwrap_cube //! @{ template class unwrap_cube { public: typedef typename T1::elem_type eT; inline unwrap_cube(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const Cube M; }; template class unwrap_cube< Cube > { public: inline unwrap_cube(const Cube& A) : M(A) { arma_extra_debug_sigprint(); } const Cube& M; }; // // // template class unwrap_cube_check { public: typedef typename T1::elem_type eT; inline unwrap_cube_check(const T1& A, const Cube&) : M(A) { arma_extra_debug_sigprint(); arma_type_check(( is_arma_cube_type::value == false )); } const Cube M; }; template class unwrap_cube_check< Cube > { public: inline unwrap_cube_check(const Cube& A, const Cube& B) : M_local( (&A == &B) ? new Cube(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_cube_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Cube* M_local; const Cube& M; }; //! @} RcppArmadillo/inst/include/armadillo_bits/glue_cov_bones.hpp0000644000176000001440000000161312200375542024123 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_cov //! @{ class glue_cov { public: template inline static void direct_cov(Mat& out, const Mat& A, const Mat& B, const uword norm_type); template inline static void direct_cov(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat< std::complex >& B, const uword norm_type); template inline static void apply(Mat& out, const Glue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_eigs_gen.hpp0000644000176000001440000000476712260426622023414 0ustar ripleyusers// Copyright (C) 2013 Ryan Curtin // Copyright (C) 2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_eigs_gen //! @{ //! eigenvalues of general sparse matrix X template inline Col< std::complex > eigs_gen ( const SpBase& X, const uword n_eigvals, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; Mat< std::complex > eigvec; Col< std::complex > eigval; const bool status = sp_auxlib::eigs_gen(eigval, eigvec, X, n_eigvals); if(status == false) { eigval.reset(); arma_bad("eigs_gen(): failed to converge"); } return eigval; } //! eigenvalues of general sparse matrix X template inline bool eigs_gen ( Col< std::complex >& eigval, const SpBase& X, const uword n_eigvals, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; Mat< std::complex > eigvec; const bool status = sp_auxlib::eigs_gen(eigval, eigvec, X, n_eigvals); if(status == false) { eigval.reset(); arma_bad("eigs_gen(): failed to converge", false); } return status; } //! eigenvalues and eigenvectors of general real sparse matrix X template inline bool eigs_gen ( Col< std::complex >& eigval, Mat< std::complex >& eigvec, const SpBase& X, const uword n_eigvals, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( void_ptr(&eigval) == void_ptr(&eigvec), "eigs_gen(): eigval is an alias of eigvec" ); const bool status = sp_auxlib::eigs_gen(eigval, eigvec, X, n_eigvals); if(status == false) { eigval.reset(); eigvec.reset(); arma_bad("eigs_gen(): failed to converge", false); } return status; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_reshape_bones.hpp0000644000176000001440000000116312200631217024437 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_reshape //! @{ class op_reshape { public: template inline static void apply( Mat& out, const Op& in); template inline static void apply(Cube& out, const OpCube& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/ProxyCube.hpp0000644000176000001440000004101712176655102023061 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup ProxyCube //! @{ template class ProxyCube { public: inline ProxyCube(const T1&) { arma_type_check(( is_arma_cube_type::value == false )); } }; // ea_type is the "element accessor" type, // which can provide access to elements via operator[] template class ProxyCube< Cube > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Cube stored_type; typedef const eT* ea_type; typedef const Cube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const Cube& Q; inline explicit ProxyCube(const Cube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube& X) const { return (void_ptr(&Q) == void_ptr(&X)); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class ProxyCube< GenCube > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef GenCube stored_type; typedef const GenCube& ea_type; typedef const GenCube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const GenCube& Q; inline explicit ProxyCube(const GenCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_rows*Q.n_cols; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_rows*Q.n_cols*Q.n_slices; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube&) const { return false; } arma_inline bool is_aligned() const { return GenCube::is_simple; } }; template class ProxyCube< OpCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Cube stored_type; typedef const elem_type* ea_type; typedef const Cube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const Cube Q; inline explicit ProxyCube(const OpCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class ProxyCube< GlueCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Cube stored_type; typedef const elem_type* ea_type; typedef const Cube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const Cube Q; inline explicit ProxyCube(const GlueCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class ProxyCube< subview_cube > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_cube stored_type; typedef const subview_cube& ea_type; typedef const subview_cube& aligned_ea_type; static const bool prefer_at_accessor = true; static const bool has_subview = true; arma_aligned const subview_cube& Q; inline explicit ProxyCube(const subview_cube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class ProxyCube< eOpCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef eOpCube stored_type; typedef const eOpCube& ea_type; typedef const eOpCube& aligned_ea_type; static const bool prefer_at_accessor = eOpCube::prefer_at_accessor; static const bool has_subview = eOpCube::has_subview; arma_aligned const eOpCube& Q; inline explicit ProxyCube(const eOpCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.get_n_rows(); } arma_inline uword get_n_cols() const { return Q.get_n_cols(); } arma_inline uword get_n_elem_slice() const { return Q.get_n_elem_slice(); } arma_inline uword get_n_slices() const { return Q.get_n_slices(); } arma_inline uword get_n_elem() const { return Q.get_n_elem(); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube& X) const { return Q.P.is_alias(X); } arma_inline bool is_aligned() const { return Q.P.is_aligned(); } }; template class ProxyCube< eGlueCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef eGlueCube stored_type; typedef const eGlueCube& ea_type; typedef const eGlueCube& aligned_ea_type; static const bool prefer_at_accessor = eGlueCube::prefer_at_accessor; static const bool has_subview = eGlueCube::has_subview; arma_aligned const eGlueCube& Q; inline explicit ProxyCube(const eGlueCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.get_n_rows(); } arma_inline uword get_n_cols() const { return Q.get_n_cols(); } arma_inline uword get_n_elem_slice() const { return Q.get_n_elem_slice(); } arma_inline uword get_n_slices() const { return Q.get_n_slices(); } arma_inline uword get_n_elem() const { return Q.get_n_elem(); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube& X) const { return (Q.P1.is_alias(X) || Q.P2.is_alias(X)); } arma_inline bool is_aligned() const { return Q.P1.is_aligned() && Q.P2.is_aligned(); } }; template class ProxyCube< mtOpCube > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef Cube stored_type; typedef const elem_type* ea_type; typedef const Cube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const Cube Q; inline explicit ProxyCube(const mtOpCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class ProxyCube< mtGlueCube > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef Cube stored_type; typedef const elem_type* ea_type; typedef const Cube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const Cube Q; inline explicit ProxyCube(const mtGlueCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_misc.hpp0000644000176000001440000000726412256741300022560 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_misc //! @{ //! \brief //! Generate a vector with 'num' elements. //! The values of the elements linearly increase from 'start' upto (and including) 'end'. template inline typename enable_if2 < is_Mat::value, vec_type >::result linspace ( const typename vec_type::pod_type start, const typename vec_type::pod_type end, const uword num = 100u ) { arma_extra_debug_sigprint(); typedef typename vec_type::elem_type eT; typedef typename vec_type::pod_type T; vec_type x; if(num >= 2) { x.set_size(num); eT* x_mem = x.memptr(); const uword num_m1 = num - 1; if(is_non_integral::value == true) { const T delta = (end-start)/T(num_m1); for(uword i=0; i= start) ? double(end-start)/double(num_m1) : -double(start-end)/double(num_m1); for(uword i=0; i(start, end, num); } // // log_exp_add template inline typename arma_real_only::result log_add_exp(eT log_a, eT log_b) { if(log_a < log_b) { std::swap(log_a, log_b); } const eT negdelta = log_b - log_a; if( (negdelta < Datum::log_min) || (arma_isfinite(negdelta) == false) ) { return log_a; } else { #if defined(ARMA_HAVE_LOG1P) return (log_a + log1p(std::exp(negdelta))); #else return (log_a + std::log(1.0 + std::exp(negdelta))); #endif } } // for compatibility with earlier versions template inline typename arma_real_only::result log_add(eT log_a, eT log_b) { return log_add_exp(log_a, log_b); } template arma_inline arma_warn_unused bool is_finite(const eT x, const typename arma_scalar_only::result* junk = 0) { arma_ignore(junk); return arma_isfinite(x); } template inline arma_warn_unused bool is_finite(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; return A.is_finite(); } template inline arma_warn_unused bool is_finite(const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube tmp(X.get_ref()); const Cube& A = tmp.M; return A.is_finite(); } //! DO NOT USE IN NEW CODE; change instances of inv(sympd(X)) to inv_sympd(X) template arma_deprecated inline const T1& sympd(const Base& X) { arma_extra_debug_sigprint(); return X.get_ref(); } template inline void swap(Mat& A, Mat& B) { arma_extra_debug_sigprint(); A.swap(B); } template inline void swap(Cube& A, Cube& B) { arma_extra_debug_sigprint(); A.swap(B); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_min_bones.hpp0000644000176000001440000000335112200631217023574 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_min //! @{ //! Class for finding minimum values in a matrix class op_min { public: template inline static void apply(Mat& out, const Op& in); // // for non-complex numbers template inline static eT direct_min(const eT* const X, const uword N); template inline static eT direct_min(const eT* const X, const uword N, uword& index_of_min_val); template inline static eT direct_min(const Mat& X, const uword row); template inline static eT min(const subview& X); template inline static typename arma_not_cx::result min(const Base& X); // // for complex numbers template inline static std::complex direct_min(const std::complex* const X, const uword n_elem); template inline static std::complex direct_min(const std::complex* const X, const uword n_elem, uword& index_of_min_val); template inline static std::complex direct_min(const Mat< std::complex >& X, const uword row); template inline static std::complex min(const subview< std::complex >&X); template inline static typename arma_cx_only::result min(const Base& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_zeros.hpp0000644000176000001440000000560212256055347022772 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_zeros //! @{ //! Generate a vector with all elements set to zero arma_inline const Gen zeros(const uword n_elem) { arma_extra_debug_sigprint(); return Gen(n_elem, 1); } template arma_inline const Gen zeros(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only::result* junk2 = 0) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_Row::value == true) { return Gen(1, n_elem); } else { return Gen(n_elem, 1); } } //! Generate a dense matrix with all elements set to zero arma_inline const Gen zeros(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return Gen(n_rows, n_cols); } template arma_inline const Gen zeros(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_Col::value == true) { arma_debug_check( (n_cols != 1), "zeros(): incompatible size" ); } else if(is_Row::value == true) { arma_debug_check( (n_rows != 1), "zeros(): incompatible size" ); } return Gen(n_rows, n_cols); } arma_inline const GenCube zeros(const uword n_rows, const uword n_cols, const uword n_slices) { arma_extra_debug_sigprint(); return GenCube(n_rows, n_cols, n_slices); } template arma_inline const GenCube zeros(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(n_rows, n_cols, n_slices); } template inline sp_obj_type zeros(const uword n_rows, const uword n_cols, const typename arma_SpMat_SpCol_SpRow_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_SpCol::value == true) { arma_debug_check( (n_cols != 1), "zeros(): incompatible size" ); } else if(is_SpRow::value == true) { arma_debug_check( (n_rows != 1), "zeros(): incompatible size" ); } return sp_obj_type(n_rows, n_cols); } //! @} RcppArmadillo/inst/include/armadillo_bits/arma_ostream_meat.hpp0000644000176000001440000003520312176655102024621 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup arma_ostream //! @{ inline arma_ostream_state::arma_ostream_state(const std::ostream& o) : orig_flags (o.flags()) , orig_precision(o.precision()) , orig_width (o.width()) , orig_fill (o.fill()) { } inline void arma_ostream_state::restore(std::ostream& o) const { o.flags (orig_flags); o.precision(orig_precision); o.width (orig_width); o.fill (orig_fill); } // // template inline std::streamsize arma_ostream::modify_stream(std::ostream& o, const eT* data, const uword n_elem) { o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.unsetf(ios::showpos); o.fill(' '); std::streamsize cell_width; bool use_layout_B = false; bool use_layout_C = false; for(uword i=0; i= eT(+100) ) || //( (is_signed::value == true) && (val <= eT(-100)) ) || //( (is_non_integral::value == true) && (val > eT(0)) && (val <= eT(+1e-4)) ) || //( (is_non_integral::value == true) && (is_signed::value == true) && (val < eT(0)) && (val >= eT(-1e-4)) ) ( cond_rel< is_signed::value >::leq(val, eT(-100)) ) || ( cond_rel< is_non_integral::value >::gt(val, eT(0)) && cond_rel< is_non_integral::value >::leq(val, eT(+1e-4)) ) || ( cond_rel< is_non_integral::value && is_signed::value >::lt(val, eT(0)) && cond_rel< is_non_integral::value && is_signed::value >::geq(val, eT(-1e-4)) ) ) { use_layout_C = true; break; } if( // (val >= eT(+10)) || ( (is_signed::value == true) && (val <= eT(-10)) ) (val >= eT(+10)) || ( cond_rel< is_signed::value >::leq(val, eT(-10)) ) ) { use_layout_B = true; } } if(use_layout_C == true) { o.setf(ios::scientific); o.setf(ios::right); o.unsetf(ios::fixed); o.precision(4); cell_width = 13; } else if(use_layout_B == true) { o.unsetf(ios::scientific); o.setf(ios::right); o.setf(ios::fixed); o.precision(4); cell_width = 10; } else { o.unsetf(ios::scientific); o.setf(ios::right); o.setf(ios::fixed); o.precision(4); cell_width = 9; } return cell_width; } //! "better than nothing" settings for complex numbers template inline std::streamsize arma_ostream::modify_stream(std::ostream& o, const std::complex* data, const uword n_elem) { arma_ignore(data); arma_ignore(n_elem); o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.fill(' '); o.setf(ios::scientific); o.setf(ios::showpos); o.setf(ios::right); o.unsetf(ios::fixed); std::streamsize cell_width; o.precision(3); cell_width = 2 + 2*(1 + 3 + o.precision() + 5) + 1; return cell_width; } template inline std::streamsize arma_ostream::modify_stream(std::ostream& o, typename SpMat::const_iterator begin, const uword n_elem, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.unsetf(ios::showpos); o.fill(' '); std::streamsize cell_width; bool use_layout_B = false; bool use_layout_C = false; for(typename SpMat::const_iterator it = begin; it.pos() < n_elem; ++it) { const eT val = *it; if( val >= eT(+100) || ( (is_signed::value == true) && (val <= eT(-100)) ) || ( (is_non_integral::value == true) && (val > eT(0)) && (val <= eT(+1e-4)) ) || ( (is_non_integral::value == true) && (is_signed::value == true) && (val < eT(0)) && (val >= eT(-1e-4)) ) ) { use_layout_C = true; break; } if( (val >= eT(+10)) || ( (is_signed::value == true) && (val <= eT(-10)) ) ) { use_layout_B = true; } } if(use_layout_C == true) { o.setf(ios::scientific); o.setf(ios::right); o.unsetf(ios::fixed); o.precision(4); cell_width = 13; } else if(use_layout_B == true) { o.unsetf(ios::scientific); o.setf(ios::right); o.setf(ios::fixed); o.precision(4); cell_width = 10; } else { o.unsetf(ios::scientific); o.setf(ios::right); o.setf(ios::fixed); o.precision(4); cell_width = 9; } return cell_width; } //! "better than nothing" settings for complex numbers template inline std::streamsize arma_ostream::modify_stream(std::ostream& o, typename SpMat::const_iterator begin, const uword n_elem, const typename arma_cx_only::result* junk) { arma_ignore(begin); arma_ignore(n_elem); arma_ignore(junk); o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.fill(' '); o.setf(ios::scientific); o.setf(ios::showpos); o.setf(ios::right); o.unsetf(ios::fixed); std::streamsize cell_width; o.precision(3); cell_width = 2 + 2*(1 + 3 + o.precision() + 5) + 1; return cell_width; } template inline void arma_ostream::print_elem_zero(std::ostream& o, const bool modify) { if(modify == true) { const std::streamsize orig_precision = o.precision(); o.precision(0); o << eT(0); o.precision(orig_precision); } else { o << eT(0); } } //! Print an element to the specified stream template arma_inline void arma_ostream::print_elem(std::ostream& o, const eT& x, const bool modify) { if(x != eT(0)) { o << x; } else { arma_ostream::print_elem_zero(o, modify); } } //! Print a complex element to the specified stream template inline void arma_ostream::print_elem(std::ostream& o, const std::complex& x, const bool modify) { if( (x.real() != T(0)) || (x.imag() != T(0)) || (modify == false) ) { std::ostringstream ss; ss.flags(o.flags()); //ss.imbue(o.getloc()); ss.precision(o.precision()); ss << '(' << x.real() << ',' << x.imag() << ')'; o << ss.str(); } else { o << "(0,0)"; } } //! Print a matrix to the specified stream template inline void arma_ostream::print(std::ostream& o, const Mat& m, const bool modify) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); const std::streamsize cell_width = modify ? arma_ostream::modify_stream(o, m.memptr(), m.n_elem) : o.width(); const uword m_n_rows = m.n_rows; const uword m_n_cols = m.n_cols; if(m.is_empty() == false) { if(m_n_cols > 0) { if(cell_width > 0) { for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols; ++col) { // the cell width appears to be reset after each element is printed, // hence we need to restore it o.width(cell_width); arma_ostream::print_elem(o, m.at(row,col), modify); } o << '\n'; } } else { for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols-1; ++col) { arma_ostream::print_elem(o, m.at(row,col), modify); o << ' '; } arma_ostream::print_elem(o, m.at(row, m_n_cols-1), modify); o << '\n'; } } } } else { o << "[matrix size: " << m_n_rows << 'x' << m_n_cols << "]\n"; } o.flush(); stream_state.restore(o); } //! Print a cube to the specified stream template inline void arma_ostream::print(std::ostream& o, const Cube& x, const bool modify) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); const std::streamsize cell_width = modify ? arma_ostream::modify_stream(o, x.memptr(), x.n_elem) : o.width(); if(x.is_empty() == false) { for(uword slice=0; slice < x.n_slices; ++slice) { o << "[cube slice " << slice << ']' << '\n'; o.width(cell_width); arma_ostream::print(o, x.slice(slice), false); o << '\n'; } } else { o << "[cube size: " << x.n_rows << 'x' << x.n_cols << 'x' << x.n_slices << "]\n"; } stream_state.restore(o); } //! Print a field to the specified stream //! Assumes type oT can be printed, i.e. oT has std::ostream& operator<< (std::ostream&, const oT&) template inline void arma_ostream::print(std::ostream& o, const field& x) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); const std::streamsize cell_width = o.width(); const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; if(x.is_empty() == false) { for(uword col=0; col inline void arma_ostream::print(std::ostream& o, const subview_field& x) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); const std::streamsize cell_width = o.width(); const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; for(uword col=0; col inline void arma_ostream::print_dense(std::ostream& o, const SpMat& m, const bool modify) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); const uword m_n_rows = m.n_rows; const uword m_n_cols = m.n_cols; if(m.n_nonzero > 0) { const std::streamsize cell_width = modify ? modify_stream(o, m.begin(), m.n_nonzero) : o.width(); typename SpMat::const_iterator begin = m.begin(); if(m_n_cols > 0) { if(cell_width > 0) { // An efficient row_iterator would make this simpler and faster for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols; ++col) { // the cell width appears to be reset after each element is printed, // hence we need to restore it o.width(cell_width); eT val = eT(0); for(typename SpMat::const_iterator it = begin; it.pos() < m.n_nonzero; ++it) { if(it.row() == row && it.col() == col) { val = *it; break; } } arma_ostream::print_elem(o,eT(val), modify); } o << '\n'; } } else { // An efficient row_iterator would make this simpler and faster for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols; ++col) { eT val = eT(0); for(typename SpMat::const_iterator it = begin; it.pos() < m.n_nonzero; ++it) { if(it.row() == row && it.col() == col) { val = *it; break; } } arma_ostream::print_elem(o,eT(val), modify); o << ' '; } o << '\n'; } } } } else { if(m.n_elem == 0) { o << "[matrix size: " << m_n_rows << 'x' << m_n_cols << "]\n"; } else { eT tmp[1]; tmp[0] = eT(0); const std::streamsize cell_width = modify ? arma_ostream::modify_stream(o, &tmp[0], 1) : o.width(); for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols; ++col) { o.width(cell_width); arma_ostream::print_elem_zero(o, modify); o << ' '; } o << '\n'; } } } o.flush(); stream_state.restore(o); } template inline void arma_ostream::print(std::ostream& o, const SpMat& m, const bool modify) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.unsetf(ios::showpos); o.unsetf(ios::scientific); o.setf(ios::right); o.setf(ios::fixed); o.precision(2); const uword m_n_nonzero = m.n_nonzero; o << "[matrix size: " << m.n_rows << 'x' << m.n_cols << "; n_nonzero: " << m_n_nonzero << "; density: " << ((m.n_elem > 0) ? (double(m_n_nonzero) / double(m.n_elem) * double(100)) : double(0)) << "%]\n\n"; if(modify == false) { stream_state.restore(o); } if(m_n_nonzero > 0) { const std::streamsize cell_width = modify ? modify_stream(o, m.begin(), m_n_nonzero) : o.width(); typename SpMat::const_iterator begin = m.begin(); while(begin != m.end()) { const uword row = begin.row(); // TODO: change the maximum number of spaces before and after each location to be dependent on n_rows and n_cols if(row < 10) { o << " "; } else if(row < 100) { o << " "; } else if(row < 1000) { o << " "; } else if(row < 10000) { o << " "; } else if(row < 100000) { o << ' '; } const uword col = begin.col(); o << '(' << row << ", " << col << ") "; if(col < 10) { o << " "; } else if(col < 100) { o << " "; } else if(col < 1000) { o << " "; } else if(col < 10000) { o << " "; } else if(col < 100000) { o << ' '; } if(cell_width > 0) { o.width(cell_width); } arma_ostream::print_elem(o, eT(*begin), modify); o << '\n'; ++begin; } o << '\n'; } o.flush(); stream_state.restore(o); } //! @} RcppArmadillo/inst/include/armadillo_bits/auxlib_meat.hpp0000644000176000001440000027601412262150442023433 0ustar ripleyusers// Copyright (C) 2008-2014 Conrad Sanderson // Copyright (C) 2008-2014 NICTA (www.nicta.com.au) // Copyright (C) 2009 Edmund Highcock // Copyright (C) 2011 James Sanders // Copyright (C) 2011 Stanislav Funiak // Copyright (C) 2012 Eric Jon Sundstrom // Copyright (C) 2012 Michael McNeil Forbes // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup auxlib //! @{ //! immediate matrix inverse template inline bool auxlib::inv(Mat& out, const Base& X, const bool slow) { arma_extra_debug_sigprint(); out = X.get_ref(); arma_debug_check( (out.is_square() == false), "inv(): given matrix is not square" ); bool status = false; const uword N = out.n_rows; if( (N <= 4) && (slow == false) ) { Mat tmp(N,N); status = auxlib::inv_noalias_tinymat(tmp, out, N); if(status == true) { arrayops::copy( out.memptr(), tmp.memptr(), tmp.n_elem ); } } if( (N > 4) || (status == false) ) { status = auxlib::inv_inplace_lapack(out); } return status; } template inline bool auxlib::inv(Mat& out, const Mat& X, const bool slow) { arma_extra_debug_sigprint(); arma_debug_check( (X.is_square() == false), "inv(): given matrix is not square" ); bool status = false; const uword N = X.n_rows; if( (N <= 4) && (slow == false) ) { if(&out != &X) { out.set_size(N,N); status = auxlib::inv_noalias_tinymat(out, X, N); } else { Mat tmp(N,N); status = auxlib::inv_noalias_tinymat(tmp, X, N); if(status == true) { arrayops::copy( out.memptr(), tmp.memptr(), tmp.n_elem ); } } } if( (N > 4) || (status == false) ) { out = X; status = auxlib::inv_inplace_lapack(out); } return status; } template inline bool auxlib::inv_noalias_tinymat(Mat& out, const Mat& X, const uword N) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const T det_min = (is_float::value) ? T(1e-19) : T(1e-154); bool calc_ok = true; const eT* Xm = X.memptr(); eT* outm = out.memptr(); // NOTE: the output matrix is assumed to have the correct size switch(N) { case 1: { outm[0] = eT(1) / Xm[0]; }; break; case 2: { const eT a = Xm[pos<0,0>::n2]; const eT b = Xm[pos<0,1>::n2]; const eT c = Xm[pos<1,0>::n2]; const eT d = Xm[pos<1,1>::n2]; const eT det_val = (a*d - b*c); if(std::abs(det_val) >= det_min) { outm[pos<0,0>::n2] = d / det_val; outm[pos<0,1>::n2] = -b / det_val; outm[pos<1,0>::n2] = -c / det_val; outm[pos<1,1>::n2] = a / det_val; } else { calc_ok = false; } }; break; case 3: { const eT det_val = auxlib::det_tinymat(X,3); if(std::abs(det_val) >= det_min) { outm[pos<0,0>::n3] = (Xm[pos<2,2>::n3]*Xm[pos<1,1>::n3] - Xm[pos<2,1>::n3]*Xm[pos<1,2>::n3]) / det_val; outm[pos<1,0>::n3] = -(Xm[pos<2,2>::n3]*Xm[pos<1,0>::n3] - Xm[pos<2,0>::n3]*Xm[pos<1,2>::n3]) / det_val; outm[pos<2,0>::n3] = (Xm[pos<2,1>::n3]*Xm[pos<1,0>::n3] - Xm[pos<2,0>::n3]*Xm[pos<1,1>::n3]) / det_val; outm[pos<0,1>::n3] = -(Xm[pos<2,2>::n3]*Xm[pos<0,1>::n3] - Xm[pos<2,1>::n3]*Xm[pos<0,2>::n3]) / det_val; outm[pos<1,1>::n3] = (Xm[pos<2,2>::n3]*Xm[pos<0,0>::n3] - Xm[pos<2,0>::n3]*Xm[pos<0,2>::n3]) / det_val; outm[pos<2,1>::n3] = -(Xm[pos<2,1>::n3]*Xm[pos<0,0>::n3] - Xm[pos<2,0>::n3]*Xm[pos<0,1>::n3]) / det_val; outm[pos<0,2>::n3] = (Xm[pos<1,2>::n3]*Xm[pos<0,1>::n3] - Xm[pos<1,1>::n3]*Xm[pos<0,2>::n3]) / det_val; outm[pos<1,2>::n3] = -(Xm[pos<1,2>::n3]*Xm[pos<0,0>::n3] - Xm[pos<1,0>::n3]*Xm[pos<0,2>::n3]) / det_val; outm[pos<2,2>::n3] = (Xm[pos<1,1>::n3]*Xm[pos<0,0>::n3] - Xm[pos<1,0>::n3]*Xm[pos<0,1>::n3]) / det_val; const eT check_val = Xm[pos<0,0>::n3]*outm[pos<0,0>::n3] + Xm[pos<0,1>::n3]*outm[pos<1,0>::n3] + Xm[pos<0,2>::n3]*outm[pos<2,0>::n3]; const T max_diff = (is_float::value) ? T(1e-4) : T(1e-10); if(std::abs(T(1) - check_val) > max_diff) { calc_ok = false; } } else { calc_ok = false; } }; break; case 4: { const eT det_val = auxlib::det_tinymat(X,4); if(std::abs(det_val) >= det_min) { outm[pos<0,0>::n4] = ( Xm[pos<1,2>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,1>::n4] - Xm[pos<1,3>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,1>::n4] + Xm[pos<1,3>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,2>::n4] - Xm[pos<1,1>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,2>::n4] - Xm[pos<1,2>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,3>::n4] + Xm[pos<1,1>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<1,0>::n4] = ( Xm[pos<1,3>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,0>::n4] - Xm[pos<1,2>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<1,3>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,2>::n4] + Xm[pos<1,0>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,2>::n4] + Xm[pos<1,2>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,3>::n4] - Xm[pos<1,0>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<2,0>::n4] = ( Xm[pos<1,1>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<1,3>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,0>::n4] + Xm[pos<1,3>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,1>::n4] - Xm[pos<1,0>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,1>::n4] - Xm[pos<1,1>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,3>::n4] + Xm[pos<1,0>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<3,0>::n4] = ( Xm[pos<1,2>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,0>::n4] - Xm[pos<1,1>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,0>::n4] - Xm[pos<1,2>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,1>::n4] + Xm[pos<1,0>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,1>::n4] + Xm[pos<1,1>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,2>::n4] - Xm[pos<1,0>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,2>::n4] ) / det_val; outm[pos<0,1>::n4] = ( Xm[pos<0,3>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,2>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,3>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,2>::n4] + Xm[pos<0,1>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,2>::n4] + Xm[pos<0,2>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,3>::n4] - Xm[pos<0,1>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<1,1>::n4] = ( Xm[pos<0,2>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,0>::n4] + Xm[pos<0,3>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,2>::n4] - Xm[pos<0,0>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,2>::n4] - Xm[pos<0,2>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,3>::n4] + Xm[pos<0,0>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<2,1>::n4] = ( Xm[pos<0,3>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,1>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,1>::n4] + Xm[pos<0,0>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,1>::n4] + Xm[pos<0,1>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,3>::n4] - Xm[pos<0,0>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<3,1>::n4] = ( Xm[pos<0,1>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,2>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,0>::n4] + Xm[pos<0,2>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,0>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,1>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,2>::n4] + Xm[pos<0,0>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,2>::n4] ) / det_val; outm[pos<0,2>::n4] = ( Xm[pos<0,2>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,1>::n4] + Xm[pos<0,3>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,2>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,2>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,3>::n4] + Xm[pos<0,1>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<1,2>::n4] = ( Xm[pos<0,3>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,2>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,2>::n4] + Xm[pos<0,2>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,3>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<2,2>::n4] = ( Xm[pos<0,1>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,0>::n4] + Xm[pos<0,3>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,3>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<3,2>::n4] = ( Xm[pos<0,2>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,1>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,1>::n4] + Xm[pos<0,1>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,2>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,2>::n4] ) / det_val; outm[pos<0,3>::n4] = ( Xm[pos<0,3>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,1>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,1>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,2>::n4] + Xm[pos<0,1>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,2>::n4] + Xm[pos<0,2>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,3>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,3>::n4] ) / det_val; outm[pos<1,3>::n4] = ( Xm[pos<0,2>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,0>::n4] + Xm[pos<0,3>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,2>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,2>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,3>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,3>::n4] ) / det_val; outm[pos<2,3>::n4] = ( Xm[pos<0,3>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,0>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,1>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,1>::n4] + Xm[pos<0,1>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,3>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,3>::n4] ) / det_val; outm[pos<3,3>::n4] = ( Xm[pos<0,1>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,0>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,0>::n4] + Xm[pos<0,2>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,1>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,1>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,2>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,2>::n4] ) / det_val; const eT check_val = Xm[pos<0,0>::n4]*outm[pos<0,0>::n4] + Xm[pos<0,1>::n4]*outm[pos<1,0>::n4] + Xm[pos<0,2>::n4]*outm[pos<2,0>::n4] + Xm[pos<0,3>::n4]*outm[pos<3,0>::n4]; const T max_diff = (is_float::value) ? T(1e-4) : T(1e-10); if(std::abs(T(1) - check_val) > max_diff) { calc_ok = false; } } else { calc_ok = false; } }; break; default: ; } return calc_ok; } template inline bool auxlib::inv_inplace_lapack(Mat& out) { arma_extra_debug_sigprint(); if(out.is_empty()) { return true; } #if defined(ARMA_USE_ATLAS) { podarray ipiv(out.n_rows); int info = atlas::clapack_getrf(atlas::CblasColMajor, out.n_rows, out.n_cols, out.memptr(), out.n_rows, ipiv.memptr()); if(info == 0) { info = atlas::clapack_getri(atlas::CblasColMajor, out.n_rows, out.memptr(), out.n_rows, ipiv.memptr()); } return (info == 0); } #elif defined(ARMA_USE_LAPACK) { blas_int n_rows = out.n_rows; blas_int lwork = (std::max)(blas_int(podarray_prealloc_n_elem::val), n_rows); blas_int info = 0; podarray ipiv(out.n_rows); if(n_rows > 16) { eT work_query[2]; blas_int lwork_query = -1; lapack::getri(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), &work_query[0], &lwork_query, &info); if(info == 0) { const blas_int lwork_proposed = static_cast( access::tmp_real(work_query[0]) ); if(lwork_proposed > lwork) { lwork = lwork_proposed; } } else { return false; } } podarray work( static_cast(lwork) ); lapack::getrf(&n_rows, &n_rows, out.memptr(), &n_rows, ipiv.memptr(), &info); if(info == 0) { lapack::getri(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), work.memptr(), &lwork, &info); } return (info == 0); } #else { arma_stop("inv(): use of ATLAS or LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::inv_tr(Mat& out, const Base& X, const uword layout) { arma_extra_debug_sigprint(); out = X.get_ref(); arma_debug_check( (out.is_square() == false), "inv(): given matrix is not square" ); if(out.is_empty()) { return true; } bool status; #if defined(ARMA_USE_LAPACK) { char uplo = (layout == 0) ? 'U' : 'L'; char diag = 'N'; blas_int n = blas_int(out.n_rows); blas_int info = 0; lapack::trtri(&uplo, &diag, &n, out.memptr(), &n, &info); status = (info == 0); } #else { arma_ignore(layout); arma_stop("inv(): use of LAPACK needs to be enabled"); status = false; } #endif if(status == true) { if(layout == 0) { // upper triangular out = trimatu(out); } else { // lower triangular out = trimatl(out); } } return status; } template inline bool auxlib::inv_sym(Mat& out, const Base& X, const uword layout) { arma_extra_debug_sigprint(); out = X.get_ref(); arma_debug_check( (out.is_square() == false), "inv(): given matrix is not square" ); if(out.is_empty()) { return true; } bool status; #if defined(ARMA_USE_LAPACK) { char uplo = (layout == 0) ? 'U' : 'L'; blas_int n = blas_int(out.n_rows); blas_int lwork = (std::max)(blas_int(podarray_prealloc_n_elem::val), 2*n); blas_int info = 0; podarray ipiv; ipiv.set_size(out.n_rows); podarray work; work.set_size( uword(lwork) ); lapack::sytrf(&uplo, &n, out.memptr(), &n, ipiv.memptr(), work.memptr(), &lwork, &info); status = (info == 0); if(status == true) { lapack::sytri(&uplo, &n, out.memptr(), &n, ipiv.memptr(), work.memptr(), &info); out = (layout == 0) ? symmatu(out) : symmatl(out); status = (info == 0); } } #else { arma_ignore(layout); arma_stop("inv(): use of LAPACK needs to be enabled"); status = false; } #endif return status; } template inline bool auxlib::inv_sympd(Mat& out, const Base& X, const uword layout) { arma_extra_debug_sigprint(); out = X.get_ref(); arma_debug_check( (out.is_square() == false), "inv_sympd(): given matrix is not square" ); if(out.is_empty()) { return true; } bool status; #if defined(ARMA_USE_LAPACK) { char uplo = (layout == 0) ? 'U' : 'L'; blas_int n = blas_int(out.n_rows); blas_int info = 0; lapack::potrf(&uplo, &n, out.memptr(), &n, &info); status = (info == 0); if(status == true) { lapack::potri(&uplo, &n, out.memptr(), &n, &info); out = (layout == 0) ? symmatu(out) : symmatl(out); status = (info == 0); } } #else { arma_ignore(layout); arma_stop("inv_sympd(): use of LAPACK needs to be enabled"); status = false; } #endif return status; } template inline eT auxlib::det(const Base& X, const bool slow) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const bool make_copy = (is_Mat::value == true) ? true : false; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; arma_debug_check( (A.is_square() == false), "det(): matrix is not square" ); const uword N = A.n_rows; if( (N <= 4) && (slow == false) ) { const T det_min = (is_float::value) ? T(1e-19) : T(1e-154); const eT det_val = auxlib::det_tinymat(A, N); return (std::abs(det_val) >= det_min) ? det_val : auxlib::det_lapack(A, make_copy); } else { return auxlib::det_lapack(A, make_copy); } } template inline eT auxlib::det_tinymat(const Mat& X, const uword N) { arma_extra_debug_sigprint(); switch(N) { case 0: return eT(1); break; case 1: return X[0]; break; case 2: { const eT* Xm = X.memptr(); return ( Xm[pos<0,0>::n2]*Xm[pos<1,1>::n2] - Xm[pos<0,1>::n2]*Xm[pos<1,0>::n2] ); } break; case 3: { // const double tmp1 = X.at(0,0) * X.at(1,1) * X.at(2,2); // const double tmp2 = X.at(0,1) * X.at(1,2) * X.at(2,0); // const double tmp3 = X.at(0,2) * X.at(1,0) * X.at(2,1); // const double tmp4 = X.at(2,0) * X.at(1,1) * X.at(0,2); // const double tmp5 = X.at(2,1) * X.at(1,2) * X.at(0,0); // const double tmp6 = X.at(2,2) * X.at(1,0) * X.at(0,1); // return (tmp1+tmp2+tmp3) - (tmp4+tmp5+tmp6); const eT* Xm = X.memptr(); const eT val1 = Xm[pos<0,0>::n3]*(Xm[pos<2,2>::n3]*Xm[pos<1,1>::n3] - Xm[pos<2,1>::n3]*Xm[pos<1,2>::n3]); const eT val2 = Xm[pos<1,0>::n3]*(Xm[pos<2,2>::n3]*Xm[pos<0,1>::n3] - Xm[pos<2,1>::n3]*Xm[pos<0,2>::n3]); const eT val3 = Xm[pos<2,0>::n3]*(Xm[pos<1,2>::n3]*Xm[pos<0,1>::n3] - Xm[pos<1,1>::n3]*Xm[pos<0,2>::n3]); return ( val1 - val2 + val3 ); } break; case 4: { const eT* Xm = X.memptr(); const eT val = \ Xm[pos<0,3>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,0>::n4] \ - Xm[pos<0,2>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,0>::n4] \ - Xm[pos<0,3>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,0>::n4] \ + Xm[pos<0,1>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,0>::n4] \ + Xm[pos<0,2>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,0>::n4] \ - Xm[pos<0,1>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,0>::n4] \ - Xm[pos<0,3>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,1>::n4] \ + Xm[pos<0,2>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,1>::n4] \ + Xm[pos<0,3>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,1>::n4] \ - Xm[pos<0,0>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,1>::n4] \ - Xm[pos<0,2>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,1>::n4] \ + Xm[pos<0,0>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,1>::n4] \ + Xm[pos<0,3>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,2>::n4] \ - Xm[pos<0,1>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,2>::n4] \ - Xm[pos<0,3>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,2>::n4] \ + Xm[pos<0,0>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,2>::n4] \ + Xm[pos<0,1>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,2>::n4] \ - Xm[pos<0,0>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,2>::n4] \ - Xm[pos<0,2>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,3>::n4] \ + Xm[pos<0,1>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,3>::n4] \ + Xm[pos<0,2>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,3>::n4] \ - Xm[pos<0,0>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,3>::n4] \ - Xm[pos<0,1>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,3>::n4] \ + Xm[pos<0,0>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,3>::n4] \ ; return val; } break; default: return eT(0); ; } } //! immediate determinant of a matrix using ATLAS or LAPACK template inline eT auxlib::det_lapack(const Mat& X, const bool make_copy) { arma_extra_debug_sigprint(); Mat X_copy; if(make_copy == true) { X_copy = X; } Mat& tmp = (make_copy == true) ? X_copy : const_cast< Mat& >(X); if(tmp.is_empty()) { return eT(1); } #if defined(ARMA_USE_ATLAS) { podarray ipiv(tmp.n_rows); //const int info = atlas::clapack_getrf(atlas::CblasColMajor, tmp.n_rows, tmp.n_cols, tmp.memptr(), tmp.n_rows, ipiv.memptr()); // on output tmp appears to be L+U_alt, where U_alt is U with the main diagonal set to zero eT val = tmp.at(0,0); for(uword i=1; i < tmp.n_rows; ++i) { val *= tmp.at(i,i); } int sign = +1; for(uword i=0; i < tmp.n_rows; ++i) { if( int(i) != ipiv.mem[i] ) // NOTE: no adjustment required, as the clapack version of getrf() assumes counting from 0 { sign *= -1; } } return ( (sign < 0) ? -val : val ); } #elif defined(ARMA_USE_LAPACK) { podarray ipiv(tmp.n_rows); blas_int info = 0; blas_int n_rows = blas_int(tmp.n_rows); blas_int n_cols = blas_int(tmp.n_cols); lapack::getrf(&n_rows, &n_cols, tmp.memptr(), &n_rows, ipiv.memptr(), &info); // on output tmp appears to be L+U_alt, where U_alt is U with the main diagonal set to zero eT val = tmp.at(0,0); for(uword i=1; i < tmp.n_rows; ++i) { val *= tmp.at(i,i); } blas_int sign = +1; for(uword i=0; i < tmp.n_rows; ++i) { if( blas_int(i) != (ipiv.mem[i] - 1) ) // NOTE: adjustment of -1 is required as Fortran counts from 1 { sign *= -1; } } return ( (sign < 0) ? -val : val ); } #else { arma_ignore(X); arma_ignore(make_copy); arma_ignore(tmp); arma_stop("det(): use of ATLAS or LAPACK needs to be enabled"); return eT(0); } #endif } //! immediate log determinant of a matrix using ATLAS or LAPACK template inline bool auxlib::log_det(eT& out_val, typename get_pod_type::result& out_sign, const Base& X) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; #if defined(ARMA_USE_ATLAS) { Mat tmp(X.get_ref()); arma_debug_check( (tmp.is_square() == false), "log_det(): given matrix is not square" ); if(tmp.is_empty()) { out_val = eT(0); out_sign = T(1); return true; } podarray ipiv(tmp.n_rows); const int info = atlas::clapack_getrf(atlas::CblasColMajor, tmp.n_rows, tmp.n_cols, tmp.memptr(), tmp.n_rows, ipiv.memptr()); // on output tmp appears to be L+U_alt, where U_alt is U with the main diagonal set to zero sword sign = (is_complex::value == false) ? ( (access::tmp_real( tmp.at(0,0) ) < T(0)) ? -1 : +1 ) : +1; eT val = (is_complex::value == false) ? std::log( (access::tmp_real( tmp.at(0,0) ) < T(0)) ? tmp.at(0,0)*T(-1) : tmp.at(0,0) ) : std::log( tmp.at(0,0) ); for(uword i=1; i < tmp.n_rows; ++i) { const eT x = tmp.at(i,i); sign *= (is_complex::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1; val += (is_complex::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x); } for(uword i=0; i < tmp.n_rows; ++i) { if( int(i) != ipiv.mem[i] ) // NOTE: no adjustment required, as the clapack version of getrf() assumes counting from 0 { sign *= -1; } } out_val = val; out_sign = T(sign); return (info == 0); } #elif defined(ARMA_USE_LAPACK) { Mat tmp(X.get_ref()); arma_debug_check( (tmp.is_square() == false), "log_det(): given matrix is not square" ); if(tmp.is_empty()) { out_val = eT(0); out_sign = T(1); return true; } podarray ipiv(tmp.n_rows); blas_int info = 0; blas_int n_rows = blas_int(tmp.n_rows); blas_int n_cols = blas_int(tmp.n_cols); lapack::getrf(&n_rows, &n_cols, tmp.memptr(), &n_rows, ipiv.memptr(), &info); // on output tmp appears to be L+U_alt, where U_alt is U with the main diagonal set to zero sword sign = (is_complex::value == false) ? ( (access::tmp_real( tmp.at(0,0) ) < T(0)) ? -1 : +1 ) : +1; eT val = (is_complex::value == false) ? std::log( (access::tmp_real( tmp.at(0,0) ) < T(0)) ? tmp.at(0,0)*T(-1) : tmp.at(0,0) ) : std::log( tmp.at(0,0) ); for(uword i=1; i < tmp.n_rows; ++i) { const eT x = tmp.at(i,i); sign *= (is_complex::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1; val += (is_complex::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x); } for(uword i=0; i < tmp.n_rows; ++i) { if( blas_int(i) != (ipiv.mem[i] - 1) ) // NOTE: adjustment of -1 is required as Fortran counts from 1 { sign *= -1; } } out_val = val; out_sign = T(sign); return (info == 0); } #else { arma_ignore(X); out_val = eT(0); out_sign = T(0); arma_stop("log_det(): use of ATLAS or LAPACK needs to be enabled"); return false; } #endif } //! immediate LU decomposition of a matrix using ATLAS or LAPACK template inline bool auxlib::lu(Mat& L, Mat& U, podarray& ipiv, const Base& X) { arma_extra_debug_sigprint(); U = X.get_ref(); const uword U_n_rows = U.n_rows; const uword U_n_cols = U.n_cols; if(U.is_empty()) { L.set_size(U_n_rows, 0); U.set_size(0, U_n_cols); ipiv.reset(); return true; } #if defined(ARMA_USE_ATLAS) || defined(ARMA_USE_LAPACK) { bool status; #if defined(ARMA_USE_ATLAS) { ipiv.set_size( (std::min)(U_n_rows, U_n_cols) ); int info = atlas::clapack_getrf(atlas::CblasColMajor, U_n_rows, U_n_cols, U.memptr(), U_n_rows, ipiv.memptr()); status = (info == 0); } #elif defined(ARMA_USE_LAPACK) { ipiv.set_size( (std::min)(U_n_rows, U_n_cols) ); blas_int info = 0; blas_int n_rows = U_n_rows; blas_int n_cols = U_n_cols; lapack::getrf(&n_rows, &n_cols, U.memptr(), &n_rows, ipiv.memptr(), &info); // take into account that Fortran counts from 1 arrayops::inplace_minus(ipiv.memptr(), blas_int(1), ipiv.n_elem); status = (info == 0); } #endif L.copy_size(U); for(uword col=0; col < U_n_cols; ++col) { for(uword row=0; (row < col) && (row < U_n_rows); ++row) { L.at(row,col) = eT(0); } if( L.in_range(col,col) == true ) { L.at(col,col) = eT(1); } for(uword row = (col+1); row < U_n_rows; ++row) { L.at(row,col) = U.at(row,col); U.at(row,col) = eT(0); } } return status; } #else { arma_stop("lu(): use of ATLAS or LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::lu(Mat& L, Mat& U, Mat& P, const Base& X) { arma_extra_debug_sigprint(); podarray ipiv1; const bool status = auxlib::lu(L, U, ipiv1, X); if(status == true) { if(U.is_empty()) { // L and U have been already set to the correct empty matrices P.eye(L.n_rows, L.n_rows); return true; } const uword n = ipiv1.n_elem; const uword P_rows = U.n_rows; podarray ipiv2(P_rows); const blas_int* ipiv1_mem = ipiv1.memptr(); blas_int* ipiv2_mem = ipiv2.memptr(); for(uword i=0; i(ipiv1_mem[i]); if( ipiv2_mem[i] != ipiv2_mem[k] ) { std::swap( ipiv2_mem[i], ipiv2_mem[k] ); } } P.zeros(P_rows, P_rows); for(uword row=0; row(ipiv2_mem[row])) = eT(1); } if(L.n_cols > U.n_rows) { L.shed_cols(U.n_rows, L.n_cols-1); } if(U.n_rows > L.n_cols) { U.shed_rows(L.n_cols, U.n_rows-1); } } return status; } template inline bool auxlib::lu(Mat& L, Mat& U, const Base& X) { arma_extra_debug_sigprint(); podarray ipiv1; const bool status = auxlib::lu(L, U, ipiv1, X); if(status == true) { if(U.is_empty()) { // L and U have been already set to the correct empty matrices return true; } const uword n = ipiv1.n_elem; const uword P_rows = U.n_rows; podarray ipiv2(P_rows); const blas_int* ipiv1_mem = ipiv1.memptr(); blas_int* ipiv2_mem = ipiv2.memptr(); for(uword i=0; i(ipiv1_mem[i]); if( ipiv2_mem[i] != ipiv2_mem[k] ) { std::swap( ipiv2_mem[i], ipiv2_mem[k] ); L.swap_rows( static_cast(ipiv2_mem[i]), static_cast(ipiv2_mem[k]) ); } } if(L.n_cols > U.n_rows) { L.shed_cols(U.n_rows, L.n_cols-1); } if(U.n_rows > L.n_cols) { U.shed_rows(L.n_cols, U.n_rows-1); } } return status; } //! immediate eigenvalues of a symmetric real matrix using LAPACK template inline bool auxlib::eig_sym(Col& eigval, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); arma_debug_check( (A.is_square() == false), "eig_sym(): given matrix is not square"); if(A.is_empty()) { eigval.reset(); return true; } eigval.set_size(A.n_rows); char jobz = 'N'; char uplo = 'U'; blas_int N = blas_int(A.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 3*N-1) ); blas_int info = 0; podarray work( static_cast(lwork) ); lapack::syev(&jobz, &uplo, &N, A.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK needs to be enabled"); return false; } #endif } //! immediate eigenvalues of a hermitian complex matrix using LAPACK template inline bool auxlib::eig_sym(Col& eigval, const Base,T1>& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename std::complex eT; Mat A(X.get_ref()); arma_debug_check( (A.is_square() == false), "eig_sym(): given matrix is not square"); if(A.is_empty()) { eigval.reset(); return true; } eigval.set_size(A.n_rows); char jobz = 'N'; char uplo = 'U'; blas_int N = blas_int(A.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 2*N-1) ); blas_int info = 0; podarray work( static_cast(lwork) ); podarray rwork( static_cast( (std::max)(blas_int(1), 3*N-2) ) ); arma_extra_debug_print("lapack::heev()"); lapack::heev(&jobz, &uplo, &N, A.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, rwork.memptr(), &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK needs to be enabled"); return false; } #endif } //! immediate eigenvalues and eigenvectors of a symmetric real matrix using LAPACK template inline bool auxlib::eig_sym(Col& eigval, Mat& eigvec, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { eigvec = X.get_ref(); arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matrix is not square" ); if(eigvec.is_empty()) { eigval.reset(); eigvec.reset(); return true; } eigval.set_size(eigvec.n_rows); char jobz = 'V'; char uplo = 'U'; blas_int N = blas_int(eigvec.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 3*N-1) ); blas_int info = 0; podarray work( static_cast(lwork) ); lapack::syev(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK needs to be enabled"); return false; } #endif } //! immediate eigenvalues and eigenvectors of a hermitian complex matrix using LAPACK template inline bool auxlib::eig_sym(Col& eigval, Mat< std::complex >& eigvec, const Base,T1>& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename std::complex eT; eigvec = X.get_ref(); arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matrix is not square" ); if(eigvec.is_empty()) { eigval.reset(); eigvec.reset(); return true; } eigval.set_size(eigvec.n_rows); char jobz = 'V'; char uplo = 'U'; blas_int N = blas_int(eigvec.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 2*N-1) ); blas_int info = 0; podarray work( static_cast(lwork) ); podarray rwork( static_cast((std::max)(blas_int(1), 3*N-2)) ); arma_extra_debug_print("lapack::heev()"); lapack::heev(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, rwork.memptr(), &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK needs to be enabled"); return false; } #endif } //! immediate eigenvalues and eigenvectors of a symmetric real matrix using LAPACK (divide and conquer algorithm) template inline bool auxlib::eig_sym_dc(Col& eigval, Mat& eigvec, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { eigvec = X.get_ref(); arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matrix is not square" ); if(eigvec.is_empty()) { eigval.reset(); eigvec.reset(); return true; } eigval.set_size(eigvec.n_rows); char jobz = 'V'; char uplo = 'U'; blas_int N = blas_int(eigvec.n_rows); blas_int lwork = 2 * (1 + 6*N + 2*(N*N)); blas_int liwork = 3 * (3 + 5*N); blas_int info = 0; podarray work( static_cast( lwork) ); podarray iwork( static_cast(liwork) ); arma_extra_debug_print("lapack::syevd()"); lapack::syevd(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, iwork.memptr(), &liwork, &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK needs to be enabled"); return false; } #endif } //! immediate eigenvalues and eigenvectors of a hermitian complex matrix using LAPACK (divide and conquer algorithm) template inline bool auxlib::eig_sym_dc(Col& eigval, Mat< std::complex >& eigvec, const Base,T1>& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename std::complex eT; eigvec = X.get_ref(); arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matrix is not square" ); if(eigvec.is_empty()) { eigval.reset(); eigvec.reset(); return true; } eigval.set_size(eigvec.n_rows); char jobz = 'V'; char uplo = 'U'; blas_int N = blas_int(eigvec.n_rows); blas_int lwork = 2 * (2*N + N*N); blas_int lrwork = 2 * (1 + 5*N + 2*(N*N)); blas_int liwork = 3 * (3 + 5*N); blas_int info = 0; podarray work( static_cast(lwork) ); podarray rwork( static_cast(lrwork) ); podarray iwork( static_cast(liwork) ); arma_extra_debug_print("lapack::heevd()"); lapack::heevd(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, rwork.memptr(), &lrwork, iwork.memptr(), &liwork, &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK needs to be enabled"); return false; } #endif } //! Eigenvalues and eigenvectors of a general square real matrix using LAPACK. //! The argument 'side' specifies which eigenvectors should be calculated //! (see code for mode details). template inline bool auxlib::eig_gen ( Col< std::complex >& eigval, Mat& l_eigvec, Mat& r_eigvec, const Base& X, const char side ) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { char jobvl; char jobvr; switch(side) { case 'l': // left jobvl = 'V'; jobvr = 'N'; break; case 'r': // right jobvl = 'N'; jobvr = 'V'; break; case 'b': // both jobvl = 'V'; jobvr = 'V'; break; case 'n': // neither jobvl = 'N'; jobvr = 'N'; break; default: arma_stop("eig_gen(): parameter 'side' is invalid"); return false; } Mat A(X.get_ref()); arma_debug_check( (A.is_square() == false), "eig_gen(): given matrix is not square" ); if(A.is_empty()) { eigval.reset(); l_eigvec.reset(); r_eigvec.reset(); return true; } const uword A_n_rows = A.n_rows; eigval.set_size(A_n_rows); l_eigvec.set_size( ((jobvl == 'V') ? A_n_rows : 1), A_n_rows ); r_eigvec.set_size( ((jobvr == 'V') ? A_n_rows : 1), A_n_rows ); blas_int N = blas_int(A_n_rows); blas_int ldvl = blas_int(l_eigvec.n_rows); blas_int ldvr = blas_int(r_eigvec.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 4*N) ); blas_int info = 0; podarray work( static_cast(lwork) ); podarray wr(A_n_rows); podarray wi(A_n_rows); arma_extra_debug_print("lapack::geev()"); lapack::geev(&jobvl, &jobvr, &N, A.memptr(), &N, wr.memptr(), wi.memptr(), l_eigvec.memptr(), &ldvl, r_eigvec.memptr(), &ldvr, work.memptr(), &lwork, &info); eigval.set_size(A_n_rows); for(uword i=0; i(wr[i], wi[i]); } return (info == 0); } #else { arma_ignore(eigval); arma_ignore(l_eigvec); arma_ignore(r_eigvec); arma_ignore(X); arma_ignore(side); arma_stop("eig_gen(): use of LAPACK needs to be enabled"); return false; } #endif } //! Eigenvalues and eigenvectors of a general square complex matrix using LAPACK //! The argument 'side' specifies which eigenvectors should be calculated //! (see code for mode details). template inline bool auxlib::eig_gen ( Col< std::complex >& eigval, Mat< std::complex >& l_eigvec, Mat< std::complex >& r_eigvec, const Base< std::complex, T1 >& X, const char side ) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename std::complex eT; char jobvl; char jobvr; switch(side) { case 'l': // left jobvl = 'V'; jobvr = 'N'; break; case 'r': // right jobvl = 'N'; jobvr = 'V'; break; case 'b': // both jobvl = 'V'; jobvr = 'V'; break; case 'n': // neither jobvl = 'N'; jobvr = 'N'; break; default: arma_stop("eig_gen(): parameter 'side' is invalid"); return false; } Mat A(X.get_ref()); arma_debug_check( (A.is_square() == false), "eig_gen(): given matrix is not square" ); if(A.is_empty()) { eigval.reset(); l_eigvec.reset(); r_eigvec.reset(); return true; } const uword A_n_rows = A.n_rows; eigval.set_size(A_n_rows); l_eigvec.set_size( ((jobvl == 'V') ? A_n_rows : 1), A_n_rows ); r_eigvec.set_size( ((jobvr == 'V') ? A_n_rows : 1), A_n_rows ); blas_int N = blas_int(A_n_rows); blas_int ldvl = blas_int(l_eigvec.n_rows); blas_int ldvr = blas_int(r_eigvec.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 2*N) ); blas_int info = 0; podarray work( static_cast(lwork) ); podarray rwork( static_cast(2*N) ); arma_extra_debug_print("lapack::cx_geev()"); lapack::cx_geev(&jobvl, &jobvr, &N, A.memptr(), &N, eigval.memptr(), l_eigvec.memptr(), &ldvl, r_eigvec.memptr(), &ldvr, work.memptr(), &lwork, rwork.memptr(), &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(l_eigvec); arma_ignore(r_eigvec); arma_ignore(X); arma_ignore(side); arma_stop("eig_gen(): use of LAPACK needs to be enabled"); return false; } #endif } //! Eigenvalues and eigenvectors of general square real matrix pair. //! The argument 'side' specifies which eigenvectors should be calculated. template inline bool auxlib::eig_pair ( Col< std::complex >& eigval, Mat& l_eigvec, Mat& r_eigvec, const Base& X, const Base& Y, const char side ) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { char jobvl; char jobvr; switch(side) { case 'l': // left jobvl = 'V'; jobvr = 'N'; break; case 'r': // right jobvl = 'N'; jobvr = 'V'; break; case 'b': // both jobvl = 'V'; jobvr = 'V'; break; case 'n': // neither jobvl = 'N'; jobvr = 'N'; break; default: arma_stop("eig_pair(): parameter 'side' is invalid"); return false; } Mat A(X.get_ref()); Mat B(Y.get_ref()); arma_debug_check( ((A.is_square() == false) || (B.is_square() == false)), "eig_pair(): given matrix is not square" ); arma_debug_check( (A.n_rows != B.n_rows), "eig_pair(): given matrices must have the same size" ); if(A.is_empty()) { eigval.reset(); l_eigvec.reset(); r_eigvec.reset(); return true; } const uword A_n_rows = A.n_rows; eigval.set_size(A_n_rows); l_eigvec.set_size( ((jobvl == 'V') ? A_n_rows : 1), A_n_rows ); r_eigvec.set_size( ((jobvr == 'V') ? A_n_rows : 1), A_n_rows ); blas_int N = blas_int(A_n_rows); blas_int ldvl = blas_int(l_eigvec.n_rows); blas_int ldvr = blas_int(r_eigvec.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 8*N) ); blas_int info = 0; podarray work( static_cast(lwork) ); podarray alphar(A_n_rows); podarray alphai(A_n_rows); podarray beta(A_n_rows); arma_extra_debug_print("lapack::ggev()"); lapack::ggev ( &jobvl, &jobvr, &N, A.memptr(), &N, B.memptr(), &N, alphar.memptr(), alphai.memptr(), beta.memptr(), l_eigvec.memptr(), &ldvl, r_eigvec.memptr(), &ldvr, work.memptr(), &lwork, &info ); if(info == 0) { // from LAPACK docs: // If ALPHAI(j) is zero, then the j-th eigenvalue is real; // if positive, then the j-th and (j+1)-st eigenvalues are a complex conjugate pair, // with ALPHAI(j+1) negative. eigval.set_size(A_n_rows); const T* alphar_mem = alphar.memptr(); const T* alphai_mem = alphai.memptr(); const T* beta_mem = beta.memptr(); bool beta_has_zero = false; for(uword j=0; j(re, im); if( (alphai_val > T(0)) && (j < (A_n_rows-1)) ) { // ensure we have exact conjugate ++j; eigval[j] = std::complex(re,-im); } } arma_debug_warn(beta_has_zero, "eig_pair(): warning: given matrix appears ill-conditioned"); return true; } else { return false; } } #else { arma_ignore(eigval); arma_ignore(l_eigvec); arma_ignore(r_eigvec); arma_ignore(X); arma_ignore(Y); arma_ignore(side); arma_stop("eig_pair(): use of LAPACK needs to be enabled"); return false; } #endif } //! Eigenvalues and eigenvectors of general square complex matrix pair. //! The argument 'side' specifies which eigenvectors should be calculated template inline bool auxlib::eig_pair ( Col< std::complex >& eigval, Mat< std::complex >& l_eigvec, Mat< std::complex >& r_eigvec, const Base< std::complex, T1 >& X, const Base< std::complex, T2 >& Y, const char side ) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename std::complex eT; char jobvl; char jobvr; switch(side) { case 'l': // left jobvl = 'V'; jobvr = 'N'; break; case 'r': // right jobvl = 'N'; jobvr = 'V'; break; case 'b': // both jobvl = 'V'; jobvr = 'V'; break; case 'n': // neither jobvl = 'N'; jobvr = 'N'; break; default: arma_stop("eig_pair(): parameter 'side' is invalid"); return false; } Mat A(X.get_ref()); Mat B(Y.get_ref()); arma_debug_check( ((A.is_square() == false) || (B.is_square() == false)), "eig_pair(): given matrix is not square" ); arma_debug_check( (A.n_rows != B.n_rows), "eig_pair(): given matrices must have the same size" ); if(A.is_empty()) { eigval.reset(); l_eigvec.reset(); r_eigvec.reset(); return true; } const uword A_n_rows = A.n_rows; podarray alpha(A_n_rows); podarray beta(A_n_rows); l_eigvec.set_size( ((jobvl == 'V') ? A_n_rows : 1), A_n_rows ); r_eigvec.set_size( ((jobvr == 'V') ? A_n_rows : 1), A_n_rows ); blas_int N = blas_int(A_n_rows); blas_int ldvl = blas_int(l_eigvec.n_rows); blas_int ldvr = blas_int(r_eigvec.n_rows); blas_int lwork = 3 * ((std::max)(1,2*N)); blas_int info = 0; podarray work( static_cast(lwork) ); podarray rwork( static_cast(8*N) ); arma_extra_debug_print("lapack::cx_ggev()"); lapack::cx_ggev ( &jobvl, &jobvr, &N, A.memptr(), &N, B.memptr(), &N, alpha.memptr(), beta.memptr(), l_eigvec.memptr(), &ldvl, r_eigvec.memptr(), &ldvr, work.memptr(), &lwork, rwork.memptr(), &info ); if(info == 0) { // TODO: figure out a more robust way to create the eigen values; // TODO: from LAPACK docs: the quotients ALPHA(j)/BETA(j) may easily over- or underflow, and BETA(j) may even be zero eigval.set_size(A_n_rows); eT* eigval_mem = eigval.memptr(); const eT* alpha_mem = alpha.memptr(); const eT* beta_mem = beta.memptr(); const std::complex cx_zero( T(0), T(0) ); bool beta_has_zero = false; for(uword i=0; i inline bool auxlib::chol(Mat& out, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { out = X.get_ref(); arma_debug_check( (out.is_square() == false), "chol(): given matrix is not square" ); if(out.is_empty()) { return true; } const uword out_n_rows = out.n_rows; char uplo = 'U'; blas_int n = out_n_rows; blas_int info = 0; lapack::potrf(&uplo, &n, out.memptr(), &n, &info); for(uword col=0; col inline bool auxlib::qr(Mat& Q, Mat& R, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { R = X.get_ref(); const uword R_n_rows = R.n_rows; const uword R_n_cols = R.n_cols; if(R.is_empty()) { Q.eye(R_n_rows, R_n_rows); return true; } blas_int m = static_cast(R_n_rows); blas_int n = static_cast(R_n_cols); blas_int lwork = 0; blas_int lwork_min = (std::max)(blas_int(1), (std::max)(m,n)); // take into account requirements of geqrf() _and_ orgqr()/ungqr() blas_int k = (std::min)(m,n); blas_int info = 0; podarray tau( static_cast(k) ); eT work_query[2]; blas_int lwork_query = -1; lapack::geqrf(&m, &n, R.memptr(), &m, tau.memptr(), &work_query[0], &lwork_query, &info); if(info == 0) { const blas_int lwork_proposed = static_cast( access::tmp_real(work_query[0]) ); lwork = (lwork_proposed > lwork_min) ? lwork_proposed : lwork_min; } else { return false; } podarray work( static_cast(lwork) ); lapack::geqrf(&m, &n, R.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); Q.set_size(R_n_rows, R_n_rows); arrayops::copy( Q.memptr(), R.memptr(), (std::min)(Q.n_elem, R.n_elem) ); // // construct R for(uword col=0; col < R_n_cols; ++col) { for(uword row=(col+1); row < R_n_rows; ++row) { R.at(row,col) = eT(0); } } if( (is_float::value == true) || (is_double::value == true) ) { lapack::orgqr(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); } else if( (is_supported_complex_float::value == true) || (is_supported_complex_double::value == true) ) { lapack::ungqr(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); } return (info == 0); } #else { arma_ignore(Q); arma_ignore(R); arma_ignore(X); arma_stop("qr(): use of LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::qr_econ(Mat& Q, Mat& R, const Base& X) { arma_extra_debug_sigprint(); // This function implements a memory-efficient QR for a non-square X that has dimensions m x n. // This basically discards the basis for the null-space. // // if m <= n: (use standard routine) // Q[m,m]*R[m,n] = X[m,n] // geqrf Needs A[m,n]: Uses R // orgqr Needs A[m,m]: Uses Q // otherwise: (memory-efficient routine) // Q[m,n]*R[n,n] = X[m,n] // geqrf Needs A[m,n]: Uses Q // geqrf Needs A[m,n]: Uses Q #if defined(ARMA_USE_LAPACK) { if(is_Mat::value == true) { const unwrap tmp(X.get_ref()); const Mat& M = tmp.M; if(M.n_rows < M.n_cols) { return auxlib::qr(Q, R, X); } } Q = X.get_ref(); const uword Q_n_rows = Q.n_rows; const uword Q_n_cols = Q.n_cols; if( Q_n_rows <= Q_n_cols ) { return auxlib::qr(Q, R, Q); } if(Q.is_empty()) { Q.set_size(Q_n_rows, 0 ); R.set_size(0, Q_n_cols); return true; } blas_int m = static_cast(Q_n_rows); blas_int n = static_cast(Q_n_cols); blas_int lwork = 0; blas_int lwork_min = (std::max)(blas_int(1), (std::max)(m,n)); // take into account requirements of geqrf() _and_ orgqr()/ungqr() blas_int k = (std::min)(m,n); blas_int info = 0; podarray tau( static_cast(k) ); eT work_query[2]; blas_int lwork_query = -1; lapack::geqrf(&m, &n, Q.memptr(), &m, tau.memptr(), &work_query[0], &lwork_query, &info); if(info == 0) { const blas_int lwork_proposed = static_cast( access::tmp_real(work_query[0]) ); lwork = (lwork_proposed > lwork_min) ? lwork_proposed : lwork_min; } else { return false; } podarray work( static_cast(lwork) ); lapack::geqrf(&m, &n, Q.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); // Q now has the elements on and above the diagonal of the array // contain the min(M,N)-by-N upper trapezoidal matrix Q // (Q is upper triangular if m >= n); // the elements below the diagonal, with the array TAU, // represent the orthogonal matrix Q as a product of min(m,n) elementary reflectors. R.set_size(Q_n_cols, Q_n_cols); // // construct R for(uword col=0; col < Q_n_cols; ++col) { for(uword row=0; row <= col; ++row) { R.at(row,col) = Q.at(row,col); } for(uword row=(col+1); row < Q_n_cols; ++row) { R.at(row,col) = eT(0); } } if( (is_float::value == true) || (is_double::value == true) ) { lapack::orgqr(&m, &n, &k, Q.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); } else if( (is_supported_complex_float::value == true) || (is_supported_complex_double::value == true) ) { lapack::ungqr(&m, &n, &k, Q.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); } return (info == 0); } #else { arma_ignore(Q); arma_ignore(R); arma_ignore(X); arma_stop("qr_econ(): use of LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::svd(Col& S, const Base& X, uword& X_n_rows, uword& X_n_cols) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); X_n_rows = A.n_rows; X_n_cols = A.n_cols; if(A.is_empty()) { S.reset(); return true; } Mat U(1, 1); Mat V(1, A.n_cols); char jobu = 'N'; char jobvt = 'N'; blas_int m = A.n_rows; blas_int n = A.n_cols; blas_int min_mn = (std::min)(m,n); blas_int lda = A.n_rows; blas_int ldu = U.n_rows; blas_int ldvt = V.n_rows; blas_int lwork = 0; blas_int lwork_min = (std::max)( blas_int(1), (std::max)( (3*min_mn + (std::max)(m,n)), 5*min_mn ) ); blas_int info = 0; S.set_size( static_cast(min_mn) ); eT work_query[2]; blas_int lwork_query = -1; lapack::gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, &work_query[0], &lwork_query, &info ); if(info == 0) { const blas_int lwork_proposed = static_cast( work_query[0] ); lwork = (lwork_proposed > lwork_min) ? lwork_proposed : lwork_min; podarray work( static_cast(lwork) ); lapack::gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, &info ); } return (info == 0); } #else { arma_ignore(S); arma_ignore(X); arma_ignore(X_n_rows); arma_ignore(X_n_cols); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::svd(Col& S, const Base, T1>& X, uword& X_n_rows, uword& X_n_cols) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); X_n_rows = A.n_rows; X_n_cols = A.n_cols; if(A.is_empty()) { S.reset(); return true; } Mat U(1, 1); Mat V(1, A.n_cols); char jobu = 'N'; char jobvt = 'N'; blas_int m = A.n_rows; blas_int n = A.n_cols; blas_int min_mn = (std::min)(m,n); blas_int lda = A.n_rows; blas_int ldu = U.n_rows; blas_int ldvt = V.n_rows; blas_int lwork = 3 * ( (std::max)(blas_int(1), 2*min_mn+(std::max)(m,n) ) ); blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray< T> rwork( static_cast(5*min_mn) ); // let gesvd_() calculate the optimum size of the workspace blas_int lwork_tmp = -1; lapack::cx_gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork_tmp, rwork.memptr(), &info ); if(info == 0) { blas_int proposed_lwork = static_cast(real(work[0])); if(proposed_lwork > lwork) { lwork = proposed_lwork; work.set_size( static_cast(lwork) ); } lapack::cx_gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), &info ); } return (info == 0); } #else { arma_ignore(S); arma_ignore(X); arma_ignore(X_n_rows); arma_ignore(X_n_cols); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::svd(Col& S, const Base& X) { arma_extra_debug_sigprint(); uword junk; return auxlib::svd(S, X, junk, junk); } template inline bool auxlib::svd(Col& S, const Base, T1>& X) { arma_extra_debug_sigprint(); uword junk; return auxlib::svd(S, X, junk, junk); } template inline bool auxlib::svd(Mat& U, Col& S, Mat& V, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); S.reset(); V.eye(A.n_cols, A.n_cols); return true; } U.set_size(A.n_rows, A.n_rows); V.set_size(A.n_cols, A.n_cols); char jobu = 'A'; char jobvt = 'A'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork_min = (std::max)( blas_int(1), (std::max)( (3*min_mn + (std::max)(m,n)), 5*min_mn ) ); blas_int lwork = 0; blas_int info = 0; S.set_size( static_cast(min_mn) ); // let gesvd_() calculate the optimum size of the workspace eT work_query[2]; blas_int lwork_query = -1; lapack::gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, &work_query[0], &lwork_query, &info ); if(info == 0) { const blas_int lwork_proposed = static_cast( work_query[0] ); lwork = (lwork_proposed > lwork_min) ? lwork_proposed : lwork_min; podarray work( static_cast(lwork) ); lapack::gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, &info ); op_strans::apply_mat_inplace(V); } return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::svd(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); S.reset(); V.eye(A.n_cols, A.n_cols); return true; } U.set_size(A.n_rows, A.n_rows); V.set_size(A.n_cols, A.n_cols); char jobu = 'A'; char jobvt = 'A'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 2*min_mn + (std::max)(m,n) ) ); blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray rwork( static_cast(5*min_mn) ); // let gesvd_() calculate the optimum size of the workspace blas_int lwork_tmp = -1; lapack::cx_gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork_tmp, rwork.memptr(), &info ); if(info == 0) { blas_int proposed_lwork = static_cast(real(work[0])); if(proposed_lwork > lwork) { lwork = proposed_lwork; work.set_size( static_cast(lwork) ); } lapack::cx_gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), &info ); op_htrans::apply_mat_inplace(V); } return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::svd_econ(Mat& U, Col& S, Mat& V, const Base& X, const char mode) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); S.set_size( static_cast(min_mn) ); blas_int ldu = 0; blas_int ldvt = 0; char jobu; char jobvt; switch(mode) { case 'l': jobu = 'S'; jobvt = 'N'; ldu = m; ldvt = 1; U.set_size( static_cast(ldu), static_cast(min_mn) ); V.reset(); break; case 'r': jobu = 'N'; jobvt = 'S'; ldu = 1; ldvt = (std::min)(m,n); U.reset(); V.set_size( static_cast(ldvt), static_cast(n) ); break; case 'b': jobu = 'S'; jobvt = 'S'; ldu = m; ldvt = (std::min)(m,n); U.set_size( static_cast(ldu), static_cast(min_mn) ); V.set_size( static_cast(ldvt), static_cast(n ) ); break; default: U.reset(); S.reset(); V.reset(); return false; } if(A.is_empty()) { U.eye(); S.reset(); V.eye(); return true; } blas_int lwork = 3 * ( (std::max)(blas_int(1), (std::max)( (3*min_mn + (std::max)(m,n)), 5*min_mn ) ) ); blas_int info = 0; podarray work( static_cast(lwork) ); // let gesvd_() calculate the optimum size of the workspace blas_int lwork_tmp = -1; lapack::gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork_tmp, &info ); if(info == 0) { blas_int proposed_lwork = static_cast(work[0]); if(proposed_lwork > lwork) { lwork = proposed_lwork; work.set_size( static_cast(lwork) ); } lapack::gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, &info ); op_strans::apply_mat_inplace(V); } return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_ignore(mode); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::svd_econ(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X, const char mode) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); S.set_size( static_cast(min_mn) ); blas_int ldu = 0; blas_int ldvt = 0; char jobu; char jobvt; switch(mode) { case 'l': jobu = 'S'; jobvt = 'N'; ldu = m; ldvt = 1; U.set_size( static_cast(ldu), static_cast(min_mn) ); V.reset(); break; case 'r': jobu = 'N'; jobvt = 'S'; ldu = 1; ldvt = (std::min)(m,n); U.reset(); V.set_size( static_cast(ldvt), static_cast(n) ); break; case 'b': jobu = 'S'; jobvt = 'S'; ldu = m; ldvt = (std::min)(m,n); U.set_size( static_cast(ldu), static_cast(min_mn) ); V.set_size( static_cast(ldvt), static_cast(n) ); break; default: U.reset(); S.reset(); V.reset(); return false; } if(A.is_empty()) { U.eye(); S.reset(); V.eye(); return true; } blas_int lwork = 3 * ( (std::max)(blas_int(1), (std::max)( (3*min_mn + (std::max)(m,n)), 5*min_mn ) ) ); blas_int info = 0; podarray work( static_cast(lwork ) ); podarray rwork( static_cast(5*min_mn) ); // let gesvd_() calculate the optimum size of the workspace blas_int lwork_tmp = -1; lapack::cx_gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork_tmp, rwork.memptr(), &info ); if(info == 0) { blas_int proposed_lwork = static_cast(real(work[0])); if(proposed_lwork > lwork) { lwork = proposed_lwork; work.set_size( static_cast(lwork) ); } lapack::cx_gesvd ( &jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), &info ); op_htrans::apply_mat_inplace(V); } return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_ignore(mode); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } // EXPERIMENTAL template inline bool auxlib::svd_dc(Col& S, const Base& X, uword& X_n_rows, uword& X_n_cols) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); X_n_rows = A.n_rows; X_n_cols = A.n_cols; if(A.is_empty()) { S.reset(); return true; } Mat U(1, 1); Mat V(1, 1); char jobz = 'N'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork = 3 * ( 3*min_mn + std::max( std::max(m,n), 7*min_mn ) ); blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray iwork( static_cast(8*min_mn) ); lapack::gesdd ( &jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, iwork.memptr(), &info ); return (info == 0); } #else { arma_ignore(S); arma_ignore(X); arma_ignore(X_n_rows); arma_ignore(X_n_cols); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } // EXPERIMENTAL template inline bool auxlib::svd_dc(Col& S, const Base, T1>& X, uword& X_n_rows, uword& X_n_cols) { arma_extra_debug_sigprint(); #if (defined(ARMA_USE_LAPACK) && defined(ARMA_DONT_USE_CX_GESDD)) { arma_extra_debug_print("auxlib::svd_dc(): redirecting to auxlib::svd(), as use of lapack::cx_gesdd() is disabled"); return auxlib::svd(S, X, X_n_rows, X_n_cols); } #elif defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); X_n_rows = A.n_rows; X_n_cols = A.n_cols; if(A.is_empty()) { S.reset(); return true; } Mat U(1, 1); Mat V(1, 1); char jobz = 'N'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork = 3 * (2*min_mn + std::max(m,n)); blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray rwork( static_cast(5*min_mn) ); podarray iwork( static_cast(8*min_mn) ); lapack::cx_gesdd ( &jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), iwork.memptr(), &info ); return (info == 0); } #else { arma_ignore(S); arma_ignore(X); arma_ignore(X_n_rows); arma_ignore(X_n_cols); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } // EXPERIMENTAL template inline bool auxlib::svd_dc(Col& S, const Base& X) { arma_extra_debug_sigprint(); uword junk; return auxlib::svd_dc(S, X, junk, junk); } // EXPERIMENTAL template inline bool auxlib::svd_dc(Col& S, const Base, T1>& X) { arma_extra_debug_sigprint(); uword junk; return auxlib::svd_dc(S, X, junk, junk); } template inline bool auxlib::svd_dc(Mat& U, Col& S, Mat& V, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); S.reset(); V.eye(A.n_cols, A.n_cols); return true; } U.set_size(A.n_rows, A.n_rows); V.set_size(A.n_cols, A.n_cols); char jobz = 'A'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int max_mn = (std::max)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork1 = 3*min_mn*min_mn + (std::max)( max_mn, 4*min_mn*min_mn + 4*min_mn ); blas_int lwork2 = 3*min_mn + (std::max)( max_mn, 4*min_mn*min_mn + 3*min_mn + max_mn ); blas_int lwork = 2 * ((std::max)(lwork1, lwork2)); // due to differences between lapack 3.1 and 3.4 blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray iwork( static_cast(8*min_mn) ); lapack::gesdd ( &jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, iwork.memptr(), &info ); op_strans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::svd_dc(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X) { arma_extra_debug_sigprint(); #if (defined(ARMA_USE_LAPACK) && defined(ARMA_DONT_USE_CX_GESDD)) { arma_extra_debug_print("auxlib::svd_dc(): redirecting to auxlib::svd(), as use of lapack::cx_gesdd() is disabled"); return auxlib::svd(U, S, V, X); } #elif defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); S.reset(); V.eye(A.n_cols, A.n_cols); return true; } U.set_size(A.n_rows, A.n_rows); V.set_size(A.n_cols, A.n_cols); char jobz = 'A'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int max_mn = (std::max)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork = 2 * (min_mn*min_mn + 2*min_mn + max_mn); blas_int lrwork1 = 5*min_mn*min_mn + 7*min_mn; blas_int lrwork2 = min_mn * ((std::max)(5*min_mn+7, 2*max_mn + 2*min_mn+1)); blas_int lrwork = (std::max)(lrwork1, lrwork2); // due to differences between lapack 3.1 and 3.4 blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray rwork( static_cast(lrwork ) ); podarray iwork( static_cast(8*min_mn) ); lapack::cx_gesdd ( &jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), iwork.memptr(), &info ); op_htrans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::svd_dc_econ(Mat& U, Col& S, Mat& V, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); char jobz = 'S'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int max_mn = (std::max)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = m; blas_int ldvt = min_mn; blas_int lwork1 = 3*min_mn*min_mn + (std::max)( max_mn, 4*min_mn*min_mn + 4*min_mn ); blas_int lwork2 = 3*min_mn + (std::max)( max_mn, 4*min_mn*min_mn + 3*min_mn + max_mn ); blas_int lwork = 2 * ((std::max)(lwork1, lwork2)); // due to differences between lapack 3.1 and 3.4 blas_int info = 0; if(A.is_empty()) { U.eye(); S.reset(); V.eye( static_cast(n), static_cast(min_mn) ); return true; } S.set_size( static_cast(min_mn) ); U.set_size( static_cast(m), static_cast(min_mn) ); V.set_size( static_cast(min_mn), static_cast(n) ); podarray work( static_cast(lwork ) ); podarray iwork( static_cast(8*min_mn) ); lapack::gesdd ( &jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, iwork.memptr(), &info ); op_strans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::svd_dc_econ(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X) { arma_extra_debug_sigprint(); #if (defined(ARMA_USE_LAPACK) && defined(ARMA_DONT_USE_CX_GESDD)) { arma_extra_debug_print("auxlib::svd_dc_econ(): redirecting to auxlib::svd_econ(), as use of lapack::cx_gesdd() is disabled"); return auxlib::svd_econ(U, S, V, X, 'b'); } #elif defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); char jobz = 'S'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int max_mn = (std::max)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = m; blas_int ldvt = min_mn; blas_int lwork = 2 * (min_mn*min_mn + 2*min_mn + max_mn); blas_int lrwork1 = 5*min_mn*min_mn + 7*min_mn; blas_int lrwork2 = min_mn * ((std::max)(5*min_mn+7, 2*max_mn + 2*min_mn+1)); blas_int lrwork = (std::max)(lrwork1, lrwork2); // due to differences between lapack 3.1 and 3.4 blas_int info = 0; if(A.is_empty()) { U.eye(); S.reset(); V.eye( static_cast(n), static_cast(min_mn) ); return true; } S.set_size( static_cast(min_mn) ); U.set_size( static_cast(m), static_cast(min_mn) ); V.set_size( static_cast(min_mn), static_cast(n) ); podarray work( static_cast(lwork ) ); podarray rwork( static_cast(lrwork ) ); podarray iwork( static_cast(8*min_mn) ); lapack::cx_gesdd ( &jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), iwork.memptr(), &info ); op_htrans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK needs to be enabled"); return false; } #endif } //! Solve a system of linear equations. //! Assumes that A.n_rows = A.n_cols and B.n_rows = A.n_rows template inline bool auxlib::solve(Mat& out, Mat& A, const Base& X, const bool slow) { arma_extra_debug_sigprint(); bool status = false; const uword A_n_rows = A.n_rows; if( (A_n_rows <= 4) && (slow == false) ) { Mat A_inv(A_n_rows, A_n_rows); status = auxlib::inv_noalias_tinymat(A_inv, A, A_n_rows); if(status == true) { const unwrap_check Y( X.get_ref(), out ); const Mat& B = Y.M; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; arma_debug_check( (A_n_rows != B_n_rows), "solve(): number of rows in the given objects must be the same" ); if(A.is_empty() || B.is_empty()) { out.zeros(A.n_cols, B_n_cols); return true; } out.set_size(A_n_rows, B_n_cols); gemm_emul::apply(out, A_inv, B); return true; } } if( (A_n_rows > 4) || (status == false) ) { out = X.get_ref(); const uword B_n_rows = out.n_rows; const uword B_n_cols = out.n_cols; arma_debug_check( (A_n_rows != B_n_rows), "solve(): number of rows in the given objects must be the same" ); if(A.is_empty() || out.is_empty()) { out.zeros(A.n_cols, B_n_cols); return true; } #if defined(ARMA_USE_ATLAS) { podarray ipiv(A_n_rows + 2); // +2 for paranoia: old versions of Atlas might be trashing memory int info = atlas::clapack_gesv(atlas::CblasColMajor, A_n_rows, B_n_cols, A.memptr(), A_n_rows, ipiv.memptr(), out.memptr(), A_n_rows); return (info == 0); } #elif defined(ARMA_USE_LAPACK) { blas_int n = blas_int(A_n_rows); // assuming A is square blas_int lda = blas_int(A_n_rows); blas_int ldb = blas_int(A_n_rows); blas_int nrhs = blas_int(B_n_cols); blas_int info = 0; podarray ipiv(A_n_rows + 2); // +2 for paranoia: some versions of Lapack might be trashing memory arma_extra_debug_print("lapack::gesv()"); lapack::gesv(&n, &nrhs, A.memptr(), &lda, ipiv.memptr(), out.memptr(), &ldb, &info); arma_extra_debug_print("lapack::gesv() -- finished"); return (info == 0); } #else { arma_stop("solve(): use of ATLAS or LAPACK needs to be enabled"); return false; } #endif } return true; } //! Solve an over-determined system. //! Assumes that A.n_rows > A.n_cols and B.n_rows = A.n_rows template inline bool auxlib::solve_od(Mat& out, Mat& A, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat tmp = X.get_ref(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = tmp.n_rows; const uword B_n_cols = tmp.n_cols; arma_debug_check( (A_n_rows != B_n_rows), "solve(): number of rows in the given objects must be the same" ); out.set_size(A_n_cols, B_n_cols); if(A.is_empty() || tmp.is_empty()) { out.zeros(); return true; } char trans = 'N'; blas_int m = blas_int(A_n_rows); blas_int n = blas_int(A_n_cols); blas_int lda = blas_int(A_n_rows); blas_int ldb = blas_int(A_n_rows); blas_int nrhs = blas_int(B_n_cols); blas_int lwork = 3 * ( (std::max)(blas_int(1), n + (std::max)(n, nrhs)) ); blas_int info = 0; podarray work( static_cast(lwork) ); // NOTE: the dgels() function in the lapack library supplied by ATLAS 3.6 seems to have problems arma_extra_debug_print("lapack::gels()"); lapack::gels( &trans, &m, &n, &nrhs, A.memptr(), &lda, tmp.memptr(), &ldb, work.memptr(), &lwork, &info ); arma_extra_debug_print("lapack::gels() -- finished"); for(uword col=0; col inline bool auxlib::solve_ud(Mat& out, Mat& A, const Base& X) { arma_extra_debug_sigprint(); // TODO: this function provides the same results as Octave 3.4.2. // TODO: however, these results are different than Matlab 7.12.0.635. // TODO: figure out whether both Octave and Matlab are correct, or only one of them #if defined(ARMA_USE_LAPACK) { const unwrap Y( X.get_ref() ); const Mat& B = Y.M; const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; arma_debug_check( (A_n_rows != B_n_rows), "solve(): number of rows in the given objects must be the same" ); // B could be an alias of "out", hence we need to check whether B is empty before setting the size of "out" if(A.is_empty() || B.is_empty()) { out.zeros(A_n_cols, B_n_cols); return true; } char trans = 'N'; blas_int m = blas_int(A_n_rows); blas_int n = blas_int(A_n_cols); blas_int lda = blas_int(A_n_rows); blas_int ldb = blas_int(A_n_cols); blas_int nrhs = blas_int(B_n_cols); blas_int lwork = 3 * ( (std::max)(blas_int(1), m + (std::max)(m,nrhs)) ); blas_int info = 0; Mat tmp(A_n_cols, B_n_cols); tmp.zeros(); for(uword col=0; col work( static_cast(lwork) ); // NOTE: the dgels() function in the lapack library supplied by ATLAS 3.6 seems to have problems arma_extra_debug_print("lapack::gels()"); lapack::gels( &trans, &m, &n, &nrhs, A.memptr(), &lda, tmp.memptr(), &ldb, work.memptr(), &lwork, &info ); arma_extra_debug_print("lapack::gels() -- finished"); out.set_size(A_n_cols, B_n_cols); for(uword col=0; col inline bool auxlib::solve_tr(Mat& out, const Mat& A, const Mat& B, const uword layout) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { if(A.is_empty() || B.is_empty()) { out.zeros(A.n_cols, B.n_cols); return true; } out = B; char uplo = (layout == 0) ? 'U' : 'L'; char trans = 'N'; char diag = 'N'; blas_int n = blas_int(A.n_rows); blas_int nrhs = blas_int(B.n_cols); blas_int info = 0; lapack::trtrs(&uplo, &trans, &diag, &n, &nrhs, A.memptr(), &n, out.memptr(), &n, &info); return (info == 0); } #else { arma_ignore(out); arma_ignore(A); arma_ignore(B); arma_ignore(layout); arma_stop("solve(): use of LAPACK needs to be enabled"); return false; } #endif } // // Schur decomposition template inline bool auxlib::schur_dec(Mat& Z, Mat& T, const Mat& A) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { arma_debug_check( (A.is_square() == false), "schur_dec(): given matrix is not square" ); if(A.is_empty()) { Z.reset(); T.reset(); return true; } const uword A_n_rows = A.n_rows; Z.set_size(A_n_rows, A_n_rows); T = A; char jobvs = 'V'; // get Schur vectors (Z) char sort = 'N'; // do not sort eigenvalues/vectors blas_int* select = 0; // pointer to sorting function blas_int n = blas_int(A_n_rows); blas_int sdim = 0; // output for sorting blas_int lwork = 3 * ( (std::max)(blas_int(1), 3*n) ); blas_int info = 0; podarray work( static_cast(lwork) ); podarray bwork(A_n_rows); podarray wr(A_n_rows); // output for eigenvalues podarray wi(A_n_rows); // output for eigenvalues lapack::gees(&jobvs, &sort, select, &n, T.memptr(), &n, &sdim, wr.memptr(), wi.memptr(), Z.memptr(), &n, work.memptr(), &lwork, bwork.memptr(), &info); return (info == 0); } #else { arma_ignore(Z); arma_ignore(T); arma_ignore(A); arma_stop("schur_dec(): use of LAPACK needs to be enabled"); return false; } #endif } template inline bool auxlib::schur_dec(Mat >& Z, Mat >& T, const Mat >& A) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { arma_debug_check( (A.is_square() == false), "schur_dec(): matrix A is not square" ); if(A.is_empty()) { Z.reset(); T.reset(); return true; } typedef std::complex eT; const uword A_n_rows = A.n_rows; Z.set_size(A_n_rows, A_n_rows); T = A; char jobvs = 'V'; // get Schur vectors (Z) char sort = 'N'; // do not sort eigenvalues/vectors blas_int* select = 0; // pointer to sorting function blas_int n = blas_int(A_n_rows); blas_int sdim = 0; // output for sorting blas_int lwork = 3 * ( (std::max)(blas_int(1), 2*n) ); blas_int info = 0; podarray work( static_cast(lwork) ); podarray bwork(A_n_rows); podarray w(A_n_rows); // output for eigenvalues podarray rwork(A_n_rows); lapack::cx_gees(&jobvs, &sort, select, &n, T.memptr(), &n, &sdim, w.memptr(), Z.memptr(), &n, work.memptr(), &lwork, rwork.memptr(), bwork.memptr(), &info); return (info == 0); } #else { arma_ignore(Z); arma_ignore(T); arma_ignore(A); arma_stop("schur_dec(): use of LAPACK needs to be enabled"); return false; } #endif } // // syl (solution of the Sylvester equation AX + XB = C) template inline bool auxlib::syl(Mat& X, const Mat& A, const Mat& B, const Mat& C) { arma_extra_debug_sigprint(); arma_debug_check ( (A.is_square() == false) || (B.is_square() == false), "syl(): given matrix is not square" ); arma_debug_check ( (C.n_rows != A.n_rows) || (C.n_cols != B.n_cols), "syl(): matrices are not conformant" ); if(A.is_empty() || B.is_empty() || C.is_empty()) { X.reset(); return true; } #if defined(ARMA_USE_LAPACK) { Mat Z1, Z2, T1, T2; const bool status_sd1 = auxlib::schur_dec(Z1, T1, A); const bool status_sd2 = auxlib::schur_dec(Z2, T2, B); if( (status_sd1 == false) || (status_sd2 == false) ) { return false; } char trana = 'N'; char tranb = 'N'; blas_int isgn = +1; blas_int m = blas_int(T1.n_rows); blas_int n = blas_int(T2.n_cols); eT scale = eT(0); blas_int info = 0; Mat Y = trans(Z1) * C * Z2; lapack::trsyl(&trana, &tranb, &isgn, &m, &n, T1.memptr(), &m, T2.memptr(), &n, Y.memptr(), &m, &scale, &info); //Y /= scale; Y /= (-scale); X = Z1 * Y * trans(Z2); return (info >= 0); } #else { arma_stop("syl(): use of LAPACK needs to be enabled"); return false; } #endif } // // lyap (solution of the continuous Lyapunov equation AX + XA^H + Q = 0) template inline bool auxlib::lyap(Mat& X, const Mat& A, const Mat& Q) { arma_extra_debug_sigprint(); arma_debug_check( (A.is_square() == false), "lyap(): matrix A is not square"); arma_debug_check( (Q.is_square() == false), "lyap(): matrix Q is not square"); arma_debug_check( (A.n_rows != Q.n_rows), "lyap(): matrices A and Q have different dimensions"); Mat htransA; op_htrans::apply_mat_noalias(htransA, A); const Mat mQ = -Q; return auxlib::syl(X, A, htransA, mQ); } // // dlyap (solution of the discrete Lyapunov equation AXA^H - X + Q = 0) template inline bool auxlib::dlyap(Mat& X, const Mat& A, const Mat& Q) { arma_extra_debug_sigprint(); arma_debug_check( (A.is_square() == false), "dlyap(): matrix A is not square"); arma_debug_check( (Q.is_square() == false), "dlyap(): matrix Q is not square"); arma_debug_check( (A.n_rows != Q.n_rows), "dlyap(): matrices A and Q have different dimensions"); const Col vecQ = reshape(Q, Q.n_elem, 1); const Mat M = eye< Mat >(Q.n_elem, Q.n_elem) - kron(conj(A), A); Col vecX; const bool status = solve(vecX, M, vecQ); if(status == true) { X = reshape(vecX, Q.n_rows, Q.n_cols); return true; } else { X.reset(); return false; } } //! @} RcppArmadillo/inst/include/armadillo_bits/op_cov_bones.hpp0000644000176000001440000000146312200631217023602 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_cov //! @{ class op_cov { public: template inline static void direct_cov(Mat& out, const Mat& X, const uword norm_type); template inline static void direct_cov(Mat< std::complex >& out, const Mat< std::complex >& X, const uword norm_type); template inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/arma_rng_cxx11.hpp0000644000176000001440000000420112246630413023741 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup arma_rng_cxx11 //! @{ class arma_rng_cxx11 { public: typedef typename std::mt19937_64::result_type seed_type; inline void set_seed(const seed_type val); arma_inline int randi_val(); arma_inline double randu_val(); arma_inline double randn_val(); template arma_inline void randn_dual_val(eT& out1, eT& out2); template inline void randi_fill(eT* mem, const uword N, const int a, const int b); inline static int randi_max_val(); private: arma_aligned std::mt19937_64 engine; // typedef for std::mersenne_twister_engine with preset parameters arma_aligned std::uniform_int_distribution i_distr; // by default uses a=0, b=std::numeric_limits::max() arma_aligned std::uniform_real_distribution u_distr; // by default uses [0,1) interval arma_aligned std::normal_distribution n_distr; // by default uses mean=0.0 and stddev=1.0 }; inline void arma_rng_cxx11::set_seed(const arma_rng_cxx11::seed_type val) { engine.seed(val); } arma_inline int arma_rng_cxx11::randi_val() { return i_distr(engine); } arma_inline double arma_rng_cxx11::randu_val() { return u_distr(engine); } arma_inline double arma_rng_cxx11::randn_val() { return n_distr(engine); } template arma_inline void arma_rng_cxx11::randn_dual_val(eT& out1, eT& out2) { out1 = eT( n_distr(engine) ); out2 = eT( n_distr(engine) ); } template inline void arma_rng_cxx11::randi_fill(eT* mem, const uword N, const int a, const int b) { std::uniform_int_distribution i_distr(a, b); for(uword i=0; i::max(); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_cx_scalar_meat.hpp0000644000176000001440000002737012250120055024575 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_cx_scalar //! @{ template inline void op_cx_scalar_times::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_times>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_plus::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_plus>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_minus_pre::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_minus_pre>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_minus_post::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_minus_post>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_div_pre::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_div_pre>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_div_post::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_div_post>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_times::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_times>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline void op_cx_scalar_plus::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_plus>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline void op_cx_scalar_minus_pre::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_minus_pre>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline void op_cx_scalar_minus_post::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_minus_post>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline void op_cx_scalar_div_pre::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_div_pre>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline void op_cx_scalar_div_post::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_div_post>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline subview::~subview() { arma_extra_debug_sigprint(); } template inline subview::subview(const Mat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols) : m(in_m) , aux_row1(in_row1) , aux_col1(in_col1) , n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows*in_n_cols) { arma_extra_debug_sigprint(); } template inline void subview::operator= (const eT val) { arma_extra_debug_sigprint(); if(n_elem != 1) { arma_debug_assert_same_size(n_rows, n_cols, 1, 1, "copy into submatrix"); } Mat& X = const_cast< Mat& >(m); X.at(aux_row1, aux_col1) = val; } template inline void subview::operator+= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_cols = n_cols; const uword local_n_rows = n_rows; if(local_n_rows == 1) { Mat& X = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; const uword end_col_plus1 = start_col + local_n_cols; uword ii,jj; for(ii=start_col, jj=start_col+1; jj < end_col_plus1; ii+=2, jj+=2) { X.at(urow, ii) += val; X.at(urow, jj) += val; } if(ii < end_col_plus1) { X.at(urow, ii) += val; } } else { for(uword ucol=0; ucol < local_n_cols; ++ucol) { arrayops::inplace_plus( colptr(ucol), val, local_n_rows ); } } } template inline void subview::operator-= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_cols = n_cols; const uword local_n_rows = n_rows; if(local_n_rows == 1) { Mat& X = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; const uword end_col_plus1 = start_col + local_n_cols; uword ii,jj; for(ii=start_col, jj=start_col+1; jj < end_col_plus1; ii+=2, jj+=2) { X.at(urow, ii) -= val; X.at(urow, jj) -= val; } if(ii < end_col_plus1) { X.at(urow, ii) -= val; } } else { for(uword ucol=0; ucol < local_n_cols; ++ucol) { arrayops::inplace_minus( colptr(ucol), val, local_n_rows ); } } } template inline void subview::operator*= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_cols = n_cols; const uword local_n_rows = n_rows; if(local_n_rows == 1) { Mat& X = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; const uword end_col_plus1 = start_col + local_n_cols; uword ii,jj; for(ii=start_col, jj=start_col+1; jj < end_col_plus1; ii+=2, jj+=2) { X.at(urow, ii) *= val; X.at(urow, jj) *= val; } if(ii < end_col_plus1) { X.at(urow, ii) *= val; } } else { for(uword ucol=0; ucol < local_n_cols; ++ucol) { arrayops::inplace_mul( colptr(ucol), val, local_n_rows ); } } } template inline void subview::operator/= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_cols = n_cols; const uword local_n_rows = n_rows; if(local_n_rows == 1) { Mat& X = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; const uword end_col_plus1 = start_col + local_n_cols; uword ii,jj; for(ii=start_col, jj=start_col+1; jj < end_col_plus1; ii+=2, jj+=2) { X.at(urow, ii) /= val; X.at(urow, jj) /= val; } if(ii < end_col_plus1) { X.at(urow, ii) /= val; } } else { for(uword ucol=0; ucol < local_n_cols; ++ucol) { arrayops::inplace_div( colptr(ucol), val, local_n_rows ); } } } template template inline void subview::operator= (const Base& in) { arma_extra_debug_sigprint(); const Proxy P(in.get_ref()); subview& s = *this; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_assert_same_size(s, P, "copy into submatrix"); const bool is_alias = P.is_alias(s.m); arma_extra_debug_warn(is_alias, "aliasing detected"); if( (is_Mat::stored_type>::value == true) || (is_alias == true) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; if(s_n_rows == 1) { const eT* x_mem = x.memptr(); Mat& A = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { A.at(urow, start_col+ii) = x_mem[ii]; A.at(urow, start_col+jj) = x_mem[jj]; } if(ii < s_n_cols) { A.at(urow, start_col+ii) = x_mem[ii]; } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { arrayops::copy( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } } } else { if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { const eT tmp1 = (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; const eT tmp2 = (Proxy::prefer_at_accessor) ? P.at(0,jj) : P[jj]; A.at(urow, start_col+ii) = tmp1; A.at(urow, start_col+jj) = tmp2; } if(ii < s_n_cols) { A.at(urow, start_col+ii) = (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { eT* s_col_data = s.colptr(ucol); uword ii,jj; for(ii=0, jj=1; jj < s_n_rows; ii+=2, jj+=2) { const eT tmp1 = P.at(ii,ucol); const eT tmp2 = P.at(jj,ucol); s_col_data[ii] = tmp1; s_col_data[jj] = tmp2; } if(ii < s_n_rows) { s_col_data[ii] = P.at(ii,ucol); } } } } } template template inline void subview::operator+= (const Base& in) { arma_extra_debug_sigprint(); const Proxy P(in.get_ref()); subview& s = *this; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_assert_same_size(s, P, "addition"); const bool is_alias = P.is_alias(s.m); arma_extra_debug_warn(is_alias, "aliasing detected"); if( (is_Mat::stored_type>::value == true) || (is_alias == true) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; if(s_n_rows == 1) { const eT* x_mem = x.memptr(); Mat& A = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { A.at(urow, start_col+ii) += x_mem[ii]; A.at(urow, start_col+jj) += x_mem[jj]; } if(ii < s_n_cols) { A.at(urow, start_col+ii) += x_mem[ii]; } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { arrayops::inplace_plus( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } } } else { if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { const eT tmp1 = (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; const eT tmp2 = (Proxy::prefer_at_accessor) ? P.at(0,jj) : P[jj]; A.at(urow, start_col+ii) += tmp1; A.at(urow, start_col+jj) += tmp2; } if(ii < s_n_cols) { A.at(urow, start_col+ii) += (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { eT* s_col_data = s.colptr(ucol); uword ii,jj; for(ii=0, jj=1; jj < s_n_rows; ii+=2, jj+=2) { const eT val1 = P.at(ii,ucol); const eT val2 = P.at(jj,ucol); s_col_data[ii] += val1; s_col_data[jj] += val2; } if(ii < s_n_rows) { s_col_data[ii] += P.at(ii,ucol); } } } } } template template inline void subview::operator-= (const Base& in) { arma_extra_debug_sigprint(); const Proxy P(in.get_ref()); subview& s = *this; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_assert_same_size(s, P, "subtraction"); const bool is_alias = P.is_alias(s.m); arma_extra_debug_warn(is_alias, "aliasing detected"); if( (is_Mat::stored_type>::value == true) || (is_alias == true) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; if(s_n_rows == 1) { const eT* x_mem = x.memptr(); Mat& A = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { A.at(urow, start_col+ii) -= x_mem[ii]; A.at(urow, start_col+jj) -= x_mem[jj]; } if(ii < s_n_cols) { A.at(urow, start_col+ii) -= x_mem[ii]; } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { arrayops::inplace_minus( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } } } else { if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { const eT tmp1 = (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; const eT tmp2 = (Proxy::prefer_at_accessor) ? P.at(0,jj) : P[jj]; A.at(urow, start_col+ii) -= tmp1; A.at(urow, start_col+jj) -= tmp2; } if(ii < s_n_cols) { A.at(urow, start_col+ii) -= (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { eT* s_col_data = s.colptr(ucol); uword ii,jj; for(ii=0, jj=1; jj < s_n_rows; ii+=2, jj+=2) { const eT val1 = P.at(ii,ucol); const eT val2 = P.at(jj,ucol); s_col_data[ii] -= val1; s_col_data[jj] -= val2; } if(ii < s_n_rows) { s_col_data[ii] -= P.at(ii,ucol); } } } } } template template inline void subview::operator%= (const Base& in) { arma_extra_debug_sigprint(); const Proxy P(in.get_ref()); subview& s = *this; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_assert_same_size(s, P, "element-wise multiplication"); const bool is_alias = P.is_alias(s.m); arma_extra_debug_warn(is_alias, "aliasing detected"); if( (is_Mat::stored_type>::value == true) || (is_alias == true) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; if(s_n_rows == 1) { const eT* x_mem = x.memptr(); Mat& A = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { A.at(urow, start_col+ii) *= x_mem[ii]; A.at(urow, start_col+jj) *= x_mem[jj]; } if(ii < s_n_cols) { A.at(urow, start_col+ii) *= x_mem[ii]; } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { arrayops::inplace_mul( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } } } else { if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { const eT tmp1 = (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; const eT tmp2 = (Proxy::prefer_at_accessor) ? P.at(0,jj) : P[jj]; A.at(urow, start_col+ii) *= tmp1; A.at(urow, start_col+jj) *= tmp2; } if(ii < s_n_cols) { A.at(urow, start_col+ii) *= (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { eT* s_col_data = s.colptr(ucol); uword ii,jj; for(ii=0, jj=1; jj < s_n_rows; ii+=2, jj+=2) { const eT val1 = P.at(ii,ucol); const eT val2 = P.at(jj,ucol); s_col_data[ii] *= val1; s_col_data[jj] *= val2; } if(ii < s_n_rows) { s_col_data[ii] *= P.at(ii,ucol); } } } } } template template inline void subview::operator/= (const Base& in) { arma_extra_debug_sigprint(); const Proxy P(in.get_ref()); subview& s = *this; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_assert_same_size(s, P, "element-wise division"); const bool is_alias = P.is_alias(s.m); arma_extra_debug_warn(is_alias, "aliasing detected"); if( (is_Mat::stored_type>::value == true) || (is_alias == true) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; if(s_n_rows == 1) { const eT* x_mem = x.memptr(); Mat& A = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { A.at(urow, start_col+ii) /= x_mem[ii]; A.at(urow, start_col+jj) /= x_mem[jj]; } if(ii < s_n_cols) { A.at(urow, start_col+ii) /= x_mem[ii]; } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { arrayops::inplace_div( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } } } else { if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { const eT tmp1 = (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; const eT tmp2 = (Proxy::prefer_at_accessor) ? P.at(0,jj) : P[jj]; A.at(urow, start_col+ii) /= tmp1; A.at(urow, start_col+jj) /= tmp2; } if(ii < s_n_cols) { A.at(urow, start_col+ii) /= (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { eT* s_col_data = s.colptr(ucol); uword ii,jj; for(ii=0, jj=1; jj < s_n_rows; ii+=2, jj+=2) { const eT val1 = P.at(ii,ucol); const eT val2 = P.at(jj,ucol); s_col_data[ii] /= val1; s_col_data[jj] /= val2; } if(ii < s_n_rows) { s_col_data[ii] /= P.at(ii,ucol); } } } } } template template inline void subview::operator=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "copy into submatrix"); // Clear the subview. zeros(); // Iterate through the sparse subview and set the nonzero values appropriately. typename SpProxy::const_iterator_type cit = p.begin(); while (cit != p.end()) { at(cit.row(), cit.col()) = *cit; ++cit; } } template template inline void subview::operator+=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "addition"); // Iterate through the sparse subview and add its values. typename SpProxy::const_iterator_type cit = p.begin(); while (cit != p.end()) { at(cit.row(), cit.col()) += *cit; ++cit; } } template template inline void subview::operator-=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "subtraction"); // Iterate through the sparse subview and subtract its values. typename SpProxy::const_iterator_type cit = p.begin(); while (cit != p.end()) { at(cit.row(), cit.col()) -= *cit; ++cit; } } template template inline void subview::operator%=(const SpBase& x) { arma_extra_debug_sigprint(); // Temporary sparse matrix to hold the values we need. SpMat tmp = x.get_ref(); arma_debug_assert_same_size(n_rows, n_cols, tmp.n_rows, tmp.n_cols, "element-wise multiplication"); // Iterate over nonzero values. // Any zero values in the sparse expression will result in a zero in our subview. typename SpMat::const_iterator cit = tmp.begin(); while (cit != tmp.end()) { // Set elements before this one to zero. tmp.at(cit.row(), cit.col()) *= at(cit.row(), cit.col()); ++cit; } // Now set the subview equal to that. *this = tmp; } template template inline void subview::operator/=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise division"); // This is probably going to fill your subview with a bunch of NaNs, // so I'm not going to bother to implement it fast. // You can have slow NaNs. They're fine too. for (uword c = 0; c < n_cols; ++c) for (uword r = 0; r < n_rows; ++r) { at(r, c) /= p.at(r, c); } } //! x.submat(...) = y.submat(...) template inline void subview::operator= (const subview& x_in) { arma_extra_debug_sigprint(); const bool overlap = check_overlap(x_in); Mat* tmp_mat = overlap ? new Mat(x_in.m) : 0; const subview* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; const subview& x = overlap ? (*tmp_subview) : x_in; subview& s = *this; arma_debug_assert_same_size(s, x, "copy into submatrix"); const uword s_n_cols = s.n_cols; const uword s_n_rows = s.n_rows; if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(s.m); const Mat& B = x.m; const uword row_A = s.aux_row1; const uword row_B = x.aux_row1; const uword start_col_A = s.aux_col1; const uword start_col_B = x.aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { const eT tmp1 = B.at(row_B, start_col_B + ii); const eT tmp2 = B.at(row_B, start_col_B + jj); A.at(row_A, start_col_A + ii) = tmp1; A.at(row_A, start_col_A + jj) = tmp2; } if(ii < s_n_cols) { A.at(row_A, start_col_A + ii) = B.at(row_B, start_col_B + ii); } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { arrayops::copy( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } } if(overlap) { delete tmp_subview; delete tmp_mat; } } template inline void subview::operator+= (const subview& x_in) { arma_extra_debug_sigprint(); const bool overlap = check_overlap(x_in); Mat* tmp_mat = overlap ? new Mat(x_in.m) : 0; const subview* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; const subview& x = overlap ? (*tmp_subview) : x_in; subview& s = *this; arma_debug_assert_same_size(s, x, "addition"); const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(s.m); const Mat& B = x.m; const uword row_A = s.aux_row1; const uword row_B = x.aux_row1; const uword start_col_A = s.aux_col1; const uword start_col_B = x.aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { const eT tmp1 = B.at(row_B, start_col_B + ii); const eT tmp2 = B.at(row_B, start_col_B + jj); A.at(row_A, start_col_A + ii) += tmp1; A.at(row_A, start_col_A + jj) += tmp2; } if(ii < s_n_cols) { A.at(row_A, start_col_A + ii) += B.at(row_B, start_col_B + ii); } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { arrayops::inplace_plus( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } } if(overlap) { delete tmp_subview; delete tmp_mat; } } template inline void subview::operator-= (const subview& x_in) { arma_extra_debug_sigprint(); const bool overlap = check_overlap(x_in); Mat* tmp_mat = overlap ? new Mat(x_in.m) : 0; const subview* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; const subview& x = overlap ? (*tmp_subview) : x_in; subview& s = *this; arma_debug_assert_same_size(s, x, "subtraction"); const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(s.m); const Mat& B = x.m; const uword row_A = s.aux_row1; const uword row_B = x.aux_row1; const uword start_col_A = s.aux_col1; const uword start_col_B = x.aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { const eT tmp1 = B.at(row_B, start_col_B + ii); const eT tmp2 = B.at(row_B, start_col_B + jj); A.at(row_A, start_col_A + ii) -= tmp1; A.at(row_A, start_col_A + jj) -= tmp2; } if(ii < s_n_cols) { A.at(row_A, start_col_A + ii) -= B.at(row_B, start_col_B + ii); } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { arrayops::inplace_minus( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } } if(overlap) { delete tmp_subview; delete tmp_mat; } } template inline void subview::operator%= (const subview& x_in) { arma_extra_debug_sigprint(); const bool overlap = check_overlap(x_in); Mat* tmp_mat = overlap ? new Mat(x_in.m) : 0; const subview* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; const subview& x = overlap ? (*tmp_subview) : x_in; subview& s = *this; arma_debug_assert_same_size(s, x, "element-wise multiplication"); const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(s.m); const Mat& B = x.m; const uword row_A = s.aux_row1; const uword row_B = x.aux_row1; const uword start_col_A = s.aux_col1; const uword start_col_B = x.aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { const eT tmp1 = B.at(row_B, start_col_B + ii); const eT tmp2 = B.at(row_B, start_col_B + jj); A.at(row_A, start_col_A + ii) *= tmp1; A.at(row_A, start_col_A + jj) *= tmp2; } if(ii < s_n_cols) { A.at(row_A, start_col_A + ii) *= B.at(row_B, start_col_B + ii); } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { arrayops::inplace_mul( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } } if(overlap) { delete tmp_subview; delete tmp_mat; } } template inline void subview::operator/= (const subview& x_in) { arma_extra_debug_sigprint(); const bool overlap = check_overlap(x_in); Mat* tmp_mat = overlap ? new Mat(x_in.m) : 0; const subview* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; const subview& x = overlap ? (*tmp_subview) : x_in; subview& s = *this; arma_debug_assert_same_size(s, x, "element-wise division"); const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(s.m); const Mat& B = x.m; const uword row_A = s.aux_row1; const uword row_B = x.aux_row1; const uword start_col_A = s.aux_col1; const uword start_col_B = x.aux_col1; uword ii,jj; for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) { const eT tmp1 = B.at(row_B, start_col_B + ii); const eT tmp2 = B.at(row_B, start_col_B + jj); A.at(row_A, start_col_A + ii) /= tmp1; A.at(row_A, start_col_A + jj) /= tmp2; } if(ii < s_n_cols) { A.at(row_A, start_col_A + ii) /= B.at(row_B, start_col_B + ii); } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { arrayops::inplace_div( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } } if(overlap) { delete tmp_subview; delete tmp_mat; } } //! transform each element in the subview using a functor template template inline void subview::transform(functor F) { arma_extra_debug_sigprint(); const uword local_n_cols = n_cols; const uword local_n_rows = n_rows; Mat& X = const_cast< Mat& >(m); if(local_n_rows == 1) { const uword urow = aux_row1; const uword start_col = aux_col1; const uword end_col_plus1 = start_col + local_n_cols; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) { X.at(urow, ucol) = eT( F( X.at(urow, ucol) ) ); } } else { const uword start_col = aux_col1; const uword start_row = aux_row1; const uword end_col_plus1 = start_col + local_n_cols; const uword end_row_plus1 = start_row + local_n_rows; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) for(uword urow = start_row; urow < end_row_plus1; ++urow) { X.at(urow, ucol) = eT( F( X.at(urow, ucol) ) ); } } } //! imbue (fill) the subview with values provided by a functor template template inline void subview::imbue(functor F) { arma_extra_debug_sigprint(); const uword local_n_cols = n_cols; const uword local_n_rows = n_rows; Mat& X = const_cast< Mat& >(m); if(local_n_rows == 1) { const uword urow = aux_row1; const uword start_col = aux_col1; const uword end_col_plus1 = start_col + local_n_cols; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) { X.at(urow, ucol) = eT( F() ); } } else { const uword start_col = aux_col1; const uword start_row = aux_row1; const uword end_col_plus1 = start_col + local_n_cols; const uword end_row_plus1 = start_row + local_n_rows; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) for(uword urow = start_row; urow < end_row_plus1; ++urow) { X.at(urow, ucol) = eT( F() ); } } } template inline void subview::fill(const eT val) { arma_extra_debug_sigprint(); const uword local_n_cols = n_cols; const uword local_n_rows = n_rows; if(local_n_rows == 1) { Mat& X = const_cast< Mat& >(m); const uword urow = aux_row1; const uword start_col = aux_col1; const uword end_col_plus1 = start_col + local_n_cols; uword ii,jj; for(ii=start_col, jj=start_col+1; jj < end_col_plus1; ii+=2, jj+=2) { X.at(urow, ii) = val; X.at(urow, jj) = val; } if(ii < end_col_plus1) { X.at(urow, ii) = val; } } else { for(uword ucol=0; ucol < local_n_cols; ++ucol) { arrayops::inplace_set( colptr(ucol), val, local_n_rows ); } } } template inline void subview::zeros() { arma_extra_debug_sigprint(); const uword local_n_cols = n_cols; const uword local_n_rows = n_rows; if(local_n_rows == 1) { (*this).fill(eT(0)); } else { for(uword ucol=0; ucol < local_n_cols; ++ucol) { arrayops::fill_zeros( colptr(ucol), local_n_rows ); } } } template inline void subview::ones() { arma_extra_debug_sigprint(); (*this).fill(eT(1)); } template inline void subview::eye() { arma_extra_debug_sigprint(); (*this).zeros(); const uword N = (std::min)(n_rows, n_cols); for(uword ii=0; ii < N; ++ii) { at(ii,ii) = eT(1); } } template inline void subview::randu() { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; if(local_n_rows == 1) { for(uword ii=0; ii < local_n_cols; ++ii) { at(0,ii) = eT(arma_rng::randu()); } } else { for(uword ii=0; ii < local_n_cols; ++ii) { arma_rng::randu::fill( colptr(ii), local_n_rows ); } } } template inline void subview::randn() { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; if(local_n_rows == 1) { for(uword ii=0; ii < local_n_cols; ++ii) { at(0,ii) = eT(arma_rng::randn()); } } else { for(uword ii=0; ii < local_n_cols; ++ii) { arma_rng::randn::fill( colptr(ii), local_n_rows ); } } } template inline eT subview::at_alt(const uword ii) const { return operator[](ii); } template inline eT& subview::operator[](const uword ii) { const uword in_col = ii / n_rows; const uword in_row = ii % n_rows; const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Mat& >(m)).mem[index] ); } template inline eT subview::operator[](const uword ii) const { const uword in_col = ii / n_rows; const uword in_row = ii % n_rows; const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template inline eT& subview::operator()(const uword ii) { arma_debug_check( (ii >= n_elem), "subview::operator(): index out of bounds"); const uword in_col = ii / n_rows; const uword in_row = ii % n_rows; const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Mat& >(m)).mem[index] ); } template inline eT subview::operator()(const uword ii) const { arma_debug_check( (ii >= n_elem), "subview::operator(): index out of bounds"); const uword in_col = ii / n_rows; const uword in_row = ii % n_rows; const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template inline eT& subview::operator()(const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds"); const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Mat& >(m)).mem[index] ); } template inline eT subview::operator()(const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds"); const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template inline eT& subview::at(const uword in_row, const uword in_col) { const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Mat& >(m)).mem[index] ); } template inline eT subview::at(const uword in_row, const uword in_col) const { const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template arma_inline eT* subview::colptr(const uword in_col) { return & access::rw((const_cast< Mat& >(m)).mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]); } template arma_inline const eT* subview::colptr(const uword in_col) const { return & m.mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]; } template inline bool subview::check_overlap(const subview& x) const { const subview& s = *this; if(&s.m != &x.m) { return false; } else { if( (s.n_elem == 0) || (x.n_elem == 0) ) { return false; } else { const uword s_row_start = s.aux_row1; const uword s_row_end_p1 = s_row_start + s.n_rows; const uword s_col_start = s.aux_col1; const uword s_col_end_p1 = s_col_start + s.n_cols; const uword x_row_start = x.aux_row1; const uword x_row_end_p1 = x_row_start + x.n_rows; const uword x_col_start = x.aux_col1; const uword x_col_end_p1 = x_col_start + x.n_cols; const bool outside_rows = ( (x_row_start >= s_row_end_p1) || (s_row_start >= x_row_end_p1) ); const bool outside_cols = ( (x_col_start >= s_col_end_p1) || (s_col_start >= x_col_end_p1) ); return ( (outside_rows == false) && (outside_cols == false) ); } } } template inline bool subview::is_vec() const { return ( (n_rows == 1) || (n_cols == 1) ); } //! X = Y.submat(...) template inline void subview::extract(Mat& out, const subview& in) { arma_extra_debug_sigprint(); // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const uword n_rows = in.n_rows; // number of rows in the subview const uword n_cols = in.n_cols; // number of columns in the subview arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols = %d in.m.n_rows = %d in.m.n_cols = %d") % out.n_rows % out.n_cols % in.m.n_rows % in.m.n_cols ); if(in.is_vec() == true) { if(n_cols == 1) // a column vector { arma_extra_debug_print("subview::extract(): copying col (going across rows)"); // in.colptr(0) the first column of the subview, taking into account any row offset arrayops::copy( out.memptr(), in.colptr(0), n_rows ); } else // a row vector (possibly empty) { arma_extra_debug_print("subview::extract(): copying row (going across columns)"); const Mat& X = in.m; eT* out_mem = out.memptr(); const uword row = in.aux_row1; const uword start_col = in.aux_col1; uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp1 = X.at(row, start_col+i); const eT tmp2 = X.at(row, start_col+j); out_mem[i] = tmp1; out_mem[j] = tmp2; } if(i < n_cols) { out_mem[i] = X.at(row, start_col+i); } } } else // general submatrix { arma_extra_debug_print("subview::extract(): general submatrix"); for(uword col=0; col < n_cols; ++col) { arrayops::copy( out.colptr(col), in.colptr(col), n_rows ); } } } //! X += Y.submat(...) template inline void subview::plus_inplace(Mat& out, const subview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "addition"); const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows == 1) { eT* out_mem = out.memptr(); const Mat& X = in.m; const uword row = in.aux_row1; const uword start_col = in.aux_col1; uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp1 = X.at(row, start_col+i); const eT tmp2 = X.at(row, start_col+j); out_mem[i] += tmp1; out_mem[j] += tmp2; } if(i < n_cols) { out_mem[i] += X.at(row, start_col+i); } } else { for(uword col=0; col < n_cols; ++col) { arrayops::inplace_plus(out.colptr(col), in.colptr(col), n_rows); } } } //! X -= Y.submat(...) template inline void subview::minus_inplace(Mat& out, const subview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "subtraction"); const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows == 1) { eT* out_mem = out.memptr(); const Mat& X = in.m; const uword row = in.aux_row1; const uword start_col = in.aux_col1; uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp1 = X.at(row, start_col+i); const eT tmp2 = X.at(row, start_col+j); out_mem[i] -= tmp1; out_mem[j] -= tmp2; } if(i < n_cols) { out_mem[i] -= X.at(row, start_col+i); } } else { for(uword col=0; col < n_cols; ++col) { arrayops::inplace_minus(out.colptr(col), in.colptr(col), n_rows); } } } //! X %= Y.submat(...) template inline void subview::schur_inplace(Mat& out, const subview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "element-wise multiplication"); const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows == 1) { eT* out_mem = out.memptr(); const Mat& X = in.m; const uword row = in.aux_row1; const uword start_col = in.aux_col1; uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp1 = X.at(row, start_col+i); const eT tmp2 = X.at(row, start_col+j); out_mem[i] *= tmp1; out_mem[j] *= tmp2; } if(i < n_cols) { out_mem[i] *= X.at(row, start_col+i); } } else { for(uword col=0; col < n_cols; ++col) { arrayops::inplace_mul(out.colptr(col), in.colptr(col), n_rows); } } } //! X /= Y.submat(...) template inline void subview::div_inplace(Mat& out, const subview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "element-wise division"); const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows == 1) { eT* out_mem = out.memptr(); const Mat& X = in.m; const uword row = in.aux_row1; const uword start_col = in.aux_col1; uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp1 = X.at(row, start_col+i); const eT tmp2 = X.at(row, start_col+j); out_mem[i] /= tmp1; out_mem[j] /= tmp2; } if(i < n_cols) { out_mem[i] /= X.at(row, start_col+i); } } else { for(uword col=0; col < n_cols; ++col) { arrayops::inplace_div(out.colptr(col), in.colptr(col), n_rows); } } } //! creation of subview (row vector) template inline subview_row subview::row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( row_num >= n_rows, "subview::row(): out of bounds" ); const uword base_row = aux_row1 + row_num; return subview_row(m, base_row, aux_col1, n_cols); } //! creation of subview (row vector) template inline const subview_row subview::row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( row_num >= n_rows, "subview::row(): out of bounds" ); const uword base_row = aux_row1 + row_num; return subview_row(m, base_row, aux_col1, n_cols); } template inline subview_row subview::operator()(const uword row_num, const span& col_span) { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; const uword base_col1 = aux_col1 + in_col1; const uword base_row = aux_row1 + row_num; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "subview::operator(): indices out of bounds or incorrectly used" ); return subview_row(m, base_row, base_col1, submat_n_cols); } template inline const subview_row subview::operator()(const uword row_num, const span& col_span) const { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; const uword base_col1 = aux_col1 + in_col1; const uword base_row = aux_row1 + row_num; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "subview::operator(): indices out of bounds or incorrectly used" ); return subview_row(m, base_row, base_col1, submat_n_cols); } //! creation of subview (column vector) template inline subview_col subview::col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "subview::col(): out of bounds"); const uword base_col = aux_col1 + col_num; return subview_col(m, base_col, aux_row1, n_rows); } //! creation of subview (column vector) template inline const subview_col subview::col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "subview::col(): out of bounds"); const uword base_col = aux_col1 + col_num; return subview_col(m, base_col, aux_row1, n_rows); } template inline subview_col subview::operator()(const span& row_span, const uword col_num) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword base_row1 = aux_row1 + in_row1; const uword base_col = aux_col1 + col_num; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "subview::operator(): indices out of bounds or incorrectly used" ); return subview_col(m, base_col, base_row1, submat_n_rows); } template inline const subview_col subview::operator()(const span& row_span, const uword col_num) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword base_row1 = aux_row1 + in_row1; const uword base_col = aux_col1 + col_num; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "subview::operator(): indices out of bounds or incorrectly used" ); return subview_col(m, base_col, base_row1, submat_n_rows); } //! create a Col object which uses memory from an existing matrix object. //! this approach is currently not alias safe //! and does not take into account that the parent matrix object could be deleted. //! if deleted memory is accessed by the created Col object, //! it will cause memory corruption and/or a crash template inline Col subview::unsafe_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "subview::unsafe_col(): out of bounds"); return Col(colptr(col_num), n_rows, false, true); } //! create a Col object which uses memory from an existing matrix object. //! this approach is currently not alias safe //! and does not take into account that the parent matrix object could be deleted. //! if deleted memory is accessed by the created Col object, //! it will cause memory corruption and/or a crash template inline const Col subview::unsafe_col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "subview::unsafe_col(): out of bounds"); return Col(const_cast(colptr(col_num)), n_rows, false, true); } //! creation of subview (submatrix comprised of specified row vectors) template inline subview subview::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "subview::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = aux_row1 + in_row1; return subview(m, base_row1, aux_col1, subview_n_rows, n_cols ); } //! creation of subview (submatrix comprised of specified row vectors) template inline const subview subview::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "subview::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = aux_row1 + in_row1; return subview(m, base_row1, aux_col1, subview_n_rows, n_cols ); } //! creation of subview (submatrix comprised of specified column vectors) template inline subview subview::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "subview::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = aux_col1 + in_col1; return subview(m, aux_row1, base_col1, n_rows, subview_n_cols); } //! creation of subview (submatrix comprised of specified column vectors) template inline const subview subview::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "subview::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = aux_col1 + in_col1; return subview(m, aux_row1, base_col1, n_rows, subview_n_cols); } //! creation of subview (submatrix) template inline subview subview::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "subview::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_row1 = aux_row1 + in_row1; const uword base_col1 = aux_col1 + in_col1; return subview(m, base_row1, base_col1, subview_n_rows, subview_n_cols); } //! creation of subview (generic submatrix) template inline const subview subview::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "subview::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_row1 = aux_row1 + in_row1; const uword base_col1 = aux_col1 + in_col1; return subview(m, base_row1, base_col1, subview_n_rows, subview_n_cols); } //! creation of subview (submatrix) template inline subview subview::submat(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "subview::submat(): indices out of bounds or incorrectly used" ); const uword base_row1 = aux_row1 + in_row1; const uword base_col1 = aux_col1 + in_col1; return subview(m, base_row1, base_col1, submat_n_rows, submat_n_cols); } //! creation of subview (generic submatrix) template inline const subview subview::submat(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "subview::submat(): indices out of bounds or incorrectly used" ); const uword base_row1 = aux_row1 + in_row1; const uword base_col1 = aux_col1 + in_col1; return subview(m, base_row1, base_col1, submat_n_rows, submat_n_cols); } template inline subview subview::operator()(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); return (*this).submat(row_span, col_span); } template inline const subview subview::operator()(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); return (*this).submat(row_span, col_span); } template inline subview_each1< subview, 0 > subview::each_col() { arma_extra_debug_sigprint(); return subview_each1< subview, 0 >(*this); } template inline subview_each1< subview, 1 > subview::each_row() { arma_extra_debug_sigprint(); return subview_each1< subview, 1 >(*this); } template template inline subview_each2< subview, 0, T1 > subview::each_col(const Base& indices) { arma_extra_debug_sigprint(); return subview_each2< subview, 0, T1 >(*this, indices); } template template inline subview_each2< subview, 1, T1 > subview::each_row(const Base& indices) { arma_extra_debug_sigprint(); return subview_each2< subview, 1, T1 >(*this, indices); } //! creation of diagview (diagonal) template inline diagview subview::diag(const sword in_id) { arma_extra_debug_sigprint(); const uword row_offset = (in_id < 0) ? uword(-in_id) : 0; const uword col_offset = (in_id > 0) ? uword( in_id) : 0; arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "subview::diag(): requested diagonal out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); const uword base_row_offset = aux_row1 + row_offset; const uword base_col_offset = aux_col1 + col_offset; return diagview(m, base_row_offset, base_col_offset, len); } //! creation of diagview (diagonal) template inline const diagview subview::diag(const sword in_id) const { arma_extra_debug_sigprint(); const uword row_offset = (in_id < 0) ? -in_id : 0; const uword col_offset = (in_id > 0) ? in_id : 0; arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "subview::diag(): requested diagonal out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); const uword base_row_offset = aux_row1 + row_offset; const uword base_col_offset = aux_col1 + col_offset; return diagview(m, base_row_offset, base_col_offset, len); } template inline void subview::swap_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 >= n_rows) || (in_row2 >= n_rows), "subview::swap_rows(): out of bounds" ); eT* mem = (const_cast< Mat& >(m)).memptr(); if(n_elem > 0) { const uword m_n_rows = m.n_rows; for(uword ucol=0; ucol < n_cols; ++ucol) { const uword offset = (aux_col1 + ucol) * m_n_rows; const uword pos1 = aux_row1 + in_row1 + offset; const uword pos2 = aux_row1 + in_row2 + offset; std::swap( access::rw(mem[pos1]), access::rw(mem[pos2]) ); } } } template inline void subview::swap_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 >= n_cols) || (in_col2 >= n_cols), "subview::swap_cols(): out of bounds" ); if(n_elem > 0) { eT* ptr1 = colptr(in_col1); eT* ptr2 = colptr(in_col2); for(uword urow=0; urow < n_rows; ++urow) { std::swap( ptr1[urow], ptr2[urow] ); } } } // template // inline // subview::iter::iter(const subview& S) // : mem (S.m.mem) // , n_rows (S.m.n_rows) // , row_start (S.aux_row1) // , row_end_p1(row_start + S.n_rows) // , row (row_start) // , col (S.aux_col1) // , i (row + col*n_rows) // { // arma_extra_debug_sigprint(); // } // // // // template // arma_inline // eT // subview::iter::operator*() const // { // return mem[i]; // } // // // // template // inline // void // subview::iter::operator++() // { // ++row; // // if(row < row_end_p1) // { // ++i; // } // else // { // row = row_start; // ++col; // // i = row + col*n_rows; // } // } // // // // template // inline // void // subview::iter::operator++(int) // { // operator++(); // } // // // template inline subview_col::subview_col(const Mat& in_m, const uword in_col) : subview(in_m, 0, in_col, in_m.n_rows, 1) , colmem(subview::colptr(0)) { arma_extra_debug_sigprint(); } template inline subview_col::subview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows) : subview(in_m, in_row1, in_col, in_n_rows, 1) , colmem(subview::colptr(0)) { arma_extra_debug_sigprint(); } template inline void subview_col::operator=(const subview& X) { arma_extra_debug_sigprint(); subview::operator=(X); } template inline void subview_col::operator=(const subview_col& X) { arma_extra_debug_sigprint(); subview::operator=(X); // interprets 'subview_col' as 'subview' } template inline void subview_col::operator=(const eT val) { arma_extra_debug_sigprint(); if(subview::n_elem != 1) { arma_debug_assert_same_size(subview::n_rows, subview::n_cols, 1, 1, "copy into submatrix"); } access::rw( colmem[0] ) = val; } template template inline void subview_col::operator=(const Base& X) { arma_extra_debug_sigprint(); subview::operator=(X); } template arma_inline const Op,op_htrans> subview_col::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> subview_col::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> subview_col::st() const { return Op,op_strans>(*this); } template inline void subview_col::fill(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_set( access::rwp(colmem), val, subview::n_rows ); } template inline void subview_col::zeros() { arma_extra_debug_sigprint(); arrayops::fill_zeros( access::rwp(colmem), subview::n_rows ); } template inline void subview_col::ones() { arma_extra_debug_sigprint(); arrayops::inplace_set( access::rwp(colmem), eT(1), subview::n_rows ); } template arma_inline eT subview_col::at_alt(const uword ii) const { const eT* colmem_aligned = colmem; memory::mark_as_aligned(colmem_aligned); return colmem_aligned[ii]; } template arma_inline eT& subview_col::operator[](const uword ii) { return access::rw( colmem[ii] ); } template arma_inline eT subview_col::operator[](const uword ii) const { return colmem[ii]; } template inline eT& subview_col::operator()(const uword ii) { arma_debug_check( (ii >= subview::n_elem), "subview::operator(): index out of bounds"); return access::rw( colmem[ii] ); } template inline eT subview_col::operator()(const uword ii) const { arma_debug_check( (ii >= subview::n_elem), "subview::operator(): index out of bounds"); return colmem[ii]; } template inline eT& subview_col::operator()(const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= subview::n_rows) || (in_col > 0)), "subview::operator(): index out of bounds"); return access::rw( colmem[in_row] ); } template inline eT subview_col::operator()(const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= subview::n_rows) || (in_col > 0)), "subview::operator(): index out of bounds"); return colmem[in_row]; } template inline eT& subview_col::at(const uword in_row, const uword) { return access::rw( colmem[in_row] ); } template inline eT subview_col::at(const uword in_row, const uword) const { return colmem[in_row]; } template arma_inline eT* subview_col::colptr(const uword) { return const_cast(colmem); } template arma_inline const eT* subview_col::colptr(const uword) const { return colmem; } template inline subview_col subview_col::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::rows(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = this->aux_row1 + in_row1; return subview_col(this->m, this->aux_col1, base_row1, subview_n_rows); } template inline const subview_col subview_col::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::rows(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = this->aux_row1 + in_row1; return subview_col(this->m, this->aux_col1, base_row1, subview_n_rows); } template inline subview_col subview_col::subvec(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = this->aux_row1 + in_row1; return subview_col(this->m, this->aux_col1, base_row1, subview_n_rows); } template inline const subview_col subview_col::subvec(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = this->aux_row1 + in_row1; return subview_col(this->m, this->aux_col1, base_row1, subview_n_rows); } // // // template inline subview_row::subview_row(const Mat& in_m, const uword in_row) : subview(in_m, in_row, 0, 1, in_m.n_cols) { arma_extra_debug_sigprint(); } template inline subview_row::subview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols) : subview(in_m, in_row, in_col1, 1, in_n_cols) { arma_extra_debug_sigprint(); } template inline void subview_row::operator=(const subview& X) { arma_extra_debug_sigprint(); subview::operator=(X); } template inline void subview_row::operator=(const subview_row& X) { arma_extra_debug_sigprint(); subview::operator=(X); // interprets 'subview_row' as 'subview' } template inline void subview_row::operator=(const eT val) { arma_extra_debug_sigprint(); subview::operator=(val); // interprets 'subview_row' as 'subview' } template template inline void subview_row::operator=(const Base& X) { arma_extra_debug_sigprint(); subview::operator=(X); } template arma_inline const Op,op_htrans> subview_row::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> subview_row::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> subview_row::st() const { return Op,op_strans>(*this); } template inline eT subview_row::at_alt(const uword ii) const { const uword index = (ii + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return subview::m.mem[index]; } template inline eT& subview_row::operator[](const uword ii) { const uword index = (ii + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return access::rw( (const_cast< Mat& >(subview::m)).mem[index] ); } template inline eT subview_row::operator[](const uword ii) const { const uword index = (ii + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return subview::m.mem[index]; } template inline eT& subview_row::operator()(const uword ii) { arma_debug_check( (ii >= subview::n_elem), "subview::operator(): index out of bounds"); const uword index = (ii + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return access::rw( (const_cast< Mat& >(subview::m)).mem[index] ); } template inline eT subview_row::operator()(const uword ii) const { arma_debug_check( (ii >= subview::n_elem), "subview::operator(): index out of bounds"); const uword index = (ii + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return subview::m.mem[index]; } template inline eT& subview_row::operator()(const uword in_row, const uword in_col) { arma_debug_check( ((in_row > 0) || (in_col >= subview::n_cols)), "subview::operator(): index out of bounds"); const uword index = (in_col + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return access::rw( (const_cast< Mat& >(subview::m)).mem[index] ); } template inline eT subview_row::operator()(const uword in_row, const uword in_col) const { arma_debug_check( ((in_row > 0) || (in_col >= subview::n_cols)), "subview::operator(): index out of bounds"); const uword index = (in_col + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return subview::m.mem[index]; } template inline eT& subview_row::at(const uword, const uword in_col) { const uword index = (in_col + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return access::rw( (const_cast< Mat& >(subview::m)).mem[index] ); } template inline eT subview_row::at(const uword, const uword in_col) const { const uword index = (in_col + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return subview::m.mem[index]; } template inline subview_row subview_row::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = this->aux_col1 + in_col1; return subview_row(this->m, this->aux_row1, base_col1, subview_n_cols); } template inline const subview_row subview_row::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::cols(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = this->aux_col1 + in_col1; return subview_row(this->m, this->aux_row1, base_col1, subview_n_cols); } template inline subview_row subview_row::subvec(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = this->aux_col1 + in_col1; return subview_row(this->m, this->aux_row1, base_col1, subview_n_cols); } template inline const subview_row subview_row::subvec(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = this->aux_col1 + in_col1; return subview_row(this->m, this->aux_row1, base_col1, subview_n_cols); } // // // template inline subview_row_strans::subview_row_strans(const subview_row& in_sv_row) : sv_row(in_sv_row ) , n_rows(in_sv_row.n_cols) , n_elem(in_sv_row.n_elem) { arma_extra_debug_sigprint(); } template inline void subview_row_strans::extract(Mat& out) const { arma_extra_debug_sigprint(); // NOTE: this function assumes that matrix 'out' has already been set to the correct size const Mat& X = sv_row.m; eT* out_mem = out.memptr(); const uword row = sv_row.aux_row1; const uword start_col = sv_row.aux_col1; const uword sv_row_n_cols = sv_row.n_cols; uword ii,jj; for(ii=0, jj=1; jj < sv_row_n_cols; ii+=2, jj+=2) { const eT tmp1 = X.at(row, start_col+ii); const eT tmp2 = X.at(row, start_col+jj); out_mem[ii] = tmp1; out_mem[jj] = tmp2; } if(ii < sv_row_n_cols) { out_mem[ii] = X.at(row, start_col+ii); } } template inline eT subview_row_strans::at_alt(const uword ii) const { return sv_row[ii]; } template inline eT subview_row_strans::operator[](const uword ii) const { return sv_row[ii]; } template inline eT subview_row_strans::operator()(const uword ii) const { return sv_row(ii); } template inline eT subview_row_strans::operator()(const uword in_row, const uword in_col) const { return sv_row(in_col, in_row); // deliberately swapped } template inline eT subview_row_strans::at(const uword in_row, const uword) const { return sv_row.at(0, in_row); // deliberately swapped } // // // template inline subview_row_htrans::subview_row_htrans(const subview_row& in_sv_row) : sv_row(in_sv_row ) , n_rows(in_sv_row.n_cols) , n_elem(in_sv_row.n_elem) { arma_extra_debug_sigprint(); } template inline void subview_row_htrans::extract(Mat& out) const { arma_extra_debug_sigprint(); // NOTE: this function assumes that matrix 'out' has already been set to the correct size const Mat& X = sv_row.m; eT* out_mem = out.memptr(); const uword row = sv_row.aux_row1; const uword start_col = sv_row.aux_col1; const uword sv_row_n_cols = sv_row.n_cols; for(uword ii=0; ii < sv_row_n_cols; ++ii) { out_mem[ii] = access::alt_conj( X.at(row, start_col+ii) ); } } template inline eT subview_row_htrans::at_alt(const uword ii) const { return access::alt_conj( sv_row[ii] ); } template inline eT subview_row_htrans::operator[](const uword ii) const { return access::alt_conj( sv_row[ii] ); } template inline eT subview_row_htrans::operator()(const uword ii) const { return access::alt_conj( sv_row(ii) ); } template inline eT subview_row_htrans::operator()(const uword in_row, const uword in_col) const { return access::alt_conj( sv_row(in_col, in_row) ); // deliberately swapped } template inline eT subview_row_htrans::at(const uword in_row, const uword) const { return access::alt_conj( sv_row.at(0, in_row) ); // deliberately swapped } //! @} RcppArmadillo/inst/include/armadillo_bits/mtOpCube_meat.hpp0000644000176000001440000000357512202101406023653 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup mtOpCube //! @{ template inline mtOpCube::mtOpCube(const T1& in_m) : m(in_m) { arma_extra_debug_sigprint(); } template inline mtOpCube::mtOpCube(const T1& in_m, const typename T1::elem_type in_aux) : m(in_m) , aux(in_aux) { arma_extra_debug_sigprint(); } template inline mtOpCube::mtOpCube(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) { arma_extra_debug_sigprint(); } template inline mtOpCube::mtOpCube(const T1& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : m(in_m) , aux(in_aux) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) { arma_extra_debug_sigprint(); } template inline mtOpCube::mtOpCube(const char junk, const T1& in_m, const out_eT in_aux) : m(in_m) , aux_out_eT(in_aux) { arma_extra_debug_sigprint(); arma_ignore(junk); } template inline mtOpCube::~mtOpCube() { arma_extra_debug_sigprint(); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_mean_meat.hpp0000644000176000001440000001616312200631217023556 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_mean //! @{ //! \brief //! For each row or for each column, find the mean value. //! The result is stored in a dense matrix that has either one column or one row. //! The dimension, for which the means are found, is set via the mean() function. template inline void op_mean::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "mean(): incorrect usage. dim must be 0 or 1"); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_mean::apply(), dim = 0"); out.set_size( (X_n_rows > 0) ? 1 : 0, X_n_cols ); if(X_n_rows > 0) { eT* out_mem = out.memptr(); for(uword col=0; col < X_n_cols; ++col) { out_mem[col] = op_mean::direct_mean( X.colptr(col), X_n_rows ); } } } else if(dim == 1) { arma_extra_debug_print("op_mean::apply(), dim = 1"); out.set_size(X_n_rows, (X_n_cols > 0) ? 1 : 0); if(X_n_cols > 0) { eT* out_mem = out.memptr(); for(uword row=0; row < X_n_rows; ++row) { out_mem[row] = op_mean::direct_mean( X, row ); } } } } template arma_pure inline eT op_mean::direct_mean(const eT* const X, const uword n_elem) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const eT result = arrayops::accumulate(X, n_elem) / T(n_elem); return arma_isfinite(result) ? result : op_mean::direct_mean_robust(X, n_elem); } template arma_pure inline eT op_mean::direct_mean_robust(const eT* const X, const uword n_elem) { arma_extra_debug_sigprint(); // use an adapted form of the mean finding algorithm from the running_stat class typedef typename get_pod_type::result T; uword i,j; eT r_mean = eT(0); for(i=0, j=1; j inline eT op_mean::direct_mean(const Mat& X, const uword row) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_cols = X.n_cols; eT val = eT(0); uword i,j; for(i=0, j=1; j < X_n_cols; i+=2, j+=2) { val += X.at(row,i); val += X.at(row,j); } if(i < X_n_cols) { val += X.at(row,i); } const eT result = val / T(X_n_cols); return arma_isfinite(result) ? result : op_mean::direct_mean_robust(X, row); } template inline eT op_mean::direct_mean_robust(const Mat& X, const uword row) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_cols = X.n_cols; eT r_mean = eT(0); for(uword col=0; col < X_n_cols; ++col) { r_mean = r_mean + (X.at(row,col) - r_mean)/T(col+1); } return r_mean; } template inline eT op_mean::mean_all(const subview& X) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword X_n_elem = X.n_elem; arma_debug_check( (X_n_elem == 0), "mean(): given object has no elements" ); eT val = eT(0); if(X_n_rows == 1) { const Mat& A = X.m; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_col_p1 = start_col + X_n_cols; uword i,j; for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2) { val += A.at(start_row, i); val += A.at(start_row, j); } if(i < end_col_p1) { val += A.at(start_row, i); } } else { for(uword col=0; col < X_n_cols; ++col) { val += arrayops::accumulate(X.colptr(col), X_n_rows); } } const eT result = val / T(X_n_elem); return arma_isfinite(result) ? result : op_mean::mean_all_robust(X); } template inline eT op_mean::mean_all_robust(const subview& X) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_row_p1 = start_row + X_n_rows; const uword end_col_p1 = start_col + X_n_cols; const Mat& A = X.m; eT r_mean = eT(0); if(X_n_rows == 1) { uword i=0; for(uword col = start_col; col < end_col_p1; ++col, ++i) { r_mean = r_mean + (A.at(start_row,col) - r_mean)/T(i+1); } } else { uword i=0; for(uword col = start_col; col < end_col_p1; ++col) for(uword row = start_row; row < end_row_p1; ++row, ++i) { r_mean = r_mean + (A.at(row,col) - r_mean)/T(i+1); } } return r_mean; } template inline eT op_mean::mean_all(const diagview& X) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_elem = X.n_elem; arma_debug_check( (X_n_elem == 0), "mean(): given object has no elements" ); eT val = eT(0); for(uword i=0; i inline eT op_mean::mean_all_robust(const diagview& X) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_elem = X.n_elem; eT r_mean = eT(0); for(uword i=0; i inline typename T1::elem_type op_mean::mean_all(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; const uword A_n_elem = A.n_elem; arma_debug_check( (A_n_elem == 0), "mean(): given object has no elements" ); return op_mean::direct_mean(A.memptr(), A_n_elem); } template arma_inline eT op_mean::robust_mean(const eT A, const eT B) { return A + (B - A)/eT(2); } template arma_inline std::complex op_mean::robust_mean(const std::complex& A, const std::complex& B) { return A + (B - A)/T(2); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_median_meat.hpp0000644000176000001440000002347312200631217024075 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // Copyright (C) 2013 Ruslan Shestopalyuk // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_median //! @{ //! \brief //! For each row or for each column, find the median value. //! The result is stored in a dense matrix that has either one column or one row. //! The dimension, for which the medians are found, is set via the median() function. template inline void op_median::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "median(): incorrect usage. dim must be 0 or 1"); const Proxy P(in.m); typedef typename Proxy::stored_type P_stored_type; const bool is_alias = P.is_alias(out); if( (is_Mat::value == true) || is_alias ) { const unwrap_check tmp(P.Q, is_alias); const typename unwrap_check::stored_type& X = tmp.M; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) // in each column { arma_extra_debug_print("op_median::apply(), dim = 0"); arma_debug_check( (X_n_rows == 0), "median(): given object has zero rows" ); out.set_size(1, X_n_cols); std::vector tmp_vec(X_n_rows); for(uword col=0; col < X_n_cols; ++col) { arrayops::copy( &(tmp_vec[0]), X.colptr(col), X_n_rows ); out[col] = op_median::direct_median(tmp_vec); } } else // in each row { arma_extra_debug_print("op_median::apply(), dim = 1"); arma_debug_check( (X_n_cols == 0), "median(): given object has zero columns" ); out.set_size(X_n_rows, 1); std::vector tmp_vec(X_n_cols); for(uword row=0; row < X_n_rows; ++row) { for(uword col=0; col < X_n_cols; ++col) { tmp_vec[col] = X.at(row,col); } out[row] = op_median::direct_median(tmp_vec); } } } else { const uword P_n_rows = P.get_n_rows(); const uword P_n_cols = P.get_n_cols(); if(dim == 0) // in each column { arma_extra_debug_print("op_median::apply(), dim = 0"); arma_debug_check( (P_n_rows == 0), "median(): given object has zero rows" ); out.set_size(1, P_n_cols); std::vector tmp_vec(P_n_rows); for(uword col=0; col < P_n_cols; ++col) { for(uword row=0; row < P_n_rows; ++row) { tmp_vec[row] = P.at(row,col); } out[col] = op_median::direct_median(tmp_vec); } } else // in each row { arma_extra_debug_print("op_median::apply(), dim = 1"); arma_debug_check( (P_n_cols == 0), "median(): given object has zero columns" ); out.set_size(P_n_rows, 1); std::vector tmp_vec(P_n_cols); for(uword row=0; row < P_n_rows; ++row) { for(uword col=0; col < P_n_cols; ++col) { tmp_vec[col] = P.at(row,col); } out[row] = op_median::direct_median(tmp_vec); } } } } //! Implementation for complex numbers template inline void op_median::apply(Mat< std::complex >& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename std::complex eT; arma_type_check(( is_same_type::no )); const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "median(): incorrect usage. dim must be 0 or 1"); if(dim == 0) // in each column { arma_extra_debug_print("op_median::apply(), dim = 0"); arma_debug_check( (X_n_rows == 0), "median(): given object has zero rows" ); out.set_size(1, X_n_cols); std::vector< arma_cx_median_packet > tmp_vec(X_n_rows); for(uword col=0; col > tmp_vec(X_n_cols); for(uword row=0; row inline typename T1::elem_type op_median::median_vec ( const T1& X, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename Proxy::stored_type P_stored_type; const Proxy P(X); const uword n_elem = P.get_n_elem(); arma_debug_check( (n_elem == 0), "median(): given object has no elements" ); std::vector tmp_vec(n_elem); if(is_Mat::value == true) { const unwrap tmp(P.Q); const typename unwrap_check::stored_type& Y = tmp.M; arrayops::copy( &(tmp_vec[0]), Y.memptr(), n_elem ); } else { if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); for(uword i=0; i inline typename T1::elem_type op_median::median_vec ( const T1& X, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; const Proxy P(X); const uword n_elem = P.get_n_elem(); arma_debug_check( (n_elem == 0), "median(): given object has no elements" ); std::vector< arma_cx_median_packet > tmp_vec(n_elem); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); for(uword i=0; i inline eT op_median::direct_median(std::vector& X) { arma_extra_debug_sigprint(); const uword n_elem = uword(X.size()); const uword half = n_elem/2; std::nth_element(X.begin(), X.begin() + half, X.end()); if((n_elem % 2) == 0) { return op_mean::robust_mean(*(std::max_element(X.begin(), X.begin() + half)), X[half]); } else { return X[half]; } } template inline void op_median::direct_cx_median_index ( uword& out_index1, uword& out_index2, std::vector< arma_cx_median_packet >& X ) { arma_extra_debug_sigprint(); const uword n_elem = uword(X.size()); const uword half = n_elem/2; std::nth_element(X.begin(), X.begin() + half, X.end()); if((n_elem % 2) == 0) { out_index1 = std::max_element(X.begin(), X.begin() + half)->index; out_index2 = X[half].index; } else { out_index1 = X[half].index; out_index2 = out_index1; } } //! @} RcppArmadillo/inst/include/armadillo_bits/mul_gemv.hpp0000644000176000001440000003301412222720570022744 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup gemv //! @{ //! for tiny square matrices, size <= 4x4 template class gemv_emul_tinysq { public: template struct pos { static const uword n2 = (do_trans_A == false) ? (row + col*2) : (col + row*2); static const uword n3 = (do_trans_A == false) ? (row + col*3) : (col + row*3); static const uword n4 = (do_trans_A == false) ? (row + col*4) : (col + row*4); }; template arma_hot arma_inline static void assign(eT* y, const eT acc, const eT alpha, const eT beta) { if(use_beta == false) { y[i] = (use_alpha == false) ? acc : alpha*acc; } else { const eT tmp = y[i]; y[i] = beta*tmp + ( (use_alpha == false) ? acc : alpha*acc ); } } template arma_hot inline static void apply( eT* y, const TA& A, const eT* x, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); const eT* Am = A.memptr(); switch(A.n_rows) { case 1: { const eT acc = Am[0] * x[0]; assign(y, acc, alpha, beta); } break; case 2: { const eT x0 = x[0]; const eT x1 = x[1]; const eT acc0 = Am[pos<0,0>::n2]*x0 + Am[pos<0,1>::n2]*x1; const eT acc1 = Am[pos<1,0>::n2]*x0 + Am[pos<1,1>::n2]*x1; assign(y, acc0, alpha, beta); assign(y, acc1, alpha, beta); } break; case 3: { const eT x0 = x[0]; const eT x1 = x[1]; const eT x2 = x[2]; const eT acc0 = Am[pos<0,0>::n3]*x0 + Am[pos<0,1>::n3]*x1 + Am[pos<0,2>::n3]*x2; const eT acc1 = Am[pos<1,0>::n3]*x0 + Am[pos<1,1>::n3]*x1 + Am[pos<1,2>::n3]*x2; const eT acc2 = Am[pos<2,0>::n3]*x0 + Am[pos<2,1>::n3]*x1 + Am[pos<2,2>::n3]*x2; assign(y, acc0, alpha, beta); assign(y, acc1, alpha, beta); assign(y, acc2, alpha, beta); } break; case 4: { const eT x0 = x[0]; const eT x1 = x[1]; const eT x2 = x[2]; const eT x3 = x[3]; const eT acc0 = Am[pos<0,0>::n4]*x0 + Am[pos<0,1>::n4]*x1 + Am[pos<0,2>::n4]*x2 + Am[pos<0,3>::n4]*x3; const eT acc1 = Am[pos<1,0>::n4]*x0 + Am[pos<1,1>::n4]*x1 + Am[pos<1,2>::n4]*x2 + Am[pos<1,3>::n4]*x3; const eT acc2 = Am[pos<2,0>::n4]*x0 + Am[pos<2,1>::n4]*x1 + Am[pos<2,2>::n4]*x2 + Am[pos<2,3>::n4]*x3; const eT acc3 = Am[pos<3,0>::n4]*x0 + Am[pos<3,1>::n4]*x1 + Am[pos<3,2>::n4]*x2 + Am[pos<3,3>::n4]*x3; assign(y, acc0, alpha, beta); assign(y, acc1, alpha, beta); assign(y, acc2, alpha, beta); assign(y, acc3, alpha, beta); } break; default: ; } } }; class gemv_emul_large_helper { public: template arma_hot inline static typename arma_not_cx::result dot_row_col( const TA& A, const eT* x, const uword row, const uword N ) { eT acc1 = eT(0); eT acc2 = eT(0); uword i,j; for(i=0, j=1; j < N; i+=2, j+=2) { const eT xi = x[i]; const eT xj = x[j]; acc1 += A.at(row,i) * xi; acc2 += A.at(row,j) * xj; } if(i < N) { acc1 += A.at(row,i) * x[i]; } return (acc1 + acc2); } template arma_hot inline static typename arma_cx_only::result dot_row_col( const TA& A, const eT* x, const uword row, const uword N ) { typedef typename get_pod_type::result T; T val_real = T(0); T val_imag = T(0); for(uword i=0; i& Ai = A.at(row,i); const std::complex& xi = x[i]; const T a = Ai.real(); const T b = Ai.imag(); const T c = xi.real(); const T d = xi.imag(); val_real += (a*c) - (b*d); val_imag += (a*d) + (b*c); } return std::complex(val_real, val_imag); } }; //! \brief //! Partial emulation of ATLAS/BLAS gemv(). //! 'y' is assumed to have been set to the correct size (i.e. taking into account the transpose) template class gemv_emul_large { public: template arma_hot inline static void apply( eT* y, const TA& A, const eT* x, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; if(do_trans_A == false) { if(A_n_rows == 1) { const eT acc = op_dot::direct_dot_arma(A_n_cols, A.memptr(), x); if( (use_alpha == false) && (use_beta == false) ) { y[0] = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { y[0] = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { y[0] = acc + beta*y[0]; } else if( (use_alpha == true ) && (use_beta == true ) ) { y[0] = alpha*acc + beta*y[0]; } } else for(uword row=0; row < A_n_rows; ++row) { const eT acc = gemv_emul_large_helper::dot_row_col(A, x, row, A_n_cols); if( (use_alpha == false) && (use_beta == false) ) { y[row] = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { y[row] = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { y[row] = acc + beta*y[row]; } else if( (use_alpha == true ) && (use_beta == true ) ) { y[row] = alpha*acc + beta*y[row]; } } } else if(do_trans_A == true) { for(uword col=0; col < A_n_cols; ++col) { // col is interpreted as row when storing the results in 'y' // const eT* A_coldata = A.colptr(col); // // eT acc = eT(0); // for(uword row=0; row < A_n_rows; ++row) // { // acc += A_coldata[row] * x[row]; // } const eT acc = op_dot::direct_dot_arma(A_n_rows, A.colptr(col), x); if( (use_alpha == false) && (use_beta == false) ) { y[col] = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { y[col] = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { y[col] = acc + beta*y[col]; } else if( (use_alpha == true ) && (use_beta == true ) ) { y[col] = alpha*acc + beta*y[col]; } } } } }; template class gemv_emul { public: template arma_hot inline static void apply( eT* y, const TA& A, const eT* x, const eT alpha = eT(1), const eT beta = eT(0), const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; if( (A_n_rows <= 4) && (A_n_rows == A_n_cols) ) { gemv_emul_tinysq::apply(y, A, x, alpha, beta); } else { gemv_emul_large::apply(y, A, x, alpha, beta); } } template arma_hot inline static void apply( eT* y, const Mat& A, const eT* x, const eT alpha = eT(1), const eT beta = eT(0), const typename arma_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Mat tmp_A; if(do_trans_A) { op_htrans::apply_mat_noalias(tmp_A, A); } const Mat& AA = (do_trans_A == false) ? A : tmp_A; const uword AA_n_rows = AA.n_rows; const uword AA_n_cols = AA.n_cols; if( (AA_n_rows <= 4) && (AA_n_rows == AA_n_cols) ) { gemv_emul_tinysq::apply(y, AA, x, alpha, beta); } else { gemv_emul_large::apply(y, AA, x, alpha, beta); } } }; //! \brief //! Wrapper for ATLAS/BLAS gemv function, using template arguments to control the arguments passed to gemv. //! 'y' is assumed to have been set to the correct size (i.e. taking into account the transpose) template class gemv { public: template inline static void apply_blas_type( eT* y, const TA& A, const eT* x, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); //const uword threshold = (is_cx::yes) ? 16u : 64u; const uword threshold = (is_cx::yes) ? 64u : 100u; if(A.n_elem <= threshold) { gemv_emul::apply(y,A,x,alpha,beta); } else { #if defined(ARMA_USE_ATLAS) { if(is_cx::no) { // use gemm() instead of gemv() to work around a speed issue in Atlas 3.8.4 arma_extra_debug_print("atlas::cblas_gemm()"); atlas::cblas_gemm ( atlas::CblasColMajor, (do_trans_A) ? ( is_cx::yes ? CblasConjTrans : atlas::CblasTrans ) : atlas::CblasNoTrans, atlas::CblasNoTrans, (do_trans_A) ? A.n_cols : A.n_rows, 1, (do_trans_A) ? A.n_rows : A.n_cols, (use_alpha) ? alpha : eT(1), A.mem, A.n_rows, x, (do_trans_A) ? A.n_rows : A.n_cols, (use_beta) ? beta : eT(0), y, (do_trans_A) ? A.n_cols : A.n_rows ); } else { arma_extra_debug_print("atlas::cblas_gemv()"); atlas::cblas_gemv ( atlas::CblasColMajor, (do_trans_A) ? ( is_cx::yes ? CblasConjTrans : atlas::CblasTrans ) : atlas::CblasNoTrans, A.n_rows, A.n_cols, (use_alpha) ? alpha : eT(1), A.mem, A.n_rows, x, 1, (use_beta) ? beta : eT(0), y, 1 ); } } #elif defined(ARMA_USE_BLAS) { arma_extra_debug_print("blas::gemv()"); const char trans_A = (do_trans_A) ? ( is_cx::yes ? 'C' : 'T' ) : 'N'; const blas_int m = A.n_rows; const blas_int n = A.n_cols; const eT local_alpha = (use_alpha) ? alpha : eT(1); //const blas_int lda = A.n_rows; const blas_int inc = 1; const eT local_beta = (use_beta) ? beta : eT(0); arma_extra_debug_print( arma_boost::format("blas::gemv(): trans_A = %c") % trans_A ); blas::gemv ( &trans_A, &m, &n, &local_alpha, A.mem, &m, // lda x, &inc, &local_beta, y, &inc ); } #else { gemv_emul::apply(y,A,x,alpha,beta); } #endif } } template arma_inline static void apply( eT* y, const TA& A, const eT* x, const eT alpha = eT(1), const eT beta = eT(0) ) { gemv_emul::apply(y,A,x,alpha,beta); } template arma_inline static void apply ( float* y, const TA& A, const float* x, const float alpha = float(1), const float beta = float(0) ) { gemv::apply_blas_type(y,A,x,alpha,beta); } template arma_inline static void apply ( double* y, const TA& A, const double* x, const double alpha = double(1), const double beta = double(0) ) { gemv::apply_blas_type(y,A,x,alpha,beta); } template arma_inline static void apply ( std::complex* y, const TA& A, const std::complex* x, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { gemv::apply_blas_type(y,A,x,alpha,beta); } template arma_inline static void apply ( std::complex* y, const TA& A, const std::complex* x, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { gemv::apply_blas_type(y,A,x,alpha,beta); } }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_toeplitz_bones.hpp0000644000176000001440000000122512111564102024660 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_toeplitz //! @{ class op_toeplitz { public: template inline static void apply(Mat& out, const Op& in); }; class op_toeplitz_c { public: template inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/glue_mixed_meat.hpp0000644000176000001440000003373212200375542024271 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_mixed //! @{ //! matrix multiplication with different element types template inline void glue_mixed_times::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_times>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; const unwrap_check_mixed tmp1(X.A, out); const unwrap_check_mixed tmp2(X.B, out); const Mat& A = tmp1.M; const Mat& B = tmp2.M; arma_debug_assert_mul_size(A, B, "matrix multiplication"); out.set_size(A.n_rows, B.n_cols); gemm_mixed<>::apply(out, A, B); } //! matrix addition with different element types template inline void glue_mixed_plus::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_plus>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "addition"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { typename Proxy::ea_type AA = A.get_ea(); typename Proxy::ea_type BB = B.get_ea(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); for(uword i=0; i::apply(AA[i]) + upgrade_val::apply(BB[i]); } } else { for(uword i=0; i::apply(AA[i]) + upgrade_val::apply(BB[i]); } } } else { uword i = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { out_mem[i] = upgrade_val::apply(A.at(row,col)) + upgrade_val::apply(B.at(row,col)); ++i; } } } //! matrix subtraction with different element types template inline void glue_mixed_minus::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_minus>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "subtraction"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { typename Proxy::ea_type AA = A.get_ea(); typename Proxy::ea_type BB = B.get_ea(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); for(uword i=0; i::apply(AA[i]) - upgrade_val::apply(BB[i]); } } else { for(uword i=0; i::apply(AA[i]) - upgrade_val::apply(BB[i]); } } } else { uword i = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { out_mem[i] = upgrade_val::apply(A.at(row,col)) - upgrade_val::apply(B.at(row,col)); ++i; } } } //! element-wise matrix division with different element types template inline void glue_mixed_div::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_div>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "element-wise division"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { typename Proxy::ea_type AA = A.get_ea(); typename Proxy::ea_type BB = B.get_ea(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); for(uword i=0; i::apply(AA[i]) / upgrade_val::apply(BB[i]); } } else { for(uword i=0; i::apply(AA[i]) / upgrade_val::apply(BB[i]); } } } else { uword i = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { out_mem[i] = upgrade_val::apply(A.at(row,col)) / upgrade_val::apply(B.at(row,col)); ++i; } } } //! element-wise matrix multiplication with different element types template inline void glue_mixed_schur::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_schur>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "element-wise multiplication"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { typename Proxy::ea_type AA = A.get_ea(); typename Proxy::ea_type BB = B.get_ea(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); for(uword i=0; i::apply(AA[i]) * upgrade_val::apply(BB[i]); } } else { for(uword i=0; i::apply(AA[i]) * upgrade_val::apply(BB[i]); } } } else { uword i = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { out_mem[i] = upgrade_val::apply(A.at(row,col)) * upgrade_val::apply(B.at(row,col)); ++i; } } } // // // //! cube addition with different element types template inline void glue_mixed_plus::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_plus>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const ProxyCube A(X.A); const ProxyCube B(X.B); arma_debug_assert_same_size(A, B, "addition"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { typename ProxyCube::ea_type AA = A.get_ea(); typename ProxyCube::ea_type BB = B.get_ea(); for(uword i=0; i::apply(AA[i]) + upgrade_val::apply(BB[i]); } } else { uword i = 0; for(uword slice = 0; slice < n_slices; ++slice) for(uword col = 0; col < n_cols; ++col ) for(uword row = 0; row < n_rows; ++row ) { out_mem[i] = upgrade_val::apply(A.at(row,col,slice)) + upgrade_val::apply(B.at(row,col,slice)); ++i; } } } //! cube subtraction with different element types template inline void glue_mixed_minus::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_minus>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const ProxyCube A(X.A); const ProxyCube B(X.B); arma_debug_assert_same_size(A, B, "subtraction"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { typename ProxyCube::ea_type AA = A.get_ea(); typename ProxyCube::ea_type BB = B.get_ea(); for(uword i=0; i::apply(AA[i]) - upgrade_val::apply(BB[i]); } } else { uword i = 0; for(uword slice = 0; slice < n_slices; ++slice) for(uword col = 0; col < n_cols; ++col ) for(uword row = 0; row < n_rows; ++row ) { out_mem[i] = upgrade_val::apply(A.at(row,col,slice)) - upgrade_val::apply(B.at(row,col,slice)); ++i; } } } //! element-wise cube division with different element types template inline void glue_mixed_div::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_div>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const ProxyCube A(X.A); const ProxyCube B(X.B); arma_debug_assert_same_size(A, B, "element-wise division"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { typename ProxyCube::ea_type AA = A.get_ea(); typename ProxyCube::ea_type BB = B.get_ea(); for(uword i=0; i::apply(AA[i]) / upgrade_val::apply(BB[i]); } } else { uword i = 0; for(uword slice = 0; slice < n_slices; ++slice) for(uword col = 0; col < n_cols; ++col ) for(uword row = 0; row < n_rows; ++row ) { out_mem[i] = upgrade_val::apply(A.at(row,col,slice)) / upgrade_val::apply(B.at(row,col,slice)); ++i; } } } //! element-wise cube multiplication with different element types template inline void glue_mixed_schur::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_schur>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const ProxyCube A(X.A); const ProxyCube B(X.B); arma_debug_assert_same_size(A, B, "element-wise multiplication"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { typename ProxyCube::ea_type AA = A.get_ea(); typename ProxyCube::ea_type BB = B.get_ea(); for(uword i=0; i::apply(AA[i]) * upgrade_val::apply(BB[i]); } } else { uword i = 0; for(uword slice = 0; slice < n_slices; ++slice) for(uword col = 0; col < n_cols; ++col ) for(uword row = 0; row < n_rows; ++row ) { out_mem[i] = upgrade_val::apply(A.at(row,col,slice)) * upgrade_val::apply(B.at(row,col,slice)); ++i; } } } //! @} RcppArmadillo/inst/include/armadillo_bits/mtGlueCube_bones.hpp0000644000176000001440000000177612202101406024352 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup mtGlueCube //! @{ template class mtGlueCube : public BaseCube > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; arma_inline mtGlueCube(const T1& in_A, const T2& in_B); arma_inline mtGlueCube(const T1& in_A, const T2& in_B, const uword in_aux_uword); arma_inline ~mtGlueCube(); arma_aligned const T1& A; //!< first operand arma_aligned const T2& B; //!< second operand arma_aligned uword aux_uword; //!< storage of auxiliary data, uword format }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_all_bones.hpp0000644000176000001440000000264412200732042023563 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_all //! @{ class op_all { public: template static inline bool all_vec_helper(const Base& X); template static inline bool all_vec_helper ( const mtOp& X, const typename arma_op_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0 ); template static inline bool all_vec_helper ( const mtGlue& X, const typename arma_glue_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0, const typename arma_not_cx::result junk3 = 0 ); template static inline bool all_vec(T1& X); template static inline void apply_helper(Mat& out, const Proxy& P, const uword dim); template static inline void apply(Mat& out, const mtOp& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_eigs_sym.hpp0000644000176000001440000000451112260176556023446 0ustar ripleyusers// Copyright (C) 2013 Ryan Curtin // Copyright (C) 2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_eigs_sym //! @{ //! eigenvalues of symmetric real sparse matrix X template inline Col eigs_sym ( const SpBase& X, const uword n_eigvals, const typename arma_real_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Mat eigvec; Col eigval; const bool status = sp_auxlib::eigs_sym(eigval, eigvec, X, n_eigvals); if(status == false) { eigval.reset(); arma_bad("eigs_sym(): failed to converge"); } return eigval; } //! eigenvalues of symmetric real sparse matrix X template inline bool eigs_sym ( Col& eigval, const SpBase& X, const uword n_eigvals, const typename arma_real_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Mat eigvec; const bool status = sp_auxlib::eigs_sym(eigval, eigvec, X, n_eigvals); if(status == false) { eigval.reset(); arma_bad("eigs_sym(): failed to converge", false); } return status; } //! eigenvalues and eigenvectors of symmetric real sparse matrix X template inline bool eigs_sym ( Col& eigval, Mat& eigvec, const SpBase& X, const uword n_eigvals, const typename arma_real_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( void_ptr(&eigval) == void_ptr(&eigvec), "eigs_sym(): eigval is an alias of eigvec" ); const bool status = sp_auxlib::eigs_sym(eigval, eigvec, X, n_eigvals); if(status == false) { eigval.reset(); arma_bad("eigs_sym(): failed to converge", false); } return status; } //! @} RcppArmadillo/inst/include/armadillo_bits/eGlue_bones.hpp0000644000176000001440000000345712176655102023376 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup eGlue //! @{ template class eGlue : public Base > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Proxy proxy1_type; typedef Proxy proxy2_type; static const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); static const bool has_subview = (Proxy::has_subview || Proxy::has_subview ); static const bool is_fixed = (Proxy::is_fixed || Proxy::is_fixed ); static const bool fake_mat = (Proxy::fake_mat || Proxy::fake_mat ); static const bool is_col = (Proxy::is_col || Proxy::is_col); static const bool is_row = (Proxy::is_row || Proxy::is_row); arma_aligned const Proxy P1; arma_aligned const Proxy P2; arma_inline ~eGlue(); arma_inline eGlue(const T1& in_A, const T2& in_B); arma_inline uword get_n_rows() const; arma_inline uword get_n_cols() const; arma_inline uword get_n_elem() const; arma_inline elem_type operator[] (const uword ii) const; arma_inline elem_type at (const uword row, const uword col) const; arma_inline elem_type at_alt (const uword ii) const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/blas_wrapper.hpp0000644000176000001440000001532012200116305023601 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifdef ARMA_USE_BLAS //! \namespace blas namespace for BLAS functions namespace blas { template inline void gemv(const char* transA, const blas_int* m, const blas_int* n, const eT* alpha, const eT* A, const blas_int* ldA, const eT* x, const blas_int* incx, const eT* beta, eT* y, const blas_int* incy) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float T; arma_fortran(arma_sgemv)(transA, m, n, (const T*)alpha, (const T*)A, ldA, (const T*)x, incx, (const T*)beta, (T*)y, incy); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dgemv)(transA, m, n, (const T*)alpha, (const T*)A, ldA, (const T*)x, incx, (const T*)beta, (T*)y, incy); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_cgemv)(transA, m, n, (const T*)alpha, (const T*)A, ldA, (const T*)x, incx, (const T*)beta, (T*)y, incy); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_zgemv)(transA, m, n, (const T*)alpha, (const T*)A, ldA, (const T*)x, incx, (const T*)beta, (T*)y, incy); } } template inline void gemm(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const eT* alpha, const eT* A, const blas_int* ldA, const eT* B, const blas_int* ldB, const eT* beta, eT* C, const blas_int* ldC) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float T; arma_fortran(arma_sgemm)(transA, transB, m, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)B, ldB, (const T*)beta, (T*)C, ldC); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dgemm)(transA, transB, m, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)B, ldB, (const T*)beta, (T*)C, ldC); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_fortran(arma_cgemm)(transA, transB, m, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)B, ldB, (const T*)beta, (T*)C, ldC); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_fortran(arma_zgemm)(transA, transB, m, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)B, ldB, (const T*)beta, (T*)C, ldC); } } template inline void syrk(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const eT* alpha, const eT* A, const blas_int* ldA, const eT* beta, eT* C, const blas_int* ldC) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float T; arma_fortran(arma_ssyrk)(uplo, transA, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)beta, (T*)C, ldC); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dsyrk)(uplo, transA, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)beta, (T*)C, ldC); } } template inline void herk(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const T* alpha, const std::complex* A, const blas_int* ldA, const T* beta, std::complex* C, const blas_int* ldC) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float TT; typedef std::complex cx_TT; arma_fortran(arma_cherk)(uplo, transA, n, k, (const TT*)alpha, (const cx_TT*)A, ldA, (const TT*)beta, (cx_TT*)C, ldC); } else if(is_double::value == true) { typedef double TT; typedef std::complex cx_TT; arma_fortran(arma_zherk)(uplo, transA, n, k, (const TT*)alpha, (const cx_TT*)A, ldA, (const TT*)beta, (cx_TT*)C, ldC); } } template inline eT dot(const uword n_elem, const eT* x, const eT* y) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { #if defined(ARMA_BLAS_SDOT_BUG) { if(n_elem == 0) { return eT(0); } const char trans = 'T'; const blas_int m = blas_int(n_elem); const blas_int n = 1; //const blas_int lda = (n_elem > 0) ? blas_int(n_elem) : blas_int(1); const blas_int inc = 1; const eT alpha = eT(1); const eT beta = eT(0); eT result[2]; // paranoia: using two elements instead of one //blas::gemv(&trans, &m, &n, &alpha, x, &lda, y, &inc, &beta, &result[0], &inc); blas::gemv(&trans, &m, &n, &alpha, x, &m, y, &inc, &beta, &result[0], &inc); return result[0]; } #else { blas_int n = blas_int(n_elem); blas_int inc = 1; typedef float T; return arma_fortran(arma_sdot)(&n, (const T*)x, &inc, (const T*)y, &inc); } #endif } else if(is_double::value == true) { blas_int n = blas_int(n_elem); blas_int inc = 1; typedef double T; return arma_fortran(arma_ddot)(&n, (const T*)x, &inc, (const T*)y, &inc); } else if( (is_supported_complex_float::value == true) || (is_supported_complex_double::value == true) ) { if(n_elem == 0) { return eT(0); } // using gemv() workaround due to compatibility issues with cdotu() and zdotu() const char trans = 'T'; const blas_int m = blas_int(n_elem); const blas_int n = 1; //const blas_int lda = (n_elem > 0) ? blas_int(n_elem) : blas_int(1); const blas_int inc = 1; const eT alpha = eT(1); const eT beta = eT(0); eT result[2]; // paranoia: using two elements instead of one //blas::gemv(&trans, &m, &n, &alpha, x, &lda, y, &inc, &beta, &result[0], &inc); blas::gemv(&trans, &m, &n, &alpha, x, &m, y, &inc, &beta, &result[0], &inc); return result[0]; } else { return eT(0); } } } #endif RcppArmadillo/inst/include/armadillo_bits/lapack_bones.hpp0000644000176000001440000005104612256014630023557 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2009 Edmund Highcock // Copyright (C) 2011 James Sanders // Copyright (C) 2012 Eric Jon Sundstrom // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifdef ARMA_USE_LAPACK #if !defined(ARMA_BLAS_CAPITALS) #define arma_sgetrf sgetrf #define arma_dgetrf dgetrf #define arma_cgetrf cgetrf #define arma_zgetrf zgetrf #define arma_sgetri sgetri #define arma_dgetri dgetri #define arma_cgetri cgetri #define arma_zgetri zgetri #define arma_strtri strtri #define arma_dtrtri dtrtri #define arma_ctrtri ctrtri #define arma_ztrtri ztrtri #define arma_ssyev ssyev #define arma_dsyev dsyev #define arma_cheev cheev #define arma_zheev zheev #define arma_ssyevd ssyevd #define arma_dsyevd dsyevd #define arma_cheevd cheevd #define arma_zheevd zheevd #define arma_sgeev sgeev #define arma_dgeev dgeev #define arma_cgeev cgeev #define arma_zgeev zgeev #define arma_sggev sggev #define arma_dggev dggev #define arma_cggev cggev #define arma_zggev zggev #define arma_spotrf spotrf #define arma_dpotrf dpotrf #define arma_cpotrf cpotrf #define arma_zpotrf zpotrf #define arma_spotri spotri #define arma_dpotri dpotri #define arma_cpotri cpotri #define arma_zpotri zpotri #define arma_sgeqrf sgeqrf #define arma_dgeqrf dgeqrf #define arma_cgeqrf cgeqrf #define arma_zgeqrf zgeqrf #define arma_sorgqr sorgqr #define arma_dorgqr dorgqr #define arma_cungqr cungqr #define arma_zungqr zungqr #define arma_sgesvd sgesvd #define arma_dgesvd dgesvd #define arma_cgesvd cgesvd #define arma_zgesvd zgesvd #define arma_sgesdd sgesdd #define arma_dgesdd dgesdd #define arma_cgesdd cgesdd #define arma_zgesdd zgesdd #define arma_sgesv sgesv #define arma_dgesv dgesv #define arma_cgesv cgesv #define arma_zgesv zgesv #define arma_sgels sgels #define arma_dgels dgels #define arma_cgels cgels #define arma_zgels zgels #define arma_strtrs strtrs #define arma_dtrtrs dtrtrs #define arma_ctrtrs ctrtrs #define arma_ztrtrs ztrtrs #define arma_sgees sgees #define arma_dgees dgees #define arma_cgees cgees #define arma_zgees zgees #define arma_strsyl strsyl #define arma_dtrsyl dtrsyl #define arma_ctrsyl ctrsyl #define arma_ztrsyl ztrsyl #define arma_ssytrf ssytrf #define arma_dsytrf dsytrf #define arma_csytrf csytrf #define arma_zsytrf zsytrf #define arma_ssytri ssytri #define arma_dsytri dsytri #define arma_csytri csytri #define arma_zsytri zsytri #else #define arma_sgetrf SGETRF #define arma_dgetrf DGETRF #define arma_cgetrf CGETRF #define arma_zgetrf ZGETRF #define arma_sgetri SGETRI #define arma_dgetri DGETRI #define arma_cgetri CGETRI #define arma_zgetri ZGETRI #define arma_strtri STRTRI #define arma_dtrtri DTRTRI #define arma_ctrtri CTRTRI #define arma_ztrtri ZTRTRI #define arma_ssyev SSYEV #define arma_dsyev DSYEV #define arma_cheev CHEEV #define arma_zheev ZHEEV #define arma_ssyevd SSYEVD #define arma_dsyevd DSYEVD #define arma_cheevd CHEEVD #define arma_zheevd ZHEEVD #define arma_sgeev SGEEV #define arma_dgeev DGEEV #define arma_cgeev CGEEV #define arma_zgeev ZGEEV #define arma_sggev SGGEV #define arma_dggev DGGEV #define arma_cggev CGGEV #define arma_zggev ZGGEV #define arma_spotrf SPOTRF #define arma_dpotrf DPOTRF #define arma_cpotrf CPOTRF #define arma_zpotrf ZPOTRF #define arma_spotri SPOTRI #define arma_dpotri DPOTRI #define arma_cpotri CPOTRI #define arma_zpotri ZPOTRI #define arma_sgeqrf SGEQRF #define arma_dgeqrf DGEQRF #define arma_cgeqrf CGEQRF #define arma_zgeqrf ZGEQRF #define arma_sorgqr SORGQR #define arma_dorgqr DORGQR #define arma_cungqr CUNGQR #define arma_zungqr ZUNGQR #define arma_sgesvd SGESVD #define arma_dgesvd DGESVD #define arma_cgesvd CGESVD #define arma_zgesvd ZGESVD #define arma_sgesdd SGESDD #define arma_dgesdd DGESDD #define arma_cgesdd CGESDD #define arma_zgesdd ZGESDD #define arma_sgesv SGESV #define arma_dgesv DGESV #define arma_cgesv CGESV #define arma_zgesv ZGESV #define arma_sgels SGELS #define arma_dgels DGELS #define arma_cgels CGELS #define arma_zgels ZGELS #define arma_strtrs STRTRS #define arma_dtrtrs DTRTRS #define arma_ctrtrs CTRTRS #define arma_ztrtrs ZTRTRS #define arma_sgees SGEES #define arma_dgees DGEES #define arma_cgees CGEES #define arma_zgees ZGEES #define arma_strsyl STRSYL #define arma_dtrsyl DTRSYL #define arma_ctrsyl CTRSYL #define arma_ztrsyl ZTRSYL #define arma_ssytrf SSYTRF #define arma_dsytrf DSYTRF #define arma_csytrf CSYTRF #define arma_zsytrf ZSYTRF #define arma_ssytri SSYTRI #define arma_dsytri DSYTRI #define arma_csytri CSYTRI #define arma_zsytri ZSYTRI #endif extern "C" { // LU factorisation void arma_fortran(arma_sgetrf)(blas_int* m, blas_int* n, float* a, blas_int* lda, blas_int* ipiv, blas_int* info); void arma_fortran(arma_dgetrf)(blas_int* m, blas_int* n, double* a, blas_int* lda, blas_int* ipiv, blas_int* info); void arma_fortran(arma_cgetrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, blas_int* info); void arma_fortran(arma_zgetrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, blas_int* info); // matrix inversion (using LU factorisation result) void arma_fortran(arma_sgetri)(blas_int* n, float* a, blas_int* lda, blas_int* ipiv, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dgetri)(blas_int* n, double* a, blas_int* lda, blas_int* ipiv, double* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_cgetri)(blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_zgetri)(blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info); // matrix inversion (triangular matrices) void arma_fortran(arma_strtri)(char* uplo, char* diag, blas_int* n, float* a, blas_int* lda, blas_int* info); void arma_fortran(arma_dtrtri)(char* uplo, char* diag, blas_int* n, double* a, blas_int* lda, blas_int* info); void arma_fortran(arma_ctrtri)(char* uplo, char* diag, blas_int* n, void* a, blas_int* lda, blas_int* info); void arma_fortran(arma_ztrtri)(char* uplo, char* diag, blas_int* n, void* a, blas_int* lda, blas_int* info); // eigenvector decomposition of symmetric real matrices void arma_fortran(arma_ssyev)(char* jobz, char* uplo, blas_int* n, float* a, blas_int* lda, float* w, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dsyev)(char* jobz, char* uplo, blas_int* n, double* a, blas_int* lda, double* w, double* work, blas_int* lwork, blas_int* info); // eigenvector decomposition of hermitian matrices (complex) void arma_fortran(arma_cheev)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, float* w, void* work, blas_int* lwork, float* rwork, blas_int* info); void arma_fortran(arma_zheev)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, double* w, void* work, blas_int* lwork, double* rwork, blas_int* info); // eigenvector decomposition of symmetric real matrices by divide and conquer void arma_fortran(arma_ssyevd)(char* jobz, char* uplo, blas_int* n, float* a, blas_int* lda, float* w, float* work, blas_int* lwork, blas_int* iwork, blas_int* liwork, blas_int* info); void arma_fortran(arma_dsyevd)(char* jobz, char* uplo, blas_int* n, double* a, blas_int* lda, double* w, double* work, blas_int* lwork, blas_int* iwork, blas_int* liwork, blas_int* info); // eigenvector decomposition of hermitian matrices (complex) by divide and conquer void arma_fortran(arma_cheevd)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, float* w, void* work, blas_int* lwork, float* rwork, blas_int* lrwork, blas_int* iwork, blas_int* liwork, blas_int* info); void arma_fortran(arma_zheevd)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, double* w, void* work, blas_int* lwork, double* rwork, blas_int* lrwork, blas_int* iwork, blas_int* liwork, blas_int* info); // eigenvector decomposition of general real matrices void arma_fortran(arma_sgeev)(char* jobvl, char* jobvr, blas_int* n, float* a, blas_int* lda, float* wr, float* wi, float* vl, blas_int* ldvl, float* vr, blas_int* ldvr, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dgeev)(char* jobvl, char* jobvr, blas_int* n, double* a, blas_int* lda, double* wr, double* wi, double* vl, blas_int* ldvl, double* vr, blas_int* ldvr, double* work, blas_int* lwork, blas_int* info); // eigenvector decomposition of general complex matrices void arma_fortran(arma_cgeev)(char* jobvl, char* jobvr, blas_int* n, void* a, blas_int* lda, void* w, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, float* rwork, blas_int* info); void arma_fortran(arma_zgeev)(char* jobvl, char* jobvr, blas_int* n, void* a, blas_int* lda, void* w, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, double* rwork, blas_int* info); // eigenvector decomposition of general real matrix pair void arma_fortran(arma_sggev)(char* jobvl, char* jobvr, blas_int* n, float* a, blas_int* lda, float* b, blas_int* ldb, float* alphar, float* alphai, float* beta, float* vl, blas_int* ldvl, float* vr, blas_int* ldvr, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dggev)(char* jobvl, char* jobvr, blas_int* n, double* a, blas_int* lda, double* b, blas_int* ldb, double* alphar, double* alphai, double* beta, double* vl, blas_int* ldvl, double* vr, blas_int* ldvr, double* work, blas_int* lwork, blas_int* info); // eigenvector decomposition of general complex matrix pair void arma_fortran(arma_cggev)(char* jobvl, char* jobvr, blas_int* n, void* a, blas_int* lda, void* b, blas_int* ldb, void* alpha, void* beta, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, float* rwork, blas_int* info); void arma_fortran(arma_zggev)(char* jobvl, char* jobvr, blas_int* n, void* a, blas_int* lda, void* b, blas_int* ldb, void* alpha, void* beta, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, double* rwork, blas_int* info); // Cholesky decomposition void arma_fortran(arma_spotrf)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* info); void arma_fortran(arma_dpotrf)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* info); void arma_fortran(arma_cpotrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info); void arma_fortran(arma_zpotrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info); // matrix inversion (using Cholesky decomposition result) void arma_fortran(arma_spotri)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* info); void arma_fortran(arma_dpotri)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* info); void arma_fortran(arma_cpotri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info); void arma_fortran(arma_zpotri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info); // QR decomposition void arma_fortran(arma_sgeqrf)(blas_int* m, blas_int* n, float* a, blas_int* lda, float* tau, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dgeqrf)(blas_int* m, blas_int* n, double* a, blas_int* lda, double* tau, double* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_cgeqrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_zgeqrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info); // Q matrix calculation from QR decomposition (real matrices) void arma_fortran(arma_sorgqr)(blas_int* m, blas_int* n, blas_int* k, float* a, blas_int* lda, float* tau, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dorgqr)(blas_int* m, blas_int* n, blas_int* k, double* a, blas_int* lda, double* tau, double* work, blas_int* lwork, blas_int* info); // Q matrix calculation from QR decomposition (complex matrices) void arma_fortran(arma_cungqr)(blas_int* m, blas_int* n, blas_int* k, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_zungqr)(blas_int* m, blas_int* n, blas_int* k, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info); // SVD (real matrices) void arma_fortran(arma_sgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, float* a, blas_int* lda, float* s, float* u, blas_int* ldu, float* vt, blas_int* ldvt, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, double* a, blas_int* lda, double* s, double* u, blas_int* ldu, double* vt, blas_int* ldvt, double* work, blas_int* lwork, blas_int* info); // SVD (complex matrices) void arma_fortran(arma_cgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, void* a, blas_int* lda, float* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, float* rwork, blas_int* info); void arma_fortran(arma_zgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, void* a, blas_int* lda, double* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, double* rwork, blas_int* info); // SVD (real matrices) by divide and conquer void arma_fortran(arma_sgesdd)(char* jobz, blas_int* m, blas_int* n, float* a, blas_int* lda, float* s, float* u, blas_int* ldu, float* vt, blas_int* ldvt, float* work, blas_int* lwork, blas_int* iwork, blas_int* info); void arma_fortran(arma_dgesdd)(char* jobz, blas_int* m, blas_int* n, double* a, blas_int* lda, double* s, double* u, blas_int* ldu, double* vt, blas_int* ldvt, double* work, blas_int* lwork, blas_int* iwork, blas_int* info); // SVD (complex matrices) by divide and conquer void arma_fortran(arma_cgesdd)(char* jobz, blas_int* m, blas_int* n, void* a, blas_int* lda, float* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, float* rwork, blas_int* iwork, blas_int* info); void arma_fortran(arma_zgesdd)(char* jobz, blas_int* m, blas_int* n, void* a, blas_int* lda, double* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, double* rwork, blas_int* iwork, blas_int* info); // solve system of linear equations, using LU decomposition void arma_fortran(arma_sgesv)(blas_int* n, blas_int* nrhs, float* a, blas_int* lda, blas_int* ipiv, float* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_dgesv)(blas_int* n, blas_int* nrhs, double* a, blas_int* lda, blas_int* ipiv, double* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_cgesv)(blas_int* n, blas_int* nrhs, void* a, blas_int* lda, blas_int* ipiv, void* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_zgesv)(blas_int* n, blas_int* nrhs, void* a, blas_int* lda, blas_int* ipiv, void* b, blas_int* ldb, blas_int* info); // solve over/underdetermined system of linear equations void arma_fortran(arma_sgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, float* a, blas_int* lda, float* b, blas_int* ldb, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, double* a, blas_int* lda, double* b, blas_int* ldb, double* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_cgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* b, blas_int* ldb, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_zgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* b, blas_int* ldb, void* work, blas_int* lwork, blas_int* info); // solve a triangular system of linear equations void arma_fortran(arma_strtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const float* a, blas_int* lda, float* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_dtrtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const double* a, blas_int* lda, double* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_ctrtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const void* a, blas_int* lda, void* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_ztrtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const void* a, blas_int* lda, void* b, blas_int* ldb, blas_int* info); // Schur decomposition (real matrices) void arma_fortran(arma_sgees)(char* jobvs, char* sort, blas_int* select, blas_int* n, float* a, blas_int* lda, blas_int* sdim, float* wr, float* wi, float* vs, blas_int* ldvs, float* work, blas_int* lwork, blas_int* bwork, blas_int* info); void arma_fortran(arma_dgees)(char* jobvs, char* sort, blas_int* select, blas_int* n, double* a, blas_int* lda, blas_int* sdim, double* wr, double* wi, double* vs, blas_int* ldvs, double* work, blas_int* lwork, blas_int* bwork, blas_int* info); // Schur decomposition (complex matrices) void arma_fortran(arma_cgees)(char* jobvs, char* sort, blas_int* select, blas_int* n, void* a, blas_int* lda, blas_int* sdim, void* w, void* vs, blas_int* ldvs, void* work, blas_int* lwork, float* rwork, blas_int* bwork, blas_int* info); void arma_fortran(arma_zgees)(char* jobvs, char* sort, blas_int* select, blas_int* n, void* a, blas_int* lda, blas_int* sdim, void* w, void* vs, blas_int* ldvs, void* work, blas_int* lwork, double* rwork, blas_int* bwork, blas_int* info); // solve a Sylvester equation ax + xb = c, with a and b assumed to be in Schur form void arma_fortran(arma_strsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const float* a, blas_int* lda, const float* b, blas_int* ldb, float* c, blas_int* ldc, float* scale, blas_int* info); void arma_fortran(arma_dtrsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const double* a, blas_int* lda, const double* b, blas_int* ldb, double* c, blas_int* ldc, double* scale, blas_int* info); void arma_fortran(arma_ctrsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const void* a, blas_int* lda, const void* b, blas_int* ldb, void* c, blas_int* ldc, float* scale, blas_int* info); void arma_fortran(arma_ztrsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const void* a, blas_int* lda, const void* b, blas_int* ldb, void* c, blas_int* ldc, double* scale, blas_int* info); void arma_fortran(arma_ssytrf)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* ipiv, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dsytrf)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* ipiv, double* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_csytrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_zsytrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_ssytri)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* ipiv, float* work, blas_int* info); void arma_fortran(arma_dsytri)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* ipiv, double* work, blas_int* info); void arma_fortran(arma_csytri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* info); void arma_fortran(arma_zsytri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* info); // void arma_fortran(arma_dgeqp3)(blas_int* m, blas_int* n, double* a, blas_int* lda, blas_int* jpvt, double* tau, double* work, blas_int* lwork, blas_int* info); // void arma_fortran(arma_dormqr)(char* side, char* trans, blas_int* m, blas_int* n, blas_int* k, double* a, blas_int* lda, double* tau, double* c, blas_int* ldc, double* work, blas_int* lwork, blas_int* info); // void arma_fortran(arma_dposv)(char* uplo, blas_int* n, blas_int* nrhs, double* a, blas_int* lda, double* b, blas_int* ldb, blas_int* info); } #endif RcppArmadillo/inst/include/armadillo_bits/spop_sum_bones.hpp0000644000176000001440000000113112111344723024156 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_sum //! @{ class spop_sum { public: template arma_hot inline static void apply(SpMat& out, const SpOp& in); template arma_hot inline static void apply_noalias(SpMat& out, const SpProxy& p, const uword dim); }; //! @} RcppArmadillo/inst/include/armadillo_bits/glue_min_bones.hpp0000644000176000001440000000144612244135164024125 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_min //! @{ class glue_min { public: template inline static void apply(Mat< eT >& out, const Proxy& PA, const Proxy& PB); template inline static void apply(Mat< std::complex >& out, const Proxy& PA, const Proxy& PB); template inline static void apply(Mat& out, const Glue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_symmat_meat.hpp0000644000176000001440000001004412200631217024140 0ustar ripleyusers// Copyright (C) 2011-2012 Conrad Sanderson // Copyright (C) 2011-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_symmat //! @{ template inline void op_symmat::apply ( Mat& out, const Op& in, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap tmp(in.m); const Mat& A = tmp.M; arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square" ); const uword N = A.n_rows; const bool upper = (in.aux_uword_a == 0); if(&out != &A) { out.copy_size(A); if(upper) { // upper triangular: copy the diagonal and the elements above the diagonal for(uword i=0; i inline void op_symmat::apply ( Mat& out, const Op& in, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap tmp(in.m); const Mat& A = tmp.M; arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square" ); const uword N = A.n_rows; const bool upper = (in.aux_uword_a == 0); if(&out != &A) { out.copy_size(A); if(upper) { // upper triangular: copy the diagonal and the elements above the diagonal for(uword i=0; i arma_inline eGlue::~eGlue() { arma_extra_debug_sigprint(); } template arma_inline eGlue::eGlue(const T1& in_A, const T2& in_B) : P1(in_A) , P2(in_B) { arma_extra_debug_sigprint(); // arma_debug_assert_same_size( P1, P2, eglue_type::text() ); arma_debug_assert_same_size ( P1.get_n_rows(), P1.get_n_cols(), P2.get_n_rows(), P2.get_n_cols(), eglue_type::text() ); } template arma_inline uword eGlue::get_n_rows() const { return is_row ? 1 : ( Proxy::is_fixed ? P1.get_n_rows() : ( Proxy::is_fixed ? P2.get_n_rows() : P1.get_n_rows() ) ); } template arma_inline uword eGlue::get_n_cols() const { return is_col ? 1 : ( Proxy::is_fixed ? P1.get_n_cols() : ( Proxy::is_fixed ? P2.get_n_cols() : P1.get_n_cols() ) ); } template arma_inline uword eGlue::get_n_elem() const { return Proxy::is_fixed ? P1.get_n_elem() : ( Proxy::is_fixed ? P2.get_n_elem() : P1.get_n_elem() ) ; } template arma_inline typename T1::elem_type eGlue::operator[] (const uword ii) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1[ii] + P2[ii]; } else if(is_same_type::yes) { return P1[ii] - P2[ii]; } else if(is_same_type::yes) { return P1[ii] / P2[ii]; } else if(is_same_type::yes) { return P1[ii] * P2[ii]; } else return eT(0); } template arma_inline typename T1::elem_type eGlue::at(const uword row, const uword col) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1.at(row,col) + P2.at(row,col); } else if(is_same_type::yes) { return P1.at(row,col) - P2.at(row,col); } else if(is_same_type::yes) { return P1.at(row,col) / P2.at(row,col); } else if(is_same_type::yes) { return P1.at(row,col) * P2.at(row,col); } else return eT(0); } template arma_inline typename T1::elem_type eGlue::at_alt(const uword ii) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1.at_alt(ii) + P2.at_alt(ii); } else if(is_same_type::yes) { return P1.at_alt(ii) - P2.at_alt(ii); } else if(is_same_type::yes) { return P1.at_alt(ii) / P2.at_alt(ii); } else if(is_same_type::yes) { return P1.at_alt(ii) * P2.at_alt(ii); } else return eT(0); } //! @} RcppArmadillo/inst/include/armadillo_bits/config.hpp0000644000176000001440000001372012261415622022402 0ustar ripleyusers// Copyright (C) 2008-2014 Conrad Sanderson // Copyright (C) 2013 Ryan Curtin // Copyright (C) 2008-2014 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #if !defined(ARMA_USE_LAPACK) // #define ARMA_USE_LAPACK //// Uncomment the above line if you have LAPACK or a high-speed replacement for LAPACK, //// such as Intel MKL, AMD ACML, or the Accelerate framework. //// LAPACK is required for matrix decompositions (eg. SVD) and matrix inverse. #endif #if !defined(ARMA_USE_BLAS) // #define ARMA_USE_BLAS //// Uncomment the above line if you have BLAS or a high-speed replacement for BLAS, //// such as OpenBLAS, GotoBLAS, Intel MKL, AMD ACML, or the Accelerate framework. //// BLAS is used for matrix multiplication. //// Without BLAS, matrix multiplication will still work, but might be slower. #endif #if !defined(ARMA_USE_ARPACK) // #define ARMA_USE_ARPACK //// Uncomment the above line if you have ARPACK or a high-speed replacement for ARPACK. //// ARPACK is required for eigendecompositions of sparse matrices, eg. eigs_sym() #endif // #define ARMA_USE_WRAPPER //// Comment out the above line if you're getting linking errors when compiling your programs, //// or if you prefer to directly link with LAPACK, BLAS or ARPACK. //// You will then need to link your programs directly with -llapack -lblas instead of -larmadillo // #define ARMA_BLAS_CAPITALS //// Uncomment the above line if your BLAS and LAPACK libraries have capitalised function names (eg. ACML on 64-bit Windows) #define ARMA_BLAS_UNDERSCORE //// Uncomment the above line if your BLAS and LAPACK libraries have function names with a trailing underscore. //// Conversely, comment it out if the function names don't have a trailing underscore. // #define ARMA_BLAS_LONG //// Uncomment the above line if your BLAS and LAPACK libraries use "long" instead of "int" // #define ARMA_BLAS_LONG_LONG //// Uncomment the above line if your BLAS and LAPACK libraries use "long long" instead of "int" // #define ARMA_USE_TBB_ALLOC //// Uncomment the above line if you want to use Intel TBB scalable_malloc() and scalable_free() instead of standard malloc() and free() // #define ARMA_USE_MKL_ALLOC //// Uncomment the above line if you want to use Intel MKL mkl_malloc() and mkl_free() instead of standard malloc() and free() // #define ARMA_USE_ATLAS // #define ARMA_ATLAS_INCLUDE_DIR /usr/include/ //// If you're using ATLAS and the compiler can't find cblas.h and/or clapack.h //// uncomment the above define and specify the appropriate include directory. //// Make sure the directory has a trailing / #if !defined(ARMA_64BIT_WORD) // #define ARMA_64BIT_WORD //// Uncomment the above line if you require matrices/vectors capable of holding more than 4 billion elements. //// Your machine and compiler must have support for 64 bit integers (eg. via "long" or "long long") #endif #if !defined(ARMA_USE_CXX11) // #define ARMA_USE_CXX11 //// Uncomment the above line if you have a C++ compiler that supports the C++11 standard //// This will enable additional features, such as use of initialiser lists #endif #if !defined(ARMA_USE_U64S64) // #define ARMA_USE_U64S64 //// Uncomment the above line if you require u64 and s64 integer types. //// Your machine and compiler must have support for 64 bit integers (eg. via "long" or "long long"). //// Note that ARMA_USE_U64S64 is automatically enabled when ARMA_64BIT_WORD or ARMA_USE_CXX11 are enabled #endif #if !defined(ARMA_USE_HDF5) // #define ARMA_USE_HDF5 //// Uncomment the above line if you want the ability to save and load matrices stored in the HDF5 format; //// the hdf5.h header file must be available on your system and you will need to link with the hdf5 library (eg. -lhdf5) #endif #if !defined(ARMA_MAT_PREALLOC) #define ARMA_MAT_PREALLOC 16 #endif //// This is the number of preallocated elements used by matrices and vectors; //// it must be an integer that is at least 1. //// If you mainly use lots of very small vectors (eg. <= 4 elements), //// change the number to the size of your vectors. #if !defined(ARMA_SPMAT_CHUNKSIZE) #define ARMA_SPMAT_CHUNKSIZE 256 #endif //// This is the minimum increase in the amount of memory (in terms of elements) allocated by a sparse matrix; //// it must be an integer that is at least 1. //// The minimum recommended size is 16. // #define ARMA_NO_DEBUG //// Uncomment the above line if you want to disable all run-time checks. //// This will result in faster code, but you first need to make sure that your code runs correctly! //// We strongly recommend to have the run-time checks enabled during development, //// as this greatly aids in finding mistakes in your code, and hence speeds up development. //// We recommend that run-time checks be disabled _only_ for the shipped version of your program. // #define ARMA_EXTRA_DEBUG //// Uncomment the above line if you want to see the function traces of how Armadillo evaluates expressions. //// This is mainly useful for debugging of the library. #if !defined(ARMA_DEFAULT_OSTREAM) #define ARMA_DEFAULT_OSTREAM std::cout #endif #define ARMA_PRINT_ERRORS //#define ARMA_PRINT_HDF5_ERRORS #if defined(ARMA_DONT_PRINT_ERRORS) #undef ARMA_PRINT_ERRORS #undef ARMA_PRINT_HDF5_ERRORS #endif #if defined(ARMA_DONT_USE_LAPACK) #undef ARMA_USE_LAPACK #endif #if defined(ARMA_DONT_USE_BLAS) #undef ARMA_USE_BLAS #endif #if defined(ARMA_DONT_USE_ARPACK) #undef ARMA_USE_ARPACK #endif #if defined(ARMA_DONT_USE_ATLAS) #undef ARMA_USE_ATLAS #undef ARMA_ATLAS_INCLUDE_DIR #endif #if defined(ARMA_DONT_USE_WRAPPER) #undef ARMA_USE_WRAPPER #endif #if defined(ARMA_DONT_USE_CXX11) #undef ARMA_USE_CXX11 #undef ARMA_USE_CXX11_RNG #endif #if defined(ARMA_USE_WRAPPER) #if defined(ARMA_USE_CXX11) #if !defined(ARMA_USE_CXX11_RNG) // #define ARMA_USE_CXX11_RNG #endif #endif #endif #if defined(ARMA_DONT_USE_HDF5) #undef ARMA_USE_HDF5 #endif RcppArmadillo/inst/include/armadillo_bits/arpack_bones.hpp0000644000176000001440000001227012256562527023576 0ustar ripleyusers// Copyright (C) 2013 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifdef ARMA_USE_ARPACK // I'm not sure this is necessary. #if !defined(ARMA_BLAS_CAPITALS) #define arma_snaupd snaupd #define arma_dnaupd dnaupd #define arma_cnaupd cnaupd #define arma_znaupd znaupd #define arma_sneupd sneupd #define arma_dneupd dneupd #define arma_cneupd cneupd #define arma_zneupd zneupd #define arma_ssaupd ssaupd #define arma_dsaupd dsaupd #define arma_sseupd sseupd #define arma_dseupd dseupd #else #define arma_snaupd SNAUPD #define arma_dnaupd DNAUPD #define arma_cnaupd CNAUPD #define arma_znaupd ZNAUPD #define arma_sneupd SNEUPD #define arma_dneupd DNEUPD #define arma_cneupd CNEUPD #define arma_zneupd ZNEUPD #define arma_ssaupd SSAUPD #define arma_dsaupd DSAUPD #define arma_sseupd SSEUPD #define arma_dseupd DSEUPD #endif extern "C" { // eigendecomposition of non-symmetric positive semi-definite matrices void arma_fortran(arma_snaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_dnaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_cnaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, float* rwork, blas_int* info); void arma_fortran(arma_znaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, double* rwork, blas_int* info); // eigendecomposition of symmetric positive semi-definite matrices void arma_fortran(arma_ssaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_dsaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info); // recovery of eigenvectors after naupd(); uses blas_int for LOGICAL types void arma_fortran(arma_sneupd)(blas_int* rvec, char* howmny, blas_int* select, float* dr, float* di, float* z, blas_int* ldz, float* sigmar, float* sigmai, float* workev, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_dneupd)(blas_int* rvec, char* howmny, blas_int* select, double* dr, double* di, double* z, blas_int* ldz, double* sigmar, double* sigmai, double* workev, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_cneupd)(blas_int* rvec, char* howmny, blas_int* select, void* d, void* z, blas_int* ldz, void* sigma, void* workev, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, float* rwork, blas_int* info); void arma_fortran(arma_zneupd)(blas_int* rvec, char* howmny, blas_int* select, void* d, void* z, blas_int* ldz, void* sigma, void* workev, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, double* rwork, blas_int* info); // recovery of eigenvectors after saupd(); uses blas_int for LOGICAL types void arma_fortran(arma_sseupd)(blas_int* rvec, char* howmny, blas_int* select, float* d, float* z, blas_int* ldz, float* sigma, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_dseupd)(blas_int* rvec, char* howmny, blas_int* select, double* d, double* z, blas_int* ldz, double* sigma, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info); } #endif RcppArmadillo/inst/include/armadillo_bits/subview_elem1_bones.hpp0000644000176000001440000000644212256553754025112 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup subview_elem1 //! @{ template class subview_elem1 : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; arma_aligned const Mat fake_m; arma_aligned const Mat& m; arma_aligned const Base& a; protected: arma_inline subview_elem1(const Mat& in_m, const Base& in_a); arma_inline subview_elem1(const Cube& in_q, const Base& in_a); public: inline ~subview_elem1(); template inline void inplace_op(const eT val); template inline void inplace_op(const subview_elem1& x ); template inline void inplace_op(const Base& x ); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; inline void fill(const eT val); inline void zeros(); inline void ones(); inline void randu(); inline void randn(); inline void operator+= (const eT val); inline void operator-= (const eT val); inline void operator*= (const eT val); inline void operator/= (const eT val); // deliberately returning void template inline void operator_equ(const subview_elem1& x); template inline void operator= (const subview_elem1& x); inline void operator= (const subview_elem1& x); template inline void operator+= (const subview_elem1& x); template inline void operator-= (const subview_elem1& x); template inline void operator%= (const subview_elem1& x); template inline void operator/= (const subview_elem1& x); template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); inline static void extract(Mat& out, const subview_elem1& in); template inline static void mat_inplace_op(Mat& out, const subview_elem1& in); inline static void plus_inplace(Mat& out, const subview_elem1& in); inline static void minus_inplace(Mat& out, const subview_elem1& in); inline static void schur_inplace(Mat& out, const subview_elem1& in); inline static void div_inplace(Mat& out, const subview_elem1& in); private: friend class Mat; friend class Cube; subview_elem1(); }; //! @} RcppArmadillo/inst/include/armadillo_bits/compiler_setup_post.hpp0000644000176000001440000000054112176655102025235 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #if defined(_MSC_VER) #pragma warning(pop) #endif RcppArmadillo/inst/include/armadillo_bits/field_meat.hpp0000644000176000001440000011772612265411417023243 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Ian Cullinan // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup field //! @{ template inline field::~field() { arma_extra_debug_sigprint_this(this); delete_objects(); if(n_elem > sizeof(mem_local)/sizeof(oT*) ) { delete [] mem; } if(arma_config::debug == true) { // try to expose buggy user code that accesses deleted objects mem = 0; } } template inline field::field() : n_rows(0) , n_cols(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint_this(this); } //! construct a field from a given field template inline field::field(const field& x) : n_rows(0) , n_cols(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint(arma_boost::format("this = %x x = %x") % this % &x); init(x); } //! construct a field from a given field template inline const field& field::operator=(const field& x) { arma_extra_debug_sigprint(); init(x); return *this; } //! construct a field from subview_field (e.g. construct a field from a delayed subfield operation) template inline field::field(const subview_field& X) : n_rows(0) , n_cols(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint_this(this); this->operator=(X); } //! construct a field from subview_field (e.g. construct a field from a delayed subfield operation) template inline const field& field::operator=(const subview_field& X) { arma_extra_debug_sigprint(); subview_field::extract(*this, X); return *this; } //! construct the field with the specified number of elements, //! assuming a column-major layout template inline field::field(const uword n_elem_in) : n_rows(0) , n_cols(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint_this(this); init(n_elem_in, 1); } //! construct the field with the specified dimensions template inline field::field(const uword n_rows_in, const uword n_cols_in) : n_rows(0) , n_cols(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint_this(this); init(n_rows_in, n_cols_in); } //! change the field to have the specified number of elements, //! assuming a column-major layout (data is not preserved) template inline void field::set_size(const uword n_elem_in) { arma_extra_debug_sigprint(arma_boost::format("n_elem_in = %d") % n_elem_in); init(n_elem_in, 1); } //! change the field to have the specified dimensions (data is not preserved) template inline void field::set_size(const uword n_rows_in, const uword n_cols_in) { arma_extra_debug_sigprint(arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in); init(n_rows_in, n_cols_in); } //! change the field to have the specified dimensions (data is not preserved) template template inline void field::copy_size(const field& x) { arma_extra_debug_sigprint(); init(x.n_rows, x.n_cols); } //! linear element accessor (treats the field as a vector); no bounds check template arma_inline oT& field::operator[] (const uword i) { return (*mem[i]); } //! linear element accessor (treats the field as a vector); no bounds check template arma_inline const oT& field::operator[] (const uword i) const { return (*mem[i]); } //! linear element accessor (treats the field as a vector); no bounds check template arma_inline oT& field::at(const uword i) { return (*mem[i]); } //! linear element accessor (treats the field as a vector); no bounds check template arma_inline const oT& field::at(const uword i) const { return (*mem[i]); } //! linear element accessor (treats the field as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline oT& field::operator() (const uword i) { arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds"); return (*mem[i]); } //! linear element accessor (treats the field as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline const oT& field::operator() (const uword i) const { arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds"); return (*mem[i]); } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline oT& field::operator() (const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "field::operator(): index out of bounds"); return (*mem[in_row + in_col*n_rows]); } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline const oT& field::operator() (const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "field::operator(): index out of bounds"); return (*mem[in_row + in_col*n_rows]); } //! element accessor; no bounds check template arma_inline oT& field::at(const uword in_row, const uword in_col) { return (*mem[in_row + in_col*n_rows]); } //! element accessor; no bounds check template arma_inline const oT& field::at(const uword in_row, const uword in_col) const { return (*mem[in_row + in_col*n_rows]); } template inline field_injector< field > field::operator<<(const oT& val) { return field_injector< field >(*this, val); } template inline field_injector< field > field::operator<<(const injector_end_of_row<>& x) { return field_injector< field >(*this, x); } //! creation of subview_field (row of a field) template inline subview_field field::row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds" ); return subview_field(*this, row_num, 0, 1, n_cols); } //! creation of subview_field (row of a field) template inline const subview_field field::row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds" ); return subview_field(*this, row_num, 0, 1, n_cols); } //! creation of subview_field (column of a field) template inline subview_field field::col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds"); return subview_field(*this, 0, col_num, n_rows, 1); } //! creation of subview_field (column of a field) template inline const subview_field field::col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds"); return subview_field(*this, 0, col_num, n_rows, 1); } //! creation of subview_field (subfield comprised of specified rows) template inline subview_field field::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( ( (in_row1 > in_row2) || (in_row2 >= n_rows) ), "field::rows(): indicies out of bounds or incorrectly used" ); const uword sub_n_rows = in_row2 - in_row1 + 1; return subview_field(*this, in_row1, 0, sub_n_rows, n_cols); } //! creation of subview_field (subfield comprised of specified rows) template inline const subview_field field::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check ( ( (in_row1 > in_row2) || (in_row2 >= n_rows) ), "field::rows(): indicies out of bounds or incorrectly used" ); const uword sub_n_rows = in_row2 - in_row1 + 1; return subview_field(*this, in_row1, 0, sub_n_rows, n_cols); } //! creation of subview_field (subfield comprised of specified columns) template inline subview_field field::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( ( (in_col1 > in_col2) || (in_col2 >= n_cols) ), "field::cols(): indicies out of bounds or incorrectly used" ); const uword sub_n_cols = in_col2 - in_col1 + 1; return subview_field(*this, 0, in_col1, n_rows, sub_n_cols); } //! creation of subview_field (subfield comprised of specified columns) template inline const subview_field field::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( ( (in_col1 > in_col2) || (in_col2 >= n_cols) ), "field::cols(): indicies out of bounds or incorrectly used" ); const uword sub_n_cols = in_col2 - in_col1 + 1; return subview_field(*this, 0, in_col1, n_rows, sub_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline subview_field field::subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "field::subfield(): indices out of bounds or incorrectly used" ); const uword sub_n_rows = in_row2 - in_row1 + 1; const uword sub_n_cols = in_col2 - in_col1 + 1; return subview_field(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline const subview_field field::subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "field::subfield(): indices out of bounds or incorrectly used" ); const uword sub_n_rows = in_row2 - in_row1 + 1; const uword sub_n_cols = in_col2 - in_col1 + 1; return subview_field(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline subview_field field::subfield(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "field::subfield(): indices or size out of bounds" ); return subview_field(*this, in_row1, in_col1, s_n_rows, s_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline const subview_field field::subfield(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "field::subfield(): indices or size out of bounds" ); return subview_field(*this, in_row1, in_col1, s_n_rows, s_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline subview_field field::subfield(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword sub_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword sub_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "field::subfield(): indices out of bounds or incorrectly used" ); return subview_field(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline const subview_field field::subfield(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword sub_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword sub_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "field::subfield(): indices out of bounds or incorrectly used" ); return subview_field(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); } template inline subview_field field::operator()(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); return (*this).subfield(row_span, col_span); } template inline const subview_field field::operator()(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); return (*this).subfield(row_span, col_span); } //! print contents of the field (to the cout stream), //! optionally preceding with a user specified line of text. //! the field class preserves the stream's flags //! but the associated operator<< function for type oT //! may still modify the stream's parameters. //! NOTE: this function assumes that type oT can be printed, //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)" //! has been defined. template inline void field::print(const std::string extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this); } //! print contents of the field to a user specified stream, //! optionally preceding with a user specified line of text. //! the field class preserves the stream's flags //! but the associated operator<< function for type oT //! may still modify the stream's parameters. //! NOTE: this function assumes that type oT can be printed, //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)" //! has been defined. template inline void field::print(std::ostream& user_stream, const std::string extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print(user_stream, *this); } //! fill the field with an object template inline void field::fill(const oT& x) { arma_extra_debug_sigprint(); field& t = *this; for(uword i=0; i inline void field::reset() { arma_extra_debug_sigprint(); init(0,0); } //! reset each object template inline void field::reset_objects() { arma_extra_debug_sigprint(); field_aux::reset_objects(*this); } //! returns true if the field has no objects template arma_inline bool field::is_empty() const { return (n_elem == 0); } //! returns true if the given index is currently in range template arma_inline arma_warn_unused bool field::in_range(const uword i) const { return (i < n_elem); } //! returns true if the given start and end indices are currently in range template arma_inline arma_warn_unused bool field::in_range(const span& x) const { arma_extra_debug_sigprint(); if(x.whole == true) { return true; } else { const uword a = x.a; const uword b = x.b; return ( (a <= b) && (b < n_elem) ); } } //! returns true if the given location is currently in range template arma_inline arma_warn_unused bool field::in_range(const uword in_row, const uword in_col) const { return ( (in_row < n_rows) && (in_col < n_cols) ); } template arma_inline arma_warn_unused bool field::in_range(const span& row_span, const uword in_col) const { arma_extra_debug_sigprint(); if(row_span.whole == true) { return (in_col < n_cols); } else { const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) ); } } template arma_inline arma_warn_unused bool field::in_range(const uword in_row, const span& col_span) const { arma_extra_debug_sigprint(); if(col_span.whole == true) { return (in_row < n_rows); } else { const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) ); } } template arma_inline arma_warn_unused bool field::in_range(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) ); const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) ); return ( (rows_ok == true) && (cols_ok == true) ); } template arma_inline arma_warn_unused bool field::in_range(const uword in_row, const uword in_col, const SizeMat& s) const { const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; if( (in_row >= l_n_rows) || (in_col >= l_n_cols) || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) ) { return false; } else { return true; } } template inline bool field::save(const std::string name, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); std::string err_msg; const bool save_okay = field_aux::save(*this, name, type, err_msg); if( (print_status == true) && (save_okay == false) ) { if(err_msg.length() > 0) { arma_warn(true, "field::save(): ", err_msg, name); } else { arma_warn(true, "field::save(): couldn't write to ", name); } } return save_okay; } template inline bool field::save(std::ostream& os, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); std::string err_msg; const bool save_okay = field_aux::save(*this, os, type, err_msg); if( (print_status == true) && (save_okay == false) ) { if(err_msg.length() > 0) { arma_warn(true, "field::save(): ", err_msg, "[ostream]"); } else { arma_warn(true, "field::save(): couldn't write to [ostream]"); } } return save_okay; } template inline bool field::load(const std::string name, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); std::string err_msg; const bool load_okay = field_aux::load(*this, name, type, err_msg); if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_warn(true, "field::load(): ", err_msg, name); } else { arma_warn(true, "field::load(): couldn't read from ", name); } } if(load_okay == false) { (*this).reset(); } return load_okay; } template inline bool field::load(std::istream& is, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); std::string err_msg; const bool load_okay = field_aux::load(*this, is, type, err_msg); if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_warn(true, "field::load(): ", err_msg, "[istream]"); } else { arma_warn(true, "field::load(): couldn't read from [istream]"); } } if(load_okay == false) { (*this).reset(); } return load_okay; } template inline bool field::quiet_save(const std::string name, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(name, type, false); } template inline bool field::quiet_save(std::ostream& os, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(os, type, false); } template inline bool field::quiet_load(const std::string name, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(name, type, false); } template inline bool field::quiet_load(std::istream& is, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(is, type, false); } //! construct a field from a given field template inline void field::init(const field& x) { arma_extra_debug_sigprint(); if(this != &x) { const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; init(x_n_rows, x_n_cols); field& t = *this; for(uword ucol=0; ucol < x_n_cols; ++ucol) for(uword urow=0; urow < x_n_rows; ++urow) { t.at(urow,ucol) = x.at(urow,ucol); } } } //! internal field construction; if the requested size is small enough, memory from the stack is used. otherwise memory is allocated via 'new' template inline void field::init(const uword n_rows_in, const uword n_cols_in) { arma_extra_debug_sigprint( arma_boost::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in ); arma_debug_check ( ( ( (n_rows_in > ARMA_MAX_UHWORD) || (n_cols_in > ARMA_MAX_UHWORD) ) ? ( (float(n_rows_in) * float(n_cols_in)) > float(ARMA_MAX_UWORD) ) : false ), "field::init(): requested size is too large; suggest to enable ARMA_64BIT_WORD" ); const uword n_elem_new = n_rows_in * n_cols_in; if(n_elem == n_elem_new) { // delete_objects(); // create_objects(); access::rw(n_rows) = n_rows_in; access::rw(n_cols) = n_cols_in; } else { delete_objects(); if(n_elem > sizeof(mem_local)/sizeof(oT*) ) { delete [] mem; } if(n_elem_new <= sizeof(mem_local)/sizeof(oT*) ) { mem = mem_local; } else { mem = new(std::nothrow) oT* [n_elem_new]; arma_check_bad_alloc( (mem == 0), "field::init(): out of memory" ); } access::rw(n_elem) = n_elem_new; if(n_elem_new == 0) { access::rw(n_rows) = 0; access::rw(n_cols) = 0; } else { access::rw(n_rows) = n_rows_in; access::rw(n_cols) = n_cols_in; } create_objects(); } } template inline void field::delete_objects() { arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem ); for(uword i=0; i inline void field::create_objects() { arma_extra_debug_sigprint( arma_boost::format("n_elem = %d") % n_elem ); for(uword i=0; i inline field::iterator::iterator(field& in_M, const bool at_end) : M(in_M) , i( (at_end == false) ? 0 : in_M.n_elem ) { arma_extra_debug_sigprint(); } template inline oT& field::iterator::operator*() { return M[i]; } template inline typename field::iterator& field::iterator::operator++() { ++i; return *this; } template inline void field::iterator::operator++(int) { operator++(); } template inline typename field::iterator& field::iterator::operator--() { if(i > 0) { --i; } return *this; } template inline void field::iterator::operator--(int) { operator--(); } template inline bool field::iterator::operator!=(const typename field::iterator& X) const { return (i != X.i); } template inline bool field::iterator::operator==(const typename field::iterator& X) const { return (i == X.i); } template inline field::const_iterator::const_iterator(const field& in_M, const bool at_end) : M(in_M) , i( (at_end == false) ? 0 : in_M.n_elem ) { arma_extra_debug_sigprint(); } template inline field::const_iterator::const_iterator(const typename field::iterator& X) : M(X.M) , i(X.i) { arma_extra_debug_sigprint(); } template inline const oT& field::const_iterator::operator*() const { return M[i]; } template inline typename field::const_iterator& field::const_iterator::operator++() { ++i; return *this; } template inline void field::const_iterator::operator++(int) { operator++(); } template inline typename field::const_iterator& field::const_iterator::operator--() { if(i > 0) { --i; } return *this; } template inline void field::const_iterator::operator--(int) { operator--(); } template inline bool field::const_iterator::operator!=(const typename field::const_iterator& X) const { return (i != X.i); } template inline bool field::const_iterator::operator==(const typename field::const_iterator& X) const { return (i == X.i); } template inline typename field::iterator field::begin() { arma_extra_debug_sigprint(); return field::iterator(*this); } template inline typename field::const_iterator field::begin() const { arma_extra_debug_sigprint(); return field::const_iterator(*this); } template inline typename field::const_iterator field::cbegin() const { arma_extra_debug_sigprint(); return field::const_iterator(*this); } template inline typename field::iterator field::end() { arma_extra_debug_sigprint(); return field::iterator(*this, true); } template inline typename field::const_iterator field::end() const { arma_extra_debug_sigprint(); return field::const_iterator(*this, true); } template inline typename field::const_iterator field::cend() const { arma_extra_debug_sigprint(); return field::const_iterator(*this, true); } template inline void field::clear() { reset(); } template inline bool field::empty() const { return (n_elem == 0); } template inline uword field::size() const { return n_elem; } // // // template inline void field_aux::reset_objects(field& x) { arma_extra_debug_sigprint(); x.delete_objects(); x.create_objects(); } template inline void field_aux::reset_objects(field< Mat >& x) { arma_extra_debug_sigprint(); for(uword i=0; i inline void field_aux::reset_objects(field< Col >& x) { arma_extra_debug_sigprint(); for(uword i=0; i inline void field_aux::reset_objects(field< Row >& x) { arma_extra_debug_sigprint(); for(uword i=0; i inline void field_aux::reset_objects(field< Cube >& x) { arma_extra_debug_sigprint(); for(uword i=0; i& x) { arma_extra_debug_sigprint(); for(uword i=0; i inline bool field_aux::save(const field&, const std::string&, const file_type, std::string& err_msg) { arma_extra_debug_sigprint(); err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = "; return false; } template inline bool field_aux::save(const field&, std::ostream&, const file_type, std::string& err_msg) { arma_extra_debug_sigprint(); err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = "; return false; } template inline bool field_aux::load(field&, const std::string&, const file_type, std::string& err_msg) { arma_extra_debug_sigprint(); err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = "; return false; } template inline bool field_aux::load(field&, std::istream&, const file_type, std::string& err_msg) { arma_extra_debug_sigprint(); err_msg = " [sorry, saving/loading this type of field is currently not supported] filename = "; return false; } template inline bool field_aux::save(const field< Mat >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, name); break; case ppm_binary: return diskio::save_ppm_binary(x, name); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Mat >& x, std::ostream& os, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, os); break; case ppm_binary: return diskio::save_ppm_binary(x, os); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Mat >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, name, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, name, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, name, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Mat >& x, std::istream& is, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, is, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, is, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, is, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Col >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, name); break; case ppm_binary: return diskio::save_ppm_binary(x, name); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Col >& x, std::ostream& os, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, os); break; case ppm_binary: return diskio::save_ppm_binary(x, os); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Col >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, name, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, name, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, name, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Col >& x, std::istream& is, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, is, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, is, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, is, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Row >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, name, err_msg); break; case ppm_binary: return diskio::save_ppm_binary(x, name, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Row >& x, std::ostream& os, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, os, err_msg); break; case ppm_binary: return diskio::save_ppm_binary(x, os, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Row >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, name, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, name, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, name, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Row >& x, std::istream& is, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, is, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, is, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, is, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Cube >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, name, err_msg); break; case ppm_binary: return diskio::save_ppm_binary(x, name, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Cube >& x, std::ostream& os, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, os, err_msg); break; case ppm_binary: return diskio::save_ppm_binary(x, os, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Cube >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, name, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, name, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, name, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Cube >& x, std::istream& is, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, is, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, is, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, is, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } inline bool field_aux::save(const field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(type); err_msg.clear(); return diskio::save_std_string(x, name); } inline bool field_aux::save(const field< std::string >& x, std::ostream& os, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(type); err_msg.clear(); return diskio::save_std_string(x, os); } inline bool field_aux::load(field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(type); return diskio::load_std_string(x, name, err_msg); } inline bool field_aux::load(field< std::string >& x, std::istream& is, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(type); return diskio::load_std_string(x, is, err_msg); } #ifdef ARMA_EXTRA_FIELD_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_FIELD_MEAT) #endif //! @} RcppArmadillo/inst/include/armadillo_bits/mtOp_meat.hpp0000644000176000001440000000332212202101406023042 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup mtOp //! @{ template inline mtOp::mtOp(const T1& in_m) : m(in_m) { arma_extra_debug_sigprint(); } template inline mtOp::mtOp(const T1& in_m, const typename T1::elem_type in_aux) : m(in_m) , aux(in_aux) { arma_extra_debug_sigprint(); } template inline mtOp::mtOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline mtOp::mtOp(const T1& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux(in_aux) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline mtOp::mtOp(const char junk, const T1& in_m, const out_eT in_aux) : m(in_m) , aux_out_eT(in_aux) { arma_ignore(junk); arma_extra_debug_sigprint(); } template inline mtOp::~mtOp() { arma_extra_debug_sigprint(); } //! @} RcppArmadillo/inst/include/armadillo_bits/sp_auxlib_meat.hpp0000644000176000001440000003433412260430020024121 0ustar ripleyusers// Copyright (C) 2013 Ryan Curtin // Copyright (C) 2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup sp_auxlib //! @{ //! immediate eigendecomposition of symmetric real sparse object template inline bool sp_auxlib::eigs_sym(Col& eigval, Mat& eigvec, const SpBase& X, const uword n_eigvals) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_ARPACK) { // Make a sparse proxy object. SpProxy p(X.get_ref()); // Make sure it's square. arma_debug_check( (p.get_n_rows() != p.get_n_cols()), "eigs_sym(): given sparse matrix is not square"); // Make sure we aren't asking for every eigenvalue. arma_debug_check( (n_eigvals >= p.get_n_rows()), "eigs_sym(): n_eigvals must be less than the number of rows in the matrix"); // If the matrix is empty, the case is trivial. if (p.get_n_cols() == 0) // We already know n_cols == n_rows. { eigval.reset(); eigvec.reset(); return true; } // Set up variables that get used for neupd(). blas_int n, ncv, ldv, lworkl, info; eT tol; podarray resid, v, workd, workl; podarray iparam, ipntr; podarray rwork; // Not used in this case. run_aupd(n_eigvals, p, true /* sym, not gen */, n, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, rwork, info); if(info != 0) { return false; } // The process has converged, and now we need to recover the actual // eigenvectors using seupd(). blas_int rvec = 1; // .TRUE blas_int nev = n_eigvals; char howmny = 'A'; char bmat = 'I'; // We are considering the standard eigenvalue problem. char which[3] = "LM"; // We want the eigenvalues with the largest magnitude. podarray select(ncv); // Logical array of dimension NCV. blas_int ldz = n; // seupd() will output directly into the eigval and eigvec objects. eigval.set_size(n_eigvals); eigvec.set_size(n, n_eigvals); arpack::seupd(&rvec, &howmny, select.memptr(), eigval.memptr(), eigvec.memptr(), &ldz, (eT*) NULL, &bmat, &n, which, &nev, &tol, resid.memptr(), &ncv, v.memptr(), &ldv, iparam.memptr(), ipntr.memptr(), workd.memptr(), workl.memptr(), &lworkl, &info); // Check for errors. if(info != 0) { return false; // std::stringstream tmp; // tmp << "eigs_sym(): ARPACK error " << info << " in seupd()"; // arma_stop(tmp.str()); } return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_ignore(n_eigvals); arma_stop("eigs_sym(): use of ARPACK needs to be enabled"); return false; } #endif } //! immediate eigendecomposition of non-symmetric real sparse object template inline bool sp_auxlib::eigs_gen(Col< std::complex >& eigval, Mat< std::complex >& eigvec, const SpBase& X, const uword n_eigvals) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_ARPACK) { // Make a sparse proxy object. SpProxy p(X.get_ref()); // Make sure it's square. arma_debug_check( (p.get_n_rows() != p.get_n_cols()), "eigs_gen(): given sparse matrix is not square"); // Make sure we aren't asking for every eigenvalue. arma_debug_check( (n_eigvals >= p.get_n_rows()), "eigs_gen(): n_eigvals must be less than the number of rows in the matrix"); // If the matrix is empty, the case is trivial. if (p.get_n_cols() == 0) // We already know n_cols == n_rows. { eigval.reset(); eigvec.reset(); return true; } // Set up variables that get used for neupd(). blas_int n, ncv, ldv, lworkl, info; T tol; podarray resid, v, workd, workl; podarray iparam, ipntr; podarray rwork; // Not used in the real case. run_aupd(n_eigvals, p, false /* gen, not sym */, n, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, rwork, info); if(info != 0) { return false; } // The process has converged, and now we need to recover the actual // eigenvectors using neupd(). blas_int rvec = 1; // .TRUE blas_int nev = n_eigvals; char howmny = 'A'; char bmat = 'I'; // We are considering the standard eigenvalue problem. char which[3] = "LM"; // We want the eigenvalues with the largest magnitude. podarray select(ncv); // Logical array of dimension NCV. podarray dr(nev + 1); // Real array of dimension NEV + 1. podarray di(nev + 1); // Real array of dimension NEV + 1. podarray z(n * (nev + 1)); // Real N by NEV array if HOWMNY = 'A'. blas_int ldz = n; podarray workev(3 * ncv); arpack::neupd(&rvec, &howmny, select.memptr(), dr.memptr(), di.memptr(), z.memptr(), &ldz, (T*) NULL, (T*) NULL, workev.memptr(), &bmat, &n, which, &nev, &tol, resid.memptr(), &ncv, v.memptr(), &ldv, iparam.memptr(), ipntr.memptr(), workd.memptr(), workl.memptr(), &lworkl, rwork.memptr(), &info); // Check for errors. if(info != 0) { return false; // std::stringstream tmp; // tmp << "eigs_gen(): ARPACK error " << info << " in neupd()"; // arma_stop(tmp.str()); } // Put it into the outputs. eigval.set_size(n_eigvals); eigvec.set_size(n, n_eigvals); for (uword i = 0; i < n_eigvals; ++i) { eigval[i] = std::complex(dr[i], di[i]); } // Now recover the eigenvectors. for (uword i = 0; i < n_eigvals; ++i) { // ARPACK ?neupd lays things out kinda odd in memory; so does LAPACK // ?geev (see auxlib::eig_gen()). if ((i < n_eigvals - 1) && (eigval[i] == std::conj(eigval[i + 1]))) { for (uword j = 0; j < n; ++j) { eigvec.at(j, i) = std::complex(z[n * i + j], z[n * (i + 1) + j]); eigvec.at(j, i + 1) = std::complex(z[n * i + j], -z[n * (i + 1) + j]); } ++i; // Skip the next one. } else if ((i == n_eigvals - 1) && (std::complex(eigval[i]).imag() != 0.0)) { // We don't have the matched conjugate eigenvalue. for (uword j = 0; j < n; ++j) { eigvec.at(j, i) = std::complex(z[n * i + j], z[n * (i + 1) + j]); } } else { // The eigenvector is entirely real. for (uword j = 0; j < n; ++j) { eigvec.at(j, i) = std::complex(z[n * i + j], T(0)); } } } return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_ignore(n_eigvals); arma_stop("eigs_gen(): use of ARPACK needs to be enabled"); return false; } #endif } //! immediate eigendecomposition of non-symmetric complex sparse object template inline bool sp_auxlib::eigs_gen(Col< std::complex >& eigval, Mat< std::complex >& eigvec, const SpBase< std::complex, T1>& X, const uword n_eigvals) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_ARPACK) { // Make a sparse proxy object. SpProxy p(X.get_ref()); // Make sure it's square. arma_debug_check( (p.get_n_rows() != p.get_n_cols()), "eigs_gen(): given sparse matrix is not square"); // Make sure we aren't asking for every eigenvalue. arma_debug_check( (n_eigvals >= p.get_n_rows()), "eigs_gen(): n_eigvals must be less than the number of rows in the matrix"); // If the matrix is empty, the case is trivial. if (p.get_n_cols() == 0) // We already know n_cols == n_rows. { eigval.reset(); eigvec.reset(); return true; } // Set up variables that get used for neupd(). blas_int n, ncv, ldv, lworkl, info; T tol; podarray< std::complex > resid, v, workd, workl; podarray iparam, ipntr; podarray rwork; run_aupd(n_eigvals, p, false /* gen, not sym */, n, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, rwork, info); if(info != 0) { return false; } // The process has converged, and now we need to recover the actual // eigenvectors using neupd(). blas_int rvec = 1; // .TRUE blas_int nev = n_eigvals; char howmny = 'A'; char bmat = 'I'; // We are considering the standard eigenvalue problem. char which[3] = "LM"; // We want the eigenvalues with the largest magnitude. podarray select(ncv); // Logical array of dimension NCV. podarray > d(nev + 1); // Real array of dimension NEV + 1. podarray > z(n * nev); // Real N by NEV array if HOWMNY = 'A'. blas_int ldz = n; podarray > workev(2 * ncv); // Prepare the outputs; neupd() will write directly to them. eigval.set_size(n_eigvals); eigvec.set_size(n, n_eigvals); std::complex sigma; arpack::neupd(&rvec, &howmny, select.memptr(), eigval.memptr(), (std::complex*) NULL, eigvec.memptr(), &ldz, (std::complex*) &sigma, (std::complex*) NULL, workev.memptr(), &bmat, &n, which, &nev, &tol, resid.memptr(), &ncv, v.memptr(), &ldv, iparam.memptr(), ipntr.memptr(), workd.memptr(), workl.memptr(), &lworkl, rwork.memptr(), &info); // Check for errors. if(info != 0) { return false; // std::stringstream tmp; // tmp << "eigs_gen(): ARPACK error " << info << " in neupd()"; // arma_stop(tmp.str()); } return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_ignore(n_eigvals); arma_stop("eigs_gen(): use of ARPACK needs to be enabled"); return false; } #endif } template inline void sp_auxlib::run_aupd ( const uword n_eigvals, const SpProxy& p, const bool sym, blas_int& n, eT& tol, podarray& resid, blas_int& ncv, podarray& v, blas_int& ldv, podarray& iparam, podarray& ipntr, podarray& workd, podarray& workl, blas_int& lworkl, podarray& rwork, blas_int& info ) { #if defined(ARMA_USE_ARPACK) { // ARPACK provides a "reverse communication interface" which is an // entertainingly archaic FORTRAN software engineering technique that // basically means that we call saupd()/naupd() and it tells us with some // return code what we need to do next (usually a matrix-vector product) and // then call it again. So this results in some type of iterative process // where we call saupd()/naupd() many times. blas_int ido = 0; // This must be 0 for the first call. char bmat = 'I'; // We are considering the standard eigenvalue problem. n = p.get_n_rows(); // The size of the matrix. char which[3] = "LM"; // We want the eigenvalues with the largest magnitude. blas_int nev = n_eigvals; tol = std::numeric_limits::epsilon(); // Machine epsilon as tolerance. resid.set_size(n); // "NCV must satisfy the two inequalities 2 <= NCV-NEV and NCV <= N". // "It is recommended that NCV >= 2 * NEV". ncv = (2 * nev < n) ? 2 * nev : ((nev + 2 < n) ? nev + 2 : n); v.set_size(n * ncv); // Array N by NCV (output). rwork.set_size(ncv); // Work array of size NCV for complex calls. ldv = n; // "Leading dimension of V exactly as declared in the calling program." // IPARAM: integer array of length 11. iparam.zeros(11); iparam(0) = 1; // Exact shifts (not provided by us). iparam(2) = 1000; // Maximum iterations; all the examples use 300, but they // were written in the ancient times. iparam(6) = 1; // Mode 1: A * x = lambda * x. // IPNTR: integer array of length 14 (output). ipntr.set_size(14); // Real work array used in the basic Arnoldi iteration for reverse // communication. workd.set_size(3 * n); // lworkl must be at least 3 * NCV^2 + 6 * NCV. lworkl = 3 * (ncv * ncv) + 6 * ncv; // Real work array of length lworkl. workl.set_size(lworkl); info = 0; // Set to 0 initially to use random initial vector. // All the parameters have been set or created. Time to loop a lot. while (ido != 99) { // Call saupd() or naupd() with the current parameters. if (sym) arpack::saupd(&ido, &bmat, &n, which, &nev, &tol, resid.memptr(), &ncv, v.memptr(), &ldv, iparam.memptr(), ipntr.memptr(), workd.memptr(), workl.memptr(), &lworkl, &info); else arpack::naupd(&ido, &bmat, &n, which, &nev, &tol, resid.memptr(), &ncv, v.memptr(), &ldv, iparam.memptr(), ipntr.memptr(), workd.memptr(), workl.memptr(), &lworkl, rwork.memptr(), &info); // What do we do now? switch (ido) { case -1: case 1: { // We need to calculate the matrix-vector multiplication y = OP * x // where x is of length n and starts at workd(ipntr(0)), and y is of // length n and starts at workd(ipntr(1)). // operator*(sp_mat, vec) doesn't properly put the result into the // right place so we'll just reimplement it here for now... // Set the output to point at the right memory. We have to subtract // one from FORTRAN pointers... Col out(workd.memptr() + ipntr(1) - 1, n, false /* don't copy */); // Set the input to point at the right memory. Col in(workd.memptr() + ipntr(0) - 1, n, false /* don't copy */); out.zeros(); typename SpProxy::const_iterator_type x_it = p.begin(); typename SpProxy::const_iterator_type x_it_end = p.end(); while(x_it != x_it_end) { out[x_it.row()] += (*x_it) * in[x_it.col()]; ++x_it; } // No need to modify memory further since it was all done in-place. break; } case 99: // Nothing to do here, things have converged. break; default: { return; // Parent frame can look at the value of info. } } } // The process has ended; check the return code. if (info != 0 && info != 1) { return; // Parent frame can look at the value of info. } } #endif } RcppArmadillo/inst/include/armadillo_bits/op_diagvec_meat.hpp0000644000176000001440000000550412200631217024235 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_diagvec //! @{ template inline void op_diagvec::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword a = X.aux_uword_a; const uword b = X.aux_uword_b; const uword row_offset = (b > 0) ? a : 0; const uword col_offset = (b == 0) ? a : 0; const Proxy P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "diagvec(): requested diagonal is out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); if(is_Mat::stored_type>::value) { op_diagvec::apply_unwrap(out, P.Q, row_offset, col_offset, len); } else { if(P.is_alias(out) == false) { op_diagvec::apply_proxy(out, P, row_offset, col_offset, len); } else { Mat tmp; op_diagvec::apply_proxy(tmp, P, row_offset, col_offset, len); out.steal_mem(tmp); } } } template arma_hot inline void op_diagvec::apply_unwrap(Mat& out, const T1& X, const uword row_offset, const uword col_offset, const uword len) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp_A(X, out); const Mat& A = tmp_A.M; out.set_size(len, 1); eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < len; i+=2, j+=2) { const eT tmp_i = A.at( i + row_offset, i + col_offset ); const eT tmp_j = A.at( j + row_offset, j + col_offset ); out_mem[i] = tmp_i; out_mem[j] = tmp_j; } if(i < len) { out_mem[i] = A.at( i + row_offset, i + col_offset ); } } template arma_hot inline void op_diagvec::apply_proxy(Mat& out, const Proxy& P, const uword row_offset, const uword col_offset, const uword len) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; out.set_size(len, 1); eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < len; i+=2, j+=2) { const eT tmp_i = P.at( i + row_offset, i + col_offset ); const eT tmp_j = P.at( j + row_offset, j + col_offset ); out_mem[i] = tmp_i; out_mem[j] = tmp_j; } if(i < len) { out_mem[i] = P.at( i + row_offset, i + col_offset ); } } //! @} RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp0000644000176000001440000027132112265411417023026 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Cube //! @{ template inline Cube::~Cube() { arma_extra_debug_sigprint_this(this); delete_mat(); if(mem_state == 0) { if(n_elem > Cube_prealloc::mem_n_elem) { memory::release( access::rw(mem) ); } } if(arma_config::debug == true) { // try to expose buggy user code that accesses deleted objects access::rw(mat_ptrs) = 0; access::rw(mem) = 0; } arma_type_check(( is_supported_elem_type::value == false )); } template inline Cube::Cube() : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); } //! construct the cube to have user specified dimensions template inline Cube::Cube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) : n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem_slice(in_n_rows*in_n_cols) , n_slices(in_n_slices) , n_elem(in_n_rows*in_n_cols*in_n_slices) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); init_cold(); } //! construct the cube to have user specified dimensions and fill with specified pattern template template inline Cube::Cube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices, const fill::fill_class&) : n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem_slice(in_n_rows*in_n_cols) , n_slices(in_n_slices) , n_elem(in_n_rows*in_n_cols*in_n_slices) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); init_cold(); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); if(is_same_type::yes) { arma_debug_check(true, "Cube::Cube(): unsupported fill type"); } } #if defined(ARMA_USE_CXX11) template inline Cube::Cube(Cube&& in_cube) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint(arma_boost::format("this = %x in_cube = %x") % this % &in_cube); (*this).steal_mem(in_cube); } template inline const Cube& Cube::operator=(Cube&& in_cube) { arma_extra_debug_sigprint(arma_boost::format("this = %x in_cube = %x") % this % &in_cube); (*this).steal_mem(in_cube); return *this; } #endif template inline void Cube::init_cold() { arma_extra_debug_sigprint( arma_boost::format("n_rows = %d, n_cols = %d, n_slices = %d") % n_rows % n_cols % n_slices ); arma_debug_check ( ( ( (n_rows > 0x0FFF) || (n_cols > 0x0FFF) || (n_slices > 0xFF) ) ? ( (float(n_rows) * float(n_cols) * float(n_slices)) > float(ARMA_MAX_UWORD) ) : false ), "Cube::init(): requested size is too large; suggest to enable ARMA_64BIT_WORD" ); if(n_elem <= Cube_prealloc::mem_n_elem) { arma_extra_debug_print("Cube::init(): using local memory"); access::rw(mem) = mem_local; } else { arma_extra_debug_print("Cube::init(): allocating memory"); access::rw(mem) = memory::acquire(n_elem); } if(n_elem == 0) { access::rw(n_rows) = 0; access::rw(n_cols) = 0; access::rw(n_elem_slice) = 0; access::rw(n_slices) = 0; } else { create_mat(); } } //! internal cube construction; if the requested size is small enough, memory from the stack is used. //! otherwise memory is allocated via 'new' template inline void Cube::init_warm(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) { arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols = %d, in_n_slices = %d") % in_n_rows % in_n_cols % in_n_slices ); if( (n_rows == in_n_rows) && (n_cols == in_n_cols) && (n_slices == in_n_slices) ) { return; } const uword t_mem_state = mem_state; bool err_state = false; char* err_msg = 0; arma_debug_set_error ( err_state, err_msg, (t_mem_state == 3), "Cube::init(): size is fixed and hence cannot be changed" ); arma_debug_set_error ( err_state, err_msg, ( ( (in_n_rows > 0x0FFF) || (in_n_cols > 0x0FFF) || (in_n_slices > 0xFF) ) ? ( (float(in_n_rows) * float(in_n_cols) * float(in_n_slices)) > float(ARMA_MAX_UWORD) ) : false ), "Cube::init(): requested size is too large" ); arma_debug_check(err_state, err_msg); const uword old_n_elem = n_elem; const uword new_n_elem = in_n_rows * in_n_cols * in_n_slices; if(old_n_elem == new_n_elem) { delete_mat(); if(new_n_elem > 0) { access::rw(n_rows) = in_n_rows; access::rw(n_cols) = in_n_cols; access::rw(n_elem_slice) = in_n_rows*in_n_cols; access::rw(n_slices) = in_n_slices; create_mat(); } } else { arma_debug_check( (t_mem_state == 2), "Cube::init(): requested size is not compatible with the size of auxiliary memory" ); delete_mat(); if(t_mem_state == 0) { if(n_elem > Cube_prealloc::mem_n_elem ) { arma_extra_debug_print("Cube::init(): freeing memory"); memory::release( access::rw(mem) ); } } access::rw(mem_state) = 0; if(new_n_elem <= Cube_prealloc::mem_n_elem) { arma_extra_debug_print("Cube::init(): using local memory"); access::rw(mem) = mem_local; } else { arma_extra_debug_print("Cube::init(): allocating memory"); access::rw(mem) = memory::acquire(new_n_elem); } if(new_n_elem > 0) { access::rw(n_rows) = in_n_rows; access::rw(n_cols) = in_n_cols; access::rw(n_elem_slice) = in_n_rows*in_n_cols; access::rw(n_slices) = in_n_slices; access::rw(n_elem) = new_n_elem; create_mat(); } } if(new_n_elem == 0) { access::rw(n_rows) = 0; access::rw(n_cols) = 0; access::rw(n_elem_slice) = 0; access::rw(n_slices) = 0; access::rw(n_elem) = 0; } } //! for constructing a complex cube out of two non-complex cubes template template inline void Cube::init ( const BaseCube::pod_type,T1>& X, const BaseCube::pod_type,T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type T; arma_type_check(( is_complex::value == false )); //!< compile-time abort if eT is not std::complex arma_type_check(( is_complex< T>::value == true )); //!< compile-time abort if T is std::complex arma_type_check(( is_same_type< std::complex, eT >::no )); //!< compile-time abort if types are not compatible const ProxyCube PX(X.get_ref()); const ProxyCube PY(Y.get_ref()); arma_debug_assert_same_size(PX, PY, "Cube()"); const uword local_n_rows = PX.get_n_rows(); const uword local_n_cols = PX.get_n_cols(); const uword local_n_slices = PX.get_n_slices(); init_warm(local_n_rows, local_n_cols, local_n_slices); eT* out_mem = (*this).memptr(); const bool prefer_at_accessor = ( ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor ); if(prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type1; typedef typename ProxyCube::ea_type ea_type2; const uword N = n_elem; ea_type1 A = PX.get_ea(); ea_type2 B = PY.get_ea(); for(uword i=0; i(A[i], B[i]); } } else { for(uword uslice = 0; uslice < local_n_slices; ++uslice) for(uword ucol = 0; ucol < local_n_cols; ++ucol ) for(uword urow = 0; urow < local_n_rows; ++urow ) { *out_mem = std::complex( PX.at(urow,ucol,uslice), PY.at(urow,ucol,uslice) ); out_mem++; } } } template inline void Cube::delete_mat() { arma_extra_debug_sigprint(); for(uword uslice = 0; uslice < n_slices; ++uslice) { delete access::rw(mat_ptrs[uslice]); } if(mem_state <= 2) { if(n_slices > Cube_prealloc::mat_ptrs_size) { delete [] mat_ptrs; } } } template inline void Cube::create_mat() { arma_extra_debug_sigprint(); if(mem_state <= 2) { if(n_slices <= Cube_prealloc::mat_ptrs_size) { access::rw(mat_ptrs) = const_cast< const Mat** >(mat_ptrs_local); } else { access::rw(mat_ptrs) = new(std::nothrow) const Mat*[n_slices]; arma_check_bad_alloc( (mat_ptrs == 0), "Cube::create_mat(): out of memory" ); } } for(uword uslice = 0; uslice < n_slices; ++uslice) { mat_ptrs[uslice] = new Mat('j', slice_memptr(uslice), n_rows, n_cols); } } //! Set the cube to be equal to the specified scalar. //! NOTE: the size of the cube will be 1x1x1 template arma_inline const Cube& Cube::operator=(const eT val) { arma_extra_debug_sigprint(); init_warm(1,1,1); access::rw(mem[0]) = val; return *this; } //! In-place addition of a scalar to all elements of the cube template arma_inline const Cube& Cube::operator+=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_plus( memptr(), val, n_elem ); return *this; } //! In-place subtraction of a scalar from all elements of the cube template arma_inline const Cube& Cube::operator-=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_minus( memptr(), val, n_elem ); return *this; } //! In-place multiplication of all elements of the cube with a scalar template arma_inline const Cube& Cube::operator*=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_mul( memptr(), val, n_elem ); return *this; } //! In-place division of all elements of the cube with a scalar template arma_inline const Cube& Cube::operator/=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_div( memptr(), val, n_elem ); return *this; } //! construct a cube from a given cube template inline Cube::Cube(const Cube& x) : n_rows(x.n_rows) , n_cols(x.n_cols) , n_elem_slice(x.n_elem_slice) , n_slices(x.n_slices) , n_elem(x.n_elem) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint(arma_boost::format("this = %x in_cube = %x") % this % &x); init_cold(); arrayops::copy( memptr(), x.mem, n_elem ); } //! construct a cube from a given cube template inline const Cube& Cube::operator=(const Cube& x) { arma_extra_debug_sigprint(arma_boost::format("this = %x in_cube = %x") % this % &x); if(this != &x) { init_warm(x.n_rows, x.n_cols, x.n_slices); arrayops::copy( memptr(), x.mem, n_elem ); } return *this; } //! construct a cube from a given auxiliary array of eTs. //! if copy_aux_mem is true, new memory is allocated and the array is copied. //! if copy_aux_mem is false, the auxiliary array is used directly (without allocating memory and copying). //! note that in the latter case //! the default is to copy the array. template inline Cube::Cube(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices, const bool copy_aux_mem, const bool strict) : n_rows ( aux_n_rows ) , n_cols ( aux_n_cols ) , n_elem_slice( aux_n_rows*aux_n_cols ) , n_slices ( aux_n_slices ) , n_elem ( aux_n_rows*aux_n_cols*aux_n_slices ) , mem_state ( copy_aux_mem ? 0 : (strict ? 2 : 1) ) , mat_ptrs ( 0 ) , mem ( copy_aux_mem ? 0 : aux_mem ) { arma_extra_debug_sigprint_this(this); if(copy_aux_mem == true) { init_cold(); arrayops::copy( memptr(), aux_mem, n_elem ); } else { create_mat(); } } //! construct a cube from a given auxiliary read-only array of eTs. //! the array is copied. template inline Cube::Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices) : n_rows(aux_n_rows) , n_cols(aux_n_cols) , n_elem_slice(aux_n_rows*aux_n_cols) , n_slices(aux_n_slices) , n_elem(aux_n_rows*aux_n_cols*aux_n_slices) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); init_cold(); arrayops::copy( memptr(), aux_mem, n_elem ); } //! in-place cube addition template inline const Cube& Cube::operator+=(const Cube& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "addition"); arrayops::inplace_plus( memptr(), m.memptr(), n_elem ); return *this; } //! in-place cube subtraction template inline const Cube& Cube::operator-=(const Cube& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "subtraction"); arrayops::inplace_minus( memptr(), m.memptr(), n_elem ); return *this; } //! in-place element-wise cube multiplication template inline const Cube& Cube::operator%=(const Cube& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "element-wise multiplication"); arrayops::inplace_mul( memptr(), m.memptr(), n_elem ); return *this; } //! in-place element-wise cube division template inline const Cube& Cube::operator/=(const Cube& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "element-wise division"); arrayops::inplace_div( memptr(), m.memptr(), n_elem ); return *this; } //! for constructing a complex cube out of two non-complex cubes template template inline Cube::Cube ( const BaseCube::pod_type,T1>& A, const BaseCube::pod_type,T2>& B ) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); init(A,B); } //! construct a cube from a subview_cube instance (e.g. construct a cube from a delayed subcube operation) template inline Cube::Cube(const subview_cube& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem_slice(X.n_elem_slice) , n_slices(X.n_slices) , n_elem(X.n_elem) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); init_cold(); subview_cube::extract(*this, X); } //! construct a cube from a subview_cube instance (e.g. construct a cube from a delayed subcube operation) template inline const Cube& Cube::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); const bool alias = (this == &(X.m)); if(alias == false) { init_warm(X.n_rows, X.n_cols, X.n_slices); subview_cube::extract(*this, X); } else { Cube tmp(X); steal_mem(tmp); } return *this; } //! in-place cube addition (using a subcube on the right-hand-side) template inline const Cube& Cube::operator+=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::plus_inplace(*this, X); return *this; } //! in-place cube subtraction (using a subcube on the right-hand-side) template inline const Cube& Cube::operator-=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::minus_inplace(*this, X); return *this; } //! in-place element-wise cube mutiplication (using a subcube on the right-hand-side) template inline const Cube& Cube::operator%=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::schur_inplace(*this, X); return *this; } //! in-place element-wise cube division (using a subcube on the right-hand-side) template inline const Cube& Cube::operator/=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::div_inplace(*this, X); return *this; } //! provide the reference to the matrix representing a single slice template arma_inline Mat& Cube::slice(const uword in_slice) { arma_extra_debug_sigprint(); arma_debug_check ( (in_slice >= n_slices), "Cube::slice(): index out of bounds" ); return const_cast< Mat& >( *(mat_ptrs[in_slice]) ); } //! provide the reference to the matrix representing a single slice template arma_inline const Mat& Cube::slice(const uword in_slice) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_slice >= n_slices), "Cube::slice(): index out of bounds" ); return *(mat_ptrs[in_slice]); } //! creation of subview_cube (subcube comprised of specified slices) template arma_inline subview_cube Cube::slices(const uword in_slice1, const uword in_slice2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_slice1 > in_slice2) || (in_slice2 >= n_slices), "Cube::slices(): indices out of bounds or incorrectly used" ); const uword subcube_n_slices = in_slice2 - in_slice1 + 1; return subview_cube(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n_slices); } //! creation of subview_cube (subcube comprised of specified slices) template arma_inline const subview_cube Cube::slices(const uword in_slice1, const uword in_slice2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_slice1 > in_slice2) || (in_slice2 >= n_slices), "Cube::rows(): indices out of bounds or incorrectly used" ); const uword subcube_n_slices = in_slice2 - in_slice1 + 1; return subview_cube(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n_slices); } //! creation of subview_cube (generic subcube) template arma_inline subview_cube Cube::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) || (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices), "Cube::subcube(): indices out of bounds or incorrectly used" ); const uword subcube_n_rows = in_row2 - in_row1 + 1; const uword subcube_n_cols = in_col2 - in_col1 + 1; const uword subcube_n_slices = in_slice2 - in_slice1 + 1; return subview_cube(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices); } //! creation of subview_cube (generic subcube) template arma_inline const subview_cube Cube::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) || (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices), "Cube::subcube(): indices out of bounds or incorrectly used" ); const uword subcube_n_rows = in_row2 - in_row1 + 1; const uword subcube_n_cols = in_col2 - in_col1 + 1; const uword subcube_n_slices = in_slice2 - in_slice1 + 1; return subview_cube(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices); } //! creation of subview_cube (generic subcube) template inline subview_cube Cube::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword l_n_slices = n_slices; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; const uword s_n_slices = s.n_slices; arma_debug_check ( ( in_row1 >= l_n_rows) || ( in_col1 >= l_n_cols) || ( in_slice1 >= l_n_slices) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols) || ((in_slice1 + s_n_slices) > l_n_slices), "Cube::subcube(): indices or size out of bounds" ); return subview_cube(*this, in_row1, in_col1, in_slice1, s_n_rows, s_n_cols, s_n_slices); } //! creation of subview_cube (generic subcube) template inline const subview_cube Cube::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword l_n_slices = n_slices; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; const uword s_n_slices = s.n_slices; arma_debug_check ( ( in_row1 >= l_n_rows) || ( in_col1 >= l_n_cols) || ( in_slice1 >= l_n_slices) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols) || ((in_slice1 + s_n_slices) > l_n_slices), "Cube::subcube(): indices or size out of bounds" ); return subview_cube(*this, in_row1, in_col1, in_slice1, s_n_rows, s_n_cols, s_n_slices); } //! creation of subview_cube (generic subcube) template inline subview_cube Cube::subcube(const span& row_span, const span& col_span, const span& slice_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const bool slice_all = slice_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; const uword in_slice1 = slice_all ? 0 : slice_span.a; const uword in_slice2 = slice_span.b; const uword subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) || ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) ) , "Cube::subcube(): indices out of bounds or incorrectly used" ); return subview_cube(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices); } //! creation of subview_cube (generic subcube) template inline const subview_cube Cube::subcube(const span& row_span, const span& col_span, const span& slice_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const bool slice_all = slice_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; const uword in_slice1 = slice_all ? 0 : slice_span.a; const uword in_slice2 = slice_span.b; const uword subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) || ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) ) , "Cube::subcube(): indices out of bounds or incorrectly used" ); return subview_cube(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices); } template inline subview_cube Cube::operator()(const span& row_span, const span& col_span, const span& slice_span) { arma_extra_debug_sigprint(); return (*this).subcube(row_span, col_span, slice_span); } template inline const subview_cube Cube::operator()(const span& row_span, const span& col_span, const span& slice_span) const { arma_extra_debug_sigprint(); return (*this).subcube(row_span, col_span, slice_span); } template inline subview_cube Cube::operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) { arma_extra_debug_sigprint(); return (*this).subcube(in_row1, in_col1, in_slice1, s); } template inline const subview_cube Cube::operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const { arma_extra_debug_sigprint(); return (*this).subcube(in_row1, in_col1, in_slice1, s); } template arma_inline subview_cube Cube::tube(const uword in_row1, const uword in_col1) { arma_extra_debug_sigprint(); arma_debug_check ( ((in_row1 >= n_rows) || (in_col1 >= n_cols)), "Cube::tube(): indices out of bounds" ); return subview_cube(*this, in_row1, in_col1, 0, 1, 1, n_slices); } template arma_inline const subview_cube Cube::tube(const uword in_row1, const uword in_col1) const { arma_extra_debug_sigprint(); arma_debug_check ( ((in_row1 >= n_rows) || (in_col1 >= n_cols)), "Cube::tube(): indices out of bounds" ); return subview_cube(*this, in_row1, in_col1, 0, 1, 1, n_slices); } template arma_inline subview_cube Cube::tube(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "Cube::tube(): indices out of bounds or incorrectly used" ); const uword subcube_n_rows = in_row2 - in_row1 + 1; const uword subcube_n_cols = in_col2 - in_col1 + 1; return subview_cube(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices); } template arma_inline const subview_cube Cube::tube(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "Cube::tube(): indices out of bounds or incorrectly used" ); const uword subcube_n_rows = in_row2 - in_row1 + 1; const uword subcube_n_cols = in_col2 - in_col1 + 1; return subview_cube(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices); } template arma_inline subview_cube Cube::tube(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "Cube::tube(): indices or size out of bounds" ); return subview_cube(*this, in_row1, in_col1, 0, s_n_rows, s_n_cols, n_slices); } template arma_inline const subview_cube Cube::tube(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "Cube::tube(): indices or size out of bounds" ); return subview_cube(*this, in_row1, in_col1, 0, s_n_rows, s_n_cols, n_slices); } template inline subview_cube Cube::tube(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Cube::tube(): indices out of bounds or incorrectly used" ); return subview_cube(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices); } template inline const subview_cube Cube::tube(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Cube::tube(): indices out of bounds or incorrectly used" ); return subview_cube(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices); } template template arma_inline subview_elem1 Cube::elem(const Base& a) { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline const subview_elem1 Cube::elem(const Base& a) const { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline subview_elem1 Cube::operator()(const Base& a) { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline const subview_elem1 Cube::operator()(const Base& a) const { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } //! remove specified slice template inline void Cube::shed_slice(const uword slice_num) { arma_extra_debug_sigprint(); arma_debug_check( slice_num >= n_slices, "Cube::shed_slice(): index out of bounds"); shed_slices(slice_num, slice_num); } //! remove specified slices template inline void Cube::shed_slices(const uword in_slice1, const uword in_slice2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_slice1 > in_slice2) || (in_slice2 >= n_slices), "Cube::shed_slices(): indices out of bounds or incorrectly used" ); const uword n_keep_front = in_slice1; const uword n_keep_back = n_slices - (in_slice2 + 1); Cube X(n_rows, n_cols, n_keep_front + n_keep_back); if(n_keep_front > 0) { X.slices( 0, (n_keep_front-1) ) = slices( 0, (in_slice1-1) ); } if(n_keep_back > 0) { X.slices( n_keep_front, (n_keep_front+n_keep_back-1) ) = slices( (in_slice2+1), (n_slices-1) ); } steal_mem(X); } //! insert N slices at the specified slice position, //! optionally setting the elements of the inserted slices to zero template inline void Cube::insert_slices(const uword slice_num, const uword N, const bool set_to_zero) { arma_extra_debug_sigprint(); const uword t_n_slices = n_slices; const uword A_n_slices = slice_num; const uword B_n_slices = t_n_slices - slice_num; // insertion at slice_num == n_slices is in effect an append operation arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): index out of bounds"); if(N > 0) { Cube out(n_rows, n_cols, t_n_slices + N); if(A_n_slices > 0) { out.slices(0, A_n_slices-1) = slices(0, A_n_slices-1); } if(B_n_slices > 0) { out.slices(slice_num + N, t_n_slices + N - 1) = slices(slice_num, t_n_slices-1); } if(set_to_zero == true) { //out.slices(slice_num, slice_num + N - 1).zeros(); for(uword i=slice_num; i < (slice_num + N); ++i) { out.slice(i).zeros(); } } steal_mem(out); } } //! insert the given object at the specified slice position; //! the given object must have the same number of rows and columns as the cube template template inline void Cube::insert_slices(const uword slice_num, const BaseCube& X) { arma_extra_debug_sigprint(); const unwrap_cube tmp(X.get_ref()); const Cube& C = tmp.M; const uword N = C.n_slices; const uword t_n_slices = n_slices; const uword A_n_slices = slice_num; const uword B_n_slices = t_n_slices - slice_num; // insertion at slice_num == n_slices is in effect an append operation arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): index out of bounds"); arma_debug_check ( ( (C.n_rows != n_rows) || (C.n_cols != n_cols) ), "Cube::insert_slices(): given object has incompatible dimensions" ); if(N > 0) { Cube out(n_rows, n_cols, t_n_slices + N); if(A_n_slices > 0) { out.slices(0, A_n_slices-1) = slices(0, A_n_slices-1); } if(B_n_slices > 0) { out.slices(slice_num + N, t_n_slices + N - 1) = slices(slice_num, t_n_slices - 1); } out.slices(slice_num, slice_num + N - 1) = C; steal_mem(out); } } //! create a cube from OpCube, i.e. run the previously delayed unary operations template template inline Cube::Cube(const GenCube& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem_slice(X.n_rows*X.n_cols) , n_slices(X.n_slices) , n_elem(X.n_rows*X.n_cols*X.n_slices) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); init_cold(); X.apply(*this); } template template inline const Cube& Cube::operator=(const GenCube& X) { arma_extra_debug_sigprint(); init_warm(X.n_rows, X.n_cols, X.n_slices); X.apply(*this); return *this; } template template inline const Cube& Cube::operator+=(const GenCube& X) { arma_extra_debug_sigprint(); X.apply_inplace_plus(*this); return *this; } template template inline const Cube& Cube::operator-=(const GenCube& X) { arma_extra_debug_sigprint(); X.apply_inplace_minus(*this); return *this; } template template inline const Cube& Cube::operator%=(const GenCube& X) { arma_extra_debug_sigprint(); X.apply_inplace_schur(*this); return *this; } template template inline const Cube& Cube::operator/=(const GenCube& X) { arma_extra_debug_sigprint(); X.apply_inplace_div(*this); return *this; } //! create a cube from OpCube, i.e. run the previously delayed unary operations template template inline Cube::Cube(const OpCube& X) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); op_type::apply(*this, X); } //! create a cube from OpCube, i.e. run the previously delayed unary operations template template inline const Cube& Cube::operator=(const OpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); op_type::apply(*this, X); return *this; } //! in-place cube addition, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator+=(const OpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Cube m(X); return (*this).operator+=(m); } //! in-place cube subtraction, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator-=(const OpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Cube m(X); return (*this).operator-=(m); } //! in-place cube element-wise multiplication, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator%=(const OpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Cube m(X); return (*this).operator%=(m); } //! in-place cube element-wise division, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator/=(const OpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Cube m(X); return (*this).operator/=(m); } //! create a cube from eOpCube, i.e. run the previously delayed unary operations template template inline Cube::Cube(const eOpCube& X) : n_rows(X.get_n_rows()) , n_cols(X.get_n_cols()) , n_elem_slice(X.get_n_elem_slice()) , n_slices(X.get_n_slices()) , n_elem(X.get_n_elem()) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); init_cold(); eop_type::apply(*this, X); } //! create a cube from eOpCube, i.e. run the previously delayed unary operations template template inline const Cube& Cube::operator=(const eOpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const bool bad_alias = ( X.P.has_subview && X.P.is_alias(*this) ); if(bad_alias == false) { init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices()); eop_type::apply(*this, X); } else { Cube tmp(X); steal_mem(tmp); } return *this; } //! in-place cube addition, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator+=(const eOpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_plus(*this, X); return *this; } //! in-place cube subtraction, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator-=(const eOpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_minus(*this, X); return *this; } //! in-place cube element-wise multiplication, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator%=(const eOpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_schur(*this, X); return *this; } //! in-place cube element-wise division, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator/=(const eOpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_div(*this, X); return *this; } //! EXPERIMENTAL template template inline Cube::Cube(const mtOpCube& X) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); op_type::apply(*this, X); } //! EXPERIMENTAL template template inline const Cube& Cube::operator=(const mtOpCube& X) { arma_extra_debug_sigprint(); op_type::apply(*this, X); return *this; } //! EXPERIMENTAL template template inline const Cube& Cube::operator+=(const mtOpCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator+=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator-=(const mtOpCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator-=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator%=(const mtOpCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator%=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator/=(const mtOpCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator/=(m); } //! create a cube from Glue, i.e. run the previously delayed binary operations template template inline Cube::Cube(const GlueCube& X) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); this->operator=(X); } //! create a cube from Glue, i.e. run the previously delayed binary operations template template inline const Cube& Cube::operator=(const GlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); glue_type::apply(*this, X); return *this; } //! in-place cube addition, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator+=(const GlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Cube m(X); return (*this).operator+=(m); } //! in-place cube subtraction, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator-=(const GlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Cube m(X); return (*this).operator-=(m); } //! in-place cube element-wise multiplication, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator%=(const GlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Cube m(X); return (*this).operator%=(m); } //! in-place cube element-wise division, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator/=(const GlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Cube m(X); return (*this).operator/=(m); } //! create a cube from eGlue, i.e. run the previously delayed binary operations template template inline Cube::Cube(const eGlueCube& X) : n_rows(X.get_n_rows()) , n_cols(X.get_n_cols()) , n_elem_slice(X.get_n_elem_slice()) , n_slices(X.get_n_slices()) , n_elem(X.get_n_elem()) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); init_cold(); eglue_type::apply(*this, X); } //! create a cube from Glue, i.e. run the previously delayed binary operations template template inline const Cube& Cube::operator=(const eGlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const bool bad_alias = ( (X.P1.has_subview && X.P1.is_alias(*this)) || (X.P2.has_subview && X.P2.is_alias(*this)) ); if(bad_alias == false) { init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices()); eglue_type::apply(*this, X); } else { Cube tmp(X); steal_mem(tmp); } return *this; } //! in-place cube addition, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator+=(const eGlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_plus(*this, X); return *this; } //! in-place cube subtraction, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator-=(const eGlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_minus(*this, X); return *this; } //! in-place cube element-wise multiplication, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator%=(const eGlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_schur(*this, X); return *this; } //! in-place cube element-wise division, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator/=(const eGlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_div(*this, X); return *this; } //! EXPERIMENTAL template template inline Cube::Cube(const mtGlueCube& X) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mat_ptrs() , mem() { arma_extra_debug_sigprint_this(this); glue_type::apply(*this, X); } //! EXPERIMENTAL template template inline const Cube& Cube::operator=(const mtGlueCube& X) { arma_extra_debug_sigprint(); glue_type::apply(*this, X); return *this; } //! EXPERIMENTAL template template inline const Cube& Cube::operator+=(const mtGlueCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator+=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator-=(const mtGlueCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator-=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator%=(const mtGlueCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator%=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator/=(const mtGlueCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator/=(m); } //! linear element accessor (treats the cube as a vector); no bounds check; assumes memory is aligned template arma_inline arma_warn_unused const eT& Cube::at_alt(const uword i) const { const eT* mem_aligned = mem; memory::mark_as_aligned(mem_aligned); return mem_aligned[i]; } //! linear element accessor (treats the cube as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused eT& Cube::operator() (const uword i) { arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds"); return access::rw(mem[i]); } //! linear element accessor (treats the cube as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused const eT& Cube::operator() (const uword i) const { arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds"); return mem[i]; } //! linear element accessor (treats the cube as a vector); no bounds check. template arma_inline arma_warn_unused eT& Cube::operator[] (const uword i) { return access::rw(mem[i]); } //! linear element accessor (treats the cube as a vector); no bounds check template arma_inline arma_warn_unused const eT& Cube::operator[] (const uword i) const { return mem[i]; } //! linear element accessor (treats the cube as a vector); no bounds check. template arma_inline arma_warn_unused eT& Cube::at(const uword i) { return access::rw(mem[i]); } //! linear element accessor (treats the cube as a vector); no bounds check template arma_inline arma_warn_unused const eT& Cube::at(const uword i) const { return mem[i]; } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused eT& Cube::operator() (const uword in_row, const uword in_col, const uword in_slice) { arma_debug_check ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) , "Cube::operator(): index out of bounds" ); return access::rw(mem[in_slice*n_elem_slice + in_col*n_rows + in_row]); } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused const eT& Cube::operator() (const uword in_row, const uword in_col, const uword in_slice) const { arma_debug_check ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) , "Cube::operator(): index out of bounds" ); return mem[in_slice*n_elem_slice + in_col*n_rows + in_row]; } //! element accessor; no bounds check template arma_inline arma_warn_unused eT& Cube::at(const uword in_row, const uword in_col, const uword in_slice) { return access::rw( mem[in_slice*n_elem_slice + in_col*n_rows + in_row] ); } //! element accessor; no bounds check template arma_inline arma_warn_unused const eT& Cube::at(const uword in_row, const uword in_col, const uword in_slice) const { return mem[in_slice*n_elem_slice + in_col*n_rows + in_row]; } //! prefix ++ template arma_inline const Cube& Cube::operator++() { Cube_aux::prefix_pp(*this); return *this; } //! postfix ++ (must not return the object by reference) template arma_inline void Cube::operator++(int) { Cube_aux::postfix_pp(*this); } //! prefix -- template arma_inline const Cube& Cube::operator--() { Cube_aux::prefix_mm(*this); return *this; } //! postfix -- (must not return the object by reference) template arma_inline void Cube::operator--(int) { Cube_aux::postfix_mm(*this); } //! returns true if all of the elements are finite template arma_inline arma_warn_unused bool Cube::is_finite() const { return arrayops::is_finite( memptr(), n_elem ); } //! returns true if the cube has no elements template arma_inline arma_warn_unused bool Cube::is_empty() const { return (n_elem == 0); } //! returns true if the given index is currently in range template arma_inline arma_warn_unused bool Cube::in_range(const uword i) const { return (i < n_elem); } //! returns true if the given start and end indices are currently in range template arma_inline arma_warn_unused bool Cube::in_range(const span& x) const { arma_extra_debug_sigprint(); if(x.whole == true) { return true; } else { const uword a = x.a; const uword b = x.b; return ( (a <= b) && (b < n_elem) ); } } //! returns true if the given location is currently in range template arma_inline arma_warn_unused bool Cube::in_range(const uword in_row, const uword in_col, const uword in_slice) const { return ( (in_row < n_rows) && (in_col < n_cols) && (in_slice < n_slices) ); } template inline arma_warn_unused bool Cube::in_range(const span& row_span, const span& col_span, const span& slice_span) const { arma_extra_debug_sigprint(); const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; const uword in_slice1 = slice_span.a; const uword in_slice2 = slice_span.b; const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) ); const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) ); const bool slices_ok = slice_span.whole ? true : ( (in_slice1 <= in_slice2) && (in_slice2 < n_slices) ); return ( (rows_ok == true) && (cols_ok == true) && (slices_ok == true) ); } template inline arma_warn_unused bool Cube::in_range(const uword in_row, const uword in_col, const uword in_slice, const SizeCube& s) const { const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword l_n_slices = n_slices; if( ( in_row >= l_n_rows) || ( in_col >= l_n_cols) || ( in_slice >= l_n_slices) || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) || ((in_slice + s.n_slices) > l_n_slices) ) { return false; } else { return true; } } //! returns a pointer to array of eTs used by the cube template arma_inline arma_warn_unused eT* Cube::memptr() { return const_cast(mem); } //! returns a pointer to array of eTs used by the cube template arma_inline arma_warn_unused const eT* Cube::memptr() const { return mem; } //! returns a pointer to array of eTs used by the specified slice in the cube template arma_inline arma_warn_unused eT* Cube::slice_memptr(const uword uslice) { return const_cast( &mem[ uslice*n_elem_slice ] ); } //! returns a pointer to array of eTs used by the specified slice in the cube template arma_inline arma_warn_unused const eT* Cube::slice_memptr(const uword uslice) const { return &mem[ uslice*n_elem_slice ]; } //! returns a pointer to array of eTs used by the specified slice in the cube template arma_inline arma_warn_unused eT* Cube::slice_colptr(const uword uslice, const uword col) { return const_cast( &mem[ uslice*n_elem_slice + col*n_rows] ); } //! returns a pointer to array of eTs used by the specified slice in the cube template arma_inline arma_warn_unused const eT* Cube::slice_colptr(const uword uslice, const uword col) const { return &mem[ uslice*n_elem_slice + col*n_rows ]; } //! print contents of the cube (to the cout stream), //! optionally preceding with a user specified line of text. //! the precision and cell width are modified. //! on return, the stream's state are restored to their original values. template inline void Cube::impl_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { ARMA_DEFAULT_OSTREAM << extra_text << '\n'; } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, true); } //! print contents of the cube to a user specified stream, //! optionally preceding with a user specified line of text. //! the precision and cell width are modified. //! on return, the stream's state are restored to their original values. template inline void Cube::impl_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { user_stream << extra_text << '\n'; } arma_ostream::print(user_stream, *this, true); } //! print contents of the cube (to the cout stream), //! optionally preceding with a user specified line of text. //! the stream's state are used as is and are not modified //! (i.e. the precision and cell width are not modified). template inline void Cube::impl_raw_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { ARMA_DEFAULT_OSTREAM << extra_text << '\n'; } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, false); } //! print contents of the cube to a user specified stream, //! optionally preceding with a user specified line of text. //! the stream's state are used as is and are not modified. //! (i.e. the precision and cell width are not modified). template inline void Cube::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { user_stream << extra_text << '\n'; } arma_ostream::print(user_stream, *this, false); } //! change the cube to have user specified dimensions (data is not preserved) template inline void Cube::set_size(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) { arma_extra_debug_sigprint(); init_warm(in_n_rows, in_n_cols, in_n_slices); } //! change the cube to have user specified dimensions (data is preserved) template inline void Cube::reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim) { arma_extra_debug_sigprint(); *this = arma::reshape(*this, in_rows, in_cols, in_slices, dim); } //! change the cube to have user specified dimensions (data is preserved) template inline void Cube::resize(const uword in_rows, const uword in_cols, const uword in_slices) { arma_extra_debug_sigprint(); *this = arma::resize(*this, in_rows, in_cols, in_slices); } //! change the cube (without preserving data) to have the same dimensions as the given cube template template inline void Cube::copy_size(const Cube& m) { arma_extra_debug_sigprint(); init_warm(m.n_rows, m.n_cols, m.n_slices); } //! transform each element in the cube using a functor template template inline const Cube& Cube::transform(functor F) { arma_extra_debug_sigprint(); eT* out_mem = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { eT tmp_ii = out_mem[ii]; eT tmp_jj = out_mem[jj]; tmp_ii = eT( F(tmp_ii) ); tmp_jj = eT( F(tmp_jj) ); out_mem[ii] = tmp_ii; out_mem[jj] = tmp_jj; } if(ii < N) { out_mem[ii] = eT( F(out_mem[ii]) ); } return *this; } //! imbue (fill) the cube with values provided by a functor template template inline const Cube& Cube::imbue(functor F) { arma_extra_debug_sigprint(); eT* out_mem = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { const eT tmp_ii = eT( F() ); const eT tmp_jj = eT( F() ); out_mem[ii] = tmp_ii; out_mem[jj] = tmp_jj; } if(ii < N) { out_mem[ii] = eT( F() ); } return *this; } //! fill the cube with the specified value template inline const Cube& Cube::fill(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_set( memptr(), val, n_elem ); return *this; } template inline const Cube& Cube::zeros() { arma_extra_debug_sigprint(); arrayops::fill_zeros(memptr(), n_elem); return *this; } template inline const Cube& Cube::zeros(const uword in_rows, const uword in_cols, const uword in_slices) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols, in_slices); return (*this).zeros(); } template inline const Cube& Cube::ones() { arma_extra_debug_sigprint(); return (*this).fill(eT(1)); } template inline const Cube& Cube::ones(const uword in_rows, const uword in_cols, const uword in_slices) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols, in_slices); return (*this).fill(eT(1)); } template inline const Cube& Cube::randu() { arma_extra_debug_sigprint(); arma_rng::randu::fill( memptr(), n_elem ); return *this; } template inline const Cube& Cube::randu(const uword in_rows, const uword in_cols, const uword in_slices) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols, in_slices); return (*this).randu(); } template inline const Cube& Cube::randn() { arma_extra_debug_sigprint(); arma_rng::randn::fill( memptr(), n_elem ); return *this; } template inline const Cube& Cube::randn(const uword in_rows, const uword in_cols, const uword in_slices) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols, in_slices); return (*this).randn(); } template inline void Cube::reset() { arma_extra_debug_sigprint(); init_warm(0,0,0); } template template inline void Cube::set_real(const BaseCube::pod_type,T1>& X) { arma_extra_debug_sigprint(); Cube_aux::set_real(*this, X); } template template inline void Cube::set_imag(const BaseCube::pod_type,T1>& X) { arma_extra_debug_sigprint(); Cube_aux::set_imag(*this, X); } template inline arma_warn_unused eT Cube::min() const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "min(): object has no elements" ); return op_min::direct_min(memptr(), n_elem); } template inline arma_warn_unused eT Cube::max() const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "max(): object has no elements" ); return op_max::direct_max(memptr(), n_elem); } template inline eT Cube::min(uword& index_of_min_val) const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "min(): object has no elements" ); return op_min::direct_min(memptr(), n_elem, index_of_min_val); } template inline eT Cube::max(uword& index_of_max_val) const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "max(): object has no elements" ); return op_max::direct_max(memptr(), n_elem, index_of_max_val); } template inline eT Cube::min(uword& row_of_min_val, uword& col_of_min_val, uword& slice_of_min_val) const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "min(): object has no elements" ); uword i; eT val = op_min::direct_min(memptr(), n_elem, i); const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; row_of_min_val = j % n_rows; col_of_min_val = j / n_rows; slice_of_min_val = in_slice; return val; } template inline eT Cube::max(uword& row_of_max_val, uword& col_of_max_val, uword& slice_of_max_val) const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "max(): object has no elements" ); uword i; eT val = op_max::direct_max(memptr(), n_elem, i); const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; row_of_max_val = j % n_rows; col_of_max_val = j / n_rows; slice_of_max_val = in_slice; return val; } //! save the cube to a file template inline bool Cube::save(const std::string name, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { case raw_ascii: save_okay = diskio::save_raw_ascii(*this, name); break; case arma_ascii: save_okay = diskio::save_arma_ascii(*this, name); break; case raw_binary: save_okay = diskio::save_raw_binary(*this, name); break; case arma_binary: save_okay = diskio::save_arma_binary(*this, name); break; case ppm_binary: save_okay = diskio::save_ppm_binary(*this, name); break; case hdf5_binary: save_okay = diskio::save_hdf5_binary(*this, name); break; default: arma_warn(print_status, "Cube::save(): unsupported file type"); save_okay = false; } arma_warn( (print_status && (save_okay == false)), "Cube::save(): couldn't write to ", name); return save_okay; } //! save the cube to a stream template inline bool Cube::save(std::ostream& os, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { case raw_ascii: save_okay = diskio::save_raw_ascii(*this, os); break; case arma_ascii: save_okay = diskio::save_arma_ascii(*this, os); break; case raw_binary: save_okay = diskio::save_raw_binary(*this, os); break; case arma_binary: save_okay = diskio::save_arma_binary(*this, os); break; case ppm_binary: save_okay = diskio::save_ppm_binary(*this, os); break; default: arma_warn(print_status, "Cube::save(): unsupported file type"); save_okay = false; } arma_warn( (print_status && (save_okay == false)), "Cube::save(): couldn't write to given stream"); return save_okay; } //! load a cube from a file template inline bool Cube::load(const std::string name, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { case auto_detect: load_okay = diskio::load_auto_detect(*this, name, err_msg); break; case raw_ascii: load_okay = diskio::load_raw_ascii(*this, name, err_msg); break; case arma_ascii: load_okay = diskio::load_arma_ascii(*this, name, err_msg); break; case raw_binary: load_okay = diskio::load_raw_binary(*this, name, err_msg); break; case arma_binary: load_okay = diskio::load_arma_binary(*this, name, err_msg); break; case ppm_binary: load_okay = diskio::load_ppm_binary(*this, name, err_msg); break; case hdf5_binary: load_okay = diskio::load_hdf5_binary(*this, name, err_msg); break; default: arma_warn(print_status, "Cube::load(): unsupported file type"); load_okay = false; } if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_warn(true, "Cube::load(): ", err_msg, name); } else { arma_warn(true, "Cube::load(): couldn't read ", name); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! load a cube from a stream template inline bool Cube::load(std::istream& is, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { case auto_detect: load_okay = diskio::load_auto_detect(*this, is, err_msg); break; case raw_ascii: load_okay = diskio::load_raw_ascii(*this, is, err_msg); break; case arma_ascii: load_okay = diskio::load_arma_ascii(*this, is, err_msg); break; case raw_binary: load_okay = diskio::load_raw_binary(*this, is, err_msg); break; case arma_binary: load_okay = diskio::load_arma_binary(*this, is, err_msg); break; case ppm_binary: load_okay = diskio::load_ppm_binary(*this, is, err_msg); break; default: arma_warn(print_status, "Cube::load(): unsupported file type"); load_okay = false; } if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_warn(true, "Cube::load(): ", err_msg, "the given stream"); } else { arma_warn(true, "Cube::load(): couldn't load from the given stream"); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! save the cube to a file, without printing any error messages template inline bool Cube::quiet_save(const std::string name, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(name, type, false); } //! save the cube to a stream, without printing any error messages template inline bool Cube::quiet_save(std::ostream& os, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(os, type, false); } //! load a cube from a file, without printing any error messages template inline bool Cube::quiet_load(const std::string name, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(name, type, false); } //! load a cube from a stream, without printing any error messages template inline bool Cube::quiet_load(std::istream& is, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(is, type, false); } template inline typename Cube::iterator Cube::begin() { arma_extra_debug_sigprint(); return memptr(); } template inline typename Cube::const_iterator Cube::begin() const { arma_extra_debug_sigprint(); return memptr(); } template inline typename Cube::const_iterator Cube::cbegin() const { arma_extra_debug_sigprint(); return memptr(); } template inline typename Cube::iterator Cube::end() { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Cube::const_iterator Cube::end() const { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Cube::const_iterator Cube::cend() const { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Cube::slice_iterator Cube::begin_slice(const uword slice_num) { arma_extra_debug_sigprint(); arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds"); return slice_memptr(slice_num); } template inline typename Cube::const_slice_iterator Cube::begin_slice(const uword slice_num) const { arma_extra_debug_sigprint(); arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds"); return slice_memptr(slice_num); } template inline typename Cube::slice_iterator Cube::end_slice(const uword slice_num) { arma_extra_debug_sigprint(); arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds"); return slice_memptr(slice_num) + n_elem_slice; } template inline typename Cube::const_slice_iterator Cube::end_slice(const uword slice_num) const { arma_extra_debug_sigprint(); arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds"); return slice_memptr(slice_num) + n_elem_slice; } //! resets this cube to an empty matrix template inline void Cube::clear() { reset(); } //! returns true if the cube has no elements template inline bool Cube::empty() const { return (n_elem == 0); } //! returns the number of elements in this cube template inline uword Cube::size() const { return n_elem; } template inline void Cube::swap(Cube& B) { Cube& A = (*this); arma_extra_debug_sigprint(arma_boost::format("A = %x B = %x") % &A % &B); if( (A.mem_state == 0) && (B.mem_state == 0) && (A.n_elem > Cube_prealloc::mem_n_elem) && (B.n_elem > Cube_prealloc::mem_n_elem) ) { A.delete_mat(); B.delete_mat(); std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); std::swap( access::rw(A.n_elem_slice), access::rw(B.n_elem_slice) ); std::swap( access::rw(A.n_slices), access::rw(B.n_slices) ); std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); std::swap( access::rw(A.mem), access::rw(B.mem) ); A.create_mat(); B.create_mat(); } else if( (A.mem_state == 0) && (B.mem_state == 0) && (A.n_elem <= Cube_prealloc::mem_n_elem) && (B.n_elem <= Cube_prealloc::mem_n_elem) ) { A.delete_mat(); B.delete_mat(); std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); std::swap( access::rw(A.n_elem_slice), access::rw(B.n_elem_slice) ); std::swap( access::rw(A.n_slices), access::rw(B.n_slices) ); std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); const uword N = (std::max)(A.n_elem, B.n_elem); eT* A_mem = A.memptr(); eT* B_mem = B.memptr(); for(uword i=0; i C = A; A.steal_mem(B); B.steal_mem(C); } else { Cube C = B; B.steal_mem(A); A.steal_mem(C); } } } //! try to steal the memory from a given cube; //! if memory can't be stolen, copy the given cube template inline void Cube::steal_mem(Cube& x) { arma_extra_debug_sigprint(); if(this != &x) { if( (mem_state <= 1) && ( ((x.mem_state == 0) && (x.n_elem > Cube_prealloc::mem_n_elem)) || (x.mem_state == 1) ) ) { reset(); const uword x_n_slices = x.n_slices; access::rw(n_rows) = x.n_rows; access::rw(n_cols) = x.n_cols; access::rw(n_elem_slice) = x.n_elem_slice; access::rw(n_slices) = x_n_slices; access::rw(n_elem) = x.n_elem; access::rw(mem_state) = x.mem_state; access::rw(mem) = x.mem; if(x_n_slices > Cube_prealloc::mat_ptrs_size) { access::rw( mat_ptrs) = x.mat_ptrs; access::rw(x.mat_ptrs) = 0; } else { access::rw(mat_ptrs) = const_cast< const Mat** >(mat_ptrs_local); for(uword i=0; i < x_n_slices; ++i) { mat_ptrs[i] = x.mat_ptrs[i]; x.mat_ptrs[i] = 0; } } access::rw(x.n_rows) = 0; access::rw(x.n_cols) = 0; access::rw(x.n_elem_slice) = 0; access::rw(x.n_slices) = 0; access::rw(x.n_elem) = 0; access::rw(x.mem_state) = 0; access::rw(x.mem) = 0; } else { (*this).operator=(x); } } } // // Cube::fixed template template arma_inline void Cube::fixed::mem_setup() { arma_extra_debug_sigprint(); if(fixed_n_elem > 0) { access::rw(Cube::n_rows) = fixed_n_rows; access::rw(Cube::n_cols) = fixed_n_cols; access::rw(Cube::n_elem_slice) = fixed_n_rows * fixed_n_cols; access::rw(Cube::n_slices) = fixed_n_slices; access::rw(Cube::n_elem) = fixed_n_elem; access::rw(Cube::mem_state) = 3; access::rw(Cube::mat_ptrs) = const_cast< const Mat** >( \ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? mat_ptrs_local_extra : mat_ptrs_local ); access::rw(Cube::mem) = (fixed_n_elem > Cube_prealloc::mem_n_elem) ? mem_local_extra : mem_local; create_mat(); } else { access::rw(Cube::n_rows) = 0; access::rw(Cube::n_cols) = 0; access::rw(Cube::n_elem_slice) = 0; access::rw(Cube::n_slices) = 0; access::rw(Cube::n_elem) = 0; access::rw(Cube::mem_state) = 3; access::rw(Cube::mat_ptrs) = 0; access::rw(Cube::mem) = 0; } } template template inline Cube::fixed::fixed() { arma_extra_debug_sigprint_this(this); mem_setup(); } template template inline Cube::fixed::fixed(const fixed& X) { arma_extra_debug_sigprint_this(this); mem_setup(); eT* dest = (use_extra) ? mem_local_extra : mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); } template template template inline Cube::fixed::fixed(const fill::fill_class&) { arma_extra_debug_sigprint_this(this); mem_setup(); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); if(is_same_type::yes) { arma_debug_check(true, "Cube::fixed::fixed(): unsupported fill type"); } } template template template inline Cube::fixed::fixed(const BaseCube& A) { arma_extra_debug_sigprint_this(this); mem_setup(); Cube::operator=(A.get_ref()); } template template template inline Cube::fixed::fixed(const BaseCube& A, const BaseCube& B) { arma_extra_debug_sigprint_this(this); mem_setup(); Cube::init(A,B); } template template inline const Cube& Cube::fixed::operator=(const fixed& X) { arma_extra_debug_sigprint(); eT* dest = (use_extra) ? mem_local_extra : mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); return *this; } template template arma_inline arma_warn_unused eT& Cube::fixed::operator[] (const uword i) { return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused const eT& Cube::fixed::operator[] (const uword i) const { return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused eT& Cube::fixed::at(const uword i) { return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused const eT& Cube::fixed::at(const uword i) const { return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused eT& Cube::fixed::operator() (const uword i) { arma_debug_check( (i >= fixed_n_elem), "Cube::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused const eT& Cube::fixed::operator() (const uword i) const { arma_debug_check( (i >= fixed_n_elem), "Cube::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused eT& Cube::fixed::at(const uword in_row, const uword in_col, const uword in_slice) { const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row; return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused const eT& Cube::fixed::at(const uword in_row, const uword in_col, const uword in_slice) const { const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row; return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused eT& Cube::fixed::operator() (const uword in_row, const uword in_col, const uword in_slice) { arma_debug_check ( (in_row >= fixed_n_rows ) || (in_col >= fixed_n_cols ) || (in_slice >= fixed_n_slices) , "operator(): index out of bounds" ); const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row; return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused const eT& Cube::fixed::operator() (const uword in_row, const uword in_col, const uword in_slice) const { arma_debug_check ( (in_row >= fixed_n_rows ) || (in_col >= fixed_n_cols ) || (in_slice >= fixed_n_slices) , "Cube::operator(): index out of bounds" ); const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row; return (use_extra) ? mem_local_extra[i] : mem_local[i]; } // // Cube_aux //! prefix ++ template arma_inline void Cube_aux::prefix_pp(Cube& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Cube_aux::prefix_pp(Cube< std::complex >& x) { x += T(1); } //! postfix ++ template arma_inline void Cube_aux::postfix_pp(Cube& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Cube_aux::postfix_pp(Cube< std::complex >& x) { x += T(1); } //! prefix -- template arma_inline void Cube_aux::prefix_mm(Cube& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Cube_aux::prefix_mm(Cube< std::complex >& x) { x -= T(1); } //! postfix -- template arma_inline void Cube_aux::postfix_mm(Cube& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Cube_aux::postfix_mm(Cube< std::complex >& x) { x -= T(1); } template inline void Cube_aux::set_real(Cube& out, const BaseCube& X) { arma_extra_debug_sigprint(); const unwrap_cube tmp(X.get_ref()); const Cube& A = tmp.M; arma_debug_assert_same_size( out, A, "Cube::set_real()" ); out = A; } template inline void Cube_aux::set_imag(Cube&, const BaseCube&) { arma_extra_debug_sigprint(); } template inline void Cube_aux::set_real(Cube< std::complex >& out, const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube P(X.get_ref()); const uword local_n_rows = P.get_n_rows(); const uword local_n_cols = P.get_n_cols(); const uword local_n_slices = P.get_n_slices(); arma_debug_assert_same_size ( out.n_rows, out.n_cols, out.n_slices, local_n_rows, local_n_cols, local_n_slices, "Cube::set_real()" ); eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type; ea_type A = P.get_ea(); const uword N = out.n_elem; for(uword i=0; i( A[i], out_mem[i].imag() ); } } else { for(uword slice = 0; slice < local_n_slices; ++slice) for(uword col = 0; col < local_n_cols; ++col ) for(uword row = 0; row < local_n_rows; ++row ) { (*out_mem) = std::complex( P.at(row,col,slice), (*out_mem).imag() ); out_mem++; } } } template inline void Cube_aux::set_imag(Cube< std::complex >& out, const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube P(X.get_ref()); const uword local_n_rows = P.get_n_rows(); const uword local_n_cols = P.get_n_cols(); const uword local_n_slices = P.get_n_slices(); arma_debug_assert_same_size ( out.n_rows, out.n_cols, out.n_slices, local_n_rows, local_n_cols, local_n_slices, "Cube::set_imag()" ); eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type; ea_type A = P.get_ea(); const uword N = out.n_elem; for(uword i=0; i( out_mem[i].real(), A[i] ); } } else { for(uword slice = 0; slice < local_n_slices; ++slice) for(uword col = 0; col < local_n_cols; ++col ) for(uword row = 0; row < local_n_rows; ++row ) { (*out_mem) = std::complex( (*out_mem).real(), P.at(row,col,slice) ); out_mem++; } } } #ifdef ARMA_EXTRA_CUBE_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_MEAT) #endif //! @} RcppArmadillo/inst/include/armadillo_bits/fn_join.hpp0000644000176000001440000000330312220540177022552 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_join //! @{ template inline const Glue join_cols(const Base& A, const Base& B) { arma_extra_debug_sigprint(); return Glue(A.get_ref(), B.get_ref(), 0); } template inline const Glue join_vert(const Base& A, const Base& B) { arma_extra_debug_sigprint(); return Glue(A.get_ref(), B.get_ref(), 0); } template inline const Glue join_rows(const Base& A, const Base& B) { arma_extra_debug_sigprint(); return Glue(A.get_ref(), B.get_ref(), 1); } template inline const Glue join_horiz(const Base& A, const Base& B) { arma_extra_debug_sigprint(); return Glue(A.get_ref(), B.get_ref(), 1); } template inline const GlueCube join_slices(const BaseCube& A, const BaseCube& B) { arma_extra_debug_sigprint(); return GlueCube(A.get_ref(), B.get_ref()); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_find_meat.hpp0000644000176000001440000002632612200631217023560 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // Copyright (C) 2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_find //! @{ template inline uword op_find::helper ( Mat& indices, const Base& X ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy A(X.get_ref()); const uword n_elem = A.get_n_elem(); indices.set_size(n_elem, 1); uword* indices_mem = indices.memptr(); uword n_nz = 0; if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type PA = A.get_ea(); for(uword i=0; i inline uword op_find::helper ( Mat& indices, const mtOp& X, const typename arma_op_rel_only::result junk1, const typename arma_not_cx::result junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); typedef typename T1::elem_type eT; const eT val = X.aux; const Proxy A(X.m); const uword n_elem = A.get_n_elem(); indices.set_size(n_elem, 1); uword* indices_mem = indices.memptr(); uword n_nz = 0; if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type PA = A.get_ea(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { const eT tpi = PA[i]; const eT tpj = PA[j]; bool not_zero_i; bool not_zero_j; if(is_same_type::yes) { not_zero_i = (val < tpi); } else if(is_same_type::yes) { not_zero_i = (tpi < val); } else if(is_same_type::yes) { not_zero_i = (val > tpi); } else if(is_same_type::yes) { not_zero_i = (tpi > val); } else if(is_same_type::yes) { not_zero_i = (val <= tpi); } else if(is_same_type::yes) { not_zero_i = (tpi <= val); } else if(is_same_type::yes) { not_zero_i = (val >= tpi); } else if(is_same_type::yes) { not_zero_i = (tpi >= val); } else if(is_same_type::yes) { not_zero_i = (tpi == val); } else if(is_same_type::yes) { not_zero_i = (tpi != val); } else not_zero_i = false; if(is_same_type::yes) { not_zero_j = (val < tpj); } else if(is_same_type::yes) { not_zero_j = (tpj < val); } else if(is_same_type::yes) { not_zero_j = (val > tpj); } else if(is_same_type::yes) { not_zero_j = (tpj > val); } else if(is_same_type::yes) { not_zero_j = (val <= tpj); } else if(is_same_type::yes) { not_zero_j = (tpj <= val); } else if(is_same_type::yes) { not_zero_j = (val >= tpj); } else if(is_same_type::yes) { not_zero_j = (tpj >= val); } else if(is_same_type::yes) { not_zero_j = (tpj == val); } else if(is_same_type::yes) { not_zero_j = (tpj != val); } else not_zero_j = false; if(not_zero_i == true) { indices_mem[n_nz] = i; ++n_nz; } if(not_zero_j == true) { indices_mem[n_nz] = j; ++n_nz; } } if(i < n_elem) { bool not_zero; const eT tmp = PA[i]; if(is_same_type::yes) { not_zero = (val < tmp); } else if(is_same_type::yes) { not_zero = (tmp < val); } else if(is_same_type::yes) { not_zero = (val > tmp); } else if(is_same_type::yes) { not_zero = (tmp > val); } else if(is_same_type::yes) { not_zero = (val <= tmp); } else if(is_same_type::yes) { not_zero = (tmp <= val); } else if(is_same_type::yes) { not_zero = (val >= tmp); } else if(is_same_type::yes) { not_zero = (tmp >= val); } else if(is_same_type::yes) { not_zero = (tmp == val); } else if(is_same_type::yes) { not_zero = (tmp != val); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } } } else { const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); uword i = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT tmp = A.at(row,col); bool not_zero; if(is_same_type::yes) { not_zero = (val < tmp); } else if(is_same_type::yes) { not_zero = (tmp < val); } else if(is_same_type::yes) { not_zero = (val > tmp); } else if(is_same_type::yes) { not_zero = (tmp > val); } else if(is_same_type::yes) { not_zero = (val <= tmp); } else if(is_same_type::yes) { not_zero = (tmp <= val); } else if(is_same_type::yes) { not_zero = (val >= tmp); } else if(is_same_type::yes) { not_zero = (tmp >= val); } else if(is_same_type::yes) { not_zero = (tmp == val); } else if(is_same_type::yes) { not_zero = (tmp != val); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } ++i; } } return n_nz; } template inline uword op_find::helper ( Mat& indices, const mtOp& X, const typename arma_op_rel_only::result junk1, const typename arma_cx_only::result junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); typedef typename T1::elem_type eT; typedef typename Proxy::ea_type ea_type; const eT val = X.aux; const Proxy A(X.m); ea_type PA = A.get_ea(); const uword n_elem = A.get_n_elem(); indices.set_size(n_elem, 1); uword* indices_mem = indices.memptr(); uword n_nz = 0; for(uword i=0; i::yes) { not_zero = (tmp == val); } else if(is_same_type::yes) { not_zero = (tmp != val); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } } return n_nz; } template inline uword op_find::helper ( Mat& indices, const mtGlue& X, const typename arma_glue_rel_only::result junk1, const typename arma_not_cx::result junk2, const typename arma_not_cx::result junk3 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); arma_ignore(junk3); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "relational operator"); ea_type1 PA = A.get_ea(); ea_type2 PB = B.get_ea(); const uword n_elem = B.get_n_elem(); indices.set_size(n_elem, 1); uword* indices_mem = indices.memptr(); uword n_nz = 0; for(uword i=0; i::yes) { not_zero = (tmp1 < tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 > tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 <= tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 >= tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 == tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 != tmp2); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } } return n_nz; } template inline uword op_find::helper ( Mat& indices, const mtGlue& X, const typename arma_glue_rel_only::result junk1, const typename arma_cx_only::result junk2, const typename arma_cx_only::result junk3 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); arma_ignore(junk3); typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "relational operator"); ea_type1 PA = A.get_ea(); ea_type2 PB = B.get_ea(); const uword n_elem = B.get_n_elem(); indices.set_size(n_elem, 1); uword* indices_mem = indices.memptr(); uword n_nz = 0; for(uword i=0; i::yes) { not_zero = (PA[i] == PB[i]); } else if(is_same_type::yes) { not_zero = (PA[i] != PB[i]); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } } return n_nz; } template inline void op_find::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); const uword k = X.aux_uword_a; const uword type = X.aux_uword_b; Mat indices; const uword n_nz = op_find::helper(indices, X.m); if(n_nz > 0) { if(type == 0) // "first" { out = (k > 0 && k <= n_nz) ? indices.rows(0, k-1 ) : indices.rows(0, n_nz-1); } else // "last" { out = (k > 0 && k <= n_nz) ? indices.rows(n_nz-k, n_nz-1) : indices.rows(0, n_nz-1); } } else { out.set_size(0,1); // empty column vector } } //! @} RcppArmadillo/inst/include/armadillo_bits/op_cumsum_meat.hpp0000644000176000001440000000407212200631217024143 0ustar ripleyusers// Copyright (C) 2010-2012 Conrad Sanderson // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_cumsum //! @{ template inline void op_cumsum_mat::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "cumsum(): incorrect usage. dim must be 0 or 1"); out.copy_size(X); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_cumsum::apply(), dim = 0"); for(uword col=0; col inline void op_cumsum_vec::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; const uword n_elem = X.n_elem; out.copy_size(X); eT* out_mem = out.memptr(); const eT* X_mem = X.memptr(); eT acc = eT(0); for(uword i=0; i inline subview_elem1::~subview_elem1() { arma_extra_debug_sigprint(); } template arma_inline subview_elem1::subview_elem1(const Mat& in_m, const Base& in_a) : m(in_m) , a(in_a) { arma_extra_debug_sigprint(); } template arma_inline subview_elem1::subview_elem1(const Cube& in_q, const Base& in_a) : fake_m( const_cast< eT* >(in_q.memptr()), in_q.n_elem, 1, false ) , m( fake_m ) , a( in_a ) { arma_extra_debug_sigprint(); } template template inline void subview_elem1::inplace_op(const eT val) { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; const unwrap_check_mixed tmp(a.get_ref(), m_local); const umat& aa = tmp.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; uword iq,jq; for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) { const uword ii = aa_mem[iq]; const uword jj = aa_mem[jq]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = val; m_mem[jj] = val; } else if(is_same_type::yes) { m_mem[ii] += val; m_mem[jj] += val; } else if(is_same_type::yes) { m_mem[ii] -= val; m_mem[jj] -= val; } else if(is_same_type::yes) { m_mem[ii] *= val; m_mem[jj] *= val; } else if(is_same_type::yes) { m_mem[ii] /= val; m_mem[jj] /= val; } } if(iq < aa_n_elem) { const uword ii = aa_mem[iq]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = val; } else if(is_same_type::yes) { m_mem[ii] += val; } else if(is_same_type::yes) { m_mem[ii] -= val; } else if(is_same_type::yes) { m_mem[ii] *= val; } else if(is_same_type::yes) { m_mem[ii] /= val; } } } template template inline void subview_elem1::inplace_op(const subview_elem1& x) { arma_extra_debug_sigprint(); subview_elem1& s = *this; if(&(s.m) == &(x.m)) { arma_extra_debug_print("subview_elem1::inplace_op(): aliasing detected"); const Mat tmp(x); if(is_same_type::yes) { s.operator= (tmp); } else if(is_same_type::yes) { s.operator+=(tmp); } else if(is_same_type::yes) { s.operator-=(tmp); } else if(is_same_type::yes) { s.operator%=(tmp); } else if(is_same_type::yes) { s.operator/=(tmp); } } else { Mat& s_m_local = const_cast< Mat& >(s.m); const Mat& x_m_local = x.m; const unwrap_check_mixed s_tmp(s.a.get_ref(), s_m_local); const unwrap_check_mixed x_tmp(x.a.get_ref(), s_m_local); const umat& s_aa = s_tmp.M; const umat& x_aa = x_tmp.M; arma_debug_check ( ( ((s_aa.is_vec() == false) && (s_aa.is_empty() == false)) || ((x_aa.is_vec() == false) && (x_aa.is_empty() == false)) ), "Mat::elem(): given object is not a vector" ); const uword* s_aa_mem = s_aa.memptr(); const uword* x_aa_mem = x_aa.memptr(); const uword s_aa_n_elem = s_aa.n_elem; arma_debug_check( (s_aa_n_elem != x_aa.n_elem), "Mat::elem(): size mismatch" ); eT* s_m_mem = s_m_local.memptr(); const uword s_m_n_elem = s_m_local.n_elem; const eT* x_m_mem = x_m_local.memptr(); const uword x_m_n_elem = x_m_local.n_elem; uword iq,jq; for(iq=0, jq=1; jq < s_aa_n_elem; iq+=2, jq+=2) { const uword s_ii = s_aa_mem[iq]; const uword s_jj = s_aa_mem[jq]; const uword x_ii = x_aa_mem[iq]; const uword x_jj = x_aa_mem[jq]; arma_debug_check ( (s_ii >= s_m_n_elem) || (s_jj >= s_m_n_elem) || (x_ii >= x_m_n_elem) || (x_jj >= x_m_n_elem), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { s_m_mem[s_ii] = x_m_mem[x_ii]; s_m_mem[s_jj] = x_m_mem[x_jj]; } else if(is_same_type::yes) { s_m_mem[s_ii] += x_m_mem[x_ii]; s_m_mem[s_jj] += x_m_mem[x_jj]; } else if(is_same_type::yes) { s_m_mem[s_ii] -= x_m_mem[x_ii]; s_m_mem[s_jj] -= x_m_mem[x_jj]; } else if(is_same_type::yes) { s_m_mem[s_ii] *= x_m_mem[x_ii]; s_m_mem[s_jj] *= x_m_mem[x_jj]; } else if(is_same_type::yes) { s_m_mem[s_ii] /= x_m_mem[x_ii]; s_m_mem[s_jj] /= x_m_mem[x_jj]; } } if(iq < s_aa_n_elem) { const uword s_ii = s_aa_mem[iq]; const uword x_ii = x_aa_mem[iq]; arma_debug_check ( ( (s_ii >= s_m_n_elem) || (x_ii >= x_m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { s_m_mem[s_ii] = x_m_mem[x_ii]; } else if(is_same_type::yes) { s_m_mem[s_ii] += x_m_mem[x_ii]; } else if(is_same_type::yes) { s_m_mem[s_ii] -= x_m_mem[x_ii]; } else if(is_same_type::yes) { s_m_mem[s_ii] *= x_m_mem[x_ii]; } else if(is_same_type::yes) { s_m_mem[s_ii] /= x_m_mem[x_ii]; } } } } template template inline void subview_elem1::inplace_op(const Base& x) { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; const unwrap_check_mixed aa_tmp(a.get_ref(), m_local); const umat& aa = aa_tmp.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; const Proxy P(x.get_ref()); arma_debug_check( (aa_n_elem != P.get_n_elem()), "Mat::elem(): size mismatch" ); const bool is_alias = P.is_alias(m); if( (is_alias == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type X = P.get_ea(); uword iq,jq; for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) { const uword ii = aa_mem[iq]; const uword jj = aa_mem[jq]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = X[iq]; m_mem[jj] = X[jq]; } else if(is_same_type::yes) { m_mem[ii] += X[iq]; m_mem[jj] += X[jq]; } else if(is_same_type::yes) { m_mem[ii] -= X[iq]; m_mem[jj] -= X[jq]; } else if(is_same_type::yes) { m_mem[ii] *= X[iq]; m_mem[jj] *= X[jq]; } else if(is_same_type::yes) { m_mem[ii] /= X[iq]; m_mem[jj] /= X[jq]; } } if(iq < aa_n_elem) { const uword ii = aa_mem[iq]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = X[iq]; } else if(is_same_type::yes) { m_mem[ii] += X[iq]; } else if(is_same_type::yes) { m_mem[ii] -= X[iq]; } else if(is_same_type::yes) { m_mem[ii] *= X[iq]; } else if(is_same_type::yes) { m_mem[ii] /= X[iq]; } } } else { arma_extra_debug_print("subview_elem1::inplace_op(): aliasing or prefer_at_accessor detected"); const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& M = tmp.M; const eT* X = M.memptr(); uword iq,jq; for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) { const uword ii = aa_mem[iq]; const uword jj = aa_mem[jq]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = X[iq]; m_mem[jj] = X[jq]; } else if(is_same_type::yes) { m_mem[ii] += X[iq]; m_mem[jj] += X[jq]; } else if(is_same_type::yes) { m_mem[ii] -= X[iq]; m_mem[jj] -= X[jq]; } else if(is_same_type::yes) { m_mem[ii] *= X[iq]; m_mem[jj] *= X[jq]; } else if(is_same_type::yes) { m_mem[ii] /= X[iq]; m_mem[jj] /= X[jq]; } } if(iq < aa_n_elem) { const uword ii = aa_mem[iq]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = X[iq]; } else if(is_same_type::yes) { m_mem[ii] += X[iq]; } else if(is_same_type::yes) { m_mem[ii] -= X[iq]; } else if(is_same_type::yes) { m_mem[ii] *= X[iq]; } else if(is_same_type::yes) { m_mem[ii] /= X[iq]; } } } } // // template arma_inline const Op,op_htrans> subview_elem1::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> subview_elem1::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> subview_elem1::st() const { return Op,op_strans>(*this); } template inline void subview_elem1::fill(const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem1::zeros() { arma_extra_debug_sigprint(); inplace_op(eT(0)); } template inline void subview_elem1::ones() { arma_extra_debug_sigprint(); inplace_op(eT(1)); } template inline void subview_elem1::randu() { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; const unwrap_check_mixed tmp(a.get_ref(), m_local); const umat& aa = tmp.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; uword iq,jq; for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) { const uword ii = aa_mem[iq]; const uword jj = aa_mem[jq]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); const eT val1 = eT(arma_rng::randu()); const eT val2 = eT(arma_rng::randu()); m_mem[ii] = val1; m_mem[jj] = val2; } if(iq < aa_n_elem) { const uword ii = aa_mem[iq]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); m_mem[ii] = eT(arma_rng::randu()); } } template inline void subview_elem1::randn() { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; const unwrap_check_mixed tmp(a.get_ref(), m_local); const umat& aa = tmp.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; uword iq,jq; for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) { const uword ii = aa_mem[iq]; const uword jj = aa_mem[jq]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); arma_rng::randn::dual_val( m_mem[ii], m_mem[jj] ); } if(iq < aa_n_elem) { const uword ii = aa_mem[iq]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); m_mem[ii] = eT(arma_rng::randn()); } } template inline void subview_elem1::operator+= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem1::operator-= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem1::operator*= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem1::operator/= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } // // template template inline void subview_elem1::operator_equ(const subview_elem1& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator= (const subview_elem1& x) { arma_extra_debug_sigprint(); (*this).operator_equ(x); } //! work around compiler bugs template inline void subview_elem1::operator= (const subview_elem1& x) { arma_extra_debug_sigprint(); (*this).operator_equ(x); } template template inline void subview_elem1::operator+= (const subview_elem1& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator-= (const subview_elem1& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator%= (const subview_elem1& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator/= (const subview_elem1& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator+= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator-= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator%= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator/= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } // // template inline void subview_elem1::extract(Mat& actual_out, const subview_elem1& in) { arma_extra_debug_sigprint(); const unwrap_check_mixed tmp1(in.a.get_ref(), actual_out); const umat& aa = tmp1.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; const Mat& m_local = in.m; const eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; const bool alias = (&actual_out == &m_local); arma_extra_debug_warn(alias, "subview_elem1::extract(): aliasing detected"); Mat* tmp_out = alias ? new Mat() : 0; Mat& out = alias ? *tmp_out : actual_out; out.set_size(aa_n_elem, 1); eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); out_mem[i] = m_mem[ii]; out_mem[j] = m_mem[jj]; } if(i < aa_n_elem) { const uword ii = aa_mem[i]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); out_mem[i] = m_mem[ii]; } if(alias == true) { actual_out.steal_mem(out); delete tmp_out; } } template template inline void subview_elem1::mat_inplace_op(Mat& out, const subview_elem1& in) { arma_extra_debug_sigprint(); const unwrap tmp1(in.a.get_ref()); const umat& aa = tmp1.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; const unwrap_check< Mat > tmp2(in.m, out); const Mat& m_local = tmp2.M; const eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; arma_debug_check( (out.n_elem != aa_n_elem), "Mat::elem(): size mismatch" ); eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { out_mem[i] += m_mem[ii]; out_mem[j] += m_mem[jj]; } else if(is_same_type::yes) { out_mem[i] -= m_mem[ii]; out_mem[j] -= m_mem[jj]; } else if(is_same_type::yes) { out_mem[i] *= m_mem[ii]; out_mem[j] *= m_mem[jj]; } else if(is_same_type::yes) { out_mem[i] /= m_mem[ii]; out_mem[j] /= m_mem[jj]; } } if(i < aa_n_elem) { const uword ii = aa_mem[i]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { out_mem[i] += m_mem[ii]; } else if(is_same_type::yes) { out_mem[i] -= m_mem[ii]; } else if(is_same_type::yes) { out_mem[i] *= m_mem[ii]; } else if(is_same_type::yes) { out_mem[i] /= m_mem[ii]; } } } template inline void subview_elem1::plus_inplace(Mat& out, const subview_elem1& in) { arma_extra_debug_sigprint(); mat_inplace_op(out, in); } template inline void subview_elem1::minus_inplace(Mat& out, const subview_elem1& in) { arma_extra_debug_sigprint(); mat_inplace_op(out, in); } template inline void subview_elem1::schur_inplace(Mat& out, const subview_elem1& in) { arma_extra_debug_sigprint(); mat_inplace_op(out, in); } template inline void subview_elem1::div_inplace(Mat& out, const subview_elem1& in) { arma_extra_debug_sigprint(); mat_inplace_op(out, in); } //! @} RcppArmadillo/inst/include/armadillo_bits/arma_config.hpp0000644000176000001440000000542612260404154023403 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup arma_config //! @{ struct arma_config { #if defined(ARMA_MAT_PREALLOC) static const uword mat_prealloc = (sword(ARMA_MAT_PREALLOC) > 0) ? uword(ARMA_MAT_PREALLOC) : 1; #else static const uword mat_prealloc = 16; #endif #if defined(ARMA_SPMAT_CHUNKSIZE) static const uword spmat_chunksize = (sword(ARMA_SPMAT_CHUNKSIZE) > 0) ? uword(ARMA_SPMAT_CHUNKSIZE) : 256; #else static const uword spmat_chunksize = 256; #endif #if defined(ARMA_USE_ATLAS) static const bool atlas = true; #else static const bool atlas = false; #endif #if defined(ARMA_USE_LAPACK) static const bool lapack = true; #else static const bool lapack = false; #endif #if defined(ARMA_USE_BLAS) static const bool blas = true; #else static const bool blas = false; #endif #if defined(ARMA_USE_ARPACK) static const bool arpack = true; #else static const bool arpack = false; #endif #if defined(ARMA_USE_HDF5) static const bool hdf5 = true; #else static const bool hdf5 = false; #endif #if defined(ARMA_NO_DEBUG) static const bool debug = false; #else static const bool debug = true; #endif #if defined(ARMA_EXTRA_DEBUG) static const bool extra_debug = true; #else static const bool extra_debug = false; #endif #if defined(ARMA_GOOD_COMPILER) static const bool good_comp = true; #else static const bool good_comp = false; #endif #if ( \ defined(ARMA_EXTRA_MAT_PROTO) || defined(ARMA_EXTRA_MAT_MEAT) \ || defined(ARMA_EXTRA_COL_PROTO) || defined(ARMA_EXTRA_COL_MEAT) \ || defined(ARMA_EXTRA_ROW_PROTO) || defined(ARMA_EXTRA_ROW_MEAT) \ || defined(ARMA_EXTRA_CUBE_PROTO) || defined(ARMA_EXTRA_CUBE_MEAT) \ || defined(ARMA_EXTRA_FIELD_PROTO) || defined(ARMA_EXTRA_FIELD_MEAT) \ || defined(ARMA_EXTRA_SPMAT_PROTO) || defined(ARMA_EXTRA_SPMAT_MEAT) \ || defined(ARMA_EXTRA_SPCOL_PROTO) || defined(ARMA_EXTRA_SPCOL_MEAT) \ || defined(ARMA_EXTRA_SPROW_PROTO) || defined(ARMA_EXTRA_SPROW_MEAT) \ ) static const bool extra_code = true; #else static const bool extra_code = false; #endif #if defined(ARMA_USE_CXX11) static const bool use_cxx11 = true; #else static const bool use_cxx11 = false; #endif #if defined(ARMA_USE_WRAPPER) static const bool use_wrapper = true; #else static const bool use_wrapper = false; #endif }; //! @} RcppArmadillo/inst/include/armadillo_bits/cond_rel_meat.hpp0000644000176000001440000000244212111344723023724 0ustar ripleyusers// Copyright (C) 2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup cond_rel //! @{ template<> template arma_inline bool cond_rel::lt(const eT A, const eT B) { return (A < B); } template<> template arma_inline bool cond_rel::lt(const eT, const eT) { return false; } template<> template arma_inline bool cond_rel::gt(const eT A, const eT B) { return (A > B); } template<> template arma_inline bool cond_rel::gt(const eT, const eT) { return false; } template<> template arma_inline bool cond_rel::leq(const eT A, const eT B) { return (A <= B); } template<> template arma_inline bool cond_rel::leq(const eT, const eT) { return false; } template<> template arma_inline bool cond_rel::geq(const eT A, const eT B) { return (A >= B); } template<> template arma_inline bool cond_rel::geq(const eT, const eT) { return false; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_stddev_bones.hpp0000644000176000001440000000107012200631217024276 0ustar ripleyusers// Copyright (C) 2009-2011 Conrad Sanderson // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_stddev //! @{ //! Class for finding the standard deviation class op_stddev { public: template inline static void apply(Mat& out, const mtOp& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_chol.hpp0000644000176000001440000000201112200375542022533 0ustar ripleyusers// Copyright (C) 2009-2011 Conrad Sanderson // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_chol //! @{ template inline const Op chol ( const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X.get_ref()); } template inline bool chol ( Mat& out, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = chol(X); } catch(std::runtime_error&) { return false; } return true; } //! @} RcppArmadillo/inst/include/armadillo_bits/OpCube_bones.hpp0000644000176000001440000000407612176655102023510 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup OpCube //! @{ //! Analog of the Op class, intended for cubes template class OpCube : public BaseCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; inline explicit OpCube(const BaseCube& in_m); inline OpCube(const BaseCube& in_m, const elem_type in_aux); inline OpCube(const BaseCube& in_m, const elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); inline OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); inline OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c, const uword in_aux_uword_d, const char junk); inline ~OpCube(); arma_aligned const T1& m; //!< storage of reference to the operand (e.g. a cube) arma_aligned elem_type aux; //!< storage of auxiliary data, user defined format arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_c; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_d; //!< storage of auxiliary data, uword format }; //! @} RcppArmadillo/inst/include/armadillo_bits/SpSubview_iterators_meat.hpp0000644000176000001440000005710612200650771026173 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpSubview //! @{ /////////////////////////////////////////////////////////////////////////////// // SpSubview::iterator_base implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpSubview::iterator_base::iterator_base(const SpSubview& in_M) : M(in_M) , internal_col(0) , internal_pos(0) , skip_pos(0) { // Technically this iterator is invalid (it may not point to a real element). } template inline SpSubview::iterator_base::iterator_base(const SpSubview& in_M, const uword in_col, const uword in_pos, const uword in_skip_pos) : M(in_M) , internal_col(in_col) , internal_pos(in_pos) , skip_pos (in_skip_pos) { // Nothing to do. } template inline eT SpSubview::iterator_base::operator*() const { return M.m.values[internal_pos + skip_pos]; } /////////////////////////////////////////////////////////////////////////////// // SpSubview::const_iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpSubview::const_iterator::const_iterator(const SpSubview& in_M, const uword initial_pos) : iterator_base(in_M, 0, initial_pos, 0) { // Corner case for empty subviews. if(in_M.n_nonzero == 0) { iterator_base::internal_col = in_M.n_cols; iterator_base::skip_pos = in_M.m.n_nonzero; return; } // Figure out the row and column of the position. // lskip_pos holds the number of values which aren't part of this subview. const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_rows = iterator_base::M.n_rows; const uword ln_cols = iterator_base::M.n_cols; uword cur_pos = 0; // off by one because we might be searching for pos 0 uword lskip_pos = iterator_base::M.m.col_ptrs[aux_col]; uword cur_col = 0; while(cur_pos < (iterator_base::internal_pos + 1)) { // Have we stepped forward a column (or multiple columns)? while(((lskip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]) && (cur_col < ln_cols)) { ++cur_col; } // See if the current position is in the subview. const uword row_index = iterator_base::M.m.row_indices[cur_pos + lskip_pos]; if(row_index < aux_row) { ++lskip_pos; // not valid } else if(row_index < (aux_row + ln_rows)) { ++cur_pos; // valid, in the subview } else { // skip to end of column const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; lskip_pos += (next_colptr - (cur_pos + lskip_pos)); } } iterator_base::internal_col = cur_col; iterator_base::skip_pos = lskip_pos; } template inline SpSubview::const_iterator::const_iterator(const SpSubview& in_M, const uword in_row, const uword in_col) : iterator_base(in_M, in_col, 0, 0) { // Corner case for empty subviews. if(in_M.n_nonzero == 0) { // We must be at the last position. iterator_base::internal_col = in_M.n_cols; iterator_base::skip_pos = in_M.m.n_nonzero; return; } // We have a destination we want to be just after, but don't know what position that is. // Because we have to count the points in this subview and not in this subview, this becomes a little difficult and slow. const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_rows = iterator_base::M.n_rows; const uword ln_cols = iterator_base::M.n_cols; uword cur_pos = 0; uword skip_pos = iterator_base::M.m.col_ptrs[aux_col]; uword cur_col = 0; while(cur_col < in_col) { // See if the current position is in the subview. const uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; if(row_index < aux_row) { ++skip_pos; } else if(row_index < (aux_row + ln_rows)) { ++cur_pos; } else { // skip to end of column const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; skip_pos += (next_colptr - (cur_pos + skip_pos)); } // Have we stepped forward a column (or multiple columns)? while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]) && (cur_col < ln_cols)) { ++cur_col; } } // Now we are either on the right column or ahead of it. if(cur_col == in_col) { // We have to find the right row index. uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; while((row_index < (in_row + aux_row))) { if(row_index < aux_row) { ++skip_pos; } else { ++cur_pos; } // Ensure we didn't step forward a column; if we did, we need to stop. while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]) && (cur_col < ln_cols)) { ++cur_col; } if(cur_col != in_col) { break; } row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; } } // Now we need to find the next valid position in the subview. uword row_index; while(true) { const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; // Are we at the last position? if(cur_col >= ln_cols) { cur_col = ln_cols; // Make sure we will be pointing at the last element in the parent matrix. skip_pos = iterator_base::M.m.n_nonzero - iterator_base::M.n_nonzero; break; } if(row_index < aux_row) { ++skip_pos; } else if(row_index < (aux_row + ln_rows)) { break; // found } else { skip_pos += (next_colptr - (cur_pos + skip_pos)); } // Did we move any columns? while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]) && (cur_col < ln_cols)) { ++cur_col; } } // It is possible we have moved another column. while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]) && (cur_col < ln_cols)) { ++cur_col; } iterator_base::internal_pos = cur_pos; iterator_base::skip_pos = skip_pos; iterator_base::internal_col = cur_col; } template inline SpSubview::const_iterator::const_iterator(const SpSubview& in_M, uword in_row, uword in_col, uword in_pos, uword in_skip_pos) : iterator_base(in_M, in_col, in_pos, in_skip_pos) { arma_ignore(in_row); // Nothing to do. } template inline SpSubview::const_iterator::const_iterator(const const_iterator& other) : iterator_base(other.M, other.internal_col, other.internal_pos, other.skip_pos) { // Nothing to do. } template inline typename SpSubview::const_iterator& SpSubview::const_iterator::operator++() { const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_rows = iterator_base::M.n_rows; const uword ln_cols = iterator_base::M.n_cols; uword cur_col = iterator_base::internal_col; uword cur_pos = iterator_base::internal_pos + 1; uword lskip_pos = iterator_base::skip_pos; uword row_index; while(true) { const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; row_index = iterator_base::M.m.row_indices[cur_pos + lskip_pos]; // Did we move any columns? while((cur_col < ln_cols) && ((lskip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1])) { ++cur_col; } // Are we at the last position? if(cur_col >= ln_cols) { cur_col = ln_cols; // Make sure we will be pointing at the last element in the parent matrix. lskip_pos = iterator_base::M.m.n_nonzero - iterator_base::M.n_nonzero; break; } if(row_index < aux_row) { ++lskip_pos; } else if(row_index < (aux_row + ln_rows)) { break; // found } else { lskip_pos += (next_colptr - (cur_pos + lskip_pos)); } } iterator_base::internal_pos = cur_pos; iterator_base::internal_col = cur_col; iterator_base::skip_pos = lskip_pos; return *this; } template inline typename SpSubview::const_iterator SpSubview::const_iterator::operator++(int) { typename SpSubview::const_iterator tmp(*this); ++(*this); return tmp; } template inline typename SpSubview::const_iterator& SpSubview::const_iterator::operator--() { const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_rows = iterator_base::M.n_rows; uword cur_col = iterator_base::internal_col; uword cur_pos = iterator_base::internal_pos - 1; uword skip_pos = iterator_base::skip_pos; // Special condition for end of iterator. if((skip_pos + cur_pos + 1) == iterator_base::M.m.n_nonzero) { // We are at the last element. So we need to set skip_pos back to what it // would be if we didn't manually modify it back in operator++(). skip_pos = iterator_base::M.m.col_ptrs[cur_col + aux_col] - iterator_base::internal_pos; } uword row_index; while(true) { const uword colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col]; row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; // Did we move back any columns? while((skip_pos + cur_pos) < iterator_base::M.m.col_ptrs[cur_col + aux_col]) { --cur_col; } if(row_index < aux_row) { skip_pos -= (colptr - (cur_pos + skip_pos) + 1); } else if(row_index < (aux_row + ln_rows)) { break; // found } else { --skip_pos; } } iterator_base::internal_pos = cur_pos; iterator_base::skip_pos = skip_pos; iterator_base::internal_col = cur_col; return *this; } template inline typename SpSubview::const_iterator SpSubview::const_iterator::operator--(int) { typename SpSubview::const_iterator tmp(*this); --(*this); return tmp; } template inline bool SpSubview::const_iterator::operator==(const const_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator!=(const const_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator==(const typename SpMat::const_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator!=(const typename SpMat::const_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator==(const const_row_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator!=(const const_row_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator==(const typename SpMat::const_row_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator!=(const typename SpMat::const_row_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } /////////////////////////////////////////////////////////////////////////////// // SpSubview::iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpValProxy > SpSubview::iterator::operator*() { return SpValProxy >( iterator_base::row(), iterator_base::col(), access::rw(iterator_base::M), &(access::rw(iterator_base::M.m.values[iterator_base::internal_pos + iterator_base::skip_pos]))); } template inline typename SpSubview::iterator& SpSubview::iterator::operator++() { const_iterator::operator++(); return *this; } template inline typename SpSubview::iterator SpSubview::iterator::operator++(int) { typename SpSubview::iterator tmp(*this); const_iterator::operator++(); return tmp; } template inline typename SpSubview::iterator& SpSubview::iterator::operator--() { const_iterator::operator--(); return *this; } template inline typename SpSubview::iterator SpSubview::iterator::operator--(int) { typename SpSubview::iterator tmp(*this); const_iterator::operator--(); return tmp; } /////////////////////////////////////////////////////////////////////////////// // SpSubview::const_row_iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpSubview::const_row_iterator::const_row_iterator(const SpSubview& in_M, uword initial_pos) : iterator_base(in_M, 0, initial_pos, 0) , internal_row(0) , actual_pos(0) { // Corner case for empty subviews. if(in_M.n_nonzero == 0) { iterator_base::internal_col = 0; internal_row = in_M.n_rows; iterator_base::skip_pos = in_M.m.n_nonzero; return; } const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_cols = iterator_base::M.n_cols; // We don't know where the elements are in each row. What we will do is // loop across all valid columns looking for elements in row 0 (and add to // our sum), then in row 1, and so forth, until we get to the desired // position. uword cur_pos = -1; uword cur_row = 0; uword cur_col = 0; while(true) { // Is there anything in the column we are looking at? const uword colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col]; const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; for(uword ind = colptr; (ind < next_colptr) && (iterator_base::M.m.row_indices[ind] <= (cur_row + aux_row)); ++ind) { // There is something in this column. Is it in the row we are looking at? const uword row_index = iterator_base::M.m.row_indices[ind]; if(row_index == (cur_row + aux_row)) { // Yes, it is in the right row. if(++cur_pos == iterator_base::internal_pos) { iterator_base::internal_col = cur_col; internal_row = cur_row; actual_pos = ind; return; } // We are done with this column. Break to the column incrementing code (directly below). break; } else if(row_index > (cur_row + aux_row)) { break; // Can't be in this column. } } cur_col++; // Done with the column. Move on. if(cur_col == ln_cols) { // Out of columns. Loop back to the beginning and look on the next row. cur_col = 0; cur_row++; } } } template inline SpSubview::const_row_iterator::const_row_iterator(const SpSubview& in_M, uword in_row, uword in_col) : iterator_base(in_M, in_col, 0, 0) , internal_row(0) , actual_pos(0) { // We have a destination we want to be just after, but don't know what that // position is. Because we will have to loop over everything anyway, create // another iterator and loop it until it is at the right place, then take its // information. const_row_iterator it(in_M, 0); while((it.row() < in_row) || ((it.row() == in_row) && (it.col() < in_col))) { ++it; } iterator_base::internal_col = it.col(); iterator_base::internal_pos = it.pos(); iterator_base::skip_pos = it.skip_pos; internal_row = it.internal_row; actual_pos = it.actual_pos; } template inline SpSubview::const_row_iterator::const_row_iterator(const const_row_iterator& other) : iterator_base(other.M, other.internal_col, other.internal_pos, other.skip_pos) , internal_row(other.internal_row) , actual_pos(other.actual_pos) { // Nothing to do. } template inline typename SpSubview::const_row_iterator& SpSubview::const_row_iterator::operator++() { // We just need to find the next nonzero element. ++iterator_base::internal_pos; // If we have exceeded the bounds, update accordingly. if(iterator_base::internal_pos >= iterator_base::M.n_nonzero) { internal_row = iterator_base::M.n_rows; iterator_base::internal_col = 0; actual_pos = iterator_base::M.m.n_nonzero; return *this; } // Otherwise, we need to search. uword cur_col = iterator_base::internal_col; uword cur_row = internal_row; const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_cols = iterator_base::M.n_cols; while(true) { // Increment the current column and see if we are on a new row. if(++cur_col == ln_cols) { cur_col = 0; ++cur_row; } // Is there anything in this new column? const uword colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col]; const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; for(uword ind = colptr; (ind < next_colptr) && (iterator_base::M.m.row_indices[ind] <= (cur_row + aux_row)); ++ind) { const uword row_index = iterator_base::M.m.row_indices[ind]; if((row_index - aux_row) == cur_row) { // We have successfully incremented. internal_row = cur_row; actual_pos = ind; iterator_base::internal_col = cur_col; return *this; } } } } template inline typename SpSubview::const_row_iterator SpSubview::const_row_iterator::operator++(int) { typename SpSubview::const_row_iterator tmp(*this); ++(*this); return tmp; } template inline typename SpSubview::const_row_iterator& SpSubview::const_row_iterator::operator--() { // We just need to find the previous element. // if(iterator_base::pos == 0) // { // // We cannot decrement. // return *this; // } // else if(iterator_base::pos == iterator_base::M.n_nonzero) // { // // We will be coming off the last element. We need to reset the row correctly, because we set row = 0 in the last matrix position. // iterator_base::row = iterator_base::M.n_rows - 1; // } // else if(iterator_base::pos > iterator_base::M.n_nonzero) // { // // This shouldn't happen... // iterator_base::pos--; // return *this; // } iterator_base::internal_pos--; // We have to search backwards. uword cur_col = iterator_base::internal_col; uword cur_row = internal_row; const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_cols = iterator_base::M.n_cols; while(true) { // Decrement the current column and see if we are on a new row. if(--cur_col > ln_cols) { cur_col = ln_cols - 1; cur_row--; } // Is there anything in this new column? const uword colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col]; const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; for(uword ind = colptr; (ind < next_colptr) && (iterator_base::M.m.row_indices[ind] <= (cur_row + aux_row)); ++ind) { const uword row_index = iterator_base::M.m.row_indices[ind]; if((row_index - aux_row) == cur_row) { iterator_base::internal_col = cur_col; internal_row = cur_row; actual_pos = ind; return *this; } } } } template inline typename SpSubview::const_row_iterator SpSubview::const_row_iterator::operator--(int) { typename SpSubview::const_row_iterator tmp(*this); --(*this); return tmp; } template inline bool SpSubview::const_row_iterator::operator==(const const_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator!=(const const_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator==(const typename SpMat::const_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator!=(const typename SpMat::const_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator==(const const_row_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator!=(const const_row_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator==(const typename SpMat::const_row_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator!=(const typename SpMat::const_row_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } /////////////////////////////////////////////////////////////////////////////// // SpSubview::row_iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpValProxy > SpSubview::row_iterator::operator*() { return SpValProxy >( const_row_iterator::internal_row, iterator_base::internal_col, access::rw(iterator_base::M), &access::rw(iterator_base::M.m.values[const_row_iterator::actual_pos])); } template inline typename SpSubview::row_iterator& SpSubview::row_iterator::operator++() { const_row_iterator::operator++(); return *this; } template inline typename SpSubview::row_iterator SpSubview::row_iterator::operator++(int) { typename SpSubview::row_iterator tmp(*this); ++(*this); return tmp; } template inline typename SpSubview::row_iterator& SpSubview::row_iterator::operator--() { const_row_iterator::operator--(); return *this; } template inline typename SpSubview::row_iterator SpSubview::row_iterator::operator--(int) { typename SpSubview::row_iterator tmp(*this); --(*this); return tmp; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_diagmat_meat.hpp0000644000176000001440000000645112222743646024261 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_diagmat //! @{ template inline void op_diagmat::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const bool P_is_vec = (n_rows == 1) || (n_cols == 1); if(P.is_alias(out) == false) { if(P_is_vec) // generate a diagonal matrix out of a vector { const uword N = (n_rows == 1) ? n_cols : n_rows; out.zeros(N, N); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type P_ea = P.get_ea(); for(uword i=0; i < N; ++i) { out.at(i,i) = P_ea[i]; } } else { if(n_rows == 1) { for(uword i=0; i < N; ++i) { out.at(i,i) = P.at(0,i); } } else { for(uword i=0; i < N; ++i) { out.at(i,i) = P.at(i,0); } } } } else // generate a diagonal matrix out of a matrix { arma_debug_check( (n_rows != n_cols), "diagmat(): given matrix is not square" ); out.zeros(n_rows, n_rows); for(uword i=0; i < n_rows; ++i) { out.at(i,i) = P.at(i,i); } } } else // we have aliasing { if(P_is_vec) // generate a diagonal matrix out of a vector { const uword N = (n_rows == 1) ? n_cols : n_rows; podarray tmp(N); eT* tmp_mem = tmp.memptr(); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type P_ea = P.get_ea(); for(uword i=0; i < N; ++i) { tmp_mem[i] = P_ea[i]; } } else { if(n_rows == 1) { for(uword i=0; i < N; ++i) { tmp_mem[i] = P.at(0,i); } } else { for(uword i=0; i < N; ++i) { tmp_mem[i] = P.at(i,0); } } } out.zeros(N, N); for(uword i=0; i < N; ++i) { out.at(i,i) = tmp_mem[i]; } } else // generate a diagonal matrix out of a matrix { arma_debug_check( (n_rows != n_cols), "diagmat(): given matrix is not square" ); if( (Proxy::has_subview == false) && (Proxy::fake_mat == false) ) { // NOTE: we have aliasing and it's not due to a subview, hence we're assuming that the output matrix already has the correct size for(uword i=0; i < n_rows; ++i) { const eT val = P.at(i,i); arrayops::fill_zeros(out.colptr(i), n_rows); out.at(i,i) = val; } } else { podarray tmp(n_rows); eT* tmp_mem = tmp.memptr(); for(uword i=0; i < n_rows; ++i) { tmp_mem[i] = P.at(i,i); } out.zeros(n_rows, n_rows); for(uword i=0; i < n_rows; ++i) { out.at(i,i) = tmp_mem[i]; } } } } } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_histc.hpp0000644000176000001440000000134712256562725022747 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Boris Sabanin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. template inline const mtGlue histc ( const Base& A, const Base& B, const uword dim = 0, const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtGlue( A.get_ref(), B.get_ref(), dim ); } RcppArmadillo/inst/include/armadillo_bits/SizeMat_bones.hpp0000644000176000001440000000135012247362764023707 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SizeMat //! @{ class SizeMat { public: const uword n_rows; const uword n_cols; inline SizeMat(const uword in_n_rows = 0, const uword in_n_cols = 0); // inline operator SizeCube () const; inline bool operator==(const SizeMat& s) const; inline bool operator!=(const SizeMat& s) const; inline bool operator==(const SizeCube& s) const; inline bool operator!=(const SizeCube& s) const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_unique_meat.hpp0000644000176000001440000000522612200631217024142 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Arnold Wiliem // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_unique //! @{ // TODO: add an efficient implementation for complex numbers template inline void op_unique::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.m); const uword in_n_rows = P.get_n_rows(); const uword in_n_cols = P.get_n_cols(); const uword in_n_elem = P.get_n_elem(); if(in_n_elem <= 1) { if(in_n_elem == 1) { const eT tmp = P[0]; out.set_size(in_n_rows, in_n_cols); out[0] = tmp; } else { out.set_size(in_n_rows, in_n_cols); } return; } std::vector lvec(in_n_elem); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = Pea[i]; const eT tmp_j = Pea[j]; lvec[i] = tmp_i; lvec[j] = tmp_j; } if(i < in_n_elem) { lvec[i] = Pea[i]; } } else { uword i = 0; for(uword col=0; col < in_n_cols; ++col) for(uword row=0; row < in_n_rows; ++row, ++i) { lvec[i] = P.at(row,col); } } std::sort( lvec.begin(), lvec.end() ); uword N_unique = 1; for(uword i=1; i < in_n_elem; ++i) { const eT a = lvec[i-1]; const eT b = lvec[i ]; const eT diff = a - b; if(diff != eT(0)) { ++N_unique; } } uword out_n_rows; uword out_n_cols; if( (in_n_rows == 1) || (in_n_cols == 1) ) { if(in_n_rows == 1) { out_n_rows = 1; out_n_cols = N_unique; } else { out_n_rows = N_unique; out_n_cols = 1; } } else { out_n_rows = N_unique; out_n_cols = 1; } // we don't need to worry about aliasing at this stage, as all the data is stored in lvec out.set_size(out_n_rows, out_n_cols); eT* out_mem = out.memptr(); if(in_n_elem > 0) { out_mem[0] = lvec[0]; } N_unique = 1; for(uword i=1; i < in_n_elem; ++i) { const eT a = lvec[i-1]; const eT b = lvec[i ]; const eT diff = a - b; if(diff != eT(0)) { out_mem[N_unique] = b; ++N_unique; } } } //! @} RcppArmadillo/inst/include/armadillo_bits/eOpCube_bones.hpp0000644000176000001440000000453712176655102023657 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup eOpCube //! @{ template class eOpCube : public BaseCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool prefer_at_accessor = ProxyCube::prefer_at_accessor; static const bool has_subview = ProxyCube::has_subview; arma_aligned const ProxyCube P; arma_aligned elem_type aux; //!< storage of auxiliary data, user defined format arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_c; //!< storage of auxiliary data, uword format inline ~eOpCube(); inline explicit eOpCube(const BaseCube& in_m); inline eOpCube(const BaseCube& in_m, const elem_type in_aux); inline eOpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline eOpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); inline eOpCube(const BaseCube& in_m, const elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); arma_inline uword get_n_rows() const; arma_inline uword get_n_cols() const; arma_inline uword get_n_elem_slice() const; arma_inline uword get_n_slices() const; arma_inline uword get_n_elem() const; arma_inline elem_type operator[] (const uword i) const; arma_inline elem_type at (const uword row, const uword col, const uword slice) const; arma_inline elem_type at_alt (const uword i) const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/spop_var_meat.hpp0000644000176000001440000002137612111344723023777 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_var //! @{ template inline void spop_var::apply(SpMat& out, const mtSpOp& in) { arma_extra_debug_sigprint(); //typedef typename T1::elem_type in_eT; typedef typename T1::pod_type out_eT; const uword norm_type = in.aux_uword_a; const uword dim = in.aux_uword_b; arma_debug_check((norm_type > 1), "var(): incorrect usage. norm_type must be 0 or 1"); arma_debug_check((dim > 1), "var(): incorrect usage. dim must be 0 or 1"); SpProxy p(in.m); if(p.is_alias(out) == false) { spop_var::apply_noalias(out, p, norm_type, dim); } else { SpMat tmp; spop_var::apply_noalias(tmp, p, norm_type, dim); out.steal_mem(tmp); } } template inline void spop_var::apply_noalias ( SpMat& out_ref, const SpProxy& p, const uword norm_type, const uword dim ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type in_eT; //typedef typename T1::pod_type out_eT; const uword p_n_rows = p.get_n_rows(); const uword p_n_cols = p.get_n_cols(); if(dim == 0) { arma_extra_debug_print("spop_var::apply(), dim = 0"); arma_debug_check((p_n_rows == 0), "var(): given object has zero rows"); out_ref.set_size(1, p_n_cols); for(uword col = 0; col < p_n_cols; ++col) { if(SpProxy::must_use_iterator == true) { // We must use an iterator; we can't access memory directly. typename SpProxy::const_iterator_type it = p.begin_col(col); typename SpProxy::const_iterator_type end = p.begin_col(col + 1); const uword n_zero = p.get_n_rows() - (end.pos() - it.pos()); // in_eT is used just to get the specialization right (complex / noncomplex) out_ref.at(col) = spop_var::iterator_var(it, end, n_zero, norm_type, in_eT(0)); } else { // We can use direct memory access to calculate the variance. out_ref.at(col) = spop_var::direct_var ( &p.get_values()[p.get_col_ptrs()[col]], p.get_col_ptrs()[col + 1] - p.get_col_ptrs()[col], p.get_n_rows(), norm_type ); } } } else if(dim == 1) { arma_extra_debug_print("spop_var::apply_noalias(), dim = 1"); arma_debug_check((p_n_cols == 0), "var(): given object has zero columns"); out_ref.set_size(p_n_rows, 1); for(uword row = 0; row < p_n_rows; ++row) { // We have to use an iterator here regardless of whether or not we can // directly access memory. typename SpProxy::const_row_iterator_type it = p.begin_row(row); typename SpProxy::const_row_iterator_type end = p.end_row(row); const uword n_zero = p.get_n_cols() - (end.pos() - it.pos()); out_ref.at(row) = spop_var::iterator_var(it, end, n_zero, norm_type, in_eT(0)); } } } template inline typename T1::pod_type spop_var::var_vec ( const T1& X, const uword norm_type ) { arma_extra_debug_sigprint(); arma_debug_check((norm_type > 1), "var(): incorrect usage. norm_type must be 0 or 1."); // conditionally unwrap it into a temporary and then directly operate. const unwrap_spmat tmp(X); return direct_var(tmp.M.values, tmp.M.n_nonzero, tmp.M.n_elem, norm_type); } template inline eT spop_var::direct_var ( const eT* const X, const uword length, const uword N, const uword norm_type ) { arma_extra_debug_sigprint(); if(length >= 2 && N >= 2) { const eT acc1 = spop_mean::direct_mean(X, length, N); eT acc2 = eT(0); eT acc3 = eT(0); uword i, j; for(i = 0, j = 1; j < length; i += 2, j += 2) { const eT Xi = X[i]; const eT Xj = X[j]; const eT tmpi = acc1 - Xi; const eT tmpj = acc1 - Xj; acc2 += tmpi * tmpi + tmpj * tmpj; acc3 += tmpi + tmpj; } if(i < length) { const eT Xi = X[i]; const eT tmpi = acc1 - Xi; acc2 += tmpi * tmpi; acc3 += tmpi; } // Now add in all zero elements. acc2 += (N - length) * (acc1 * acc1); acc3 += (N - length) * acc1; const eT norm_val = (norm_type == 0) ? eT(N - 1) : eT(N); const eT var_val = (acc2 - (acc3 * acc3) / eT(N)) / norm_val; return var_val; } else if(length == 1 && N > 1) // if N == 1, then variance is zero. { const eT mean = X[0] / eT(N); const eT val = mean - X[0]; const eT acc2 = (val * val) + (N - length) * (mean * mean); const eT acc3 = val + (N - length) * mean; const eT norm_val = (norm_type == 0) ? eT(N - 1) : eT(N); const eT var_val = (acc2 - (acc3 * acc3) / eT(N)) / norm_val; return var_val; } else { return eT(0); } } template inline T spop_var::direct_var ( const std::complex* const X, const uword length, const uword N, const uword norm_type ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(length >= 2 && N >= 2) { const eT acc1 = spop_mean::direct_mean(X, length, N); T acc2 = T(0); eT acc3 = eT(0); for (uword i = 0; i < length; ++i) { const eT tmp = acc1 - X[i]; acc2 += std::norm(tmp); acc3 += tmp; } // Add zero elements to sums acc2 += std::norm(acc1) * T(N - length); acc3 += acc1 * T(N - length); const T norm_val = (norm_type == 0) ? T(N - 1) : T(N); const T var_val = (acc2 - std::norm(acc3) / T(N)) / norm_val; return var_val; } else if(length == 1 && N > 1) // if N == 1, then variance is zero. { const eT mean = X[0] / T(N); const eT val = mean - X[0]; const T acc2 = std::norm(val) + (N - length) * std::norm(mean); const eT acc3 = val + T(N - length) * mean; const T norm_val = (norm_type == 0) ? T(N - 1) : T(N); const T var_val = (acc2 - std::norm(acc3) / T(N)) / norm_val; return var_val; } else { return T(0); // All elements are zero } } template inline eT spop_var::iterator_var ( T1& it, const T1& end, const uword n_zero, const uword norm_type, const eT junk1, const typename arma_not_cx::result* junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); T1 new_it(it); // for mean // T1 backup_it(it); // in case we have to call robust iterator_var eT mean = spop_mean::iterator_mean(new_it, end, n_zero, eT(0)); eT acc2 = eT(0); eT acc3 = eT(0); const uword it_begin_pos = it.pos(); while (it != end) { const eT tmp = mean - (*it); acc2 += (tmp * tmp); acc3 += (tmp); ++it; } const uword n_nonzero = (it.pos() - it_begin_pos); if (n_nonzero == 0) { return eT(0); } if (n_nonzero + n_zero == 1) { return eT(0); // only one element } // Add in entries for zeros. acc2 += eT(n_zero) * (mean * mean); acc3 += eT(n_zero) * mean; const eT norm_val = (norm_type == 0) ? eT(n_zero + n_nonzero - 1) : eT(n_zero + n_nonzero); const eT var_val = (acc2 - (acc3 * acc3) / eT(n_nonzero + n_zero)) / norm_val; return var_val; } template inline typename get_pod_type::result spop_var::iterator_var ( T1& it, const T1& end, const uword n_zero, const uword norm_type, const eT junk1, const typename arma_cx_only::result* junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); typedef typename get_pod_type::result T; T1 new_it(it); // for mean // T1 backup_it(it); // in case we have to call robust iterator_var eT mean = spop_mean::iterator_mean(new_it, end, n_zero, eT(0)); T acc2 = T(0); eT acc3 = eT(0); const uword it_begin_pos = it.pos(); while (it != end) { eT tmp = mean - (*it); acc2 += std::norm(tmp); acc3 += (tmp); ++it; } const uword n_nonzero = (it.pos() - it_begin_pos); if (n_nonzero == 0) { return T(0); } if (n_nonzero + n_zero == 1) { return T(0); // only one element } // Add in entries for zero elements. acc2 += T(n_zero) * std::norm(mean); acc3 += T(n_zero) * mean; const T norm_val = (norm_type == 0) ? T(n_zero + n_nonzero - 1) : T(n_zero + n_nonzero); const T var_val = (acc2 - std::norm(acc3) / T(n_nonzero + n_zero)) / norm_val; return var_val; } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_eps.hpp0000644000176000001440000000357312200375542022413 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_eps //! @{ //! \brief //! eps version for non-complex matrices and vectors template inline const eOp eps(const Base& X, const typename arma_not_cx::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return eOp(X.get_ref()); } //! \brief //! eps version for complex matrices and vectors template inline Mat< typename T1::pod_type > eps(const Base< std::complex, T1>& X, const typename arma_cx_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; typedef typename T1::elem_type eT; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; Mat out(A.n_rows, A.n_cols); T* out_mem = out.memptr(); const eT* A_mem = A.memptr(); const uword n_elem = A.n_elem; for(uword i=0; i arma_inline arma_warn_unused typename arma_integral_only::result eps(const eT& x) { arma_ignore(x); return eT(0); } template arma_inline arma_warn_unused typename arma_real_only::result eps(const eT& x) { return eop_aux::direct_eps(x); } template arma_inline arma_warn_unused typename arma_real_only::result eps(const std::complex& x) { return eop_aux::direct_eps(x); } //! @} RcppArmadillo/inst/include/armadillo_bits/typedef_elem_check.hpp0000644000176000001440000000304312246642071024734 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup typedef_elem //! @{ namespace junk { struct arma_elem_size_test { arma_static_check( (sizeof(u8) != 1), ERROR___TYPE_U8_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(s8) != 1), ERROR___TYPE_S8_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(u16) != 2), ERROR___TYPE_U16_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(s16) != 2), ERROR___TYPE_S16_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(u32) != 4), ERROR___TYPE_U32_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(s32) != 4), ERROR___TYPE_S32_HAS_UNSUPPORTED_SIZE ); #if defined(ARMA_USE_U64S64) arma_static_check( (sizeof(u64) != 8), ERROR___TYPE_U64_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(s64) != 8), ERROR___TYPE_S64_HAS_UNSUPPORTED_SIZE ); #endif arma_static_check( (sizeof(float) != 4), ERROR___TYPE_FLOAT_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(double) != 8), ERROR___TYPE_DOUBLE_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(std::complex) != 8), ERROR___TYPE_COMPLEX_FLOAT_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(std::complex) != 16), ERROR___TYPE_COMPLEX_DOUBLE_HAS_UNSUPPORTED_SIZE ); }; } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_resize.hpp0000644000176000001440000000160312200375542023115 0ustar ripleyusers// Copyright (C) 2011 Conrad Sanderson // Copyright (C) 2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_resize //! @{ template inline const Op resize(const Base& X, const uword in_n_rows, const uword in_n_cols) { arma_extra_debug_sigprint(); return Op(X.get_ref(), in_n_rows, in_n_cols); } template inline const OpCube resize(const BaseCube& X, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) { arma_extra_debug_sigprint(); return OpCube(X.get_ref(), in_n_rows, in_n_cols, in_n_slices); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_inv_bones.hpp0000644000176000001440000000231412200631217023603 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_inv //! @{ //! 'invert matrix' operation (general matrices) class op_inv { public: template inline static void apply(Mat& out, const Mat& A, const bool slow = false); template inline static void apply(Mat& out, const Op& in); template inline static void apply_diag(Mat& out, const Base& X); }; //! 'invert matrix' operation (triangular matrices) class op_inv_tr { public: template inline static void apply(Mat& out, const Op& in); }; //! 'invert matrix' operation (symmetric positive definite matrices) class op_inv_sympd { public: template inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/SpBase_bones.hpp0000644000176000001440000000247612176655102023512 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpBase //! @{ template struct SpBase { arma_inline const derived& get_ref() const; inline const SpOp t() const; //!< Hermitian transpose inline const SpOp ht() const; //!< Hermitian transpose inline const SpOp st() const; //!< simple transpose inline void print(const std::string extra_text = "") const; inline void print(std::ostream& user_stream, const std::string extra_text = "") const; inline void raw_print(const std::string extra_text = "") const; inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const; inline void print_dense(const std::string extra_text = "") const; inline void print_dense(std::ostream& user_stream, const std::string extra_text = "") const; inline void raw_print_dense(const std::string extra_text = "") const; inline void raw_print_dense(std::ostream& user_stream, const std::string extra_text = "") const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_speye.hpp0000644000176000001440000000223412256055347022753 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_speye //! @{ //! Generate a sparse matrix with the values along the main diagonal set to one template inline obj_type speye(const uword n_rows, const uword n_cols, const typename arma_SpMat_SpCol_SpRow_only::result* junk = NULL) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_SpCol::value == true) { arma_debug_check( (n_cols != 1), "speye(): incompatible size" ); } else if(is_SpRow::value == true) { arma_debug_check( (n_rows != 1), "speye(): incompatible size" ); } obj_type out; out.eye(n_rows, n_cols); return out; } // Convenience shortcut method (no template parameter necessary) inline sp_mat speye(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); sp_mat out; out.eye(n_rows, n_cols); return out; } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_mean.hpp0000644000176000001440000000664212200375542022544 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_mean //! @{ template arma_inline const Op mean ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op mean ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type mean ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_mean::mean_all(X); } //! \brief //! Immediate 'find mean value' operation, //! invoked, for example, by: mean(mean(A)) template inline arma_warn_unused typename T1::elem_type mean(const Op& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("mean(): two consecutive mean() calls detected"); return op_mean::mean_all(in.m); } template arma_inline const Op< Op, op_mean> mean(const Op& in, const uword dim) { arma_extra_debug_sigprint(); return Op< Op, op_mean>(in, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & mean(const T& x) { return x; } template inline arma_warn_unused const SpOp mean ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_sparse_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_sparse_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return SpOp(X, dim, 0); } template inline arma_warn_unused const SpOp mean ( const T1& X, const uword dim, const typename enable_if< resolves_to_sparse_vector::value == true >::result* junk1 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); return SpOp(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type mean ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if< resolves_to_sparse_vector::value == true >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return spop_mean::mean_all(X); } template inline arma_warn_unused typename T1::elem_type mean(const SpOp& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("mean(): two consecutive mean() calls detected"); return spop_mean::mean_all(in.m); } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_solve_bones.hpp0000644000176000001440000000150512200375542024464 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_solve //! @{ class glue_solve { public: template inline static void solve_direct(Mat& out, Mat& A, const Base& X, const bool slow); template inline static void apply(Mat& out, const Glue& X); }; class glue_solve_tr { public: template inline static void apply(Mat& out, const Glue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/traits.hpp0000644000176000001440000007126412200116446022445 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup traits //! @{ template struct get_pod_type { typedef T1 result; }; template struct get_pod_type< std::complex > { typedef T2 result; }; template struct is_Mat_fixed_only { typedef char yes[1]; typedef char no[2]; template static yes& check(typename X::Mat_fixed_type*); template static no& check(...); static const bool value = ( sizeof(check(0)) == sizeof(yes) ); }; template struct is_Row_fixed_only { typedef char yes[1]; typedef char no[2]; template static yes& check(typename X::Row_fixed_type*); template static no& check(...); static const bool value = ( sizeof(check(0)) == sizeof(yes) ); }; template struct is_Col_fixed_only { typedef char yes[1]; typedef char no[2]; template static yes& check(typename X::Col_fixed_type*); template static no& check(...); static const bool value = ( sizeof(check(0)) == sizeof(yes) ); }; template struct is_Mat_fixed { static const bool value = ( is_Mat_fixed_only::value || is_Row_fixed_only::value || is_Col_fixed_only::value ); }; template struct is_Mat_only { static const bool value = is_Mat_fixed_only::value; }; template struct is_Mat_only< Mat > { static const bool value = true; }; template struct is_Mat_only< const Mat > { static const bool value = true; }; template struct is_Mat { static const bool value = ( is_Mat_fixed_only::value || is_Row_fixed_only::value || is_Col_fixed_only::value ); }; template struct is_Mat< Mat > { static const bool value = true; }; template struct is_Mat< const Mat > { static const bool value = true; }; template struct is_Mat< Row > { static const bool value = true; }; template struct is_Mat< const Row > { static const bool value = true; }; template struct is_Mat< Col > { static const bool value = true; }; template struct is_Mat< const Col > { static const bool value = true; }; template struct is_Row { static const bool value = is_Row_fixed_only::value; }; template struct is_Row< Row > { static const bool value = true; }; template struct is_Row< const Row > { static const bool value = true; }; template struct is_Col { static const bool value = is_Col_fixed_only::value; }; template struct is_Col< Col > { static const bool value = true; }; template struct is_Col< const Col > { static const bool value = true; }; template struct is_diagview { static const bool value = false; }; template struct is_diagview< diagview > { static const bool value = true; }; template struct is_diagview< const diagview > { static const bool value = true; }; template struct is_subview { static const bool value = false; }; template struct is_subview< subview > { static const bool value = true; }; template struct is_subview< const subview > { static const bool value = true; }; template struct is_subview_row { static const bool value = false; }; template struct is_subview_row< subview_row > { static const bool value = true; }; template struct is_subview_row< const subview_row > { static const bool value = true; }; template struct is_subview_col { static const bool value = false; }; template struct is_subview_col< subview_col > { static const bool value = true; }; template struct is_subview_col< const subview_col > { static const bool value = true; }; template struct is_subview_elem1 { static const bool value = false; }; template struct is_subview_elem1< subview_elem1 > { static const bool value = true; }; template struct is_subview_elem1< const subview_elem1 > { static const bool value = true; }; template struct is_subview_elem2 { static const bool value = false; }; template struct is_subview_elem2< subview_elem2 > { static const bool value = true; }; template struct is_subview_elem2< const subview_elem2 > { static const bool value = true; }; // // // template struct is_Cube { static const bool value = false; }; template struct is_Cube< Cube > { static const bool value = true; }; template struct is_subview_cube { static const bool value = false; }; template struct is_subview_cube< subview_cube > { static const bool value = true; }; // // // template struct is_Gen { static const bool value = false; }; template struct is_Gen< Gen > { static const bool value = true; }; template struct is_Gen< const Gen > { static const bool value = true; }; template struct is_Op { static const bool value = false; }; template struct is_Op< Op > { static const bool value = true; }; template struct is_Op< const Op > { static const bool value = true; }; template struct is_eOp { static const bool value = false; }; template struct is_eOp< eOp > { static const bool value = true; }; template struct is_eOp< const eOp > { static const bool value = true; }; template struct is_mtOp { static const bool value = false; }; template struct is_mtOp< mtOp > { static const bool value = true; }; template struct is_mtOp< const mtOp > { static const bool value = true; }; template struct is_Glue { static const bool value = false; }; template struct is_Glue< Glue > { static const bool value = true; }; template struct is_Glue< const Glue > { static const bool value = true; }; template struct is_eGlue { static const bool value = false; }; template struct is_eGlue< eGlue > { static const bool value = true; }; template struct is_eGlue< const eGlue > { static const bool value = true; }; template struct is_mtGlue { static const bool value = false; }; template struct is_mtGlue< mtGlue > { static const bool value = true; }; template struct is_mtGlue< const mtGlue > { static const bool value = true; }; // // template struct is_glue_times { static const bool value = false; }; template struct is_glue_times< Glue > { static const bool value = true; }; template struct is_glue_times< const Glue > { static const bool value = true; }; template struct is_glue_times_diag { static const bool value = false; }; template struct is_glue_times_diag< Glue > { static const bool value = true; }; template struct is_glue_times_diag< const Glue > { static const bool value = true; }; template struct is_op_diagmat { static const bool value = false; }; template struct is_op_diagmat< Op > { static const bool value = true; }; template struct is_op_diagmat< const Op > { static const bool value = true; }; template struct is_op_htrans2 { static const bool value = false; }; template struct is_op_htrans2< Op > { static const bool value = true; }; template struct is_op_htrans2< const Op > { static const bool value = true; }; // // template struct is_Mat_trans { static const bool value = false; }; template struct is_Mat_trans< Op > { static const bool value = is_Mat::value; }; template struct is_Mat_trans< Op > { static const bool value = is_Mat::value; }; // // template struct is_GenCube { static const bool value = false; }; template struct is_GenCube< GenCube > { static const bool value = true; }; template struct is_OpCube { static const bool value = false; }; template struct is_OpCube< OpCube > { static const bool value = true; }; template struct is_eOpCube { static const bool value = false; }; template struct is_eOpCube< eOpCube > { static const bool value = true; }; template struct is_mtOpCube { static const bool value = false; }; template struct is_mtOpCube< mtOpCube > { static const bool value = true; }; template struct is_GlueCube { static const bool value = false; }; template struct is_GlueCube< GlueCube > { static const bool value = true; }; template struct is_eGlueCube { static const bool value = false; }; template struct is_eGlueCube< eGlueCube > { static const bool value = true; }; template struct is_mtGlueCube { static const bool value = false; }; template struct is_mtGlueCube< mtGlueCube > { static const bool value = true; }; // // // template struct is_op_rel { static const bool value = false; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; // // // template struct is_basevec { static const bool value = ( is_Row_fixed_only::value || is_Col_fixed_only::value ); }; template struct is_basevec< Row > { static const bool value = true; }; template struct is_basevec< const Row > { static const bool value = true; }; template struct is_basevec< Col > { static const bool value = true; }; template struct is_basevec< const Col > { static const bool value = true; }; template struct is_basevec< subview_row > { static const bool value = true; }; template struct is_basevec< const subview_row > { static const bool value = true; }; template struct is_basevec< subview_col > { static const bool value = true; }; template struct is_basevec< const subview_col > { static const bool value = true; }; template struct is_basevec< diagview > { static const bool value = true; }; template struct is_basevec< const diagview > { static const bool value = true; }; template struct is_basevec< subview_elem1 > { static const bool value = true; }; template struct is_basevec< const subview_elem1 > { static const bool value = true; }; // // // template struct is_arma_type { static const bool value = is_Mat::value || is_Gen::value || is_Op::value || is_Glue::value || is_eOp::value || is_eGlue::value || is_mtOp::value || is_mtGlue::value || is_diagview::value || is_subview::value || is_subview_row::value || is_subview_col::value || is_subview_elem1::value || is_subview_elem2::value ; }; template struct is_arma_cube_type { static const bool value = is_Cube::value || is_GenCube::value || is_OpCube::value || is_eOpCube::value || is_mtOpCube::value || is_GlueCube::value || is_eGlueCube::value || is_mtGlueCube::value || is_subview_cube::value ; }; // // // template struct is_SpMat { static const bool value = false; }; template struct is_SpMat< SpMat > { static const bool value = true; }; template struct is_SpMat< SpCol > { static const bool value = true; }; template struct is_SpMat< SpRow > { static const bool value = true; }; template struct is_SpRow { static const bool value = false; }; template struct is_SpRow< SpRow > { static const bool value = true; }; template struct is_SpCol { static const bool value = false; }; template struct is_SpCol< SpCol > { static const bool value = true; }; template struct is_SpSubview { static const bool value = false; }; template struct is_SpSubview< SpSubview > { static const bool value = true; }; template struct is_SpOp { static const bool value = false; }; template struct is_SpOp< SpOp > { static const bool value = true; }; template struct is_SpGlue { static const bool value = false; }; template struct is_SpGlue< SpGlue > { static const bool value = true; }; template struct is_mtSpOp { static const bool value = false; }; template struct is_mtSpOp< mtSpOp > { static const bool value = true; }; template struct is_arma_sparse_type { static const bool value = is_SpMat::value || is_SpSubview::value || is_SpOp::value || is_SpGlue::value || is_mtSpOp::value ; }; // // // template struct is_same_type { static const bool value = false; static const bool yes = false; static const bool no = true; }; template struct is_same_type { static const bool value = true; static const bool yes = true; static const bool no = false; }; // // // template struct is_u8 { static const bool value = false; }; template<> struct is_u8 { static const bool value = true; }; template struct is_s8 { static const bool value = false; }; template<> struct is_s8 { static const bool value = true; }; template struct is_u16 { static const bool value = false; }; template<> struct is_u16 { static const bool value = true; }; template struct is_s16 { static const bool value = false; }; template<> struct is_s16 { static const bool value = true; }; template struct is_u32 { static const bool value = false; }; template<> struct is_u32 { static const bool value = true; }; template struct is_s32 { static const bool value = false; }; template<> struct is_s32 { static const bool value = true; }; #if defined(ARMA_USE_U64S64) template struct is_u64 { static const bool value = false; }; template<> struct is_u64 { static const bool value = true; }; template struct is_s64 { static const bool value = false; }; template<> struct is_s64 { static const bool value = true; }; #endif template struct is_ulng_t { static const bool value = false; }; template<> struct is_ulng_t { static const bool value = true; }; template struct is_slng_t { static const bool value = false; }; template<> struct is_slng_t { static const bool value = true; }; template struct is_ulng_t_32 { static const bool value = false; }; template<> struct is_ulng_t_32 { static const bool value = (sizeof(ulng_t) == 4); }; template struct is_slng_t_32 { static const bool value = false; }; template<> struct is_slng_t_32 { static const bool value = (sizeof(slng_t) == 4); }; template struct is_ulng_t_64 { static const bool value = false; }; template<> struct is_ulng_t_64 { static const bool value = (sizeof(ulng_t) == 8); }; template struct is_slng_t_64 { static const bool value = false; }; template<> struct is_slng_t_64 { static const bool value = (sizeof(slng_t) == 8); }; template struct is_uword { static const bool value = false; }; template<> struct is_uword { static const bool value = true; }; template struct is_sword { static const bool value = false; }; template<> struct is_sword { static const bool value = true; }; template struct is_float { static const bool value = false; }; template<> struct is_float { static const bool value = true; }; template struct is_double { static const bool value = false; }; template<> struct is_double { static const bool value = true; }; template struct is_real { static const bool value = false; }; template<> struct is_real { static const bool value = true; }; template<> struct is_real { static const bool value = true; }; template struct is_not_complex { static const bool value = true; }; template struct is_not_complex< std::complex > { static const bool value = false; }; template struct is_complex { static const bool value = false; }; // template<> template struct is_complex< std::complex > { static const bool value = true; }; template struct is_complex_float { static const bool value = false; }; template<> struct is_complex_float< std::complex > { static const bool value = true; }; template struct is_complex_double { static const bool value = false; }; template<> struct is_complex_double< std::complex > { static const bool value = true; }; template struct is_complex_strict { static const bool value = false; }; template<> struct is_complex_strict< std::complex > { static const bool value = true; }; template<> struct is_complex_strict< std::complex > { static const bool value = true; }; template struct is_cx { static const bool value = false; static const bool yes = false; static const bool no = true; }; // template<> template struct is_cx< std::complex > { static const bool value = true; static const bool yes = true; static const bool no = false; }; //! check for a weird implementation of the std::complex class template struct is_supported_complex { static const bool value = false; }; //template<> template struct is_supported_complex< std::complex > { static const bool value = ( sizeof(std::complex) == 2*sizeof(eT) ); }; template struct is_supported_complex_float { static const bool value = false; }; template<> struct is_supported_complex_float< std::complex > { static const bool value = ( sizeof(std::complex) == 2*sizeof(float) ); }; template struct is_supported_complex_double { static const bool value = false; }; template<> struct is_supported_complex_double< std::complex > { static const bool value = ( sizeof(std::complex) == 2*sizeof(double) ); }; template struct is_supported_elem_type { static const bool value = \ is_u8::value || is_s8::value || is_u16::value || is_s16::value || is_u32::value || is_s32::value || #if defined(ARMA_USE_U64S64) is_u64::value || is_s64::value || #endif #if defined(ARMA_ALLOW_LONG) is_ulng_t::value || is_slng_t::value || #endif is_float::value || is_double::value || is_supported_complex_float::value || is_supported_complex_double::value; }; template struct is_supported_blas_type { static const bool value = \ is_float::value || is_double::value || is_supported_complex_float::value || is_supported_complex_double::value; }; template struct is_signed { static const bool value = true; }; template<> struct is_signed { static const bool value = false; }; template<> struct is_signed { static const bool value = false; }; template<> struct is_signed { static const bool value = false; }; #if defined(ARMA_USE_U64S64) template<> struct is_signed { static const bool value = false; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct is_signed { static const bool value = false; }; #endif template struct is_non_integral { static const bool value = false; }; template<> struct is_non_integral< float > { static const bool value = true; }; template<> struct is_non_integral< double > { static const bool value = true; }; template<> struct is_non_integral< std::complex > { static const bool value = true; }; template<> struct is_non_integral< std::complex > { static const bool value = true; }; // class arma_junk_class; template struct force_different_type { typedef T1 T1_result; typedef T2 T2_result; }; template struct force_different_type { typedef T1 T1_result; typedef arma_junk_class T2_result; }; // template struct resolves_to_vector_default { static const bool value = false; }; template struct resolves_to_vector_test { static const bool value = T1::is_col || T1::is_row; }; template struct resolves_to_vector_redirect {}; template struct resolves_to_vector_redirect { typedef resolves_to_vector_default result; }; template struct resolves_to_vector_redirect { typedef resolves_to_vector_test result; }; template struct resolves_to_vector : public resolves_to_vector_redirect::value>::result {}; template struct resolves_to_sparse_vector : public resolves_to_vector_redirect::value>::result {}; template struct is_glue_mixed_times { static const bool value = false; }; template<> struct is_glue_mixed_times { static const bool value = true; }; template struct is_glue_mixed_elem { static const bool value = false; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template struct is_op_mixed_elem { static const bool value = false; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template struct is_spop_elem { static const bool value = false; }; template<> struct is_spop_elem { static const bool value = true; }; template struct is_spglue_elem { static const bool value = false; }; template<> struct is_spglue_elem { static const bool value = true; }; template<> struct is_spglue_elem { static const bool value = true; }; template<> struct is_spglue_elem { static const bool value = true; }; template<> struct is_spglue_elem { static const bool value = true; }; template struct is_spglue_times { static const bool value = false; }; template<> struct is_spglue_times { static const bool value = true; }; template struct is_spglue_times2 { static const bool value = false; }; template<> struct is_spglue_times { static const bool value = true; }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_norm.hpp0000644000176000001440000003654412200375542022603 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_norm //! @{ template arma_hot inline typename T1::pod_type arma_vec_norm_1(const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; T acc = T(0); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); const uword N = P.get_n_elem(); T acc1 = T(0); T acc2 = T(0); uword i,j; for(i=0, j=1; j arma_hot inline typename T1::pod_type arma_vec_norm_2 ( const Proxy& P, const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; T acc = T(0); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); const uword N = P.get_n_elem(); T acc1 = T(0); T acc2 = T(0); uword i,j; for(i=0, j=1; j arma_hot inline typename T1::pod_type arma_vec_norm_2 ( const Proxy& P, const typename arma_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; T acc = T(0); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); const uword N = P.get_n_elem(); for(uword i=0; i arma_hot inline typename T1::pod_type arma_vec_norm_k ( const Proxy& P, const int k ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; T acc = T(0); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); const uword N = P.get_n_elem(); uword i,j; for(i=0, j=1; j arma_hot inline typename T1::pod_type arma_vec_norm_max(const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const uword N = P.get_n_elem(); T max_val = (N != 1) ? priv::most_neg() : std::abs(P[0]); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j arma_hot inline typename T1::pod_type arma_vec_norm_min(const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const uword N = P.get_n_elem(); T min_val = (N != 1) ? priv::most_pos() : std::abs(P[0]); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j tmp_i) { min_val = tmp_i; } if(min_val > tmp_j) { min_val = tmp_j; } } if(i < N) { const T tmp_i = std::abs(A[i]); if(min_val > tmp_i) { min_val = tmp_i; } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows != 1) { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const T tmp = std::abs(P.at(row,col)); if(min_val > tmp) { min_val = tmp; } } } else { for(uword col=0; col < n_cols; ++col) { const T tmp = std::abs(P.at(0,col)); if(min_val > tmp) { min_val = tmp; } } } } return min_val; } template inline typename T1::pod_type arma_mat_norm_1(const Proxy& P) { arma_extra_debug_sigprint(); // TODO: this can be sped up with a dedicated implementation return as_scalar( max( sum(abs(P.Q), 0), 1) ); } template inline typename T1::pod_type arma_mat_norm_2(const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; // TODO: is the SVD based approach only valid for square matrices? Col S; svd(S, P.Q); return (S.n_elem > 0) ? max(S) : T(0); } template inline typename T1::pod_type arma_mat_norm_inf(const Proxy& P) { arma_extra_debug_sigprint(); // TODO: this can be sped up with a dedicated implementation return as_scalar( max( sum(abs(P.Q), 1), 0) ); } template inline arma_warn_unused typename enable_if2< is_arma_type::value, typename T1::pod_type >::result norm ( const T1& X, const uword k, const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; const Proxy P(X); if(P.get_n_elem() == 0) { return T(0); } const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1); if(is_vec == true) { switch(k) { case 1: return arma_vec_norm_1(P); break; case 2: return arma_vec_norm_2(P); break; default: { arma_debug_check( (k == 0), "norm(): k must be greater than zero" ); return arma_vec_norm_k(P, int(k)); } } } else { switch(k) { case 1: return arma_mat_norm_1(P); break; case 2: return arma_mat_norm_2(P); break; default: arma_stop("norm(): unsupported matrix norm type"); return T(0); } } } template inline arma_warn_unused typename enable_if2< is_arma_type::value, typename T1::pod_type >::result norm ( const T1& X, const char* method, const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; const Proxy P(X); if(P.get_n_elem() == 0) { return T(0); } const char sig = method[0]; const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1); if(is_vec == true) { if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // max norm { return arma_vec_norm_max(P); } else if(sig == '-') // min norm { return arma_vec_norm_min(P); } else if( (sig == 'f') || (sig == 'F') ) { return arma_vec_norm_2(P); } else { arma_stop("norm(): unsupported vector norm type"); return T(0); } } else { if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // inf norm { return arma_mat_norm_inf(P); } else if( (sig == 'f') || (sig == 'F') ) { return arma_vec_norm_2(P); } else { arma_stop("norm(): unsupported matrix norm type"); return T(0); } } } // // norms for sparse matrices template inline typename T1::pod_type arma_mat_norm_1(const SpProxy& P) { arma_extra_debug_sigprint(); // TODO: this can be sped up with a dedicated implementation return as_scalar( max( sum(abs(P.Q), 0), 1) ); } // template // inline // typename T1::pod_type // arma_mat_norm_2(const SpProxy& P) // { // arma_extra_debug_sigprint(); // // // TODO: norm = sqrt( largest eigenvalue of (A^H)*A ), where ^H is the conjugate transpose // // TODO: can use ARPACK or directly implement the Arnoldi iteration // // http://math.stackexchange.com/questions/4368/computing-the-largest-eigenvalue-of-a-very-large-sparse-matrix // } template inline typename T1::pod_type arma_mat_norm_inf(const SpProxy& P) { arma_extra_debug_sigprint(); // TODO: this can be sped up with a dedicated implementation return as_scalar( max( sum(abs(P.Q), 1), 0) ); } template inline arma_warn_unused typename enable_if2< is_arma_sparse_type::value, typename T1::pod_type >::result norm ( const T1& X, const uword k, const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; const SpProxy P(X); if(P.get_n_nonzero() == 0) { return T(0); } const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1); if(is_vec == true) { const unwrap_spmat::stored_type> tmp(P.Q); const SpMat& A = tmp.M; // create a fake dense vector to allow reuse of code for dense vectors Col fake_vector( access::rwp(A.values), A.n_nonzero, false ); const Proxy< Col > P_fake_vector(fake_vector); switch(k) { case 1: return arma_vec_norm_1(P_fake_vector); break; case 2: return arma_vec_norm_2(P_fake_vector); break; default: { arma_debug_check( (k == 0), "norm(): k must be greater than zero" ); return arma_vec_norm_k(P_fake_vector, int(k)); } } } else { switch(k) { case 1: return arma_mat_norm_1(P); break; // case 2: // return arma_mat_norm_2(P); // break; default: arma_stop("norm(): unsupported or unimplemented norm type for sparse matrices"); return T(0); } } } template inline arma_warn_unused typename enable_if2< is_arma_sparse_type::value, typename T1::pod_type >::result norm ( const T1& X, const char* method, const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; const SpProxy P(X); if(P.get_n_nonzero() == 0) { return T(0); } const unwrap_spmat::stored_type> tmp(P.Q); const SpMat& A = tmp.M; // create a fake dense vector to allow reuse of code for dense vectors Col fake_vector( access::rwp(A.values), A.n_nonzero, false ); const Proxy< Col > P_fake_vector(fake_vector); const char sig = method[0]; const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1); if(is_vec == true) { if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // max norm { return arma_vec_norm_max(P_fake_vector); } else if(sig == '-') // min norm { const T val = arma_vec_norm_min(P_fake_vector); if( P.get_n_nonzero() < P.get_n_elem() ) { return (std::min)(T(0), val); } else { return val; } } else if( (sig == 'f') || (sig == 'F') ) { return arma_vec_norm_2(P_fake_vector); } else { arma_stop("norm(): unsupported vector norm type"); return T(0); } } else { if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // inf norm { return arma_mat_norm_inf(P); } else if( (sig == 'f') || (sig == 'F') ) { return arma_vec_norm_2(P_fake_vector); } else { arma_stop("norm(): unsupported matrix norm type"); return T(0); } } } //! @} RcppArmadillo/inst/include/armadillo_bits/eop_core_bones.hpp0000644000176000001440000001102512216162176024115 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup eop_core //! @{ template class eop_core { public: // matrices template arma_hot inline static void apply(Mat& out, const eOp& x); template arma_hot inline static void apply_inplace_plus (Mat& out, const eOp& x); template arma_hot inline static void apply_inplace_minus(Mat& out, const eOp& x); template arma_hot inline static void apply_inplace_schur(Mat& out, const eOp& x); template arma_hot inline static void apply_inplace_div (Mat& out, const eOp& x); // cubes template arma_hot inline static void apply(Cube& out, const eOpCube& x); template arma_hot inline static void apply_inplace_plus (Cube& out, const eOpCube& x); template arma_hot inline static void apply_inplace_minus(Cube& out, const eOpCube& x); template arma_hot inline static void apply_inplace_schur(Cube& out, const eOpCube& x); template arma_hot inline static void apply_inplace_div (Cube& out, const eOpCube& x); // common template arma_hot arma_pure arma_inline static eT process(const eT val, const eT k); }; class eop_neg : public eop_core {}; class eop_scalar_plus : public eop_core {}; class eop_scalar_minus_pre : public eop_core {}; class eop_scalar_minus_post : public eop_core {}; class eop_scalar_times : public eop_core {}; class eop_scalar_div_pre : public eop_core {}; class eop_scalar_div_post : public eop_core {}; class eop_square : public eop_core {}; class eop_sqrt : public eop_core {}; class eop_log : public eop_core {}; class eop_log2 : public eop_core {}; class eop_log10 : public eop_core {}; class eop_trunc_log : public eop_core {}; class eop_exp : public eop_core {}; class eop_exp2 : public eop_core {}; class eop_exp10 : public eop_core {}; class eop_trunc_exp : public eop_core {}; class eop_cos : public eop_core {}; class eop_sin : public eop_core {}; class eop_tan : public eop_core {}; class eop_acos : public eop_core {}; class eop_asin : public eop_core {}; class eop_atan : public eop_core {}; class eop_cosh : public eop_core {}; class eop_sinh : public eop_core {}; class eop_tanh : public eop_core {}; class eop_acosh : public eop_core {}; class eop_asinh : public eop_core {}; class eop_atanh : public eop_core {}; class eop_eps : public eop_core {}; class eop_abs : public eop_core {}; class eop_conj : public eop_core {}; class eop_pow : public eop_core {}; class eop_floor : public eop_core {}; class eop_ceil : public eop_core {}; class eop_round : public eop_core {}; class eop_sign : public eop_core {}; //! @} RcppArmadillo/inst/include/armadillo_bits/op_trimat_meat.hpp0000644000176000001440000001256212200631217024135 0ustar ripleyusers// Copyright (C) 2010-2012 Conrad Sanderson // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) // Copyright (C) 2011 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_trimat //! @{ template inline void op_trimat::fill_zeros(Mat& out, const bool upper) { arma_extra_debug_sigprint(); const uword N = out.n_rows; if(upper) { // upper triangular: set all elements below the diagonal to zero for(uword i=0; i inline void op_trimat::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m); const Mat& A = tmp.M; arma_debug_check( (A.is_square() == false), "trimatu()/trimatl(): given matrix must be square" ); const uword N = A.n_rows; const bool upper = (in.aux_uword_a == 0); if(&out != &A) { out.copy_size(A); if(upper) { // upper triangular: copy the diagonal and the elements above the diagonal for(uword i=0; i inline void op_trimat::apply(Mat& out, const Op, op_trimat>& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m.m); const Mat& A = tmp.M; const bool upper = (in.aux_uword_a == 0); op_trimat::apply_htrans(out, A, upper); } template inline void op_trimat::apply_htrans ( Mat& out, const Mat& A, const bool upper, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); // This specialisation is for trimatl(trans(X)) = trans(trimatu(X)) and also // trimatu(trans(X)) = trans(trimatl(X)). We want to avoid the creation of an // extra temporary. // It doesn't matter if the input and output matrices are the same; we will // pull data from the upper or lower triangular to the lower or upper // triangular (respectively) and then set the rest to 0, so overwriting issues // aren't present. arma_debug_check( (A.is_square() == false), "trimatu()/trimatl(): given matrix must be square" ); const uword N = A.n_rows; if(&out != &A) { out.copy_size(A); } // We can't really get away with any array copy operations here, // unfortunately... if(upper) { // Upper triangular: but since we're transposing, we're taking the lower // triangular and putting it in the upper half. for(uword row = 0; row < N; ++row) { eT* out_colptr = out.colptr(row); for(uword col = 0; col <= row; ++col) { //out.at(col, row) = A.at(row, col); out_colptr[col] = A.at(row, col); } } } else { // Lower triangular: but since we're transposing, we're taking the upper // triangular and putting it in the lower half. for(uword row = 0; row < N; ++row) { for(uword col = row; col < N; ++col) { out.at(col, row) = A.at(row, col); } } } op_trimat::fill_zeros(out, upper); } template inline void op_trimat::apply_htrans ( Mat& out, const Mat& A, const bool upper, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( (A.is_square() == false), "trimatu()/trimatl(): given matrix must be square" ); const uword N = A.n_rows; if(&out != &A) { out.copy_size(A); } if(upper) { // Upper triangular: but since we're transposing, we're taking the lower // triangular and putting it in the upper half. for(uword row = 0; row < N; ++row) { eT* out_colptr = out.colptr(row); for(uword col = 0; col <= row; ++col) { //out.at(col, row) = std::conj( A.at(row, col) ); out_colptr[col] = std::conj( A.at(row, col) ); } } } else { // Lower triangular: but since we're transposing, we're taking the upper // triangular and putting it in the lower half. for(uword row = 0; row < N; ++row) { for(uword col = row; col < N; ++col) { out.at(col, row) = std::conj( A.at(row, col) ); } } } op_trimat::fill_zeros(out, upper); } //! @} RcppArmadillo/inst/include/armadillo_bits/spop_mean_meat.hpp0000644000176000001440000001272512111344723024125 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_mean //! @{ template inline void spop_mean::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check((dim > 1), "mean(): incorrect usage. dim must be 0 or 1"); SpProxy p(in.m); if(p.is_alias(out) == false) { spop_mean::apply_noalias(out, p, dim); } else { SpMat tmp; spop_mean::apply_noalias(tmp, p, dim); out.steal_mem(tmp); } } template inline void spop_mean::apply_noalias ( SpMat& out_ref, const SpProxy& p, const uword dim ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword p_n_rows = p.get_n_rows(); const uword p_n_cols = p.get_n_cols(); if (dim == 0) { arma_extra_debug_print("spop_mean::apply_noalias(), dim = 0"); out_ref.set_size((p_n_rows > 0) ? 1 : 0, p_n_cols); if(p_n_rows > 0) { for(uword col = 0; col < p_n_cols; ++col) { // Do we have to use an iterator or can we use memory directly? if(SpProxy::must_use_iterator == true) { typename SpProxy::const_iterator_type it = p.begin_col(col); typename SpProxy::const_iterator_type end = p.begin_col(col + 1); const uword n_zero = p.get_n_rows() - (end.pos() - it.pos()); out_ref.at(col) = spop_mean::iterator_mean(it, end, n_zero, eT(0)); } else { out_ref.at(col) = spop_mean::direct_mean ( &p.get_values()[p.get_col_ptrs()[col]], p.get_col_ptrs()[col + 1] - p.get_col_ptrs()[col], p.get_n_rows() ); } } } } else if (dim == 1) { arma_extra_debug_print("spop_mean::apply_noalias(), dim = 1"); out_ref.set_size(p_n_rows, (p_n_cols > 0) ? 1 : 0); if(p_n_cols > 0) { for(uword row = 0; row < p_n_rows; ++row) { // We must use an iterator regardless of how it is stored. typename SpProxy::const_row_iterator_type it = p.begin_row(row); typename SpProxy::const_row_iterator_type end = p.end_row(row); const uword n_zero = p.get_n_cols() - (end.pos() - it.pos()); out_ref.at(row) = spop_mean::iterator_mean(it, end, n_zero, eT(0)); } } } } template inline eT spop_mean::direct_mean ( const eT* const X, const uword length, const uword N ) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const eT result = arrayops::accumulate(X, length) / T(N); return arma_isfinite(result) ? result : spop_mean::direct_mean_robust(X, length, N); } template inline eT spop_mean::direct_mean_robust ( const eT* const X, const uword length, const uword N ) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; uword i, j; eT r_mean = eT(0); const uword diff = (N - length); // number of zeros for(i = 0, j = 1; j < length; i += 2, j += 2) { const eT Xi = X[i]; const eT Xj = X[j]; r_mean += (Xi - r_mean) / T(diff + j); r_mean += (Xj - r_mean) / T(diff + j + 1); } if(i < length) { const eT Xi = X[i]; r_mean += (Xi - r_mean) / T(diff + i + 1); } return r_mean; } template inline typename T1::elem_type spop_mean::mean_all(const SpBase& X) { arma_extra_debug_sigprint(); SpProxy p(X.get_ref()); if (SpProxy::must_use_iterator == true) { typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type end = p.end(); return spop_mean::iterator_mean(it, end, p.get_n_elem() - p.get_n_nonzero(), typename T1::elem_type(0)); } else // must_use_iterator == false; that is, we can directly access the values array { return spop_mean::direct_mean(p.get_values(), p.get_n_nonzero(), p.get_n_elem()); } } template inline eT spop_mean::iterator_mean(T1& it, const T1& end, const uword n_zero, const eT junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename get_pod_type::result T; eT sum = eT(0); T1 backup_it(it); // in case we have to use robust iterator_mean const uword it_begin_pos = it.pos(); while (it != end) { sum += (*it); ++it; } const eT result = sum / T(n_zero + (it.pos() - it_begin_pos)); return arma_isfinite(result) ? result : spop_mean::iterator_mean_robust(backup_it, end, n_zero, eT(0)); } template inline eT spop_mean::iterator_mean_robust(T1& it, const T1& end, const uword n_zero, const eT junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename get_pod_type::result T; eT r_mean = eT(0); const uword it_begin_pos = it.pos(); while (it != end) { r_mean += ((*it - r_mean) / T(n_zero + (it.pos() - it_begin_pos) + 1)); ++it; } return r_mean; } //! @} RcppArmadillo/inst/include/armadillo_bits/mul_herk.hpp0000644000176000001440000003156112222720570022744 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup herk //! @{ class herk_helper { public: template inline static void inplace_conj_copy_upper_tri_to_lower_tri(Mat& C) { // under the assumption that C is a square matrix const uword N = C.n_rows; for(uword k=0; k < N; ++k) { eT* colmem = C.colptr(k); for(uword i=(k+1); i < N; ++i) { colmem[i] = std::conj( C.at(k,i) ); } } } template static arma_hot arma_pure inline eT dot_conj_row(const uword n_elem, const eT* const A, const Mat& B, const uword row) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; T val_real = T(0); T val_imag = T(0); for(uword i=0; i& X = A[i]; const std::complex& Y = B.at(row,i); const T a = X.real(); const T b = X.imag(); const T c = Y.real(); const T d = Y.imag(); val_real += (a*c) + (b*d); val_imag += (b*c) - (a*d); } return std::complex(val_real, val_imag); } }; template class herk_vec { public: template arma_hot inline static void apply ( Mat< std::complex >& C, const TA& A, const T alpha = T(1), const T beta = T(0) ) { arma_extra_debug_sigprint(); typedef std::complex eT; const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; // for beta != 0, C is assumed to be hermitian // do_trans_A == false -> C = alpha * A * A^H + beta*C // do_trans_A == true -> C = alpha * A^H * A + beta*C const eT* A_mem = A.memptr(); if(do_trans_A == false) { if(A_n_rows == 1) { const eT acc = op_cdot::direct_cdot(A_n_cols, A_mem, A_mem); if( (use_alpha == false) && (use_beta == false) ) { C[0] = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C[0] = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C[0] = acc + beta*C[0]; } else if( (use_alpha == true ) && (use_beta == true ) ) { C[0] = alpha*acc + beta*C[0]; } } else for(uword row_A=0; row_A < A_n_rows; ++row_A) { const eT& A_rowdata = A_mem[row_A]; for(uword k=row_A; k < A_n_rows; ++k) { const eT acc = A_rowdata * std::conj( A_mem[k] ); if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A, k) = acc; if(row_A != k) { C.at(k, row_A) = std::conj(acc); } } else if( (use_alpha == true) && (use_beta == false) ) { const eT val = alpha*acc; C.at(row_A, k) = val; if(row_A != k) { C.at(k, row_A) = std::conj(val); } } else if( (use_alpha == false) && (use_beta == true) ) { C.at(row_A, k) = acc + beta*C.at(row_A, k); if(row_A != k) { C.at(k, row_A) = std::conj(acc) + beta*C.at(k, row_A); } } else if( (use_alpha == true) && (use_beta == true) ) { const eT val = alpha*acc; C.at(row_A, k) = val + beta*C.at(row_A, k); if(row_A != k) { C.at(k, row_A) = std::conj(val) + beta*C.at(k, row_A); } } } } } else if(do_trans_A == true) { if(A_n_cols == 1) { const eT acc = op_cdot::direct_cdot(A_n_rows, A_mem, A_mem); if( (use_alpha == false) && (use_beta == false) ) { C[0] = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C[0] = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C[0] = acc + beta*C[0]; } else if( (use_alpha == true ) && (use_beta == true ) ) { C[0] = alpha*acc + beta*C[0]; } } else for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const eT A_coldata = std::conj( A_mem[col_A] ); for(uword k=col_A; k < A_n_cols ; ++k) { const eT acc = A_coldata * A_mem[k]; if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A, k) = acc; if(col_A != k) { C.at(k, col_A) = std::conj(acc); } } else if( (use_alpha == true ) && (use_beta == false) ) { const eT val = alpha*acc; C.at(col_A, k) = val; if(col_A != k) { C.at(k, col_A) = std::conj(val); } } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A, k) = acc + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = std::conj(acc) + beta*C.at(k, col_A); } } else if( (use_alpha == true ) && (use_beta == true ) ) { const eT val = alpha*acc; C.at(col_A, k) = val + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = std::conj(val) + beta*C.at(k, col_A); } } } } } } }; template class herk_emul { public: template arma_hot inline static void apply ( Mat< std::complex >& C, const TA& A, const T alpha = T(1), const T beta = T(0) ) { arma_extra_debug_sigprint(); typedef std::complex eT; // do_trans_A == false -> C = alpha * A * A^H + beta*C // do_trans_A == true -> C = alpha * A^H * A + beta*C if(do_trans_A == false) { Mat AA; op_htrans::apply_mat_noalias(AA, A); herk_emul::apply(C, AA, alpha, beta); } else if(do_trans_A == true) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const eT* A_coldata = A.colptr(col_A); for(uword k=col_A; k < A_n_cols ; ++k) { const eT acc = op_cdot::direct_cdot(A_n_rows, A_coldata, A.colptr(k)); if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A, k) = acc; if(col_A != k) { C.at(k, col_A) = std::conj(acc); } } else if( (use_alpha == true) && (use_beta == false) ) { const eT val = alpha*acc; C.at(col_A, k) = val; if(col_A != k) { C.at(k, col_A) = std::conj(val); } } else if( (use_alpha == false) && (use_beta == true) ) { C.at(col_A, k) = acc + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = std::conj(acc) + beta*C.at(k, col_A); } } else if( (use_alpha == true) && (use_beta == true) ) { const eT val = alpha*acc; C.at(col_A, k) = val + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = std::conj(val) + beta*C.at(k, col_A); } } } } } } }; template class herk { public: template inline static void apply_blas_type( Mat >& C, const TA& A, const T alpha = T(1), const T beta = T(0) ) { arma_extra_debug_sigprint(); const uword threshold = 16; if(A.is_vec()) { // work around poor handling of vectors by herk() in ATLAS 3.8.4 and standard BLAS herk_vec::apply(C,A,alpha,beta); return; } if( (A.n_elem <= threshold) ) { herk_emul::apply(C,A,alpha,beta); } else { #if defined(ARMA_USE_ATLAS) { if(use_beta == true) { typedef typename std::complex eT; // use a temporary matrix, as we can't assume that matrix C is already symmetric Mat D(C.n_rows, C.n_cols); herk::apply_blas_type(D,A,alpha); // NOTE: assuming beta=1; this is okay for now, as currently glue_times only uses beta=1 arrayops::inplace_plus(C.memptr(), D.memptr(), C.n_elem); return; } atlas::cblas_herk ( atlas::CblasColMajor, atlas::CblasUpper, (do_trans_A) ? CblasConjTrans : atlas::CblasNoTrans, C.n_cols, (do_trans_A) ? A.n_rows : A.n_cols, (use_alpha) ? alpha : T(1), A.mem, (do_trans_A) ? A.n_rows : C.n_cols, (use_beta) ? beta : T(0), C.memptr(), C.n_cols ); herk_helper::inplace_conj_copy_upper_tri_to_lower_tri(C); } #elif defined(ARMA_USE_BLAS) { if(use_beta == true) { typedef typename std::complex eT; // use a temporary matrix, as we can't assume that matrix C is already symmetric Mat D(C.n_rows, C.n_cols); herk::apply_blas_type(D,A,alpha); // NOTE: assuming beta=1; this is okay for now, as currently glue_times only uses beta=1 arrayops::inplace_plus(C.memptr(), D.memptr(), C.n_elem); return; } arma_extra_debug_print("blas::herk()"); const char uplo = 'U'; const char trans_A = (do_trans_A) ? 'C' : 'N'; const blas_int n = C.n_cols; const blas_int k = (do_trans_A) ? A.n_rows : A.n_cols; const T local_alpha = (use_alpha) ? alpha : T(1); const T local_beta = (use_beta) ? beta : T(0); const blas_int lda = (do_trans_A) ? k : n; arma_extra_debug_print( arma_boost::format("blas::herk(): trans_A = %c") % trans_A ); blas::herk ( &uplo, &trans_A, &n, &k, &local_alpha, A.mem, &lda, &local_beta, C.memptr(), &n // &ldc ); herk_helper::inplace_conj_copy_upper_tri_to_lower_tri(C); } #else { herk_emul::apply(C,A,alpha,beta); } #endif } } template inline static void apply( Mat& C, const TA& A, const eT alpha = eT(1), const eT beta = eT(0), const typename arma_not_cx::result* junk = 0 ) { arma_ignore(C); arma_ignore(A); arma_ignore(alpha); arma_ignore(beta); arma_ignore(junk); // herk() cannot be used by non-complex matrices return; } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const float alpha = float(1), const float beta = float(0) ) { herk::apply_blas_type(C,A,alpha,beta); } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const double alpha = double(1), const double beta = double(0) ) { herk::apply_blas_type(C,A,alpha,beta); } }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_kron.hpp0000644000176000001440000000361512200375542022572 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_kron //! @{ //! \brief //! kronecker product of two matrices, //! with the matrices having the same element type template arma_inline const Glue kron(const Base& A, const Base& B) { arma_extra_debug_sigprint(); return Glue(A.get_ref(), B.get_ref()); } //! \brief //! kronecker product of two matrices, //! with the matrices having different element types template inline Mat::eT> kron(const Base,T1>& X, const Base& Y) { arma_extra_debug_sigprint(); typedef typename std::complex eT1; promote_type::check(); const unwrap tmp1(X.get_ref()); const unwrap tmp2(Y.get_ref()); const Mat& A = tmp1.M; const Mat& B = tmp2.M; Mat out; glue_kron::direct_kron(out, A, B); return out; } //! \brief //! kronecker product of two matrices, //! with the matrices having different element types template inline Mat::eT> kron(const Base& X, const Base,T2>& Y) { arma_extra_debug_sigprint(); typedef typename std::complex eT2; promote_type::check(); const unwrap tmp1(X.get_ref()); const unwrap tmp2(Y.get_ref()); const Mat& A = tmp1.M; const Mat& B = tmp2.M; Mat out; glue_kron::direct_kron(out, A, B); return out; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_dot_bones.hpp0000644000176000001440000000643712220557270023617 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_dot //! @{ //! \brief //! dot product operation class op_dot { public: template arma_hot arma_pure arma_inline static typename arma_not_cx::result direct_dot_arma(const uword n_elem, const eT* const A, const eT* const B); template arma_hot arma_pure inline static typename arma_cx_only::result direct_dot_arma(const uword n_elem, const eT* const A, const eT* const B); template arma_hot arma_pure inline static typename arma_real_only::result direct_dot(const uword n_elem, const eT* const A, const eT* const B); template arma_hot arma_pure inline static typename arma_cx_only::result direct_dot(const uword n_elem, const eT* const A, const eT* const B); template arma_hot arma_pure inline static typename arma_integral_only::result direct_dot(const uword n_elem, const eT* const A, const eT* const B); template arma_hot arma_pure inline static eT direct_dot(const uword n_elem, const eT* const A, const eT* const B, const eT* C); template arma_hot inline static typename T1::elem_type apply(const T1& X, const T2& Y); template arma_hot inline static typename arma_not_cx::result apply_proxy(const Proxy& PA, const Proxy& PB); template arma_hot inline static typename arma_cx_only::result apply_proxy(const Proxy& PA, const Proxy& PB); template arma_hot inline static eT dot_and_copy_row(eT* out, const TA& A, const uword row, const eT* B_mem, const uword N); }; //! \brief //! normalised dot product operation class op_norm_dot { public: template arma_hot inline static typename T1::elem_type apply (const T1& X, const T2& Y); template arma_hot inline static typename T1::elem_type apply_unwrap(const T1& X, const T2& Y); }; //! \brief //! complex conjugate dot product operation class op_cdot { public: template arma_hot inline static eT direct_cdot_arma(const uword n_elem, const eT* const A, const eT* const B); template arma_hot inline static eT direct_cdot(const uword n_elem, const eT* const A, const eT* const B); template arma_hot inline static typename T1::elem_type apply (const T1& X, const T2& Y); template arma_hot inline static typename T1::elem_type apply_unwrap(const T1& X, const T2& Y); template arma_hot inline static typename T1::elem_type apply_proxy (const T1& X, const T2& Y); }; class op_dot_mixed { public: template arma_hot inline static typename promote_type::result apply(const T1& A, const T2& B); }; //! @} RcppArmadillo/inst/include/armadillo_bits/OpCube_meat.hpp0000644000176000001440000000452512176655102023327 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup OpCube //! @{ template OpCube::OpCube(const BaseCube& in_m) : m(in_m.get_ref()) { arma_extra_debug_sigprint(); } template OpCube::OpCube(const BaseCube& in_m, const typename T1::elem_type in_aux) : m(in_m.get_ref()) , aux(in_aux) { arma_extra_debug_sigprint(); } template OpCube::OpCube(const BaseCube& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : m(in_m.get_ref()) , aux(in_aux) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) { arma_extra_debug_sigprint(); } template OpCube::OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m.get_ref()) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template OpCube::OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : m(in_m.get_ref()) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) { arma_extra_debug_sigprint(); } template OpCube::OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c, const uword in_aux_uword_d, const char) : m(in_m.get_ref()) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) , aux_uword_d(in_aux_uword_d) { arma_extra_debug_sigprint(); } template OpCube::~OpCube() { arma_extra_debug_sigprint(); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_dot_meat.hpp0000644000176000001440000003276312220557270023440 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_dot //! @{ //! for two arrays, generic version for non-complex values template arma_hot arma_pure arma_inline typename arma_not_cx::result op_dot::direct_dot_arma(const uword n_elem, const eT* const A, const eT* const B) { arma_extra_debug_sigprint(); #if (__FINITE_MATH_ONLY__ > 0) { eT val = eT(0); for(uword i=0; i arma_hot arma_pure inline typename arma_cx_only::result op_dot::direct_dot_arma(const uword n_elem, const eT* const A, const eT* const B) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; T val_real = T(0); T val_imag = T(0); for(uword i=0; i& X = A[i]; const std::complex& Y = B[i]; const T a = X.real(); const T b = X.imag(); const T c = Y.real(); const T d = Y.imag(); val_real += (a*c) - (b*d); val_imag += (a*d) + (b*c); } return std::complex(val_real, val_imag); } //! for two arrays, float and double version template arma_hot arma_pure inline typename arma_real_only::result op_dot::direct_dot(const uword n_elem, const eT* const A, const eT* const B) { arma_extra_debug_sigprint(); if( n_elem <= 32u ) { return op_dot::direct_dot_arma(n_elem, A, B); } else { #if defined(ARMA_USE_ATLAS) { arma_extra_debug_print("atlas::cblas_dot()"); return atlas::cblas_dot(n_elem, A, B); } #elif defined(ARMA_USE_BLAS) { arma_extra_debug_print("blas::dot()"); return blas::dot(n_elem, A, B); } #else { return op_dot::direct_dot_arma(n_elem, A, B); } #endif } } //! for two arrays, complex version template inline arma_hot arma_pure typename arma_cx_only::result op_dot::direct_dot(const uword n_elem, const eT* const A, const eT* const B) { if( n_elem <= 16u ) { return op_dot::direct_dot_arma(n_elem, A, B); } else { #if defined(ARMA_USE_ATLAS) { arma_extra_debug_print("atlas::cx_cblas_dot()"); return atlas::cx_cblas_dot(n_elem, A, B); } #elif defined(ARMA_USE_BLAS) { arma_extra_debug_print("blas::dot()"); return blas::dot(n_elem, A, B); } #else { return op_dot::direct_dot_arma(n_elem, A, B); } #endif } } //! for two arrays, integral version template arma_hot arma_pure inline typename arma_integral_only::result op_dot::direct_dot(const uword n_elem, const eT* const A, const eT* const B) { return op_dot::direct_dot_arma(n_elem, A, B); } //! for three arrays template arma_hot arma_pure inline eT op_dot::direct_dot(const uword n_elem, const eT* const A, const eT* const B, const eT* C) { arma_extra_debug_sigprint(); eT val = eT(0); for(uword i=0; i arma_hot inline typename T1::elem_type op_dot::apply(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); const bool prefer_at_accessor = (Proxy::prefer_at_accessor) || (Proxy::prefer_at_accessor); const bool do_unwrap = ((is_Mat::value == true) && (is_Mat::value == true)) || prefer_at_accessor; if(do_unwrap == true) { const unwrap tmp1(X); const unwrap tmp2(Y); const typename unwrap::stored_type& A = tmp1.M; const typename unwrap::stored_type& B = tmp2.M; arma_debug_check ( (A.n_elem != B.n_elem), "dot(): objects must have the same number of elements" ); return op_dot::direct_dot(A.n_elem, A.memptr(), B.memptr()); } else { const Proxy PA(X); const Proxy PB(Y); arma_debug_check( (PA.get_n_elem() != PB.get_n_elem()), "dot(): objects must have the same number of elements" ); return op_dot::apply_proxy(PA,PB); } } template arma_hot inline typename arma_not_cx::result op_dot::apply_proxy(const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const uword N = PA.get_n_elem(); ea_type1 A = PA.get_ea(); ea_type2 B = PB.get_ea(); eT val1 = eT(0); eT val2 = eT(0); uword i,j; for(i=0, j=1; j arma_hot inline typename arma_cx_only::result op_dot::apply_proxy(const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const uword N = PA.get_n_elem(); ea_type1 A = PA.get_ea(); ea_type2 B = PB.get_ea(); T val_real = T(0); T val_imag = T(0); for(uword i=0; i xx = A[i]; const std::complex yy = B[i]; const T a = xx.real(); const T b = xx.imag(); const T c = yy.real(); const T d = yy.imag(); val_real += (a*c) - (b*d); val_imag += (a*d) + (b*c); } return std::complex(val_real, val_imag); } template arma_hot inline eT op_dot::dot_and_copy_row(eT* out, const TA& A, const uword row, const eT* B_mem, const uword N) { eT acc1 = eT(0); eT acc2 = eT(0); uword i,j; for(i=0, j=1; j < N; i+=2, j+=2) { const eT val_i = A.at(row, i); const eT val_j = A.at(row, j); out[i] = val_i; out[j] = val_j; acc1 += val_i * B_mem[i]; acc2 += val_j * B_mem[j]; } if(i < N) { const eT val_i = A.at(row, i); out[i] = val_i; acc1 += val_i * B_mem[i]; } return acc1 + acc2; } // // op_norm_dot template arma_hot inline typename T1::elem_type op_norm_dot::apply(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const bool prefer_at_accessor = (Proxy::prefer_at_accessor) && (Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { const Proxy PA(X); const Proxy PB(Y); const uword N = PA.get_n_elem(); arma_debug_check( (N != PB.get_n_elem()), "norm_dot(): objects must have the same number of elements" ); ea_type1 A = PA.get_ea(); ea_type2 B = PB.get_ea(); eT acc1 = eT(0); eT acc2 = eT(0); eT acc3 = eT(0); for(uword i=0; i arma_hot inline typename T1::elem_type op_norm_dot::apply_unwrap(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp1(X); const unwrap tmp2(Y); const Mat& A = tmp1.M; const Mat& B = tmp2.M; arma_debug_check( (A.n_elem != B.n_elem), "norm_dot(): objects must have the same number of elements" ); const uword N = A.n_elem; const eT* A_mem = A.memptr(); const eT* B_mem = B.memptr(); eT acc1 = eT(0); eT acc2 = eT(0); eT acc3 = eT(0); for(uword i=0; i arma_hot arma_pure inline eT op_cdot::direct_cdot_arma(const uword n_elem, const eT* const A, const eT* const B) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; T val_real = T(0); T val_imag = T(0); for(uword i=0; i& X = A[i]; const std::complex& Y = B[i]; const T a = X.real(); const T b = X.imag(); const T c = Y.real(); const T d = Y.imag(); val_real += (a*c) + (b*d); val_imag += (a*d) - (b*c); } return std::complex(val_real, val_imag); } template arma_hot arma_pure inline eT op_cdot::direct_cdot(const uword n_elem, const eT* const A, const eT* const B) { arma_extra_debug_sigprint(); if( n_elem <= 32u ) { return op_cdot::direct_cdot_arma(n_elem, A, B); } else { #if defined(ARMA_USE_BLAS) { arma_extra_debug_print("blas::gemv()"); // using gemv() workaround due to compatibility issues with cdotc() and zdotc() const char trans = 'C'; const blas_int m = blas_int(n_elem); const blas_int n = 1; //const blas_int lda = (n_elem > 0) ? blas_int(n_elem) : blas_int(1); const blas_int inc = 1; const eT alpha = eT(1); const eT beta = eT(0); eT result[2]; // paranoia: using two elements instead of one //blas::gemv(&trans, &m, &n, &alpha, A, &lda, B, &inc, &beta, &result[0], &inc); blas::gemv(&trans, &m, &n, &alpha, A, &m, B, &inc, &beta, &result[0], &inc); return result[0]; } #elif defined(ARMA_USE_ATLAS) { // TODO: use dedicated atlas functions cblas_cdotc_sub() and cblas_zdotc_sub() and retune threshold return op_cdot::direct_cdot_arma(n_elem, A, B); } #else { return op_cdot::direct_cdot_arma(n_elem, A, B); } #endif } } template arma_hot inline typename T1::elem_type op_cdot::apply(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); if( (is_Mat::value == true) && (is_Mat::value == true) ) { return op_cdot::apply_unwrap(X,Y); } else { return op_cdot::apply_proxy(X,Y); } } template arma_hot inline typename T1::elem_type op_cdot::apply_unwrap(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp1(X); const unwrap tmp2(Y); const Mat& A = tmp1.M; const Mat& B = tmp2.M; arma_debug_check( (A.n_elem != B.n_elem), "cdot(): objects must have the same number of elements" ); return op_cdot::direct_cdot( A.n_elem, A.mem, B.mem ); } template arma_hot inline typename T1::elem_type op_cdot::apply_proxy(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const bool prefer_at_accessor = (Proxy::prefer_at_accessor) || (Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { const Proxy PA(X); const Proxy PB(Y); const uword N = PA.get_n_elem(); arma_debug_check( (N != PB.get_n_elem()), "cdot(): objects must have the same number of elements" ); ea_type1 A = PA.get_ea(); ea_type2 B = PB.get_ea(); T val_real = T(0); T val_imag = T(0); for(uword i=0; i AA = A[i]; const std::complex BB = B[i]; const T a = AA.real(); const T b = AA.imag(); const T c = BB.real(); const T d = BB.imag(); val_real += (a*c) + (b*d); val_imag += (a*d) - (b*c); } return std::complex(val_real, val_imag); } else { return op_cdot::apply_unwrap( X, Y ); } } template arma_hot inline typename promote_type::result op_dot_mixed::apply(const T1& A, const T2& B) { arma_extra_debug_sigprint(); typedef typename T1::elem_type in_eT1; typedef typename T2::elem_type in_eT2; typedef typename promote_type::result out_eT; const Proxy PA(A); const Proxy PB(B); const uword N = PA.get_n_elem(); arma_debug_check( (N != PB.get_n_elem()), "dot(): objects must have the same number of elements" ); out_eT acc = out_eT(0); for(uword i=0; i < N; ++i) { acc += upgrade_val::apply(PA[i]) * upgrade_val::apply(PB[i]); } return acc; } //! @} RcppArmadillo/inst/include/armadillo_bits/SpSubview_meat.hpp0000644000176000001440000007543212111344723024077 0ustar ripleyusers// Copyright (C) 2011-2012 Ryan Curtin // Copyright (C) 2011 Matthew Amidon // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpSubview //! @{ template arma_inline SpSubview::SpSubview(const SpMat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols) : m(in_m) , aux_row1(in_row1) , aux_col1(in_col1) , n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows * in_n_cols) , n_nonzero(0) { arma_extra_debug_sigprint(); // There must be a O(1) way to do this uword lend = m.col_ptrs[in_col1 + in_n_cols]; uword lend_row = in_row1 + in_n_rows; uword count = 0; for(uword i = m.col_ptrs[in_col1]; i < lend; ++i) { if(m.row_indices[i] >= in_row1 && m.row_indices[i] < lend_row) { ++count; } } access::rw(n_nonzero) = count; } template arma_inline SpSubview::SpSubview(SpMat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols) : m(in_m) , aux_row1(in_row1) , aux_col1(in_col1) , n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows * in_n_cols) , n_nonzero(0) { arma_extra_debug_sigprint(); // There must be a O(1) way to do this uword lend = m.col_ptrs[in_col1 + in_n_cols]; uword lend_row = in_row1 + in_n_rows; uword count = 0; for(uword i = m.col_ptrs[in_col1]; i < lend; ++i) { if(m.row_indices[i] >= in_row1 && m.row_indices[i] < lend_row) { ++count; } } access::rw(n_nonzero) = count; } template inline SpSubview::~SpSubview() { arma_extra_debug_sigprint(); } template inline const SpSubview& SpSubview::operator+=(const eT val) { arma_extra_debug_sigprint(); if(val == eT(0)) { return *this; } const uword lstart_row = aux_row1; const uword lend_row = aux_row1 + n_rows; const uword lstart_col = aux_col1; const uword lend_col = aux_col1 + n_cols; const uword old_n_nonzero = m.n_nonzero; // iterate over our part of the sparse matrix for(uword lcol = lstart_col; lcol < lend_col; ++lcol) for(uword lrow = lstart_row; lrow < lend_row; ++lrow) { access::rw(m).at(lrow, lcol) += val; } const uword new_n_nonzero = m.n_nonzero; access::rw(n_nonzero) += (new_n_nonzero - old_n_nonzero); return *this; } template inline const SpSubview& SpSubview::operator-=(const eT val) { arma_extra_debug_sigprint(); if(val == eT(0)) { return *this; } const uword lstart_row = aux_row1; const uword lend_row = aux_row1 + n_rows; const uword lstart_col = aux_col1; const uword lend_col = aux_col1 + n_cols; const uword old_n_nonzero = m.n_nonzero; for(uword lcol = lstart_col; lcol < lend_col; ++lcol) for(uword lrow = lstart_row; lrow < lend_row; ++lrow) { access::rw(m).at(lrow, lcol) -= val; } const uword new_n_nonzero = m.n_nonzero; access::rw(n_nonzero) += (new_n_nonzero - old_n_nonzero); return *this; } template inline const SpSubview& SpSubview::operator*=(const eT val) { arma_extra_debug_sigprint(); if(val == eT(0)) { // Turn it all into zeros. for(iterator it(*this); it != end(); ++it) { (*it) = eT(0); // zero out the value. it.internal_pos--; } return *this; } const uword lstart_row = aux_row1; const uword lend_row = aux_row1 + n_rows; const uword lstart_col = aux_col1; const uword lend_col = aux_col1 + n_cols; for(uword c = lstart_col; c < lend_col; ++c) { for(uword r = m.col_ptrs[c]; r < m.col_ptrs[c + 1]; ++r) { if(m.row_indices[r] >= lstart_row && m.row_indices[r] < lend_row) { access::rw(m.values[r]) *= val; } } } return *this; } template inline const SpSubview& SpSubview::operator/=(const eT val) { arma_extra_debug_sigprint(); const uword lstart_col = aux_col1; const uword lend_col = aux_col1 + n_cols; const uword lstart_row = aux_row1; const uword lend_row = aux_row1 + n_rows; const uword old_n_nonzero = m.n_nonzero; for(uword c = lstart_col; c < lend_col; ++c) for(uword r = lstart_row; r < lend_row; ++r) { access::rw(m).at(r, c) /= val; } const uword new_n_nonzero = m.n_nonzero; access::rw(n_nonzero) += (new_n_nonzero - old_n_nonzero); return *this; } template template inline const SpSubview& SpSubview::operator=(const Base& x) { arma_extra_debug_sigprint(); const Proxy P(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "insert into sparse submatrix"); const uword old_n_nonzero = m.n_nonzero; for(uword c = 0; c < n_cols; ++c) { for(uword r = 0; r < n_rows; ++r) { at(r, c) = P.at(r, c); } } const uword new_n_nonzero = m.n_nonzero; access::rw(n_nonzero) += (new_n_nonzero - old_n_nonzero); return *this; } template template inline const SpSubview& SpSubview::operator+=(const Base& x) { arma_extra_debug_sigprint(); const Proxy P(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "addition"); const uword old_n_nonzero = m.n_nonzero; for(uword c = 0; c < n_cols; ++c) { for(uword r = 0; r < n_rows; ++r) { at(r, c) += P.at(r, c); } } const uword new_n_nonzero = m.n_nonzero; access::rw(n_nonzero) += (new_n_nonzero - old_n_nonzero); return *this; } template template inline const SpSubview& SpSubview::operator-=(const Base& x) { arma_extra_debug_sigprint(); const Proxy P(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "subtraction"); const uword old_n_nonzero = m.n_nonzero; for(uword c = 0; c < n_cols; ++c) { for(uword r = 0; r < n_rows; ++r) { at(r, c) -= P.at(r, c); } } const uword new_n_nonzero = m.n_nonzero; access::rw(n_nonzero) += (new_n_nonzero - old_n_nonzero); return *this; } template template inline const SpSubview& SpSubview::operator*=(const Base& x) { arma_extra_debug_sigprint(); const Proxy P(x.get_ref()); // Must be exactly the same size for this (we can't modify our own size). arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "matrix multiplication"); SpMat tmp(*this); Mat other_tmp(x.get_ref()); tmp *= other_tmp; operator=(tmp); return *this; } template template inline const SpSubview& SpSubview::operator%=(const Base& x) { arma_extra_debug_sigprint(); const Proxy P(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "element-wise multiplication"); const uword old_n_nonzero = m.n_nonzero; for(iterator it(*this); it != end(); ++it) { (*it) *= P.at(it.row(), it.col()); if(P.at(it.row(), it.col()) == eT(0)) { it.internal_pos--; } } const uword new_n_nonzero = m.n_nonzero; access::rw(n_nonzero) += (new_n_nonzero - old_n_nonzero); return *this; } template template inline const SpSubview& SpSubview::operator/=(const Base& x) { arma_extra_debug_sigprint(); const Proxy P(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "element-wise division"); const uword old_n_nonzero = m.n_nonzero; for(uword c = 0; c < n_cols; ++c) { for(uword r = 0; r < n_rows; ++r) { at(r, c) /= P.at(r, c); } } const uword new_n_nonzero = m.n_nonzero; access::rw(n_nonzero) += (new_n_nonzero - old_n_nonzero); return *this; } template inline const SpSubview& SpSubview::operator=(const SpSubview& x) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "insertion into sparse submatrix"); const bool alias = ( &m == &(x.m) ); if(alias == false) { const_iterator cit = x.begin(); iterator it = begin(); while((cit != x.end()) || (it != end())) { if((cit.row() == it.row()) && (cit.col() == it.col())) { (*it) = (*cit); ++it; ++cit; } else { if((cit.col() > it.col()) || ((cit.col() == it.col()) && (cit.row() > it.row()))) { // cit is "ahead" (*it) = eT(0); // erase element it.internal_pos--; // update iterator so it still works ++it; } else { // it is "ahead" at(cit.row(), cit.col()) = (*cit); it.internal_pos++; // update iterator so it still works ++cit; } } } access::rw(n_nonzero) = x.n_nonzero; } else { const SpMat tmp(x); (*this).operator=(tmp); } return *this; } template template inline const SpSubview& SpSubview::operator=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "insertion into sparse submatrix"); if(p.is_alias(m) == false) { typename SpProxy::const_iterator_type cit = p.begin(); iterator it(*this); while((cit != p.end()) || (it != end())) { if(cit == it) // at the same location { (*it) = (*cit); ++it; ++cit; } else { if((cit.col() > it.col()) || ((cit.col() == it.col()) && (cit.row() > it.row()))) { // cit is "ahead" (*it) = eT(0); // erase element it.internal_pos--; // update iterator so it still works ++it; } else { // it is "ahead" at(cit.row(), cit.col()) = (*cit); it.internal_pos++; // update iterator so it still works ++cit; } } } } else { const SpMat tmp(p.Q); (*this).operator=(tmp); } return *this; } template template inline const SpSubview& SpSubview::operator+=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "addition"); if(p.is_alias(m) == false) { typename SpProxy::const_iterator_type cit = p.begin(); while(cit != p.end()) { at(cit.row(), cit.col()) += (*cit); ++cit; } } else { const SpMat tmp(p.Q); (*this).operator+=(tmp); } return *this; } template template inline const SpSubview& SpSubview::operator-=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "subtraction"); if(p.is_alias(m) == false) { typename SpProxy::const_iterator_type cit = p.begin(); while(cit != p.end()) { at(cit.row(), cit.col()) -= (*cit); ++cit; } } else { const SpMat tmp(p.Q); (*this).operator-=(tmp); } return *this; } template template inline const SpSubview& SpSubview::operator*=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "matrix multiplication"); // Because we have to use a temporary anyway, it doesn't make sense to // reimplement this here. return operator=((*this) * x.get_ref()); } template template inline const SpSubview& SpSubview::operator%=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise multiplication"); if(p.is_alias(m) == false) { typename SpProxy::const_iterator_type cit = p.begin(); iterator it(*this); while((it != end()) || (cit != p.end())) { if((cit.row() == it.row()) && (cit.col() == it.col())) { (*it) *= (*cit); ++it; ++cit; } else { if((cit.col() > it.col()) || ((cit.col() == it.col()) && (cit.row() > it.row()))) { // cit is "ahead" (*it) = eT(0); // erase element -- x has a zero here it.internal_pos--; // update iterator so it still works ++it; } else { // it is "ahead" ++cit; } } } } else { const SpMat tmp(p.Q); (*this).operator%=(tmp); } return *this; } //! If you are using this function, you are probably misguided. template template inline const SpSubview& SpSubview::operator/=(const SpBase& x) { arma_extra_debug_sigprint(); SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise division"); if(p.is_alias(m) == false) { for(uword lcol = 0; lcol < n_cols; ++lcol) for(uword lrow = 0; lrow < n_rows; ++lrow) { at(lrow,lcol) /= p.at(lrow,lcol); } } else { const SpMat tmp(p.Q); (*this).operator/=(tmp); } return *this; } template inline void SpSubview::fill(const eT val) { arma_extra_debug_sigprint(); if(val != eT(0)) { // TODO: implement a faster version; the code below is slow const uword lstart_row = aux_row1; const uword lend_row = aux_row1 + n_rows; const uword lstart_col = aux_col1; const uword lend_col = aux_col1 + n_cols; const uword orig_nonzero = m.n_nonzero; // iterate over our part of the sparse matrix for(uword lcol = lstart_col; lcol < lend_col; ++lcol) for(uword lrow = lstart_row; lrow < lend_row; ++lrow) { access::rw(m).at(lrow, lcol) = val; } access::rw(n_nonzero) += (m.n_nonzero - orig_nonzero); } else { (*this).zeros(); } } template inline void SpSubview::zeros() { arma_extra_debug_sigprint(); // we can be a little smarter here iterator it(*this); while(it != end()) { (*it) = eT(0); it.internal_pos--; // hack to update iterator without requiring a new one ++it; } } template inline void SpSubview::ones() { arma_extra_debug_sigprint(); (*this).fill(eT(1)); } template inline void SpSubview::eye() { arma_extra_debug_sigprint(); // clear other things (*this).zeros(); const uword orig_nonzero = m.n_nonzero; // now the diagonal ones const uword end_index = std::min(n_rows, n_cols); for(uword ind = 0; ind < end_index; ++ind) { access::rw(m).at(ind + aux_row1, ind + aux_col1) = eT(1); } access::rw(n_nonzero) += (m.n_nonzero - orig_nonzero); } template arma_hot inline SpValProxy > SpSubview::operator[](const uword i) { const uword lrow = i % n_rows; const uword lcol = i / n_rows; return (*this).at(lrow, lcol); } template arma_hot inline eT SpSubview::operator[](const uword i) const { const uword lrow = i % n_rows; const uword lcol = i / n_rows; return (*this).at(lrow, lcol); } template arma_hot inline SpValProxy< SpSubview > SpSubview::operator()(const uword i) { arma_debug_check( (i >= n_elem), "SpSubview::operator(): index out of bounds"); const uword lrow = i % n_rows; const uword lcol = i / n_rows; return (*this).at(lrow, lcol); } template arma_hot inline eT SpSubview::operator()(const uword i) const { arma_debug_check( (i >= n_elem), "SpSubview::operator(): index out of bounds"); const uword lrow = i % n_rows; const uword lcol = i / n_rows; return (*this).at(lrow, lcol); } template arma_hot inline SpValProxy< SpSubview > SpSubview::operator()(const uword in_row, const uword in_col) { arma_debug_check( (in_row >= n_rows) || (in_col >= n_cols), "SpSubview::operator(): index out of bounds"); return (*this).at(in_row, in_col); } template arma_hot inline eT SpSubview::operator()(const uword in_row, const uword in_col) const { arma_debug_check( (in_row >= n_rows) || (in_col >= n_cols), "SpSubview::operator(): index out of bounds"); return (*this).at(in_row, in_col); } template arma_hot inline SpValProxy< SpSubview > SpSubview::at(const uword i) { const uword lrow = i % n_rows; const uword lcol = i / n_cols; return (*this).at(lrow, lcol); } template arma_hot inline eT SpSubview::at(const uword i) const { const uword lrow = i % n_rows; const uword lcol = i / n_cols; return (*this).at(lrow, lcol); } template arma_hot inline SpValProxy< SpSubview > SpSubview::at(const uword in_row, const uword in_col) { const uword colptr = m.col_ptrs[in_col + aux_col1]; const uword next_colptr = m.col_ptrs[in_col + aux_col1 + 1]; // Step through the row indices to see if our element exists. for(uword i = colptr; i < next_colptr; ++i) { // First check that we have not stepped past it. if((in_row + aux_row1) < m.row_indices[i]) { return SpValProxy >(in_row, in_col, *this); // Proxy for a zero value. } // Now check if we are at the correct place. if((in_row + aux_row1) == m.row_indices[i]) // If we are, return a reference to the value. { return SpValProxy >(in_row, in_col, *this, &access::rw(m.values[i])); } } // We did not find it, so it does not exist. return SpValProxy >(in_row, in_col, *this); } template arma_hot inline eT SpSubview::at(const uword in_row, const uword in_col) const { return m.at(aux_row1 + in_row, aux_col1 + in_col); } template inline bool SpSubview::check_overlap(const SpSubview& x) const { const subview& t = *this; if(&t.m != &x.m) { return false; } else { if( (t.n_elem == 0) || (x.n_elem == 0) ) { return false; } else { const uword t_row_start = t.aux_row1; const uword t_row_end_p1 = t_row_start + t.n_rows; const uword t_col_start = t.aux_col1; const uword t_col_end_p1 = t_col_start + t.n_cols; const uword x_row_start = x.aux_row1; const uword x_row_end_p1 = x_row_start + x.n_rows; const uword x_col_start = x.aux_col1; const uword x_col_end_p1 = x_col_start + x.n_cols; const bool outside_rows = ( (x_row_start >= t_row_end_p1) || (t_row_start >= x_row_end_p1) ); const bool outside_cols = ( (x_col_start >= t_col_end_p1) || (t_col_start >= x_col_end_p1) ); return ( (outside_rows == false) && (outside_cols == false) ); } } } template inline bool SpSubview::is_vec() const { return ( (n_rows == 1) || (n_cols == 1) ); } template inline SpSubview SpSubview::row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check(row_num >= n_rows, "SpSubview::row(): out of bounds"); return submat(row_num, 0, row_num, n_cols - 1); } template inline const SpSubview SpSubview::row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check(row_num >= n_rows, "SpSubview::row(): out of bounds"); return submat(row_num, 0, row_num, n_cols - 1); } template inline SpSubview SpSubview::col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check(col_num >= n_cols, "SpSubview::col(): out of bounds"); return submat(0, col_num, n_rows - 1, col_num); } template inline const SpSubview SpSubview::col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check(col_num >= n_cols, "SpSubview::col(): out of bounds"); return submat(0, col_num, n_rows - 1, col_num); } template inline SpSubview SpSubview::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "SpSubview::rows(): indices out of bounds or incorrectly used" ); return submat(in_row1, 0, in_row2, n_cols - 1); } template inline const SpSubview SpSubview::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "SpSubview::rows(): indices out of bounds or incorrectly used" ); return submat(in_row1, 0, in_row2, n_cols - 1); } template inline SpSubview SpSubview::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "SpSubview::cols(): indices out of bounds or incorrectly used" ); return submat(0, in_col1, n_rows - 1, in_col2); } template inline const SpSubview SpSubview::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "SpSubview::cols(): indices out of bounds or incorrectly used" ); return submat(0, in_col1, n_rows - 1, in_col2); } template inline SpSubview SpSubview::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "SpSubview::submat(): indices out of bounds or incorrectly used" ); return access::rw(m).submat(in_row1 + aux_row1, in_col1 + aux_col1, in_row2 + aux_row1, in_col2 + aux_col1); } template inline const SpSubview SpSubview::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "SpSubview::submat(): indices out of bounds or incorrectly used" ); return m.submat(in_row1 + aux_row1, in_col1 + aux_col1, in_row2 + aux_row1, in_col2 + aux_col1); } template inline SpSubview SpSubview::submat(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = row_span.whole; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_all ? n_rows : row_span.b; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_all ? n_cols : col_span.b; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= n_rows))) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= n_cols))), "SpSubview::submat(): indices out of bounds or incorrectly used" ); return submat(in_row1, in_col1, in_row2, in_col2); } template inline const SpSubview SpSubview::submat(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = row_span.whole; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_all ? n_rows - 1 : row_span.b; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_all ? n_cols - 1 : col_span.b; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= n_rows))) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= n_cols))), "SpSubview::submat(): indices out of bounds or incorrectly used" ); return submat(in_row1, in_col1, in_row2, in_col2); } template inline SpSubview SpSubview::operator()(const uword row_num, const span& col_span) { arma_extra_debug_sigprint(); return submat(span(row_num, row_num), col_span); } template inline const SpSubview SpSubview::operator()(const uword row_num, const span& col_span) const { arma_extra_debug_sigprint(); return submat(span(row_num, row_num), col_span); } template inline SpSubview SpSubview::operator()(const span& row_span, const uword col_num) { arma_extra_debug_sigprint(); return submat(row_span, span(col_num, col_num)); } template inline const SpSubview SpSubview::operator()(const span& row_span, const uword col_num) const { arma_extra_debug_sigprint(); return submat(row_span, span(col_num, col_num)); } template inline SpSubview SpSubview::operator()(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); return submat(row_span, col_span); } template inline const SpSubview SpSubview::operator()(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); return submat(row_span, col_span); } template inline void SpSubview::swap_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check((in_row1 >= n_rows) || (in_row2 >= n_rows), "SpSubview::swap_rows(): invalid row index"); const uword lstart_col = aux_col1; const uword lend_col = aux_col1 + n_cols; for(uword c = lstart_col; c < lend_col; ++c) { eT val = m.at(in_row1 + aux_row1, c); access::rw(m).at(in_row2 + aux_row1, c) = m.at(in_row1 + aux_row1, c); access::rw(m).at(in_row1 + aux_row1, c) = val; } } template inline void SpSubview::swap_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check((in_col1 >= n_cols) || (in_col2 >= n_cols), "SpSubview::swap_cols(): invalid column index"); const uword lstart_row = aux_row1; const uword lend_row = aux_row1 + n_rows; for(uword r = lstart_row; r < lend_row; ++r) { eT val = m.at(r, in_col1 + aux_col1); access::rw(m).at(r, in_col1 + aux_col1) = m.at(r, in_col2 + aux_col1); access::rw(m).at(r, in_col2 + aux_col1) = val; } } template inline typename SpSubview::iterator SpSubview::begin() { return iterator(*this); } template inline typename SpSubview::const_iterator SpSubview::begin() const { return const_iterator(*this); } template inline typename SpSubview::iterator SpSubview::begin_col(const uword col_num) { return iterator(*this, 0, col_num); } template inline typename SpSubview::const_iterator SpSubview::begin_col(const uword col_num) const { return const_iterator(*this, 0, col_num); } template inline typename SpSubview::row_iterator SpSubview::begin_row(const uword row_num) { return row_iterator(*this, row_num, 0); } template inline typename SpSubview::const_row_iterator SpSubview::begin_row(const uword row_num) const { return const_row_iterator(*this, row_num, 0); } template inline typename SpSubview::iterator SpSubview::end() { return iterator(*this, 0, n_cols, n_nonzero, m.n_nonzero - n_nonzero); } template inline typename SpSubview::const_iterator SpSubview::end() const { return const_iterator(*this, 0, n_cols, n_nonzero, m.n_nonzero - n_nonzero); } template inline typename SpSubview::row_iterator SpSubview::end_row() { return row_iterator(*this, n_nonzero); } template inline typename SpSubview::const_row_iterator SpSubview::end_row() const { return const_row_iterator(*this, n_nonzero); } template inline typename SpSubview::row_iterator SpSubview::end_row(const uword row_num) { return row_iterator(*this, row_num + 1, 0); } template inline typename SpSubview::const_row_iterator SpSubview::end_row(const uword row_num) const { return const_row_iterator(*this, row_num + 1, 0); } template inline arma_hot arma_warn_unused eT& SpSubview::add_element(const uword in_row, const uword in_col, const eT in_val) { arma_extra_debug_sigprint(); // This may not actually add an element. const uword old_n_nonzero = m.n_nonzero; eT& retval = access::rw(m).add_element(in_row + aux_row1, in_col + aux_col1, in_val); // Update n_nonzero (if necessary). access::rw(n_nonzero) += (m.n_nonzero - old_n_nonzero); return retval; } template inline void SpSubview::delete_element(const uword in_row, const uword in_col) { arma_extra_debug_sigprint(); // This may not actually delete an element. const uword old_n_nonzero = m.n_nonzero; access::rw(m).delete_element(in_row + aux_row1, in_col + aux_col1); access::rw(n_nonzero) -= (old_n_nonzero - m.n_nonzero); } /** * Sparse subview col * template inline SpSubview_col::SpSubview_col(const Mat& in_m, const uword in_col) { arma_extra_debug_sigprint(); } template inline SpSubview_col::SpSubview_col(Mat& in_m, const uword in_col) { arma_extra_debug_sigprint(); } template inline SpSubview_col::SpSubview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows) { arma_extra_debug_sigprint(); } template inline SpSubview_col::SpSubview_col(Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows) { arma_extra_debug_sigprint(); } */ /** * Sparse subview row * template inline SpSubview_row::SpSubview_row(const Mat& in_m, const uword in_row) { arma_extra_debug_sigprint(); } template inline SpSubview_row::SpSubview_row(Mat& in_m, const uword in_row) { arma_extra_debug_sigprint(); } template inline SpSubview_row::SpSubview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols) { arma_extra_debug_sigprint(); } template inline SpSubview_row::SpSubview_row(Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols) { arma_extra_debug_sigprint(); } */ //! @} RcppArmadillo/inst/include/armadillo_bits/strip.hpp0000644000176000001440000000340612257054523022302 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup strip //! @{ template struct strip_diagmat { typedef T1 stored_type; arma_hot inline strip_diagmat(const T1& X) : M(X) { arma_extra_debug_sigprint(); } static const bool do_diagmat = false; const T1& M; }; template struct strip_diagmat< Op > { typedef T1 stored_type; arma_hot inline strip_diagmat(const Op& X) : M(X.m) { arma_extra_debug_sigprint(); } static const bool do_diagmat = true; const T1& M; }; template struct strip_inv { typedef T1 stored_type; arma_hot inline strip_inv(const T1& X) : M(X) { arma_extra_debug_sigprint(); } const T1& M; static const bool slow = false; static const bool do_inv = false; }; template struct strip_inv< Op > { typedef T1 stored_type; arma_hot inline strip_inv(const Op& X) : M(X.m) , slow(X.aux_uword_a == 1) { arma_extra_debug_sigprint(); } const T1& M; const bool slow; static const bool do_inv = true; }; template struct strip_inv< Op > { typedef T1 stored_type; arma_hot inline strip_inv(const Op& X) : M(X.m) , slow(X.aux_uword_a == 1) { arma_extra_debug_sigprint(); } const T1& M; const bool slow; static const bool do_inv = true; }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_cor.hpp0000644000176000001440000000204312200375542022376 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_cor //! @{ template inline const Op cor(const Base& X, const uword norm_type = 0) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "cor(): norm_type must be 0 or 1"); return Op(X.get_ref(), norm_type, 0); } template inline const Glue cor(const Base& A, const Base& B, const uword norm_type = 0) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "cor(): norm_type must be 0 or 1"); return Glue(A.get_ref(), B.get_ref(), norm_type); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_princomp_bones.hpp0000644000176000001440000000673312200631217024647 0ustar ripleyusers// Copyright (C) 2010-2012 Conrad Sanderson // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) // Copyright (C) 2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_princomp //! @{ class op_princomp { public: // // real element versions template inline static bool direct_princomp ( Mat& coeff_out, const Base& X, const typename arma_not_cx::result* junk = 0 ); template inline static bool direct_princomp ( Mat& coeff_out, Mat& score_out, const Base& X, const typename arma_not_cx::result* junk = 0 ); template inline static bool direct_princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, const Base& X, const typename arma_not_cx::result* junk = 0 ); template inline static bool direct_princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, Col& tsquared_out, const Base& X, const typename arma_not_cx::result* junk = 0 ); // // complex element versions template inline static bool direct_princomp ( Mat< std::complex >& coeff_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk = 0 ); template inline static bool direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk = 0 ); template inline static bool direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, Col< typename T1::pod_type >& latent_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk = 0 ); template inline static bool direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, Col< typename T1::pod_type >& latent_out, Col< std::complex >& tsquared_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk = 0 ); template inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_trans.hpp0000644000176000001440000000516312200375542022750 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_trans //! @{ template arma_inline const Op trans ( const T1& X, const typename enable_if< is_arma_type::value == true >::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X); } template arma_inline const Op htrans ( const T1& X, const typename enable_if< is_arma_type::value == true >::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X); } //! two consecutive transpose operations cancel each other template arma_inline const T1& trans(const Op& X) { arma_extra_debug_sigprint(); arma_extra_debug_print("trans(): removing op_htrans"); return X.m; } template arma_inline const T1& htrans(const Op& X) { arma_extra_debug_sigprint(); arma_extra_debug_print("htrans(): removing op_htrans"); return X.m; } // // handling of sparse matrices template inline typename enable_if2 < is_arma_sparse_type::value, const SpOp >::result trans ( const T1& x, const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return SpOp(x); } template inline typename enable_if2 < is_arma_sparse_type::value, const SpOp >::result trans ( const T1& x, const typename arma_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return SpOp(x); } template inline typename enable_if2 < is_arma_sparse_type::value, const SpOp >::result htrans ( const T1& x, const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return SpOp(x); } template inline typename enable_if2 < is_arma_sparse_type::value, const SpOp >::result htrans ( const T1& x, const typename arma_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return SpOp(x); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_cov.hpp0000644000176000001440000000204112200375542022400 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_cov //! @{ template inline const Op cov(const Base& X, const uword norm_type = 0) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "cov(): norm_type must be 0 or 1"); return Op(X.get_ref(), norm_type, 0); } template inline const Glue cov(const Base& A, const Base& B, const uword norm_type = 0) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "cov(): norm_type must be 0 or 1"); return Glue(A.get_ref(), B.get_ref(), norm_type); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_prod.hpp0000644000176000001440000000474212200375542022567 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_prod //! @{ //! \brief //! Delayed product of elements of a matrix along a specified dimension (either rows or columns). //! The result is stored in a dense matrix that has either one column or one row. //! For dim = 0, find the sum of each column (i.e. traverse across rows) //! For dim = 1, find the sum of each row (i.e. traverse across columns) //! The default is dim = 0. //! NOTE: this function works differently than in Matlab/Octave. template arma_inline const Op prod ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op prod ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type prod ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_prod::prod( X ); } //! \brief //! Immediate 'product of all values' operation, //! invoked, for example, by: prod(prod(A)) template inline arma_warn_unused typename T1::elem_type prod(const Op& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("prod(): two consecutive prod() calls detected"); return op_prod::prod( in.m ); } template inline const Op, op_prod> prod(const Op& in, const uword dim) { arma_extra_debug_sigprint(); return Op, op_prod>(in, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & prod(const T& x) { return x; } //! @} RcppArmadillo/inst/include/armadillo_bits/running_stat_vec_meat.hpp0000644000176000001440000003245712250100525025512 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup running_stat_vec //! @{ template running_stat_vec::~running_stat_vec() { arma_extra_debug_sigprint_this(this); } template running_stat_vec::running_stat_vec(const bool in_calc_cov) : calc_cov(in_calc_cov) { arma_extra_debug_sigprint_this(this); } template running_stat_vec::running_stat_vec(const running_stat_vec& in_rsv) : calc_cov (in_rsv.calc_cov) , counter (in_rsv.counter) , r_mean (in_rsv.r_mean) , r_var (in_rsv.r_var) , r_cov (in_rsv.r_cov) , min_val (in_rsv.min_val) , max_val (in_rsv.max_val) , min_val_norm(in_rsv.min_val_norm) , max_val_norm(in_rsv.max_val_norm) { arma_extra_debug_sigprint_this(this); } template const running_stat_vec& running_stat_vec::operator=(const running_stat_vec& in_rsv) { arma_extra_debug_sigprint(); access::rw(calc_cov) = in_rsv.calc_cov; counter = in_rsv.counter; r_mean = in_rsv.r_mean; r_var = in_rsv.r_var; r_cov = in_rsv.r_cov; min_val = in_rsv.min_val; max_val = in_rsv.max_val; min_val_norm = in_rsv.min_val_norm; max_val_norm = in_rsv.max_val_norm; return *this; } //! update statistics to reflect new sample template template arma_hot inline void running_stat_vec::operator() (const Base::T, T1>& X) { arma_extra_debug_sigprint(); const unwrap tmp(X.get_ref()); const Mat& sample = tmp.M; if( sample.is_empty() ) { return; } if( sample.is_finite() == false ) { arma_warn(true, "running_stat_vec: sample ignored as it has non-finite elements"); return; } running_stat_vec_aux::update_stats(*this, sample); } template template arma_hot inline void running_stat_vec::operator() (const Base< std::complex::T>, T1>& X) { arma_extra_debug_sigprint(); const unwrap tmp(X.get_ref()); const Mat< std::complex >& sample = tmp.M; if( sample.is_empty() ) { return; } if( sample.is_finite() == false ) { arma_warn(true, "running_stat_vec: sample ignored as it has non-finite elements"); return; } running_stat_vec_aux::update_stats(*this, sample); } //! set all statistics to zero template inline void running_stat_vec::reset() { arma_extra_debug_sigprint(); counter.reset(); r_mean.reset(); r_var.reset(); r_cov.reset(); min_val.reset(); max_val.reset(); min_val_norm.reset(); max_val_norm.reset(); r_var_dummy.reset(); r_cov_dummy.reset(); tmp1.reset(); tmp2.reset(); } //! mean or average value template inline const Mat< typename running_stat_vec::eT >& running_stat_vec::mean() const { arma_extra_debug_sigprint(); return r_mean; } //! variance template inline const Mat< typename running_stat_vec::T >& running_stat_vec::var(const uword norm_type) { arma_extra_debug_sigprint(); const T N = counter.value(); if(N > T(1)) { if(norm_type == 0) { return r_var; } else { const T N_minus_1 = counter.value_minus_1(); r_var_dummy = (N_minus_1/N) * r_var; return r_var_dummy; } } else { r_var_dummy.zeros(r_mean.n_rows, r_mean.n_cols); return r_var_dummy; } } //! standard deviation template inline Mat< typename running_stat_vec::T > running_stat_vec::stddev(const uword norm_type) const { arma_extra_debug_sigprint(); const T N = counter.value(); if(N > T(1)) { if(norm_type == 0) { return sqrt(r_var); } else { const T N_minus_1 = counter.value_minus_1(); return sqrt( (N_minus_1/N) * r_var ); } } else { return Mat(); } } //! covariance template inline const Mat< typename running_stat_vec::eT >& running_stat_vec::cov(const uword norm_type) { arma_extra_debug_sigprint(); if(calc_cov == true) { const T N = counter.value(); if(N > T(1)) { if(norm_type == 0) { return r_cov; } else { const T N_minus_1 = counter.value_minus_1(); r_cov_dummy = (N_minus_1/N) * r_cov; return r_cov_dummy; } } else { r_cov_dummy.zeros(r_mean.n_rows, r_mean.n_cols); return r_cov_dummy; } } else { r_cov_dummy.reset(); return r_cov_dummy; } } //! vector with minimum values template inline const Mat< typename running_stat_vec::eT >& running_stat_vec::min() const { arma_extra_debug_sigprint(); return min_val; } //! vector with maximum values template inline const Mat< typename running_stat_vec::eT >& running_stat_vec::max() const { arma_extra_debug_sigprint(); return max_val; } //! number of samples so far template inline typename running_stat_vec::T running_stat_vec::count() const { arma_extra_debug_sigprint(); return counter.value(); } // //! update statistics to reflect new sample (version for non-complex numbers) template inline void running_stat_vec_aux::update_stats ( running_stat_vec& x, const Mat::eT>& sample, const typename arma_not_cx::eT>::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename running_stat_vec::eT eT; typedef typename running_stat_vec::T T; const T N = x.counter.value(); if(N > T(0)) { arma_debug_assert_same_size(x.r_mean, sample, "running_stat_vec(): dimensionality mismatch"); const uword n_elem = sample.n_elem; const eT* sample_mem = sample.memptr(); eT* r_mean_mem = x.r_mean.memptr(); T* r_var_mem = x.r_var.memptr(); eT* min_val_mem = x.min_val.memptr(); eT* max_val_mem = x.max_val.memptr(); const T N_plus_1 = x.counter.value_plus_1(); const T N_minus_1 = x.counter.value_minus_1(); if(x.calc_cov == true) { Mat& tmp1 = x.tmp1; Mat& tmp2 = x.tmp2; tmp1 = sample - x.r_mean; if(sample.n_cols == 1) { tmp2 = tmp1*trans(tmp1); } else { tmp2 = trans(tmp1)*tmp1; } x.r_cov *= (N_minus_1/N); x.r_cov += tmp2 / N_plus_1; } for(uword i=0; i max_val_mem[i]) { max_val_mem[i] = val; } const eT r_mean_val = r_mean_mem[i]; const eT tmp = val - r_mean_val; r_var_mem[i] = N_minus_1/N * r_var_mem[i] + (tmp*tmp)/N_plus_1; r_mean_mem[i] = r_mean_val + (val - r_mean_val)/N_plus_1; } } else { arma_debug_check( (sample.is_vec() == false), "running_stat_vec(): given sample is not a vector"); x.r_mean.set_size(sample.n_rows, sample.n_cols); x.r_var.zeros(sample.n_rows, sample.n_cols); if(x.calc_cov == true) { x.r_cov.zeros(sample.n_elem, sample.n_elem); } x.min_val.set_size(sample.n_rows, sample.n_cols); x.max_val.set_size(sample.n_rows, sample.n_cols); const uword n_elem = sample.n_elem; const eT* sample_mem = sample.memptr(); eT* r_mean_mem = x.r_mean.memptr(); eT* min_val_mem = x.min_val.memptr(); eT* max_val_mem = x.max_val.memptr(); for(uword i=0; i inline void running_stat_vec_aux::update_stats ( running_stat_vec& x, const Mat::T > >& sample, const typename arma_not_cx::eT>::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename running_stat_vec::eT eT; running_stat_vec_aux::update_stats(x, conv_to< Mat >::from(sample)); } //! update statistics to reflect new sample (version for complex numbers, non-complex sample) template inline void running_stat_vec_aux::update_stats ( running_stat_vec& x, const Mat::T >& sample, const typename arma_cx_only::eT>::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename running_stat_vec::eT eT; running_stat_vec_aux::update_stats(x, conv_to< Mat >::from(sample)); } //! alter statistics to reflect new sample (version for complex numbers, complex sample) template inline void running_stat_vec_aux::update_stats ( running_stat_vec& x, const Mat::eT>& sample, const typename arma_cx_only::eT>::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename running_stat_vec::eT eT; typedef typename running_stat_vec::T T; const T N = x.counter.value(); if(N > T(0)) { arma_debug_assert_same_size(x.r_mean, sample, "running_stat_vec(): dimensionality mismatch"); const uword n_elem = sample.n_elem; const eT* sample_mem = sample.memptr(); eT* r_mean_mem = x.r_mean.memptr(); T* r_var_mem = x.r_var.memptr(); eT* min_val_mem = x.min_val.memptr(); eT* max_val_mem = x.max_val.memptr(); T* min_val_norm_mem = x.min_val_norm.memptr(); T* max_val_norm_mem = x.max_val_norm.memptr(); const T N_plus_1 = x.counter.value_plus_1(); const T N_minus_1 = x.counter.value_minus_1(); if(x.calc_cov == true) { Mat& tmp1 = x.tmp1; Mat& tmp2 = x.tmp2; tmp1 = sample - x.r_mean; if(sample.n_cols == 1) { tmp2 = arma::conj(tmp1)*strans(tmp1); } else { tmp2 = trans(tmp1)*tmp1; //tmp2 = strans(conj(tmp1))*tmp1; } x.r_cov *= (N_minus_1/N); x.r_cov += tmp2 / N_plus_1; } for(uword i=0; i max_val_norm_mem[i]) { max_val_norm_mem[i] = val_norm; max_val_mem[i] = val; } const eT& r_mean_val = r_mean_mem[i]; r_var_mem[i] = N_minus_1/N * r_var_mem[i] + std::norm(val - r_mean_val)/N_plus_1; r_mean_mem[i] = r_mean_val + (val - r_mean_val)/N_plus_1; } } else { arma_debug_check( (sample.is_vec() == false), "running_stat_vec(): given sample is not a vector"); x.r_mean.set_size(sample.n_rows, sample.n_cols); x.r_var.zeros(sample.n_rows, sample.n_cols); if(x.calc_cov == true) { x.r_cov.zeros(sample.n_elem, sample.n_elem); } x.min_val.set_size(sample.n_rows, sample.n_cols); x.max_val.set_size(sample.n_rows, sample.n_cols); x.min_val_norm.set_size(sample.n_rows, sample.n_cols); x.max_val_norm.set_size(sample.n_rows, sample.n_cols); const uword n_elem = sample.n_elem; const eT* sample_mem = sample.memptr(); eT* r_mean_mem = x.r_mean.memptr(); eT* min_val_mem = x.min_val.memptr(); eT* max_val_mem = x.max_val.memptr(); T* min_val_norm_mem = x.min_val_norm.memptr(); T* max_val_norm_mem = x.max_val_norm.memptr(); for(uword i=0; i arma_inline bool arma_isfinite(eT val) { arma_ignore(val); return true; } template<> arma_inline bool arma_isfinite(float x) { #if defined(ARMA_USE_CXX11) { return std::isfinite(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::isfinite(x); } #elif defined(ARMA_HAVE_ISFINITE) { return (std::isfinite(x) != 0); } #else { const bool x_is_inf = ( (x == x) && ((x - x) != float(0)) ); const bool x_is_nan = (x != x); return ( (x_is_inf == false) && (x_is_nan == false) ); } #endif } template<> arma_inline bool arma_isfinite(double x) { #if defined(ARMA_USE_CXX11) { return std::isfinite(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::isfinite(x); } #elif defined(ARMA_HAVE_ISFINITE) { return (std::isfinite(x) != 0); } #else { const bool x_is_inf = ( (x == x) && ((x - x) != double(0)) ); const bool x_is_nan = (x != x); return ( (x_is_inf == false) && (x_is_nan == false) ); } #endif } template arma_inline bool arma_isfinite(const std::complex& x) { if( (arma_isfinite(x.real()) == false) || (arma_isfinite(x.imag()) == false) ) { return false; } else { return true; } } // // wrappers for trigonometric functions // // wherever possible, try to use C++11 or TR1 versions of the following functions: // // complex acos // complex asin // complex atan // // real acosh // real asinh // real atanh // // complex acosh // complex asinh // complex atanh // // // if C++11 or TR1 are not available, we have rudimentary versions of: // // real acosh // real asinh // real atanh template arma_inline std::complex arma_acos(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::acos(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::acos(x); } #else { arma_stop("acos(): need C++11 compiler"); return std::complex(0); } #endif } template arma_inline std::complex arma_asin(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::asin(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::asin(x); } #else { arma_stop("asin(): need C++11 compiler"); return std::complex(0); } #endif } template arma_inline std::complex arma_atan(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::atan(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::atan(x); } #else { arma_stop("atan(): need C++11 compiler"); return std::complex(0); } #endif } template arma_inline eT arma_acosh(const eT x) { #if defined(ARMA_USE_CXX11) { return std::acosh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::acosh(x); } #else { if(x >= eT(1)) { // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/02/ return std::log( x + std::sqrt(x*x - eT(1)) ); } else { if(std::numeric_limits::has_quiet_NaN == true) { return -(std::numeric_limits::quiet_NaN()); } else { return eT(0); } } } #endif } template arma_inline eT arma_asinh(const eT x) { #if defined(ARMA_USE_CXX11) { return std::asinh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::asinh(x); } #else { // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/02/ return std::log( x + std::sqrt(x*x + eT(1)) ); } #endif } template arma_inline eT arma_atanh(const eT x) { #if defined(ARMA_USE_CXX11) { return std::atanh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::atanh(x); } #else { if( (x >= eT(-1)) && (x <= eT(+1)) ) { // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/02/ return std::log( ( eT(1)+x ) / ( eT(1)-x ) ) / eT(2); } else { if(std::numeric_limits::has_quiet_NaN == true) { return -(std::numeric_limits::quiet_NaN()); } else { return eT(0); } } } #endif } template arma_inline std::complex arma_acosh(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::acosh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::acosh(x); } #else { arma_stop("acosh(): need C++11 compiler"); return std::complex(0); } #endif } template arma_inline std::complex arma_asinh(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::asinh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::asinh(x); } #else { arma_stop("asinh(): need C++11 compiler"); return std::complex(0); } #endif } template arma_inline std::complex arma_atanh(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::atanh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::atanh(x); } #else { arma_stop("atanh(): need C++11 compiler"); return std::complex(0); } #endif } //! @} RcppArmadillo/inst/include/armadillo_bits/BaseCube_bones.hpp0000644000176000001440000000150012176655102023771 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup BaseCube //! @{ //! Analog of the Base class, intended for cubes template struct BaseCube { arma_inline const derived& get_ref() const; inline void print(const std::string extra_text = "") const; inline void print(std::ostream& user_stream, const std::string extra_text = "") const; inline void raw_print(const std::string extra_text = "") const; inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/eglue_core_bones.hpp0000644000176000001440000000502012176655102024432 0ustar ripleyusers// Copyright (C) 2010-2012 Conrad Sanderson // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup eglue_core //! @{ template struct eglue_core { // matrices template arma_hot inline static void apply(Mat& out, const eGlue& x); template arma_hot inline static void apply_inplace_plus (Mat& out, const eGlue& x); template arma_hot inline static void apply_inplace_minus(Mat& out, const eGlue& x); template arma_hot inline static void apply_inplace_schur(Mat& out, const eGlue& x); template arma_hot inline static void apply_inplace_div (Mat& out, const eGlue& x); // cubes template arma_hot inline static void apply(Cube& out, const eGlueCube& x); template arma_hot inline static void apply_inplace_plus (Cube& out, const eGlueCube& x); template arma_hot inline static void apply_inplace_minus(Cube& out, const eGlueCube& x); template arma_hot inline static void apply_inplace_schur(Cube& out, const eGlueCube& x); template arma_hot inline static void apply_inplace_div (Cube& out, const eGlueCube& x); }; class eglue_plus : public eglue_core { public: inline static const char* text() { return "addition"; } }; class eglue_minus : public eglue_core { public: inline static const char* text() { return "subtraction"; } }; class eglue_div : public eglue_core { public: inline static const char* text() { return "element-wise division"; } }; class eglue_schur : public eglue_core { public: inline static const char* text() { return "element-wise multiplication"; } }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_cross.hpp0000644000176000001440000000122612200375542022746 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_cross //! @{ //! cross product (only valid for 3 dimensional vectors) template inline const Glue cross(const Base& X, const Base& Y) { arma_extra_debug_sigprint(); return Glue(X.get_ref(), Y.get_ref()); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_repmat_bones.hpp0000644000176000001440000000103612200631217024277 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_repmat //! @{ class op_repmat { public: template inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/spop_max_bones.hpp0000644000176000001440000000224712111344723024150 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_max //! @{ class spop_max { public: template inline static void apply(SpMat& out, const SpOp& in); template inline static void apply_noalias(SpMat& out, const SpProxy& p, const uword dim, const typename arma_not_cx::result* junk = 0); template inline static void apply_noalias(SpMat& out, const SpProxy& p, const uword dim, const typename arma_cx_only::result* junk = 0); template inline static typename T1::elem_type vector_max(const T1& X, const typename arma_not_cx::result* junk = 0); template inline static typename T1::elem_type vector_max(const T1& X, const typename arma_cx_only::result* junk = 0); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_all.hpp0000644000176000001440000000350512200732042022357 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_all //! @{ template arma_inline const mtOp all ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return mtOp(X, dim, 0); } template inline arma_warn_unused bool all ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return op_all::all_vec(X); } template inline arma_warn_unused bool all ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_all::all_vec(X); } template inline arma_warn_unused bool all(const mtOp& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("all(): two consecutive calls to all() detected"); return op_all::all_vec(in.m); } template arma_inline const Op< mtOp, op_all> all(const mtOp& in, const uword dim) { arma_extra_debug_sigprint(); return mtOp, op_all>(in, dim, 0); } //! @} RcppArmadillo/inst/include/armadillo_bits/SpRow_bones.hpp0000644000176000001440000000604612111344723023375 0ustar ripleyusers// Copyright (C) 2011-2012 Ryan Curtin // Copyright (C) 2011 Matthew Amidon // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpRow //! @{ //! Class for sparse row vectors (sparse matrices with only one row) template class SpRow : public SpMat { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = true; static const bool is_col = false; inline SpRow(); inline explicit SpRow(const uword N); inline SpRow(const uword in_rows, const uword in_cols); inline SpRow(const char* text); inline const SpRow& operator=(const char* text); inline SpRow(const std::string& text); inline const SpRow& operator=(const std::string& text); inline const SpRow& operator=(const eT val); template inline SpRow(const Base& X); template inline const SpRow& operator=(const Base& X); template inline SpRow(const SpBase& X); template inline const SpRow& operator=(const SpBase& X); template inline explicit SpRow(const SpBase& A, const SpBase& B); inline SpValProxy > col(const uword col_num); inline eT col(const uword col_num) const; // arma_inline subview_row cols(const uword in_col1, const uword in_col2); // arma_inline const subview_row cols(const uword in_col1, const uword in_col2) const; // arma_inline subview_row subvec(const uword in_col1, const uword in_col2); // arma_inline const subview_row subvec(const uword in_col1, const uword in_col2) const; // arma_inline subview_row subvec(const span& col_span); // arma_inline const subview_row subvec(const span& col_span) const; // arma_inline subview_row operator()(const span& col_span); // arma_inline const subview_row operator()(const span& col_span) const; inline void shed_col (const uword col_num); inline void shed_cols(const uword in_col1, const uword in_col2); // inline void insert_cols(const uword col_num, const uword N, const bool set_to_zero = true); // template inline void insert_cols(const uword col_num, const Base& X); typedef typename SpMat::iterator row_iterator; typedef typename SpMat::const_iterator const_row_iterator; inline row_iterator begin_row(const uword row_num = 0); inline const_row_iterator begin_row(const uword row_num = 0) const; inline row_iterator end_row(const uword row_num = 0); inline const_row_iterator end_row(const uword row_num = 0) const; #ifdef ARMA_EXTRA_SPROW_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPROW_PROTO) #endif }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_cond.hpp0000644000176000001440000000157212255754610022553 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_cond //! @{ template arma_warn_unused inline typename enable_if2::value, typename T1::pod_type>::result cond(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; Col S; const bool status = auxlib::svd_dc(S, X); if(status == false) { arma_bad("cond(): failed to converge", false); return T(0); } if(S.n_elem > 0) { return T( max(S) / min(S) ); } else { return T(0); } } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_syl_lyap.hpp0000644000176000001440000000413012200375542023446 0ustar ripleyusers// Copyright (C) 2011-2012 Conrad Sanderson // Copyright (C) 2011-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_syl_lyap //! @{ //! find the solution of the Sylvester equation AX + XB = C template inline bool syl ( Mat & out, const Base& in_A, const Base& in_B, const Base& in_C, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap_check tmp_A(in_A.get_ref(), out); const unwrap_check tmp_B(in_B.get_ref(), out); const unwrap_check tmp_C(in_C.get_ref(), out); const Mat& A = tmp_A.M; const Mat& B = tmp_B.M; const Mat& C = tmp_C.M; const bool status = auxlib::syl(out, A, B, C); if(status == false) { out.reset(); arma_bad("syl(): equation appears to be singular", false); } return status; } template inline Mat syl ( const Base& in_A, const Base& in_B, const Base& in_C, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap tmp_A( in_A.get_ref() ); const unwrap tmp_B( in_B.get_ref() ); const unwrap tmp_C( in_C.get_ref() ); const Mat& A = tmp_A.M; const Mat& B = tmp_B.M; const Mat& C = tmp_C.M; Mat out; const bool status = auxlib::syl(out, A, B, C); if(status == false) { out.reset(); arma_bad("syl(): equation appears to be singular"); } return out; } //! @} RcppArmadillo/inst/include/armadillo_bits/podarray_bones.hpp0000644000176000001440000000362512177612753024161 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup podarray //! @{ struct podarray_prealloc_n_elem { static const uword val = 16; }; //! A lightweight array for POD types. For internal use only! template class podarray { public: arma_aligned const uword n_elem; //!< number of elements held arma_aligned eT* mem; //!< pointer to memory used by the object protected: //! internal memory, to avoid calling the 'new' operator for small amounts of memory. arma_align_mem eT mem_local[ podarray_prealloc_n_elem::val ]; public: inline ~podarray(); inline podarray(); inline podarray (const podarray& x); inline const podarray& operator=(const podarray& x); arma_inline explicit podarray(const uword new_N); arma_inline explicit podarray(const eT* X, const uword new_N); template inline explicit podarray(const Proxy& P); arma_inline eT& operator[] (const uword i); arma_inline eT operator[] (const uword i) const; arma_inline eT& operator() (const uword i); arma_inline eT operator() (const uword i) const; inline void set_min_size(const uword min_n_elem); inline void set_size(const uword new_n_elem); inline void reset(); inline void fill(const eT val); inline void zeros(); inline void zeros(const uword new_n_elem); arma_inline eT* memptr(); arma_inline const eT* memptr() const; arma_hot inline void copy_row(const Mat& A, const uword row); protected: inline void init_cold(const uword new_n_elem); inline void init_warm(const uword new_n_elem); }; //! @} RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp0000644000176000001440000007306512265111302022660 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Col //! @{ //! construct an empty column vector template inline Col::Col() : Mat(arma_vec_indicator(), 1) { arma_extra_debug_sigprint(); } template inline Col::Col(const Col& X) : Mat(arma_vec_indicator(), X.n_elem, 1, 1) { arma_extra_debug_sigprint(); arrayops::copy((*this).memptr(), X.memptr(), X.n_elem); } //! construct a column vector with the specified number of n_elem template inline Col::Col(const uword in_n_elem) : Mat(arma_vec_indicator(), in_n_elem, 1, 1) { arma_extra_debug_sigprint(); } template inline Col::Col(const uword in_n_rows, const uword in_n_cols) : Mat(arma_vec_indicator(), 0, 0, 1) { arma_extra_debug_sigprint(); Mat::init_warm(in_n_rows, in_n_cols); } template template inline Col::Col(const uword in_n_elem, const fill::fill_class& f) : Mat(arma_vec_indicator(), in_n_elem, 1, 1) { arma_extra_debug_sigprint(); (*this).fill(f); } template template inline Col::Col(const uword in_n_rows, const uword in_n_cols, const fill::fill_class& f) : Mat(arma_vec_indicator(), 0, 0, 1) { arma_extra_debug_sigprint(); Mat::init_warm(in_n_rows, in_n_cols); (*this).fill(f); } //! construct a column vector from specified text template inline Col::Col(const char* text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; } //! construct a column vector from specified text template inline const Col& Col::operator=(const char* text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; return *this; } //! construct a column vector from specified text template inline Col::Col(const std::string& text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; } //! construct a column vector from specified text template inline const Col& Col::operator=(const std::string& text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; return *this; } //! create a column vector from std::vector template inline Col::Col(const std::vector& x) : Mat(arma_vec_indicator(), uword(x.size()), 1, 1) { arma_extra_debug_sigprint_this(this); if(x.size() > 0) { arrayops::copy( Mat::memptr(), &(x[0]), uword(x.size()) ); } } //! create a column vector from std::vector template inline const Col& Col::operator=(const std::vector& x) { arma_extra_debug_sigprint(); Mat::init_warm(uword(x.size()), 1); if(x.size() > 0) { arrayops::copy( Mat::memptr(), &(x[0]), uword(x.size()) ); } return *this; } #if defined(ARMA_USE_CXX11) template inline Col::Col(const std::initializer_list& list) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(list); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; } template inline const Col& Col::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(list); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; return *this; } template inline Col::Col(Col&& X) : Mat(arma_vec_indicator(), 1) { arma_extra_debug_sigprint(arma_boost::format("this = %x X = %x") % this % &X); access::rw(Mat::n_rows) = X.n_rows; access::rw(Mat::n_cols) = 1; access::rw(Mat::n_elem) = X.n_elem; if( ((X.mem_state == 0) && (X.n_elem > arma_config::mat_prealloc)) || (X.mem_state == 1) || (X.mem_state == 2) ) { access::rw(Mat::mem_state) = X.mem_state; access::rw(Mat::mem) = X.mem; access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 1; access::rw(X.n_elem) = 0; access::rw(X.mem_state) = 0; access::rw(X.mem) = 0; } else { (*this).init_cold(); arrayops::copy( (*this).memptr(), X.mem, X.n_elem ); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) ) { access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 1; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } } } template inline const Col& Col::operator=(Col&& X) { arma_extra_debug_sigprint(arma_boost::format("this = %x X = %x") % this % &X); (*this).steal_mem(X); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) && (this != &X) ) { access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 1; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } return *this; } #endif template inline Col::Col(const SpCol& X) : Mat(arma_vec_indicator(), X.n_elem, 1, 1) { arma_extra_debug_sigprint_this(this); arrayops::inplace_set(Mat::memptr(), eT(0), X.n_elem); for(typename SpCol::const_iterator it = X.begin(); it != X.end(); ++it) { at(it.row()) = (*it); } } template inline const Col& Col::operator=(const eT val) { arma_extra_debug_sigprint(); Mat::operator=(val); return *this; } template inline const Col& Col::operator=(const Col& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template template inline Col::Col(const Base& X) : Mat(arma_vec_indicator(), 1) { arma_extra_debug_sigprint(); Mat::operator=(X.get_ref()); } template template inline const Col& Col::operator=(const Base& X) { arma_extra_debug_sigprint(); Mat::operator=(X.get_ref()); return *this; } //! construct a column vector from a given auxiliary array of eTs template inline Col::Col(eT* aux_mem, const uword aux_length, const bool copy_aux_mem, const bool strict) : Mat(aux_mem, aux_length, 1, copy_aux_mem, strict) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 1; } //! construct a column vector from a given auxiliary array of eTs template inline Col::Col(const eT* aux_mem, const uword aux_length) : Mat(aux_mem, aux_length, 1) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 1; } template template inline Col::Col ( const Base::pod_type, T1>& A, const Base::pod_type, T2>& B ) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 1; Mat::init(A,B); } template template inline Col::Col(const BaseCube& X) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 1; Mat::operator=(X); } template template inline const Col& Col::operator=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template inline Col::Col(const subview_cube& X) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 1; Mat::operator=(X); } template inline const Col& Col::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template inline mat_injector< Col > Col::operator<<(const eT val) { return mat_injector< Col >(*this, val); } template arma_inline const Op,op_htrans> Col::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> Col::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> Col::st() const { return Op,op_strans>(*this); } template arma_inline subview_col Col::row(const uword in_row1) { arma_extra_debug_sigprint(); arma_debug_check( (in_row1 >= Mat::n_rows), "Col::row(): indices out of bounds or incorrectly used"); return subview_col(*this, 0, in_row1, 1); } template arma_inline const subview_col Col::row(const uword in_row1) const { arma_extra_debug_sigprint(); arma_debug_check( (in_row1 >= Mat::n_rows), "Col::row(): indices out of bounds or incorrectly used"); return subview_col(*this, 0, in_row1, 1); } template arma_inline subview_col Col::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat::n_rows) ), "Col::rows(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline const subview_col Col::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat::n_rows) ), "Col::rows(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline subview_col Col::subvec(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat::n_rows) ), "Col::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline const subview_col Col::subvec(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat::n_rows) ), "Col::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline subview_col Col::rows(const span& row_span) { arma_extra_debug_sigprint(); return subvec(row_span); } template arma_inline const subview_col Col::rows(const span& row_span) const { arma_extra_debug_sigprint(); return subvec(row_span); } template arma_inline subview_col Col::subvec(const span& row_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = Mat::n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subvec_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ), "Col::subvec(): indices out of bounds or incorrectly used"); return subview_col(*this, 0, in_row1, subvec_n_rows); } template arma_inline const subview_col Col::subvec(const span& row_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = Mat::n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subvec_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ), "Col::subvec(): indices out of bounds or incorrectly used"); return subview_col(*this, 0, in_row1, subvec_n_rows); } template arma_inline subview_col Col::operator()(const span& row_span) { arma_extra_debug_sigprint(); return subvec(row_span); } template arma_inline const subview_col Col::operator()(const span& row_span) const { arma_extra_debug_sigprint(); return subvec(row_span); } //! remove specified row template inline void Col::shed_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( row_num >= Mat::n_rows, "Col::shed_row(): index out of bounds"); shed_rows(row_num, row_num); } //! remove specified rows template inline void Col::shed_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= Mat::n_rows), "Col::shed_rows(): indices out of bounds or incorrectly used" ); const uword n_keep_front = in_row1; const uword n_keep_back = Mat::n_rows - (in_row2 + 1); Col X(n_keep_front + n_keep_back); eT* X_mem = X.memptr(); const eT* t_mem = (*this).memptr(); if(n_keep_front > 0) { arrayops::copy( X_mem, t_mem, n_keep_front ); } if(n_keep_back > 0) { arrayops::copy( &(X_mem[n_keep_front]), &(t_mem[in_row2+1]), n_keep_back); } Mat::steal_mem(X); } //! insert N rows at the specified row position, //! optionally setting the elements of the inserted rows to zero template inline void Col::insert_rows(const uword row_num, const uword N, const bool set_to_zero) { arma_extra_debug_sigprint(); const uword t_n_rows = Mat::n_rows; const uword A_n_rows = row_num; const uword B_n_rows = t_n_rows - row_num; // insertion at row_num == n_rows is in effect an append operation arma_debug_check( (row_num > t_n_rows), "Col::insert_rows(): index out of bounds"); if(N > 0) { Col out(t_n_rows + N); eT* out_mem = out.memptr(); const eT* t_mem = (*this).memptr(); if(A_n_rows > 0) { arrayops::copy( out_mem, t_mem, A_n_rows ); } if(B_n_rows > 0) { arrayops::copy( &(out_mem[row_num + N]), &(t_mem[row_num]), B_n_rows ); } if(set_to_zero == true) { arrayops::inplace_set( &(out_mem[row_num]), eT(0), N ); } Mat::steal_mem(out); } } //! insert the given object at the specified row position; //! the given object must have one column template template inline void Col::insert_rows(const uword row_num, const Base& X) { arma_extra_debug_sigprint(); Mat::insert_rows(row_num, X); } template arma_inline arma_warn_unused eT& Col::at(const uword i) { return access::rw(Mat::mem[i]); } template arma_inline arma_warn_unused const eT& Col::at(const uword i) const { return Mat::mem[i]; } template arma_inline arma_warn_unused eT& Col::at(const uword in_row, const uword) { return access::rw( Mat::mem[in_row] ); } template arma_inline arma_warn_unused const eT& Col::at(const uword in_row, const uword) const { return Mat::mem[in_row]; } template inline typename Col::row_iterator Col::begin_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "begin_row(): index out of bounds"); return Mat::memptr() + row_num; } template inline typename Col::const_row_iterator Col::begin_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "begin_row(): index out of bounds"); return Mat::memptr() + row_num; } template inline typename Col::row_iterator Col::end_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "end_row(): index out of bounds"); return Mat::memptr() + row_num + 1; } template inline typename Col::const_row_iterator Col::end_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "end_row(): index out of bounds"); return Mat::memptr() + row_num + 1; } template template arma_inline void Col::fixed::change_to_row() { arma_extra_debug_sigprint(); access::rw(Mat::n_cols) = fixed_n_elem; access::rw(Mat::n_rows) = 1; } template template arma_inline Col::fixed::fixed() : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); } template template arma_inline Col::fixed::fixed(const fixed& X) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); } template template inline Col::fixed::fixed(const subview_cube& X) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Col::operator=(X); } template template template inline Col::fixed::fixed(const fill::fill_class&) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).eye(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); } template template template inline Col::fixed::fixed(const Base& A) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Col::operator=(A.get_ref()); } template template template inline Col::fixed::fixed(const Base& A, const Base& B) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Col::init(A,B); } template template inline Col::fixed::fixed(const eT* aux_mem) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; arrayops::copy( dest, aux_mem, fixed_n_elem ); } //! NOTE: this function relies on //! Col::operator=(text), to change vec_state as well as swapping n_rows and n_cols, //! and Mat::init(), to check that the given vector will not have a different size than fixed_n_elem. template template inline Col::fixed::fixed(const char* text) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); change_to_row(); Col::operator=(text); } //! NOTE: this function relies on //! Col::operator=(text), to change vec_state as well as swapping n_rows and n_cols, //! and Mat::init(), to check that the given vector will not have a different size than fixed_n_elem. template template inline Col::fixed::fixed(const std::string& text) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); change_to_row(); Col::operator=(text); } template template template const Col& Col::fixed::operator=(const Base& A) { arma_extra_debug_sigprint(); Col::operator=(A.get_ref()); return *this; } template template const Col& Col::fixed::operator=(const eT val) { arma_extra_debug_sigprint(); Col::operator=(val); return *this; } template template const Col& Col::fixed::operator=(const char* text) { arma_extra_debug_sigprint(); change_to_row(); Col::operator=(text); return *this; } template template const Col& Col::fixed::operator=(const std::string& text) { arma_extra_debug_sigprint(); change_to_row(); Col::operator=(text); return *this; } template template const Col& Col::fixed::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); Col::operator=(X); return *this; } #if defined(ARMA_USE_CXX11) template template inline Col::fixed::fixed(const std::initializer_list& list) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); (*this).operator=(list); } template template inline const Col& Col::fixed::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); const uword N = list.size(); arma_debug_check( (N > fixed_n_elem), "Col::fixed: initialiser list is too long" ); eT* this_mem = (*this).memptr(); arrayops::copy( this_mem, list.begin(), N ); for(uword iq=N; iq < fixed_n_elem; ++iq) { this_mem[iq] = eT(0); } return *this; } #endif template template arma_inline const Col& Col::fixed::operator=(const fixed& X) { arma_extra_debug_sigprint(); eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); return *this; } template template arma_inline const Op< typename Col::template fixed::Col_fixed_type, op_htrans > Col::fixed::t() const { return Op< typename Col::template fixed::Col_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Col::template fixed::Col_fixed_type, op_htrans > Col::fixed::ht() const { return Op< typename Col::template fixed::Col_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Col::template fixed::Col_fixed_type, op_strans > Col::fixed::st() const { return Op< typename Col::template fixed::Col_fixed_type, op_strans >(*this); } template template arma_inline arma_warn_unused const eT& Col::fixed::at_alt(const uword ii) const { #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE) return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; #else const eT* mem_aligned = (use_extra) ? mem_local_extra : Mat::mem_local; memory::mark_as_aligned(mem_aligned); return mem_aligned[ii]; #endif } template template arma_inline arma_warn_unused eT& Col::fixed::operator[] (const uword ii) { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Col::fixed::operator[] (const uword ii) const { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Col::fixed::at(const uword ii) { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Col::fixed::at(const uword ii) const { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Col::fixed::operator() (const uword ii) { arma_debug_check( (ii >= fixed_n_elem), "Col::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Col::fixed::operator() (const uword ii) const { arma_debug_check( (ii >= fixed_n_elem), "Col::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Col::fixed::at(const uword in_row, const uword) { return (use_extra) ? mem_local_extra[in_row] : Mat::mem_local[in_row]; } template template arma_inline arma_warn_unused const eT& Col::fixed::at(const uword in_row, const uword) const { return (use_extra) ? mem_local_extra[in_row] : Mat::mem_local[in_row]; } template template arma_inline arma_warn_unused eT& Col::fixed::operator() (const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= fixed_n_elem) || (in_col > 0)), "Col::operator(): index out of bounds" ); return (use_extra) ? mem_local_extra[in_row] : Mat::mem_local[in_row]; } template template arma_inline arma_warn_unused const eT& Col::fixed::operator() (const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= fixed_n_elem) || (in_col > 0)), "Col::operator(): index out of bounds" ); return (use_extra) ? mem_local_extra[in_row] : Mat::mem_local[in_row]; } template template arma_inline arma_warn_unused eT* Col::fixed::memptr() { return (use_extra) ? mem_local_extra : Mat::mem_local; } template template arma_inline arma_warn_unused const eT* Col::fixed::memptr() const { return (use_extra) ? mem_local_extra : Mat::mem_local; } template template arma_hot inline const Col& Col::fixed::fill(const eT val) { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, val ); return *this; } template template arma_hot inline const Col& Col::fixed::zeros() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(0) ); return *this; } template template arma_hot inline const Col& Col::fixed::ones() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(1) ); return *this; } template inline Col::Col(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem) : Mat(arma_fixed_indicator(), in_n_elem, 1, 1, in_mem) { arma_extra_debug_sigprint_this(this); } #ifdef ARMA_EXTRA_COL_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_COL_MEAT) #endif //! @} RcppArmadillo/inst/include/armadillo_bits/diagview_bones.hpp0000644000176000001440000000612212236716467024135 0ustar ripleyusers// Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // Copyright (C) 2008-2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup diagview //! @{ //! Class for storing data required to extract and set the diagonals of a matrix template class diagview : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; arma_aligned const Mat& m; static const bool is_row = false; static const bool is_col = true; const uword row_offset; const uword col_offset; const uword n_rows; // equal to n_elem const uword n_elem; static const uword n_cols = 1; protected: arma_inline diagview(const Mat& in_m, const uword in_row_offset, const uword in_col_offset, const uword len); public: inline ~diagview(); inline void operator=(const diagview& x); inline void operator+=(const eT val); inline void operator-=(const eT val); inline void operator*=(const eT val); inline void operator/=(const eT val); template inline void operator= (const Base& x); template inline void operator+=(const Base& x); template inline void operator-=(const Base& x); template inline void operator%=(const Base& x); template inline void operator/=(const Base& x); arma_inline eT at_alt (const uword ii) const; arma_inline eT& operator[](const uword ii); arma_inline eT operator[](const uword ii) const; arma_inline eT& at(const uword ii); arma_inline eT at(const uword ii) const; arma_inline eT& operator()(const uword ii); arma_inline eT operator()(const uword ii) const; arma_inline eT& at(const uword in_n_row, const uword); arma_inline eT at(const uword in_n_row, const uword) const; arma_inline eT& operator()(const uword in_n_row, const uword in_n_col); arma_inline eT operator()(const uword in_n_row, const uword in_n_col) const; arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; inline void fill(const eT val); inline void zeros(); inline void ones(); inline void randu(); inline void randn(); inline static void extract(Mat& out, const diagview& in); inline static void plus_inplace(Mat& out, const diagview& in); inline static void minus_inplace(Mat& out, const diagview& in); inline static void schur_inplace(Mat& out, const diagview& in); inline static void div_inplace(Mat& out, const diagview& in); private: friend class Mat; friend class subview; diagview(); //diagview(const diagview&); // making this private causes an error under gcc 4.1/4.2, but not 4.3 }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_sprandn.hpp0000644000176000001440000000341012246034243023257 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_sprandn //! @{ //! Generate a sparse matrix with a randomly selected subset of the elements //! set to random values from a Gaussian distribution with zero mean and unit variance template inline obj_type sprandn ( const uword n_rows, const uword n_cols, const double density, const typename arma_SpMat_SpCol_SpRow_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_SpCol::value == true) { arma_debug_check( (n_cols != 1), "sprandn(): incompatible size" ); } else if(is_SpRow::value == true) { arma_debug_check( (n_rows != 1), "sprandn(): incompatible size" ); } obj_type out; out.sprandn(n_rows, n_cols, density); return out; } inline sp_mat sprandn(const uword n_rows, const uword n_cols, const double density) { arma_extra_debug_sigprint(); sp_mat out; out.sprandn(n_rows, n_cols, density); return out; } //! Generate a sparse matrix with the non-zero values in the same locations as in the given sparse matrix X, //! with the non-zero values set to random values from a Gaussian distribution with zero mean and unit variance template inline SpMat sprandn(const SpBase& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; SpMat out( X.get_ref() ); arma_rng::randn::fill( access::rwp(out.values), out.n_nonzero ); return out; } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_fft.hpp0000644000176000001440000000430112216161240022364 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_fft //! @{ // 1D FFT & 1D IFFT template inline typename enable_if2 < (is_arma_type::value && is_real::value), const mtOp, T1, op_fft_real> >::result fft(const T1& A) { arma_extra_debug_sigprint(); return mtOp, T1, op_fft_real>(A, uword(0), uword(1)); } template inline typename enable_if2 < (is_arma_type::value && is_real::value), const mtOp, T1, op_fft_real> >::result fft(const T1& A, const uword N) { arma_extra_debug_sigprint(); return mtOp, T1, op_fft_real>(A, N, uword(0)); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), const Op >::result fft(const T1& A) { arma_extra_debug_sigprint(); return Op(A, uword(0), uword(1)); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), const Op >::result fft(const T1& A, const uword N) { arma_extra_debug_sigprint(); return Op(A, N, uword(0)); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), const Op >::result ifft(const T1& A) { arma_extra_debug_sigprint(); return Op(A, uword(0), uword(1)); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), const Op >::result ifft(const T1& A, const uword N) { arma_extra_debug_sigprint(); return Op(A, N, uword(0)); } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_join_meat.hpp0000644000176000001440000000720512220540177024116 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_join //! @{ template inline void glue_join::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword join_type = X.aux_uword; const unwrap A_tmp(X.A); const unwrap B_tmp(X.B); const Mat& A = A_tmp.M; const Mat& B = B_tmp.M; if( (&out != &A) && (&out != &B) ) { glue_join::apply_noalias(out, A, B, join_type); } else { Mat tmp; glue_join::apply_noalias(tmp, A, B, join_type); out.steal_mem(tmp); } } template inline void glue_join::apply_noalias(Mat& out, const Mat& A, const Mat& B, const uword join_type) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if(join_type == 0) { arma_debug_check ( ( (A_n_cols != B_n_cols) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ), "join_cols() / join_vert(): number of columns must be the same" ); } else { arma_debug_check ( ( (A_n_rows != B.n_rows) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ), "join_rows() / join_horiz(): number of rows must be the same" ); } if(join_type == 0) // join columns (i.e. result matrix has more rows) { out.set_size( A_n_rows + B_n_rows, (std::max)(A_n_cols, B_n_cols) ); if( out.n_elem > 0 ) { if(A.is_empty() == false) { out.submat(0, 0, A_n_rows-1, out.n_cols-1) = A; } if(B.is_empty() == false) { out.submat(A_n_rows, 0, out.n_rows-1, out.n_cols-1) = B; } } } else // join rows (i.e. result matrix has more columns) { out.set_size( (std::max)(A_n_rows, B_n_rows), A_n_cols + B_n_cols ); if( out.n_elem > 0 ) { if(A.is_empty() == false) { out.submat(0, 0, out.n_rows-1, A.n_cols-1) = A; } if(B.is_empty() == false) { out.submat(0, A_n_cols, out.n_rows-1, out.n_cols-1) = B; } } } } template inline void glue_join::apply(Cube& out, const GlueCube& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube A_tmp(X.A); const unwrap_cube B_tmp(X.B); const Cube& A = A_tmp.M; const Cube& B = B_tmp.M; if(A.n_elem == 0) { out = B; return; } if(B.n_elem == 0) { out = A; return; } arma_debug_check( ( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) ), "join_slices(): size of slices must be the same" ); if( (&out != &A) && (&out != &B) ) { out.set_size(A.n_rows, A.n_cols, A.n_slices + B.n_slices); out.slices(0, A.n_slices-1 ) = A; out.slices(A.n_slices, out.n_slices-1) = B; } else // we have aliasing { Cube C(A.n_rows, A.n_cols, A.n_slices + B.n_slices); C.slices(0, A.n_slices-1) = A; C.slices(A.n_slices, C.n_slices-1) = B; out.steal_mem(C); } } //! @} RcppArmadillo/inst/include/armadillo_bits/diskio_bones.hpp0000644000176000001440000002634512151257357023623 0ustar ripleyusers// Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2009-2010 Ian Cullinan // Copyright (C) 2012 Ryan Curtin // Copyright (C) 2013 Szabolcs Horvat // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup diskio //! @{ //! class for saving and loading matrices and fields class diskio { public: template inline static std::string gen_txt_header(const Mat& x); template inline static std::string gen_bin_header(const Mat& x); template inline static std::string gen_bin_header(const SpMat& x); template inline static std::string gen_txt_header(const Cube& x); template inline static std::string gen_bin_header(const Cube& x); inline static file_type guess_file_type(std::istream& f); inline static char conv_to_hex_char(const u8 x); inline static void conv_to_hex(char* out, const u8 x); inline static std::string gen_tmp_name(const std::string& x); inline static bool safe_rename(const std::string& old_name, const std::string& new_name); template inline static bool convert_naninf(eT& val, const std::string& token); template inline static bool convert_naninf(std::complex& val, const std::string& token); // // matrix saving template inline static bool save_raw_ascii (const Mat& x, const std::string& final_name); template inline static bool save_raw_binary (const Mat& x, const std::string& final_name); template inline static bool save_arma_ascii (const Mat& x, const std::string& final_name); template inline static bool save_csv_ascii (const Mat& x, const std::string& final_name); template inline static bool save_arma_binary(const Mat& x, const std::string& final_name); template inline static bool save_pgm_binary (const Mat& x, const std::string& final_name); template inline static bool save_pgm_binary (const Mat< std::complex >& x, const std::string& final_name); template inline static bool save_hdf5_binary(const Mat& x, const std::string& final_name); template inline static bool save_raw_ascii (const Mat& x, std::ostream& f); template inline static bool save_raw_binary (const Mat& x, std::ostream& f); template inline static bool save_arma_ascii (const Mat& x, std::ostream& f); template inline static bool save_csv_ascii (const Mat& x, std::ostream& f); template inline static bool save_arma_binary(const Mat& x, std::ostream& f); template inline static bool save_pgm_binary (const Mat& x, std::ostream& f); template inline static bool save_pgm_binary (const Mat< std::complex >& x, std::ostream& f); // // matrix loading template inline static bool load_raw_ascii (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_binary (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_ascii (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_csv_ascii (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_pgm_binary (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_pgm_binary (Mat< std::complex >& x, const std::string& name, std::string& err_msg); template inline static bool load_hdf5_binary(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_auto_detect(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_ascii (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_raw_binary (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_ascii (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_csv_ascii (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_pgm_binary (Mat& x, std::istream& is, std::string& err_msg); template inline static bool load_pgm_binary (Mat< std::complex >& x, std::istream& is, std::string& err_msg); template inline static bool load_auto_detect(Mat& x, std::istream& f, std::string& err_msg); inline static void pnm_skip_comments(std::istream& f); // // sparse matrix saving template inline static bool save_coord_ascii(const SpMat& x, const std::string& final_name); template inline static bool save_arma_binary(const SpMat& x, const std::string& final_name); template inline static bool save_coord_ascii(const SpMat& x, std::ostream& f); template inline static bool save_coord_ascii(const SpMat< std::complex >& x, std::ostream& f); template inline static bool save_arma_binary(const SpMat& x, std::ostream& f); // // sparse matrix loading template inline static bool load_coord_ascii(SpMat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(SpMat& x, const std::string& name, std::string& err_msg); template inline static bool load_coord_ascii(SpMat& x, std::istream& f, std::string& err_msg); template inline static bool load_coord_ascii(SpMat< std::complex >& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(SpMat& x, std::istream& f, std::string& err_msg); // // cube saving template inline static bool save_raw_ascii (const Cube& x, const std::string& name); template inline static bool save_raw_binary (const Cube& x, const std::string& name); template inline static bool save_arma_ascii (const Cube& x, const std::string& name); template inline static bool save_arma_binary(const Cube& x, const std::string& name); template inline static bool save_hdf5_binary(const Cube& x, const std::string& name); template inline static bool save_raw_ascii (const Cube& x, std::ostream& f); template inline static bool save_raw_binary (const Cube& x, std::ostream& f); template inline static bool save_arma_ascii (const Cube& x, std::ostream& f); template inline static bool save_arma_binary(const Cube& x, std::ostream& f); // // cube loading template inline static bool load_raw_ascii (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_binary (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_ascii (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_hdf5_binary(Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_auto_detect(Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_ascii (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_raw_binary (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_ascii (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_auto_detect(Cube& x, std::istream& f, std::string& err_msg); // // field saving and loading template inline static bool save_arma_binary(const field& x, const std::string& name); template inline static bool save_arma_binary(const field& x, std::ostream& f); template inline static bool load_arma_binary( field& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary( field& x, std::istream& f, std::string& err_msg); template inline static bool load_auto_detect( field& x, const std::string& name, std::string& err_msg); template inline static bool load_auto_detect( field& x, std::istream& f, std::string& err_msg); inline static bool save_std_string(const field& x, const std::string& name); inline static bool save_std_string(const field& x, std::ostream& f); inline static bool load_std_string( field& x, const std::string& name, std::string& err_msg); inline static bool load_std_string( field& x, std::istream& f, std::string& err_msg); // // handling of PPM images by cubes template inline static bool save_ppm_binary(const Cube& x, const std::string& final_name); template inline static bool save_ppm_binary(const Cube& x, std::ostream& f); template inline static bool load_ppm_binary( Cube& x, const std::string& final_name, std::string& err_msg); template inline static bool load_ppm_binary( Cube& x, std::istream& f, std::string& err_msg); // // handling of PPM images by fields template inline static bool save_ppm_binary(const field& x, const std::string& final_name); template inline static bool save_ppm_binary(const field& x, std::ostream& f); template inline static bool load_ppm_binary( field& x, const std::string& final_name, std::string& err_msg); template inline static bool load_ppm_binary( field& x, std::istream& f, std::string& err_msg); }; //! @} RcppArmadillo/inst/include/armadillo_bits/GenCube_bones.hpp0000644000176000001440000000321712176400754023640 0ustar ripleyusers// Copyright (C) 2011-2013 Conrad Sanderson // Copyright (C) 2011-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup GenCube //! @{ //! support class for generator functions (eg. zeros, randu, randn, ...) template class GenCube : public BaseCube > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool prefer_at_accessor = false; static const bool is_simple = (is_same_type::value) || (is_same_type::value); arma_aligned const uword n_rows; arma_aligned const uword n_cols; arma_aligned const uword n_slices; arma_inline GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices); arma_inline ~GenCube(); arma_inline static eT generate(); arma_inline eT operator[] (const uword i) const; arma_inline eT at (const uword row, const uword col, const uword slice) const; arma_inline eT at_alt (const uword i) const; inline void apply (Cube& out) const; inline void apply_inplace_plus (Cube& out) const; inline void apply_inplace_minus(Cube& out) const; inline void apply_inplace_schur(Cube& out) const; inline void apply_inplace_div (Cube& out) const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_cov_meat.hpp0000644000176000001440000000420012200631217023412 0ustar ripleyusers// Copyright (C) 2009-2011 Conrad Sanderson // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_cov //! @{ template inline void op_cov::direct_cov(Mat& out, const Mat& A, const uword norm_type) { arma_extra_debug_sigprint(); if(A.is_vec()) { if(A.n_rows == 1) { out = var(trans(A), norm_type); } else { out = var(A, norm_type); } } else { const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); const Row acc = sum(A); out = trans(A) * A; out -= (trans(acc) * acc)/eT(N); out /= norm_val; } } template inline void op_cov::direct_cov(Mat< std::complex >& out, const Mat< std::complex >& A, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(A.is_vec()) { if(A.n_rows == 1) { const Mat tmp_mat = var(trans(A), norm_type); out.set_size(1,1); out[0] = tmp_mat[0]; } else { const Mat tmp_mat = var(A, norm_type); out.set_size(1,1); out[0] = tmp_mat[0]; } } else { const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); const Row acc = sum(A); out = trans(A) * A; // out = strans(conj(A)) * A; out -= (trans(acc) * acc)/eT(N); // out -= (strans(conj(acc)) * acc)/eT(N); out /= norm_val; } } template inline void op_cov::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& A = tmp.M; const uword norm_type = in.aux_uword_a; op_cov::direct_cov(out, A, norm_type); } //! @} RcppArmadillo/inst/include/armadillo_bits/operator_cube_plus.hpp0000644000176000001440000000633012177612753025042 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_cube_plus //! @{ //! unary plus operation (does nothing, but is required for completeness) template arma_inline const BaseCube& operator+ ( const BaseCube& X ) { arma_extra_debug_sigprint(); return X; } //! BaseCube + scalar template arma_inline const eOpCube operator+ ( const BaseCube& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! scalar + BaseCube template arma_inline const eOpCube operator+ ( const typename T1::elem_type k, const BaseCube& X ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! non-complex BaseCube + complex scalar (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_plus> operator+ ( const BaseCube& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_plus>('j', X.get_ref(), k); } //! complex scalar + non-complex BaseCube (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_plus> operator+ ( const std::complex& k, const BaseCube& X ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_plus>('j', X.get_ref(), k); // NOTE: order is swapped } //! addition of BaseCube objects with same element type template arma_inline const eGlueCube operator+ ( const BaseCube& X, const BaseCube& Y ) { arma_extra_debug_sigprint(); return eGlueCube(X.get_ref(), Y.get_ref()); } //! addition of BaseCube objects with different element types template inline const mtGlueCube::result, T1, T2, glue_mixed_plus> operator+ ( const BaseCube< typename force_different_type::T1_result, T1>& X, const BaseCube< typename force_different_type::T2_result, T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } //! @} RcppArmadillo/inst/include/armadillo_bits/spop_strans_meat.hpp0000644000176000001440000000406412111344723024514 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_strans //! @{ template arma_hot inline void spop_strans::apply_proxy(SpMat& out, const T1& X) { arma_extra_debug_sigprint(); const SpProxy p(X); if(p.is_alias(out) == false) { out.set_size( p.get_n_cols(), p.get_n_rows() ); out.mem_resize(p.get_n_nonzero()); typename SpProxy::const_row_iterator_type it = p.begin_row(); while(it.pos() < p.get_n_nonzero()) { access::rw(out.values[it.pos()]) = (*it); access::rw(out.row_indices[it.pos()]) = it.col(); // transpose ++access::rw(out.col_ptrs[it.row() + 1]); ++it; } // Fix column pointers. const uword out_n_cols = out.n_cols; for(uword c = 1; c <= out_n_cols; ++c) { access::rw(out.col_ptrs[c]) += out.col_ptrs[c - 1]; } } else { SpMat result( p.get_n_cols(), p.get_n_rows() ); result.mem_resize(p.get_n_nonzero()); typename SpProxy::const_row_iterator_type it = p.begin_row(); while(it.pos() < p.get_n_nonzero()) { access::rw(result.values[it.pos()]) = (*it); access::rw(result.row_indices[it.pos()]) = it.col(); // transpose ++access::rw(result.col_ptrs[it.row() + 1]); ++it; } // Fix column pointers. const uword result_n_cols = result.n_cols; for(uword c = 1; c <= result_n_cols; ++c) { access::rw(result.col_ptrs[c]) += result.col_ptrs[c - 1]; } out.steal_mem(result); } } template arma_hot inline void spop_strans::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); spop_strans::apply_proxy(out, in.m); } //! @} RcppArmadillo/inst/include/armadillo_bits/SizeMat_meat.hpp0000644000176000001440000000261412247362764023533 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SizeMat //! @{ inline SizeMat::SizeMat(const uword in_n_rows, const uword in_n_cols) : n_rows(in_n_rows) , n_cols(in_n_cols) { arma_extra_debug_sigprint(); } // inline // SizeMat::operator SizeCube () const // { // return SizeCube(n_rows, n_cols, 1); // } inline bool SizeMat::operator==(const SizeMat& s) const { if(n_rows != s.n_rows) { return false; } if(n_cols != s.n_cols) { return false; } return true; } inline bool SizeMat::operator!=(const SizeMat& s) const { if(n_rows != s.n_rows) { return true; } if(n_cols != s.n_cols) { return true; } return false; } inline bool SizeMat::operator==(const SizeCube& s) const { if(n_rows != s.n_rows ) { return false; } if(n_cols != s.n_cols ) { return false; } if(uword(1) != s.n_slices) { return false; } return true; } inline bool SizeMat::operator!=(const SizeCube& s) const { if(n_rows != s.n_rows ) { return true; } if(n_cols != s.n_cols ) { return true; } if(uword(1) != s.n_slices) { return true; } return false; } //! @} RcppArmadillo/inst/include/armadillo_bits/GenCube_meat.hpp0000644000176000001440000001176412246034243023460 0ustar ripleyusers// Copyright (C) 2011-2013 Conrad Sanderson // Copyright (C) 2011-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Gen //! @{ template arma_inline GenCube::GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) : n_rows (in_n_rows ) , n_cols (in_n_cols ) , n_slices(in_n_slices) { arma_extra_debug_sigprint(); } template arma_inline GenCube::~GenCube() { arma_extra_debug_sigprint(); } template arma_inline eT GenCube::generate() { if(is_same_type::yes) { return eT(1); } else if(is_same_type::yes) { return eT(0); } else if(is_same_type::yes) { return eT(arma_rng::randu()); } else if(is_same_type::yes) { return eT(arma_rng::randn()); } else { return eT(); } } template arma_inline eT GenCube::operator[](const uword) const { return GenCube::generate(); } template arma_inline eT GenCube::at(const uword, const uword, const uword) const { return GenCube::generate(); } template arma_inline eT GenCube::at_alt(const uword) const { return GenCube::generate(); } template inline void GenCube::apply(Cube& out) const { arma_extra_debug_sigprint(); // NOTE: we're assuming that the cube has already been set to the correct size; // this is done by either the Cube contructor or operator=() if(is_same_type::yes) { out.ones(); } else if(is_same_type::yes) { out.zeros(); } else if(is_same_type::yes) { out.randu(); } else if(is_same_type::yes) { out.randn(); } } template inline void GenCube::apply_inplace_plus(Cube& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition"); eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword i,j; for(i=0, j=1; j::generate(); const eT tmp_j = GenCube::generate(); out_mem[i] += tmp_i; out_mem[j] += tmp_j; } if(i < n_elem) { out_mem[i] += GenCube::generate(); } } template inline void GenCube::apply_inplace_minus(Cube& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction"); eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword i,j; for(i=0, j=1; j::generate(); const eT tmp_j = GenCube::generate(); out_mem[i] -= tmp_i; out_mem[j] -= tmp_j; } if(i < n_elem) { out_mem[i] -= GenCube::generate(); } } template inline void GenCube::apply_inplace_schur(Cube& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication"); eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword i,j; for(i=0, j=1; j::generate(); const eT tmp_j = GenCube::generate(); out_mem[i] *= tmp_i; out_mem[j] *= tmp_j; } if(i < n_elem) { out_mem[i] *= GenCube::generate(); } } template inline void GenCube::apply_inplace_div(Cube& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division"); eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword i,j; for(i=0, j=1; j::generate(); const eT tmp_j = GenCube::generate(); out_mem[i] /= tmp_i; out_mem[j] /= tmp_j; } if(i < n_elem) { out_mem[i] /= GenCube::generate(); } } //! @} RcppArmadillo/inst/include/armadillo_bits/eOp_meat.hpp0000644000176000001440000000476312176655102022701 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup eOp //! @{ template eOp::eOp(const T1& in_m) : P(in_m) { arma_extra_debug_sigprint(); } template eOp::eOp(const T1& in_m, const typename T1::elem_type in_aux) : P(in_m) , aux(in_aux) { arma_extra_debug_sigprint(); } template eOp::eOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : P(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template eOp::eOp(const T1& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b) : P(in_m) , aux(in_aux) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template eOp::~eOp() { arma_extra_debug_sigprint(); } template arma_inline uword eOp::get_n_rows() const { return is_row ? 1 : P.get_n_rows(); } template arma_inline uword eOp::get_n_cols() const { return is_col ? 1 : P.get_n_cols(); } template arma_inline uword eOp::get_n_elem() const { return P.get_n_elem(); } template arma_inline typename T1::elem_type eOp::operator[] (const uword ii) const { return eop_core::process(P[ii], aux); } template arma_inline typename T1::elem_type eOp::at(const uword row, const uword col) const { if(is_row) { return eop_core::process(P.at(0, col), aux); } else if(is_col) { return eop_core::process(P.at(row, 0), aux); } else { return eop_core::process(P.at(row, col), aux); } } template arma_inline typename T1::elem_type eOp::at_alt(const uword ii) const { return eop_core::process(P.at_alt(ii), aux); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_unique_bones.hpp0000644000176000001440000000102012200631217024306 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Arnold Wiliem // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_unique //! @{ class op_unique { public: template inline static void apply(Mat& out, const Op& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/operator_cube_minus.hpp0000644000176000001440000000662512177612753025221 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_cube_minus //! @{ //! unary - template arma_inline const eOpCube operator- ( const BaseCube& X ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref()); } //! cancellation of two consecutive negations: -(-T1) template arma_inline const T1& operator- ( const eOpCube& X ) { arma_extra_debug_sigprint(); return X.m; } //! BaseCube - scalar template arma_inline const eOpCube operator- ( const BaseCube& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! scalar - BaseCube template arma_inline const eOpCube operator- ( const typename T1::elem_type k, const BaseCube& X ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! complex scalar - non-complex BaseCube (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_minus_pre> operator- ( const std::complex& k, const BaseCube& X ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_minus_pre>('j', X.get_ref(), k); } //! non-complex BaseCube - complex scalar (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_minus_post> operator- ( const BaseCube& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_minus_post>('j', X.get_ref(), k); } //! subtraction of BaseCube objects with same element type template arma_inline const eGlueCube operator- ( const BaseCube& X, const BaseCube& Y ) { arma_extra_debug_sigprint(); return eGlueCube(X.get_ref(), Y.get_ref()); } //! subtraction of BaseCube objects with different element types template inline const mtGlueCube::result, T1, T2, glue_mixed_minus> operator- ( const BaseCube< typename force_different_type::T1_result, T1>& X, const BaseCube< typename force_different_type::T2_result, T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } //! @} RcppArmadillo/inst/include/armadillo_bits/subview_cube_meat.hpp0000644000176000001440000013250712246034243024631 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup subview_cube //! @{ template inline subview_cube::~subview_cube() { arma_extra_debug_sigprint(); } template arma_inline subview_cube::subview_cube ( const Cube& in_m, const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices ) : m (in_m) , aux_row1 (in_row1) , aux_col1 (in_col1) , aux_slice1 (in_slice1) , n_rows (in_n_rows) , n_cols (in_n_cols) , n_elem_slice(in_n_rows * in_n_cols) , n_slices (in_n_slices) , n_elem (n_elem_slice * in_n_slices) { arma_extra_debug_sigprint(); } template inline void subview_cube::operator= (const eT val) { arma_extra_debug_sigprint(); if(n_elem != 1) { arma_debug_assert_same_size(n_rows, n_cols, n_slices, 1, 1, 1, "copy into subcube"); } Cube& Q = const_cast< Cube& >(m); Q.at(aux_row1, aux_col1, aux_slice1) = val; } template inline void subview_cube::operator+= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::inplace_plus( slice_colptr(slice,col), val, local_n_rows ); } } } template inline void subview_cube::operator-= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::inplace_minus( slice_colptr(slice,col), val, local_n_rows ); } } } template inline void subview_cube::operator*= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::inplace_mul( slice_colptr(slice,col), val, local_n_rows ); } } } template inline void subview_cube::operator/= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::inplace_div( slice_colptr(slice,col), val, local_n_rows ); } } } template template inline void subview_cube::operator= (const BaseCube& in) { arma_extra_debug_sigprint(); const unwrap_cube tmp(in.get_ref()); const Cube& x = tmp.M; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "copy into subcube"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::copy( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template template inline void subview_cube::operator+= (const BaseCube& in) { arma_extra_debug_sigprint(); const unwrap_cube tmp(in.get_ref()); const Cube& x = tmp.M; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "addition"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template template inline void subview_cube::operator-= (const BaseCube& in) { arma_extra_debug_sigprint(); const unwrap_cube tmp(in.get_ref()); const Cube& x = tmp.M; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "subtraction"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template template inline void subview_cube::operator%= (const BaseCube& in) { arma_extra_debug_sigprint(); const unwrap_cube tmp(in.get_ref()); const Cube& x = tmp.M; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "element-wise multiplication"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template template inline void subview_cube::operator/= (const BaseCube& in) { arma_extra_debug_sigprint(); const unwrap_cube tmp(in.get_ref()); const Cube& x = tmp.M; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "element-wise division"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } //! x.subcube(...) = y.subcube(...) template inline void subview_cube::operator= (const subview_cube& x_in) { arma_extra_debug_sigprint(); const bool overlap = check_overlap(x_in); Cube* tmp_cube = overlap ? new Cube(x_in.m) : 0; const subview_cube* tmp_subview_cube = overlap ? new subview_cube(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; const subview_cube& x = overlap ? (*tmp_subview_cube) : x_in; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "copy into subcube"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::copy( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } if(overlap) { delete tmp_subview_cube; delete tmp_cube; } } template inline void subview_cube::operator+= (const subview_cube& x_in) { arma_extra_debug_sigprint(); const bool overlap = check_overlap(x_in); Cube* tmp_cube = overlap ? new Cube(x_in.m) : 0; const subview_cube* tmp_subview_cube = overlap ? new subview_cube(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; const subview_cube& x = overlap ? (*tmp_subview_cube) : x_in; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "addition"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } if(overlap) { delete tmp_subview_cube; delete tmp_cube; } } template inline void subview_cube::operator-= (const subview_cube& x_in) { arma_extra_debug_sigprint(); const bool overlap = check_overlap(x_in); Cube* tmp_cube = overlap ? new Cube(x_in.m) : 0; const subview_cube* tmp_subview_cube = overlap ? new subview_cube(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; const subview_cube& x = overlap ? (*tmp_subview_cube) : x_in; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "subtraction"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } if(overlap) { delete tmp_subview_cube; delete tmp_cube; } } template inline void subview_cube::operator%= (const subview_cube& x_in) { arma_extra_debug_sigprint(); const bool overlap = check_overlap(x_in); Cube* tmp_cube = overlap ? new Cube(x_in.m) : 0; const subview_cube* tmp_subview_cube = overlap ? new subview_cube(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; const subview_cube& x = overlap ? (*tmp_subview_cube) : x_in; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "element-wise multiplication"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } if(overlap) { delete tmp_subview_cube; delete tmp_cube; } } template inline void subview_cube::operator/= (const subview_cube& x_in) { arma_extra_debug_sigprint(); const bool overlap = check_overlap(x_in); Cube* tmp_cube = overlap ? new Cube(x_in.m) : 0; const subview_cube* tmp_subview_cube = overlap ? new subview_cube(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; const subview_cube& x = overlap ? (*tmp_subview_cube) : x_in; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "element-wise division"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } if(overlap) { delete tmp_subview_cube; delete tmp_cube; } } template template inline void subview_cube::operator= (const Base& in) { arma_extra_debug_sigprint(); const unwrap tmp(in.get_ref()); const Mat& x = tmp.M; subview_cube& t = *this; const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) { // interpret the matrix as a cube with one slice for(uword col = 0; col < t_n_cols; ++col) { arrayops::copy( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); } } else if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) { for(uword i=0; i < t_n_slices; ++i) { arrayops::copy( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); } } else if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; for(uword slice=0; slice < t_n_slices; ++slice) { const uword mod_slice = t_aux_slice1 + slice; const eT* x_colptr = x.colptr(slice); uword i,j; for(i=0, j=1; j < t_n_cols; i+=2, j+=2) { const eT tmp_i = x_colptr[i]; const eT tmp_j = x_colptr[j]; Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) = tmp_i; Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) = tmp_j; } if(i < t_n_cols) { Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) = x_colptr[i]; } } } else { if(arma_config::debug == true) { arma_stop( arma_incompat_size_string(t, x, "copy into subcube") ); } } } template template inline void subview_cube::operator+= (const Base& in) { arma_extra_debug_sigprint(); const unwrap tmp(in.get_ref()); const Mat& x = tmp.M; subview_cube& t = *this; const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_plus( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); } } else if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) { for(uword i=0; i < t_n_slices; ++i) { arrayops::inplace_plus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); } } else if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; for(uword slice=0; slice < t_n_slices; ++slice) { const uword mod_slice = t_aux_slice1 + slice; const eT* x_colptr = x.colptr(slice); uword i,j; for(i=0, j=1; j < t_n_cols; i+=2, j+=2) { const eT tmp_i = x_colptr[i]; const eT tmp_j = x_colptr[j]; Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) += tmp_i; Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) += tmp_j; } if(i < t_n_cols) { Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) += x_colptr[i]; } } } else { if(arma_config::debug == true) { arma_stop( arma_incompat_size_string(t, x, "addition") ); } } } template template inline void subview_cube::operator-= (const Base& in) { arma_extra_debug_sigprint(); const unwrap tmp(in.get_ref()); const Mat& x = tmp.M; subview_cube& t = *this; const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_minus( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); } } else if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) { for(uword i=0; i < t_n_slices; ++i) { arrayops::inplace_minus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); } } else if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; for(uword slice=0; slice < t_n_slices; ++slice) { const uword mod_slice = t_aux_slice1 + slice; const eT* x_colptr = x.colptr(slice); uword i,j; for(i=0, j=1; j < t_n_cols; i+=2, j+=2) { const eT tmp_i = x_colptr[i]; const eT tmp_j = x_colptr[j]; Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) -= tmp_i; Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) -= tmp_j; } if(i < t_n_cols) { Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) -= x_colptr[i]; } } } else { if(arma_config::debug == true) { arma_stop( arma_incompat_size_string(t, x, "subtraction") ); } } } template template inline void subview_cube::operator%= (const Base& in) { arma_extra_debug_sigprint(); const unwrap tmp(in.get_ref()); const Mat& x = tmp.M; subview_cube& t = *this; const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_mul( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); } } else if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) { for(uword i=0; i < t_n_slices; ++i) { arrayops::inplace_mul( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); } } else if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; for(uword slice=0; slice < t_n_slices; ++slice) { const uword mod_slice = t_aux_slice1 + slice; const eT* x_colptr = x.colptr(slice); uword i,j; for(i=0, j=1; j < t_n_cols; i+=2, j+=2) { const eT tmp_i = x_colptr[i]; const eT tmp_j = x_colptr[j]; Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) *= tmp_i; Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) *= tmp_j; } if(i < t_n_cols) { Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) *= x_colptr[i]; } } } else { if(arma_config::debug == true) { arma_stop( arma_incompat_size_string(t, x, "element-wise multiplication") ); } } } template template inline void subview_cube::operator/= (const Base& in) { arma_extra_debug_sigprint(); const unwrap tmp(in.get_ref()); const Mat& x = tmp.M; subview_cube& t = *this; const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_div( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); } } else if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) { for(uword i=0; i < t_n_slices; ++i) { arrayops::inplace_div( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); } } else if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; for(uword slice=0; slice < t_n_slices; ++slice) { const uword mod_slice = t_aux_slice1 + slice; const eT* x_colptr = x.colptr(slice); uword i,j; for(i=0, j=1; j < t_n_cols; i+=2, j+=2) { const eT tmp_i = x_colptr[i]; const eT tmp_j = x_colptr[j]; Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) /= tmp_i; Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) /= tmp_j; } if(i < t_n_cols) { Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) /= x_colptr[i]; } } } else { if(arma_config::debug == true) { arma_stop( arma_incompat_size_string(t, x, "element-wise division") ); } } } //! transform each element in the subview using a functor template template inline void subview_cube::transform(functor F) { arma_extra_debug_sigprint(); Cube& Q = const_cast< Cube& >(m); const uword start_col = aux_col1; const uword start_row = aux_row1; const uword start_slice = aux_slice1; const uword end_col_plus1 = start_col + n_cols; const uword end_row_plus1 = start_row + n_rows; const uword end_slice_plus1 = start_slice + n_slices; for(uword uslice = start_slice; uslice < end_slice_plus1; ++uslice) for(uword ucol = start_col; ucol < end_col_plus1; ++ucol ) for(uword urow = start_row; urow < end_row_plus1; ++urow ) { Q.at(urow, ucol, uslice) = eT( F( Q.at(urow, ucol, uslice) ) ); } } //! imbue (fill) the subview with values provided by a functor template template inline void subview_cube::imbue(functor F) { arma_extra_debug_sigprint(); Cube& Q = const_cast< Cube& >(m); const uword start_col = aux_col1; const uword start_row = aux_row1; const uword start_slice = aux_slice1; const uword end_col_plus1 = start_col + n_cols; const uword end_row_plus1 = start_row + n_rows; const uword end_slice_plus1 = start_slice + n_slices; for(uword uslice = start_slice; uslice < end_slice_plus1; ++uslice) for(uword ucol = start_col; ucol < end_col_plus1; ++ucol ) for(uword urow = start_row; urow < end_row_plus1; ++urow ) { Q.at(urow, ucol, uslice) = eT( F() ); } } template inline void subview_cube::fill(const eT val) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::inplace_set( slice_colptr(slice,col), val, local_n_rows ); } } } template inline void subview_cube::zeros() { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::fill_zeros( slice_colptr(slice,col), local_n_rows ); } } } template inline void subview_cube::ones() { arma_extra_debug_sigprint(); fill(eT(1)); } template inline void subview_cube::randu() { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arma_rng::randu::fill( slice_colptr(slice,col), local_n_rows ); } } } template inline void subview_cube::randn() { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arma_rng::randn::fill( slice_colptr(slice,col), local_n_rows ); } } } template inline eT subview_cube::at_alt(const uword i) const { return operator[](i); } template inline eT& subview_cube::operator[](const uword i) { const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; const uword in_col = j / n_rows; const uword in_row = j % n_rows; const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Cube& >(m)).mem[index] ); } template inline eT subview_cube::operator[](const uword i) const { const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; const uword in_col = j / n_rows; const uword in_row = j % n_rows; const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template inline eT& subview_cube::operator()(const uword i) { arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of bounds"); const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; const uword in_col = j / n_rows; const uword in_row = j % n_rows; const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Cube& >(m)).mem[index] ); } template inline eT subview_cube::operator()(const uword i) const { arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of bounds"); const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; const uword in_col = j / n_rows; const uword in_row = j % n_rows; const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template arma_inline eT& subview_cube::operator()(const uword in_row, const uword in_col, const uword in_slice) { arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) ), "subview_cube::operator(): location out of bounds"); const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Cube& >(m)).mem[index] ); } template arma_inline eT subview_cube::operator()(const uword in_row, const uword in_col, const uword in_slice) const { arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) ), "subview_cube::operator(): location out of bounds"); const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template arma_inline eT& subview_cube::at(const uword in_row, const uword in_col, const uword in_slice) { const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Cube& >(m)).mem[index] ); } template arma_inline eT subview_cube::at(const uword in_row, const uword in_col, const uword in_slice) const { const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template arma_inline eT* subview_cube::slice_colptr(const uword in_slice, const uword in_col) { return & access::rw((const_cast< Cube& >(m)).mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 ]); } template arma_inline const eT* subview_cube::slice_colptr(const uword in_slice, const uword in_col) const { return & m.mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 ]; } template inline bool subview_cube::check_overlap(const subview_cube& x) const { const subview_cube& t = *this; if(&t.m != &x.m) { return false; } else { if( (t.n_elem == 0) || (x.n_elem == 0) ) { return false; } else { const uword t_row_start = t.aux_row1; const uword t_row_end_p1 = t_row_start + t.n_rows; const uword t_col_start = t.aux_col1; const uword t_col_end_p1 = t_col_start + t.n_cols; const uword t_slice_start = t.aux_slice1; const uword t_slice_end_p1 = t_slice_start + t.n_slices; const uword x_row_start = x.aux_row1; const uword x_row_end_p1 = x_row_start + x.n_rows; const uword x_col_start = x.aux_col1; const uword x_col_end_p1 = x_col_start + x.n_cols; const uword x_slice_start = x.aux_slice1; const uword x_slice_end_p1 = x_slice_start + x.n_slices; const bool outside_rows = ( (x_row_start >= t_row_end_p1 ) || (t_row_start >= x_row_end_p1 ) ); const bool outside_cols = ( (x_col_start >= t_col_end_p1 ) || (t_col_start >= x_col_end_p1 ) ); const bool outside_slices = ( (x_slice_start >= t_slice_end_p1) || (t_slice_start >= x_slice_end_p1) ); return ( (outside_rows == false) && (outside_cols == false) && (outside_slices == false) ); } } } template inline bool subview_cube::check_overlap(const Mat& x) const { const subview_cube& t = *this; const uword t_aux_slice1 = t.aux_slice1; const uword t_aux_slice2_plus_1 = t_aux_slice1 + t.n_slices; for(uword slice = t_aux_slice1; slice < t_aux_slice2_plus_1; ++slice) { const Mat& y = *(t.m.mat_ptrs[slice]); if( x.memptr() == y.memptr() ) { return true; } } return false; } //! cube X = Y.subcube(...) template inline void subview_cube::extract(Cube& out, const subview_cube& in) { arma_extra_debug_sigprint(); // NOTE: we're assuming that the cube has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Cube contructor or operator=() const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; const uword n_slices = in.n_slices; arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols = %d out.n_slices = %d in.m.n_rows = %d in.m.n_cols = %d in.m.n_slices = %d") % out.n_rows % out.n_cols % out.n_slices % in.m.n_rows % in.m.n_cols % in.m.n_slices); for(uword slice = 0; slice < n_slices; ++slice) { for(uword col = 0; col < n_cols; ++col) { arrayops::copy( out.slice_colptr(slice,col), in.slice_colptr(slice,col), n_rows ); } } } //! cube X += Y.subcube(...) template inline void subview_cube::plus_inplace(Cube& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "addition"); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; const uword n_slices = out.n_slices; for(uword slice = 0; slice inline void subview_cube::minus_inplace(Cube& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "subtraction"); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; const uword n_slices = out.n_slices; for(uword slice = 0; slice inline void subview_cube::schur_inplace(Cube& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "element-wise multiplication"); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; const uword n_slices = out.n_slices; for(uword slice = 0; slice inline void subview_cube::div_inplace(Cube& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "element-wise division"); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; const uword n_slices = out.n_slices; for(uword slice = 0; slice inline void subview_cube::extract(Mat& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { out.set_size(in_n_rows, in_n_cols); for(uword col=0; col < in_n_cols; ++col) { arrayops::copy( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); } } else { if(out_vec_state == 0) { if(in_n_cols == 1) { out.set_size(in_n_rows, in_n_slices); for(uword i=0; i < in_n_slices; ++i) { arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if(in_n_rows == 1) { const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; out.set_size(in_n_cols, in_n_slices); for(uword slice=0; slice < in_n_slices; ++slice) { const uword mod_slice = in_aux_slice1 + slice; eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); out_colptr[i] = tmp_i; out_colptr[j] = tmp_j; } if(i < in_n_cols) { out_colptr[i] = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); } } } } else { out.set_size(in_n_slices); eT* out_mem = out.memptr(); const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword i=0; i inline void subview_cube::plus_inplace(Mat& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_cube_as_mat(out, in, "addition", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword col=0; col < in_n_cols; ++col) { arrayops::inplace_plus( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword slice=0; slice < in_n_slices; ++slice) { const uword mod_slice = in_aux_slice1 + slice; eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); out_colptr[i] += tmp_i; out_colptr[j] += tmp_j; } if(i < in_n_cols) { out_colptr[i] += Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); } } } } else { eT* out_mem = out.memptr(); const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword i=0; i inline void subview_cube::minus_inplace(Mat& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_cube_as_mat(out, in, "subtraction", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword col=0; col < in_n_cols; ++col) { arrayops::inplace_minus( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword slice=0; slice < in_n_slices; ++slice) { const uword mod_slice = in_aux_slice1 + slice; eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); out_colptr[i] -= tmp_i; out_colptr[j] -= tmp_j; } if(i < in_n_cols) { out_colptr[i] -= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); } } } } else { eT* out_mem = out.memptr(); const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword i=0; i inline void subview_cube::schur_inplace(Mat& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword col=0; col < in_n_cols; ++col) { arrayops::inplace_mul( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword slice=0; slice < in_n_slices; ++slice) { const uword mod_slice = in_aux_slice1 + slice; eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); out_colptr[i] *= tmp_i; out_colptr[j] *= tmp_j; } if(i < in_n_cols) { out_colptr[i] *= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); } } } } else { eT* out_mem = out.memptr(); const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword i=0; i inline void subview_cube::div_inplace(Mat& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_cube_as_mat(out, in, "element-wise division", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword col=0; col < in_n_cols; ++col) { arrayops::inplace_div( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword slice=0; slice < in_n_slices; ++slice) { const uword mod_slice = in_aux_slice1 + slice; eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); out_colptr[i] /= tmp_i; out_colptr[j] /= tmp_j; } if(i < in_n_cols) { out_colptr[i] /= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); } } } } else { eT* out_mem = out.memptr(); const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword i=0; i class eGlueCube : public BaseCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); static const bool has_subview = (ProxyCube::has_subview || ProxyCube::has_subview ); arma_aligned const ProxyCube P1; arma_aligned const ProxyCube P2; arma_inline ~eGlueCube(); arma_inline eGlueCube(const T1& in_A, const T2& in_B); arma_inline uword get_n_rows() const; arma_inline uword get_n_cols() const; arma_inline uword get_n_elem_slice() const; arma_inline uword get_n_slices() const; arma_inline uword get_n_elem() const; arma_inline elem_type operator[] (const uword i) const; arma_inline elem_type at (const uword row, const uword col, const uword slice) const; arma_inline elem_type at_alt (const uword i) const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/glue_toeplitz_meat.hpp0000644000176000001440000000265612200375542025036 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_toeplitz //! @{ template inline void glue_toeplitz::apply(Mat& out, const Glue& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp1(in.A, out); const unwrap_check tmp2(in.B, out); const Mat& A = tmp1.M; const Mat& B = tmp2.M; arma_debug_check ( ( ((A.is_vec() == false) && (A.is_empty() == false)) || ((B.is_vec() == false) && (B.is_empty() == false)) ), "toeplitz(): given object is not a vector" ); const uword A_N = A.n_elem; const uword B_N = B.n_elem; const eT* A_mem = A.memptr(); const eT* B_mem = B.memptr(); out.set_size(A_N, B_N); if( out.is_empty() ) { return; } for(uword col=0; col < B_N; ++col) { eT* col_mem = out.colptr(col); uword i = 0; for(uword row=col; row < A_N; ++row, ++i) { col_mem[row] = A_mem[i]; } } for(uword row=0; row < A_N; ++row) { uword i = 1; for(uword col=(row+1); col < B_N; ++col, ++i) { out.at(row,col) = B_mem[i]; } } } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_cov_meat.hpp0000644000176000001440000000655212200375542023752 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_cov //! @{ template inline void glue_cov::direct_cov(Mat& out, const Mat& A, const Mat& B, const uword norm_type) { arma_extra_debug_sigprint(); if(A.is_vec() && B.is_vec()) { arma_debug_check( (A.n_elem != B.n_elem), "cov(): the number of elements in A and B must match" ); const eT* A_ptr = A.memptr(); const eT* B_ptr = B.memptr(); eT A_acc = eT(0); eT B_acc = eT(0); eT out_acc = eT(0); const uword N = A.n_elem; for(uword i=0; i 1) ? eT(N-1) : eT(1) ) : eT(N); out.set_size(1,1); out[0] = out_acc/norm_val; } else { arma_debug_assert_mul_size(A, B, true, false, "cov()"); const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); out = trans(A) * B; out -= (trans(sum(A)) * sum(B))/eT(N); out /= norm_val; } } template inline void glue_cov::direct_cov(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat< std::complex >& B, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(A.is_vec() && B.is_vec()) { arma_debug_check( (A.n_elem != B.n_elem), "cov(): the number of elements in A and B must match" ); const eT* A_ptr = A.memptr(); const eT* B_ptr = B.memptr(); eT A_acc = eT(0); eT B_acc = eT(0); eT out_acc = eT(0); const uword N = A.n_elem; for(uword i=0; i 1) ? eT(N-1) : eT(1) ) : eT(N); out.set_size(1,1); out[0] = out_acc/norm_val; } else { arma_debug_assert_mul_size(A, B, true, false, "cov()"); const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); out = trans(A) * B; // out = strans(conj(A)) * B; out -= (trans(sum(A)) * sum(B))/eT(N); // out -= (strans(conj(sum(A))) * sum(B))/eT(N); out /= norm_val; } } template inline void glue_cov::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check A_tmp(X.A, out); const unwrap_check B_tmp(X.B, out); const Mat& A = A_tmp.M; const Mat& B = B_tmp.M; const uword norm_type = X.aux_uword; if(&A != &B) { glue_cov::direct_cov(out, A, B, norm_type); } else { op_cov::direct_cov(out, A, norm_type); } } //! @} RcppArmadillo/inst/include/armadillo_bits/SpBase_meat.hpp0000644000176000001440000000613412176655102023325 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpBase //! @{ template arma_inline const derived& SpBase::get_ref() const { return static_cast(*this); } template inline const SpOp SpBase::t() const { return SpOp( (*this).get_ref() ); } template inline const SpOp SpBase::ht() const { return SpOp( (*this).get_ref() ); } template inline const SpOp SpBase::st() const { return SpOp( (*this).get_ref() ); } template inline void SpBase::print(const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_print(extra_text); } template inline void SpBase::print(std::ostream& user_stream, const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_print(user_stream, extra_text); } template inline void SpBase::raw_print(const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_raw_print(extra_text); } template inline void SpBase::raw_print(std::ostream& user_stream, const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_raw_print(user_stream, extra_text); } template inline void SpBase::print_dense(const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_print_dense(extra_text); } template inline void SpBase::print_dense(std::ostream& user_stream, const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_print_dense(user_stream, extra_text); } template inline void SpBase::raw_print_dense(const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_raw_print_dense(extra_text); } template inline void SpBase::raw_print_dense(std::ostream& user_stream, const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_raw_print_dense(user_stream, extra_text); } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_conv_bones.hpp0000644000176000001440000000077312200375542024307 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_conv //! @{ class glue_conv { public: template inline static void apply(Mat& out, const Glue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/eOp_bones.hpp0000644000176000001440000000377212176655102023060 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup eOp //! @{ template class eOp : public Base > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Proxy proxy_type; static const bool prefer_at_accessor = Proxy::prefer_at_accessor; static const bool has_subview = Proxy::has_subview; static const bool is_fixed = Proxy::is_fixed; static const bool fake_mat = Proxy::fake_mat; static const bool is_row = Proxy::is_row; static const bool is_col = Proxy::is_col; arma_aligned const Proxy P; arma_aligned elem_type aux; //!< storage of auxiliary data, user defined format arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format inline ~eOp(); inline explicit eOp(const T1& in_m); inline eOp(const T1& in_m, const elem_type in_aux); inline eOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline eOp(const T1& in_m, const elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b); arma_inline uword get_n_rows() const; arma_inline uword get_n_cols() const; arma_inline uword get_n_elem() const; arma_inline elem_type operator[] (const uword ii) const; arma_inline elem_type at (const uword row, const uword col) const; arma_inline elem_type at_alt (const uword ii) const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/sp_auxlib_bones.hpp0000644000176000001440000000351512260166736024322 0ustar ripleyusers// Copyright (C) 2013 Ryan Curtin // Copyright (C) 2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup sp_auxlib //! @{ //! wrapper for accesing external functions for sparse matrices defined in ARPACK class sp_auxlib { public: // // eigs_sym() via ARPACK template inline static bool eigs_sym(Col& eigval, Mat& eigvec, const SpBase& X, const uword n_eigvals); template inline static bool eigs_sym(Col& eigval, Mat< std::complex >& eigvec, const SpBase< std::complex, T1 >& X, const uword n_eigvals); // // eigs_gen() via ARPACK template inline static bool eigs_gen(Col< std::complex >& eigval, Mat< std::complex >& eigvec, const SpBase& X, const uword n_eigvals); template inline static bool eigs_gen(Col< std::complex >& eigval, Mat< std::complex >& eigvec, const SpBase< std::complex, T1>& X, const uword n_eigvals); private: // calls arpack saupd()/naupd() because the code is so similar for each // all of the extra variables are later used by seupd()/neupd(), but those // functions are very different and we can't combine their code template inline static void run_aupd ( const uword n_eigvals, const SpProxy& p, const bool sym, blas_int& n, eT& tol, podarray& resid, blas_int& ncv, podarray& v, blas_int& ldv, podarray& iparam, podarray& ipntr, podarray& workd, podarray& workl, blas_int& lworkl, podarray& rwork, blas_int& info ); }; RcppArmadillo/inst/include/armadillo_bits/spop_max_meat.hpp0000644000176000001440000002176312111344723023774 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_max //! @{ template inline void spop_max::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check((dim > 1), "max(): incorrect usage. dim must be 0 or 1"); const SpProxy p(in.m); if(p.is_alias(out) == false) { spop_max::apply_noalias(out, p, dim); } else { SpMat tmp; spop_max::apply_noalias(tmp, p, dim); out.steal_mem(tmp); } } template inline void spop_max::apply_noalias ( SpMat& result, const SpProxy& p, const uword dim, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; if(dim == 0) { // maximum in each column result.set_size(1, p.get_n_cols()); if(p.get_n_nonzero() == 0) { return; } typename SpProxy::const_iterator_type it = p.begin(); uword cur_col = it.col(); uword elem_in_col = 1; eT cur_max = (*it); ++it; while(it != p.end()) { if(it.col() != cur_col) { // was the column full? if(elem_in_col == p.get_n_rows()) { result.at(0, cur_col) = cur_max; } else { result.at(0, cur_col) = std::max(eT(0), cur_max); } cur_col = it.col(); elem_in_col = 0; cur_max = (*it); } else { cur_max = std::max(cur_max, *it); } ++elem_in_col; ++it; } if(elem_in_col == p.get_n_rows()) { result.at(0, cur_col) = cur_max; } else { result.at(0, cur_col) = std::max(eT(0), cur_max); } } else { // maximum in each row result.set_size(p.get_n_rows(), 1); if(p.get_n_nonzero() == 0) { return; } typename SpProxy::const_row_iterator_type it = p.begin_row(); uword cur_row = it.row(); uword elem_in_row = 1; eT cur_max = (*it); ++it; while(it.pos() < p.get_n_nonzero()) { if(it.row() != cur_row) { // was the row full? if(elem_in_row == p.get_n_cols()) { result.at(cur_row, 0) = cur_max; } else { result.at(cur_row, 0) = std::max(eT(0), cur_max); } cur_row = it.row(); elem_in_row = 0; cur_max = (*it); } else { cur_max = std::max(cur_max, *it); } ++elem_in_row; ++it; } if(elem_in_row == p.get_n_cols()) { result.at(cur_row, 0) = cur_max; } else { result.at(cur_row, 0) = std::max(eT(0), cur_max); } } } template inline void spop_max::apply_noalias ( SpMat& result, const SpProxy& p, const uword dim, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; if(dim == 0) { // maximum in each column result.set_size(1, p.get_n_cols()); if(p.get_n_nonzero() == 0) { return; } typename SpProxy::const_iterator_type it = p.begin(); uword cur_col = it.col(); uword elem_in_col = 1; eT cur_max_orig = *it; T cur_max_abs = std::abs(cur_max_orig); ++it; while(it != p.end()) { if(it.col() != cur_col) { // was the column full? if(elem_in_col == p.get_n_rows()) { result.at(0, cur_col) = cur_max_orig; } else { eT val1 = eT(0); result.at(0, cur_col) = ( std::abs(val1) >= cur_max_abs ) ? val1 : cur_max_orig; } cur_col = it.col(); elem_in_col = 0; cur_max_orig = *it; cur_max_abs = std::abs(cur_max_orig); } else { eT val1_orig = *it; T val1_abs = std::abs(val1_orig); if( val1_abs >= cur_max_abs ) { cur_max_abs = val1_abs; cur_max_orig = val1_orig; } } ++elem_in_col; ++it; } if(elem_in_col == p.get_n_rows()) { result.at(0, cur_col) = cur_max_orig; } else { eT val1 = eT(0); result.at(0, cur_col) = ( std::abs(val1) >= cur_max_abs ) ? val1 : cur_max_orig; } } else { // maximum in each row result.set_size(p.get_n_rows(), 1); if(p.get_n_nonzero() == 0) { return; } typename SpProxy::const_row_iterator_type it = p.begin_row(); uword cur_row = it.row(); uword elem_in_row = 1; eT cur_max_orig = *it; T cur_max_abs = std::abs(cur_max_orig); ++it; while(it.pos() < p.get_n_nonzero()) { if(it.row() != cur_row) { // was the row full? if(elem_in_row == p.get_n_cols()) { result.at(cur_row, 0) = cur_max_orig; } else { eT val1 = eT(0); result.at(cur_row, 0) = ( std::abs(val1) >= cur_max_abs ) ? val1 : cur_max_orig; } cur_row = it.row(); elem_in_row = 0; cur_max_orig = *it; cur_max_abs = std::abs(cur_max_orig); } else { eT val1_orig = *it; T val1_abs = std::abs(val1_orig); if( val1_abs >= cur_max_abs ) { cur_max_abs = val1_abs; cur_max_orig = val1_orig; } } ++elem_in_row; ++it; } if(elem_in_row == p.get_n_cols()) { result.at(cur_row, 0) = cur_max_orig; } else { eT val1 = eT(0); result.at(cur_row, 0) = ( std::abs(val1) >= cur_max_abs ) ? val1 : cur_max_orig; } } } template inline typename T1::elem_type spop_max::vector_max ( const T1& x, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const SpProxy p(x); if(p.get_n_nonzero() == 0) { return eT(0); } if(SpProxy::must_use_iterator == false) { // direct access of values if(p.get_n_nonzero() == p.get_n_elem()) { return op_max::direct_max(p.get_values(), p.get_n_nonzero()); } else { return std::max(eT(0), op_max::direct_max(p.get_values(), p.get_n_nonzero())); } } else { // use iterator typename SpProxy::const_iterator_type it = p.begin(); eT result = (*it); ++it; while(it != p.end()) { if((*it) > result) { result = (*it); } ++it; } if(p.get_n_nonzero() == p.get_n_elem()) { return result; } else { return std::max(eT(0), result); } } } template inline typename T1::elem_type spop_max::vector_max ( const T1& x, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const SpProxy p(x); if(p.get_n_nonzero() == 0) { return eT(0); } if(SpProxy::must_use_iterator == false) { // direct access of values if(p.get_n_nonzero() == p.get_n_elem()) { return op_max::direct_max(p.get_values(), p.get_n_nonzero()); } else { const eT val1 = eT(0); const eT val2 = op_max::direct_max(p.get_values(), p.get_n_nonzero()); return ( std::abs(val1) >= std::abs(val2) ) ? val1 : val2; } } else { // use iterator typename SpProxy::const_iterator_type it = p.begin(); eT best_val_orig = *it; T best_val_abs = std::abs(best_val_orig); ++it; while(it != p.end()) { eT val_orig = *it; T val_abs = std::abs(val_orig); if(val_abs > best_val_abs) { best_val_abs = val_abs; best_val_orig = val_orig; } ++it; } if(p.get_n_nonzero() == p.get_n_elem()) { return best_val_orig; } else { const eT val1 = eT(0); return ( std::abs(val1) >= best_val_abs ) ? val1 : best_val_orig; } } } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_times_bones.hpp0000644000176000001440000001055412257054523024466 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_times //! @{ //! \brief //! Template metaprogram depth_lhs //! calculates the number of Glue instances on the left hand side argument of Glue //! i.e. it recursively expands each Tx, until the type of Tx is not "Glue<..,.., glue_type>" (i.e the "glue_type" changes) template struct depth_lhs { static const uword num = 0; }; template struct depth_lhs< glue_type, Glue > { static const uword num = 1 + depth_lhs::num; }; template struct glue_times_redirect2_helper { template arma_hot inline static void apply(Mat& out, const Glue& X); }; template<> struct glue_times_redirect2_helper { template arma_hot inline static void apply(Mat& out, const Glue& X); }; template struct glue_times_redirect3_helper { template arma_hot inline static void apply(Mat& out, const Glue< Glue,T3,glue_times>& X); }; template<> struct glue_times_redirect3_helper { template arma_hot inline static void apply(Mat& out, const Glue< Glue,T3,glue_times>& X); }; template struct glue_times_redirect { template arma_hot inline static void apply(Mat& out, const Glue& X); }; template<> struct glue_times_redirect<2> { template arma_hot inline static void apply(Mat& out, const Glue& X); }; template<> struct glue_times_redirect<3> { template arma_hot inline static void apply(Mat& out, const Glue< Glue,T3,glue_times>& X); }; template<> struct glue_times_redirect<4> { template arma_hot inline static void apply(Mat& out, const Glue< Glue< Glue, T3, glue_times>, T4, glue_times>& X); }; //! Class which implements the immediate multiplication of two or more matrices class glue_times { public: template arma_hot inline static void apply(Mat& out, const Glue& X); template arma_hot inline static void apply_inplace(Mat& out, const T1& X); template arma_hot inline static void apply_inplace_plus(Mat& out, const Glue& X, const sword sign); // template arma_inline static uword mul_storage_cost(const TA& A, const TB& B); template arma_hot inline static void apply(Mat& out, const TA& A, const TB& B, const eT val); template arma_hot inline static void apply(Mat& out, const TA& A, const TB& B, const TC& C, const eT val); template arma_hot inline static void apply(Mat& out, const TA& A, const TB& B, const TC& C, const TD& D, const eT val); }; class glue_times_diag { public: template arma_hot inline static void apply(Mat& out, const Glue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/SpProxy.hpp0000644000176000001440000004001712111344723022555 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpProxy //! @{ template class SpProxy< SpMat > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef SpMat stored_type; typedef typename SpMat::const_iterator const_iterator_type; typedef typename SpMat::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const SpMat& Q; inline explicit SpProxy(const SpMat& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } }; template class SpProxy< SpCol > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef SpCol stored_type; typedef typename SpCol::const_iterator const_iterator_type; typedef typename SpCol::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const SpCol& Q; inline explicit SpProxy(const SpCol& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin(); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } }; template class SpProxy< SpRow > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef SpRow stored_type; typedef typename SpRow::const_iterator const_iterator_type; typedef typename SpRow::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = false; static const bool is_row = true; static const bool is_col = false; arma_aligned const SpRow& Q; inline explicit SpProxy(const SpRow& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return 1; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } }; template class SpProxy< SpSubview > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef SpSubview stored_type; typedef typename SpSubview::const_iterator const_iterator_type; typedef typename SpSubview::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = true; static const bool Q_created_by_proxy = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const SpSubview& Q; inline explicit SpProxy(const SpSubview& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.m.values; } arma_inline const uword* get_row_indices() const { return Q.m.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.m.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat& X) const { return (void_ptr(&Q.m) == void_ptr(&X)); } }; template class SpProxy< SpOp > { public: typedef typename T1::elem_type elem_type; typedef typename T1::elem_type eT; typedef typename get_pod_type::result pod_type; typedef SpMat stored_type; typedef typename SpMat::const_iterator const_iterator_type; typedef typename SpMat::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = true; static const bool is_row = SpOp::is_row; static const bool is_col = SpOp::is_col; arma_aligned const SpMat Q; inline explicit SpProxy(const SpOp& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat&) const { return false; } }; template class SpProxy< SpGlue > { public: typedef typename T1::elem_type elem_type; typedef typename T1::elem_type eT; typedef typename get_pod_type::result pod_type; typedef SpMat stored_type; typedef typename SpMat::const_iterator const_iterator_type; typedef typename SpMat::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = true; static const bool is_row = SpGlue::is_row; static const bool is_col = SpGlue::is_col; arma_aligned const SpMat Q; inline explicit SpProxy(const SpGlue& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat&) const { return false; } }; template class SpProxy< mtSpOp > { public: typedef out_eT elem_type; typedef typename T1::elem_type eT; typedef typename get_pod_type::result pod_type; typedef SpMat stored_type; typedef typename SpMat::const_iterator const_iterator_type; typedef typename SpMat::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = true; static const bool is_row = mtSpOp::is_row; static const bool is_col = mtSpOp::is_col; arma_aligned const SpMat Q; inline explicit SpProxy(const mtSpOp& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat&) const { return false; } }; //! @} RcppArmadillo/inst/include/armadillo_bits/subview_elem2_meat.hpp0000644000176000001440000004574012176655102024726 0ustar ripleyusers// Copyright (C) 2012-2013 Conrad Sanderson // Copyright (C) 2012-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup subview_elem2 //! @{ template inline subview_elem2::~subview_elem2() { arma_extra_debug_sigprint(); } template arma_inline subview_elem2::subview_elem2 ( const Mat& in_m, const Base& in_ri, const Base& in_ci, const bool in_all_rows, const bool in_all_cols ) : m (in_m ) , base_ri (in_ri ) , base_ci (in_ci ) , all_rows (in_all_rows) , all_cols (in_all_cols) { arma_extra_debug_sigprint(); } template template inline void subview_elem2::inplace_op(const eT val) { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); const uword m_n_rows = m_local.n_rows; const uword m_n_cols = m_local.n_cols; if( (all_rows == false) && (all_cols == false) ) { const unwrap_check_mixed tmp1(base_ri.get_ref(), m_local); const unwrap_check_mixed tmp2(base_ci.get_ref(), m_local); const umat& ri = tmp1.M; const umat& ci = tmp2.M; arma_debug_check ( ( ((ri.is_vec() == false) && (ri.is_empty() == false)) || ((ci.is_vec() == false) && (ci.is_empty() == false)) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col > m_n_cols), "Mat::elem(): index out of bounds" ); for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row > m_n_rows), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_local.at(row,col) = val; } else if(is_same_type::yes) { m_local.at(row,col) += val; } else if(is_same_type::yes) { m_local.at(row,col) -= val; } else if(is_same_type::yes) { m_local.at(row,col) *= val; } else if(is_same_type::yes) { m_local.at(row,col) /= val; } } } } else if( (all_rows == true) && (all_cols == false) ) { const unwrap_check_mixed tmp2(base_ci.get_ref(), m_local); const umat& ci = tmp2.M; arma_debug_check ( ( (ci.is_vec() == false) && (ci.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col > m_n_cols), "Mat::elem(): index out of bounds" ); eT* colptr = m_local.colptr(col); if(is_same_type::yes) { arrayops::inplace_set (colptr, val, m_n_rows); } else if(is_same_type::yes) { arrayops::inplace_plus (colptr, val, m_n_rows); } else if(is_same_type::yes) { arrayops::inplace_minus(colptr, val, m_n_rows); } else if(is_same_type::yes) { arrayops::inplace_mul (colptr, val, m_n_rows); } else if(is_same_type::yes) { arrayops::inplace_div (colptr, val, m_n_rows); } } } else if( (all_rows == false) && (all_cols == true) ) { const unwrap_check_mixed tmp1(base_ri.get_ref(), m_local); const umat& ri = tmp1.M; arma_debug_check ( ( (ri.is_vec() == false) && (ri.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; for(uword col=0; col < m_n_cols; ++col) { for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row > m_n_rows), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_local.at(row,col) = val; } else if(is_same_type::yes) { m_local.at(row,col) += val; } else if(is_same_type::yes) { m_local.at(row,col) -= val; } else if(is_same_type::yes) { m_local.at(row,col) *= val; } else if(is_same_type::yes) { m_local.at(row,col) /= val; } } } } } template template inline void subview_elem2::inplace_op(const Base& x) { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); const uword m_n_rows = m_local.n_rows; const uword m_n_cols = m_local.n_cols; const unwrap_check tmp(x.get_ref(), m_local); const Mat& X = tmp.M; if( (all_rows == false) && (all_cols == false) ) { const unwrap_check_mixed tmp1(base_ri.get_ref(), m_local); const unwrap_check_mixed tmp2(base_ci.get_ref(), m_local); const umat& ri = tmp1.M; const umat& ci = tmp2.M; arma_debug_check ( ( ((ri.is_vec() == false) && (ri.is_empty() == false)) || ((ci.is_vec() == false) && (ci.is_empty() == false)) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; arma_debug_assert_same_size( ri_n_elem, ci_n_elem, X.n_rows, X.n_cols, "Mat::elem()" ); for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col > m_n_cols), "Mat::elem(): index out of bounds" ); for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row > m_n_rows), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_local.at(row,col) = X.at(ri_count, ci_count); } else if(is_same_type::yes) { m_local.at(row,col) += X.at(ri_count, ci_count); } else if(is_same_type::yes) { m_local.at(row,col) -= X.at(ri_count, ci_count); } else if(is_same_type::yes) { m_local.at(row,col) *= X.at(ri_count, ci_count); } else if(is_same_type::yes) { m_local.at(row,col) /= X.at(ri_count, ci_count); } } } } else if( (all_rows == true) && (all_cols == false) ) { const unwrap_check_mixed tmp2(base_ci.get_ref(), m_local); const umat& ci = tmp2.M; arma_debug_check ( ( (ci.is_vec() == false) && (ci.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; arma_debug_assert_same_size( m_n_rows, ci_n_elem, X.n_rows, X.n_cols, "Mat::elem()" ); for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col > m_n_cols), "Mat::elem(): index out of bounds" ); eT* m_colptr = m_local.colptr(col); const eT* X_colptr = X.colptr(ci_count); if(is_same_type::yes) { arrayops::copy (m_colptr, X_colptr, m_n_rows); } else if(is_same_type::yes) { arrayops::inplace_plus (m_colptr, X_colptr, m_n_rows); } else if(is_same_type::yes) { arrayops::inplace_minus(m_colptr, X_colptr, m_n_rows); } else if(is_same_type::yes) { arrayops::inplace_mul (m_colptr, X_colptr, m_n_rows); } else if(is_same_type::yes) { arrayops::inplace_div (m_colptr, X_colptr, m_n_rows); } } } else if( (all_rows == false) && (all_cols == true) ) { const unwrap_check_mixed tmp1(base_ri.get_ref(), m_local); const umat& ri = tmp1.M; arma_debug_check ( ( (ri.is_vec() == false) && (ri.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; arma_debug_assert_same_size( ri_n_elem, m_n_cols, X.n_rows, X.n_cols, "Mat::elem()" ); for(uword col=0; col < m_n_cols; ++col) { for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row > m_n_rows), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_local.at(row,col) = X.at(ri_count, col); } else if(is_same_type::yes) { m_local.at(row,col) += X.at(ri_count, col); } else if(is_same_type::yes) { m_local.at(row,col) -= X.at(ri_count, col); } else if(is_same_type::yes) { m_local.at(row,col) *= X.at(ri_count, col); } else if(is_same_type::yes) { m_local.at(row,col) /= X.at(ri_count, col); } } } } } // // template inline void subview_elem2::fill(const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem2::zeros() { arma_extra_debug_sigprint(); inplace_op(eT(0)); } template inline void subview_elem2::ones() { arma_extra_debug_sigprint(); inplace_op(eT(1)); } template inline void subview_elem2::operator+= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem2::operator-= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem2::operator*= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem2::operator/= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } // // template template inline void subview_elem2::operator_equ(const subview_elem2& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator= (const subview_elem2& x) { arma_extra_debug_sigprint(); (*this).operator_equ(x); } //! work around compiler bugs template inline void subview_elem2::operator= (const subview_elem2& x) { arma_extra_debug_sigprint(); (*this).operator_equ(x); } template template inline void subview_elem2::operator+= (const subview_elem2& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator-= (const subview_elem2& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator%= (const subview_elem2& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator/= (const subview_elem2& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator+= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator-= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator%= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator/= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } // // template inline void subview_elem2::extract(Mat& actual_out, const subview_elem2& in) { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(in.m); const uword m_n_rows = m_local.n_rows; const uword m_n_cols = m_local.n_cols; const bool alias = (&actual_out == &m_local); arma_extra_debug_warn(alias, "subview_elem2::extract(): aliasing detected"); Mat* tmp_out = alias ? new Mat() : 0; Mat& out = alias ? *tmp_out : actual_out; if( (in.all_rows == false) && (in.all_cols == false) ) { const unwrap_check_mixed tmp1(in.base_ri.get_ref(), actual_out); const unwrap_check_mixed tmp2(in.base_ci.get_ref(), actual_out); const umat& ri = tmp1.M; const umat& ci = tmp2.M; arma_debug_check ( ( ((ri.is_vec() == false) && (ri.is_empty() == false)) || ((ci.is_vec() == false) && (ci.is_empty() == false)) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; out.set_size(ri_n_elem, ci_n_elem); eT* out_mem = out.memptr(); uword out_count = 0; for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col > m_n_cols), "Mat::elem(): index out of bounds" ); for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row > m_n_rows), "Mat::elem(): index out of bounds" ); out_mem[out_count] = m_local.at(row,col); ++out_count; } } } else if( (in.all_rows == true) && (in.all_cols == false) ) { const unwrap_check_mixed tmp2(in.base_ci.get_ref(), m_local); const umat& ci = tmp2.M; arma_debug_check ( ( (ci.is_vec() == false) && (ci.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; out.set_size(m_n_rows, ci_n_elem); for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col > m_n_cols), "Mat::elem(): index out of bounds" ); arrayops::copy( out.colptr(ci_count), m_local.colptr(col), m_n_rows ); } } else if( (in.all_rows == false) && (in.all_cols == true) ) { const unwrap_check_mixed tmp1(in.base_ri.get_ref(), m_local); const umat& ri = tmp1.M; arma_debug_check ( ( (ri.is_vec() == false) && (ri.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; out.set_size(ri_n_elem, m_n_cols); for(uword col=0; col < m_n_cols; ++col) { for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row > m_n_rows), "Mat::elem(): index out of bounds" ); out.at(ri_count,col) = m_local.at(row,col); } } } if(alias) { actual_out.steal_mem(out); delete tmp_out; } } // TODO: implement a dedicated function instead of creating a temporary (but lots of potential aliasing issues) template inline void subview_elem2::plus_inplace(Mat& out, const subview_elem2& in) { arma_extra_debug_sigprint(); const Mat tmp(in); out += tmp; } template inline void subview_elem2::minus_inplace(Mat& out, const subview_elem2& in) { arma_extra_debug_sigprint(); const Mat tmp(in); out -= tmp; } template inline void subview_elem2::schur_inplace(Mat& out, const subview_elem2& in) { arma_extra_debug_sigprint(); const Mat tmp(in); out %= tmp; } template inline void subview_elem2::div_inplace(Mat& out, const subview_elem2& in) { arma_extra_debug_sigprint(); const Mat tmp(in); out /= tmp; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_diagvec_bones.hpp0000644000176000001440000000156212200631217024415 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_diagvec //! @{ class op_diagvec { public: template inline static void apply(Mat& out, const Op& X); template arma_hot inline static void apply_unwrap(Mat& out, const T1& X, const uword row_offset, const uword col_offset, const uword len); template arma_hot inline static void apply_proxy(Mat& out, const Proxy& P, const uword row_offset, const uword col_offset, const uword len); }; //! @} RcppArmadillo/inst/include/armadillo_bits/eGlueCube_meat.hpp0000644000176000001440000000717412176655102024015 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup eGlueCube //! @{ template arma_inline eGlueCube::~eGlueCube() { arma_extra_debug_sigprint(); } template arma_inline eGlueCube::eGlueCube(const T1& in_A, const T2& in_B) : P1(in_A) , P2(in_B) { arma_extra_debug_sigprint(); arma_debug_assert_same_size ( P1.get_n_rows(), P1.get_n_cols(), P1.get_n_slices(), P2.get_n_rows(), P2.get_n_cols(), P2.get_n_slices(), eglue_type::text() ); } template arma_inline uword eGlueCube::get_n_rows() const { return P1.get_n_rows(); } template arma_inline uword eGlueCube::get_n_cols() const { return P1.get_n_cols(); } template arma_inline uword eGlueCube::get_n_slices() const { return P1.get_n_slices(); } template arma_inline uword eGlueCube::get_n_elem_slice() const { return P1.get_n_elem_slice(); } template arma_inline uword eGlueCube::get_n_elem() const { return P1.get_n_elem(); } template arma_inline typename T1::elem_type eGlueCube::operator[] (const uword i) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1[i] + P2[i]; } else if(is_same_type::yes) { return P1[i] - P2[i]; } else if(is_same_type::yes) { return P1[i] / P2[i]; } else if(is_same_type::yes) { return P1[i] * P2[i]; } else return eT(0); } template arma_inline typename T1::elem_type eGlueCube::at(const uword row, const uword col, const uword slice) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1.at(row,col,slice) + P2.at(row,col,slice); } else if(is_same_type::yes) { return P1.at(row,col,slice) - P2.at(row,col,slice); } else if(is_same_type::yes) { return P1.at(row,col,slice) / P2.at(row,col,slice); } else if(is_same_type::yes) { return P1.at(row,col,slice) * P2.at(row,col,slice); } else return eT(0); } template arma_inline typename T1::elem_type eGlueCube::at_alt(const uword i) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1.at_alt(i) + P2.at_alt(i); } else if(is_same_type::yes) { return P1.at_alt(i) - P2.at_alt(i); } else if(is_same_type::yes) { return P1.at_alt(i) / P2.at_alt(i); } else if(is_same_type::yes) { return P1.at_alt(i) * P2.at_alt(i); } else return eT(0); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_trunc_log.hpp0000644000176000001440000000270312200375542023612 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_trunc_log //! @{ template inline static typename arma_real_only::result trunc_log(const eT x) { if(std::numeric_limits::is_iec559) { if(x == std::numeric_limits::infinity()) { return Math::log_max(); } else { return (x <= eT(0)) ? Math::log_min() : std::log(x); } } else { return std::log(x); } } template inline static typename arma_integral_only::result trunc_log(const eT x) { return eT( trunc_log( double(x) ) ); } template inline static std::complex trunc_log(const std::complex& x) { return std::complex( trunc_log( std::abs(x) ), std::arg(x) ); } template arma_inline const eOp trunc_log(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube trunc_log(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_max.hpp0000644000176000001440000000750512244135164022412 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_max //! @{ //! \brief //! Delayed 'maximum values' operation. //! The dimension, along which the maxima are found, is set via 'dim'. //! For dim = 0, the maximum value of each column is found (i.e. searches by traversing across rows). //! For dim = 1, the maximum value of each row is found (i.e. searches by traversing across columns). //! The default is dim = 0. template arma_inline const Op max ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op max ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type max ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_max::max(X); } //! \brief //! Immediate 'find maximum value' operation, //! invoked, for example, by: max(max(A)) template inline arma_warn_unused typename T1::elem_type max(const Op& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("max(): two consecutive max() calls detected"); return op_max::max(in.m); } template arma_inline const Op< Op, op_max> max(const Op& in, const uword dim) { arma_extra_debug_sigprint(); return Op< Op, op_max>(in, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & max(const T& x) { return x; } //! element-wise maximum template arma_inline typename enable_if2 < ( is_arma_type::value && is_arma_type::value && is_same_type::value ), const Glue >::result max ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return Glue(X, Y); } template inline arma_warn_unused typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == true), typename T1::elem_type >::result max(const T1& x) { arma_extra_debug_sigprint(); return spop_max::vector_max(x); } template inline typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == false), const SpOp >::result max(const T1& X, const uword dim = 0) { arma_extra_debug_sigprint(); return SpOp(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type max(const SpOp& X) { arma_extra_debug_sigprint(); arma_extra_debug_print("max(): two consecutive max() calls detected"); return spop_max::vector_max(X.m); } template inline const SpOp< SpOp, spop_max> max(const SpOp& in, const uword dim) { arma_extra_debug_sigprint(); return SpOp< SpOp, spop_max>(in, dim, 0); } //! @} RcppArmadillo/inst/include/armadillo_bits/access.hpp0000644000176000001440000000254712176655102022407 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup access //! @{ class access { public: //! internal function to allow modification of data declared as read-only (use with caution) template arma_inline static T1& rw (const T1& x) { return const_cast(x); } template arma_inline static T1*& rwp(const T1* const& x) { return const_cast(x); } //! internal function to obtain the real part of either a plain number or a complex number template arma_inline static const eT& tmp_real(const eT& X) { return X; } template arma_inline static const T tmp_real(const std::complex& X) { return X.real(); } //! internal function to work around braindead compilers template arma_inline static const typename enable_if2::value, const eT&>::result alt_conj(const eT& X) { return X; } template arma_inline static const typename enable_if2< is_complex::value, const eT >::result alt_conj(const eT& X) { return std::conj(X); } }; //! @} RcppArmadillo/inst/include/armadillo_bits/spop_mean_bones.hpp0000644000176000001440000000271012111344723024276 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_mean //! @{ //! Class for finding mean values of a sparse matrix class spop_mean { public: // Apply mean into an output sparse matrix (or vector). template inline static void apply(SpMat& out, const SpOp& in); template inline static void apply_noalias(SpMat& out, const SpProxy& p, const uword dim); // Take direct mean of a set of values. Length of array and number of values can be different. template inline static eT direct_mean(const eT* const X, const uword length, const uword N); template inline static eT direct_mean_robust(const eT* const X, const uword length, const uword N); template inline static typename T1::elem_type mean_all(const SpBase& X); // Take the mean using an iterator. template inline static eT iterator_mean(T1& it, const T1& end, const uword n_zero, const eT junk); template inline static eT iterator_mean_robust(T1& it, const T1& end, const uword n_zero, const eT junk); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_size.hpp0000644000176000001440000000533712245272107022600 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_size //! @{ inline const SizeMat size(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return SizeMat(n_rows, n_cols); } template inline typename enable_if2< is_arma_type::value, const SizeMat >::result size(const T1& X) { arma_extra_debug_sigprint(); const Proxy P(X); return SizeMat( P.get_n_rows(), P.get_n_cols() ); } template inline typename enable_if2< is_arma_type::value, const uword >::result size(const T1& X, const uword dim) { arma_extra_debug_sigprint(); arma_debug_check( (dim >= 2), "size(): dimension out of bounds" ); const Proxy P(X); return (dim == 0) ? P.get_n_rows() : P.get_n_cols(); } inline const SizeCube size(const uword n_rows, const uword n_cols, const uword n_slices) { arma_extra_debug_sigprint(); return SizeCube(n_rows, n_cols, n_slices); } template inline typename enable_if2< is_arma_cube_type::value, const SizeCube >::result size(const T1& X) { arma_extra_debug_sigprint(); const ProxyCube P(X); return SizeCube( P.get_n_rows(), P.get_n_cols(), P.get_n_slices() ); } template inline typename enable_if2< is_arma_cube_type::value, const uword >::result size(const T1& X, const uword dim) { arma_extra_debug_sigprint(); arma_debug_check( (dim >= 3), "size(): dimension out of bounds" ); const ProxyCube P(X); return (dim == 0) ? P.get_n_rows() : ( (dim == 1) ? P.get_n_cols() : P.get_n_slices() ); } template inline typename enable_if2< is_arma_sparse_type::value, const SizeMat >::result size(const T1& X) { arma_extra_debug_sigprint(); const SpProxy P(X); return SizeMat( P.get_n_rows(), P.get_n_cols() ); } template inline typename enable_if2< is_arma_sparse_type::value, const uword >::result size(const T1& X, const uword dim) { arma_extra_debug_sigprint(); arma_debug_check( (dim >= 2), "size(): dimension out of bounds" ); const SpProxy P(X); return (dim == 0) ? P.get_n_rows() : P.get_n_cols(); } template inline const SizeMat size(const field& X) { arma_extra_debug_sigprint(); return SizeMat( X.n_rows, X.n_cols ); } template inline const SizeMat size(const subview_field& X) { arma_extra_debug_sigprint(); return SizeMat( X.n_rows, X.n_cols ); } //! @} RcppArmadillo/inst/include/armadillo_bits/auxlib_bones.hpp0000644000176000001440000002032112262150442023577 0ustar ripleyusers// Copyright (C) 2008-2014 Conrad Sanderson // Copyright (C) 2008-2014 NICTA (www.nicta.com.au) // Copyright (C) 2009 Edmund Highcock // Copyright (C) 2011 James Sanders // Copyright (C) 2012 Eric Jon Sundstrom // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup auxlib //! @{ //! wrapper for accessing external functions defined in ATLAS, LAPACK or BLAS libraries class auxlib { public: template struct pos { static const uword n2 = row + col*2; static const uword n3 = row + col*3; static const uword n4 = row + col*4; }; // // inv template inline static bool inv(Mat& out, const Base& X, const bool slow = false); template inline static bool inv(Mat& out, const Mat& A, const bool slow = false); template inline static bool inv_noalias_tinymat(Mat& out, const Mat& X, const uword N); template inline static bool inv_inplace_lapack(Mat& out); // // inv_tr template inline static bool inv_tr(Mat& out, const Base& X, const uword layout); // // inv_sym template inline static bool inv_sym(Mat& out, const Base& X, const uword layout); // // inv_sympd template inline static bool inv_sympd(Mat& out, const Base& X, const uword layout); // // det template inline static eT det(const Base& X, const bool slow = false); template inline static eT det_tinymat(const Mat& X, const uword N); template inline static eT det_lapack(const Mat& X, const bool make_copy); // // log_det template inline static bool log_det(eT& out_val, typename get_pod_type::result& out_sign, const Base& X); // // lu template inline static bool lu(Mat& L, Mat& U, podarray& ipiv, const Base& X); template inline static bool lu(Mat& L, Mat& U, Mat& P, const Base& X); template inline static bool lu(Mat& L, Mat& U, const Base& X); // // eig_sym template inline static bool eig_sym(Col& eigval, const Base& X); template inline static bool eig_sym(Col& eigval, const Base,T1>& X); template inline static bool eig_sym(Col& eigval, Mat& eigvec, const Base& X); template inline static bool eig_sym(Col& eigval, Mat< std::complex >& eigvec, const Base,T1>& X); template inline static bool eig_sym_dc(Col& eigval, Mat& eigvec, const Base& X); template inline static bool eig_sym_dc(Col& eigval, Mat< std::complex >& eigvec, const Base,T1>& X); // // eig_gen template inline static bool eig_gen(Col< std::complex >& eigval, Mat& l_eigvec, Mat& r_eigvec, const Base& X, const char side); template inline static bool eig_gen(Col< std::complex >& eigval, Mat< std::complex >& l_eigvec, Mat< std::complex >& r_eigvec, const Base< std::complex, T1 >& X, const char side); // // eig_pair template inline static bool eig_pair(Col< std::complex >& eigval, Mat& l_eigvec, Mat& r_eigvec, const Base& X, const Base& Y, const char side); template inline static bool eig_pair(Col< std::complex >& eigval, Mat< std::complex >& l_eigvec, Mat< std::complex >& r_eigvec, const Base< std::complex, T1 >& X, const Base< std::complex, T2 >& Y, const char side); // // chol template inline static bool chol(Mat& out, const Base& X); // // qr template inline static bool qr(Mat& Q, Mat& R, const Base& X); template inline static bool qr_econ(Mat& Q, Mat& R, const Base& X); // // svd template inline static bool svd(Col& S, const Base& X, uword& n_rows, uword& n_cols); template inline static bool svd(Col& S, const Base, T1>& X, uword& n_rows, uword& n_cols); template inline static bool svd(Col& S, const Base& X); template inline static bool svd(Col& S, const Base, T1>& X); template inline static bool svd(Mat& U, Col& S, Mat& V, const Base& X); template inline static bool svd(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X); template inline static bool svd_econ(Mat& U, Col& S, Mat& V, const Base& X, const char mode); template inline static bool svd_econ(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X, const char mode); // EXPERIMENTAL template inline static bool svd_dc(Col& S, const Base& X, uword& n_rows, uword& n_cols); // EXPERIMENTAL template inline static bool svd_dc(Col& S, const Base, T1>& X, uword& n_rows, uword& n_cols); // EXPERIMENTAL template inline static bool svd_dc(Col& S, const Base& X); // EXPERIMENTAL template inline static bool svd_dc(Col& S, const Base, T1>& X); template inline static bool svd_dc(Mat& U, Col& S, Mat& V, const Base& X); template inline static bool svd_dc(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X); template inline static bool svd_dc_econ(Mat& U, Col& S, Mat& V, const Base& X); template inline static bool svd_dc_econ(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X); // // solve template inline static bool solve (Mat& out, Mat& A, const Base& X, const bool slow = false); template inline static bool solve_od(Mat& out, Mat& A, const Base& X); template inline static bool solve_ud(Mat& out, Mat& A, const Base& X); // // solve_tr template inline static bool solve_tr(Mat& out, const Mat& A, const Mat& B, const uword layout); // // Schur decomposition template inline static bool schur_dec(Mat& Z, Mat& T, const Mat& A); template inline static bool schur_dec(Mat >& Z, Mat >& T, const Mat >& A); // // syl (solution of the Sylvester equation AX + XB = C) template inline static bool syl(Mat& X, const Mat& A, const Mat& B, const Mat& C); // // lyap (solution of the continuous Lyapunov equation AX + XA^H + Q = 0) template inline static bool lyap(Mat& X, const Mat& A, const Mat& Q); // // dlyap (solution of the discrete Lyapunov equation AXA^H - X + Q = 0) template inline static bool dlyap(Mat& X, const Mat& A, const Mat& Q); }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_repmat_meat.hpp0000644000176000001440000000471712256562725024152 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_repmat //! @{ //! \brief //! implementation of the 'repeat matrix' operation, used for constructing matrices template inline void op_repmat::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; const uword copies_per_row = in.aux_uword_a; const uword copies_per_col = in.aux_uword_b; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; out.set_size(X_n_rows * copies_per_row, X_n_cols * copies_per_col); const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; // if( (out_n_rows > 0) && (out_n_cols > 0) ) // { // for(uword col = 0; col < out_n_cols; col += X_n_cols) // for(uword row = 0; row < out_n_rows; row += X_n_rows) // { // out.submat(row, col, row+X_n_rows-1, col+X_n_cols-1) = X; // } // } if( (out_n_rows > 0) && (out_n_cols > 0) ) { if(copies_per_row != 1) { for(uword col_copy=0; col_copy < copies_per_col; ++col_copy) { const uword out_col_offset = X_n_cols * col_copy; for(uword col=0; col < X_n_cols; ++col) { eT* out_colptr = out.colptr(col + out_col_offset); const eT* X_colptr = X.colptr(col); for(uword row_copy=0; row_copy < copies_per_row; ++row_copy) { const uword out_row_offset = X_n_rows * row_copy; arrayops::copy( &out_colptr[out_row_offset], X_colptr, X_n_rows ); } } } } else { for(uword col_copy=0; col_copy < copies_per_col; ++col_copy) { const uword out_col_offset = X_n_cols * col_copy; for(uword col=0; col < X_n_cols; ++col) { eT* out_colptr = out.colptr(col + out_col_offset); const eT* X_colptr = X.colptr(col); arrayops::copy( out_colptr, X_colptr, X_n_rows ); } } } } } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_solve_meat.hpp0000644000176000001440000000452712200375542024313 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_solve //! @{ template inline void glue_solve::solve_direct(Mat& out, Mat& A, const Base& X, const bool slow) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; bool status = false; if(A_n_rows == A_n_cols) { status = auxlib::solve(out, A, X, slow); } else if(A_n_rows > A_n_cols) { arma_extra_debug_print("solve(): detected over-determined system"); status = auxlib::solve_od(out, A, X); } else { arma_extra_debug_print("solve(): detected under-determined system"); status = auxlib::solve_ud(out, A, X); } if(status == false) { out.reset(); arma_bad("solve(): solution not found"); } } template inline void glue_solve::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; Mat A = X.A.get_ref(); glue_solve::solve_direct( out, A, X.B, (X.aux_uword == 1) ); } template inline void glue_solve_tr::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check A_tmp(X.A, out); const unwrap_check B_tmp(X.B, out); const Mat& A = A_tmp.M; const Mat& B = B_tmp.M; bool err_state = false; char* err_msg = 0; arma_debug_set_error( err_state, err_msg, ((&A) == (&B)), "solve(): A is an alias of B" ); arma_debug_set_error( err_state, err_msg, (A.n_rows != B.n_rows), "solve(): number of rows in A and B must be the same" ); arma_debug_set_error( err_state, err_msg, (A.is_square() == false), "solve(): A is not a square matrix" ); arma_debug_check(err_state, err_msg); const bool status = auxlib::solve_tr(out, A, B, X.aux_uword); if(status == false) { out.reset(); arma_bad("solve(): solution not found"); } } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_ones.hpp0000644000176000001440000000444612233361440022566 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_ones //! @{ arma_inline const Gen ones(const uword n_elem) { arma_extra_debug_sigprint(); return Gen(n_elem, 1); } template arma_inline const Gen ones(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only::result* junk2 = 0) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_Row::value == true) { return Gen(1, n_elem); } else { return Gen(n_elem, 1); } } arma_inline const Gen ones(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return Gen(n_rows, n_cols); } template inline const Gen ones(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_Col::value == true) { arma_debug_check( (n_cols != 1), "ones(): incompatible size" ); } else if(is_Row::value == true) { arma_debug_check( (n_rows != 1), "ones(): incompatible size" ); } return Gen(n_rows, n_cols); } arma_inline const GenCube ones(const uword n_rows, const uword n_cols, const uword n_slices) { arma_extra_debug_sigprint(); return GenCube(n_rows, n_cols, n_slices); } template arma_inline const GenCube ones(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(n_rows, n_cols, n_slices); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_conv_to.hpp0000644000176000001440000004135412200375542023272 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_conv_to //! @{ //! conversion from Armadillo Base and BaseCube objects to scalars //! (kept only for compatibility with old code; use as_scalar() instead for Base objects like Mat) template class conv_to { public: template inline static out_eT from(const Base& in, const typename arma_not_cx::result* junk = 0); template inline static out_eT from(const Base& in, const typename arma_cx_only::result* junk = 0); template inline static out_eT from(const BaseCube& in, const typename arma_not_cx::result* junk = 0); template inline static out_eT from(const BaseCube& in, const typename arma_cx_only::result* junk = 0); }; template template inline out_eT conv_to::from(const Base& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_type_check(( is_supported_elem_type::value == false )); const unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" ); return out_eT(X.mem[0]); } template template inline out_eT conv_to::from(const Base& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_type_check(( is_supported_elem_type::value == false )); const unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" ); out_eT out; arrayops::convert_cx_scalar(out, X.mem[0]); return out; } template template inline out_eT conv_to::from(const BaseCube& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_type_check(( is_supported_elem_type::value == false )); const unwrap_cube tmp(in.get_ref()); const Cube& X = tmp.M; arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" ); return out_eT(X.mem[0]); } template template inline out_eT conv_to::from(const BaseCube& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_type_check(( is_supported_elem_type::value == false )); const unwrap_cube tmp(in.get_ref()); const Cube& X = tmp.M; arma_debug_check( (X.n_elem != 1), "conv_to(): given object doesn't have exactly one element" ); out_eT out; arrayops::convert_cx_scalar(out, X.mem[0]); return out; } //! conversion to Armadillo matrices from Armadillo Base objects, as well as from std::vector template class conv_to< Mat > { public: template inline static Mat from(const Base& in, const typename arma_not_cx::result* junk = 0); template inline static Mat from(const Base& in, const typename arma_cx_only::result* junk = 0); template inline static Mat from(const std::vector& in, const typename arma_not_cx::result* junk = 0); template inline static Mat from(const std::vector& in, const typename arma_cx_only::result* junk = 0); }; template template inline Mat conv_to< Mat >::from(const Base& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap tmp(in.get_ref()); const Mat& X = tmp.M; Mat out(X.n_rows, X.n_cols); arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); return out; } template template inline Mat conv_to< Mat >::from(const Base& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap tmp(in.get_ref()); const Mat& X = tmp.M; Mat out(X.n_rows, X.n_cols); arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); return out; } template template inline Mat conv_to< Mat >::from(const std::vector& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword N = uword( in.size() ); Mat out(N, 1); if(N > 0) { out_eT* out_mem = out.memptr(); const in_eT* in_mem = &(in[0]); for(uword i=0; i template inline Mat conv_to< Mat >::from(const std::vector& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); Mat out(in.size(), 1); typename std::vector::const_iterator in_begin = in.begin(); typename std::vector::const_iterator in_end = in.end(); typename Mat::iterator out_begin = out.begin(); typename Mat::iterator out_end = out.end(); typename std::vector::const_iterator in_it; typename Mat::iterator out_it; for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it) { out_eT& out_elem = (*out_it); const in_eT& in_elem = (*in_it); arrayops::convert_cx_scalar(out_elem, in_elem); } return out; } //! conversion to Armadillo row vectors from Armadillo Base objects, as well as from std::vector template class conv_to< Row > { public: template inline static Row from(const Base& in, const typename arma_not_cx::result* junk = 0); template inline static Row from(const Base& in, const typename arma_cx_only::result* junk = 0); template inline static Row from(const std::vector& in, const typename arma_not_cx::result* junk = 0); template inline static Row from(const std::vector& in, const typename arma_cx_only::result* junk = 0); }; template template inline Row conv_to< Row >::from(const Base& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); Row out(X.n_elem); arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); return out; } template template inline Row conv_to< Row >::from(const Base& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); Row out(X.n_rows, X.n_cols); arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); return out; } template template inline Row conv_to< Row >::from(const std::vector& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword N = uword( in.size() ); Row out(N); if(N > 0) { out_eT* out_mem = out.memptr(); const in_eT* in_mem = &(in[0]); for(uword i=0; i template inline Row conv_to< Row >::from(const std::vector& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); Row out( in.size() ); typename std::vector::const_iterator in_begin = in.begin(); typename std::vector::const_iterator in_end = in.end(); typename Row::iterator out_begin = out.begin(); typename Row::iterator out_end = out.end(); typename std::vector::const_iterator in_it; typename Row::iterator out_it; for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it) { out_eT& out_elem = (*out_it); const in_eT& in_elem = (*in_it); arrayops::convert_cx_scalar(out_elem, in_elem); } return out; } //! conversion to Armadillo column vectors from Armadillo Base objects, as well as from std::vector template class conv_to< Col > { public: template inline static Col from(const Base& in, const typename arma_not_cx::result* junk = 0); template inline static Col from(const Base& in, const typename arma_cx_only::result* junk = 0); template inline static Col from(const std::vector& in, const typename arma_not_cx::result* junk = 0); template inline static Col from(const std::vector& in, const typename arma_cx_only::result* junk = 0); }; template template inline Col conv_to< Col >::from(const Base& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); Col out(X.n_elem); arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); return out; } template template inline Col conv_to< Col >::from(const Base& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); Col out(X.n_rows, X.n_cols); arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); return out; } template template inline Col conv_to< Col >::from(const std::vector& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword N = uword( in.size() ); Col out(N); if(N > 0) { out_eT* out_mem = out.memptr(); const in_eT* in_mem = &(in[0]); for(uword i=0; i template inline Col conv_to< Col >::from(const std::vector& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); Col out( in.size() ); typename std::vector::const_iterator in_begin = in.begin(); typename std::vector::const_iterator in_end = in.end(); typename Col::iterator out_begin = out.begin(); typename Col::iterator out_end = out.end(); typename std::vector::const_iterator in_it; typename Col::iterator out_it; for(in_it = in_begin, out_it = out_begin; (in_it != in_end) && (out_it != out_end); ++in_it, ++out_it) { out_eT& out_elem = (*out_it); const in_eT& in_elem = (*in_it); arrayops::convert_cx_scalar(out_elem, in_elem); } return out; } //! conversion to Armadillo cubes from Armadillo BaseCube objects template class conv_to< Cube > { public: template inline static Cube from(const BaseCube& in, const typename arma_not_cx::result* junk = 0); template inline static Cube from(const BaseCube& in, const typename arma_cx_only::result* junk = 0); }; template template inline Cube conv_to< Cube >::from(const BaseCube& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap_cube tmp( in.get_ref() ); const Cube& X = tmp.M; Cube out(X.n_rows, X.n_cols, X.n_slices); arrayops::convert( out.memptr(), X.memptr(), out.n_elem ); return out; } template template inline Cube conv_to< Cube >::from(const BaseCube& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap_cube tmp( in.get_ref() ); const Cube& X = tmp.M; Cube out(X.n_rows, X.n_cols, X.n_slices); arrayops::convert_cx( out.memptr(), X.memptr(), out.n_elem ); return out; } //! conversion to std::vector from Armadillo Base objects template class conv_to< std::vector > { public: template inline static std::vector from(const Base& in, const typename arma_not_cx::result* junk = 0); template inline static std::vector from(const Base& in, const typename arma_cx_only::result* junk = 0); }; template template inline std::vector conv_to< std::vector >::from(const Base& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); const uword N = X.n_elem; std::vector out(N); if(N > 0) { out_eT* out_mem = &(out[0]); const in_eT* X_mem = X.memptr(); for(uword i=0; i template inline std::vector conv_to< std::vector >::from(const Base& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); std::vector out(X.n_elem); typename Mat::const_iterator X_begin = X.begin(); typename Mat::const_iterator X_end = X.end(); typename std::vector::iterator out_begin = out.begin(); typename std::vector::iterator out_end = out.end(); typename Mat::const_iterator X_it; typename std::vector::iterator out_it; for(X_it = X_begin, out_it = out_begin; (X_it != X_end) && (out_it != out_end); ++X_it, ++out_it) { out_eT& out_elem = (*out_it); const in_eT& X_elem = (*X_it); arrayops::convert_cx_scalar(out_elem, X_elem); } return out; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_any_bones.hpp0000644000176000001440000000264412200726565023617 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_any //! @{ class op_any { public: template static inline bool any_vec_helper(const Base& X); template static inline bool any_vec_helper ( const mtOp& X, const typename arma_op_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0 ); template static inline bool any_vec_helper ( const mtGlue& X, const typename arma_glue_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0, const typename arma_not_cx::result junk3 = 0 ); template static inline bool any_vec(T1& X); template static inline void apply_helper(Mat& out, const Proxy& P, const uword dim); template static inline void apply(Mat& out, const mtOp& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_misc_bones.hpp0000644000176000001440000000243112262045120023742 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_misc //! @{ class op_real { public: template inline static void apply( Mat& out, const mtOp& X); template inline static void apply( Cube& out, const mtOpCube& X); }; class op_imag { public: template inline static void apply( Mat& out, const mtOp& X); template inline static void apply( Cube& out, const mtOpCube& X); }; class op_abs { public: template inline static void apply( Mat& out, const mtOp& X); template inline static void apply( Cube& out, const mtOpCube& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/SpRow_meat.hpp0000644000176000001440000003075512111344723023221 0ustar ripleyusers// Copyright (C) 2011-2012 Ryan Curtin // Copyright (C) 2011 Matthew Amidon // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpRow //! @{ template inline SpRow::SpRow() : SpMat(1, 0) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; } template inline SpRow::SpRow(const uword in_n_elem) : SpMat(1, in_n_elem) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; } template inline SpRow::SpRow(const uword in_n_rows, const uword in_n_cols) : SpMat(in_n_rows, in_n_cols) { arma_extra_debug_sigprint(); arma_debug_check((in_n_rows != 1), "SpRow::SpRow(): must have only one row"); access::rw(SpMat::vec_state) = 2; } template inline SpRow::SpRow(const char* text) : SpMat(text) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; arma_debug_check((SpMat::n_rows != 1), "SpRow::SpRow(): must have only one row"); } template inline const SpRow& SpRow::operator=(const char* text) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; SpMat::operator=(text); return *this; } template inline SpRow::SpRow(const std::string& text) : SpMat(text) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; arma_debug_check((SpMat::n_rows != 1), "SpRow::SpRow(): must have only one row"); } template inline const SpRow& SpRow::operator=(const std::string& text) { arma_extra_debug_sigprint(); SpMat::operator=(text); return *this; } template inline const SpRow& SpRow::operator=(const eT val) { arma_extra_debug_sigprint(); SpMat::operator=(val); return *this; } template template inline SpRow::SpRow(const Base& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; SpMat::operator=(X.get_ref()); } template template inline const SpRow& SpRow::operator=(const Base& X) { arma_extra_debug_sigprint(); SpMat::operator=(X.get_ref()); return *this; } template template inline SpRow::SpRow(const SpBase& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; SpMat::operator=(X.get_ref()); } template template inline const SpRow& SpRow::operator=(const SpBase& X) { arma_extra_debug_sigprint(); SpMat::operator=(X.get_ref()); return *this; } template template inline SpRow::SpRow ( const SpBase::pod_type, T1>& A, const SpBase::pod_type, T2>& B ) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; SpMat::init(A,B); } template inline SpValProxy< SpMat > SpRow::col(const uword col_num) { arma_debug_check( (col_num >= SpMat::n_cols), "SpRow::col(): out of bounds" ); return SpMat::at(0, col_num); } template inline eT SpRow::col(const uword col_num) const { arma_debug_check( (col_num >= SpMat::n_cols), "SpRow::col(): out of bounds" ); return SpMat::at(0, col_num); } /* template arma_inline subview_row SpRow::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "SpRow::cols(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline const subview_row SpRow::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "SpRow::cols(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline subview_row SpRow::subvec(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "SpRow::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline const subview_row SpRow::subvec(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "SpRow::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline subview_row SpRow::subvec(const span& col_span) { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = Mat::n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subvec_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ), "SpRow::subvec(): indices out of bounds or incorrectly used"); return subview_row(*this, 0, in_col1, subvec_n_cols); } template arma_inline const subview_row SpRow::subvec(const span& col_span) const { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = Mat::n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subvec_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ), "SpRow::subvec(): indices out of bounds or incorrectly used"); return subview_row(*this, 0, in_col1, subvec_n_cols); } */ // template // arma_inline // subview_row // SpRow::operator()(const span& col_span) // { // arma_extra_debug_sigprint(); // // return subvec(col_span); // } // // // // template // arma_inline // const subview_row // SpRow::operator()(const span& col_span) const // { // arma_extra_debug_sigprint(); // // return subvec(col_span); // } //! remove specified columns template inline void SpRow::shed_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= SpMat::n_cols, "SpRow::shed_col(): out of bounds"); shed_cols(col_num, col_num); } //! remove specified columns template inline void SpRow::shed_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= SpMat::n_cols), "SpRow::shed_cols(): indices out of bounds or incorrectly used" ); const uword diff = (in_col2 - in_col1 + 1); // This is doubleplus easy because we have all the column pointers stored. const uword start = SpMat::col_ptrs[in_col1]; const uword end = SpMat::col_ptrs[in_col2 + 1]; if (start != end) { const uword elem_diff = end - start; eT* new_values = memory::acquire_chunked (SpMat::n_nonzero - elem_diff); uword* new_row_indices = memory::acquire_chunked(SpMat::n_nonzero - elem_diff); // Copy first set of elements, if necessary. if (start > 0) { arrayops::copy(new_values, SpMat::values, start); arrayops::copy(new_row_indices, SpMat::row_indices, start); } // Copy last set of elements, if necessary. if (end != SpMat::n_nonzero) { arrayops::copy(new_values + start, SpMat::values + end, (SpMat::n_nonzero - end)); arrayops::copy(new_row_indices + start, SpMat::row_indices + end, (SpMat::n_nonzero - end)); } memory::release(SpMat::values); memory::release(SpMat::row_indices); access::rw(SpMat::values) = new_values; access::rw(SpMat::row_indices) = new_row_indices; access::rw(SpMat::n_nonzero) -= elem_diff; } // Update column pointers. uword* new_col_ptrs = memory::acquire(SpMat::n_cols - diff + 1); // Copy first part of column pointers. if (in_col1 > 0) { arrayops::copy(new_col_ptrs, SpMat::col_ptrs, in_col1); } // Copy last part of column pointers (and adjust their values as necessary). if (in_col2 < SpMat::n_cols - 1) { arrayops::copy(new_col_ptrs + in_col1, SpMat::col_ptrs + in_col2 + 1, SpMat::n_cols - in_col2); // Modify their values. arrayops::inplace_minus(new_col_ptrs + in_col1, (end - start), SpMat::n_cols - in_col2); } memory::release(SpMat::col_ptrs); access::rw(SpMat::col_ptrs) = new_col_ptrs; access::rw(SpMat::n_cols) -= diff; access::rw(SpMat::n_elem) -= diff; } // //! insert N cols at the specified col position, // //! optionally setting the elements of the inserted cols to zero // template // inline // void // SpRow::insert_cols(const uword col_num, const uword N, const bool set_to_zero) // { // arma_extra_debug_sigprint(); // // // insertion at col_num == n_cols is in effect an append operation // arma_debug_check( (col_num > SpMat::n_cols), "SpRow::insert_cols(): out of bounds"); // // arma_debug_check( (set_to_zero == false), "SpRow::insert_cols(): cannot set elements to nonzero values"); // // uword newVal = (col_num == 0) ? 0 : SpMat::col_ptrs[col_num]; // SpMat::col_ptrs.insert(col_num, N, newVal); // uword* new_col_ptrs = memory::acquire(SpMat::n_cols + N); // // arrayops::copy(new_col_ptrs, SpMat::col_ptrs, col_num); // // uword fill_value = (col_num == 0) ? 0 : SpMat::col_ptrs[col_num - 1]; // arrayops::inplace_set(new_col_ptrs + col_num, fill_value, N); // // arrayops::copy(new_col_ptrs + col_num + N, SpMat::col_ptrs + col_num, SpMat::n_cols - col_num); // // access::rw(SpMat::n_cols) += N; // access::rw(SpMat::n_elem) += N; // } // // // // //! insert the given object at the specified col position; // //! the given object must have one row // template // template // inline // void // SpRow::insert_cols(const uword col_num, const Base& X) // { // arma_extra_debug_sigprint(); // // SpMat::insert_cols(col_num, X); // } template inline typename SpRow::row_iterator SpRow::begin_row(const uword row_num) { arma_extra_debug_sigprint(); // Since this is a row, row_num can only be 0. But the option is provided for // compatibility. arma_debug_check((row_num >= 1), "SpRow::row(): invalid row index"); return SpMat::begin(); } template inline typename SpRow::const_row_iterator SpRow::begin_row(const uword row_num) const { arma_extra_debug_sigprint(); // Since this is a row, row_num can only be 0. But the option is provided for // compatibility. arma_debug_check((row_num >= 1), "SpRow::row(): invalid row index"); return SpMat::begin(); } template inline typename SpRow::row_iterator SpRow::end_row(const uword row_num) { arma_extra_debug_sigprint(); // Since this is a row, row_num can only be 0. But the option is provided for // compatibility. arma_debug_check((row_num >= 1), "SpRow::row(): invalid row index"); return SpMat::end(); } template inline typename SpRow::const_row_iterator SpRow::end_row(const uword row_num) const { arma_extra_debug_sigprint(); // Since this is a row, row_num can only be 0. But the option is provided for // compatibility. arma_debug_check((row_num >= 1), "SpRow::row(): invalid row index"); return SpMat::end(); } #ifdef ARMA_EXTRA_SPROW_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPROW_MEAT) #endif //! @} RcppArmadillo/inst/include/armadillo_bits/op_sort_meat.hpp0000644000176000001440000001034112200631217023615 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_sort //! @{ template class arma_ascend_sort_helper { public: arma_inline bool operator() (eT a, eT b) const { return (a < b); } }; template class arma_descend_sort_helper { public: arma_inline bool operator() (eT a, eT b) const { return (a > b); } }; template class arma_ascend_sort_helper< std::complex > { public: typedef typename std::complex eT; inline bool operator() (const eT& a, const eT& b) const { return (std::abs(a) < std::abs(b)); } }; template class arma_descend_sort_helper< std::complex > { public: typedef typename std::complex eT; inline bool operator() (const eT& a, const eT& b) const { return (std::abs(a) > std::abs(b)); } }; template inline void op_sort::direct_sort(eT* X, const uword n_elem, const uword sort_type) { arma_extra_debug_sigprint(); if(sort_type == 0) { arma_ascend_sort_helper comparator; std::sort(&X[0], &X[n_elem], comparator); } else { arma_descend_sort_helper comparator; std::sort(&X[0], &X[n_elem], comparator); } } template inline void op_sort::direct_sort_ascending(eT* X, const uword n_elem) { arma_extra_debug_sigprint(); arma_ascend_sort_helper comparator; std::sort(&X[0], &X[n_elem], comparator); } template inline void op_sort::copy_row(eT* X, const Mat& A, const uword row) { const uword N = A.n_cols; uword i,j; for(i=0, j=1; j inline void op_sort::copy_row(Mat& A, const eT* X, const uword row) { const uword N = A.n_cols; uword i,j; for(i=0, j=1; j inline void op_sort::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; const uword sort_type = in.aux_uword_a; const uword dim = in.aux_uword_b; arma_debug_check( (sort_type > 1), "sort(): incorrect usage. sort_type must be 0 or 1"); arma_debug_check( (dim > 1), "sort(): incorrect usage. dim must be 0 or 1" ); arma_debug_check( (X.is_finite() == false), "sort(): given object has non-finite elements" ); if( (X.n_rows * X.n_cols) <= 1 ) { out = X; return; } if(dim == 0) // sort the contents of each column { arma_extra_debug_print("op_sort::apply(), dim = 0"); out = X; const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; for(uword col=0; col < n_cols; ++col) { op_sort::direct_sort( out.colptr(col), n_rows, sort_type ); } } else if(dim == 1) // sort the contents of each row { if(X.n_rows == 1) // a row vector { arma_extra_debug_print("op_sort::apply(), dim = 1, vector specific"); out = X; op_sort::direct_sort(out.memptr(), out.n_elem, sort_type); } else // not a row vector { arma_extra_debug_print("op_sort::apply(), dim = 1, generic"); out.copy_size(X); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; podarray tmp_array(n_cols); for(uword row=0; row < n_rows; ++row) { op_sort::copy_row(tmp_array.memptr(), X, row); op_sort::direct_sort( tmp_array.memptr(), n_cols, sort_type ); op_sort::copy_row(out, tmp_array.memptr(), row); } } } } //! @} RcppArmadillo/inst/include/armadillo_bits/op_stddev_meat.hpp0000644000176000001440000000425512200631217024126 0ustar ripleyusers// Copyright (C) 2009-2011 Conrad Sanderson // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_stddev //! @{ //! \brief //! For each row or for each column, find the standard deviation. //! The result is stored in a dense matrix that has either one column or one row. //! The dimension for which the standard deviations are found is set via the stddev() function. template inline void op_stddev::apply(Mat& out, const mtOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type in_eT; typedef typename T1::pod_type out_eT; const unwrap_check_mixed tmp(in.m, out); const Mat& X = tmp.M; const uword norm_type = in.aux_uword_a; const uword dim = in.aux_uword_b; arma_debug_check( (norm_type > 1), "stddev(): incorrect usage. norm_type must be 0 or 1"); arma_debug_check( (dim > 1), "stddev(): incorrect usage. dim must be 0 or 1" ); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_stddev::apply(), dim = 0"); arma_debug_check( (X_n_rows == 0), "stddev(): given object has zero rows" ); out.set_size(1, X_n_cols); out_eT* out_mem = out.memptr(); for(uword col=0; col dat(X_n_cols); in_eT* dat_mem = dat.memptr(); out_eT* out_mem = out.memptr(); for(uword row=0; row arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator/ ( const T1& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOp(X, k); } //! scalar / Base template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator/ ( const typename T1::elem_type k, const T1& X ) { arma_extra_debug_sigprint(); return eOp(X, k); } //! complex scalar / non-complex Base template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_div_pre> >::result operator/ ( const std::complex& k, const T1& X ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_div_pre>('j', X, k); } //! non-complex Base / complex scalar template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_div_post> >::result operator/ ( const T1& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_div_post>('j', X, k); } //! element-wise division of Base objects with same element type template arma_inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && is_same_type::value), const eGlue >::result operator/ ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return eGlue(X, Y); } //! element-wise division of Base objects with different element types template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_same_type::no)), const mtGlue::result, T1, T2, glue_mixed_div> >::result operator/ ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlue( X, Y ); } //! element-wise division of sparse matrix by scalar template inline typename enable_if2::value, SpMat >::result operator/ ( const T1& X, const typename T1::elem_type y ) { arma_extra_debug_sigprint(); SpMat result(X); result /= y; return result; } //! element-wise division of one sparse and one dense object template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_type::value && is_same_type::value), SpMat >::result operator/ ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(x); const Proxy pb(y); const uword n_rows = pa.get_n_rows(); const uword n_cols = pa.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, pb.get_n_rows(), pb.get_n_cols(), "element-wise division"); SpMat result(n_rows, n_cols); uword new_n_nonzero = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT val = pa.at(row,col) / pb.at(row, col); if(val != eT(0)) { ++new_n_nonzero; } } result.mem_resize(new_n_nonzero); uword cur_pos = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT val = pa.at(row,col) / pb.at(row, col); if(val != eT(0)) { access::rw(result.values[cur_pos]) = val; access::rw(result.row_indices[cur_pos]) = row; ++access::rw(result.col_ptrs[col + 1]); ++cur_pos; } } // Fix column pointers for(uword col = 1; col <= result.n_cols; ++col) { access::rw(result.col_ptrs[col]) += result.col_ptrs[col - 1]; } return result; } //! element-wise division of one dense and one sparse object template inline typename enable_if2 < (is_arma_type::value && is_arma_sparse_type::value && is_same_type::value), Mat >::result operator/ ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy pa(x); const SpProxy pb(y); const uword n_rows = pa.get_n_rows(); const uword n_cols = pa.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, pb.get_n_rows(), pb.get_n_cols(), "element-wise division"); Mat result(n_rows, n_cols); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { result.at(row, col) = pa.at(row, col) / pb.at(row, col); } return result; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_fft_meat.hpp0000644000176000001440000001773312222743646023437 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_fft //! @{ // // op_fft_real template inline void op_fft_real::apply( Mat< std::complex >& out, const mtOp,T1,op_fft_real>& in ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type in_eT; typedef typename std::complex out_eT; const Proxy P(in.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_elem = P.get_n_elem(); const bool is_vec = ( (n_rows == 1) || (n_cols == 1) ); const uword N_orig = (is_vec) ? n_elem : n_rows; const uword N_user = (in.aux_uword_b == 0) ? in.aux_uword_a : N_orig; fft_engine worker(N_user); // no need to worry about aliasing, as we're going from a real object to complex complex, which by definition cannot alias if(is_vec) { (n_cols == 1) ? out.set_size(N_user, 1) : out.set_size(1, N_user); if( (out.n_elem == 0) || (N_orig == 0) ) { out.zeros(); return; } if( (N_user == 1) && (N_orig >= 1) ) { out[0] = out_eT( P[0] ); return; } podarray data(N_user); out_eT* data_mem = data.memptr(); if(N_user > N_orig) { arrayops::fill_zeros( &data_mem[N_orig], (N_user - N_orig) ); } const uword N = (std::min)(N_user, N_orig); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type X = P.get_ea(); for(uword i=0; i < N; ++i) { data_mem[i] = out_eT( X[i], in_eT(0) ); } } else { if(n_cols == 1) { for(uword i=0; i < N; ++i) { data_mem[i] = out_eT( P.at(i,0), in_eT(0) ); } } else { for(uword i=0; i < N; ++i) { data_mem[i] = out_eT( P.at(0,i), in_eT(0) ); } } } worker.run( out.memptr(), data_mem ); } else { // process each column seperately out.set_size(N_user, n_cols); if( (out.n_elem == 0) || (N_orig == 0) ) { out.zeros(); return; } if( (N_user == 1) && (N_orig >= 1) ) { for(uword col=0; col < n_cols; ++col) { out.at(0,col) = out_eT( P.at(0,col) ); } return; } podarray data(N_user); out_eT* data_mem = data.memptr(); if(N_user > N_orig) { arrayops::fill_zeros( &data_mem[N_orig], (N_user - N_orig) ); } const uword N = (std::min)(N_user, N_orig); for(uword col=0; col < n_cols; ++col) { for(uword i=0; i < N; ++i) { data_mem[i] = P.at(i, col); } worker.run( out.colptr(col), data_mem ); } } } // // op_fft_cx template inline void op_fft_cx::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(in.m); if(P.is_alias(out) == false) { op_fft_cx::apply_noalias(out, P, in.aux_uword_a, in.aux_uword_b); } else { Mat tmp; op_fft_cx::apply_noalias(tmp, P, in.aux_uword_a, in.aux_uword_b); out.steal_mem(tmp); } } template inline void op_fft_cx::apply_noalias(Mat& out, const Proxy& P, const uword a, const uword b) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_elem = P.get_n_elem(); const bool is_vec = ( (n_rows == 1) || (n_cols == 1) ); const uword N_orig = (is_vec) ? n_elem : n_rows; const uword N_user = (b == 0) ? a : N_orig; fft_engine worker(N_user); if(is_vec) { (n_cols == 1) ? out.set_size(N_user, 1) : out.set_size(1, N_user); if( (out.n_elem == 0) || (N_orig == 0) ) { out.zeros(); return; } if( (N_user == 1) && (N_orig >= 1) ) { out[0] = P[0]; return; } if( (N_user > N_orig) || (is_Mat::stored_type>::value == false) ) { podarray data(N_user); eT* data_mem = data.memptr(); if(N_user > N_orig) { arrayops::fill_zeros( &data_mem[N_orig], (N_user - N_orig) ); } op_fft_cx::copy_vec( data_mem, P, (std::min)(N_user, N_orig) ); worker.run( out.memptr(), data_mem ); } else { const unwrap< typename Proxy::stored_type > tmp(P.Q); worker.run( out.memptr(), tmp.M.memptr() ); } } else { // process each column seperately out.set_size(N_user, n_cols); if( (out.n_elem == 0) || (N_orig == 0) ) { out.zeros(); return; } if( (N_user == 1) && (N_orig >= 1) ) { for(uword col=0; col < n_cols; ++col) { out.at(0,col) = P.at(0,col); } return; } if( (N_user > N_orig) || (is_Mat::stored_type>::value == false) ) { podarray data(N_user); eT* data_mem = data.memptr(); if(N_user > N_orig) { arrayops::fill_zeros( &data_mem[N_orig], (N_user - N_orig) ); } const uword N = (std::min)(N_user, N_orig); for(uword col=0; col < n_cols; ++col) { for(uword i=0; i < N; ++i) { data_mem[i] = P.at(i, col); } worker.run( out.colptr(col), data_mem ); } } else { const unwrap< typename Proxy::stored_type > tmp(P.Q); for(uword col=0; col < n_cols; ++col) { worker.run( out.colptr(col), tmp.M.colptr(col) ); } } } // correct the scaling for the inverse transform if(inverse == true) { typedef typename get_pod_type::result T; const T k = T(1) / T(N_user); eT* out_mem = out.memptr(); const uword out_n_elem = out.n_elem; for(uword i=0; i < out_n_elem; ++i) { out_mem[i] *= k; } } } template arma_hot inline void op_fft_cx::copy_vec(typename Proxy::elem_type* dest, const Proxy& P, const uword N) { arma_extra_debug_sigprint(); if(is_Mat< typename Proxy::stored_type >::value == true) { op_fft_cx::copy_vec_unwrap(dest, P, N); } else { op_fft_cx::copy_vec_proxy(dest, P, N); } } template arma_hot inline void op_fft_cx::copy_vec_unwrap(typename Proxy::elem_type* dest, const Proxy& P, const uword N) { arma_extra_debug_sigprint(); const unwrap< typename Proxy::stored_type > tmp(P.Q); arrayops::copy(dest, tmp.M.memptr(), N); } template arma_hot inline void op_fft_cx::copy_vec_proxy(typename Proxy::elem_type* dest, const Proxy& P, const uword N) { arma_extra_debug_sigprint(); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type X = P.get_ea(); for(uword i=0; i < N; ++i) { dest[i] = X[i]; } } else { if(P.get_n_cols() == 1) { for(uword i=0; i < N; ++i) { dest[i] = P.at(i,0); } } else { for(uword i=0; i < N; ++i) { dest[i] = P.at(0,i); } } } } // // op_ifft_cx template inline void op_ifft_cx::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(in.m); if(P.is_alias(out) == false) { op_fft_cx::apply_noalias(out, P, in.aux_uword_a, in.aux_uword_b); } else { Mat tmp; op_fft_cx::apply_noalias(tmp, P, in.aux_uword_a, in.aux_uword_b); out.steal_mem(tmp); } } //! @} RcppArmadillo/inst/include/armadillo_bits/GlueCube_meat.hpp0000644000176000001440000000140512176655102023637 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup GlueCube //! @{ template inline GlueCube::GlueCube(const BaseCube& in_A, const BaseCube& in_B) : A(in_A.get_ref()) , B(in_B.get_ref()) { arma_extra_debug_sigprint(); } template inline GlueCube::~GlueCube() { arma_extra_debug_sigprint(); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_cumsum.hpp0000644000176000001440000000444212200375542023131 0ustar ripleyusers// Copyright (C) 2010-2012 Conrad Sanderson // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_cumsum //! @{ template arma_inline const Op cumsum ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op cumsum ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template arma_inline const Op cumsum ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X); } template arma_inline const Op, op_cumsum_mat> cumsum ( const Op& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op, op_cumsum_mat>(X, dim, 0); } template arma_inline const Op, op_cumsum_vec> cumsum ( const Op& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op, op_cumsum_vec>(X); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & cumsum(const T& x) { return x; } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_cor_meat.hpp0000644000176000001440000001031412200375542023735 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_cor //! @{ template inline void glue_cor::direct_cor(Mat& out, const Mat& A, const Mat& B, const uword norm_type) { arma_extra_debug_sigprint(); if(A.is_empty() || B.is_empty() ) { out.reset(); return; } if(A.is_vec() && B.is_vec()) { arma_debug_check( (A.n_elem != B.n_elem), "cor(): the number of elements in the two vectors must match" ); const eT* A_ptr = A.memptr(); const eT* B_ptr = B.memptr(); eT A_acc = eT(0); eT B_acc = eT(0); eT out_acc = eT(0); const uword N = A.n_elem; for(uword i=0; i 1) ? eT(N-1) : eT(1) ) : eT(N); out.set_size(1,1); out[0] = out_acc/norm_val; const Mat stddev_A = (A.n_rows == 1) ? Mat(stddev(trans(A))) : Mat(stddev(A)); const Mat stddev_B = (B.n_rows == 1) ? Mat(stddev(trans(B))) : Mat(stddev(B)); out /= stddev_A * stddev_B; } else { arma_debug_assert_mul_size(A, B, true, false, "cor()"); const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); out = trans(A) * B; out -= (trans(sum(A)) * sum(B))/eT(N); out /= norm_val; out /= trans(stddev(A)) * stddev(B); } } template inline void glue_cor::direct_cor(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat< std::complex >& B, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(A.is_empty() || B.is_empty() ) { out.reset(); return; } if(A.is_vec() && B.is_vec()) { arma_debug_check( (A.n_elem != B.n_elem), "cor(): the number of elements in the two vectors must match" ); const eT* A_ptr = A.memptr(); const eT* B_ptr = B.memptr(); eT A_acc = eT(0); eT B_acc = eT(0); eT out_acc = eT(0); const uword N = A.n_elem; for(uword i=0; i 1) ? eT(N-1) : eT(1) ) : eT(N); out.set_size(1,1); out[0] = out_acc/norm_val; const Mat stddev_A = (A.n_rows == 1) ? Mat(stddev(trans(A))) : Mat(stddev(A)); const Mat stddev_B = (B.n_rows == 1) ? Mat(stddev(trans(B))) : Mat(stddev(B)); out /= conv_to< Mat >::from( stddev_A * stddev_B ); } else { arma_debug_assert_mul_size(A, B, true, false, "cor()"); const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); out = trans(A) * B; // out = strans(conj(A)) * B; out -= (trans(sum(A)) * sum(B))/eT(N); // out -= (strans(conj(sum(A))) * sum(B))/eT(N); out /= norm_val; out /= conv_to< Mat >::from( trans(stddev(A)) * stddev(B) ); } } template inline void glue_cor::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check A_tmp(X.A, out); const unwrap_check B_tmp(X.B, out); const Mat& A = A_tmp.M; const Mat& B = B_tmp.M; const uword norm_type = X.aux_uword; if(&A != &B) { glue_cor::direct_cor(out, A, B, norm_type); } else { op_cor::direct_cor(out, A, norm_type); } } //! @} RcppArmadillo/inst/include/armadillo_bits/spop_sum_meat.hpp0000644000176000001440000000323712111344723024007 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_sum //! @{ template arma_hot inline void spop_sum::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check((dim > 1), "sum(): incorrect usage. dim must be 0 or 1"); const SpProxy p(in.m); if(p.is_alias(out) == false) { spop_sum::apply_noalias(out, p, dim); } else { SpMat tmp; spop_sum::apply_noalias(tmp, p, dim); out.steal_mem(tmp); } } template arma_hot inline void spop_sum::apply_noalias(SpMat& out, const SpProxy& p, const uword dim) { arma_extra_debug_sigprint(); if(dim == 0) // find the sum in each column { out.zeros(1, p.get_n_cols()); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { out.at(0, it.col()) += (*it); ++it; } } else // find the sum in each row { out.zeros(p.get_n_rows(), 1); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { out.at(it.row(), 0) += (*it); ++it; } } } //! @} RcppArmadillo/inst/include/armadillo_bits/running_stat_meat.hpp0000644000176000001440000001742212247631767024677 0ustar ripleyusers// Copyright (C) 2009-2011 Conrad Sanderson // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup running_stat //! @{ template inline arma_counter::~arma_counter() { arma_extra_debug_sigprint_this(this); } template inline arma_counter::arma_counter() : d_count( eT(0)) , i_count(uword(0)) { arma_extra_debug_sigprint_this(this); } template inline const arma_counter& arma_counter::operator++() { if(i_count < ARMA_MAX_UWORD) { i_count++; } else { d_count += eT(ARMA_MAX_UWORD); i_count = 1; } return *this; } template inline void arma_counter::operator++(int) { operator++(); } template inline void arma_counter::reset() { d_count = eT(0); i_count = uword(0); } template inline eT arma_counter::value() const { return d_count + eT(i_count); } template inline eT arma_counter::value_plus_1() const { if(i_count < ARMA_MAX_UWORD) { return d_count + eT(i_count + 1); } else { return d_count + eT(ARMA_MAX_UWORD) + eT(1); } } template inline eT arma_counter::value_minus_1() const { if(i_count > 0) { return d_count + eT(i_count - 1); } else { return d_count - eT(1); } } // template running_stat::~running_stat() { arma_extra_debug_sigprint_this(this); } template running_stat::running_stat() : r_mean ( eT(0)) , r_var (typename running_stat::T(0)) , min_val ( eT(0)) , max_val ( eT(0)) , min_val_norm(typename running_stat::T(0)) , max_val_norm(typename running_stat::T(0)) { arma_extra_debug_sigprint_this(this); } //! update statistics to reflect new sample template inline void running_stat::operator() (const typename running_stat::T sample) { arma_extra_debug_sigprint(); if( arma_isfinite(sample) == false ) { arma_warn(true, "running_stat: sample ignored as it is non-finite" ); return; } running_stat_aux::update_stats(*this, sample); } //! update statistics to reflect new sample (version for complex numbers) template inline void running_stat::operator() (const std::complex< typename running_stat::T >& sample) { arma_extra_debug_sigprint(); if( arma_isfinite(sample) == false ) { arma_warn(true, "running_stat: sample ignored as it is non-finite" ); return; } running_stat_aux::update_stats(*this, sample); } //! set all statistics to zero template inline void running_stat::reset() { arma_extra_debug_sigprint(); // typedef typename running_stat::T T; counter.reset(); r_mean = eT(0); r_var = T(0); min_val = eT(0); max_val = eT(0); min_val_norm = T(0); max_val_norm = T(0); } //! mean or average value template inline eT running_stat::mean() const { arma_extra_debug_sigprint(); return r_mean; } //! variance template inline typename running_stat::T running_stat::var(const uword norm_type) const { arma_extra_debug_sigprint(); const T N = counter.value(); if(N > T(1)) { if(norm_type == 0) { return r_var; } else { const T N_minus_1 = counter.value_minus_1(); return (N_minus_1/N) * r_var; } } else { return T(0); } } //! standard deviation template inline typename running_stat::T running_stat::stddev(const uword norm_type) const { arma_extra_debug_sigprint(); return std::sqrt( (*this).var(norm_type) ); } //! minimum value template inline eT running_stat::min() const { arma_extra_debug_sigprint(); return min_val; } //! maximum value template inline eT running_stat::max() const { arma_extra_debug_sigprint(); return max_val; } //! number of samples so far template inline typename get_pod_type::result running_stat::count() const { arma_extra_debug_sigprint(); return counter.value(); } //! update statistics to reflect new sample (version for non-complex numbers, non-complex sample) template inline void running_stat_aux::update_stats(running_stat& x, const eT sample, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename running_stat::T T; const T N = x.counter.value(); if(N > T(0)) { if(sample < x.min_val) { x.min_val = sample; } if(sample > x.max_val) { x.max_val = sample; } const T N_plus_1 = x.counter.value_plus_1(); const T N_minus_1 = x.counter.value_minus_1(); // note: variance has to be updated before the mean const eT tmp = sample - x.r_mean; x.r_var = N_minus_1/N * x.r_var + (tmp*tmp)/N_plus_1; x.r_mean = x.r_mean + (sample - x.r_mean)/N_plus_1; //x.r_mean = (N/N_plus_1)*x.r_mean + sample/N_plus_1; //x.r_mean = (x.r_mean + sample/N) * N/N_plus_1; } else { x.r_mean = sample; x.min_val = sample; x.max_val = sample; // r_var is initialised to zero // in the constructor and reset() } x.counter++; } //! update statistics to reflect new sample (version for non-complex numbers, complex sample) template inline void running_stat_aux::update_stats(running_stat& x, const std::complex& sample, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); running_stat_aux::update_stats(x, std::real(sample)); } //! update statistics to reflect new sample (version for complex numbers, non-complex sample) template inline void running_stat_aux::update_stats(running_stat& x, const typename eT::value_type sample, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename eT::value_type T; running_stat_aux::update_stats(x, std::complex(sample)); } //! alter statistics to reflect new sample (version for complex numbers, complex sample) template inline void running_stat_aux::update_stats(running_stat& x, const eT& sample, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename eT::value_type T; const T sample_norm = std::norm(sample); const T N = x.counter.value(); if(N > T(0)) { if(sample_norm < x.min_val_norm) { x.min_val_norm = sample_norm; x.min_val = sample; } if(sample_norm > x.max_val_norm) { x.max_val_norm = sample_norm; x.max_val = sample; } const T N_plus_1 = x.counter.value_plus_1(); const T N_minus_1 = x.counter.value_minus_1(); x.r_var = N_minus_1/N * x.r_var + std::norm(sample - x.r_mean)/N_plus_1; x.r_mean = x.r_mean + (sample - x.r_mean)/N_plus_1; //x.r_mean = (N/N_plus_1)*x.r_mean + sample/N_plus_1; //x.r_mean = (x.r_mean + sample/N) * N/N_plus_1; } else { x.r_mean = sample; x.min_val = sample; x.max_val = sample; x.min_val_norm = sample_norm; x.max_val_norm = sample_norm; // r_var is initialised to zero // in the constructor and reset() } x.counter++; } //! @} RcppArmadillo/inst/include/armadillo_bits/spop_min_meat.hpp0000644000176000001440000002175112111344723023767 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_min //! @{ template inline void spop_min::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check((dim > 1), "min(): incorrect usage. dim must be 0 or 1"); const SpProxy p(in.m); if(p.is_alias(out) == false) { spop_min::apply_noalias(out, p, dim); } else { SpMat tmp; spop_min::apply_noalias(tmp, p, dim); out.steal_mem(tmp); } } template inline void spop_min::apply_noalias ( SpMat& result, const SpProxy& p, const uword dim, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; if(dim == 0) { // minimum in each column result.set_size(1, p.get_n_cols()); if(p.get_n_nonzero() == 0) { return; } typename SpProxy::const_iterator_type it = p.begin(); uword cur_col = it.col(); uword elem_in_col = 1; eT cur_min = (*it); ++it; while(it != p.end()) { if(it.col() != cur_col) { // was the column full? if(elem_in_col == p.get_n_rows()) { result.at(0, cur_col) = cur_min; } else { result.at(0, cur_col) = std::min(eT(0), cur_min); } cur_col = it.col(); elem_in_col = 0; cur_min = (*it); } else { cur_min = std::min(cur_min, *it); } ++elem_in_col; ++it; } if(elem_in_col == p.get_n_rows()) { result.at(0, cur_col) = cur_min; } else { result.at(0, cur_col) = std::min(eT(0), cur_min); } } else { // minimum in each row result.set_size(p.get_n_rows(), 1); if(p.get_n_nonzero() == 0) { return; } typename SpProxy::const_row_iterator_type it = p.begin_row(); uword cur_row = it.row(); uword elem_in_row = 1; eT cur_min = (*it); ++it; while(it.pos() < p.get_n_nonzero()) { if(it.row() != cur_row) { // was the row full? if(elem_in_row == p.get_n_cols()) { result.at(cur_row, 0) = cur_min; } else { result.at(cur_row, 0) = std::min(eT(0), cur_min); } cur_row = it.row(); elem_in_row = 0; cur_min = (*it); } else { cur_min = std::min(cur_min, *it); } ++elem_in_row; ++it; } if(elem_in_row == p.get_n_cols()) { result.at(cur_row, 0) = cur_min; } else { result.at(cur_row, 0) = std::min(eT(0), cur_min); } } } template inline void spop_min::apply_noalias ( SpMat& result, const SpProxy& p, const uword dim, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; if(dim == 0) { // minimum in each column result.set_size(1, p.get_n_cols()); if(p.get_n_nonzero() == 0) { return; } typename SpProxy::const_iterator_type it = p.begin(); uword cur_col = it.col(); uword elem_in_col = 1; eT cur_min_orig = *it; T cur_min_abs = std::abs(cur_min_orig); ++it; while(it != p.end()) { if(it.col() != cur_col) { // was the column full? if(elem_in_col == p.get_n_rows()) { result.at(0, cur_col) = cur_min_orig; } else { eT val1 = eT(0); result.at(0, cur_col) = ( std::abs(val1) < cur_min_abs ) ? val1 : cur_min_orig; } cur_col = it.col(); elem_in_col = 0; cur_min_orig = *it; cur_min_abs = std::abs(cur_min_orig); } else { eT val1_orig = *it; T val1_abs = std::abs(val1_orig); if( val1_abs < cur_min_abs ) { cur_min_abs = val1_abs; cur_min_orig = val1_orig; } } ++elem_in_col; ++it; } if(elem_in_col == p.get_n_rows()) { result.at(0, cur_col) = cur_min_orig; } else { eT val1 = eT(0); result.at(0, cur_col) = ( std::abs(val1) < cur_min_abs ) ? val1 : cur_min_orig; } } else { // minimum in each row result.set_size(p.get_n_rows(), 1); if(p.get_n_nonzero() == 0) { return; } typename SpProxy::const_row_iterator_type it = p.begin_row(); uword cur_row = it.row(); uword elem_in_row = 1; eT cur_min_orig = *it; T cur_min_abs = std::abs(cur_min_orig); ++it; while(it.pos() < p.get_n_nonzero()) { if(it.row() != cur_row) { // was the row full? if(elem_in_row == p.get_n_cols()) { result.at(cur_row, 0) = cur_min_orig; } else { eT val1 = eT(0); result.at(cur_row, 0) = ( std::abs(val1) < cur_min_abs ) ? val1 : cur_min_orig; } cur_row = it.row(); elem_in_row = 0; cur_min_orig = *it; cur_min_abs = std::abs(cur_min_orig); } else { eT val1_orig = *it; T val1_abs = std::abs(val1_orig); if( val1_abs < cur_min_abs ) { cur_min_abs = val1_abs; cur_min_orig = val1_orig; } } ++elem_in_row; ++it; } if(elem_in_row == p.get_n_cols()) { result.at(cur_row, 0) = cur_min_orig; } else { eT val1 = eT(0); result.at(cur_row, 0) = ( std::abs(val1) < cur_min_abs ) ? val1 : cur_min_orig; } } } template inline typename T1::elem_type spop_min::vector_min ( const T1& x, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const SpProxy p(x); if(p.get_n_nonzero() == 0) { return eT(0); } if(SpProxy::must_use_iterator == false) { // direct access of values if(p.get_n_nonzero() == p.get_n_elem()) { return op_min::direct_min(p.get_values(), p.get_n_nonzero()); } else { return std::min(eT(0), op_min::direct_min(p.get_values(), p.get_n_nonzero())); } } else { // use iterator typename SpProxy::const_iterator_type it = p.begin(); eT result = (*it); ++it; while(it != p.end()) { if((*it) < result) { result = (*it); } ++it; } if(p.get_n_nonzero() == p.get_n_elem()) { return result; } else { return std::min(eT(0), result); } } } template inline typename T1::elem_type spop_min::vector_min ( const T1& x, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const SpProxy p(x); if(p.get_n_nonzero() == 0) { return eT(0); } if(SpProxy::must_use_iterator == false) { // direct access of values if(p.get_n_nonzero() == p.get_n_elem()) { return op_min::direct_min(p.get_values(), p.get_n_nonzero()); } else { const eT val1 = eT(0); const eT val2 = op_min::direct_min(p.get_values(), p.get_n_nonzero()); return ( std::abs(val1) < std::abs(val2) ) ? val1 : val2; } } else { // use iterator typename SpProxy::const_iterator_type it = p.begin(); eT best_val_orig = *it; T best_val_abs = std::abs(best_val_orig); ++it; while(it != p.end()) { eT val_orig = *it; T val_abs = std::abs(val_orig); if(val_abs < best_val_abs) { best_val_abs = val_abs; best_val_orig = val_orig; } ++it; } if(p.get_n_nonzero() == p.get_n_elem()) { return best_val_orig; } else { const eT val1 = eT(0); return ( std::abs(val1) < best_val_abs ) ? val1 : best_val_orig; } } } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_kron_meat.hpp0000644000176000001440000000565112220542411024124 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_kron //! @{ //! \brief //! both input matrices have the same element type template inline void glue_kron::direct_kron(Mat& out, const Mat& A, const Mat& B) { arma_extra_debug_sigprint(); const uword A_rows = A.n_rows; const uword A_cols = A.n_cols; const uword B_rows = B.n_rows; const uword B_cols = B.n_cols; out.set_size(A_rows*B_rows, A_cols*B_cols); for(uword j = 0; j < A_cols; j++) { for(uword i = 0; i < A_rows; i++) { out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A.at(i,j) * B; } } } //! \brief //! different types of input matrices //! A -> complex, B -> basic element type template inline void glue_kron::direct_kron(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat& B) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const uword A_rows = A.n_rows; const uword A_cols = A.n_cols; const uword B_rows = B.n_rows; const uword B_cols = B.n_cols; out.set_size(A_rows*B_rows, A_cols*B_cols); Mat tmp_B = conv_to< Mat >::from(B); for(uword j = 0; j < A_cols; j++) { for(uword i = 0; i < A_rows; i++) { out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A.at(i,j) * tmp_B; } } } //! \brief //! different types of input matrices //! A -> basic element type, B -> complex template inline void glue_kron::direct_kron(Mat< std::complex >& out, const Mat& A, const Mat< std::complex >& B) { arma_extra_debug_sigprint(); const uword A_rows = A.n_rows; const uword A_cols = A.n_cols; const uword B_rows = B.n_rows; const uword B_cols = B.n_cols; out.set_size(A_rows*B_rows, A_cols*B_cols); for(uword j = 0; j < A_cols; j++) { for(uword i = 0; i < A_rows; i++) { out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A.at(i,j) * B; } } } //! \brief //! apply Kronecker product for two objects with same element type template inline void glue_kron::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap A_tmp(X.A); const unwrap B_tmp(X.B); const Mat& A = A_tmp.M; const Mat& B = B_tmp.M; if( (&out != &A) && (&out != &B) ) { glue_kron::direct_kron(out, A, B); } else { Mat tmp; glue_kron::direct_kron(tmp, A, B); out.steal_mem(tmp); } } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_spones.hpp0000644000176000001440000000137612256056330023134 0ustar ripleyusers// Copyright (C) 2012-2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_spones //! @{ //! Generate a sparse matrix with the non-zero values in the same locations as in the given sparse matrix X, //! with the non-zero values set to one template inline SpMat spones(const SpBase& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; SpMat out( X.get_ref() ); arrayops::inplace_set( access::rwp(out.values), eT(1), out.n_nonzero ); return out; } //! @} RcppArmadillo/inst/include/armadillo_bits/SizeCube_bones.hpp0000644000176000001440000000143712247362764024052 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SizeCube //! @{ class SizeCube { public: const uword n_rows; const uword n_cols; const uword n_slices; inline SizeCube(const uword in_n_rows = 0, const uword in_n_cols = 0, const uword in_n_slices = 0); // inline operator SizeMat () const; inline bool operator==(const SizeCube& s) const; inline bool operator!=(const SizeCube& s) const; inline bool operator==(const SizeMat& s) const; inline bool operator!=(const SizeMat& s) const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/upgrade_val.hpp0000644000176000001440000001105312176655102023427 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup upgrade_val //! @{ //! upgrade_val is used to ensure an operation such as multiplication is possible between two types. //! values are upgraded only where necessary. template struct upgrade_val { typedef typename promote_type::result T1_result; typedef typename promote_type::result T2_result; arma_inline static typename promote_type::result apply(const T1 x) { typedef typename promote_type::result out_type; return out_type(x); } arma_inline static typename promote_type::result apply(const T2 x) { typedef typename promote_type::result out_type; return out_type(x); } }; // template<> template struct upgrade_val { typedef T T1_result; typedef T T2_result; arma_inline static const T& apply(const T& x) { return x; } }; //! upgrade a type to allow multiplication with a complex type //! e.g. the int in "int * complex" is upgraded to a double // template<> template struct upgrade_val< std::complex, T2 > { typedef std::complex T1_result; typedef T T2_result; arma_inline static const std::complex& apply(const std::complex& x) { return x; } arma_inline static T apply(const T2 x) { return T(x); } }; // template<> template struct upgrade_val< T1, std::complex > { typedef T T1_result; typedef std::complex T2_result; arma_inline static T apply(const T1 x) { return T(x); } arma_inline static const std::complex& apply(const std::complex& x) { return x; } }; //! ensure we don't lose precision when multiplying a complex number with a higher precision real number template<> struct upgrade_val< std::complex, double > { typedef std::complex T1_result; typedef double T2_result; arma_inline static const std::complex apply(const std::complex& x) { return std::complex(x); } arma_inline static double apply(const double x) { return x; } }; template<> struct upgrade_val< double, std::complex > { typedef double T1_result; typedef std::complex T2_result; arma_inline static double apply(const double x) { return x; } arma_inline static const std::complex apply(const std::complex& x) { return std::complex(x); } }; //! ensure we don't lose precision when multiplying complex numbers with different underlying types template<> struct upgrade_val< std::complex, std::complex > { typedef std::complex T1_result; typedef std::complex T2_result; arma_inline static const std::complex apply(const std::complex& x) { return std::complex(x); } arma_inline static const std::complex& apply(const std::complex& x) { return x; } }; template<> struct upgrade_val< std::complex, std::complex > { typedef std::complex T1_result; typedef std::complex T2_result; arma_inline static const std::complex& apply(const std::complex& x) { return x; } arma_inline static const std::complex apply(const std::complex& x) { return std::complex(x); } }; //! work around limitations in the complex class (at least as present in gcc 4.1 & 4.3) template<> struct upgrade_val< std::complex, float > { typedef std::complex T1_result; typedef double T2_result; arma_inline static const std::complex& apply(const std::complex& x) { return x; } arma_inline static double apply(const float x) { return double(x); } }; template<> struct upgrade_val< float, std::complex > { typedef double T1_result; typedef std::complex T2_result; arma_inline static double apply(const float x) { return double(x); } arma_inline static const std::complex& apply(const std::complex& x) { return x; } }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_htrans_meat.hpp0000644000176000001440000002547512222720570024150 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_htrans //! @{ template arma_hot arma_inline void op_htrans::apply_mat_noalias(Mat& out, const Mat& A, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_strans::apply_mat_noalias(out, A); } template arma_hot inline void op_htrans::apply_mat_noalias(Mat& out, const Mat& A, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; out.set_size(A_n_cols, A_n_rows); if( (A_n_cols == 1) || (A_n_rows == 1) ) { const uword n_elem = A.n_elem; const eT* A_mem = A.memptr(); eT* out_mem = out.memptr(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::conj(A_mem[i]); } } else { for(uword in_row = 0; in_row < A_n_rows; ++in_row) { const uword out_col = in_row; for(uword in_col = 0; in_col < A_n_cols; ++in_col) { const uword out_row = in_col; out.at(out_row, out_col) = std::conj( A.at(in_row, in_col) ); } } } } template arma_hot arma_inline void op_htrans::apply_mat_inplace(Mat& out, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_strans::apply_mat_inplace(out); } template arma_hot inline void op_htrans::apply_mat_inplace(Mat& out, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; if(n_rows == n_cols) { arma_extra_debug_print("doing in-place hermitian transpose of a square matrix"); for(uword col=0; col < n_cols; ++col) { eT* coldata = out.colptr(col); out.at(col,col) = std::conj( out.at(col,col) ); for(uword row=(col+1); row < n_rows; ++row) { const eT val1 = std::conj(coldata[row]); const eT val2 = std::conj(out.at(col,row)); out.at(col,row) = val1; coldata[row] = val2; } } } else { Mat tmp; op_htrans::apply_mat_noalias(tmp, out); out.steal_mem(tmp); } } template arma_hot arma_inline void op_htrans::apply_mat(Mat& out, const Mat& A, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_strans::apply_mat(out, A); } template arma_hot inline void op_htrans::apply_mat(Mat& out, const Mat& A, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); if(&out != &A) { op_htrans::apply_mat_noalias(out, A); } else { op_htrans::apply_mat_inplace(out); } } template arma_hot inline void op_htrans::apply_proxy(Mat& out, const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X); // allow detection of in-place transpose if( (is_Mat::stored_type>::value == true) && (Proxy::fake_mat == false) ) { const unwrap::stored_type> tmp(P.Q); op_htrans::apply_mat(out, tmp.M); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const bool is_alias = P.is_alias(out); if( (resolves_to_vector::value == true) && (Proxy::prefer_at_accessor == false) ) { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* out_mem = out.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::conj(Pea[i]); } } else // aliasing { Mat out2(n_cols, n_rows); eT* out_mem = out2.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::conj(Pea[i]); } out.steal_mem(out2); } } else { if(is_alias == false) { out.set_size(n_cols, n_rows); for(uword k=0; k < n_cols; ++k) for(uword i=0; i < n_rows; ++i) { out.at(k,i) = std::conj(P.at(i,k)); } } else // aliasing { Mat out2(n_cols, n_rows); for(uword k=0; k < n_cols; ++k) for(uword i=0; i < n_rows; ++i) { out2.at(k,i) = std::conj(P.at(i,k)); } out.steal_mem(out2); } } } } template arma_hot inline void op_htrans::apply(Mat& out, const Op& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_strans::apply_proxy(out, in.m); } template arma_hot inline void op_htrans::apply(Mat& out, const Op& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_htrans::apply_proxy(out, in.m); } template arma_hot inline void op_htrans::apply(Mat& out, const Op< Op, op_htrans>& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m.m); const Mat& A = tmp.M; const bool upper = in.m.aux_uword_a; op_trimat::apply_htrans(out, A, upper); } // // op_htrans2 template arma_hot arma_inline void op_htrans2::apply_noalias(Mat& out, const Mat& A, const eT val) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; out.set_size(A_n_cols, A_n_rows); if( (A_n_cols == 1) || (A_n_rows == 1) ) { const uword n_elem = A.n_elem; const eT* A_mem = A.memptr(); eT* out_mem = out.memptr(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = val * std::conj(A_mem[i]); } } else { for(uword in_row = 0; in_row < A_n_rows; ++in_row) { const uword out_col = in_row; for(uword in_col = 0; in_col < A_n_cols; ++in_col) { const uword out_row = in_col; out.at(out_row, out_col) = val * std::conj( A.at(in_row, in_col) ); } } } } template arma_hot inline void op_htrans2::apply(Mat& out, const Mat& A, const eT val) { arma_extra_debug_sigprint(); if(&out != &A) { op_htrans2::apply_noalias(out, A, val); } else { const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; if(n_rows == n_cols) { arma_extra_debug_print("doing in-place hermitian transpose of a square matrix"); // TODO: do multiplication while swapping for(uword col=0; col < n_cols; ++col) { eT* coldata = out.colptr(col); out.at(col,col) = std::conj( out.at(col,col) ); for(uword row=(col+1); row < n_rows; ++row) { const eT val1 = std::conj(coldata[row]); const eT val2 = std::conj(out.at(col,row)); out.at(col,row) = val1; coldata[row] = val2; } } arrayops::inplace_mul( out.memptr(), val, out.n_elem ); } else { Mat tmp; op_htrans2::apply_noalias(tmp, A, val); out.steal_mem(tmp); } } } template arma_hot inline void op_htrans2::apply_proxy(Mat& out, const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X); // allow detection of in-place transpose if( (is_Mat::stored_type>::value == true) && (Proxy::fake_mat == false) ) { const unwrap::stored_type> tmp(P.Q); op_htrans2::apply(out, tmp.M, val); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const bool is_alias = P.is_alias(out); if( (resolves_to_vector::value == true) && (Proxy::prefer_at_accessor == false) ) { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* out_mem = out.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = val * std::conj(Pea[i]); } } else // aliasing { Mat out2(n_cols, n_rows); eT* out_mem = out2.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = val * std::conj(Pea[i]); } out.steal_mem(out2); } } else { if(is_alias == false) { out.set_size(n_cols, n_rows); for(uword k=0; k < n_cols; ++k) for(uword i=0; i < n_rows; ++i) { out.at(k,i) = val * std::conj(P.at(i,k)); } } else // aliasing { Mat out2(n_cols, n_rows); for(uword k=0; k < n_cols; ++k) for(uword i=0; i < n_rows; ++i) { out2.at(k,i) = val * std::conj(P.at(i,k)); } out.steal_mem(out2); } } } } template arma_hot inline void op_htrans2::apply(Mat& out, const Op& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_strans2::apply_proxy(out, in.m, in.aux); } template arma_hot inline void op_htrans2::apply(Mat& out, const Op& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_htrans2::apply_proxy(out, in.m, in.aux); } //! @} RcppArmadillo/inst/include/armadillo_bits/arpack_wrapper.hpp0000644000176000001440000001362712256562527024157 0ustar ripleyusers// Copyright (C) 2013 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifdef ARMA_USE_ARPACK //! \namespace arpack namespace for ARPACK functions namespace arpack { // If real, then eT == eeT; otherwise, eT == std::complex. // For real calls, rwork is ignored; it's only necessary in the complex case. template inline void naupd(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, eeT* tol, eT* resid, blas_int* ncv, eT* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, eT* workd, eT* workl, blas_int* lworkl, eeT* rwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_snaupd)(ido, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dnaupd)(ido, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_supported_complex_float::value == true) { typedef std::complex T; typedef float xT; arma_fortran(arma_cnaupd)(ido, bmat, n, which, nev, (xT*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, (xT*) rwork, info); } else if(is_supported_complex_double::value == true) { typedef std::complex T; typedef double xT; arma_fortran(arma_znaupd)(ido, bmat, n, which, nev, (xT*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, (xT*) rwork, info); } } //! The use of two template types is necessary here because the compiler will //! instantiate this method for complex types (where eT != eeT) but that in //! practice that is never actually used. template inline void saupd(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, eeT* tol, eT* resid, blas_int* ncv, eT* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, eT* workd, eT* workl, blas_int* lworkl, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_ssaupd)(ido, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dsaupd)(ido, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } } template inline void seupd(blas_int* rvec, char* howmny, blas_int* select, eT* d, eT* z, blas_int* ldz, eT* sigma, char* bmat, blas_int* n, char* which, blas_int* nev, eT* tol, eT* resid, blas_int* ncv, eT* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, eT* workd, eT* workl, blas_int* lworkl, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sseupd)(rvec, howmny, select, (T*) d, (T*) z, ldz, (T*) sigma, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dseupd)(rvec, howmny, select, (T*) d, (T*) z, ldz, (T*) sigma, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } } // for complex versions, pass d for dr, and null for di; pass sigma for // sigmar, and null for sigmai; rwork isn't used for non-complex versions template inline void neupd(blas_int* rvec, char* howmny, blas_int* select, eT* dr, eT* di, eT* z, blas_int* ldz, eT* sigmar, eT* sigmai, eT* workev, char* bmat, blas_int* n, char* which, blas_int* nev, eeT* tol, eT* resid, blas_int* ncv, eT* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, eT* workd, eT* workl, blas_int* lworkl, eeT* rwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value == true) { typedef float T; arma_fortran(arma_sneupd)(rvec, howmny, select, (T*) dr, (T*) di, (T*) z, ldz, (T*) sigmar, (T*) sigmai, (T*) workev, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_double::value == true) { typedef double T; arma_fortran(arma_dneupd)(rvec, howmny, select, (T*) dr, (T*) di, (T*) z, ldz, (T*) sigmar, (T*) sigmai, (T*) workev, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_supported_complex_float::value == true) { typedef float xT; // eT is taken typedef std::complex T; arma_fortran(arma_cneupd)(rvec, howmny, select, (T*) dr, (T*) z, ldz, (T*) sigmar, (T*) workev, bmat, n, which, nev, (xT*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, (xT*) rwork, info); } else if(is_supported_complex_double::value == true) { typedef double xT; // eT is taken typedef std::complex T; arma_fortran(arma_zneupd)(rvec, howmny, select, (T*) dr, (T*) z, ldz, (T*) sigmar, (T*) workev, bmat, n, which, nev, (xT*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, (xT*) rwork, info); } } } // namespace arpack #endif RcppArmadillo/inst/include/armadillo_bits/eop_aux.hpp0000644000176000001440000003302212246034243022571 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup eop_aux //! @{ //! use of the SFINAE approach to work around compiler limitations //! http://en.wikipedia.org/wiki/SFINAE class eop_aux { public: template arma_inline static typename arma_integral_only::result acos (const eT x) { return eT( std::acos(double(x)) ); } template arma_inline static typename arma_integral_only::result asin (const eT x) { return eT( std::asin(double(x)) ); } template arma_inline static typename arma_integral_only::result atan (const eT x) { return eT( std::atan(double(x)) ); } template arma_inline static typename arma_real_only::result acos (const eT x) { return std::acos(x); } template arma_inline static typename arma_real_only::result asin (const eT x) { return std::asin(x); } template arma_inline static typename arma_real_only::result atan (const eT x) { return std::atan(x); } template arma_inline static typename arma_cx_only::result acos (const eT x) { return arma_acos(x); } template arma_inline static typename arma_cx_only::result asin (const eT x) { return arma_asin(x); } template arma_inline static typename arma_cx_only::result atan (const eT x) { return arma_atan(x); } template arma_inline static typename arma_integral_only::result acosh (const eT x) { return eT( arma_acosh(double(x)) ); } template arma_inline static typename arma_integral_only::result asinh (const eT x) { return eT( arma_asinh(double(x)) ); } template arma_inline static typename arma_integral_only::result atanh (const eT x) { return eT( arma_atanh(double(x)) ); } template arma_inline static typename arma_real_or_cx_only::result acosh (const eT x) { return arma_acosh(x); } template arma_inline static typename arma_real_or_cx_only::result asinh (const eT x) { return arma_asinh(x); } template arma_inline static typename arma_real_or_cx_only::result atanh (const eT x) { return arma_atanh(x); } template arma_inline static typename arma_not_cx::result conj(const eT x) { return x; } template arma_inline static std::complex conj(const std::complex& x) { return std::conj(x); } template arma_inline static typename arma_integral_only::result sqrt (const eT x) { return eT( std::sqrt (double(x)) ); } template arma_inline static typename arma_integral_only::result log10 (const eT x) { return eT( std::log10(double(x)) ); } template arma_inline static typename arma_integral_only::result log (const eT x) { return eT( std::log (double(x)) ); } template arma_inline static typename arma_integral_only::result exp (const eT x) { return eT( std::exp (double(x)) ); } template arma_inline static typename arma_integral_only::result cos (const eT x) { return eT( std::cos (double(x)) ); } template arma_inline static typename arma_integral_only::result sin (const eT x) { return eT( std::sin (double(x)) ); } template arma_inline static typename arma_integral_only::result tan (const eT x) { return eT( std::tan (double(x)) ); } template arma_inline static typename arma_integral_only::result cosh (const eT x) { return eT( std::cosh (double(x)) ); } template arma_inline static typename arma_integral_only::result sinh (const eT x) { return eT( std::sinh (double(x)) ); } template arma_inline static typename arma_integral_only::result tanh (const eT x) { return eT( std::tanh (double(x)) ); } template arma_inline static typename arma_real_or_cx_only::result sqrt (const eT x) { return std::sqrt (x); } template arma_inline static typename arma_real_or_cx_only::result log10 (const eT x) { return std::log10(x); } template arma_inline static typename arma_real_or_cx_only::result log (const eT x) { return std::log (x); } template arma_inline static typename arma_real_or_cx_only::result exp (const eT x) { return std::exp (x); } template arma_inline static typename arma_real_or_cx_only::result cos (const eT x) { return std::cos (x); } template arma_inline static typename arma_real_or_cx_only::result sin (const eT x) { return std::sin (x); } template arma_inline static typename arma_real_or_cx_only::result tan (const eT x) { return std::tan (x); } template arma_inline static typename arma_real_or_cx_only::result cosh (const eT x) { return std::cosh (x); } template arma_inline static typename arma_real_or_cx_only::result sinh (const eT x) { return std::sinh (x); } template arma_inline static typename arma_real_or_cx_only::result tanh (const eT x) { return std::tanh (x); } template arma_inline static typename arma_unsigned_integral_only::result neg (const eT x) { return x; } template arma_inline static typename arma_signed_only::result neg (const eT x) { return -x; } template arma_inline static typename arma_integral_only::result floor (const eT x) { return x; } template arma_inline static typename arma_real_only::result floor (const eT x) { return std::floor(x); } template arma_inline static typename arma_cx_only::result floor (const eT& x) { return eT( std::floor(x.real()), std::floor(x.imag()) ); } template arma_inline static typename arma_integral_only::result ceil (const eT x) { return x; } template arma_inline static typename arma_real_only::result ceil (const eT x) { return std::ceil(x); } template arma_inline static typename arma_cx_only::result ceil (const eT& x) { return eT( std::ceil(x.real()), std::ceil(x.imag()) ); } #if defined(ARMA_USE_CXX11) template arma_inline static typename arma_integral_only::result round (const eT x) { return x; } template arma_inline static typename arma_real_only::result round (const eT x) { return std::round(x); } template arma_inline static typename arma_cx_only::result round (const eT& x) { return eT( std::round(x.real()), std::round(x.imag()) ); } #else template arma_inline static typename arma_integral_only::result round (const eT x) { return x; } template arma_inline static typename arma_real_only::result round (const eT x) { return (x >= eT(0)) ? std::floor(x+0.5) : std::ceil(x-0.5); } template arma_inline static typename arma_cx_only::result round (const eT& x) { return eT( eop_aux::round(x.real()), eop_aux::round(x.imag()) ); } #endif #if defined(ARMA_USE_CXX11) template arma_inline static typename arma_integral_only::result log2 (const eT x) { return eT( std::log(double(x))/ double(0.69314718055994530942) ); } template arma_inline static typename arma_real_only::result log2 (const eT x) { return std::log2(x); } template arma_inline static typename arma_cx_only::result log2 (const eT& x) { typedef typename get_pod_type::result T; return std::log(x) / T(0.69314718055994530942); } #else template arma_inline static typename arma_integral_only::result log2 (const eT x) { return eT( std::log(double(x))/ double(0.69314718055994530942) ); } template arma_inline static typename arma_real_or_cx_only::result log2 (const eT x) { typedef typename get_pod_type::result T; return std::log(x) / T(0.69314718055994530942); } #endif #if defined(ARMA_USE_CXX11) template arma_inline static typename arma_integral_only::result exp2 (const eT x) { return eT( std::pow(double(2), double(x)) ); } template arma_inline static typename arma_real_only::result exp2 (const eT x) { return std::exp2(x); } template arma_inline static typename arma_cx_only::result exp2 (const eT& x) { typedef typename get_pod_type::result T; return std::pow( T(2), x); } #else template arma_inline static typename arma_integral_only::result exp2 (const eT x) { return eT( std::pow(double(2), double(x)) ); } template arma_inline static typename arma_real_or_cx_only::result exp2 (const eT x) { typedef typename get_pod_type::result T; return std::pow( T(2), x); } #endif template arma_inline static typename arma_integral_only::result exp10 (const eT x) { return eT( std::pow(double(10), double(x)) ); } template arma_inline static typename arma_real_or_cx_only::result exp10 (const eT x) { typedef typename get_pod_type::result T; return std::pow( T(10), x); } template arma_inline static typename arma_unsigned_integral_only::result arma_abs (const eT x) { return x; } template arma_inline static typename arma_signed_integral_only::result arma_abs (const eT x) { return std::abs(x); } template arma_inline static typename arma_real_only::result arma_abs (const eT x) { return std::abs(x); } template arma_inline static typename arma_real_only< T>::result arma_abs (const std::complex& x) { return std::abs(x); } template arma_inline static typename arma_unsigned_integral_only::result sign (const eT x) { return (x > eT(0)) ? eT(+1) : eT(0); } template arma_inline static typename arma_signed_integral_only::result sign (const eT x) { return (x > eT(0)) ? eT(+1) : ( (x < eT(0)) ? eT(-1) : eT(0) ); } template arma_inline static typename arma_real_only::result sign (const eT x) { return (x > eT(0)) ? eT(+1) : ( (x < eT(0)) ? eT(-1) : eT(0) ); } template arma_inline static typename arma_cx_only::result sign (const eT& x) { typedef typename eT::value_type T; return (x.real() != T(0) && x.imag() != T(0)) ? (x / std::abs(x)) : x; } template arma_inline static typename arma_integral_only::result pow (const T1 base, const T2 exponent) { return T1( std::pow( double(base), double(exponent) ) ); } template arma_inline static typename arma_real_or_cx_only::result pow (const T1 base, const T2 exponent) { return std::pow(base, exponent); } template arma_inline static typename arma_integral_only::result direct_eps(const eT) { return eT(0); } template inline static typename arma_real_only::result direct_eps(const eT x) { //arma_extra_debug_sigprint(); // acording to IEEE Standard for Floating-Point Arithmetic (IEEE 754) // the mantissa length for double is 53 bits = std::numeric_limits::digits // the mantissa length for float is 24 bits = std::numeric_limits::digits //return std::pow( std::numeric_limits::radix, (std::floor(std::log10(std::abs(x))/std::log10(std::numeric_limits::radix))-(std::numeric_limits::digits-1)) ); const eT radix_eT = eT(std::numeric_limits::radix); const eT digits_m1_eT = eT(std::numeric_limits::digits - 1); // return std::pow( radix_eT, eT(std::floor(std::log10(std::abs(x))/std::log10(radix_eT)) - digits_m1_eT) ); return eop_aux::pow( radix_eT, eT(std::floor(std::log10(std::abs(x))/std::log10(radix_eT)) - digits_m1_eT) ); } template inline static typename arma_real_only::result direct_eps(const std::complex x) { //arma_extra_debug_sigprint(); //return std::pow( std::numeric_limits::radix, (std::floor(std::log10(std::abs(x))/std::log10(std::numeric_limits::radix))-(std::numeric_limits::digits-1)) ); const T radix_T = T(std::numeric_limits::radix); const T digits_m1_T = T(std::numeric_limits::digits - 1); return std::pow( radix_T, T(std::floor(std::log10(std::abs(x))/std::log10(radix_T)) - digits_m1_T) ); } }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_shuffle_meat.hpp0000644000176000001440000001067512246040726024305 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_shuffle //! @{ template inline void op_shuffle::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m); const Mat& X = tmp.M; if(X.is_empty()) { out.copy_size(X); return; } const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "shuffle(): dim must be 0 or 1" ); const uword N = (dim == 0) ? X.n_rows : X.n_cols; // see "fn_sort_index.hpp" for the definition of "arma_sort_index_packet" // and the associated comparison functor std::vector< arma_sort_index_packet > packet_vec(N); for(uword i=0; i()); packet_vec[i].index = i; } arma_sort_index_helper_ascend comparator; std::sort( packet_vec.begin(), packet_vec.end(), comparator ); const bool is_alias = (&out == &X); if(X.is_vec() == false) { if(is_alias == false) { arma_extra_debug_print("op_shuffle::apply(): matrix"); out.copy_size(X); if(dim == 0) { for(uword i=0; i 1) // i.e. column vector { for(uword i=0; i 1) // i.e. row vector { for(uword i=0; i 1) // i.e. column vector { for(uword i=0; i 1) // i.e. row vector { for(uword i=0; i inline const mtOp hist ( const Base& A, const uword n_bins = 10, const arma_empty_class junk1 = arma_empty_class(), const typename arma_not_cx::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return mtOp( A.get_ref(), n_bins, 0 ); } template inline const mtGlue hist ( const Base& A, const Base& B, const uword dim = 0, const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtGlue( A.get_ref(), B.get_ref(), dim ); } RcppArmadillo/inst/include/armadillo_bits/fn_sum.hpp0000644000176000001440000000710512200375542022423 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_sum //! @{ //! \brief //! Delayed sum of elements of a matrix along a specified dimension (either rows or columns). //! The result is stored in a dense matrix that has either one column or one row. //! For dim = 0, find the sum of each column (traverse across rows) //! For dim = 1, find the sum of each row (traverse across columns) //! The default is dim = 0. //! NOTE: the dim argument is different than in Matlab/Octave. template arma_inline const Op sum ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op sum ( const T1& X, const uword dim, const typename enable_if< resolves_to_vector::value == true >::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } //! \brief //! Immediate 'sum all values' operation for expressions which resolve to a vector template inline arma_warn_unused typename T1::elem_type sum ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if< resolves_to_vector::value == true >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return accu(X); } //! \brief //! Immediate 'sum all values' operation, //! invoked, for example, by: sum(sum(A)) template inline arma_warn_unused typename T1::elem_type sum(const Op& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("sum(): two consecutive sum() calls detected"); return accu(in.m); } template arma_inline const Op, op_sum> sum(const Op& in, const uword dim) { arma_extra_debug_sigprint(); return Op, op_sum>(in, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & sum(const T& x) { return x; } //! sum of sparse object template inline typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == true), typename T1::elem_type >::result sum(const T1& x) { arma_extra_debug_sigprint(); // sum elements return accu(x); } template inline typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == false), const SpOp >::result sum(const T1& x, const uword dim = 0) { arma_extra_debug_sigprint(); return SpOp(x, dim, 0); } template inline arma_warn_unused typename T1::elem_type sum(const SpOp& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("sum(): two consecutive sum() calls detected"); return accu(in.m); } template arma_inline const SpOp, spop_sum> sum(const SpOp& in, const uword dim) { arma_extra_debug_sigprint(); return SpOp, spop_sum>(in, dim, 0); } //! @} RcppArmadillo/inst/include/armadillo_bits/Glue_bones.hpp0000644000176000001440000000332412176655102023222 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Glue //! @{ //! Class for storing data required for delayed binary operations, //! such as the operands (e.g. two matrices) and the binary operator (e.g. addition). //! The operands are stored as references (which can be optimised away), //! while the operator is "stored" through the template definition (glue_type). //! The operands can be 'Mat', 'Row', 'Col', 'Op', and 'Glue'. //! Note that as 'Glue' can be one of the operands, more than two matrices can be stored. //! //! For example, we could have: Glue //! //! Another example is: Glue< Op, Op, glue_times > template class Glue : public Base > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = (is_same_type::value) ? T1::is_row : false; static const bool is_col = (is_same_type::value) ? T2::is_col : false; arma_inline Glue(const T1& in_A, const T2& in_B); arma_inline Glue(const T1& in_A, const T2& in_B, const uword in_aux_uword); arma_inline ~Glue(); const T1& A; //!< first operand const T2& B; //!< second operand uword aux_uword; //!< storage of auxiliary data, uword format }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_trig.hpp0000644000176000001440000001236212200375542022565 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_trig //! @{ // // trigonometric functions: // cos family: cos, acos, cosh, acosh // sin family: sin, asin, sinh, asinh // tan family: tan, atan, tanh, atanh // // cos template arma_inline const eOp cos(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube cos(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // acos template arma_inline const eOp acos(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube acos(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // cosh template arma_inline const eOp cosh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube cosh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // acosh template arma_inline const eOp acosh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube acosh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // sin template arma_inline const eOp sin(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube sin(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // asin template arma_inline const eOp asin(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube asin(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // sinh template arma_inline const eOp sinh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube sinh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // asinh template arma_inline const eOp asinh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube asinh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // tan template arma_inline const eOp tan(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube tan(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // atan template arma_inline const eOp atan(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube atan(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // tanh template arma_inline const eOp tanh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube tanh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // atanh template arma_inline const eOp atanh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube atanh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } //! @} RcppArmadillo/inst/include/armadillo_bits/mtOpCube_bones.hpp0000644000176000001440000000342112202101406024021 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup mtOpCube //! @{ template class mtOpCube : public BaseCube > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef typename T1::elem_type in_eT; inline explicit mtOpCube(const T1& in_m); inline mtOpCube(const T1& in_m, const in_eT in_aux); inline mtOpCube(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); inline mtOpCube(const T1& in_m, const in_eT in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); inline mtOpCube(const char junk, const T1& in_m, const out_eT in_aux); inline ~mtOpCube(); arma_aligned const T1& m; //!< storage of reference to the operand (eg. a matrix) arma_aligned in_eT aux; //!< storage of auxiliary data, using the element type as used by T1 arma_aligned out_eT aux_out_eT; //!< storage of auxiliary data, using the element type as specified by the out_eT template parameter arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_c; //!< storage of auxiliary data, uword format }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_max_bones.hpp0000644000176000001440000000335312200631217023600 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_max //! @{ //! Class for finding maximum values in a matrix class op_max { public: template inline static void apply(Mat& out, const Op& in); // // for non-complex numbers template inline static eT direct_max(const eT* const X, const uword N); template inline static eT direct_max(const eT* const X, const uword N, uword& index_of_max_val); template inline static eT direct_max(const Mat& X, const uword row); template inline static eT max(const subview& X); template inline static typename arma_not_cx::result max(const Base& X); // // for complex numbers template inline static std::complex direct_max(const std::complex* const X, const uword n_elem); template inline static std::complex direct_max(const std::complex* const X, const uword n_elem, uword& index_of_max_val); template inline static std::complex direct_max(const Mat< std::complex >& X, const uword row); template inline static std::complex max(const subview< std::complex >& X); template inline static typename arma_cx_only::result max(const Base& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/Col_bones.hpp0000644000176000001440000001773312252274740023054 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Col //! @{ //! Class for column vectors (matrices with only one column) template class Col : public Mat { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_col = true; static const bool is_row = false; inline Col(); inline Col(const Col& X); inline explicit Col(const uword n_elem); inline Col(const uword in_rows, const uword in_cols); template inline Col(const uword n_elem, const fill::fill_class& f); template inline Col(const uword in_rows, const uword in_cols, const fill::fill_class& f); inline Col(const char* text); inline const Col& operator=(const char* text); inline Col(const std::string& text); inline const Col& operator=(const std::string& text); inline Col(const std::vector& x); inline const Col& operator=(const std::vector& x); #if defined(ARMA_USE_CXX11) inline Col(const std::initializer_list& list); inline const Col& operator=(const std::initializer_list& list); inline Col(Col&& m); inline const Col& operator=(Col&& m); #endif inline explicit Col(const SpCol& X); inline const Col& operator=(const eT val); inline const Col& operator=(const Col& m); template inline Col(const Base& X); template inline const Col& operator=(const Base& X); inline Col( eT* aux_mem, const uword aux_length, const bool copy_aux_mem = true, const bool strict = true); inline Col(const eT* aux_mem, const uword aux_length); template inline explicit Col(const Base& A, const Base& B); template inline Col(const BaseCube& X); template inline const Col& operator=(const BaseCube& X); inline Col(const subview_cube& X); inline const Col& operator=(const subview_cube& X); inline mat_injector operator<<(const eT val); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; arma_inline subview_col row(const uword row_num); arma_inline const subview_col row(const uword row_num) const; using Mat::rows; using Mat::operator(); arma_inline subview_col rows(const uword in_row1, const uword in_row2); arma_inline const subview_col rows(const uword in_row1, const uword in_row2) const; arma_inline subview_col subvec(const uword in_row1, const uword in_row2); arma_inline const subview_col subvec(const uword in_row1, const uword in_row2) const; arma_inline subview_col rows(const span& row_span); arma_inline const subview_col rows(const span& row_span) const; arma_inline subview_col subvec(const span& row_span); arma_inline const subview_col subvec(const span& row_span) const; arma_inline subview_col operator()(const span& row_span); arma_inline const subview_col operator()(const span& row_span) const; inline void shed_row (const uword row_num); inline void shed_rows(const uword in_row1, const uword in_row2); inline void insert_rows(const uword row_num, const uword N, const bool set_to_zero = true); template inline void insert_rows(const uword row_num, const Base& X); arma_inline arma_warn_unused eT& at(const uword i); arma_inline arma_warn_unused const eT& at(const uword i) const; arma_inline arma_warn_unused eT& at(const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at(const uword in_row, const uword in_col) const; typedef eT* row_iterator; typedef const eT* const_row_iterator; inline row_iterator begin_row(const uword row_num); inline const_row_iterator begin_row(const uword row_num) const; inline row_iterator end_row (const uword row_num); inline const_row_iterator end_row (const uword row_num) const; template class fixed; protected: inline Col(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem); public: #ifdef ARMA_EXTRA_COL_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_COL_PROTO) #endif }; template template class Col::fixed : public Col { private: static const bool use_extra = (fixed_n_elem > arma_config::mat_prealloc); arma_align_mem eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ]; arma_inline void change_to_row(); public: typedef fixed Col_fixed_type; typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_col = true; static const bool is_row = false; static const uword n_rows = fixed_n_elem; static const uword n_cols = 1; static const uword n_elem = fixed_n_elem; arma_inline fixed(); arma_inline fixed(const fixed& X); inline fixed(const subview_cube& X); template inline fixed(const fill::fill_class& f); template inline fixed(const Base& A); template inline fixed(const Base& A, const Base& B); inline fixed(const eT* aux_mem); inline fixed(const char* text); inline fixed(const std::string& text); template inline const Col& operator=(const Base& A); inline const Col& operator=(const eT val); inline const Col& operator=(const char* text); inline const Col& operator=(const std::string& text); inline const Col& operator=(const subview_cube& X); using Col::operator(); #if defined(ARMA_USE_CXX11) inline fixed(const std::initializer_list& list); inline const Col& operator=(const std::initializer_list& list); #endif arma_inline const Col& operator=(const fixed& X); arma_inline const Op< Col_fixed_type, op_htrans > t() const; arma_inline const Op< Col_fixed_type, op_htrans > ht() const; arma_inline const Op< Col_fixed_type, op_strans > st() const; arma_inline arma_warn_unused const eT& at_alt (const uword i) const; arma_inline arma_warn_unused eT& operator[] (const uword i); arma_inline arma_warn_unused const eT& operator[] (const uword i) const; arma_inline arma_warn_unused eT& at (const uword i); arma_inline arma_warn_unused const eT& at (const uword i) const; arma_inline arma_warn_unused eT& operator() (const uword i); arma_inline arma_warn_unused const eT& operator() (const uword i) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT* memptr(); arma_inline arma_warn_unused const eT* memptr() const; arma_hot inline const Col& fill(const eT val); arma_hot inline const Col& zeros(); arma_hot inline const Col& ones(); }; //! @} RcppArmadillo/inst/include/armadillo_bits/distr_param.hpp0000644000176000001440000000147612250240752023445 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup distr_param //! @{ class distr_param { public: uword state; union { int a_int; double a_double; }; union { int b_int; double b_double; }; inline distr_param() : state(0) { } inline explicit distr_param(const int a, const int b) : state(1) , a_int(a) , b_int(b) { } inline explicit distr_param(const double a, const double b) : state(2) , a_double(a) , b_double(b) { } }; //! @} RcppArmadillo/inst/include/armadillo_bits/SpMat_bones.hpp0000644000176000001440000006537212256046163023365 0ustar ripleyusers// Copyright (C) 2011-2013 Ryan Curtin // Copyright (C) 2012-2013 Conrad Sanderson // Copyright (C) 2011 Matthew Amidon // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpMat //! @{ //! Sparse matrix class, with data stored in compressed sparse column (CSC) format template class SpMat : public SpBase< eT, SpMat > { public: typedef eT elem_type; //!< the type of elements stored in the matrix typedef typename get_pod_type::result pod_type; //!< if eT is non-complex, pod_type is the same as eT; otherwise, pod_type is the underlying type used by std::complex static const bool is_row = false; static const bool is_col = false; const uword n_rows; //!< number of rows in the matrix (read-only) const uword n_cols; //!< number of columns in the matrix (read-only) const uword n_elem; //!< number of elements in the matrix (read-only) const uword n_nonzero; //!< number of nonzero elements in the matrix (read-only) const uword vec_state; //!< 0: matrix; 1: column vector; 2: row vector // So that SpValProxy can call add_element() and delete_element(). friend class SpValProxy >; friend class SpSubview; /** * The memory used to store the values of the matrix. * In accordance with the CSC format, this stores only the actual values. * The correct locations of the values are assembled from the row indices * and the column pointers. The length of this array is n_nonzero + 1; the * final value ensures the integrity of iterators. If you are planning on * resizing this vector, it's probably best to use mem_resize() instead. */ const eT* const values; /** * The row indices of each value. row_indices[i] is the row of values[i]. * The length of this array is n_nonzero + 1; the final value ensures the * integrity of iterators. If you are planning on resizing this vector, it's * probably best to use mem_resize() instead. */ const uword* const row_indices; /** * The column pointers. This stores the index of the first item in column i. * That is, values[col_ptrs[i]] is the first value in column i, and it is in * row row_indices[col_ptrs[i]]. This array is of length (n_cols + 2); the * element col_ptrs[n_cols] should be equal to n_nonzero, and the element * col_ptrs[n_cols + 1] is an invalid very large value that ensures the * integrity of iterators. */ const uword* const col_ptrs; inline SpMat(); //! Size will be 0x0 (empty). inline ~SpMat(); inline SpMat(const uword in_rows, const uword in_cols); inline SpMat(const char* text); inline const SpMat& operator=(const char* text); inline SpMat(const std::string& text); inline const SpMat& operator=(const std::string& text); inline SpMat(const SpMat& x); #if defined(ARMA_USE_CXX11) inline SpMat(SpMat&& m); inline const SpMat& operator=(SpMat&& m); #endif template inline SpMat(const Base& locations, const Base& values, const bool sort_locations = true); template inline SpMat(const Base& locations, const Base& values, const uword n_rows, const uword n_cols, const bool sort_locations = true); template inline SpMat(const Base& rowind, const Base& colptr, const Base& values, const uword n_rows, const uword n_cols); inline const SpMat& operator=(const eT val); //! Sets size to 1x1. inline const SpMat& operator*=(const eT val); inline const SpMat& operator/=(const eT val); // operator+=(val) and operator-=(val) are not defined as they don't make sense for sparse matrices /** * Operators on other sparse matrices. These work as though you would expect. */ inline const SpMat& operator=(const SpMat& m); inline const SpMat& operator+=(const SpMat& m); inline const SpMat& operator-=(const SpMat& m); inline const SpMat& operator*=(const SpMat& m); inline const SpMat& operator%=(const SpMat& m); inline const SpMat& operator/=(const SpMat& m); /** * Operators on other regular matrices. These work as though you would expect. */ template inline explicit SpMat(const Base& m); template inline const SpMat& operator=(const Base& m); template inline const SpMat& operator*=(const Base& m); template inline const SpMat& operator/=(const Base& m); template inline const SpMat& operator%=(const Base& m); //! construction of complex matrix out of two non-complex matrices; template inline explicit SpMat(const SpBase& A, const SpBase& B); /** * Operations on sparse subviews. */ inline SpMat(const SpSubview& X); inline const SpMat& operator=(const SpSubview& X); inline const SpMat& operator+=(const SpSubview& X); inline const SpMat& operator-=(const SpSubview& X); inline const SpMat& operator*=(const SpSubview& X); inline const SpMat& operator%=(const SpSubview& X); inline const SpMat& operator/=(const SpSubview& X); /** * Operations on regular subviews. */ inline SpMat(const subview& x); inline const SpMat& operator=(const subview& x); inline const SpMat& operator+=(const subview& x); inline const SpMat& operator-=(const subview& x); inline const SpMat& operator*=(const subview& x); inline const SpMat& operator%=(const subview& x); inline const SpMat& operator/=(const subview& x); // delayed unary ops template inline SpMat(const SpOp& X); template inline const SpMat& operator=(const SpOp& X); template inline const SpMat& operator+=(const SpOp& X); template inline const SpMat& operator-=(const SpOp& X); template inline const SpMat& operator*=(const SpOp& X); template inline const SpMat& operator%=(const SpOp& X); template inline const SpMat& operator/=(const SpOp& X); // delayed binary ops template inline SpMat(const SpGlue& X); template inline const SpMat& operator=(const SpGlue& X); template inline const SpMat& operator+=(const SpGlue& X); template inline const SpMat& operator-=(const SpGlue& X); template inline const SpMat& operator*=(const SpGlue& X); template inline const SpMat& operator%=(const SpGlue& X); template inline const SpMat& operator/=(const SpGlue& X); // delayed mixted-type unary ops template inline SpMat(const mtSpOp& X); template inline const SpMat& operator=(const mtSpOp& X); template inline const SpMat& operator+=(const mtSpOp& X); template inline const SpMat& operator-=(const mtSpOp& X); template inline const SpMat& operator*=(const mtSpOp& X); template inline const SpMat& operator%=(const mtSpOp& X); template inline const SpMat& operator/=(const mtSpOp& X); /** * Submatrix methods. */ arma_inline SpSubview row(const uword row_num); arma_inline const SpSubview row(const uword row_num) const; inline SpSubview operator()(const uword row_num, const span& col_span); inline const SpSubview operator()(const uword row_num, const span& col_span) const; arma_inline SpSubview col(const uword col_num); arma_inline const SpSubview col(const uword col_num) const; inline SpSubview operator()(const span& row_span, const uword col_num); inline const SpSubview operator()(const span& row_span, const uword col_num) const; /** * Row- and column-related functions. */ inline void swap_rows(const uword in_row1, const uword in_row2); inline void swap_cols(const uword in_col1, const uword in_col2); inline void shed_row(const uword row_num); inline void shed_col(const uword col_num); inline void shed_rows(const uword in_row1, const uword in_row2); inline void shed_cols(const uword in_col1, const uword in_col2); arma_inline SpSubview rows(const uword in_row1, const uword in_row2); arma_inline const SpSubview rows(const uword in_row1, const uword in_row2) const; arma_inline SpSubview cols(const uword in_col1, const uword in_col2); arma_inline const SpSubview cols(const uword in_col1, const uword in_col2) const; arma_inline SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); arma_inline const SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; arma_inline SpSubview submat(const uword in_row1, const uword in_col1, const SizeMat& s); arma_inline const SpSubview submat(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline SpSubview submat (const span& row_span, const span& col_span); inline const SpSubview submat (const span& row_span, const span& col_span) const; inline SpSubview operator()(const span& row_span, const span& col_span); inline const SpSubview operator()(const span& row_span, const span& col_span) const; arma_inline SpSubview operator()(const uword in_row1, const uword in_col1, const SizeMat& s); arma_inline const SpSubview operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const; /** * Element access; access the i'th element (works identically to the Mat accessors). * If there is nothing at element i, 0 is returned. * * @param i Element to access. */ arma_inline arma_warn_unused SpValProxy > operator[] (const uword i); arma_inline arma_warn_unused eT operator[] (const uword i) const; arma_inline arma_warn_unused SpValProxy > at (const uword i); arma_inline arma_warn_unused eT at (const uword i) const; arma_inline arma_warn_unused SpValProxy > operator() (const uword i); arma_inline arma_warn_unused eT operator() (const uword i) const; /** * Element access; access the element at row in_row and column in_col. * If there is nothing at that position, 0 is returned. */ arma_inline arma_warn_unused SpValProxy > at (const uword in_row, const uword in_col); arma_inline arma_warn_unused eT at (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused SpValProxy > operator() (const uword in_row, const uword in_col); arma_inline arma_warn_unused eT operator() (const uword in_row, const uword in_col) const; /** * Information boolean checks on matrices. */ arma_inline arma_warn_unused bool is_empty() const; arma_inline arma_warn_unused bool is_vec() const; arma_inline arma_warn_unused bool is_rowvec() const; arma_inline arma_warn_unused bool is_colvec() const; arma_inline arma_warn_unused bool is_square() const; inline arma_warn_unused bool is_finite() const; arma_inline arma_warn_unused bool in_range(const uword i) const; arma_inline arma_warn_unused bool in_range(const span& x) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const SizeMat& s) const; /** * Printing the matrix. * * @param extra_text Text to prepend to output. */ inline void impl_print(const std::string& extra_text) const; inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const; inline void impl_raw_print(const std::string& extra_text) const; inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const; inline void impl_print_dense(const std::string& extra_text) const; inline void impl_print_dense(std::ostream& user_stream, const std::string& extra_text) const; inline void impl_raw_print_dense(const std::string& extra_text) const; inline void impl_raw_print_dense(std::ostream& user_stream, const std::string& extra_text) const; //! Copy the size of another matrix. template inline void copy_size(const SpMat& m); template inline void copy_size(const Mat& m); /** * Set the size of the matrix; the matrix will be sized as a column vector * * @param in_elem Number of elements to allow. */ inline void set_size(const uword in_elem); /** * Set the size of the matrix * * @param in_rows Number of rows to allow. * @param in_cols Number of columns to allow. */ inline void set_size(const uword in_rows, const uword in_cols); inline void reshape(const uword in_rows, const uword in_cols, const uword dim = 0); inline const SpMat& zeros(); inline const SpMat& zeros(const uword in_elem); inline const SpMat& zeros(const uword in_rows, const uword in_cols); inline const SpMat& eye(); inline const SpMat& eye(const uword in_rows, const uword in_cols); inline const SpMat& speye(); inline const SpMat& speye(const uword in_rows, const uword in_cols); inline const SpMat& sprandu(const uword in_rows, const uword in_cols, const double density); inline const SpMat& sprandn(const uword in_rows, const uword in_cols, const double density); inline void reset(); /** * Get the minimum or maximum of the matrix. */ inline arma_warn_unused eT min() const; inline eT min(uword& index_of_min_val) const; inline eT min(uword& row_of_min_val, uword& col_of_min_val) const; inline arma_warn_unused eT max() const; inline eT max(uword& index_of_max_val) const; inline eT max(uword& row_of_min_val, uword& col_of_min_val) const; // saving and loading inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const; inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const; inline bool load(const std::string name, const file_type type = arma_binary, const bool print_status = true); inline bool load( std::istream& is, const file_type type = arma_binary, const bool print_status = true); inline bool quiet_save(const std::string name, const file_type type = arma_binary) const; inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const; inline bool quiet_load(const std::string name, const file_type type = arma_binary); inline bool quiet_load( std::istream& is, const file_type type = arma_binary); // TODO: speed up loading of sparse matrices stored as text files (ie. raw_ascii and coord_ascii) // TODO: implement auto_detect for sparse matrices // TODO: modify docs to specify which formats are not applicable to sparse matrices // These forward declarations are necessary. class iterator_base; class iterator; class const_iterator; class row_iterator; class const_row_iterator; // Iterator base provides basic operators but not how to compare or how to // iterate. class iterator_base { public: inline iterator_base(const SpMat& in_M); inline iterator_base(const SpMat& in_M, const uword col, const uword pos); inline arma_hot eT operator*() const; // Don't hold location internally; call "dummy" methods to get that information. arma_inline uword row() const { return M.row_indices[internal_pos]; } arma_inline uword col() const { return internal_col; } arma_inline uword pos() const { return internal_pos; } arma_aligned const SpMat& M; arma_aligned uword internal_col; arma_aligned uword internal_pos; // So that we satisfy the STL iterator types. typedef std::bidirectional_iterator_tag iterator_category; typedef eT value_type; typedef uword difference_type; // not certain on this one typedef const eT* pointer; typedef const eT& reference; }; class const_iterator : public iterator_base { public: inline const_iterator(const SpMat& in_M, uword initial_pos = 0); // Assumes initial_pos is valid. //! Once initialized, will be at the first nonzero value after the given position (using forward columnwise traversal). inline const_iterator(const SpMat& in_M, uword in_row, uword in_col); //! If you know the exact position of the iterator. in_row is a dummy argument. inline const_iterator(const SpMat& in_M, uword in_row, uword in_col, uword in_pos); inline const_iterator(const const_iterator& other); inline arma_hot const_iterator& operator++(); inline arma_hot const_iterator operator++(int); inline arma_hot const_iterator& operator--(); inline arma_hot const_iterator operator--(int); inline arma_hot bool operator==(const const_iterator& rhs) const; inline arma_hot bool operator!=(const const_iterator& rhs) const; inline arma_hot bool operator==(const typename SpSubview::const_iterator& rhs) const; inline arma_hot bool operator!=(const typename SpSubview::const_iterator& rhs) const; inline arma_hot bool operator==(const const_row_iterator& rhs) const; inline arma_hot bool operator!=(const const_row_iterator& rhs) const; inline arma_hot bool operator==(const typename SpSubview::const_row_iterator& rhs) const; inline arma_hot bool operator!=(const typename SpSubview::const_row_iterator& rhs) const; }; /** * So that we can iterate over nonzero values, we need an iterator * implementation. This can't be as simple as Mat's, which is just a pointer * to an eT. If a value is set to 0 using this iterator, the iterator is no * longer valid! */ class iterator : public const_iterator { public: inline iterator(SpMat& in_M, uword initial_pos = 0) : const_iterator(in_M, initial_pos) { } inline iterator(SpMat& in_M, uword in_row, uword in_col) : const_iterator(in_M, in_row, in_col) { } inline iterator(SpMat& in_M, uword in_row, uword in_col, uword in_pos) : const_iterator(in_M, in_row, in_col, in_pos) { } inline iterator(const const_iterator& other) : const_iterator(other) { } inline arma_hot SpValProxy > operator*(); // overloads needed for return type correctness inline arma_hot iterator& operator++(); inline arma_hot iterator operator++(int); inline arma_hot iterator& operator--(); inline arma_hot iterator operator--(int); // This has a different value_type than iterator_base. typedef SpValProxy > value_type; typedef const SpValProxy >* pointer; typedef const SpValProxy >& reference; }; class const_row_iterator : public iterator_base { public: inline const_row_iterator(const SpMat& in_M, uword initial_pos = 0); //! Once initialized, will be at the first nonzero value after the given position (using forward row-wise traversal). inline const_row_iterator(const SpMat& in_M, uword in_row, uword in_col); inline const_row_iterator(const const_row_iterator& other); inline arma_hot const_row_iterator& operator++(); inline arma_hot const_row_iterator operator++(int); inline arma_hot const_row_iterator& operator--(); inline arma_hot const_row_iterator operator--(int); uword internal_row; // Hold row internally because we use internal_pos differently. uword actual_pos; // Actual position in matrix. arma_inline eT operator*() const { return iterator_base::M.values[actual_pos]; } arma_inline uword row() const { return internal_row; } inline arma_hot bool operator==(const const_iterator& rhs) const; inline arma_hot bool operator!=(const const_iterator& rhs) const; inline arma_hot bool operator==(const typename SpSubview::const_iterator& rhs) const; inline arma_hot bool operator!=(const typename SpSubview::const_iterator& rhs) const; inline arma_hot bool operator==(const const_row_iterator& rhs) const; inline arma_hot bool operator!=(const const_row_iterator& rhs) const; inline arma_hot bool operator==(const typename SpSubview::const_row_iterator& rhs) const; inline arma_hot bool operator!=(const typename SpSubview::const_row_iterator& rhs) const; }; class row_iterator : public const_row_iterator { public: inline row_iterator(SpMat& in_M, uword initial_pos = 0) : const_row_iterator(in_M, initial_pos) { } //! Once initialized, will be at the first nonzero value after the given position (using forward row-wise traversal). inline row_iterator(SpMat& in_M, uword in_row, uword in_col) : const_row_iterator(in_M, in_row, in_col) { } inline row_iterator(const row_iterator& other) : const_row_iterator(other) { } inline arma_hot SpValProxy > operator*(); // overloads required for return type correctness inline arma_hot row_iterator& operator++(); inline arma_hot row_iterator operator++(int); inline arma_hot row_iterator& operator--(); inline arma_hot row_iterator operator--(int); // This has a different value_type than iterator_base. typedef SpValProxy > value_type; typedef const SpValProxy >* pointer; typedef const SpValProxy >& reference; }; inline iterator begin(); inline const_iterator begin() const; inline iterator end(); inline const_iterator end() const; inline iterator begin_col(const uword col_num); inline const_iterator begin_col(const uword col_num) const; inline iterator end_col(const uword col_num); inline const_iterator end_col(const uword col_num) const; inline row_iterator begin_row(const uword row_num = 0); inline const_row_iterator begin_row(const uword row_num = 0) const; inline row_iterator end_row(); inline const_row_iterator end_row() const; inline row_iterator end_row(const uword row_num); inline const_row_iterator end_row(const uword row_num) const; inline void clear(); inline bool empty() const; inline uword size() const; /** * Resize memory. You are responsible for updating the column pointers and * filling the new memory (if the new size is larger). If the new size is * smaller, the first new_n_nonzero elements will be copied. n_nonzero is * updated. */ inline void mem_resize(const uword new_n_nonzero); //! don't use this unless you're writing internal Armadillo code inline void steal_mem(SpMat& X); //! don't use this unless you're writing internal Armadillo code template< typename T1, typename Functor> arma_hot inline void init_xform (const SpBase& x, const Functor& func); template arma_hot inline void init_xform_mt(const SpBase& x, const Functor& func); protected: /** * Initialize the matrix to the specified size. Data is not preserved, so the matrix is assumed to be entirely sparse (empty). */ inline void init(uword in_rows, uword in_cols); /** * Initialize the matrix from text. Data is (of course) not preserved, and * the size will be reset. */ inline void init(const std::string& text); /** * Initialize from another matrix (copy). */ inline void init(const SpMat& x); private: /** * Return the given element. */ inline arma_hot arma_warn_unused SpValProxy > get_value(const uword i); inline arma_hot arma_warn_unused eT get_value(const uword i) const; inline arma_hot arma_warn_unused SpValProxy > get_value(const uword in_row, const uword in_col); inline arma_hot arma_warn_unused eT get_value(const uword in_row, const uword in_col) const; /** * Given the index representing which of the nonzero values this is, return * its actual location, either in row/col or just the index. */ arma_inline arma_hot arma_warn_unused uword get_position(const uword i) const; arma_inline arma_hot void get_position(const uword i, uword& row_of_i, uword& col_of_i) const; /** * Add an element at the given position, and return a reference to it. The * element will be set to 0 (unless otherwise specified). If the element * already exists, its value will be overwritten. * * @param in_row Row of new element. * @param in_col Column of new element. * @param in_val Value to set new element to (default 0.0). */ inline arma_hot arma_warn_unused eT& add_element(const uword in_row, const uword in_col, const eT in_val = 0.0); /** * Delete an element at the given position. * * @param in_row Row of element to be deleted. * @param in_col Column of element to be deleted. */ inline arma_hot void delete_element(const uword in_row, const uword in_col); public: #ifdef ARMA_EXTRA_SPMAT_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPMAT_PROTO) #endif }; #define ARMA_HAS_SPMAT //! @} RcppArmadillo/inst/include/armadillo_bits/mul_syrk.hpp0000644000176000001440000002760112222720570023003 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup syrk //! @{ class syrk_helper { public: template inline static void inplace_copy_upper_tri_to_lower_tri(Mat& C) { // under the assumption that C is a square matrix const uword N = C.n_rows; for(uword k=0; k < N; ++k) { eT* colmem = C.colptr(k); uword i, j; for(i=(k+1), j=(k+2); j < N; i+=2, j+=2) { const eT tmp_i = C.at(k,i); const eT tmp_j = C.at(k,j); colmem[i] = tmp_i; colmem[j] = tmp_j; } if(i < N) { colmem[i] = C.at(k,i); } } } }; //! partial emulation of BLAS function syrk(), specialised for A being a vector template class syrk_vec { public: template arma_hot inline static void apply ( Mat& C, const TA& A, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); const uword A_n1 = (do_trans_A == false) ? A.n_rows : A.n_cols; const uword A_n2 = (do_trans_A == false) ? A.n_cols : A.n_rows; const eT* A_mem = A.memptr(); if(A_n1 == 1) { const eT acc1 = op_dot::direct_dot(A_n2, A_mem, A_mem); if( (use_alpha == false) && (use_beta == false) ) { C[0] = acc1; } else if( (use_alpha == true ) && (use_beta == false) ) { C[0] = alpha*acc1; } else if( (use_alpha == false) && (use_beta == true ) ) { C[0] = acc1 + beta*C[0]; } else if( (use_alpha == true ) && (use_beta == true ) ) { C[0] = alpha*acc1 + beta*C[0]; } } else for(uword k=0; k < A_n1; ++k) { const eT A_k = A_mem[k]; uword i,j; for(i=(k), j=(k+1); j < A_n1; i+=2, j+=2) { const eT acc1 = A_k * A_mem[i]; const eT acc2 = A_k * A_mem[j]; if( (use_alpha == false) && (use_beta == false) ) { C.at(k, i) = acc1; C.at(k, j) = acc2; C.at(i, k) = acc1; C.at(j, k) = acc2; } else if( (use_alpha == true ) && (use_beta == false) ) { const eT val1 = alpha*acc1; const eT val2 = alpha*acc2; C.at(k, i) = val1; C.at(k, j) = val2; C.at(i, k) = val1; C.at(j, k) = val2; } else if( (use_alpha == false) && (use_beta == true) ) { C.at(k, i) = acc1 + beta*C.at(k, i); C.at(k, j) = acc2 + beta*C.at(k, j); if(i != k) { C.at(i, k) = acc1 + beta*C.at(i, k); } C.at(j, k) = acc2 + beta*C.at(j, k); } else if( (use_alpha == true ) && (use_beta == true) ) { const eT val1 = alpha*acc1; const eT val2 = alpha*acc2; C.at(k, i) = val1 + beta*C.at(k, i); C.at(k, j) = val2 + beta*C.at(k, j); if(i != k) { C.at(i, k) = val1 + beta*C.at(i, k); } C.at(j, k) = val2 + beta*C.at(j, k); } } if(i < A_n1) { const eT acc1 = A_k * A_mem[i]; if( (use_alpha == false) && (use_beta == false) ) { C.at(k, i) = acc1; C.at(i, k) = acc1; } else if( (use_alpha == true) && (use_beta == false) ) { const eT val1 = alpha*acc1; C.at(k, i) = val1; C.at(i, k) = val1; } else if( (use_alpha == false) && (use_beta == true) ) { C.at(k, i) = acc1 + beta*C.at(k, i); if(i != k) { C.at(i, k) = acc1 + beta*C.at(i, k); } } else if( (use_alpha == true) && (use_beta == true) ) { const eT val1 = alpha*acc1; C.at(k, i) = val1 + beta*C.at(k, i); if(i != k) { C.at(i, k) = val1 + beta*C.at(i, k); } } } } } }; //! partial emulation of BLAS function syrk() template class syrk_emul { public: template arma_hot inline static void apply ( Mat& C, const TA& A, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); // do_trans_A == false -> C = alpha * A * A^T + beta*C // do_trans_A == true -> C = alpha * A^T * A + beta*C if(do_trans_A == false) { Mat AA; op_strans::apply_mat_noalias(AA, A); syrk_emul::apply(C, AA, alpha, beta); } else if(do_trans_A == true) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const eT* A_coldata = A.colptr(col_A); for(uword k=col_A; k < A_n_cols; ++k) { const eT acc = op_dot::direct_dot_arma(A_n_rows, A_coldata, A.colptr(k)); if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A, k) = acc; C.at(k, col_A) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { const eT val = alpha*acc; C.at(col_A, k) = val; C.at(k, col_A) = val; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A, k) = acc + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = acc + beta*C.at(k, col_A); } } else if( (use_alpha == true ) && (use_beta == true ) ) { const eT val = alpha*acc; C.at(col_A, k) = val + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = val + beta*C.at(k, col_A); } } } } } } }; template class syrk { public: template inline static void apply_blas_type( Mat& C, const TA& A, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); if(A.is_vec()) { // work around poor handling of vectors by syrk() in ATLAS 3.8.4 and standard BLAS syrk_vec::apply(C,A,alpha,beta); return; } const uword threshold = (is_cx::yes ? 16u : 48u); if( A.n_elem <= threshold ) { syrk_emul::apply(C,A,alpha,beta); } else { #if defined(ARMA_USE_ATLAS) { if(use_beta == true) { // use a temporary matrix, as we can't assume that matrix C is already symmetric Mat D(C.n_rows, C.n_cols); syrk::apply_blas_type(D,A,alpha); // NOTE: assuming beta=1; this is okay for now, as currently glue_times only uses beta=1 arrayops::inplace_plus(C.memptr(), D.memptr(), C.n_elem); return; } atlas::cblas_syrk ( atlas::CblasColMajor, atlas::CblasUpper, (do_trans_A) ? atlas::CblasTrans : atlas::CblasNoTrans, C.n_cols, (do_trans_A) ? A.n_rows : A.n_cols, (use_alpha) ? alpha : eT(1), A.mem, (do_trans_A) ? A.n_rows : C.n_cols, (use_beta) ? beta : eT(0), C.memptr(), C.n_cols ); syrk_helper::inplace_copy_upper_tri_to_lower_tri(C); } #elif defined(ARMA_USE_BLAS) { if(use_beta == true) { // use a temporary matrix, as we can't assume that matrix C is already symmetric Mat D(C.n_rows, C.n_cols); syrk::apply_blas_type(D,A,alpha); // NOTE: assuming beta=1; this is okay for now, as currently glue_times only uses beta=1 arrayops::inplace_plus(C.memptr(), D.memptr(), C.n_elem); return; } arma_extra_debug_print("blas::syrk()"); const char uplo = 'U'; const char trans_A = (do_trans_A) ? 'T' : 'N'; const blas_int n = C.n_cols; const blas_int k = (do_trans_A) ? A.n_rows : A.n_cols; const eT local_alpha = (use_alpha) ? alpha : eT(1); const eT local_beta = (use_beta) ? beta : eT(0); const blas_int lda = (do_trans_A) ? k : n; arma_extra_debug_print( arma_boost::format("blas::syrk(): trans_A = %c") % trans_A ); blas::syrk ( &uplo, &trans_A, &n, &k, &local_alpha, A.mem, &lda, &local_beta, C.memptr(), &n // &ldc ); syrk_helper::inplace_copy_upper_tri_to_lower_tri(C); } #else { syrk_emul::apply(C,A,alpha,beta); } #endif } } template inline static void apply( Mat& C, const TA& A, const eT alpha = eT(1), const eT beta = eT(0) ) { if(is_cx::no) { if(A.is_vec()) { syrk_vec::apply(C,A,alpha,beta); } else { syrk_emul::apply(C,A,alpha,beta); } } else { // handling of complex matrix by syrk_emul() is not yet implemented return; } } template arma_inline static void apply ( Mat& C, const TA& A, const float alpha = float(1), const float beta = float(0) ) { syrk::apply_blas_type(C,A,alpha,beta); } template arma_inline static void apply ( Mat& C, const TA& A, const double alpha = double(1), const double beta = double(0) ) { syrk::apply_blas_type(C,A,alpha,beta); } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { arma_ignore(C); arma_ignore(A); arma_ignore(alpha); arma_ignore(beta); // handling of complex matrix by syrk() is not yet implemented return; } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { arma_ignore(C); arma_ignore(A); arma_ignore(alpha); arma_ignore(beta); // handling of complex matrix by syrk() is not yet implemented return; } }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_cumsum_bones.hpp0000644000176000001440000000122512200631217024320 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_cumsum //! @{ class op_cumsum_mat { public: template inline static void apply(Mat& out, const Op& in); }; class op_cumsum_vec { public: template inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_resize_bones.hpp0000644000176000001440000000114512200631217024311 0ustar ripleyusers// Copyright (C) 2011 Conrad Sanderson // Copyright (C) 2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_resize //! @{ class op_resize { public: template inline static void apply( Mat& out, const Op& in); template inline static void apply(Cube& out, const OpCube& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/glue_relational_bones.hpp0000644000176000001440000000425012200375542025466 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_relational //! @{ class glue_rel_lt { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_gt { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_lteq { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_gteq { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_eq { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_noteq { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_elem.hpp0000644000176000001440000002723512256511734022555 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_elem //! @{ // // real template arma_inline const T1& real(const Base& X) { arma_extra_debug_sigprint(); return X.get_ref(); } template arma_inline const T1& real(const BaseCube& X) { arma_extra_debug_sigprint(); return X.get_ref(); } template inline const mtOp real(const Base, T1>& X) { arma_extra_debug_sigprint(); return mtOp( X.get_ref() ); } template inline const mtOpCube real(const BaseCube, T1>& X) { arma_extra_debug_sigprint(); return mtOpCube( X.get_ref() ); } // // imag template inline const Gen< Mat, gen_zeros > imag(const Base& X) { arma_extra_debug_sigprint(); const Proxy A(X.get_ref()); return Gen< Mat, gen_zeros>(A.get_n_rows(), A.get_n_cols()); } template inline const GenCube imag(const BaseCube& X) { arma_extra_debug_sigprint(); const ProxyCube A(X.get_ref()); return GenCube(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); } template inline const mtOp imag(const Base, T1>& X) { arma_extra_debug_sigprint(); return mtOp( X.get_ref() ); } template inline const mtOpCube imag(const BaseCube,T1>& X) { arma_extra_debug_sigprint(); return mtOpCube( X.get_ref() ); } // // log template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result log(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube log(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // log2 template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result log2(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube log2(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // log10 template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result log10(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube log10(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // exp template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result exp(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube exp(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // exp2 template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result exp2(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube exp2(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // exp10 template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result exp10(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube exp10(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // abs template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result abs(const T1& X, const typename arma_not_cx::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return eOp(X); } template arma_inline const eOpCube abs(const BaseCube& X, const typename arma_not_cx::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return eOpCube(X.get_ref()); } template inline const mtOp abs(const Base, T1>& X, const typename arma_cx_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtOp( X.get_ref() ); } template inline const mtOpCube abs(const BaseCube< std::complex,T1>& X, const typename arma_cx_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtOpCube( X.get_ref() ); } template arma_inline const SpOp abs(const SpBase& X, const typename arma_not_cx::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return SpOp(X.get_ref()); } template arma_inline const mtSpOp abs(const SpBase< std::complex, T1>& X, const typename arma_cx_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtSpOp(X.get_ref()); } // // square template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result square(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube square(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } template arma_inline const SpOp square(const SpBase& A) { arma_extra_debug_sigprint(); return SpOp(A.get_ref()); } // // sqrt template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result sqrt(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube sqrt(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } template arma_inline const SpOp sqrt(const SpBase& A) { arma_extra_debug_sigprint(); return SpOp(A.get_ref()); } // // conj template arma_inline const T1& conj(const Base& A) { arma_extra_debug_sigprint(); return A.get_ref(); } template arma_inline const T1& conj(const BaseCube& A) { arma_extra_debug_sigprint(); return A.get_ref(); } template arma_inline const eOp conj(const Base,T1>& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube conj(const BaseCube,T1>& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } template arma_inline const T1& conj(const eOp& A) { arma_extra_debug_sigprint(); return A.m; } template arma_inline const T1& conj(const eOpCube& A) { arma_extra_debug_sigprint(); return A.m; } // pow template arma_inline const eOp pow(const Base& A, const typename T1::elem_type exponent) { arma_extra_debug_sigprint(); return eOp(A.get_ref(), exponent); } template arma_inline const eOpCube pow(const BaseCube& A, const typename T1::elem_type exponent) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref(), exponent); } // pow, specialised handling (non-complex exponent for complex matrices) template arma_inline const eOp pow(const Base& A, const typename T1::elem_type::value_type exponent) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; return eOp(A.get_ref(), eT(exponent)); } template arma_inline const eOpCube pow(const BaseCube& A, const typename T1::elem_type::value_type exponent) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; return eOpCube(A.get_ref(), eT(exponent)); } // // floor template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result floor(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube floor(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // ceil template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result ceil(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube ceil(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // round template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result round(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube round(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // sign template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result sign(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube sign(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } //! @} RcppArmadillo/inst/include/armadillo_bits/mtOp_bones.hpp0000644000176000001440000000337012202101406023225 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup mtOp //! @{ template class mtOp : public Base > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef typename T1::elem_type in_eT; static const bool is_row = T1::is_row && is_op_mixed_elem::value; static const bool is_col = T1::is_col && is_op_mixed_elem::value; inline explicit mtOp(const T1& in_m); inline mtOp(const T1& in_m, const in_eT in_aux); inline mtOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline mtOp(const T1& in_m, const in_eT in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b); inline mtOp(const char junk, const T1& in_m, const out_eT in_aux); inline ~mtOp(); arma_aligned const T1& m; //!< storage of reference to the operand (eg. a matrix) arma_aligned in_eT aux; //!< storage of auxiliary data, using the element type as used by T1 arma_aligned out_eT aux_out_eT; //!< storage of auxiliary data, using the element type as specified by the out_eT template parameter arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_sort_index.hpp0000644000176000001440000001352512254740076024007 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_sort_index //! @{ template struct arma_sort_index_packet { T1 val; T2 index; }; class arma_sort_index_helper_ascend { public: template arma_inline bool operator() (const arma_sort_index_packet& A, const arma_sort_index_packet& B) const { return (A.val < B.val); } }; class arma_sort_index_helper_descend { public: template arma_inline bool operator() (const arma_sort_index_packet& A, const arma_sort_index_packet& B) const { return (A.val > B.val); } }; template void inline sort_index_helper(umat_elem_type* out_mem, const eT* in_mem, const uword n_elem) { arma_extra_debug_sigprint(); std::vector< arma_sort_index_packet > packet_vec(n_elem); for(uword i=0; i inline umat sort_index ( const Base& X, const uword sort_type = 0, const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; if(A.is_empty() == true) { return umat(); } arma_debug_check( (A.is_vec() == false), "sort_index(): currently only handles vectors"); typedef typename umat::elem_type out_elem_type; umat out(A.n_rows, A.n_cols); if(sort_type == 0) { sort_index_helper(out.memptr(), A.mem, A.n_elem); } else { sort_index_helper(out.memptr(), A.mem, A.n_elem); } return out; } //! kept for compatibility with old code template inline umat stable_sort_index ( const Base& X, const uword sort_type = 0, const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; if(A.is_empty() == true) { return umat(); } arma_debug_check( (A.is_vec() == false), "stable_sort_index(): currently only handles vectors"); typedef typename umat::elem_type out_elem_type; umat out(A.n_rows, A.n_cols); if(sort_type == 0) { sort_index_helper(out.memptr(), A.mem, A.n_elem); } else { sort_index_helper(out.memptr(), A.mem, A.n_elem); } return out; } template inline typename enable_if2 < ( (is_arma_type::value == true) && (is_same_type::value == true) && (is_cx::value == false) ), umat >::result sort_index ( const T1& X, const T2* sort_direction ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(X); const Mat& A = tmp.M; if(A.is_empty() == true) { return umat(); } arma_debug_check( (A.is_vec() == false), "sort_index(): currently only handles vectors"); const char sig = sort_direction[0]; arma_debug_check( ((sig != 'a') && (sig != 'd')), "sort_index(): unknown sort direction" ); typedef typename umat::elem_type out_elem_type; umat out(A.n_rows, A.n_cols); if(sig == 'a') { sort_index_helper(out.memptr(), A.mem, A.n_elem); } else { sort_index_helper(out.memptr(), A.mem, A.n_elem); } return out; } template inline typename enable_if2 < ( (is_arma_type::value == true) && (is_same_type::value == true) && (is_cx::value == false) ), umat >::result stable_sort_index ( const T1& X, const T2* sort_direction ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(X); const Mat& A = tmp.M; if(A.is_empty() == true) { return umat(); } arma_debug_check( (A.is_vec() == false), "stable_sort_index(): currently only handles vectors"); const char sig = sort_direction[0]; arma_debug_check( ((sig != 'a') && (sig != 'd')), "stable_sort_index(): unknown sort direction" ); typedef typename umat::elem_type out_elem_type; umat out(A.n_rows, A.n_cols); if(sig == 'a') { sort_index_helper(out.memptr(), A.mem, A.n_elem); } else { sort_index_helper(out.memptr(), A.mem, A.n_elem); } return out; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_vectorise_bones.hpp0000644000176000001440000000206112256607540025026 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_vectorise //! @{ class op_vectorise_col { public: template inline static void apply( Mat& out, const Op& in); template inline static void apply_proxy( Mat& out, const Proxy& P); }; class op_vectorise_row { public: template inline static void apply( Mat& out, const Op& in); template inline static void apply_proxy( Mat& out, const Proxy& P); }; class op_vectorise_all { public: template inline static void apply( Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_solve.hpp0000644000176000001440000000726112244603630022752 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_solve //! @{ //! Solve a system of linear equations, i.e., A*X = B, where X is unknown. //! For a square matrix A, this function is conceptually the same as X = inv(A)*B, //! but is done more efficiently. //! The number of rows in A and B must be the same. //! B can be either a column vector or a matrix. //! This function will also try to provide approximate solutions //! to under-determined as well as over-determined systems (non-square A matrices). template inline const Glue solve ( const Base& A, const Base& B, const bool slow = false, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Glue(A.get_ref(), B.get_ref(), ((slow == false) ? 0 : 1) ); } template inline const Glue solve ( const Base& A, const Base& B, const char* method, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'f')), "solve(): unknown method specified" ); return Glue( A.get_ref(), B.get_ref(), ((sig == 'f') ? 0 : 1) ); } template inline const Glue solve ( const Op& A, const Base& B, const bool slow = false, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(slow); arma_ignore(junk); return Glue(A.m, B.get_ref(), A.aux_uword_a); } template inline const Glue solve ( const Op& A, const Base& B, const char* method, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'f')), "solve(): unknown method specified" ); return Glue(A.m, B.get_ref(), A.aux_uword_a); } template inline bool solve ( Mat& out, const Base& A, const Base& B, const bool slow = false, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = solve( A.get_ref(), B.get_ref(), slow ); } catch(std::runtime_error&) { return false; } return true; } template inline bool solve ( Mat& out, const Base& A, const Base& B, const char* method, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = solve( A.get_ref(), B.get_ref(), method ); } catch(std::runtime_error&) { return false; } return true; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_chol_meat.hpp0000644000176000001440000000120212200631217023547 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_chol //! @{ template inline void op_chol::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); const bool status = auxlib::chol(out, X.m); if(status == false) { out.reset(); arma_bad("chol(): failed to converge"); } } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_stddev.hpp0000644000176000001440000000334212200375542023107 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_stddev //! @{ template inline const mtOp stddev ( const T1& X, const uword norm_type = 0, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return mtOp(X, norm_type, dim); } template inline const mtOp stddev ( const T1& X, const uword norm_type, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtOp(X, norm_type, dim); } template inline arma_warn_unused typename T1::pod_type stddev ( const T1& X, const uword norm_type = 0, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return std::sqrt( op_var::var_vec(X, norm_type) ); } template arma_inline arma_warn_unused const typename arma_scalar_only::result stddev(const T&) { return T(0); } //! @} RcppArmadillo/inst/include/armadillo_bits/include_atlas.hpp0000644000176000001440000000163512176655102023752 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #if defined(ARMA_USE_ATLAS) #if !defined(ARMA_ATLAS_INCLUDE_DIR) extern "C" { #include #include } #else #define ARMA_STR1(x) x #define ARMA_STR2(x) ARMA_STR1(x) #define ARMA_CBLAS ARMA_STR2(ARMA_ATLAS_INCLUDE_DIR)ARMA_STR2(cblas.h) #define ARMA_CLAPACK ARMA_STR2(ARMA_ATLAS_INCLUDE_DIR)ARMA_STR2(clapack.h) extern "C" { #include ARMA_INCFILE_WRAP(ARMA_CBLAS) #include ARMA_INCFILE_WRAP(ARMA_CLAPACK) } #undef ARMA_STR1 #undef ARMA_STR2 #undef ARMA_CBLAS #undef ARMA_CLAPACK #endif #endif RcppArmadillo/inst/include/armadillo_bits/fn_flip.hpp0000644000176000001440000000132112200375542022543 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_flip //! @{ template arma_inline const Op flipud(const Base& X) { arma_extra_debug_sigprint(); return Op(X.get_ref()); } template arma_inline const Op fliplr(const Base& X) { arma_extra_debug_sigprint(); return Op(X.get_ref()); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_vectorise.hpp0000644000176000001440000000160112176420204023613 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_vectorise //! @{ template inline typename enable_if2 < is_arma_type::value, const Op >::result vectorise(const T1& X) { arma_extra_debug_sigprint(); return Op(X); } template inline typename enable_if2 < is_arma_type::value, const Op >::result vectorise(const T1& X, const uword dim) { arma_extra_debug_sigprint(); arma_debug_check( (dim > 1), "vectorise(): dim must be 0 or 1"); return Op(X, dim, 0); } //! @} RcppArmadillo/inst/include/armadillo_bits/operator_plus.hpp0000644000176000001440000001202712177612510024033 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_plus //! @{ //! unary plus operation (does nothing, but is required for completeness) template arma_inline typename enable_if2< is_arma_type::value, const T1& >::result operator+ (const T1& X) { arma_extra_debug_sigprint(); return X; } //! Base + scalar template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator+ (const T1& X, const typename T1::elem_type k) { arma_extra_debug_sigprint(); return eOp(X, k); } //! scalar + Base template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator+ (const typename T1::elem_type k, const T1& X) { arma_extra_debug_sigprint(); return eOp(X, k); // NOTE: order is swapped } //! non-complex Base + complex scalar template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_plus> >::result operator+ ( const T1& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_plus>('j', X, k); } //! complex scalar + non-complex Base template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_plus> >::result operator+ ( const std::complex& k, const T1& X ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_plus>('j', X, k); // NOTE: order is swapped } //! addition of user-accessible Armadillo objects with same element type template arma_inline typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value, const eGlue >::result operator+ ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return eGlue(X, Y); } //! addition of user-accessible Armadillo objects with different element types template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_same_type::no)), const mtGlue::result, T1, T2, glue_mixed_plus> >::result operator+ ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlue( X, Y ); } //! addition of two sparse objects template inline arma_hot typename enable_if2 < (is_arma_sparse_type::value && is_arma_sparse_type::value && is_same_type::value), SpGlue >::result operator+ ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); return SpGlue(x, y); } //! addition of sparse and non-sparse object template inline typename enable_if2 < (is_arma_type::value && is_arma_sparse_type::value && is_same_type::value), Mat >::result operator+ ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); Mat result(x); const SpProxy pb(y); arma_debug_assert_same_size( result.n_rows, result.n_cols, pb.get_n_rows(), pb.get_n_cols(), "addition" ); typename SpProxy::const_iterator_type it = pb.begin(); typename SpProxy::const_iterator_type it_end = pb.end(); while(it != it_end) { result.at(it.row(), it.col()) += (*it); ++it; } return result; } //! addition of sparse and non-sparse object template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_type::value && is_same_type::value), Mat >::result operator+ ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); // Just call the other order (these operations are commutative) return (y + x); } //! @} RcppArmadillo/inst/include/armadillo_bits/wall_clock_bones.hpp0000644000176000001440000000155112251611645024436 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup wall_clock //! @{ //! Class for measuring time intervals class wall_clock { public: inline wall_clock(); inline ~wall_clock(); inline void tic(); //!< start the timer inline double toc(); //!< return the number of seconds since the last call to tic() private: bool valid; #if defined(ARMA_USE_CXX11) std::chrono::steady_clock::time_point chrono_time1; #elif defined(ARMA_HAVE_GETTIMEOFDAY) struct timeval posix_time1; struct timeval posix_time2; #else clock_t time1; #endif }; //! @} RcppArmadillo/inst/include/armadillo_bits/unwrap_spmat.hpp0000644000176000001440000000366412176655102023667 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup unwrap_spmat //! @{ template struct unwrap_spmat { typedef typename T1::elem_type eT; inline unwrap_spmat(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const SpMat M; }; template struct unwrap_spmat< SpMat > { inline unwrap_spmat(const SpMat& A) : M(A) { arma_extra_debug_sigprint(); } const SpMat& M; }; template struct unwrap_spmat< SpRow > { inline unwrap_spmat(const SpRow& A) : M(A) { arma_extra_debug_sigprint(); } const SpRow& M; }; template struct unwrap_spmat< SpCol > { inline unwrap_spmat(const SpCol& A) : M(A) { arma_extra_debug_sigprint(); } const SpCol& M; }; template struct unwrap_spmat< SpOp > { typedef typename T1::elem_type eT; inline unwrap_spmat(const SpOp& A) : M(A) { arma_extra_debug_sigprint(); } const SpMat M; }; template struct unwrap_spmat< SpGlue > { typedef typename T1::elem_type eT; inline unwrap_spmat(const SpGlue& A) : M(A) { arma_extra_debug_sigprint(); } const SpMat M; }; template struct unwrap_spmat< mtSpOp > { inline unwrap_spmat(const mtSpOp& A) : M(A) { arma_extra_debug_sigprint(); } const SpMat M; }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_flip_meat.hpp0000644000176000001440000000263712200631217023571 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_flip //! @{ template inline void op_flipud::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m); const Mat X = tmp.M; if(&out != &X) { out.copy_size(X); for(uword i=0; i inline void op_fliplr::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m); const Mat X = tmp.M; if(&out != &X) { out.copy_size(X); for(uword i=0; i arma_hot inline static void apply(SpMat& out, const SpGlue& X); template arma_hot inline static void apply_noalias(SpMat& result, const SpProxy& pa, const SpProxy& pb); }; class spglue_minus2 { public: template arma_hot inline static void apply(SpMat& out, const SpGlue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/glue_min_meat.hpp0000644000176000001440000000576412244135164023754 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_min //! @{ template inline void glue_min::apply(Mat& out, const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); const uword n_rows = PA.get_n_rows(); const uword n_cols = PA.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, PB.get_n_rows(), PB.get_n_cols(), "min(): given objects do not have the same size"); out.set_size(n_rows, n_cols); eT* out_mem = out.memptr(); if( (Proxy::prefer_at_accessor == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type A = PA.get_ea(); typename Proxy::ea_type B = PB.get_ea(); const uword N = PA.get_n_elem(); for(uword i=0; i inline void glue_min::apply(Mat< std::complex >& out, const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const uword n_rows = PA.get_n_rows(); const uword n_cols = PA.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, PB.get_n_rows(), PB.get_n_cols(), "min(): given objects do not have the same size"); out.set_size(n_rows, n_cols); eT* out_mem = out.memptr(); if( (Proxy::prefer_at_accessor == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type A = PA.get_ea(); typename Proxy::ea_type B = PB.get_ea(); const uword N = PA.get_n_elem(); for(uword i=0; i inline void glue_min::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy PA(X.A); const Proxy PB(X.B); if(PA.is_alias(out) || PB.is_alias(out)) { Mat tmp; glue_min::apply(tmp, PA, PB); out.steal_mem(tmp); } else { glue_min::apply(out, PA, PB); } } //! @} RcppArmadillo/inst/include/armadillo_bits/Gen_meat.hpp0000644000176000001440000001543112246034243022654 0ustar ripleyusers// Copyright (C) 2011-2013 Conrad Sanderson // Copyright (C) 2011-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Gen //! @{ template arma_inline Gen::Gen(const uword in_n_rows, const uword in_n_cols) : n_rows(in_n_rows) , n_cols(in_n_cols) { arma_extra_debug_sigprint(); } template arma_inline Gen::~Gen() { arma_extra_debug_sigprint(); } template arma_inline typename T1::elem_type Gen::generate() { typedef typename T1::elem_type eT; if(is_same_type::yes) { return eT(1); } else if(is_same_type::yes) { return eT(0); } else if(is_same_type::yes) { return eT(arma_rng::randu()); } else if(is_same_type::yes) { return eT(arma_rng::randn()); } else { return eT(); } } template arma_inline typename T1::elem_type Gen::operator[](const uword ii) const { typedef typename T1::elem_type eT; if(is_same_type::yes) { return ((ii % n_rows) == (ii / n_rows)) ? eT(1) : eT(0); } else { return Gen::generate(); } } template arma_inline typename T1::elem_type Gen::at(const uword row, const uword col) const { typedef typename T1::elem_type eT; if(is_same_type::yes) { return (row == col) ? eT(1) : eT(0); } else { return Gen::generate(); } } template arma_inline typename T1::elem_type Gen::at_alt(const uword ii) const { return operator[](ii); } template inline void Gen::apply(Mat& out) const { arma_extra_debug_sigprint(); // NOTE: we're assuming that the matrix has already been set to the correct size; // this is done by either the Mat contructor or operator=() if(is_same_type::yes) { out.eye(); } else if(is_same_type::yes) { out.ones(); } else if(is_same_type::yes) { out.zeros(); } else if(is_same_type::yes) { out.randu(); } else if(is_same_type::yes) { out.randn(); } } template inline void Gen::apply_inplace_plus(Mat& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addition"); typedef typename T1::elem_type eT; if(is_same_type::yes) { const uword N = (std::min)(n_rows, n_cols); for(uword iq=0; iq < N; ++iq) { out.at(iq,iq) += eT(1); } } else { eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword iq,jq; for(iq=0, jq=1; jq < n_elem; iq+=2, jq+=2) { const eT tmp_i = Gen::generate(); const eT tmp_j = Gen::generate(); out_mem[iq] += tmp_i; out_mem[jq] += tmp_j; } if(iq < n_elem) { out_mem[iq] += Gen::generate(); } } } template inline void Gen::apply_inplace_minus(Mat& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subtraction"); typedef typename T1::elem_type eT; if(is_same_type::yes) { const uword N = (std::min)(n_rows, n_cols); for(uword iq=0; iq < N; ++iq) { out.at(iq,iq) -= eT(1); } } else { eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword iq,jq; for(iq=0, jq=1; jq < n_elem; iq+=2, jq+=2) { const eT tmp_i = Gen::generate(); const eT tmp_j = Gen::generate(); out_mem[iq] -= tmp_i; out_mem[jq] -= tmp_j; } if(iq < n_elem) { out_mem[iq] -= Gen::generate(); } } } template inline void Gen::apply_inplace_schur(Mat& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise multiplication"); typedef typename T1::elem_type eT; if(is_same_type::yes) { const uword N = (std::min)(n_rows, n_cols); for(uword iq=0; iq < N; ++iq) { for(uword row=0; row < iq; ++row) { out.at(row,iq) = eT(0); } for(uword row=iq+1; row < n_rows; ++row) { out.at(row,iq) = eT(0); } } } else { eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword iq,jq; for(iq=0, jq=1; jq < n_elem; iq+=2, jq+=2) { const eT tmp_i = Gen::generate(); const eT tmp_j = Gen::generate(); out_mem[iq] *= tmp_i; out_mem[jq] *= tmp_j; } if(iq < n_elem) { out_mem[iq] *= Gen::generate(); } } } template inline void Gen::apply_inplace_div(Mat& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise division"); typedef typename T1::elem_type eT; if(is_same_type::yes) { const uword N = (std::min)(n_rows, n_cols); for(uword iq=0; iq < N; ++iq) { const eT zero = eT(0); for(uword row=0; row < iq; ++row) { out.at(row,iq) /= zero; } for(uword row=iq+1; row < n_rows; ++row) { out.at(row,iq) /= zero; } } } else { eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword iq,jq; for(iq=0, jq=1; jq < n_elem; iq+=2, jq+=2) { const eT tmp_i = Gen::generate(); const eT tmp_j = Gen::generate(); out_mem[iq] /= tmp_i; out_mem[jq] /= tmp_j; } if(iq < n_elem) { out_mem[iq] /= Gen::generate(); } } } //! @} RcppArmadillo/inst/include/armadillo_bits/SpCol_bones.hpp0000644000176000001440000000561512111344723023344 0ustar ripleyusers// Copyright (C) 2011-2012 Ryan Curtin // Copyright (C) 2011 Matthew Amidon // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpCol //! @{ //! Class for sparse column vectors (matrices with only one column) template class SpCol : public SpMat { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; inline SpCol(); inline explicit SpCol(const uword n_elem); inline SpCol(const uword in_rows, const uword in_cols); inline SpCol(const char* text); inline const SpCol& operator=(const char* text); inline SpCol(const std::string& text); inline const SpCol& operator=(const std::string& text); inline const SpCol& operator=(const eT val); template inline SpCol(const Base& X); template inline const SpCol& operator=(const Base& X); template inline SpCol(const SpBase& X); template inline const SpCol& operator=(const SpBase& X); template inline explicit SpCol(const SpBase& A, const SpBase& B); inline SpValProxy > row(const uword row_num); inline eT row(const uword row_num) const; // arma_inline subview_col rows(const uword in_row1, const uword in_row2); // arma_inline const subview_col rows(const uword in_row1, const uword in_row2) const; // arma_inline subview_col subvec(const uword in_row1, const uword in_row2); // arma_inline const subview_col subvec(const uword in_row1, const uword in_row2) const; // arma_inline subview_col subvec(const span& row_span); // arma_inline const subview_col subvec(const span& row_span) const; inline void shed_row (const uword row_num); inline void shed_rows(const uword in_row1, const uword in_row2); // inline void insert_rows(const uword row_num, const uword N, const bool set_to_zero = true); // template inline void insert_rows(const uword row_num, const Base& X); typedef typename SpMat::iterator row_iterator; typedef typename SpMat::const_iterator const_row_iterator; inline row_iterator begin_row(const uword row_num = 0); inline const_row_iterator begin_row(const uword row_num = 0) const; inline row_iterator end_row (const uword row_num = 0); inline const_row_iterator end_row (const uword row_num = 0) const; #ifdef ARMA_EXTRA_SPCOL_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPCOL_PROTO) #endif }; RcppArmadillo/inst/include/armadillo_bits/fn_inv.hpp0000644000176000001440000000743512256741666022440 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_inv //! @{ //! delayed matrix inverse (general matrices) template arma_inline const Op inv ( const Base& X, const bool slow = false, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X.get_ref(), ((slow == false) ? 0 : 1), 0); } template arma_inline const Op inv ( const Base& X, const char* method, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'f')), "inv(): unknown method specified" ); return Op(X.get_ref(), ((sig == 'f') ? 0 : 1), 0); } //! delayed matrix inverse (triangular matrices) template arma_inline const Op inv ( const Op& X, const bool slow = false, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(slow); arma_ignore(junk); return Op(X.m, X.aux_uword_a, 0); } template arma_inline const Op inv ( const Op& X, const char* method, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'f')), "inv(): unknown method specified" ); return Op(X.m, X.aux_uword_a, 0); } template inline bool inv ( Mat& out, const Base& X, const bool slow = false, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = inv(X,slow); } catch(std::runtime_error&) { return false; } return true; } template inline bool inv ( Mat& out, const Base& X, const char* method, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = inv(X,method); } catch(std::runtime_error&) { return false; } return true; } //! inverse of symmetric positive definite matrices template arma_inline const Op inv_sympd ( const Base& X, const char* method = "std", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'f')), "inv_sympd(): unknown method specified" ); return Op(X.get_ref(), 0, 0); } template inline bool inv_sympd ( Mat& out, const Base& X, const char* method = "std", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = inv_sympd(X,method); } catch(std::runtime_error&) { return false; } return true; } //! @} RcppArmadillo/inst/include/armadillo_bits/subview_field_bones.hpp0000644000176000001440000000346712176655102025165 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup subview_field //! @{ //! Class for storing data required to construct or apply operations to a subfield //! (i.e. where the subfield starts and ends as well as a reference/pointer to the original field), template class subview_field { public: typedef oT object_type; const field& f; const uword aux_row1; const uword aux_col1; const uword n_rows; const uword n_cols; const uword n_elem; protected: arma_inline subview_field(const field& in_f, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); public: inline ~subview_field(); inline void operator= (const field& x); inline void operator= (const subview_field& x); arma_inline oT& operator[](const uword i); arma_inline const oT& operator[](const uword i) const; arma_inline oT& operator()(const uword i); arma_inline const oT& operator()(const uword i) const; arma_inline oT& at(const uword row, const uword col); arma_inline const oT& at(const uword row, const uword col) const; arma_inline oT& operator()(const uword row, const uword col); arma_inline const oT& operator()(const uword row, const uword col) const; inline bool check_overlap(const subview_field& x) const; inline static void extract(field& out, const subview_field& in); private: friend class field; subview_field(); //subview_field(const subview_field&); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_fft2.hpp0000644000176000001440000000472712216161240022462 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_fft2 //! @{ // 2D FFT & 2D IFFT template inline typename enable_if2 < is_arma_type::value, Mat< std::complex > >::result fft2(const T1& A) { arma_extra_debug_sigprint(); // not exactly efficient, but "better-than-nothing" implementation typedef typename T1::pod_type T; Mat< std::complex > B = fft(A); // for square matrices, strans() will work out that an inplace transpose can be done, // hence we can potentially avoid creating a temporary matrix B = strans(B); return strans( fft(B) ); } template inline typename enable_if2 < is_arma_type::value, Mat< std::complex > >::result fft2(const T1& A, const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(A); const Mat& B = tmp.M; const bool do_resize = (B.n_rows != n_rows) || (B.n_cols != n_cols); return fft2( do_resize ? resize(B,n_rows,n_cols) : B ); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), Mat< std::complex > >::result ifft2(const T1& A) { arma_extra_debug_sigprint(); // not exactly efficient, but "better-than-nothing" implementation typedef typename T1::pod_type T; Mat< std::complex > B = ifft(A); // for square matrices, strans() will work out that an inplace transpose can be done, // hence we can potentially avoid creating a temporary matrix B = strans(B); return strans( ifft(B) ); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), Mat< std::complex > >::result ifft2(const T1& A, const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(A); const Mat& B = tmp.M; const bool do_resize = (B.n_rows != n_rows) || (B.n_cols != n_cols); return ifft2( do_resize ? resize(B,n_rows,n_cols) : B ); } //! @} RcppArmadillo/inst/include/armadillo_bits/fft_engine.hpp0000644000176000001440000002465612127576022023256 0ustar ripleyusers// This Source Code Form is a compilation of: // (1) source code written by Conrad Sanderson, and // (2) a modified form of source code referred to as "kissfft.hh". // // This compilation is Copyright (C) 2013 Conrad Sanderson // and is subject to the terms of the Mozilla Public License, v. 2.0. // // The source code that is distinct and separate from "kissfft.hh" // is Copyright (C) 2013 Conrad Sanderson and is subject to the // terms of the Mozilla Public License, v. 2.0. // // If a copy of the MPL was not distributed with this file, // You can obtain one at http://mozilla.org/MPL/2.0/. // // The original "kissfft.hh" source code is licensed under a 3-clause BSD license, // as follows: // // Copyright (c) 2003-2010 Mark Borgerding // // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // * Neither the author nor the names of any contributors may be used to endorse or promote // products derived from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. template struct store {}; template struct store { static const uword N = fixed_N; arma_aligned cx_type coeffs_array[fixed_N]; inline store() {} inline store(uword) {} arma_inline cx_type* coeffs_ptr() { return &coeffs_array[0]; } arma_inline const cx_type* coeffs_ptr() const { return &coeffs_array[0]; } }; template struct store { const uword N; podarray coeffs_array; inline store() : N(0) {} inline store(uword in_N) : N(in_N) { coeffs_array.set_size(N); } arma_inline cx_type* coeffs_ptr() { return coeffs_array.memptr(); } arma_inline const cx_type* coeffs_ptr() const { return coeffs_array.memptr(); } }; template class fft_engine : public store 0)> { public: typedef typename get_pod_type::result T; using store 0)>::N; using store 0)>::coeffs_ptr; podarray residue; podarray radix; podarray tmp_array; template inline uword calc_radix() { uword i = 0; for(uword n = N, r=4; n >= 2; ++i) { while( (n % r) > 0 ) { switch(r) { case 2: r = 3; break; case 4: r = 2; break; default: r += 2; break; } if(r*r > n) { r = n; } } n /= r; if(fill) { residue[i] = n; radix[i] = r; } } return i; } inline fft_engine(const uword in_N) : store< cx_type, fixed_N, (fixed_N > 0) >(in_N) { arma_extra_debug_sigprint(); const uword len = calc_radix(); residue.set_size(len); radix.set_size(len); calc_radix(); // calculate the constant coefficients cx_type* coeffs = coeffs_ptr(); const T k = T( (inverse) ? +2 : -2 ) * std::acos( T(-1) ) / T(N); for(uword i=0; i < N; ++i) { coeffs[i] = std::exp( cx_type(T(0), i*k) ); } } arma_hot inline void butterfly_2(cx_type* Y, const uword stride, const uword m) { arma_extra_debug_sigprint(); const cx_type* coeffs = coeffs_ptr(); for(uword i=0; i < m; ++i) { const cx_type t = Y[i+m] * coeffs[i*stride]; Y[i+m] = Y[i] - t; Y[i ] += t; } } arma_hot inline void butterfly_3(cx_type* Y, const uword stride, const uword m) { arma_extra_debug_sigprint(); arma_aligned cx_type tmp[5]; cx_type* coeffs1 = coeffs_ptr(); cx_type* coeffs2 = coeffs1; const T coeff_sm_imag = coeffs1[stride*m].imag(); const uword n = m*2; // TODO: rearrange the indices within tmp[] into a more sane order for(uword i = m; i > 0; --i) { tmp[1] = Y[m] * (*coeffs1); tmp[2] = Y[n] * (*coeffs2); tmp[0] = tmp[1] - tmp[2]; tmp[0] *= coeff_sm_imag; tmp[3] = tmp[1] + tmp[2]; Y[m] = cx_type( (Y[0].real() - (0.5*tmp[3].real())), (Y[0].imag() - (0.5*tmp[3].imag())) ); Y[0] += tmp[3]; Y[n] = cx_type( (Y[m].real() + tmp[0].imag()), (Y[m].imag() - tmp[0].real()) ); Y[m] += cx_type( -tmp[0].imag(), tmp[0].real() ); Y++; coeffs1 += stride; coeffs2 += stride*2; } } arma_hot inline void butterfly_4(cx_type* Y, const uword stride, const uword m) { arma_extra_debug_sigprint(); arma_aligned cx_type tmp[7]; const cx_type* coeffs = coeffs_ptr(); const uword m2 = m*2; const uword m3 = m*3; // TODO: rearrange the indices within tmp[] into a more sane order for(uword i=0; i < m; ++i) { tmp[0] = Y[i + m ] * coeffs[i*stride ]; tmp[2] = Y[i + m3] * coeffs[i*stride*3]; tmp[3] = tmp[0] + tmp[2]; //tmp[4] = tmp[0] - tmp[2]; //tmp[4] = (inverse) ? cx_type( -(tmp[4].imag()), tmp[4].real() ) : cx_type( tmp[4].imag(), -tmp[4].real() ); tmp[4] = (inverse) ? cx_type( (tmp[2].imag() - tmp[0].imag()), (tmp[0].real() - tmp[2].real()) ) : cx_type( (tmp[0].imag() - tmp[2].imag()), (tmp[2].real() - tmp[0].real()) ); tmp[1] = Y[i + m2] * coeffs[i*stride*2]; tmp[5] = Y[i] - tmp[1]; Y[i ] += tmp[1]; Y[i + m2] = Y[i] - tmp[3]; Y[i ] += tmp[3]; Y[i + m ] = tmp[5] + tmp[4]; Y[i + m3] = tmp[5] - tmp[4]; } } inline arma_hot void butterfly_5(cx_type* Y, const uword stride, const uword m) { arma_extra_debug_sigprint(); arma_aligned cx_type tmp[13]; const cx_type* coeffs = coeffs_ptr(); const T a_real = coeffs[stride*1*m].real(); const T a_imag = coeffs[stride*1*m].imag(); const T b_real = coeffs[stride*2*m].real(); const T b_imag = coeffs[stride*2*m].imag(); cx_type* Y0 = Y; cx_type* Y1 = Y + 1*m; cx_type* Y2 = Y + 2*m; cx_type* Y3 = Y + 3*m; cx_type* Y4 = Y + 4*m; for(uword i=0; i < m; ++i) { tmp[0] = (*Y0); tmp[1] = (*Y1) * coeffs[stride*1*i]; tmp[2] = (*Y2) * coeffs[stride*2*i]; tmp[3] = (*Y3) * coeffs[stride*3*i]; tmp[4] = (*Y4) * coeffs[stride*4*i]; tmp[7] = tmp[1] + tmp[4]; tmp[8] = tmp[2] + tmp[3]; tmp[9] = tmp[2] - tmp[3]; tmp[10] = tmp[1] - tmp[4]; (*Y0) += tmp[7]; (*Y0) += tmp[8]; tmp[5] = tmp[0] + cx_type( ( (tmp[7].real() * a_real) + (tmp[8].real() * b_real) ), ( (tmp[7].imag() * a_real) + (tmp[8].imag() * b_real) ) ); tmp[6] = cx_type( ( (tmp[10].imag() * a_imag) + (tmp[9].imag() * b_imag) ), ( -(tmp[10].real() * a_imag) - (tmp[9].real() * b_imag) ) ); (*Y1) = tmp[5] - tmp[6]; (*Y4) = tmp[5] + tmp[6]; tmp[11] = tmp[0] + cx_type( ( (tmp[7].real() * b_real) + (tmp[8].real() * a_real) ), ( (tmp[7].imag() * b_real) + (tmp[8].imag() * a_real) ) ); tmp[12] = cx_type( ( -(tmp[10].imag() * b_imag) + (tmp[9].imag() * a_imag) ), ( (tmp[10].real() * b_imag) - (tmp[9].real() * a_imag) ) ); (*Y2) = tmp[11] + tmp[12]; (*Y3) = tmp[11] - tmp[12]; Y0++; Y1++; Y2++; Y3++; Y4++; } } arma_hot inline void butterfly_N(cx_type* Y, const uword stride, const uword m, const uword r) { arma_extra_debug_sigprint(); const cx_type* coeffs = coeffs_ptr(); tmp_array.set_min_size(r); cx_type* tmp = tmp_array.memptr(); for(uword u=0; u < m; ++u) { uword k = u; for(uword v=0; v < r; ++v) { tmp[v] = Y[k]; k += m; } k = u; for(uword v=0; v < r; ++v) { Y[k] = tmp[0]; uword j = 0; for(uword w=1; w < r; ++w) { j += stride * k; if(j >= N) { j -= N; } Y[k] += tmp[w] * coeffs[j]; } k += m; } } } inline void run(cx_type* Y, const cx_type* X, const uword stage = 0, const uword stride = 1) { arma_extra_debug_sigprint(); const uword m = residue[stage]; const uword r = radix[stage]; const cx_type *Y_end = Y + r*m; if(m == 1) { for(cx_type* Yi = Y; Yi != Y_end; Yi++, X += stride) { (*Yi) = (*X); } } else { const uword next_stage = stage + 1; const uword next_stride = stride * r; for(cx_type* Yi = Y; Yi != Y_end; Yi += m, X += stride) { run(Yi, X, next_stage, next_stride); } } switch(r) { case 2: butterfly_2(Y, stride, m ); break; case 3: butterfly_3(Y, stride, m ); break; case 4: butterfly_4(Y, stride, m ); break; case 5: butterfly_5(Y, stride, m ); break; default: butterfly_N(Y, stride, m, r); break; } } }; RcppArmadillo/inst/include/armadillo_bits/arma_static_check.hpp0000644000176000001440000000216012254475442024565 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup arma_static_check //! @{ template struct arma_type_check_cxx1998 { arma_inline static void apply() { static const char junk[ ERROR___INCORRECT_OR_UNSUPPORTED_TYPE ? -1 : +1 ]; } }; template<> struct arma_type_check_cxx1998 { arma_inline static void apply() { } }; #if defined(ARMA_USE_CXX11) #define arma_static_check(condition, message) static_assert( !(condition), #message ) #define arma_type_check(condition) static_assert( !(condition), "error: incorrect or unsupported type" ) #else #define arma_static_check(condition, message) static const char message[ (condition) ? -1 : +1 ] #define arma_type_check(condition) arma_type_check_cxx1998::apply() #endif //! @} RcppArmadillo/inst/include/armadillo_bits/operator_times.hpp0000644000176000001440000002637412177612510024203 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_times //! @{ //! Base * scalar template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator* (const T1& X, const typename T1::elem_type k) { arma_extra_debug_sigprint(); return eOp(X,k); } //! scalar * Base template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator* (const typename T1::elem_type k, const T1& X) { arma_extra_debug_sigprint(); return eOp(X,k); // NOTE: order is swapped } //! non-complex Base * complex scalar template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_times> >::result operator* ( const T1& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_times>('j', X, k); } //! complex scalar * non-complex Base template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_times> >::result operator* ( const std::complex& k, const T1& X ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_times>('j', X, k); } //! scalar * trans(T1) template arma_inline const Op operator* (const typename T1::elem_type k, const Op& X) { arma_extra_debug_sigprint(); return Op(X.m, k); } //! trans(T1) * scalar template arma_inline const Op operator* (const Op& X, const typename T1::elem_type k) { arma_extra_debug_sigprint(); return Op(X.m, k); } //! Base * diagmat template arma_inline typename enable_if2 < (is_arma_type::value && is_same_type::value), const Glue, glue_times_diag> >::result operator* (const T1& X, const Op& Y) { arma_extra_debug_sigprint(); return Glue, glue_times_diag>(X, Y); } //! diagmat * Base template arma_inline typename enable_if2 < (is_arma_type::value && is_same_type::value), const Glue, T2, glue_times_diag> >::result operator* (const Op& X, const T2& Y) { arma_extra_debug_sigprint(); return Glue, T2, glue_times_diag>(X, Y); } //! diagmat * diagmat template inline Mat< typename promote_type::result > operator* (const Op& X, const Op& Y) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const diagmat_proxy A(X.m); const diagmat_proxy B(Y.m); arma_debug_assert_mul_size(A.n_elem, A.n_elem, B.n_elem, B.n_elem, "matrix multiplication"); const uword N = A.n_elem; Mat out(N,N); out.zeros(); for(uword i=0; i::apply( A[i] ) * upgrade_val::apply( B[i] ); } return out; } //! multiplication of Base objects with same element type template arma_inline typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value, const Glue >::result operator* (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return Glue(X, Y); } //! multiplication of Base objects with different element types template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_same_type::no)), const mtGlue< typename promote_type::result, T1, T2, glue_mixed_times > >::result operator* ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlue( X, Y ); } //! sparse multiplied by scalar template inline typename enable_if2 < is_arma_sparse_type::value, SpOp >::result operator* ( const T1& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return SpOp(X, k); } template inline typename enable_if2 < is_arma_sparse_type::value, SpOp >::result operator* ( const typename T1::elem_type k, const T1& X ) { arma_extra_debug_sigprint(); return SpOp(X, k); } //! multiplication of two sparse objects template inline arma_hot typename enable_if2 < (is_arma_sparse_type::value && is_arma_sparse_type::value && is_same_type::value), const SpGlue >::result operator* ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); return SpGlue(x, y); } //! convert "(sparse + sparse) * scalar" to specialised operation "scalar * (sparse + sparse)" template inline const SpGlue operator* ( const SpGlue& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "scalar * (sparse + sparse)" to specialised operation template inline const SpGlue operator* ( const typename T1::elem_type k, const SpGlue& X ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "(sparse - sparse) * scalar" to specialised operation "scalar * (sparse - sparse)" template inline const SpGlue operator* ( const SpGlue& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "scalar * (sparse - sparse)" to specialised operation template inline const SpGlue operator* ( const typename T1::elem_type k, const SpGlue& X ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "(sparse*sparse) * scalar" to specialised operation "scalar * (sparse*sparse)" template inline const SpGlue operator* ( const SpGlue& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "scalar * (sparse*sparse)" to specialised operation template inline const SpGlue operator* ( const typename T1::elem_type k, const SpGlue& X ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "(scalar*sparse) * sparse" to specialised operation "scalar * (sparse*sparse)" template inline typename enable_if2 < is_arma_sparse_type::value, const SpGlue >::result operator* ( const SpOp& X, const T2& Y ) { arma_extra_debug_sigprint(); return SpGlue(X.m, Y, X.aux); } //! convert "sparse * (scalar*sparse)" to specialised operation "scalar * (sparse*sparse)" template inline typename enable_if2 < is_arma_sparse_type::value, const SpGlue >::result operator* ( const T1& X, const SpOp& Y ) { arma_extra_debug_sigprint(); return SpGlue(X, Y.m, Y.aux); } //! multiplication of one sparse and one dense object template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_type::value && is_same_type::value), Mat >::result operator* ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); const SpProxy pa(x); const Proxy pb(y); arma_debug_assert_mul_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "matrix multiplication"); Mat result(pa.get_n_rows(), pb.get_n_cols()); result.zeros(); if( (pa.get_n_nonzero() > 0) && (pb.get_n_elem() > 0) ) { typename SpProxy::const_iterator_type x_it = pa.begin(); typename SpProxy::const_iterator_type x_it_end = pa.end(); const uword result_n_cols = result.n_cols; while(x_it != x_it_end) { for(uword col = 0; col < result_n_cols; ++col) { result.at(x_it.row(), col) += (*x_it) * pb.at(x_it.col(), col); } ++x_it; } } return result; } //! multiplication of one dense and one sparse object template inline typename enable_if2 < (is_arma_type::value && is_arma_sparse_type::value && is_same_type::value), Mat >::result operator* ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); const Proxy pa(x); const SpProxy pb(y); arma_debug_assert_mul_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "matrix multiplication"); Mat result(pa.get_n_rows(), pb.get_n_cols()); result.zeros(); if( (pa.get_n_elem() > 0) && (pb.get_n_nonzero() > 0) ) { typename SpProxy::const_iterator_type y_col_it = pb.begin(); typename SpProxy::const_iterator_type y_col_it_end = pb.end(); const uword result_n_rows = result.n_rows; while(y_col_it != y_col_it_end) { for(uword row = 0; row < result_n_rows; ++row) { result.at(row, y_col_it.col()) += pa.at(row, y_col_it.row()) * (*y_col_it); } ++y_col_it; } } return result; } //! @} RcppArmadillo/inst/include/armadillo_bits/arma_boost.hpp0000644000176000001440000002417012252034373023264 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup arma_boost //! @{ namespace arma_boost { #if defined(ARMA_HAVE_SNPRINTF) #define arma_snprintf std::snprintf #else // better-than-nothing emulation of C99 snprintf(), // with correct return value and null-terminated output string. // note that _snprintf() provided by MS is not a good substitute for snprintf() inline int arma_snprintf(char* out, size_t size, const char* fmt, ...) { size_t i; for(i=0; i 0) out[size-1] = char(0); return int(i); } #endif class format { public: format(const char* in_fmt) : A(in_fmt) { } format(const std::string& in_fmt) : A(in_fmt) { } const std::string A; private: format(); }; template class basic_format { public: basic_format(const T1& in_A, const T2& in_B) : A(in_A) , B(in_B) { } const T1& A; const T2& B; private: basic_format(); }; template inline basic_format< format, T2 > operator% (const format& X, const T2& arg) { return basic_format< format, T2 >(X, arg); } template inline basic_format< basic_format, T3 > operator% (const basic_format& X, const T3& arg) { return basic_format< basic_format, T3 >(X, arg); } template inline std::string str(const basic_format< format, T2>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.c_str(), X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer == true) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template inline std::string str(const basic_format< basic_format< format, T2>, T3>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.A.c_str(), X.A.B, X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer == true) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template inline std::string str(const basic_format< basic_format< basic_format< format, T2>, T3>, T4>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.A.A.c_str(), X.A.A.B, X.A.B, X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer == true) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template inline std::string str(const basic_format< basic_format< basic_format< basic_format< format, T2>, T3>, T4>, T5>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.A.A.A.c_str(), X.A.A.A.B, X.A.A.B, X.A.B, X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer == true) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template inline std::string str(const basic_format< basic_format< basic_format< basic_format< basic_format< format, T2>, T3>, T4>, T5>, T6>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.A.A.A.A.c_str(), X.A.A.A.A.B, X.A.A.A.B, X.A.A.B, X.A.B, X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer == true) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template inline std::string str(const basic_format< basic_format< basic_format< basic_format< basic_format< basic_format< format, T2>, T3>, T4>, T5>, T6>, T7>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.A.A.A.A.A.c_str(), X.A.A.A.A.A.B, X.A.A.A.A.B, X.A.A.A.B, X.A.A.B, X.A.B, X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer == true) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template struct format_metaprog { static const uword depth = 0; inline static const std::string& get_fmt(const T1& X) { return X.A; } }; //template<> template struct format_metaprog< basic_format > { static const uword depth = 1 + format_metaprog::depth; inline static const std::string& get_fmt(const T1& X) { return format_metaprog::get_fmt(X.A); } }; template inline std::string str(const basic_format& X) { return format_metaprog< basic_format >::get_fmt(X.A); } template inline std::ostream& operator<< (std::ostream& o, const basic_format& X) { o << str(X); return o; } template struct string_only { }; template<> struct string_only { typedef std::string result; }; template struct char_only { }; template<> struct char_only { typedef char result; }; template struct basic_format_only { }; template struct basic_format_only< basic_format > { typedef basic_format result; }; template inline static const T1& str_wrapper(const T1& x, const typename string_only::result* junk = 0) { arma_ignore(junk); return x; } template inline static const T1* str_wrapper(const T1* x, const typename char_only::result* junk = 0) { arma_ignore(junk); return x; } template inline static std::string str_wrapper(const T1& x, const typename basic_format_only::result* junk = 0) { arma_ignore(junk); return str(x); } } //! @} RcppArmadillo/inst/include/armadillo_bits/SpOp_meat.hpp0000644000176000001440000000174712111344723023027 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpOp //! @{ template inline SpOp::SpOp(const T1& in_m) : m(in_m) { arma_extra_debug_sigprint(); } template inline SpOp::SpOp(const T1& in_m, const typename T1::elem_type in_aux) : m(in_m) , aux(in_aux) { arma_extra_debug_sigprint(); } template inline SpOp::SpOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline SpOp::~SpOp() { arma_extra_debug_sigprint(); } //! @} RcppArmadillo/inst/include/armadillo_bits/Row_bones.hpp0000644000176000001440000001765312252274740023107 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Row //! @{ //! Class for row vectors (matrices with only one row) template class Row : public Mat { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_col = false; static const bool is_row = true; inline Row(); inline Row(const Row& X); inline explicit Row(const uword N); inline Row(const uword in_rows, const uword in_cols); template inline Row(const uword n_elem, const fill::fill_class& f); template inline Row(const uword in_rows, const uword in_cols, const fill::fill_class& f); inline Row(const char* text); inline const Row& operator=(const char* text); inline Row(const std::string& text); inline const Row& operator=(const std::string& text); inline Row(const std::vector& x); inline const Row& operator=(const std::vector& x); #if defined(ARMA_USE_CXX11) inline Row(const std::initializer_list& list); inline const Row& operator=(const std::initializer_list& list); inline Row(Row&& m); inline const Row& operator=(Row&& m); #endif inline explicit Row(const SpRow& X); inline const Row& operator=(const eT val); inline const Row& operator=(const Row& X); template inline Row(const Base& X); template inline const Row& operator=(const Base& X); inline Row( eT* aux_mem, const uword aux_length, const bool copy_aux_mem = true, const bool strict = true); inline Row(const eT* aux_mem, const uword aux_length); template inline explicit Row(const Base& A, const Base& B); template inline Row(const BaseCube& X); template inline const Row& operator=(const BaseCube& X); inline Row(const subview_cube& X); inline const Row& operator=(const subview_cube& X); inline mat_injector operator<<(const eT val); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; arma_inline subview_row col(const uword col_num); arma_inline const subview_row col(const uword col_num) const; using Mat::cols; using Mat::operator(); arma_inline subview_row cols(const uword in_col1, const uword in_col2); arma_inline const subview_row cols(const uword in_col1, const uword in_col2) const; arma_inline subview_row subvec(const uword in_col1, const uword in_col2); arma_inline const subview_row subvec(const uword in_col1, const uword in_col2) const; arma_inline subview_row cols(const span& col_span); arma_inline const subview_row cols(const span& col_span) const; arma_inline subview_row subvec(const span& col_span); arma_inline const subview_row subvec(const span& col_span) const; arma_inline subview_row operator()(const span& col_span); arma_inline const subview_row operator()(const span& col_span) const; inline void shed_col (const uword col_num); inline void shed_cols(const uword in_col1, const uword in_col2); inline void insert_cols(const uword col_num, const uword N, const bool set_to_zero = true); template inline void insert_cols(const uword col_num, const Base& X); arma_inline arma_warn_unused eT& at(const uword i); arma_inline arma_warn_unused const eT& at(const uword i) const; arma_inline arma_warn_unused eT& at(const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at(const uword in_row, const uword in_col) const; typedef eT* row_iterator; typedef const eT* const_row_iterator; inline row_iterator begin_row(const uword row_num); inline const_row_iterator begin_row(const uword row_num) const; inline row_iterator end_row (const uword row_num); inline const_row_iterator end_row (const uword row_num) const; template class fixed; protected: inline Row(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem); public: #ifdef ARMA_EXTRA_ROW_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_ROW_PROTO) #endif }; template template class Row::fixed : public Row { private: static const bool use_extra = (fixed_n_elem > arma_config::mat_prealloc); arma_align_mem eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ]; public: typedef fixed Row_fixed_type; typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_col = false; static const bool is_row = true; static const uword n_rows = 1; static const uword n_cols = fixed_n_elem; static const uword n_elem = fixed_n_elem; arma_inline fixed(); arma_inline fixed(const fixed& X); inline fixed(const subview_cube& X); template inline fixed(const fill::fill_class& f); template inline fixed(const Base& A); template inline fixed(const Base& A, const Base& B); inline fixed(const eT* aux_mem); inline fixed(const char* text); inline fixed(const std::string& text); template inline const Row& operator=(const Base& A); inline const Row& operator=(const eT val); inline const Row& operator=(const char* text); inline const Row& operator=(const std::string& text); inline const Row& operator=(const subview_cube& X); using Row::operator(); #if defined(ARMA_USE_CXX11) inline fixed(const std::initializer_list& list); inline const Row& operator=(const std::initializer_list& list); #endif arma_inline const Row& operator=(const fixed& X); arma_inline const Op< Row_fixed_type, op_htrans > t() const; arma_inline const Op< Row_fixed_type, op_htrans > ht() const; arma_inline const Op< Row_fixed_type, op_strans > st() const; arma_inline arma_warn_unused const eT& at_alt (const uword i) const; arma_inline arma_warn_unused eT& operator[] (const uword i); arma_inline arma_warn_unused const eT& operator[] (const uword i) const; arma_inline arma_warn_unused eT& at (const uword i); arma_inline arma_warn_unused const eT& at (const uword i) const; arma_inline arma_warn_unused eT& operator() (const uword i); arma_inline arma_warn_unused const eT& operator() (const uword i) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT* memptr(); arma_inline arma_warn_unused const eT* memptr() const; arma_hot inline const Row& fill(const eT val); arma_hot inline const Row& zeros(); arma_hot inline const Row& ones(); }; //! @} RcppArmadillo/inst/include/armadillo_bits/running_stat_vec_bones.hpp0000644000176000001440000000732212247625623025704 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup running_stat_vec //! @{ template struct rsv_get_elem_type { }; template struct rsv_get_elem_type { typedef obj_type elem_type; }; template struct rsv_get_elem_type { typedef typename obj_type::elem_type elem_type; }; //! Class for keeping statistics of a continuously sampled process / signal. //! Useful if the storage of individual samples is not necessary or desired. //! Also useful if the number of samples is not known beforehand or exceeds //! available memory. template class running_stat_vec { public: // voodoo for compatibility with old user code typedef typename rsv_get_elem_type::value>::elem_type eT; typedef typename get_pod_type::result T; inline ~running_stat_vec(); inline running_stat_vec(const bool in_calc_cov = false); // TODO: investigate char* overload, eg. "calc_cov", "no_calc_cov" inline running_stat_vec(const running_stat_vec& in_rsv); inline const running_stat_vec& operator=(const running_stat_vec& in_rsv); template arma_hot inline void operator() (const Base< T, T1>& X); template arma_hot inline void operator() (const Base, T1>& X); inline void reset(); inline const Mat& mean() const; inline const Mat< T>& var (const uword norm_type = 0); inline Mat< T> stddev(const uword norm_type = 0) const; inline const Mat& cov (const uword norm_type = 0); inline const Mat& min() const; inline const Mat& max() const; inline T count() const; // // private: const bool calc_cov; arma_aligned arma_counter counter; arma_aligned Mat r_mean; arma_aligned Mat< T> r_var; arma_aligned Mat r_cov; arma_aligned Mat min_val; arma_aligned Mat max_val; arma_aligned Mat< T> min_val_norm; arma_aligned Mat< T> max_val_norm; arma_aligned Mat< T> r_var_dummy; arma_aligned Mat r_cov_dummy; arma_aligned Mat tmp1; arma_aligned Mat tmp2; friend class running_stat_vec_aux; }; class running_stat_vec_aux { public: template inline static void update_stats ( running_stat_vec& x, const Mat::eT>& sample, const typename arma_not_cx::eT>::result* junk = 0 ); template inline static void update_stats ( running_stat_vec& x, const Mat::T > >& sample, const typename arma_not_cx::eT>::result* junk = 0 ); template inline static void update_stats ( running_stat_vec& x, const Mat< typename running_stat_vec::T >& sample, const typename arma_cx_only::eT>::result* junk = 0 ); template inline static void update_stats ( running_stat_vec& x, const Mat::eT>& sample, const typename arma_cx_only::eT>::result* junk = 0 ); }; //! @} RcppArmadillo/inst/include/armadillo_bits/spop_min_bones.hpp0000644000176000001440000000224712111344723024146 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_min //! @{ class spop_min { public: template inline static void apply(SpMat& out, const SpOp& in); template inline static void apply_noalias(SpMat& out, const SpProxy& p, const uword dim, const typename arma_not_cx::result* junk = 0); template inline static void apply_noalias(SpMat& out, const SpProxy& p, const uword dim, const typename arma_cx_only::result* junk = 0); template inline static typename T1::elem_type vector_min(const T1& X, const typename arma_not_cx::result* junk = 0); template inline static typename T1::elem_type vector_min(const T1& X, const typename arma_cx_only::result* junk = 0); }; //! @} RcppArmadillo/inst/include/armadillo_bits/operator_relational.hpp0000644000176000001440000001435612177612753025222 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_relational //! @{ // < : lt // > : gt // <= : lteq // >= : gteq // == : eq // != : noteq template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_cx::no) && (is_cx::no)), const mtGlue >::result operator< (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_cx::no) && (is_cx::no)), const mtGlue >::result operator> (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_cx::no) && (is_cx::no)), const mtGlue >::result operator<= (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_cx::no) && (is_cx::no)), const mtGlue >::result operator>= (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value), const mtGlue >::result operator== (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value), const mtGlue >::result operator!= (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } // // // template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator< (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator< (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator> (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator> (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator<= (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator<= (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator>= (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator>= (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < is_arma_type::value, const mtOp >::result operator== (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < is_arma_type::value, const mtOp >::result operator== (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < is_arma_type::value, const mtOp >::result operator!= (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < is_arma_type::value, const mtOp >::result operator!= (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_cor_bones.hpp0000644000176000001440000000161312200375542024117 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_cor //! @{ class glue_cor { public: template inline static void direct_cor(Mat& out, const Mat& A, const Mat& B, const uword norm_type); template inline static void direct_cor(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat< std::complex >& B, const uword norm_type); template inline static void apply(Mat& out, const Glue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/promote_type.hpp0000644000176000001440000003404112177612753023674 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup promote_type //! @{ template struct is_promotable { static const bool value = false; typedef T1 result; }; struct is_promotable_ok { static const bool value = true; }; template struct is_promotable : public is_promotable_ok { typedef T result; }; template struct is_promotable, T> : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable, std::complex > : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable, float> : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable, double> : public is_promotable_ok { typedef std::complex result; }; #if defined(ARMA_USE_U64S64) template struct is_promotable, u64> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, s64> : public is_promotable_ok { typedef std::complex result; }; #endif #if defined(ARMA_ALLOW_LONG) template struct is_promotable, ulng_t> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, slng_t> : public is_promotable_ok { typedef std::complex result; }; #endif template struct is_promotable, s32> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, u32> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, s16> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, u16> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, s8> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, u8> : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; #endif #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef u32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef u32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; // s32 ? template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; // s32 ? template<> struct is_promotable : public is_promotable_ok { typedef u16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s8 result; }; // s16 ? // // mirrored versions template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable, std::complex > : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; #if defined(ARMA_USE_U64S64) template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; #endif #if defined(ARMA_ALLOW_LONG) template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; #endif template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; #endif #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef u32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef u32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; // s32 ? template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; // s32 ? template<> struct is_promotable : public is_promotable_ok { typedef u16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s8 result; }; // s16 ? template struct promote_type { inline static void check() { arma_type_check(( is_promotable::value == false )); } typedef typename is_promotable::result result; }; template struct eT_promoter { typedef typename promote_type::result eT; }; //! @} RcppArmadillo/inst/include/armadillo_bits/Base_meat.hpp0000644000176000001440000000670112244602366023022 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Base //! @{ template arma_inline const derived& Base::get_ref() const { return static_cast(*this); } template arma_inline const Op Base::t() const { return Op( (*this).get_ref() ); } template arma_inline const Op Base::ht() const { return Op( (*this).get_ref() ); } template arma_inline const Op Base::st() const { return Op( (*this).get_ref() ); } template inline void Base::print(const std::string extra_text) const { const Proxy P( (*this).get_ref() ); const quasi_unwrap< typename Proxy::stored_type > tmp(P.Q); tmp.M.impl_print(extra_text); } template inline void Base::print(std::ostream& user_stream, const std::string extra_text) const { const Proxy P( (*this).get_ref() ); const quasi_unwrap< typename Proxy::stored_type > tmp(P.Q); tmp.M.impl_print(user_stream, extra_text); } template inline void Base::raw_print(const std::string extra_text) const { const Proxy P( (*this).get_ref() ); const quasi_unwrap< typename Proxy::stored_type > tmp(P.Q); tmp.M.impl_raw_print(extra_text); } template inline void Base::raw_print(std::ostream& user_stream, const std::string extra_text) const { const Proxy P( (*this).get_ref() ); const quasi_unwrap< typename Proxy::stored_type > tmp(P.Q); tmp.M.impl_raw_print(user_stream, extra_text); } // // extra functions defined in Base_blas_elem_type template arma_inline const Op Base_blas_elem_type::i(const bool slow) const { return Op( static_cast(*this), ((slow == false) ? 0 : 1), 0 ); } template arma_inline const Op Base_blas_elem_type::i(const char* method) const { const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'f')), "Base::i(): unknown method specified" ); return Op( static_cast(*this), ((sig == 'f') ? 0 : 1), 0 ); } // // extra functions defined in Base_eval_Mat template arma_inline const derived& Base_eval_Mat::eval() const { arma_extra_debug_sigprint(); return static_cast(*this); } // // extra functions defined in Base_eval_expr template arma_inline Mat Base_eval_expr::eval() const { arma_extra_debug_sigprint(); return Mat( static_cast(*this) ); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_shuffle.hpp0000644000176000001440000000322712223247006023252 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_shuffle //! @{ //! \brief //! Shuffle the rows or the columns of a matrix or vector in random fashion. //! If dim = 0, shuffle the columns (default operation). //! If dim = 1, shuffle the rows. template arma_inline const Op shuffle ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op shuffle ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template arma_inline const Op shuffle ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return T1::is_row ? Op(X, 1, 0) : Op(X, 0, 0); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_cor_meat.hpp0000644000176000001440000000415512200631217023417 0ustar ripleyusers// Copyright (C) 2009-2011 Conrad Sanderson // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_cor //! @{ template inline void op_cor::direct_cor(Mat& out, const Mat& A, const uword norm_type) { arma_extra_debug_sigprint(); if(A.is_empty()) { out.reset(); return; } if(A.is_vec()) { out.set_size(1,1); out[0] = eT(1); } else { const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); const Row acc = sum(A); const Row sd = stddev(A); out = (trans(A) * A); out -= (trans(acc) * acc)/eT(N); out /= norm_val; out /= trans(sd) * sd; } } template inline void op_cor::direct_cor(Mat< std::complex >& out, const Mat< std::complex >& A, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(A.is_empty()) { out.reset(); return; } if(A.is_vec()) { out.set_size(1,1); out[0] = eT(1); } else { const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); const Row acc = sum(A); const Row sd = stddev(A); out = trans(A) * A; // out = strans(conj(A)) * A; out -= (trans(acc) * acc)/eT(N); // out -= (strans(conj(acc)) * acc)/eT(N); out /= norm_val; //out = out / (trans(sd) * sd); out /= conv_to< Mat >::from(trans(sd) * sd); } } template inline void op_cor::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& A = tmp.M; const uword norm_type = in.aux_uword_a; op_cor::direct_cor(out, A, norm_type); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_as_scalar.hpp0000644000176000001440000002607412200375542023555 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_as_scalar //! @{ template struct as_scalar_redirect { template inline static typename T1::elem_type apply(const T1& X); }; template<> struct as_scalar_redirect<2> { template inline static typename T1::elem_type apply(const Glue& X); }; template<> struct as_scalar_redirect<3> { template inline static typename T1::elem_type apply(const Glue< Glue, T3, glue_times>& X); }; template template inline typename T1::elem_type as_scalar_redirect::apply(const T1& X) { arma_extra_debug_sigprint(); // typedef typename T1::elem_type eT; const Proxy P(X); arma_debug_check( (P.get_n_elem() != 1), "as_scalar(): expression doesn't evaluate to exactly one element" ); return (Proxy::prefer_at_accessor == true) ? P.at(0,0) : P[0]; } template inline typename T1::elem_type as_scalar_redirect<2>::apply(const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // T1 must result in a matrix with one row // T2 must result in a matrix with one column const bool has_all_mat = (is_Mat::value || is_Mat_trans::value) && (is_Mat::value || is_Mat_trans::value); const bool prefer_at_accessor = Proxy::prefer_at_accessor || Proxy::prefer_at_accessor; const bool do_partial_unwrap = has_all_mat || prefer_at_accessor; if(do_partial_unwrap == true) { const partial_unwrap tmp1(X.A); const partial_unwrap tmp2(X.B); typedef typename partial_unwrap::stored_type TA; typedef typename partial_unwrap::stored_type TB; const TA& A = tmp1.M; const TB& B = tmp2.M; const uword A_n_rows = (tmp1.do_trans == false) ? (TA::is_row ? 1 : A.n_rows) : (TA::is_col ? 1 : A.n_cols); const uword A_n_cols = (tmp1.do_trans == false) ? (TA::is_col ? 1 : A.n_cols) : (TA::is_row ? 1 : A.n_rows); const uword B_n_rows = (tmp2.do_trans == false) ? (TB::is_row ? 1 : B.n_rows) : (TB::is_col ? 1 : B.n_cols); const uword B_n_cols = (tmp2.do_trans == false) ? (TB::is_col ? 1 : B.n_cols) : (TB::is_row ? 1 : B.n_rows); arma_debug_check( (A_n_rows != 1) || (B_n_cols != 1) || (A_n_cols != B_n_rows), "as_scalar(): incompatible dimensions" ); const eT val = op_dot::direct_dot(A.n_elem, A.memptr(), B.memptr()); return (tmp1.do_times || tmp2.do_times) ? (val * tmp1.get_val() * tmp2.get_val()) : val; } else { const Proxy PA(X.A); const Proxy PB(X.B); arma_debug_check ( (PA.get_n_rows() != 1) || (PB.get_n_cols() != 1) || (PA.get_n_cols() != PB.get_n_rows()), "as_scalar(): incompatible dimensions" ); return op_dot::apply_proxy(PA,PB); } } template inline typename T1::elem_type as_scalar_redirect<3>::apply(const Glue< Glue, T3, glue_times >& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // T1 * T2 must result in a matrix with one row // T3 must result in a matrix with one column typedef typename strip_inv ::stored_type T2_stripped_1; typedef typename strip_diagmat::stored_type T2_stripped_2; const strip_inv strip1(X.A.B); const strip_diagmat strip2(strip1.M); const bool tmp2_do_inv = strip1.do_inv; const bool tmp2_do_diagmat = strip2.do_diagmat; if(tmp2_do_diagmat == false) { const Mat tmp(X); arma_debug_check( (tmp.n_elem != 1), "as_scalar(): expression doesn't evaluate to exactly one element" ); return tmp[0]; } else { const partial_unwrap tmp1(X.A.A); const partial_unwrap tmp2(strip2.M); const partial_unwrap tmp3(X.B); const Mat& A = tmp1.M; const Mat& B = tmp2.M; const Mat& C = tmp3.M; const uword A_n_rows = (tmp1.do_trans == false) ? A.n_rows : A.n_cols; const uword A_n_cols = (tmp1.do_trans == false) ? A.n_cols : A.n_rows; const bool B_is_vec = B.is_vec(); const uword B_n_rows = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans == false) ? B.n_rows : B.n_cols ); const uword B_n_cols = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans == false) ? B.n_cols : B.n_rows ); const uword C_n_rows = (tmp3.do_trans == false) ? C.n_rows : C.n_cols; const uword C_n_cols = (tmp3.do_trans == false) ? C.n_cols : C.n_rows; const eT val = tmp1.get_val() * tmp2.get_val() * tmp3.get_val(); arma_debug_check ( (A_n_rows != 1) || (C_n_cols != 1) || (A_n_cols != B_n_rows) || (B_n_cols != C_n_rows) , "as_scalar(): incompatible dimensions" ); if(B_is_vec == true) { if(tmp2_do_inv == true) { return val * op_dotext::direct_rowvec_invdiagvec_colvec(A.mem, B, C.mem); } else { return val * op_dot::direct_dot(A.n_elem, A.mem, B.mem, C.mem); } } else { if(tmp2_do_inv == true) { return val * op_dotext::direct_rowvec_invdiagmat_colvec(A.mem, B, C.mem); } else { return val * op_dotext::direct_rowvec_diagmat_colvec(A.mem, B, C.mem); } } } } template inline typename T1::elem_type as_scalar_diag(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; arma_debug_check( (A.n_elem != 1), "as_scalar(): expression doesn't evaluate to exactly one element" ); return A.mem[0]; } template inline typename T1::elem_type as_scalar_diag(const Glue< Glue, T3, glue_times >& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // T1 * T2 must result in a matrix with one row // T3 must result in a matrix with one column typedef typename strip_diagmat::stored_type T2_stripped; const strip_diagmat strip(X.A.B); const partial_unwrap tmp1(X.A.A); const partial_unwrap tmp2(strip.M); const partial_unwrap tmp3(X.B); const Mat& A = tmp1.M; const Mat& B = tmp2.M; const Mat& C = tmp3.M; const uword A_n_rows = (tmp1.do_trans == false) ? A.n_rows : A.n_cols; const uword A_n_cols = (tmp1.do_trans == false) ? A.n_cols : A.n_rows; const bool B_is_vec = B.is_vec(); const uword B_n_rows = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans == false) ? B.n_rows : B.n_cols ); const uword B_n_cols = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans == false) ? B.n_cols : B.n_rows ); const uword C_n_rows = (tmp3.do_trans == false) ? C.n_rows : C.n_cols; const uword C_n_cols = (tmp3.do_trans == false) ? C.n_cols : C.n_rows; const eT val = tmp1.get_val() * tmp2.get_val() * tmp3.get_val(); arma_debug_check ( (A_n_rows != 1) || (C_n_cols != 1) || (A_n_cols != B_n_rows) || (B_n_cols != C_n_rows) , "as_scalar(): incompatible dimensions" ); if(B_is_vec == true) { return val * op_dot::direct_dot(A.n_elem, A.mem, B.mem, C.mem); } else { return val * op_dotext::direct_rowvec_diagmat_colvec(A.mem, B, C.mem); } } template arma_inline arma_warn_unused typename T1::elem_type as_scalar(const Glue& X, const typename arma_not_cx::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_glue_times_diag::value == false) { const sword N_mat = 1 + depth_lhs< glue_times, Glue >::num; arma_extra_debug_print(arma_boost::format("N_mat = %d") % N_mat); return as_scalar_redirect::apply(X); } else { return as_scalar_diag(X); } } template inline arma_warn_unused typename T1::elem_type as_scalar(const Base& X) { arma_extra_debug_sigprint(); // typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); arma_debug_check( (P.get_n_elem() != 1), "as_scalar(): expression doesn't evaluate to exactly one element" ); return (Proxy::prefer_at_accessor == true) ? P.at(0,0) : P[0]; } // ensure the following two functions are aware of each other template inline arma_warn_unused typename T1::elem_type as_scalar(const eOp& X); template inline arma_warn_unused typename T1::elem_type as_scalar(const eGlue& X); template inline arma_warn_unused typename T1::elem_type as_scalar(const eOp& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const eT val = as_scalar(X.P.Q); return eop_core::process(val, X.aux); } template inline arma_warn_unused typename T1::elem_type as_scalar(const eGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const eT a = as_scalar(X.P1.Q); const eT b = as_scalar(X.P2.Q); // the optimiser will keep only one return statement if(is_same_type::yes) { return a + b; } else if(is_same_type::yes) { return a - b; } else if(is_same_type::yes) { return a / b; } else if(is_same_type::yes) { return a * b; } } template inline arma_warn_unused typename T1::elem_type as_scalar(const BaseCube& X) { arma_extra_debug_sigprint(); // typedef typename T1::elem_type eT; const ProxyCube P(X.get_ref()); arma_debug_check( (P.get_n_elem() != 1), "as_scalar(): expression doesn't evaluate to exactly one element" ); return (ProxyCube::prefer_at_accessor == true) ? P.at(0,0,0) : P[0]; } template arma_inline arma_warn_unused const typename arma_scalar_only::result & as_scalar(const T& x) { return x; } template arma_inline arma_warn_unused typename T1::elem_type as_scalar(const SpBase& X) { typedef typename T1::elem_type eT; const unwrap_spmat tmp(X.get_ref()); const SpMat& A = tmp.M; arma_debug_check( (A.n_elem != 1), "as_scalar(): expression doesn't evaluate to exactly one element" ); return A.at(0,0); } //! @} RcppArmadillo/inst/include/armadillo_bits/mtGlueCube_meat.hpp0000644000176000001440000000177512202101406024171 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup mtGlueCube //! @{ template inline mtGlueCube::mtGlueCube(const T1& in_A, const T2& in_B) : A(in_A) , B(in_B) { arma_extra_debug_sigprint(); } template inline mtGlueCube::mtGlueCube(const T1& in_A, const T2& in_B, const uword in_aux_uword) : A(in_A) , B(in_B) , aux_uword(in_aux_uword) { arma_extra_debug_sigprint(); } template inline mtGlueCube::~mtGlueCube() { arma_extra_debug_sigprint(); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_eig_sym.hpp0000644000176000001440000000503312253325464023257 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // Copyright (C) 2011 Stanislav Funiak // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_eig_sym //! @{ //! Eigenvalues of real/complex symmetric/hermitian matrix X template inline bool eig_sym ( Col& eigval, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); // unwrap_check not used as T1::elem_type and T1::pod_type may not be the same. // furthermore, it doesn't matter if X is an alias of eigval, as auxlib::eig_sym() makes a copy of X const bool status = auxlib::eig_sym(eigval, X); if(status == false) { eigval.reset(); arma_bad("eig_sym(): failed to converge", false); } return status; } //! Eigenvalues of real/complex symmetric/hermitian matrix X template inline Col eig_sym ( const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Col out; const bool status = auxlib::eig_sym(out, X); if(status == false) { out.reset(); arma_bad("eig_sym(): failed to converge"); } return out; } //! Eigenvalues and eigenvectors of real/complex symmetric/hermitian matrix X template inline bool eig_sym ( Col& eigval, Mat& eigvec, const Base& X, const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( void_ptr(&eigval) == void_ptr(&eigvec), "eig_sym(): eigval is an alias of eigvec" ); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'd')), "eig_sym(): unknown method specified" ); const bool status = (sig == 'd') ? auxlib::eig_sym_dc(eigval, eigvec, X) : auxlib::eig_sym(eigval, eigvec, X); if(status == false) { eigval.reset(); eigvec.reset(); arma_bad("eig_sym(): failed to converge", false); } return status; } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_max_meat.hpp0000644000176000001440000000576412244135164023756 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_max //! @{ template inline void glue_max::apply(Mat& out, const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); const uword n_rows = PA.get_n_rows(); const uword n_cols = PA.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, PB.get_n_rows(), PB.get_n_cols(), "max(): given objects do not have the same size"); out.set_size(n_rows, n_cols); eT* out_mem = out.memptr(); if( (Proxy::prefer_at_accessor == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type A = PA.get_ea(); typename Proxy::ea_type B = PB.get_ea(); const uword N = PA.get_n_elem(); for(uword i=0; i inline void glue_max::apply(Mat< std::complex >& out, const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const uword n_rows = PA.get_n_rows(); const uword n_cols = PA.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, PB.get_n_rows(), PB.get_n_cols(), "max(): given objects do not have the same size"); out.set_size(n_rows, n_cols); eT* out_mem = out.memptr(); if( (Proxy::prefer_at_accessor == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type A = PA.get_ea(); typename Proxy::ea_type B = PB.get_ea(); const uword N = PA.get_n_elem(); for(uword i=0; i std::abs(B_val) ) ? A_val : B_val; } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT A_val = PA.at(row,col); const eT B_val = PB.at(row,col); *out_mem = ( std::abs(A_val) > std::abs(B_val) ) ? A_val : B_val; ++out_mem; } } } template inline void glue_max::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy PA(X.A); const Proxy PB(X.B); if(PA.is_alias(out) || PB.is_alias(out)) { Mat tmp; glue_max::apply(tmp, PA, PB); out.steal_mem(tmp); } else { glue_max::apply(out, PA, PB); } } //! @} RcppArmadillo/inst/include/armadillo_bits/op_inv_meat.hpp0000644000176000001440000000536212256734213023444 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_inv //! @{ //! immediate inverse of a matrix, storing the result in a dense matrix template inline void op_inv::apply(Mat& out, const Mat& A, const bool slow) { arma_extra_debug_sigprint(); // no need to check for aliasing, due to: // - auxlib::inv() copies A to out before inversion // - for 2x2 and 3x3 matrices the code is alias safe bool status = auxlib::inv(out, A, slow); if(status == false) { out.reset(); arma_bad("inv(): matrix appears to be singular"); } } //! immediate inverse of T1, storing the result in a dense matrix template inline void op_inv::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); const strip_diagmat strip(X.m); if(strip.do_diagmat == true) { op_inv::apply_diag(out, strip.M); } else { const uword mode = X.aux_uword_a; const bool status = (mode == 0) ? auxlib::inv(out, X.m) : auxlib::inv(out, X.m, true); if(status == false) { out.reset(); arma_bad("inv(): matrix appears to be singular"); } } } template inline void op_inv::apply_diag(Mat& out, const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const diagmat_proxy_check A(X.get_ref(), out); const uword N = A.n_elem; out.set_size(N,N); for(uword col=0; col inline void op_inv_tr::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); const bool status = auxlib::inv_tr(out, X.m, X.aux_uword_a); if(status == false) { out.reset(); arma_bad("inv(): matrix appears to be singular"); } } //! inverse of T1 (symmetric positive definite matrices) template inline void op_inv_sympd::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); const bool status = auxlib::inv_sympd(out, X.m, X.aux_uword_a); if(status == false) { out.reset(); arma_bad("inv_sympd(): matrix appears to be singular"); } } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_randu.hpp0000644000176000001440000000522712246034243022733 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_randu //! @{ inline double randu() { return arma_rng::randu(); } template inline typename arma_scalar_only::result randu() { return eT(arma_rng::randu()); } //! Generate a vector with all elements set to random values in the [0,1] interval (uniform distribution) arma_inline const Gen randu(const uword n_elem) { arma_extra_debug_sigprint(); return Gen(n_elem, 1); } template arma_inline const Gen randu(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only::result* junk2 = 0) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_Row::value == true) { return Gen(1, n_elem); } else { return Gen(n_elem, 1); } } //! Generate a dense matrix with all elements set to random values in the [0,1] interval (uniform distribution) arma_inline const Gen randu(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return Gen(n_rows, n_cols); } template arma_inline const Gen randu(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_Col::value == true) { arma_debug_check( (n_cols != 1), "randu(): incompatible size" ); } else if(is_Row::value == true) { arma_debug_check( (n_rows != 1), "randu(): incompatible size" ); } return Gen(n_rows, n_cols); } arma_inline const GenCube randu(const uword n_rows, const uword n_cols, const uword n_slices) { arma_extra_debug_sigprint(); return GenCube(n_rows, n_cols, n_slices); } template arma_inline const GenCube randu(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(n_rows, n_cols, n_slices); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_trunc_exp.hpp0000644000176000001440000000251012200375542023621 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_trunc_exp //! @{ template inline static typename arma_real_only::result trunc_exp(const eT x) { if(std::numeric_limits::is_iec559 && (x >= Math::log_max() )) { return std::numeric_limits::max(); } else { return std::exp(x); } } template inline static typename arma_integral_only::result trunc_exp(const eT x) { return eT( trunc_exp( double(x) ) ); } template inline static std::complex trunc_exp(const std::complex& x) { return std::polar( trunc_exp( x.real() ), x.imag() ); } template arma_inline const eOp trunc_exp(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube trunc_exp(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } //! @} RcppArmadillo/inst/include/armadillo_bits/diskio_meat.hpp0000644000176000001440000027573312206605301023435 0ustar ripleyusers// Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2009-2010 Ian Cullinan // Copyright (C) 2012 Ryan Curtin // Copyright (C) 2013 Szabolcs Horvat // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup diskio //! @{ //! Generate the first line of the header used for saving matrices in text format. //! Format: "ARMA_MAT_TXT_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not applicable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. template inline std::string diskio::gen_txt_header(const Mat& x) { arma_type_check(( is_supported_elem_type::value == false )); arma_ignore(x); if(is_u8::value == true) { return std::string("ARMA_MAT_TXT_IU001"); } else if(is_s8::value == true) { return std::string("ARMA_MAT_TXT_IS001"); } else if(is_u16::value == true) { return std::string("ARMA_MAT_TXT_IU002"); } else if(is_s16::value == true) { return std::string("ARMA_MAT_TXT_IS002"); } else if(is_u32::value == true) { return std::string("ARMA_MAT_TXT_IU004"); } else if(is_s32::value == true) { return std::string("ARMA_MAT_TXT_IS004"); } #if defined(ARMA_USE_U64S64) else if(is_u64::value == true) { return std::string("ARMA_MAT_TXT_IU008"); } else if(is_s64::value == true) { return std::string("ARMA_MAT_TXT_IS008"); } #endif #if defined(ARMA_ALLOW_LONG) else if(is_ulng_t_32::value == true) { return std::string("ARMA_MAT_TXT_IU004"); } else if(is_slng_t_32::value == true) { return std::string("ARMA_MAT_TXT_IS004"); } else if(is_ulng_t_64::value == true) { return std::string("ARMA_MAT_TXT_IU008"); } else if(is_slng_t_64::value == true) { return std::string("ARMA_MAT_TXT_IS008"); } #endif else if(is_float::value == true) { return std::string("ARMA_MAT_TXT_FN004"); } else if(is_double::value == true) { return std::string("ARMA_MAT_TXT_FN008"); } else if(is_complex_float::value == true) { return std::string("ARMA_MAT_TXT_FC008"); } else if(is_complex_double::value == true) { return std::string("ARMA_MAT_TXT_FC016"); } else { return std::string(); } } //! Generate the first line of the header used for saving matrices in binary format. //! Format: "ARMA_MAT_BIN_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not applicable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. template inline std::string diskio::gen_bin_header(const Mat& x) { arma_type_check(( is_supported_elem_type::value == false )); arma_ignore(x); if(is_u8::value == true) { return std::string("ARMA_MAT_BIN_IU001"); } else if(is_s8::value == true) { return std::string("ARMA_MAT_BIN_IS001"); } else if(is_u16::value == true) { return std::string("ARMA_MAT_BIN_IU002"); } else if(is_s16::value == true) { return std::string("ARMA_MAT_BIN_IS002"); } else if(is_u32::value == true) { return std::string("ARMA_MAT_BIN_IU004"); } else if(is_s32::value == true) { return std::string("ARMA_MAT_BIN_IS004"); } #if defined(ARMA_USE_U64S64) else if(is_u64::value == true) { return std::string("ARMA_MAT_BIN_IU008"); } else if(is_s64::value == true) { return std::string("ARMA_MAT_BIN_IS008"); } #endif #if defined(ARMA_ALLOW_LONG) else if(is_ulng_t_32::value == true) { return std::string("ARMA_MAT_BIN_IU004"); } else if(is_slng_t_32::value == true) { return std::string("ARMA_MAT_BIN_IS004"); } else if(is_ulng_t_64::value == true) { return std::string("ARMA_MAT_BIN_IU008"); } else if(is_slng_t_64::value == true) { return std::string("ARMA_MAT_BIN_IS008"); } #endif else if(is_float::value == true) { return std::string("ARMA_MAT_BIN_FN004"); } else if(is_double::value == true) { return std::string("ARMA_MAT_BIN_FN008"); } else if(is_complex_float::value == true) { return std::string("ARMA_MAT_BIN_FC008"); } else if(is_complex_double::value == true) { return std::string("ARMA_MAT_BIN_FC016"); } else { return std::string(); } } //! Generate the first line of the header used for saving matrices in binary format. //! Format: "ARMA_SPM_BIN_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not applicable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. template inline std::string diskio::gen_bin_header(const SpMat& x) { arma_type_check(( is_supported_elem_type::value == false )); arma_ignore(x); if(is_u8::value == true) { return std::string("ARMA_SPM_BIN_IU001"); } else if(is_s8::value == true) { return std::string("ARMA_SPM_BIN_IS001"); } else if(is_u16::value == true) { return std::string("ARMA_SPM_BIN_IU002"); } else if(is_s16::value == true) { return std::string("ARMA_SPM_BIN_IS002"); } else if(is_u32::value == true) { return std::string("ARMA_SPM_BIN_IU004"); } else if(is_s32::value == true) { return std::string("ARMA_SPM_BIN_IS004"); } #if defined(ARMA_USE_U64S64) else if(is_u64::value == true) { return std::string("ARMA_SPM_BIN_IU008"); } else if(is_s64::value == true) { return std::string("ARMA_SPM_BIN_IS008"); } #endif #if defined(ARMA_ALLOW_LONG) else if(is_ulng_t_32::value == true) { return std::string("ARMA_SPM_BIN_IU004"); } else if(is_slng_t_32::value == true) { return std::string("ARMA_SPM_BIN_IS004"); } else if(is_ulng_t_64::value == true) { return std::string("ARMA_SPM_BIN_IU008"); } else if(is_slng_t_64::value == true) { return std::string("ARMA_SPM_BIN_IS008"); } #endif else if(is_float::value == true) { return std::string("ARMA_SPM_BIN_FN004"); } else if(is_double::value == true) { return std::string("ARMA_SPM_BIN_FN008"); } else if(is_complex_float::value == true) { return std::string("ARMA_SPM_BIN_FC008"); } else if(is_complex_double::value == true) { return std::string("ARMA_SPM_BIN_FC016"); } else { return std::string(); } } //! Generate the first line of the header used for saving cubes in text format. //! Format: "ARMA_CUB_TXT_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not applicable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. template inline std::string diskio::gen_txt_header(const Cube& x) { arma_type_check(( is_supported_elem_type::value == false )); arma_ignore(x); if(is_u8::value == true) { return std::string("ARMA_CUB_TXT_IU001"); } else if(is_s8::value == true) { return std::string("ARMA_CUB_TXT_IS001"); } else if(is_u16::value == true) { return std::string("ARMA_CUB_TXT_IU002"); } else if(is_s16::value == true) { return std::string("ARMA_CUB_TXT_IS002"); } else if(is_u32::value == true) { return std::string("ARMA_CUB_TXT_IU004"); } else if(is_s32::value == true) { return std::string("ARMA_CUB_TXT_IS004"); } #if defined(ARMA_USE_U64S64) else if(is_u64::value == true) { return std::string("ARMA_CUB_TXT_IU008"); } else if(is_s64::value == true) { return std::string("ARMA_CUB_TXT_IS008"); } #endif #if defined(ARMA_ALLOW_LONG) else if(is_ulng_t_32::value == true) { return std::string("ARMA_CUB_TXT_IU004"); } else if(is_slng_t_32::value == true) { return std::string("ARMA_CUB_TXT_IS004"); } else if(is_ulng_t_64::value == true) { return std::string("ARMA_CUB_TXT_IU008"); } else if(is_slng_t_64::value == true) { return std::string("ARMA_CUB_TXT_IS008"); } #endif else if(is_float::value == true) { return std::string("ARMA_CUB_TXT_FN004"); } else if(is_double::value == true) { return std::string("ARMA_CUB_TXT_FN008"); } else if(is_complex_float::value == true) { return std::string("ARMA_CUB_TXT_FC008"); } else if(is_complex_double::value == true) { return std::string("ARMA_CUB_TXT_FC016"); } else { return std::string(); } } //! Generate the first line of the header used for saving cubes in binary format. //! Format: "ARMA_CUB_BIN_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not applicable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. template inline std::string diskio::gen_bin_header(const Cube& x) { arma_type_check(( is_supported_elem_type::value == false )); arma_ignore(x); if(is_u8::value == true) { return std::string("ARMA_CUB_BIN_IU001"); } else if(is_s8::value == true) { return std::string("ARMA_CUB_BIN_IS001"); } else if(is_u16::value == true) { return std::string("ARMA_CUB_BIN_IU002"); } else if(is_s16::value == true) { return std::string("ARMA_CUB_BIN_IS002"); } else if(is_u32::value == true) { return std::string("ARMA_CUB_BIN_IU004"); } else if(is_s32::value == true) { return std::string("ARMA_CUB_BIN_IS004"); } #if defined(ARMA_USE_U64S64) else if(is_u64::value == true) { return std::string("ARMA_CUB_BIN_IU008"); } else if(is_s64::value == true) { return std::string("ARMA_CUB_BIN_IS008"); } #endif #if defined(ARMA_ALLOW_LONG) else if(is_ulng_t_32::value == true) { return std::string("ARMA_CUB_BIN_IU004"); } else if(is_slng_t_32::value == true) { return std::string("ARMA_CUB_BIN_IS004"); } else if(is_ulng_t_64::value == true) { return std::string("ARMA_CUB_BIN_IU008"); } else if(is_slng_t_64::value == true) { return std::string("ARMA_CUB_BIN_IS008"); } #endif else if(is_float::value == true) { return std::string("ARMA_CUB_BIN_FN004"); } else if(is_double::value == true) { return std::string("ARMA_CUB_BIN_FN008"); } else if(is_complex_float::value == true) { return std::string("ARMA_CUB_BIN_FC008"); } else if(is_complex_double::value == true) { return std::string("ARMA_CUB_BIN_FC016"); } else { return std::string(); } } inline file_type diskio::guess_file_type(std::istream& f) { arma_extra_debug_sigprint(); f.clear(); const std::fstream::pos_type pos1 = f.tellg(); f.clear(); f.seekg(0, ios::end); f.clear(); const std::fstream::pos_type pos2 = f.tellg(); const uword N = ( (pos1 >= 0) && (pos2 >= 0) ) ? uword(pos2 - pos1) : 0; f.clear(); f.seekg(pos1); podarray data(N); unsigned char* ptr = data.memptr(); f.clear(); f.read( reinterpret_cast(ptr), std::streamsize(N) ); const bool load_okay = f.good(); f.clear(); f.seekg(pos1); bool has_binary = false; bool has_comma = false; bool has_bracket = false; if(load_okay == true) { uword i = 0; uword j = (N >= 2) ? 1 : 0; for(; j= 123)) || ((val_j <= 8) || (val_j >= 123)) ) { has_binary = true; break; } if( (val_i == ',') || (val_j == ',') ) { has_comma = true; } if( (val_i == '(') || (val_j == '(') || (val_i == ')') || (val_j == ')') ) { has_bracket = true; } } } else { return file_type_unknown; } if(has_binary) { return raw_binary; } if(has_comma && (has_bracket == false)) { return csv_ascii; } return raw_ascii; } inline char diskio::conv_to_hex_char(const u8 x) { char out; switch(x) { case 0: out = '0'; break; case 1: out = '1'; break; case 2: out = '2'; break; case 3: out = '3'; break; case 4: out = '4'; break; case 5: out = '5'; break; case 6: out = '6'; break; case 7: out = '7'; break; case 8: out = '8'; break; case 9: out = '9'; break; case 10: out = 'a'; break; case 11: out = 'b'; break; case 12: out = 'c'; break; case 13: out = 'd'; break; case 14: out = 'e'; break; case 15: out = 'f'; break; default: out = '-'; break; } return out; } inline void diskio::conv_to_hex(char* out, const u8 x) { const u8 a = x / 16; const u8 b = x - 16*a; out[0] = conv_to_hex_char(a); out[1] = conv_to_hex_char(b); } //! Append a quasi-random string to the given filename. //! The rand() function is deliberately not used, //! as rand() has an internal state that changes //! from call to call. Such states should not be //! modified in scientific applications, where the //! results should be reproducable and not affected //! by saving data. inline std::string diskio::gen_tmp_name(const std::string& x) { const std::string* ptr_x = &x; const u8* ptr_ptr_x = reinterpret_cast(&ptr_x); const char* extra = ".tmp_"; const uword extra_size = 5; const uword tmp_size = 2*sizeof(u8*) + 2*2; char tmp[tmp_size]; uword char_count = 0; for(uword i=0; i(x.size()); u8 sum = 0; for(uword i=0; i inline bool diskio::convert_naninf(eT& val, const std::string& token) { // see if the token represents a NaN or Inf if( (token.length() == 3) || (token.length() == 4) ) { const bool neg = (token[0] == '-'); const bool pos = (token[0] == '+'); const size_t offset = ( (neg || pos) && (token.length() == 4) ) ? 1 : 0; const std::string token2 = token.substr(offset, 3); if( (token2 == "inf") || (token2 == "Inf") || (token2 == "INF") ) { val = neg ? -(Datum::inf) : Datum::inf; return true; } else if( (token2 == "nan") || (token2 == "Nan") || (token2 == "NaN") || (token2 == "NAN") ) { val = neg ? -(Datum::nan) : Datum::nan; return true; } } return false; } template inline bool diskio::convert_naninf(std::complex& val, const std::string& token) { if( token.length() >= 5 ) { std::stringstream ss( token.substr(1, token.length()-2) ); // strip '(' at the start and ')' at the end std::string token_real; std::string token_imag; std::getline(ss, token_real, ','); std::getline(ss, token_imag); std::stringstream ss_real(token_real); std::stringstream ss_imag(token_imag); T val_real = T(0); T val_imag = T(0); ss_real >> val_real; ss_imag >> val_imag; bool success_real = true; bool success_imag = true; if(ss_real.fail() == true) { success_real = diskio::convert_naninf( val_real, token_real ); } if(ss_imag.fail() == true) { success_imag = diskio::convert_naninf( val_imag, token_imag ); } val = std::complex(val_real, val_imag); return (success_real && success_imag); } return false; } //! Save a matrix as raw text (no header, human readable). //! Matrices can be loaded in Matlab and Octave, as long as they don't have complex elements. template inline bool diskio::save_raw_ascii(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::fstream f(tmp_name.c_str(), std::fstream::out); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_raw_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix as raw text (no header, human readable). //! Matrices can be loaded in Matlab and Octave, as long as they don't have complex elements. template inline bool diskio::save_raw_ascii(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); uword cell_width; // TODO: need sane values for complex numbers if( (is_float::value == true) || (is_double::value == true) ) { f.setf(ios::scientific); f.precision(12); cell_width = 20; } for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float::value == true) || (is_double::value == true) ) { f.width(cell_width); } f << x.at(row,col); } f.put('\n'); } return f.good(); } //! Save a matrix as raw binary (no header) template inline bool diskio::save_raw_binary(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_raw_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } template inline bool diskio::save_raw_binary(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); f.write( reinterpret_cast(x.mem), std::streamsize(x.n_elem*sizeof(eT)) ); return f.good(); } //! Save a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::save_arma_ascii(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str()); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::save_arma_ascii(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); f << diskio::gen_txt_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << '\n'; uword cell_width; // TODO: need sane values for complex numbers if( (is_float::value == true) || (is_double::value == true) ) { f.setf(ios::scientific); f.precision(12); cell_width = 20; } for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float::value == true) || (is_double::value == true) ) { f.width(cell_width); } f << x.at(row,col); } f.put('\n'); } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; } //! Save a matrix in CSV text format (human readable) template inline bool diskio::save_csv_ascii(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str()); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_csv_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix in CSV text format (human readable) template inline bool diskio::save_csv_ascii(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); // TODO: need sane values for complex numbers if( (is_float::value == true) || (is_double::value == true) ) { f.setf(ios::scientific); f.precision(12); } uword x_n_rows = x.n_rows; uword x_n_cols = x.n_cols; for(uword row=0; row < x_n_rows; ++row) { for(uword col=0; col < x_n_cols; ++col) { f << x.at(row,col); if( col < (x_n_cols-1) ) { f.put(','); } } f.put('\n'); } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; } //! Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions template inline bool diskio::save_arma_binary(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions template inline bool diskio::save_arma_binary(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); f << diskio::gen_bin_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << '\n'; f.write( reinterpret_cast(x.mem), std::streamsize(x.n_elem*sizeof(eT)) ); return f.good(); } //! Save a matrix as a PGM greyscale image template inline bool diskio::save_pgm_binary(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::fstream f(tmp_name.c_str(), std::fstream::out | std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_pgm_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } // // TODO: // add functionality to save the image in a normalised format, // i.e. scaled so that every value falls in the [0,255] range. //! Save a matrix as a PGM greyscale image template inline bool diskio::save_pgm_binary(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); f << "P5" << '\n'; f << x.n_cols << ' ' << x.n_rows << '\n'; f << 255 << '\n'; const uword n_elem = x.n_rows * x.n_cols; podarray tmp(n_elem); uword i = 0; for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { tmp[i] = u8( x.at(row,col) ); // TODO: add round() ? ++i; } } f.write(reinterpret_cast(tmp.mem), std::streamsize(n_elem) ); return f.good(); } //! Save a matrix as a PGM greyscale image template inline bool diskio::save_pgm_binary(const Mat< std::complex >& x, const std::string& final_name) { arma_extra_debug_sigprint(); const uchar_mat tmp = conv_to::from(x); return diskio::save_pgm_binary(tmp, final_name); } //! Save a matrix as a PGM greyscale image template inline bool diskio::save_pgm_binary(const Mat< std::complex >& x, std::ostream& f) { arma_extra_debug_sigprint(); const uchar_mat tmp = conv_to::from(x); return diskio::save_pgm_binary(tmp, f); } //! Save a matrix as part of a HDF5 file template inline bool diskio::save_hdf5_binary(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) { #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Disable annoying HDF5 error messages. H5Eset_auto(H5E_DEFAULT, NULL, NULL); } #endif bool save_okay = false; const std::string tmp_name = diskio::gen_tmp_name(final_name); // Set up the file according to HDF5's preferences hid_t file = H5Fcreate(tmp_name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); // We need to create a dataset, datatype, and dataspace hsize_t dims[2]; dims[1] = x.n_rows; dims[0] = x.n_cols; hid_t dataspace = H5Screate_simple(2, dims, NULL); // treat the matrix as a 2d array dataspace hid_t datatype = hdf5_misc::get_hdf5_type(); // If this returned something invalid, well, it's time to crash. arma_check(datatype == -1, "Mat::save(): unknown datatype for HDF5"); // MATLAB forces the users to specify a name at save time for HDF5; Octave // will use the default of 'dataset' unless otherwise specified, so we will // use that. hid_t dataset = H5Dcreate(file, "dataset", datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); // H5Dwrite does not make a distinction between row-major and column-major; // it just writes the memory. MATLAB and Octave store HDF5 matrices as // column-major, though, so we can save ours like that too and not need to // transpose. herr_t status = H5Dwrite(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, x.mem); save_okay = (status >= 0); H5Dclose(dataset); H5Tclose(datatype); H5Sclose(dataspace); H5Fclose(file); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } return save_okay; } #else { arma_ignore(x); arma_ignore(final_name); arma_stop("Mat::save(): use of HDF5 needs to be enabled"); return false; } #endif } //! Load a matrix as raw text (no header, human readable). //! Can read matrices saved as text in Matlab and Octave. //! NOTE: this is much slower than reading a file with a header. template inline bool diskio::load_raw_ascii(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_raw_ascii(x, f, err_msg); f.close(); } return load_okay; } //! Load a matrix as raw text (no header, human readable). //! Can read matrices saved as text in Matlab and Octave. //! NOTE: this is much slower than reading a file with a header. template inline bool diskio::load_raw_ascii(Mat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = f.good(); f.clear(); const std::fstream::pos_type pos1 = f.tellg(); // // work out the size uword f_n_rows = 0; uword f_n_cols = 0; bool f_n_cols_found = false; std::string line_string; std::string token; std::stringstream line_stream; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_n_cols = 0; while (line_stream >> token) { ++line_n_cols; } if(f_n_cols_found == false) { f_n_cols = line_n_cols; f_n_cols_found = true; } else { if(line_n_cols != f_n_cols) { err_msg = "inconsistent number of columns in "; load_okay = false; } } ++f_n_rows; } if(load_okay == true) { f.clear(); f.seekg(pos1); x.set_size(f_n_rows, f_n_cols); std::stringstream ss; for(uword row=0; (row < x.n_rows) && (load_okay == true); ++row) { for(uword col=0; (col < x.n_cols) && (load_okay == true); ++col) { f >> token; ss.clear(); ss.str(token); eT val = eT(0); ss >> val; if(ss.fail() == false) { x.at(row,col) = val; } else { const bool success = diskio::convert_naninf( x.at(row,col), token ); if(success == false) { load_okay = false; err_msg = "couldn't interpret data in "; } } } } } // an empty file indicates an empty matrix if( (f_n_cols_found == false) && (load_okay == true) ) { x.reset(); } return load_okay; } //! Load a matrix in binary format (no header); //! the matrix is assumed to have one column template inline bool diskio::load_raw_binary(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_raw_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_raw_binary(Mat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(err_msg); f.clear(); const std::streampos pos1 = f.tellg(); f.clear(); f.seekg(0, ios::end); f.clear(); const std::streampos pos2 = f.tellg(); const uword N = ( (pos1 >= 0) && (pos2 >= 0) ) ? uword(pos2 - pos1) : 0; f.clear(); //f.seekg(0, ios::beg); f.seekg(pos1); x.set_size(N / sizeof(eT), 1); f.clear(); f.read( reinterpret_cast(x.memptr()), std::streamsize(N) ); return f.good(); } //! Load a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::load_arma_ascii(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f(name.c_str()); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_ascii(x, f, err_msg); f.close(); } return load_okay; } //! Load a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::load_arma_ascii(Mat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; uword f_n_rows; uword f_n_cols; f >> f_header; f >> f_n_rows; f >> f_n_cols; if(f_header == diskio::gen_txt_header(x)) { x.zeros(f_n_rows, f_n_cols); std::string token; std::stringstream ss; for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f >> token; ss.clear(); ss.str(token); eT val = eT(0); ss >> val; if(ss.fail() == false) { x.at(row,col) = val; } else { diskio::convert_naninf( x.at(row,col), token ); } } } load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } return load_okay; } //! Load a matrix in CSV text format (human readable) template inline bool diskio::load_csv_ascii(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_csv_ascii(x, f, err_msg); f.close(); } return load_okay; } //! Load a matrix in CSV text format (human readable) template inline bool diskio::load_csv_ascii(Mat& x, std::istream& f, std::string&) { arma_extra_debug_sigprint(); bool load_okay = f.good(); f.clear(); const std::fstream::pos_type pos1 = f.tellg(); // // work out the size uword f_n_rows = 0; uword f_n_cols = 0; std::string line_string; std::string token; std::stringstream line_stream; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_n_cols = 0; while(line_stream.good() == true) { std::getline(line_stream, token, ','); ++line_n_cols; } if(f_n_cols < line_n_cols) { f_n_cols = line_n_cols; } ++f_n_rows; } f.clear(); f.seekg(pos1); x.zeros(f_n_rows, f_n_cols); uword row = 0; std::stringstream ss; while(f.good() == true) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword col = 0; while(line_stream.good() == true) { std::getline(line_stream, token, ','); ss.clear(); ss.str(token); eT val = eT(0); ss >> val; if(ss.fail() == false) { x.at(row,col) = val; } else { diskio::convert_naninf( x.at(row,col), token ); } ++col; } ++row; } return load_okay; } //! Load a matrix in binary format, //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::load_arma_binary(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_arma_binary(Mat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; uword f_n_rows; uword f_n_cols; f >> f_header; f >> f_n_rows; f >> f_n_cols; if(f_header == diskio::gen_bin_header(x)) { //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Windows machine a newline could be two characters f.get(); x.set_size(f_n_rows,f_n_cols); f.read( reinterpret_cast(x.memptr()), std::streamsize(x.n_elem*sizeof(eT)) ); load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } return load_okay; } inline void diskio::pnm_skip_comments(std::istream& f) { while( isspace(f.peek()) ) { while( isspace(f.peek()) ) { f.get(); } if(f.peek() == '#') { while( (f.peek() != '\r') && (f.peek()!='\n') ) { f.get(); } } } } //! Load a PGM greyscale image as a matrix template inline bool diskio::load_pgm_binary(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_pgm_binary(x, f, err_msg); f.close(); } return load_okay; } //! Load a PGM greyscale image as a matrix template inline bool diskio::load_pgm_binary(Mat& x, std::istream& f, std::string& err_msg) { bool load_okay = true; std::string f_header; f >> f_header; if(f_header == "P5") { uword f_n_rows = 0; uword f_n_cols = 0; int f_maxval = 0; diskio::pnm_skip_comments(f); f >> f_n_cols; diskio::pnm_skip_comments(f); f >> f_n_rows; diskio::pnm_skip_comments(f); f >> f_maxval; f.get(); if( (f_maxval > 0) || (f_maxval <= 65535) ) { x.set_size(f_n_rows,f_n_cols); if(f_maxval <= 255) { const uword n_elem = f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(n_elem) ); uword i = 0; //cout << "f_n_cols = " << f_n_cols << endl; //cout << "f_n_rows = " << f_n_rows << endl; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { x.at(row,col) = eT(tmp[i]); ++i; } } } else { const uword n_elem = f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(n_elem*2) ); uword i = 0; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { x.at(row,col) = eT(tmp[i]); ++i; } } } } else { load_okay = false; err_msg = "currently no code available to handle loading "; } if(f.good() == false) { load_okay = false; } } else { load_okay = false; err_msg = "unsupported header in "; } return load_okay; } //! Load a PGM greyscale image as a matrix template inline bool diskio::load_pgm_binary(Mat< std::complex >& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); uchar_mat tmp; const bool load_okay = diskio::load_pgm_binary(tmp, name, err_msg); x = conv_to< Mat< std::complex > >::from(tmp); return load_okay; } //! Load a PGM greyscale image as a matrix template inline bool diskio::load_pgm_binary(Mat< std::complex >& x, std::istream& is, std::string& err_msg) { arma_extra_debug_sigprint(); uchar_mat tmp; const bool load_okay = diskio::load_pgm_binary(tmp, is, err_msg); x = conv_to< Mat< std::complex > >::from(tmp); return load_okay; } //! Load a HDF5 file as a matrix template inline bool diskio::load_hdf5_binary(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) { // These may be necessary to store the error handler (if we need to). herr_t (*old_func)(hid_t, void*); void *old_client_data; #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Save old error handler. H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data); // Disable annoying HDF5 error messages. H5Eset_auto(H5E_DEFAULT, NULL, NULL); } #endif bool load_okay = false; hid_t fid = H5Fopen(name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); if(fid >= 0) { // MATLAB HDF5 dataset names are user-specified; // Octave tends to store the datasets in a group, with the actual dataset being referred to as "value". // So we will search for "dataset" and "value", and if those are not found we will take the first dataset we do find. std::vector searchNames; searchNames.push_back("dataset"); searchNames.push_back("value"); hid_t dataset = hdf5_misc::search_hdf5_file(searchNames, fid, 2, false); if(dataset >= 0) { hid_t filespace = H5Dget_space(dataset); // This must be <= 2 due to our search rules. const int ndims = H5Sget_simple_extent_ndims(filespace); hsize_t dims[2]; const herr_t query_status = H5Sget_simple_extent_dims(filespace, dims, NULL); // arma_check(query_status < 0, "Mat::load(): cannot get size of HDF5 dataset"); if(query_status < 0) { err_msg = "cannot get size of HDF5 dataset in "; H5Sclose(filespace); H5Dclose(dataset); H5Fclose(fid); #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Restore HDF5 error handler. H5Eset_auto(H5E_DEFAULT, old_func, old_client_data); } #endif return false; } if(ndims == 1) { dims[1] = 1; } // Vector case; fake second dimension (one column). x.set_size(dims[1], dims[0]); // Now we have to see what type is stored to figure out how to load it. hid_t datatype = H5Dget_type(dataset); hid_t mat_type = hdf5_misc::get_hdf5_type(); // If these are the same type, it is simple. if(H5Tequal(datatype, mat_type) > 0) { // Load directly; H5S_ALL used so that we load the entire dataset. hid_t read_status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(x.memptr())); if(read_status >= 0) { load_okay = true; } } else { // Load into another array and convert its type accordingly. hid_t read_status = hdf5_misc::load_and_convert_hdf5(x.memptr(), dataset, datatype, x.n_elem); if(read_status >= 0) { load_okay = true; } } // Now clean up. H5Tclose(datatype); H5Tclose(mat_type); H5Sclose(filespace); } H5Dclose(dataset); H5Fclose(fid); if(load_okay == false) { err_msg = "unsupported or incorrect HDF5 data in "; } } else { err_msg = "cannot open file "; } #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Restore HDF5 error handler. H5Eset_auto(H5E_DEFAULT, old_func, old_client_data); } #endif return load_okay; } #else { arma_ignore(x); arma_ignore(name); arma_ignore(err_msg); arma_stop("Mat::load(): use of HDF5 needs to be enabled"); return false; } #endif } //! Try to load a matrix by automatically determining its type template inline bool diskio::load_auto_detect(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) // We're currently using the C bindings for the HDF5 library, which don't support C++ streams if( H5Fis_hdf5(name.c_str()) ) { return load_hdf5_binary(x, name, err_msg); } #endif std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_auto_detect(x, f, err_msg); f.close(); } return load_okay; } //! Try to load a matrix by automatically determining its type template inline bool diskio::load_auto_detect(Mat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); static const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT"; static const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN"; static const std::string P5 = "P5"; podarray raw_header(ARMA_MAT_TXT.length() + 1); std::streampos pos = f.tellg(); f.read( raw_header.memptr(), std::streamsize(ARMA_MAT_TXT.length()) ); raw_header[ARMA_MAT_TXT.length()] = '\0'; f.clear(); f.seekg(pos); const std::string header = raw_header.mem; if(ARMA_MAT_TXT == header.substr(0,ARMA_MAT_TXT.length())) { return load_arma_ascii(x, f, err_msg); } else if(ARMA_MAT_BIN == header.substr(0,ARMA_MAT_BIN.length())) { return load_arma_binary(x, f, err_msg); } else if(P5 == header.substr(0,P5.length())) { return load_pgm_binary(x, f, err_msg); } else { const file_type ft = guess_file_type(f); switch(ft) { case csv_ascii: return load_csv_ascii(x, f, err_msg); break; case raw_binary: return load_raw_binary(x, f, err_msg); break; case raw_ascii: return load_raw_ascii(x, f, err_msg); break; default: err_msg = "unknown data in "; return false; } } return false; } // // sparse matrices // //! Save a matrix in ASCII coord format template inline bool diskio::save_coord_ascii(const SpMat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str()); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_coord_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix in ASCII coord format template inline bool diskio::save_coord_ascii(const SpMat& x, std::ostream& f) { arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); typename SpMat::const_iterator iter = x.begin(); typename SpMat::const_iterator iter_end = x.end(); for(; iter != iter_end; ++iter) { f.setf(ios::fixed); f << iter.row() << ' ' << iter.col() << ' '; if( (is_float::value == true) || (is_double::value == true) ) { f.setf(ios::scientific); f.precision(12); } f << (*iter) << '\n'; } // make sure it's possible to figure out the matrix size later if( (x.n_rows > 0) && (x.n_cols > 0) ) { const uword max_row = (x.n_rows > 0) ? x.n_rows-1 : 0; const uword max_col = (x.n_cols > 0) ? x.n_cols-1 : 0; if( x.at(max_row, max_col) == eT(0) ) { f.setf(ios::fixed); f << max_row << ' ' << max_col << " 0\n"; } } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; } //! Save a matrix in ASCII coord format (complex numbers) template inline bool diskio::save_coord_ascii(const SpMat< std::complex >& x, std::ostream& f) { arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); typedef typename std::complex eT; typename SpMat::const_iterator iter = x.begin(); typename SpMat::const_iterator iter_end = x.end(); for(; iter != iter_end; ++iter) { f.setf(ios::fixed); f << iter.row() << ' ' << iter.col() << ' '; if( (is_float::value == true) || (is_double::value == true) ) { f.setf(ios::scientific); f.precision(12); } const eT val = (*iter); f << val.real() << ' ' << val.imag() << '\n'; } // make sure it's possible to figure out the matrix size later if( (x.n_rows > 0) && (x.n_cols > 0) ) { const uword max_row = (x.n_rows > 0) ? x.n_rows-1 : 0; const uword max_col = (x.n_cols > 0) ? x.n_cols-1 : 0; if( x.at(max_row, max_col) == eT(0) ) { f.setf(ios::fixed); f << max_row << ' ' << max_col << " 0 0\n"; } } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; } //! Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions template inline bool diskio::save_arma_binary(const SpMat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions template inline bool diskio::save_arma_binary(const SpMat& x, std::ostream& f) { arma_extra_debug_sigprint(); f << diskio::gen_bin_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_nonzero << '\n'; f.write( reinterpret_cast(x.values), std::streamsize(x.n_nonzero*sizeof(eT)) ); f.write( reinterpret_cast(x.row_indices), std::streamsize(x.n_nonzero*sizeof(uword)) ); f.write( reinterpret_cast(x.col_ptrs), std::streamsize((x.n_cols+1)*sizeof(uword)) ); return f.good(); } template inline bool diskio::load_coord_ascii(SpMat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_coord_ascii(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_coord_ascii(SpMat& x, std::istream& f, std::string& err_msg) { bool load_okay = f.good(); f.clear(); const std::fstream::pos_type pos1 = f.tellg(); // // work out the size uword f_n_rows = 0; uword f_n_cols = 0; uword f_n_nz = 0; bool size_found = false; std::string line_string; std::string token; std::stringstream line_stream; std::stringstream ss; uword last_line_row = 0; uword last_line_col = 0; bool first_line = true; bool weird_format = false; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_row = 0; uword line_col = 0; // a valid line in co-ord format has at least 2 entries line_stream >> line_row; if(line_stream.good() == false) { load_okay = false; break; } line_stream >> line_col; size_found = true; if(f_n_rows < line_row) f_n_rows = line_row; if(f_n_cols < line_col) f_n_cols = line_col; if(first_line == true) { first_line = false; } else { if( (line_col < last_line_col) || ((line_row <= last_line_row) && (line_col <= last_line_col)) ) { weird_format = true; } } last_line_row = line_row; last_line_col = line_col; if(line_stream.good() == true) { eT final_val = eT(0); line_stream >> token; if(line_stream.fail() == false) { eT val = eT(0); ss.clear(); ss.str(token); ss >> val; if(ss.fail() == false) { final_val = val; } else { val = eT(0); const bool success = diskio::convert_naninf( val, token ); if(success == true) { final_val = val; } } } if(final_val != eT(0)) { ++f_n_nz; } } } if(size_found == true) { // take into account that indices start at 0 f_n_rows++; f_n_cols++; } if(load_okay == true) { f.clear(); f.seekg(pos1); x.set_size(f_n_rows, f_n_cols); if(weird_format == false) { x.mem_resize(f_n_nz); } uword pos = 0; while(f.good() == true) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_row = 0; uword line_col = 0; line_stream >> line_row; line_stream >> line_col; eT final_val = eT(0); line_stream >> token; if(line_stream.fail() == false) { eT val = eT(0); ss.clear(); ss.str(token); ss >> val; if(ss.fail() == false) { final_val = val; } else { val = eT(0); const bool success = diskio::convert_naninf( val, token ); if(success == true) { final_val = val; } } } if(final_val != eT(0)) { if(weird_format == false) { access::rw(x.row_indices[pos]) = line_row; access::rw(x.values[pos]) = final_val; ++access::rw(x.col_ptrs[line_col + 1]); ++pos; } else { x.at(line_row,line_col) = final_val; } } } if(weird_format == false) { for(uword c = 1; c <= f_n_cols; ++c) { access::rw(x.col_ptrs[c]) += x.col_ptrs[c - 1]; } } } return load_okay; } template inline bool diskio::load_coord_ascii(SpMat< std::complex >& x, std::istream& f, std::string& err_msg) { bool load_okay = f.good(); f.clear(); const std::fstream::pos_type pos1 = f.tellg(); // // work out the size uword f_n_rows = 0; uword f_n_cols = 0; uword f_n_nz = 0; bool size_found = false; std::string line_string; std::string token_real; std::string token_imag; std::stringstream line_stream; std::stringstream ss; uword last_line_row = 0; uword last_line_col = 0; bool first_line = true; bool weird_format = false; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_row = 0; uword line_col = 0; // a valid line in co-ord format has at least 2 entries line_stream >> line_row; if(line_stream.good() == false) { load_okay = false; break; } line_stream >> line_col; size_found = true; if(f_n_rows < line_row) f_n_rows = line_row; if(f_n_cols < line_col) f_n_cols = line_col; if(first_line == true) { first_line = false; } else { if( (line_col < last_line_col) || ((line_row <= last_line_row) && (line_col <= last_line_col)) ) { weird_format = true; } } last_line_row = line_row; last_line_col = line_col; if(line_stream.good() == true) { T final_val_real = T(0); T final_val_imag = T(0); line_stream >> token_real; if(line_stream.fail() == false) { T val_real = T(0); ss.clear(); ss.str(token_real); ss >> val_real; if(ss.fail() == false) { final_val_real = val_real; } else { val_real = T(0); const bool success = diskio::convert_naninf( val_real, token_real ); if(success == true) { final_val_real = val_real; } } } line_stream >> token_imag; if(line_stream.fail() == false) { T val_imag = T(0); ss.clear(); ss.str(token_imag); ss >> val_imag; if(ss.fail() == false) { final_val_imag = val_imag; } else { val_imag = T(0); const bool success = diskio::convert_naninf( val_imag, token_imag ); if(success == true) { final_val_imag = val_imag; } } } if( (final_val_real != T(0)) || (final_val_imag != T(0)) ) { ++f_n_nz; } } } if(size_found == true) { // take into account that indices start at 0 f_n_rows++; f_n_cols++; } if(load_okay == true) { f.clear(); f.seekg(pos1); x.set_size(f_n_rows, f_n_cols); if(weird_format == false) { x.mem_resize(f_n_nz); } uword pos = 0; while(f.good() == true) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_row = 0; uword line_col = 0; line_stream >> line_row; line_stream >> line_col; T final_val_real = T(0); T final_val_imag = T(0); line_stream >> token_real; if(line_stream.fail() == false) { T val_real = T(0); ss.clear(); ss.str(token_real); ss >> val_real; if(ss.fail() == false) { final_val_real = val_real; } else { val_real = T(0); const bool success = diskio::convert_naninf( val_real, token_real ); if(success == true) { final_val_real = val_real; } } } line_stream >> token_imag; if(line_stream.fail() == false) { T val_imag = T(0); ss.clear(); ss.str(token_imag); ss >> val_imag; if(ss.fail() == false) { final_val_imag = val_imag; } else { val_imag = T(0); const bool success = diskio::convert_naninf( val_imag, token_imag ); if(success == true) { final_val_imag = val_imag; } } } if( (final_val_real != T(0)) || (final_val_imag != T(0)) ) { if(weird_format == false) { access::rw(x.row_indices[pos]) = line_row; access::rw(x.values[pos]) = std::complex(final_val_real, final_val_imag); ++access::rw(x.col_ptrs[line_col + 1]); ++pos; } else { x.at(line_row,line_col) = std::complex(final_val_real, final_val_imag); } } } if(weird_format == false) { for(uword c = 1; c <= f_n_cols; ++c) { access::rw(x.col_ptrs[c]) += x.col_ptrs[c - 1]; } } } return load_okay; } //! Load a matrix in binary format, //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::load_arma_binary(SpMat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_arma_binary(SpMat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; f >> f_header; if(f_header == diskio::gen_bin_header(x)) { uword f_n_rows; uword f_n_cols; uword f_n_nz; f >> f_n_rows; f >> f_n_cols; f >> f_n_nz; //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Windows machine a newline could be two characters f.get(); x.set_size(f_n_rows, f_n_cols); x.mem_resize(f_n_nz); f.read( reinterpret_cast(access::rwp(x.values)), std::streamsize(x.n_nonzero*sizeof(eT)) ); f.read( reinterpret_cast(access::rwp(x.row_indices)), std::streamsize(x.n_nonzero*sizeof(uword)) ); f.read( reinterpret_cast(access::rwp(x.col_ptrs)), std::streamsize((x.n_cols+1)*sizeof(uword)) ); load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } return load_okay; } // cubes //! Save a cube as raw text (no header, human readable). template inline bool diskio::save_raw_ascii(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::fstream f(tmp_name.c_str(), std::fstream::out); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = save_raw_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a cube as raw text (no header, human readable). template inline bool diskio::save_raw_ascii(const Cube& x, std::ostream& f) { arma_extra_debug_sigprint(); uword cell_width; // TODO: need sane values for complex numbers if( (is_float::value == true) || (is_double::value == true) ) { f.setf(ios::scientific); f.precision(12); cell_width = 20; } for(uword slice=0; slice < x.n_slices; ++slice) { for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float::value == true) || (is_double::value == true) ) { f.width(cell_width); } f << x.at(row,col,slice); } f.put('\n'); } } return f.good(); } //! Save a cube as raw binary (no header) template inline bool diskio::save_raw_binary(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_raw_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } template inline bool diskio::save_raw_binary(const Cube& x, std::ostream& f) { arma_extra_debug_sigprint(); f.write( reinterpret_cast(x.mem), std::streamsize(x.n_elem*sizeof(eT)) ); return f.good(); } //! Save a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions template inline bool diskio::save_arma_ascii(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str()); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions template inline bool diskio::save_arma_ascii(const Cube& x, std::ostream& f) { arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); f << diskio::gen_txt_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n'; uword cell_width; // TODO: need sane values for complex numbers if( (is_float::value == true) || (is_double::value == true) ) { f.setf(ios::scientific); f.precision(12); cell_width = 20; } for(uword slice=0; slice < x.n_slices; ++slice) { for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float::value == true) || (is_double::value == true) ) { f.width(cell_width); } f << x.at(row,col,slice); } f.put('\n'); } } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; } //! Save a cube in binary format, //! with a header that stores the cube type as well as its dimensions template inline bool diskio::save_arma_binary(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a cube in binary format, //! with a header that stores the cube type as well as its dimensions template inline bool diskio::save_arma_binary(const Cube& x, std::ostream& f) { arma_extra_debug_sigprint(); f << diskio::gen_bin_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n'; f.write( reinterpret_cast(x.mem), std::streamsize(x.n_elem*sizeof(eT)) ); return f.good(); } //! Save a cube as part of a HDF5 file template inline bool diskio::save_hdf5_binary(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) { #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Disable annoying HDF5 error messages. H5Eset_auto(H5E_DEFAULT, NULL, NULL); } #endif bool save_okay = false; const std::string tmp_name = diskio::gen_tmp_name(final_name); // Set up the file according to HDF5's preferences hid_t file = H5Fcreate(tmp_name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); // We need to create a dataset, datatype, and dataspace hsize_t dims[3]; dims[2] = x.n_rows; dims[1] = x.n_cols; dims[0] = x.n_slices; hid_t dataspace = H5Screate_simple(3, dims, NULL); // treat the cube as a 3d array dataspace hid_t datatype = hdf5_misc::get_hdf5_type(); // If this returned something invalid, well, it's time to crash. arma_check(datatype == -1, "Cube::save(): unknown datatype for HDF5"); // MATLAB forces the users to specify a name at save time for HDF5; Octave // will use the default of 'dataset' unless otherwise specified, so we will // use that. hid_t dataset = H5Dcreate(file, "dataset", datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); herr_t status = H5Dwrite(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, x.mem); save_okay = (status >= 0); H5Dclose(dataset); H5Tclose(datatype); H5Sclose(dataspace); H5Fclose(file); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } return save_okay; } #else { arma_ignore(x); arma_ignore(final_name); arma_stop("Cube::save(): use of HDF5 needs to be enabled"); return false; } #endif } //! Load a cube as raw text (no header, human readable). //! NOTE: this is much slower than reading a file with a header. template inline bool diskio::load_raw_ascii(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); Mat tmp; const bool load_okay = diskio::load_raw_ascii(tmp, name, err_msg); if(load_okay == true) { if(tmp.is_empty() == false) { x.set_size(tmp.n_rows, tmp.n_cols, 1); x.slice(0) = tmp; } else { x.reset(); } } return load_okay; } //! Load a cube as raw text (no header, human readable). //! NOTE: this is much slower than reading a file with a header. template inline bool diskio::load_raw_ascii(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); Mat tmp; const bool load_okay = diskio::load_raw_ascii(tmp, f, err_msg); if(load_okay == true) { if(tmp.is_empty() == false) { x.set_size(tmp.n_rows, tmp.n_cols, 1); x.slice(0) = tmp; } else { x.reset(); } } return load_okay; } //! Load a cube in binary format (no header); //! the cube is assumed to have one slice with one column template inline bool diskio::load_raw_binary(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_raw_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_raw_binary(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(err_msg); f.clear(); const std::streampos pos1 = f.tellg(); f.clear(); f.seekg(0, ios::end); f.clear(); const std::streampos pos2 = f.tellg(); const uword N = ( (pos1 >= 0) && (pos2 >= 0) ) ? uword(pos2 - pos1) : 0; f.clear(); //f.seekg(0, ios::beg); f.seekg(pos1); x.set_size(N / sizeof(eT), 1, 1); f.clear(); f.read( reinterpret_cast(x.memptr()), std::streamsize(N) ); return f.good(); } //! Load a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions template inline bool diskio::load_arma_ascii(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f(name.c_str()); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_ascii(x, f, err_msg); f.close(); } return load_okay; } //! Load a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions template inline bool diskio::load_arma_ascii(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; uword f_n_rows; uword f_n_cols; uword f_n_slices; f >> f_header; f >> f_n_rows; f >> f_n_cols; f >> f_n_slices; if(f_header == diskio::gen_txt_header(x)) { x.set_size(f_n_rows, f_n_cols, f_n_slices); for(uword slice=0; slice < x.n_slices; ++slice) { for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f >> x.at(row,col,slice); } } } load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } return load_okay; } //! Load a cube in binary format, //! with a header that indicates the cube type as well as its dimensions template inline bool diskio::load_arma_binary(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_arma_binary(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; uword f_n_rows; uword f_n_cols; uword f_n_slices; f >> f_header; f >> f_n_rows; f >> f_n_cols; f >> f_n_slices; if(f_header == diskio::gen_bin_header(x)) { //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Windows machine a newline could be two characters f.get(); x.set_size(f_n_rows, f_n_cols, f_n_slices); f.read( reinterpret_cast(x.memptr()), std::streamsize(x.n_elem*sizeof(eT)) ); load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } return load_okay; } //! Load a HDF5 file as a cube template inline bool diskio::load_hdf5_binary(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) { // These may be necessary to store the error handler (if we need to). herr_t (*old_func)(hid_t, void*); void *old_client_data; #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Save old error handler. H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data); // Disable annoying HDF5 error messages. H5Eset_auto(H5E_DEFAULT, NULL, NULL); } #endif bool load_okay = false; hid_t fid = H5Fopen(name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); if(fid >= 0) { // MATLAB HDF5 dataset names are user-specified; // Octave tends to store the datasets in a group, with the actual dataset being referred to as "value". // So we will search for "dataset" and "value", and if those are not found we will take the first dataset we do find. std::vector searchNames; searchNames.push_back("dataset"); searchNames.push_back("value"); hid_t dataset = hdf5_misc::search_hdf5_file(searchNames, fid, 3, false); if(dataset >= 0) { hid_t filespace = H5Dget_space(dataset); // This must be <= 3 due to our search rules. const int ndims = H5Sget_simple_extent_ndims(filespace); hsize_t dims[3]; const herr_t query_status = H5Sget_simple_extent_dims(filespace, dims, NULL); // arma_check(query_status < 0, "Cube::load(): cannot get size of HDF5 dataset"); if(query_status < 0) { err_msg = "cannot get size of HDF5 dataset in "; H5Sclose(filespace); H5Dclose(dataset); H5Fclose(fid); #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Restore HDF5 error handler. H5Eset_auto(H5E_DEFAULT, old_func, old_client_data); } #endif return false; } if (ndims == 1) { dims[1] = 1; dims[2] = 1; } // Vector case; one row/colum, several slices if (ndims == 2) { dims[2] = 1; } // Matrix case; one column, several rows/slices x.set_size(dims[2], dims[1], dims[0]); // Now we have to see what type is stored to figure out how to load it. hid_t datatype = H5Dget_type(dataset); hid_t mat_type = hdf5_misc::get_hdf5_type(); // If these are the same type, it is simple. if(H5Tequal(datatype, mat_type) > 0) { // Load directly; H5S_ALL used so that we load the entire dataset. hid_t read_status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(x.memptr())); if(read_status >= 0) { load_okay = true; } } else { // Load into another array and convert its type accordingly. hid_t read_status = hdf5_misc::load_and_convert_hdf5(x.memptr(), dataset, datatype, x.n_elem); if(read_status >= 0) { load_okay = true; } } // Now clean up. H5Tclose(datatype); H5Tclose(mat_type); H5Sclose(filespace); } H5Dclose(dataset); H5Fclose(fid); if(load_okay == false) { err_msg = "unsupported or incorrect HDF5 data in "; } } else { err_msg = "cannot open file "; } #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Restore HDF5 error handler. H5Eset_auto(H5E_DEFAULT, old_func, old_client_data); } #endif return load_okay; } #else { arma_ignore(x); arma_ignore(name); arma_ignore(err_msg); arma_stop("Cube::load(): use of HDF5 needs to be enabled"); return false; } #endif } //! Try to load a cube by automatically determining its type template inline bool diskio::load_auto_detect(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) // We're currently using the C bindings for the HDF5 library, which don't support C++ streams if( H5Fis_hdf5(name.c_str()) ) { return load_hdf5_binary(x, name, err_msg); } #endif std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_auto_detect(x, f, err_msg); f.close(); } return load_okay; } //! Try to load a cube by automatically determining its type template inline bool diskio::load_auto_detect(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); static const std::string ARMA_CUB_TXT = "ARMA_CUB_TXT"; static const std::string ARMA_CUB_BIN = "ARMA_CUB_BIN"; static const std::string P6 = "P6"; podarray raw_header(ARMA_CUB_TXT.length() + 1); std::streampos pos = f.tellg(); f.read( raw_header.memptr(), std::streamsize(ARMA_CUB_TXT.length()) ); raw_header[ARMA_CUB_TXT.length()] = '\0'; f.clear(); f.seekg(pos); const std::string header = raw_header.mem; if(ARMA_CUB_TXT == header.substr(0, ARMA_CUB_TXT.length())) { return load_arma_ascii(x, f, err_msg); } else if(ARMA_CUB_BIN == header.substr(0, ARMA_CUB_BIN.length())) { return load_arma_binary(x, f, err_msg); } else if(P6 == header.substr(0, P6.length())) { return load_ppm_binary(x, f, err_msg); } else { const file_type ft = guess_file_type(f); switch(ft) { // case csv_ascii: // return load_csv_ascii(x, f, err_msg); // break; case raw_binary: return load_raw_binary(x, f, err_msg); break; case raw_ascii: return load_raw_ascii(x, f, err_msg); break; default: err_msg = "unknown data in "; return false; } } return false; } // fields template inline bool diskio::save_arma_binary(const field& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } template inline bool diskio::save_arma_binary(const field& x, std::ostream& f) { arma_extra_debug_sigprint(); arma_type_check(( (is_Mat::value == false) && (is_Cube::value == false) )); f << "ARMA_FLD_BIN" << '\n'; f << x.n_rows << '\n'; f << x.n_cols << '\n'; bool save_okay = true; for(uword i=0; i inline bool diskio::load_arma_binary(field& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f( name.c_str(), std::fstream::binary ); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_arma_binary(field& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_type_check(( (is_Mat::value == false) && (is_Cube::value == false) )); bool load_okay = true; std::string f_type; f >> f_type; if(f_type != "ARMA_FLD_BIN") { load_okay = false; err_msg = "unsupported field type in "; } else { uword f_n_rows; uword f_n_cols; f >> f_n_rows; f >> f_n_cols; x.set_size(f_n_rows, f_n_cols); f.get(); for(uword i=0; i& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_std_string(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } inline bool diskio::save_std_string(const field& x, std::ostream& f) { arma_extra_debug_sigprint(); for(uword row=0; row& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f( name.c_str() ); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_std_string(x, f, err_msg); f.close(); } return load_okay; } inline bool diskio::load_std_string(field& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = true; // // work out the size uword f_n_rows = 0; uword f_n_cols = 0; bool f_n_cols_found = false; std::string line_string; std::string token; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) break; std::stringstream line_stream(line_string); uword line_n_cols = 0; while (line_stream >> token) line_n_cols++; if(f_n_cols_found == false) { f_n_cols = line_n_cols; f_n_cols_found = true; } else { if(line_n_cols != f_n_cols) { load_okay = false; err_msg = "inconsistent number of columns in "; } } ++f_n_rows; } if(load_okay == true) { f.clear(); f.seekg(0, ios::beg); //f.seekg(start); x.set_size(f_n_rows, f_n_cols); for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f >> x.at(row,col); } } } if(f.good() == false) { load_okay = false; } return load_okay; } //! Try to load a field by automatically determining its type template inline bool diskio::load_auto_detect(field& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_auto_detect(x, f, err_msg); f.close(); } return load_okay; } //! Try to load a field by automatically determining its type template inline bool diskio::load_auto_detect(field& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_type_check(( is_Mat::value == false )); static const std::string ARMA_FLD_BIN = "ARMA_FLD_BIN"; static const std::string P6 = "P6"; podarray raw_header(ARMA_FLD_BIN.length() + 1); std::streampos pos = f.tellg(); f.read( raw_header.memptr(), std::streamsize(ARMA_FLD_BIN.length()) ); f.clear(); f.seekg(pos); raw_header[ARMA_FLD_BIN.length()] = '\0'; const std::string header = raw_header.mem; if(ARMA_FLD_BIN == header.substr(0, ARMA_FLD_BIN.length())) { return load_arma_binary(x, f, err_msg); } else if(P6 == header.substr(0, P6.length())) { return load_ppm_binary(x, f, err_msg); } else { err_msg = "unsupported header in "; return false; } } // // handling of PPM images by cubes template inline bool diskio::load_ppm_binary(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_ppm_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_ppm_binary(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; f >> f_header; if(f_header == "P6") { uword f_n_rows = 0; uword f_n_cols = 0; int f_maxval = 0; diskio::pnm_skip_comments(f); f >> f_n_cols; diskio::pnm_skip_comments(f); f >> f_n_rows; diskio::pnm_skip_comments(f); f >> f_maxval; f.get(); if( (f_maxval > 0) || (f_maxval <= 65535) ) { x.set_size(f_n_rows, f_n_cols, 3); if(f_maxval <= 255) { const uword n_elem = 3*f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(n_elem) ); uword i = 0; //cout << "f_n_cols = " << f_n_cols << endl; //cout << "f_n_rows = " << f_n_rows << endl; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { x.at(row,col,0) = eT(tmp[i+0]); x.at(row,col,1) = eT(tmp[i+1]); x.at(row,col,2) = eT(tmp[i+2]); i+=3; } } } else { const uword n_elem = 3*f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(2*n_elem) ); uword i = 0; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { x.at(row,col,0) = eT(tmp[i+0]); x.at(row,col,1) = eT(tmp[i+1]); x.at(row,col,2) = eT(tmp[i+2]); i+=3; } } } } else { load_okay = false; err_msg = "currently no code available to handle loading "; } if(f.good() == false) { load_okay = false; } } else { load_okay = false; err_msg = "unsupported header in "; } return load_okay; } template inline bool diskio::save_ppm_binary(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_ppm_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } template inline bool diskio::save_ppm_binary(const Cube& x, std::ostream& f) { arma_extra_debug_sigprint(); arma_debug_check( (x.n_slices != 3), "diskio::save_ppm_binary(): given cube must have exactly 3 slices" ); const uword n_elem = 3 * x.n_rows * x.n_cols; podarray tmp(n_elem); uword i = 0; for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { tmp[i+0] = u8( access::tmp_real( x.at(row,col,0) ) ); tmp[i+1] = u8( access::tmp_real( x.at(row,col,1) ) ); tmp[i+2] = u8( access::tmp_real( x.at(row,col,2) ) ); i+=3; } } f << "P6" << '\n'; f << x.n_cols << '\n'; f << x.n_rows << '\n'; f << 255 << '\n'; f.write( reinterpret_cast(tmp.mem), std::streamsize(n_elem) ); return f.good(); } // // handling of PPM images by fields template inline bool diskio::load_ppm_binary(field& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_ppm_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_ppm_binary(field& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_type_check(( is_Mat::value == false )); typedef typename T1::elem_type eT; bool load_okay = true; std::string f_header; f >> f_header; if(f_header == "P6") { uword f_n_rows = 0; uword f_n_cols = 0; int f_maxval = 0; diskio::pnm_skip_comments(f); f >> f_n_cols; diskio::pnm_skip_comments(f); f >> f_n_rows; diskio::pnm_skip_comments(f); f >> f_maxval; f.get(); if( (f_maxval > 0) || (f_maxval <= 65535) ) { x.set_size(3); Mat& R = x(0); Mat& G = x(1); Mat& B = x(2); R.set_size(f_n_rows,f_n_cols); G.set_size(f_n_rows,f_n_cols); B.set_size(f_n_rows,f_n_cols); if(f_maxval <= 255) { const uword n_elem = 3*f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(n_elem) ); uword i = 0; //cout << "f_n_cols = " << f_n_cols << endl; //cout << "f_n_rows = " << f_n_rows << endl; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { R.at(row,col) = eT(tmp[i+0]); G.at(row,col) = eT(tmp[i+1]); B.at(row,col) = eT(tmp[i+2]); i+=3; } } } else { const uword n_elem = 3*f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(2*n_elem) ); uword i = 0; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { R.at(row,col) = eT(tmp[i+0]); G.at(row,col) = eT(tmp[i+1]); B.at(row,col) = eT(tmp[i+2]); i+=3; } } } } else { load_okay = false; err_msg = "currently no code available to handle loading "; } if(f.good() == false) { load_okay = false; } } else { load_okay = false; err_msg = "unsupported header in "; } return load_okay; } template inline bool diskio::save_ppm_binary(const field& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_ppm_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } template inline bool diskio::save_ppm_binary(const field& x, std::ostream& f) { arma_extra_debug_sigprint(); arma_type_check(( is_Mat::value == false )); typedef typename T1::elem_type eT; arma_debug_check( (x.n_elem != 3), "diskio::save_ppm_binary(): given field must have exactly 3 matrices of equal size" ); bool same_size = true; for(uword i=1; i<3; ++i) { if( (x(0).n_rows != x(i).n_rows) || (x(0).n_cols != x(i).n_cols) ) { same_size = false; break; } } arma_debug_check( (same_size != true), "diskio::save_ppm_binary(): given field must have exactly 3 matrices of equal size" ); const Mat& R = x(0); const Mat& G = x(1); const Mat& B = x(2); f << "P6" << '\n'; f << R.n_cols << '\n'; f << R.n_rows << '\n'; f << 255 << '\n'; const uword n_elem = 3 * R.n_rows * R.n_cols; podarray tmp(n_elem); uword i = 0; for(uword row=0; row < R.n_rows; ++row) { for(uword col=0; col < R.n_cols; ++col) { tmp[i+0] = u8( access::tmp_real( R.at(row,col) ) ); tmp[i+1] = u8( access::tmp_real( G.at(row,col) ) ); tmp[i+2] = u8( access::tmp_real( B.at(row,col) ) ); i+=3; } } f.write( reinterpret_cast(tmp.mem), std::streamsize(n_elem) ); return f.good(); } //! @} RcppArmadillo/inst/include/armadillo_bits/SpOp_bones.hpp0000644000176000001440000000277612111344723023212 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpOp //! @{ template class SpOp : public SpBase > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = (T1::is_row && is_spop_elem::value) || ( T1::is_col && (is_same_type::value || is_same_type::value) ); static const bool is_col = (T1::is_col && is_spop_elem::value) || ( T1::is_row && (is_same_type::value || is_same_type::value) ); inline explicit SpOp(const T1& in_m); inline SpOp(const T1& in_m, const elem_type in_aux); inline SpOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline ~SpOp(); arma_aligned const T1& m; //!< storage of reference to the operand (eg. a matrix) arma_aligned elem_type aux; //!< storage of auxiliary data, user defined format arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_dotext_meat.hpp0000644000176000001440000000640312200631217024141 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_dotext //! @{ template inline eT op_dotext::direct_rowvec_mat_colvec ( const eT* A_mem, const Mat& B, const eT* C_mem ) { arma_extra_debug_sigprint(); const uword cost_AB = B.n_cols; const uword cost_BC = B.n_rows; if(cost_AB <= cost_BC) { podarray tmp(B.n_cols); for(uword col=0; col tmp(B.n_rows); for(uword row=0; row inline eT op_dotext::direct_rowvec_transmat_colvec ( const eT* A_mem, const Mat& B, const eT* C_mem ) { arma_extra_debug_sigprint(); const uword cost_AB = B.n_rows; const uword cost_BC = B.n_cols; if(cost_AB <= cost_BC) { podarray tmp(B.n_rows); for(uword row=0; row tmp(B.n_cols); for(uword col=0; col inline eT op_dotext::direct_rowvec_diagmat_colvec ( const eT* A_mem, const Mat& B, const eT* C_mem ) { arma_extra_debug_sigprint(); eT val = eT(0); for(uword i=0; i inline eT op_dotext::direct_rowvec_invdiagmat_colvec ( const eT* A_mem, const Mat& B, const eT* C_mem ) { arma_extra_debug_sigprint(); eT val = eT(0); for(uword i=0; i inline eT op_dotext::direct_rowvec_invdiagvec_colvec ( const eT* A_mem, const Mat& B, const eT* C_mem ) { arma_extra_debug_sigprint(); const eT* B_mem = B.mem; eT val = eT(0); for(uword i=0; i inline std::ostream& arma_stream_err1(std::ostream* user_stream) { static std::ostream* stream_err1 = &(ARMA_DEFAULT_OSTREAM); if(user_stream != NULL) { stream_err1 = user_stream; } return *stream_err1; } template inline std::ostream& arma_stream_err2(std::ostream* user_stream) { static std::ostream* stream_err2 = &(ARMA_DEFAULT_OSTREAM); if(user_stream != NULL) { stream_err2 = user_stream; } return *stream_err2; } inline void set_stream_err1(std::ostream& user_stream) { arma_stream_err1(&user_stream); } inline void set_stream_err2(std::ostream& user_stream) { arma_stream_err2(&user_stream); } inline std::ostream& get_stream_err1() { return arma_stream_err1(NULL); } inline std::ostream& get_stream_err2() { return arma_stream_err2(NULL); } // // arma_stop //! print a message to get_stream_err1() and/or throw a logic_error exception template arma_cold arma_noinline static void arma_stop(const T1& x) { #if defined(ARMA_PRINT_ERRORS) { std::ostream& out = get_stream_err1(); out.flush(); out << '\n'; out << "error: " << x << '\n'; out << '\n'; out.flush(); } #else { arma_ignore(x); } #endif throw std::logic_error( std::string(x) ); } template arma_cold arma_noinline static void arma_stop_bad_alloc(const T1& x) { #if defined(ARMA_PRINT_ERRORS) { std::ostream& out = get_stream_err2(); out.flush(); out << '\n'; out << "error: " << x << '\n'; out << '\n'; out.flush(); } #else { arma_ignore(x); } #endif throw std::bad_alloc(); } // // arma_bad //! print a message to get_stream_err2() and/or throw a run-time error exception template arma_cold arma_noinline static void arma_bad(const T1& x, const bool hurl = true) { #if defined(ARMA_PRINT_ERRORS) { std::ostream& out = get_stream_err2(); out.flush(); out << '\n'; out << "error: " << x << '\n'; out << '\n'; out.flush(); } #else { arma_ignore(x); } #endif if(hurl == true) { throw std::runtime_error( std::string(x) ); } } // // arma_print arma_cold inline void arma_print() { get_stream_err1() << std::endl; } template arma_cold arma_noinline static void arma_print(const T1& x) { get_stream_err1() << x << std::endl; } template arma_cold arma_noinline static void arma_print(const T1& x, const T2& y) { get_stream_err1() << x << y << std::endl; } template arma_cold arma_noinline static void arma_print(const T1& x, const T2& y, const T3& z) { get_stream_err1() << x << y << z << std::endl; } // // arma_sigprint //! print a message the the log stream with a preceding @ character. //! by default the log stream is cout. //! used for printing the signature of a function //! (see the arma_extra_debug_sigprint macro) inline void arma_sigprint(const char* x) { get_stream_err1() << "@ " << x; } // // arma_bktprint inline void arma_bktprint() { get_stream_err1() << std::endl; } template inline void arma_bktprint(const T1& x) { get_stream_err1() << " [" << x << ']' << std::endl; } template inline void arma_bktprint(const T1& x, const T2& y) { get_stream_err1() << " [" << x << y << ']' << std::endl; } // // arma_thisprint inline void arma_thisprint(const void* this_ptr) { get_stream_err1() << " [this = " << this_ptr << ']' << std::endl; } // // arma_warn //! print a message to the warn stream template arma_cold arma_noinline static void arma_warn(const bool state, const T1& x) { if(state==true) { get_stream_err2() << x << std::endl; } } template arma_cold arma_noinline static void arma_warn(const bool state, const T1& x, const T2& y) { if(state==true) { get_stream_err2() << x << y << std::endl; } } template arma_cold arma_noinline static void arma_warn(const bool state, const T1& x, const T2& y, const T3& z) { if(state==true) { get_stream_err2() << x << y << z << std::endl; } } // // arma_check //! if state is true, abort program template arma_hot inline void arma_check(const bool state, const T1& x) { if(state==true) { arma_stop(arma_boost::str_wrapper(x)); } } template arma_hot inline void arma_check(const bool state, const T1& x, const T2& y) { if(state==true) { arma_stop( std::string(x) + std::string(y) ); } } template arma_hot inline void arma_check_bad_alloc(const bool state, const T1& x) { if(state==true) { arma_stop_bad_alloc(x); } } // // arma_set_error arma_hot arma_inline void arma_set_error(bool& err_state, char*& err_msg, const bool expression, const char* message) { if(expression == true) { err_state = true; err_msg = const_cast(message); } } // // functions for generating strings indicating size errors arma_cold arma_noinline static std::string arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) { std::stringstream tmp; tmp << x << ": incompatible matrix dimensions: " << A_n_rows << 'x' << A_n_cols << " and " << B_n_rows << 'x' << B_n_cols; return tmp.str(); } arma_cold arma_noinline static std::string arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const uword A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_slices, const char* x) { std::stringstream tmp; tmp << x << ": incompatible cube dimensions: " << A_n_rows << 'x' << A_n_cols << 'x' << A_n_slices << " and " << B_n_rows << 'x' << B_n_cols << 'x' << B_n_slices; return tmp.str(); } template arma_cold arma_noinline static std::string arma_incompat_size_string(const subview_cube& Q, const Mat& A, const char* x) { std::stringstream tmp; tmp << x << ": interpreting matrix as cube with dimenensions: " << A.n_rows << 'x' << A.n_cols << 'x' << 1 << " or " << A.n_rows << 'x' << 1 << 'x' << A.n_cols << " or " << 1 << 'x' << A.n_rows << 'x' << A.n_cols << " is incompatible with cube dimensions: " << Q.n_rows << 'x' << Q.n_cols << 'x' << Q.n_slices; return tmp.str(); } // // functions for checking whether two matrices have the same dimensions arma_inline arma_hot void arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) { if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } //! stop if given matrices have different sizes template arma_hot inline void arma_assert_same_size(const Mat& A, const Mat& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } //! stop if given proxies have different sizes template arma_hot inline void arma_assert_same_size(const Proxy& A, const Proxy& B, const char* x) { const uword A_n_rows = A.get_n_rows(); const uword A_n_cols = A.get_n_cols(); const uword B_n_rows = B.get_n_rows(); const uword B_n_cols = B.get_n_cols(); if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const subview& A, const subview& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const Mat& A, const subview& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const subview& A, const Mat& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const Mat& A, const Proxy& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.get_n_rows(); const uword B_n_cols = B.get_n_cols(); if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const Proxy& A, const Mat& B, const char* x) { const uword A_n_rows = A.get_n_rows(); const uword A_n_cols = A.get_n_cols(); const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const Proxy& A, const subview& B, const char* x) { const uword A_n_rows = A.get_n_rows(); const uword A_n_cols = A.get_n_cols(); const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const subview& A, const Proxy& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.get_n_rows(); const uword B_n_cols = B.get_n_cols(); if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } // // functions for checking whether two cubes have the same dimensions arma_hot inline void arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uword A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_slices, const char* x) { if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_n_rows, B_n_cols, B_n_slices, x) ); } } //! stop if given cubes have different sizes template arma_hot inline void arma_assert_same_size(const Cube& A, const Cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); } } template arma_hot inline void arma_assert_same_size(const Cube& A, const subview_cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); } } template arma_hot inline void arma_assert_same_size(const subview_cube& A, const Cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); } } template arma_hot inline void arma_assert_same_size(const subview_cube& A, const subview_cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices)) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); } } //! stop if given cube proxies have different sizes template arma_hot inline void arma_assert_same_size(const ProxyCube& A, const ProxyCube& B, const char* x) { const uword A_n_rows = A.get_n_rows(); const uword A_n_cols = A.get_n_cols(); const uword A_n_slices = A.get_n_slices(); const uword B_n_rows = B.get_n_rows(); const uword B_n_cols = B.get_n_cols(); const uword B_n_slices = B.get_n_slices(); if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices)) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_n_rows, B_n_cols, B_n_slices, x) ); } } // // functions for checking whether a cube or subcube can be interpreted as a matrix (i.e. single slice) template arma_hot inline void arma_assert_same_size(const Cube& A, const Mat& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) ); } } template arma_hot inline void arma_assert_same_size(const Mat& A, const Cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) ); } } template arma_hot inline void arma_assert_same_size(const subview_cube& A, const Mat& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) ); } } template arma_hot inline void arma_assert_same_size(const Mat& A, const subview_cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) ); } } template inline void arma_assert_cube_as_mat(const Mat& M, const T1& Q, const char* x, const bool check_compat_size) { const uword Q_n_rows = Q.n_rows; const uword Q_n_cols = Q.n_cols; const uword Q_n_slices = Q.n_slices; const uword M_vec_state = M.vec_state; if(M_vec_state == 0) { if( ( (Q_n_rows == 1) || (Q_n_cols == 1) || (Q_n_slices == 1) ) == false ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a matrix; one of the dimensions must be 1"; arma_stop( tmp.str() ); } } else { if(Q_n_slices == 1) { if( (M_vec_state == 1) && (Q_n_cols != 1) ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a column vector"; arma_stop( tmp.str() ); } if( (M_vec_state == 2) && (Q_n_rows != 1) ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a row vector"; arma_stop( tmp.str() ); } } else { if( (Q_n_cols != 1) && (Q_n_rows != 1) ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a vector"; arma_stop( tmp.str() ); } } } if(check_compat_size == true) { const uword M_n_rows = M.n_rows; const uword M_n_cols = M.n_cols; if(M_vec_state == 0) { if( ( ( (Q_n_rows == M_n_rows) && (Q_n_cols == M_n_cols) ) || ( (Q_n_rows == M_n_rows) && (Q_n_slices == M_n_cols) ) || ( (Q_n_cols == M_n_rows) && (Q_n_slices == M_n_cols) ) ) == false ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimenensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a matrix with dimensions " << M_n_rows << 'x' << M_n_cols; arma_stop( tmp.str() ); } } else { if(Q_n_slices == 1) { if( (M_vec_state == 1) && (Q_n_rows != M_n_rows) ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a column vector with dimensions " << M_n_rows << 'x' << M_n_cols; arma_stop( tmp.str() ); } if( (M_vec_state == 2) && (Q_n_cols != M_n_cols) ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a row vector with dimensions " << M_n_rows << 'x' << M_n_cols; arma_stop( tmp.str() ); } } else { if( ( (M_n_cols == Q_n_slices) || (M_n_rows == Q_n_slices) ) == false ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a vector with dimensions " << M_n_rows << 'x' << M_n_cols; arma_stop( tmp.str() ); } } } } } // // functions for checking whether two matrices have dimensions that are compatible with the matrix multiply operation arma_hot inline void arma_assert_mul_size(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) { if(A_n_cols != B_n_rows) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } //! stop if given matrices are incompatible for multiplication template arma_hot inline void arma_assert_mul_size(const Mat& A, const Mat& B, const char* x) { const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; if(A_n_cols != B_n_rows) { arma_stop( arma_incompat_size_string(A.n_rows, A_n_cols, B_n_rows, B.n_cols, x) ); } } //! stop if given matrices are incompatible for multiplication template arma_hot inline void arma_assert_mul_size(const Mat& A, const Mat& B, const bool do_trans_A, const bool do_trans_B, const char* x) { const uword final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows; const uword final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols; if(final_A_n_cols != final_B_n_rows) { const uword final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols; const uword final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows; arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, final_B_n_rows, final_B_n_cols, x) ); } } template arma_hot inline void arma_assert_trans_mul_size(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) { const uword final_A_n_cols = (do_trans_A == false) ? A_n_cols : A_n_rows; const uword final_B_n_rows = (do_trans_B == false) ? B_n_rows : B_n_cols; if(final_A_n_cols != final_B_n_rows) { const uword final_A_n_rows = (do_trans_A == false) ? A_n_rows : A_n_cols; const uword final_B_n_cols = (do_trans_B == false) ? B_n_cols : B_n_rows; arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, final_B_n_rows, final_B_n_cols, x) ); } } template arma_hot inline void arma_assert_mul_size(const Mat& A, const subview& B, const char* x) { if(A.n_cols != B.n_rows) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); } } template arma_hot inline void arma_assert_mul_size(const subview& A, const Mat& B, const char* x) { if(A.n_cols != B.n_rows) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); } } template arma_hot inline void arma_assert_mul_size(const subview& A, const subview& B, const char* x) { if(A.n_cols != B.n_rows) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); } } // // macros // #define ARMA_STRING1(x) #x // #define ARMA_STRING2(x) ARMA_STRING1(x) // #define ARMA_FILELINE __FILE__ ": " ARMA_STRING2(__LINE__) #if defined(ARMA_NO_DEBUG) #undef ARMA_EXTRA_DEBUG #define arma_debug_print true ? (void)0 : arma_print #define arma_debug_warn true ? (void)0 : arma_warn #define arma_debug_check true ? (void)0 : arma_check #define arma_debug_set_error true ? (void)0 : arma_set_error #define arma_debug_assert_same_size true ? (void)0 : arma_assert_same_size #define arma_debug_assert_mul_size true ? (void)0 : arma_assert_mul_size #define arma_debug_assert_trans_mul_size true ? (void)0 : arma_assert_trans_mul_size #define arma_debug_assert_cube_as_mat true ? (void)0 : arma_assert_cube_as_mat #else #define arma_debug_print arma_print #define arma_debug_warn arma_warn #define arma_debug_check arma_check #define arma_debug_set_error arma_set_error #define arma_debug_assert_same_size arma_assert_same_size #define arma_debug_assert_mul_size arma_assert_mul_size #define arma_debug_assert_trans_mul_size arma_assert_trans_mul_size #define arma_debug_assert_cube_as_mat arma_assert_cube_as_mat #endif #if defined(ARMA_EXTRA_DEBUG) #define arma_extra_debug_sigprint arma_sigprint(ARMA_FNSIG); arma_bktprint #define arma_extra_debug_sigprint_this arma_sigprint(ARMA_FNSIG); arma_thisprint #define arma_extra_debug_print arma_print #define arma_extra_debug_warn arma_warn #define arma_extra_debug_check arma_check #else #define arma_extra_debug_sigprint true ? (void)0 : arma_bktprint #define arma_extra_debug_sigprint_this true ? (void)0 : arma_thisprint #define arma_extra_debug_print true ? (void)0 : arma_print #define arma_extra_debug_warn true ? (void)0 : arma_warn #define arma_extra_debug_check true ? (void)0 : arma_check #endif #if defined(ARMA_EXTRA_DEBUG) namespace junk { class arma_first_extra_debug_message { public: inline arma_first_extra_debug_message() { union { unsigned short a; unsigned char b[sizeof(unsigned short)]; } endian_test; endian_test.a = 1; const bool little_endian = (endian_test.b[0] == 1); const char* nickname = ARMA_VERSION_NAME; std::ostream& out = get_stream_err1(); out << "@ ---" << '\n'; out << "@ Armadillo " << arma_version::major << '.' << arma_version::minor << '.' << arma_version::patch << " (" << nickname << ")\n"; out << "@ arma_config::use_wrapper = " << arma_config::use_wrapper << '\n'; out << "@ arma_config::use_cxx11 = " << arma_config::use_cxx11 << '\n'; out << "@ arma_config::lapack = " << arma_config::lapack << '\n'; out << "@ arma_config::blas = " << arma_config::blas << '\n'; out << "@ arma_config::arpack = " << arma_config::arpack << '\n'; out << "@ arma_config::atlas = " << arma_config::atlas << '\n'; out << "@ arma_config::hdf5 = " << arma_config::hdf5 << '\n'; out << "@ arma_config::good_comp = " << arma_config::good_comp << '\n'; out << "@ arma_config::extra_code = " << arma_config::extra_code << '\n'; out << "@ arma_config::mat_prealloc = " << arma_config::mat_prealloc << '\n'; out << "@ sizeof(void*) = " << sizeof(void*) << '\n'; out << "@ sizeof(uword) = " << sizeof(uword) << '\n'; out << "@ sizeof(int) = " << sizeof(int) << '\n'; out << "@ sizeof(long) = " << sizeof(long) << '\n'; out << "@ sizeof(blas_int) = " << sizeof(blas_int) << '\n'; out << "@ little_endian = " << little_endian << '\n'; out << "@ ---" << std::endl; } }; static arma_first_extra_debug_message arma_first_extra_debug_message_run; } #endif //! @} RcppArmadillo/inst/include/armadillo_bits/op_cx_scalar_bones.hpp0000644000176000001440000000654112200631217024754 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_cx_scalar //! @{ class op_cx_scalar_times { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_times>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_times>& X ); }; class op_cx_scalar_plus { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_plus>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_plus>& X ); }; class op_cx_scalar_minus_pre { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_minus_pre>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_minus_pre>& X ); }; class op_cx_scalar_minus_post { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_minus_post>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_minus_post>& X ); }; class op_cx_scalar_div_pre { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_div_pre>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_div_pre>& X ); }; class op_cx_scalar_div_post { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_div_post>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_div_post>& X ); }; //! @} RcppArmadillo/inst/include/armadillo_bits/subview_field_meat.hpp0000644000176000001440000001473412176655102025004 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup subview_field //! @{ template inline subview_field::~subview_field() { arma_extra_debug_sigprint(); } template arma_inline subview_field::subview_field ( const field& in_f, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols ) : f(in_f) , aux_row1(in_row1) , aux_col1(in_col1) , n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows*in_n_cols) { arma_extra_debug_sigprint(); } template inline void subview_field::operator= (const field& x) { arma_extra_debug_sigprint(); subview_field& t = *this; arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols), "incompatible field dimensions"); for(uword col=0; col inline void subview_field::operator= (const subview_field& x_in) { arma_extra_debug_sigprint(); const bool overlap = check_overlap(x_in); field* tmp_field = overlap ? new field(x_in.f) : 0; const subview_field* tmp_subview = overlap ? new subview_field(*tmp_field, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; const subview_field& x = overlap ? (*tmp_subview) : x_in; subview_field& t = *this; arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols), "incompatible field dimensions"); for(uword col=0; col arma_inline oT& subview_field::operator[](const uword i) { const uword in_col = i / n_rows; const uword in_row = i % n_rows; const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *((const_cast< field& >(f)).mem[index]); } template arma_inline const oT& subview_field::operator[](const uword i) const { const uword in_col = i / n_rows; const uword in_row = i % n_rows; const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *(f.mem[index]); } template arma_inline oT& subview_field::operator()(const uword i) { arma_debug_check( (i >= n_elem), "subview_field::operator(): index out of bounds"); const uword in_col = i / n_rows; const uword in_row = i % n_rows; const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *((const_cast< field& >(f)).mem[index]); } template arma_inline const oT& subview_field::operator()(const uword i) const { arma_debug_check( (i >= n_elem), "subview_field::operator(): index out of bounds"); const uword in_col = i / n_rows; const uword in_row = i % n_rows; const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *(f.mem[index]); } template arma_inline oT& subview_field::operator()(const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview_field::operator(): index out of bounds"); const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *((const_cast< field& >(f)).mem[index]); } template arma_inline const oT& subview_field::operator()(const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview_field::operator(): index out of bounds"); const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *(f.mem[index]); } template arma_inline oT& subview_field::at(const uword in_row, const uword in_col) { const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *((const_cast< field& >(f)).mem[index]); } template arma_inline const oT& subview_field::at(const uword in_row, const uword in_col) const { //arma_extra_debug_sigprint(); const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *(f.mem[index]); } template inline bool subview_field::check_overlap(const subview_field& x) const { const subview_field& t = *this; if(&t.f != &x.f) { return false; } else { if( (t.n_elem == 0) || (x.n_elem == 0) ) { return false; } else { const uword t_row_start = t.aux_row1; const uword t_row_end_p1 = t_row_start + t.n_rows; const uword t_col_start = t.aux_col1; const uword t_col_end_p1 = t_col_start + t.n_cols; const uword x_row_start = x.aux_row1; const uword x_row_end_p1 = x_row_start + x.n_rows; const uword x_col_start = x.aux_col1; const uword x_col_end_p1 = x_col_start + x.n_cols; const bool outside_rows = ( (x_row_start >= t_row_end_p1) || (t_row_start >= x_row_end_p1) ); const bool outside_cols = ( (x_col_start >= t_col_end_p1) || (t_col_start >= x_col_end_p1) ); return ( (outside_rows == false) && (outside_cols == false) ); } } } //! X = Y.subfield(...) template inline void subview_field::extract(field& actual_out, const subview_field& in) { arma_extra_debug_sigprint(); // const bool alias = (&actual_out == &in.f); field* tmp = (alias) ? new field : 0; field& out = (alias) ? (*tmp) : actual_out; // const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; out.set_size(n_rows, n_cols); arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols = %d in.m.n_rows = %d in.m.n_cols = %d") % out.n_rows % out.n_cols % in.f.n_rows % in.f.n_cols ); for(uword col = 0; col inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/constants.hpp0000644000176000001440000002372312176655102023161 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup constants //! @{ namespace priv { class Datum_helper { public: template static typename arma_real_only::result nan(typename arma_real_only::result* junk = 0) { arma_ignore(junk); if(std::numeric_limits::has_quiet_NaN == true) { return std::numeric_limits::quiet_NaN(); } else { return eT(0); } } template static typename arma_cx_only::result nan(typename arma_cx_only::result* junk = 0) { arma_ignore(junk); typedef typename get_pod_type::result T; return eT( Datum_helper::nan(), Datum_helper::nan() ); } template static typename arma_integral_only::result nan(typename arma_integral_only::result* junk = 0) { arma_ignore(junk); return eT(0); } template static typename arma_real_only::result inf(typename arma_real_only::result* junk = 0) { arma_ignore(junk); if(std::numeric_limits::has_infinity == true) { return std::numeric_limits::infinity(); } else { return std::numeric_limits::max(); } } template static typename arma_cx_only::result inf(typename arma_cx_only::result* junk = 0) { arma_ignore(junk); typedef typename get_pod_type::result T; return eT( Datum_helper::inf(), Datum_helper::inf() ); } template static typename arma_integral_only::result inf(typename arma_integral_only::result* junk = 0) { arma_ignore(junk); return std::numeric_limits::max(); } }; } //! various constants. //! Physical constants taken from NIST and WolframAlpha on 2009-06-23 //! http://physics.nist.gov/cuu/Constants //! http://www.wolframalpha.com //! See also http://en.wikipedia.org/wiki/Physical_constant template class Datum { public: static const eT pi; //!< ratio of any circle's circumference to its diameter static const eT e; //!< base of the natural logarithm static const eT euler; //!< Euler's constant, aka Euler-Mascheroni constant static const eT gratio; //!< golden ratio static const eT sqrt2; //!< square root of 2 static const eT eps; //!< the difference between 1 and the least value greater than 1 that is representable static const eT log_min; //!< log of the minimum representable value static const eT log_max; //!< log of the maximum representable value static const eT nan; //!< "not a number" static const eT inf; //!< infinity // static const eT m_u; //!< atomic mass constant (in kg) static const eT N_A; //!< Avogadro constant static const eT k; //!< Boltzmann constant (in joules per kelvin) static const eT k_evk; //!< Boltzmann constant (in eV/K) static const eT a_0; //!< Bohr radius (in meters) static const eT mu_B; //!< Bohr magneton static const eT Z_0; //!< characteristic impedance of vacuum (in ohms) static const eT G_0; //!< conductance quantum (in siemens) static const eT k_e; //!< Coulomb's constant (in meters per farad) static const eT eps_0; //!< electric constant (in farads per meter) static const eT m_e; //!< electron mass (in kg) static const eT eV; //!< electron volt (in joules) static const eT ec; //!< elementary charge (in coulombs) static const eT F; //!< Faraday constant (in coulombs) static const eT alpha; //!< fine-structure constant static const eT alpha_inv; //!< inverse fine-structure constant static const eT K_J; //!< Josephson constant static const eT mu_0; //!< magnetic constant (in henries per meter) static const eT phi_0; //!< magnetic flux quantum (in webers) static const eT R; //!< molar gas constant (in joules per mole kelvin) static const eT G; //!< Newtonian constant of gravitation (in newton square meters per kilogram squared) static const eT h; //!< Planck constant (in joule seconds) static const eT h_bar; //!< Planck constant over 2 pi, aka reduced Planck constant (in joule seconds) static const eT m_p; //!< proton mass (in kg) static const eT R_inf; //!< Rydberg constant (in reciprocal meters) static const eT c_0; //!< speed of light in vacuum (in meters per second) static const eT sigma; //!< Stefan-Boltzmann constant static const eT R_k; //!< von Klitzing constant (in ohms) static const eT b; //!< Wien wavelength displacement law constant }; // the long lengths of the constants are for future support of "long double" // and any smart compiler that does high-precision computation at compile-time template const eT Datum::pi = eT(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679); template const eT Datum::e = eT(2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274); template const eT Datum::euler = eT(0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495); template const eT Datum::gratio = eT(1.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374); template const eT Datum::sqrt2 = eT(1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727); template const eT Datum::eps = std::numeric_limits::epsilon(); template const eT Datum::log_min = std::log(std::numeric_limits::min()); template const eT Datum::log_max = std::log(std::numeric_limits::max()); template const eT Datum::nan = priv::Datum_helper::nan(); template const eT Datum::inf = priv::Datum_helper::inf(); template const eT Datum::m_u = eT(1.660538782e-27); template const eT Datum::N_A = eT(6.02214179e23); template const eT Datum::k = eT(1.3806504e-23); template const eT Datum::k_evk = eT(8.617343e-5); template const eT Datum::a_0 = eT(0.52917720859e-10); template const eT Datum::mu_B = eT(927.400915e-26); template const eT Datum::Z_0 = eT(3.76730313461771e-2); template const eT Datum::G_0 = eT(7.7480917004e-5); template const eT Datum::k_e = eT(8.9875517873681764e9); template const eT Datum::eps_0 = eT(8.85418781762039e-12); template const eT Datum::m_e = eT(9.10938215e-31); template const eT Datum::eV = eT(1.602176487e-19); template const eT Datum::ec = eT(1.602176487e-19); template const eT Datum::F = eT(96485.3399); template const eT Datum::alpha = eT(7.2973525376e-3); template const eT Datum::alpha_inv = eT(137.035999679); template const eT Datum::K_J = eT(483597.891e9); template const eT Datum::mu_0 = eT(1.25663706143592e-06); template const eT Datum::phi_0 = eT(2.067833667e-15); template const eT Datum::R = eT(8.314472); template const eT Datum::G = eT(6.67428e-11); template const eT Datum::h = eT(6.62606896e-34); template const eT Datum::h_bar = eT(1.054571628e-34); template const eT Datum::m_p = eT(1.672621637e-27); template const eT Datum::R_inf = eT(10973731.568527); template const eT Datum::c_0 = eT(299792458.0); template const eT Datum::sigma = eT(5.670400e-8); template const eT Datum::R_k = eT(25812.807557); template const eT Datum::b = eT(2.8977685e-3); typedef Datum fdatum; typedef Datum datum; namespace priv { template static arma_inline arma_hot typename arma_real_only::result most_neg(typename arma_real_only::result* junk = 0) { arma_ignore(junk); if(std::numeric_limits::has_infinity == true) { return -(std::numeric_limits::infinity()); } else { return -(std::numeric_limits::max()); } } template static arma_inline arma_hot typename arma_integral_only::result most_neg(typename arma_integral_only::result* junk = 0) { arma_ignore(junk); return std::numeric_limits::min(); } template static arma_inline arma_hot typename arma_real_only::result most_pos(typename arma_real_only::result* junk = 0) { arma_ignore(junk); if(std::numeric_limits::has_infinity == true) { return std::numeric_limits::infinity(); } else { return std::numeric_limits::max(); } } template static arma_inline arma_hot typename arma_integral_only::result most_pos(typename arma_integral_only::result* junk = 0) { arma_ignore(junk); return std::numeric_limits::max(); } } //! @} RcppArmadillo/inst/include/armadillo_bits/op_htrans_bones.hpp0000644000176000001440000000547012222720570024321 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_htrans //! @{ //! 'hermitian transpose' operation class op_htrans { public: template arma_hot arma_inline static void apply_mat_noalias(Mat& out, const Mat& A, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply_mat_noalias(Mat& out, const Mat& A, const typename arma_cx_only::result* junk = 0); // template arma_hot arma_inline static void apply_mat_inplace(Mat& out, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply_mat_inplace(Mat& out, const typename arma_cx_only::result* junk = 0); // template arma_hot arma_inline static void apply_mat(Mat& out, const Mat& A, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply_mat(Mat& out, const Mat& A, const typename arma_cx_only::result* junk = 0); // template arma_hot inline static void apply_proxy(Mat& out, const T1& X); // template arma_hot inline static void apply(Mat& out, const Op& in, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply(Mat& out, const Op& in, const typename arma_cx_only::result* junk = 0); // template arma_hot inline static void apply(Mat& out, const Op< Op, op_htrans>& in); }; class op_htrans2 { public: template arma_hot inline static void apply_noalias(Mat& out, const Mat& A, const eT val); template arma_hot inline static void apply(Mat& out, const Mat& A, const eT val); // template arma_hot inline static void apply_proxy(Mat& out, const T1& X, const typename T1::elem_type val); // template arma_hot inline static void apply(Mat& out, const Op& in, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply(Mat& out, const Op& in, const typename arma_cx_only::result* junk = 0); }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_prod_bones.hpp0000644000176000001440000000137512200631217023761 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_prod //! @{ //! Class for finding products of values in a matrix (e.g. along rows or columns) class op_prod { public: template inline static void apply(Mat& out, const Op& in); template inline static eT prod(const subview& S); template inline static typename T1::elem_type prod(const Base& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_sum_meat.hpp0000644000176000001440000000645512200631217023445 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_sum //! @{ //! \brief //! Immediate sum of elements of a matrix along a specified dimension (either rows or columns). //! The result is stored in a dense matrix that has either one column or one row. //! See the sum() function for more details. template arma_hot inline void op_sum::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "sum(): incorrect usage. dim must be 0 or 1"); const Proxy P(in.m); typedef typename Proxy::stored_type P_stored_type; const bool is_alias = P.is_alias(out); if( (is_Mat::value == true) || is_alias ) { const unwrap_check tmp(P.Q, is_alias); const typename unwrap_check::stored_type& X = tmp.M; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) // traverse across rows (i.e. find the sum in each column) { out.set_size(1, X_n_cols); eT* out_mem = out.memptr(); for(uword col=0; col < X_n_cols; ++col) { out_mem[col] = arrayops::accumulate( X.colptr(col), X_n_rows ); } } else // traverse across columns (i.e. find the sum in each row) { out.set_size(X_n_rows, 1); eT* out_mem = out.memptr(); for(uword row=0; row < X_n_rows; ++row) { eT val = eT(0); uword i,j; for(i=0, j=1; j < X_n_cols; i+=2, j+=2) { val += X.at(row,i); val += X.at(row,j); } if(i < X_n_cols) { val += X.at(row,i); } out_mem[row] = val; } } } else { const uword P_n_rows = P.get_n_rows(); const uword P_n_cols = P.get_n_cols(); if(dim == 0) // traverse across rows (i.e. find the sum in each column) { out.set_size(1, P_n_cols); eT* out_mem = out.memptr(); for(uword col=0; col < P_n_cols; ++col) { eT val = eT(0); uword i,j; for(i=0, j=1; j < P_n_rows; i+=2, j+=2) { val += P.at(i,col); val += P.at(j,col); } if(i < P_n_rows) { val += P.at(i,col); } out_mem[col] = val; } } else // traverse across columns (i.e. find the sum in each row) { out.set_size(P_n_rows, 1); eT* out_mem = out.memptr(); for(uword row=0; row < P_n_rows; ++row) { eT val = eT(0); uword i,j; for(i=0, j=1; j < P_n_cols; i+=2, j+=2) { val += P.at(row,i); val += P.at(row,j); } if(i < P_n_cols) { val += P.at(row,i); } out_mem[row] = val; } } } } //! @} RcppArmadillo/inst/include/armadillo_bits/arma_version.hpp0000644000176000001440000000177412265635471023642 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup arma_version //! @{ #define ARMA_VERSION_MAJOR 4 #define ARMA_VERSION_MINOR 000 #define ARMA_VERSION_PATCH 2 #define ARMA_VERSION_NAME "Feral Steamroller" struct arma_version { static const unsigned int major = ARMA_VERSION_MAJOR; static const unsigned int minor = ARMA_VERSION_MINOR; static const unsigned int patch = ARMA_VERSION_PATCH; static inline std::string as_string() { const char* nickname = ARMA_VERSION_NAME; std::stringstream ss; ss << arma_version::major << '.' << arma_version::minor << '.' << arma_version::patch << " (" << nickname << ')'; return ss.str(); } }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_chol_bones.hpp0000644000176000001440000000076012200631217023737 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_chol //! @{ class op_chol { public: template inline static void apply(Mat& out, const Op& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_numel.hpp0000644000176000001440000000232112221200405022716 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_numel //! @{ template inline typename enable_if2< is_arma_type::value, uword >::result numel(const T1& X) { arma_extra_debug_sigprint(); const Proxy P(X); return P.get_n_elem(); } template inline typename enable_if2< is_arma_cube_type::value, uword >::result numel(const T1& X) { arma_extra_debug_sigprint(); const ProxyCube P(X); return P.get_n_elem(); } template inline typename enable_if2< is_arma_sparse_type::value, uword >::result numel(const T1& X) { arma_extra_debug_sigprint(); const SpProxy P(X); return P.get_n_elem(); } template inline uword numel(const field& X) { arma_extra_debug_sigprint(); return X.n_elem; } template inline uword numel(const subview_field& X) { arma_extra_debug_sigprint(); return X.n_elem; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_trimat_bones.hpp0000644000176000001440000000211312200631217024304 0ustar ripleyusers// Copyright (C) 2010-2012 Conrad Sanderson // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) // Copyright (C) 2011 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_trimat //! @{ class op_trimat { public: template inline static void fill_zeros(Mat& A, const bool upper); // template inline static void apply(Mat& out, const Op& in); template inline static void apply(Mat& out, const Op, op_trimat>& in); // template inline static void apply_htrans(Mat& out, const Mat& A, const bool upper, const typename arma_not_cx::result* junk = 0); template inline static void apply_htrans(Mat& out, const Mat& A, const bool upper, const typename arma_cx_only::result* junk = 0); }; //! @} RcppArmadillo/inst/include/armadillo_bits/diagmat_proxy.hpp0000644000176000001440000003544312111344723024007 0ustar ripleyusers// Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2008-2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup diagmat_proxy //! @{ template class diagmat_proxy_default { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_default(const T1& X) : P ( X ) , P_is_vec( (resolves_to_vector::value) || (P.get_n_rows() == 1) || (P.get_n_cols() == 1) ) , P_is_col( T1::is_col || (P.get_n_cols() == 1) ) , n_elem ( P_is_vec ? P.get_n_elem() : (std::min)(P.get_n_elem(), P.get_n_rows()) ) { arma_extra_debug_sigprint(); arma_debug_check ( (P_is_vec == false) && (P.get_n_rows() != P.get_n_cols()), "diagmat(): only vectors and square matrices are accepted" ); } arma_inline elem_type operator[](const uword i) const { if(Proxy::prefer_at_accessor == false) { return P_is_vec ? P[i] : P.at(i,i); } else { if(P_is_vec) { return (P_is_col) ? P.at(i,0) : P.at(0,i); } else { return P.at(i,i); } } } arma_inline elem_type at(const uword row, const uword col) const { if(row == col) { if(Proxy::prefer_at_accessor == false) { return (P_is_vec) ? P[row] : P.at(row,row); } else { if(P_is_vec) { return (P_is_col) ? P.at(row,0) : P.at(0,row); } else { return P.at(row,row); } } } else { return elem_type(0); } } const Proxy P; const bool P_is_vec; const bool P_is_col; const uword n_elem; }; template class diagmat_proxy_fixed { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_fixed(const T1& X) : P(X) { arma_extra_debug_sigprint(); arma_debug_check ( (P_is_vec == false) && (T1::n_rows != T1::n_cols), "diagmat(): only vectors and square matrices are accepted" ); } arma_inline elem_type operator[](const uword i) const { return (P_is_vec) ? P[i] : P.at(i,i); } arma_inline elem_type at(const uword row, const uword col) const { if(row == col) { return (P_is_vec) ? P[row] : P.at(row,row); } else { return elem_type(0); } } const T1& P; static const bool P_is_vec = (T1::n_rows == 1) || (T1::n_cols == 1); static const uword n_elem = P_is_vec ? T1::n_elem : ( (T1::n_elem < T1::n_rows) ? T1::n_elem : T1::n_rows ); }; template struct diagmat_proxy_redirect {}; template struct diagmat_proxy_redirect { typedef diagmat_proxy_default result; }; template struct diagmat_proxy_redirect { typedef diagmat_proxy_fixed result; }; template class diagmat_proxy : public diagmat_proxy_redirect::value >::result { public: inline diagmat_proxy(const T1& X) : diagmat_proxy_redirect< T1, is_Mat_fixed::value >::result(X) { } }; template class diagmat_proxy< Mat > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy(const Mat& X) : P ( X ) , P_is_vec( (X.n_rows == 1) || (X.n_cols == 1) ) , n_elem ( P_is_vec ? X.n_elem : (std::min)(X.n_elem, X.n_rows) ) { arma_extra_debug_sigprint(); arma_debug_check ( (P_is_vec == false) && (P.n_rows != P.n_cols), "diagmat(): only vectors and square matrices are accepted" ); } arma_inline elem_type operator[] (const uword i) const { return P_is_vec ? P[i] : P.at(i,i); } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); } const Mat& P; const bool P_is_vec; const uword n_elem; }; template class diagmat_proxy< Row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy(const Row& X) : P(X) , n_elem(X.n_elem) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const Row& P; const uword n_elem; }; template class diagmat_proxy< Col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy(const Col& X) : P(X) , n_elem(X.n_elem) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const Col& P; const uword n_elem; }; template class diagmat_proxy< subview_row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy(const subview_row& X) : P(X) , n_elem(X.n_elem) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const subview_row& P; const uword n_elem; }; template class diagmat_proxy< subview_col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy(const subview_col& X) : P(X) , n_elem(X.n_elem) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const subview_col& P; const uword n_elem; }; // // // template class diagmat_proxy_check_default { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check_default(const T1& X, const Mat&) : P(X) , P_is_vec( (resolves_to_vector::value) || (P.n_rows == 1) || (P.n_cols == 1) ) , n_elem( P_is_vec ? P.n_elem : (std::min)(P.n_elem, P.n_rows) ) { arma_extra_debug_sigprint(); arma_debug_check ( (P_is_vec == false) && (P.n_rows != P.n_cols), "diagmat(): only vectors and square matrices are accepted" ); } arma_inline elem_type operator[] (const uword i) const { return P_is_vec ? P[i] : P.at(i,i); } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); } const Mat P; const bool P_is_vec; const uword n_elem; }; template class diagmat_proxy_check_fixed { public: typedef typename T1::elem_type eT; typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check_fixed(const T1& X, const Mat& out) : P( const_cast(X.memptr()), T1::n_rows, T1::n_cols, (&X == &out), false ) { arma_extra_debug_sigprint(); arma_debug_check ( (P_is_vec == false) && (T1::n_rows != T1::n_cols), "diagmat(): only vectors and square matrices are accepted" ); } arma_inline eT operator[] (const uword i) const { return P_is_vec ? P[i] : P.at(i,i); } arma_inline eT at (const uword row, const uword col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); } const Mat P; // TODO: why not just store X directly as T1& ? test with fixed size vectors and matrices static const bool P_is_vec = (T1::n_rows == 1) || (T1::n_cols == 1); static const uword n_elem = P_is_vec ? T1::n_elem : ( (T1::n_elem < T1::n_rows) ? T1::n_elem : T1::n_rows ); }; template struct diagmat_proxy_check_redirect {}; template struct diagmat_proxy_check_redirect { typedef diagmat_proxy_check_default result; }; template struct diagmat_proxy_check_redirect { typedef diagmat_proxy_check_fixed result; }; template class diagmat_proxy_check : public diagmat_proxy_check_redirect::value >::result { public: inline diagmat_proxy_check(const T1& X, const Mat& out) : diagmat_proxy_check_redirect< T1, is_Mat_fixed::value >::result(X, out) { } }; template class diagmat_proxy_check< Mat > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check(const Mat& X, const Mat& out) : P_local ( (&X == &out) ? new Mat(X) : 0 ) , P ( (&X == &out) ? (*P_local) : X ) , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) ) , n_elem ( P_is_vec ? P.n_elem : (std::min)(P.n_elem, P.n_rows) ) { arma_extra_debug_sigprint(); arma_debug_check ( (P_is_vec == false) && (P.n_rows != P.n_cols), "diagmat(): only vectors and square matrices are accepted" ); } inline ~diagmat_proxy_check() { if(P_local) { delete P_local; } } arma_inline elem_type operator[] (const uword i) const { return P_is_vec ? P[i] : P.at(i,i); } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); } const Mat* P_local; const Mat& P; const bool P_is_vec; const uword n_elem; }; template class diagmat_proxy_check< Row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check(const Row& X, const Mat& out) : P_local ( (&X == reinterpret_cast*>(&out)) ? new Row(X) : 0 ) , P ( (&X == reinterpret_cast*>(&out)) ? (*P_local) : X ) , n_elem (X.n_elem) { arma_extra_debug_sigprint(); } inline ~diagmat_proxy_check() { if(P_local) { delete P_local; } } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const Row* P_local; const Row& P; const uword n_elem; }; template class diagmat_proxy_check< Col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check(const Col& X, const Mat& out) : P_local ( (&X == reinterpret_cast*>(&out)) ? new Col(X) : 0 ) , P ( (&X == reinterpret_cast*>(&out)) ? (*P_local) : X ) , n_elem (X.n_elem) { arma_extra_debug_sigprint(); } inline ~diagmat_proxy_check() { if(P_local) { delete P_local; } } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const Col* P_local; const Col& P; const uword n_elem; }; template class diagmat_proxy_check< subview_row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check(const subview_row& X, const Mat&) : P ( X ) , n_elem ( X.n_elem ) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const Row P; const uword n_elem; }; template class diagmat_proxy_check< subview_col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check(const subview_col& X, const Mat& out) : P ( const_cast(X.colptr(0)), X.n_rows, (&(X.m) == &out), false ) , n_elem( X.n_elem ) //, X_ref ( X ) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const Col P; const uword n_elem; //const subview_col& X_ref; // prevents the compiler from potentially deleting X before we're done with it }; //! @} RcppArmadillo/inst/include/armadillo_bits/spop_htrans_meat.hpp0000644000176000001440000000440512111344723024500 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_htrans //! @{ template arma_hot inline void spop_htrans::apply(SpMat& out, const SpOp& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); spop_strans::apply_proxy(out, in.m); } template arma_hot inline void spop_htrans::apply(SpMat& out, const SpOp& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const SpProxy p(in.m); if(p.is_alias(out) == false) { out.set_size( p.get_n_cols(), p.get_n_rows() ); out.mem_resize(p.get_n_nonzero()); typename SpProxy::const_row_iterator_type it = p.begin_row(); while(it.pos() < p.get_n_nonzero()) { access::rw(out.values[it.pos()]) = std::conj(*it); access::rw(out.row_indices[it.pos()]) = it.col(); // transpose ++access::rw(out.col_ptrs[it.row() + 1]); ++it; } // Fix column pointers. const uword out_n_cols = out.n_cols; for(uword c = 1; c <= out_n_cols; ++c) { access::rw(out.col_ptrs[c]) += out.col_ptrs[c - 1]; } } else { SpMat result( p.get_n_cols(), p.get_n_rows() ); result.mem_resize(p.get_n_nonzero()); typename SpProxy::const_row_iterator_type it = p.begin_row(); while(it.pos() < p.get_n_nonzero()) { access::rw(result.values[it.pos()]) = std::conj(*it); access::rw(result.row_indices[it.pos()]) = it.col(); // transpose ++access::rw(result.col_ptrs[it.row() + 1]); ++it; } // Fix column pointers. const uword result_n_cols = result.n_cols; for(uword c = 1; c <= result_n_cols; ++c) { access::rw(result.col_ptrs[c]) += result.col_ptrs[c - 1]; } out.steal_mem(result); } } //! @} RcppArmadillo/inst/include/armadillo_bits/unwrap.hpp0000644000176000001440000015047112252261213022451 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup unwrap //! @{ template struct unwrap_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline unwrap_default(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap_fixed { typedef T1 stored_type; inline explicit unwrap_fixed(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const T1& M; }; template struct unwrap_redirect {}; template struct unwrap_redirect { typedef unwrap_default result; }; template struct unwrap_redirect { typedef unwrap_fixed result; }; template struct unwrap : public unwrap_redirect::value >::result { inline unwrap(const T1& A) : unwrap_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct unwrap< Mat > { typedef Mat stored_type; inline unwrap(const Mat& A) : M(A) { arma_extra_debug_sigprint(); } const Mat& M; }; template struct unwrap< Row > { typedef Row stored_type; inline unwrap(const Row& A) : M(A) { arma_extra_debug_sigprint(); } const Row& M; }; template struct unwrap< Col > { typedef Col stored_type; inline unwrap(const Col& A) : M(A) { arma_extra_debug_sigprint(); } const Col& M; }; template struct unwrap< mtGlue > { typedef Mat stored_type; inline unwrap(const mtGlue& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap< mtOp > { typedef Mat stored_type; inline unwrap(const mtOp& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; // // // template struct quasi_unwrap_default { typedef typename T1::elem_type eT; static const bool has_subview = false; inline quasi_unwrap_default(const T1& A) : M(A) { arma_extra_debug_sigprint(); } // NOTE: DO NOT DIRECTLY CHECK FOR ALIASING BY TAKING THE ADDRESS OF THE "M" OBJECT IN ANY quasi_unwrap CLASS !!! const Mat M; template arma_inline bool is_alias(const Mat&) const { return false; } }; template struct quasi_unwrap_fixed { typedef typename T1::elem_type eT; static const bool has_subview = false; inline explicit quasi_unwrap_fixed(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const Mat& M; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap_redirect {}; template struct quasi_unwrap_redirect { typedef quasi_unwrap_default result; }; template struct quasi_unwrap_redirect { typedef quasi_unwrap_fixed result; }; template struct quasi_unwrap : public quasi_unwrap_redirect::value >::result { typedef typename quasi_unwrap_redirect::value >::result quasi_unwrap_extra; static const bool has_subview = quasi_unwrap_extra::has_subview; inline quasi_unwrap(const T1& A) : quasi_unwrap_extra(A) { } using quasi_unwrap_extra::M; using quasi_unwrap_extra::is_alias; }; template struct quasi_unwrap< Mat > { static const bool has_subview = false; inline quasi_unwrap(const Mat& A) : M(A) { arma_extra_debug_sigprint(); } const Mat& M; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap< Row > { static const bool has_subview = false; inline quasi_unwrap(const Row& A) : M(A) { arma_extra_debug_sigprint(); } const Row& M; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap< Col > { static const bool has_subview = false; inline quasi_unwrap(const Col& A) : M(A) { arma_extra_debug_sigprint(); } const Col& M; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap< subview_col > { static const bool has_subview = true; inline quasi_unwrap(const subview_col& A) : M ( const_cast( A.colptr(0) ), A.n_rows, 1, false, false ) , src( A.m ) { arma_extra_debug_sigprint(); } const Mat M; const Mat& src; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&src) == void_ptr(&X)); } }; template struct quasi_unwrap< mtGlue > { static const bool has_subview = false; inline quasi_unwrap(const mtGlue& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; template arma_inline bool is_alias(const Mat&) const { return false; } }; template struct quasi_unwrap< mtOp > { static const bool has_subview = false; inline quasi_unwrap(const mtOp& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; template arma_inline bool is_alias(const Mat&) const { return false; } }; // // // template struct unwrap_check_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline unwrap_check_default(const T1& A, const Mat&) : M(A) { arma_extra_debug_sigprint(); } inline unwrap_check_default(const T1& A, const bool) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap_check_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline unwrap_check_fixed(const T1& A, const Mat& B) : M_local( (&A == &B) ? new T1(A) : 0 ) , M ( (&A == &B) ? *M_local : A ) { arma_extra_debug_sigprint(); } inline unwrap_check_fixed(const T1& A, const bool is_alias) : M_local( is_alias ? new T1(A) : 0 ) , M ( is_alias ? *M_local : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const T1* M_local; const T1& M; }; template struct unwrap_check_redirect {}; template struct unwrap_check_redirect { typedef unwrap_check_default result; }; template struct unwrap_check_redirect { typedef unwrap_check_fixed result; }; template struct unwrap_check : public unwrap_check_redirect::value >::result { inline unwrap_check(const T1& A, const Mat& B) : unwrap_check_redirect< T1, is_Mat_fixed::value >::result(A, B) { } inline unwrap_check(const T1& A, const bool is_alias) : unwrap_check_redirect< T1, is_Mat_fixed::value >::result(A, is_alias) { } }; template struct unwrap_check< Mat > { typedef Mat stored_type; inline unwrap_check(const Mat& A, const Mat& B) : M_local( (&A == &B) ? new Mat(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } unwrap_check(const Mat& A, const bool is_alias) : M_local( is_alias ? new Mat(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Mat* M_local; const Mat& M; }; template struct unwrap_check< Row > { typedef Row stored_type; inline unwrap_check(const Row& A, const Mat& B) : M_local( (&A == &B) ? new Row(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } unwrap_check(const Row& A, const bool is_alias) : M_local( is_alias ? new Row(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Row* M_local; const Row& M; }; template struct unwrap_check< Col > { typedef Col stored_type; inline unwrap_check(const Col& A, const Mat& B) : M_local( (&A == &B) ? new Col(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } unwrap_check(const Col& A, const bool is_alias) : M_local( is_alias ? new Col(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Col* M_local; const Col& M; }; // // // template struct unwrap_check_mixed { typedef typename T1::elem_type eT1; template inline unwrap_check_mixed(const T1& A, const Mat&) : M(A) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const T1& A, const bool) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap_check_mixed< Mat > { template inline unwrap_check_mixed(const Mat& A, const Mat& B) : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Mat(A) : 0 ) , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const Mat& A, const bool is_alias) : M_local( is_alias ? new Mat(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_mixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Mat* M_local; const Mat& M; }; template struct unwrap_check_mixed< Row > { template inline unwrap_check_mixed(const Row& A, const Mat& B) : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Row(A) : 0 ) , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const Row& A, const bool is_alias) : M_local( is_alias ? new Row(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_mixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Row* M_local; const Row& M; }; template struct unwrap_check_mixed< Col > { template inline unwrap_check_mixed(const Col& A, const Mat& B) : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Col(A) : 0 ) , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const Col& A, const bool is_alias) : M_local( is_alias ? new Col(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_mixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Col* M_local; const Col& M; }; // // // template struct partial_unwrap_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_default(const T1& A) : M(A) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const Mat M; }; template struct partial_unwrap_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_fixed(const T1& A) : M(A) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const T1& M; }; template struct partial_unwrap_redirect {}; template struct partial_unwrap_redirect { typedef partial_unwrap_default result; }; template struct partial_unwrap_redirect { typedef partial_unwrap_fixed result; }; template struct partial_unwrap : public partial_unwrap_redirect::value >::result { inline partial_unwrap(const T1& A) : partial_unwrap_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct partial_unwrap< Mat > { typedef Mat stored_type; inline partial_unwrap(const Mat& A) : M(A) { arma_extra_debug_sigprint(); } inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const Mat& M; }; template struct partial_unwrap< Row > { typedef Row stored_type; inline partial_unwrap(const Row& A) : M(A) { arma_extra_debug_sigprint(); } inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const Row& M; }; template struct partial_unwrap< Col > { typedef Col stored_type; inline partial_unwrap(const Col& A) : M(A) { arma_extra_debug_sigprint(); } inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap class is only used by as_scalar(), // NOTE: which doesn't need to check for aliasing (ie. it doesn't need to compare the address of M with another matrix) template struct partial_unwrap< subview_col > { typedef Col stored_type; inline partial_unwrap(const subview_col& A) : M ( const_cast( A.colptr(0) ), A.n_rows, false, false ) { arma_extra_debug_sigprint(); } inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const Col M; }; template struct partial_unwrap_htrans_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_htrans_default(const Op& A) : M(A.m) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const Mat M; }; template struct partial_unwrap_htrans_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_htrans_fixed(const Op& A) : M(A.m) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const T1& M; }; template struct partial_unwrap_htrans_redirect {}; template struct partial_unwrap_htrans_redirect { typedef partial_unwrap_htrans_default result; }; template struct partial_unwrap_htrans_redirect { typedef partial_unwrap_htrans_fixed result; }; template struct partial_unwrap< Op > : public partial_unwrap_htrans_redirect::value >::result { inline partial_unwrap(const Op& A) : partial_unwrap_htrans_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct partial_unwrap< Op< Mat, op_htrans> > { typedef Mat stored_type; inline partial_unwrap(const Op< Mat, op_htrans>& A) : M(A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const Mat& M; }; template struct partial_unwrap< Op< Row, op_htrans> > { typedef Row stored_type; inline partial_unwrap(const Op< Row, op_htrans>& A) : M(A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const Row& M; }; template struct partial_unwrap< Op< Col, op_htrans> > { typedef Col stored_type; inline partial_unwrap(const Op< Col, op_htrans>& A) : M(A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap class is only used by as_scalar(), // NOTE: which doesn't need to check for aliasing (ie. it doesn't need to compare the address of M with another matrix) template struct partial_unwrap< Op< subview_col, op_htrans> > { typedef Col stored_type; inline partial_unwrap(const Op< subview_col, op_htrans>& A) : M ( const_cast( A.m.colptr(0) ), A.m.n_rows, false, false ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const Col M; }; template struct partial_unwrap_htrans2_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_htrans2_default(const Op& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_htrans2_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_htrans2_fixed(const Op& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const T1& M; }; template struct partial_unwrap_htrans2_redirect {}; template struct partial_unwrap_htrans2_redirect { typedef partial_unwrap_htrans2_default result; }; template struct partial_unwrap_htrans2_redirect { typedef partial_unwrap_htrans2_fixed result; }; template struct partial_unwrap< Op > : public partial_unwrap_htrans2_redirect::value >::result { inline partial_unwrap(const Op& A) : partial_unwrap_htrans2_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct partial_unwrap< Op< Mat, op_htrans2> > { typedef Mat stored_type; inline partial_unwrap(const Op< Mat, op_htrans2>& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const Mat& M; }; template struct partial_unwrap< Op< Row, op_htrans2> > { typedef Row stored_type; inline partial_unwrap(const Op< Row, op_htrans2>& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const Row& M; }; template struct partial_unwrap< Op< Col, op_htrans2> > { typedef Col stored_type; inline partial_unwrap(const Op< Col, op_htrans2>& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap class is only used by as_scalar(), // NOTE: which doesn't need to check for aliasing (ie. it doesn't need to compare the address of M with another matrix) template struct partial_unwrap< Op< subview_col, op_htrans2> > { typedef Col stored_type; inline partial_unwrap(const Op< subview_col, op_htrans2>& A) : val( A.aux ) , M ( const_cast( A.m.colptr(0) ), A.m.n_rows, false, false ) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const Col M; }; template struct partial_unwrap_scalar_times_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_scalar_times_default(const eOp& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_scalar_times_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_scalar_times_fixed(const eOp& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const T1& M; }; template struct partial_unwrap_scalar_times_redirect {}; template struct partial_unwrap_scalar_times_redirect { typedef partial_unwrap_scalar_times_default result; }; template struct partial_unwrap_scalar_times_redirect { typedef partial_unwrap_scalar_times_fixed result; }; template struct partial_unwrap< eOp > : public partial_unwrap_scalar_times_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap(const eOp& A) : partial_unwrap_scalar_times_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Mat stored_type; inline partial_unwrap(const eOp,eop_scalar_times>& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Mat& M; }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Row stored_type; inline partial_unwrap(const eOp,eop_scalar_times>& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Row& M; }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Col stored_type; inline partial_unwrap(const eOp,eop_scalar_times>& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Col& M; }; // TODO: struct partial_unwrap< eOp, eop_scalar_times> > template struct partial_unwrap_neg_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_neg_default(const eOp& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Mat M; }; template struct partial_unwrap_neg_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_neg_fixed(const eOp& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const T1& M; }; template struct partial_unwrap_neg_redirect {}; template struct partial_unwrap_neg_redirect { typedef partial_unwrap_neg_default result; }; template struct partial_unwrap_neg_redirect { typedef partial_unwrap_neg_fixed result; }; template struct partial_unwrap< eOp > : public partial_unwrap_neg_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap(const eOp& A) : partial_unwrap_neg_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct partial_unwrap< eOp, eop_neg> > { typedef Mat stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Mat& M; }; template struct partial_unwrap< eOp, eop_neg> > { typedef Row stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Row& M; }; template struct partial_unwrap< eOp, eop_neg> > { typedef Col stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Col& M; }; // TODO: struct partial_unwrap< eOp, eop_neg> > // template struct partial_unwrap_check_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_default(const T1& A, const Mat&) : M(A) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const Mat M; }; template struct partial_unwrap_check_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_fixed(const T1& A, const Mat& B) : M_local( (&A == &B) ? new T1(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_redirect {}; template struct partial_unwrap_check_redirect { typedef partial_unwrap_check_default result; }; template struct partial_unwrap_check_redirect { typedef partial_unwrap_check_fixed result; }; template struct partial_unwrap_check : public partial_unwrap_check_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const T1& A, const Mat& B) : partial_unwrap_check_redirect< T1, is_Mat_fixed::value >::result(A, B) { } }; template struct partial_unwrap_check< Mat > { typedef Mat stored_type; arma_hot inline partial_unwrap_check(const Mat& A, const Mat& B) : M_local ( (&A == &B) ? new Mat(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; // the order below is important const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< Row > { typedef Row stored_type; arma_hot inline partial_unwrap_check(const Row& A, const Mat& B) : M_local ( (&A == &B) ? new Row(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; // the order below is important const Row* M_local; const Row& M; }; template struct partial_unwrap_check< Col > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const Col& A, const Mat& B) : M_local ( (&A == &B) ? new Col(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; // the order below is important const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< subview_col > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const subview_col& A, const Mat& B) : M ( const_cast( A.colptr(0) ), A.n_rows, (&(A.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const Col M; }; template struct partial_unwrap_check_htrans_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_htrans_default(const Op& A, const Mat&) : M(A.m) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const Mat M; }; template struct partial_unwrap_check_htrans_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_htrans_fixed(const Op& A, const Mat& B) : M_local( (&(A.m) == &B) ? new T1(A.m) : 0 ) , M ( (&(A.m) == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_htrans_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_htrans_redirect {}; template struct partial_unwrap_check_htrans_redirect { typedef partial_unwrap_check_htrans_default result; }; template struct partial_unwrap_check_htrans_redirect { typedef partial_unwrap_check_htrans_fixed result; }; template struct partial_unwrap_check< Op > : public partial_unwrap_check_htrans_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const Op& A, const Mat& B) : partial_unwrap_check_htrans_redirect< T1, is_Mat_fixed::value >::result(A, B) { } }; template struct partial_unwrap_check< Op< Mat, op_htrans> > { typedef Mat stored_type; arma_hot inline partial_unwrap_check(const Op< Mat, op_htrans>& A, const Mat& B) : M_local ( (&A.m == &B) ? new Mat(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; // the order below is important const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< Op< Row, op_htrans> > { typedef Row stored_type; arma_hot inline partial_unwrap_check(const Op< Row, op_htrans>& A, const Mat& B) : M_local ( (&A.m == &B) ? new Row(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; // the order below is important const Row* M_local; const Row& M; }; template struct partial_unwrap_check< Op< Col, op_htrans> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const Op< Col, op_htrans>& A, const Mat& B) : M_local ( (&A.m == &B) ? new Col(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; // the order below is important const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< Op< subview_col, op_htrans> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const Op< subview_col, op_htrans>& A, const Mat& B) : M ( const_cast( A.m.colptr(0) ), A.m.n_rows, (&(A.m.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const Col M; }; template struct partial_unwrap_check_htrans2_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_htrans2_default(const Op& A, const Mat&) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_check_htrans2_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_htrans2_fixed(const Op& A, const Mat& B) : val (A.aux) , M_local( (&(A.m) == &B) ? new T1(A.m) : 0 ) , M ( (&(A.m) == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_htrans2_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_htrans2_redirect {}; template struct partial_unwrap_check_htrans2_redirect { typedef partial_unwrap_check_htrans2_default result; }; template struct partial_unwrap_check_htrans2_redirect { typedef partial_unwrap_check_htrans2_fixed result; }; template struct partial_unwrap_check< Op > : public partial_unwrap_check_htrans2_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const Op& A, const Mat& B) : partial_unwrap_check_htrans2_redirect< T1, is_Mat_fixed::value >::result(A, B) { } }; template struct partial_unwrap_check< Op< Mat, op_htrans2> > { typedef Mat stored_type; arma_hot inline partial_unwrap_check(const Op< Mat, op_htrans2>& A, const Mat& B) : val (A.aux) , M_local ( (&A.m == &B) ? new Mat(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; // the order below is important const eT val; const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< Op< Row, op_htrans2> > { typedef Row stored_type; arma_hot inline partial_unwrap_check(const Op< Row, op_htrans2>& A, const Mat& B) : val (A.aux) , M_local ( (&A.m == &B) ? new Row(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; // the order below is important const eT val; const Row* M_local; const Row& M; }; template struct partial_unwrap_check< Op< Col, op_htrans2> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const Op< Col, op_htrans2>& A, const Mat& B) : val (A.aux) , M_local ( (&A.m == &B) ? new Col(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; // the order below is important const eT val; const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< Op< subview_col, op_htrans2> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const Op< subview_col, op_htrans2>& A, const Mat& B) : val( A.aux ) , M ( const_cast( A.m.colptr(0) ), A.m.n_rows, (&(A.m.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const Col M; }; template struct partial_unwrap_check_scalar_times_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_scalar_times_default(const eOp& A, const Mat&) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_check_scalar_times_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_scalar_times_fixed(const eOp& A, const Mat& B) : val ( A.aux ) , M_local( (&(A.P.Q) == &B) ? new T1(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? (*M_local) : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_scalar_times_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_scalar_times_redirect {}; template struct partial_unwrap_check_scalar_times_redirect { typedef partial_unwrap_check_scalar_times_default result; }; template struct partial_unwrap_check_scalar_times_redirect { typedef partial_unwrap_check_scalar_times_fixed result; }; template struct partial_unwrap_check< eOp > : public partial_unwrap_check_scalar_times_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const eOp& A, const Mat& B) : partial_unwrap_check_scalar_times_redirect< T1, is_Mat_fixed::value >::result(A, B) { } }; template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Mat stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val (A.aux) , M_local( (&(A.P.Q) == &B) ? new Mat(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Row stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val(A.aux) , M_local( (&(A.P.Q) == &B) ? new Row(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Row* M_local; const Row& M; }; template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val ( A.aux ) , M_local( (&(A.P.Q) == &B) ? new Col(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val( A.aux ) , M ( const_cast( A.P.Q.colptr(0) ), A.P.Q.n_rows, (&(A.P.Q.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Col M; }; template struct partial_unwrap_check_neg_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_neg_default(const eOp& A, const Mat&) : M(A.P.Q) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Mat M; }; template struct partial_unwrap_check_neg_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_neg_fixed(const eOp& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new T1(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? (*M_local) : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_neg_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_neg_redirect {}; template struct partial_unwrap_check_neg_redirect { typedef partial_unwrap_check_neg_default result; }; template struct partial_unwrap_check_neg_redirect { typedef partial_unwrap_check_neg_fixed result; }; template struct partial_unwrap_check< eOp > : public partial_unwrap_check_neg_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const eOp& A, const Mat& B) : partial_unwrap_check_neg_redirect< T1, is_Mat_fixed::value >::result(A, B) { } }; template struct partial_unwrap_check< eOp, eop_neg> > { typedef Mat stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new Mat(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< eOp, eop_neg> > { typedef Row stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new Row(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Row* M_local; const Row& M; }; template struct partial_unwrap_check< eOp, eop_neg> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new Col(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< eOp, eop_neg> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M ( const_cast( A.P.Q.colptr(0) ), A.P.Q.n_rows, (&(A.P.Q.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Col M; }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_strans_meat.hpp0000644000176000001440000003740412225211761024156 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_strans //! @{ //! for tiny square matrices (size <= 4x4) template arma_hot inline void op_strans::apply_mat_noalias_tinysq(Mat& out, const TA& A) { const eT* Am = A.memptr(); eT* outm = out.memptr(); switch(A.n_rows) { case 1: { outm[0] = Am[0]; } break; case 2: { outm[pos::n2] = Am[pos::n2]; outm[pos::n2] = Am[pos::n2]; outm[pos::n2] = Am[pos::n2]; outm[pos::n2] = Am[pos::n2]; } break; case 3: { outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; } break; case 4: { outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; } break; default: ; } } //! Immediate transpose of a dense matrix template arma_hot inline void op_strans::apply_mat_noalias(Mat& out, const TA& A) { arma_extra_debug_sigprint(); const uword A_n_cols = A.n_cols; const uword A_n_rows = A.n_rows; out.set_size(A_n_cols, A_n_rows); if( (TA::is_row) || (TA::is_col) || (A_n_cols == 1) || (A_n_rows == 1) ) { arrayops::copy( out.memptr(), A.memptr(), A.n_elem ); } else { if( (A_n_rows <= 4) && (A_n_rows == A_n_cols) ) { op_strans::apply_mat_noalias_tinysq(out, A); } else { for(uword k=0; k < A_n_cols; ++k) { uword i, j; const eT* colptr = A.colptr(k); for(i=0, j=1; j < A_n_rows; i+=2, j+=2) { const eT tmp_i = colptr[i]; const eT tmp_j = colptr[j]; out.at(k, i) = tmp_i; out.at(k, j) = tmp_j; } if(i < A_n_rows) { out.at(k, i) = colptr[i]; } } } } } template arma_hot inline void op_strans::apply_mat_inplace(Mat& out) { arma_extra_debug_sigprint(); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; if(n_rows == n_cols) { arma_extra_debug_print("op_strans::apply(): doing in-place transpose of a square matrix"); const uword N = n_rows; for(uword k=0; k < N; ++k) { eT* colptr = out.colptr(k); uword i,j; for(i=(k+1), j=(k+2); j < N; i+=2, j+=2) { std::swap(out.at(k,i), colptr[i]); std::swap(out.at(k,j), colptr[j]); } if(i < N) { std::swap(out.at(k,i), colptr[i]); } } } else { Mat tmp; op_strans::apply_mat_noalias(tmp, out); out.steal_mem(tmp); } } template arma_hot inline void op_strans::apply_mat(Mat& out, const TA& A) { arma_extra_debug_sigprint(); if(&out != &A) { op_strans::apply_mat_noalias(out, A); } else { op_strans::apply_mat_inplace(out); } } template arma_hot inline void op_strans::apply_proxy(Mat& out, const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X); // allow detection of in-place transpose if( (is_Mat::stored_type>::value == true) && (Proxy::fake_mat == false) ) { const unwrap::stored_type> tmp(P.Q); op_strans::apply_mat(out, tmp.M); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const bool is_alias = P.is_alias(out); if( (resolves_to_vector::value == true) && (Proxy::prefer_at_accessor == false) ) { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* out_mem = out.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { const eT tmp_i = Pea[i]; const eT tmp_j = Pea[j]; out_mem[i] = tmp_i; out_mem[j] = tmp_j; } if(i < n_elem) { out_mem[i] = Pea[i]; } } else // aliasing { Mat out2(n_cols, n_rows); eT* out_mem = out2.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { const eT tmp_i = Pea[i]; const eT tmp_j = Pea[j]; out_mem[i] = tmp_i; out_mem[j] = tmp_j; } if(i < n_elem) { out_mem[i] = Pea[i]; } out.steal_mem(out2); } } else // general matrix transpose { if(is_alias == false) { out.set_size(n_cols, n_rows); for(uword k=0; k < n_cols; ++k) { uword i, j; for(i=0, j=1; j < n_rows; i+=2, j+=2) { const eT tmp_i = P.at(i,k); const eT tmp_j = P.at(j,k); out.at(k,i) = tmp_i; out.at(k,j) = tmp_j; } if(i < n_rows) { out.at(k,i) = P.at(i,k); } } } else // aliasing { Mat out2(n_cols, n_rows); for(uword k=0; k < n_cols; ++k) { uword i, j; for(i=0, j=1; j < n_rows; i+=2, j+=2) { const eT tmp_i = P.at(i,k); const eT tmp_j = P.at(j,k); out2.at(k,i) = tmp_i; out2.at(k,j) = tmp_j; } if(i < n_rows) { out2.at(k,i) = P.at(i,k); } } out.steal_mem(out2); } } } } template arma_hot inline void op_strans::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); op_strans::apply_proxy(out, in.m); } // // op_strans2 //! for tiny square matrices (size <= 4x4) template arma_hot inline void op_strans2::apply_noalias_tinysq(Mat& out, const TA& A, const eT val) { const eT* Am = A.memptr(); eT* outm = out.memptr(); switch(A.n_rows) { case 1: { outm[0] = val * Am[0]; } break; case 2: { outm[pos::n2] = val * Am[pos::n2]; outm[pos::n2] = val * Am[pos::n2]; outm[pos::n2] = val * Am[pos::n2]; outm[pos::n2] = val * Am[pos::n2]; } break; case 3: { outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; } break; case 4: { outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; } break; default: ; } } template arma_hot inline void op_strans2::apply_noalias(Mat& out, const TA& A, const eT val) { arma_extra_debug_sigprint(); const uword A_n_cols = A.n_cols; const uword A_n_rows = A.n_rows; out.set_size(A_n_cols, A_n_rows); if( (TA::is_col) || (TA::is_row) || (A_n_cols == 1) || (A_n_rows == 1) ) { const uword N = A.n_elem; const eT* A_mem = A.memptr(); eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < N; i+=2, j+=2) { const eT tmp_i = A_mem[i]; const eT tmp_j = A_mem[j]; out_mem[i] = val * tmp_i; out_mem[j] = val * tmp_j; } if(i < N) { out_mem[i] = val * A_mem[i]; } } else { if( (A_n_rows <= 4) && (A_n_rows == A_n_cols) ) { op_strans2::apply_noalias_tinysq(out, A, val); } else { for(uword k=0; k < A_n_cols; ++k) { uword i, j; const eT* colptr = A.colptr(k); for(i=0, j=1; j < A_n_rows; i+=2, j+=2) { const eT tmp_i = colptr[i]; const eT tmp_j = colptr[j]; out.at(k, i) = val * tmp_i; out.at(k, j) = val * tmp_j; } if(i < A_n_rows) { out.at(k, i) = val * colptr[i]; } } } } } template arma_hot inline void op_strans2::apply(Mat& out, const TA& A, const eT val) { arma_extra_debug_sigprint(); if(&out != &A) { op_strans2::apply_noalias(out, A, val); } else { const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; if(n_rows == n_cols) { arma_extra_debug_print("op_strans2::apply(): doing in-place transpose of a square matrix"); const uword N = n_rows; // TODO: do multiplication while swapping for(uword k=0; k < N; ++k) { eT* colptr = out.colptr(k); uword i,j; for(i=(k+1), j=(k+2); j < N; i+=2, j+=2) { std::swap(out.at(k,i), colptr[i]); std::swap(out.at(k,j), colptr[j]); } if(i < N) { std::swap(out.at(k,i), colptr[i]); } } arrayops::inplace_mul( out.memptr(), val, out.n_elem ); } else { Mat tmp; op_strans2::apply_noalias(tmp, A, val); out.steal_mem(tmp); } } } template arma_hot inline void op_strans2::apply_proxy(Mat& out, const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X); // allow detection of in-place transpose if( (is_Mat::stored_type>::value == true) && (Proxy::fake_mat == false) ) { const unwrap::stored_type> tmp(P.Q); op_strans2::apply(out, tmp.M, val); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const bool is_alias = P.is_alias(out); if( (resolves_to_vector::value == true) && (Proxy::prefer_at_accessor == false) ) { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* out_mem = out.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { const eT tmp_i = Pea[i]; const eT tmp_j = Pea[j]; out_mem[i] = val * tmp_i; out_mem[j] = val * tmp_j; } if(i < n_elem) { out_mem[i] = val * Pea[i]; } } else // aliasing { Mat out2(n_cols, n_rows); eT* out_mem = out2.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { const eT tmp_i = Pea[i]; const eT tmp_j = Pea[j]; out_mem[i] = val * tmp_i; out_mem[j] = val * tmp_j; } if(i < n_elem) { out_mem[i] = val * Pea[i]; } out.steal_mem(out2); } } else // general matrix transpose { if(is_alias == false) { out.set_size(n_cols, n_rows); for(uword k=0; k < n_cols; ++k) { uword i, j; for(i=0, j=1; j < n_rows; i+=2, j+=2) { const eT tmp_i = P.at(i,k); const eT tmp_j = P.at(j,k); out.at(k,i) = val * tmp_i; out.at(k,j) = val * tmp_j; } if(i < n_rows) { out.at(k,i) = val * P.at(i,k); } } } else // aliasing { Mat out2(n_cols, n_rows); for(uword k=0; k < n_cols; ++k) { uword i, j; for(i=0, j=1; j < n_rows; i+=2, j+=2) { const eT tmp_i = P.at(i,k); const eT tmp_j = P.at(j,k); out2.at(k,i) = val * tmp_i; out2.at(k,j) = val * tmp_j; } if(i < n_rows) { out2.at(k,i) = val * P.at(i,k); } } out.steal_mem(out2); } } } } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_repmat.hpp0000644000176000001440000000125212256562725023120 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_repmat //! @{ //! \brief //! delayed 'repeat matrix' construction of a matrix template arma_inline const Op repmat(const Base& A, const uword r, const uword c) { arma_extra_debug_sigprint(); return Op(A.get_ref(), r, c); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_misc_meat.hpp0000644000176000001440000001353112262045120023565 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_misc //! @{ template inline void op_real::apply( Mat& out, const mtOp& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const Proxy P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); out.set_size(n_rows, n_cols); T* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::real( A[i] ); } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { *out_mem = std::real( P.at(row,col) ); out_mem++; } } } template inline void op_real::apply( Cube& out, const mtOpCube& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const ProxyCube P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_slices = P.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); T* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::real( A[i] ); } } else { for(uword slice=0; slice < n_slices; ++slice) for(uword col=0; col < n_cols; ++col ) for(uword row=0; row < n_rows; ++row ) { *out_mem = std::real( P.at(row,col,slice) ); out_mem++; } } } template inline void op_imag::apply( Mat& out, const mtOp& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const Proxy P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); out.set_size(n_rows, n_cols); T* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::imag( A[i] ); } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { *out_mem = std::imag( P.at(row,col) ); out_mem++; } } } template inline void op_imag::apply( Cube& out, const mtOpCube& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const ProxyCube P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_slices = P.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); T* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::imag( A[i] ); } } else { for(uword slice=0; slice < n_slices; ++slice) for(uword col=0; col < n_cols; ++col ) for(uword row=0; row < n_rows; ++row ) { *out_mem = std::imag( P.at(row,col,slice) ); out_mem++; } } } template inline void op_abs::apply( Mat& out, const mtOp& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const Proxy P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); out.set_size(n_rows, n_cols); T* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::abs( A[i] ); } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { *out_mem = std::abs( P.at(row,col) ); out_mem++; } } } template inline void op_abs::apply( Cube& out, const mtOpCube& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const ProxyCube P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_slices = P.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); T* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::abs( A[i] ); } } else { for(uword slice=0; slice < n_slices; ++slice) for(uword col=0; col < n_cols; ++col ) for(uword row=0; row < n_rows; ++row ) { *out_mem = std::abs( P.at(row,col,slice) ); out_mem++; } } } //! @} RcppArmadillo/inst/include/armadillo_bits/op_strans_bones.hpp0000644000176000001440000000477612222720570024344 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_strans //! @{ //! 'matrix transpose' operation (simple transpose, ie. without taking the conjugate of the elements) class op_strans { public: template struct pos { static const uword n2 = (do_flip == false) ? (row + col*2) : (col + row*2); static const uword n3 = (do_flip == false) ? (row + col*3) : (col + row*3); static const uword n4 = (do_flip == false) ? (row + col*4) : (col + row*4); }; template arma_hot inline static void apply_mat_noalias_tinysq(Mat& out, const TA& A); template arma_hot inline static void apply_mat_noalias(Mat& out, const TA& A); template arma_hot inline static void apply_mat_inplace(Mat& out); template arma_hot inline static void apply_mat(Mat& out, const TA& A); template arma_hot inline static void apply_proxy(Mat& out, const T1& X); template arma_hot inline static void apply(Mat& out, const Op& in); }; class op_strans2 { public: template struct pos { static const uword n2 = (do_flip == false) ? (row + col*2) : (col + row*2); static const uword n3 = (do_flip == false) ? (row + col*3) : (col + row*3); static const uword n4 = (do_flip == false) ? (row + col*4) : (col + row*4); }; template arma_hot inline static void apply_noalias_tinysq(Mat& out, const TA& A, const eT val); template arma_hot inline static void apply_noalias(Mat& out, const TA& A, const eT val); template arma_hot inline static void apply(Mat& out, const TA& A, const eT val); template arma_hot inline static void apply_proxy(Mat& out, const T1& X, const typename T1::elem_type val); // NOTE: there is no direct handling of Op, as op_strans2::apply_proxy() is currently only called by op_htrans2 for non-complex numbers }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_diagmat.hpp0000644000176000001440000000153412200375542023225 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_diagmat //! @{ //! interpret a matrix or a vector as a diagonal matrix (i.e. off-diagonal entries are zero) template arma_inline typename enable_if2 < is_arma_type::value, const Op >::result diagmat(const T1& X) { arma_extra_debug_sigprint(); return Op(X); } // TODO: // create "op_diagmat2", to allow placement of vector onto a sub- or super- diagonal. // op_diagmat2 is required, as other code assumes that op_diagmat indicates only the main diagonal) //! @} RcppArmadillo/inst/include/armadillo_bits/mtGlue_bones.hpp0000644000176000001440000000244512202101406023545 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup mtGlue //! @{ template class mtGlue : public Base > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = ( is_glue_mixed_elem::value && (T1::is_row || T2::is_row) ) || ( is_glue_mixed_times::value && T1::is_row ); static const bool is_col = ( is_glue_mixed_elem::value && (T1::is_col || T2::is_col) ) || ( is_glue_mixed_times::value && T2::is_col ); arma_inline mtGlue(const T1& in_A, const T2& in_B); arma_inline mtGlue(const T1& in_A, const T2& in_B, const uword in_aux_uword); arma_inline ~mtGlue(); arma_aligned const T1& A; //!< first operand arma_aligned const T2& B; //!< second operand arma_aligned uword aux_uword; //!< storage of auxiliary data, uword format }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_princomp_meat.hpp0000644000176000001440000003610412250111350024456 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // Copyright (C) 2010 Dimitrios Bouzas // Copyright (C) 2011 Stanislav Funiak // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_princomp //! @{ //! \brief //! principal component analysis -- 4 arguments version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors //! tsquared_out -> Hotelling's T^2 statistic template inline bool op_princomp::direct_princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, Col& tsquared_out, const Base& X, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); //Col s_tmp = zeros< Col >(n_cols); Col s_tmp(n_cols); s_tmp.zeros(); s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); s = s_tmp; // compute the Hotelling's T-squared s_tmp.rows(0,n_rows-2) = eT(1) / s_tmp.rows(0,n_rows-2); const Mat S = score_out * diagmat(Col(s_tmp)); tsquared_out = sum(S%S,1); } else { // compute the Hotelling's T-squared const Mat S = score_out * diagmat(Col( eT(1) / s)); tsquared_out = sum(S%S,1); } // compute the eigenvalues of the principal vectors latent_out = s%s; } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); latent_out.set_size(n_cols); latent_out.zeros(); tsquared_out.set_size(n_rows); tsquared_out.zeros(); } return true; } //! \brief //! principal component analysis -- 3 arguments version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors template inline bool op_princomp::direct_princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, const Base& X, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); Col s_tmp = zeros< Col >(n_cols); s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); s = s_tmp; } // compute the eigenvalues of the principal vectors latent_out = s%s; } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); latent_out.set_size(n_cols); latent_out.zeros(); } return true; } //! \brief //! principal component analysis -- 2 arguments version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples template inline bool op_princomp::direct_princomp ( Mat& coeff_out, Mat& score_out, const Base& X, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); Col s_tmp = zeros< Col >(n_cols); s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); s = s_tmp; } } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); } return true; } //! \brief //! principal component analysis -- 1 argument version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients template inline bool op_princomp::direct_princomp ( Mat& coeff_out, const Base& X, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap Y( X.get_ref() ); const Mat& in = Y.M; if(in.n_elem != 0) { Mat tmp = in; tmp.each_row() -= mean(in); // singular value decomposition Mat U; Col s; const bool svd_ok = svd(U, s, coeff_out, tmp); if(svd_ok == false) { return false; } } else { coeff_out.eye(in.n_cols, in.n_cols); } return true; } //! \brief //! principal component analysis -- 4 arguments complex version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors //! tsquared_out -> Hotelling's T^2 statistic template inline bool op_princomp::direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, Col< typename T1::pod_type >& latent_out, Col< std::complex >& tsquared_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; typedef std::complex eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col< T> s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); Col s_tmp = zeros< Col >(n_cols); s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); s = s_tmp; // compute the Hotelling's T-squared s_tmp.rows(0,n_rows-2) = 1.0 / s_tmp.rows(0,n_rows-2); const Mat S = score_out * diagmat(Col(s_tmp)); tsquared_out = sum(S%S,1); } else { // compute the Hotelling's T-squared const Mat S = score_out * diagmat(Col(T(1) / s)); tsquared_out = sum(S%S,1); } // compute the eigenvalues of the principal vectors latent_out = s%s; } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); latent_out.set_size(n_cols); latent_out.zeros(); tsquared_out.set_size(n_rows); tsquared_out.zeros(); } return true; } //! \brief //! principal component analysis -- 3 arguments complex version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors template inline bool op_princomp::direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, Col< typename T1::pod_type >& latent_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; typedef std::complex eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col< T> s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); Col s_tmp = zeros< Col >(n_cols); s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); s = s_tmp; } // compute the eigenvalues of the principal vectors latent_out = s%s; } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); latent_out.set_size(n_cols); latent_out.zeros(); } return true; } //! \brief //! principal component analysis -- 2 arguments complex version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples template inline bool op_princomp::direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; typedef std::complex eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col< T> s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); } } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); } return true; } //! \brief //! principal component analysis -- 1 argument complex version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients template inline bool op_princomp::direct_princomp ( Mat< std::complex >& coeff_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; typedef std::complex eT; const unwrap Y( X.get_ref() ); const Mat& in = Y.M; if(in.n_elem != 0) { // singular value decomposition Mat U; Col< T> s; Mat tmp = in; tmp.each_row() -= mean(in); const bool svd_ok = svd(U, s, coeff_out, tmp); if(svd_ok == false) { return false; } } else { coeff_out.eye(in.n_cols, in.n_cols); } return true; } template inline void op_princomp::apply ( Mat& out, const Op& in ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& A = tmp.M; const bool status = op_princomp::direct_princomp(out, A); if(status == false) { out.reset(); arma_bad("princomp(): failed to converge"); } } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_cross_bones.hpp0000644000176000001440000000077612200375542024476 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_cross //! @{ class glue_cross { public: template inline static void apply(Mat& out, const Glue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/mtSpOp_bones.hpp0000644000176000001440000000210212111344723023532 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup mtSpOp //! @{ // Class for delayed multi-type sparse operations. These are operations where // the resulting type is different than the stored type. template class mtSpOp : public SpBase > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef typename T1::elem_type in_eT; static const bool is_row = false; static const bool is_col = false; inline explicit mtSpOp(const T1& in_m); inline mtSpOp(const T1& in_m, const uword aux_uword_a, const uword aux_uword_b); inline ~mtSpOp(); arma_aligned const T1& m; arma_aligned uword aux_uword_a; arma_aligned uword aux_uword_b; }; //! @} RcppArmadillo/inst/include/armadillo_bits/SizeCube_meat.hpp0000644000176000001440000000326412247362764023672 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SizeCube //! @{ inline SizeCube::SizeCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) : n_rows (in_n_rows ) , n_cols (in_n_cols ) , n_slices(in_n_slices) { arma_extra_debug_sigprint(); } // inline // SizeCube::operator SizeMat () const // { // arma_debug_check( (n_slices != 1), "SizeCube: n_slices != 1, hence cube size cannot be interpreted as matrix size" ); // // return SizeMat(n_rows, n_cols); // } inline bool SizeCube::operator==(const SizeCube& s) const { if(n_rows != s.n_rows ) { return false; } if(n_cols != s.n_cols ) { return false; } if(n_slices != s.n_slices) { return false; } return true; } inline bool SizeCube::operator!=(const SizeCube& s) const { if(n_rows != s.n_rows ) { return true; } if(n_cols != s.n_cols ) { return true; } if(n_slices != s.n_slices) { return true; } return false; } inline bool SizeCube::operator==(const SizeMat& s) const { if(n_rows != s.n_rows) { return false; } if(n_cols != s.n_cols) { return false; } if(n_slices != uword(1)) { return false; } return true; } inline bool SizeCube::operator!=(const SizeMat& s) const { if(n_rows != s.n_rows) { return true; } if(n_cols != s.n_cols) { return true; } if(n_slices != uword(1)) { return true; } return false; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_vectorise_meat.hpp0000644000176000001440000001032212256607540024645 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_vectorise //! @{ template inline void op_vectorise_col::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); const Proxy P(in.m); op_vectorise_col::apply_proxy(out, P); } template inline void op_vectorise_col::apply_proxy(Mat& out, const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; if(P.is_alias(out) == false) { const uword N = P.get_n_elem(); out.set_size(N, 1); if(is_Mat::stored_type>::value == true) { const unwrap::stored_type> tmp(P.Q); arrayops::copy(out.memptr(), tmp.M.memptr(), N); } else { eT* outmem = out.memptr(); if(Proxy::prefer_at_accessor == false) { // TODO: add handling of aligned access ? typename Proxy::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j < N; i+=2, j+=2) { const eT tmp_i = A[i]; const eT tmp_j = A[j]; outmem[i] = tmp_i; outmem[j] = tmp_j; } if(i < N) { outmem[i] = A[i]; } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { for(uword i=0; i < n_cols; ++i) { outmem[i] = P.at(0,i); } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { *outmem = P.at(row,col); outmem++; } } } } } else // we have aliasing { arma_extra_debug_print("op_vectorise_col::apply(): aliasing detected"); if( (is_Mat::stored_type>::value == true) && (Proxy::fake_mat == false) ) { out.set_size(out.n_elem, 1); // set_size() doesn't destroy data as long as the number of elements in the matrix remains the same } else { Mat tmp; op_vectorise_col::apply_proxy(tmp, P); out.steal_mem(tmp); } } } template inline void op_vectorise_row::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); const Proxy P(in.m); op_vectorise_row::apply_proxy(out, P); } template inline void op_vectorise_row::apply_proxy(Mat& out, const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; if(P.is_alias(out) == false) { out.set_size( 1, P.get_n_elem() ); eT* outmem = out.memptr(); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); for(uword row=0; row < n_rows; ++row) { uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp_i = P.at(row,i); const eT tmp_j = P.at(row,j); *outmem = tmp_i; outmem++; *outmem = tmp_j; outmem++; } if(i < n_cols) { *outmem = P.at(row,i); outmem++; } } } else // we have aliasing { arma_extra_debug_print("op_vectorise_row::apply(): aliasing detected"); Mat tmp; op_vectorise_row::apply_proxy(tmp, P); out.steal_mem(tmp); } } template inline void op_vectorise_all::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); const Proxy P(in.m); const uword dim = in.aux_uword_a; if(dim == 0) { op_vectorise_col::apply_proxy(out, P); } else { op_vectorise_row::apply_proxy(out, P); } } //! @} RcppArmadillo/inst/include/armadillo_bits/Glue_meat.hpp0000644000176000001440000000161312176655102023041 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Glue //! @{ template inline Glue::Glue(const T1& in_A, const T2& in_B) : A(in_A) , B(in_B) { arma_extra_debug_sigprint(); } template inline Glue::Glue(const T1& in_A, const T2& in_B, const uword in_aux_uword) : A(in_A) , B(in_B) , aux_uword(in_aux_uword) { arma_extra_debug_sigprint(); } template inline Glue::~Glue() { arma_extra_debug_sigprint(); } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_join_bones.hpp0000644000176000001440000000143412220540177024274 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_join //! @{ class glue_join { public: template inline static void apply(Mat& out, const Glue& X); template inline static void apply_noalias(Mat& out, const Mat& A, const Mat& B, const uword join_type); template inline static void apply(Cube& out, const GlueCube& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_reshape_meat.hpp0000644000176000001440000001250712176422451024275 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_reshape //! @{ template inline void op_reshape::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap A_tmp(in.m); const Mat& A = A_tmp.M; const bool is_alias = (&out == &A); const uword in_n_rows = in.aux_uword_a; const uword in_n_cols = in.aux_uword_b; const uword in_dim = in.aux_uword_c; const uword in_n_elem = in_n_rows * in_n_cols; if(A.n_elem == in_n_elem) { if(in_dim == 0) { if(is_alias == false) { out.set_size(in_n_rows, in_n_cols); arrayops::copy( out.memptr(), A.memptr(), out.n_elem ); } else // &out == &A, i.e. inplace resize { out.set_size(in_n_rows, in_n_cols); // set_size() doesn't destroy data as long as the number of elements in the matrix remains the same } } else { unwrap_check< Mat > B_tmp(A, is_alias); const Mat& B = B_tmp.M; out.set_size(in_n_rows, in_n_cols); eT* out_mem = out.memptr(); const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; for(uword row=0; row > B_tmp(A, is_alias); const Mat& B = B_tmp.M; const uword n_elem_to_copy = (std::min)(B.n_elem, in_n_elem); out.set_size(in_n_rows, in_n_cols); eT* out_mem = out.memptr(); if(in_dim == 0) { arrayops::copy( out_mem, B.memptr(), n_elem_to_copy ); } else { uword row = 0; uword col = 0; const uword B_n_cols = B.n_cols; for(uword i=0; i= B_n_cols) { col = 0; ++row; } } } for(uword i=n_elem_to_copy; i inline void op_reshape::apply(Cube& out, const OpCube& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube A_tmp(in.m); const Cube& A = A_tmp.M; const uword in_n_rows = in.aux_uword_a; const uword in_n_cols = in.aux_uword_b; const uword in_n_slices = in.aux_uword_c; const uword in_dim = in.aux_uword_d; const uword in_n_elem = in_n_rows * in_n_cols * in_n_slices; if(A.n_elem == in_n_elem) { if(in_dim == 0) { if(&out != &A) { out.set_size(in_n_rows, in_n_cols, in_n_slices); arrayops::copy( out.memptr(), A.memptr(), out.n_elem ); } else // &out == &A, i.e. inplace resize { out.set_size(in_n_rows, in_n_cols, in_n_slices); // set_size() doesn't destroy data as long as the number of elements in the cube remains the same } } else { unwrap_cube_check< Cube > B_tmp(A, out); const Cube& B = B_tmp.M; out.set_size(in_n_rows, in_n_cols, in_n_slices); eT* out_mem = out.memptr(); const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; const uword B_n_slices = B.n_slices; for(uword slice = 0; slice < B_n_slices; ++slice) for(uword row = 0; row < B_n_rows; ++row ) for(uword col = 0; col < B_n_cols; ++col ) { *out_mem = B.at(row,col,slice); out_mem++; } } } else { const unwrap_cube_check< Cube > B_tmp(A, out); const Cube& B = B_tmp.M; const uword n_elem_to_copy = (std::min)(B.n_elem, in_n_elem); out.set_size(in_n_rows, in_n_cols, in_n_slices); eT* out_mem = out.memptr(); if(in_dim == 0) { arrayops::copy( out_mem, B.memptr(), n_elem_to_copy ); } else { uword row = 0; uword col = 0; uword slice = 0; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; for(uword i=0; i= B_n_cols) { col = 0; ++row; if(row >= B_n_rows) { row = 0; ++slice; } } } } for(uword i=n_elem_to_copy; i inline xvec_htrans::xvec_htrans(const eT* const in_mem, const uword in_n_rows, const uword in_n_cols) : mem (in_mem ) , n_rows(in_n_cols ) // deliberately swapped , n_cols(in_n_rows ) , n_elem(in_n_rows*in_n_cols) { arma_extra_debug_sigprint(); } template inline void xvec_htrans::extract(Mat& out) const { arma_extra_debug_sigprint(); // NOTE: this function assumes that matrix 'out' has already been set to the correct size const eT* in_mem = mem; eT* out_mem = out.memptr(); const uword N = n_elem; for(uword ii=0; ii < N; ++ii) { out_mem[ii] = access::alt_conj( in_mem[ii] ); } } template inline eT xvec_htrans::operator[](const uword ii) const { return access::alt_conj( mem[ii] ); } template inline eT xvec_htrans::at_alt(const uword ii) const { return access::alt_conj( mem[ii] ); } template inline eT xvec_htrans::at(const uword in_row, const uword in_col) const { //return (n_rows == 1) ? access::alt_conj( mem[in_col] ) : access::alt_conj( mem[in_row] ); return access::alt_conj( mem[in_row + in_col] ); // either in_row or in_col must be zero, as we're storing a vector } //! @} RcppArmadillo/inst/include/armadillo_bits/blas_bones.hpp0000644000176000001440000001177612200064222023242 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifdef ARMA_USE_BLAS #if !defined(ARMA_BLAS_CAPITALS) #define arma_sdot sdot #define arma_ddot ddot #define arma_sgemv sgemv #define arma_dgemv dgemv #define arma_cgemv cgemv #define arma_zgemv zgemv #define arma_sgemm sgemm #define arma_dgemm dgemm #define arma_cgemm cgemm #define arma_zgemm zgemm #define arma_ssyrk ssyrk #define arma_dsyrk dsyrk #define arma_cherk cherk #define arma_zherk zherk #else #define arma_sdot SDOT #define arma_ddot DDOT #define arma_sgemv SGEMV #define arma_dgemv DGEMV #define arma_cgemv CGEMV #define arma_zgemv ZGEMV #define arma_sgemm SGEMM #define arma_dgemm DGEMM #define arma_cgemm CGEMM #define arma_zgemm ZGEMM #define arma_ssyrk SSYRK #define arma_dsyrk DSYRK #define arma_cherk CHERK #define arma_zherk ZHERK #endif extern "C" { float arma_fortran(arma_sdot)(blas_int* n, const float* x, blas_int* incx, const float* y, blas_int* incy); double arma_fortran(arma_ddot)(blas_int* n, const double* x, blas_int* incx, const double* y, blas_int* incy); void arma_fortran(arma_sgemv)(const char* transA, const blas_int* m, const blas_int* n, const float* alpha, const float* A, const blas_int* ldA, const float* x, const blas_int* incx, const float* beta, float* y, const blas_int* incy); void arma_fortran(arma_dgemv)(const char* transA, const blas_int* m, const blas_int* n, const double* alpha, const double* A, const blas_int* ldA, const double* x, const blas_int* incx, const double* beta, double* y, const blas_int* incy); void arma_fortran(arma_cgemv)(const char* transA, const blas_int* m, const blas_int* n, const void* alpha, const void* A, const blas_int* ldA, const void* x, const blas_int* incx, const void* beta, void* y, const blas_int* incy); void arma_fortran(arma_zgemv)(const char* transA, const blas_int* m, const blas_int* n, const void* alpha, const void* A, const blas_int* ldA, const void* x, const blas_int* incx, const void* beta, void* y, const blas_int* incy); void arma_fortran(arma_sgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const float* alpha, const float* A, const blas_int* ldA, const float* B, const blas_int* ldB, const float* beta, float* C, const blas_int* ldC); void arma_fortran(arma_dgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const double* alpha, const double* A, const blas_int* ldA, const double* B, const blas_int* ldB, const double* beta, double* C, const blas_int* ldC); void arma_fortran(arma_cgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const void* alpha, const void* A, const blas_int* ldA, const void* B, const blas_int* ldB, const void* beta, void* C, const blas_int* ldC); void arma_fortran(arma_zgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const void* alpha, const void* A, const blas_int* ldA, const void* B, const blas_int* ldB, const void* beta, void* C, const blas_int* ldC); void arma_fortran(arma_ssyrk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const float* alpha, const float* A, const blas_int* ldA, const float* beta, float* C, const blas_int* ldC); void arma_fortran(arma_dsyrk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const double* alpha, const double* A, const blas_int* ldA, const double* beta, double* C, const blas_int* ldC); void arma_fortran(arma_cherk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const float* alpha, const void* A, const blas_int* ldA, const float* beta, void* C, const blas_int* ldC); void arma_fortran(arma_zherk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const double* alpha, const void* A, const blas_int* ldA, const double* beta, void* C, const blas_int* ldC); // void arma_fortran(arma_dswap)(const blas_int* n, double* x, const blas_int* incx, double* y, const blas_int* incy); // void arma_fortran(arma_dscal)(const blas_int* n, const double* alpha, double* x, const blas_int* incx); // void arma_fortran(arma_dcopy)(const blas_int* n, const double* x, const blas_int* incx, double* y, const blas_int* incy); // void arma_fortran(arma_daxpy)(const blas_int* n, const double* alpha, const double* x, const blas_int* incx, double* y, const blas_int* incy); // void arma_fortran(arma_dger )(const blas_int* m, const blas_int* n, const double* alpha, const double* x, const blas_int* incx, const double* y, const blas_int* incy, double* A, const blas_int* ldA); } #endif RcppArmadillo/inst/include/armadillo_bits/Proxy.hpp0000644000176000001440000017723112176655102022272 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Proxy //! @{ // ea_type is the "element accessor" type, // which can provide access to elements via operator[] template struct Proxy_default { inline Proxy_default(const T1&) { arma_type_check(( is_arma_type::value == false )); } }; template struct Proxy_fixed { typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef T1 stored_type; typedef const elem_type* ea_type; typedef const T1& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = true; static const bool fake_mat = false; static const bool is_row = T1::is_row; static const bool is_col = T1::is_col; arma_aligned const T1& Q; inline explicit Proxy_fixed(const T1& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline static uword get_n_rows() { return T1::n_rows; } arma_inline static uword get_n_cols() { return T1::n_cols; } arma_inline static uword get_n_elem() { return T1::n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } arma_inline bool is_aligned() const { #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE) return true; #else return memory::is_aligned(Q.memptr()); #endif } }; template struct Proxy_redirect {}; template struct Proxy_redirect { typedef Proxy_default result; }; template struct Proxy_redirect { typedef Proxy_fixed result; }; template class Proxy : public Proxy_redirect::value >::result { public: inline Proxy(const T1& A) : Proxy_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template class Proxy< Mat > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const eT* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const Mat& Q; inline explicit Proxy(const Mat& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< Col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Col stored_type; typedef const eT* ea_type; typedef const Col& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const Col& Q; inline explicit Proxy(const Col& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< Row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Row stored_type; typedef const eT* ea_type; typedef const Row& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = true; static const bool is_col = false; arma_aligned const Row& Q; inline explicit Proxy(const Row& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return 1; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword, const uword col) const { return Q[col]; } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< Gen > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Gen stored_type; typedef const Gen& ea_type; typedef const Gen& aligned_ea_type; static const bool prefer_at_accessor = Gen::prefer_at_accessor; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = Gen::is_row; static const bool is_col = Gen::is_col; arma_aligned const Gen& Q; inline explicit Proxy(const Gen& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return (is_row ? 1 : Q.n_rows); } arma_inline uword get_n_cols() const { return (is_col ? 1 : Q.n_cols); } arma_inline uword get_n_elem() const { return (is_row ? 1 : Q.n_rows) * (is_col ? 1 : Q.n_cols); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return Gen::is_simple; } }; template class Proxy< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = Op::is_row; static const bool is_col = Op::is_col; arma_aligned const Mat Q; inline explicit Proxy(const Op& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy_diagvec_mat { inline Proxy_diagvec_mat(const T1&) {} }; template class Proxy_diagvec_mat< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef diagview stored_type; typedef const diagview& ea_type; typedef const diagview& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const Mat& R; arma_aligned const diagview Q; inline explicit Proxy_diagvec_mat(const Op& A) : R(A.m), Q( R.diag( (A.aux_uword_b > 0) ? -sword(A.aux_uword_a) : sword(A.aux_uword_a) ) ) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q.at(row, 0); } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&R) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy_diagvec_expr { inline Proxy_diagvec_expr(const T1&) {} }; template class Proxy_diagvec_expr< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const Mat Q; inline explicit Proxy_diagvec_expr(const Op& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q.at(row, 0); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template struct Proxy_diagvec_redirect {}; template struct Proxy_diagvec_redirect< Op, true > { typedef Proxy_diagvec_mat < Op > result; }; template struct Proxy_diagvec_redirect< Op, false> { typedef Proxy_diagvec_expr< Op > result; }; template class Proxy< Op > : public Proxy_diagvec_redirect< Op, is_Mat::value >::result { public: typedef typename Proxy_diagvec_redirect< Op, is_Mat::value >::result Proxy_diagvec; inline explicit Proxy(const Op& A) : Proxy_diagvec(A) { arma_extra_debug_sigprint(); } }; template struct Proxy_xtrans_default { typedef typename T1::elem_type eT; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; arma_aligned const Mat Q; arma_hot inline Proxy_xtrans_default(const T1& A) : Q(A) { arma_extra_debug_sigprint(); } template arma_inline bool is_alias(const Mat&) const { return false; } }; template struct Proxy_xtrans_vector { inline Proxy_xtrans_vector(const T1&) {} }; template struct Proxy_xtrans_vector< Op > { typedef typename T1::elem_type eT; static const bool prefer_at_accessor = false; static const bool has_subview = quasi_unwrap::has_subview; static const bool is_fixed = false; static const bool fake_mat = true; arma_aligned const quasi_unwrap U; // avoid copy if T1 is a Row, Col or subview_col arma_aligned const Mat Q; inline Proxy_xtrans_vector(const Op& A) : U(A.m) , Q(const_cast(U.M.memptr()), U.M.n_cols, U.M.n_rows, false, false) { arma_extra_debug_sigprint(); } template arma_inline bool is_alias(const Mat& X) const { return U.is_alias(X); } }; template struct Proxy_xtrans_vector< Op > { typedef typename T1::elem_type eT; static const bool prefer_at_accessor = false; static const bool has_subview = quasi_unwrap::has_subview; static const bool is_fixed = false; static const bool fake_mat = true; arma_aligned const quasi_unwrap U; // avoid copy if T1 is a Row, Col or subview_col arma_aligned const Mat Q; inline Proxy_xtrans_vector(const Op& A) : U(A.m) , Q(const_cast(U.M.memptr()), U.M.n_cols, U.M.n_rows, false, false) { arma_extra_debug_sigprint(); } template arma_inline bool is_alias(const Mat& X) const { return U.is_alias(X); } }; template struct Proxy_xtrans_redirect {}; template struct Proxy_xtrans_redirect { typedef Proxy_xtrans_default result; }; template struct Proxy_xtrans_redirect { typedef Proxy_xtrans_vector result; }; template class Proxy< Op > : public Proxy_xtrans_redirect < Op, ((is_complex::value == false) && ((Op::is_row) || (Op::is_col)) ) >::result { public: typedef typename Proxy_xtrans_redirect < Op, ((is_complex::value == false) && ((Op::is_row) || (Op::is_col)) ) >::result Proxy_xtrans; typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = Proxy_xtrans::prefer_at_accessor; static const bool has_subview = Proxy_xtrans::has_subview; static const bool is_fixed = Proxy_xtrans::is_fixed; static const bool fake_mat = Proxy_xtrans::fake_mat; // NOTE: the Op class takes care of swapping row and col for op_htrans static const bool is_row = Op::is_row; static const bool is_col = Op::is_col; using Proxy_xtrans::Q; inline explicit Proxy(const Op& A) : Proxy_xtrans(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return Proxy_xtrans::is_alias(X); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< Op > : public Proxy_xtrans_redirect < Op, ( (Op::is_row) || (Op::is_col) ) >::result { public: typedef typename Proxy_xtrans_redirect < Op, ( (Op::is_row) || (Op::is_col) ) >::result Proxy_xtrans; typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = Proxy_xtrans::prefer_at_accessor; static const bool has_subview = Proxy_xtrans::has_subview; static const bool is_fixed = Proxy_xtrans::is_fixed; static const bool fake_mat = Proxy_xtrans::fake_mat; // NOTE: the Op class takes care of swapping row and col for op_strans static const bool is_row = Op::is_row; static const bool is_col = Op::is_col; using Proxy_xtrans::Q; inline explicit Proxy(const Op& A) : Proxy_xtrans(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return Proxy_xtrans::is_alias(X); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template struct Proxy_subview_row_htrans_cx { typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row_htrans stored_type; typedef const subview_row_htrans& ea_type; typedef const subview_row_htrans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row_htrans Q; inline explicit Proxy_subview_row_htrans_cx(const Op, op_htrans>& A) : Q(A.m) { arma_extra_debug_sigprint(); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.sv_row.m)) == void_ptr(&X)); } }; template struct Proxy_subview_row_htrans_non_cx { typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row_strans stored_type; typedef const subview_row_strans& ea_type; typedef const subview_row_strans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row_strans Q; inline explicit Proxy_subview_row_htrans_non_cx(const Op, op_htrans>& A) : Q(A.m) { arma_extra_debug_sigprint(); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.sv_row.m)) == void_ptr(&X)); } }; template struct Proxy_subview_row_htrans_redirect {}; template struct Proxy_subview_row_htrans_redirect { typedef Proxy_subview_row_htrans_cx result; }; template struct Proxy_subview_row_htrans_redirect { typedef Proxy_subview_row_htrans_non_cx result; }; template class Proxy< Op, op_htrans> > : public Proxy_subview_row_htrans_redirect < eT, is_complex::value >::result { public: typedef typename Proxy_subview_row_htrans_redirect < eT, is_complex::value >::result Proxy_sv_row_ht; typedef typename Proxy_sv_row_ht::elem_type elem_type; typedef typename Proxy_sv_row_ht::pod_type pod_type; typedef typename Proxy_sv_row_ht::stored_type stored_type; typedef typename Proxy_sv_row_ht::ea_type ea_type; typedef typename Proxy_sv_row_ht::ea_type aligned_ea_type; static const bool prefer_at_accessor = Proxy_sv_row_ht::prefer_at_accessor; static const bool has_subview = Proxy_sv_row_ht::has_subview; static const bool is_fixed = Proxy_sv_row_ht::is_fixed; static const bool fake_mat = Proxy_sv_row_ht::fake_mat; static const bool is_row = false; static const bool is_col = true; using Proxy_sv_row_ht::Q; inline explicit Proxy(const Op, op_htrans>& A) : Proxy_sv_row_ht(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return Proxy_sv_row_ht::is_alias(X); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< Op, op_strans> > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row_strans stored_type; typedef const subview_row_strans& ea_type; typedef const subview_row_strans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row_strans Q; inline explicit Proxy(const Op, op_strans>& A) : Q(A.m) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.sv_row.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< Op< Row< std::complex >, op_htrans> > { public: typedef typename std::complex eT; typedef typename std::complex elem_type; typedef T pod_type; typedef xvec_htrans stored_type; typedef const xvec_htrans& ea_type; typedef const xvec_htrans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; const xvec_htrans Q; const Row& src; inline explicit Proxy(const Op< Row< std::complex >, op_htrans>& A) : Q (A.m.memptr(), A.m.n_rows, A.m.n_cols) , src(A.m) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return void_ptr(&src) == void_ptr(&X); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< Op< Col< std::complex >, op_htrans> > { public: typedef typename std::complex eT; typedef typename std::complex elem_type; typedef T pod_type; typedef xvec_htrans stored_type; typedef const xvec_htrans& ea_type; typedef const xvec_htrans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = true; static const bool is_col = false; const xvec_htrans Q; const Col& src; inline explicit Proxy(const Op< Col< std::complex >, op_htrans>& A) : Q (A.m.memptr(), A.m.n_rows, A.m.n_cols) , src(A.m) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return 1; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword, const uword col) const { return Q[col]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return void_ptr(&src) == void_ptr(&X); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< Op< subview_col< std::complex >, op_htrans> > { public: typedef typename std::complex eT; typedef typename std::complex elem_type; typedef T pod_type; typedef xvec_htrans stored_type; typedef const xvec_htrans& ea_type; typedef const xvec_htrans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = true; static const bool is_col = false; const xvec_htrans Q; const subview_col& src; inline explicit Proxy(const Op< subview_col< std::complex >, op_htrans>& A) : Q (A.m.colptr(0), A.m.n_rows, A.m.n_cols) , src(A.m) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return 1; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword, const uword col) const { return Q[col]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return void_ptr(&src.m) == void_ptr(&X); } arma_inline bool is_aligned() const { return false; } }; template struct Proxy_htrans2_default { typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const Mat Q; arma_hot inline Proxy_htrans2_default(const T1& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template struct Proxy_htrans2_vector { inline Proxy_htrans2_vector(const T1&) {} }; template struct Proxy_htrans2_vector< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef eOp< Op, eop_scalar_times> stored_type; typedef const eOp< Op, eop_scalar_times>& ea_type; typedef const eOp< Op, eop_scalar_times>& aligned_ea_type; static const bool prefer_at_accessor = eOp< Op, eop_scalar_times>::prefer_at_accessor; static const bool has_subview = eOp< Op, eop_scalar_times>::has_subview; static const bool is_fixed = eOp< Op, eop_scalar_times>::is_fixed; static const bool fake_mat = eOp< Op, eop_scalar_times>::fake_mat; // NOTE: the Op class takes care of swapping row and col for op_htrans static const bool is_row = eOp< Op, eop_scalar_times>::is_row; static const bool is_col = eOp< Op, eop_scalar_times>::is_col; arma_aligned const Op R; arma_aligned const eOp< Op, eop_scalar_times > Q; inline explicit Proxy_htrans2_vector(const Op& A) : R(A.m) , Q(R, A.aux) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.get_n_rows(); } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.get_n_cols(); } arma_inline uword get_n_elem() const { return Q.get_n_elem(); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return Q.P.is_alias(X); } arma_inline bool is_aligned() const { return Q.P.is_aligned(); } }; template struct Proxy_htrans2_redirect {}; template struct Proxy_htrans2_redirect { typedef Proxy_htrans2_default result; }; template struct Proxy_htrans2_redirect { typedef Proxy_htrans2_vector result; }; template class Proxy< Op > : public Proxy_htrans2_redirect < Op, ( (Op::is_row) || (Op::is_col) ) >::result { public: typedef typename Proxy_htrans2_redirect < Op, ( (Op::is_row) || (Op::is_col) ) >::result Proxy_htrans2; typedef typename Proxy_htrans2::elem_type elem_type; typedef typename Proxy_htrans2::pod_type pod_type; typedef typename Proxy_htrans2::stored_type stored_type; typedef typename Proxy_htrans2::ea_type ea_type; typedef typename Proxy_htrans2::aligned_ea_type aligned_ea_type; static const bool prefer_at_accessor = Proxy_htrans2::prefer_at_accessor; static const bool has_subview = Proxy_htrans2::has_subview; static const bool is_fixed = Proxy_htrans2::is_fixed; static const bool fake_mat = Proxy_htrans2::fake_mat; static const bool is_row = Proxy_htrans2::is_row; static const bool is_col = Proxy_htrans2::is_col; using Proxy_htrans2::Q; inline explicit Proxy(const Op& A) : Proxy_htrans2(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Proxy_htrans2::get_n_rows(); } arma_inline uword get_n_cols() const { return Proxy_htrans2::get_n_cols(); } arma_inline uword get_n_elem() const { return Proxy_htrans2::get_n_elem(); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Proxy_htrans2::get_ea(); } arma_inline aligned_ea_type get_aligned_ea() const { return Proxy_htrans2::get_aligned_ea(); } template arma_inline bool is_alias(const Mat& X) const { return Proxy_htrans2::is_alias(X); } arma_inline bool is_aligned() const { return Proxy_htrans2::is_aligned(); } }; template class Proxy< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = true; static const bool is_row = false; static const bool is_col = true; arma_aligned const unwrap U; arma_aligned const Mat Q; inline explicit Proxy(const Op& A) : U(A.m) , Q(const_cast(U.M.memptr()), U.M.n_elem, 1, false, false) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return ( void_ptr(&X) == void_ptr(&(U.M)) ); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< Glue > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = Glue::is_row; static const bool is_col = Glue::is_col; arma_aligned const Mat Q; inline explicit Proxy(const Glue& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< subview > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview stored_type; typedef const subview& ea_type; typedef const subview& aligned_ea_type; static const bool prefer_at_accessor = true; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const subview& Q; inline explicit Proxy(const subview& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< subview_col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_col stored_type; typedef const eT* ea_type; typedef const subview_col& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_col& Q; inline explicit Proxy(const subview_col& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.colmem; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.colmem); } }; template class Proxy< subview_row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row stored_type; typedef const subview_row& ea_type; typedef const subview_row& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = true; static const bool is_col = false; arma_aligned const subview_row& Q; inline explicit Proxy(const subview_row& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return 1; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword, const uword col) const { return Q[col]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< subview_row_strans > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row_strans stored_type; typedef const subview_row_strans& ea_type; typedef const subview_row_strans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row_strans& Q; inline explicit Proxy(const subview_row_strans& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.sv_row.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< subview_row_htrans > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row_htrans stored_type; typedef const subview_row_htrans& ea_type; typedef const subview_row_htrans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row_htrans& Q; inline explicit Proxy(const subview_row_htrans& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.sv_row.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< xvec_htrans > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const eT* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const Mat Q; inline explicit Proxy(const xvec_htrans& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< subview_elem1 > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const eT* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const Mat Q; inline explicit Proxy(const subview_elem1& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< subview_elem2 > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const eT* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const Mat Q; inline explicit Proxy(const subview_elem2& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< diagview > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef diagview stored_type; typedef const diagview& ea_type; typedef const diagview& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const diagview& Q; inline explicit Proxy(const diagview& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q.at(row, 0); } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< eOp > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef eOp stored_type; typedef const eOp& ea_type; typedef const eOp& aligned_ea_type; static const bool prefer_at_accessor = eOp::prefer_at_accessor; static const bool has_subview = eOp::has_subview; static const bool is_fixed = eOp::is_fixed; static const bool fake_mat = eOp::fake_mat; static const bool is_row = eOp::is_row; static const bool is_col = eOp::is_col; arma_aligned const eOp& Q; inline explicit Proxy(const eOp& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.get_n_rows(); } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.get_n_cols(); } arma_inline uword get_n_elem() const { return Q.get_n_elem(); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return Q.P.is_alias(X); } arma_inline bool is_aligned() const { return Q.P.is_aligned(); } }; template class Proxy< eGlue > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef eGlue stored_type; typedef const eGlue& ea_type; typedef const eGlue& aligned_ea_type; static const bool prefer_at_accessor = eGlue::prefer_at_accessor; static const bool has_subview = eGlue::has_subview; static const bool is_fixed = eGlue::is_fixed; static const bool fake_mat = eGlue::fake_mat; static const bool is_row = eGlue::is_row; static const bool is_col = eGlue::is_col; arma_aligned const eGlue& Q; inline explicit Proxy(const eGlue& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.get_n_rows(); } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.get_n_cols(); } arma_inline uword get_n_elem() const { return Q.get_n_elem(); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (Q.P1.is_alias(X) || Q.P2.is_alias(X)); } arma_inline bool is_aligned() const { return (Q.P1.is_aligned() && Q.P2.is_aligned()); } }; template class Proxy< mtOp > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = mtOp::is_row; static const bool is_col = mtOp::is_col; arma_aligned const Mat Q; inline explicit Proxy(const mtOp& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< mtGlue > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool is_fixed = false; static const bool fake_mat = false; static const bool is_row = mtGlue::is_row; static const bool is_col = mtGlue::is_col; arma_aligned const Mat Q; inline explicit Proxy(const mtGlue& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; //! @} RcppArmadillo/inst/include/armadillo_bits/mtSpOp_meat.hpp0000644000176000001440000000155412111344723023364 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup mtSpOp //! @{ template inline mtSpOp::mtSpOp(const T1& in_m) : m(in_m) { arma_extra_debug_sigprint(); } template inline mtSpOp::mtSpOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline mtSpOp::~mtSpOp() { arma_extra_debug_sigprint(); } RcppArmadillo/inst/include/armadillo_bits/glue_cross_meat.hpp0000644000176000001440000000370012200375542024304 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_cross //! @{ template inline void glue_cross::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy PA(X.A); const Proxy PB(X.B); arma_debug_check( ((PA.get_n_elem() != 3) || (PB.get_n_elem() != 3)), "cross(): input vectors must have 3 elements" ); const uword PA_n_rows = Proxy::is_row ? 1 : PA.get_n_rows(); const uword PA_n_cols = Proxy::is_col ? 1 : PA.get_n_cols(); out.set_size(PA_n_rows, PA_n_cols); eT* out_mem = out.memptr(); if( (Proxy::prefer_at_accessor == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type A = PA.get_ea(); typename Proxy::ea_type B = PB.get_ea(); const eT ax = A[0]; const eT ay = A[1]; const eT az = A[2]; const eT bx = B[0]; const eT by = B[1]; const eT bz = B[2]; out_mem[0] = ay*bz - az*by; out_mem[1] = az*bx - ax*bz; out_mem[2] = ax*by - ay*bx; } else { const bool PA_is_col = Proxy::is_col ? true : (PA_n_cols == 1); const bool PB_is_col = Proxy::is_col ? true : (PB.get_n_cols() == 1); const eT ax = PA.at(0,0); const eT ay = PA_is_col ? PA.at(1,0) : PA.at(0,1); const eT az = PA_is_col ? PA.at(2,0) : PA.at(0,2); const eT bx = PB.at(0,0); const eT by = PB_is_col ? PB.at(1,0) : PB.at(0,1); const eT bz = PB_is_col ? PB.at(2,0) : PB.at(0,2); out_mem[0] = ay*bz - az*by; out_mem[1] = az*bx - ax*bz; out_mem[2] = ax*by - ay*bx; } } //! @} RcppArmadillo/inst/include/armadillo_bits/mul_gemm_mixed.hpp0000644000176000001440000002753112222720570024130 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup gemm_mixed //! @{ //! \brief //! Matrix multplication where the matrices have differing element types. //! Uses caching for speedup. //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes) template class gemm_mixed_large { public: template arma_hot inline static void apply ( Mat& C, const Mat& A, const Mat& B, const out_eT alpha = out_eT(1), const out_eT beta = out_eT(0) ) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (do_trans_A == false) && (do_trans_B == false) ) { podarray tmp(A_n_cols); in_eT1* A_rowdata = tmp.memptr(); for(uword row_A=0; row_A < A_n_rows; ++row_A) { tmp.copy_row(A, row_A); for(uword col_B=0; col_B < B_n_cols; ++col_B) { const in_eT2* B_coldata = B.colptr(col_B); out_eT acc = out_eT(0); for(uword i=0; i < B_n_rows; ++i) { acc += upgrade_val::apply(A_rowdata[i]) * upgrade_val::apply(B_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(row_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(row_A,col_B) = acc + beta*C.at(row_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(row_A,col_B) = alpha*acc + beta*C.at(row_A,col_B); } } } } else if( (do_trans_A == true) && (do_trans_B == false) ) { for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const in_eT1* A_coldata = A.colptr(col_A); for(uword col_B=0; col_B < B_n_cols; ++col_B) { const in_eT2* B_coldata = B.colptr(col_B); out_eT acc = out_eT(0); for(uword i=0; i < B_n_rows; ++i) { acc += upgrade_val::apply(A_coldata[i]) * upgrade_val::apply(B_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,col_B) = acc + beta*C.at(col_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,col_B) = alpha*acc + beta*C.at(col_A,col_B); } } } } else if( (do_trans_A == false) && (do_trans_B == true) ) { Mat B_tmp; op_strans::apply_mat_noalias(B_tmp, B); gemm_mixed_large::apply(C, A, B_tmp, alpha, beta); } else if( (do_trans_A == true) && (do_trans_B == true) ) { // mat B_tmp = trans(B); // dgemm_arma::apply(C, A, B_tmp, alpha, beta); // By using the trans(A)*trans(B) = trans(B*A) equivalency, // transpose operations are not needed podarray tmp(B_n_cols); in_eT2* B_rowdata = tmp.memptr(); for(uword row_B=0; row_B < B_n_rows; ++row_B) { tmp.copy_row(B, row_B); for(uword col_A=0; col_A < A_n_cols; ++col_A) { const in_eT1* A_coldata = A.colptr(col_A); out_eT acc = out_eT(0); for(uword i=0; i < A_n_rows; ++i) { acc += upgrade_val::apply(B_rowdata[i]) * upgrade_val::apply(A_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,row_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,row_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,row_B) = acc + beta*C.at(col_A,row_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,row_B) = alpha*acc + beta*C.at(col_A,row_B); } } } } } }; //! Matrix multplication where the matrices have different element types. //! Simple version (no caching). //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes) template class gemm_mixed_small { public: template arma_hot inline static void apply ( Mat& C, const Mat& A, const Mat& B, const out_eT alpha = out_eT(1), const out_eT beta = out_eT(0) ) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (do_trans_A == false) && (do_trans_B == false) ) { for(uword row_A = 0; row_A < A_n_rows; ++row_A) { for(uword col_B = 0; col_B < B_n_cols; ++col_B) { const in_eT2* B_coldata = B.colptr(col_B); out_eT acc = out_eT(0); for(uword i = 0; i < B_n_rows; ++i) { const out_eT val1 = upgrade_val::apply(A.at(row_A,i)); const out_eT val2 = upgrade_val::apply(B_coldata[i]); acc += val1 * val2; //acc += upgrade_val::apply(A.at(row_A,i)) * upgrade_val::apply(B_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(row_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(row_A,col_B) = acc + beta*C.at(row_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(row_A,col_B) = alpha*acc + beta*C.at(row_A,col_B); } } } } else if( (do_trans_A == true) && (do_trans_B == false) ) { for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const in_eT1* A_coldata = A.colptr(col_A); for(uword col_B=0; col_B < B_n_cols; ++col_B) { const in_eT2* B_coldata = B.colptr(col_B); out_eT acc = out_eT(0); for(uword i=0; i < B_n_rows; ++i) { acc += upgrade_val::apply(A_coldata[i]) * upgrade_val::apply(B_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,col_B) = acc + beta*C.at(col_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,col_B) = alpha*acc + beta*C.at(col_A,col_B); } } } } else if( (do_trans_A == false) && (do_trans_B == true) ) { for(uword row_A = 0; row_A < A_n_rows; ++row_A) { for(uword row_B = 0; row_B < B_n_rows; ++row_B) { out_eT acc = out_eT(0); for(uword i = 0; i < B_n_cols; ++i) { acc += upgrade_val::apply(A.at(row_A,i)) * upgrade_val::apply(B.at(row_B,i)); } if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A,row_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(row_A,row_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(row_A,row_B) = acc + beta*C.at(row_A,row_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(row_A,row_B) = alpha*acc + beta*C.at(row_A,row_B); } } } } else if( (do_trans_A == true) && (do_trans_B == true) ) { for(uword row_B=0; row_B < B_n_rows; ++row_B) { for(uword col_A=0; col_A < A_n_cols; ++col_A) { const in_eT1* A_coldata = A.colptr(col_A); out_eT acc = out_eT(0); for(uword i=0; i < A_n_rows; ++i) { acc += upgrade_val::apply(B.at(row_B,i)) * upgrade_val::apply(A_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,row_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,row_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,row_B) = acc + beta*C.at(col_A,row_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,row_B) = alpha*acc + beta*C.at(col_A,row_B); } } } } } }; //! \brief //! Matrix multplication where the matrices have differing element types. template class gemm_mixed { public: //! immediate multiplication of matrices A and B, storing the result in C template inline static void apply ( Mat& C, const Mat& A, const Mat& B, const out_eT alpha = out_eT(1), const out_eT beta = out_eT(0) ) { arma_extra_debug_sigprint(); Mat tmp_A; Mat tmp_B; const bool predo_trans_A = ( (do_trans_A == true) && (is_cx::yes) ); const bool predo_trans_B = ( (do_trans_B == true) && (is_cx::yes) ); if(do_trans_A) { op_htrans::apply_mat_noalias(tmp_A, A); } if(do_trans_B) { op_htrans::apply_mat_noalias(tmp_B, B); } const Mat& AA = (predo_trans_A == false) ? A : tmp_A; const Mat& BB = (predo_trans_B == false) ? B : tmp_B; if( (AA.n_elem <= 64u) && (BB.n_elem <= 64u) ) { gemm_mixed_small<((predo_trans_A) ? false : do_trans_A), ((predo_trans_B) ? false : do_trans_B), use_alpha, use_beta>::apply(C, AA, BB, alpha, beta); } else { gemm_mixed_large<((predo_trans_A) ? false : do_trans_A), ((predo_trans_B) ? false : do_trans_B), use_alpha, use_beta>::apply(C, AA, BB, alpha, beta); } } }; //! @} RcppArmadillo/inst/include/armadillo_bits/glue_histc_meat.hpp0000644000176000001440000000730012256562725024301 0ustar ripleyusers// Copyright (C) 2012-2013 Conrad Sanderson // Copyright (C) 2012-2013 NICTA (www.nicta.com.au) // Copyright (C) 2012 Boris Sabanin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. template inline void glue_histc::apply(Mat& out, const mtGlue& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword; const unwrap_check_mixed tmp1(in.A, out); const unwrap_check_mixed tmp2(in.B, out); const Mat& X = tmp1.M; const Mat& E = tmp2.M; arma_debug_check ( ((E.is_vec() == false) && (E.is_empty() == false)), "histc(): parameter 'edges' must be a vector" ); arma_debug_check ( (dim > 1), "histc(): parameter 'dim' must be 0 or 1" ); const uword X_n_elem = X.n_elem; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword E_n_elem = E.n_elem; if( E_n_elem == 0 ) { out.reset(); return; } // for vectors we are currently ignoring the "dim" parameter uword out_n_rows = 0; uword out_n_cols = 0; if(X.is_vec()) { if(X.is_rowvec()) { out_n_rows = 1; out_n_cols = E_n_elem; } else if(X.is_colvec()) { out_n_rows = E_n_elem; out_n_cols = 1; } } else { if(dim == 0) { out_n_rows = E_n_elem; out_n_cols = X_n_cols; } else if(dim == 1) { out_n_rows = X_n_rows; out_n_cols = E_n_elem; } } out.zeros(out_n_rows, out_n_cols); const eT* E_mem = E.memptr(); if(X.is_vec() == true) { uword* out_mem = out.memptr(); const eT* X_mem = X.memptr(); for(uword j=0; j inline static void apply(Mat& out, const mtOp& in); // template inline static typename get_pod_type::result var_vec(const subview_col& X, const uword norm_type = 0); template inline static typename get_pod_type::result var_vec(const subview_row& X, const uword norm_type = 0); template inline static typename T1::pod_type var_vec(const Base& X, const uword norm_type = 0); // template inline static eT direct_var(const eT* const X, const uword N, const uword norm_type = 0); template inline static eT direct_var_robust(const eT* const X, const uword N, const uword norm_type = 0); // template inline static T direct_var(const std::complex* const X, const uword N, const uword norm_type = 0); template inline static T direct_var_robust(const std::complex* const X, const uword N, const uword norm_type = 0); }; //! @} RcppArmadillo/inst/include/armadillo_bits/atlas_bones.hpp0000644000176000001440000001462212176655102023435 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifdef ARMA_USE_ATLAS //! \namespace atlas namespace for ATLAS functions (imported from the global namespace) namespace atlas { using ::CblasColMajor; using ::CblasNoTrans; using ::CblasTrans; using ::CblasConjTrans; using ::CblasLower; using ::CblasUpper; #if defined(ARMA_USE_WRAPPER) extern "C" { float wrapper_cblas_sdot(const int N, const float *X, const int incX, const float *Y, const int incY); double wrapper_cblas_ddot(const int N, const double *X, const int incX, const double *Y, const int incY); void wrapper_cblas_cdotu_sub(const int N, const void *X, const int incX, const void *Y, const int incY, void *dotu); void wrapper_cblas_zdotu_sub(const int N, const void *X, const int incX, const void *Y, const int incY, void *dotu); void wrapper_cblas_sgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const float alpha, const float *A, const int lda, const float *X, const int incX, const float beta, float *Y, const int incY); void wrapper_cblas_dgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const double alpha, const double *A, const int lda, const double *X, const int incX, const double beta, double *Y, const int incY); void wrapper_cblas_cgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const void *alpha, const void *A, const int lda, const void *X, const int incX, const void *beta, void *Y, const int incY); void wrapper_cblas_zgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const void *alpha, const void *A, const int lda, const void *X, const int incX, const void *beta, void *Y, const int incY); void wrapper_cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const float alpha, const float *A, const int lda, const float *B, const int ldb, const float beta, float *C, const int ldc); void wrapper_cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const double alpha, const double *A, const int lda, const double *B, const int ldb, const double beta, double *C, const int ldc); void wrapper_cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const void *alpha, const void *A, const int lda, const void *B, const int ldb, const void *beta, void *C, const int ldc); void wrapper_cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const void *alpha, const void *A, const int lda, const void *B, const int ldb, const void *beta, void *C, const int ldc); void wrapper_cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const float alpha, const float *A, const int lda, const float beta, float *C, const int ldc); void wrapper_cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const double alpha, const double *A, const int lda, const double beta, double *C, const int ldc); void wrapper_cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const float alpha, const void *A, const int lda, const float beta, void *C, const int ldc); void wrapper_cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const double alpha, const void *A, const int lda, const double beta, void *C, const int ldc); int wrapper_clapack_sgetrf(const enum CBLAS_ORDER Order, const int M, const int N, float *A, const int lda, int *ipiv); int wrapper_clapack_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N, double *A, const int lda, int *ipiv); int wrapper_clapack_cgetrf(const enum CBLAS_ORDER Order, const int M, const int N, void *A, const int lda, int *ipiv); int wrapper_clapack_zgetrf(const enum CBLAS_ORDER Order, const int M, const int N, void *A, const int lda, int *ipiv); int wrapper_clapack_sgetri(const enum CBLAS_ORDER Order, const int N, float *A, const int lda, const int *ipiv); int wrapper_clapack_dgetri(const enum CBLAS_ORDER Order, const int N, double *A, const int lda, const int *ipiv); int wrapper_clapack_cgetri(const enum CBLAS_ORDER Order, const int N, void *A, const int lda, const int *ipiv); int wrapper_clapack_zgetri(const enum CBLAS_ORDER Order, const int N, void *A, const int lda, const int *ipiv); int wrapper_clapack_sgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, float *A, const int lda, int *ipiv, float *B, const int ldb); int wrapper_clapack_dgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, double *A, const int lda, int *ipiv, double *B, const int ldb); int wrapper_clapack_cgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, void *A, const int lda, int *ipiv, void *B, const int ldb); int wrapper_clapack_zgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, void *A, const int lda, int *ipiv, void *B, const int ldb); } #endif } #endif RcppArmadillo/inst/include/armadillo_bits/op_pinv_bones.hpp0000644000176000001440000000103312224726163023773 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_pinv //! @{ class op_pinv { public: template inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_symmat_bones.hpp0000644000176000001440000000135612200631217024326 0ustar ripleyusers// Copyright (C) 2011 Conrad Sanderson // Copyright (C) 2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_symmat //! @{ class op_symmat { public: template inline static void apply(Mat& out, const Op& in, const typename arma_not_cx::result* junk = 0); template inline static void apply(Mat& out, const Op& in, const typename arma_cx_only::result* junk = 0); }; //! @} RcppArmadillo/inst/include/armadillo_bits/subview_bones.hpp0000644000176000001440000003016312236716467024024 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // Copyright (C) 2011 James Sanders // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup subview //! @{ //! Class for storing data required to construct or apply operations to a submatrix //! (i.e. where the submatrix starts and ends as well as a reference/pointer to the original matrix), template class subview : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; arma_aligned const Mat& m; static const bool is_row = false; static const bool is_col = false; const uword aux_row1; const uword aux_col1; const uword n_rows; const uword n_cols; const uword n_elem; protected: arma_inline subview(const Mat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); public: inline ~subview(); inline void operator= (const eT val); inline void operator+= (const eT val); inline void operator-= (const eT val); inline void operator*= (const eT val); inline void operator/= (const eT val); // deliberately returning void template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); template inline void operator= (const SpBase& x); template inline void operator+=(const SpBase& x); template inline void operator-=(const SpBase& x); template inline void operator%=(const SpBase& x); template inline void operator/=(const SpBase& x); inline void operator= (const subview& x); inline void operator+= (const subview& x); inline void operator-= (const subview& x); inline void operator%= (const subview& x); inline void operator/= (const subview& x); inline static void extract(Mat& out, const subview& in); inline static void plus_inplace(Mat& out, const subview& in); inline static void minus_inplace(Mat& out, const subview& in); inline static void schur_inplace(Mat& out, const subview& in); inline static void div_inplace(Mat& out, const subview& in); template inline void transform(functor F); template inline void imbue(functor F); inline void fill(const eT val); inline void zeros(); inline void ones(); inline void eye(); inline void randu(); inline void randn(); inline eT at_alt (const uword ii) const; inline eT& operator[](const uword ii); inline eT operator[](const uword ii) const; inline eT& operator()(const uword ii); inline eT operator()(const uword ii) const; inline eT& operator()(const uword in_row, const uword in_col); inline eT operator()(const uword in_row, const uword in_col) const; inline eT& at(const uword in_row, const uword in_col); inline eT at(const uword in_row, const uword in_col) const; arma_inline eT* colptr(const uword in_col); arma_inline const eT* colptr(const uword in_col) const; inline bool check_overlap(const subview& x) const; inline bool is_vec() const; inline subview_row row(const uword row_num); inline const subview_row row(const uword row_num) const; inline subview_row operator()(const uword row_num, const span& col_span); inline const subview_row operator()(const uword row_num, const span& col_span) const; inline subview_col col(const uword col_num); inline const subview_col col(const uword col_num) const; inline subview_col operator()(const span& row_span, const uword col_num); inline const subview_col operator()(const span& row_span, const uword col_num) const; inline Col unsafe_col(const uword col_num); inline const Col unsafe_col(const uword col_num) const; inline subview rows(const uword in_row1, const uword in_row2); inline const subview rows(const uword in_row1, const uword in_row2) const; inline subview cols(const uword in_col1, const uword in_col2); inline const subview cols(const uword in_col1, const uword in_col2) const; inline subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); inline const subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; inline subview submat (const span& row_span, const span& col_span); inline const subview submat (const span& row_span, const span& col_span) const; inline subview operator()(const span& row_span, const span& col_span); inline const subview operator()(const span& row_span, const span& col_span) const; inline subview_each1< subview, 0 > each_col(); inline subview_each1< subview, 1 > each_row(); template inline subview_each2< subview, 0, T1 > each_col(const Base& indices); template inline subview_each2< subview, 1, T1 > each_row(const Base& indices); inline diagview diag(const sword in_id = 0); inline const diagview diag(const sword in_id = 0) const; inline void swap_rows(const uword in_row1, const uword in_row2); inline void swap_cols(const uword in_col1, const uword in_col2); // // primitive forward iterator // class iter // { // public: // // inline iter(const subview& in_M); // // arma_inline eT operator* () const; // // inline void operator++(); // inline void operator++(int); // // // private: // // arma_aligned const eT* mem; // // arma_aligned uword n_rows; // // arma_aligned uword row_start; // arma_aligned uword row_end_p1; // // arma_aligned uword row; // arma_aligned uword col; // arma_aligned uword i; // }; private: friend class Mat; subview(); }; template class subview_col : public subview { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; const eT* colmem; inline void operator= (const subview& x); inline void operator= (const subview_col& x); inline void operator= (const eT val); template inline void operator= (const Base& x); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; inline void fill(const eT val); inline void zeros(); inline void ones(); arma_inline eT at_alt (const uword i) const; arma_inline eT& operator[](const uword i); arma_inline eT operator[](const uword i) const; inline eT& operator()(const uword i); inline eT operator()(const uword i) const; inline eT& operator()(const uword in_row, const uword in_col); inline eT operator()(const uword in_row, const uword in_col) const; inline eT& at(const uword in_row, const uword in_col); inline eT at(const uword in_row, const uword in_col) const; arma_inline eT* colptr(const uword in_col); arma_inline const eT* colptr(const uword in_col) const; inline subview_col rows(const uword in_row1, const uword in_row2); inline const subview_col rows(const uword in_row1, const uword in_row2) const; inline subview_col subvec(const uword in_row1, const uword in_row2); inline const subview_col subvec(const uword in_row1, const uword in_row2) const; // TODO: add operator()(span) protected: inline subview_col(const Mat& in_m, const uword in_col); inline subview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); private: friend class Mat; friend class Col; friend class subview; subview_col(); }; template class subview_row : public subview { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = true; static const bool is_col = false; inline void operator= (const subview& x); inline void operator= (const subview_row& x); inline void operator= (const eT val); template inline void operator= (const Base& x); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; inline eT at_alt (const uword i) const; inline eT& operator[](const uword i); inline eT operator[](const uword i) const; inline eT& operator()(const uword i); inline eT operator()(const uword i) const; inline eT& operator()(const uword in_row, const uword in_col); inline eT operator()(const uword in_row, const uword in_col) const; inline eT& at(const uword in_row, const uword in_col); inline eT at(const uword in_row, const uword in_col) const; inline subview_row cols(const uword in_col1, const uword in_col2); inline const subview_row cols(const uword in_col1, const uword in_col2) const; inline subview_row subvec(const uword in_col1, const uword in_col2); inline const subview_row subvec(const uword in_col1, const uword in_col2) const; // TODO: add operator()(span) protected: inline subview_row(const Mat& in_m, const uword in_row); inline subview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); private: friend class Mat; friend class Row; friend class subview; subview_row(); }; template class subview_row_strans : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row& sv_row; const uword n_rows; // equal to n_elem const uword n_elem; static const uword n_cols = 1; inline explicit subview_row_strans(const subview_row& in_sv_row); inline void extract(Mat& out) const; inline eT at_alt (const uword i) const; inline eT operator[](const uword i) const; inline eT operator()(const uword i) const; inline eT operator()(const uword in_row, const uword in_col) const; inline eT at(const uword in_row, const uword in_col) const; }; template class subview_row_htrans : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row& sv_row; const uword n_rows; // equal to n_elem const uword n_elem; static const uword n_cols = 1; inline explicit subview_row_htrans(const subview_row& in_sv_row); inline void extract(Mat& out) const; inline eT at_alt (const uword i) const; inline eT operator[](const uword i) const; inline eT operator()(const uword i) const; inline eT operator()(const uword in_row, const uword in_col) const; inline eT at(const uword in_row, const uword in_col) const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/spglue_times_meat.hpp0000644000176000001440000001743712132137141024646 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spglue_times //! @{ template inline void spglue_times::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(X.A); const SpProxy pb(X.B); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_times::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_times::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } } template arma_hot inline void spglue_times::apply_noalias(SpMat& c, const SpProxy& pa, const SpProxy& pb) { arma_extra_debug_sigprint(); const uword x_n_rows = pa.get_n_rows(); const uword x_n_cols = pa.get_n_cols(); const uword y_n_rows = pb.get_n_rows(); const uword y_n_cols = pb.get_n_cols(); arma_debug_assert_mul_size(x_n_rows, x_n_cols, y_n_rows, y_n_cols, "matrix multiplication"); // First we must determine the structure of the new matrix (column pointers). // This follows the algorithm described in 'Sparse Matrix Multiplication // Package (SMMP)' (R.E. Bank and C.C. Douglas, 2001). Their description of // "SYMBMM" does not include anything about memory allocation. In addition it // does not consider that there may be elements which space may be allocated // for but which evaluate to zero anyway. So we have to modify the algorithm // to work that way. For the "SYMBMM" implementation we will not determine // the row indices but instead just the column pointers. //SpMat c(x_n_rows, y_n_cols); // Initializes col_ptrs to 0. c.zeros(x_n_rows, y_n_cols); //if( (pa.get_n_elem() == 0) || (pb.get_n_elem() == 0) ) if( (pa.get_n_nonzero() == 0) || (pb.get_n_nonzero() == 0) ) { return; } // Auxiliary storage which denotes when items have been found. podarray index(x_n_rows); index.fill(x_n_rows); // Fill with invalid links. typename SpProxy::const_iterator_type y_it = pb.begin(); typename SpProxy::const_iterator_type y_end = pb.end(); // SYMBMM: calculate column pointers for resultant matrix to obtain a good // upper bound on the number of nonzero elements. uword cur_col_length = 0; uword last_ind = x_n_rows + 1; do { const uword y_it_row = y_it.row(); // Look through the column that this point (*y_it) could affect. typename SpProxy::const_iterator_type x_it = pa.begin_col(y_it_row); while(x_it.col() == y_it_row) { // A point at x(i, j) and y(j, k) implies a point at c(i, k). if(index[x_it.row()] == x_n_rows) { index[x_it.row()] = last_ind; last_ind = x_it.row(); ++cur_col_length; } ++x_it; } const uword old_col = y_it.col(); ++y_it; // See if column incremented. if(old_col != y_it.col()) { // Set column pointer (this is not a cumulative count; that is done later). access::rw(c.col_ptrs[old_col + 1]) = cur_col_length; cur_col_length = 0; // Return index markers to zero. Use last_ind for traversal. while(last_ind != x_n_rows + 1) { const uword tmp = index[last_ind]; index[last_ind] = x_n_rows; last_ind = tmp; } } } while(y_it != y_end); // Accumulate column pointers. for(uword i = 0; i < c.n_cols; ++i) { access::rw(c.col_ptrs[i + 1]) += c.col_ptrs[i]; } // Now that we know a decent bound on the number of nonzero elements, allocate // the memory and fill it. c.mem_resize(c.col_ptrs[c.n_cols]); // Now the implementation of the NUMBMM algorithm. uword cur_pos = 0; // Current position in c matrix. podarray sums(x_n_rows); // Partial sums. sums.zeros(); // setting the size of 'sorted_indices' to x_n_rows is a better-than-nothing guess; // the correct minimum size is determined later podarray sorted_indices(x_n_rows); // last_ind is already set to x_n_rows, and cur_col_length is already set to 0. // We will loop through all columns as necessary. uword cur_col = 0; while(cur_col < c.n_cols) { // Skip to next column with elements in it. while((cur_col < c.n_cols) && (c.col_ptrs[cur_col] == c.col_ptrs[cur_col + 1])) { // Update current column pointer to actual number of nonzero elements up // to this point. access::rw(c.col_ptrs[cur_col]) = cur_pos; ++cur_col; } if(cur_col == c.n_cols) { break; } // Update current column pointer. access::rw(c.col_ptrs[cur_col]) = cur_pos; // Check all elements in this column. typename SpProxy::const_iterator_type y_col_it = pb.begin_col(cur_col); while(y_col_it.col() == cur_col) { // Check all elements in the column of the other matrix corresponding to // the row of this column. typename SpProxy::const_iterator_type x_col_it = pa.begin_col(y_col_it.row()); const eT y_value = (*y_col_it); while(x_col_it.col() == y_col_it.row()) { // A point at x(i, j) and y(j, k) implies a point at c(i, k). // Add to partial sum. const eT x_value = (*x_col_it); sums[x_col_it.row()] += (x_value * y_value); // Add point if it hasn't already been marked. if(index[x_col_it.row()] == x_n_rows) { index[x_col_it.row()] = last_ind; last_ind = x_col_it.row(); } ++x_col_it; } ++y_col_it; } // Now sort the indices that were used in this column. //podarray sorted_indices(c.col_ptrs[cur_col + 1] - c.col_ptrs[cur_col]); sorted_indices.set_min_size(c.col_ptrs[cur_col + 1] - c.col_ptrs[cur_col]); // .set_min_size() can only enlarge the array to the specified size, // hence if we request a smaller size than already allocated, // no new memory allocation is done uword cur_index = 0; while(last_ind != x_n_rows + 1) { const uword tmp = last_ind; // Check that it wasn't a "fake" nonzero element. if(sums[tmp] != eT(0)) { // Assign to next open position. sorted_indices[cur_index] = tmp; ++cur_index; } last_ind = index[tmp]; index[tmp] = x_n_rows; } // Now sort the indices. if (cur_index != 0) { op_sort::direct_sort_ascending(sorted_indices.memptr(), cur_index); for(uword k = 0; k < cur_index; ++k) { const uword row = sorted_indices[k]; access::rw(c.row_indices[cur_pos]) = row; access::rw(c.values[cur_pos]) = sums[row]; sums[row] = eT(0); ++cur_pos; } } // Move to next column. ++cur_col; } // Update last column pointer and resize to actual memory size. access::rw(c.col_ptrs[c.n_cols]) = cur_pos; c.mem_resize(cur_pos); } // // // spglue_times2: scalar*(A * B) template inline void spglue_times2::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(X.A); const SpProxy pb(X.B); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_times::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_times::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } out *= X.aux; } //! @} RcppArmadillo/inst/include/armadillo_bits/BaseCube_meat.hpp0000644000176000001440000000301112176655102023610 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup BaseCube //! @{ template arma_inline const derived& BaseCube::get_ref() const { return static_cast(*this); } template inline void BaseCube::print(const std::string extra_text) const { const unwrap_cube tmp( (*this).get_ref() ); tmp.M.impl_print(extra_text); } template inline void BaseCube::print(std::ostream& user_stream, const std::string extra_text) const { const unwrap_cube tmp( (*this).get_ref() ); tmp.M.impl_print(user_stream, extra_text); } template inline void BaseCube::raw_print(const std::string extra_text) const { const unwrap_cube tmp( (*this).get_ref() ); tmp.M.impl_raw_print(extra_text); } template inline void BaseCube::raw_print(std::ostream& user_stream, const std::string extra_text) const { const unwrap_cube tmp( (*this).get_ref() ); tmp.M.impl_raw_print(user_stream, extra_text); } //! @} RcppArmadillo/inst/include/armadillo_bits/mul_gemm.hpp0000644000176000001440000003250012222720570022732 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup gemm //! @{ //! for tiny square matrices, size <= 4x4 template class gemm_emul_tinysq { public: template arma_hot inline static void apply ( Mat& C, const TA& A, const TB& B, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); switch(A.n_rows) { case 4: gemv_emul_tinysq::apply( C.colptr(3), A, B.colptr(3), alpha, beta ); case 3: gemv_emul_tinysq::apply( C.colptr(2), A, B.colptr(2), alpha, beta ); case 2: gemv_emul_tinysq::apply( C.colptr(1), A, B.colptr(1), alpha, beta ); case 1: gemv_emul_tinysq::apply( C.colptr(0), A, B.colptr(0), alpha, beta ); default: ; } } }; //! emulation of gemm(), for non-complex matrices only, as it assumes only simple transposes (ie. doesn't do hermitian transposes) template class gemm_emul_large { public: template arma_hot inline static void apply ( Mat& C, const TA& A, const TB& B, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (do_trans_A == false) && (do_trans_B == false) ) { arma_aligned podarray tmp(A_n_cols); eT* A_rowdata = tmp.memptr(); for(uword row_A=0; row_A < A_n_rows; ++row_A) { //tmp.copy_row(A, row_A); const eT acc0 = op_dot::dot_and_copy_row(A_rowdata, A, row_A, B.colptr(0), A_n_cols); if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A,0) = acc0; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(row_A,0) = alpha*acc0; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(row_A,0) = acc0 + beta*C.at(row_A,0); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(row_A,0) = alpha*acc0 + beta*C.at(row_A,0); } //for(uword col_B=0; col_B < B_n_cols; ++col_B) for(uword col_B=1; col_B < B_n_cols; ++col_B) { const eT acc = op_dot::direct_dot_arma(B_n_rows, A_rowdata, B.colptr(col_B)); if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(row_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(row_A,col_B) = acc + beta*C.at(row_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(row_A,col_B) = alpha*acc + beta*C.at(row_A,col_B); } } } } else if( (do_trans_A == true) && (do_trans_B == false) ) { for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const eT* A_coldata = A.colptr(col_A); for(uword col_B=0; col_B < B_n_cols; ++col_B) { const eT acc = op_dot::direct_dot_arma(B_n_rows, A_coldata, B.colptr(col_B)); if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,col_B) = acc + beta*C.at(col_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,col_B) = alpha*acc + beta*C.at(col_A,col_B); } } } } else if( (do_trans_A == false) && (do_trans_B == true) ) { Mat BB; op_strans::apply_mat_noalias(BB, B); gemm_emul_large::apply(C, A, BB, alpha, beta); } else if( (do_trans_A == true) && (do_trans_B == true) ) { // mat B_tmp = trans(B); // dgemm_arma::apply(C, A, B_tmp, alpha, beta); // By using the trans(A)*trans(B) = trans(B*A) equivalency, // transpose operations are not needed arma_aligned podarray tmp(B.n_cols); eT* B_rowdata = tmp.memptr(); for(uword row_B=0; row_B < B_n_rows; ++row_B) { tmp.copy_row(B, row_B); for(uword col_A=0; col_A < A_n_cols; ++col_A) { const eT acc = op_dot::direct_dot_arma(A_n_rows, B_rowdata, A.colptr(col_A)); if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,row_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,row_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,row_B) = acc + beta*C.at(col_A,row_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,row_B) = alpha*acc + beta*C.at(col_A,row_B); } } } } } }; template class gemm_emul { public: template arma_hot inline static void apply ( Mat& C, const TA& A, const TB& B, const eT alpha = eT(1), const eT beta = eT(0), const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows <= 4) && (A_n_rows == A_n_cols) && (A_n_rows == B_n_rows) && (B_n_rows == B_n_cols) ) { if(do_trans_B == false) { gemm_emul_tinysq::apply(C, A, B, alpha, beta); } else { Mat BB(A_n_rows, A_n_rows); op_strans::apply_mat_noalias_tinysq(BB, B); gemm_emul_tinysq::apply(C, A, BB, alpha, beta); } } else { gemm_emul_large::apply(C, A, B, alpha, beta); } } template arma_hot inline static void apply ( Mat& C, const Mat& A, const Mat& B, const eT alpha = eT(1), const eT beta = eT(0), const typename arma_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); // "better than nothing" handling of hermitian transposes for complex number matrices Mat tmp_A; Mat tmp_B; if(do_trans_A) { op_htrans::apply_mat_noalias(tmp_A, A); } if(do_trans_B) { op_htrans::apply_mat_noalias(tmp_B, B); } const Mat& AA = (do_trans_A == false) ? A : tmp_A; const Mat& BB = (do_trans_B == false) ? B : tmp_B; const uword A_n_rows = AA.n_rows; const uword A_n_cols = AA.n_cols; const uword B_n_rows = BB.n_rows; const uword B_n_cols = BB.n_cols; if( (A_n_rows <= 4) && (A_n_rows == A_n_cols) && (A_n_rows == B_n_rows) && (B_n_rows == B_n_cols) ) { gemm_emul_tinysq::apply(C, AA, BB, alpha, beta); } else { gemm_emul_large::apply(C, AA, BB, alpha, beta); } } }; //! \brief //! Wrapper for ATLAS/BLAS dgemm function, using template arguments to control the arguments passed to dgemm. //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes) template class gemm { public: template inline static void apply_blas_type( Mat& C, const TA& A, const TB& B, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); const uword threshold = (is_Mat_fixed::value && is_Mat_fixed::value) ? (is_cx::yes ? 16u : 64u) : (is_cx::yes ? 16u : 48u); if( (A.n_elem <= threshold) && (B.n_elem <= threshold) ) { gemm_emul::apply(C,A,B,alpha,beta); } else { #if defined(ARMA_USE_ATLAS) { arma_extra_debug_print("atlas::cblas_gemm()"); atlas::cblas_gemm ( atlas::CblasColMajor, (do_trans_A) ? ( is_cx::yes ? CblasConjTrans : atlas::CblasTrans ) : atlas::CblasNoTrans, (do_trans_B) ? ( is_cx::yes ? CblasConjTrans : atlas::CblasTrans ) : atlas::CblasNoTrans, C.n_rows, C.n_cols, (do_trans_A) ? A.n_rows : A.n_cols, (use_alpha) ? alpha : eT(1), A.mem, (do_trans_A) ? A.n_rows : C.n_rows, B.mem, (do_trans_B) ? C.n_cols : ( (do_trans_A) ? A.n_rows : A.n_cols ), (use_beta) ? beta : eT(0), C.memptr(), C.n_rows ); } #elif defined(ARMA_USE_BLAS) { arma_extra_debug_print("blas::gemm()"); const char trans_A = (do_trans_A) ? ( is_cx::yes ? 'C' : 'T' ) : 'N'; const char trans_B = (do_trans_B) ? ( is_cx::yes ? 'C' : 'T' ) : 'N'; const blas_int m = C.n_rows; const blas_int n = C.n_cols; const blas_int k = (do_trans_A) ? A.n_rows : A.n_cols; const eT local_alpha = (use_alpha) ? alpha : eT(1); const blas_int lda = (do_trans_A) ? k : m; const blas_int ldb = (do_trans_B) ? n : k; const eT local_beta = (use_beta) ? beta : eT(0); arma_extra_debug_print( arma_boost::format("blas::gemm(): trans_A = %c") % trans_A ); arma_extra_debug_print( arma_boost::format("blas::gemm(): trans_B = %c") % trans_B ); blas::gemm ( &trans_A, &trans_B, &m, &n, &k, &local_alpha, A.mem, &lda, B.mem, &ldb, &local_beta, C.memptr(), &m ); } #else { gemm_emul::apply(C,A,B,alpha,beta); } #endif } } //! immediate multiplication of matrices A and B, storing the result in C template inline static void apply( Mat& C, const TA& A, const TB& B, const eT alpha = eT(1), const eT beta = eT(0) ) { gemm_emul::apply(C,A,B,alpha,beta); } template arma_inline static void apply ( Mat& C, const TA& A, const TB& B, const float alpha = float(1), const float beta = float(0) ) { gemm::apply_blas_type(C,A,B,alpha,beta); } template arma_inline static void apply ( Mat& C, const TA& A, const TB& B, const double alpha = double(1), const double beta = double(0) ) { gemm::apply_blas_type(C,A,B,alpha,beta); } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const TB& B, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { gemm::apply_blas_type(C,A,B,alpha,beta); } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const TB& B, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { gemm::apply_blas_type(C,A,B,alpha,beta); } }; //! @} RcppArmadillo/inst/include/armadillo_bits/op_median_bones.hpp0000644000176000001440000000273412200631217024252 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_median //! @{ template struct arma_cx_median_packet { T val; uword index; }; template arma_inline bool operator< (const arma_cx_median_packet& A, const arma_cx_median_packet& B) { return A.val < B.val; } //! Class for finding median values of a matrix class op_median { public: template inline static void apply(Mat& out, const Op& in); template inline static void apply(Mat< std::complex >& out, const Op& in); // // template inline static typename T1::elem_type median_vec(const T1& X, const typename arma_not_cx::result* junk = 0); template inline static typename T1::elem_type median_vec(const T1& X, const typename arma_cx_only::result* junk = 0); // // template inline static eT direct_median(std::vector& X); template inline static void direct_cx_median_index(uword& out_index1, uword& out_index2, std::vector< arma_cx_median_packet >& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/arrayops_bones.hpp0000644000176000001440000001165512260435137024172 0ustar ripleyusers// Copyright (C) 2011-2013 Conrad Sanderson // Copyright (C) 2011-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup arrayops //! @{ class arrayops { public: template arma_hot arma_inline static void copy(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void copy_small(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void copy_forwards(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void copy_backwards(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void fill_zeros(eT* dest, const uword n_elem); // // array = convert(array) template arma_hot arma_inline static void convert_cx_scalar(out_eT& out, const in_eT& in, const typename arma_not_cx::result* junk1 = 0, const typename arma_not_cx< in_eT>::result* junk2 = 0); template arma_hot arma_inline static void convert_cx_scalar(out_eT& out, const std::complex& in, const typename arma_not_cx::result* junk = 0); template arma_hot arma_inline static void convert_cx_scalar(std::complex& out, const std::complex< in_T>& in); template arma_hot inline static void convert(out_eT* dest, const in_eT* src, const uword n_elem); template arma_hot inline static void convert_cx(out_eT* dest, const in_eT* src, const uword n_elem); // // array op= array template arma_hot inline static void inplace_plus(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_minus(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_mul(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_div(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_plus_base(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_minus_base(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_mul_base(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_div_base(eT* dest, const eT* src, const uword n_elem); // // array op= scalar template arma_hot inline static void inplace_set(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_set_small(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_set_fixed(eT* dest, const eT val); template arma_hot inline static void inplace_plus(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_minus(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_mul(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_div(eT* dest, const eT val, const uword n_elem); // // scalar = op(array) template arma_hot arma_pure inline static eT accumulate(const eT* src, const uword n_elem); template arma_hot arma_pure inline static eT product(const eT* src, const uword n_elem); template arma_hot arma_pure inline static bool is_finite(const eT* src, const uword n_elem); template arma_hot arma_pure inline static typename get_pod_type::result norm_1(const eT* src, const uword n_elem); template arma_hot arma_pure inline static eT norm_2(const eT* src, const uword n_elem, const typename arma_not_cx::result* junk = 0); template arma_hot arma_pure inline static T norm_2(const std::complex* src, const uword n_elem); template arma_hot arma_pure inline static typename get_pod_type::result norm_k(const eT* src, const uword n_elem, const int k); template arma_hot arma_pure inline static typename get_pod_type::result norm_max(const eT* src, const uword n_elem); template arma_hot arma_pure inline static typename get_pod_type::result norm_min(const eT* src, const uword n_elem); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_unique.hpp0000644000176000001440000000115212256562725023135 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Arnold Wiliem // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. template inline const Op unique ( const Base& A, const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op( A.get_ref() ); } RcppArmadillo/inst/include/armadillo_bits/fn_median.hpp0000644000176000001440000000302412200375542023050 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_median //! @{ template arma_inline const Op median ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op median ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type median ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_median::median_vec(X); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & median(const T& x) { return x; } //! @} RcppArmadillo/inst/include/armadillo_bits/atlas_wrapper.hpp0000644000176000001440000002235712226643006024007 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifdef ARMA_USE_ATLAS //! \namespace atlas namespace for ATLAS functions (imported from the global namespace) namespace atlas { template inline static const eT& tmp_real(const eT& X) { return X; } template inline static const T tmp_real(const std::complex& X) { return X.real(); } template arma_inline eT cblas_dot(const int N, const eT* X, const eT* Y) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float T; return eT( arma_atlas(cblas_sdot)(N, (const T*)X, 1, (const T*)Y, 1) ); } else if(is_double::value == true) { typedef double T; return eT( arma_atlas(cblas_ddot)(N, (const T*)X, 1, (const T*)Y, 1) ); } else { return eT(0); } } template arma_inline eT cx_cblas_dot(const int N, const eT* X, const eT* Y) { arma_type_check((is_supported_blas_type::value == false)); if(is_supported_complex_float::value == true) { typedef typename std::complex T; T out; arma_atlas(cblas_cdotu_sub)(N, (const T*)X, 1, (const T*)Y, 1, &out); return eT(out); } else if(is_supported_complex_double::value == true) { typedef typename std::complex T; T out; arma_atlas(cblas_zdotu_sub)(N, (const T*)X, 1, (const T*)Y, 1, &out); return eT(out); } else { return eT(0); } } template inline void cblas_gemv ( const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const eT alpha, const eT *A, const int lda, const eT *X, const int incX, const eT beta, eT *Y, const int incY ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float T; arma_atlas(cblas_sgemv)(Order, TransA, M, N, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)X, incX, (const T)tmp_real(beta), (T*)Y, incY); } else if(is_double::value == true) { typedef double T; arma_atlas(cblas_dgemv)(Order, TransA, M, N, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)X, incX, (const T)tmp_real(beta), (T*)Y, incY); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_atlas(cblas_cgemv)(Order, TransA, M, N, (const T*)&alpha, (const T*)A, lda, (const T*)X, incX, (const T*)&beta, (T*)Y, incY); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_atlas(cblas_zgemv)(Order, TransA, M, N, (const T*)&alpha, (const T*)A, lda, (const T*)X, incX, (const T*)&beta, (T*)Y, incY); } } template inline void cblas_gemm ( const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const eT alpha, const eT *A, const int lda, const eT *B, const int ldb, const eT beta, eT *C, const int ldc ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float T; arma_atlas(cblas_sgemm)(Order, TransA, TransB, M, N, K, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)B, ldb, (const T)tmp_real(beta), (T*)C, ldc); } else if(is_double::value == true) { typedef double T; arma_atlas(cblas_dgemm)(Order, TransA, TransB, M, N, K, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)B, ldb, (const T)tmp_real(beta), (T*)C, ldc); } else if(is_supported_complex_float::value == true) { typedef std::complex T; arma_atlas(cblas_cgemm)(Order, TransA, TransB, M, N, K, (const T*)&alpha, (const T*)A, lda, (const T*)B, ldb, (const T*)&beta, (T*)C, ldc); } else if(is_supported_complex_double::value == true) { typedef std::complex T; arma_atlas(cblas_zgemm)(Order, TransA, TransB, M, N, K, (const T*)&alpha, (const T*)A, lda, (const T*)B, ldb, (const T*)&beta, (T*)C, ldc); } } template inline void cblas_syrk ( const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const eT alpha, const eT* A, const int lda, const eT beta, eT* C, const int ldc ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float T; arma_atlas(cblas_ssyrk)(Order, Uplo, Trans, N, K, (const T)alpha, (const T*)A, lda, (const T)beta, (T*)C, ldc); } else if(is_double::value == true) { typedef double T; arma_atlas(cblas_dsyrk)(Order, Uplo, Trans, N, K, (const T)alpha, (const T*)A, lda, (const T)beta, (T*)C, ldc); } } template inline void cblas_herk ( const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const T alpha, const std::complex* A, const int lda, const T beta, std::complex* C, const int ldc ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float TT; typedef std::complex cx_TT; arma_atlas(cblas_cherk)(Order, Uplo, Trans, N, K, (const TT)alpha, (const cx_TT*)A, lda, (const TT)beta, (cx_TT*)C, ldc); } else if(is_double::value == true) { typedef double TT; typedef std::complex cx_TT; arma_atlas(cblas_zherk)(Order, Uplo, Trans, N, K, (const TT)alpha, (const cx_TT*)A, lda, (const TT)beta, (cx_TT*)C, ldc); } } template inline int clapack_getrf ( const enum CBLAS_ORDER Order, const int M, const int N, eT *A, const int lda, int *ipiv ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float T; return arma_atlas(clapack_sgetrf)(Order, M, N, (T*)A, lda, ipiv); } else if(is_double::value == true) { typedef double T; return arma_atlas(clapack_dgetrf)(Order, M, N, (T*)A, lda, ipiv); } else if(is_supported_complex_float::value == true) { typedef std::complex T; return arma_atlas(clapack_cgetrf)(Order, M, N, (T*)A, lda, ipiv); } else if(is_supported_complex_double::value == true) { typedef std::complex T; return arma_atlas(clapack_zgetrf)(Order, M, N, (T*)A, lda, ipiv); } else { return -1; } } template inline int clapack_getri ( const enum CBLAS_ORDER Order, const int N, eT *A, const int lda, const int *ipiv ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float T; return arma_atlas(clapack_sgetri)(Order, N, (T*)A, lda, ipiv); } else if(is_double::value == true) { typedef double T; return arma_atlas(clapack_dgetri)(Order, N, (T*)A, lda, ipiv); } else if(is_supported_complex_float::value == true) { typedef std::complex T; return arma_atlas(clapack_cgetri)(Order, N, (T*)A, lda, ipiv); } else if(is_supported_complex_double::value == true) { typedef std::complex T; return arma_atlas(clapack_zgetri)(Order, N, (T*)A, lda, ipiv); } else { return -1; } } template inline int clapack_gesv ( const enum CBLAS_ORDER Order, const int N, const int NRHS, eT* A, const int lda, int* ipiv, eT* B, const int ldb ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value == true) { typedef float T; return arma_atlas(clapack_sgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb); } else if(is_double::value == true) { typedef double T; return arma_atlas(clapack_dgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb); } else if(is_supported_complex_float::value == true) { typedef std::complex T; return arma_atlas(clapack_cgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb); } else if(is_supported_complex_double::value == true) { typedef std::complex T; return arma_atlas(clapack_zgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb); } else { return -1; } } } #endif RcppArmadillo/inst/include/armadillo_bits/span.hpp0000644000176000001440000000254612217773605022113 0ustar ripleyusers// Copyright (C) 2010-2012 Conrad Sanderson // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) // Copyright (C) 2011 Stanislav Funiak // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup span //! @{ struct span_alt {}; template class span_base { public: static const span_alt all; }; template const span_alt span_base::all = span_alt(); class span : public span_base<> { public: uword a; uword b; bool whole; inline span() : whole(true) { } inline span(const span_alt&) : whole(true) { } // TODO: // if the "explicit" keyword is removed or commented out, // the compiler will be able to automatically convert integers to an instance of the span class. // this is useful for Cube::operator()(span&, span&, span&), // but it might have unintended consequences or interactions elsewhere. // as such, removal of "explicit" needs thorough testing. inline explicit span(const uword in_a) : a(in_a) , b(in_a) , whole(false) { } inline span(const uword in_a, const uword in_b) : a(in_a) , b(in_b) , whole(false) { } }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_svd.hpp0000644000176000001440000000777712252272712022434 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_svd //! @{ template inline bool svd ( Col& S, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); // it doesn't matter if X is an alias of S, as auxlib::svd() makes a copy of X const bool status = auxlib::svd_dc(S, X); if(status == false) { S.reset(); arma_bad("svd(): failed to converge", false); } return status; } template inline Col svd ( const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Col out; const bool status = auxlib::svd_dc(out, X); if(status == false) { out.reset(); arma_bad("svd(): failed to converge"); } return out; } template inline bool svd ( Mat& U, Col& S, Mat& V, const Base& X, const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check ( ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ), "svd(): two or more output objects are the same object" ); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'd')), "svd(): unknown method specified" ); // auxlib::svd() makes an internal copy of X const bool status = (sig == 'd') ? auxlib::svd_dc(U, S, V, X) : auxlib::svd(U, S, V, X); if(status == false) { U.reset(); S.reset(); V.reset(); arma_bad("svd(): failed to converge", false); } return status; } template inline bool svd_econ ( Mat& U, Col& S, Mat& V, const Base& X, const char mode, const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check ( ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ), "svd_econ(): two or more output objects are the same object" ); arma_debug_check ( ( (mode != 'l') && (mode != 'r') && (mode != 'b') ), "svd_econ(): parameter 'mode' or 'side' is incorrect" ); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'd')), "svd_econ(): unknown method specified" ); const bool status = ((mode == 'b') && (sig == 'd')) ? auxlib::svd_dc_econ(U, S, V, X) : auxlib::svd_econ(U, S, V, X, mode); if(status == false) { U.reset(); S.reset(); V.reset(); arma_bad("svd_econ(): failed to converge", false); } return status; } template inline bool svd_econ ( Mat& U, Col& S, Mat& V, const Base& X, const char* side = "both", const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return svd_econ(U,S,V,X,side[0],method); } //! @} RcppArmadillo/inst/include/armadillo_bits/arma_ostream_bones.hpp0000644000176000001440000000445112206306526024777 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup arma_ostream //! @{ class arma_ostream_state { private: const ios::fmtflags orig_flags; const std::streamsize orig_precision; const std::streamsize orig_width; const char orig_fill; public: inline arma_ostream_state(const std::ostream& o); inline void restore(std::ostream& o) const; }; class arma_ostream { public: template inline static std::streamsize modify_stream(std::ostream& o, const eT* data, const uword n_elem); template inline static std::streamsize modify_stream(std::ostream& o, const std::complex* data, const uword n_elem); template inline static std::streamsize modify_stream(std::ostream& o, typename SpMat::const_iterator begin, const uword n_elem, const typename arma_not_cx::result* junk = 0); template inline static std::streamsize modify_stream(std::ostream& o, typename SpMat::const_iterator begin, const uword n_elem, const typename arma_cx_only::result* junk = 0); template inline static void print_elem_zero(std::ostream& o, const bool modify); template arma_inline static void print_elem(std::ostream& o, const eT& x, const bool modify); template inline static void print_elem(std::ostream& o, const std::complex& x, const bool modify); template inline static void print(std::ostream& o, const Mat& m, const bool modify); template inline static void print(std::ostream& o, const Cube& m, const bool modify); template inline static void print(std::ostream& o, const field& m); template inline static void print(std::ostream& o, const subview_field& m); template inline static void print_dense(std::ostream& o, const SpMat& m, const bool modify); template inline static void print(std::ostream& o, const SpMat& m, const bool modify); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_var.hpp0000644000176000001440000000566612200375542022421 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_var //! @{ template inline const mtOp var ( const T1& X, const uword norm_type = 0, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return mtOp(X, norm_type, dim); } template inline const mtOp var ( const T1& X, const uword norm_type, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtOp(X, norm_type, dim); } template inline arma_warn_unused typename T1::pod_type var ( const T1& X, const uword norm_type = 0, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_var::var_vec( X, norm_type ); } template arma_inline arma_warn_unused const typename arma_scalar_only::result var(const T&) { return T(0); } template inline const mtSpOp var ( const T1& X, const uword norm_type = 0, const uword dim = 0, const typename enable_if< is_arma_sparse_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_sparse_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return mtSpOp(X, norm_type, dim); } template inline const mtSpOp var ( const T1& X, const uword norm_type, const uword dim = 0, const typename enable_if::value == true>::result* junk1 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); return mtSpOp(X, norm_type, dim); } template inline typename T1::pod_type var ( const T1& X, const uword norm_type = 0, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return spop_var::var_vec(X, norm_type); } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_mixed_bones.hpp0000644000176000001440000000433312200375542024444 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_mixed //! @{ class glue_mixed_times { public: template inline static void apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_times>& X); }; class glue_mixed_plus { public: template inline static void apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_plus>& X); template inline static void apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_plus>& X); }; class glue_mixed_minus { public: template inline static void apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_minus>& X); template inline static void apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_minus>& X); }; class glue_mixed_div { public: template inline static void apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_div>& X); template inline static void apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_div>& X); }; class glue_mixed_schur { public: template inline static void apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_schur>& X); template inline static void apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_schur>& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/eglue_core_meat.hpp0000644000176000001440000007641212176655102024267 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup eglue_core //! @{ #undef arma_applier_1u #undef arma_applier_1a #undef arma_applier_2 #undef arma_applier_3 #undef operatorA #undef operatorB #define arma_applier_1u(operatorA, operatorB) \ {\ uword i,j;\ \ for(i=0, j=1; j template arma_hot inline void eglue_core::apply(Mat& out, const eGlue& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() eT* out_mem = out.memptr(); if(prefer_at_accessor == false) { const uword n_elem = (Proxy::is_fixed || Proxy::is_fixed) ? x.get_n_elem() : out.n_elem; //if( memory::is_aligned(out_mem) ) if( memory::is_aligned(out_mem) && ((Proxy::is_fixed && Proxy::is_fixed) ? (x.get_n_elem() >= 32) : true) ) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename Proxy::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename Proxy::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(=, +); } else if(is_same_type::yes) { arma_applier_1a(=, -); } else if(is_same_type::yes) { arma_applier_1a(=, /); } else if(is_same_type::yes) { arma_applier_1a(=, *); } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(=, +); } else if(is_same_type::yes) { arma_applier_1u(=, -); } else if(is_same_type::yes) { arma_applier_1u(=, /); } else if(is_same_type::yes) { arma_applier_1u(=, *); } } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(=, +); } else if(is_same_type::yes) { arma_applier_1u(=, -); } else if(is_same_type::yes) { arma_applier_1u(=, /); } else if(is_same_type::yes) { arma_applier_1u(=, *); } } } else { const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const Proxy& P1 = x.P1; const Proxy& P2 = x.P2; if(is_same_type::yes) { arma_applier_2(=, +); } else if(is_same_type::yes) { arma_applier_2(=, -); } else if(is_same_type::yes) { arma_applier_2(=, /); } else if(is_same_type::yes) { arma_applier_2(=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_plus(Mat& out, const eGlue& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addition"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = (Proxy::is_fixed || Proxy::is_fixed) ? x.get_n_elem() : out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename Proxy::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename Proxy::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(+=, +); } else if(is_same_type::yes) { arma_applier_1a(+=, -); } else if(is_same_type::yes) { arma_applier_1a(+=, /); } else if(is_same_type::yes) { arma_applier_1a(+=, *); } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(+=, +); } else if(is_same_type::yes) { arma_applier_1u(+=, -); } else if(is_same_type::yes) { arma_applier_1u(+=, /); } else if(is_same_type::yes) { arma_applier_1u(+=, *); } } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(+=, +); } else if(is_same_type::yes) { arma_applier_1u(+=, -); } else if(is_same_type::yes) { arma_applier_1u(+=, /); } else if(is_same_type::yes) { arma_applier_1u(+=, *); } } } else { const Proxy& P1 = x.P1; const Proxy& P2 = x.P2; if(is_same_type::yes) { arma_applier_2(+=, +); } else if(is_same_type::yes) { arma_applier_2(+=, -); } else if(is_same_type::yes) { arma_applier_2(+=, /); } else if(is_same_type::yes) { arma_applier_2(+=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_minus(Mat& out, const eGlue& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subtraction"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = (Proxy::is_fixed || Proxy::is_fixed) ? x.get_n_elem() : out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename Proxy::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename Proxy::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(-=, +); } else if(is_same_type::yes) { arma_applier_1a(-=, -); } else if(is_same_type::yes) { arma_applier_1a(-=, /); } else if(is_same_type::yes) { arma_applier_1a(-=, *); } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(-=, +); } else if(is_same_type::yes) { arma_applier_1u(-=, -); } else if(is_same_type::yes) { arma_applier_1u(-=, /); } else if(is_same_type::yes) { arma_applier_1u(-=, *); } } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(-=, +); } else if(is_same_type::yes) { arma_applier_1u(-=, -); } else if(is_same_type::yes) { arma_applier_1u(-=, /); } else if(is_same_type::yes) { arma_applier_1u(-=, *); } } } else { const Proxy& P1 = x.P1; const Proxy& P2 = x.P2; if(is_same_type::yes) { arma_applier_2(-=, +); } else if(is_same_type::yes) { arma_applier_2(-=, -); } else if(is_same_type::yes) { arma_applier_2(-=, /); } else if(is_same_type::yes) { arma_applier_2(-=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_schur(Mat& out, const eGlue& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise multiplication"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = (Proxy::is_fixed || Proxy::is_fixed) ? x.get_n_elem() : out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename Proxy::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename Proxy::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(*=, +); } else if(is_same_type::yes) { arma_applier_1a(*=, -); } else if(is_same_type::yes) { arma_applier_1a(*=, /); } else if(is_same_type::yes) { arma_applier_1a(*=, *); } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(*=, +); } else if(is_same_type::yes) { arma_applier_1u(*=, -); } else if(is_same_type::yes) { arma_applier_1u(*=, /); } else if(is_same_type::yes) { arma_applier_1u(*=, *); } } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(*=, +); } else if(is_same_type::yes) { arma_applier_1u(*=, -); } else if(is_same_type::yes) { arma_applier_1u(*=, /); } else if(is_same_type::yes) { arma_applier_1u(*=, *); } } } else { const Proxy& P1 = x.P1; const Proxy& P2 = x.P2; if(is_same_type::yes) { arma_applier_2(*=, +); } else if(is_same_type::yes) { arma_applier_2(*=, -); } else if(is_same_type::yes) { arma_applier_2(*=, /); } else if(is_same_type::yes) { arma_applier_2(*=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_div(Mat& out, const eGlue& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise division"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = (Proxy::is_fixed || Proxy::is_fixed) ? x.get_n_elem() : out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename Proxy::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename Proxy::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(/=, +); } else if(is_same_type::yes) { arma_applier_1a(/=, -); } else if(is_same_type::yes) { arma_applier_1a(/=, /); } else if(is_same_type::yes) { arma_applier_1a(/=, *); } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(/=, +); } else if(is_same_type::yes) { arma_applier_1u(/=, -); } else if(is_same_type::yes) { arma_applier_1u(/=, /); } else if(is_same_type::yes) { arma_applier_1u(/=, *); } } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(/=, +); } else if(is_same_type::yes) { arma_applier_1u(/=, -); } else if(is_same_type::yes) { arma_applier_1u(/=, /); } else if(is_same_type::yes) { arma_applier_1u(/=, *); } } } else { const Proxy& P1 = x.P1; const Proxy& P2 = x.P2; if(is_same_type::yes) { arma_applier_2(/=, +); } else if(is_same_type::yes) { arma_applier_2(/=, -); } else if(is_same_type::yes) { arma_applier_2(/=, /); } else if(is_same_type::yes) { arma_applier_2(/=, *); } } } // // cubes template template arma_hot inline void eglue_core::apply(Cube& out, const eGlueCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); // NOTE: we're assuming that the cube has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Cube contructor or operator=() eT* out_mem = out.memptr(); if(prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename ProxyCube::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename ProxyCube::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(=, +); } else if(is_same_type::yes) { arma_applier_1a(=, -); } else if(is_same_type::yes) { arma_applier_1a(=, /); } else if(is_same_type::yes) { arma_applier_1a(=, *); } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(=, +); } else if(is_same_type::yes) { arma_applier_1u(=, -); } else if(is_same_type::yes) { arma_applier_1u(=, /); } else if(is_same_type::yes) { arma_applier_1u(=, *); } } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(=, +); } else if(is_same_type::yes) { arma_applier_1u(=, -); } else if(is_same_type::yes) { arma_applier_1u(=, /); } else if(is_same_type::yes) { arma_applier_1u(=, *); } } } else { const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); const ProxyCube& P1 = x.P1; const ProxyCube& P2 = x.P2; if(is_same_type::yes) { arma_applier_3(=, +); } else if(is_same_type::yes) { arma_applier_3(=, -); } else if(is_same_type::yes) { arma_applier_3(=, /); } else if(is_same_type::yes) { arma_applier_3(=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_plus(Cube& out, const eGlueCube& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename ProxyCube::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename ProxyCube::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(+=, +); } else if(is_same_type::yes) { arma_applier_1a(+=, -); } else if(is_same_type::yes) { arma_applier_1a(+=, /); } else if(is_same_type::yes) { arma_applier_1a(+=, *); } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(+=, +); } else if(is_same_type::yes) { arma_applier_1u(+=, -); } else if(is_same_type::yes) { arma_applier_1u(+=, /); } else if(is_same_type::yes) { arma_applier_1u(+=, *); } } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(+=, +); } else if(is_same_type::yes) { arma_applier_1u(+=, -); } else if(is_same_type::yes) { arma_applier_1u(+=, /); } else if(is_same_type::yes) { arma_applier_1u(+=, *); } } } else { const ProxyCube& P1 = x.P1; const ProxyCube& P2 = x.P2; if(is_same_type::yes) { arma_applier_3(+=, +); } else if(is_same_type::yes) { arma_applier_3(+=, -); } else if(is_same_type::yes) { arma_applier_3(+=, /); } else if(is_same_type::yes) { arma_applier_3(+=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_minus(Cube& out, const eGlueCube& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename ProxyCube::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename ProxyCube::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(-=, +); } else if(is_same_type::yes) { arma_applier_1a(-=, -); } else if(is_same_type::yes) { arma_applier_1a(-=, /); } else if(is_same_type::yes) { arma_applier_1a(-=, *); } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(-=, +); } else if(is_same_type::yes) { arma_applier_1u(-=, -); } else if(is_same_type::yes) { arma_applier_1u(-=, /); } else if(is_same_type::yes) { arma_applier_1u(-=, *); } } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(-=, +); } else if(is_same_type::yes) { arma_applier_1u(-=, -); } else if(is_same_type::yes) { arma_applier_1u(-=, /); } else if(is_same_type::yes) { arma_applier_1u(-=, *); } } } else { const ProxyCube& P1 = x.P1; const ProxyCube& P2 = x.P2; if(is_same_type::yes) { arma_applier_3(-=, +); } else if(is_same_type::yes) { arma_applier_3(-=, -); } else if(is_same_type::yes) { arma_applier_3(-=, /); } else if(is_same_type::yes) { arma_applier_3(-=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_schur(Cube& out, const eGlueCube& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename ProxyCube::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename ProxyCube::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(*=, +); } else if(is_same_type::yes) { arma_applier_1a(*=, -); } else if(is_same_type::yes) { arma_applier_1a(*=, /); } else if(is_same_type::yes) { arma_applier_1a(*=, *); } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(*=, +); } else if(is_same_type::yes) { arma_applier_1u(*=, -); } else if(is_same_type::yes) { arma_applier_1u(*=, /); } else if(is_same_type::yes) { arma_applier_1u(*=, *); } } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(*=, +); } else if(is_same_type::yes) { arma_applier_1u(*=, -); } else if(is_same_type::yes) { arma_applier_1u(*=, /); } else if(is_same_type::yes) { arma_applier_1u(*=, *); } } } else { const ProxyCube& P1 = x.P1; const ProxyCube& P2 = x.P2; if(is_same_type::yes) { arma_applier_3(*=, +); } else if(is_same_type::yes) { arma_applier_3(*=, -); } else if(is_same_type::yes) { arma_applier_3(*=, /); } else if(is_same_type::yes) { arma_applier_3(*=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_div(Cube& out, const eGlueCube& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename ProxyCube::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename ProxyCube::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(/=, +); } else if(is_same_type::yes) { arma_applier_1a(/=, -); } else if(is_same_type::yes) { arma_applier_1a(/=, /); } else if(is_same_type::yes) { arma_applier_1a(/=, *); } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(/=, +); } else if(is_same_type::yes) { arma_applier_1u(/=, -); } else if(is_same_type::yes) { arma_applier_1u(/=, /); } else if(is_same_type::yes) { arma_applier_1u(/=, *); } } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(/=, +); } else if(is_same_type::yes) { arma_applier_1u(/=, -); } else if(is_same_type::yes) { arma_applier_1u(/=, /); } else if(is_same_type::yes) { arma_applier_1u(/=, *); } } } else { const ProxyCube& P1 = x.P1; const ProxyCube& P2 = x.P2; if(is_same_type::yes) { arma_applier_3(/=, +); } else if(is_same_type::yes) { arma_applier_3(/=, -); } else if(is_same_type::yes) { arma_applier_3(/=, /); } else if(is_same_type::yes) { arma_applier_3(/=, *); } } } #undef arma_applier_1u #undef arma_applier_1a #undef arma_applier_2 #undef arma_applier_3 //! @} RcppArmadillo/inst/include/armadillo_bits/fn_lu.hpp0000644000176000001440000000337412200375542022243 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_lu //! @{ //! immediate lower upper decomposition, permutation info is embedded into L (similar to Matlab/Octave) template inline bool lu ( Mat& L, Mat& U, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( (&L == &U), "lu(): L and U are the same object"); const bool status = auxlib::lu(L, U, X); if(status == false) { L.reset(); U.reset(); arma_bad("lu(): failed to converge", false); } return status; } //! immediate lower upper decomposition, also providing the permutation matrix template inline bool lu ( Mat& L, Mat& U, Mat& P, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( ( (&L == &U) || (&L == &P) || (&U == &P) ), "lu(): two or more output objects are the same object"); const bool status = auxlib::lu(L, U, P, X); if(status == false) { L.reset(); U.reset(); P.reset(); arma_bad("lu(): failed to converge", false); } return status; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_sort_bones.hpp0000644000176000001440000000160312200631217023776 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_sort //! @{ class op_sort { public: template inline static void copy_row(eT* X, const Mat& A, const uword row); template inline static void copy_row(Mat& A, const eT* X, const uword row); template inline static void direct_sort(eT* X, const uword N, const uword sort_type = 0); template inline static void direct_sort_ascending(eT* X, const uword N); template inline static void apply(Mat& out, const Op& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/mtGlue_meat.hpp0000644000176000001440000000174112202101406023363 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup mtGlue //! @{ template inline mtGlue::mtGlue(const T1& in_A, const T2& in_B) : A(in_A) , B(in_B) { arma_extra_debug_sigprint(); } template inline mtGlue::mtGlue(const T1& in_A, const T2& in_B, const uword in_aux_uword) : A(in_A) , B(in_B) , aux_uword(in_aux_uword) { arma_extra_debug_sigprint(); } template inline mtGlue::~mtGlue() { arma_extra_debug_sigprint(); } //! @} RcppArmadillo/inst/include/armadillo_bits/forward_bones.hpp0000644000176000001440000001426612221176567024005 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. using std::cout; using std::cerr; using std::endl; using std::ios; template struct Base; template struct BaseCube; template class Mat; template class Col; template class Row; template class Cube; template class xvec_htrans; template class field; template class subview; template class subview_col; template class subview_row; template class subview_row_strans; template class subview_row_htrans; template class subview_cube; template class subview_field; template class SpValProxy; template class SpMat; template class SpCol; template class SpRow; template class SpSubview; template class diagview; template class subview_elem1; template class subview_elem2; template class subview_each1; template class subview_each2; class SizeMat; class SizeCube; class arma_empty_class {}; class diskio; class op_min; class op_max; class op_strans; class op_htrans; class op_htrans2; class op_inv; class op_sum; class op_abs; class op_diagmat; class op_trimat; class op_diagvec; class op_vectorise_col; class eop_conj; class glue_times; class glue_times_diag; class glue_rel_lt; class glue_rel_gt; class glue_rel_lteq; class glue_rel_gteq; class glue_rel_eq; class glue_rel_noteq; class op_rel_lt_pre; class op_rel_lt_post; class op_rel_gt_pre; class op_rel_gt_post; class op_rel_lteq_pre; class op_rel_lteq_post; class op_rel_gteq_pre; class op_rel_gteq_post; class op_rel_eq; class op_rel_noteq; class gen_ones_diag; class gen_ones_full; class gen_zeros; class gen_randu; class gen_randn; class glue_mixed_plus; class glue_mixed_minus; class glue_mixed_div; class glue_mixed_schur; class glue_mixed_times; class op_cx_scalar_times; class op_cx_scalar_plus; class op_cx_scalar_minus_pre; class op_cx_scalar_minus_post; class op_cx_scalar_div_pre; class op_cx_scalar_div_post; class op_subview_elem_equ; class op_subview_elem_inplace_plus; class op_subview_elem_inplace_minus; class op_subview_elem_inplace_schur; class op_subview_elem_inplace_div; template class gemm; template class gemv; template< typename eT, typename gen_type> class Gen; template< typename T1, typename op_type> class Op; template< typename T1, typename eop_type> class eOp; template class mtOp; template< typename T1, typename T2, typename glue_type> class Glue; template< typename T1, typename T2, typename eglue_type> class eGlue; template class mtGlue; template< typename eT, typename gen_type> class GenCube; template< typename T1, typename op_type> class OpCube; template< typename T1, typename eop_type> class eOpCube; template class mtOpCube; template< typename T1, typename T2, typename glue_type> class GlueCube; template< typename T1, typename T2, typename eglue_type> class eGlueCube; template class mtGlueCube; template class Proxy; template class ProxyCube; class spop_strans; class spop_htrans; class spop_scalar_times; class spglue_plus; class spglue_plus2; class spglue_minus; class spglue_minus2; class spglue_times; class spglue_times2; template< typename T1, typename spop_type> class SpOp; template class mtSpOp; template class SpGlue; template class SpProxy; struct arma_vec_indicator {}; struct arma_fixed_indicator {}; //! \addtogroup injector //! @{ template struct injector_end_of_row {}; static const injector_end_of_row<> endr = injector_end_of_row<>(); //!< endr indicates "end of row" when using the << operator; //!< similar conceptual meaning to std::endl //! @} //! \addtogroup diskio //! @{ enum file_type { file_type_unknown, auto_detect, //!< Automatically detect the file type raw_ascii, //!< ASCII format (text), without any other information. arma_ascii, //!< Armadillo ASCII format (text), with information about matrix type and size csv_ascii, //!< comma separated values (CSV), without any other information raw_binary, //!< raw binary format, without any other information. arma_binary, //!< Armadillo binary format, with information about matrix type and size pgm_binary, //!< Portable Grey Map (greyscale image) ppm_binary, //!< Portable Pixel Map (colour image), used by the field and cube classes hdf5_binary, //!< Open binary format, not specific to Armadillo, which can store arbitrary data coord_ascii //!< simple co-ordinate format for sparse matrices }; //! @} //! \addtogroup fill //! @{ namespace fill { struct fill_none {}; struct fill_zeros {}; struct fill_ones {}; struct fill_eye {}; struct fill_randu {}; struct fill_randn {}; template struct fill_class { inline fill_class() {} }; static const fill_class none; static const fill_class zeros; static const fill_class ones; static const fill_class eye; static const fill_class randu; static const fill_class randn; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_var_meat.hpp0000644000176000001440000001530012200631217023416 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_var //! @{ //! \brief //! For each row or for each column, find the variance. //! The result is stored in a dense matrix that has either one column or one row. //! The dimension, for which the variances are found, is set via the var() function. template inline void op_var::apply(Mat& out, const mtOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type in_eT; typedef typename T1::pod_type out_eT; const unwrap_check_mixed tmp(in.m, out); const Mat& X = tmp.M; const uword norm_type = in.aux_uword_a; const uword dim = in.aux_uword_b; arma_debug_check( (norm_type > 1), "var(): incorrect usage. norm_type must be 0 or 1"); arma_debug_check( (dim > 1), "var(): incorrect usage. dim must be 0 or 1" ); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_var::apply(), dim = 0"); arma_debug_check( (X_n_rows == 0), "var(): given object has zero rows" ); out.set_size(1, X_n_cols); out_eT* out_mem = out.memptr(); for(uword col=0; col dat(X_n_cols); in_eT* dat_mem = dat.memptr(); out_eT* out_mem = out.memptr(); for(uword row=0; row inline typename T1::pod_type op_var::var_vec(const Base& X, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; arma_debug_check( (norm_type > 1), "var(): incorrect usage. norm_type must be 0 or 1"); const Proxy P(X.get_ref()); const podarray tmp(P); return op_var::direct_var(tmp.memptr(), tmp.n_elem, norm_type); } template inline typename get_pod_type::result op_var::var_vec(const subview_col& X, const uword norm_type) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "var(): incorrect usage. norm_type must be 0 or 1"); return op_var::direct_var(X.colptr(0), X.n_rows, norm_type); } template inline typename get_pod_type::result op_var::var_vec(const subview_row& X, const uword norm_type) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "var(): incorrect usage. norm_type must be 0 or 1"); const Mat& A = X.m; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_col_p1 = start_col + X.n_cols; podarray tmp(X.n_elem); eT* tmp_mem = tmp.memptr(); for(uword i=0, col=start_col; col < end_col_p1; ++col, ++i) { tmp_mem[i] = A.at(start_row, col); } return op_var::direct_var(tmp.memptr(), tmp.n_elem, norm_type); } //! find the variance of an array template inline eT op_var::direct_var(const eT* const X, const uword n_elem, const uword norm_type) { arma_extra_debug_sigprint(); if(n_elem >= 2) { const eT acc1 = op_mean::direct_mean(X, n_elem); eT acc2 = eT(0); eT acc3 = eT(0); uword i,j; for(i=0, j=1; j inline eT op_var::direct_var_robust(const eT* const X, const uword n_elem, const uword norm_type) { arma_extra_debug_sigprint(); if(n_elem > 1) { eT r_mean = X[0]; eT r_var = eT(0); for(uword i=1; i inline T op_var::direct_var(const std::complex* const X, const uword n_elem, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(n_elem >= 2) { const eT acc1 = op_mean::direct_mean(X, n_elem); T acc2 = T(0); eT acc3 = eT(0); for(uword i=0; i inline T op_var::direct_var_robust(const std::complex* const X, const uword n_elem, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(n_elem > 1) { eT r_mean = X[0]; T r_var = T(0); for(uword i=1; i inline obj_type randi(const uword n_rows, const uword n_cols, const distr_param& param = distr_param(), const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename obj_type::elem_type eT; if(is_Col::value == true) { arma_debug_check( (n_cols != 1), "randi(): incompatible size" ); } else if(is_Row::value == true) { arma_debug_check( (n_rows != 1), "randi(): incompatible size" ); } obj_type out(n_rows, n_cols); int a; int b; if(param.state == 0) { a = 0; b = arma_rng::randi::max_val(); } else if(param.state == 1) { a = param.a_int; b = param.b_int; } else { a = int(param.a_double); b = int(param.b_double); } arma_debug_check( (a > b), "randi(): incorrect distribution parameters: a must be less than b" ); arma_rng::randi::fill(out.memptr(), out.n_elem, a, b); return out; } template inline obj_type randi(const uword n_elem, const distr_param& param = distr_param(), const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only::result* junk2 = 0) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_Row::value == true) { return randi(1, n_elem, param); } else { return randi(n_elem, 1, param); } } inline imat randi(const uword n_rows, const uword n_cols, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randi(n_rows, n_cols, param); } inline ivec randi(const uword n_elem, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randi(n_elem, param); } template inline cube_type randi(const uword n_rows, const uword n_cols, const uword n_slices, const distr_param& param = distr_param(), const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename cube_type::elem_type eT; cube_type out(n_rows, n_cols, n_slices); int a; int b; if(param.state == 0) { a = 0; b = arma_rng::randi::max_val(); } else if(param.state == 1) { a = param.a_int; b = param.b_int; } else { a = int(param.a_double); b = int(param.b_double); } arma_debug_check( (a > b), "randi(): incorrect distribution parameters: a must be less than b" ); arma_rng::randi::fill(out.memptr(), out.n_elem, a, b); return out; } inline icube randi(const uword n_rows, const uword n_cols, const uword n_slices, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randi(n_rows, n_cols, n_slices, param); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_pinv.hpp0000644000176000001440000000274212252070123022567 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_pinv //! @{ template inline const Op pinv ( const Base& X, const typename T1::elem_type tol = 0.0, const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'd')), "pinv(): unknown method specified" ); return (sig == 'd') ? Op(X.get_ref(), tol, 1, 0) : Op(X.get_ref(), tol, 0, 0); } template inline bool pinv ( Mat& out, const Base& X, const typename T1::elem_type tol = 0.0, const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = pinv(X, tol, method); } catch(std::runtime_error&) { return false; } return true; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_find_bones.hpp0000644000176000001440000000375112200631217023735 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // Copyright (C) 2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_find //! @{ class op_find { public: template inline static uword helper ( Mat& indices, const Base& X ); template inline static uword helper ( Mat& indices, const mtOp& X, const typename arma_op_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0 ); template inline static uword helper ( Mat& indices, const mtOp& X, const typename arma_op_rel_only::result junk1 = 0, const typename arma_cx_only::result junk2 = 0 ); template inline static uword helper ( Mat& indices, const mtGlue& X, const typename arma_glue_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0, const typename arma_not_cx::result junk3 = 0 ); template inline static uword helper ( Mat& indices, const mtGlue& X, const typename arma_glue_rel_only::result junk1 = 0, const typename arma_cx_only::result junk2 = 0, const typename arma_cx_only::result junk3 = 0 ); template inline static void apply(Mat& out, const mtOp& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_diagvec.hpp0000644000176000001440000000123512200375542023217 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_diagvec //! @{ //! extract a diagonal from a matrix template arma_inline const Op diagvec(const Base& X, const sword diag_id = 0) { arma_extra_debug_sigprint(); return Op(X.get_ref(), ((diag_id < 0) ? -diag_id : diag_id), ((diag_id < 0) ? 1 : 0) ); } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_relational_meat.hpp0000644000176000001440000001510112200375542025303 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_relational //! @{ #undef operator_rel #undef operator_str #undef arma_applier_mat #undef arma_applier_cube #define arma_applier_mat(operator_rel, operator_str) \ {\ const Proxy P1(X.A);\ const Proxy P2(X.B);\ \ arma_debug_assert_same_size(P1, P2, operator_str);\ \ const bool bad_alias = (Proxy::has_subview && P1.is_alias(out)) || (Proxy::has_subview && P2.is_alias(out));\ \ if(bad_alias == false)\ {\ \ const uword n_rows = P1.get_n_rows();\ const uword n_cols = P1.get_n_cols();\ \ out.set_size(n_rows, n_cols);\ \ uword* out_mem = out.memptr();\ \ const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor);\ \ if(prefer_at_accessor == false)\ {\ typename Proxy::ea_type A = P1.get_ea();\ typename Proxy::ea_type B = P2.get_ea();\ \ const uword n_elem = out.n_elem;\ \ for(uword i=0; i::stored_type> tmp1(P1.Q, P1.is_alias(out));\ const unwrap_check::stored_type> tmp2(P2.Q, P2.is_alias(out));\ \ out = (tmp1.M) operator_rel (tmp2.M);\ }\ } #define arma_applier_cube(operator_rel, operator_str) \ {\ const ProxyCube P1(X.A);\ const ProxyCube P2(X.B);\ \ arma_debug_assert_same_size(P1, P2, operator_str);\ \ const bool bad_alias = (ProxyCube::has_subview && P1.is_alias(out)) || (ProxyCube::has_subview && P2.is_alias(out));\ \ if(bad_alias == false)\ {\ \ const uword n_rows = P1.get_n_rows();\ const uword n_cols = P1.get_n_cols();\ const uword n_slices = P1.get_n_slices();\ \ out.set_size(n_rows, n_cols, n_slices);\ \ uword* out_mem = out.memptr();\ \ const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor);\ \ if(prefer_at_accessor == false)\ {\ typename ProxyCube::ea_type A = P1.get_ea();\ typename ProxyCube::ea_type B = P2.get_ea();\ \ const uword n_elem = out.n_elem;\ \ for(uword i=0; i::stored_type> tmp1(P1.Q);\ const unwrap_cube::stored_type> tmp2(P2.Q);\ \ out = (tmp1.M) operator_rel (tmp2.M);\ }\ } template inline void glue_rel_lt::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(<, "operator<"); } template inline void glue_rel_gt::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(>, "operator>"); } template inline void glue_rel_lteq::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(<=, "operator<="); } template inline void glue_rel_gteq::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(>=, "operator>="); } template inline void glue_rel_eq::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(==, "operator=="); } template inline void glue_rel_noteq::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(!=, "operator!="); } // // // template inline void glue_rel_lt::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(<, "operator<"); } template inline void glue_rel_gt::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(>, "operator>"); } template inline void glue_rel_lteq::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(<=, "operator<="); } template inline void glue_rel_gteq::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(>=, "operator>="); } template inline void glue_rel_eq::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(==, "operator=="); } template inline void glue_rel_noteq::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(!=, "operator!="); } #undef arma_applier_mat #undef arma_applier_cube //! @} RcppArmadillo/inst/include/armadillo_bits/fn_reshape.hpp0000644000176000001440000000213212200375542023241 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_reshape //! @{ template inline const Op reshape(const Base& X, const uword in_n_rows, const uword in_n_cols, const uword dim = 0) { arma_extra_debug_sigprint(); arma_debug_check( (dim > 1), "reshape(): dim must be 0 or 1"); return Op(X.get_ref(), in_n_rows, in_n_cols, dim, 'j'); } template inline const OpCube reshape(const BaseCube& X, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices, const uword dim = 0) { arma_extra_debug_sigprint(); arma_debug_check( (dim > 1), "reshape(): dim must be 0 or 1"); return OpCube(X.get_ref(), in_n_rows, in_n_cols, in_n_slices, dim, 'j'); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_diagmat_bones.hpp0000644000176000001440000000077012200631217024421 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_diagmat //! @{ class op_diagmat { public: template inline static void apply(Mat& out, const Op& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_find.hpp0000644000176000001440000000453712256511734022553 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_find //! @{ template inline const mtOp find(const Base& X, const uword k = 0, const char* direction = "first") { arma_extra_debug_sigprint(); const char sig = direction[0]; arma_debug_check ( ( (sig != 'f') && (sig != 'F') && (sig != 'l') && (sig != 'L') ), "find(): direction must be \"first\" or \"last\"" ); const uword type = ( (sig == 'f') || (sig == 'F') ) ? 0 : 1; return mtOp(X.get_ref(), k, type); } template inline umat find(const BaseCube& X, const uword k = 0, const char* direction = "first") { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube tmp(X.get_ref()); const Mat R( const_cast< eT* >(tmp.M.memptr()), tmp.M.n_elem, 1, false ); return find(R, k, direction); } template inline umat find(const mtOpCube& X, const uword k = 0, const char* direction = "first") { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube tmp(X.m); const Mat R( const_cast< eT* >(tmp.M.memptr()), tmp.M.n_elem, 1, false ); return find( mtOp, op_rel_type>(R, X.aux), k, direction ); } template inline umat find(const mtGlueCube& X, const uword k = 0, const char* direction = "first") { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; const unwrap_cube tmp1(X.A); const unwrap_cube tmp2(X.B); arma_debug_assert_same_size( tmp1.M, tmp2.M, "relational operator" ); const Mat R1( const_cast< eT1* >(tmp1.M.memptr()), tmp1.M.n_elem, 1, false ); const Mat R2( const_cast< eT2* >(tmp2.M.memptr()), tmp2.M.n_elem, 1, false ); return find( mtGlue, Mat, glue_rel_type>(R1, R2), k, direction ); } //! @} RcppArmadillo/inst/include/armadillo_bits/operator_cube_div.hpp0000644000176000001440000000573712177612753024653 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_cube_div //! @{ //! BaseCube / scalar template arma_inline const eOpCube operator/ ( const BaseCube& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! scalar / BaseCube template arma_inline const eOpCube operator/ ( const typename T1::elem_type k, const BaseCube& X ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! complex scalar / non-complex BaseCube (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_div_pre> operator/ ( const std::complex& k, const BaseCube& X ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_div_pre>('j', X.get_ref(), k); } //! non-complex BaseCube / complex scalar (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_div_post> operator/ ( const BaseCube& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_div_post>('j', X.get_ref(), k); } //! element-wise division of BaseCube objects with same element type template arma_inline const eGlueCube operator/ ( const BaseCube& X, const BaseCube& Y ) { arma_extra_debug_sigprint(); return eGlueCube(X.get_ref(), Y.get_ref()); } //! element-wise division of BaseCube objects with different element types template inline const mtGlueCube::result, T1, T2, glue_mixed_div> operator/ ( const BaseCube< typename force_different_type::T1_result, T1>& X, const BaseCube< typename force_different_type::T2_result, T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_inplace_trans.hpp0000644000176000001440000000354512260751214024445 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_inplace_trans //! @{ template inline typename enable_if2 < is_cx::no, void >::result inplace_htrans ( Mat& X, const char* method = "std" ) { arma_extra_debug_sigprint(); inplace_strans(X, method); } template inline typename enable_if2 < is_cx::yes, void >::result inplace_htrans ( Mat& X, const char* method = "std" ) { arma_extra_debug_sigprint(); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'l')), "inplace_htrans(): unknown method specified" ); const bool low_memory = (sig == 'l'); if( (low_memory == false) || (X.n_rows == X.n_cols) ) { op_htrans::apply_mat_inplace(X); } else { inplace_strans(X, method); X = conj(X); } } template inline typename enable_if2 < is_cx::no, void >::result inplace_trans ( Mat& X, const char* method = "std" ) { arma_extra_debug_sigprint(); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'l')), "inplace_trans(): unknown method specified" ); inplace_strans(X, method); } template inline typename enable_if2 < is_cx::yes, void >::result inplace_trans ( Mat& X, const char* method = "std" ) { arma_extra_debug_sigprint(); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'l')), "inplace_trans(): unknown method specified" ); inplace_htrans(X, method); } //! @} RcppArmadillo/inst/include/armadillo_bits/spop_misc_bones.hpp0000644000176000001440000000223412111344723024312 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_misc //! @{ class spop_scalar_times { public: template arma_hot inline static void apply(SpMat& out, const SpOp& in); }; class spop_square { public: template arma_hot inline static void apply(SpMat& out, const SpOp& in); }; class spop_sqrt { public: template arma_hot inline static void apply(SpMat& out, const SpOp& in); }; class spop_abs { public: template arma_hot inline static void apply(SpMat& out, const SpOp& in); }; class spop_cx_abs { public: template arma_hot inline static void apply(SpMat& out, const mtSpOp& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/Op_meat.hpp0000644000176000001440000000322112176655102022520 0ustar ripleyusers// Copyright (C) 2008-2011 Conrad Sanderson // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Op //! @{ template inline Op::Op(const T1& in_m) : m(in_m) { arma_extra_debug_sigprint(); } template inline Op::Op(const T1& in_m, const typename T1::elem_type in_aux) : m(in_m) , aux(in_aux) { arma_extra_debug_sigprint(); } template inline Op::Op(const T1& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux(in_aux) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline Op::Op(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline Op::Op(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c, const char) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) { arma_extra_debug_sigprint(); } template inline Op::~Op() { arma_extra_debug_sigprint(); } //! @} RcppArmadillo/inst/include/armadillo_bits/operator_ostream.hpp0000644000176000001440000000342712257214264024531 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_ostream //! @{ template inline std::ostream& operator<< (std::ostream& o, const Base& X) { arma_extra_debug_sigprint(); const unwrap tmp(X.get_ref()); arma_ostream::print(o, tmp.M, true); return o; } template inline std::ostream& operator<< (std::ostream& o, const SpBase& X) { arma_extra_debug_sigprint(); const unwrap_spmat tmp(X.get_ref()); arma_ostream::print(o, tmp.M, true); return o; } template inline std::ostream& operator<< (std::ostream& o, const SpValProxy& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; o << eT(X); return o; } template inline std::ostream& operator<< (std::ostream& o, const BaseCube& X) { arma_extra_debug_sigprint(); const unwrap_cube tmp(X.get_ref()); arma_ostream::print(o, tmp.M, true); return o; } //! Print the contents of a field to the specified stream. template inline std::ostream& operator<< (std::ostream& o, const field& X) { arma_extra_debug_sigprint(); arma_ostream::print(o, X); return o; } //! Print the contents of a subfield to the specified stream template inline std::ostream& operator<< (std::ostream& o, const subview_field& X) { arma_extra_debug_sigprint(); arma_ostream::print(o, X); return o; } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_eye.hpp0000644000176000001440000000206312233362710022376 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_eye //! @{ arma_inline const Gen eye(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return Gen(n_rows, n_cols); } template arma_inline const Gen eye(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_Col::value == true) { arma_debug_check( (n_cols != 1), "eye(): incompatible size" ); } else if(is_Row::value == true) { arma_debug_check( (n_rows != 1), "eye(): incompatible size" ); } return Gen(n_rows, n_cols); } //! @} RcppArmadillo/inst/include/armadillo_bits/op_any_meat.hpp0000644000176000001440000002134612200700172023421 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_any //! @{ template inline bool op_any::any_vec_helper(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i inline bool op_any::any_vec_helper ( const mtOp& X, const typename arma_op_rel_only::result junk1, const typename arma_not_cx::result junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); typedef typename T1::elem_type eT; const eT val = X.aux; const Proxy P(X.m); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); const uword n_elem = P.get_n_elem(); for(uword i=0; i < n_elem; ++i) { const eT tmp = Pea[i]; if(is_same_type::yes) { if(val < tmp) { return true; } } else if(is_same_type::yes) { if(tmp < val) { return true; } } else if(is_same_type::yes) { if(val > tmp) { return true; } } else if(is_same_type::yes) { if(tmp > val) { return true; } } else if(is_same_type::yes) { if(val <= tmp) { return true; } } else if(is_same_type::yes) { if(tmp <= val) { return true; } } else if(is_same_type::yes) { if(val >= tmp) { return true; } } else if(is_same_type::yes) { if(tmp >= val) { return true; } } else if(is_same_type::yes) { if(tmp == val) { return true; } } else if(is_same_type::yes) { if(tmp != val) { return true; } } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT tmp = P.at(row,col); if(is_same_type::yes) { if(val < tmp) { return true; } } else if(is_same_type::yes) { if(tmp < val) { return true; } } else if(is_same_type::yes) { if(val > tmp) { return true; } } else if(is_same_type::yes) { if(tmp > val) { return true; } } else if(is_same_type::yes) { if(val <= tmp) { return true; } } else if(is_same_type::yes) { if(tmp <= val) { return true; } } else if(is_same_type::yes) { if(val >= tmp) { return true; } } else if(is_same_type::yes) { if(tmp >= val) { return true; } } else if(is_same_type::yes) { if(tmp == val) { return true; } } else if(is_same_type::yes) { if(tmp != val) { return true; } } } } return false; } template inline bool op_any::any_vec_helper ( const mtGlue& X, const typename arma_glue_rel_only::result junk1, const typename arma_not_cx::result junk2, const typename arma_not_cx::result junk3 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); arma_ignore(junk3); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "relational operator"); const bool prefer_at_accessor = Proxy::prefer_at_accessor || Proxy::prefer_at_accessor; if(prefer_at_accessor == false) { ea_type1 PA = A.get_ea(); ea_type2 PB = B.get_ea(); const uword n_elem = A.get_n_elem(); for(uword i=0; i::yes) { if(tmp1 < tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 > tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 <= tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 >= tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 == tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 != tmp2) { return true; } } } } else { const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT1 tmp1 = A.at(row,col); const eT2 tmp2 = B.at(row,col); if(is_same_type::yes) { if(tmp1 < tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 > tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 <= tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 >= tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 == tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 != tmp2) { return true; } } } } return false; } template inline bool op_any::any_vec(T1& X) { arma_extra_debug_sigprint(); return op_any::any_vec_helper(X); } template inline void op_any::apply_helper(Mat& out, const Proxy& P, const uword dim) { arma_extra_debug_sigprint(); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); typedef typename Proxy::elem_type eT; if(dim == 0) // traverse rows (ie. process each column) { out.zeros(1, n_cols); uword* out_mem = out.memptr(); if(is_Mat::stored_type>::value == true) { const unwrap::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); for(uword row=0; row < n_rows; ++row) { if(colmem[row] != eT(0)) { out_mem[col] = uword(1); break; } } } } else { for(uword col=0; col < n_cols; ++col) { for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { out_mem[col] = uword(1); break; } } } } } else { out.zeros(n_rows, 1); uword* out_mem = out.memptr(); if(is_Mat::stored_type>::value == true) { const unwrap::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); for(uword row=0; row < n_rows; ++row) { if(colmem[row] != eT(0)) { out_mem[row] = uword(1); } } } } else { for(uword col=0; col < n_cols; ++col) { for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { out_mem[row] = uword(1); } } } } } } template inline void op_any::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); const uword dim = X.aux_uword_a; const Proxy P(X.m); if(P.is_alias(out) == false) { op_any::apply_helper(out, P, dim); } else { Mat out2; op_any::apply_helper(out2, P, dim); out.steal_mem(out2); } } //! @} RcppArmadillo/inst/include/armadillo_bits/subview_cube_bones.hpp0000644000176000001440000001057712236716467025031 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup subview_cube //! @{ //! Class for storing data required to construct or apply operations to a subcube //! (i.e. where the subcube starts and ends as well as a reference/pointer to the original cube), template class subview_cube : public BaseCube > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; arma_aligned const Cube& m; const uword aux_row1; const uword aux_col1; const uword aux_slice1; const uword n_rows; const uword n_cols; const uword n_elem_slice; const uword n_slices; const uword n_elem; protected: arma_inline subview_cube(const Cube& in_m, const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices); public: inline ~subview_cube(); inline void operator= (const eT val); inline void operator+= (const eT val); inline void operator-= (const eT val); inline void operator*= (const eT val); inline void operator/= (const eT val); // deliberately returning void template inline void operator= (const BaseCube& x); template inline void operator+= (const BaseCube& x); template inline void operator-= (const BaseCube& x); template inline void operator%= (const BaseCube& x); template inline void operator/= (const BaseCube& x); inline void operator= (const subview_cube& x); inline void operator+= (const subview_cube& x); inline void operator-= (const subview_cube& x); inline void operator%= (const subview_cube& x); inline void operator/= (const subview_cube& x); template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); inline static void extract(Cube& out, const subview_cube& in); inline static void plus_inplace(Cube& out, const subview_cube& in); inline static void minus_inplace(Cube& out, const subview_cube& in); inline static void schur_inplace(Cube& out, const subview_cube& in); inline static void div_inplace(Cube& out, const subview_cube& in); inline static void extract(Mat& out, const subview_cube& in); inline static void plus_inplace(Mat& out, const subview_cube& in); inline static void minus_inplace(Mat& out, const subview_cube& in); inline static void schur_inplace(Mat& out, const subview_cube& in); inline static void div_inplace(Mat& out, const subview_cube& in); template inline void transform(functor F); template inline void imbue(functor F); inline void fill(const eT val); inline void zeros(); inline void ones(); inline void randu(); inline void randn(); inline eT at_alt (const uword i) const; inline eT& operator[](const uword i); inline eT operator[](const uword i) const; inline eT& operator()(const uword i); inline eT operator()(const uword i) const; arma_inline eT& operator()(const uword in_row, const uword in_col, const uword in_slice); arma_inline eT operator()(const uword in_row, const uword in_col, const uword in_slice) const; arma_inline eT& at(const uword in_row, const uword in_col, const uword in_slice); arma_inline eT at(const uword in_row, const uword in_col, const uword in_slice) const; arma_inline eT* slice_colptr(const uword in_slice, const uword in_col); arma_inline const eT* slice_colptr(const uword in_slice, const uword in_col) const; inline bool check_overlap(const subview_cube& x) const; inline bool check_overlap(const Mat& x) const; private: friend class Mat; friend class Cube; subview_cube(); }; //! @} RcppArmadillo/inst/include/armadillo_bits/Op_bones.hpp0000644000176000001440000000504412176655102022705 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Op //! @{ //! Class for storing data required for delayed unary operations, //! such as the operand (e.g. the matrix to which the operation is to be applied) and the unary operator (e.g. inverse). //! The operand is stored as a reference (which can be optimised away), //! while the operator is "stored" through the template definition (op_type). //! The operands can be 'Mat', 'Row', 'Col', 'Op', and 'Glue'. //! Note that as 'Glue' can be one of the operands, more than one matrix can be stored. //! //! For example, we could have: //! Op< Glue< Mat, Mat, glue_times >, op_htrans > template class Op : public Base > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = ( T1::is_col && (is_same_type::value || is_same_type::value || is_same_type::value) ); static const bool is_col = ( T1::is_row && (is_same_type::value || is_same_type::value || is_same_type::value) ) || (is_same_type::value) || (is_same_type::value); inline explicit Op(const T1& in_m); inline Op(const T1& in_m, const elem_type in_aux); inline Op(const T1& in_m, const elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b); inline Op(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline Op(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c, const char junk); inline ~Op(); arma_aligned const T1& m; //!< storage of reference to the operand (eg. a matrix) arma_aligned elem_type aux; //!< storage of auxiliary data, user defined format arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_c; //!< storage of auxiliary data, uword format }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_det.hpp0000644000176000001440000001213212262150201022356 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_det //! @{ //! determinant of mat template inline arma_warn_unused typename T1::elem_type det ( const Base& X, const bool slow = false, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return auxlib::det(X, slow); } template inline arma_warn_unused typename T1::elem_type det ( const Base& X, const char* method, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'f')), "det(): unknown method specified" ); const bool slow = (sig == 's'); return auxlib::det(X, slow); } //! determinant of diagmat template inline arma_warn_unused typename T1::elem_type det ( const Op& X, const bool slow = false ) { arma_extra_debug_sigprint(); arma_ignore(slow); typedef typename T1::elem_type eT; const diagmat_proxy A(X.m); const uword N = A.n_elem; eT val1 = eT(1); eT val2 = eT(1); uword i,j; for(i=0, j=1; j inline arma_warn_unused typename T1::elem_type det ( const Op& X, const char* method ) { arma_extra_debug_sigprint(); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'f')), "det(): unknown method specified" ); return det(X, false); } //! determinant of a triangular matrix template inline arma_warn_unused typename T1::elem_type det ( const Op& X, const bool slow = false ) { arma_extra_debug_sigprint(); arma_ignore(slow); typedef typename T1::elem_type eT; const Proxy P(X.m); const uword N = P.get_n_rows(); arma_debug_check( (N != P.get_n_cols()), "det(): matrix is not square" ); eT val1 = eT(1); eT val2 = eT(1); uword i,j; for(i=0, j=1; j inline arma_warn_unused typename T1::elem_type det ( const Op& X, const char* method ) { arma_extra_debug_sigprint(); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'f')), "det(): unknown method specified" ); return det(X, false); } //! determinant of inv(A), without doing the inverse operation template inline arma_warn_unused typename T1::elem_type det ( const Op& X, const bool slow = false, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const eT tmp = det(X.m, slow); arma_debug_warn( (tmp == eT(0)), "det(): warning: denominator is zero" ); return eT(1) / tmp; } template inline arma_warn_unused typename T1::elem_type det ( const Op& X, const char* method, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'f')), "det(): unknown method specified" ); const bool slow = (sig == 's'); return det(X, slow); } //! determinant of trans(A) template inline arma_warn_unused typename T1::elem_type det ( const Op& in, const bool slow = false, const typename arma_blas_type_only::result* junk1 = 0, const typename arma_not_cx::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return auxlib::det(in.m, slow); // bypass op_htrans } template inline arma_warn_unused typename T1::elem_type det ( const Op& in, const char* method, const typename arma_blas_type_only::result* junk1 = 0, const typename arma_not_cx::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'f')), "det(): unknown method specified" ); const bool slow = (sig == 's'); return auxlib::det(in.m, slow); // bypass op_htrans } template arma_inline arma_warn_unused const typename arma_scalar_only::result & det(const T& x) { return x; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_max_meat.hpp0000644000176000001440000002544712200631217023430 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_max //! @{ //! \brief //! For each row or for each column, find the maximum value. //! The result is stored in a dense matrix that has either one column or one row. //! The dimension, for which the maxima are found, is set via the max() function. template inline void op_max::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "max(): incorrect usage. dim must be 0 or 1"); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_max::apply(), dim = 0"); arma_debug_check( (X_n_rows == 0), "max(): given object has zero rows" ); out.set_size(1, X_n_cols); eT* out_mem = out.memptr(); for(uword col=0; col arma_pure inline eT op_max::direct_max(const eT* const X, const uword n_elem) { arma_extra_debug_sigprint(); eT max_val = priv::most_neg(); uword i,j; for(i=0, j=1; j max_val) { max_val = X_i; } if(X_j > max_val) { max_val = X_j; } } if(i < n_elem) { const eT X_i = X[i]; if(X_i > max_val) { max_val = X_i; } } return max_val; } template inline eT op_max::direct_max(const eT* const X, const uword n_elem, uword& index_of_max_val) { arma_extra_debug_sigprint(); eT max_val = priv::most_neg(); uword best_index = 0; uword i,j; for(i=0, j=1; j max_val) { max_val = X_i; best_index = i; } if(X_j > max_val) { max_val = X_j; best_index = j; } } if(i < n_elem) { const eT X_i = X[i]; if(X_i > max_val) { max_val = X_i; best_index = i; } } index_of_max_val = best_index; return max_val; } template inline eT op_max::direct_max(const Mat& X, const uword row) { arma_extra_debug_sigprint(); const uword X_n_cols = X.n_cols; eT max_val = priv::most_neg(); uword i,j; for(i=0, j=1; j < X_n_cols; i+=2, j+=2) { const eT tmp_i = X.at(row,i); const eT tmp_j = X.at(row,j); if(tmp_i > max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < X_n_cols) { const eT tmp_i = X.at(row,i); if(tmp_i > max_val) { max_val = tmp_i; } } return max_val; } template inline eT op_max::max(const subview& X) { arma_extra_debug_sigprint(); arma_debug_check( (X.n_elem == 0), "max(): given object has no elements" ); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; eT max_val = priv::most_neg(); if(X_n_rows == 1) { const Mat& A = X.m; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_col_p1 = start_col + X_n_cols; uword i,j; for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2) { const eT tmp_i = A.at(start_row, i); const eT tmp_j = A.at(start_row, j); if(tmp_i > max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < end_col_p1) { const eT tmp_i = A.at(start_row, i); if(tmp_i > max_val) { max_val = tmp_i; } } } else { for(uword col=0; col < X_n_cols; ++col) { eT tmp_val = op_max::direct_max(X.colptr(col), X_n_rows); if(tmp_val > max_val) { max_val = tmp_val; } } } return max_val; } template inline typename arma_not_cx::result op_max::max(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); arma_debug_check( (n_elem == 0), "max(): given object has no elements" ); eT max_val = priv::most_neg(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < n_elem) { const eT tmp_i = A[i]; if(tmp_i > max_val) { max_val = tmp_i; } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp_i = P.at(0,i); const eT tmp_j = P.at(0,j); if(tmp_i > max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < n_cols) { const eT tmp_i = P.at(0,i); if(tmp_i > max_val) { max_val = tmp_i; } } } else { for(uword col=0; col < n_cols; ++col) { uword i,j; for(i=0, j=1; j < n_rows; i+=2, j+=2) { const eT tmp_i = P.at(i,col); const eT tmp_j = P.at(j,col); if(tmp_i > max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < n_rows) { const eT tmp_i = P.at(i,col); if(tmp_i > max_val) { max_val = tmp_i; } } } } } return max_val; } template inline std::complex op_max::direct_max(const std::complex* const X, const uword n_elem) { arma_extra_debug_sigprint(); uword index = 0; T max_val = priv::most_neg(); for(uword i=0; i max_val) { max_val = tmp_val; index = i; } } return X[index]; } template inline std::complex op_max::direct_max(const std::complex* const X, const uword n_elem, uword& index_of_max_val) { arma_extra_debug_sigprint(); uword index = 0; T max_val = priv::most_neg(); for(uword i=0; i max_val) { max_val = tmp_val; index = i; } } index_of_max_val = index; return X[index]; } template inline std::complex op_max::direct_max(const Mat< std::complex >& X, const uword row) { arma_extra_debug_sigprint(); const uword X_n_cols = X.n_cols; uword index = 0; T max_val = priv::most_neg(); for(uword col=0; col max_val) { max_val = tmp_val; index = col; } } return X.at(row,index); } template inline std::complex op_max::max(const subview< std::complex >& X) { arma_extra_debug_sigprint(); arma_debug_check( (X.n_elem == 0), "max(): given object has no elements" ); const Mat< std::complex >& A = X.m; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_row_p1 = start_row + X_n_rows; const uword end_col_p1 = start_col + X_n_cols; T max_val = priv::most_neg(); uword best_row = 0; uword best_col = 0; if(X_n_rows == 1) { best_col = 0; for(uword col=start_col; col < end_col_p1; ++col) { const T tmp_val = std::abs( A.at(start_row, col) ); if(tmp_val > max_val) { max_val = tmp_val; best_col = col; } } best_row = start_row; } else { for(uword col=start_col; col < end_col_p1; ++col) for(uword row=start_row; row < end_row_p1; ++row) { const T tmp_val = std::abs( A.at(row, col) ); if(tmp_val > max_val) { max_val = tmp_val; best_row = row; best_col = col; } } } return A.at(best_row, best_col); } template inline typename arma_cx_only::result op_max::max(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); arma_debug_check( (n_elem == 0), "max(): given object has no elements" ); T max_val = priv::most_neg(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); uword index = 0; for(uword i=0; i max_val) { max_val = tmp; index = i; } } return( A[index] ); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); uword best_row = 0; uword best_col = 0; if(n_rows == 1) { for(uword col=0; col < n_cols; ++col) { const T tmp = std::abs(P.at(0,col)); if(tmp > max_val) { max_val = tmp; best_col = col; } } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const T tmp = std::abs(P.at(row,col)); if(tmp > max_val) { max_val = tmp; best_row = row; best_col = col; } } } return P.at(best_row, best_col); } } //! @} RcppArmadillo/inst/include/armadillo_bits/typedef_mat_fixed.hpp0000644000176000001440000001572512246641052024625 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup typedef_mat_fixed //! @{ typedef umat::fixed<2,2> umat22; typedef umat::fixed<3,3> umat33; typedef umat::fixed<4,4> umat44; typedef umat::fixed<5,5> umat55; typedef umat::fixed<6,6> umat66; typedef umat::fixed<7,7> umat77; typedef umat::fixed<8,8> umat88; typedef umat::fixed<9,9> umat99; typedef imat::fixed<2,2> imat22; typedef imat::fixed<3,3> imat33; typedef imat::fixed<4,4> imat44; typedef imat::fixed<5,5> imat55; typedef imat::fixed<6,6> imat66; typedef imat::fixed<7,7> imat77; typedef imat::fixed<8,8> imat88; typedef imat::fixed<9,9> imat99; typedef fmat::fixed<2,2> fmat22; typedef fmat::fixed<3,3> fmat33; typedef fmat::fixed<4,4> fmat44; typedef fmat::fixed<5,5> fmat55; typedef fmat::fixed<6,6> fmat66; typedef fmat::fixed<7,7> fmat77; typedef fmat::fixed<8,8> fmat88; typedef fmat::fixed<9,9> fmat99; typedef mat::fixed<2,2> mat22; typedef mat::fixed<3,3> mat33; typedef mat::fixed<4,4> mat44; typedef mat::fixed<5,5> mat55; typedef mat::fixed<6,6> mat66; typedef mat::fixed<7,7> mat77; typedef mat::fixed<8,8> mat88; typedef mat::fixed<9,9> mat99; typedef cx_fmat::fixed<2,2> cx_fmat22; typedef cx_fmat::fixed<3,3> cx_fmat33; typedef cx_fmat::fixed<4,4> cx_fmat44; typedef cx_fmat::fixed<5,5> cx_fmat55; typedef cx_fmat::fixed<6,6> cx_fmat66; typedef cx_fmat::fixed<7,7> cx_fmat77; typedef cx_fmat::fixed<8,8> cx_fmat88; typedef cx_fmat::fixed<9,9> cx_fmat99; typedef cx_mat::fixed<2,2> cx_mat22; typedef cx_mat::fixed<3,3> cx_mat33; typedef cx_mat::fixed<4,4> cx_mat44; typedef cx_mat::fixed<5,5> cx_mat55; typedef cx_mat::fixed<6,6> cx_mat66; typedef cx_mat::fixed<7,7> cx_mat77; typedef cx_mat::fixed<8,8> cx_mat88; typedef cx_mat::fixed<9,9> cx_mat99; // typedef uvec::fixed<2> uvec2; typedef uvec::fixed<3> uvec3; typedef uvec::fixed<4> uvec4; typedef uvec::fixed<5> uvec5; typedef uvec::fixed<6> uvec6; typedef uvec::fixed<7> uvec7; typedef uvec::fixed<8> uvec8; typedef uvec::fixed<9> uvec9; typedef ivec::fixed<2> ivec2; typedef ivec::fixed<3> ivec3; typedef ivec::fixed<4> ivec4; typedef ivec::fixed<5> ivec5; typedef ivec::fixed<6> ivec6; typedef ivec::fixed<7> ivec7; typedef ivec::fixed<8> ivec8; typedef ivec::fixed<9> ivec9; typedef fvec::fixed<2> fvec2; typedef fvec::fixed<3> fvec3; typedef fvec::fixed<4> fvec4; typedef fvec::fixed<5> fvec5; typedef fvec::fixed<6> fvec6; typedef fvec::fixed<7> fvec7; typedef fvec::fixed<8> fvec8; typedef fvec::fixed<9> fvec9; typedef vec::fixed<2> vec2; typedef vec::fixed<3> vec3; typedef vec::fixed<4> vec4; typedef vec::fixed<5> vec5; typedef vec::fixed<6> vec6; typedef vec::fixed<7> vec7; typedef vec::fixed<8> vec8; typedef vec::fixed<9> vec9; typedef cx_fvec::fixed<2> cx_fvec2; typedef cx_fvec::fixed<3> cx_fvec3; typedef cx_fvec::fixed<4> cx_fvec4; typedef cx_fvec::fixed<5> cx_fvec5; typedef cx_fvec::fixed<6> cx_fvec6; typedef cx_fvec::fixed<7> cx_fvec7; typedef cx_fvec::fixed<8> cx_fvec8; typedef cx_fvec::fixed<9> cx_fvec9; typedef cx_vec::fixed<2> cx_vec2; typedef cx_vec::fixed<3> cx_vec3; typedef cx_vec::fixed<4> cx_vec4; typedef cx_vec::fixed<5> cx_vec5; typedef cx_vec::fixed<6> cx_vec6; typedef cx_vec::fixed<7> cx_vec7; typedef cx_vec::fixed<8> cx_vec8; typedef cx_vec::fixed<9> cx_vec9; // typedef ucolvec::fixed<2> ucolvec2; typedef ucolvec::fixed<3> ucolvec3; typedef ucolvec::fixed<4> ucolvec4; typedef ucolvec::fixed<5> ucolvec5; typedef ucolvec::fixed<6> ucolvec6; typedef ucolvec::fixed<7> ucolvec7; typedef ucolvec::fixed<8> ucolvec8; typedef ucolvec::fixed<9> ucolvec9; typedef icolvec::fixed<2> icolvec2; typedef icolvec::fixed<3> icolvec3; typedef icolvec::fixed<4> icolvec4; typedef icolvec::fixed<5> icolvec5; typedef icolvec::fixed<6> icolvec6; typedef icolvec::fixed<7> icolvec7; typedef icolvec::fixed<8> icolvec8; typedef icolvec::fixed<9> icolvec9; typedef fcolvec::fixed<2> fcolvec2; typedef fcolvec::fixed<3> fcolvec3; typedef fcolvec::fixed<4> fcolvec4; typedef fcolvec::fixed<5> fcolvec5; typedef fcolvec::fixed<6> fcolvec6; typedef fcolvec::fixed<7> fcolvec7; typedef fcolvec::fixed<8> fcolvec8; typedef fcolvec::fixed<9> fcolvec9; typedef colvec::fixed<2> colvec2; typedef colvec::fixed<3> colvec3; typedef colvec::fixed<4> colvec4; typedef colvec::fixed<5> colvec5; typedef colvec::fixed<6> colvec6; typedef colvec::fixed<7> colvec7; typedef colvec::fixed<8> colvec8; typedef colvec::fixed<9> colvec9; typedef cx_fcolvec::fixed<2> cx_fcolvec2; typedef cx_fcolvec::fixed<3> cx_fcolvec3; typedef cx_fcolvec::fixed<4> cx_fcolvec4; typedef cx_fcolvec::fixed<5> cx_fcolvec5; typedef cx_fcolvec::fixed<6> cx_fcolvec6; typedef cx_fcolvec::fixed<7> cx_fcolvec7; typedef cx_fcolvec::fixed<8> cx_fcolvec8; typedef cx_fcolvec::fixed<9> cx_fcolvec9; typedef cx_colvec::fixed<2> cx_colvec2; typedef cx_colvec::fixed<3> cx_colvec3; typedef cx_colvec::fixed<4> cx_colvec4; typedef cx_colvec::fixed<5> cx_colvec5; typedef cx_colvec::fixed<6> cx_colvec6; typedef cx_colvec::fixed<7> cx_colvec7; typedef cx_colvec::fixed<8> cx_colvec8; typedef cx_colvec::fixed<9> cx_colvec9; // typedef urowvec::fixed<2> urowvec2; typedef urowvec::fixed<3> urowvec3; typedef urowvec::fixed<4> urowvec4; typedef urowvec::fixed<5> urowvec5; typedef urowvec::fixed<6> urowvec6; typedef urowvec::fixed<7> urowvec7; typedef urowvec::fixed<8> urowvec8; typedef urowvec::fixed<9> urowvec9; typedef irowvec::fixed<2> irowvec2; typedef irowvec::fixed<3> irowvec3; typedef irowvec::fixed<4> irowvec4; typedef irowvec::fixed<5> irowvec5; typedef irowvec::fixed<6> irowvec6; typedef irowvec::fixed<7> irowvec7; typedef irowvec::fixed<8> irowvec8; typedef irowvec::fixed<9> irowvec9; typedef frowvec::fixed<2> frowvec2; typedef frowvec::fixed<3> frowvec3; typedef frowvec::fixed<4> frowvec4; typedef frowvec::fixed<5> frowvec5; typedef frowvec::fixed<6> frowvec6; typedef frowvec::fixed<7> frowvec7; typedef frowvec::fixed<8> frowvec8; typedef frowvec::fixed<9> frowvec9; typedef rowvec::fixed<2> rowvec2; typedef rowvec::fixed<3> rowvec3; typedef rowvec::fixed<4> rowvec4; typedef rowvec::fixed<5> rowvec5; typedef rowvec::fixed<6> rowvec6; typedef rowvec::fixed<7> rowvec7; typedef rowvec::fixed<8> rowvec8; typedef rowvec::fixed<9> rowvec9; typedef cx_frowvec::fixed<2> cx_frowvec2; typedef cx_frowvec::fixed<3> cx_frowvec3; typedef cx_frowvec::fixed<4> cx_frowvec4; typedef cx_frowvec::fixed<5> cx_frowvec5; typedef cx_frowvec::fixed<6> cx_frowvec6; typedef cx_frowvec::fixed<7> cx_frowvec7; typedef cx_frowvec::fixed<8> cx_frowvec8; typedef cx_frowvec::fixed<9> cx_frowvec9; typedef cx_rowvec::fixed<2> cx_rowvec2; typedef cx_rowvec::fixed<3> cx_rowvec3; typedef cx_rowvec::fixed<4> cx_rowvec4; typedef cx_rowvec::fixed<5> cx_rowvec5; typedef cx_rowvec::fixed<6> cx_rowvec6; typedef cx_rowvec::fixed<7> cx_rowvec7; typedef cx_rowvec::fixed<8> cx_rowvec8; typedef cx_rowvec::fixed<9> cx_rowvec9; //! @} RcppArmadillo/inst/include/armadillo_bits/op_toeplitz_meat.hpp0000644000176000001440000000432712111564102024506 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_toeplitz //! @{ template inline void op_toeplitz::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; arma_debug_check( ((X.is_vec() == false) && (X.is_empty() == false)), "toeplitz(): given object is not a vector" ); const uword N = X.n_elem; const eT* X_mem = X.memptr(); out.set_size(N,N); for(uword col=0; col < N; ++col) { eT* col_mem = out.colptr(col); uword i; i = col; for(uword row=0; row < col; ++row, --i) { col_mem[row] = X_mem[i]; } i = 0; for(uword row=col; row < N; ++row, ++i) { col_mem[row] = X_mem[i]; } } } template inline void op_toeplitz_c::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; arma_debug_check( ((X.is_vec() == false) && (X.is_empty() == false)), "circ_toeplitz(): given object is not a vector" ); const uword N = X.n_elem; const eT* X_mem = X.memptr(); out.set_size(N,N); if(X.is_rowvec() == true) { for(uword row=0; row < N; ++row) { uword i; i = row; for(uword col=0; col < row; ++col, --i) { out.at(row,col) = X_mem[N-i]; } i = 0; for(uword col=row; col < N; ++col, ++i) { out.at(row,col) = X_mem[i]; } } } else { for(uword col=0; col < N; ++col) { eT* col_mem = out.colptr(col); uword i; i = col; for(uword row=0; row < col; ++row, --i) { col_mem[row] = X_mem[N-i]; } i = 0; for(uword row=col; row < N; ++row, ++i) { col_mem[row] = X_mem[i]; } } } } //! @} RcppArmadillo/inst/include/armadillo_bits/spglue_plus_bones.hpp0000644000176000001440000000150112111344723024654 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spglue_plus //! @{ class spglue_plus { public: template arma_hot inline static void apply(SpMat& out, const SpGlue& X); template arma_hot inline static void apply_noalias(SpMat& out, const SpProxy& pa, const SpProxy& pb); }; class spglue_plus2 { public: template arma_hot inline static void apply(SpMat& out, const SpGlue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/hdf5_misc.hpp0000644000176000001440000004275212151522310022774 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2013 Szabolcs Horvat // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup hdf5_misc //! @{ #if defined(ARMA_USE_HDF5) namespace hdf5_misc { //! Given a certain type, find the corresponding HDF5 datatype. This can't be //! done entirely at compile time, unfortunately, because the H5T_* macros //! depend on function calls. template< typename eT > inline hid_t get_hdf5_type() { return -1; // Return invalid. } //! Specializations for each valid element type //! (taken from all the possible typedefs of {u8, s8, ..., u64, s64} and the other native types. //! We can't use the actual u8/s8 typedefs because their relations to the H5T_... types are unclear. template<> inline hid_t get_hdf5_type< unsigned char >() { return H5Tcopy(H5T_NATIVE_UCHAR); } template<> inline hid_t get_hdf5_type< char >() { return H5Tcopy(H5T_NATIVE_CHAR); } template<> inline hid_t get_hdf5_type< short >() { return H5Tcopy(H5T_NATIVE_SHORT); } template<> inline hid_t get_hdf5_type< unsigned short >() { return H5Tcopy(H5T_NATIVE_USHORT); } template<> inline hid_t get_hdf5_type< int >() { return H5Tcopy(H5T_NATIVE_INT); } template<> inline hid_t get_hdf5_type< unsigned int >() { return H5Tcopy(H5T_NATIVE_UINT); } template<> inline hid_t get_hdf5_type< long >() { return H5Tcopy(H5T_NATIVE_LONG); } template<> inline hid_t get_hdf5_type< unsigned long >() { return H5Tcopy(H5T_NATIVE_ULONG); } #if defined(ARMA_USE_U64S64) && defined(ULLONG_MAX) template<> inline hid_t get_hdf5_type< long long >() { return H5Tcopy(H5T_NATIVE_LLONG); } template<> inline hid_t get_hdf5_type< unsigned long long >() { return H5Tcopy(H5T_NATIVE_ULLONG); } #endif template<> inline hid_t get_hdf5_type< float >() { return H5Tcopy(H5T_NATIVE_FLOAT); } template<> inline hid_t get_hdf5_type< double >() { return H5Tcopy(H5T_NATIVE_DOUBLE); } //! Utility hid_t since HOFFSET() won't work with std::complex. template struct hdf5_complex_t { eT real; eT imag; }; template<> inline hid_t get_hdf5_type< std::complex >() { hid_t type = H5Tcreate(H5T_COMPOUND, sizeof(hdf5_complex_t)); H5Tinsert(type, "real", HOFFSET(hdf5_complex_t, real), H5T_NATIVE_FLOAT); H5Tinsert(type, "imag", HOFFSET(hdf5_complex_t, imag), H5T_NATIVE_FLOAT); return type; } template<> inline hid_t get_hdf5_type< std::complex >() { hid_t type = H5Tcreate(H5T_COMPOUND, sizeof(hdf5_complex_t)); H5Tinsert(type, "real", HOFFSET(hdf5_complex_t, real), H5T_NATIVE_DOUBLE); H5Tinsert(type, "imag", HOFFSET(hdf5_complex_t, imag), H5T_NATIVE_DOUBLE); return type; } // Compare datatype against all supported types. inline bool is_supported_arma_hdf5_type(hid_t datatype) { hid_t search_type; bool is_equal; // start with most likely used types: double, complex, float, complex search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type< std::complex >(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type< std::complex >(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } // remaining supported types: u8, s8, u16, s16, u32, s32, u64, s64, ulng_t, slng_t search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } #if defined(ARMA_USE_U64S64) { search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } } #endif #if defined(ARMA_ALLOW_LONG) { search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( H5Tequal(datatype, search_type) > 0 ); H5Tclose(search_type); if (is_equal) { return true; } } #endif return false; } //! Auxiliary functions and structs for search_hdf5_file. struct hdf5_search_info { const std::vector& names; int num_dims; bool exact; hid_t best_match; size_t best_match_position; // Position of best match in names vector. }; inline herr_t hdf5_search_callback ( hid_t loc_id, const char* name, const H5O_info_t* info, void* operator_data // hdf5_search_info ) { hdf5_search_info* search_info = (hdf5_search_info*) operator_data; // We are looking for datasets. if (info->type == H5O_TYPE_DATASET) { // Check type of dataset to see if we could even load it. hid_t dataset = H5Dopen(loc_id, name, H5P_DEFAULT); hid_t datatype = H5Dget_type(dataset); const bool is_supported = is_supported_arma_hdf5_type(datatype); H5Tclose(datatype); H5Dclose(dataset); if(is_supported == false) { // Forget about it and move on. return 0; } // Now we have to check against our set of names. // Only check names which could be better. for (size_t string_pos = 0; string_pos < search_info->best_match_position; ++string_pos) { // name is the full path (/path/to/dataset); names[string_pos] may be // "dataset", "/to/dataset", or "/path/to/dataset". // So if we count the number of forward slashes in names[string_pos], // and then simply take the last substring of name containing that number of slashes, // we can do the comparison. // Count the number of forward slashes in names[string_pos]. uword count = 0; for (uword i = 0; i < search_info->names[string_pos].length(); ++i) { if ((search_info->names[string_pos])[i] == '/') { ++count; } } // Count the number of forward slashes in the full name. uword name_count = 0; const std::string str = std::string(name); for (uword i = 0; i < str.length(); ++i) { if (str[i] == '/') { ++count; } } // If we are asking for more slashes than we have, this can't be a match. // Skip to below, where we decide whether or not to keep it anyway based // on the exactness condition of the search. if (count <= name_count) { size_t start_pos = (count == 0) ? 0 : std::string::npos; while (count > 0) { // Move pointer to previous slash. start_pos = str.rfind('/', start_pos); // Break if we've run out of slashes. if (start_pos == std::string::npos) { break; } --count; } // Now take the substring (this may end up being the full string). const std::string substring = str.substr(start_pos); // Are they the same? if (substring == search_info->names[string_pos]) { // We have found the object; it must be better than our existing match. hid_t match_candidate = H5Dopen(loc_id, name, H5P_DEFAULT); // arma_check(match_candidate < 0, "Mat::load(): cannot open an HDF5 dataset"); if(match_candidate < 0) { return -1; } // Ensure that the dataset is valid and of the correct dimensionality. hid_t filespace = H5Dget_space(match_candidate); int num_dims = H5Sget_simple_extent_ndims(filespace); if (num_dims <= search_info->num_dims) { // Valid dataset -- we'll keep it. // If we already have an existing match we have to close it. if (search_info->best_match != -1) { H5Dclose(search_info->best_match); } search_info->best_match_position = string_pos; search_info->best_match = match_candidate; } H5Sclose(filespace); } } // If they are not the same, but we have not found anything and we don't need an exact match, take this. if ((search_info->exact == false) && (search_info->best_match == -1)) { hid_t match_candidate = H5Dopen(loc_id, name, H5P_DEFAULT); // arma_check(match_candidate < 0, "Mat::load(): cannot open an HDF5 dataset"); if(match_candidate < 0) { return -1; } hid_t filespace = H5Dget_space(match_candidate); int num_dims = H5Sget_simple_extent_ndims(filespace); if (num_dims <= search_info->num_dims) { // Valid dataset -- we'll keep it. search_info->best_match = H5Dopen(loc_id, name, H5P_DEFAULT); } H5Sclose(filespace); } } } return 0; } //! Search an HDF5 file for the given dataset names. //! If 'exact' is true, failure to find a dataset in the list of names means that -1 is returned. //! If 'exact' is false and no datasets are found, -1 is returned. //! The number of dimensions is used to help prune down invalid datasets; //! 2 dimensions is a matrix, 1 dimension is a vector, and 3 dimensions is a cube. //! If the number of dimensions in a dataset is less than or equal to num_dims, //! it will be considered -- for instance, a one-dimensional HDF5 vector can be loaded as a single-column matrix. inline hid_t search_hdf5_file ( const std::vector& names, hid_t hdf5_file, int num_dims = 2, bool exact = false ) { hdf5_search_info search_info = { names, num_dims, exact, -1, names.size() }; // We'll use the H5Ovisit to track potential entries. herr_t status = H5Ovisit(hdf5_file, H5_INDEX_NAME, H5_ITER_NATIVE, hdf5_search_callback, void_ptr(&search_info)); // Return the best match; it will be -1 if there was a problem. return (status < 0) ? -1 : search_info.best_match; } //! Load an HDF5 matrix into an array of type specified by datatype, //! then convert that into the desired array 'dest'. //! This should only be called when eT is not the datatype. template inline hid_t load_and_convert_hdf5 ( eT *dest, hid_t dataset, hid_t datatype, uword n_elem ) { // We can't use nice template specializations here // as the determination of the type of 'datatype' must be done at runtime. // So we end up with this ugliness... hid_t search_type; bool is_equal; // u8 search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // s8 search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // u16 search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // s16 search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // u32 search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // s32 search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } #if defined(ARMA_USE_U64S64) { // u64 search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // s64 search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } } #endif #if defined(ARMA_ALLOW_LONG) { // ulng_t search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // slng_t search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } } #endif // float search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // double search_type = get_hdf5_type(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // complex float search_type = get_hdf5_type< std::complex >(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { if(is_complex::value == false) { return -1; // can't read complex data into non-complex matrix/cube } Col< std::complex > v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert_cx(dest, v.memptr(), n_elem); return status; } // complex double search_type = get_hdf5_type< std::complex >(); is_equal = (H5Tequal(datatype, search_type) > 0); H5Tclose(search_type); if(is_equal) { if(is_complex::value == false) { return -1; // can't read complex data into non-complex matrix/cube } Col< std::complex > v(n_elem); hid_t status = H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert_cx(dest, v.memptr(), n_elem); return status; } return -1; // Failure. } } // namespace hdf5_misc #endif // #if defined(ARMA_USE_HDF5) //! @} RcppArmadillo/inst/include/armadillo_bits/fn_trimat.hpp0000644000176000001440000000134012200375542023112 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_trimat //! @{ template arma_inline const Op trimatu(const Base& X) { arma_extra_debug_sigprint(); return Op(X.get_ref(), 0, 0); } template arma_inline const Op trimatl(const Base& X) { arma_extra_debug_sigprint(); return Op(X.get_ref(), 1, 0); } //! @} RcppArmadillo/inst/include/armadillo_bits/glue_times_meat.hpp0000644000176000001440000007151412257054523024311 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_times //! @{ template template arma_hot inline void glue_times_redirect2_helper::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const partial_unwrap_check tmp1(X.A, out); const partial_unwrap_check tmp2(X.B, out); const typename partial_unwrap_check::stored_type& A = tmp1.M; const typename partial_unwrap_check::stored_type& B = tmp2.M; const bool use_alpha = partial_unwrap_check::do_times || partial_unwrap_check::do_times; const eT alpha = use_alpha ? (tmp1.get_val() * tmp2.get_val()) : eT(0); glue_times::apply < eT, partial_unwrap_check::do_trans, partial_unwrap_check::do_trans, (partial_unwrap_check::do_times || partial_unwrap_check::do_times) > (out, A, B, alpha); } template arma_hot inline void glue_times_redirect2_helper::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; if(strip_inv::do_inv == false) { const partial_unwrap_check tmp1(X.A, out); const partial_unwrap_check tmp2(X.B, out); const typename partial_unwrap_check::stored_type& A = tmp1.M; const typename partial_unwrap_check::stored_type& B = tmp2.M; const bool use_alpha = partial_unwrap_check::do_times || partial_unwrap_check::do_times; const eT alpha = use_alpha ? (tmp1.get_val() * tmp2.get_val()) : eT(0); glue_times::apply < eT, partial_unwrap_check::do_trans, partial_unwrap_check::do_trans, (partial_unwrap_check::do_times || partial_unwrap_check::do_times) > (out, A, B, alpha); } else { arma_extra_debug_print("glue_times_redirect<2>::apply(): detected inv(A)*B"); const strip_inv A_strip(X.A); Mat A = A_strip.M; arma_debug_check( (A.is_square() == false), "inv(): given matrix is not square" ); const unwrap_check B_tmp(X.B, out); const Mat& B = B_tmp.M; glue_solve::solve_direct( out, A, B, A_strip.slow ); } } template template arma_hot inline void glue_times_redirect3_helper::apply(Mat& out, const Glue< Glue, T3, glue_times>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // we have exactly 3 objects // hence we can safely expand X as X.A.A, X.A.B and X.B const partial_unwrap_check tmp1(X.A.A, out); const partial_unwrap_check tmp2(X.A.B, out); const partial_unwrap_check tmp3(X.B, out); const typename partial_unwrap_check::stored_type& A = tmp1.M; const typename partial_unwrap_check::stored_type& B = tmp2.M; const typename partial_unwrap_check::stored_type& C = tmp3.M; const bool use_alpha = partial_unwrap_check::do_times || partial_unwrap_check::do_times || partial_unwrap_check::do_times; const eT alpha = use_alpha ? (tmp1.get_val() * tmp2.get_val() * tmp3.get_val()) : eT(0); glue_times::apply < eT, partial_unwrap_check::do_trans, partial_unwrap_check::do_trans, partial_unwrap_check::do_trans, (partial_unwrap_check::do_times || partial_unwrap_check::do_times || partial_unwrap_check::do_times) > (out, A, B, C, alpha); } template arma_hot inline void glue_times_redirect3_helper::apply(Mat& out, const Glue< Glue, T3, glue_times>& X) { arma_extra_debug_sigprint(); // TODO: investigate detecting inv(A)*B*C and replacing with solve(A,B)*C typedef typename T1::elem_type eT; if(strip_inv::do_inv == false) { // we have exactly 3 objects // hence we can safely expand X as X.A.A, X.A.B and X.B const partial_unwrap_check tmp1(X.A.A, out); const partial_unwrap_check tmp2(X.A.B, out); const partial_unwrap_check tmp3(X.B, out); const typename partial_unwrap_check::stored_type& A = tmp1.M; const typename partial_unwrap_check::stored_type& B = tmp2.M; const typename partial_unwrap_check::stored_type& C = tmp3.M; const bool use_alpha = partial_unwrap_check::do_times || partial_unwrap_check::do_times || partial_unwrap_check::do_times; const eT alpha = use_alpha ? (tmp1.get_val() * tmp2.get_val() * tmp3.get_val()) : eT(0); glue_times::apply < eT, partial_unwrap_check::do_trans, partial_unwrap_check::do_trans, partial_unwrap_check::do_trans, (partial_unwrap_check::do_times || partial_unwrap_check::do_times || partial_unwrap_check::do_times) > (out, A, B, C, alpha); } else { // replace A*inv(B)*C with A*solve(B,C) arma_extra_debug_print("glue_times_redirect<3>::apply(): detected A*inv(B)*C"); const strip_inv B_strip(X.A.B); Mat B = B_strip.M; arma_debug_check( (B.is_square() == false), "inv(): given matrix is not square" ); const unwrap C_tmp(X.B); const Mat& C = C_tmp.M; Mat solve_result; glue_solve::solve_direct( solve_result, B, C, B_strip.slow ); const partial_unwrap_check tmp1(X.A.A, out); const typename partial_unwrap_check::stored_type& A = tmp1.M; const bool use_alpha = partial_unwrap_check::do_times; const eT alpha = use_alpha ? tmp1.get_val() : eT(0); glue_times::apply < eT, partial_unwrap_check::do_trans, false, partial_unwrap_check::do_times > (out, A, solve_result, alpha); } } template template arma_hot inline void glue_times_redirect::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const partial_unwrap_check tmp1(X.A, out); const partial_unwrap_check tmp2(X.B, out); const typename partial_unwrap_check::stored_type& A = tmp1.M; const typename partial_unwrap_check::stored_type& B = tmp2.M; const bool use_alpha = partial_unwrap_check::do_times || partial_unwrap_check::do_times; const eT alpha = use_alpha ? (tmp1.get_val() * tmp2.get_val()) : eT(0); glue_times::apply < eT, partial_unwrap_check::do_trans, partial_unwrap_check::do_trans, (partial_unwrap_check::do_times || partial_unwrap_check::do_times) > (out, A, B, alpha); } template arma_hot inline void glue_times_redirect<2>::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; glue_times_redirect2_helper< is_supported_blas_type::value >::apply(out, X); } template arma_hot inline void glue_times_redirect<3>::apply(Mat& out, const Glue< Glue, T3, glue_times>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; glue_times_redirect3_helper< is_supported_blas_type::value >::apply(out, X); } template arma_hot inline void glue_times_redirect<4>::apply(Mat& out, const Glue< Glue< Glue, T3, glue_times>, T4, glue_times>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // there is exactly 4 objects // hence we can safely expand X as X.A.A.A, X.A.A.B, X.A.B and X.B const partial_unwrap_check tmp1(X.A.A.A, out); const partial_unwrap_check tmp2(X.A.A.B, out); const partial_unwrap_check tmp3(X.A.B, out); const partial_unwrap_check tmp4(X.B, out); const typename partial_unwrap_check::stored_type& A = tmp1.M; const typename partial_unwrap_check::stored_type& B = tmp2.M; const typename partial_unwrap_check::stored_type& C = tmp3.M; const typename partial_unwrap_check::stored_type& D = tmp4.M; const bool use_alpha = partial_unwrap_check::do_times || partial_unwrap_check::do_times || partial_unwrap_check::do_times || partial_unwrap_check::do_times; const eT alpha = use_alpha ? (tmp1.get_val() * tmp2.get_val() * tmp3.get_val() * tmp4.get_val()) : eT(0); glue_times::apply < eT, partial_unwrap_check::do_trans, partial_unwrap_check::do_trans, partial_unwrap_check::do_trans, partial_unwrap_check::do_trans, (partial_unwrap_check::do_times || partial_unwrap_check::do_times || partial_unwrap_check::do_times || partial_unwrap_check::do_times) > (out, A, B, C, D, alpha); } template arma_hot inline void glue_times::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); const sword N_mat = 1 + depth_lhs< glue_times, Glue >::num; arma_extra_debug_print(arma_boost::format("N_mat = %d") % N_mat); glue_times_redirect::apply(out, X); } template arma_hot inline void glue_times::apply_inplace(Mat& out, const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check B_tmp(X, out); const Mat& B = B_tmp.M; arma_debug_assert_mul_size(out, B, "matrix multiplication"); const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; if(out_n_cols == B.n_cols) { // size of resulting matrix is the same as 'out' podarray tmp(out_n_cols); eT* tmp_rowdata = tmp.memptr(); for(uword row=0; row < out_n_rows; ++row) { tmp.copy_row(out, row); for(uword col=0; col < out_n_cols; ++col) { out.at(row,col) = op_dot::direct_dot( out_n_cols, tmp_rowdata, B.colptr(col) ); } } } else { const Mat tmp(out); glue_times::apply(out, tmp, B, eT(1)); } } template arma_hot inline void glue_times::apply_inplace_plus(Mat& out, const Glue& X, const sword sign) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const partial_unwrap_check tmp1(X.A, out); const partial_unwrap_check tmp2(X.B, out); typedef typename partial_unwrap_check::stored_type TA; typedef typename partial_unwrap_check::stored_type TB; const TA& A = tmp1.M; const TB& B = tmp2.M; const bool do_trans_A = partial_unwrap_check::do_trans; const bool do_trans_B = partial_unwrap_check::do_trans; const bool use_alpha = partial_unwrap_check::do_times || partial_unwrap_check::do_times || (sign < sword(0)); const eT alpha = use_alpha ? ( tmp1.get_val() * tmp2.get_val() * ( (sign > sword(0)) ? eT(1) : eT(-1) ) ) : eT(0); arma_debug_assert_mul_size(A, B, do_trans_A, do_trans_B, "matrix multiplication"); const uword result_n_rows = (do_trans_A == false) ? (TA::is_row ? 1 : A.n_rows) : (TA::is_col ? 1 : A.n_cols); const uword result_n_cols = (do_trans_B == false) ? (TB::is_col ? 1 : B.n_cols) : (TB::is_row ? 1 : B.n_rows); arma_debug_assert_same_size(out.n_rows, out.n_cols, result_n_rows, result_n_cols, "addition"); if(out.n_elem == 0) { return; } if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == false) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == true) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == false) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::yes) ) { herk::apply(out, A, T(0), T(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == true) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == false) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::yes) ) { herk::apply(out, A, T(0), T(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == true) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == false) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == true) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } } template arma_inline uword glue_times::mul_storage_cost(const TA& A, const TB& B) { const uword final_A_n_rows = (do_trans_A == false) ? ( TA::is_row ? 1 : A.n_rows ) : ( TA::is_col ? 1 : A.n_cols ); const uword final_B_n_cols = (do_trans_B == false) ? ( TB::is_col ? 1 : B.n_cols ) : ( TB::is_row ? 1 : B.n_rows ); return final_A_n_rows * final_B_n_cols; } template < typename eT, const bool do_trans_A, const bool do_trans_B, const bool use_alpha, typename TA, typename TB > arma_hot inline void glue_times::apply ( Mat& out, const TA& A, const TB& B, const eT alpha ) { arma_extra_debug_sigprint(); //arma_debug_assert_mul_size(A, B, do_trans_A, do_trans_B, "matrix multiplication"); arma_debug_assert_trans_mul_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "matrix multiplication"); const uword final_n_rows = (do_trans_A == false) ? (TA::is_row ? 1 : A.n_rows) : (TA::is_col ? 1 : A.n_cols); const uword final_n_cols = (do_trans_B == false) ? (TB::is_col ? 1 : B.n_cols) : (TB::is_row ? 1 : B.n_rows); out.set_size(final_n_rows, final_n_cols); if( (A.n_elem == 0) || (B.n_elem == 0) ) { out.zeros(); return; } if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == false) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr()); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr()); } else { gemm::apply(out, A, B ); } } else if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == true) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha); } else { gemm::apply(out, A, B, alpha); } } else if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == false) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr()); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr()); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A ); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::yes) ) { herk::apply(out, A ); } else { gemm::apply(out, A, B ); } } else if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == true) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha); } else { gemm::apply(out, A, B, alpha); } } else if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == false) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr()); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr()); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A ); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::yes) ) { herk::apply(out, A ); } else { gemm::apply(out, A, B ); } } else if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == true) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha); } else { gemm::apply(out, A, B, alpha); } } else if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == false) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr()); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr()); } else { gemm::apply(out, A, B ); } } else if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == true) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha); } else { gemm::apply(out, A, B, alpha); } } } template < typename eT, const bool do_trans_A, const bool do_trans_B, const bool do_trans_C, const bool use_alpha, typename TA, typename TB, typename TC > arma_hot inline void glue_times::apply ( Mat& out, const TA& A, const TB& B, const TC& C, const eT alpha ) { arma_extra_debug_sigprint(); Mat tmp; const uword storage_cost_AB = glue_times::mul_storage_cost(A, B); const uword storage_cost_BC = glue_times::mul_storage_cost(B, C); if(storage_cost_AB <= storage_cost_BC) { // out = (A*B)*C glue_times::apply(tmp, A, B, alpha); glue_times::apply(out, tmp, C, eT(0)); } else { // out = A*(B*C) glue_times::apply(tmp, B, C, alpha); glue_times::apply(out, A, tmp, eT(0)); } } template < typename eT, const bool do_trans_A, const bool do_trans_B, const bool do_trans_C, const bool do_trans_D, const bool use_alpha, typename TA, typename TB, typename TC, typename TD > arma_hot inline void glue_times::apply ( Mat& out, const TA& A, const TB& B, const TC& C, const TD& D, const eT alpha ) { arma_extra_debug_sigprint(); Mat tmp; const uword storage_cost_AC = glue_times::mul_storage_cost(A, C); const uword storage_cost_BD = glue_times::mul_storage_cost(B, D); if(storage_cost_AC <= storage_cost_BD) { // out = (A*B*C)*D glue_times::apply(tmp, A, B, C, alpha); glue_times::apply(out, tmp, D, eT(0)); } else { // out = A*(B*C*D) glue_times::apply(tmp, B, C, D, alpha); glue_times::apply(out, A, tmp, eT(0)); } } // // glue_times_diag template arma_hot inline void glue_times_diag::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const strip_diagmat S1(X.A); const strip_diagmat S2(X.B); typedef typename strip_diagmat::stored_type T1_stripped; typedef typename strip_diagmat::stored_type T2_stripped; if( (strip_diagmat::do_diagmat == true) && (strip_diagmat::do_diagmat == false) ) { const diagmat_proxy_check A(S1.M, out); const unwrap_check tmp(X.B, out); const Mat& B = tmp.M; const uword A_n_elem = A.n_elem; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; arma_debug_assert_mul_size(A_n_elem, A_n_elem, B_n_rows, B_n_cols, "matrix multiplication"); out.set_size(A_n_elem, B_n_cols); for(uword col=0; col < B_n_cols; ++col) { eT* out_coldata = out.colptr(col); const eT* B_coldata = B.colptr(col); uword i,j; for(i=0, j=1; j < B_n_rows; i+=2, j+=2) { eT tmp_i = A[i]; eT tmp_j = A[j]; tmp_i *= B_coldata[i]; tmp_j *= B_coldata[j]; out_coldata[i] = tmp_i; out_coldata[j] = tmp_j; } if(i < B_n_rows) { out_coldata[i] = A[i] * B_coldata[i]; } } } else if( (strip_diagmat::do_diagmat == false) && (strip_diagmat::do_diagmat == true) ) { const unwrap_check tmp(X.A, out); const Mat& A = tmp.M; const diagmat_proxy_check B(S2.M, out); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_elem = B.n_elem; arma_debug_assert_mul_size(A_n_rows, A_n_cols, B_n_elem, B_n_elem, "matrix multiplication"); out.set_size(A_n_rows, B_n_elem); for(uword col=0; col < A_n_cols; ++col) { const eT val = B[col]; eT* out_coldata = out.colptr(col); const eT* A_coldata = A.colptr(col); uword i,j; for(i=0, j=1; j < A_n_rows; i+=2, j+=2) { const eT tmp_i = A_coldata[i] * val; const eT tmp_j = A_coldata[j] * val; out_coldata[i] = tmp_i; out_coldata[j] = tmp_j; } if(i < A_n_rows) { out_coldata[i] = A_coldata[i] * val; } } } else if( (strip_diagmat::do_diagmat == true) && (strip_diagmat::do_diagmat == true) ) { const diagmat_proxy_check A(S1.M, out); const diagmat_proxy_check B(S2.M, out); const uword A_n_elem = A.n_elem; const uword B_n_elem = B.n_elem; arma_debug_assert_mul_size(A_n_elem, A_n_elem, B_n_elem, B_n_elem, "matrix multiplication"); out.zeros(A_n_elem, A_n_elem); for(uword i=0; i < A_n_elem; ++i) { out.at(i,i) = A[i] * B[i]; } } } //! @} RcppArmadillo/inst/include/armadillo_bits/wall_clock_meat.hpp0000644000176000001440000000351312251611645024256 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup wall_clock //! @{ inline wall_clock::wall_clock() : valid(false) { arma_extra_debug_sigprint(); } inline wall_clock::~wall_clock() { arma_extra_debug_sigprint(); } inline void wall_clock::tic() { arma_extra_debug_sigprint(); #if defined(ARMA_USE_CXX11) { chrono_time1 = std::chrono::steady_clock::now(); valid = true; } #elif defined(ARMA_HAVE_GETTIMEOFDAY) { gettimeofday(&posix_time1, 0); valid = true; } #else { time1 = clock(); valid = true; } #endif } inline double wall_clock::toc() { arma_extra_debug_sigprint(); if(valid) { #if defined(ARMA_USE_CXX11) { const std::chrono::steady_clock::time_point chrono_time2 = std::chrono::steady_clock::now(); typedef std::chrono::duration duration_type; const duration_type chrono_span = std::chrono::duration_cast< duration_type >(chrono_time2 - chrono_time1); return chrono_span.count(); } #elif defined(ARMA_HAVE_GETTIMEOFDAY) { gettimeofday(&posix_time2, 0); const double tmp_time1 = posix_time1.tv_sec + posix_time1.tv_usec * 1.0e-6; const double tmp_time2 = posix_time2.tv_sec + posix_time2.tv_usec * 1.0e-6; return tmp_time2 - tmp_time1; } #else { clock_t time2 = clock(); clock_t diff = time2 - time1; return double(diff) / double(CLOCKS_PER_SEC); } #endif } else { return 0.0; } } //! @} RcppArmadillo/inst/include/armadillo_bits/spop_var_bones.hpp0000644000176000001440000000376512111344723024161 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_var //! @{ //! Class for finding variance values of a sparse matrix class spop_var { public: template inline static void apply(SpMat& out, const mtSpOp& in); template inline static void apply_noalias(SpMat& out, const SpProxy& p, const uword norm_type, const uword dim); // Calculate variance of a sparse vector, where we can directly use the memory. template inline static typename T1::pod_type var_vec(const T1& X, const uword norm_type = 0); // Calculate the variance directly. Because this is for sparse matrices, we // specify both the number of elements in the array (the length of the array) // as well as the actual number of elements when zeros are included. template inline static eT direct_var(const eT* const X, const uword length, const uword N, const uword norm_type = 0); // For complex numbers. template inline static T direct_var(const std::complex* const X, const uword length, const uword N, const uword norm_type = 0); // Calculate the variance using iterators, for non-complex numbers. template inline static eT iterator_var(T1& it, const T1& end, const uword n_zero, const uword norm_type, const eT junk1, const typename arma_not_cx::result* junk2 = 0); // Calculate the variance using iterators, for complex numbers. template inline static typename get_pod_type::result iterator_var(T1& it, const T1& end, const uword n_zero, const uword norm_type, const eT junk1, const typename arma_cx_only::result* junk2 = 0); }; //! @} RcppArmadillo/inst/include/armadillo_bits/SpGlue_bones.hpp0000644000176000001440000000235712111344723023523 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpGlue //! @{ template class SpGlue : public SpBase > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = ( (T1::is_row || T2::is_row) && is_spglue_elem::value ) || ( (is_spglue_times::value || is_spglue_times2::value) ? T1::is_row : false ); static const bool is_col = ( (T1::is_col || T2::is_col) && is_spglue_elem::value ) || ( (is_spglue_times::value || is_spglue_times2::value) ? T2::is_col : false ); arma_inline SpGlue(const T1& in_A, const T2& in_B); arma_inline SpGlue(const T1& in_A, const T2& in_B, const elem_type in_aux); arma_inline ~SpGlue(); const T1& A; //!< first operand const T2& B; //!< second operand elem_type aux; }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_inplace_strans.hpp0000644000176000001440000000414012260751214024620 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 Alexandre Drouin // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_inplace_strans //! @{ template inline void inplace_strans ( Mat& X, const char* method = "std" ) { arma_extra_debug_sigprint(); const char sig = method[0]; arma_debug_check( ((sig != 's') && (sig != 'l')), "inplace_strans(): unknown method specified" ); const bool low_memory = (sig == 'l'); if( (low_memory == false) || (X.n_rows == X.n_cols) ) { op_strans::apply_mat_inplace(X); } else { // in-place algorithm inspired by: // Fred G. Gustavson, Tadeusz Swirszcz. // In-Place Transposition of Rectangular Matrices. // Applied Parallel Computing. State of the Art in Scientific Computing. // Lecture Notes in Computer Science. Volume 4699, pp. 560-569, 2007. // X.set_size() will check whether we can change the dimensions of X; // X.set_size() will also reuse existing memory, as the number of elements hasn't changed X.set_size(X.n_cols, X.n_rows); const uword m = X.n_cols; const uword n = X.n_rows; std::vector visited(X.n_elem); // TODO: replace std::vector with a better implementation for(uword col = 0; col < m; ++col) for(uword row = 0; row < n; ++row) { const uword pos = col*n + row; if(visited[pos] == false) { uword curr_pos = pos; eT val = X.at(row, col); while(visited[curr_pos] == false) { visited[curr_pos] = true; const uword j = curr_pos / m; const uword i = curr_pos - m * j; const eT tmp = X.at(j, i); X.at(j, i) = val; val = tmp; curr_pos = i*n + j; } } } } } //! @} RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp0000644000176000001440000044412512265411417022675 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Mat //! @{ template inline Mat::~Mat() { arma_extra_debug_sigprint_this(this); if(mem_state == 0) { if(n_elem > arma_config::mat_prealloc) { memory::release( access::rw(mem) ); } } if(arma_config::debug == true) { // try to expose buggy user code that accesses deleted objects access::rw(mem) = 0; } arma_type_check(( is_supported_elem_type::value == false )); } template inline Mat::Mat() : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); } //! construct the matrix to have user specified dimensions template inline Mat::Mat(const uword in_n_rows, const uword in_n_cols) : n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows*in_n_cols) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); } //! construct the matrix to have user specified dimensions and fill with specified pattern template template inline Mat::Mat(const uword in_n_rows, const uword in_n_cols, const fill::fill_class& f) : n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows*in_n_cols) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); (*this).fill(f); } //! constructor used by Row and Col classes template inline Mat::Mat(const arma_vec_indicator&, const uhword in_vec_state) : n_rows( (in_vec_state == 2) ? 1 : 0 ) , n_cols( (in_vec_state == 1) ? 1 : 0 ) , n_elem(0) , vec_state(in_vec_state) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); } //! constructor used by Row and Col classes template inline Mat::Mat(const arma_vec_indicator&, const uword in_n_rows, const uword in_n_cols, const uhword in_vec_state) : n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows*in_n_cols) , vec_state(in_vec_state) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); } template inline Mat::Mat(const arma_fixed_indicator&, const uword in_n_rows, const uword in_n_cols, const uhword in_vec_state, const eT* in_mem) : n_rows (in_n_rows) , n_cols (in_n_cols) , n_elem (in_n_rows*in_n_cols) , vec_state (in_vec_state) , mem_state (3) , mem (in_mem) { arma_extra_debug_sigprint_this(this); } template inline void Mat::init_cold() { arma_extra_debug_sigprint( arma_boost::format("n_rows = %d, n_cols = %d") % n_rows % n_cols ); // ensure that n_elem can hold the result of (n_rows * n_cols) arma_debug_check ( ( ( (n_rows > ARMA_MAX_UHWORD) || (n_cols > ARMA_MAX_UHWORD) ) ? ( (float(n_rows) * float(n_cols)) > float(ARMA_MAX_UWORD) ) : false ), "Mat::init(): requested size is too large; suggest to enable ARMA_64BIT_WORD" ); if(n_elem <= arma_config::mat_prealloc) { arma_extra_debug_print("Mat::init(): using local memory"); access::rw(mem) = mem_local; } else { arma_extra_debug_print("Mat::init(): allocating memory"); access::rw(mem) = memory::acquire(n_elem); } } //! internal matrix construction; if the requested size is small enough, memory from the stack is used. otherwise memory is allocated via 'new' template inline void Mat::init_warm(uword in_n_rows, uword in_n_cols) { arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols = %d") % in_n_rows % in_n_cols ); if( (n_rows == in_n_rows) && (n_cols == in_n_cols) ) { return; } bool err_state = false; char* err_msg = 0; const uhword t_vec_state = vec_state; const uhword t_mem_state = mem_state; arma_debug_set_error ( err_state, err_msg, (t_mem_state == 3), "Mat::init(): size is fixed and hence cannot be changed" ); if(t_vec_state > 0) { if( (in_n_rows == 0) && (in_n_cols == 0) ) { if(t_vec_state == 1) { in_n_cols = 1; } else if(t_vec_state == 2) { in_n_rows = 1; } } else { if(t_vec_state == 1) { arma_debug_set_error ( err_state, err_msg, (in_n_cols != 1), "Mat::init(): requested size is not compatible with column vector layout" ); } else if(t_vec_state == 2) { arma_debug_set_error ( err_state, err_msg, (in_n_rows != 1), "Mat::init(): requested size is not compatible with row vector layout" ); } } } // ensure that n_elem can hold the result of (n_rows * n_cols) arma_debug_set_error ( err_state, err_msg, ( ( (in_n_rows > ARMA_MAX_UHWORD) || (in_n_cols > ARMA_MAX_UHWORD) ) ? ( (float(in_n_rows) * float(in_n_cols)) > float(ARMA_MAX_UWORD) ) : false ), "Mat::init(): requested size is too large" ); arma_debug_check(err_state, err_msg); const uword old_n_elem = n_elem; const uword new_n_elem = in_n_rows * in_n_cols; if(old_n_elem == new_n_elem) { arma_extra_debug_print("Mat::init(): reusing memory"); access::rw(n_rows) = in_n_rows; access::rw(n_cols) = in_n_cols; } else { arma_debug_check ( (t_mem_state == 2), "Mat::init(): mismatch between size of auxiliary memory and requested size" ); if(t_mem_state == 0) { if(old_n_elem > arma_config::mat_prealloc) { arma_extra_debug_print("Mat::init(): freeing memory"); memory::release( access::rw(mem) ); } } if(new_n_elem <= arma_config::mat_prealloc) { arma_extra_debug_print("Mat::init(): using local memory"); access::rw(mem) = mem_local; } else { arma_extra_debug_print("Mat::init(): allocating memory"); access::rw(mem) = memory::acquire(new_n_elem); } access::rw(n_rows) = in_n_rows; access::rw(n_cols) = in_n_cols; access::rw(n_elem) = new_n_elem; access::rw(mem_state) = 0; } } //! create the matrix from a textual description template inline Mat::Mat(const char* text) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init( std::string(text) ); } //! create the matrix from a textual description template inline const Mat& Mat::operator=(const char* text) { arma_extra_debug_sigprint(); init( std::string(text) ); return *this; } //! create the matrix from a textual description template inline Mat::Mat(const std::string& text) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init(text); } //! create the matrix from a textual description template inline const Mat& Mat::operator=(const std::string& text) { arma_extra_debug_sigprint(); init(text); return *this; } //! internal function to create the matrix from a textual description template inline void Mat::init(const std::string& text_orig) { arma_extra_debug_sigprint(); const bool replace_commas = (is_cx::yes) ? false : ( text_orig.find(',') != std::string::npos ); std::string* text_mod = (replace_commas) ? new std::string(text_orig) : NULL; const std::string& text = (replace_commas) ? ( std::replace((*text_mod).begin(), (*text_mod).end(), ',', ' '), (*text_mod) ) : text_orig; // // work out the size uword t_n_rows = 0; uword t_n_cols = 0; bool t_n_cols_found = false; std::string token; std::string::size_type line_start = 0; std::string::size_type line_end = 0; std::stringstream line_stream; while( line_start < text.length() ) { line_end = text.find(';', line_start); if(line_end == std::string::npos) { line_end = text.length()-1; } std::string::size_type line_len = line_end - line_start + 1; line_stream.clear(); line_stream.str( text.substr(line_start,line_len) ); uword line_n_cols = 0; while(line_stream >> token) { ++line_n_cols; } if(line_n_cols > 0) { if(t_n_cols_found == false) { t_n_cols = line_n_cols; t_n_cols_found = true; } else { arma_check( (line_n_cols != t_n_cols), "Mat::init(): inconsistent number of columns in given string"); } ++t_n_rows; } line_start = line_end+1; } Mat& x = *this; x.set_size(t_n_rows, t_n_cols); line_start = 0; line_end = 0; uword urow = 0; while( line_start < text.length() ) { line_end = text.find(';', line_start); if(line_end == std::string::npos) { line_end = text.length()-1; } std::string::size_type line_len = line_end - line_start + 1; line_stream.clear(); line_stream.str( text.substr(line_start,line_len) ); // uword ucol = 0; // while(line_stream >> token) // { // x.at(urow,ucol) = strtod(token.c_str(), 0); // ++ucol; // } uword ucol = 0; eT val; while(line_stream >> val) { x.at(urow,ucol) = val; ++ucol; } ++urow; line_start = line_end+1; } if(replace_commas) { delete text_mod; } } //! create the matrix from std::vector template inline Mat::Mat(const std::vector& x) : n_rows(uword(x.size())) , n_cols(1) , n_elem(uword(x.size())) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); if(n_elem > 0) { arrayops::copy( memptr(), &(x[0]), n_elem ); } } //! create the matrix from std::vector template inline const Mat& Mat::operator=(const std::vector& x) { arma_extra_debug_sigprint(); init_warm(uword(x.size()), 1); if(x.size() > 0) { arrayops::copy( memptr(), &(x[0]), uword(x.size()) ); } return *this; } #if defined(ARMA_USE_CXX11) template inline Mat::Mat(const std::initializer_list& list) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init(list); } template inline const Mat& Mat::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); init(list); return *this; } template inline Mat::Mat(Mat&& X) : n_rows (X.n_rows) , n_cols (X.n_cols) , n_elem (X.n_elem) , vec_state(0 ) , mem_state(0 ) , mem ( ) { arma_extra_debug_sigprint(arma_boost::format("this = %x X = %x") % this % &X); if( ((X.mem_state == 0) && (X.n_elem > arma_config::mat_prealloc)) || (X.mem_state == 1) || (X.mem_state == 2) ) { access::rw(mem_state) = X.mem_state; access::rw(mem) = X.mem; access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem_state) = 0; access::rw(X.mem) = 0; } else { init_cold(); arrayops::copy( memptr(), X.mem, X.n_elem ); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) ) { access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } } } template inline const Mat& Mat::operator=(Mat&& X) { arma_extra_debug_sigprint(arma_boost::format("this = %x X = %x") % this % &X); (*this).steal_mem(X); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) && (this != &X) ) { access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } return *this; } #endif //! Set the matrix to be equal to the specified scalar. //! NOTE: the size of the matrix will be 1x1 template arma_inline const Mat& Mat::operator=(const eT val) { arma_extra_debug_sigprint(); init_warm(1,1); access::rw(mem[0]) = val; return *this; } //! In-place addition of a scalar to all elements of the matrix template arma_inline const Mat& Mat::operator+=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_plus( memptr(), val, n_elem ); return *this; } //! In-place subtraction of a scalar from all elements of the matrix template arma_inline const Mat& Mat::operator-=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_minus( memptr(), val, n_elem ); return *this; } //! In-place multiplication of all elements of the matrix with a scalar template arma_inline const Mat& Mat::operator*=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_mul( memptr(), val, n_elem ); return *this; } //! In-place division of all elements of the matrix with a scalar template arma_inline const Mat& Mat::operator/=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_div( memptr(), val, n_elem ); return *this; } //! construct a matrix from a given matrix template inline Mat::Mat(const Mat& in_mat) : n_rows(in_mat.n_rows) , n_cols(in_mat.n_cols) , n_elem(in_mat.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") % this % &in_mat); init_cold(); arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem ); } //! construct a matrix from a given matrix template inline const Mat& Mat::operator=(const Mat& in_mat) { arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") % this % &in_mat); if(this != &in_mat) { init_warm(in_mat.n_rows, in_mat.n_cols); arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem ); } return *this; } #if defined(ARMA_USE_CXX11) template inline void Mat::init(const std::initializer_list& list) { arma_extra_debug_sigprint(); const uword N = list.size(); set_size(1, N); arrayops::copy( memptr(), list.begin(), N ); } #endif //! for constructing a complex matrix out of two non-complex matrices template template inline void Mat::init ( const Base::pod_type, T1>& X, const Base::pod_type, T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type T; arma_type_check(( is_complex::value == false )); //!< compile-time abort if eT is not std::complex arma_type_check(( is_complex< T>::value == true )); //!< compile-time abort if T is std::complex arma_type_check(( is_same_type< std::complex, eT >::no )); //!< compile-time abort if types are not compatible const Proxy PX(X.get_ref()); const Proxy PY(Y.get_ref()); arma_debug_assert_same_size(PX, PY, "Mat()"); const uword local_n_rows = PX.get_n_rows(); const uword local_n_cols = PX.get_n_cols(); init_warm(local_n_rows, local_n_cols); eT* out_mem = (*this).memptr(); const bool prefer_at_accessor = ( Proxy::prefer_at_accessor || Proxy::prefer_at_accessor ); if(prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const uword N = n_elem; ea_type1 A = PX.get_ea(); ea_type2 B = PY.get_ea(); for(uword ii=0; ii < N; ++ii) { out_mem[ii] = std::complex(A[ii], B[ii]); } } else { for(uword ucol=0; ucol < local_n_cols; ++ucol) for(uword urow=0; urow < local_n_rows; ++urow) { *out_mem = std::complex(PX.at(urow,ucol), PY.at(urow,ucol)); out_mem++; } } } //! swap the contents of this matrix, denoted as matrix A, with given matrix B template inline void Mat::swap(Mat& B) { Mat& A = (*this); arma_extra_debug_sigprint(arma_boost::format("A = %x B = %x") % &A % &B); bool layout_ok = false; if(A.vec_state == B.vec_state) { layout_ok = true; } else { const uhword A_vec_state = A.vec_state; const uhword B_vec_state = B.vec_state; const bool A_absorbs_B = (A_vec_state == 0) || ( (A_vec_state == 1) && (B.n_cols == 1) ) || ( (A_vec_state == 2) && (B.n_rows == 1) ); const bool B_absorbs_A = (B_vec_state == 0) || ( (B_vec_state == 1) && (A.n_cols == 1) ) || ( (B_vec_state == 2) && (A.n_rows == 1) ); layout_ok = A_absorbs_B && B_absorbs_A; } const uhword A_mem_state = A.mem_state; const uhword B_mem_state = B.mem_state; if( (A_mem_state == 0) && (B_mem_state == 0) && layout_ok ) { const uword A_n_elem = A.n_elem; const uword B_n_elem = B.n_elem; const bool A_use_local_mem = (A_n_elem <= arma_config::mat_prealloc); const bool B_use_local_mem = (B_n_elem <= arma_config::mat_prealloc); if( (A_use_local_mem == false) && (B_use_local_mem == false) ) { std::swap( access::rw(A.mem), access::rw(B.mem) ); } else if( (A_use_local_mem == true) && (B_use_local_mem == true) ) { eT* A_mem_local = &(A.mem_local[0]); eT* B_mem_local = &(B.mem_local[0]); access::rw(A.mem) = A_mem_local; access::rw(B.mem) = B_mem_local; const uword N = (std::max)(A_n_elem, B_n_elem); for(uword ii=0; ii < N; ++ii) { std::swap( A_mem_local[ii], B_mem_local[ii] ); } } else if( (A_use_local_mem == true) && (B_use_local_mem == false) ) { eT* A_mem_local = &(A.mem_local[0]); eT* B_mem_local = &(B.mem_local[0]); arrayops::copy(B_mem_local, A_mem_local, A_n_elem); access::rw(A.mem) = B.mem; access::rw(B.mem) = B_mem_local; } else if( (A_use_local_mem == false) && (B_use_local_mem == true) ) { eT* A_mem_local = &(A.mem_local[0]); eT* B_mem_local = &(B.mem_local[0]); arrayops::copy(A_mem_local, B_mem_local, B_n_elem); access::rw(B.mem) = A.mem; access::rw(A.mem) = A_mem_local; } std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); } else if( (A_mem_state <= 2) && (B_mem_state <= 2) && (A.n_elem == B.n_elem) && layout_ok ) { std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); const uword N = A.n_elem; eT* A_mem = A.memptr(); eT* B_mem = B.memptr(); for(uword ii=0; ii < N; ++ii) { std::swap(A_mem[ii], B_mem[ii]); } } else if( (A.n_rows == B.n_rows) && (A.n_cols == B.n_cols) ) { const uword N = A.n_elem; eT* A_mem = A.memptr(); eT* B_mem = B.memptr(); for(uword ii=0; ii < N; ++ii) { std::swap(A_mem[ii], B_mem[ii]); } } else { // generic swap to handle remaining cases if(A.n_elem <= B.n_elem) { Mat C = A; A.steal_mem(B); B.steal_mem(C); } else { Mat C = B; B.steal_mem(A); A.steal_mem(C); } } } //! try to steal the memory from a given matrix; //! if memory can't be stolen, copy the given matrix template inline void Mat::steal_mem(Mat& x) { arma_extra_debug_sigprint(); if(this != &x) { const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; const uword x_n_elem = x.n_elem; const uword x_vec_state = x.vec_state; const uword x_mem_state = x.mem_state; const uword t_vec_state = vec_state; const uword t_mem_state = mem_state; bool layout_ok = false; if(t_vec_state == x_vec_state) { layout_ok = true; } else { if( (t_vec_state == 1) && (x_n_cols == 1) ) { layout_ok = true; } if( (t_vec_state == 2) && (x_n_rows == 1) ) { layout_ok = true; } } if( (t_mem_state <= 1) && ( ((x_mem_state == 0) && (x_n_elem > arma_config::mat_prealloc)) || (x_mem_state == 1) ) && layout_ok ) { reset(); access::rw(n_rows) = x_n_rows; access::rw(n_cols) = x_n_cols; access::rw(n_elem) = x_n_elem; access::rw(mem_state) = x_mem_state; access::rw(mem) = x.mem; access::rw(x.n_rows) = 0; access::rw(x.n_cols) = 0; access::rw(x.n_elem) = 0; access::rw(x.mem_state) = 0; access::rw(x.mem) = 0; } else { (*this).operator=(x); } } } //! construct a matrix from a given auxiliary array of eTs. //! if copy_aux_mem is true, new memory is allocated and the array is copied. //! if copy_aux_mem is false, the auxiliary array is used directly (without allocating memory and copying). //! the default is to copy the array. template inline Mat::Mat(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const bool copy_aux_mem, const bool strict) : n_rows ( aux_n_rows ) , n_cols ( aux_n_cols ) , n_elem ( aux_n_rows*aux_n_cols ) , vec_state( 0 ) , mem_state( copy_aux_mem ? 0 : ( strict ? 2 : 1 ) ) , mem ( copy_aux_mem ? 0 : aux_mem ) { arma_extra_debug_sigprint_this(this); if(copy_aux_mem == true) { init_cold(); arrayops::copy( memptr(), aux_mem, n_elem ); } } //! construct a matrix from a given auxiliary read-only array of eTs. //! the array is copied. template inline Mat::Mat(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols) : n_rows(aux_n_rows) , n_cols(aux_n_cols) , n_elem(aux_n_rows*aux_n_cols) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); arrayops::copy( memptr(), aux_mem, n_elem ); } //! DANGEROUS! Construct a temporary matrix, using auxiliary memory. //! This constructor is NOT intended for usage by user code. //! Its sole purpose is to be used by the Cube class. template inline Mat::Mat(const char junk, const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols) : n_rows (aux_n_rows ) , n_cols (aux_n_cols ) , n_elem (aux_n_rows*aux_n_cols) , vec_state(0 ) , mem_state(3 ) , mem (aux_mem ) { arma_extra_debug_sigprint_this(this); arma_ignore(junk); } //! in-place matrix addition template inline const Mat& Mat::operator+=(const Mat& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "addition"); arrayops::inplace_plus( memptr(), m.memptr(), n_elem ); return *this; } //! in-place matrix subtraction template inline const Mat& Mat::operator-=(const Mat& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "subtraction"); arrayops::inplace_minus( memptr(), m.memptr(), n_elem ); return *this; } //! in-place matrix multiplication template inline const Mat& Mat::operator*=(const Mat& m) { arma_extra_debug_sigprint(); glue_times::apply_inplace(*this, m); return *this; } //! in-place element-wise matrix multiplication template inline const Mat& Mat::operator%=(const Mat& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "element-wise multiplication"); arrayops::inplace_mul( memptr(), m.memptr(), n_elem ); return *this; } //! in-place element-wise matrix division template inline const Mat& Mat::operator/=(const Mat& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "element-wise division"); arrayops::inplace_div( memptr(), m.memptr(), n_elem ); return *this; } template template inline Mat::Mat(const BaseCube& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); (*this).operator=(X); } template template inline const Mat& Mat::operator=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat& out = *this; const unwrap_cube tmp(X.get_ref()); const Cube& in = tmp.M; arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { out.set_size(in_n_rows, in_n_cols); for(uword ucol=0; ucol < in_n_cols; ++ucol) { arrayops::copy( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows ); } } else { if(out_vec_state == 0) { if(in_n_cols == 1) { out.set_size(in_n_rows, in_n_slices); for(uword i=0; i < in_n_slices; ++i) { arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if(in_n_rows == 1) { out.set_size(in_n_cols, in_n_slices); for(uword slice=0; slice < in_n_slices; ++slice) { eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = in.at(0, i, slice); const eT tmp_j = in.at(0, j, slice); out_colptr[i] = tmp_i; out_colptr[j] = tmp_j; } if(i < in_n_cols) { out_colptr[i] = in.at(0, i, slice); } } } } else { out.set_size(in_n_slices); eT* out_mem = out.memptr(); for(uword i=0; i template inline const Mat& Mat::operator+=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat& out = *this; const unwrap_cube tmp(X.get_ref()); const Cube& in = tmp.M; arma_debug_assert_cube_as_mat(out, in, "addition", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword ucol=0; ucol < in_n_cols; ++ucol) { arrayops::inplace_plus( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { for(uword slice=0; slice < in_n_slices; ++slice) { eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = in.at(0, i, slice); const eT tmp_j = in.at(0, j, slice); out_colptr[i] += tmp_i; out_colptr[j] += tmp_j; } if(i < in_n_cols) { out_colptr[i] += in.at(0, i, slice); } } } } else { eT* out_mem = out.memptr(); for(uword i=0; i template inline const Mat& Mat::operator-=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat& out = *this; const unwrap_cube tmp(X.get_ref()); const Cube& in = tmp.M; arma_debug_assert_cube_as_mat(out, in, "subtraction", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword ucol=0; ucol < in_n_cols; ++ucol) { arrayops::inplace_minus( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { for(uword slice=0; slice < in_n_slices; ++slice) { eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = in.at(0, i, slice); const eT tmp_j = in.at(0, j, slice); out_colptr[i] -= tmp_i; out_colptr[j] -= tmp_j; } if(i < in_n_cols) { out_colptr[i] -= in.at(0, i, slice); } } } } else { eT* out_mem = out.memptr(); for(uword i=0; i template inline const Mat& Mat::operator*=(const BaseCube& X) { arma_extra_debug_sigprint(); const Mat B(X); (*this).operator*=(B); return *this; } template template inline const Mat& Mat::operator%=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat& out = *this; const unwrap_cube tmp(X.get_ref()); const Cube& in = tmp.M; arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword ucol=0; ucol < in_n_cols; ++ucol) { arrayops::inplace_mul( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { for(uword slice=0; slice < in_n_slices; ++slice) { eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = in.at(0, i, slice); const eT tmp_j = in.at(0, j, slice); out_colptr[i] *= tmp_i; out_colptr[j] *= tmp_j; } if(i < in_n_cols) { out_colptr[i] *= in.at(0, i, slice); } } } } else { eT* out_mem = out.memptr(); for(uword i=0; i template inline const Mat& Mat::operator/=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat& out = *this; const unwrap_cube tmp(X.get_ref()); const Cube& in = tmp.M; arma_debug_assert_cube_as_mat(out, in, "element-wise division", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword ucol=0; ucol < in_n_cols; ++ucol) { arrayops::inplace_div( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { for(uword slice=0; slice < in_n_slices; ++slice) { eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = in.at(0, i, slice); const eT tmp_j = in.at(0, j, slice); out_colptr[i] /= tmp_i; out_colptr[j] /= tmp_j; } if(i < in_n_cols) { out_colptr[i] /= in.at(0, i, slice); } } } } else { eT* out_mem = out.memptr(); for(uword i=0; i template inline Mat::Mat ( const Base::pod_type,T1>& A, const Base::pod_type,T2>& B ) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init(A,B); } //! construct a matrix from subview (e.g. construct a matrix from a delayed submatrix operation) template inline Mat::Mat(const subview& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); subview::extract(*this, X); } //! construct a matrix from subview (e.g. construct a matrix from a delayed submatrix operation) template inline const Mat& Mat::operator=(const subview& X) { arma_extra_debug_sigprint(); const bool alias = (this == &(X.m)); if(alias == false) { init_warm(X.n_rows, X.n_cols); subview::extract(*this, X); } else { Mat tmp(X); steal_mem(tmp); } return *this; } //! in-place matrix addition (using a submatrix on the right-hand-side) template inline const Mat& Mat::operator+=(const subview& X) { arma_extra_debug_sigprint(); subview::plus_inplace(*this, X); return *this; } //! in-place matrix subtraction (using a submatrix on the right-hand-side) template inline const Mat& Mat::operator-=(const subview& X) { arma_extra_debug_sigprint(); subview::minus_inplace(*this, X); return *this; } //! in-place matrix mutiplication (using a submatrix on the right-hand-side) template inline const Mat& Mat::operator*=(const subview& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace(*this, X); return *this; } //! in-place element-wise matrix mutiplication (using a submatrix on the right-hand-side) template inline const Mat& Mat::operator%=(const subview& X) { arma_extra_debug_sigprint(); subview::schur_inplace(*this, X); return *this; } //! in-place element-wise matrix division (using a submatrix on the right-hand-side) template inline const Mat& Mat::operator/=(const subview& X) { arma_extra_debug_sigprint(); subview::div_inplace(*this, X); return *this; } template inline Mat::Mat(const subview_row_strans& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); X.extract(*this); } template inline Mat::Mat(const subview_row_htrans& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); X.extract(*this); } template inline Mat::Mat(const xvec_htrans& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); X.extract(*this); } //! construct a matrix from a subview_cube instance template inline Mat::Mat(const subview_cube& x) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); this->operator=(x); } //! construct a matrix from a subview_cube instance template inline const Mat& Mat::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::extract(*this, X); return *this; } //! in-place matrix addition (using a single-slice subcube on the right-hand-side) template inline const Mat& Mat::operator+=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::plus_inplace(*this, X); return *this; } //! in-place matrix subtraction (using a single-slice subcube on the right-hand-side) template inline const Mat& Mat::operator-=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::minus_inplace(*this, X); return *this; } //! in-place matrix mutiplication (using a single-slice subcube on the right-hand-side) template inline const Mat& Mat::operator*=(const subview_cube& X) { arma_extra_debug_sigprint(); const Mat tmp(X); glue_times::apply_inplace(*this, tmp); return *this; } //! in-place element-wise matrix mutiplication (using a single-slice subcube on the right-hand-side) template inline const Mat& Mat::operator%=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::schur_inplace(*this, X); return *this; } //! in-place element-wise matrix division (using a single-slice subcube on the right-hand-side) template inline const Mat& Mat::operator/=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::div_inplace(*this, X); return *this; } //! construct a matrix from diagview (e.g. construct a matrix from a delayed diag operation) template inline Mat::Mat(const diagview& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); diagview::extract(*this, X); } //! construct a matrix from diagview (e.g. construct a matrix from a delayed diag operation) template inline const Mat& Mat::operator=(const diagview& X) { arma_extra_debug_sigprint(); const bool alias = (this == &(X.m)); if(alias == false) { init_warm(X.n_rows, X.n_cols); diagview::extract(*this, X); } else { Mat tmp(X); steal_mem(tmp); } return *this; } //! in-place matrix addition (using a diagview on the right-hand-side) template inline const Mat& Mat::operator+=(const diagview& X) { arma_extra_debug_sigprint(); diagview::plus_inplace(*this, X); return *this; } //! in-place matrix subtraction (using a diagview on the right-hand-side) template inline const Mat& Mat::operator-=(const diagview& X) { arma_extra_debug_sigprint(); diagview::minus_inplace(*this, X); return *this; } //! in-place matrix mutiplication (using a diagview on the right-hand-side) template inline const Mat& Mat::operator*=(const diagview& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace(*this, X); return *this; } //! in-place element-wise matrix mutiplication (using a diagview on the right-hand-side) template inline const Mat& Mat::operator%=(const diagview& X) { arma_extra_debug_sigprint(); diagview::schur_inplace(*this, X); return *this; } //! in-place element-wise matrix division (using a diagview on the right-hand-side) template inline const Mat& Mat::operator/=(const diagview& X) { arma_extra_debug_sigprint(); diagview::div_inplace(*this, X); return *this; } template template inline Mat::Mat(const subview_elem1& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); this->operator=(X); } template template inline const Mat& Mat::operator=(const subview_elem1& X) { arma_extra_debug_sigprint(); subview_elem1::extract(*this, X); return *this; } template template inline const Mat& Mat::operator+=(const subview_elem1& X) { arma_extra_debug_sigprint(); subview_elem1::plus_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator-=(const subview_elem1& X) { arma_extra_debug_sigprint(); subview_elem1::minus_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator*=(const subview_elem1& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator%=(const subview_elem1& X) { arma_extra_debug_sigprint(); subview_elem1::schur_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator/=(const subview_elem1& X) { arma_extra_debug_sigprint(); subview_elem1::div_inplace(*this, X); return *this; } template template inline Mat::Mat(const subview_elem2& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); this->operator=(X); } template template inline const Mat& Mat::operator=(const subview_elem2& X) { arma_extra_debug_sigprint(); subview_elem2::extract(*this, X); return *this; } template template inline const Mat& Mat::operator+=(const subview_elem2& X) { arma_extra_debug_sigprint(); subview_elem2::plus_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator-=(const subview_elem2& X) { arma_extra_debug_sigprint(); subview_elem2::minus_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator*=(const subview_elem2& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator%=(const subview_elem2& X) { arma_extra_debug_sigprint(); subview_elem2::schur_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator/=(const subview_elem2& X) { arma_extra_debug_sigprint(); subview_elem2::div_inplace(*this, X); return *this; } template template inline Mat::Mat(const SpBase& m) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); const SpProxy p(m.get_ref()); access::rw(n_rows) = p.get_n_rows(); access::rw(n_cols) = p.get_n_cols(); access::rw(n_elem) = p.get_n_elem(); init_cold(); zeros(); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { at(it.row(), it.col()) = (*it); ++it; } } template template inline const Mat& Mat::operator=(const SpBase& m) { arma_extra_debug_sigprint(); const SpProxy p(m.get_ref()); init_warm(p.get_n_rows(), p.get_n_cols()); zeros(); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { at(it.row(), it.col()) = (*it); ++it; } return *this; } template template inline const Mat& Mat::operator+=(const SpBase& m) { arma_extra_debug_sigprint(); const SpProxy p(m.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "addition"); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { at(it.row(), it.col()) += (*it); ++it; } return *this; } template template inline const Mat& Mat::operator-=(const SpBase& m) { arma_extra_debug_sigprint(); const SpProxy p(m.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "subtraction"); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { at(it.row(), it.col()) -= (*it); ++it; } return *this; } template template inline const Mat& Mat::operator*=(const SpBase& m) { arma_extra_debug_sigprint(); Mat z; z = (*this) * m.get_ref(); steal_mem(z); return *this; } template template inline const Mat& Mat::operator%=(const SpBase& m) { arma_extra_debug_sigprint(); const SpProxy p(m.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise multiplication"); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); // We have to zero everything that isn't being used. arrayops::inplace_set(memptr(), eT(0), (it.col() * n_rows) + it.row()); while(it != it_end) { const uword cur_loc = (it.col() * n_rows) + it.row(); access::rw(mem[cur_loc]) *= (*it); ++it; const uword next_loc = (it == it_end) ? (p.get_n_cols() * n_rows) : (it.col() * n_rows) + it.row(); arrayops::inplace_set(memptr() + cur_loc + 1, eT(0), (next_loc - cur_loc - 1)); } return *this; } template template inline const Mat& Mat::operator/=(const SpBase& m) { arma_extra_debug_sigprint(); const SpProxy p(m.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise division"); // If you use this method, you are probably stupid or misguided, but for completeness it is implemented. // Unfortunately the best way to do this is loop over every element. for(uword c = 0; c < n_cols; ++c) for(uword r = 0; r < n_rows; ++r) { at(r, c) /= p.at(r, c); } return *this; } template inline mat_injector< Mat > Mat::operator<<(const eT val) { return mat_injector< Mat >(*this, val); } template inline mat_injector< Mat > Mat::operator<<(const injector_end_of_row<>& x) { return mat_injector< Mat >(*this, x); } //! creation of subview (row vector) template arma_inline subview_row Mat::row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( row_num >= n_rows, "Mat::row(): index out of bounds" ); return subview_row(*this, row_num); } //! creation of subview (row vector) template arma_inline const subview_row Mat::row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( row_num >= n_rows, "Mat::row(): index out of bounds" ); return subview_row(*this, row_num); } template inline subview_row Mat::operator()(const uword row_num, const span& col_span) { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::operator(): indices out of bounds or incorrectly used" ); return subview_row(*this, row_num, in_col1, submat_n_cols); } template inline const subview_row Mat::operator()(const uword row_num, const span& col_span) const { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::operator(): indices out of bounds or incorrectly used" ); return subview_row(*this, row_num, in_col1, submat_n_cols); } //! creation of subview (column vector) template arma_inline subview_col Mat::col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "Mat::col(): index out of bounds"); return subview_col(*this, col_num); } //! creation of subview (column vector) template arma_inline const subview_col Mat::col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "Mat::col(): index out of bounds"); return subview_col(*this, col_num); } template inline subview_col Mat::operator()(const span& row_span, const uword col_num) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "Mat::operator(): indices out of bounds or incorrectly used" ); return subview_col(*this, col_num, in_row1, submat_n_rows); } template inline const subview_col Mat::operator()(const span& row_span, const uword col_num) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "Mat::operator(): indices out of bounds or incorrectly used" ); return subview_col(*this, col_num, in_row1, submat_n_rows); } //! create a Col object which uses memory from an existing matrix object. //! this approach is currently not alias safe //! and does not take into account that the parent matrix object could be deleted. //! if deleted memory is accessed by the created Col object, //! it will cause memory corruption and/or a crash template inline Col Mat::unsafe_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): index out of bounds"); return Col(colptr(col_num), n_rows, false, true); } //! create a Col object which uses memory from an existing matrix object. //! this approach is currently not alias safe //! and does not take into account that the parent matrix object could be deleted. //! if deleted memory is accessed by the created Col object, //! it will cause memory corruption and/or a crash template inline const Col Mat::unsafe_col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): index out of bounds"); typedef const Col out_type; return out_type(const_cast(colptr(col_num)), n_rows, false, true); } //! creation of subview (submatrix comprised of specified row vectors) template arma_inline subview Mat::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "Mat::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview(*this, in_row1, 0, subview_n_rows, n_cols ); } //! creation of subview (submatrix comprised of specified row vectors) template arma_inline const subview Mat::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "Mat::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview(*this, in_row1, 0, subview_n_rows, n_cols ); } //! creation of subview (submatrix comprised of specified column vectors) template arma_inline subview Mat::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "Mat::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview(*this, 0, in_col1, n_rows, subview_n_cols); } //! creation of subview (submatrix comprised of specified column vectors) template arma_inline const subview Mat::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "Mat::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview(*this, 0, in_col1, n_rows, subview_n_cols); } //! creation of subview (submatrix comprised of specified row vectors) template inline subview Mat::rows(const span& row_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "Mat::rows(): indices out of bounds or incorrectly used" ); return subview(*this, in_row1, 0, submat_n_rows, n_cols); } //! creation of subview (submatrix comprised of specified row vectors) template inline const subview Mat::rows(const span& row_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "Mat::rows(): indices out of bounds or incorrectly used" ); return subview(*this, in_row1, 0, submat_n_rows, n_cols); } //! creation of subview (submatrix comprised of specified column vectors) template arma_inline subview Mat::cols(const span& col_span) { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::cols(): indices out of bounds or incorrectly used" ); return subview(*this, 0, in_col1, n_rows, submat_n_cols); } //! creation of subview (submatrix comprised of specified column vectors) template arma_inline const subview Mat::cols(const span& col_span) const { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::cols(): indices out of bounds or incorrectly used" ); return subview(*this, 0, in_col1, n_rows, submat_n_cols); } //! creation of subview (submatrix) template arma_inline subview Mat::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "Mat::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; return subview(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); } //! creation of subview (generic submatrix) template arma_inline const subview Mat::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "Mat::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; return subview(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); } //! creation of subview (submatrix) template arma_inline subview Mat::submat(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "Mat::submat(): indices or size out of bounds" ); return subview(*this, in_row1, in_col1, s_n_rows, s_n_cols); } //! creation of subview (submatrix) template arma_inline const subview Mat::submat(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "Mat::submat(): indices or size out of bounds" ); return subview(*this, in_row1, in_col1, s_n_rows, s_n_cols); } //! creation of subview (submatrix) template inline subview Mat::submat(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::submat(): indices out of bounds or incorrectly used" ); return subview(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); } //! creation of subview (generic submatrix) template inline const subview Mat::submat(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::submat(): indices out of bounds or incorrectly used" ); return subview(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); } template inline subview Mat::operator()(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); return (*this).submat(row_span, col_span); } template inline const subview Mat::operator()(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); return (*this).submat(row_span, col_span); } template inline subview Mat::operator()(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).submat(in_row1, in_col1, s); } template inline const subview Mat::operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); return (*this).submat(in_row1, in_col1, s); } template template arma_inline subview_elem1 Mat::elem(const Base& a) { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline const subview_elem1 Mat::elem(const Base& a) const { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline subview_elem1 Mat::operator()(const Base& a) { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline const subview_elem1 Mat::operator()(const Base& a) const { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline subview_elem2 Mat::elem(const Base& ri, const Base& ci) { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline const subview_elem2 Mat::elem(const Base& ri, const Base& ci) const { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline subview_elem2 Mat::submat(const Base& ri, const Base& ci) { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline const subview_elem2 Mat::submat(const Base& ri, const Base& ci) const { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline subview_elem2 Mat::operator()(const Base& ri, const Base& ci) { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline const subview_elem2 Mat::operator()(const Base& ri, const Base& ci) const { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline subview_elem2 Mat::rows(const Base& ri) { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ri, false, true); } template template arma_inline const subview_elem2 Mat::rows(const Base& ri) const { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ri, false, true); } template template arma_inline subview_elem2 Mat::cols(const Base& ci) { arma_extra_debug_sigprint(); return subview_elem2(*this, ci, ci, true, false); } template template arma_inline const subview_elem2 Mat::cols(const Base& ci) const { arma_extra_debug_sigprint(); return subview_elem2(*this, ci, ci, true, false); } template arma_inline subview_each1< Mat, 0 > Mat::each_col() { arma_extra_debug_sigprint(); return subview_each1< Mat, 0>(*this); } template arma_inline subview_each1< Mat, 1 > Mat::each_row() { arma_extra_debug_sigprint(); return subview_each1< Mat, 1>(*this); } template template inline subview_each2< Mat, 0, T1 > Mat::each_col(const Base& indices) { arma_extra_debug_sigprint(); return subview_each2< Mat, 0, T1 >(*this, indices); } template template inline subview_each2< Mat, 1, T1 > Mat::each_row(const Base& indices) { arma_extra_debug_sigprint(); return subview_each2< Mat, 1, T1 >(*this, indices); } //! creation of diagview (diagonal) template arma_inline diagview Mat::diag(const sword in_id) { arma_extra_debug_sigprint(); const uword row_offset = (in_id < 0) ? uword(-in_id) : 0; const uword col_offset = (in_id > 0) ? uword( in_id) : 0; arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "Mat::diag(): requested diagonal out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); return diagview(*this, row_offset, col_offset, len); } //! creation of diagview (diagonal) template arma_inline const diagview Mat::diag(const sword in_id) const { arma_extra_debug_sigprint(); const uword row_offset = (in_id < 0) ? -in_id : 0; const uword col_offset = (in_id > 0) ? in_id : 0; arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "Mat::diag(): requested diagonal out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); return diagview(*this, row_offset, col_offset, len); } template inline void Mat::swap_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; arma_debug_check ( (in_row1 >= local_n_rows) || (in_row2 >= local_n_rows), "Mat::swap_rows(): index out of bounds" ); if(n_elem > 0) { for(uword ucol=0; ucol < local_n_cols; ++ucol) { const uword offset = ucol * local_n_rows; const uword pos1 = in_row1 + offset; const uword pos2 = in_row2 + offset; std::swap( access::rw(mem[pos1]), access::rw(mem[pos2]) ); } } } template inline void Mat::swap_cols(const uword in_colA, const uword in_colB) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; arma_debug_check ( (in_colA >= local_n_cols) || (in_colB >= local_n_cols), "Mat::swap_cols(): index out of bounds" ); if(n_elem > 0) { eT* ptrA = colptr(in_colA); eT* ptrB = colptr(in_colB); eT tmp_i; eT tmp_j; uword iq,jq; for(iq=0, jq=1; jq < local_n_rows; iq+=2, jq+=2) { tmp_i = ptrA[iq]; tmp_j = ptrA[jq]; ptrA[iq] = ptrB[iq]; ptrA[jq] = ptrB[jq]; ptrB[iq] = tmp_i; ptrB[jq] = tmp_j; } if(iq < local_n_rows) { std::swap( ptrA[iq], ptrB[iq] ); } } } //! remove specified row template inline void Mat::shed_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( row_num >= n_rows, "Mat::shed_row(): index out of bounds"); shed_rows(row_num, row_num); } //! remove specified column template inline void Mat::shed_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "Mat::shed_col(): index out of bounds"); shed_cols(col_num, col_num); } //! remove specified rows template inline void Mat::shed_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "Mat::shed_rows(): indices out of bounds or incorrectly used" ); const uword n_keep_front = in_row1; const uword n_keep_back = n_rows - (in_row2 + 1); Mat X(n_keep_front + n_keep_back, n_cols); if(n_keep_front > 0) { X.rows( 0, (n_keep_front-1) ) = rows( 0, (in_row1-1) ); } if(n_keep_back > 0) { X.rows( n_keep_front, (n_keep_front+n_keep_back-1) ) = rows( (in_row2+1), (n_rows-1) ); } steal_mem(X); } //! remove specified columns template inline void Mat::shed_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "Mat::shed_cols(): indices out of bounds or incorrectly used" ); const uword n_keep_front = in_col1; const uword n_keep_back = n_cols - (in_col2 + 1); Mat X(n_rows, n_keep_front + n_keep_back); if(n_keep_front > 0) { X.cols( 0, (n_keep_front-1) ) = cols( 0, (in_col1-1) ); } if(n_keep_back > 0) { X.cols( n_keep_front, (n_keep_front+n_keep_back-1) ) = cols( (in_col2+1), (n_cols-1) ); } steal_mem(X); } //! insert N rows at the specified row position, //! optionally setting the elements of the inserted rows to zero template inline void Mat::insert_rows(const uword row_num, const uword N, const bool set_to_zero) { arma_extra_debug_sigprint(); const uword t_n_rows = n_rows; const uword t_n_cols = n_cols; const uword A_n_rows = row_num; const uword B_n_rows = t_n_rows - row_num; // insertion at row_num == n_rows is in effect an append operation arma_debug_check( (row_num > t_n_rows), "Mat::insert_rows(): index out of bounds"); if(N > 0) { Mat out(t_n_rows + N, t_n_cols); if(A_n_rows > 0) { out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1); } if(B_n_rows > 0) { out.rows(row_num + N, t_n_rows + N - 1) = rows(row_num, t_n_rows-1); } if(set_to_zero == true) { out.rows(row_num, row_num + N - 1).zeros(); } steal_mem(out); } } //! insert N columns at the specified column position, //! optionally setting the elements of the inserted columns to zero template inline void Mat::insert_cols(const uword col_num, const uword N, const bool set_to_zero) { arma_extra_debug_sigprint(); const uword t_n_rows = n_rows; const uword t_n_cols = n_cols; const uword A_n_cols = col_num; const uword B_n_cols = t_n_cols - col_num; // insertion at col_num == n_cols is in effect an append operation arma_debug_check( (col_num > t_n_cols), "Mat::insert_cols(): index out of bounds"); if(N > 0) { Mat out(t_n_rows, t_n_cols + N); if(A_n_cols > 0) { out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1); } if(B_n_cols > 0) { out.cols(col_num + N, t_n_cols + N - 1) = cols(col_num, t_n_cols-1); } if(set_to_zero == true) { out.cols(col_num, col_num + N - 1).zeros(); } steal_mem(out); } } //! insert the given object at the specified row position; //! the given object must have the same number of columns as the matrix template template inline void Mat::insert_rows(const uword row_num, const Base& X) { arma_extra_debug_sigprint(); const unwrap tmp(X.get_ref()); const Mat& C = tmp.M; const uword C_n_rows = C.n_rows; const uword C_n_cols = C.n_cols; const uword t_n_rows = n_rows; const uword t_n_cols = n_cols; const uword A_n_rows = row_num; const uword B_n_rows = t_n_rows - row_num; bool err_state = false; char* err_msg = 0; // insertion at row_num == n_rows is in effect an append operation arma_debug_set_error ( err_state, err_msg, (row_num > t_n_rows), "Mat::insert_rows(): index out of bounds" ); arma_debug_set_error ( err_state, err_msg, ( (C_n_cols != t_n_cols) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ), "Mat::insert_rows(): given object has an incompatible number of columns" ); arma_debug_check(err_state, err_msg); if(C_n_rows > 0) { Mat out( t_n_rows + C_n_rows, (std::max)(t_n_cols, C_n_cols) ); if(t_n_cols > 0) { if(A_n_rows > 0) { out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1); } if( (t_n_cols > 0) && (B_n_rows > 0) ) { out.rows(row_num + C_n_rows, t_n_rows + C_n_rows - 1) = rows(row_num, t_n_rows - 1); } } if(C_n_cols > 0) { out.rows(row_num, row_num + C_n_rows - 1) = C; } steal_mem(out); } } //! insert the given object at the specified column position; //! the given object must have the same number of rows as the matrix template template inline void Mat::insert_cols(const uword col_num, const Base& X) { arma_extra_debug_sigprint(); const unwrap tmp(X.get_ref()); const Mat& C = tmp.M; const uword C_n_rows = C.n_rows; const uword C_n_cols = C.n_cols; const uword t_n_rows = n_rows; const uword t_n_cols = n_cols; const uword A_n_cols = col_num; const uword B_n_cols = t_n_cols - col_num; bool err_state = false; char* err_msg = 0; // insertion at col_num == n_cols is in effect an append operation arma_debug_set_error ( err_state, err_msg, (col_num > t_n_cols), "Mat::insert_cols(): index out of bounds" ); arma_debug_set_error ( err_state, err_msg, ( (C_n_rows != t_n_rows) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ), "Mat::insert_cols(): given object has an incompatible number of rows" ); arma_debug_check(err_state, err_msg); if(C_n_cols > 0) { Mat out( (std::max)(t_n_rows, C_n_rows), t_n_cols + C_n_cols ); if(t_n_rows > 0) { if(A_n_cols > 0) { out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1); } if(B_n_cols > 0) { out.cols(col_num + C_n_cols, t_n_cols + C_n_cols - 1) = cols(col_num, t_n_cols - 1); } } if(C_n_rows > 0) { out.cols(col_num, col_num + C_n_cols - 1) = C; } steal_mem(out); } } template template inline Mat::Mat(const Gen& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(n_rows*n_cols) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); init_cold(); X.apply(*this); } template template inline const Mat& Mat::operator=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); init_warm(X.n_rows, X.n_cols); X.apply(*this); return *this; } template template inline const Mat& Mat::operator+=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); X.apply_inplace_plus(*this); return *this; } template template inline const Mat& Mat::operator-=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); X.apply_inplace_minus(*this); return *this; } template template inline const Mat& Mat::operator*=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Mat tmp(X); return (*this).operator*=(tmp); } template template inline const Mat& Mat::operator%=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); X.apply_inplace_schur(*this); return *this; } template template inline const Mat& Mat::operator/=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); X.apply_inplace_div(*this); return *this; } //! create a matrix from Op, i.e. run the previously delayed unary operations template template inline Mat::Mat(const Op& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); op_type::apply(*this, X); } //! create a matrix from Op, i.e. run the previously delayed unary operations template template inline const Mat& Mat::operator=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); op_type::apply(*this, X); return *this; } //! in-place matrix addition, with the right-hand-side operand having delayed operations template template inline const Mat& Mat::operator+=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Mat m(X); return (*this).operator+=(m); } //! in-place matrix subtraction, with the right-hand-side operand having delayed operations template template inline const Mat& Mat::operator-=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Mat m(X); return (*this).operator-=(m); } //! in-place matrix multiplication, with the right-hand-side operand having delayed operations template template inline const Mat& Mat::operator*=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); glue_times::apply_inplace(*this, X); return *this; } //! in-place matrix element-wise multiplication, with the right-hand-side operand having delayed operations template template inline const Mat& Mat::operator%=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Mat m(X); return (*this).operator%=(m); } //! in-place matrix element-wise division, with the right-hand-side operand having delayed operations template template inline const Mat& Mat::operator/=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Mat m(X); return (*this).operator/=(m); } //! create a matrix from eOp, i.e. run the previously delayed unary operations template template inline Mat::Mat(const eOp& X) : n_rows(X.get_n_rows()) , n_cols(X.get_n_cols()) , n_elem(X.get_n_elem()) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); init_cold(); eop_type::apply(*this, X); } //! create a matrix from eOp, i.e. run the previously delayed unary operations template template inline const Mat& Mat::operator=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const bool bad_alias = (eOp::proxy_type::has_subview && X.P.is_alias(*this)); if(bad_alias == false) { init_warm(X.get_n_rows(), X.get_n_cols()); eop_type::apply(*this, X); } else { arma_extra_debug_print("bad_alias = true"); Mat tmp(X); steal_mem(tmp); } return *this; } template template inline const Mat& Mat::operator+=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_plus(*this, X); return *this; } template template inline const Mat& Mat::operator-=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_minus(*this, X); return *this; } template template inline const Mat& Mat::operator*=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); glue_times::apply_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator%=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_schur(*this, X); return *this; } template template inline const Mat& Mat::operator/=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_div(*this, X); return *this; } //! EXPERIMENTAL template template inline Mat::Mat(const mtOp& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); op_type::apply(*this, X); } //! EXPERIMENTAL template template inline const Mat& Mat::operator=(const mtOp& X) { arma_extra_debug_sigprint(); op_type::apply(*this, X); return *this; } //! EXPERIMENTAL template template inline const Mat& Mat::operator+=(const mtOp& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator+=(m); } //! EXPERIMENTAL template template inline const Mat& Mat::operator-=(const mtOp& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator-=(m); } //! EXPERIMENTAL template template inline const Mat& Mat::operator*=(const mtOp& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator*=(m); } //! EXPERIMENTAL template template inline const Mat& Mat::operator%=(const mtOp& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator%=(m); } //! EXPERIMENTAL template template inline const Mat& Mat::operator/=(const mtOp& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator/=(m); } //! create a matrix from Glue, i.e. run the previously delayed binary operations template template inline Mat::Mat(const Glue& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); glue_type::apply(*this, X); } //! create a matrix from Glue, i.e. run the previously delayed binary operations template template inline const Mat& Mat::operator=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); glue_type::apply(*this, X); return *this; } //! in-place matrix addition, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator+=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Mat m(X); return (*this).operator+=(m); } //! in-place matrix subtraction, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator-=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Mat m(X); return (*this).operator-=(m); } //! in-place matrix multiplications, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator*=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); glue_times::apply_inplace(*this, X); return *this; } //! in-place matrix element-wise multiplication, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator%=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Mat m(X); return (*this).operator%=(m); } //! in-place matrix element-wise division, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator/=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Mat m(X); return (*this).operator/=(m); } template template inline const Mat& Mat::operator+=(const Glue& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace_plus(*this, X, sword(+1)); return *this; } template template inline const Mat& Mat::operator-=(const Glue& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace_plus(*this, X, sword(-1)); return *this; } //! create a matrix from eGlue, i.e. run the previously delayed binary operations template template inline Mat::Mat(const eGlue& X) : n_rows(X.get_n_rows()) , n_cols(X.get_n_cols()) , n_elem(X.get_n_elem()) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); init_cold(); eglue_type::apply(*this, X); } //! create a matrix from eGlue, i.e. run the previously delayed binary operations template template inline const Mat& Mat::operator=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const bool bad_alias = ( (eGlue::proxy1_type::has_subview && X.P1.is_alias(*this)) || (eGlue::proxy2_type::has_subview && X.P2.is_alias(*this)) ); if(bad_alias == false) { init_warm(X.get_n_rows(), X.get_n_cols()); eglue_type::apply(*this, X); } else { arma_extra_debug_print("bad_alias = true"); Mat tmp(X); steal_mem(tmp); } return *this; } //! in-place matrix addition, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator+=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_plus(*this, X); return *this; } //! in-place matrix subtraction, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator-=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_minus(*this, X); return *this; } template template inline const Mat& Mat::operator*=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); glue_times::apply_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator%=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_schur(*this, X); return *this; } template template inline const Mat& Mat::operator/=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_div(*this, X); return *this; } //! EXPERIMENTAL: create a matrix from mtGlue, i.e. run the previously delayed binary operations template template inline Mat::Mat(const mtGlue& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); glue_type::apply(*this, X); } //! EXPERIMENTAL: create a matrix from Glue, i.e. run the previously delayed binary operations template template inline const Mat& Mat::operator=(const mtGlue& X) { arma_extra_debug_sigprint(); glue_type::apply(*this, X); return *this; } //! EXPERIMENTAL: in-place matrix addition, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator+=(const mtGlue& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator+=(m); } //! EXPERIMENTAL: in-place matrix subtraction, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator-=(const mtGlue& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator-=(m); } //! EXPERIMENTAL: in-place matrix multiplications, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator*=(const mtGlue& X) { arma_extra_debug_sigprint(); const Mat m(X); glue_times::apply_inplace(*this, m); return *this; } //! EXPERIMENTAL: in-place matrix element-wise multiplication, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator%=(const mtGlue& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator%=(m); } //! EXPERIMENTAL: in-place matrix element-wise division, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator/=(const mtGlue& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator/=(m); } //! linear element accessor (treats the matrix as a vector); no bounds check; assumes memory is aligned template arma_inline arma_warn_unused const eT& Mat::at_alt(const uword ii) const { const eT* mem_aligned = mem; memory::mark_as_aligned(mem_aligned); return mem_aligned[ii]; } //! linear element accessor (treats the matrix as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused eT& Mat::operator() (const uword ii) { arma_debug_check( (ii >= n_elem), "Mat::operator(): index out of bounds"); return access::rw(mem[ii]); } //! linear element accessor (treats the matrix as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused const eT& Mat::operator() (const uword ii) const { arma_debug_check( (ii >= n_elem), "Mat::operator(): index out of bounds"); return mem[ii]; } //! linear element accessor (treats the matrix as a vector); no bounds check. template arma_inline arma_warn_unused eT& Mat::operator[] (const uword ii) { return access::rw(mem[ii]); } //! linear element accessor (treats the matrix as a vector); no bounds check template arma_inline arma_warn_unused const eT& Mat::operator[] (const uword ii) const { return mem[ii]; } //! linear element accessor (treats the matrix as a vector); no bounds check. template arma_inline arma_warn_unused eT& Mat::at(const uword ii) { return access::rw(mem[ii]); } //! linear element accessor (treats the matrix as a vector); no bounds check template arma_inline arma_warn_unused const eT& Mat::at(const uword ii) const { return mem[ii]; } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused eT& Mat::operator() (const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): index out of bounds"); return access::rw(mem[in_row + in_col*n_rows]); } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused const eT& Mat::operator() (const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): index out of bounds"); return mem[in_row + in_col*n_rows]; } //! element accessor; no bounds check template arma_inline arma_warn_unused eT& Mat::at(const uword in_row, const uword in_col) { return access::rw( mem[in_row + in_col*n_rows] ); } //! element accessor; no bounds check template arma_inline arma_warn_unused const eT& Mat::at(const uword in_row, const uword in_col) const { return mem[in_row + in_col*n_rows]; } //! prefix ++ template arma_inline const Mat& Mat::operator++() { Mat_aux::prefix_pp(*this); return *this; } //! postfix ++ (must not return the object by reference) template arma_inline void Mat::operator++(int) { Mat_aux::postfix_pp(*this); } //! prefix -- template arma_inline const Mat& Mat::operator--() { Mat_aux::prefix_mm(*this); return *this; } //! postfix -- (must not return the object by reference) template arma_inline void Mat::operator--(int) { Mat_aux::postfix_mm(*this); } //! returns true if the matrix has no elements template arma_inline arma_warn_unused bool Mat::is_empty() const { return (n_elem == 0); } //! returns true if the object can be interpreted as a column or row vector template arma_inline arma_warn_unused bool Mat::is_vec() const { return ( (n_rows == 1) || (n_cols == 1) ); } //! returns true if the object can be interpreted as a row vector template arma_inline arma_warn_unused bool Mat::is_rowvec() const { return (n_rows == 1); } //! returns true if the object can be interpreted as a column vector template arma_inline arma_warn_unused bool Mat::is_colvec() const { return (n_cols == 1); } //! returns true if the object has the same number of non-zero rows and columnns template arma_inline arma_warn_unused bool Mat::is_square() const { return (n_rows == n_cols); } //! returns true if all of the elements are finite template inline arma_warn_unused bool Mat::is_finite() const { return arrayops::is_finite( memptr(), n_elem ); } //! returns true if the given index is currently in range template arma_inline arma_warn_unused bool Mat::in_range(const uword ii) const { return (ii < n_elem); } //! returns true if the given start and end indices are currently in range template arma_inline arma_warn_unused bool Mat::in_range(const span& x) const { arma_extra_debug_sigprint(); if(x.whole == true) { return true; } else { const uword a = x.a; const uword b = x.b; return ( (a <= b) && (b < n_elem) ); } } //! returns true if the given location is currently in range template arma_inline arma_warn_unused bool Mat::in_range(const uword in_row, const uword in_col) const { return ( (in_row < n_rows) && (in_col < n_cols) ); } template arma_inline arma_warn_unused bool Mat::in_range(const span& row_span, const uword in_col) const { arma_extra_debug_sigprint(); if(row_span.whole == true) { return (in_col < n_cols); } else { const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) ); } } template arma_inline arma_warn_unused bool Mat::in_range(const uword in_row, const span& col_span) const { arma_extra_debug_sigprint(); if(col_span.whole == true) { return (in_row < n_rows); } else { const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) ); } } template arma_inline arma_warn_unused bool Mat::in_range(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) ); const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) ); return ( (rows_ok == true) && (cols_ok == true) ); } template arma_inline arma_warn_unused bool Mat::in_range(const uword in_row, const uword in_col, const SizeMat& s) const { const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; if( (in_row >= l_n_rows) || (in_col >= l_n_cols) || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) ) { return false; } else { return true; } } //! returns a pointer to array of eTs for a specified column; no bounds check template arma_inline arma_warn_unused eT* Mat::colptr(const uword in_col) { return & access::rw(mem[in_col*n_rows]); } //! returns a pointer to array of eTs for a specified column; no bounds check template arma_inline arma_warn_unused const eT* Mat::colptr(const uword in_col) const { return & mem[in_col*n_rows]; } //! returns a pointer to array of eTs used by the matrix template arma_inline arma_warn_unused eT* Mat::memptr() { return const_cast(mem); } //! returns a pointer to array of eTs used by the matrix template arma_inline arma_warn_unused const eT* Mat::memptr() const { return mem; } //! print contents of the matrix (to the cout stream), //! optionally preceding with a user specified line of text. //! the precision and cell width are modified. //! on return, the stream's state are restored to their original values. template inline void Mat::impl_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, true); } //! print contents of the matrix to a user specified stream, //! optionally preceding with a user specified line of text. //! the precision and cell width are modified. //! on return, the stream's state are restored to their original values. template inline void Mat::impl_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print(user_stream, *this, true); } //! print contents of the matrix (to the cout stream), //! optionally preceding with a user specified line of text. //! the stream's state are used as is and are not modified //! (i.e. the precision and cell width are not modified). template inline void Mat::impl_raw_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, false); } //! print contents of the matrix to a user specified stream, //! optionally preceding with a user specified line of text. //! the stream's state are used as is and are not modified. //! (i.e. the precision and cell width are not modified). template inline void Mat::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print(user_stream, *this, false); } //! change the matrix to have user specified dimensions (data is not preserved) template inline void Mat::set_size(const uword in_elem) { arma_extra_debug_sigprint(); switch(vec_state) { case 0: case 1: init_warm(in_elem, 1); break; case 2: init_warm(1, in_elem); break; default: ; } } //! change the matrix to have user specified dimensions (data is not preserved) template inline void Mat::set_size(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); init_warm(in_rows, in_cols); } //! change the matrix to have user specified dimensions (data is preserved) template inline void Mat::resize(const uword in_elem) { arma_extra_debug_sigprint(); switch(vec_state) { case 0: case 1: (*this).resize(in_elem, 1); break; case 2: (*this).resize(1, in_elem); break; default: ; } } //! change the matrix to have user specified dimensions (data is preserved) template inline void Mat::resize(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); *this = arma::resize(*this, in_rows, in_cols); } //! change the matrix to have user specified dimensions (data is preserved) template inline void Mat::reshape(const uword in_rows, const uword in_cols, const uword dim) { arma_extra_debug_sigprint(); *this = arma::reshape(*this, in_rows, in_cols, dim); } //! change the matrix (without preserving data) to have the same dimensions as the given expression template template inline void Mat::copy_size(const Base& X) { arma_extra_debug_sigprint(); const Proxy P(X.get_ref()); const uword X_n_rows = P.get_n_rows(); const uword X_n_cols = P.get_n_cols(); init_warm(X_n_rows, X_n_cols); } //! transform each element in the matrix using a functor template template inline const Mat& Mat::transform(functor F) { arma_extra_debug_sigprint(); eT* out_mem = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { eT tmp_ii = out_mem[ii]; eT tmp_jj = out_mem[jj]; tmp_ii = eT( F(tmp_ii) ); tmp_jj = eT( F(tmp_jj) ); out_mem[ii] = tmp_ii; out_mem[jj] = tmp_jj; } if(ii < N) { out_mem[ii] = eT( F(out_mem[ii]) ); } return *this; } //! imbue (fill) the matrix with values provided by a functor template template inline const Mat& Mat::imbue(functor F) { arma_extra_debug_sigprint(); eT* out_mem = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { const eT tmp_ii = eT( F() ); const eT tmp_jj = eT( F() ); out_mem[ii] = tmp_ii; out_mem[jj] = tmp_jj; } if(ii < N) { out_mem[ii] = eT( F() ); } return *this; } //! fill the matrix with the specified value template arma_hot inline const Mat& Mat::fill(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_set( memptr(), val, n_elem ); return *this; } //! fill the matrix with the specified value template template arma_hot inline const Mat& Mat::fill(const fill::fill_class&) { arma_extra_debug_sigprint(); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).eye(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); return *this; } template inline const Mat& Mat::zeros() { arma_extra_debug_sigprint(); arrayops::fill_zeros(memptr(), n_elem); return *this; } template inline const Mat& Mat::zeros(const uword in_elem) { arma_extra_debug_sigprint(); set_size(in_elem); return (*this).zeros(); } template inline const Mat& Mat::zeros(const uword in_n_rows, const uword in_n_cols) { arma_extra_debug_sigprint(); set_size(in_n_rows, in_n_cols); return (*this).zeros(); } template inline const Mat& Mat::ones() { arma_extra_debug_sigprint(); return fill(eT(1)); } template inline const Mat& Mat::ones(const uword in_elem) { arma_extra_debug_sigprint(); set_size(in_elem); return fill(eT(1)); } template inline const Mat& Mat::ones(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols); return fill(eT(1)); } template inline const Mat& Mat::randu() { arma_extra_debug_sigprint(); arma_rng::randu::fill( memptr(), n_elem ); return *this; } template inline const Mat& Mat::randu(const uword in_elem) { arma_extra_debug_sigprint(); set_size(in_elem); return (*this).randu(); } template inline const Mat& Mat::randu(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols); return (*this).randu(); } template inline const Mat& Mat::randn() { arma_extra_debug_sigprint(); arma_rng::randn::fill( memptr(), n_elem ); return *this; } template inline const Mat& Mat::randn(const uword in_elem) { arma_extra_debug_sigprint(); set_size(in_elem); return (*this).randn(); } template inline const Mat& Mat::randn(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols); return (*this).randn(); } template inline const Mat& Mat::eye() { arma_extra_debug_sigprint(); (*this).zeros(); const uword N = (std::min)(n_rows, n_cols); for(uword ii=0; ii inline const Mat& Mat::eye(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols); return (*this).eye(); } template inline void Mat::reset() { arma_extra_debug_sigprint(); switch(vec_state) { default: init_warm(0, 0); break; case 1: init_warm(0, 1); break; case 2: init_warm(1, 0); break; } } template template inline void Mat::set_real(const Base::pod_type,T1>& X) { arma_extra_debug_sigprint(); Mat_aux::set_real(*this, X); } template template inline void Mat::set_imag(const Base::pod_type,T1>& X) { arma_extra_debug_sigprint(); Mat_aux::set_imag(*this, X); } template inline arma_warn_unused eT Mat::min() const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "min(): object has no elements" ); return op_min::direct_min(memptr(), n_elem); } template inline arma_warn_unused eT Mat::max() const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "max(): object has no elements" ); return op_max::direct_max(memptr(), n_elem); } template inline eT Mat::min(uword& index_of_min_val) const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "min(): object has no elements" ); return op_min::direct_min(memptr(), n_elem, index_of_min_val); } template inline eT Mat::max(uword& index_of_max_val) const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "max(): object has no elements" ); return op_max::direct_max(memptr(), n_elem, index_of_max_val); } template inline eT Mat::min(uword& row_of_min_val, uword& col_of_min_val) const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "min(): object has no elements" ); uword iq; eT val = op_min::direct_min(memptr(), n_elem, iq); row_of_min_val = iq % n_rows; col_of_min_val = iq / n_rows; return val; } template inline eT Mat::max(uword& row_of_max_val, uword& col_of_max_val) const { arma_extra_debug_sigprint(); arma_debug_check( (n_elem == 0), "max(): object has no elements" ); uword iq; eT val = op_max::direct_max(memptr(), n_elem, iq); row_of_max_val = iq % n_rows; col_of_max_val = iq / n_rows; return val; } //! save the matrix to a file template inline bool Mat::save(const std::string name, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { case raw_ascii: save_okay = diskio::save_raw_ascii(*this, name); break; case arma_ascii: save_okay = diskio::save_arma_ascii(*this, name); break; case csv_ascii: save_okay = diskio::save_csv_ascii(*this, name); break; case raw_binary: save_okay = diskio::save_raw_binary(*this, name); break; case arma_binary: save_okay = diskio::save_arma_binary(*this, name); break; case pgm_binary: save_okay = diskio::save_pgm_binary(*this, name); break; case hdf5_binary: save_okay = diskio::save_hdf5_binary(*this, name); break; default: arma_warn(print_status, "Mat::save(): unsupported file type"); save_okay = false; } arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't write to ", name); return save_okay; } //! save the matrix to a stream template inline bool Mat::save(std::ostream& os, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { case raw_ascii: save_okay = diskio::save_raw_ascii(*this, os); break; case arma_ascii: save_okay = diskio::save_arma_ascii(*this, os); break; case csv_ascii: save_okay = diskio::save_csv_ascii(*this, os); break; case raw_binary: save_okay = diskio::save_raw_binary(*this, os); break; case arma_binary: save_okay = diskio::save_arma_binary(*this, os); break; case pgm_binary: save_okay = diskio::save_pgm_binary(*this, os); break; default: arma_warn(print_status, "Mat::save(): unsupported file type"); save_okay = false; } arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't write to the given stream"); return save_okay; } //! load a matrix from a file template inline bool Mat::load(const std::string name, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { case auto_detect: load_okay = diskio::load_auto_detect(*this, name, err_msg); break; case raw_ascii: load_okay = diskio::load_raw_ascii(*this, name, err_msg); break; case arma_ascii: load_okay = diskio::load_arma_ascii(*this, name, err_msg); break; case csv_ascii: load_okay = diskio::load_csv_ascii(*this, name, err_msg); break; case raw_binary: load_okay = diskio::load_raw_binary(*this, name, err_msg); break; case arma_binary: load_okay = diskio::load_arma_binary(*this, name, err_msg); break; case pgm_binary: load_okay = diskio::load_pgm_binary(*this, name, err_msg); break; case hdf5_binary: load_okay = diskio::load_hdf5_binary(*this, name, err_msg); break; default: arma_warn(print_status, "Mat::load(): unsupported file type"); load_okay = false; } if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_warn(true, "Mat::load(): ", err_msg, name); } else { arma_warn(true, "Mat::load(): couldn't read ", name); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! load a matrix from a stream template inline bool Mat::load(std::istream& is, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { case auto_detect: load_okay = diskio::load_auto_detect(*this, is, err_msg); break; case raw_ascii: load_okay = diskio::load_raw_ascii(*this, is, err_msg); break; case arma_ascii: load_okay = diskio::load_arma_ascii(*this, is, err_msg); break; case csv_ascii: load_okay = diskio::load_csv_ascii(*this, is, err_msg); break; case raw_binary: load_okay = diskio::load_raw_binary(*this, is, err_msg); break; case arma_binary: load_okay = diskio::load_arma_binary(*this, is, err_msg); break; case pgm_binary: load_okay = diskio::load_pgm_binary(*this, is, err_msg); break; default: arma_warn(print_status, "Mat::load(): unsupported file type"); load_okay = false; } if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_warn(true, "Mat::load(): ", err_msg, "the given stream"); } else { arma_warn(true, "Mat::load(): couldn't load from the given stream"); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! save the matrix to a file, without printing any error messages template inline bool Mat::quiet_save(const std::string name, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(name, type, false); } //! save the matrix to a stream, without printing any error messages template inline bool Mat::quiet_save(std::ostream& os, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(os, type, false); } //! load a matrix from a file, without printing any error messages template inline bool Mat::quiet_load(const std::string name, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(name, type, false); } //! load a matrix from a stream, without printing any error messages template inline bool Mat::quiet_load(std::istream& is, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(is, type, false); } template inline Mat::row_iterator::row_iterator(Mat& in_M, const uword in_row) : M (in_M ) , row(in_row) , col(0 ) { arma_extra_debug_sigprint(); } template inline eT& Mat::row_iterator::operator*() { return M.at(row,col); } template inline typename Mat::row_iterator& Mat::row_iterator::operator++() { ++col; if(col >= M.n_cols) { col = 0; ++row; } return *this; } template inline void Mat::row_iterator::operator++(int) { operator++(); } template inline typename Mat::row_iterator& Mat::row_iterator::operator--() { if(col > 0) { --col; } else { if(row > 0) { col = M.n_cols - 1; --row; } } return *this; } template inline void Mat::row_iterator::operator--(int) { operator--(); } template inline bool Mat::row_iterator::operator!=(const typename Mat::row_iterator& X) const { return ( (row != X.row) || (col != X.col) ) ? true : false; } template inline bool Mat::row_iterator::operator==(const typename Mat::row_iterator& X) const { return ( (row == X.row) && (col == X.col) ) ? true : false; } template inline Mat::const_row_iterator::const_row_iterator(const Mat& in_M, const uword in_row) : M (in_M ) , row(in_row) , col(0 ) { arma_extra_debug_sigprint(); } template inline Mat::const_row_iterator::const_row_iterator(const typename Mat::row_iterator& X) : M (X.M) , row(X.row) , col(X.col) { arma_extra_debug_sigprint(); } template inline eT Mat::const_row_iterator::operator*() const { return M.at(row,col); } template inline typename Mat::const_row_iterator& Mat::const_row_iterator::operator++() { ++col; if(col >= M.n_cols) { col = 0; ++row; } return *this; } template inline void Mat::const_row_iterator::operator++(int) { operator++(); } template inline typename Mat::const_row_iterator& Mat::const_row_iterator::operator--() { if(col > 0) { --col; } else { if(row > 0) { col = M.n_cols - 1; --row; } } return *this; } template inline void Mat::const_row_iterator::operator--(int) { operator--(); } template inline bool Mat::const_row_iterator::operator!=(const typename Mat::const_row_iterator& X) const { return ( (row != X.row) || (col != X.col) ) ? true : false; } template inline bool Mat::const_row_iterator::operator==(const typename Mat::const_row_iterator& X) const { return ( (row == X.row) && (col == X.col) ) ? true : false; } template inline typename Mat::iterator Mat::begin() { arma_extra_debug_sigprint(); return memptr(); } template inline typename Mat::const_iterator Mat::begin() const { arma_extra_debug_sigprint(); return memptr(); } template inline typename Mat::const_iterator Mat::cbegin() const { arma_extra_debug_sigprint(); return memptr(); } template inline typename Mat::iterator Mat::end() { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Mat::const_iterator Mat::end() const { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Mat::const_iterator Mat::cend() const { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Mat::col_iterator Mat::begin_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds"); return colptr(col_num); } template inline typename Mat::const_col_iterator Mat::begin_col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds"); return colptr(col_num); } template inline typename Mat::col_iterator Mat::end_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds"); return colptr(col_num) + n_rows; } template inline typename Mat::const_col_iterator Mat::end_col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds"); return colptr(col_num) + n_rows; } template inline typename Mat::row_iterator Mat::begin_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" ); return typename Mat::row_iterator(*this, row_num); } template inline typename Mat::const_row_iterator Mat::begin_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" ); return typename Mat::const_row_iterator(*this, row_num); } template inline typename Mat::row_iterator Mat::end_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" ); return typename Mat::row_iterator(*this, row_num + 1); } template inline typename Mat::const_row_iterator Mat::end_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" ); return typename Mat::const_row_iterator(*this, row_num + 1); } //! resets this matrix to an empty matrix template inline void Mat::clear() { reset(); } //! returns true if the matrix has no elements template inline bool Mat::empty() const { return (n_elem == 0); } //! returns the number of elements in this matrix template inline uword Mat::size() const { return n_elem; } template template arma_inline Mat::fixed::fixed() : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); } template template arma_inline Mat::fixed::fixed(const fixed& X) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); } template template template inline Mat::fixed::fixed(const fill::fill_class&) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).eye(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); } template template template inline Mat::fixed::fixed(const Base& A) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); Mat::operator=(A.get_ref()); } template template template inline Mat::fixed::fixed(const Base& A, const Base& B) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); Mat::init(A,B); } template template inline Mat::fixed::fixed(const eT* aux_mem) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : mem_local; arrayops::copy( dest, aux_mem, fixed_n_elem ); } template template inline Mat::fixed::fixed(const char* text) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); Mat::operator=(text); } template template inline Mat::fixed::fixed(const std::string& text) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); Mat::operator=(text); } #if defined(ARMA_USE_CXX11) template template inline Mat::fixed::fixed(const std::initializer_list& list) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); (*this).operator=(list); } template template inline const Mat& Mat::fixed::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); const uword N = list.size(); arma_debug_check( (N > fixed_n_elem), "Mat::fixed: initialiser list is too long" ); eT* this_mem = (*this).memptr(); arrayops::copy( this_mem, list.begin(), N ); for(uword iq=N; iq < fixed_n_elem; ++iq) { this_mem[iq] = eT(0); } return *this; } #endif template template arma_inline const Mat& Mat::fixed::operator=(const fixed& X) { arma_extra_debug_sigprint(); eT* dest = (use_extra) ? mem_local_extra : mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); return *this; } template template arma_inline const Op< typename Mat::template fixed::Mat_fixed_type, op_htrans > Mat::fixed::t() const { return Op< typename Mat::template fixed::Mat_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Mat::template fixed::Mat_fixed_type, op_htrans > Mat::fixed::ht() const { return Op< typename Mat::template fixed::Mat_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Mat::template fixed::Mat_fixed_type, op_strans > Mat::fixed::st() const { return Op< typename Mat::template fixed::Mat_fixed_type, op_strans >(*this); } template template arma_inline arma_warn_unused const eT& Mat::fixed::at_alt(const uword ii) const { #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE) return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; #else const eT* mem_aligned = (use_extra) ? mem_local_extra : mem_local; memory::mark_as_aligned(mem_aligned); return mem_aligned[ii]; #endif } template template arma_inline arma_warn_unused eT& Mat::fixed::operator[] (const uword ii) { return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Mat::fixed::operator[] (const uword ii) const { return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused eT& Mat::fixed::at(const uword ii) { return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Mat::fixed::at(const uword ii) const { return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused eT& Mat::fixed::operator() (const uword ii) { arma_debug_check( (ii >= fixed_n_elem), "Mat::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Mat::fixed::operator() (const uword ii) const { arma_debug_check( (ii >= fixed_n_elem), "Mat::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused eT& Mat::fixed::at(const uword in_row, const uword in_col) { const uword iq = in_row + in_col*fixed_n_rows; return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; } template template arma_inline arma_warn_unused const eT& Mat::fixed::at(const uword in_row, const uword in_col) const { const uword iq = in_row + in_col*fixed_n_rows; return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; } template template arma_inline arma_warn_unused eT& Mat::fixed::operator() (const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::operator(): index out of bounds"); const uword iq = in_row + in_col*fixed_n_rows; return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; } template template arma_inline arma_warn_unused const eT& Mat::fixed::operator() (const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::operator(): index out of bounds"); const uword iq = in_row + in_col*fixed_n_rows; return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; } template template arma_inline arma_warn_unused eT* Mat::fixed::colptr(const uword in_col) { eT* mem_actual = (use_extra) ? mem_local_extra : mem_local; return & access::rw(mem_actual[in_col*fixed_n_rows]); } template template arma_inline arma_warn_unused const eT* Mat::fixed::colptr(const uword in_col) const { const eT* mem_actual = (use_extra) ? mem_local_extra : mem_local; return & mem_actual[in_col*fixed_n_rows]; } template template arma_inline arma_warn_unused eT* Mat::fixed::memptr() { return (use_extra) ? mem_local_extra : mem_local; } template template arma_inline arma_warn_unused const eT* Mat::fixed::memptr() const { return (use_extra) ? mem_local_extra : mem_local; } template template arma_inline arma_warn_unused bool Mat::fixed::is_vec() const { return ( (fixed_n_rows == 1) || (fixed_n_cols == 1) ); } template template arma_hot inline const Mat& Mat::fixed::fill(const eT val) { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(mem_local[0]); arrayops::inplace_set_fixed( mem_use, val ); return *this; } template template arma_hot inline const Mat& Mat::fixed::zeros() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(0) ); return *this; } template template arma_hot inline const Mat& Mat::fixed::ones() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(1) ); return *this; } //! prefix ++ template arma_inline void Mat_aux::prefix_pp(Mat& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Mat_aux::prefix_pp(Mat< std::complex >& x) { x += T(1); } //! postfix ++ template arma_inline void Mat_aux::postfix_pp(Mat& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Mat_aux::postfix_pp(Mat< std::complex >& x) { x += T(1); } //! prefix -- template arma_inline void Mat_aux::prefix_mm(Mat& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Mat_aux::prefix_mm(Mat< std::complex >& x) { x -= T(1); } //! postfix -- template arma_inline void Mat_aux::postfix_mm(Mat& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Mat_aux::postfix_mm(Mat< std::complex >& x) { x -= T(1); } template inline void Mat_aux::set_real(Mat& out, const Base& X) { arma_extra_debug_sigprint(); const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; arma_debug_assert_same_size( out, A, "Mat::set_real()" ); out = A; } template inline void Mat_aux::set_imag(Mat&, const Base&) { arma_extra_debug_sigprint(); } template inline void Mat_aux::set_real(Mat< std::complex >& out, const Base& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy P(X.get_ref()); const uword local_n_rows = P.get_n_rows(); const uword local_n_cols = P.get_n_cols(); arma_debug_assert_same_size( out.n_rows, out.n_cols, local_n_rows, local_n_cols, "Mat::set_real()" ); eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); const uword N = out.n_elem; for(uword i=0; i( A[i], out_mem[i].imag() ); } } else { for(uword col=0; col < local_n_cols; ++col) for(uword row=0; row < local_n_rows; ++row) { (*out_mem) = std::complex( P.at(row,col), (*out_mem).imag() ); out_mem++; } } } template inline void Mat_aux::set_imag(Mat< std::complex >& out, const Base& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy P(X.get_ref()); const uword local_n_rows = P.get_n_rows(); const uword local_n_cols = P.get_n_cols(); arma_debug_assert_same_size( out.n_rows, out.n_cols, local_n_rows, local_n_cols, "Mat::set_imag()" ); eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); const uword N = out.n_elem; for(uword i=0; i( out_mem[i].real(), A[i] ); } } else { for(uword col=0; col < local_n_cols; ++col) for(uword row=0; row < local_n_rows; ++row) { (*out_mem) = std::complex( (*out_mem).real(), P.at(row,col) ); out_mem++; } } } #ifdef ARMA_EXTRA_MAT_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_MEAT) #endif //! @} RcppArmadillo/inst/include/armadillo_bits/fn_princomp.hpp0000644000176000001440000000757212200375542023456 0ustar ripleyusers// Copyright (C) 2010-2012 Conrad Sanderson // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) // Copyright (C) 2010 Dimitrios Bouzas // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_princomp //! @{ //! \brief //! principal component analysis -- 4 arguments version //! coeff_out -> principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors //! tsquared_out -> Hotelling's T^2 statistic template inline bool princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, Col& tsquared_out, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool status = op_princomp::direct_princomp(coeff_out, score_out, latent_out, tsquared_out, X); if(status == false) { coeff_out.reset(); score_out.reset(); latent_out.reset(); tsquared_out.reset(); arma_bad("princomp(): failed to converge", false); } return status; } //! \brief //! principal component analysis -- 3 arguments version //! coeff_out -> principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors template inline bool princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool status = op_princomp::direct_princomp(coeff_out, score_out, latent_out, X); if(status == false) { coeff_out.reset(); score_out.reset(); latent_out.reset(); arma_bad("princomp(): failed to converge", false); } return status; } //! \brief //! principal component analysis -- 2 arguments version //! coeff_out -> principal component coefficients //! score_out -> projected samples template inline bool princomp ( Mat& coeff_out, Mat& score_out, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool status = op_princomp::direct_princomp(coeff_out, score_out, X); if(status == false) { coeff_out.reset(); score_out.reset(); arma_bad("princomp(): failed to converge", false); } return status; } //! \brief //! principal component analysis -- 1 argument version //! coeff_out -> principal component coefficients template inline bool princomp ( Mat& coeff_out, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool status = op_princomp::direct_princomp(coeff_out, X); if(status == false) { coeff_out.reset(); arma_bad("princomp(): failed to converge", false); } return status; } template inline const Op princomp ( const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X.get_ref()); } //! @} RcppArmadillo/inst/include/armadillo_bits/eop_core_meat.hpp0000644000176000001440000005334012216162176023743 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup eop_core //! @{ #undef arma_applier_1u #undef arma_applier_1a #undef arma_applier_2 #undef arma_applier_3 #undef operatorA #define arma_applier_1u(operatorA) \ {\ uword i,j;\ \ for(i=0, j=1; j::process(tmp_i, k);\ tmp_j = eop_core::process(tmp_j, k);\ \ out_mem[i] operatorA tmp_i;\ out_mem[j] operatorA tmp_j;\ }\ \ if(i < n_elem)\ {\ out_mem[i] operatorA eop_core::process(P[i], k);\ }\ } #define arma_applier_1a(operatorA) \ {\ uword i,j;\ \ for(i=0, j=1; j::process(tmp_i, k);\ tmp_j = eop_core::process(tmp_j, k);\ \ out_mem[i] operatorA tmp_i;\ out_mem[j] operatorA tmp_j;\ }\ \ if(i < n_elem)\ {\ out_mem[i] operatorA eop_core::process(P.at_alt(i), k);\ }\ } #define arma_applier_2(operatorA) \ {\ if(n_rows != 1)\ {\ for(uword col=0; col::process(tmp_i, k);\ tmp_j = eop_core::process(tmp_j, k);\ \ *out_mem operatorA tmp_i; out_mem++;\ *out_mem operatorA tmp_j; out_mem++;\ }\ \ if(i < n_rows)\ {\ *out_mem operatorA eop_core::process(P.at(i,col), k); out_mem++;\ }\ }\ }\ else\ {\ for(uword count=0; count < n_cols; ++count)\ {\ out_mem[count] operatorA eop_core::process(P.at(0,count), k);\ }\ }\ } #define arma_applier_3(operatorA) \ {\ for(uword slice=0; slice::process(tmp_i, k);\ tmp_j = eop_core::process(tmp_j, k);\ \ *out_mem operatorA tmp_i; out_mem++; \ *out_mem operatorA tmp_j; out_mem++; \ }\ \ if(i < n_rows)\ {\ *out_mem operatorA eop_core::process(P.at(i,col,slice), k); out_mem++; \ }\ }\ }\ } // // matrices template template arma_hot inline void eop_core::apply(Mat& out, const eOp& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = (Proxy::is_fixed) ? x.get_n_elem() : out.n_elem; //if(memory::is_aligned(out_mem)) if( memory::is_aligned(out_mem) && ((Proxy::is_fixed) ? (x.get_n_elem() >= 32) : true) ) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename Proxy::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(=); } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(=); } } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(=); } } else { const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const Proxy& P = x.P; arma_applier_2(=); } } template template arma_hot inline void eop_core::apply_inplace_plus(Mat& out, const eOp& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addition"); const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = (Proxy::is_fixed) ? x.get_n_elem() : out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename Proxy::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(+=); } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(+=); } } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(+=); } } else { const Proxy& P = x.P; arma_applier_2(+=); } } template template arma_hot inline void eop_core::apply_inplace_minus(Mat& out, const eOp& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subtraction"); const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = (Proxy::is_fixed) ? x.get_n_elem() : out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename Proxy::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(-=); } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(-=); } } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(-=); } } else { const Proxy& P = x.P; arma_applier_2(-=); } } template template arma_hot inline void eop_core::apply_inplace_schur(Mat& out, const eOp& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise multiplication"); const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = (Proxy::is_fixed) ? x.get_n_elem() : out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename Proxy::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(*=); } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(*=); } } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(*=); } } else { const Proxy& P = x.P; arma_applier_2(*=); } } template template arma_hot inline void eop_core::apply_inplace_div(Mat& out, const eOp& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise division"); const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = (Proxy::is_fixed) ? x.get_n_elem() : out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename Proxy::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(/=); } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(/=); } } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(/=); } } else { const Proxy& P = x.P; arma_applier_2(/=); } } // // cubes template template arma_hot inline void eop_core::apply(Cube& out, const eOpCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const eT k = x.aux; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename ProxyCube::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(=); } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(=); } } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(=); } } else { const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); const ProxyCube& P = x.P; arma_applier_3(=); } } template template arma_hot inline void eop_core::apply_inplace_plus(Cube& out, const eOpCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition"); const eT k = x.aux; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename ProxyCube::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(+=); } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(+=); } } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(+=); } } else { const ProxyCube& P = x.P; arma_applier_3(+=); } } template template arma_hot inline void eop_core::apply_inplace_minus(Cube& out, const eOpCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction"); const eT k = x.aux; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename ProxyCube::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(-=); } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(-=); } } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(-=); } } else { const ProxyCube& P = x.P; arma_applier_3(-=); } } template template arma_hot inline void eop_core::apply_inplace_schur(Cube& out, const eOpCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication"); const eT k = x.aux; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename ProxyCube::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(*=); } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(*=); } } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(*=); } } else { const ProxyCube& P = x.P; arma_applier_3(*=); } } template template arma_hot inline void eop_core::apply_inplace_div(Cube& out, const eOpCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division"); const eT k = x.aux; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename ProxyCube::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(/=); } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(/=); } } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(/=); } } else { const ProxyCube& P = x.P; arma_applier_3(/=); } } // // common template template arma_hot arma_pure arma_inline eT eop_core::process(const eT, const eT) { arma_stop("eop_core::process(): unhandled eop_type"); return eT(0); } template<> template arma_hot arma_const arma_inline eT eop_core::process(const eT val, const eT k) { return val + k; } template<> template arma_hot arma_const arma_inline eT eop_core::process(const eT val, const eT k) { return k - val; } template<> template arma_hot arma_const arma_inline eT eop_core::process(const eT val, const eT k) { return val - k; } template<> template arma_hot arma_const arma_inline eT eop_core::process(const eT val, const eT k) { return val * k; } template<> template arma_hot arma_const arma_inline eT eop_core::process(const eT val, const eT k) { return k / val; } template<> template arma_hot arma_const arma_inline eT eop_core::process(const eT val, const eT k) { return val / k; } template<> template arma_hot arma_const arma_inline eT eop_core::process(const eT val, const eT ) { return val*val; } template<> template arma_hot arma_const arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::neg(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::sqrt(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::log(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::log2(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::log10(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return arma::trunc_log(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::exp(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::exp2(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::exp10(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return arma::trunc_exp(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::cos(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::sin(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::tan(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::acos(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::asin(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::atan(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::cosh(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::sinh(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::tanh(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::acosh(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::asinh(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::atanh(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::direct_eps(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::arma_abs(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::conj(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT k) { return eop_aux::pow(val, k); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::floor(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::ceil(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::round(val); } template<> template arma_hot arma_pure arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::sign(val); } #undef arma_applier_1u #undef arma_applier_1a #undef arma_applier_2 #undef arma_applier_3 //! @} RcppArmadillo/inst/include/armadillo_bits/spglue_minus_meat.hpp0000644000176000001440000000765512111344723024664 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spglue_minus //! @{ template inline void spglue_minus::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(X.A); const SpProxy pb(X.B); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_minus::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_minus::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } } template arma_hot inline void spglue_minus::apply_noalias(SpMat& result, const SpProxy& pa, const SpProxy& pb) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "subtraction"); if( (pa.get_n_nonzero() != 0) && (pb.get_n_nonzero() != 0) ) { result.set_size(pa.get_n_rows(), pa.get_n_cols()); // Resize memory to correct size. result.mem_resize(n_unique(pa, pb, op_n_unique_sub())); // Now iterate across both matrices. typename SpProxy::const_iterator_type x_it = pa.begin(); typename SpProxy::const_iterator_type y_it = pb.begin(); typename SpProxy::const_iterator_type x_end = pa.end(); typename SpProxy::const_iterator_type y_end = pb.end(); uword cur_val = 0; while((x_it != x_end) || (y_it != y_end)) { if(x_it == y_it) { const eT val = (*x_it) - (*y_it); if (val != eT(0)) { access::rw(result.values[cur_val]) = val; access::rw(result.row_indices[cur_val]) = x_it.row(); ++access::rw(result.col_ptrs[x_it.col() + 1]); ++cur_val; } ++x_it; ++y_it; } else { const uword x_it_row = x_it.row(); const uword x_it_col = x_it.col(); const uword y_it_row = y_it.row(); const uword y_it_col = y_it.col(); if((x_it_col < y_it_col) || ((x_it_col == y_it_col) && (x_it_row < y_it_row))) // if y is closer to the end { access::rw(result.values[cur_val]) = (*x_it); access::rw(result.row_indices[cur_val]) = x_it_row; ++access::rw(result.col_ptrs[x_it_col + 1]); ++cur_val; ++x_it; } else { access::rw(result.values[cur_val]) = -(*y_it); access::rw(result.row_indices[cur_val]) = y_it_row; ++access::rw(result.col_ptrs[y_it_col + 1]); ++cur_val; ++y_it; } } } // Fix column pointers to be cumulative. for(uword c = 1; c <= result.n_cols; ++c) { access::rw(result.col_ptrs[c]) += result.col_ptrs[c - 1]; } } else { if(pa.get_n_nonzero() == 0) { result = pb.Q; result *= eT(-1); return; } if(pb.get_n_nonzero() == 0) { result = pa.Q; return; } } } // // // spglue_minus2: scalar*(A - B) template inline void spglue_minus2::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(X.A); const SpProxy pb(X.B); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_minus::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_minus::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } out *= X.aux; } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_qr.hpp0000644000176000001440000000303412200375542022236 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_qr //! @{ //! QR decomposition template inline bool qr ( Mat& Q, Mat& R, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( (&Q == &R), "qr(): Q and R are the same object"); const bool status = auxlib::qr(Q, R, X); if(status == false) { Q.reset(); R.reset(); arma_bad("qr(): failed to converge", false); } return status; } //! economical QR decomposition template inline bool qr_econ ( Mat& Q, Mat& R, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( (&Q == &R), "qr_econ(): Q and R are the same object"); const bool status = auxlib::qr_econ(Q, R, X); if(status == false) { Q.reset(); R.reset(); arma_bad("qr_econ(): failed to converge", false); } return status; } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_n_unique.hpp0000644000176000001440000000520512111344723023437 0ustar ripleyusers// Copyright (C) 2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_n_unique //! @{ //! \brief //! Get the number of unique nonzero elements in two sparse matrices. //! This is very useful for determining the amount of memory necessary before //! a sparse matrix operation on two matrices. template inline uword n_unique ( const SpBase& x, const SpBase& y, const op_n_unique_type junk ) { arma_extra_debug_sigprint(); const SpProxy pa(x.get_ref()); const SpProxy pb(y.get_ref()); return n_unique(pa,pb,junk); } template arma_hot inline uword n_unique ( const SpProxy& pa, const SpProxy& pb, const op_n_unique_type junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); // Use iterators. typename SpProxy::const_iterator_type x_it = pa.begin(); typename SpProxy::const_iterator_type y_it = pb.begin(); uword total_n_nonzero = 0; while((x_it != pa.end()) || (y_it != pb.end())) { if(x_it == y_it) { if(op_n_unique_type::eval((*x_it), (*y_it)) != typename T1::elem_type(0)) { ++total_n_nonzero; } ++x_it; ++y_it; } else { if((x_it.col() < y_it.col()) || ((x_it.col() == y_it.col()) && (x_it.row() < y_it.row()))) // if y is closer to the end { if(op_n_unique_type::eval((*x_it), typename T1::elem_type(0)) != typename T1::elem_type(0)) { ++total_n_nonzero; } ++x_it; } else // x is closer to the end { if(op_n_unique_type::eval(typename T1::elem_type(0), (*y_it)) != typename T1::elem_type(0)) { ++total_n_nonzero; } ++y_it; } } } return total_n_nonzero; } // Simple operators. struct op_n_unique_add { template inline static eT eval(const eT& l, const eT& r) { return (l + r); } }; struct op_n_unique_sub { template inline static eT eval(const eT& l, const eT& r) { return (l - r); } }; struct op_n_unique_mul { template inline static eT eval(const eT& l, const eT& r) { return (l * r); } }; struct op_n_unique_count { template inline static eT eval(const eT& l, const eT& r) { return 1; } }; //! @} RcppArmadillo/inst/include/armadillo_bits/typedef_elem.hpp0000644000176000001440000000515312246642071023603 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup typedef_elem //! @{ #if UCHAR_MAX >= 0xff typedef unsigned char u8; typedef char s8; #elif defined(UINT8_MAX) typedef uint8_t u8; typedef int8_t s8; #else #error "don't know how to typedef 'u8' on this system" #endif // NOTE: // "signed char" is not the same as "char". // http://www.embedded.com/columns/programmingpointers/206107018 // http://en.wikipedia.org/wiki/C_variable_types_and_declarations #if USHRT_MAX >= 0xffff typedef unsigned short u16; typedef short s16; #elif defined(UINT16_MAX) typedef uint16_t u16; typedef int16_t s16; #else #error "don't know how to typedef 'u16' on this system" #endif #if UINT_MAX >= 0xffffffff typedef unsigned int u32; typedef int s32; #elif defined(UINT32_MAX) typedef uint32_t u32; typedef int32_t s32; #else #error "don't know how to typedef 'u32' on this system" #endif #if defined(ARMA_USE_U64S64) #if ULLONG_MAX >= 0xffffffffffffffff typedef unsigned long long u64; typedef long long s64; #elif ULONG_MAX >= 0xffffffffffffffff typedef unsigned long u64; typedef long s64; #define ARMA_U64_IS_LONG #elif defined(UINT64_MAX) typedef uint64_t u64; typedef int64_t s64; #else #error "don't know how to typedef 'u64' on this system; please disable ARMA_64BIT_WORD and/or ARMA_USE_U64S64" #endif #endif #if !defined(ARMA_USE_U64S64) || (defined(ARMA_USE_U64S64) && !defined(ARMA_U64_IS_LONG)) #define ARMA_ALLOW_LONG #endif typedef unsigned long ulng_t; typedef long slng_t; #if !defined(ARMA_64BIT_WORD) typedef u32 uword; typedef s32 sword; typedef u16 uhword; typedef s16 shword; #define ARMA_MAX_UWORD 0xffffffff #define ARMA_MAX_UHWORD 0xffff #else typedef u64 uword; typedef s64 sword; typedef u32 uhword; typedef s32 shword; #define ARMA_MAX_UWORD 0xffffffffffffffff #define ARMA_MAX_UHWORD 0xffffffff #endif typedef std::complex cx_float; typedef std::complex cx_double; #if defined(ARMA_BLAS_LONG_LONG) typedef long long blas_int; #elif defined(ARMA_BLAS_LONG) typedef long blas_int; #else typedef int blas_int; #endif typedef void* void_ptr; //! @} RcppArmadillo/inst/include/armadillo_bits/glue_toeplitz_bones.hpp0000644000176000001440000000102512200375542025203 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_toeplitz //! @{ class glue_toeplitz { public: template inline static void apply(Mat& out, const Glue& in); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_any.hpp0000644000176000001440000000350512200700172022375 0ustar ripleyusers// Copyright (C) 2013 Conrad Sanderson // Copyright (C) 2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_any //! @{ template arma_inline const mtOp any ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return mtOp(X, dim, 0); } template inline arma_warn_unused bool any ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return op_any::any_vec(X); } template inline arma_warn_unused bool any ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_any::any_vec(X); } template inline arma_warn_unused bool any(const mtOp& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("any(): two consecutive calls to any() detected"); return op_any::any_vec(in.m); } template arma_inline const Op< mtOp, op_any> any(const mtOp& in, const uword dim) { arma_extra_debug_sigprint(); return mtOp, op_any>(in, dim, 0); } //! @} RcppArmadillo/inst/include/armadillo_bits/spglue_times_bones.hpp0000644000176000001440000000146212111344723025020 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spglue_times //! @{ class spglue_times { public: template inline static void apply(SpMat& out, const SpGlue& X); template arma_hot inline static void apply_noalias(SpMat& c, const SpProxy& pa, const SpProxy& pb); }; class spglue_times2 { public: template inline static void apply(SpMat& out, const SpGlue& X); }; //! @} RcppArmadillo/inst/include/armadillo_bits/fn_rank.hpp0000644000176000001440000000257612251624575022572 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // Copyright (C) 2009-2010 Dimitrios Bouzas // Copyright (C) 2011 Stanislav Funiak // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_rank //! @{ template inline arma_warn_unused uword rank ( const Base& X, typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; uword X_n_rows; uword X_n_cols; Col s; const bool status = auxlib::svd_dc(s, X, X_n_rows, X_n_cols); const uword n_elem = s.n_elem; if(status == true) { if( (tol == T(0)) && (n_elem > 0) ) { tol = (std::max)(X_n_rows, X_n_cols) * eop_aux::direct_eps(max(s)); } // count non zero valued elements in s const T* s_mem = s.memptr(); uword count = 0; for(uword i=0; i tol) { ++count; } } return count; } else { arma_bad("rank(): failed to converge"); return uword(0); } } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_dot.hpp0000644000176000001440000001476412220557270022420 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // Copyright (C) 2012 Ryan Curtin // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_dot //! @{ template arma_inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::yes, typename T1::elem_type >::result dot ( const T1& A, const T2& B ) { arma_extra_debug_sigprint(); return op_dot::apply(A,B); } template inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::no, typename promote_type::result >::result dot ( const T1& A, const T2& B ) { arma_extra_debug_sigprint(); return op_dot_mixed::apply(A,B); } template arma_inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value, typename T1::elem_type >::result norm_dot ( const T1& A, const T2& B ) { arma_extra_debug_sigprint(); return op_norm_dot::apply(A,B); } // // cdot template arma_inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value && is_not_complex::value, typename T1::elem_type >::result cdot ( const T1& A, const T2& B ) { arma_extra_debug_sigprint(); return op_dot::apply(A,B); } template arma_inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value && is_complex::value, typename T1::elem_type >::result cdot ( const T1& A, const T2& B ) { arma_extra_debug_sigprint(); return op_cdot::apply(A,B); } // convert dot(htrans(x), y) to cdot(x,y) template arma_inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_same_type::value && is_complex::value, typename T1::elem_type >::result dot ( const Op& A, const T2& B ) { arma_extra_debug_sigprint(); return cdot(A.m, B); } // // for sparse matrices // namespace priv { template arma_hot inline typename T1::elem_type dot_helper(const SpProxy& pa, const SpProxy& pb) { typedef typename T1::elem_type eT; // Iterate over both objects and see when they are the same eT result = eT(0); typename SpProxy::const_iterator_type a_it = pa.begin(); typename SpProxy::const_iterator_type a_end = pa.end(); typename SpProxy::const_iterator_type b_it = pb.begin(); typename SpProxy::const_iterator_type b_end = pb.end(); while((a_it != a_end) && (b_it != b_end)) { if(a_it == b_it) { result += (*a_it) * (*b_it); ++a_it; ++b_it; } else if((a_it.col() < b_it.col()) || ((a_it.col() == b_it.col()) && (a_it.row() < b_it.row()))) { // a_it is "behind" ++a_it; } else { // b_it is "behind" ++b_it; } } return result; } } //! dot product of two sparse objects template arma_warn_unused arma_hot inline typename enable_if2 <(is_arma_sparse_type::value) && (is_arma_sparse_type::value) && (is_same_type::value), typename T1::elem_type >::result dot ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); const SpProxy pa(x); const SpProxy pb(y); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "dot()"); typedef typename T1::elem_type eT; typedef typename SpProxy::stored_type pa_Q_type; typedef typename SpProxy::stored_type pb_Q_type; if( ( (SpProxy::must_use_iterator == false) && (SpProxy::must_use_iterator == false) ) && ( (is_SpMat::value == true ) && (is_SpMat::value == true ) ) ) { const unwrap_spmat tmp_a(pa.Q); const unwrap_spmat tmp_b(pb.Q); const SpMat& A = tmp_a.M; const SpMat& B = tmp_b.M; if( &A == &B ) { // We can do it directly! return op_dot::direct_dot_arma(A.n_nonzero, A.values, A.values); } else { return priv::dot_helper(pa,pb); } } else { return priv::dot_helper(pa,pb); } } //! dot product of one dense and one sparse object template arma_warn_unused arma_hot inline typename enable_if2 <(is_arma_type::value) && (is_arma_sparse_type::value) && (is_same_type::value), typename T1::elem_type >::result dot ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); const Proxy pa(x); const SpProxy pb(y); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "dot()"); typedef typename T1::elem_type eT; eT result = eT(0); typename SpProxy::const_iterator_type it = pb.begin(); typename SpProxy::const_iterator_type it_end = pb.end(); // prefer_at_accessor won't save us operations while(it != it_end) { result += (*it) * pa.at(it.row(), it.col()); ++it; } return result; } //! dot product of one sparse and one dense object template arma_warn_unused arma_hot inline typename enable_if2 <(is_arma_sparse_type::value) && (is_arma_type::value) && (is_same_type::value), typename T1::elem_type >::result dot ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); // this is commutative return dot(y, x); } //! @} RcppArmadillo/inst/include/armadillo_bits/SpGlue_meat.hpp0000644000176000001440000000155312111344723023340 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpGlue //! @{ template inline SpGlue::SpGlue(const T1& in_A, const T2& in_B) : A(in_A) , B(in_B) { arma_extra_debug_sigprint(); } template inline SpGlue::SpGlue(const T1& in_A, const T2& in_B, const typename T1::elem_type in_aux) : A(in_A) , B(in_B) , aux(in_aux) { arma_extra_debug_sigprint(); } template inline SpGlue::~SpGlue() { arma_extra_debug_sigprint(); } //! @} RcppArmadillo/inst/include/armadillo_bits/Row_meat.hpp0000644000176000001440000006736612265111302022721 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Row //! @{ //! construct an empty row vector template inline Row::Row() : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(); } template inline Row::Row(const Row& X) : Mat(arma_vec_indicator(), 1, X.n_elem, 2) { arma_extra_debug_sigprint(); arrayops::copy((*this).memptr(), X.memptr(), X.n_elem); } //! construct a row vector with the specified number of n_elem template inline Row::Row(const uword in_n_elem) : Mat(arma_vec_indicator(), 1, in_n_elem, 2) { arma_extra_debug_sigprint(); } template inline Row::Row(const uword in_n_rows, const uword in_n_cols) : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(); Mat::init_warm(in_n_rows, in_n_cols); } template template inline Row::Row(const uword in_n_elem, const fill::fill_class& f) : Mat(arma_vec_indicator(), 1, in_n_elem, 2) { arma_extra_debug_sigprint(); (*this).fill(f); } template template inline Row::Row(const uword in_n_rows, const uword in_n_cols, const fill::fill_class& f) : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(); Mat::init_warm(in_n_rows, in_n_cols); (*this).fill(f); } template inline Row::Row(const char* text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); } template inline const Row& Row::operator=(const char* text) { arma_extra_debug_sigprint(); Mat::operator=(text); return *this; } template inline Row::Row(const std::string& text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); } template inline const Row& Row::operator=(const std::string& text) { arma_extra_debug_sigprint(); Mat::operator=(text); return *this; } //! create a row vector from std::vector template inline Row::Row(const std::vector& x) : Mat(arma_vec_indicator(), 1, uword(x.size()), 2) { arma_extra_debug_sigprint_this(this); if(x.size() > 0) { arrayops::copy( Mat::memptr(), &(x[0]), uword(x.size()) ); } } //! create a row vector from std::vector template inline const Row& Row::operator=(const std::vector& x) { arma_extra_debug_sigprint(); Mat::init_warm(1, uword(x.size())); if(x.size() > 0) { arrayops::copy( Mat::memptr(), &(x[0]), uword(x.size()) ); } return *this; } #if defined(ARMA_USE_CXX11) template inline Row::Row(const std::initializer_list& list) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(list); } template inline const Row& Row::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); Mat::operator=(list); return *this; } template inline Row::Row(Row&& X) : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(arma_boost::format("this = %x X = %x") % this % &X); access::rw(Mat::n_rows) = 1; access::rw(Mat::n_cols) = X.n_cols; access::rw(Mat::n_elem) = X.n_elem; if( ((X.mem_state == 0) && (X.n_elem > arma_config::mat_prealloc)) || (X.mem_state == 1) || (X.mem_state == 2) ) { access::rw(Mat::mem_state) = X.mem_state; access::rw(Mat::mem) = X.mem; access::rw(X.n_rows) = 1; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem_state) = 0; access::rw(X.mem) = 0; } else { (*this).init_cold(); arrayops::copy( (*this).memptr(), X.mem, X.n_elem ); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) ) { access::rw(X.n_rows) = 1; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } } } template inline const Row& Row::operator=(Row&& X) { arma_extra_debug_sigprint(arma_boost::format("this = %x X = %x") % this % &X); (*this).steal_mem(X); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) && (this != &X) ) { access::rw(X.n_rows) = 1; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } return *this; } #endif template inline Row::Row(const SpRow& X) : Mat(arma_vec_indicator(), 1, X.n_elem, 1) { arma_extra_debug_sigprint_this(this); arrayops::inplace_set(Mat::memptr(), eT(0), X.n_elem); for(typename SpRow::const_iterator it = X.begin(); it != X.end(); ++it) { at(it.col()) = (*it); } } template inline const Row& Row::operator=(const eT val) { arma_extra_debug_sigprint(); Mat::operator=(val); return *this; } template inline const Row& Row::operator=(const Row& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template template inline Row::Row(const Base& X) : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(); Mat::operator=(X.get_ref()); } template template inline const Row& Row::operator=(const Base& X) { arma_extra_debug_sigprint(); Mat::operator=(X.get_ref()); return *this; } //! construct a row vector from a given auxiliary array template inline Row::Row(eT* aux_mem, const uword aux_length, const bool copy_aux_mem, const bool strict) : Mat(aux_mem, 1, aux_length, copy_aux_mem, strict) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; } //! construct a row vector from a given auxiliary array template inline Row::Row(const eT* aux_mem, const uword aux_length) : Mat(aux_mem, 1, aux_length) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; } template template inline Row::Row ( const Base::pod_type, T1>& A, const Base::pod_type, T2>& B ) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::init(A,B); } template template inline Row::Row(const BaseCube& X) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(X); } template template inline const Row& Row::operator=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template inline Row::Row(const subview_cube& X) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(X); } template inline const Row& Row::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template inline mat_injector< Row > Row::operator<<(const eT val) { return mat_injector< Row >(*this, val); } template arma_inline const Op,op_htrans> Row::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> Row::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> Row::st() const { return Op,op_strans>(*this); } template arma_inline subview_row Row::col(const uword in_col1) { arma_extra_debug_sigprint(); arma_debug_check( (in_col1 >= Mat::n_cols), "Row::col(): indices out of bounds or incorrectly used"); return subview_row(*this, 0, in_col1, 1); } template arma_inline const subview_row Row::col(const uword in_col1) const { arma_extra_debug_sigprint(); arma_debug_check( (in_col1 >= Mat::n_cols), "Row::col(): indices out of bounds or incorrectly used"); return subview_row(*this, 0, in_col1, 1); } template arma_inline subview_row Row::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::cols(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline const subview_row Row::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::cols(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline subview_row Row::subvec(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline const subview_row Row::subvec(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline subview_row Row::cols(const span& col_span) { arma_extra_debug_sigprint(); return subvec(col_span); } template arma_inline const subview_row Row::cols(const span& col_span) const { arma_extra_debug_sigprint(); return subvec(col_span); } template arma_inline subview_row Row::subvec(const span& col_span) { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = Mat::n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subvec_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ), "Row::subvec(): indices out of bounds or incorrectly used"); return subview_row(*this, 0, in_col1, subvec_n_cols); } template arma_inline const subview_row Row::subvec(const span& col_span) const { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = Mat::n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subvec_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ), "Row::subvec(): indices out of bounds or incorrectly used"); return subview_row(*this, 0, in_col1, subvec_n_cols); } template arma_inline subview_row Row::operator()(const span& col_span) { arma_extra_debug_sigprint(); return subvec(col_span); } template arma_inline const subview_row Row::operator()(const span& col_span) const { arma_extra_debug_sigprint(); return subvec(col_span); } //! remove specified columns template inline void Row::shed_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= Mat::n_cols, "Row::shed_col(): index out of bounds"); shed_cols(col_num, col_num); } //! remove specified columns template inline void Row::shed_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols), "Row::shed_cols(): indices out of bounds or incorrectly used" ); const uword n_keep_front = in_col1; const uword n_keep_back = Mat::n_cols - (in_col2 + 1); Row X(n_keep_front + n_keep_back); eT* X_mem = X.memptr(); const eT* t_mem = (*this).memptr(); if(n_keep_front > 0) { arrayops::copy( X_mem, t_mem, n_keep_front ); } if(n_keep_back > 0) { arrayops::copy( &(X_mem[n_keep_front]), &(t_mem[in_col2+1]), n_keep_back); } Mat::steal_mem(X); } //! insert N cols at the specified col position, //! optionally setting the elements of the inserted cols to zero template inline void Row::insert_cols(const uword col_num, const uword N, const bool set_to_zero) { arma_extra_debug_sigprint(); const uword t_n_cols = Mat::n_cols; const uword A_n_cols = col_num; const uword B_n_cols = t_n_cols - col_num; // insertion at col_num == n_cols is in effect an append operation arma_debug_check( (col_num > t_n_cols), "Row::insert_cols(): index out of bounds"); if(N > 0) { Row out(t_n_cols + N); eT* out_mem = out.memptr(); const eT* t_mem = (*this).memptr(); if(A_n_cols > 0) { arrayops::copy( out_mem, t_mem, A_n_cols ); } if(B_n_cols > 0) { arrayops::copy( &(out_mem[col_num + N]), &(t_mem[col_num]), B_n_cols ); } if(set_to_zero == true) { arrayops::inplace_set( &(out_mem[col_num]), eT(0), N ); } Mat::steal_mem(out); } } //! insert the given object at the specified col position; //! the given object must have one row template template inline void Row::insert_cols(const uword col_num, const Base& X) { arma_extra_debug_sigprint(); Mat::insert_cols(col_num, X); } template arma_inline arma_warn_unused eT& Row::at(const uword i) { return access::rw(Mat::mem[i]); } template arma_inline arma_warn_unused const eT& Row::at(const uword i) const { return Mat::mem[i]; } template arma_inline arma_warn_unused eT& Row::at(const uword, const uword in_col) { return access::rw( Mat::mem[in_col] ); } template arma_inline arma_warn_unused const eT& Row::at(const uword, const uword in_col) const { return Mat::mem[in_col]; } template inline typename Row::row_iterator Row::begin_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "begin_row(): index out of bounds"); return Mat::memptr(); } template inline typename Row::const_row_iterator Row::begin_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "begin_row(): index out of bounds"); return Mat::memptr(); } template inline typename Row::row_iterator Row::end_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "end_row(): index out of bounds"); return Mat::memptr() + Mat::n_cols; } template inline typename Row::const_row_iterator Row::end_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "end_row(): index out of bounds"); return Mat::memptr() + Mat::n_cols; } template template inline Row::fixed::fixed() : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); } template template arma_inline Row::fixed::fixed(const fixed& X) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); } template template arma_inline Row::fixed::fixed(const subview_cube& X) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Row::operator=(X); } template template template inline Row::fixed::fixed(const fill::fill_class&) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).eye(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); } template template template arma_inline Row::fixed::fixed(const Base& A) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Row::operator=(A.get_ref()); } template template template arma_inline Row::fixed::fixed(const Base& A, const Base& B) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Row::init(A,B); } template template inline Row::fixed::fixed(const eT* aux_mem) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; arrayops::copy( dest, aux_mem, fixed_n_elem ); } template template inline Row::fixed::fixed(const char* text) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Row::operator=(text); } template template inline Row::fixed::fixed(const std::string& text) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Row::operator=(text); } template template template const Row& Row::fixed::operator=(const Base& A) { arma_extra_debug_sigprint(); Row::operator=(A.get_ref()); return *this; } template template const Row& Row::fixed::operator=(const eT val) { arma_extra_debug_sigprint(); Row::operator=(val); return *this; } template template const Row& Row::fixed::operator=(const char* text) { arma_extra_debug_sigprint(); Row::operator=(text); return *this; } template template const Row& Row::fixed::operator=(const std::string& text) { arma_extra_debug_sigprint(); Row::operator=(text); return *this; } template template const Row& Row::fixed::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); Row::operator=(X); return *this; } #if defined(ARMA_USE_CXX11) template template inline Row::fixed::fixed(const std::initializer_list& list) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); (*this).operator=(list); } template template inline const Row& Row::fixed::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); const uword N = list.size(); arma_debug_check( (N > fixed_n_elem), "Row::fixed: initialiser list is too long" ); eT* this_mem = (*this).memptr(); arrayops::copy( this_mem, list.begin(), N ); for(uword iq=N; iq < fixed_n_elem; ++iq) { this_mem[iq] = eT(0); } return *this; } #endif template template arma_inline const Row& Row::fixed::operator=(const fixed& X) { arma_extra_debug_sigprint(); eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); return *this; } template template arma_inline const Op< typename Row::template fixed::Row_fixed_type, op_htrans > Row::fixed::t() const { return Op< typename Row::template fixed::Row_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Row::template fixed::Row_fixed_type, op_htrans > Row::fixed::ht() const { return Op< typename Row::template fixed::Row_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Row::template fixed::Row_fixed_type, op_strans > Row::fixed::st() const { return Op< typename Row::template fixed::Row_fixed_type, op_strans >(*this); } template template arma_inline arma_warn_unused const eT& Row::fixed::at_alt(const uword ii) const { #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE) return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; #else const eT* mem_aligned = (use_extra) ? mem_local_extra : Mat::mem_local; memory::mark_as_aligned(mem_aligned); return mem_aligned[ii]; #endif } template template arma_inline arma_warn_unused eT& Row::fixed::operator[] (const uword ii) { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Row::fixed::operator[] (const uword ii) const { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Row::fixed::at(const uword ii) { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Row::fixed::at(const uword ii) const { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Row::fixed::operator() (const uword ii) { arma_debug_check( (ii >= fixed_n_elem), "Row::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Row::fixed::operator() (const uword ii) const { arma_debug_check( (ii >= fixed_n_elem), "Row::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Row::fixed::at(const uword, const uword in_col) { return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; } template template arma_inline arma_warn_unused const eT& Row::fixed::at(const uword, const uword in_col) const { return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; } template template arma_inline arma_warn_unused eT& Row::fixed::operator() (const uword in_row, const uword in_col) { arma_debug_check( ((in_row > 0) || (in_col >= fixed_n_elem)), "Row::operator(): index out of bounds" ); return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; } template template arma_inline arma_warn_unused const eT& Row::fixed::operator() (const uword in_row, const uword in_col) const { arma_debug_check( ((in_row > 0) || (in_col >= fixed_n_elem)), "Row::operator(): index out of bounds" ); return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; } template template arma_inline arma_warn_unused eT* Row::fixed::memptr() { return (use_extra) ? mem_local_extra : Mat::mem_local; } template template arma_inline arma_warn_unused const eT* Row::fixed::memptr() const { return (use_extra) ? mem_local_extra : Mat::mem_local; } template template arma_hot inline const Row& Row::fixed::fill(const eT val) { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, val ); return *this; } template template arma_hot inline const Row& Row::fixed::zeros() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(0) ); return *this; } template template arma_hot inline const Row& Row::fixed::ones() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(1) ); return *this; } template inline Row::Row(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem) : Mat(arma_fixed_indicator(), 1, in_n_elem, 2, in_mem) { arma_extra_debug_sigprint_this(this); } #ifdef ARMA_EXTRA_ROW_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_ROW_MEAT) #endif //! @} RcppArmadillo/inst/include/armadillo_bits/op_dotext_bones.hpp0000644000176000001440000000202712200631217024317 0ustar ripleyusers// Copyright (C) 2008-2010 Conrad Sanderson // Copyright (C) 2008-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_dotext //! @{ class op_dotext { public: template inline static eT direct_rowvec_mat_colvec (const eT* A_mem, const Mat& B, const eT* C_mem); template inline static eT direct_rowvec_transmat_colvec (const eT* A_mem, const Mat& B, const eT* C_mem); template inline static eT direct_rowvec_diagmat_colvec (const eT* A_mem, const Mat& B, const eT* C_mem); template inline static eT direct_rowvec_invdiagmat_colvec(const eT* A_mem, const Mat& B, const eT* C_mem); template inline static eT direct_rowvec_invdiagvec_colvec(const eT* A_mem, const Mat& B, const eT* C_mem); }; //! @} RcppArmadillo/inst/include/armadillo_bits/running_stat_bones.hpp0000644000176000001440000000473412247635517025056 0ustar ripleyusers// Copyright (C) 2009-2013 Conrad Sanderson // Copyright (C) 2009-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup running_stat //! @{ template class arma_counter { public: inline ~arma_counter(); inline arma_counter(); inline const arma_counter& operator++(); inline void operator++(int); inline void reset(); inline eT value() const; inline eT value_plus_1() const; inline eT value_minus_1() const; private: arma_aligned eT d_count; arma_aligned uword i_count; }; //! Class for keeping statistics of a continuously sampled process / signal. //! Useful if the storage of individual samples is not necessary or desired. //! Also useful if the number of samples is not known beforehand or exceeds //! available memory. template class running_stat { public: typedef typename get_pod_type::result T; inline ~running_stat(); inline running_stat(); inline void operator() (const T sample); inline void operator() (const std::complex& sample); inline void reset(); inline eT mean() const; inline T var (const uword norm_type = 0) const; inline T stddev(const uword norm_type = 0) const; inline eT min() const; inline eT max() const; inline T count() const; // // private: arma_aligned arma_counter counter; arma_aligned eT r_mean; arma_aligned T r_var; arma_aligned eT min_val; arma_aligned eT max_val; arma_aligned T min_val_norm; arma_aligned T max_val_norm; friend class running_stat_aux; }; class running_stat_aux { public: template inline static void update_stats(running_stat& x, const eT sample, const typename arma_not_cx::result* junk = 0); template inline static void update_stats(running_stat& x, const std::complex& sample, const typename arma_not_cx::result* junk = 0); template inline static void update_stats(running_stat& x, const typename eT::value_type sample, const typename arma_cx_only::result* junk = 0); template inline static void update_stats(running_stat& x, const eT& sample, const typename arma_cx_only::result* junk = 0); }; //! @} RcppArmadillo/inst/include/armadillo_bits/glue_hist_meat.hpp0000644000176000001440000001214112256562725024135 0ustar ripleyusers// Copyright (C) 2012-2013 Conrad Sanderson // Copyright (C) 2012-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. template inline void glue_hist::apply(Mat& out, const mtGlue& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword; const unwrap_check_mixed tmp1(in.A, out); const unwrap_check_mixed tmp2(in.B, out); const Mat& X = tmp1.M; const Mat& C = tmp2.M; arma_debug_check ( ((C.is_vec() == false) && (C.is_empty() == false)), "hist(): parameter 'centers' must be a vector" ); arma_debug_check ( (dim > 1), "hist(): parameter 'dim' must be 0 or 1" ); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword X_n_elem = X.n_elem; const uword C_n_elem = C.n_elem; if( C_n_elem == 0 ) { out.reset(); return; } // for vectors we are currently ignoring the "dim" parameter uword out_n_rows = 0; uword out_n_cols = 0; if(X.is_vec()) { if(X.is_rowvec()) { out_n_rows = 1; out_n_cols = C_n_elem; } else if(X.is_colvec()) { out_n_rows = C_n_elem; out_n_cols = 1; } } else { if(dim == 0) { out_n_rows = C_n_elem; out_n_cols = X_n_cols; } else if(dim == 1) { out_n_rows = X_n_rows; out_n_cols = C_n_elem; } } out.zeros(out_n_rows, out_n_cols); const eT* C_mem = C.memptr(); const eT center_0 = C_mem[0]; if(X.is_vec()) { const eT* X_mem = X.memptr(); uword* out_mem = out.memptr(); for(uword i=0; i < X_n_elem; ++i) { const eT val = X_mem[i]; if(is_finite(val)) { eT opt_dist = (val >= center_0) ? (val - center_0) : (center_0 - val); uword opt_index = 0; for(uword j=1; j < C_n_elem; ++j) { const eT center = C_mem[j]; const eT dist = (val >= center) ? (val - center) : (center - val); if(dist < opt_dist) { opt_dist = dist; opt_index = j; } else { break; } } out_mem[opt_index]++; } else { // -inf if(val < eT(0)) { out_mem[0]++; } // +inf if(val > eT(0)) { out_mem[C_n_elem-1]++; } // ignore NaN } } } else { if(dim == 0) { for(uword col=0; col < X_n_cols; ++col) { const eT* X_coldata = X.colptr(col); uword* out_coldata = out.colptr(col); for(uword row=0; row < X_n_rows; ++row) { const eT val = X_coldata[row]; if(arma_isfinite(val)) { eT opt_dist = (center_0 >= val) ? (center_0 - val) : (val - center_0); uword opt_index = 0; for(uword j=1; j < C_n_elem; ++j) { const eT center = C_mem[j]; const eT dist = (center >= val) ? (center - val) : (val - center); if(dist < opt_dist) { opt_dist = dist; opt_index = j; } else { break; } } out_coldata[opt_index]++; } else { // -inf if(val < eT(0)) { out_coldata[0]++; } // +inf if(val > eT(0)) { out_coldata[C_n_elem-1]++; } // ignore NaN } } } } else if(dim == 1) { for(uword row=0; row < X_n_rows; ++row) { for(uword col=0; col < X_n_cols; ++col) { const eT val = X.at(row,col); if(arma_isfinite(val)) { eT opt_dist = (center_0 >= val) ? (center_0 - val) : (val - center_0); uword opt_index = 0; for(uword j=1; j < C_n_elem; ++j) { const eT center = C_mem[j]; const eT dist = (center >= val) ? (center - val) : (val - center); if(dist < opt_dist) { opt_dist = dist; opt_index = j; } else { break; } } out.at(row,opt_index)++; } else { // -inf if(val < eT(0)) { out.at(row,0)++; } // +inf if(val > eT(0)) { out.at(row,C_n_elem-1)++; } // ignore NaN } } } } } } RcppArmadillo/inst/include/armadillo_bits/op_relational_meat.hpp0000644000176000001440000002314612200631217024767 0ustar ripleyusers// Copyright (C) 2009-2012 Conrad Sanderson // Copyright (C) 2009-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_relational //! @{ #undef operator_rel #undef arma_applier_mat_pre #undef arma_applier_mat_post #undef arma_applier_cube_pre #undef arma_applier_cube_post #define arma_applier_mat_pre(operator_rel) \ {\ typedef typename T1::elem_type eT;\ typedef typename Proxy::ea_type ea_type;\ \ const eT val = X.aux;\ \ const Proxy P(X.m);\ \ const uword n_rows = P.get_n_rows();\ const uword n_cols = P.get_n_cols();\ \ const bool bad_alias = ( Proxy::has_subview && P.is_alias(out) );\ \ if(bad_alias == false)\ {\ out.set_size(n_rows, n_cols);\ \ uword* out_mem = out.memptr();\ \ if(Proxy::prefer_at_accessor == false)\ {\ ea_type PA = P.get_ea();\ const uword n_elem = out.n_elem;\ \ for(uword i=0; i tmp(P.Q);\ \ out = (val) operator_rel (tmp);\ }\ } #define arma_applier_mat_post(operator_rel) \ {\ typedef typename T1::elem_type eT;\ typedef typename Proxy::ea_type ea_type;\ \ const eT val = X.aux;\ \ const Proxy P(X.m);\ \ const uword n_rows = P.get_n_rows();\ const uword n_cols = P.get_n_cols();\ \ const bool bad_alias = ( Proxy::has_subview && P.is_alias(out) );\ \ if(bad_alias == false)\ {\ out.set_size(n_rows, n_cols);\ \ uword* out_mem = out.memptr();\ \ if(Proxy::prefer_at_accessor == false)\ {\ ea_type PA = P.get_ea();\ const uword n_elem = out.n_elem;\ \ for(uword i=0; i tmp(P.Q);\ \ out = (tmp) operator_rel (val);\ }\ } #define arma_applier_cube_pre(operator_rel) \ {\ typedef typename T1::elem_type eT;\ typedef typename ProxyCube::ea_type ea_type;\ \ const eT val = X.aux;\ \ const ProxyCube P(X.m);\ \ const uword n_rows = P.get_n_rows();\ const uword n_cols = P.get_n_cols();\ const uword n_slices = P.get_n_slices();\ \ const bool bad_alias = ( ProxyCube::has_subview && P.is_alias(out) );\ \ if(bad_alias == false)\ {\ out.set_size(n_rows, n_cols, n_slices);\ \ uword* out_mem = out.memptr();\ \ if(ProxyCube::prefer_at_accessor == false)\ {\ ea_type PA = P.get_ea();\ const uword n_elem = out.n_elem;\ \ for(uword i=0; i::stored_type> tmp(P.Q);\ \ out = (val) operator_rel (tmp.M);\ }\ } #define arma_applier_cube_post(operator_rel) \ {\ typedef typename T1::elem_type eT;\ typedef typename ProxyCube::ea_type ea_type;\ \ const eT val = X.aux;\ \ const ProxyCube P(X.m);\ \ const uword n_rows = P.get_n_rows();\ const uword n_cols = P.get_n_cols();\ const uword n_slices = P.get_n_slices();\ \ const bool bad_alias = ( ProxyCube::has_subview && P.is_alias(out) );\ \ if(bad_alias == false)\ {\ out.set_size(n_rows, n_cols, n_slices);\ \ uword* out_mem = out.memptr();\ \ if(ProxyCube::prefer_at_accessor == false)\ {\ ea_type PA = P.get_ea();\ const uword n_elem = out.n_elem;\ \ for(uword i=0; i::stored_type> tmp(P.Q);\ \ out = (tmp.M) operator_rel (val);\ }\ } template inline void op_rel_lt_pre::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_pre( < ); } template inline void op_rel_gt_pre::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_pre( > ); } template inline void op_rel_lteq_pre::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_pre( <= ); } template inline void op_rel_gteq_pre::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_pre( >= ); } template inline void op_rel_lt_post::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( < ); } template inline void op_rel_gt_post::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( > ); } template inline void op_rel_lteq_post::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( <= ); } template inline void op_rel_gteq_post::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( >= ); } template inline void op_rel_eq::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( == ); } template inline void op_rel_noteq::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( != ); } // // // template inline void op_rel_lt_pre::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_pre( < ); } template inline void op_rel_gt_pre::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_pre( > ); } template inline void op_rel_lteq_pre::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_pre( <= ); } template inline void op_rel_gteq_pre::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_pre( >= ); } template inline void op_rel_lt_post::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( < ); } template inline void op_rel_gt_post::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( > ); } template inline void op_rel_lteq_post::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( <= ); } template inline void op_rel_gteq_post::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( >= ); } template inline void op_rel_eq::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( == ); } template inline void op_rel_noteq::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( != ); } #undef arma_applier_mat_pre #undef arma_applier_mat_post #undef arma_applier_cube_pre #undef arma_applier_cube_post //! @} RcppArmadillo/inst/include/armadillo_bits/spop_misc_meat.hpp0000644000176000001440000000446612111344723024143 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup spop_misc //! @{ namespace priv { template struct functor_scalar_times { const eT k; functor_scalar_times(const eT in_k) : k(in_k) {} arma_inline eT operator()(const eT val) const { return val * k; } }; } template inline void spop_scalar_times::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; out.init_xform(in.m, priv::functor_scalar_times(in.aux)); } namespace priv { struct functor_square { template arma_inline eT operator()(const eT val) const { return val*val; } }; } template inline void spop_square::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); out.init_xform(in.m, priv::functor_square()); } namespace priv { struct functor_sqrt { template arma_inline eT operator()(const eT val) const { return eop_aux::sqrt(val); } }; } template inline void spop_sqrt::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); out.init_xform(in.m, priv::functor_sqrt()); } namespace priv { struct functor_abs { template arma_inline eT operator()(const eT val) const { return eop_aux::arma_abs(val); } }; } template inline void spop_abs::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); out.init_xform(in.m, priv::functor_abs()); } namespace priv { struct functor_cx_abs { template arma_inline T operator()(const std::complex& val) const { return std::abs(val); } }; } template inline void spop_cx_abs::apply(SpMat& out, const mtSpOp& in) { arma_extra_debug_sigprint(); out.init_xform_mt(in.m, priv::functor_cx_abs()); } //! @} RcppArmadillo/inst/include/armadillo_bits/restrictors.hpp0000644000176000001440000002214412233430607023517 0ustar ripleyusers// Copyright (C) 2010-2013 Conrad Sanderson // Copyright (C) 2010-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup restrictors //! @{ // structures for template based restrictions of input/output arguments // (part of the SFINAE approach) // http://en.wikipedia.org/wiki/SFINAE template struct arma_scalar_only { }; template<> struct arma_scalar_only { typedef u8 result; }; template<> struct arma_scalar_only { typedef s8 result; }; template<> struct arma_scalar_only { typedef u16 result; }; template<> struct arma_scalar_only { typedef s16 result; }; template<> struct arma_scalar_only { typedef u32 result; }; template<> struct arma_scalar_only { typedef s32 result; }; #if defined(ARMA_USE_U64S64) template<> struct arma_scalar_only { typedef u64 result; }; template<> struct arma_scalar_only { typedef s64 result; }; #endif template<> struct arma_scalar_only { typedef float result; }; template<> struct arma_scalar_only { typedef double result; }; #if defined(ARMA_ALLOW_LONG) template<> struct arma_scalar_only { typedef ulng_t result; }; template<> struct arma_scalar_only { typedef slng_t result; }; #endif template struct arma_scalar_only< std::complex > { typedef std::complex result; }; template struct arma_integral_only { }; template<> struct arma_integral_only { typedef u8 result; }; template<> struct arma_integral_only { typedef s8 result; }; template<> struct arma_integral_only { typedef u16 result; }; template<> struct arma_integral_only { typedef s16 result; }; template<> struct arma_integral_only { typedef u32 result; }; template<> struct arma_integral_only { typedef s32 result; }; #if defined(ARMA_USE_U64S64) template<> struct arma_integral_only { typedef u64 result; }; template<> struct arma_integral_only { typedef s64 result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct arma_integral_only { typedef ulng_t result; }; template<> struct arma_integral_only { typedef slng_t result; }; #endif template struct arma_unsigned_integral_only { }; template<> struct arma_unsigned_integral_only { typedef u8 result; }; template<> struct arma_unsigned_integral_only { typedef u16 result; }; template<> struct arma_unsigned_integral_only { typedef u32 result; }; #if defined(ARMA_USE_U64S64) template<> struct arma_unsigned_integral_only { typedef u64 result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct arma_unsigned_integral_only { typedef ulng_t result; }; #endif template struct arma_signed_integral_only { }; template<> struct arma_signed_integral_only { typedef s8 result; }; template<> struct arma_signed_integral_only { typedef s16 result; }; template<> struct arma_signed_integral_only { typedef s32 result; }; #if defined(ARMA_USE_U64S64) template<> struct arma_signed_integral_only { typedef s64 result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct arma_signed_integral_only { typedef slng_t result; }; #endif template struct arma_signed_only { }; template<> struct arma_signed_only { typedef s8 result; }; template<> struct arma_signed_only { typedef s16 result; }; template<> struct arma_signed_only { typedef s32 result; }; #if defined(ARMA_USE_U64S64) template<> struct arma_signed_only { typedef s64 result; }; #endif template<> struct arma_signed_only { typedef float result; }; template<> struct arma_signed_only { typedef double result; }; #if defined(ARMA_ALLOW_LONG) template<> struct arma_signed_only { typedef slng_t result; }; #endif template struct arma_signed_only< std::complex > { typedef std::complex result; }; template struct arma_real_only { }; template<> struct arma_real_only { typedef float result; }; template<> struct arma_real_only { typedef double result; }; template struct arma_real_or_cx_only { }; template<> struct arma_real_or_cx_only< float > { typedef float result; }; template<> struct arma_real_or_cx_only< double > { typedef double result; }; template<> struct arma_real_or_cx_only< std::complex > { typedef std::complex result; }; template<> struct arma_real_or_cx_only< std::complex > { typedef std::complex result; }; template struct arma_cx_only { }; template<> struct arma_cx_only< std::complex > { typedef std::complex result; }; template<> struct arma_cx_only< std::complex > { typedef std::complex result; }; template struct arma_not_cx { typedef T result; }; template struct arma_not_cx< std::complex > { }; template struct arma_blas_type_only { }; template<> struct arma_blas_type_only< float > { typedef float result; }; template<> struct arma_blas_type_only< double > { typedef double result; }; template<> struct arma_blas_type_only< std::complex > { typedef std::complex result; }; template<> struct arma_blas_type_only< std::complex > { typedef std::complex result; }; template struct arma_not_blas_type { typedef T result; }; template<> struct arma_not_blas_type< float > { }; template<> struct arma_not_blas_type< double > { }; template<> struct arma_not_blas_type< std::complex > { }; template<> struct arma_not_blas_type< std::complex > { }; template struct arma_op_rel_only { }; template<> struct arma_op_rel_only< op_rel_lt_pre > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_lt_post > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_gt_pre > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_gt_post > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_lteq_pre > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_lteq_post > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_gteq_pre > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_gteq_post > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_eq > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_noteq > { typedef int result; }; template struct arma_not_op_rel { typedef int result; }; template<> struct arma_not_op_rel< op_rel_lt_pre > { }; template<> struct arma_not_op_rel< op_rel_lt_post > { }; template<> struct arma_not_op_rel< op_rel_gt_pre > { }; template<> struct arma_not_op_rel< op_rel_gt_post > { }; template<> struct arma_not_op_rel< op_rel_lteq_pre > { }; template<> struct arma_not_op_rel< op_rel_lteq_post > { }; template<> struct arma_not_op_rel< op_rel_gteq_pre > { }; template<> struct arma_not_op_rel< op_rel_gteq_post > { }; template<> struct arma_not_op_rel< op_rel_eq > { }; template<> struct arma_not_op_rel< op_rel_noteq > { }; template struct arma_glue_rel_only { }; template<> struct arma_glue_rel_only< glue_rel_lt > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_gt > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_lteq > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_gteq > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_eq > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_noteq > { typedef int result; }; template struct arma_Mat_Col_Row_only { }; template struct arma_Mat_Col_Row_only< Mat > { typedef Mat result; }; template struct arma_Mat_Col_Row_only< Col > { typedef Col result; }; template struct arma_Mat_Col_Row_only< Row > { typedef Row result; }; template struct arma_Cube_only { }; template struct arma_Cube_only< Cube > { typedef Cube result; }; template struct arma_SpMat_SpCol_SpRow_only { }; template struct arma_SpMat_SpCol_SpRow_only< SpMat > { typedef SpMat result; }; template struct arma_SpMat_SpCol_SpRow_only< SpCol > { typedef SpCol result; }; template struct arma_SpMat_SpCol_SpRow_only< SpRow > { typedef SpRow result; }; template struct enable_if { }; template<> struct enable_if { typedef int result; }; template struct enable_if2 { }; template< typename result_type > struct enable_if2 { typedef result_type result; }; //! @} RcppArmadillo/inst/include/armadillo_bits/SpMat_meat.hpp0000644000176000001440000033362712265411417023204 0ustar ripleyusers// Copyright (C) 2011-2013 Ryan Curtin // Copyright (C) 2012-2013 Conrad Sanderson // Copyright (C) 2011 Matthew Amidon // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpMat //! @{ /** * Initialize a sparse matrix with size 0x0 (empty). */ template inline SpMat::SpMat() : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(memory::acquire_chunked(1)) , row_indices(memory::acquire_chunked(1)) , col_ptrs(memory::acquire(2)) { arma_extra_debug_sigprint_this(this); access::rw(values[0]) = 0; access::rw(row_indices[0]) = 0; access::rw(col_ptrs[0]) = 0; // No elements. access::rw(col_ptrs[1]) = std::numeric_limits::max(); } /** * Clean up the memory of a sparse matrix and destruct it. */ template inline SpMat::~SpMat() { arma_extra_debug_sigprint_this(this); if(values ) { memory::release(access::rw(values)); } if(row_indices) { memory::release(access::rw(row_indices)); } if(col_ptrs ) { memory::release(access::rw(col_ptrs)); } } /** * Constructor with size given. */ template inline SpMat::SpMat(const uword in_rows, const uword in_cols) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); init(in_rows, in_cols); } /** * Assemble from text. */ template inline SpMat::SpMat(const char* text) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); init(std::string(text)); } template inline const SpMat& SpMat::operator=(const char* text) { arma_extra_debug_sigprint(); init(std::string(text)); } template inline SpMat::SpMat(const std::string& text) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint(); init(text); } template inline const SpMat& SpMat::operator=(const std::string& text) { arma_extra_debug_sigprint(); init(text); } template inline SpMat::SpMat(const SpMat& x) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); init(x); } #if defined(ARMA_USE_CXX11) template inline SpMat::SpMat(SpMat&& in_mat) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") % this % &in_mat); (*this).steal_mem(in_mat); } template inline const SpMat& SpMat::operator=(SpMat&& in_mat) { arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") % this % &in_mat); (*this).steal_mem(in_mat); return *this; } #endif //! Insert a large number of values at once. //! locations.row[0] should be row indices, locations.row[1] should be column indices, //! and values should be the corresponding values. //! If sort_locations is false, then it is assumed that the locations and values //! are already sorted in column-major ordering. template template inline SpMat::SpMat(const Base& locations_expr, const Base& vals_expr, const bool sort_locations) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); const unwrap locs_tmp( locations_expr.get_ref() ); const Mat& locs = locs_tmp.M; const unwrap vals_tmp( vals_expr.get_ref() ); const Mat& vals = vals_tmp.M; arma_debug_check( (vals.is_vec() == false), "SpMat::SpMat(): given 'values' object is not a vector" ); arma_debug_check((locs.n_cols != vals.n_elem), "SpMat::SpMat(): number of locations is different than number of values"); // If there are no elements in the list, max() will fail. if (locs.n_cols == 0) { init(0, 0); return; } arma_debug_check((locs.n_rows != 2), "SpMat::SpMat(): locations matrix must have two rows"); // Automatically determine size (and check if it's sorted). uvec bounds = arma::max(locs, 1); init(bounds[0] + 1, bounds[1] + 1); // Resize to correct number of elements. mem_resize(vals.n_elem); // Reset column pointers to zero. arrayops::inplace_set(access::rwp(col_ptrs), uword(0), n_cols + 1); bool actually_sorted = true; if(sort_locations == true) { // sort_index() uses std::sort() which may use quicksort... so we better // make sure it's not already sorted before taking an O(N^2) sort penalty. for (uword i = 1; i < locs.n_cols; ++i) { if ((locs.at(1, i) < locs.at(1, i - 1)) || (locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) <= locs.at(0, i - 1))) { actually_sorted = false; break; } } if(actually_sorted == false) { // This may not be the fastest possible implementation but it maximizes code reuse. Col abslocs(locs.n_cols); for (uword i = 0; i < locs.n_cols; ++i) { abslocs[i] = locs.at(1, i) * n_rows + locs.at(0, i); } // Now we will sort with sort_index(). uvec sorted_indices = sort_index(abslocs); // Ascending sort. // Now we add the elements in this sorted order. for (uword i = 0; i < sorted_indices.n_elem; ++i) { arma_debug_check((locs.at(0, sorted_indices[i]) >= n_rows), "SpMat::SpMat(): invalid row index"); arma_debug_check((locs.at(1, sorted_indices[i]) >= n_cols), "SpMat::SpMat(): invalid column index"); access::rw(values[i]) = vals[sorted_indices[i]]; access::rw(row_indices[i]) = locs.at(0, sorted_indices[i]); access::rw(col_ptrs[locs.at(1, sorted_indices[i]) + 1])++; } } } if( (sort_locations == false) || (actually_sorted == true) ) { // Now set the values and row indices correctly. // Increment the column pointers in each column (so they are column "counts"). for (uword i = 0; i < vals.n_elem; ++i) { arma_debug_check((locs.at(0, i) >= n_rows), "SpMat::SpMat(): invalid row index"); arma_debug_check((locs.at(1, i) >= n_cols), "SpMat::SpMat(): invalid column index"); // Check ordering in debug mode. if(i > 0) { arma_debug_check ( ( (locs.at(1, i) < locs.at(1, i - 1)) || (locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) < locs.at(0, i - 1)) ), "SpMat::SpMat(): out of order points; either pass sort_locations = true, or sort points in column-major ordering" ); arma_debug_check((locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) == locs.at(0, i - 1)), "SpMat::SpMat(): two identical point locations in list"); } access::rw(values[i]) = vals[i]; access::rw(row_indices[i]) = locs.at(0, i); access::rw(col_ptrs[locs.at(1, i) + 1])++; } } // Now fix the column pointers. for (uword i = 0; i <= n_cols; ++i) { access::rw(col_ptrs[i + 1]) += col_ptrs[i]; } } //! Insert a large number of values at once. //! locations.row[0] should be row indices, locations.row[1] should be column indices, //! and values should be the corresponding values. //! If sort_locations is false, then it is assumed that the locations and values //! are already sorted in column-major ordering. //! In this constructor the size is explicitly given. template template inline SpMat::SpMat(const Base& locations_expr, const Base& vals_expr, const uword in_n_rows, const uword in_n_cols, const bool sort_locations) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); init(in_n_rows, in_n_cols); const unwrap locs_tmp( locations_expr.get_ref() ); const unwrap vals_tmp( vals_expr.get_ref() ); const Mat& locs = locs_tmp.M; const Mat& vals = vals_tmp.M; arma_debug_check( (vals.is_vec() == false), "SpMat::SpMat(): given 'values' object is not a vector" ); arma_debug_check( (locs.n_rows != 2), "SpMat::SpMat(): locations matrix must have two rows" ); arma_debug_check( (locs.n_cols != vals.n_elem), "SpMat::SpMat(): number of locations is different than number of values" ); // Resize to correct number of elements. mem_resize(vals.n_elem); // Reset column pointers to zero. arrayops::inplace_set(access::rwp(col_ptrs), uword(0), n_cols + 1); bool actually_sorted = true; if(sort_locations == true) { // sort_index() uses std::sort() which may use quicksort... so we better // make sure it's not already sorted before taking an O(N^2) sort penalty. for (uword i = 1; i < locs.n_cols; ++i) { if ((locs.at(1, i) < locs.at(1, i - 1)) || (locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) <= locs.at(0, i - 1))) { actually_sorted = false; break; } } if(actually_sorted == false) { // This may not be the fastest possible implementation but it maximizes code reuse. Col abslocs(locs.n_cols); for (uword i = 0; i < locs.n_cols; ++i) { abslocs[i] = locs.at(1, i) * n_rows + locs.at(0, i); } // Now we will sort with sort_index(). uvec sorted_indices = sort_index(abslocs); // Ascending sort. // Now we add the elements in this sorted order. for (uword i = 0; i < sorted_indices.n_elem; ++i) { arma_debug_check((locs.at(0, sorted_indices[i]) >= n_rows), "SpMat::SpMat(): invalid row index"); arma_debug_check((locs.at(1, sorted_indices[i]) >= n_cols), "SpMat::SpMat(): invalid column index"); access::rw(values[i]) = vals[sorted_indices[i]]; access::rw(row_indices[i]) = locs.at(0, sorted_indices[i]); access::rw(col_ptrs[locs.at(1, sorted_indices[i]) + 1])++; } } } if( (sort_locations == false) || (actually_sorted == true) ) { // Now set the values and row indices correctly. // Increment the column pointers in each column (so they are column "counts"). for (uword i = 0; i < vals.n_elem; ++i) { arma_debug_check((locs.at(0, i) >= n_rows), "SpMat::SpMat(): invalid row index"); arma_debug_check((locs.at(1, i) >= n_cols), "SpMat::SpMat(): invalid column index"); // Check ordering in debug mode. if(i > 0) { arma_debug_check ( ( (locs.at(1, i) < locs.at(1, i - 1)) || (locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) < locs.at(0, i - 1)) ), "SpMat::SpMat(): out of order points; either pass sort_locations = true or sort points in column-major ordering" ); arma_debug_check((locs.at(1, i) == locs.at(1, i - 1) && locs.at(0, i) == locs.at(0, i - 1)), "SpMat::SpMat(): two identical point locations in list"); } //! If sort_locations is false, then it is assumed that the locations and values //! are already sorted in column-major ordering. access::rw(values[i]) = vals[i]; access::rw(row_indices[i]) = locs.at(0, i); access::rw(col_ptrs[locs.at(1, i) + 1])++; } } // Now fix the column pointers. for (uword i = 0; i <= n_cols; ++i) { access::rw(col_ptrs[i + 1]) += col_ptrs[i]; } } //! Insert a large number of values at once. //! Per CSC format, rowind_expr should be row indices, //! colptr_expr should column ptr indices locations, //! and values should be the corresponding values. //! In this constructor the size is explicitly given. //! Values are assumed to be sorted, and the size //! information is trusted template template inline SpMat::SpMat ( const Base& rowind_expr, const Base& colptr_expr, const Base& values_expr, const uword in_n_rows, const uword in_n_cols ) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); init(in_n_rows, in_n_cols); const unwrap rowind_tmp( rowind_expr.get_ref() ); const unwrap colptr_tmp( colptr_expr.get_ref() ); const unwrap vals_tmp( values_expr.get_ref() ); const Mat& rowind = rowind_tmp.M; const Mat& colptr = colptr_tmp.M; const Mat& vals = vals_tmp.M; arma_debug_check( (rowind.is_vec() == false), "SpMat::SpMat(): given 'rowind' object is not a vector" ); arma_debug_check( (colptr.is_vec() == false), "SpMat::SpMat(): given 'colptr' object is not a vector" ); arma_debug_check( (vals.is_vec() == false), "SpMat::SpMat(): given 'values' object is not a vector" ); arma_debug_check( (rowind.n_elem != vals.n_elem), "SpMat::SpMat(): number of row indices is not equal to number of values" ); arma_debug_check( (colptr.n_elem != (n_cols+1) ), "SpMat::SpMat(): number of column pointers is not equal to n_cols+1" ); // Resize to correct number of elements (this also sets n_nonzero) mem_resize(vals.n_elem); // copy supplied values into sparse matrix -- not checked for consistency arrayops::copy(access::rwp(row_indices), rowind.memptr(), rowind.n_elem ); arrayops::copy(access::rwp(col_ptrs), colptr.memptr(), colptr.n_elem ); arrayops::copy(access::rwp(values), vals.memptr(), vals.n_elem ); // important: set the sentinel as well access::rw(col_ptrs[n_cols + 1]) = std::numeric_limits::max(); } /** * Simple operators with plain values. These operate on every value in the * matrix, so a sparse matrix += 1 will turn all those zeroes into ones. Be * careful and make sure that's what you really want! */ template inline const SpMat& SpMat::operator=(const eT val) { arma_extra_debug_sigprint(); // Resize to 1x1 then set that to the right value. init(1, 1); // Sets col_ptrs to 0. mem_resize(1); // One element. // Manually set element. access::rw(values[0]) = val; access::rw(row_indices[0]) = 0; access::rw(col_ptrs[1]) = 1; return *this; } template inline const SpMat& SpMat::operator*=(const eT val) { arma_extra_debug_sigprint(); if(val == eT(0)) { // Everything will be zero. init(n_rows, n_cols); return *this; } arrayops::inplace_mul( access::rwp(values), val, n_nonzero ); return *this; } template inline const SpMat& SpMat::operator/=(const eT val) { arma_extra_debug_sigprint(); arma_debug_check( (val == eT(0)), "element-wise division: division by zero" ); arrayops::inplace_div( access::rwp(values), val, n_nonzero ); return *this; } template inline const SpMat& SpMat::operator=(const SpMat& x) { arma_extra_debug_sigprint(); init(x); return *this; } template inline const SpMat& SpMat::operator+=(const SpMat& x) { arma_extra_debug_sigprint(); SpMat out; out = (*this) + x; steal_mem(out); return *this; } template inline const SpMat& SpMat::operator-=(const SpMat& x) { arma_extra_debug_sigprint(); SpMat out; out = (*this) - x; steal_mem(out); return *this; } template inline const SpMat& SpMat::operator*=(const SpMat& y) { arma_extra_debug_sigprint(); SpMat z; z = (*this) * y; steal_mem(z); return *this; } // This is in-place element-wise matrix multiplication. template inline const SpMat& SpMat::operator%=(const SpMat& x) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise multiplication"); // We can do this with two iterators rather simply. iterator it = begin(); const_iterator x_it = x.begin(); while (it != end() && x_it != x.end()) { // One of these will be further advanced than the other (or they will be at the same place). if ((it.row() == x_it.row()) && (it.col() == x_it.col())) { // There is an element at this place in both matrices. Multiply. (*it) *= (*x_it); // Now move on to the next position. it++; x_it++; } else if ((it.col() < x_it.col()) || ((it.col() == x_it.col()) && (it.row() < x_it.row()))) { // This case is when our matrix has an element which the other matrix does not. // So we must delete this element. (*it) = 0; // Because we have deleted the element, we now have to manually set the position... it.internal_pos--; // Now we can increment our iterator. it++; } else /* if our iterator is ahead of the other matrix */ { // In this case we don't need to set anything to 0; our element is already 0. // We can just increment the iterator of the other matrix. x_it++; } } // If we are not at the end of our matrix, then we must terminate the remaining elements. while (it != end()) { (*it) = 0; // Hack to manually set the position right... it.internal_pos--; it++; // ...and then an increment. } return *this; } // Construct a complex matrix out of two non-complex matrices template template inline SpMat::SpMat ( const SpBase::pod_type, T1>& A, const SpBase::pod_type, T2>& B ) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // extra element is set when mem_resize is called , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint(); typedef typename T1::elem_type T; // Make sure eT is complex and T is not (compile-time check). arma_type_check(( is_complex::value == false )); arma_type_check(( is_complex< T>::value == true )); // Compile-time abort if types are not compatible. arma_type_check(( is_same_type< std::complex, eT >::no )); const unwrap_spmat tmp1(A.get_ref()); const unwrap_spmat tmp2(B.get_ref()); const SpMat& X = tmp1.M; const SpMat& Y = tmp2.M; arma_debug_assert_same_size(X.n_rows, X.n_cols, Y.n_rows, Y.n_cols, "SpMat()"); const uword l_n_rows = X.n_rows; const uword l_n_cols = X.n_cols; // Set size of matrix correctly. init(l_n_rows, l_n_cols); mem_resize(n_unique(X, Y, op_n_unique_count())); // Now on a second iteration, fill it. typename SpMat::const_iterator x_it = X.begin(); typename SpMat::const_iterator x_end = X.end(); typename SpMat::const_iterator y_it = Y.begin(); typename SpMat::const_iterator y_end = Y.end(); uword cur_pos = 0; while ((x_it != x_end) || (y_it != y_end)) { if(x_it == y_it) // if we are at the same place { access::rw(values[cur_pos]) = std::complex((T) *x_it, (T) *y_it); access::rw(row_indices[cur_pos]) = x_it.row(); ++access::rw(col_ptrs[x_it.col() + 1]); ++x_it; ++y_it; } else { if((x_it.col() < y_it.col()) || ((x_it.col() == y_it.col()) && (x_it.row() < y_it.row()))) // if y is closer to the end { access::rw(values[cur_pos]) = std::complex((T) *x_it, T(0)); access::rw(row_indices[cur_pos]) = x_it.row(); ++access::rw(col_ptrs[x_it.col() + 1]); ++x_it; } else // x is closer to the end { access::rw(values[cur_pos]) = std::complex(T(0), (T) *y_it); access::rw(row_indices[cur_pos]) = y_it.row(); ++access::rw(col_ptrs[y_it.col() + 1]); ++y_it; } } ++cur_pos; } // Now fix the column pointers; they are supposed to be a sum. for (uword c = 1; c <= n_cols; ++c) { access::rw(col_ptrs[c]) += col_ptrs[c - 1]; } } template inline const SpMat& SpMat::operator/=(const SpMat& x) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise division"); // If you use this method, you are probably stupid or misguided, but for compatibility with Mat, we have implemented it anyway. // We have to loop over every element, which is not good. In fact, it makes me physically sad to write this. for(uword c = 0; c < n_cols; ++c) { for(uword r = 0; r < n_rows; ++r) { at(r, c) /= x.at(r, c); } } return *this; } template template inline SpMat::SpMat(const Base& x) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // extra element is set when mem_resize is called in operator=() , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); (*this).operator=(x); } template template inline const SpMat& SpMat::operator=(const Base& x) { arma_extra_debug_sigprint(); const Proxy p(x.get_ref()); const uword x_n_rows = p.get_n_rows(); const uword x_n_cols = p.get_n_cols(); const uword x_n_elem = p.get_n_elem(); init(x_n_rows, x_n_cols); // Count number of nonzero elements in base object. uword n = 0; if(Proxy::prefer_at_accessor == true) { for(uword j = 0; j < x_n_cols; ++j) for(uword i = 0; i < x_n_rows; ++i) { if(p.at(i, j) != eT(0)) { ++n; } } } else { for(uword i = 0; i < x_n_elem; ++i) { if(p[i] != eT(0)) { ++n; } } } mem_resize(n); // Now the memory is resized correctly; add nonzero elements. n = 0; for(uword j = 0; j < x_n_cols; ++j) for(uword i = 0; i < x_n_rows; ++i) { const eT val = p.at(i, j); if(val != eT(0)) { access::rw(values[n]) = val; access::rw(row_indices[n]) = i; access::rw(col_ptrs[j + 1])++; ++n; } } // Sum column counts to be column pointers. for(uword c = 1; c <= n_cols; ++c) { access::rw(col_ptrs[c]) += col_ptrs[c - 1]; } return *this; } template template inline const SpMat& SpMat::operator*=(const Base& y) { arma_extra_debug_sigprint(); const Proxy p(y.get_ref()); arma_debug_assert_mul_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "matrix multiplication"); // We assume the matrix structure is such that we will end up with a sparse // matrix. Assuming that every entry in the dense matrix is nonzero (which is // a fairly valid assumption), each row with any nonzero elements in it (in this // matrix) implies an entire nonzero column. Therefore, we iterate over all // the row_indices and count the number of rows with any elements in them // (using the quasi-linked-list idea from SYMBMM -- see operator_times.hpp). podarray index(n_rows); index.fill(n_rows); // Fill with invalid links. uword last_index = n_rows + 1; for(uword i = 0; i < n_nonzero; ++i) { if(index[row_indices[i]] == n_rows) { index[row_indices[i]] = last_index; last_index = row_indices[i]; } } // Now count the number of rows which have nonzero elements. uword nonzero_rows = 0; while(last_index != n_rows + 1) { ++nonzero_rows; last_index = index[last_index]; } SpMat z(n_rows, p.get_n_cols()); z.mem_resize(nonzero_rows * p.get_n_cols()); // upper bound on size // Now we have to fill all the elements using a modification of the NUMBMM algorithm. uword cur_pos = 0; podarray partial_sums(n_rows); partial_sums.zeros(); for(uword lcol = 0; lcol < n_cols; ++lcol) { const_iterator it = begin(); while(it != end()) { const eT value = (*it); partial_sums[it.row()] += (value * p.at(it.col(), lcol)); ++it; } // Now add all partial sums to the matrix. for(uword i = 0; i < n_rows; ++i) { if(partial_sums[i] != eT(0)) { access::rw(z.values[cur_pos]) = partial_sums[i]; access::rw(z.row_indices[cur_pos]) = i; ++access::rw(z.col_ptrs[lcol + 1]); //printf("colptr %d now %d\n", lcol + 1, z.col_ptrs[lcol + 1]); ++cur_pos; partial_sums[i] = 0; // Would it be faster to do this in batch later? } } } // Now fix the column pointers. for(uword c = 1; c <= z.n_cols; ++c) { access::rw(z.col_ptrs[c]) += z.col_ptrs[c - 1]; } // Resize to final correct size. z.mem_resize(z.col_ptrs[z.n_cols]); // Now take the memory of the temporary matrix. steal_mem(z); return *this; } /** * Don't use this function. It's not mathematically well-defined and wastes * cycles to trash all your data. This is dumb. */ template template inline const SpMat& SpMat::operator/=(const Base& x) { arma_extra_debug_sigprint(); SpMat tmp = (*this) / x.get_ref(); steal_mem(tmp); return *this; } template template inline const SpMat& SpMat::operator%=(const Base& x) { arma_extra_debug_sigprint(); const Proxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise multiplication"); // Count the number of elements we will need. SpMat tmp(n_rows, n_cols); const_iterator it = begin(); uword new_n_nonzero = 0; while(it != end()) { // prefer_at_accessor == false can't save us any work here if(((*it) * p.at(it.row(), it.col())) != eT(0)) { ++new_n_nonzero; } ++it; } // Resize. tmp.mem_resize(new_n_nonzero); const_iterator c_it = begin(); uword cur_pos = 0; while(c_it != end()) { // prefer_at_accessor == false can't save us any work here const eT val = (*c_it) * p.at(c_it.row(), c_it.col()); if(val != eT(0)) { access::rw(tmp.values[cur_pos]) = val; access::rw(tmp.row_indices[cur_pos]) = c_it.row(); ++access::rw(tmp.col_ptrs[c_it.col() + 1]); ++cur_pos; } ++c_it; } // Fix column pointers. for(uword c = 1; c <= n_cols; ++c) { access::rw(tmp.col_ptrs[c]) += tmp.col_ptrs[c - 1]; } steal_mem(tmp); return *this; } /** * Functions on subviews. */ template inline SpMat::SpMat(const SpSubview& X) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // extra element added when mem_resize is called , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); (*this).operator=(X); } template inline const SpMat& SpMat::operator=(const SpSubview& X) { arma_extra_debug_sigprint(); const uword in_n_cols = X.n_cols; const uword in_n_rows = X.n_rows; const bool alias = (this == &(X.m)); if(alias == false) { init(in_n_rows, in_n_cols); const uword x_n_nonzero = X.n_nonzero; mem_resize(x_n_nonzero); typename SpSubview::const_iterator it = X.begin(); while(it != X.end()) { access::rw(row_indices[it.pos()]) = it.row(); access::rw(values[it.pos()]) = (*it); ++access::rw(col_ptrs[it.col() + 1]); ++it; } // Now sum column pointers. for(uword c = 1; c <= n_cols; ++c) { access::rw(col_ptrs[c]) += col_ptrs[c - 1]; } } else { // Create it in a temporary. SpMat tmp(X); steal_mem(tmp); } return *this; } template inline const SpMat& SpMat::operator+=(const SpSubview& X) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, X.n_rows, X.n_cols, "addition"); typename SpSubview::const_iterator it = X.begin(); while(it != X.end()) { at(it.row(), it.col()) += (*it); ++it; } return *this; } template inline const SpMat& SpMat::operator-=(const SpSubview& X) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, X.n_rows, X.n_cols, "subtraction"); typename SpSubview::const_iterator it = X.begin(); while(it != X.end()) { at(it.row(), it.col()) -= (*it); ++it; } return *this; } template inline const SpMat& SpMat::operator*=(const SpSubview& y) { arma_extra_debug_sigprint(); arma_debug_assert_mul_size(n_rows, n_cols, y.n_rows, y.n_cols, "matrix multiplication"); // Cannot be done in-place (easily). SpMat z = (*this) * y; steal_mem(z); return *this; } template inline const SpMat& SpMat::operator%=(const SpSubview& x) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise multiplication"); iterator it = begin(); typename SpSubview::const_iterator xit = x.begin(); while((it != end()) || (xit != x.end())) { if((xit.row() == it.row()) && (xit.col() == it.col())) { (*it) *= (*xit); ++it; ++xit; } else { if((xit.col() > it.col()) || ((xit.col() == it.col()) && (xit.row() > it.row()))) { // xit is "ahead" (*it) = eT(0); // erase element; x has a zero here it.internal_pos--; // update iterator so it still works ++it; } else { // it is "ahead" ++xit; } } } return *this; } template inline const SpMat& SpMat::operator/=(const SpSubview& x) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise division"); // There is no pretty way to do this. for(uword elem = 0; elem < n_elem; elem++) { at(elem) /= x(elem); } return *this; } /** * Operators on regular subviews. */ template inline SpMat::SpMat(const subview& x) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // extra value set in operator=() , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); (*this).operator=(x); } template inline const SpMat& SpMat::operator=(const subview& x) { arma_extra_debug_sigprint(); const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; // Set the size correctly. init(x_n_rows, x_n_cols); // Count number of nonzero elements. uword n = 0; for(uword c = 0; c < x_n_cols; ++c) { for(uword r = 0; r < x_n_rows; ++r) { if(x.at(r, c) != eT(0)) { ++n; } } } // Resize memory appropriately. mem_resize(n); n = 0; for(uword c = 0; c < x_n_cols; ++c) { for(uword r = 0; r < x_n_rows; ++r) { const eT val = x.at(r, c); if(val != eT(0)) { access::rw(values[n]) = val; access::rw(row_indices[n]) = r; ++access::rw(col_ptrs[c + 1]); ++n; } } } // Fix column counts into column pointers. for(uword c = 1; c <= n_cols; ++c) { access::rw(col_ptrs[c]) += col_ptrs[c - 1]; } return *this; } template inline const SpMat& SpMat::operator+=(const subview& x) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "addition"); // Loop over every element. This could probably be written in a more // efficient way, by calculating the number of nonzero elements the output // matrix will have, allocating the memory correctly, and then filling the // matrix correctly. However... for now, this works okay. for(uword lcol = 0; lcol < n_cols; ++lcol) for(uword lrow = 0; lrow < n_rows; ++lrow) { at(lrow, lcol) += x.at(lrow, lcol); } return *this; } template inline const SpMat& SpMat::operator-=(const subview& x) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "subtraction"); // Loop over every element. for(uword lcol = 0; lcol < n_cols; ++lcol) for(uword lrow = 0; lrow < n_rows; ++lrow) { at(lrow, lcol) -= x.at(lrow, lcol); } return *this; } template inline const SpMat& SpMat::operator*=(const subview& y) { arma_extra_debug_sigprint(); arma_debug_assert_mul_size(n_rows, n_cols, y.n_rows, y.n_cols, "matrix multiplication"); SpMat z(n_rows, y.n_cols); // Performed in the same fashion as operator*=(SpMat). for (const_row_iterator x_row_it = begin_row(); x_row_it.pos() < n_nonzero; ++x_row_it) { for (uword lcol = 0; lcol < y.n_cols; ++lcol) { // At this moment in the loop, we are calculating anything that is contributed to by *x_row_it and *y_col_it. // Given that our position is x_ab and y_bc, there will only be a contribution if x.col == y.row, and that // contribution will be in location z_ac. z.at(x_row_it.row, lcol) += (*x_row_it) * y.at(x_row_it.col, lcol); } } steal_mem(z); return *this; } template inline const SpMat& SpMat::operator%=(const subview& x) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise multiplication"); // Loop over every element. for(uword lcol = 0; lcol < n_cols; ++lcol) for(uword lrow = 0; lrow < n_rows; ++lrow) { at(lrow, lcol) *= x.at(lrow, lcol); } return *this; } template inline const SpMat& SpMat::operator/=(const subview& x) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise division"); // Loop over every element. for(uword lcol = 0; lcol < n_cols; ++lcol) for(uword lrow = 0; lrow < n_rows; ++lrow) { at(lrow, lcol) /= x.at(lrow, lcol); } return *this; } template template inline SpMat::SpMat(const SpOp& X) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // set in application of sparse operation , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); spop_type::apply(*this, X); } template template inline const SpMat& SpMat::operator=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); spop_type::apply(*this, X); return *this; } template template inline const SpMat& SpMat::operator+=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator+=(m); } template template inline const SpMat& SpMat::operator-=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator-=(m); } template template inline const SpMat& SpMat::operator*=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator*=(m); } template template inline const SpMat& SpMat::operator%=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator%=(m); } template template inline const SpMat& SpMat::operator/=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator/=(m); } template template inline SpMat::SpMat(const SpGlue& X) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // extra element set in application of sparse glue , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); spglue_type::apply(*this, X); } template template inline SpMat::SpMat(const mtSpOp& X) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // extra element set in application of sparse glue , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); spop_type::apply(*this, X); } template template inline const SpMat& SpMat::operator=(const mtSpOp& X) { arma_extra_debug_sigprint(); spop_type::apply(*this, X); return *this; } template template inline const SpMat& SpMat::operator+=(const mtSpOp& X) { arma_extra_debug_sigprint(); const SpMat m(X); return (*this).operator+=(m); } template template inline const SpMat& SpMat::operator-=(const mtSpOp& X) { arma_extra_debug_sigprint(); const SpMat m(X); return (*this).operator-=(m); } template template inline const SpMat& SpMat::operator*=(const mtSpOp& X) { arma_extra_debug_sigprint(); const SpMat m(X); return (*this).operator*=(m); } template template inline const SpMat& SpMat::operator%=(const mtSpOp& X) { arma_extra_debug_sigprint(); const SpMat m(X); return (*this).operator%=(m); } template template inline const SpMat& SpMat::operator/=(const mtSpOp& X) { arma_extra_debug_sigprint(); const SpMat m(X); return (*this).operator/=(m); } template template inline const SpMat& SpMat::operator=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); spglue_type::apply(*this, X); return *this; } template template inline const SpMat& SpMat::operator+=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator+=(m); } template template inline const SpMat& SpMat::operator-=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator-=(m); } template template inline const SpMat& SpMat::operator*=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator*=(m); } template template inline const SpMat& SpMat::operator%=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator%=(m); } template template inline const SpMat& SpMat::operator/=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator/=(m); } template arma_inline SpSubview SpMat::row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check(row_num >= n_rows, "SpMat::row(): out of bounds"); return SpSubview(*this, row_num, 0, 1, n_cols); } template arma_inline const SpSubview SpMat::row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check(row_num >= n_rows, "SpMat::row(): out of bounds"); return SpSubview(*this, row_num, 0, 1, n_cols); } template inline SpSubview SpMat::operator()(const uword row_num, const span& col_span) { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "SpMat::operator(): indices out of bounds or incorrectly used" ); return SpSubview(*this, row_num, in_col1, 1, submat_n_cols); } template inline const SpSubview SpMat::operator()(const uword row_num, const span& col_span) const { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "SpMat::operator(): indices out of bounds or incorrectly used" ); return SpSubview(*this, row_num, in_col1, 1, submat_n_cols); } template arma_inline SpSubview SpMat::col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check(col_num >= n_cols, "SpMat::col(): out of bounds"); return SpSubview(*this, 0, col_num, n_rows, 1); } template arma_inline const SpSubview SpMat::col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check(col_num >= n_cols, "SpMat::col(): out of bounds"); return SpSubview(*this, 0, col_num, n_rows, 1); } template inline SpSubview SpMat::operator()(const span& row_span, const uword col_num) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "SpMat::operator(): indices out of bounds or incorrectly used" ); return SpSubview(*this, in_row1, col_num, submat_n_rows, 1); } template inline const SpSubview SpMat::operator()(const span& row_span, const uword col_num) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "SpMat::operator(): indices out of bounds or incorrectly used" ); return SpSubview(*this, in_row1, col_num, submat_n_rows, 1); } /** * Swap in_row1 with in_row2. */ template inline void SpMat::swap_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 >= n_rows) || (in_row2 >= n_rows), "SpMat::swap_rows(): out of bounds" ); // Sanity check. if (in_row1 == in_row2) { return; } // The easier way to do this, instead of collecting all the elements in one row and then swapping with the other, will be // to iterate over each column of the matrix (since we store in column-major format) and then swap the two elements in the two rows at that time. // We will try to avoid using the at() call since it is expensive, instead preferring to use an iterator to track our position. uword col1 = (in_row1 < in_row2) ? in_row1 : in_row2; uword col2 = (in_row1 < in_row2) ? in_row2 : in_row1; for (uword lcol = 0; lcol < n_cols; lcol++) { // If there is nothing in this column we can ignore it. if (col_ptrs[lcol] == col_ptrs[lcol + 1]) { continue; } // These will represent the positions of the items themselves. uword loc1 = n_nonzero + 1; uword loc2 = n_nonzero + 1; for (uword search_pos = col_ptrs[lcol]; search_pos < col_ptrs[lcol + 1]; search_pos++) { if (row_indices[search_pos] == col1) { loc1 = search_pos; } if (row_indices[search_pos] == col2) { loc2 = search_pos; break; // No need to look any further. } } // There are four cases: we found both elements; we found one element (loc1); we found one element (loc2); we found zero elements. // If we found zero elements no work needs to be done and we can continue to the next column. if ((loc1 != (n_nonzero + 1)) && (loc2 != (n_nonzero + 1))) { // This is an easy case: just swap the values. No index modifying necessary. eT tmp = values[loc1]; access::rw(values[loc1]) = values[loc2]; access::rw(values[loc2]) = tmp; } else if (loc1 != (n_nonzero + 1)) // We only found loc1 and not loc2. { // We need to find the correct place to move our value to. It will be forward (not backwards) because in_row2 > in_row1. // Each iteration of the loop swaps the current value (loc1) with (loc1 + 1); in this manner we move our value down to where it should be. while (((loc1 + 1) < col_ptrs[lcol + 1]) && (row_indices[loc1 + 1] < in_row2)) { // Swap both the values and the indices. The column should not change. eT tmp = values[loc1]; access::rw(values[loc1]) = values[loc1 + 1]; access::rw(values[loc1 + 1]) = tmp; uword tmp_index = row_indices[loc1]; access::rw(row_indices[loc1]) = row_indices[loc1 + 1]; access::rw(row_indices[loc1 + 1]) = tmp_index; loc1++; // And increment the counter. } // Now set the row index correctly. access::rw(row_indices[loc1]) = in_row2; } else if (loc2 != (n_nonzero + 1)) { // We need to find the correct place to move our value to. It will be backwards (not forwards) because in_row1 < in_row2. // Each iteration of the loop swaps the current value (loc2) with (loc2 - 1); in this manner we move our value up to where it should be. while (((loc2 - 1) >= col_ptrs[lcol]) && (row_indices[loc2 - 1] > in_row1)) { // Swap both the values and the indices. The column should not change. eT tmp = values[loc2]; access::rw(values[loc2]) = values[loc2 - 1]; access::rw(values[loc2 - 1]) = tmp; uword tmp_index = row_indices[loc2]; access::rw(row_indices[loc2]) = row_indices[loc2 - 1]; access::rw(row_indices[loc2 - 1]) = tmp_index; loc2--; // And decrement the counter. } // Now set the row index correctly. access::rw(row_indices[loc2]) = in_row1; } /* else: no need to swap anything; both values are zero */ } } /** * Swap in_col1 with in_col2. */ template inline void SpMat::swap_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); // slow but works for(uword lrow = 0; lrow < n_rows; ++lrow) { eT tmp = at(lrow, in_col1); at(lrow, in_col1) = at(lrow, in_col2); at(lrow, in_col2) = tmp; } } /** * Remove the row row_num. */ template inline void SpMat::shed_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check (row_num >= n_rows, "SpMat::shed_row(): out of bounds"); shed_rows (row_num, row_num); } /** * Remove the column col_num. */ template inline void SpMat::shed_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check (col_num >= n_cols, "SpMat::shed_col(): out of bounds"); shed_cols(col_num, col_num); } /** * Remove all rows between (and including) in_row1 and in_row2. */ template inline void SpMat::shed_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "SpMat::shed_rows(): indices out of bounds or incorectly used" ); uword i, j; // Store the length of values uword vlength = n_nonzero; // Store the length of col_ptrs uword clength = n_cols + 1; // This is O(n * n_cols) and inplace, there may be a faster way, though. for (i = 0, j = 0; i < vlength; ++i) { // Store the row of the ith element. const uword lrow = row_indices[i]; // Is the ith element in the range of rows we want to remove? if (lrow >= in_row1 && lrow <= in_row2) { // Increment our "removed elements" counter. ++j; // Adjust the values of col_ptrs each time we remove an element. // Basically, the length of one column reduces by one, and everything to // its right gets reduced by one to represent all the elements being // shifted to the left by one. for(uword k = 0; k < clength; ++k) { if (col_ptrs[k] > (i - j + 1)) { --access::rw(col_ptrs[k]); } } } else { // We shift the element we checked to the left by how many elements // we have removed. // j = 0 until we remove the first element. if (j != 0) { access::rw(row_indices[i - j]) = (lrow > in_row2) ? (lrow - (in_row2 - in_row1 + 1)) : lrow; access::rw(values[i - j]) = values[i]; } } } // j is the number of elements removed. // Shrink the vectors. This will copy the memory. mem_resize(n_nonzero - j); // Adjust row and element counts. access::rw(n_rows) = n_rows - (in_row2 - in_row1) - 1; access::rw(n_elem) = n_rows * n_cols; } /** * Remove all columns between (and including) in_col1 and in_col2. */ template inline void SpMat::shed_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "SpMat::shed_cols(): indices out of bounds or incorrectly used" ); // First we find the locations in values and row_indices for the column entries. uword col_beg = col_ptrs[in_col1]; uword col_end = col_ptrs[in_col2 + 1]; // Then we find the number of entries in the column. uword diff = col_end - col_beg; if (diff > 0) { eT* new_values = memory::acquire_chunked (n_nonzero - diff); uword* new_row_indices = memory::acquire_chunked(n_nonzero - diff); // Copy first part. if (col_beg != 0) { arrayops::copy(new_values, values, col_beg); arrayops::copy(new_row_indices, row_indices, col_beg); } // Copy second part. if (col_end != n_nonzero) { arrayops::copy(new_values + col_beg, values + col_end, n_nonzero - col_end); arrayops::copy(new_row_indices + col_beg, row_indices + col_end, n_nonzero - col_end); } memory::release(values); memory::release(row_indices); access::rw(values) = new_values; access::rw(row_indices) = new_row_indices; // Update counts and such. access::rw(n_nonzero) -= diff; } // Update column pointers. const uword new_n_cols = n_cols - ((in_col2 - in_col1) + 1); uword* new_col_ptrs = memory::acquire(new_n_cols + 2); new_col_ptrs[new_n_cols + 1] = std::numeric_limits::max(); // Copy first set of columns (no manipulation required). if (in_col1 != 0) { arrayops::copy(new_col_ptrs, col_ptrs, in_col1); } // Copy second set of columns (manipulation required). uword cur_col = in_col1; for (uword i = in_col2 + 1; i <= n_cols; ++i, ++cur_col) { new_col_ptrs[cur_col] = col_ptrs[i] - diff; } memory::release(col_ptrs); access::rw(col_ptrs) = new_col_ptrs; // We update the element and column counts, and we're done. access::rw(n_cols) = new_n_cols; access::rw(n_elem) = n_cols * n_rows; } template arma_inline SpSubview SpMat::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "SpMat::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; return SpSubview(*this, in_row1, 0, subview_n_rows, n_cols); } template arma_inline const SpSubview SpMat::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "SpMat::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; return SpSubview(*this, in_row1, 0, subview_n_rows, n_cols); } template arma_inline SpSubview SpMat::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "SpMat::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; return SpSubview(*this, 0, in_col1, n_rows, subview_n_cols); } template arma_inline const SpSubview SpMat::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "SpMat::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; return SpSubview(*this, 0, in_col1, n_rows, subview_n_cols); } template arma_inline SpSubview SpMat::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "SpMat::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; return SpSubview(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); } template arma_inline const SpSubview SpMat::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "SpMat::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; return SpSubview(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); } template arma_inline SpSubview SpMat::submat(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "SpMat::submat(): indices or size out of bounds" ); return SpSubview(*this, in_row1, in_col1, s_n_rows, s_n_cols); } template arma_inline const SpSubview SpMat::submat(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "SpMat::submat(): indices or size out of bounds" ); return SpSubview(*this, in_row1, in_col1, s_n_rows, s_n_cols); } template inline SpSubview SpMat::submat(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "SpMat::submat(): indices out of bounds or incorrectly used" ); return SpSubview(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); } template inline const SpSubview SpMat::submat(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "SpMat::submat(): indices out of bounds or incorrectly used" ); return SpSubview(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); } template inline SpSubview SpMat::operator()(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); return submat(row_span, col_span); } template inline const SpSubview SpMat::operator()(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); return submat(row_span, col_span); } template arma_inline SpSubview SpMat::operator()(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).submat(in_row1, in_col1, s); } template arma_inline const SpSubview SpMat::operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); return (*this).submat(in_row1, in_col1, s); } /** * Element access; acces the i'th element (works identically to the Mat accessors). * If there is nothing at element i, 0 is returned. * * @param i Element to access. */ template arma_inline arma_warn_unused SpValProxy > SpMat::operator[](const uword i) { return get_value(i); } template arma_inline arma_warn_unused eT SpMat::operator[](const uword i) const { return get_value(i); } template arma_inline arma_warn_unused SpValProxy > SpMat::at(const uword i) { return get_value(i); } template arma_inline arma_warn_unused eT SpMat::at(const uword i) const { return get_value(i); } template arma_inline arma_warn_unused SpValProxy > SpMat::operator()(const uword i) { arma_debug_check( (i >= n_elem), "SpMat::operator(): out of bounds"); return get_value(i); } template arma_inline arma_warn_unused eT SpMat::operator()(const uword i) const { arma_debug_check( (i >= n_elem), "SpMat::operator(): out of bounds"); return get_value(i); } /** * Element access; access the element at row in_rows and column in_col. * If there is nothing at that position, 0 is returned. */ template arma_inline arma_warn_unused SpValProxy > SpMat::at(const uword in_row, const uword in_col) { return get_value(in_row, in_col); } template arma_inline arma_warn_unused eT SpMat::at(const uword in_row, const uword in_col) const { return get_value(in_row, in_col); } template arma_inline arma_warn_unused SpValProxy > SpMat::operator()(const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "SpMat::operator(): out of bounds"); return get_value(in_row, in_col); } template arma_inline arma_warn_unused eT SpMat::operator()(const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "SpMat::operator(): out of bounds"); return get_value(in_row, in_col); } /** * Check if matrix is empty (no size, no values). */ template arma_inline arma_warn_unused bool SpMat::is_empty() const { return(n_elem == 0); } //! returns true if the object can be interpreted as a column or row vector template arma_inline arma_warn_unused bool SpMat::is_vec() const { return ( (n_rows == 1) || (n_cols == 1) ); } //! returns true if the object can be interpreted as a row vector template arma_inline arma_warn_unused bool SpMat::is_rowvec() const { return (n_rows == 1); } //! returns true if the object can be interpreted as a column vector template arma_inline arma_warn_unused bool SpMat::is_colvec() const { return (n_cols == 1); } //! returns true if the object has the same number of non-zero rows and columnns template arma_inline arma_warn_unused bool SpMat::is_square() const { return (n_rows == n_cols); } //! returns true if all of the elements are finite template inline arma_warn_unused bool SpMat::is_finite() const { for(uword i = 0; i < n_nonzero; i++) { if(arma_isfinite(values[i]) == false) { return false; } } return true; // No infinite values. } //! returns true if the given index is currently in range template arma_inline arma_warn_unused bool SpMat::in_range(const uword i) const { return (i < n_elem); } //! returns true if the given start and end indices are currently in range template arma_inline arma_warn_unused bool SpMat::in_range(const span& x) const { arma_extra_debug_sigprint(); if(x.whole == true) { return true; } else { const uword a = x.a; const uword b = x.b; return ( (a <= b) && (b < n_elem) ); } } //! returns true if the given location is currently in range template arma_inline arma_warn_unused bool SpMat::in_range(const uword in_row, const uword in_col) const { return ( (in_row < n_rows) && (in_col < n_cols) ); } template arma_inline arma_warn_unused bool SpMat::in_range(const span& row_span, const uword in_col) const { arma_extra_debug_sigprint(); if(row_span.whole == true) { return (in_col < n_cols); } else { const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) ); } } template arma_inline arma_warn_unused bool SpMat::in_range(const uword in_row, const span& col_span) const { arma_extra_debug_sigprint(); if(col_span.whole == true) { return (in_row < n_rows); } else { const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) ); } } template arma_inline arma_warn_unused bool SpMat::in_range(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) ); const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) ); return ( (rows_ok == true) && (cols_ok == true) ); } template arma_inline arma_warn_unused bool SpMat::in_range(const uword in_row, const uword in_col, const SizeMat& s) const { const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; if( (in_row >= l_n_rows) || (in_col >= l_n_cols) || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) ) { return false; } else { return true; } } template inline void SpMat::impl_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, true); } template inline void SpMat::impl_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print(user_stream, *this, true); } template inline void SpMat::impl_raw_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, false); } template inline void SpMat::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print(user_stream, *this, false); } /** * Matrix printing, prepends supplied text. * Prints 0 wherever no element exists. */ template inline void SpMat::impl_print_dense(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print_dense(ARMA_DEFAULT_OSTREAM, *this, true); } template inline void SpMat::impl_print_dense(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print_dense(user_stream, *this, true); } template inline void SpMat::impl_raw_print_dense(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print_dense(ARMA_DEFAULT_OSTREAM, *this, false); } template inline void SpMat::impl_raw_print_dense(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print_dense(user_stream, *this, false); } //! Set the size to the size of another matrix. template template inline void SpMat::copy_size(const SpMat& m) { arma_extra_debug_sigprint(); init(m.n_rows, m.n_cols); } template template inline void SpMat::copy_size(const Mat& m) { arma_extra_debug_sigprint(); init(m.n_rows, m.n_cols); } /** * Set the size of the matrix; the matrix will be sized as a column vector * * @param in_elem Number of elements to allow. */ template inline void SpMat::set_size(const uword in_elem) { arma_extra_debug_sigprint(); // If this is a row vector, we resize to a row vector. if(vec_state == 2) { init(1, in_elem); } else { init(in_elem, 1); } } /** * Set the size of the matrix * * @param in_rows Number of rows to allow. * @param in_cols Number of columns to allow. */ template inline void SpMat::set_size(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); init(in_rows, in_cols); } template inline void SpMat::reshape(const uword in_rows, const uword in_cols, const uword dim) { arma_extra_debug_sigprint(); if (dim == 0) { // We have to modify all of the relevant row indices and the relevant column pointers. // Iterate over all the points to do this. We won't be deleting any points, but we will be modifying // columns and rows. We'll have to store a new set of column vectors. uword* new_col_ptrs = memory::acquire(in_cols + 2); new_col_ptrs[in_cols + 1] = std::numeric_limits::max(); uword* new_row_indices = memory::acquire_chunked(n_nonzero + 1); access::rw(new_row_indices[n_nonzero]) = 0; arrayops::inplace_set(new_col_ptrs, uword(0), in_cols + 1); for(const_iterator it = begin(); it != end(); it++) { uword vector_position = (it.col() * n_rows) + it.row(); new_row_indices[it.pos()] = vector_position % in_rows; ++new_col_ptrs[vector_position / in_rows + 1]; } // Now sum the column counts to get the new column pointers. for(uword i = 1; i <= in_cols; i++) { access::rw(new_col_ptrs[i]) += new_col_ptrs[i - 1]; } // Copy the new row indices. memory::release(row_indices); access::rw(row_indices) = new_row_indices; memory::release(col_ptrs); access::rw(col_ptrs) = new_col_ptrs; // Now set the size. access::rw(n_rows) = in_rows; access::rw(n_cols) = in_cols; } else { // Row-wise reshaping. This is more tedious and we will use a separate sparse matrix to do it. SpMat tmp(in_rows, in_cols); for(const_row_iterator it = begin_row(); it.pos() < n_nonzero; it++) { uword vector_position = (it.row() * n_cols) + it.col(); tmp((vector_position / in_cols), (vector_position % in_cols)) = (*it); } (*this).operator=(tmp); } } template inline const SpMat& SpMat::zeros() { arma_extra_debug_sigprint(); if (n_nonzero > 0) { memory::release(values); memory::release(row_indices); access::rw(values) = memory::acquire_chunked(1); access::rw(row_indices) = memory::acquire_chunked(1); access::rw(values[0]) = 0; access::rw(row_indices[0]) = 0; } access::rw(n_nonzero) = 0; arrayops::inplace_set(access::rwp(col_ptrs), uword(0), n_cols + 1); return *this; } template inline const SpMat& SpMat::zeros(const uword in_elem) { arma_extra_debug_sigprint(); if(vec_state == 2) { init(1, in_elem); // Row vector } else { init(in_elem, 1); } return *this; } template inline const SpMat& SpMat::zeros(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); init(in_rows, in_cols); return *this; } template inline const SpMat& SpMat::eye() { arma_extra_debug_sigprint(); return (*this).eye(n_rows, n_cols); } template inline const SpMat& SpMat::eye(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); const uword N = (std::min)(in_rows, in_cols); init(in_rows, in_cols); mem_resize(N); arrayops::inplace_set(access::rwp(values), eT(1), N); for(uword i = 0; i < N; ++i) { access::rw(row_indices[i]) = i; } for(uword i = 0; i <= N; ++i) { access::rw(col_ptrs[i]) = i; } access::rw(n_nonzero) = N; return *this; } template inline const SpMat& SpMat::speye() { arma_extra_debug_sigprint(); return (*this).eye(n_rows, n_cols); } template inline const SpMat& SpMat::speye(const uword in_n_rows, const uword in_n_cols) { arma_extra_debug_sigprint(); return (*this).eye(in_n_rows, in_n_cols); } template inline const SpMat& SpMat::sprandu(const uword in_rows, const uword in_cols, const double density) { arma_extra_debug_sigprint(); arma_debug_check( ( (density < double(0)) || (density > double(1)) ), "sprandu(): density must be in the [0,1] interval" ); zeros(in_rows, in_cols); mem_resize( uword(density * double(in_rows) * double(in_cols) + 0.5) ); if(n_nonzero == 0) { return *this; } arma_rng::randu::fill( access::rwp(values), n_nonzero ); uvec indices = linspace( 0u, in_rows*in_cols-1, n_nonzero ); // perturb the indices for(uword i=1; i < n_nonzero-1; ++i) { const uword index_left = indices[i-1]; const uword index_right = indices[i+1]; const uword center = (index_left + index_right) / 2; const uword delta1 = center - index_left - 1; const uword delta2 = index_right - center - 1; const uword min_delta = (std::min)(delta1, delta2); uword index_new = uword( double(center) + double(min_delta) * (2.0*randu()-1.0) ); // paranoia, but better be safe than sorry if( (index_left < index_new) && (index_new < index_right) ) { indices[i] = index_new; } } uword cur_index = 0; uword count = 0; for(uword lcol = 0; lcol < in_cols; ++lcol) for(uword lrow = 0; lrow < in_rows; ++lrow) { if(count == indices[cur_index]) { access::rw(row_indices[cur_index]) = lrow; access::rw(col_ptrs[lcol + 1])++; ++cur_index; } ++count; } if(cur_index != n_nonzero) { // Fix size to correct size. mem_resize(cur_index); } // Sum column pointers. for(uword lcol = 1; lcol <= in_cols; ++lcol) { access::rw(col_ptrs[lcol]) += col_ptrs[lcol - 1]; } return *this; } template inline const SpMat& SpMat::sprandn(const uword in_rows, const uword in_cols, const double density) { arma_extra_debug_sigprint(); arma_debug_check( ( (density < double(0)) || (density > double(1)) ), "sprandn(): density must be in the [0,1] interval" ); zeros(in_rows, in_cols); mem_resize( uword(density * double(in_rows) * double(in_cols) + 0.5) ); if(n_nonzero == 0) { return *this; } arma_rng::randn::fill( access::rwp(values), n_nonzero ); uvec indices = linspace( 0u, in_rows*in_cols-1, n_nonzero ); // perturb the indices for(uword i=1; i < n_nonzero-1; ++i) { const uword index_left = indices[i-1]; const uword index_right = indices[i+1]; const uword center = (index_left + index_right) / 2; const uword delta1 = center - index_left - 1; const uword delta2 = index_right - center - 1; const uword min_delta = (std::min)(delta1, delta2); uword index_new = uword( double(center) + double(min_delta) * (2.0*randu()-1.0) ); // paranoia, but better be safe than sorry if( (index_left < index_new) && (index_new < index_right) ) { indices[i] = index_new; } } uword cur_index = 0; uword count = 0; for(uword lcol = 0; lcol < in_cols; ++lcol) for(uword lrow = 0; lrow < in_rows; ++lrow) { if(count == indices[cur_index]) { access::rw(row_indices[cur_index]) = lrow; access::rw(col_ptrs[lcol + 1])++; ++cur_index; } ++count; } if(cur_index != n_nonzero) { // Fix size to correct size. mem_resize(cur_index); } // Sum column pointers. for(uword lcol = 1; lcol <= in_cols; ++lcol) { access::rw(col_ptrs[lcol]) += col_ptrs[lcol - 1]; } return *this; } template inline void SpMat::reset() { arma_extra_debug_sigprint(); switch(vec_state) { default: init(0, 0); break; case 1: init(0, 1); break; case 2: init(1, 0); break; } } /** * Get the minimum or the maximum of the matrix. */ template inline arma_warn_unused eT SpMat::min() const { arma_extra_debug_sigprint(); arma_debug_check((n_elem == 0), "min(): object has no elements"); if (n_nonzero == 0) { return 0; } eT val = op_min::direct_min(values, n_nonzero); if ((val > 0) && (n_nonzero < n_elem)) // A sparse 0 is less. { val = 0; } return val; } template inline eT SpMat::min(uword& index_of_min_val) const { arma_extra_debug_sigprint(); arma_debug_check((n_elem == 0), "min(): object has no elements"); eT val = 0; if (n_nonzero == 0) // There are no other elements. It must be 0. { index_of_min_val = 0; } else { uword location; val = op_min::direct_min(values, n_nonzero, location); if ((val > 0) && (n_nonzero < n_elem)) // A sparse 0 is less. { val = 0; // Give back the index to the first zero position. index_of_min_val = 0; while (get_position(index_of_min_val) == index_of_min_val) // An element exists at that position. { index_of_min_val++; } } else { index_of_min_val = get_position(location); } } return val; } template inline eT SpMat::min(uword& row_of_min_val, uword& col_of_min_val) const { arma_extra_debug_sigprint(); arma_debug_check((n_elem == 0), "min(): object has no elements"); eT val = 0; if (n_nonzero == 0) // There are no other elements. It must be 0. { row_of_min_val = 0; col_of_min_val = 0; } else { uword location; val = op_min::direct_min(values, n_nonzero, location); if ((val > 0) && (n_nonzero < n_elem)) // A sparse 0 is less. { val = 0; location = 0; while (get_position(location) == location) // An element exists at that position. { location++; } row_of_min_val = location % n_rows; col_of_min_val = location / n_rows; } else { get_position(location, row_of_min_val, col_of_min_val); } } return val; } template inline arma_warn_unused eT SpMat::max() const { arma_extra_debug_sigprint(); arma_debug_check((n_elem == 0), "max(): object has no elements"); if (n_nonzero == 0) { return 0; } eT val = op_max::direct_max(values, n_nonzero); if ((val < 0) && (n_nonzero < n_elem)) // A sparse 0 is more. { return 0; } return val; } template inline eT SpMat::max(uword& index_of_max_val) const { arma_extra_debug_sigprint(); arma_debug_check((n_elem == 0), "max(): object has no elements"); eT val = 0; if (n_nonzero == 0) { index_of_max_val = 0; } else { uword location; val = op_max::direct_max(values, n_nonzero, location); if ((val < 0) && (n_nonzero < n_elem)) // A sparse 0 is more. { val = 0; location = 0; while (get_position(location) == location) // An element exists at that position. { location++; } } else { index_of_max_val = get_position(location); } } return val; } template inline eT SpMat::max(uword& row_of_max_val, uword& col_of_max_val) const { arma_extra_debug_sigprint(); arma_debug_check((n_elem == 0), "max(): object has no elements"); eT val = 0; if (n_nonzero == 0) { row_of_max_val = 0; col_of_max_val = 0; } else { uword location; val = op_max::direct_max(values, n_nonzero, location); if ((val < 0) && (n_nonzero < n_elem)) // A sparse 0 is more. { val = 0; location = 0; while (get_position(location) == location) // An element exists at that position. { location++; } row_of_max_val = location % n_rows; col_of_max_val = location / n_rows; } else { get_position(location, row_of_max_val, col_of_max_val); } } return val; } //! save the matrix to a file template inline bool SpMat::save(const std::string name, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { // case raw_ascii: // save_okay = diskio::save_raw_ascii(*this, name); // break; // case csv_ascii: // save_okay = diskio::save_csv_ascii(*this, name); // break; case arma_binary: save_okay = diskio::save_arma_binary(*this, name); break; case coord_ascii: save_okay = diskio::save_coord_ascii(*this, name); break; default: arma_warn(true, "SpMat::save(): unsupported file type"); save_okay = false; } arma_warn( (save_okay == false), "SpMat::save(): couldn't write to ", name); return save_okay; } //! save the matrix to a stream template inline bool SpMat::save(std::ostream& os, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { // case raw_ascii: // save_okay = diskio::save_raw_ascii(*this, os); // break; // case csv_ascii: // save_okay = diskio::save_csv_ascii(*this, os); // break; case arma_binary: save_okay = diskio::save_arma_binary(*this, os); break; case coord_ascii: save_okay = diskio::save_coord_ascii(*this, os); break; default: arma_warn(true, "SpMat::save(): unsupported file type"); save_okay = false; } arma_warn( (save_okay == false), "SpMat::save(): couldn't write to the given stream"); return save_okay; } //! load a matrix from a file template inline bool SpMat::load(const std::string name, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { // case auto_detect: // load_okay = diskio::load_auto_detect(*this, name, err_msg); // break; // case raw_ascii: // load_okay = diskio::load_raw_ascii(*this, name, err_msg); // break; // case csv_ascii: // load_okay = diskio::load_csv_ascii(*this, name, err_msg); // break; case arma_binary: load_okay = diskio::load_arma_binary(*this, name, err_msg); break; case coord_ascii: load_okay = diskio::load_coord_ascii(*this, name, err_msg); break; default: arma_warn(true, "SpMat::load(): unsupported file type"); load_okay = false; } if(load_okay == false) { if(err_msg.length() > 0) { arma_warn(true, "SpMat::load(): ", err_msg, name); } else { arma_warn(true, "SpMat::load(): couldn't read ", name); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! load a matrix from a stream template inline bool SpMat::load(std::istream& is, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { // case auto_detect: // load_okay = diskio::load_auto_detect(*this, is, err_msg); // break; // case raw_ascii: // load_okay = diskio::load_raw_ascii(*this, is, err_msg); // break; // case csv_ascii: // load_okay = diskio::load_csv_ascii(*this, is, err_msg); // break; case arma_binary: load_okay = diskio::load_arma_binary(*this, is, err_msg); break; case coord_ascii: load_okay = diskio::load_coord_ascii(*this, is, err_msg); break; default: arma_warn(true, "SpMat::load(): unsupported file type"); load_okay = false; } if(load_okay == false) { if(err_msg.length() > 0) { arma_warn(true, "SpMat::load(): ", err_msg, "the given stream"); } else { arma_warn(true, "SpMat::load(): couldn't load from the given stream"); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! save the matrix to a file, without printing any error messages template inline bool SpMat::quiet_save(const std::string name, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(name, type, false); } //! save the matrix to a stream, without printing any error messages template inline bool SpMat::quiet_save(std::ostream& os, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(os, type, false); } //! load a matrix from a file, without printing any error messages template inline bool SpMat::quiet_load(const std::string name, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(name, type, false); } //! load a matrix from a stream, without printing any error messages template inline bool SpMat::quiet_load(std::istream& is, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(is, type, false); } /** * Initialize the matrix to the specified size. Data is not preserved, so the matrix is assumed to be entirely sparse (empty). */ template inline void SpMat::init(uword in_rows, uword in_cols) { arma_extra_debug_sigprint(); // Verify that we are allowed to do this. if(vec_state > 0) { if((in_rows == 0) && (in_cols == 0)) { if(vec_state == 1) { in_cols = 1; } else if(vec_state == 2) { in_rows = 1; } } else { arma_debug_check ( ( ((vec_state == 1) && (in_cols != 1)) || ((vec_state == 2) && (in_rows != 1)) ), "SpMat::init(): object is a row or column vector; requested size is not compatible" ); } } // Ensure that n_elem can hold the result of (n_rows * n_cols) arma_debug_check ( ( ( (in_rows > ARMA_MAX_UHWORD) || (in_cols > ARMA_MAX_UHWORD) ) ? ( (float(in_rows) * float(in_cols)) > float(ARMA_MAX_UWORD) ) : false ), "SpMat::init(): requested size is too large; suggest to enable ARMA_64BIT_WORD" ); // Clean out the existing memory. if (values) { memory::release(values); memory::release(row_indices); } access::rw(values) = memory::acquire_chunked (1); access::rw(row_indices) = memory::acquire_chunked(1); access::rw(values[0]) = 0; access::rw(row_indices[0]) = 0; memory::release(col_ptrs); // Set the new size accordingly. access::rw(n_rows) = in_rows; access::rw(n_cols) = in_cols; access::rw(n_elem) = (in_rows * in_cols); access::rw(n_nonzero) = 0; // Try to allocate the column pointers, filling them with 0, // except for the last element which contains the maximum possible element // (so iterators terminate correctly). access::rw(col_ptrs) = memory::acquire(in_cols + 2); arrayops::inplace_set(access::rwp(col_ptrs), uword(0), in_cols + 1); access::rw(col_ptrs[in_cols + 1]) = std::numeric_limits::max(); } /** * Initialize the matrix from a string. */ template inline void SpMat::init(const std::string& text) { arma_extra_debug_sigprint(); // Figure out the size first. uword t_n_rows = 0; uword t_n_cols = 0; bool t_n_cols_found = false; std::string token; std::string::size_type line_start = 0; std::string::size_type line_end = 0; while (line_start < text.length()) { line_end = text.find(';', line_start); if (line_end == std::string::npos) line_end = text.length() - 1; std::string::size_type line_len = line_end - line_start + 1; std::stringstream line_stream(text.substr(line_start, line_len)); // Step through each column. uword line_n_cols = 0; while (line_stream >> token) { ++line_n_cols; } if (line_n_cols > 0) { if (t_n_cols_found == false) { t_n_cols = line_n_cols; t_n_cols_found = true; } else // Check it each time through, just to make sure. arma_check((line_n_cols != t_n_cols), "SpMat::init(): inconsistent number of columns in given string"); ++t_n_rows; } line_start = line_end + 1; } set_size(t_n_rows, t_n_cols); // Second time through will pick up all the values. line_start = 0; line_end = 0; uword lrow = 0; while (line_start < text.length()) { line_end = text.find(';', line_start); if (line_end == std::string::npos) line_end = text.length() - 1; std::string::size_type line_len = line_end - line_start + 1; std::stringstream line_stream(text.substr(line_start, line_len)); uword lcol = 0; eT val; while (line_stream >> val) { // Only add nonzero elements. if (val != eT(0)) { get_value(lrow, lcol) = val; } ++lcol; } ++lrow; line_start = line_end + 1; } } /** * Copy from another matrix. */ template inline void SpMat::init(const SpMat& x) { arma_extra_debug_sigprint(); // Ensure we are not initializing to ourselves. if (this != &x) { init(x.n_rows, x.n_cols); // values and row_indices may not be null. if (values != NULL) { memory::release(values); memory::release(row_indices); } access::rw(values) = memory::acquire_chunked (x.n_nonzero + 1); access::rw(row_indices) = memory::acquire_chunked(x.n_nonzero + 1); // Now copy over the elements. arrayops::copy(access::rwp(values), x.values, x.n_nonzero + 1); arrayops::copy(access::rwp(row_indices), x.row_indices, x.n_nonzero + 1); arrayops::copy(access::rwp(col_ptrs), x.col_ptrs, x.n_cols + 1); access::rw(n_nonzero) = x.n_nonzero; } } template inline void SpMat::mem_resize(const uword new_n_nonzero) { arma_extra_debug_sigprint(); if(n_nonzero != new_n_nonzero) { if(new_n_nonzero == 0) { memory::release(values); memory::release(row_indices); access::rw(values) = memory::acquire_chunked (1); access::rw(row_indices) = memory::acquire_chunked(1); access::rw( values[0]) = 0; access::rw(row_indices[0]) = 0; } else { // Figure out the actual amount of memory currently allocated // NOTE: this relies on memory::acquire_chunked() being used for the 'values' and 'row_indices' arrays const uword n_alloc = memory::enlarge_to_mult_of_chunksize(n_nonzero); if(n_alloc < new_n_nonzero) { eT* new_values = memory::acquire_chunked (new_n_nonzero + 1); uword* new_row_indices = memory::acquire_chunked(new_n_nonzero + 1); if(n_nonzero > 0) { // Copy old elements. uword copy_len = std::min(n_nonzero, new_n_nonzero); arrayops::copy(new_values, values, copy_len); arrayops::copy(new_row_indices, row_indices, copy_len); } memory::release(values); memory::release(row_indices); access::rw(values) = new_values; access::rw(row_indices) = new_row_indices; } // Set the "fake end" of the matrix by setting the last value and row // index to 0. This helps the iterators work correctly. access::rw( values[new_n_nonzero]) = 0; access::rw(row_indices[new_n_nonzero]) = 0; } access::rw(n_nonzero) = new_n_nonzero; } } // Steal memory from another matrix. template inline void SpMat::steal_mem(SpMat& x) { arma_extra_debug_sigprint(); if(this != &x) { if(values ) { memory::release(access::rw(values)); } if(row_indices) { memory::release(access::rw(row_indices)); } if(col_ptrs ) { memory::release(access::rw(col_ptrs)); } access::rw(n_rows) = x.n_rows; access::rw(n_cols) = x.n_cols; access::rw(n_elem) = x.n_elem; access::rw(n_nonzero) = x.n_nonzero; access::rw(values) = x.values; access::rw(row_indices) = x.row_indices; access::rw(col_ptrs) = x.col_ptrs; // Set other matrix to empty. access::rw(x.n_rows) = 0; access::rw(x.n_cols) = 0; access::rw(x.n_elem) = 0; access::rw(x.n_nonzero) = 0; access::rw(x.values) = NULL; access::rw(x.row_indices) = NULL; access::rw(x.col_ptrs) = NULL; } } template template arma_hot inline void SpMat::init_xform(const SpBase& A, const Functor& func) { arma_extra_debug_sigprint(); // if possible, avoid doing a copy and instead apply func to the generated elements if(SpProxy::Q_created_by_proxy == true) { (*this) = A.get_ref(); const uword nnz = n_nonzero; eT* t_values = access::rwp(values); for(uword i=0; i < nnz; ++i) { t_values[i] = func(t_values[i]); } } else { init_xform_mt(A.get_ref(), func); } } template template arma_hot inline void SpMat::init_xform_mt(const SpBase& A, const Functor& func) { arma_extra_debug_sigprint(); const SpProxy P(A.get_ref()); if( (P.is_alias(*this) == true) || (is_SpMat::stored_type>::value == true) ) { // NOTE: unwrap_spmat will convert a submatrix to a matrix, which in effect takes care of aliasing with submatrices; // NOTE: however, when more delayed ops are implemented, more elaborate handling of aliasing will be necessary const unwrap_spmat::stored_type> tmp(P.Q); const SpMat& x = tmp.M; if(void_ptr(this) != void_ptr(&x)) { init(x.n_rows, x.n_cols); // values and row_indices may not be null. if(values != NULL) { memory::release(values); memory::release(row_indices); } access::rw(values) = memory::acquire_chunked (x.n_nonzero + 1); access::rw(row_indices) = memory::acquire_chunked(x.n_nonzero + 1); arrayops::copy(access::rwp(row_indices), x.row_indices, x.n_nonzero + 1); arrayops::copy(access::rwp(col_ptrs), x.col_ptrs, x.n_cols + 1); access::rw(n_nonzero) = x.n_nonzero; } // initialise the elements array with a transformed version of the elements from x const uword nnz = n_nonzero; const eT2* x_values = x.values; eT* t_values = access::rwp(values); for(uword i=0; i < nnz; ++i) { t_values[i] = func(x_values[i]); // NOTE: func() must produce a value of type eT (ie. act as a convertor between eT2 and eT) } } else { init(P.get_n_rows(), P.get_n_cols()); mem_resize(P.get_n_nonzero()); typename SpProxy::const_iterator_type it = P.begin(); while(it != P.end()) { access::rw(row_indices[it.pos()]) = it.row(); access::rw(values[it.pos()]) = func(*it); // NOTE: func() must produce a value of type eT (ie. act as a convertor between eT2 and eT) ++access::rw(col_ptrs[it.col() + 1]); ++it; } // Now sum column pointers. for(uword c = 1; c <= n_cols; ++c) { access::rw(col_ptrs[c]) += col_ptrs[c - 1]; } } } template inline typename SpMat::iterator SpMat::begin() { return iterator(*this); } template inline typename SpMat::const_iterator SpMat::begin() const { return const_iterator(*this); } template inline typename SpMat::iterator SpMat::end() { return iterator(*this, 0, n_cols, n_nonzero); } template inline typename SpMat::const_iterator SpMat::end() const { return const_iterator(*this, 0, n_cols, n_nonzero); } template inline typename SpMat::iterator SpMat::begin_col(const uword col_num) { return iterator(*this, 0, col_num); } template inline typename SpMat::const_iterator SpMat::begin_col(const uword col_num) const { return const_iterator(*this, 0, col_num); } template inline typename SpMat::iterator SpMat::end_col(const uword col_num) { return iterator(*this, 0, col_num + 1); } template inline typename SpMat::const_iterator SpMat::end_col(const uword col_num) const { return const_iterator(*this, 0, col_num + 1); } template inline typename SpMat::row_iterator SpMat::begin_row(const uword row_num) { return row_iterator(*this, row_num, 0); } template inline typename SpMat::const_row_iterator SpMat::begin_row(const uword row_num) const { return const_row_iterator(*this, row_num, 0); } template inline typename SpMat::row_iterator SpMat::end_row() { return row_iterator(*this, n_nonzero); } template inline typename SpMat::const_row_iterator SpMat::end_row() const { return const_row_iterator(*this, n_nonzero); } template inline typename SpMat::row_iterator SpMat::end_row(const uword row_num) { return row_iterator(*this, row_num + 1, 0); } template inline typename SpMat::const_row_iterator SpMat::end_row(const uword row_num) const { return const_row_iterator(*this, row_num + 1, 0); } template inline void SpMat::clear() { (*this).reset(); } template inline bool SpMat::empty() const { return (n_elem == 0); } template inline uword SpMat::size() const { return n_elem; } template inline arma_hot arma_warn_unused SpValProxy > SpMat::get_value(const uword i) { // First convert to the actual location. uword lcol = i / n_rows; // Integer division. uword lrow = i % n_rows; return get_value(lrow, lcol); } template inline arma_hot arma_warn_unused eT SpMat::get_value(const uword i) const { // First convert to the actual location. uword lcol = i / n_rows; // Integer division. uword lrow = i % n_rows; return get_value(lrow, lcol); } template inline arma_hot arma_warn_unused SpValProxy > SpMat::get_value(const uword in_row, const uword in_col) { const uword colptr = col_ptrs[in_col]; const uword next_colptr = col_ptrs[in_col + 1]; // Step through the row indices to see if our element exists. for (uword i = colptr; i < next_colptr; ++i) { const uword row_index = row_indices[i]; // First check that we have not stepped past it. if (in_row < row_index) // If we have, then it doesn't exist: return 0. { return SpValProxy >(in_row, in_col, *this); // Proxy for a zero value. } // Now check if we are at the correct place. if (in_row == row_index) // If we are, return a reference to the value. { return SpValProxy >(in_row, in_col, *this, &access::rw(values[i])); } } // We did not find it, so it does not exist: return 0. return SpValProxy >(in_row, in_col, *this); } template inline arma_hot arma_warn_unused eT SpMat::get_value(const uword in_row, const uword in_col) const { const uword colptr = col_ptrs[in_col]; const uword next_colptr = col_ptrs[in_col + 1]; // Step through the row indices to see if our element exists. for (uword i = colptr; i < next_colptr; ++i) { const uword row_index = row_indices[i]; // First check that we have not stepped past it. if (in_row < row_index) // If we have, then it doesn't exist: return 0. { return eT(0); } // Now check if we are at the correct place. if (in_row == row_index) // If we are, return the value. { return values[i]; } } // We did not find it, so it does not exist: return 0. return eT(0); } /** * Given the index representing which of the nonzero values this is, return its * actual location, either in row/col or just the index. */ template arma_hot arma_inline arma_warn_unused uword SpMat::get_position(const uword i) const { uword lrow, lcol; get_position(i, lrow, lcol); // Assemble the row/col into the element's location in the matrix. return (lrow + n_rows * lcol); } template arma_hot arma_inline void SpMat::get_position(const uword i, uword& row_of_i, uword& col_of_i) const { arma_debug_check((i >= n_nonzero), "SpMat::get_position(): index out of bounds"); col_of_i = 0; while (col_ptrs[col_of_i + 1] <= i) { col_of_i++; } row_of_i = row_indices[i]; return; } /** * Add an element at the given position, and return a reference to it. The * element will be set to 0 (unless otherwise specified). If the element * already exists, its value will be overwritten. * * @param in_row Row of new element. * @param in_col Column of new element. * @param in_val Value to set new element to (default 0.0). */ template inline arma_hot arma_warn_unused eT& SpMat::add_element(const uword in_row, const uword in_col, const eT val) { arma_extra_debug_sigprint(); // We will assume the new element does not exist and begin the search for // where to insert it. If we find that it already exists, we will then // overwrite it. uword colptr = col_ptrs[in_col ]; uword next_colptr = col_ptrs[in_col + 1]; uword pos = colptr; // The position in the matrix of this value. if (colptr != next_colptr) { // There are other elements in this column, so we must find where this // element will fit as compared to those. while (pos < next_colptr && in_row > row_indices[pos]) { pos++; } // We aren't inserting into the last position, so it is still possible // that the element may exist. if (pos != next_colptr && row_indices[pos] == in_row) { // It already exists. Then, just overwrite it. access::rw(values[pos]) = val; return access::rw(values[pos]); } } // // Element doesn't exist, so we have to insert it // // We have to update the rest of the column pointers. for (uword i = in_col + 1; i < n_cols + 1; i++) { access::rw(col_ptrs[i])++; // We are only inserting one new element. } // Figure out the actual amount of memory currently allocated // NOTE: this relies on memory::acquire_chunked() being used for the 'values' and 'row_indices' arrays const uword n_alloc = memory::enlarge_to_mult_of_chunksize(n_nonzero + 1); // If possible, avoid time-consuming memory allocation if(n_alloc > (n_nonzero + 1)) { arrayops::copy_backwards(access::rwp(values) + pos + 1, values + pos, (n_nonzero - pos) + 1); arrayops::copy_backwards(access::rwp(row_indices) + pos + 1, row_indices + pos, (n_nonzero - pos) + 1); // Insert the new element. access::rw(values[pos]) = val; access::rw(row_indices[pos]) = in_row; access::rw(n_nonzero)++; } else { const uword old_n_nonzero = n_nonzero; access::rw(n_nonzero)++; // Add to count of nonzero elements. // Allocate larger memory. eT* new_values = memory::acquire_chunked (n_nonzero + 1); uword* new_row_indices = memory::acquire_chunked(n_nonzero + 1); // Copy things over, before the new element. if (pos > 0) { arrayops::copy(new_values, values, pos); arrayops::copy(new_row_indices, row_indices, pos); } // Insert the new element. new_values[pos] = val; new_row_indices[pos] = in_row; // Copy the rest of things over (including the extra element at the end). arrayops::copy(new_values + pos + 1, values + pos, (old_n_nonzero - pos) + 1); arrayops::copy(new_row_indices + pos + 1, row_indices + pos, (old_n_nonzero - pos) + 1); // Assign new pointers. memory::release(values); memory::release(row_indices); access::rw(values) = new_values; access::rw(row_indices) = new_row_indices; } return access::rw(values[pos]); } /** * Delete an element at the given position. * * @param in_row Row of element to be deleted. * @param in_col Column of element to be deleted. */ template inline arma_hot void SpMat::delete_element(const uword in_row, const uword in_col) { arma_extra_debug_sigprint(); // We assume the element exists (although... it may not) and look for its // exact position. If it doesn't exist... well, we don't need to do anything. uword colptr = col_ptrs[in_col]; uword next_colptr = col_ptrs[in_col + 1]; if (colptr != next_colptr) { // There's at least one element in this column. // Let's see if we are one of them. for (uword pos = colptr; pos < next_colptr; pos++) { if (in_row == row_indices[pos]) { const uword old_n_nonzero = n_nonzero; --access::rw(n_nonzero); // Remove one from the count of nonzero elements. // Found it. Now remove it. // Figure out the actual amount of memory currently allocated and the actual amount that will be required // NOTE: this relies on memory::acquire_chunked() being used for the 'values' and 'row_indices' arrays const uword n_alloc = memory::enlarge_to_mult_of_chunksize(old_n_nonzero + 1); const uword n_alloc_mod = memory::enlarge_to_mult_of_chunksize(n_nonzero + 1); // If possible, avoid time-consuming memory allocation if(n_alloc_mod == n_alloc) { if (pos < n_nonzero) // remember, we decremented n_nonzero { arrayops::copy_forwards(access::rwp(values) + pos, values + pos + 1, (n_nonzero - pos) + 1); arrayops::copy_forwards(access::rwp(row_indices) + pos, row_indices + pos + 1, (n_nonzero - pos) + 1); } } else { // Make new arrays. eT* new_values = memory::acquire_chunked (n_nonzero + 1); uword* new_row_indices = memory::acquire_chunked(n_nonzero + 1); if (pos > 0) { arrayops::copy(new_values, values, pos); arrayops::copy(new_row_indices, row_indices, pos); } arrayops::copy(new_values + pos, values + pos + 1, (n_nonzero - pos) + 1); arrayops::copy(new_row_indices + pos, row_indices + pos + 1, (n_nonzero - pos) + 1); memory::release(values); memory::release(row_indices); access::rw(values) = new_values; access::rw(row_indices) = new_row_indices; } // And lastly, update all the column pointers (decrement by one). for (uword i = in_col + 1; i < n_cols + 1; i++) { --access::rw(col_ptrs[i]); // We only removed one element. } return; // There is nothing left to do. } } } return; // The element does not exist, so there's nothing for us to do. } #ifdef ARMA_EXTRA_SPMAT_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPMAT_MEAT) #endif //! @} RcppArmadillo/inst/include/armadillo_bits/SpValProxy_meat.hpp0000644000176000001440000001230012156062240024220 0ustar ripleyusers// Copyright (C) 2011-2012 Ryan Curtin // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpValProxy //! @{ //! SpValProxy implementation. template arma_inline SpValProxy::SpValProxy(uword in_row, uword in_col, T1& in_parent, eT* in_val_ptr) : row(in_row) , col(in_col) , val_ptr(in_val_ptr) , parent(in_parent) { // Nothing to do. } template arma_inline SpValProxy& SpValProxy::operator=(const SpValProxy& rhs) { return (*this).operator=(eT(rhs)); } template template arma_inline SpValProxy& SpValProxy::operator=(const SpValProxy& rhs) { return (*this).operator=(eT(rhs)); } template arma_inline SpValProxy& SpValProxy::operator=(const eT rhs) { if (rhs != eT(0)) // A nonzero element is being assigned. { if (val_ptr) { // The value exists and merely needs to be updated. *val_ptr = rhs; } else { // The value is nonzero and must be added. val_ptr = &parent.add_element(row, col, rhs); } } else // A zero is being assigned.~ { if (val_ptr) { // The element exists, but we need to remove it, because it is being set to 0. parent.delete_element(row, col); val_ptr = NULL; } // If the element does not exist, we do not need to do anything at all. } return *this; } template arma_inline SpValProxy& SpValProxy::operator+=(const eT rhs) { if (val_ptr) { // The value already exists and merely needs to be updated. *val_ptr += rhs; check_zero(); } else { if (rhs != eT(0)) { // The value does not exist and must be added. val_ptr = &parent.add_element(row, col, rhs); } } return *this; } template arma_inline SpValProxy& SpValProxy::operator-=(const eT rhs) { if (val_ptr) { // The value already exists and merely needs to be updated. *val_ptr -= rhs; check_zero(); } else { if (rhs != eT(0)) { // The value does not exist and must be added. val_ptr = &parent.add_element(row, col, -rhs); } } return *this; } template arma_inline SpValProxy& SpValProxy::operator*=(const eT rhs) { if (rhs != eT(0)) { if (val_ptr) { // The value already exists and merely needs to be updated. *val_ptr *= rhs; check_zero(); } } else { if (val_ptr) { // Since we are multiplying by zero, the value can be deleted. parent.delete_element(row, col); val_ptr = NULL; } } return *this; } template arma_inline SpValProxy& SpValProxy::operator/=(const eT rhs) { if (rhs != eT(0)) // I hope this is true! { if (val_ptr) { *val_ptr /= rhs; check_zero(); } } else { if (val_ptr) { *val_ptr /= rhs; // That is where it gets ugly. // Now check if it's 0. if (*val_ptr == eT(0)) { parent.delete_element(row, col); val_ptr = NULL; } } else { eT val = eT(0) / rhs; // This may vary depending on type and implementation. if (val != eT(0)) { // Ok, now we have to add it. val_ptr = &parent.add_element(row, col, val); } } } return *this; } template arma_inline SpValProxy& SpValProxy::operator++() { if (val_ptr) { (*val_ptr) += eT(1); check_zero(); } else { val_ptr = &parent.add_element(row, col, eT(1)); } return *this; } template arma_inline SpValProxy& SpValProxy::operator--() { if (val_ptr) { (*val_ptr) -= eT(1); check_zero(); } else { val_ptr = &parent.add_element(row, col, eT(-1)); } return *this; } template arma_inline typename T1::elem_type SpValProxy::operator++(const int) { if (val_ptr) { (*val_ptr) += eT(1); check_zero(); } else { val_ptr = &parent.add_element(row, col, eT(1)); } if (val_ptr) // It may have changed to now be 0. { return *(val_ptr) - eT(1); } else { return eT(0); } } template arma_inline typename T1::elem_type SpValProxy::operator--(const int) { if (val_ptr) { (*val_ptr) -= eT(1); check_zero(); } else { val_ptr = &parent.add_element(row, col, eT(-1)); } if (val_ptr) // It may have changed to now be 0. { return *(val_ptr) + eT(1); } else { return eT(0); } } template arma_inline SpValProxy::operator eT() const { if (val_ptr) { return *val_ptr; } else { return eT(0); } } template arma_inline arma_hot void SpValProxy::check_zero() { if (*val_ptr == eT(0)) { parent.delete_element(row, col); val_ptr = NULL; } } //! @} RcppArmadillo/inst/include/armadillo_bits/Base_bones.hpp0000644000176000001440000000535112244602366023202 0ustar ripleyusers// Copyright (C) 2008-2013 Conrad Sanderson // Copyright (C) 2008-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Base //! @{ template struct Base_blas_elem_type { arma_inline const Op i(const bool slow = false) const; //!< matrix inverse arma_inline const Op i(const char* method ) const; //!< matrix inverse }; template struct Base_other_elem_type { }; template struct Base_extra {}; template struct Base_extra { typedef Base_blas_elem_type result; }; template struct Base_extra { typedef Base_other_elem_type result; }; template struct Base_eval_Mat { const derived& eval() const; }; template struct Base_eval_expr { Mat eval() const; //!< force the immediate evaluation of a delayed expression }; template struct Base_eval {}; template struct Base_eval { typedef Base_eval_Mat result; }; template struct Base_eval { typedef Base_eval_expr result; }; //! Class for static polymorphism, modelled after the "Curiously Recurring Template Pattern" (CRTP). //! Used for type-safe downcasting in functions that restrict their input(s) to be classes that are //! derived from Base (e.g. Mat, Op, Glue, diagview, subview). //! A Base object can be converted to a Mat object by the unwrap class. template struct Base : public Base_extra::value>::result , public Base_eval::value>::result { arma_inline const derived& get_ref() const; arma_inline const Op t() const; //!< Hermitian transpose arma_inline const Op ht() const; //!< Hermitian transpose arma_inline const Op st() const; //!< simple transpose inline void print(const std::string extra_text = "") const; inline void print(std::ostream& user_stream, const std::string extra_text = "") const; inline void raw_print(const std::string extra_text = "") const; inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/glue_hist_bones.hpp0000644000176000001440000000071012256562725024314 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // Copyright (C) 2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. class glue_hist { public: template inline static void apply(Mat& out, const mtGlue& in); }; RcppArmadillo/inst/include/armadillo_bits/fn_min.hpp0000644000176000001440000000750312244135164022406 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_min //! @{ //! \brief //! Delayed 'minimum values' operation. //! The dimension, along which the minima are found, is set via 'dim'. //! For dim = 0, the minimum value of each column is found (i.e. searches by traversing across rows). //! For dim = 1, the minimum value of each row is found (i.e. searches by traversing across columns). //! The default is dim = 0. template arma_inline const Op min ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op min ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type min ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_min::min(X); } //! \brief //! Immediate 'find minimum value' operation, //! invoked, for example, by: min(min(A)) template inline arma_warn_unused typename T1::elem_type min(const Op& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("min(): two consecutive min() calls detected"); return op_min::min(in.m); } template arma_inline const Op< Op, op_min> min(const Op& in, const uword dim) { arma_extra_debug_sigprint(); return Op< Op, op_min>(in, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & min(const T& x) { return x; } //! element-wise minimum template arma_inline typename enable_if2 < ( is_arma_type::value && is_arma_type::value && is_same_type::value ), const Glue >::result min ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return Glue(X, Y); } template inline arma_warn_unused typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == true), typename T1::elem_type >::result min(const T1& x) { arma_extra_debug_sigprint(); return spop_min::vector_min(x); } template inline typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == false), const SpOp >::result min(const T1& X, const uword dim = 0) { arma_extra_debug_sigprint(); return SpOp(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type min(const SpOp& X) { arma_extra_debug_sigprint(); arma_extra_debug_print("min(): two consecutive min() calls detected"); return spop_min::vector_min(X.m); } template inline const SpOp< SpOp, spop_min> min(const SpOp& in, const uword dim) { arma_extra_debug_sigprint(); return SpOp< SpOp, spop_min>(in, dim, 0); } //! @} RcppArmadillo/inst/include/armadillo_bits/Gen_bones.hpp0000644000176000001440000000333312176400754023040 0ustar ripleyusers// Copyright (C) 2011-2013 Conrad Sanderson // Copyright (C) 2011-2013 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup Gen //! @{ //! support class for generator functions (eg. zeros, randu, randn, ...) template class Gen : public Base > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool prefer_at_accessor = (is_same_type::value) ? true : false; static const bool is_simple = (is_same_type::value) || (is_same_type::value); static const bool is_row = T1::is_row; static const bool is_col = T1::is_col; arma_aligned const uword n_rows; arma_aligned const uword n_cols; arma_inline Gen(const uword in_n_rows, const uword in_n_cols); arma_inline ~Gen(); arma_inline static elem_type generate(); arma_inline elem_type operator[] (const uword ii) const; arma_inline elem_type at (const uword row, const uword col) const; arma_inline elem_type at_alt (const uword ii) const; inline void apply (Mat& out) const; inline void apply_inplace_plus (Mat& out) const; inline void apply_inplace_minus(Mat& out) const; inline void apply_inplace_schur(Mat& out) const; inline void apply_inplace_div (Mat& out) const; }; //! @} RcppArmadillo/inst/include/armadillo_bits/injector_meat.hpp0000644000176000001440000002447112202101406023750 0ustar ripleyusers// Copyright (C) 2010 Conrad Sanderson // Copyright (C) 2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup injector //! @{ template inline mat_injector_row::mat_injector_row() : n_cols(0) { arma_extra_debug_sigprint(); A.set_size( podarray_prealloc_n_elem::val ); } template inline void mat_injector_row::insert(const eT val) const { arma_extra_debug_sigprint(); if(n_cols < A.n_elem) { A[n_cols] = val; ++n_cols; } else { B.set_size(2 * A.n_elem); arrayops::copy(B.memptr(), A.memptr(), n_cols); B[n_cols] = val; ++n_cols; std::swap( access::rw(A.mem), access::rw(B.mem) ); std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); } } // // // template inline mat_injector::mat_injector(T1& in_X, const typename mat_injector::elem_type val) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; AA = new podarray< mat_injector_row* >; BB = new podarray< mat_injector_row* >; podarray< mat_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*(A[0])).insert(val); } template inline mat_injector::mat_injector(T1& in_X, const injector_end_of_row<>& x) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); arma_ignore(x); typedef typename mat_injector::elem_type eT; AA = new podarray< mat_injector_row* >; BB = new podarray< mat_injector_row* >; podarray< mat_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*this).end_of_row(); } template inline mat_injector::~mat_injector() { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; podarray< mat_injector_row* >& A = *AA; if(n_rows > 0) { uword max_n_cols = (*(A[0])).n_cols; for(uword row=1; row::value == true) { X.set_size(max_n_rows, max_n_cols); for(uword row=0; row::value == true) { arma_debug_check( (max_n_rows > 1), "matrix initialisation: incompatible dimensions" ); const uword n_cols = (*(A[0])).n_cols; X.set_size(1, n_cols); arrayops::copy( X.memptr(), (*(A[0])).A.memptr(), n_cols ); } else if(is_Col::value == true) { const bool is_vec = ( (max_n_rows == 1) || (max_n_cols == 1) ); arma_debug_check( (is_vec == false), "matrix initialisation: incompatible dimensions" ); const uword n_elem = (std::max)(max_n_rows, max_n_cols); X.set_size(n_elem, 1); uword i = 0; for(uword row=0; row inline void mat_injector::insert(const typename mat_injector::elem_type val) const { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; podarray< mat_injector_row* >& A = *AA; (*(A[n_rows-1])).insert(val); } template inline void mat_injector::end_of_row() const { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; podarray< mat_injector_row* >& A = *AA; podarray< mat_injector_row* >& B = *BB; B.set_size( n_rows+1 ); arrayops::copy(B.memptr(), A.memptr(), n_rows); for(uword row=n_rows; row<(n_rows+1); ++row) { B[row] = new mat_injector_row; } std::swap(AA, BB); n_rows += 1; } template arma_inline const mat_injector& operator<<(const mat_injector& ref, const typename mat_injector::elem_type val) { arma_extra_debug_sigprint(); ref.insert(val); return ref; } template arma_inline const mat_injector& operator<<(const mat_injector& ref, const injector_end_of_row<>& x) { arma_extra_debug_sigprint(); arma_ignore(x); ref.end_of_row(); return ref; } //// using a mixture of operator << and , doesn't work yet //// e.g. A << 1, 2, 3 << endr //// in the above "3 << endr" requires special handling. //// similarly, special handling is necessary for "endr << 3" //// // template // arma_inline // const mat_injector& // operator,(const mat_injector& ref, const typename mat_injector::elem_type val) // { // arma_extra_debug_sigprint(); // // ref.insert(val); // // return ref; // } // template // arma_inline // const mat_injector& // operator,(const mat_injector& ref, const injector_end_of_row<>& x) // { // arma_extra_debug_sigprint(); // arma_ignore(x); // // ref.end_of_row(); // // return ref; // } // // // template inline field_injector_row::field_injector_row() : n_cols(0) { arma_extra_debug_sigprint(); AA = new field; BB = new field; field& A = *AA; A.set_size( field_prealloc_n_elem::val ); } template inline field_injector_row::~field_injector_row() { arma_extra_debug_sigprint(); delete AA; delete BB; } template inline void field_injector_row::insert(const oT& val) const { arma_extra_debug_sigprint(); field& A = *AA; field& B = *BB; if(n_cols < A.n_elem) { A[n_cols] = val; ++n_cols; } else { B.set_size(2 * A.n_elem); for(uword i=0; i inline field_injector::field_injector(T1& in_X, const typename field_injector::object_type& val) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; AA = new podarray< field_injector_row* >; BB = new podarray< field_injector_row* >; podarray< field_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*(A[0])).insert(val); } template inline field_injector::field_injector(T1& in_X, const injector_end_of_row<>& x) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); arma_ignore(x); typedef typename field_injector::object_type oT; AA = new podarray< field_injector_row* >; BB = new podarray< field_injector_row* >; podarray< field_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*this).end_of_row(); } template inline field_injector::~field_injector() { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; podarray< field_injector_row* >& A = *AA; if(n_rows > 0) { uword max_n_cols = (*(A[0])).n_cols; for(uword row=1; row& tmp = *((*(A[row])).AA); X.at(row,col) = tmp[col]; } for(uword col=n_cols; col inline void field_injector::insert(const typename field_injector::object_type& val) const { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; podarray< field_injector_row* >& A = *AA; (*(A[n_rows-1])).insert(val); } template inline void field_injector::end_of_row() const { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; podarray< field_injector_row* >& A = *AA; podarray< field_injector_row* >& B = *BB; B.set_size( n_rows+1 ); for(uword row=0; row; } std::swap(AA, BB); n_rows += 1; } template arma_inline const field_injector& operator<<(const field_injector& ref, const typename field_injector::object_type& val) { arma_extra_debug_sigprint(); ref.insert(val); return ref; } template arma_inline const field_injector& operator<<(const field_injector& ref, const injector_end_of_row<>& x) { arma_extra_debug_sigprint(); arma_ignore(x); ref.end_of_row(); return ref; } //! @} RcppArmadillo/inst/include/armadillo_bits/SpMat_iterators_meat.hpp0000644000176000001440000004273112111344723025264 0ustar ripleyusers// Copyright (C) 2011-2012 Ryan Curtin // Copyright (C) 2011 Matthew Amidon // Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup SpMat //! @{ /////////////////////////////////////////////////////////////////////////////// // SpMat::iterator_base implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpMat::iterator_base::iterator_base(const SpMat& in_M) : M(in_M) , internal_col(0) , internal_pos(0) { // Technically this iterator is invalid (it may not point to a real element) } template inline SpMat::iterator_base::iterator_base(const SpMat& in_M, const uword in_col, const uword in_pos) : M(in_M) , internal_col(in_col) , internal_pos(in_pos) { // Nothing to do. } template inline arma_hot eT SpMat::iterator_base::operator*() const { return M.values[internal_pos]; } /////////////////////////////////////////////////////////////////////////////// // SpMat::const_iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpMat::const_iterator::const_iterator(const SpMat& in_M, uword initial_pos) : iterator_base(in_M, 0, initial_pos) { // Corner case for empty matrices. if(in_M.n_nonzero == 0) { iterator_base::internal_col = in_M.n_cols; return; } // Determine which column we should be in. while(iterator_base::M.col_ptrs[iterator_base::internal_col + 1] <= iterator_base::internal_pos) { iterator_base::internal_col++; } } template inline SpMat::const_iterator::const_iterator(const SpMat& in_M, uword in_row, uword in_col) : iterator_base(in_M, in_col, 0) { // So we have a position we want to be right after. Skip to the column. iterator_base::internal_pos = iterator_base::M.col_ptrs[iterator_base::internal_col]; // Now we have to make sure that is the right column. while(iterator_base::M.col_ptrs[iterator_base::internal_col + 1] <= iterator_base::internal_pos) { iterator_base::internal_col++; } // Now we have to get to the right row. while((iterator_base::M.row_indices[iterator_base::internal_pos] < in_row) && (iterator_base::internal_col == in_col)) { ++(*this); // Increment iterator. } } template inline SpMat::const_iterator::const_iterator(const SpMat& in_M, const uword /* in_row */, const uword in_col, const uword in_pos) : iterator_base(in_M, in_col, in_pos) { // Nothing to do. } template inline SpMat::const_iterator::const_iterator(const typename SpMat::const_iterator& other) : iterator_base(other.M, other.internal_col, other.internal_pos) { // Nothing to do. } template inline arma_hot typename SpMat::const_iterator& SpMat::const_iterator::operator++() { ++iterator_base::internal_pos; if (iterator_base::internal_pos == iterator_base::M.n_nonzero) { iterator_base::internal_col = iterator_base::M.n_cols; return *this; } // Check to see if we moved a column. while (iterator_base::M.col_ptrs[iterator_base::internal_col + 1] <= iterator_base::internal_pos) { ++iterator_base::internal_col; } return *this; } template inline arma_hot typename SpMat::const_iterator SpMat::const_iterator::operator++(int) { typename SpMat::const_iterator tmp(*this); ++(*this); return tmp; } template inline arma_hot typename SpMat::const_iterator& SpMat::const_iterator::operator--() { //iterator_base::M.print("M"); // printf("decrement from %d, %d, %d\n", iterator_base::internal_pos, iterator_base::internal_col, iterator_base::row()); --iterator_base::internal_pos; // printf("now pos %d\n", iterator_base::internal_pos); // First, see if we moved back a column. while (iterator_base::internal_pos < iterator_base::M.col_ptrs[iterator_base::internal_col]) { // printf("colptr %d (col %d)\n", iterator_base::M.col_ptrs[iterator_base::internal_col], iterator_base::internal_col); --iterator_base::internal_col; } return *this; } template inline arma_hot typename SpMat::const_iterator SpMat::const_iterator::operator--(int) { typename SpMat::const_iterator tmp(*this); --(*this); return tmp; } template inline arma_hot bool SpMat::const_iterator::operator==(const const_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator!=(const const_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator==(const typename SpSubview::const_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator!=(const typename SpSubview::const_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator==(const const_row_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator!=(const const_row_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator==(const typename SpSubview::const_row_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator!=(const typename SpSubview::const_row_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } /////////////////////////////////////////////////////////////////////////////// // SpMat::iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline arma_hot SpValProxy > SpMat::iterator::operator*() { return SpValProxy >( iterator_base::M.row_indices[iterator_base::internal_pos], iterator_base::internal_col, access::rw(iterator_base::M), &access::rw(iterator_base::M.values[iterator_base::internal_pos])); } template inline arma_hot typename SpMat::iterator& SpMat::iterator::operator++() { const_iterator::operator++(); return *this; } template inline arma_hot typename SpMat::iterator SpMat::iterator::operator++(int) { typename SpMat::iterator tmp(*this); const_iterator::operator++(); return tmp; } template inline arma_hot typename SpMat::iterator& SpMat::iterator::operator--() { const_iterator::operator--(); return *this; } template inline arma_hot typename SpMat::iterator SpMat::iterator::operator--(int) { typename SpMat::iterator tmp(*this); const_iterator::operator--(); return tmp; } /////////////////////////////////////////////////////////////////////////////// // SpMat::const_row_iterator implementation // /////////////////////////////////////////////////////////////////////////////// /** * Initialize the const_row_iterator. */ template inline SpMat::const_row_iterator::const_row_iterator(const SpMat& in_M, uword initial_pos) : iterator_base(in_M, 0, initial_pos) , internal_row(0) , actual_pos(0) { // Corner case for empty matrix. if(in_M.n_nonzero == 0) { iterator_base::internal_col = 0; internal_row = in_M.n_rows; return; } // We don't count zeroes in our position count, so we have to find the nonzero // value corresponding to the given initial position. We assume initial_pos // is valid. // This is irritating because we don't know where the elements are in each // row. What we will do is loop across all columns looking for elements in // row 0 (and add to our sum), then in row 1, and so forth, until we get to // the desired position. uword cur_pos = -1; uword cur_row = 0; uword cur_col = 0; while(true) // This loop is terminated from the inside. { // Is there anything in the column we are looking at? for (uword ind = 0; ((iterator_base::M.col_ptrs[cur_col] + ind < iterator_base::M.col_ptrs[cur_col + 1]) && (iterator_base::M.row_indices[iterator_base::M.col_ptrs[cur_col] + ind] <= cur_row)); ind++) { // There is something in this column. Is it in the row we are looking at? const uword row_index = iterator_base::M.row_indices[iterator_base::M.col_ptrs[cur_col] + ind]; if (row_index == cur_row) { // Yes, it is what we are looking for. Increment our current position. if (++cur_pos == iterator_base::internal_pos) { actual_pos = iterator_base::M.col_ptrs[cur_col] + ind; internal_row = cur_row; iterator_base::internal_col = cur_col; return; } // We are done with this column. Break to the column incrementing code (directly below). break; } else if(row_index > cur_row) { break; // Can't be in this column. } } cur_col++; // Done with the column. Move on. if (cur_col == iterator_base::M.n_cols) { // We are out of columns. Loop back to the beginning and look on the // next row. cur_col = 0; cur_row++; } } } template inline SpMat::const_row_iterator::const_row_iterator(const SpMat& in_M, uword in_row, uword in_col) : iterator_base(in_M, in_col, 0) , internal_row(0) , actual_pos(0) { // This is slow. It needs to be rewritten. // So we have a destination we want to be just after, but don't know what position that is. Make another iterator to find out... const_row_iterator it(in_M, 0); while((it.row() < in_row) || ((it.row() == in_row) && (it.col() < in_col))) { it++; } // Now that it is at the right place, take its position. iterator_base::internal_col = it.internal_col; iterator_base::internal_pos = it.internal_pos; internal_row = it.internal_row; actual_pos = it.actual_pos; } /** * Initialize the const_row_iterator from another const_row_iterator. */ template inline SpMat::const_row_iterator::const_row_iterator(const typename SpMat::const_row_iterator& other) : iterator_base(other.M, other.internal_col, other.internal_pos) , internal_row(other.internal_row) , actual_pos(other.actual_pos) { // Nothing to do. } /** * Increment the row_iterator. */ template inline arma_hot typename SpMat::const_row_iterator& SpMat::const_row_iterator::operator++() { // We just need to find the next nonzero element. iterator_base::internal_pos++; if(iterator_base::internal_pos == iterator_base::M.n_nonzero) { internal_row = iterator_base::M.n_rows; iterator_base::internal_col = 0; actual_pos = iterator_base::M.n_nonzero; return *this; } // Otherwise, we need to search. uword cur_col = iterator_base::internal_col; uword cur_row = internal_row; while (true) // This loop is terminated from the inside. { // Increment the current column and see if we are now on a new row. if (++cur_col == iterator_base::M.n_cols) { cur_col = 0; cur_row++; } // Is there anything in this new column? for (uword ind = 0; ((iterator_base::M.col_ptrs[cur_col] + ind < iterator_base::M.col_ptrs[cur_col + 1]) && (iterator_base::M.row_indices[iterator_base::M.col_ptrs[cur_col] + ind] <= cur_row)); ind++) { if (iterator_base::M.row_indices[iterator_base::M.col_ptrs[cur_col] + ind] == cur_row) { // We have successfully incremented. internal_row = cur_row; iterator_base::internal_col = cur_col; actual_pos = iterator_base::M.col_ptrs[cur_col] + ind; return *this; // Now we are done. } } } } /** * Increment the row_iterator (but do not return anything. */ template inline arma_hot typename SpMat::const_row_iterator SpMat::const_row_iterator::operator++(int) { typename SpMat::const_row_iterator tmp(*this); ++(*this); return tmp; } /** * Decrement the row_iterator. */ template inline arma_hot typename SpMat::const_row_iterator& SpMat::const_row_iterator::operator--() { iterator_base::internal_pos--; // We have to search backwards. uword cur_col = iterator_base::internal_col; uword cur_row = internal_row; while (true) // This loop is terminated from the inside. { // Decrement the current column and see if we are now on a new row. This is a uword so a negativity check won't work. if (--cur_col > iterator_base::M.n_cols /* this means it underflew */) { cur_col = iterator_base::M.n_cols - 1; cur_row--; } // Is there anything in this new column? for (uword ind = 0; ((iterator_base::M.col_ptrs[cur_col] + ind < iterator_base::M.col_ptrs[cur_col + 1]) && (iterator_base::M.row_indices[iterator_base::M.col_ptrs[cur_col] + ind] <= cur_row)); ind++) { if (iterator_base::M.row_indices[iterator_base::M.col_ptrs[cur_col] + ind] == cur_row) { // We have successfully decremented. iterator_base::internal_col = cur_col; internal_row = cur_row; actual_pos = iterator_base::M.col_ptrs[cur_col] + ind; return *this; // Now we are done. } } } } /** * Decrement the row_iterator. */ template inline arma_hot typename SpMat::const_row_iterator SpMat::const_row_iterator::operator--(int) { typename SpMat::const_row_iterator tmp(*this); --(*this); return tmp; } template inline arma_hot bool SpMat::const_row_iterator::operator==(const const_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator!=(const const_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator==(const typename SpSubview::const_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator!=(const typename SpSubview::const_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator==(const const_row_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator!=(const const_row_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator==(const typename SpSubview::const_row_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator!=(const typename SpSubview::const_row_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } /////////////////////////////////////////////////////////////////////////////// // SpMat::row_iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline arma_hot SpValProxy > SpMat::row_iterator::operator*() { return SpValProxy >( const_row_iterator::internal_row, iterator_base::internal_col, access::rw(iterator_base::M), &access::rw(iterator_base::M.values[const_row_iterator::actual_pos])); } template inline arma_hot typename SpMat::row_iterator& SpMat::row_iterator::operator++() { const_row_iterator::operator++(); return *this; } template inline arma_hot typename SpMat::row_iterator SpMat::row_iterator::operator++(int) { typename SpMat::row_iterator tmp(*this); const_row_iterator::operator++(); return tmp; } template inline arma_hot typename SpMat::row_iterator& SpMat::row_iterator::operator--() { const_row_iterator::operator--(); return *this; } template inline arma_hot typename SpMat::row_iterator SpMat::row_iterator::operator--(int) { typename SpMat::row_iterator tmp(*this); const_row_iterator::operator--(); return tmp; } //! @} RcppArmadillo/inst/include/armadillo_bits/fn_sprandu.hpp0000644000176000001440000000334612246034243023276 0ustar ripleyusers// Copyright (C) 2012 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup fn_sprandu //! @{ //! Generate a sparse matrix with a randomly selected subset of the elements //! set to random values in the [0,1] interval (uniform distribution) template inline obj_type sprandu ( const uword n_rows, const uword n_cols, const double density, const typename arma_SpMat_SpCol_SpRow_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_SpCol::value == true) { arma_debug_check( (n_cols != 1), "sprandu(): incompatible size" ); } else if(is_SpRow::value == true) { arma_debug_check( (n_rows != 1), "sprandu(): incompatible size" ); } obj_type out; out.sprandu(n_rows, n_cols, density); return out; } inline sp_mat sprandu(const uword n_rows, const uword n_cols, const double density) { arma_extra_debug_sigprint(); sp_mat out; out.sprandu(n_rows, n_cols, density); return out; } //! Generate a sparse matrix with the non-zero values in the same locations as in the given sparse matrix X, //! with the non-zero values set to random values in the [0,1] interval (uniform distribution) template inline SpMat sprandu(const SpBase& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; SpMat out( X.get_ref() ); arma_rng::randu::fill( access::rwp(out.values), out.n_nonzero ); return out; } //! @} RcppArmadillo/inst/include/armadillo_bits/op_min_meat.hpp0000644000176000001440000002552312200631217023421 0ustar ripleyusers// Copyright (C) 2008-2012 Conrad Sanderson // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup op_min //! @{ //! \brief //! For each row or for each column, find the minimum value. //! The result is stored in a dense matrix that has either one column or one row. //! The dimension, for which the minima are found, is set via the min() function. template inline void op_min::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "min(): incorrect usage. dim must be 0 or 1"); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) // min in each column { arma_extra_debug_print("op_min::apply(), dim = 0"); arma_debug_check( (X_n_rows == 0), "min(): given object has zero rows" ); out.set_size(1, X_n_cols); eT* out_mem = out.memptr(); for(uword col=0; col arma_pure inline eT op_min::direct_min(const eT* const X, const uword n_elem) { arma_extra_debug_sigprint(); eT min_val = priv::most_pos(); uword i,j; for(i=0, j=1; j inline eT op_min::direct_min(const eT* const X, const uword n_elem, uword& index_of_min_val) { arma_extra_debug_sigprint(); eT min_val = priv::most_pos(); uword best_index = 0; uword i,j; for(i=0, j=1; j inline eT op_min::direct_min(const Mat& X, const uword row) { arma_extra_debug_sigprint(); const uword X_n_cols = X.n_cols; eT min_val = priv::most_pos(); uword i,j; for(i=0, j=1; j < X_n_cols; i+=2, j+=2) { const eT tmp_i = X.at(row,i); const eT tmp_j = X.at(row,j); if(tmp_i < min_val) { min_val = tmp_i; } if(tmp_j < min_val) { min_val = tmp_j; } } if(i < X_n_cols) { const eT tmp_i = X.at(row,i); if(tmp_i < min_val) { min_val = tmp_i; } } return min_val; } template inline eT op_min::min(const subview& X) { arma_extra_debug_sigprint(); arma_debug_check( (X.n_elem == 0), "min(): given object has no elements" ); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; eT min_val = priv::most_pos(); if(X_n_rows == 1) { const Mat& A = X.m; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_col_p1 = start_col + X_n_cols; uword i,j; for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2) { const eT tmp_i = A.at(start_row, i); const eT tmp_j = A.at(start_row, j); if(tmp_i < min_val) { min_val = tmp_i; } if(tmp_j < min_val) { min_val = tmp_j; } } if(i < end_col_p1) { const eT tmp_i = A.at(start_row, i); if(tmp_i < min_val) { min_val = tmp_i; } } } else { for(uword col=0; col < X_n_cols; ++col) { eT tmp_val = op_min::direct_min(X.colptr(col), X_n_rows); if(tmp_val < min_val) { min_val = tmp_val; } } } return min_val; } template inline typename arma_not_cx::result op_min::min(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); arma_debug_check( (n_elem == 0), "min(): given object has no elements" ); eT min_val = priv::most_pos(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j inline std::complex op_min::direct_min(const std::complex* const X, const uword n_elem) { arma_extra_debug_sigprint(); uword index = 0; T min_val = priv::most_pos(); for(uword i=0; i inline std::complex op_min::direct_min(const std::complex* const X, const uword n_elem, uword& index_of_min_val) { arma_extra_debug_sigprint(); uword index = 0; T min_val = priv::most_pos(); for(uword i=0; i inline std::complex op_min::direct_min(const Mat< std::complex >& X, const uword row) { arma_extra_debug_sigprint(); const uword X_n_cols = X.n_cols; uword index = 0; T min_val = priv::most_pos(); for(uword col=0; col inline std::complex op_min::min(const subview< std::complex >& X) { arma_extra_debug_sigprint(); arma_debug_check( (X.n_elem == 0), "min(): given object has no elements" ); const Mat< std::complex >& A = X.m; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_row_p1 = start_row + X_n_rows; const uword end_col_p1 = start_col + X_n_cols; T min_val = priv::most_pos(); uword best_row = 0; uword best_col = 0; if(X_n_rows == 1) { best_col = 0; for(uword col=start_col; col < end_col_p1; ++col) { const T tmp_val = std::abs( A.at(start_row, col) ); if(tmp_val < min_val) { min_val = tmp_val; best_col = col; } } best_row = start_row; } else { for(uword col=start_col; col < end_col_p1; ++col) for(uword row=start_row; row < end_row_p1; ++row) { const T tmp_val = std::abs( A.at(row, col) ); if(tmp_val < min_val) { min_val = tmp_val; best_row = row; best_col = col; } } } return A.at(best_row, best_col); } template inline typename arma_cx_only::result op_min::min(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); arma_debug_check( (n_elem == 0), "min(): given object has no elements" ); T min_val = priv::most_pos(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); uword index = 0; for(uword i=0; i inline Col< std::complex > eig_gen ( const Base& X, const typename arma_blas_type_only::result* junk1 = 0, const typename arma_not_cx::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); Mat l_eigvec; Mat r_eigvec; Col< std::complex > eigval; const bool status = auxlib::eig_gen(eigval, l_eigvec, r_eigvec, X, 'n'); if(status == false) { eigval.reset(); arma_bad("eig_gen(): failed to converge"); } return eigval; } //! Eigenvalues of general complex square matrix X template inline Col< std::complex > eig_gen ( const Base< std::complex, T1>& X, const typename arma_blas_type_only< std::complex >::result* junk1 = 0, const typename arma_cx_only< std::complex >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); Mat< std::complex > l_eigvec; Mat< std::complex > r_eigvec; Col< std::complex > eigval; const bool status = auxlib::eig_gen(eigval, l_eigvec, r_eigvec, X, 'n'); if(status == false) { eigval.reset(); arma_bad("eig_gen(): failed to converge"); } return eigval; } //! Eigenvalues of general real square matrix X template inline bool eig_gen ( Col< std::complex >& eigval, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Mat l_eigvec; Mat r_eigvec; const bool status = auxlib::eig_gen(eigval, l_eigvec, r_eigvec, X, 'n'); if(status == false) { eigval.reset(); arma_bad("eig_gen(): failed to converge", false); } return status; } //! Eigenvalues of general complex square matrix X template inline bool eig_gen ( Col< std::complex >& eigval, const Base< std::complex, T1>& X, const typename arma_blas_type_only< std::complex >::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Mat< std::complex > l_eigvec; Mat< std::complex > r_eigvec; const bool status = auxlib::eig_gen(eigval, l_eigvec, r_eigvec, X, 'n'); if(status == false) { eigval.reset(); arma_bad("eig_gen(): failed to converge", false); } return status; } //! Eigenvalues and eigenvectors of general real square matrix X. //! Optional argument 'side' specifies which eigenvectors should be computed: //! 'r' for right (default) and 'l' for left. template inline bool eig_gen ( Col< std::complex >& eigval, Mat< std::complex >& eigvec, const Base& X, const char side = 'r', const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); //std::cout << "real" << std::endl; arma_debug_check( ( ((void*)(&eigval)) == ((void*)(&eigvec)) ), "eig_gen(): eigval is an alias of eigvec" ); Mat dummy_eigvec; Mat tmp_eigvec; bool status; switch(side) { case 'r': status = auxlib::eig_gen(eigval, dummy_eigvec, tmp_eigvec, X, side); break; case 'l': status = auxlib::eig_gen(eigval, tmp_eigvec, dummy_eigvec, X, side); break; default: arma_stop("eig_gen(): parameter 'side' is invalid"); status = false; } if(status == false) { eigval.reset(); eigvec.reset(); arma_bad("eig_gen(): failed to converge", false); } else { const uword n = eigval.n_elem; if(n > 0) { eigvec.set_size(n,n); for(uword j=0; j >( tmp_eigvec.col(j), tmp_eigvec.col(j+1) ); // eigvec.col(j+1) = Mat< std::complex >( tmp_eigvec.col(j), -tmp_eigvec.col(j+1) ); for(uword i=0; i( tmp_eigvec.at(i,j), tmp_eigvec.at(i,j+1) ); eigvec.at(i,j+1) = std::complex( tmp_eigvec.at(i,j), -tmp_eigvec.at(i,j+1) ); } ++j; } else { // eigvec.col(i) = tmp_eigvec.col(i); for(uword i=0; i(tmp_eigvec.at(i,j), eT(0)); } } } } } return status; } //! Eigenvalues and eigenvectors of general complex square matrix X //! Optional argument 'side' specifies which eigenvectors should be computed: //! 'r' for right (default) and 'l' for left. template inline bool eig_gen ( Col >& eigval, Mat >& eigvec, const Base, T1>& X, const char side = 'r', const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); //std::cout << "complex" << std::endl; arma_debug_check( ( ((void*)(&eigval)) == ((void*)(&eigvec)) ), "eig_gen(): eigval is an alias of eigvec" ); Mat< std::complex > dummy_eigvec; bool status; switch(side) { case 'r': status = auxlib::eig_gen(eigval, dummy_eigvec, eigvec, X, side); break; case 'l': status = auxlib::eig_gen(eigval, eigvec, dummy_eigvec, X, side); break; default: arma_stop("eig_gen(): parameter 'side' is invalid"); status = false; } if(status == false) { eigval.reset(); eigvec.reset(); arma_bad("eig_gen(): failed to converge", false); } return status; } //! Eigenvalues and eigenvectors (both left and right) of general real/complex square matrix X //! NOTE: DO NOT USE THIS FUNCTION; it is kept ONLY for compatibility with old user code template arma_deprecated inline bool eig_gen ( Col< std::complex >& eigval, Mat& l_eigvec, Mat& r_eigvec, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check ( ((&l_eigvec) == (&r_eigvec)), "eig_gen(): l_eigvec is an alias of r_eigvec" ); arma_debug_check ( ( (((void*)(&eigval)) == ((void*)(&l_eigvec))) || (((void*)(&eigval)) == ((void*)(&r_eigvec))) ), "eig_gen(): eigval is an alias of l_eigvec or r_eigvec" ); const bool status = auxlib::eig_gen(eigval, l_eigvec, r_eigvec, X, 'b'); if(status == false) { eigval.reset(); l_eigvec.reset(); r_eigvec.reset(); arma_bad("eig_gen(): failed to converge", false); } return status; } //! @} RcppArmadillo/inst/include/armadillo_bits/operator_cube_relational.hpp0000644000176000001440000001423412177612753026213 0ustar ripleyusers// Copyright (C) 2009-2010 Conrad Sanderson // Copyright (C) 2009-2010 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup operator_cube_relational //! @{ // < : lt // > : gt // <= : lteq // >= : gteq // == : eq // != : noteq template inline const mtGlueCube operator< (const BaseCube::result,T1>& X, const BaseCube::result,T2>& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator> (const BaseCube::result,T1>& X, const BaseCube::result,T2>& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator<= (const BaseCube::result,T1>& X, const BaseCube::result,T2>& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator>= (const BaseCube::result,T1>& X, const BaseCube::result,T2>& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator== (const BaseCube& X, const BaseCube& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator!= (const BaseCube& X, const BaseCube& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } // // // template inline const mtOpCube operator< (const typename arma_not_cx::result val, const BaseCube::result,T1>& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator< (const BaseCube::result,T1>& X, const typename arma_not_cx::result val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator> (const typename arma_not_cx::result val, const BaseCube::result,T1>& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator> (const BaseCube::result,T1>& X, const typename arma_not_cx::result val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator<= (const typename arma_not_cx::result val, const BaseCube::result,T1>& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator<= (const BaseCube::result,T1>& X, const typename arma_not_cx::result val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator>= (const typename arma_not_cx::result val, const BaseCube::result,T1>& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator>= (const BaseCube::result,T1>& X, const typename arma_not_cx::result val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator== (const typename T1::elem_type val, const BaseCube& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator== (const BaseCube& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator!= (const typename T1::elem_type val, const BaseCube& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator!= (const BaseCube& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } //! @} RcppArmadillo/inst/include/RcppArmadilloConfig.h0000644000176000001440000000531312253723621021470 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // RcppArmadilloConfig.h: Rcpp/Armadillo glue // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RcppArmadillo__RcppArmadilloConfig__h #define RcppArmadillo__RcppArmadilloConfig__h #if !defined(ARMA_USE_LAPACK) #define ARMA_USE_LAPACK #endif #if !defined(ARMA_USE_BLAS) #define ARMA_USE_BLAS #endif #define ARMA_HAVE_STD_ISFINITE #define ARMA_HAVE_STD_ISINF #define ARMA_HAVE_STD_ISNAN #define ARMA_HAVE_STD_SNPRINTF /* TODO: we might need to undef this on other platforms as well */ #if defined(__GNUC__) && defined(_WIN64) || defined(__FreeBSD__) #undef ARMA_HAVE_STD_SNPRINTF #endif /* suncc does not have std::isfinite (which is not standard) so we tell armadillo not to use it, and comment out a few others while we are at it */ #if defined(__SUNPRO_CC) #undef ARMA_HAVE_STD_ISFINITE #undef ARMA_HAVE_STD_SNPRINTF #undef ARMA_HAVE_LOG1P #undef ARMA_HAVE_STD_ISINF #undef ARMA_HAVE_STD_ISNAN #endif // Let's be careful for now and undef this as not all compilers support this #if defined(ARMA_USE_CXX11) #undef ARMA_USE_CXX11 #endif // Rcpp has its own stream object which cooperates more nicely with R's i/o // And as of Armadillo 2.4.3, we can use this stream object as well #if !defined(ARMA_DEFAULT_OSTREAM) #define ARMA_DEFAULT_OSTREAM Rcpp::Rcout #endif // R now defines NDEBUG which suppresses a number of useful Armadillo tests // Users can still defined it later, and/or define ARMA_NO_DEBUG #if defined(NDEBUG) #undef NDEBUG #endif // R can be built with its own Rlapack library, or use an external // one. Only the latter has zgesdd, a complex-valued SVD using divide-and-conquer #ifdef WIN32 // on Windows we do not assume ZGESDD #define ARMA_DONT_USE_CX_GESDD 1 #else // on the other OSs we test via LAPACK_LIBS (in configure) which // updates this include file #include #endif #endif RcppArmadillo/inst/include/RcppArmadillo/0000755000176000001440000000000012267661346020201 5ustar ripleyusersRcppArmadillo/inst/include/RcppArmadillo/Row_meat.h0000644000176000001440000000320612253723621022116 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // Row_meat.h: Rcpp/Armadillo glue // // Copyright (C) 2011 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RCPPARMADILLO_ROW_MEAT_H #define RCPPARMADILLO_ROW_MEAT_H template template inline Row::Row( const Rcpp::VectorBase& X ) : Mat( X ) { arma_extra_debug_sigprint(this); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 2; } template template inline Row::Row( const Rcpp::MatrixBase& X ) : Mat( X ) { arma_extra_debug_sigprint(this); arma_debug_check( (Mat::n_rows > 1), "Row(): incompatible dimensions" ); access::rw(Mat::vec_state) = 2; } #endif RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h0000644000176000001440000001073012253723621022070 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // Mat_meat.h: Rcpp/Armadillo glue // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RCPPARMADILLO_MAT_MEAT_H #define RCPPARMADILLO_MAT_MEAT_H namespace RcppArmadillo{ template inline void check(){ #if !defined(ARMA_USE_CXX11) arma_type_check_cxx1998< is_same_type< eT, rcpp_type >::value == false >::apply(); #else static_assert( is_same_type< eT, rcpp_type >::value , "error: incorrect or unsupported type" ); #endif } template <> inline void check< std::complex, Rcomplex >(){} template inline void fill_ptr__impl( eT* ptr, const Rcpp::VectorBase& X, u32 n_elem, ::Rcpp::traits::true_type ){ for( u32 i=0; i::type, eT>( X[i] ) ; } } template inline void fill_ptr__impl( eT* ptr, const Rcpp::VectorBase& X, u32 n_elem, ::Rcpp::traits::false_type ){ for( u32 i=0; i inline void fill_ptr( eT* ptr, const Rcpp::VectorBase& X, u32 n_elem ){ return fill_ptr__impl( ptr, X, n_elem, typename ::Rcpp::traits::r_sexptype_needscast() ) ; } template inline void fill_ptr_matrix__impl( eT* ptr, const Rcpp::MatrixBase& X, u32 nr, u32 nc, ::Rcpp::traits::true_type ){ u32 k, i_col, i_row ; for( i_col=0, k=0 ; i_col < nc; ++i_col){ for( i_row = 0; i_row < nr ; ++i_row, ++k ){ ptr[k] = Rcpp::internal::caster< typename Rcpp::traits::storage_type::type, eT>( X(i_row,i_col)) ; } } } template inline void fill_ptr_matrix__impl( eT* ptr, const Rcpp::MatrixBase& X, u32 nr, u32 nc, ::Rcpp::traits::false_type ){ u32 k, i_col, i_row ; for( i_col=0, k=0 ; i_col < nc; ++i_col){ for( i_row = 0; i_row < nr ; ++i_row, ++k ){ ptr[k] = X(i_row,i_col) ; } } } template inline void fill_ptr_matrix( eT* ptr, const Rcpp::MatrixBase& X, u32 nr, u32 nc){ return fill_ptr_matrix__impl( ptr, X, nr, nc, typename ::Rcpp::traits::r_sexptype_needscast() ) ; } } template template inline Mat::Mat( const Rcpp::VectorBase& X ) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem(0) { arma_extra_debug_sigprint_this(this); RcppArmadillo::check::type >() ; set_size(X.size(), 1); RcppArmadillo::fill_ptr( memptr(), X, n_elem ) ; } template template inline Mat::Mat( const Rcpp::MatrixBase& X ) : n_rows( 0 ) , n_cols( 0 ) , n_elem( 0 ) , vec_state(0) , mem_state(0) , mem(0) { arma_extra_debug_sigprint_this(this); RcppArmadillo::check::type >() ; u32 nr = X.nrow(), nc = X.ncol() ; set_size( nr, nc ) ; RcppArmadillo::fill_ptr_matrix( memptr(), X, nr, nc ); } #endif RcppArmadillo/inst/include/RcppArmadillo/Mat_proto.h0000644000176000001440000000237012253723621022306 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // Mat_proto.h: Rcpp/Armadillo glue // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RCPPARMADILLO_MAT_PROTO_H #define RCPPARMADILLO_MAT_PROTO_H template inline Mat( const Rcpp::VectorBase& X ) ; template inline Mat( const Rcpp::MatrixBase& X ) ; #endif RcppArmadillo/inst/include/RcppArmadillo/Col_meat.h0000644000176000001440000000312112253723621022060 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // Col_meat.h: Rcpp/Armadillo glue // // Copyright (C) 2011 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RCPPARMADILLO_COL_MEAT_H #define RCPPARMADILLO_COL_MEAT_H template template inline Col::Col( const Rcpp::VectorBase& X ) : Mat( X ) { arma_extra_debug_sigprint(this); access::rw(Mat::vec_state) = 1; } template template inline Col::Col( const Rcpp::MatrixBase& X ) : Mat( X ) { arma_extra_debug_sigprint(this); arma_debug_check( (Mat::n_cols > 1), "Col(): incompatible dimensions" ); access::rw(Mat::vec_state) = 1; } #endif RcppArmadillo/inst/include/RcppArmadillo/Row_proto.h0000644000176000001440000000237012253723621022334 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // Row_proto.h: Rcpp/Armadillo glue // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RCPPARMADILLO_ROW_PROTO_H #define RCPPARMADILLO_ROW_PROTO_H template inline Row( const Rcpp::VectorBase& X ) ; template inline Row( const Rcpp::MatrixBase& X ) ; #endif RcppArmadillo/inst/include/RcppArmadillo/Col_proto.h0000644000176000001440000000237012253723621022302 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // Col_proto.h: Rcpp/Armadillo glue // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RCPPARMADILLO_COL_PROTO_H #define RCPPARMADILLO_COL_PROTO_H template inline Col( const Rcpp::VectorBase& X ) ; template inline Col( const Rcpp::MatrixBase& X ) ; #endif RcppArmadillo/inst/include/RcppArmadilloForward.h0000644000176000001440000001066112253723621021671 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // RcppArmadilloForward.h: Rcpp/Armadillo glue // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RcppArmadillo__RcppArmadilloForward__h #define RcppArmadillo__RcppArmadilloForward__h #include #include #include #define ARMA_EXTRA_MAT_PROTO RcppArmadillo/Mat_proto.h #define ARMA_EXTRA_MAT_MEAT RcppArmadillo/Mat_meat.h #define ARMA_EXTRA_COL_PROTO RcppArmadillo/Col_proto.h #define ARMA_EXTRA_COL_MEAT RcppArmadillo/Col_meat.h #define ARMA_EXTRA_ROW_PROTO RcppArmadillo/Row_proto.h #define ARMA_EXTRA_ROW_MEAT RcppArmadillo/Row_meat.h #include /* forward declarations */ namespace Rcpp { /* support for wrap */ template SEXP wrap ( const arma::Mat& ) ; template SEXP wrap ( const arma::Row& ) ; template SEXP wrap ( const arma::Col& ) ; template SEXP wrap ( const arma::field& ) ; template SEXP wrap ( const arma::Cube& ) ; template SEXP wrap ( const arma::subview& ) ; template SEXP wrap ( const arma::SpMat& ) ; template SEXP wrap(const arma::Glue& X ) ; template SEXP wrap(const arma::Op& X ) ; template SEXP wrap(const arma::eGlue& X ) ; template SEXP wrap(const arma::eOp& X ) ; template SEXP wrap(const arma::OpCube& X ) ; template SEXP wrap(const arma::GlueCube& X ) ; template SEXP wrap(const arma::eOpCube& X ) ; template SEXP wrap(const arma::eGlueCube& X ) ; template SEXP wrap( const arma::mtOp& X ) ; template SEXP wrap( const arma::mtGlue& X ); template SEXP wrap( const arma::Gen& X) ; template SEXP wrap( const arma::GenCube& X) ; namespace traits { /* support for as */ template class Exporter< arma::Mat > ; template class Exporter< arma::Row > ; template class Exporter< arma::Col > ; template class Exporter< arma::SpMat > ; // template class Exporter< arma::field > ; // template class Exporter< arma::Cube > ; } // namespace traits template class ConstReferenceInputParameter< arma::Mat > ; template class ReferenceInputParameter< arma::Mat > ; template class ConstInputParameter< arma::Mat > ; template class ConstReferenceInputParameter< arma::Col > ; template class ReferenceInputParameter< arma::Col > ; template class ConstInputParameter< arma::Col > ; template class ConstReferenceInputParameter< arma::Row > ; template class ReferenceInputParameter< arma::Row > ; template class ConstInputParameter< arma::Row > ; } #endif RcppArmadillo/inst/include/RcppArmadilloSugar.h0000644000176000001440000000240012253723621021336 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // RcppArmadilloSugar.h: Rcpp/Armadillo glue // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RcppArmadillo__RcppArmadilloSugar__h #define RcppArmadillo__RcppArmadilloSugar__h namespace Rcpp{ // forward is not needed anymore, but we just leave this // for backwards compatibility template inline const T& forward(const T& x) { return x; } } // Rcpp #endif RcppArmadillo/inst/include/README0000644000176000001440000000035012253723621016314 0ustar ripleyusersto upgrade to a new release of armadillo: - copy the armadillo file here - replace the armadillo_bits directory by the one from the armadillo source - ignore (or remove) armadillo_bits/config.hpp.cmake as we do not configuration RcppArmadillo/inst/include/RcppArmadilloWrap.h0000644000176000001440000002510112253723621021171 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // RcppArmadilloWrap.h: Rcpp/Armadillo glue // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RcppArmadillo__RcppArmadilloWrap__h #define RcppArmadillo__RcppArmadilloWrap__h namespace Rcpp{ namespace RcppArmadillo{ template SEXP arma_wrap( const T& object, const ::Rcpp::Dimension& dim){ ::Rcpp::RObject x = ::Rcpp::wrap( object.memptr() , object.memptr() + object.n_elem ) ; x.attr( "dim" ) = dim ; return x; } // DE 03-Aug-2013 // here is an alternate form which would not set dimension which we could do // for row and column vectors -- but the current form of return row and col // as matrix types with one col (or row, respectively) is now entrenched template SEXP arma_wrap(const T& object) { return ::Rcpp::wrap(object.memptr() , object.memptr() + object.n_elem); } template SEXP arma_subview_wrap( const arma::subview& data, int nrows, int ncols ){ const int RTYPE = Rcpp::traits::r_sexptype_traits::rtype ; Rcpp::Matrix mat( nrows, ncols ) ; for( int j=0, k=0; j SEXP wrap ( const arma::Mat& data ){ return RcppArmadillo::arma_wrap( data, Dimension( data.n_rows, data.n_cols ) ) ; } template SEXP wrap( const arma::Col& data ){ return RcppArmadillo::arma_wrap( data, Dimension( data.n_elem, 1) ) ; } template SEXP wrap( const arma::Row& data ){ return RcppArmadillo::arma_wrap(data, Dimension( 1, data.n_elem ) ) ; } template SEXP wrap( const arma::Cube& data ){ return RcppArmadillo::arma_wrap(data, Dimension( data.n_rows, data.n_cols, data.n_slices ) ) ; } template SEXP wrap( const arma::subview& data ){ return RcppArmadillo::arma_subview_wrap( data, data.n_rows, data.n_cols ) ; } template SEXP wrap ( const arma::SpMat& sm ){ const int RTYPE = Rcpp::traits::r_sexptype_traits::rtype; IntegerVector dim = IntegerVector::create( sm.n_rows, sm.n_cols ); // copy the data into R objects Vector x(sm.values, sm.values + sm.n_nonzero ) ; IntegerVector i(sm.row_indices, sm.row_indices + sm.n_nonzero); IntegerVector p(sm.col_ptrs, sm.col_ptrs + sm.n_cols+1 ) ; std::string klass ; switch( RTYPE ){ case REALSXP: klass = "dgCMatrix" ; break ; // case INTSXP : klass = "igCMatrix" ; break ; class not exported case LGLSXP : klass = "lgCMatrix" ; break ; default: throw std::invalid_argument( "RTYPE not matched in conversion to sparse matrix" ) ; } S4 s(klass); s.slot("i") = i; s.slot("p") = p; s.slot("x") = x; s.slot("Dim") = dim; return s; } namespace RcppArmadillo { /* Importer class for field */ template class FieldImporter { public: typedef T r_import_type ; FieldImporter( const arma::field& data_ ) : data(data_){} inline int size() const { return data.n_elem ; } inline T get(int i) const { return data[i] ; } inline SEXP wrap( int i) const { return ::Rcpp::wrap( data[i] ) ; } private: const arma::field& data ; } ; } // namespace RcppArmadillo template SEXP wrap( const arma::field& data){ RObject x = wrap( RcppArmadillo::FieldImporter( data ) ) ; x.attr("dim" ) = Dimension( data.n_rows, data.n_cols ) ; return x ; } /* TODO: maybe we could use the advanced constructor to avoid creating the temporary Mat */ template SEXP wrap(const arma::Glue& X ){ return wrap( arma::Mat(X) ) ; } template SEXP wrap(const arma::Op& X ){ return wrap( arma::Mat(X) ) ; } template SEXP wrap(const arma::OpCube& X ){ return wrap( arma::Cube(X) ) ; } template SEXP wrap(const arma::GlueCube& X ){ return wrap( arma::Cube(X) ) ; } template SEXP wrap(const arma::GenCube& X){ return wrap( arma::Cube( X ) ) ; } namespace RcppArmadillo{ /* we can intercept and directly build the resulting matrix using memory allocated by R */ template SEXP wrap_eglue( const arma::eGlue& X, ::Rcpp::traits::false_type ){ int n_rows = X.P1.get_n_rows() ; int n_cols = X.P1.get_n_cols() ; typedef typename ::Rcpp::Vector< ::Rcpp::traits::r_sexptype_traits< typename T1::elem_type>::rtype > VECTOR ; VECTOR res(::Rcpp::Dimension( n_rows , n_cols )) ; ::arma::Mat result( res.begin(), n_rows, n_cols, false ) ; result = X ; return res ; } template SEXP wrap_eglue( const arma::eGlue& X, ::Rcpp::traits::true_type ){ return ::Rcpp::wrap( arma::Mat(X) ) ; } template SEXP wrap_eop( const arma::eOp& X, ::Rcpp::traits::false_type ){ int n_rows = X.get_n_rows(); int n_cols = X.get_n_cols(); typedef typename ::Rcpp::Vector< ::Rcpp::traits::r_sexptype_traits< typename T1::elem_type>::rtype > VECTOR ; VECTOR res(::Rcpp::Dimension( n_rows , n_cols )) ; ::arma::Mat result( res.begin(), n_rows, n_cols, false ) ; result = X ; return res ; } template SEXP wrap_eop( const arma::eOp& X, ::Rcpp::traits::true_type ){ return ::Rcpp::wrap( arma::Mat(X) ) ; } // template // SEXP wrap_mtop( const arma::mtOp& X, ::Rcpp::traits::false_type ){ // // int n_rows = X.P.n_rows ; // // int n_cols = X.P.n_cols ; // // typedef typename ::Rcpp::Vector< ::Rcpp::traits::r_sexptype_traits< typename T1::elem_type>::rtype > VECTOR ; // // VECTOR res(::Rcpp::Dimension( n_rows , n_cols )) ; // // ::arma::Mat result( res.begin(), n_rows, n_cols, false ) ; // // result = X ; // // return res ; // return ::Rcpp::wrap( arma::Mat(X) ) ; // } // // template // SEXP wrap_mtop( const arma::mtOp& X, ::Rcpp::traits::true_type ){ // return ::Rcpp::wrap( arma::Mat(X) ) ; // } // // template // SEXP wrap_mtglue( const arma::mtGlue& X, ::Rcpp::traits::false_type ){ // // int n_rows = X.P1.n_rows ; // // int n_cols = X.P1.n_cols ; // // typedef typename ::Rcpp::Vector< ::Rcpp::traits::r_sexptype_traits< typename T1::elem_type>::rtype > VECTOR ; // // VECTOR res(::Rcpp::Dimension( n_rows , n_cols )) ; // // ::arma::Mat result( res.begin(), n_rows, n_cols, false ) ; // // result = X ; // // return res ; // return ::Rcpp::wrap( arma::Mat(X) ) ; // } // // template // SEXP wrap_mtglue( const arma::mtGlue& X , ::Rcpp::traits::true_type ){ // return ::Rcpp::wrap( arma::Mat(X) ) ; // } } // namespace RcppArmadillo template SEXP wrap(const arma::eGlue& X ){ return RcppArmadillo::wrap_eglue( X, typename traits::r_sexptype_needscast::type() ) ; } template SEXP wrap(const arma::eOp& X ){ return RcppArmadillo::wrap_eop( X, typename traits::r_sexptype_needscast::type() ) ; } template SEXP wrap(const arma::eOpCube& X ){ return wrap( arma::Cube(X) ) ; } template SEXP wrap(const arma::eGlueCube& X ){ return wrap( arma::Cube(X) ) ; } template SEXP wrap( const arma::mtOp& X ){ // return RcppArmadillo::wrap_mtop( X, typename traits::r_sexptype_needscast::type() ) ; return wrap( arma::Mat( X ) ) ; } template SEXP wrap( const arma::mtGlue& X ){ // return RcppArmadillo::wrap_mtglue( X, typename traits::r_sexptype_needscast::type() ) ; return wrap( arma::Mat( X ) ) ; } template SEXP wrap( const arma::Gen& X){ return wrap( eT(X) ) ; } } #endif RcppArmadillo/inst/include/RcppArmadilloExtensions/0000755000176000001440000000000012253723621022247 5ustar ripleyusersRcppArmadillo/inst/include/RcppArmadilloExtensions/sample.h0000644000176000001440000001715012253723621023705 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // sample.cpp: Rcpp/Armadillo equivalent to R's sample(). // This is to be used in C++ functions, and should *not* be called from R. // It should yield identical results to R in most cases // (note that Walker's alias method is not implemented). // // Copyright (C) 2012 - 2013 Christian Gunning // Copyright (C) 2013 Romain Francois // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RCPPARMADILLO__EXTENSIONS__SAMPLE_H #define RCPPARMADILLO__EXTENSIONS__SAMPLE_H #include namespace Rcpp{ namespace RcppArmadillo{ //Declarations template void SampleReplace( INDEX &index, int nOrig, int size); template void SampleNoReplace( INDEX &index, int nOrig, int size); template void ProbSampleReplace(INDEX &index, int nOrig, int size, arma::vec &prob); template void ProbSampleNoReplace(INDEX &index, int nOrig, int size, arma::vec &prob); template void FixProb(PROB &prob, int size, bool replace); template T sample(const T &x, const int size, const bool replace, NumericVector prob_ = NumericVector(0) ) { // Templated sample -- should work on any Rcpp Vector int ii, jj; int nOrig = x.size(); int probsize = prob_.size(); // Create return object T ret(size); if ( size > nOrig && !replace) throw std::range_error( "Tried to sample more elements than in x without replacement" ) ; // Store the sample ids here, modify in-place IntegerVector index(size); if (probsize == 0) { // No probabilities given if (replace) { SampleReplace(index, nOrig, size); } else { SampleNoReplace(index, nOrig, size); } } else { if (probsize != nOrig) throw std::range_error( "Number of probabilities must equal input vector length" ) ; // normalize, error-check probability vector // fixprob will be modified in-place NumericVector fixprob = clone(prob_); FixProb(fixprob, size, replace); // // Copy the given probabilities into an arma vector arma::vec prob(fixprob.begin(), fixprob.size()); if (replace) { // check for walker alias conditions int walker_test = sum( (probsize * prob) > 0.1); if (walker_test < 200) { ProbSampleReplace(index, nOrig, size, prob); } else { throw std::range_error( "Walker Alias method not implemented. R-core sample() is likely faster for this problem."); // WalkerProbSampleReplace(index, nOrig, size, prob); } } else { ProbSampleNoReplace(index, nOrig, size, prob); } } // copy the results into the return vector for (ii=0; ii void SampleReplace( INDEX &index, int nOrig, int size) { int ii; for (ii = 0; ii < size; ii++) { index[ii] = nOrig * unif_rand(); } } template void SampleNoReplace( INDEX &index, int nOrig, int size) { int ii, jj; IntegerVector sub(nOrig); for (ii = 0; ii < nOrig; ii++) { sub[ii] = ii; } for (ii = 0; ii < size; ii++) { jj = nOrig * unif_rand(); index[ii] = sub[jj]; // replace sampled element with last, decrement sub[jj] = sub[--nOrig]; } } template void FixProb(PROB &prob, const int size, const bool replace) { // prob is modified in-place. // Is this better than cloning it? double sum = 0.0; int ii, nPos = 0; int nn = prob.size(); for (ii = 0; ii < nn; ii++) { if (!R_FINITE(prob[ii])) //does this work?? throw std::range_error( "NAs not allowed in probability" ) ; if (prob[ii] < 0.0) throw std::range_error( "Negative probabilities not allowed" ) ; if (prob[ii] > 0.0) { nPos++; sum += prob[ii]; } } if (nPos == 0 || (!replace && size > nPos)) { throw std::range_error("Not enough positive probabilities"); } prob = prob / sum; //sugar } // Unequal probability sampling with replacement template void ProbSampleReplace(INDEX &index, int nOrig, int size, arma::vec &prob){ double rU; int ii, jj; int nOrig_1 = nOrig - 1; arma::uvec perm = arma::sort_index(prob, 1); //descending sort of index prob = arma::sort(prob, 1); // descending sort of prob // cumulative probabilities prob = arma::cumsum(prob); // compute the sample for (ii = 0; ii < size; ii++) { rU = unif_rand(); for (jj = 0; jj < nOrig_1; jj++) { if (rU <= prob[jj]) break; } index[ii] = perm[jj]; } } // Unequal probability sampling without replacement template void ProbSampleNoReplace(INDEX &index, int nOrig, int size, arma::vec &prob){ int ii, jj, kk; int nOrig_1 = nOrig - 1; double rT, mass, totalmass = 1.0; arma::uvec perm = arma::sort_index(prob, 1); //descending sort of index prob = arma::sort(prob, 1); // descending sort of prob // compute the sample for (ii = 0; ii < size; ii++, nOrig_1--) { rT = totalmass * unif_rand(); mass = 0; for (jj = 0; jj < nOrig_1; jj++) { mass += prob[jj]; if (rT <= mass) break; } index[ii] = perm[jj]; totalmass -= prob[jj]; for ( kk = jj; kk < nOrig_1; kk++) { prob[kk] = prob[kk+1]; perm[kk] = perm[kk+1]; } } } } } #endif RcppArmadillo/inst/include/RcppArmadilloAs.h0000644000176000001440000001546312253723621020635 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // RcppArmadilloAs.h: Rcpp/Armadillo glue, support for as // // Copyright (C) 2013 Dirk Eddelbuettel and Romain Francois // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RcppArmadillo__RcppArmadilloAs__h #define RcppArmadillo__RcppArmadilloAs__h namespace Rcpp{ namespace traits { template class Exporter< arma::Col > : public IndexingExporter< arma::Col, T > { public: Exporter(SEXP x) : IndexingExporter< arma::Col, T >(x){} }; template class Exporter< arma::Row > : public IndexingExporter< arma::Row, T > { public: Exporter(SEXP x) : IndexingExporter< arma::Row, T >(x){} }; template class Exporter< arma::Mat > : public MatrixExporter< arma::Mat, T > { public: Exporter(SEXP x) : MatrixExporter< arma::Mat, T >(x){} }; template class Exporter< const arma::Mat& > { public: typedef typename Rcpp::Matrix< Rcpp::traits::r_sexptype_traits::rtype > MATRIX ; Exporter(SEXP x) : mat(x) {} inline arma::Mat* get(){ return new arma::Mat( mat.begin(), mat.nrow(), mat.ncol(), false ) ; } private: MATRIX mat ; }; template class Exporter< arma::SpMat > { public: Exporter( SEXP x ) : mat(x){} arma::SpMat get(){ const int RTYPE = Rcpp::traits::r_sexptype_traits::rtype; IntegerVector dims = mat.slot("Dim"); IntegerVector i = mat.slot("i") ; IntegerVector p = mat.slot("p") ; Vector x = mat.slot("x") ; arma::SpMat res(dims[0], dims[1]); // create space for values, and copy arma::access::rw(res.values) = arma::memory::acquire_chunked(x.size() + 1); arma::arrayops::copy(arma::access::rwp(res.values), x.begin(), x.size() + 1); // create space for row_indices, and copy arma::access::rw(res.row_indices) = arma::memory::acquire_chunked(i.size() + 1); std::copy( i.begin(), i.end(), arma::access::rwp(res.row_indices) ) ; // create space for col_ptrs, and copy arma::access::rw(res.col_ptrs) = arma::memory::acquire(p.size() + 2); std::copy(p.begin(), p.end(), arma::access::rwp(res.col_ptrs) ); // important: set the sentinel as well arma::access::rwp(res.col_ptrs)[p.size()+1] = std::numeric_limits::max(); // set the number of non-zero elements arma::access::rw(res.n_nonzero) = x.size(); return res; } private: S4 mat ; } ; } template class ConstReferenceInputParameter< arma::Mat > { public: typedef const typename arma::Mat& const_reference ; ConstReferenceInputParameter( SEXP x_ ) : m(x_), mat( reinterpret_cast( m.begin() ), m.nrow(), m.ncol(), false ){} inline operator const_reference(){ return mat ; } private: Rcpp::Matrix< Rcpp::traits::r_sexptype_traits::rtype > m ; arma::Mat mat ; } ; template class ReferenceInputParameter< arma::Mat > { public: typedef typename arma::Mat& reference ; ReferenceInputParameter( SEXP x_ ) : m(x_), mat( reinterpret_cast( m.begin() ), m.nrow(), m.ncol(), false ){} inline operator reference(){ return mat ; } private: Rcpp::Matrix< Rcpp::traits::r_sexptype_traits::rtype > m ; arma::Mat mat ; } ; template class ConstInputParameter< arma::Mat > { public: typedef const typename arma::Mat const_nonref; ConstInputParameter(SEXP x_) : m(x_), mat( reinterpret_cast( m.begin() ), m.nrow(), m.ncol(), false){} inline operator const_nonref() { return mat ; } private: Rcpp::Matrix< Rcpp::traits::r_sexptype_traits::rtype > m ; arma::Mat mat ; }; template class ArmaVec_InputParameter { public: ArmaVec_InputParameter( SEXP x_ ) : v(x_), vec( reinterpret_cast( v.begin() ), v.size(), false ){} inline operator REF(){ return vec ; } private: Rcpp::Vector< Rcpp::traits::r_sexptype_traits::rtype > v ; VEC vec ; } ; #define MAKE_INPUT_PARAMETER(INPUT_TYPE,TYPE,REF) \ template \ class INPUT_TYPE : public ArmaVec_InputParameter{ \ public: \ INPUT_TYPE( SEXP x) : ArmaVec_InputParameter(x){} \ } ; MAKE_INPUT_PARAMETER(ConstReferenceInputParameter, arma::Col, const arma::Col& ) MAKE_INPUT_PARAMETER(ReferenceInputParameter , arma::Col, arma::Col& ) MAKE_INPUT_PARAMETER(ConstInputParameter , arma::Col, const arma::Col ) MAKE_INPUT_PARAMETER(ConstReferenceInputParameter, arma::Row, const arma::Row& ) MAKE_INPUT_PARAMETER(ReferenceInputParameter , arma::Row, arma::Row& ) MAKE_INPUT_PARAMETER(ConstInputParameter , arma::Row, const arma::Row ) #undef MAKE_INPUT_PARAMETER } #endif RcppArmadillo/inst/include/RcppArmadillo.h0000644000176000001440000000417112253723621020343 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ // // RcppArmadillo.h: Rcpp/Armadillo glue // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RcppArmadillo__RcppArmadillo__h #define RcppArmadillo__RcppArmadillo__h #if defined(Rcpp_hpp) && !defined(COMPILING_RCPPARMADILLO) #error "The file 'Rcpp.h' should not be included. Please correct to include only 'RcppArmadillo.h'." #endif #include #include #include #include #include /* ZGESDD - compute the singular value decomposition (SVD); of a */ /* complex M-by-N matrix A, optionally computing the left and/or */ /* right singular vectors. If singular vectors are desired, it uses a */ /* divide-and-conquer algorithm. */ // namespace { // extern "C" void F77_NAME(zgesdd)(const char *jobz, const int *m, const int *n, // Rcomplex *a, const int *lda, double *s, // Rcomplex *u, const int *ldu, // Rcomplex *vt, const int *ldvt, // Rcomplex *work, const int *lwork, // double *rwork, // int *iwork, int *info); // } #endif RcppArmadillo/inst/include/armadillo0000644000176000001440000004665212262264315017342 0ustar ripleyusers// Copyright (C) 2008-2014 Conrad Sanderson // Copyright (C) 2008-2014 NICTA (www.nicta.com.au) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifndef ARMA_INCLUDES #define ARMA_INCLUDES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if ( defined(__unix__) || defined(__unix) || defined(_POSIX_C_SOURCE) || (defined(__APPLE__) && defined(__MACH__)) ) && !defined(_WIN32) #include #endif #if (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) #include #endif #include "armadillo_bits/config.hpp" #include "armadillo_bits/compiler_setup.hpp" #if defined(ARMA_USE_CXX11) #include #include #include #include #endif #if defined(ARMA_USE_TBB_ALLOC) #include #endif #if defined(ARMA_USE_MKL_ALLOC) #include #endif #if !defined(ARMA_USE_CXX11) #if defined(ARMA_HAVE_TR1) #include #include #endif #endif #include "armadillo_bits/include_atlas.hpp" #if defined(ARMA_USE_HDF5) #include #endif //! \namespace arma namespace for Armadillo classes and functions namespace arma { // preliminaries #include "armadillo_bits/forward_bones.hpp" #include "armadillo_bits/arma_static_check.hpp" #include "armadillo_bits/typedef_elem.hpp" #include "armadillo_bits/typedef_elem_check.hpp" #include "armadillo_bits/typedef_mat.hpp" #include "armadillo_bits/arma_boost.hpp" #include "armadillo_bits/arma_version.hpp" #include "armadillo_bits/arma_config.hpp" #include "armadillo_bits/traits.hpp" #include "armadillo_bits/promote_type.hpp" #include "armadillo_bits/upgrade_val.hpp" #include "armadillo_bits/restrictors.hpp" #include "armadillo_bits/access.hpp" #include "armadillo_bits/span.hpp" #include "armadillo_bits/distr_param.hpp" #include "armadillo_bits/constants.hpp" #include "armadillo_bits/constants_compat.hpp" #if defined(ARMA_USE_CXX11_RNG) #include "armadillo_bits/arma_rng_cxx11.hpp" #include "armadillo_bits/arma_rng.hpp" #else #include "armadillo_bits/arma_rng_cxx98.hpp" #include "armadillo_bits/arma_rng.hpp" #endif // // class prototypes #include "armadillo_bits/Base_bones.hpp" #include "armadillo_bits/BaseCube_bones.hpp" #include "armadillo_bits/SpBase_bones.hpp" #include "armadillo_bits/blas_bones.hpp" #include "armadillo_bits/lapack_bones.hpp" #include "armadillo_bits/atlas_bones.hpp" #include "armadillo_bits/arpack_bones.hpp" #include "armadillo_bits/blas_wrapper.hpp" #include "armadillo_bits/lapack_wrapper.hpp" #include "armadillo_bits/atlas_wrapper.hpp" #include "armadillo_bits/arpack_wrapper.hpp" #include "armadillo_bits/cond_rel_bones.hpp" #include "armadillo_bits/arrayops_bones.hpp" #include "armadillo_bits/podarray_bones.hpp" #include "armadillo_bits/auxlib_bones.hpp" #include "armadillo_bits/sp_auxlib_bones.hpp" #include "armadillo_bits/injector_bones.hpp" #include "armadillo_bits/Mat_bones.hpp" #include "armadillo_bits/Col_bones.hpp" #include "armadillo_bits/Row_bones.hpp" #include "armadillo_bits/Cube_bones.hpp" #include "armadillo_bits/xvec_htrans_bones.hpp" #include "armadillo_bits/SizeMat_bones.hpp" #include "armadillo_bits/SizeCube_bones.hpp" #include "armadillo_bits/SpValProxy_bones.hpp" #include "armadillo_bits/SpMat_bones.hpp" #include "armadillo_bits/SpCol_bones.hpp" #include "armadillo_bits/SpRow_bones.hpp" #include "armadillo_bits/SpSubview_bones.hpp" #include "armadillo_bits/typedef_mat_fixed.hpp" #include "armadillo_bits/field_bones.hpp" #include "armadillo_bits/subview_bones.hpp" #include "armadillo_bits/subview_elem1_bones.hpp" #include "armadillo_bits/subview_elem2_bones.hpp" #include "armadillo_bits/subview_field_bones.hpp" #include "armadillo_bits/subview_cube_bones.hpp" #include "armadillo_bits/diagview_bones.hpp" #include "armadillo_bits/subview_each_bones.hpp" #include "armadillo_bits/diskio_bones.hpp" #include "armadillo_bits/wall_clock_bones.hpp" #include "armadillo_bits/running_stat_bones.hpp" #include "armadillo_bits/running_stat_vec_bones.hpp" #include "armadillo_bits/Op_bones.hpp" #include "armadillo_bits/OpCube_bones.hpp" #include "armadillo_bits/SpOp_bones.hpp" #include "armadillo_bits/eOp_bones.hpp" #include "armadillo_bits/eOpCube_bones.hpp" #include "armadillo_bits/mtOp_bones.hpp" #include "armadillo_bits/mtOpCube_bones.hpp" #include "armadillo_bits/mtSpOp_bones.hpp" #include "armadillo_bits/Glue_bones.hpp" #include "armadillo_bits/eGlue_bones.hpp" #include "armadillo_bits/mtGlue_bones.hpp" #include "armadillo_bits/SpGlue_bones.hpp" #include "armadillo_bits/GlueCube_bones.hpp" #include "armadillo_bits/eGlueCube_bones.hpp" #include "armadillo_bits/mtGlueCube_bones.hpp" #include "armadillo_bits/eop_core_bones.hpp" #include "armadillo_bits/eglue_core_bones.hpp" #include "armadillo_bits/Gen_bones.hpp" #include "armadillo_bits/GenCube_bones.hpp" #include "armadillo_bits/op_diagmat_bones.hpp" #include "armadillo_bits/op_diagvec_bones.hpp" #include "armadillo_bits/op_dot_bones.hpp" #include "armadillo_bits/op_inv_bones.hpp" #include "armadillo_bits/op_htrans_bones.hpp" #include "armadillo_bits/op_max_bones.hpp" #include "armadillo_bits/op_min_bones.hpp" #include "armadillo_bits/op_mean_bones.hpp" #include "armadillo_bits/op_median_bones.hpp" #include "armadillo_bits/op_sort_bones.hpp" #include "armadillo_bits/op_sum_bones.hpp" #include "armadillo_bits/op_stddev_bones.hpp" #include "armadillo_bits/op_strans_bones.hpp" #include "armadillo_bits/op_var_bones.hpp" #include "armadillo_bits/op_repmat_bones.hpp" #include "armadillo_bits/op_reshape_bones.hpp" #include "armadillo_bits/op_vectorise_bones.hpp" #include "armadillo_bits/op_resize_bones.hpp" #include "armadillo_bits/op_cov_bones.hpp" #include "armadillo_bits/op_cor_bones.hpp" #include "armadillo_bits/op_shuffle_bones.hpp" #include "armadillo_bits/op_prod_bones.hpp" #include "armadillo_bits/op_pinv_bones.hpp" #include "armadillo_bits/op_dotext_bones.hpp" #include "armadillo_bits/op_flip_bones.hpp" #include "armadillo_bits/op_princomp_bones.hpp" #include "armadillo_bits/op_misc_bones.hpp" #include "armadillo_bits/op_relational_bones.hpp" #include "armadillo_bits/op_find_bones.hpp" #include "armadillo_bits/op_chol_bones.hpp" #include "armadillo_bits/op_cx_scalar_bones.hpp" #include "armadillo_bits/op_trimat_bones.hpp" #include "armadillo_bits/op_cumsum_bones.hpp" #include "armadillo_bits/op_symmat_bones.hpp" #include "armadillo_bits/op_hist_bones.hpp" #include "armadillo_bits/op_unique_bones.hpp" #include "armadillo_bits/op_toeplitz_bones.hpp" #include "armadillo_bits/op_fft_bones.hpp" #include "armadillo_bits/op_any_bones.hpp" #include "armadillo_bits/op_all_bones.hpp" #include "armadillo_bits/glue_times_bones.hpp" #include "armadillo_bits/glue_mixed_bones.hpp" #include "armadillo_bits/glue_cov_bones.hpp" #include "armadillo_bits/glue_cor_bones.hpp" #include "armadillo_bits/glue_kron_bones.hpp" #include "armadillo_bits/glue_cross_bones.hpp" #include "armadillo_bits/glue_join_bones.hpp" #include "armadillo_bits/glue_relational_bones.hpp" #include "armadillo_bits/glue_solve_bones.hpp" #include "armadillo_bits/glue_conv_bones.hpp" #include "armadillo_bits/glue_toeplitz_bones.hpp" #include "armadillo_bits/glue_hist_bones.hpp" #include "armadillo_bits/glue_histc_bones.hpp" #include "armadillo_bits/glue_max_bones.hpp" #include "armadillo_bits/glue_min_bones.hpp" #include "armadillo_bits/spop_max_bones.hpp" #include "armadillo_bits/spop_min_bones.hpp" #include "armadillo_bits/spop_sum_bones.hpp" #include "armadillo_bits/spop_strans_bones.hpp" #include "armadillo_bits/spop_htrans_bones.hpp" #include "armadillo_bits/spop_misc_bones.hpp" #include "armadillo_bits/spop_mean_bones.hpp" #include "armadillo_bits/spop_var_bones.hpp" #include "armadillo_bits/spglue_plus_bones.hpp" #include "armadillo_bits/spglue_minus_bones.hpp" #include "armadillo_bits/spglue_times_bones.hpp" // // low-level debugging and memory handling functions #include "armadillo_bits/debug.hpp" #include "armadillo_bits/memory.hpp" // // #include "armadillo_bits/arma_cmath.hpp" // // classes that underlay metaprogramming #include "armadillo_bits/unwrap.hpp" #include "armadillo_bits/unwrap_cube.hpp" #include "armadillo_bits/unwrap_spmat.hpp" #include "armadillo_bits/Proxy.hpp" #include "armadillo_bits/ProxyCube.hpp" #include "armadillo_bits/SpProxy.hpp" #include "armadillo_bits/diagmat_proxy.hpp" #include "armadillo_bits/strip.hpp" #include "armadillo_bits/Op_meat.hpp" #include "armadillo_bits/OpCube_meat.hpp" #include "armadillo_bits/SpOp_meat.hpp" #include "armadillo_bits/mtOp_meat.hpp" #include "armadillo_bits/mtOpCube_meat.hpp" #include "armadillo_bits/mtSpOp_meat.hpp" #include "armadillo_bits/Glue_meat.hpp" #include "armadillo_bits/GlueCube_meat.hpp" #include "armadillo_bits/SpGlue_meat.hpp" #include "armadillo_bits/eop_aux.hpp" #include "armadillo_bits/eOp_meat.hpp" #include "armadillo_bits/eOpCube_meat.hpp" #include "armadillo_bits/eGlue_meat.hpp" #include "armadillo_bits/eGlueCube_meat.hpp" #include "armadillo_bits/mtGlue_meat.hpp" #include "armadillo_bits/mtGlueCube_meat.hpp" #include "armadillo_bits/Base_meat.hpp" #include "armadillo_bits/BaseCube_meat.hpp" #include "armadillo_bits/SpBase_meat.hpp" #include "armadillo_bits/Gen_meat.hpp" #include "armadillo_bits/GenCube_meat.hpp" // // ostream #include "armadillo_bits/arma_ostream_bones.hpp" #include "armadillo_bits/arma_ostream_meat.hpp" // // n_unique, which is used by some sparse operators #include "armadillo_bits/fn_n_unique.hpp" // // operators #include "armadillo_bits/operator_plus.hpp" #include "armadillo_bits/operator_minus.hpp" #include "armadillo_bits/operator_times.hpp" #include "armadillo_bits/operator_schur.hpp" #include "armadillo_bits/operator_div.hpp" #include "armadillo_bits/operator_relational.hpp" #include "armadillo_bits/operator_cube_plus.hpp" #include "armadillo_bits/operator_cube_minus.hpp" #include "armadillo_bits/operator_cube_times.hpp" #include "armadillo_bits/operator_cube_schur.hpp" #include "armadillo_bits/operator_cube_div.hpp" #include "armadillo_bits/operator_cube_relational.hpp" #include "armadillo_bits/operator_ostream.hpp" // // user accessible functions // the order of the fn_*.hpp include files matters, // as some files require functionality given in preceding files #include "armadillo_bits/fn_conv_to.hpp" #include "armadillo_bits/fn_min.hpp" #include "armadillo_bits/fn_max.hpp" #include "armadillo_bits/fn_accu.hpp" #include "armadillo_bits/fn_sum.hpp" #include "armadillo_bits/fn_diagmat.hpp" #include "armadillo_bits/fn_diagvec.hpp" #include "armadillo_bits/fn_inv.hpp" #include "armadillo_bits/fn_trace.hpp" #include "armadillo_bits/fn_trans.hpp" #include "armadillo_bits/fn_det.hpp" #include "armadillo_bits/fn_log_det.hpp" #include "armadillo_bits/fn_eig_sym.hpp" #include "armadillo_bits/fn_eig_gen.hpp" #include "armadillo_bits/fn_eig_pair.hpp" #include "armadillo_bits/fn_lu.hpp" #include "armadillo_bits/fn_zeros.hpp" #include "armadillo_bits/fn_ones.hpp" #include "armadillo_bits/fn_eye.hpp" #include "armadillo_bits/fn_misc.hpp" #include "armadillo_bits/fn_find.hpp" #include "armadillo_bits/fn_elem.hpp" #include "armadillo_bits/fn_norm.hpp" #include "armadillo_bits/fn_dot.hpp" #include "armadillo_bits/fn_randu.hpp" #include "armadillo_bits/fn_randn.hpp" #include "armadillo_bits/fn_trig.hpp" #include "armadillo_bits/fn_mean.hpp" #include "armadillo_bits/fn_median.hpp" #include "armadillo_bits/fn_stddev.hpp" #include "armadillo_bits/fn_var.hpp" #include "armadillo_bits/fn_sort.hpp" #include "armadillo_bits/fn_sort_index.hpp" #include "armadillo_bits/fn_strans.hpp" #include "armadillo_bits/fn_chol.hpp" #include "armadillo_bits/fn_qr.hpp" #include "armadillo_bits/fn_svd.hpp" #include "armadillo_bits/fn_solve.hpp" #include "armadillo_bits/fn_repmat.hpp" #include "armadillo_bits/fn_reshape.hpp" #include "armadillo_bits/fn_vectorise.hpp" #include "armadillo_bits/fn_resize.hpp" #include "armadillo_bits/fn_cov.hpp" #include "armadillo_bits/fn_cor.hpp" #include "armadillo_bits/fn_shuffle.hpp" #include "armadillo_bits/fn_prod.hpp" #include "armadillo_bits/fn_eps.hpp" #include "armadillo_bits/fn_pinv.hpp" #include "armadillo_bits/fn_rank.hpp" #include "armadillo_bits/fn_kron.hpp" #include "armadillo_bits/fn_flip.hpp" #include "armadillo_bits/fn_as_scalar.hpp" #include "armadillo_bits/fn_princomp.hpp" #include "armadillo_bits/fn_cross.hpp" #include "armadillo_bits/fn_join.hpp" #include "armadillo_bits/fn_conv.hpp" #include "armadillo_bits/fn_trunc_exp.hpp" #include "armadillo_bits/fn_trunc_log.hpp" #include "armadillo_bits/fn_toeplitz.hpp" #include "armadillo_bits/fn_trimat.hpp" #include "armadillo_bits/fn_cumsum.hpp" #include "armadillo_bits/fn_symmat.hpp" #include "armadillo_bits/fn_syl_lyap.hpp" #include "armadillo_bits/fn_hist.hpp" #include "armadillo_bits/fn_histc.hpp" #include "armadillo_bits/fn_unique.hpp" #include "armadillo_bits/fn_fft.hpp" #include "armadillo_bits/fn_fft2.hpp" #include "armadillo_bits/fn_any.hpp" #include "armadillo_bits/fn_all.hpp" #include "armadillo_bits/fn_size.hpp" #include "armadillo_bits/fn_numel.hpp" #include "armadillo_bits/fn_inplace_strans.hpp" #include "armadillo_bits/fn_inplace_trans.hpp" #include "armadillo_bits/fn_randi.hpp" #include "armadillo_bits/fn_cond.hpp" #include "armadillo_bits/fn_speye.hpp" #include "armadillo_bits/fn_spones.hpp" #include "armadillo_bits/fn_sprandn.hpp" #include "armadillo_bits/fn_sprandu.hpp" #include "armadillo_bits/fn_eigs_sym.hpp" #include "armadillo_bits/fn_eigs_gen.hpp" // misc stuff #include "armadillo_bits/hdf5_misc.hpp" #include "armadillo_bits/fft_engine.hpp" // // classes implementing various forms of dense matrix multiplication #include "armadillo_bits/mul_gemv.hpp" #include "armadillo_bits/mul_gemm.hpp" #include "armadillo_bits/mul_gemm_mixed.hpp" #include "armadillo_bits/mul_syrk.hpp" #include "armadillo_bits/mul_herk.hpp" // // class meat #include "armadillo_bits/eop_core_meat.hpp" #include "armadillo_bits/eglue_core_meat.hpp" #include "armadillo_bits/cond_rel_meat.hpp" #include "armadillo_bits/arrayops_meat.hpp" #include "armadillo_bits/podarray_meat.hpp" #include "armadillo_bits/auxlib_meat.hpp" #include "armadillo_bits/sp_auxlib_meat.hpp" #include "armadillo_bits/injector_meat.hpp" #include "armadillo_bits/Mat_meat.hpp" #include "armadillo_bits/Col_meat.hpp" #include "armadillo_bits/Row_meat.hpp" #include "armadillo_bits/Cube_meat.hpp" #include "armadillo_bits/xvec_htrans_meat.hpp" #include "armadillo_bits/SizeMat_meat.hpp" #include "armadillo_bits/SizeCube_meat.hpp" #include "armadillo_bits/field_meat.hpp" #include "armadillo_bits/subview_meat.hpp" #include "armadillo_bits/subview_elem1_meat.hpp" #include "armadillo_bits/subview_elem2_meat.hpp" #include "armadillo_bits/subview_field_meat.hpp" #include "armadillo_bits/subview_cube_meat.hpp" #include "armadillo_bits/diagview_meat.hpp" #include "armadillo_bits/subview_each_meat.hpp" #include "armadillo_bits/SpValProxy_meat.hpp" #include "armadillo_bits/SpMat_meat.hpp" #include "armadillo_bits/SpMat_iterators_meat.hpp" #include "armadillo_bits/SpCol_meat.hpp" #include "armadillo_bits/SpRow_meat.hpp" #include "armadillo_bits/SpSubview_meat.hpp" #include "armadillo_bits/SpSubview_iterators_meat.hpp" #include "armadillo_bits/diskio_meat.hpp" #include "armadillo_bits/wall_clock_meat.hpp" #include "armadillo_bits/running_stat_meat.hpp" #include "armadillo_bits/running_stat_vec_meat.hpp" #include "armadillo_bits/op_diagmat_meat.hpp" #include "armadillo_bits/op_diagvec_meat.hpp" #include "armadillo_bits/op_dot_meat.hpp" #include "armadillo_bits/op_inv_meat.hpp" #include "armadillo_bits/op_htrans_meat.hpp" #include "armadillo_bits/op_max_meat.hpp" #include "armadillo_bits/op_min_meat.hpp" #include "armadillo_bits/op_mean_meat.hpp" #include "armadillo_bits/op_median_meat.hpp" #include "armadillo_bits/op_sort_meat.hpp" #include "armadillo_bits/op_sum_meat.hpp" #include "armadillo_bits/op_stddev_meat.hpp" #include "armadillo_bits/op_strans_meat.hpp" #include "armadillo_bits/op_var_meat.hpp" #include "armadillo_bits/op_repmat_meat.hpp" #include "armadillo_bits/op_reshape_meat.hpp" #include "armadillo_bits/op_vectorise_meat.hpp" #include "armadillo_bits/op_resize_meat.hpp" #include "armadillo_bits/op_cov_meat.hpp" #include "armadillo_bits/op_cor_meat.hpp" #include "armadillo_bits/op_shuffle_meat.hpp" #include "armadillo_bits/op_prod_meat.hpp" #include "armadillo_bits/op_pinv_meat.hpp" #include "armadillo_bits/op_dotext_meat.hpp" #include "armadillo_bits/op_flip_meat.hpp" #include "armadillo_bits/op_princomp_meat.hpp" #include "armadillo_bits/op_misc_meat.hpp" #include "armadillo_bits/op_relational_meat.hpp" #include "armadillo_bits/op_find_meat.hpp" #include "armadillo_bits/op_chol_meat.hpp" #include "armadillo_bits/op_cx_scalar_meat.hpp" #include "armadillo_bits/op_trimat_meat.hpp" #include "armadillo_bits/op_cumsum_meat.hpp" #include "armadillo_bits/op_symmat_meat.hpp" #include "armadillo_bits/op_hist_meat.hpp" #include "armadillo_bits/op_unique_meat.hpp" #include "armadillo_bits/op_toeplitz_meat.hpp" #include "armadillo_bits/op_fft_meat.hpp" #include "armadillo_bits/op_any_meat.hpp" #include "armadillo_bits/op_all_meat.hpp" #include "armadillo_bits/glue_times_meat.hpp" #include "armadillo_bits/glue_mixed_meat.hpp" #include "armadillo_bits/glue_cov_meat.hpp" #include "armadillo_bits/glue_cor_meat.hpp" #include "armadillo_bits/glue_kron_meat.hpp" #include "armadillo_bits/glue_cross_meat.hpp" #include "armadillo_bits/glue_join_meat.hpp" #include "armadillo_bits/glue_relational_meat.hpp" #include "armadillo_bits/glue_solve_meat.hpp" #include "armadillo_bits/glue_conv_meat.hpp" #include "armadillo_bits/glue_toeplitz_meat.hpp" #include "armadillo_bits/glue_hist_meat.hpp" #include "armadillo_bits/glue_histc_meat.hpp" #include "armadillo_bits/glue_max_meat.hpp" #include "armadillo_bits/glue_min_meat.hpp" #include "armadillo_bits/spop_max_meat.hpp" #include "armadillo_bits/spop_min_meat.hpp" #include "armadillo_bits/spop_sum_meat.hpp" #include "armadillo_bits/spop_strans_meat.hpp" #include "armadillo_bits/spop_htrans_meat.hpp" #include "armadillo_bits/spop_misc_meat.hpp" #include "armadillo_bits/spop_mean_meat.hpp" #include "armadillo_bits/spop_var_meat.hpp" #include "armadillo_bits/spglue_plus_meat.hpp" #include "armadillo_bits/spglue_minus_meat.hpp" #include "armadillo_bits/spglue_times_meat.hpp" } #include "armadillo_bits/compiler_setup_post.hpp" #endif RcppArmadillo/inst/include/RcppArmadilloLapack.h.in0000644000176000001440000000207412253723621022064 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- // // RcppArmadilloLapack.h: Toggle for use of zgesdd // // Copyright (C) 2013 Dirk Eddelbuettel // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #ifndef RcppArmadillo__RcppArmadilloLapack__h #define RcppArmadillo__RcppArmadilloLapack__h // value on next line may be changed to #define by the configure script // #undef ARMA_DONT_USE_CX_GESDD #endif RcppArmadillo/tests/0000755000176000001440000000000012253723621014200 5ustar ripleyusersRcppArmadillo/tests/doRUnit.R0000644000176000001440000000250712253723621015713 0ustar ripleyusers#### doRUnit.R --- Run RUnit tests ####------------------------------------------------------------------------ ### borrowed from package fUtilities in RMetrics ### http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/fUtilities/tests/doRUnit.R?rev=1958&root=rmetrics&view=markup ### Originally follows Gregor Gojanc's example in CRAN package 'gdata' ### and the corresponding section in the R Wiki: ### http://wiki.r-project.org/rwiki/doku.php?id=developers:runit ### MM: Vastly changed: This should also be "runnable" for *installed* ## package which has no ./tests/ ## ----> put the bulk of the code e.g. in ../inst/unitTests/runTests.R : if(require("RUnit", quietly = TRUE)) { pkg <- "RcppArmadillo" require( pkg, character.only=TRUE) path <- system.file("unitTests", package = pkg) stopifnot(file.exists(path), file.info(path.expand(path))$isdir) pathRcppArmadilloTests <<- system.file("unitTests", package = pkg) stopifnot(file.exists(pathRcppArmadilloTests), file.info(path.expand(pathRcppArmadilloTests))$isdir) ## without this, we get unit test failures Sys.setenv( R_TESTS = "" ) RcppArmadillo.unit.test.output.dir <- getwd() source(file.path(path, "runTests.R"), echo = TRUE) } else { print( "package RUnit not available, cannot run unit tests" ) } RcppArmadillo/src/0000755000176000001440000000000012267623072013631 5ustar ripleyusersRcppArmadillo/src/Makevars0000644000176000001440000000022712253723621015322 0ustar ripleyusers## -*- mode: makefile; -*- PKG_CXXFLAGS=-I../inst/include PKG_LIBS=`$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) RcppArmadillo/src/fastLm.cpp0000644000176000001440000000320412267623072015562 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- // // fastLm.cpp: Rcpp/Armadillo glue example of a simple lm() alternative // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #include using namespace Rcpp ; // [[Rcpp::export]] List fastLm(const arma::mat& X, const arma::colvec& y) { int n = X.n_rows, k = X.n_cols; arma::colvec coef = arma::solve(X, y); // fit model y ~ X arma::colvec res = y - X*coef; // residuals // std.errors of coefficients double s2 = std::inner_product(res.begin(), res.end(), res.begin(), 0.0)/(n - k); arma::colvec std_err = arma::sqrt(s2 * arma::diagvec(arma::pinv(arma::trans(X)*X))); return List::create(_["coefficients"] = coef, _["stderr"] = std_err, _["df.residual"] = n - k ); } RcppArmadillo/src/RcppArmadillo.cpp0000644000176000001440000000314212267623072017066 0ustar ripleyusers// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- // // RcppArmadillo.cpp: Rcpp/Armadillo glue // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates // // This file is part of RcppArmadillo. // // RcppArmadillo is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // RcppArmadillo is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with RcppArmadillo. If not, see . #include using namespace Rcpp; const unsigned int arma::arma_version::major; const unsigned int arma::arma_version::minor; const unsigned int arma::arma_version::patch; // [[Rcpp::export]] IntegerVector armadillo_version(bool single) { if( single ){ return wrap( 10000*arma::arma_version::major + 100*arma::arma_version::minor + arma::arma_version::patch ) ; } IntegerVector version = IntegerVector::create(_["major"] = arma::arma_version::major, _["minor"] = arma::arma_version::minor, _["patch"] = arma::arma_version::patch); return version ; } RcppArmadillo/src/Makevars.win0000644000176000001440000000050012253723621016110 0ustar ripleyusers## This assumes that we can call Rscript to ask Rcpp about its locations ## Use the R_HOME indirection to support installations of multiple R version PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()") PKG_CPPFLAGS = -I../inst/include -I. PKG_LIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) RcppArmadillo/src/RcppExports.cpp0000644000176000001440000000222012267623072016622 0ustar ripleyusers// This file was generated by Rcpp::compileAttributes // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #include "../inst/include/RcppArmadillo.h" #include using namespace Rcpp; // fastLm List fastLm(const arma::mat& X, const arma::colvec& y); RcppExport SEXP RcppArmadillo_fastLm(SEXP XSEXP, SEXP ySEXP) { BEGIN_RCPP SEXP __sexp_result; { Rcpp::RNGScope __rngScope; Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP ); Rcpp::traits::input_parameter< const arma::colvec& >::type y(ySEXP ); List __result = fastLm(X, y); PROTECT(__sexp_result = Rcpp::wrap(__result)); } UNPROTECT(1); return __sexp_result; END_RCPP } // armadillo_version IntegerVector armadillo_version(bool single); RcppExport SEXP RcppArmadillo_armadillo_version(SEXP singleSEXP) { BEGIN_RCPP SEXP __sexp_result; { Rcpp::RNGScope __rngScope; Rcpp::traits::input_parameter< bool >::type single(singleSEXP ); IntegerVector __result = armadillo_version(single); PROTECT(__sexp_result = Rcpp::wrap(__result)); } UNPROTECT(1); return __sexp_result; END_RCPP } RcppArmadillo/NAMESPACE0000644000176000001440000000040412267623015014254 0ustar ripleyusersuseDynLib(RcppArmadillo) import(Rcpp) export(fastLmPure, fastLm, RcppArmadillo.package.skeleton) S3method(fastLm, default) S3method(fastLm, formula) S3method(predict, fastLm) S3method(print, fastLm) S3method(summary, fastLm) S3method(print, summary.fastLm) RcppArmadillo/R/0000755000176000001440000000000012253723621013237 5ustar ripleyusersRcppArmadillo/R/inline.R0000644000176000001440000000171512253723621014644 0ustar ripleyusers## Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates ## ## This file is part of RcppArmadillo. ## ## RcppArmadillo is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 2 of the License, or ## (at your option) any later version. ## ## RcppArmadillo is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with RcppArmadillo. If not, see . inlineCxxPlugin <- Rcpp:::Rcpp.plugin.maker( include.before = "#include ", libs = "$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)", package = "RcppArmadillo" ) RcppArmadillo/R/RcppExports.R0000644000176000001440000000051212253723621015651 0ustar ripleyusers# This file was generated by Rcpp::compileAttributes # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 fastLm <- function(X, y) { .Call('RcppArmadillo_fastLm', PACKAGE = 'RcppArmadillo', X, y) } armadillo_version <- function(single) { .Call('RcppArmadillo_armadillo_version', PACKAGE = 'RcppArmadillo', single) } RcppArmadillo/R/unit.test.R0000644000176000001440000000362312253723621015323 0ustar ripleyusers# Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates # # This file is part of RcppArmadillo. # # RcppArmadillo is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # RcppArmadillo is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with RcppArmadillo. If not, see . test <- function( output = if( file.exists( "/tmp" ) ) "/tmp" else getwd() ){ if( !file.exists( output ) ){ stop( "output directory does not exist" ) } Rscript <- file.path( R.home( component = "bin" ), "Rscript" ) if( .Platform$OS.type == "windows" ){ Rscript <- sprintf( "%s.exe", Rscript ) } test.script <- system.file( "unitTests", "runTests.R", package = "RcppArmadillo" ) cmd <- sprintf( '"%s" "%s" --output=%s', Rscript, test.script, output ) system( cmd ) } unit_test_setup <- function(file = NULL, packages = NULL) { function(){ if( !is.null(packages) ){ for( p in packages ){ suppressMessages( require( p, character.only = TRUE ) ) } } if( !is.null(file) ){ if (exists("pathRcppArmadilloTests")) { sourceCpp(file.path(get("pathRcppArmadilloTests"), "cpp", file )) } else if (file.exists( file.path("cpp", file ) )) { sourceCpp( file.path( "cpp", file ) ) } else { sourceCpp(system.file("unitTests", "cpp", file, package="RcppArmadillo")) } } } } RcppArmadillo/R/fastLm.R0000644000176000001440000000777112253723621014624 0ustar ripleyusers## fastLm.R: Rcpp/Armadillo implementation of lm() ## ## Copyright (C) 2010 - 2013 Dirk Eddelbuettel, Romain Francois and Douglas Bates ## ## This file is part of RcppArmadillo. ## ## RcppArmadillo is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 2 of the License, or ## (at your option) any later version. ## ## RcppArmadillo is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with RcppArmadillo. If not, see . fastLmPure <- function(X, y) { stopifnot(is.matrix(X), is.numeric(y), nrow(y)==nrow(X)) .Call( "RcppArmadillo_fastLm", X, y, PACKAGE = "RcppArmadillo" ) } fastLm <- function(X, ...) UseMethod("fastLm") fastLm.default <- function(X, y, ...) { X <- as.matrix(X) y <- as.numeric(y) res <- fastLmPure(X, y) res$coefficients <- as.vector(res$coefficient) names(res$coefficients) <- colnames(X) res$fitted.values <- as.vector(X %*% res$coefficients) res$residuals <- y - res$fitted.values res$call <- match.call() res$intercept <- any(apply(X, 2, function(x) all(x == x[1]))) class(res) <- "fastLm" res } print.fastLm <- function(x, ...) { cat("\nCall:\n") print(x$call) cat("\nCoefficients:\n") print(x$coefficients, digits=5) } summary.fastLm <- function(object, ...) { se <- object$stderr tval <- coef(object)/se TAB <- cbind(Estimate = coef(object), StdErr = se, t.value = tval, p.value = 2*pt(-abs(tval), df=object$df)) # why do I need this here? rownames(TAB) <- names(object$coefficients) colnames(TAB) <- c("Estimate", "StdErr", "t.value", "p.value") ## cf src/library/stats/R/lm.R and case with no weights and an intercept f <- object$fitted.values r <- object$residuals #mss <- sum((f - mean(f))^2) mss <- if (object$intercept) sum((f - mean(f))^2) else sum(f^2) rss <- sum(r^2) r.squared <- mss/(mss + rss) df.int <- if (object$intercept) 1L else 0L n <- length(f) rdf <- object$df adj.r.squared <- 1 - (1 - r.squared) * ((n - df.int)/rdf) res <- list(call=object$call, coefficients=TAB, r.squared=r.squared, adj.r.squared=adj.r.squared, sigma=sqrt(sum((object$residuals)^2)/rdf), df=object$df, residSum=summary(object$residuals, digits=5)[-4]) class(res) <- "summary.fastLm" res } print.summary.fastLm <- function(x, ...) { cat("\nCall:\n") print(x$call) cat("\nResiduals:\n") print(x$residSum) cat("\n") printCoefmat(x$coefficients, P.values=TRUE, has.Pvalue=TRUE) digits <- max(3, getOption("digits") - 3) cat("\nResidual standard error: ", formatC(x$sigma, digits=digits), " on ", formatC(x$df), " degrees of freedom\n", sep="") cat("Multiple R-squared: ", formatC(x$r.squared, digits=digits), ",\tAdjusted R-squared: ",formatC(x$adj.r.squared, digits=digits), "\n", sep="") invisible(x) } fastLm.formula <- function(formula, data=list(), ...) { mf <- model.frame(formula=formula, data=data) x <- model.matrix(attr(mf, "terms"), data=mf) y <- model.response(mf) res <- fastLm.default(x, y, ...) res$call <- match.call() res$formula <- formula res$intercept <- attr(attr(mf, "terms"), "intercept") res } predict.fastLm <- function(object, newdata=NULL, ...) { if (is.null(newdata)) { y <- fitted(object) } else { if (!is.null(object$formula)) { x <- model.matrix(object$formula, newdata) } else { x <- newdata } y <- as.vector(x %*% coef(object)) } y } RcppArmadillo/R/RcppArmadillo.package.skeleton.R0000644000176000001440000001007012253723621021326 0ustar ripleyusers## RcppArmadillo.package.skeleton.R: makes a skeleton for a package that wants to use RcppArmadillo ## ## Copyright (C) 2010 Dirk Eddelbuettel, Romain Francois and Douglas Bates ## ## This file is part of RcppArmadillo. ## ## RcppArmadillo is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 2 of the License, or ## (at your option) any later version. ## ## RcppArmadillo is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with RcppArmadillo. If not, see . RcppArmadillo.package.skeleton <- function( name = "anRpackage", list = character(), environment = .GlobalEnv, path = ".", force = FALSE, namespace = TRUE, code_files = character(), example_code = TRUE ){ env <- parent.frame(1) if( !length(list) ){ fake <- TRUE assign( "Rcpp.fake.fun", function(){}, envir = env ) } else { fake <- FALSE } # first let the traditional version do its business call <- match.call() call[[1]] <- as.name("package.skeleton") call[["namespace"]] <- namespace if( "example_code" %in% names( call ) ){ # remove the example_code argument call[["example_code"]] <- NULL } if( fake ){ call[["list"]] <- "Rcpp.fake.fun" } tryCatch( eval( call, envir = env ), error = function(e){ stop( "error while calling `package.skeleton`" ) } ) message( "\nAdding RcppArmadillo settings" ) # now pick things up root <- file.path( path, name ) # Add Rcpp to the DESCRIPTION DESCRIPTION <- file.path( root, "DESCRIPTION" ) if( file.exists( DESCRIPTION ) ){ x <- cbind( read.dcf( DESCRIPTION ), "Depends" = sprintf( "Rcpp (>= %s), RcppArmadillo (>= %s) ", packageDescription("Rcpp")[["Version"]], packageDescription("RcppArmadillo")[["Version"]]), "LinkingTo" = "Rcpp, RcppArmadillo" ) write.dcf( x, file = DESCRIPTION ) message( " >> added Depends: Rcpp, RcppArmadillo" ) message( " >> added LinkingTo: Rcpp, RcppArmadillo" ) } # if there is a NAMESPACE, add a useDynLib NAMESPACE <- file.path( root, "NAMESPACE") if( file.exists( NAMESPACE ) ){ lines <- readLines( NAMESPACE ) if( ! grepl( "useDynLib", lines ) ){ lines <- c( sprintf( "useDynLib(%s)", name), lines) writeLines( lines, con = NAMESPACE ) message( " >> added useDynLib directive to NAMESPACE" ) } } # lay things out in the src directory src <- file.path( root, "src") if( !file.exists( src )){ dir.create( src ) } skeleton <- system.file( "skeleton", package = "RcppArmadillo" ) Makevars <- file.path( src, "Makevars" ) if( !file.exists( Makevars ) ){ file.copy( file.path( skeleton, "Makevars" ), Makevars ) message( " >> added Makevars file with Rcpp settings" ) } Makevars.win <- file.path( src, "Makevars.win" ) if( !file.exists( Makevars.win ) ){ file.copy( file.path( skeleton, "Makevars.win" ), Makevars.win ) message( " >> added Makevars.win file with RcppArmadillo settings" ) } if( example_code ){ header <- readLines( file.path( skeleton, "rcpparma_hello_world.h" ) ) header <- gsub( "@PKG@", name, header, fixed = TRUE ) writeLines( header , file.path( src, "rcpparma_hello_world.h" ) ) message( " >> added example header file using Rcpp/RcppArmadillo") file.copy( file.path( skeleton, "rcpparma_hello_world.cpp" ), src ) message( " >> added example src file using armadillo classes") rcode <- readLines( file.path( skeleton, "rcpparma_hello_world.R" ) ) rcode <- gsub( "@PKG@", name, rcode, fixed = TRUE ) writeLines( rcode , file.path( root, "R", "rcpparma_hello_world.R" ) ) message( " >> added example R file calling the C++ example") } if( fake ){ rm( "Rcpp.fake.fun", envir = env ) unlink( file.path( root, "R" , "Rcpp.fake.fun.R" ) ) unlink( file.path( root, "man", "Rcpp.fake.fun.Rd" ) ) } invisible( NULL ) } RcppArmadillo/R/flags.R0000644000176000001440000000167712253723621014471 0ustar ripleyusers## Copyright (C) 2010 Dirk Eddelbuettel, Romain Francois and Douglas Bates ## ## This file is part of RcppArmadillo. ## ## RcppArmadillo is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 2 of the License, or ## (at your option) any later version. ## ## RcppArmadillo is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with RcppArmadillo. If not, see . RcppArmadilloCxxFlags <- function(){ paste( '-I"', system.file( "include", package = "RcppArmadillo" ), '"', sep = "" ) } CxxFlags <- function(){ cat( RcppArmadilloCxxFlags() ) } RcppArmadillo/vignettes/0000755000176000001440000000000012267623072015052 5ustar ripleyusersRcppArmadillo/vignettes/RcppArmadillo.bib0000644000176000001440000004414412253723621020264 0ustar ripleyusers@String{CRAN = "http://CRAN.R-Project.org/" } @String{manuals = CRAN # "doc/manuals/" } @String{RCoreTeam = "{R Development Core Team}" } @String{RFoundation = "R Foundation for Statistical Computing" } @String{R-Forge = "http://R-Forge.R-Project.org/" } @manual{Abrahams+Grosse-Kunstleve:2003:Boost.Python, author = { David Abrahams and Ralf W. Grosse-Kunstleve }, organization = "Boost Consulting", title = "Building Hybrid Systems with Boost.Python", year = 2003, url = "http://www.boostpro.com/writing/bpl.pdf" } @Book{Abrahams+Gurtovoy:2004:TemplateMetaprogramming, author = {David Abrahams and Aleksey Gurtovoy}, title = {{C++} {T}emplate {M}etaprogramming: Concepts, Tools and Techniques from {B}oost and Beyond}, publisher = {Addison-Wesley}, year = 2004, address = {Boston} } @Manual{Armstrong:2009:RAbstraction, title = {{RAbstraction}: {C++} abstraction for {R} objects}, author = {Whit Armstrong}, year = 2009, note = {Code repository last updated July 22, 2009.}, url = {http://github.com/armstrtw/rabstraction} } @Manual{Armstrong:2009:RObjects, title = {{RObjects}: {C++} wrapper for R objects (a better implementation of {RAbstraction}}, author = {Whit Armstrong}, year = 2009, note = {Code repository last updated November 28, 2009.}, url = {http://github.com/armstrtw/RObjects} } @InProceedings{Bates+DebRoy:2001:C++Classes, author = {Douglas M. Bates and Saikat DebRoy}, title = {{C++} Classes for {R} Objects}, booktitle = {Proceedings of the 2nd International Workshop on Distributed Statistical Computing (DSC 2001)}, year = 2001, editor = {Kurt Hornik and Friedrich Leisch}, address = {TU Vienna, Austria} } @Misc{Brokken:2011:Cpp, author = {Frank B. Brokken}, title = {C++ Annotations}, howpublished = {Electronic book, University of Groningen}, year = 2012, url = {http://www.icce.rug.nl/documents/cplusplus/}, note = {Version 9.3.0, accessed 2012-04-13.}, } @Book{Chambers:2008:SoDA, author = {John M. Chambers}, title = {Software for Data Analysis: Programming with {R}}, publisher = {Springer}, year = 2008, series = {Statistics and Computing}, address = {Heidelberg}, note = {{ISBN} 978-0-387-75935-7} } @Manual{CRAN:RandomFields, title = {RandomFields: Simulation and Analysis of Random Fields}, author = {Martin Schlather}, year = 2012, note = {R package version 2.0.54}, url = CRAN # "package=RandomFields" } @Manual{CRAN:RDieHarder, title = {RDieHarder: R interface to the DieHarder RNG test suite}, author = {Dirk Eddelbuettel}, year = 2012, note = {R package version 0.1.2}, url = CRAN # "package=RDieHarder" } @Manual{CRAN:RInside, title = {RInside: C++ classes to embed R in C++ applications}, author = {Dirk Eddelbuettel and Romain Fran\c{c}ois}, year = 2012, note = {R package version 0.2.6}, url = CRAN # "package=RInside" } @Manual{CRAN:RProtoBuf, title = {RProtoBuf: R Interface to the Protocol Buffers API}, author = {Romain Fran\c{c}ois and Dirk Eddelbuettel}, year = 2011, note = {R package version 0.2.3}, url = CRAN # "package=RProtoBuf" } @Manual{CRAN:RQuantLib, title = {RQuantLib: {R} interface to the {QuantLib} library}, author = {Dirk Eddelbuettel and Khanh Nguyen}, year = 2011, note = {R package version 0.3.8}, url = CRAN # "package=RQuantLib" } @Manual{CRAN:Rcpp, title = {Rcpp: Seamless R and C++ Integration}, author = {Dirk Eddelbuettel and Romain Fran\c{c}ois}, year = 2012, note = {R package version 0.10.2}, url = CRAN # "package=Rcpp" } @Manual{CRAN:RcppArmadillo, title = {RcppArmadillo: Rcpp integration for Armadillo templated linear algebra library}, author = {Romain Fran\c{c}ois and Dirk Eddelbuettel and Douglas Bates}, year = 2012, note = {R package version 0.3.6.1}, url = CRAN # "package=RcppArmadillo" } @Manual{CRAN:RcppBDT, title = {RcppBDT: Rcpp binding for the Boost Date\_Time library}, author = {Dirk Eddelbuettel and Romain Fran\c{c}ois}, year = 2011, note = {R package version 0.1.0}, url = CRAN # "package=RcppBDT" } @Manual{CRAN:RcppClassic, title = {RcppClassic: Deprecated 'classic' Rcpp API}, author = {Dirk Eddelbuettel and Romain Fran\c{c}ois}, year = 2011, note = {R package version 0.9.1}, url = CRAN # "package=RcppClassic" } @Manual{CRAN:RcppDE, title = {RcppDE: Global optimization by differential evolution in C++}, author = {Dirk Eddelbuettel}, year = 2012, note = {R package version 0.1.1}, url = CRAN # "package=RcppDE" } @Manual{CRAN:RcppEigen, title = {RcppEigen: Rcpp integration for the Eigen templated linear algebra library}, author = {Douglas Bates and Romain Fran\c{c}ois and Dirk Eddelbuettel}, year = 2012, note = {R package version 0.2.0}, url = CRAN # "package=RcppEigen" } @Manual{CRAN:RcppExamples, title = {RcppExamples: Examples using {Rcpp} to interface {R} and {C++}}, author = {Dirk Eddelbuettel and Romain Fran\c{c}ois}, year = 2011, note = {R package version 0.1.3}, url = CRAN # "package=RcppExamples" } @Manual{CRAN:RcppGSL, title = {RcppGSL: Rcpp integration for GNU GSL vectors and matrices}, author = {Romain Fran\c{c}ois and Dirk Eddelbuettel}, year = 2010, note = {R package version 0.1.0}, url = CRAN # "package=RcppGSL" } @Manual{CRAN:Rserve, title = {Rserve: Binary R server}, author = {Simon Urbanek}, year = 2012, note = {R package version 0.6-8}, url = CRAN # "package=Rserve" } @Manual{CRAN:rbenchmark, title = {rbenchmark: Benchmarking routine for R}, author = {Wacek Kusnierczyk}, year = 2010, note = {R package version 0.3}, url = CRAN # "package=rbenchmark" } @Manual{CRAN:rdyncall, title = {rdyncall: Improved Foreign Function Interface (FFI) and Dynamic Bindings to C Libraries}, author = {Daniel Adler}, year = 2011, note = {R package version 0.7.4}, url = CRAN # "package=rdyncall" } @Manual{CRAN:cxxPack, title = {cxxpack: {R/C++} Tools for Literate Statistical Practice}, author = {Dominick Samperi}, year = 2010, note = {R package version 7.0.6}, url = CRAN # "package=cxxPack" } @Manual{CRAN:gsl, title = {gsl: Wrapper for the Gnu Scientific Library}, author = {Robin K. S. Hankin}, year = 2011, note = {R package version 1.9-9}, url = CRAN # "package=gsl" } @Manual{CRAN:highlight, title = {highlight: Syntax highlighter}, author = {Romain Fran\c{c}ois}, year = 2011, note = {R package version 0.3-1}, url = CRAN # "package=highlight" } @Manual{CRAN:inline, title = {inline: Inline C, C++, Fortran function calls from R}, author = {Oleg Sklyar and Duncan Murdoch and Mike Smith and Dirk Eddelbuettel and Romain Fran\c{c}ois}, year = 2012, note = {R package version 0.3.10}, url = CRAN # "package=inline" } @Manual{CRAN:minqa, title = {minqa: Derivative-free optimization algorithms by quadratic approximation}, author = {Douglas Bates and Katharine M. Mullen and John C. Nash and Ravi Varadhan}, year = 2012, note = {R package version 1.2.0}, url = CRAN # "package=minqa" } @Manual{CRAN:topicmodels, title = {topicmodels: Topic models}, author = {Bettina Gr\"{u}n and Kurt Hornik}, year = 2012, note = {R package version 0.1-5}, url = CRAN # "package=topicmodels" } @Article{Eddelbuettel+Sanderson:2014:RcppArmadillo, title = {RcppArmadillo: Accelerating {R} with high-performance {C++} linear algebra}, author = {Dirk Eddelbuettel and Conrad Sanderson}, journal = {Computational Statistics and Data Analysis}, year = 2014, volume = 71, month = {March}, pages = {1054--1063}, doi = {10.1016/j.csda.2013.02.005}, url = {http://dx.doi.org/10.1016/j.csda.2013.02.005} } @Article{Eddelbuettel+Francois:2011:Rcpp, title = {{Rcpp}: Seamless {R} and {C++} Integration}, author = {Dirk Eddelbuettel and Romain Fran\c{c}ois}, journal = {Journal of Statistical Software}, year = 2011, volume = 40, number = 8, pages = {1--18}, url = {http://www.jstatsoft.org/v40/i08/}, } @Book{Eddelbuettel:2013:Rcpp, author = {Dirk Eddelbuettel}, title = {Seamless R and C++ Integration with Rcpp}, publisher = {Springer}, year = 2013, address = {New York}, isbn = {978-1-4614-6867-7} } @Article{Gropp+Lusk+Doss+Skjellum:1996:MPI, author = {William Gropp and Ewing Lusk and Nathan Doss and Anthony Skjellum}, title = {A high-performance, portable implementation of the {MPI} message passing interface standard}, journal = {Parallel Computing}, year = 1996, url = {http://dx.doi.org/10.1016/0167-8191(96)00024-5}, volume = 22, number = 6, pages = {789--828} } @Book{Gropp+Lusk+Skjellum:1999:MPI, author = {William Gropp and Ewing Lusk and Anthony Skjellum}, title = {Using {MPI}: Portable Parallel Programming with the Message Passing Interface}, publisher = {MIT Press}, year = 1999, series = {Scientific and Engineering Computation Series}, edition = {2nd}, month = {November}, note = {{ISBN} 978-0-262-57132-6}} @Manual{GSL, title = {{GNU} {S}cientific {L}ibrary {R}eference {M}anual}, author = {Mark Galassi and Jim Davies and James Theiler and Brian Gough and Gerard Jungman and Patrick Alken and Michael Booth and Fabrice Rossi}, year = {2010}, edition = {3rd}, note = {Version 1.14. {ISBN} 0954612078}, url = {http://www.gnu.org/software/gsl} } @Unpublished{Java+Gaile+Manly:2007:RCpp, author = {James J. Java and Daniel P. Gaile and Kenneth E. Manly}, title = {{R/Cpp}: Interface Classes to Simplify Using {R} Objects in {C++} Extensions}, note = {Unpublished manuscript, University at Buffalo}, url = {http://sphhp.buffalo.edu/biostat/research/techreports/UB_Biostatistics_TR0702.pdf}, month = {July}, year = 2007 } @InProceedings{Leisch:2008:Tutorial, author = {Friedrich Leisch}, title = {Tutorial on {C}reating \proglang{R} {P}ackages}, booktitle = {COMPSTAT 2008 -- Proceedings in Computational Statistics}, year = 2008, editor = {Paula Brito}, address = {Heidelberg, Germany}, publisher = {Physica Verlag}, url = CRAN # "doc/contrib/Leisch-CreatingPackages.pdf" } @Manual{Liang:2008:rcppbind, title = {rcppbind: {A} template library for R/C++ developers}, author = {Gang Liang}, year = 2008, note = {R package version 1.0}, url = R-Forge # "projects/rcppbind" } @Book{Lippman+Lajoie+Moo:2005:Cpp_Primer, author = {Stanley B. Lippman and Jos\'{e}e Lajoie and Barbara E. Moo}, title = {The C++ Primer}, publisher = {Addison-Wesley}, year = 2005, edition = {4th} } @book{Meyers:1995:MoreEffectiveC++, author = {Scott Meyers}, title = {More Effective C++: 35 New Ways to Improve Your Programs and Designs}, year = 1995, note = {{ISBN} 020163371X}, publisher = {Addison-Wesley Longman Publishing Co., Inc.}, address = {Boston, MA, USA}, } @book{Meyers:2001:EffectiveSTL, author = {Scott Meyers}, title = {Effective STL: 50 specific ways to improve your use of the standard template library}, year = 2001, note = {{ISBN} 0-201-74962-9}, publisher = {Addison-Wesley Longman Ltd.}, address = {Essex, UK}, } @book{Meyers:2005:EffectiveC++, author = {Scott Meyers}, title = {Effective C++: 55 Specific Ways to Improve Your Programs and Designs}, year = 2005, note = {{ISBN} 978-0321334879}, publisher = {Addison-Wesley Professional}, edition = {Third}, } @Book{Plauger+Et+Al:2000:STL, author = {P.J. Plauger and Alexander Stepanov and Meng Lee and David R. Musser}, title = {The {C++} Standard Template Library}, publisher = {Prentice Hall PTR}, year = 2000, note = {{ISBN} 978-0134376332} } @manual{R:Administration, author = RCoreTeam, organization = RFoundation, address = {Vienna, Austria}, year = 2012, title = "R Installation and Administration", note = {{ISBN} 3-900051-09-7}, url = manuals # "R-admin.html" } @manual{R:Extensions, author = RCoreTeam, organization = RFoundation, address = {Vienna, Austria}, year = 2012, title = "Writing R extensions", note = {{ISBN} 3-900051-11-9}, url = manuals # "R-exts.html" } @manual{R:Internals, author = RCoreTeam, organization = RFoundation, address = {Vienna, Austria}, year = 2012, title = "R internals", note = {{ISBN} 3-900051-14-3}, url = manuals # "R-ints.html" } @manual{R:Main, title = {R: A Language and Environment for Statistical Computing}, author = RCoreTeam, organization = RFoundation, address = {Vienna, Austria}, year = 2012, note = {{ISBN} 3-900051-07-0}, url = {http://www.R-project.org/}, } @manual{R:Language, author = RCoreTeam, organization = RFoundation, address = {Vienna, Austria}, year = 2012, title = "R language", note = {{ISBN} 3-900051-13-5}, url = manuals # "R-lang.html" } @InProceedings{Runnalls:2009:CXXR, author = {Andrew Runnalls}, title = {Aspects of {CXXR} internals}, booktitle = {Directions in Statistical Computing}, address = {University of Copenhagen, Denmark}, year = 2009 } @Manual{Samperi:2009:RcppTemplate, title = {RcppTemplate: Rcpp {R/C++} Object Mapping Library and Package Template}, author = {Dominick Samperi}, year = 2009, note = {(Archived) R package version 6.1}, url = CRAN # "/src/contrib/Archive/RcppTemplate" } @TechReport{Sanderson:2010:Armadillo, author = {Conrad Sanderson}, title = {{Armadillo}: {An} open source {C++} Algebra Library for Fast Prototyping and Computationally Intensive Experiments }, institution = {{NICTA}}, year = 2010, url = "http://arma.sourceforge.net" } @Book{Stroustrup:1997:Cpp, author = {Bjarne Stroustrup}, title = {The C++ Programming Language}, publisher = {Addison-Wesley}, year = 1997, edition = {3rd} } @Article{TempleLang:2009:ModestProposal, author = {Duncan {Temple Lang}}, title = {A modest proposal: an approach to making the internal {R} system extensible}, journal = {Computational Statistics}, year = 2009, volume = 24, number = 2, pages = {271-281}, month = {May} } @Article{TempleLang:2009:RGCCTranslationUnit, author = {Duncan {Temple Lang}}, title = {Working with meta-data from {C/C++} code in {R}: the {RGCCTranslationUnit} package}, journal = {Computational Statistics}, year = 2009, volume = 24, number = 2, pages = {283-293}, month = {May} } @article{Tusell:2010:Kalman, author = "Fernando Tusell", title = "Kalman Filtering in {R}", journal = "Journal of Statistical Software", volume = 39, number = 2, pages = "1--27", year = 2011, URL = "http://www.jstatsoft.org/v39/i02" } @InProceedings{Urbanek:2003:Rserve, author = {Simon Urbanek}, title = {{Rserve}: A Fast Way to Provide {R} Functionality to Applications}, booktitle = {Proceedings of the 3rd International Workshop on Distributed Statistical Computing (DSC 2003)}, year = 2003, editor = {Kurt Hornik and Friedrich Leisch and Achim Zeileis}, address = {TU Vienna, Austria} } @Book{Vandevoorde+Josuttis:2003:Templates, author = {David Vandevoorde and Nicolai M. Josuttis}, title = {{C++} {T}emplates: The Complete Guide}, publisher = {Addison-Wesley}, year = 2003, address = {Boston} } @inproceedings{Veldhuizen:1998:Blitz, author = {Todd L. Veldhuizen}, title = {Arrays in {Blitz++}}, booktitle = {ISCOPE '98: Proceedings of the Second International Symposium on Computing in Object-Oriented Parallel Environments}, note = {{ISBN} 3-540-65387-2}, year = 1998, pages = {223--230}, publisher = {Springer-Verlag}, address = {London, UK}, } @Book{Vandevoorde_2002, title = {C++ Templates: The Complete Guide}, author = {David Vandevoorde and Nicolai M. Josuttis}, publisher = {Addison-Wesley Professional}, year = 2002 } @Book{Abrahams_2004, title = {C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond}, author = {David Abrahams and Aleksey Gurtovoy}, publisher = {Addison-Wesley Professional}, year = {2004} } @Book{Demmel_1997, title = {Applied Numerical Linear Algebra}, author = {James W. Demmel}, publisher = {SIAM}, year = {1997}, note = {{ISBN} 978-0898713893}, } @Book{Kurzak_2010, title = {Scientific Computing with Multicore and Accelerators}, editor = {Jakub Kurzak and David A. Bader and Jack Dongarra}, publisher = {CRC Press}, year = {2010}, note = {{ISBN} 978-1439825365}, } @Misc{Tierney:2012:ByteCompiler, author = {Luke Tierney}, title = {A Byte-Code Compiler for {R}}, howpublished = {Manuscript, Department of Statistics and Actuarial Science, University of Iowa}, year = 2012, url = {www.stat.uiowa.edu/~luke/R/compiler/compiler.pdf}, annote = {Accessed 2012-06-25.}, } @InProceedings{Morandat_2012, author = {Floral Morandat and Brandon Hill and Leo Osvald and Jan Vitek}, title = {Evaluating the Design of the {R} Language}, booktitle = {ECOOP 2012: Proceedings of European Conference on Object-Oriented Programming}, year = 2012, } @Article{Reddy_2013, title = {Improved Foreground Detection via Block-based Classifier Cascade with Probabilistic Decision Integration}, author = {Vikas Reddy and Conrad Sanderson and Brian C. Lovell}, journal = {IEEE Transactions on Circuits and Systems for Video Technology}, year = 2013, volume = 23, number = 1, pages = {83--93} } @Article{Li_CSDA_2013, title = {An unscented {K}alman smoother for volatility extraction: Evidence from stock prices and options}, author = {Junye Li}, journal = {Computational Statistics and Data Analysis}, year = 2013, volume = 58, pages = {15--26} } RcppArmadillo/vignettes/kalmanExample.pdf0000644000176000001440000006174012253723621020330 0ustar ripleyusers%PDF-1.4 %ρ\r 1 0 obj << /CreationDate (D:20120620194803) /ModDate (D:20120620194803) /Title (R Graphics Output) /Producer (R 2.15.0) /Creator (R) >> endobj 2 0 obj << /Type /Catalog /Pages 3 0 R >> endobj 7 0 obj << /Type /Page /Parent 3 0 R /Contents 8 0 R /Resources 4 0 R >> endobj 8 0 obj << /Length 21298 /Filter /FlateDecode >> stream x}I-Inl-t;ca[,@ ]Ƶl#CjNvYHF10>cV?>族Ïsc<3m7?>ˏ?([h?8?>5ϫ~?(TS!߄s+xϱ v~zM'߅8<7Q>} g߅ c ޅg,g8?ۄyos"Y8[?l;5m<>KhYǻl!,;oG;.gywqQ?,;!}ސu6puk}>Joym>&Pxuގ>-!|+urisvի,<ճIXE?=]xGfY^-% |0>O~m[{Xmulθy#V~:xiOgOWElA1-c8/̱͗ ^.g^ue^WgxnmoBtBn?4_xTq_|n1;3yO|8|h|G[4/?<6΋Z]/^|s0_vw~^|>m(׻!͋]f/[}HkoۣWmmW1ie99 J]IŇ1~3f1?egg!`il>}〶=r>C!9~~nSGӓ0ߠ쳧zy♜m5 ~I vG6Xx[>w1t8qumv5B{;;3xZB-^7ac2;k{y`ٛl>< :/#>M ͗p=臎|獬ɡ2w9Б$Gv ~KbooB|4z;^|줮:,_~+]]xxR`dӵUbfo7S՜Oٰt~Fa cS0=;FMA1C ޅї!RyuƓno l\t~c=n{>jv~~mӟa^)B :w̎zz1{V6b> fy9?I}1䙸1\ߥ9oCcr}\ɗid>mx16?;aU1,sp~_x:~ķ_vq}xb bw6gq폓=OoO sƄ9ώnK? `XG9a?>G|Ѓ`;,rӣ tq*at >ZՔ ?D\َԂ 9ۓPgR<̡ > `PLxrzgۚ=|Da6Ɨ=,`OqAך_f FS SX|:zW;;iP4VbNnsk]SSo:P`} ^OEEqb9zԇWy^jtNOI,bVkߢ7yP[o]TLH][XH}_ |m1YLHXٮOX+I&x{Ç͡CSbxNv40UO߰YlVm?t|G3ZKF}x{\F$}^1Ǧ|i><}Ƭӗ#ٻ{nq~Uúk;6bP5_#VO-)Y+ Ck< ec/^xj%p8T*v3O},m{S|Ʊ| taa-j cm>#X=cO o=zOR7͞ajr縵O{-6ZV|OCm,p_uiHZlihZqie;&Jh#Uq!{8VB;o*>4q?8fjez ɻs:|\ySks:T,>tÓ0'F[|Y×53ToOkzl ?Ty_bݑ]691}\Go]b1FO¥io 1z `tA GT.AǶ&'~~Ida+ !z޾/Ɩ߼4ַd W;x`>&D<roؙS6M̈!:>1ǃ$?MbT{`ɔn,7oo)Ws_zh韾ͼ\׏#KhO4(; eewDd1Gmh{?w6?7NwpLyEJTE}ט;|>>{uiry*׏_{ܱ^qf)%ܶ|Gn |bwMKWun92vmG9Ikf+E~l|VG,$VtYoû KW%_®~-c1"99++#VG5r+4aMAgLb~m۔/bs|wj8q\ ?U\Q[`9ogi,9R7/yے/aWՖHZʶ T,ET쵎)H(kb-Mݠ lK.]V[6[,뾘X+0)mMubcEA Ύ m嗰lK]F,AkTwNnW1# Xo|`f"9ֳ4fݤkڶ\~ R†w?9-搱A9sK8A vX~`XQ_ cnPlK.]V[vbDXr(-P(łg,#r C+*9I,ԝXږ\~ t,rX|Mkxp=lXQ_aJv&%O¶KoT;REK\+Kl5|jv[7(%_®~}a,XǺk.G~J p!tY1JbEA7-M -ے/aWՖ/V7Qq%(;]@bE| [!lݤkڶ\~ ڦwߜ Tw ?+/-g ;{Ka,Sw~Ŷ)_~ߗ=N}_F.cn;&ў7Dž%%9'ř-a;Top#6?ŜH lYs9)zGӺbs>%_®~-\sc9|-snX>bTRB(30NyCI[7)IOc܈k<& 6b4gg E=L{g,\&Vt`'&XJݠkٖ\~ *Mdsecx*ƪHrk kq0-,BR7(DarE7ՖN-֊b,0E:ޖ#%λ ?;&hֽ-m嗰nK ! b:X$E{ϭ;pcIQ7-ɖ[OIu*\u~oKmaϷ 4Z' _)ÁΔc!Dל- %_®~-|J8׶J~V wXQ/4^[atv}۲#%"{vqQa=FRq&W b59شL,u{r%rD۱Y-' ]\i+"l%%8<6N[y=n<%nˉշ8~Lʓx&t]=nyEg]$62nRD^)_E9 k\zN ~wha9_zcE\3aACr}̶)_~[ma`y4[iNj}'mz&e*yb+|$E>[Ysr%ۢ>VNŒ(wl/=tYĊFlXMvaɶKocKc`Z9j%^qRK3xsŧ؎uu ۖ/cWDEɹb:naeyc$ p؆M)l[.]v[p@}sQ ;FGi)zW _rs:քuumz2J V^+q+*uwN9&a^}mnx"lK.]v[/Pu[HYovD푢凧M:s`gؘ^-- p嗰n ηbLv sa=); j9%Vt ;t|m[r%rb#"}_ȉݨ3ň>9Lw-XVu (M-ےSbtDǹSJs:v ;]C|1ƊnZʖ [umWUݿȗcUs8Ѻ•X\%E{{)GRĊn/0~M-/-_®~-MdszY㒑43L|/D+ kqʙ ura[r%ۂ/1rlh c΁B+a =X6hU[7()_~{^'bNq 5~D;G"8ʟzNFVn/e#nchuC]8pf5\8⢥8mE18P4i-QMIpv|@EC {)0ٛ!tb`1pd8dVniؔjqbCsd 7O90ek$R'ERR 'Z w2 - V_>m5s8ّ"5d)GE-V]Ó^\f6ӰIo.!:9ך]sihvA>͓γ󨮱j>v Zb7AOmK.]v[8ǁ]osvݴ '~c`ߑӀqrq+؛ӱclcЍt{n vmf Vvs13Fḯ1=2,Iˌ(Mi/\~ 0s) g}pR k krZnRNa[r%7ՖCrb*aa$晤)ك+j8n8cݤzrep+_+d a-c AގrS ~Q؝ҝi[t~maX;v !FdYkTl#[bE 3bf,+a-vm9Ԅa+8ŧs/XhcMlΎcȶM"jˉ Ģ߀= N2|O;J<(,)91vLǭSض\ p355/ 'DRe8Kp&6nݤRo92vm84 A. CX+mvQ@#ebEe`9Ŷ;nRnyض~0Aueh.9{AEp08ӫ`G/<ƒnZӱq" "uuo~-cCJɹ^ )Rd[Ɗ:>=L@jݤ6nvm_aGq!֢qW-|9S7&=^Ċ:r%v`ݺA:KoE[{noTRar{9&e/\2g`؎quڶKo`@EXCvcbnZĶܝ|`[rwٖL3ۅ8<\wȐĊj>\:cTpEږ\~ T<̉Z9̈Tz|DȣXQW:9i؍{ҽy%_®~-xp v-v<g+5S%3J(O'PnRno92vm9VU"4B;607{[ik kqp؝IL[-_~[m<. "]_+'QQW0X6ҸDvjCބux99H(=%_®~-/֙a-AhJXkw"l%Hi%H*XQ֒$a+;ZҶKoq]40×h9RpbEUǒS{#h<Kۛcʂ]v[jFI ?<+>g-)r5KJpֈ1$ViD[[pVjK {}둸 Θ[Ċ}(-9_˥^ږ\~ GE7RË' H&Ja/RLb8)H YMĊp8mHw.pm嗰n ,r:t*9xnRw"ǚ'rS+79AbHݤr%ۂ^Prr0mQZRwئ)]O_ۘiJnyJے/aW&~8Z9'>s,&XW58镀 ̲cݑsisF~{޼VsKg+֨"[QcE91gd, ۖ\~ }]G5G]lұw4sCq_F|K4ű18.#͕d8# ]Hx('-#mзe :q&vS2ePCOkNa`.eC j (_8\Ή;7S˓r$u R؎ZwMm婰n }D_EO-gZTcEݪ,d÷:mSn=٘.iC8ONb"aEh'vCF2mK.]v[0(#CbEݙi }gNmW.Ѥb?>9 0e{/Q7+}cKl$Gury\OqM%g itͽr/{ԔWU&T,9O,[w$-mK.]bZrX̳QY͛c-ǟ59ޒSV`-ug-vmP-᫡A6ƚ:sfk [wJT[.'21 8\,.5SŔ{YtI76BXQ1ƴ.CcѝirE71|^+۴?;co[u- \ʍa*~闱nKgGm':wy]䇻n`ðGbq0$u-yw ۂ 1$\`*ERnMy,H$t\m嗰n 'Qۙ5A8Ԭ)cV1ct$W.1[]u  q/ݤ-:{Yt"1ِ r)5H"#QNYDIQ$Zf7YFe^>ȑ%_®~-%Nx3' EkNO$OęP1t ^#$iR:$[WˁX+LxqMIp!y&$XND! W0RkUڔ*MDka{6}^53hk^jKQu8y 5npZwdlsƍ[|Ub 0^䜻wm>t/C$2)4#9e'ĩ$pKMKqvB4fL 󢑠#LXz H46zq"{uk-Y E6%7-}:OS392+XŤiSIlD4[5bL,niOݿ-DZga.LHЧ!K[0f qgbc/mRyCgs8ǎ8Į3N̑!XJƑ#0Æ|dSRz#GOw]$n)^L Ȍi$h}蛍3? WcC5;)ٔj_3:Hr9/ TNS4vqX蹱ZoZ8hhږ\~ TD<335tmwAL99kÙY=˳mV[vĨܳa)Lr.a+̔ 1ur˷/aWģ*t{Hꍝ #0u\YXQ-SB碌dYۖ\~ tDZz9X Ⱦ2_0E{'w/?;y9kb &t۶Kox=9,V9p;Nŵ۲v=~aMeWbSSضo~-,4-ԒgXs#;f12ۆ֚;)]1jQĢka\,+L5d{T#q:RYS+ 4t%7-#d.y1K3ljc)"h ,ŗ8%ȋ#pyS+ tڴj18`ck"`#BCҎs‰hY.CNX·ZKʐMI qreA =QO}YRKQ"8.G \upv=qdMW1U8UVy aARDGzKb sqiYlI6%7-}\bz}D]̙GZk)bc<7myZ3mJJo[|qZX"AXD CZ%*݉8`\V㻪_))!nU|&,J Ε9si{F՛ڳ9K,Rwʖ-vmi<uĖk y0qbyRMH>w +;,,`QaMے/aWݖ᱿b idT9)\46Ϳǖ;tWFk*ϯ%Om,&-gTM"jKTcWC!os6RE,\sVTU`0<"n%Eۖ\~ S3&`H nJ`IQ7- Cv}Q-oU~mٹBݳ3ds6'׬ '#kg?fW ul[r%r$F*df6τ:2hrwXSO%V%ݤ|3o~-b8˞1aUw(9CF }ts| '"7ZL)u-vmab<.&@OE,Fn Z7E{Lb);Fa3mc'229%_ԝqi[r%rfsP'^בP"^C 0HXQ5b[ʗֽe[l[r%YP0n+3".);J΢f_gQxxe^.Yζ-®~Pޚ_+KoE@ ~u- QVUuOݶ=}ۖ\~ShKYQk\o$1)b @cE^N8P7)-_kQE7۲JEMmkgcbTQFr{1VTu䨞7Yti[r%vFam-_Zk`]vFyG0|9XyuӶKoGc49rrpQ#J92J[ĊkdSˤkdے/aWݖʪw~5&XHћ)C aY=XQ˝6W)m[r]b_t-ba-~1G9IVɢ4s+*Sg'u܌e6i[r%ݖr`dl 8:XF, [Ċ擜!银%_®~-66,[VZY۲[$leruXV,[%_®~mHLr^IĚ )E-ueyE|N-v[mŖ Sm9lCng j>XHĊ9"@irE7ﶔ *]UE=|g:H@XQK%gt]ڦ~oaX}goEBtm)C aƚ>-h5jz:mK.ۂROɩl? NED`TcT/1Rc0v~ǭuӶKoe (£"'JPEul/}-?d9u{x9mK.]v[pfޥ꓃,EZ.Ue9K+*K'Zb,U%_®~-gMMCQiꦾr|+śVotgMMے/aWՖz'*V+/*{nlkXoˍ58l { ֺIײ-nˎݝi/9x cڙAPOE+k{/9͵š]Ǘ%_®~-C)@lo+{%=9(L؎uwm嗰nKavıVE U  ;YHug >cEe‰Wa5_e>!ۖ~{Yls\A^t^ i H^\'t9n[7)%_~m*..FcYCa۱ )ǐoTcAp"j~࢖pHCn[~dSRz#*\ҌΊmX?)D*†ө$Z<&f ,۔j+/ Ih̍i t;DPS,Ƒ9 GUQk))ncsL3p2jM'N^vy03 R#2ͨ"|ԚG2m_q{XKl*Ca`ȳQiÈZԗZIʊSPX!Qpi ~-LgTwgFMz3b1Ewr-vmaQ9/hXU"A"rTdKe㭛Mۖ/aW99v")vehت)XHc l;b씺Vi[r%r^Nˡsɩ|j6&\l*"{Ɗ*%gb<ңnQ5l[nےǢK>N](֋HBj*핔sXS- cSYUX<Ð%?|9v[&VONCsAƎ,:,0ĊgE]2 ζ%>E ³nr :?FF7-_cEXÜkcuireR07J9;3O.5 rqM1‰؎ܺ{FZڶ)jK媢˛3f(G#Tvxr4y2˛sD9ZU-=%nˁV[iEQ}q5$>Z+YS98=uM[~+m[rE7ݖOOrvB/fl][YN8=3Iږ\~ `-3x50X\ cE^%h+{.9妣u-mK.]v[X,=msY}qACHJ{+gOaNChcq/u)l[r%c.lvo'Aesи:?[l^Ċ6m敱M"nˁOAl;P;x:l/3%?drr8.0#˶%_~mɲh {0-GDbEbrmܶ%_®~-%ě}s/xKɻn9";+jx29|QG2u7;m嗰n Y;", aTګ|0zDXQI'961TB3Nږ\~ Tc_c3D^ 7V9؆u6o~-Gb8>VTk)i*很k+,uŶ%_~mX)Z9X. q-Fj ՖѢX*Jݙ 0mK.]v[gh6nt꫗wr+ScNcpHk-vm)gЙt_)hT+9+*#`Sc&KM%_®~-q` 4za.!H75/sp fa7{Y-mSnۂ3fNSGUH\M^jI> XS%lv ۱k=hmrE7n|- Tv -XQi6u鞃su0HMm婰n ^Ft}1xŷCC8``9'{%99XLy3mK.]v[Wyrpu3u& qc+דш]r=ٶ%_®~0^N;rb\/a/B,A&9ؤO,r)_~m9}hliΎƤNj,l/6s$Nn#QsXL-G-"n1z ?mH^ڋ/^[aI홊+9cU3m[.O]v[:D;1V!#ؼrhiSBaUr$1vuir%Rѳ$}+ͩ m + -ÔEXO_?s\2Ly焄s0 }wk3%Or e C'%\N1(ҹp9rxaȺXQO'gGcq-yw]&FҘ0l̹GRəXQ{ j\-v9EP7xfPxjuQ[i#lI)ni۔/b}G>|vb΃G;4\l/AßkOrP(&{)-vmAu-W!boH*͆ !עt~O&xuN"6{@nR5m[.O]v[9N6ggV,E,N }7e{}r,$Vq9c]c;HwqmK.]v[/Y@|_ĩr6d72ٸXQY:9v$ʺm嗰n Av} LJaARԗTʬA Lbk6ugV۴-v^+'uWD"e{ydy)&b958XK[C<$8;/'99ڂDQ4$.uJV {cCN3Խf %v0Fs-mK.]v[P3sSac&h8Xne $O9A+dQsXۀ؈S/]Ո\~ }SQzg},w)S ō=\Wk lc˥b?o]v[;yGa IC2=)䈸I).b#'խԗ<9-_®~l(^ON;\бƖԗ"JάƊ31%bfKwQٶ\~ }DyerSmYYkqqr5=LBU8t׼維9ӥn(ؑ#.dl:R~1v&={ݳ6mK.ʢ۹]~q!8( b`=l-G$5x^y]f-C-| -f(,ĉ'؊ O49JKL=_D'><L+>$mޑ)*{>KfG`|p&۝L6%7-} xu3xyyD:zJ(lj% K \N$Sش z(bH}b^qʉ."t"͠Gh,"@]iYC6)7ĭٿ4gjNŤ3v]BQLرd~HaEIɜdGSlryJ7-?q|-_v`/Â,BF+ȏ=K2fԎ:A=}h~:SHONDV!hZ36)7ĭeh_m̋WS=Z_>~wO폿U A տ?~ҳ%dendstream endobj 3 0 obj << /Type /Pages /Kids [ 7 0 R ] /Count 1 /MediaBox [0 0 504 504] >> endobj 4 0 obj << /ProcSet [/PDF /Text] /Font <> /ExtGState << /GS1 11 0 R /GS2 12 0 R /GS257 13 0 R /GS258 14 0 R >> /ColorSpace << /sRGB 5 0 R >> >> endobj 5 0 obj [/ICCBased 6 0 R] endobj 6 0 obj << /Alternate /DeviceRGB /N 3 /Length 2596 /Filter /FlateDecode >> stream xwTSϽ7PkhRH H.*1 J"6DTpDQ2(C"QDqpId߼y͛~kg}ֺLX Xňg` lpBF|،l *?Y"1P\8=W%Oɘ4M0J"Y2Vs,[|e92<se'9`2&ctI@o|N6(.sSdl-c(2-yH_/XZ.$&\SM07#1ؙYrfYym";8980m-m(]v^DW~ emi]P`/u}q|^R,g+\Kk)/C_|Rax8t1C^7nfzDp 柇u$/ED˦L L[B@ٹЖX!@~(* {d+} G͋љς}WL$cGD2QZ4 E@@A(q`1D `'u46ptc48.`R0) @Rt CXCP%CBH@Rf[(t CQhz#0 Zl`O828.p|O×X ?:0FBx$ !i@ڐH[EE1PL ⢖V6QP>U(j MFkt,:.FW8c1L&ӎ9ƌaX: rbl1 {{{;}#tp8_\8"Ey.,X%%Gщ1-9ҀKl.oo/O$&'=JvMޞxǥ{=Vs\x ‰N柜>ucKz=s/ol|ϝ?y ^d]ps~:;/;]7|WpQoH!ɻVsnYs}ҽ~4] =>=:`;cܱ'?e~!ańD#G&}'/?^xI֓?+\wx20;5\ӯ_etWf^Qs-mw3+?~O~endstream endobj 9 0 obj << /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [ 45/minus 96/quoteleft 144/dotlessi /grave /acute /circumflex /tilde /macron /breve /dotaccent /dieresis /.notdef /ring /cedilla /.notdef /hungarumlaut /ogonek /caron /space] >> endobj 10 0 obj << /Type /Font /Subtype /Type1 /Name /F2 /BaseFont /Helvetica /Encoding 9 0 R >> endobj 11 0 obj << /Type /ExtGState /CA 0.867 >> endobj 12 0 obj << /Type /ExtGState /CA 1.000 >> endobj 13 0 obj << /Type /ExtGState /ca 1.000 >> endobj 14 0 obj << /Type /ExtGState /ca 0.867 >> endobj xref 0 15 0000000000 65535 f 0000000021 00000 n 0000000164 00000 n 0000021664 00000 n 0000021747 00000 n 0000021911 00000 n 0000021944 00000 n 0000000213 00000 n 0000000293 00000 n 0000024639 00000 n 0000024896 00000 n 0000024993 00000 n 0000025042 00000 n 0000025091 00000 n 0000025140 00000 n trailer << /Size 15 /Info 1 0 R /Root 2 0 R >> startxref 25189 %%EOF RcppArmadillo/vignettes/RcppArmadillo-unitTests.Rnw0000644000176000001440000000402712253723621022272 0ustar ripleyusers\documentclass[10pt]{article} %\VignetteIndexEntry{RcppArmadillo-unitTests} %\VignetteKeywords{R,Armadillo,Rcpp,unit tests} %\VignettePackage{RcppArmadillo} \usepackage{vmargin} \setmargrb{0.75in}{0.75in}{0.75in}{0.75in} \RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave \RequirePackage[T1]{fontenc} <>= require(RcppArmadillo) prettyVersion <- packageDescription("RcppArmadillo")$Version prettyDate <- format(Sys.Date(), "%B %e, %Y") library(RUnit) @ \usepackage[colorlinks]{hyperref} \author{Dirk Eddelbuettel, Romain Fran\c{c}ois and Douglas Bates} \title{\textbf{RcppArmadillo}: Unit testing results} \date{\textbf{RcppArmadillo} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}} \begin{document} \maketitle \section*{Test Execution} <>= pkg <- "RcppArmadillo" if (file.exists("unitTests-results")) unlink("unitTests-results", recursive = TRUE) dir.create("unitTests-results") pathRcppArmadilloTests <<- system.file("unitTests", package = pkg) path <- system.file("unitTests", package=pkg) testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs=path) tests <- runTestSuite(testSuite) err <- getErrors(tests) if (err$nFail > 0) stop(sprintf("unit test problems: %d failures", err$nFail)) if (err$nErr > 0) stop( sprintf("unit test problems: %d errors", err$nErr)) printHTMLProtocol(tests, fileName=sprintf("unitTests-results/%s-unitTests.html", pkg)) printTextProtocol(tests, fileName=sprintf("unitTests-results/%s-unitTests.txt" , pkg)) if (file.exists("/tmp")) { invisible(sapply(c("txt", "html"), function(ext) { fname <- sprintf("unitTests-results/%s-unitTests.%s", pkg, ext) file.copy(fname, "/tmp", overwrite=TRUE) })) } @ \section*{Test Results} \begin{verbatim} <>= results <- "unitTests-results/RcppArmadillo-unitTests.txt" if (file.exists(results)) { writeLines(readLines(results)) } else{ writeLines( "unit test results not available" ) } @ \end{verbatim} \end{document} RcppArmadillo/vignettes/RcppArmadillo-intro.Rnw0000644000176000001440000012041712253723621021425 0ustar ripleyusers \documentclass[preprint,authoryear,times]{elsarticle} %\VignetteIndexEntry{RcppArmadillo-introduction} %\VignetteKeywords{R, C++, Armadillo, linear algebra, kalman filter} %\VignettePackage{RcppArmadillo} \usepackage{url} % break URLs \usepackage{booktabs} % fancier tables \usepackage{color} % color use \usepackage{listings} \definecolor{darkgray}{rgb}{0.975,0.975,0.975} \lstset{ % %basicstyle=\small, % the size of the fonts that are used for the code numbers=left, % where to put the line-numbers numberstyle=\tiny, % the size of the fonts that are used for the line-numbers stepnumber=2, % the step between two line-numbers. If it's 1, each line % will be numbered numbersep=5pt, % how far the line-numbers are from the code backgroundcolor=\color{darkgray}, % choose the background color. Must add \usepackage{color} showspaces=false, % show spaces adding particular underscores showstringspaces=false, % underline spaces within strings showtabs=false, % show tabs within strings adding particular underscores %frame=single, % adds a frame around the code tabsize=2, % sets default tabsize to 2 spaces captionpos=b, % sets the caption-position to bottom breaklines=true, % sets automatic line breaking breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace %title=\lstname, % show the filename of files included with \lstinputlisting; % also try caption instead of title %escapeinside={\%*}{*)}, % if you want to add a comment within your code %morekeywords={*,...} % if you want to add more keywords to the set % basicstyle=\ttfamily\small, commentstyle=\textsl, keywordstyle=\ttfamily\small %keywordstyle=\color{black}\bfseries\tt } \usepackage[colorlinks]{hyperref}% for \href \definecolor{link}{rgb}{0,0,0.3} % next few lines courtesy of RJournal.sty \hypersetup{ colorlinks,% citecolor=link,% filecolor=link,% linkcolor=link,% urlcolor=link } %%% from jss.cls defs \makeatletter \newcommand\code{\bgroup\@makeother\_\@makeother\~\@makeother\$\@codex} \def\@codex#1{{\normalfont\ttfamily\hyphenchar\font=-1 #1}\egroup} \makeatother %\newcommand{\proglang}[1]{\textsf{#1}} \newcommand{\proglang}[1]{#1} % also neutering the proglang macro \newcommand{\R}{\proglang{R}\ } % NB forces a space so not good before % fullstop etc. \newcommand{\Rns}{\proglang{R}} % without the space \newcommand{\Cpp}{\proglang{C++}\ } %\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}\index{#1}} %\newcommand{\pkg}[1]{{\it #1}} \newcommand{\pkg}[1]{{#1}} % null op for now \journal{Computational Statistics and Data Analysis} <>= prettyVersion <- packageDescription("RcppArmadillo")$Version #$ prettyDate <- format(Sys.Date(), "%B %e, %Y") @ \begin{document} \begin{frontmatter} \title{RcppArmadillo: Accelerating R \\with High-Performance C++ Linear Algebra\footnote{ This vignette corresponds to a \href{http://dx.doi.org/10.1016/j.csda.2013.02.005}{paper published} in \href{http://www.journals.elsevier.com/computational-statistics-and-data-analysis/}{Computational Statistics and Data Analysis}. Currently still identical to the paper, this vignette version may over time receive minor updates. For citations, please use \citet{Eddelbuettel+Sanderson:2014:RcppArmadillo} as provided by \code{citation("RcppArmadillo")}. % This version corresponds to \pkg{RcppArmadillo} version \Sexpr{prettyVersion} and was typeset on \Sexpr{prettyDate}. } } \author[de]{Dirk Eddelbuettel}%\corref{cor}} %\ead[de]{edd@debian.org} % \ead[de,url]{http://dirk.eddelbuettel.com} %\cortext[cor]{Corresponding author. Email: \url{edd@debian.org}.}% Postal address: 711 Monroe Avenue, %River Forest, IL 60305, USA. } %he \pkg{RcppArmadillo} package is available %with the electronic version of this article, as well as via every CRAN mirror.} \address[de]{Debian Project, \url{http://www.debian.org}} \author[cs1,cs2]{Conrad Sanderson} %\ead[cs1]{nowhere} % CS i'd prefer to leave out my email address %\ead[cs1,url]{http://www.nicta.com.au/people/sandersonc} %\ead[cs2,url]{http://itee.uq.edu.au/~conrad/} \address[cs1]{NICTA, PO Box 6020, St Lucia, QLD 4067, Australia} \address[cs2]{Queensland University of Technology (QUT), Brisbane, QLD 4000, Australia} \begin{abstract} \noindent The \proglang{R} statistical environment and language has demonstrated particular strengths for interactive development of statistical algorithms, as well as data modelling and visualisation. Its current implementation has an interpreter at its core which may result in a performance penalty in comparison to directly executing user algorithms in the native machine code of the host CPU. In contrast, the \proglang{C++} language has no built-in visualisation capabilities, handling of linear algebra or even basic statistical algorithms; however, user programs are converted to high-performance machine code, ahead of execution. % A new method avoids possible speed penalties in \proglang{R} by using the \pkg{Rcpp} extension package in conjunction with the \pkg{Armadillo} \Cpp matrix library. In addition to the inherent performance advantages of compiled code, \pkg{Armadillo} provides an easy-to-use template-based meta-programming framework, allowing the automatic pooling of several linear algebra operations into one, which in turn can lead to further speedups. With the aid of \pkg{Rcpp} and \pkg{Armadillo}, conversion of linear algebra centered algorithms from \proglang{R} to \proglang{C++} becomes straightforward. The algorithms retains the overall structure as well as readability, all while maintaining a bidirectional link with the host R environment. Empirical timing comparisons of \proglang{R} and \proglang{C++} implementations of a Kalman filtering algorithm indicate a speedup of several orders of magnitude. \end{abstract} \begin{keyword} Software \sep R \sep C++ \sep linear algebra \end{keyword} \end{frontmatter} \section{Overview} Linear algebra is a cornerstone of statistical computing and statistical software systems. Various matrix decompositions, linear program solvers, and eigenvalue / eigenvector computations are key to many estimation and analysis routines. As generally useful procedures, these are often abstracted and regrouped in specific libraries for linear algebra which statistical programmers have provided for various programming languages and environments. One such environment and statistical programming language is R \citep{R:Main}. It has become a tool of choice for data analysis and applied statistics \citep{Morandat_2012}. While R has particular strengths at fast prototyping and easy visualisation of data, its implementation has an interpreter at its core. In comparison to running user algorithms in the native machine code of the host CPU, the use of an interpreter often results in a performance penalty for non-trivial algorithms that perform elaborate data manipulation \citep{Morandat_2012}. With user algorithms becoming more complex and increasing in functionality, as well as with data sets which continue to increase in size, the issue of execution speed becomes more important. The \Cpp language offers a complementary set of attributes: while it has no built-in visualisation capabilities nor handling of linear algebra or statistical methods, user programs are converted to high-performance machine code ahead of execution. It is also inherently flexible. One key feature is \textit{operator overloading} which allows the programmer to define custom behaviour for mathematical operators such as $+$, $-$, $*$ \citep{Meyers:2005:EffectiveC++}. \Cpp also provides language constructs known as {\it templates}, originally intended to easily allow the reuse of algorithms for various object types, and later extended to a programming construct in its own right called \textit{template meta-programming} \citep{Vandevoorde_2002,Abrahams_2004} Operator overloading allows mathematical operations to be extended to user-defined objects, such as matrices. This in turn allows linear algebra expressions to be written in a more natural manner (eg.~\mbox{$X = 0.1*A + 0.2*B$}), rather than the far less readable traditional function call syntax, eg.~\mbox{$X = \mbox{\it add}(\mbox{\it multiply}(0.1,A), \mbox{\it multiply}(0.2,B))$}. Template meta-programming is the process of inducing the \Cpp compiler to execute, at compile time, Turing-complete programs written in a somewhat opaque subset of the \Cpp language~\citep{Vandevoorde_2002,Abrahams_2004}. These meta-programs in effect generate further \Cpp code (often specialised for particular object types), which is finally converted into machine code. An early and influential example of exploiting both meta-programming and overloading of mathematical operators was provided by the Blitz++ library \citep{Veldhuizen:1998:Blitz}, targeted for efficient processing of arrays. Blitz++ employed elaborate meta-programming to avoid the generation of temporary array objects during the evaluation of mathematical expressions. However, the library's capabilities and usage were held back at the time by the limited availability of compilers correctly implementing all the necessary features and nuances of the \Cpp language. We present a new method of avoiding the speed penalty in R by using the Rcpp extension package \citep{Eddelbuettel+Francois:2011:Rcpp, CRAN:Rcpp,Eddelbuettel:2013:Rcpp} in conjunction with the \pkg{Armadillo} \Cpp linear algebra library \citep{Sanderson:2010:Armadillo}. Similar to Blitz++, \pkg{Armadillo} uses operator overloading and various template meta-programming techniques to attain efficiency. However, it has been written to target modern \Cpp compilers as well as providing a much larger set of linear algebra operations than Blitz++. R programs augmented to use \pkg{Armadillo} retain the overall structure as well as readability, all while retaining a bidirectional link with the host R environment. Section~\ref{sec:arma} provides an overview of \pkg{Armadillo}, followed by its integration with the Rcpp extension package. Section~\ref{sec:kalman} shows an example of an R program and its conversion to \Cpp via Rcpp and \pkg{Armadillo}. Section~\ref{sec:speed} discusses an empirical timing comparison between the R and \Cpp versions before Section~\ref{sec:conclusion} concludes. \section{Armadillo} \label{sec:arma} The \pkg{Armadillo} \Cpp library provides vector, matrix and cube types (supporting integer, floating point and complex numbers) as well as a subset of trigonometric and statistics functions~\citep{Sanderson:2010:Armadillo}. In addition to elementary operations such as addition and matrix multiplication, various matrix factorisations and submatrix manipulation operations are provided. The corresponding application programming interface (syntax) enables the programmer to write code which is both concise and easy-to-read to those familiar with scripting languages such as \proglang{Matlab} and \proglang{R}. Table~\ref{tab:arma} lists a few common \pkg{Armadillo} functions. Matrix multiplication and factorisations are accomplished through integration with the underlying operations stemming from standard numerical libraries such as BLAS and LAPACK~\citep{Demmel_1997}. Similar to how environments such as R are implemented, these underlying libraries can be replaced in a transparent manner with variants that are optimised to the specific hardware platform and/or multi-threaded to automatically take advantage of the now-common multi-core platforms~\citep{Kurzak_2010}. \begin{table}[!b] \centering \footnotesize \begin{tabular}{ll} \toprule \textbf{Armadillo function} \phantom{XXXXXXX} & \textbf{Description} \\ \midrule \code{X(1,2) = 3} & Assign value 3 to element at location (1,2) of matrix $X$ \\ % DE shortened to fit on \textwidth \code{X = A + B} & Add matrices $A$ and $B$ \\ \code{X( span(1,2), span(3,4) )} & Provide read/write access to submatrix of $X$ \\ \code{zeros(rows [, cols [, slices]))} & Generate vector (or matrix or cube) of zeros\\ \code{ones(rows [, cols [, slices]))} & Generate vector (or matrix or cube) of ones\\ \code{eye(rows, cols)} & Matrix diagonal set to 1, off-diagonal elements set to 0 \\ %\code{linspace(start, end, N=100)} & $N$ element vector with elements from start to end \\ \code{repmat(X, row_copies, col_copies)} & Replicate matrix $X$ in block-like manner \\ \code{det(X)} & Returns the determinant of matrix $X$\\ %\code{dot(A, B)} & Dot-product of confirming vectors $A$ and $B$ \\ \code{norm(X, p)} & Compute the $p$-norm of matrix or vector $X$\\ \code{rank(X)} & Compute the rank of matrix $X$ \\ %\code{trace(X)} & Compute the trace of matrix $X$ \\ %\code{diagvec(X, k=0)} & Extracts the $k$-th diagnonal from matrix $X$\\ \code{min(X, dim=0)};~ \code{max(X, dim=0)} & Extremum value of each column~of $X$~(row if \code{dim=1}) \\ \code{trans(X)} ~or~ \code{X.t()} & Return transpose of $X$ \\ \code{R = chol(X)} & Cholesky decomposition of $X$ such that $R^{T} R = X$ \\ \code{inv(X)} ~or~ \code{X.i()} & Returns the inverse of square matrix $X$ \\ \code{pinv(X)} & Returns the pseudo-inverse of matrix $X$ \\ \code{lu(L, U, P, X)} & LU decomp.~with partial pivoting; also \code{lu(L, U, X)} \\ %\code{lu(L, U, P, X)} & LU decomposition with partial pivoting \\ \code{qr(Q, R, X)} & QR decomp.~into orthogonal $Q$ and right-triangular $R$\\ \code{X = solve(A, B)} & Solve system $AX = B$ for $X$ \\ \code{s = svd(X); svd(U, s, V, X)} & Singular-value decomposition of $X$ \\ \bottomrule \end{tabular} \caption{Selected \pkg{Armadillo} functions with brief descriptions; see \texttt{http://arma.sf.net/docs.html} for more complete documentation. Several optional additional arguments have been omitted here for brevity.\label{tab:arma}} \end{table} \pkg{Armadillo} uses a delayed evaluation approach to combine several operations into one and reduce (or eliminate) the need for temporary objects. In contrast to brute-force evaluations, delayed evaluation can provide considerable performance improvements as well as reduced memory usage. The delayed evaluation machinery is accomplished through template meta-programming~\citep{Vandevoorde_2002,Abrahams_2004}, where the \Cpp compiler is induced to reason about mathematical expressions at {\it compile time}. Where possible, the \Cpp compiler can generate machine code that is tailored for each expression. As an example of the possible efficiency gains, let us consider the expression \mbox{$X = A - B + C$}, where $A$, $B$ and $C$ are matrices. A brute-force implementation would evaluate $A-B$ first and store the result in a temporary matrix $T$. The next operation would be \mbox{$T + C$}, with the result finally stored in $X$. The creation of the temporary matrix, and using two separate loops for the subtraction and addition of matrix elements is suboptimal from an efficiency point of view. Through the overloading of mathematical operators, \pkg{Armadillo} avoids the generation of the temporary matrix by first converting the expression into a set of lightweight \code{Glue} objects, which only store references to the matrices and \pkg{Armadillo}'s representations of mathematical expressions (eg.~other \code{Glue} objects). To indicate that an operation comprised of subtraction and addition is required, the exact type of the \code{Glue} objects is automatically inferred from the given expression through template meta-programming. More specifically, given the expression \mbox{$X = A - B + C$}, \pkg{Armadillo} automatically induces the compiler to generate an instance of the lightweight \code{Glue} storage object with the following \Cpp {\it type}: \centerline{~} \centerline{\code{Glue< Glue, Mat, glue\_plus>}} \centerline{~} \noindent where \code{Glue<...>} indicates that \code{Glue} is a C++ template class, with the items between `\code{<}' and `\code{>}' specifying template parameters; the outer \code{Glue<..., Mat, glue\_plus>} is the \code{Glue} object indicating an addition operation, storing a reference to a matrix as well as a reference to another \code{Glue} object; the inner \code{Glue} stores references to two matrices and indicates a subtraction operation. In both the inner and outer \code{Glue}, the type \code{Mat} specifies that a reference to a matrix object is to be held. The expression evaluator in \pkg{Armadillo} is then automatically invoked through the ``\code{=}'' operation, which interprets (at compile time) the template parameters of the compound \code{Glue} object and generates \Cpp code equivalent to: \centerline{~} \centerline{\code{for(int i=0; i library(inline) R> R> g <- cxxfunction(signature(vs="numeric"), + plugin="RcppArmadillo", body=' + arma::vec v = Rcpp::as(vs); + arma::mat op = v * v.t(); + double ip = arma::as_scalar(v.t() * v); + return Rcpp::List::create(Rcpp::Named("outer")=op, + Rcpp::Named("inner")=ip); +') R> g(7:11) $outer [,1] [,2] [,3] [,4] [,5] [1,] 49 56 63 70 77 [2,] 56 64 72 80 88 [3,] 63 72 81 90 99 [4,] 70 80 90 100 110 [5,] 77 88 99 110 121 $inner [1] 415 \end{lstlisting} Consider the simple example in Listing~\ref{code:RcppArmaEx}. Given a vector, the \code{g()} function returns both the outer and inner products. We load the inline package \citep{CRAN:inline}, which provides \code{cxxfunction()} that we use to compile, link and load the \Cpp code which is passed as the \code{body} argument. We declare the function signature to contain a single argument named `\code{vs}'. On line five, this argument is used to instantiate an \pkg{Armadillo} column vector object named `\code{v}' (using the templated conversion function \code{as()} from Rcpp). In lines six and seven, the outer and inner product of the column vector are calculated by appropriately multiplying the vector with its transpose. This shows how the \code{*} operator for multiplication has been overloaded to provide the appropriate operation for the types implemented by \pkg{Armadillo}. The inner product creates a scalar variable, and in contrast to \R where each object is a vector type (even if of length one), we have to explicitly convert using \code{as_scalar()} to assign the value to a variable of type \code{double}. Finally, the last line creates an \R named list type containing both results. As a result of calling \code{cxxfunction()}, a new function is created. It contains a reference to the native code, compiled on the fly based on the \Cpp code provided to \code{cxxfunction()} and makes it available directly from \R under a user-assigned function name, here \code{g()}. The listing also shows how the \code{Rcpp} and \code{arma} namespaces are used to disambiguate symbols from the two libraries; the \code{::} operator is already familiar to R programmers who use the NAMESPACE directive in \R in a similar fashion. The listing also demonstrates how the new function \code{g()} can be called with a suitable argument. Here we create a vector of five elements, containing values ranging from 7 to 11. The function's output, here the list containing both outer and inner product, is then displayed as it is not assigned to a variable. This simple example illustrates how \R objects can be transferred directly into corresponding \pkg{Armadillo} objects using the interface code provided by \pkg{Rcpp}. It also shows how deployment of \pkg{RcppArmadillo} is straightforward, even for interactive work where functions can be compiled on the fly. Similarly, usage in packages is also uncomplicated and follows the documentation provided with \pkg{Rcpp}~\citep{CRAN:Rcpp,Eddelbuettel:2013:Rcpp}. \section{Kalman Filtering Example} \label{sec:kalman} The Kalman filter is ubiquitous in many engineering disciplines as well as in statistics and econometrics~\citep{Tusell:2010:Kalman}. A recent example of an application is volatility extraction in a diffusion option pricing model~\citep{Li_CSDA_2013}. Even in its simplest linear form, the Kalman filter can provide simple estimates by recursively applying linear updates which are robust to noise and can cope with missing data. Moreover, the estimation process is lightweight and fast, and consumes only minimal amounts of memory as few state variables are required. % We discuss a standard example below. The (two-dimensional) position of an object is estimated based on past values. A $6 \times 1$ state vector includes $X$ and $Y$ coordinates determining the position, two variables for speed (or velocity) $V_X$ and $V_Y$ relative to the two coordinates, as well as two acceleration variables $A_X$ and $A_Y$. We have the positions being updated as a function of the velocity \begin{displaymath} X = X_0 + V_X dt \mbox{\phantom{XX} and \phantom{XX}} Y = Y_0 + V_Y dt, \end{displaymath} \noindent and the velocity being updated as a function of the (unobserved) acceleration: \begin{displaymath} V_x = V_{X,0} + A_X dt \mbox{\phantom{XX} and \phantom{XX}} V_y = V_{Y,0} + A_Y dt. \end{displaymath} % \begin{eqnarray*} % X & = & X_0 + V_x dt \\ % Y & = & Y_0 + V_y dt \\ % V_x & = & V_{x,0} + A_x dt \\ % V_y & = & V_{y,0} + A_y dt \\ % \end{eqnarray*} With covariance matrices $Q$ and $R$ for (Gaussian) error terms, the standard Kalman filter estimation involves a linear prediction step resulting in a new predicted state vector, and a new covariance estimate. This leads to a residuals vector and a covariance matrix for residuals which are used to determine the (optimal) Kalman gain, which is then used to update the state estimate and covariance matrix. All of these steps involve only matrix multiplication and inversions, making the algorithm very suitable for an implementation in any language which can use matrix expressions. An example for \proglang{Matlab} is provided on the Mathworks website\footnote{See \url{http://www.mathworks.com/products/matlab-coder/demos.html?file=/products/demos/shipping/coder/coderdemo_kalman_filter.html}.} and shown in Listing~\ref{code:matlabkalman}. \lstset{ language=matlab, basicstyle=\ttfamily\footnotesize, caption={Basic Kalman filter in \proglang{Matlab}.}, label={code:matlabkalman} } \begin{lstlisting}[frame=tb] % Copyright 2010 The MathWorks, Inc. function y = kalmanfilter(z) dt=1; % Initialize state transition matrix A=[ 1 0 dt 0 0 0; 0 1 0 dt 0 0;... % [x ], [y ] 0 0 1 0 dt 0; 0 0 0 1 0 dt;... % [Vx], [Vy] 0 0 0 0 1 0 ; 0 0 0 0 0 1 ]; % [Ax], [Ay] H = [ 1 0 0 0 0 0; 0 1 0 0 0 0 ]; % Init. measuremnt mat Q = eye(6); R = 1000 * eye(2); persistent x_est p_est % Init. state cond. if isempty(x_est) x_est = zeros(6, 1); % x_est=[x,y,Vx,Vy,Ax,Ay]' p_est = zeros(6, 6); end x_prd = A * x_est; % Predicted state + covar. p_prd = A * p_est * A' + Q; S = H * p_prd' * H' + R; % Estimation B = H * p_prd'; klm_gain = (S \ B)'; % Estimated state and covariance x_est = x_prd + klm_gain * (z - H * x_prd); p_est = p_prd - klm_gain * H * p_prd; y = H * x_est; % Comp. estim. measurements end % of the function \end{lstlisting} % function x = kalmanExample % load pos.txt; % renamed here % x = kalmanM(pos); \lstset{ language=R, basicstyle=\ttfamily\small, caption={Basic Kalman filter in \Rns ~ (referred to as {\it FirstKalmanR}).}, label={code:FirstKalmanR} } \begin{lstlisting}[frame=tb] FirstKalmanR <- function(pos) { kalmanfilter <- function(z) { dt <- 1 A <- matrix(c( 1, 0, dt, 0, 0, 0, 0, 1, 0, dt, 0, 0, # x, y 0, 0, 1, 0, dt, 0, 0, 0, 0, 1, 0, dt, # Vx, Vy 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1), # Ax, Ay 6, 6, byrow=TRUE) H <- matrix( c(1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), 2, 6, byrow=TRUE) Q <- diag(6) R <- 1000 * diag(2) xprd <- A %*% xest # predicted state and covriance pprd <- A %*% pest %*% t(A) + Q S <- H %*% t(pprd) %*% t(H) + R # estimation B <- H %*% t(pprd) kalmangain <- t(solve(S, B)) ## estimated state and covariance, assign to vars in parent env xest <<- xprd + kalmangain %*% (z - H %*% xprd) pest <<- pprd - kalmangain %*% H %*% pprd ## compute the estimated measurements y <- H %*% xest } xest <- matrix(0, 6, 1) pest <- matrix(0, 6, 6) N <- nrow(pos) y <- matrix(NA, N, 2) for (i in 1:N) { y[i,] <- kalmanfilter(t(pos[i,,drop=FALSE])) } invisible(y) } \end{lstlisting} A straightforward \R implementation can be written as a close transcription of the \proglang{Matlab} version; we refer to this version as \code{FirstKalmanR}. It is shown in Listing~\ref{code:FirstKalmanR}. A slightly improved version (where several invariant statements are moved out of the repeatedly-called function) is provided in Listing~\ref{code:Rkalman} on page~\pageref{code:Rkalman} showing the function \code{KalmanR}. The estimates of the state vector and its covariance matrix are updated iteratively. The \proglang{Matlab} implementation uses two variables declared `persistent' for this. In \Rns, which does not have such an attribute for variables, we store them in the enclosing environment of the outer function \code{KalmanR}, which contains an inner function \code{kalmanfilter} that is called for each observation. \pkg{Armadillo} provides efficient vector and matrix classes to implement the Kalman filter. In Listing~\ref{code:CppKalmanClass} on page~\pageref{code:CppKalmanClass}, we show a simple \Cpp class containing a basic constructor as well as one additional member function. The constructor can be used to initialise all variables as we are guaranteed that the code in the class constructor will be executed exactly once when this class is instantiated. A class also makes it easy to add `persistent' local variables, which is a feature we need here. Given such a class, the estimation can be accessed from \R via a short and simple routine such as the one shown in Listing~\ref{code:InlineKalman}. \lstset{ language=R, basicstyle=\ttfamily\small, caption={An improved Kalman filter implemented in \Rns ~ (referred to as {\it KalmanR}).}, label={code:Rkalman} } \begin{lstlisting}[frame=tb] KalmanR <- function(pos) { kalmanfilter <- function(z) { ## predicted state and covariance xprd <- A %*% xest pprd <- A %*% pest %*% t(A) + Q ## estimation S <- H %*% t(pprd) %*% t(H) + R B <- H %*% t(pprd) kalmangain <- t(solve(S, B)) ## estimated state and covariance ## assigned to vars in parent env xest <<- xprd + kalmangain %*% (z - H %*% xprd) pest <<- pprd - kalmangain %*% H %*% pprd ## compute the estimated measurements y <- H %*% xest } dt <- 1 A <- matrix( c( 1, 0, dt, 0, 0, 0, # x 0, 1, 0, dt, 0, 0, # y 0, 0, 1, 0, dt, 0, # Vx 0, 0, 0, 1, 0, dt, # Vy 0, 0, 0, 0, 1, 0, # Ax 0, 0, 0, 0, 0, 1), # Ay 6, 6, byrow=TRUE) H <- matrix( c(1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), 2, 6, byrow=TRUE) Q <- diag(6) R <- 1000 * diag(2) N <- nrow(pos) Y <- matrix(NA, N, 2) xest <- matrix(0, 6, 1) pest <- matrix(0, 6, 6) for (i in 1:N) { Y[i,] <- kalmanfilter(t(pos[i,,drop=FALSE])) } invisible(Y) } \end{lstlisting} \lstset{ language=C++, basicstyle=\ttfamily\small, caption={A Kalman filter class in \proglang{C++}, using \pkg{Armadillo} classes.}, label={code:CppKalmanClass} } \begin{lstlisting}[frame=tb] using namespace arma; class Kalman { private: mat A, H, Q, R, xest, pest; double dt; public: // constructor, sets up data structures Kalman() : dt(1.0) { A.eye(6,6); A(0,2) = A(1,3) = A(2,4) = A(3,5) = dt; H.zeros(2,6); H(0,0) = H(1,1) = 1.0; Q.eye(6,6); R = 1000 * eye(2,2); xest.zeros(6,1); pest.zeros(6,6); } // sole member function: estimate model mat estimate(const mat & Z) { unsigned int n = Z.n_rows, k = Z.n_cols; mat Y = zeros(n, k); mat xprd, pprd, S, B, kalmangain; colvec z, y; for (unsigned int i = 0; i kalmanSrc <- ' + mat Z = as(ZS); // passed from R + Kalman K; + mat Y = K.estimate(Z); + return wrap(Y);' R> KalmanCpp <- cxxfunction(signature(ZS="numeric"), + body=kalmanSrc, include=kalmanClass, + plugin="RcppArmadillo") \end{lstlisting} The content of Listing~\ref{code:CppKalmanClass} is assigned to a variable \code{kalmanClass} which (on line seven) is passed to the \code{include=} argument. This provides the required class declaration and definition. The four lines of code in lines two to five, assigned to \code{kalmanSrc}, provide the function body required by \code{cxxfunction()}. From both these elements and the function signature argument, \code{cxxfunction()} creates a very simple yet efficient \Cpp implementation of the Kalman filter which we can access from \Rns. Given a vector of observations $Z$, it estimates a vector of position estimates $Y$. \begin{figure}[H]%[!tb] \centerline{\includegraphics[width=0.75\columnwidth]{kalmanExample.pdf}} % for eps: \centerline{\includegraphics[width=0.85\columnwidth]{kalmanExample}} \caption{An example of object trajectory and the corresponding Kalman filter estimate.\label{fig:kalmanexample} } \end{figure} This is illustrated in Figure~\ref{fig:kalmanexample} which displays the original object trajectory (using light-coloured square symbols) as well as the position estimates provided by the Kalman filter (using dark-coloured circles). This uses the same dataset provided by the Mathworks for their example; the data is believed to be simulated. We note that this example is meant to be illustrative and does not attempt to provide a reference implementation of a Kalman filter. \proglang{R} contains several packages providing various implementations, as discussed in the survey provided by \cite{Tusell:2010:Kalman}. \section{Empirical Speed Comparison} \label{sec:speed} \lstset{ language=R, basicstyle=\ttfamily\small, caption={R code for timing comparison of Kalman filter implementations.}, label={code:BenchmarkKalman} } \begin{lstlisting}[frame=tb] R> require(rbenchmark) R> require(compiler) R> R> FirstKalmanRC <- cmpfun(FirstKalmanR) R> KalmanRC <- cmpfun(KalmanR) R> R> ## Read data, ensure identical results R> pos <- as.matrix(read.table("pos.txt", header=FALSE, + col.names=c("x","y"))) R> stopifnot(all.equal(KalmanR(pos), KalmanRC(pos)), + all.equal(KalmanR(pos), KalmanCpp(pos)), + all.equal(FirstKalmanR(pos), FirstKalmanRC(pos)), + all.equal(KalmanR(pos), FirstKalmanR(pos))) R> R> res <- benchmark(KalmanR(pos), KalmanRC(pos), + FirstKalmanR(pos), FirstKalmanRC(pos), + KalmanCpp(pos), + columns = c("test", "replications", + "elapsed", "relative"), + order="relative", + replications=100) \end{lstlisting} Listing~\ref{code:BenchmarkKalman} contains the code for creating a simple benchmarking exercise. It compares several functions for implementing the Kalman filter, all executed within the \R environment. Specifically, we examine the initial \R version \code{FirstKalmanR} shown in Listing~\ref{code:FirstKalmanR}, a refactored version \code{KalmanR} shown in Listing~\ref{code:Rkalman}, an improved version\footnote{The improved version replaces explicit transpose and multiplication with the \code{crossprod} function.} due to an anonymous referee (not shown, but included in the package), as well as byte-compiled versions (designated with a trailing `C') created by using the byte-code compiler introduced with \R version 2.13.0 \citep{Tierney:2012:ByteCompiler}. Finally, the \Cpp version shown in Listings~\ref{code:CppKalmanClass} and \ref{code:InlineKalman} is used. Also shown are the \R statements for creating the byte-compiled variants via calls to \code{cmpfun()}. This is followed by a test to ensure that all variants provide the same results. Next, the actual benchmark is executed before the result is displayed. %R> print(res) % test replications elapsed relative %5 KalmanCpp(pos) 100 0.087 1.0000 %2 KalmanRC(pos) 100 5.774 66.3678 %1 KalmanR(pos) 100 6.448 74.1149 %4 FirstKalmanRC(pos) 100 8.153 93.7126 %3 FirstKalmanR(pos) 100 8.901 102.3103 % more recent results: % test replications elapsed relative %6 KalmanCpp3(pos) 100 0.098 1.000000 %5 KalmanCpp(pos) 100 0.104 1.061224 %2 KalmanRC(pos) 100 5.579 56.928571 %1 KalmanR(pos) 100 5.807 59.255102 %4 FirstKalmanRC(pos) 100 8.196 83.632653 %3 FirstKalmanR(pos) 100 8.686 88.632653 \begin{table}[t!] \begin{center} \begin{small} \begin{tabular}{lrr} \toprule {\bf Implementation \phantom{XXX}} & {\bf Time in seconds} & {\bf Relative to best solution} \\ \cmidrule(r){1-3} KalmanCpp & 0.73 & 1.0 \\ KalmanRimpC & 21.10 & 29.0 \\ KalmanRimp & 22.01 & 30.2 \\ KalmanRC & 28.64 & 39.3 \\ KalmanR & 31.30 & 43.0 \\ FirstKalmanRC & 49.40 & 67.9 \\ FirstKalmanR & 64.00 & 88.0 \\ \bottomrule \end{tabular} \end{small} \caption{Performance comparison of various implementations of a Kalman filter. KalmanCpp is the \mbox{\pkg{RcppArmadillo}} based implementation in \Cpp shown in Listings~\ref{code:CppKalmanClass} and \ref{code:InlineKalman}. KalmanRimp is an improved version supplied by an anonymous referee which uses the \code{crossprod} function instead of explicit transpose and multiplication. KalmanR is the \R implementation shown in Listing~\ref{code:Rkalman}; FirstKalmanR is a direct translation of the original Matlab implementation shown in Listing~\ref{code:FirstKalmanR}. In all cases, the trailing `C' denotes a byte-compiled variant of the corresponding R code. Timings are averaged over 500 replications. The comparison was made using \proglang{R} version 2.15.2, \pkg{Rcpp} version 0.10.2 and \pkg{RcppArmadillo} version 0.3.6.1 on Ubuntu 12.10 running in 64-bit mode on a 2.67 GHz Intel i7 processor. \label{tab:benchmark} } \end{center} \end{table} The results are shown in Table~\ref{tab:benchmark}. Optimising and improving the \proglang{R} code has merits: we notice a steady improvement from the slowest \proglang{R} version to the fastest \proglang{R} version. Byte-compiling R code provides an additional performance gain which is more pronounced for the slower variant than the fastest implementation in \proglang{R}. However, the \code{KalmanCpp} function created using \mbox{\pkg{RcppArmadillo}} clearly outperforms all other variants, underscoring the principal point of this paper. These results are consistent with the empirical observations made by \cite{Morandat_2012}, who also discuss several reasons for the slow speed of R compared to the C language, a close relative of C++. \section{Conclusion} \label{sec:conclusion} This paper introduced the \pkg{RcppArmadillo} package for use within the R statistical environment. By using the \pkg{Rcpp} interface package, \pkg{RcppArmadillo} brings the speed of \Cpp along with the highly expressive \pkg{Armadillo} linear algebra library to the \R language. % A small example implementing a Kalman filter illustrated two key aspects. First, orders of magnitude of performance gains can be obtained by deploying \Cpp code along with \Rns. Second, the ease of use and readability of the corresponding C++ code is similar to the \R code from which it was derived. This combination makes \pkg{RcppArmadillo} a compelling tool in the arsenal of applied researchers deploying computational methods in statistical computing and data analysis. As of early-2013, about 30 \proglang{R} packages on CRAN deploy \pkg{RcppArmadillo}\footnote{See \url{http://cran.r-project.org/package=RcppArmadillo} for more details.}, showing both the usefulness of \proglang{Armadillo} and its acceptance by the \proglang{R} community. \section*{Acknowledgements} NICTA is funded by the Australian Government as represented by the Department of Broadband, Communications and the Digital Economy, as well as the Australian Research Council through the ICT Centre of Excellence program. Adam M.~Johansen provided helpful comments on an earlier draft. Comments by two anonymous referees and one editor further improved the paper and are gratefully acknowledged. \bibliographystyle{elsarticle-harv} \bibliography{RcppArmadillo} \end{document} %%% Local Variables: %%% mode: latex %%% TeX-master: t %%% End: RcppArmadillo/vignettes/elsarticle.cls0000644000176000001440000006275712253723621017721 0ustar ripleyusers%% %% This is file `elsarticle.cls', %% generated with the docstrip utility. %% %% The original source files were: %% %% elsarticle.dtx (with options: `class') %% %% Copyright 2007, 2008, 2009 Elsevier Ltd %% %% This file is part of the 'Elsarticle Bundle'. %% ------------------------------------------- %% %% It may be distributed under the conditions of the LaTeX Project Public %% License, either version 1.2 of this license or (at your option) any %% later version. The latest version of this license is in %% http://www.latex-project.org/lppl.txt %% and version 1.2 or later is part of all distributions of LaTeX %% version 1999/12/01 or later. %% %% The list of all files belonging to the 'Elsarticle Bundle' is %% given in the file `manifest.txt'. %% %% %% $Id: elsarticle.dtx 19 2009-12-17 07:07:52Z rishi $ %% \def\RCSfile{elsarticle}% \def\RCSversion{1.20b}% \def\RCSdate{2009/09/17}% \def\@shortjnl{\relax} \def\@journal{Elsevier Ltd} \def\@company{Elsevier Ltd} \def\@issn{000-0000} \def\@shortjid{elsarticle} \NeedsTeXFormat{LaTeX2e}[1995/12/01] \ProvidesClass{\@shortjid}[\RCSdate, \RCSversion: \@journal] \def\ABD{\AtBeginDocument} \newif\ifpreprint \preprintfalse \newif\iflongmktitle \longmktitlefalse \def\@blstr{1} \newdimen\@bls \@bls=\baselineskip \def\@finalWarning{% *****************************************************\MessageBreak This document is typeset in the CRC style which\MessageBreak is not suitable for submission.\MessageBreak \MessageBreak Please typeset again using 'preprint' option\MessageBreak for creating PDF suitable for submission.\MessageBreak ******************************************************\MessageBreak } \DeclareOption{preprint}{\global\preprinttrue \gdef\@blstr{1}\xdef\jtype{0}% \AtBeginDocument{\@twosidefalse\@mparswitchfalse}} \DeclareOption{final}{\gdef\@blstr{1}\global\preprintfalse} \DeclareOption{review}{\global\preprinttrue\gdef\@blstr{1.5}} \DeclareOption{authoryear}{\xdef\@biboptions{round,authoryear}} \DeclareOption{number}{\xdef\@biboptions{numbers}} \DeclareOption{numbers}{\xdef\@biboptions{numbers}} \DeclareOption{longtitle}{\global\longmktitletrue} \DeclareOption{5p}{\xdef\jtype{5}\global\preprintfalse \ExecuteOptions{twocolumn}} \def\jtype{0} \DeclareOption{3p}{\xdef\jtype{3}\global\preprintfalse} \DeclareOption{1p}{\xdef\jtype{1}\global\preprintfalse \AtBeginDocument{\@twocolumnfalse}} \DeclareOption{times}{\IfFileExists{txfonts.sty}% {\AtEndOfClass{\RequirePackage{txfonts}% \gdef\ttdefault{cmtt}% \let\iint\relax \let\iiint\relax \let\iiiint\relax \let\idotsint\relax \let\openbox\relax}}{\RequirePackage{times}}} \ExecuteOptions{a4paper,10pt,oneside,onecolumn,number,preprint} \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}} \ProcessOptions \LoadClass{article} \RequirePackage{graphicx} \let\comma\@empty \let\tnotesep\@empty \def\title#1{\gdef\@title{#1}} \let\@title\@empty \def\elsLabel#1{\@bsphack\protected@write\@auxout{}% {\string\Newlabel{#1}{\@currentlabel}}\@esphack} \def\Newlabel#1#2{\expandafter\xdef\csname X@#1\endcsname{#2}} \def\elsRef#1{\@ifundefined{X@#1}{0}{\csname X@#1\endcsname}% } \def\tnotemark[#1]{\textsuperscript{\@for\@@tmark:=#1\do{% \edef\tnotenum{\@ifundefined{X@\@@tmark}{1}{\elsRef{\@@tmark}}}% \ifcase\tnotenum\or\ding{73}\or,\ding{73}\ding{73}\fi}}% } \let\@tnotemark\@empty \let\@tnotes\@empty \RequirePackage{pifont} \newcounter{tnote} \def\tnotetext[#1]#2{\g@addto@macro\@tnotes{% \refstepcounter{tnote}\elsLabel{#1}% \def\thefootnote{\ifcase\c@tnote\or\ding{73}\or\ding{73}\ding{73}\fi}% \footnotetext{#2}}} \let\@nonumnotes\@empty \def\nonumnote#1{\g@addto@macro\@nonumnotes{% \let\thefootnote\relax\footnotetext{#1}}} \newcounter{fnote} \def\fnmark[#1]{\let\comma\@empty \def\@fnmark{\@for\@@fnmark:=#1\do{% \edef\fnotenum{\@ifundefined{X@\@@fnmark}{1}{\elsRef{\@@fnmark}}}% \unskip\comma\fnotenum\let\comma,}}% } \let\@fnotes\@empty\let\@fnmark\@empty \def\fntext[#1]#2{\g@addto@macro\@fnotes{% \refstepcounter{fnote}\elsLabel{#1}% \def\thefootnote{\thefnote}% \global\setcounter{footnote}{\thefnote}% \footnotetext{#2}}} \def\cormark[#1]{\edef\cnotenum{\elsRef{#1}}% \unskip\textsuperscript{\sep\ifcase\cnotenum\or $\ast$\or$\ast\ast$\fi\hspace{-1pt}}\let\sep=,} \let\@cormark\@empty \let\@cornotes\@empty \newcounter{cnote} \def\cortext[#1]#2{\g@addto@macro\@cornotes{% \refstepcounter{cnote}\elsLabel{#1}% \def\thefootnote{\ifcase\thecnote\or$\ast$\or $\ast\ast$\fi}% \footnotetext{#2}}} \let\@corref\@empty \def\corref#1{\edef\cnotenum{\elsRef{#1}}% \edef\@corref{\ifcase\cnotenum\or $\ast$\or$\ast\ast$\fi\hskip-1pt}} \def\fnref#1{\fnmark[#1]} \def\tnoteref#1{\tnotemark[#1]} \def\resetTitleCounters{\c@cnote=0 \c@fnote=0 \c@tnote=0 \c@footnote=0} \let\eadsep\@empty \let\@elseads\@empty \let\@elsuads\@empty \let\@cormark\@empty \def\hashchar{\expandafter\@gobble\string\~} \def\underscorechar{\expandafter\@gobble\string\_} \def\lbracechar{\expandafter\@gobble\string\{} \def\rbracechar{\expandafter\@gobble\string\}} \def\ead{\@ifnextchar[{\@uad}{\@ead}} \gdef\@ead#1{\bgroup\def\_{\string\underscorechar\space}% \def\{{\string\lbracechar\space}% \def~{\hashchar\space}% \def\}{\string\rbracechar\space}% \edef\tmp{\the\@eadauthor} \immediate\write\@auxout{\string\emailauthor {#1}{\expandafter\strip@prefix\meaning\tmp}}% \egroup } \newcounter{ead} \gdef\emailauthor#1#2{\stepcounter{ead}% \g@addto@macro\@elseads{\raggedright% \let\corref\@gobble \eadsep\texttt{#1} (#2)\def\eadsep{\unskip,\space}}% } \gdef\@uad[#1]#2{\bgroup \def~{\string\hashchar\space}% \def\_{\string\underscorechar\space}% \edef\tmp{\the\@eadauthor} \immediate\write\@auxout{\string\urlauthor {#2}{\expandafter\strip@prefix\meaning\tmp}}% \egroup } \def\urlauthor#1#2{\g@addto@macro\@elsuads{\let\corref\@gobble% \raggedright\eadsep\texttt{#1}\space(#2)% \def\eadsep{\unskip,\space}}% } \def\elsauthors{} \def\pprinttitle{} \let\authorsep\@empty \let\sep\@empty \newcounter{author} \def\author{\@ifnextchar[{\@@author}{\@author}} \newtoks\@eadauthor \def\@@author[#1]#2{\g@addto@macro\elsauthors{% \def\baselinestretch{1}% \authorsep#2\unskip\textsuperscript{%#1% \@for\@@affmark:=#1\do{% \edef\affnum{\@ifundefined{X@\@@affmark}{1}{\elsRef{\@@affmark}}}% \unskip\sep\affnum\let\sep=,}% \ifx\@fnmark\@empty\else\unskip\sep\@fnmark\let\sep=,\fi \ifx\@corref\@empty\else\unskip\sep\@corref\let\sep=,\fi }% \def\authorsep{\unskip,\space}% \global\let\sep\@empty\global\let\@corref\@empty \global\let\@fnmark\@empty}% \@eadauthor={#2} } \def\@author#1{\g@addto@macro\elsauthors{\normalsize% \def\baselinestretch{1}% \upshape\authorsep#1\unskip\textsuperscript{% \ifx\@fnmark\@empty\else\unskip\sep\@fnmark\let\sep=,\fi \ifx\@corref\@empty\else\unskip\sep\@corref\let\sep=,\fi }% \def\authorsep{\unskip,\space}% \global\let\@fnmark\@empty \global\let\@corref\@empty \global\let\sep\@empty}% \@eadauthor={#1} } \def\elsaddress{} \def\addsep{\par\vskip6pt} \def\address{\@ifnextchar[{\@@address}{\@address}} \def\@alph#1{% \ifcase#1\or a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or k\or l\or m\or n\or o\or p\or q\or r\or s\or t\or u\or v\or w\or x\or y\or z% \or aa\or ab\or ac\or ad\or ae\or af\or ag\or ah\or ai\or aj\or ak\or al\or am\or an\or ao\or ap\or aq\or ar\or as\or at\or au\or av\or aw\or ax\or ay\or az% \or ba\or bb\or bc\or bd\or be\or bf\or bg\or bh\or bi\or bj\or bk\or bl\or bm\or bn\or bo\or bp\or bq\or br\or bs\or bt\or bu\or bv\or bw\or bx\or by\or bz% \or ca\or cb\or cc\or cd\or ce\or cf\or cg\or ch\or ci\or cj\or ck\or cl\or cm\or cn\or co\or cp\or cq\or cr\or cs\or ct\or cu\or cv\or cw\or cx\or cy\or cz% \or da\or db\or dc\or dd\or de\or df\or dg\or dh\or di\or dj\or dk\or dl\or dm\or dn\or do\or dp\or dq\or dr\or ds\or dt\or du\or dv\or dw\or dx\or dy\or dz% \or ea\or eb\or ec\or ed\or ee\or ef\or eg\or eh\or ei\or ej\or ek\or el\or em\or en\or eo\or ep\or eq\or er\or es\or et\or eu\or ev\or ew\or ex\or ey\or ez% \or fa\or fb\or fc\or fd\or fe\or ff\or fg\or fh\or fi\or fj\or fk\or fl\or fm\or fn\or fo\or fp\or fq\or fr\or fs\or ft\or fu\or fv\or fw\or fx\or fy\or fz% \or ga\or gb\or gc\or gd\or ge\or gf\or gg\or gh\or gi\or gj\or gk\or gl\or gm\or gn\or go\or gp\or gq\or gr\or gs\or gt\or gu\or gv\or gw\or gx\or gy\or gz% \else\@ctrerr\fi} \newcounter{affn} \renewcommand\theaffn{\alph{affn}} \long\def\@@address[#1]#2{\g@addto@macro\elsaddress{% \def\baselinestretch{1}% \refstepcounter{affn} \xdef\@currentlabel{\theaffn} \elsLabel{#1}% \textsuperscript{\theaffn}#2\par}} \long\def\@address#1{\g@addto@macro\elsauthors{% \def\baselinestretch{1}% \addsep\footnotesize\itshape#1\def\addsep{\par\vskip6pt}% \def\authorsep{\par\vskip8pt}}} \newbox\absbox \renewenvironment{abstract}{\global\setbox\absbox=\vbox\bgroup \hsize=\textwidth\def\baselinestretch{1}% \noindent\unskip\textbf{Abstract} \par\medskip\noindent\unskip\ignorespaces} {\egroup} \newbox\keybox \def\keyword{% \def\sep{\unskip, }% \def\MSC{\@ifnextchar[{\@MSC}{\@MSC[2000]}} \def\@MSC[##1]{\par\leavevmode\hbox {\it ##1~MSC:\space}}% \def\PACS{\par\leavevmode\hbox {\it PACS:\space}}% \def\JEL{\par\leavevmode\hbox {\it JEL:\space}}% \global\setbox\keybox=\vbox\bgroup\hsize=\textwidth \normalsize\normalfont\def\baselinestretch{1} \parskip\z@ \noindent\textit{Keywords: } \raggedright % Keywords are not justified. \ignorespaces} \def\endkeyword{\par \egroup} \newdimen\Columnwidth \Columnwidth=\columnwidth \def\printFirstPageNotes{% \iflongmktitle \let\columnwidth=\textwidth\fi \ifx\@tnotes\@empty\else\@tnotes\fi \ifx\@nonumnotes\@empty\else\@nonumnotes\fi \ifx\@cornotes\@empty\else\@cornotes\fi \ifx\@elseads\@empty\relax\else \let\thefootnote\relax \footnotetext{\ifnum\theead=1\relax \textit{Email address:\space}\else \textit{Email addresses:\space}\fi \@elseads}\fi \ifx\@elsuads\@empty\relax\else \let\thefootnote\relax \footnotetext{\textit{URL:\space}% \@elsuads}\fi \ifx\@fnotes\@empty\else\@fnotes\fi \iflongmktitle\if@twocolumn \let\columnwidth=\Columnwidth\fi\fi } \long\def\pprintMaketitle{\clearpage \iflongmktitle\if@twocolumn\let\columnwidth=\textwidth\fi\fi \resetTitleCounters \def\baselinestretch{1}% \printFirstPageNotes \begin{center}% \thispagestyle{pprintTitle}% \def\baselinestretch{1}% \Large\@title\par\vskip18pt \normalsize\elsauthors\par\vskip10pt \footnotesize\itshape\elsaddress\par\vskip36pt \hrule\vskip12pt \ifvoid\absbox\else\unvbox\absbox\par\vskip10pt\fi \ifvoid\keybox\else\unvbox\keybox\par\vskip10pt\fi \hrule\vskip12pt \end{center}% \gdef\thefootnote{\arabic{footnote}}% } \def\printWarning{% \mbox{}\par\vfill\par\bgroup \fboxsep12pt\fboxrule1pt \hspace*{.18\textwidth} \fcolorbox{gray50}{gray10}{\box\warnbox} \egroup\par\vfill\thispagestyle{empty} \setcounter{page}{0} \clearpage} \long\def\finalMaketitle{% \resetTitleCounters \def\baselinestretch{1}% \MaketitleBox \thispagestyle{pprintTitle}% \gdef\thefootnote{\arabic{footnote}}% } \long\def\MaketitleBox{% \resetTitleCounters \def\baselinestretch{1}% \begin{center}% \def\baselinestretch{1}% \Large\@title\par\vskip18pt \normalsize\elsauthors\par\vskip10pt \footnotesize\itshape\elsaddress\par\vskip36pt \hrule\vskip12pt \ifvoid\absbox\else\unvbox\absbox\par\vskip10pt\fi \ifvoid\keybox\else\unvbox\keybox\par\vskip10pt\fi \hrule\vskip12pt \end{center}% } \def\FNtext#1{\par\bgroup\footnotesize#1\egroup} \newdimen\space@left \def\alarm#1{\typeout{******************************}% \typeout{#1}% \typeout{******************************}% } \long\def\getSpaceLeft{%\global\@twocolumnfalse% \global\setbox0=\vbox{\hsize=\textwidth\MaketitleBox}% \global\setbox1=\vbox{\hsize=\textwidth \let\footnotetext\FNtext \printFirstPageNotes}% \xdef\noteheight{\the\ht1}% \xdef\titleheight{\the\ht0}% \@tempdima=\vsize \advance\@tempdima-\noteheight \advance\@tempdima-1\baselineskip } \skip\footins=24pt \newbox\els@boxa \newbox\els@boxb \ifpreprint \def\maketitle{\pprintMaketitle} \else \ifnum\jtype=1 \def\maketitle{% \iflongmktitle\getSpaceLeft \global\setbox\els@boxa=\vsplit0 to \@tempdima \box\els@boxa\par\resetTitleCounters \thispagestyle{pprintTitle}% \printFirstPageNotes \box0% \else \finalMaketitle\printFirstPageNotes \fi \gdef\thefootnote{\arabic{footnote}}}% \else \ifnum\jtype=5 \def\maketitle{% \iflongmktitle\getSpaceLeft \global\setbox\els@boxa=\vsplit0 to \@tempdima \box\els@boxa\par\resetTitleCounters \thispagestyle{pprintTitle}% \printFirstPageNotes \twocolumn[\box0]%\printFirstPageNotes \else \twocolumn[\finalMaketitle]\printFirstPageNotes \fi \gdef\thefootnote{\arabic{footnote}}} \else \if@twocolumn \def\maketitle{% \iflongmktitle\getSpaceLeft \global\setbox\els@boxa=\vsplit0 to \@tempdima \box\els@boxa\par\resetTitleCounters \thispagestyle{pprintTitle}% \printFirstPageNotes \twocolumn[\box0]% \else \twocolumn[\finalMaketitle]\printFirstPageNotes \fi \gdef\thefootnote{\arabic{footnote}}}% \else \def\maketitle{% \iflongmktitle\getSpaceLeft \global\setbox\els@boxa=\vsplit0 to \@tempdima \box\els@boxa\par\resetTitleCounters \thispagestyle{pprintTitle}% \printFirstPageNotes \box0% \else \finalMaketitle\printFirstPageNotes \fi \gdef\thefootnote{\arabic{footnote}}}% \fi \fi \fi \fi \def\ps@pprintTitle{% \let\@oddhead\@empty \let\@evenhead\@empty \def\@oddfoot{\footnotesize\itshape Preprint submitted to \ifx\@journal\@empty Elsevier \else\@journal\fi\hfill\today}% \let\@evenfoot\@oddfoot} \def\@seccntDot{.} \def\@seccntformat#1{\csname the#1\endcsname\@seccntDot\hskip 0.5em} \renewcommand\section{\@startsection {section}{1}{\z@}% {18\p@ \@plus 6\p@ \@minus 3\p@}% {9\p@ \@plus 6\p@ \@minus 3\p@}% {\normalsize\bfseries\boldmath}} \renewcommand\subsection{\@startsection{subsection}{2}{\z@}% {12\p@ \@plus 6\p@ \@minus 3\p@}% {3\p@ \@plus 6\p@ \@minus 3\p@}% {\normalfont\normalsize\itshape}} \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}% {12\p@ \@plus 6\p@ \@minus 3\p@}% {\p@}% {\normalfont\normalsize\itshape}} \def\paragraph{\secdef{\els@aparagraph}{\els@bparagraph}} \def\els@aparagraph[#1]#2{\elsparagraph[#1]{#2.}} \def\els@bparagraph#1{\elsparagraph*{#1.}} \newcommand\elsparagraph{\@startsection{paragraph}{4}{0\z@}% {10\p@ \@plus 6\p@ \@minus 3\p@}% {-6\p@}% {\normalfont\itshape}} \newdimen\leftMargin \leftMargin=2em \newtoks\@enLab %\newtoks\@enfont \def\@enQmark{?} \def\@enLabel#1#2{% \edef\@enThe{\noexpand#1{\@enumctr}}% \@enLab\expandafter{\the\@enLab\csname the\@enumctr\endcsname}% \@enloop} \def\@enSpace{\afterassignment\@enSp@ce\let\@tempa= } \def\@enSp@ce{\@enLab\expandafter{\the\@enLab\space}\@enloop} \def\@enGroup#1{\@enLab\expandafter{\the\@enLab{#1}}\@enloop} \def\@enOther#1{\@enLab\expandafter{\the\@enLab#1}\@enloop} \def\@enloop{\futurelet\@entemp\@enloop@} \def\@enloop@{% \ifx A\@entemp \def\@tempa{\@enLabel\Alph }\else \ifx a\@entemp \def\@tempa{\@enLabel\alph }\else \ifx i\@entemp \def\@tempa{\@enLabel\roman }\else \ifx I\@entemp \def\@tempa{\@enLabel\Roman }\else \ifx 1\@entemp \def\@tempa{\@enLabel\arabic}\else \ifx \@sptoken\@entemp \let\@tempa\@enSpace \else \ifx \bgroup\@entemp \let\@tempa\@enGroup \else \ifx \@enum@\@entemp \let\@tempa\@gobble \else \let\@tempa\@enOther \fi\fi\fi\fi\fi\fi\fi\fi \@tempa} \newlength{\@sep} \newlength{\@@sep} \setlength{\@sep}{.5\baselineskip plus.2\baselineskip minus.2\baselineskip} \setlength{\@@sep}{.1\baselineskip plus.01\baselineskip minus.05\baselineskip} \providecommand{\sfbc}{\rmfamily\upshape} \providecommand{\sfn}{\rmfamily\upshape} \def\@enfont{\ifnum \@enumdepth >1\let\@nxt\sfn \else\let\@nxt\sfbc \fi\@nxt} \def\enumerate{% \ifnum \@enumdepth >3 \@toodeep\else \advance\@enumdepth \@ne \edef\@enumctr{enum\romannumeral\the\@enumdepth}\fi \@ifnextchar[{\@@enum@}{\@enum@}} \def\@@enum@[#1]{% \@enLab{}\let\@enThe\@enQmark \@enloop#1\@enum@ \ifx\@enThe\@enQmark\@warning{The counter will not be printed.% ^^J\space\@spaces\@spaces\@spaces The label is: \the\@enLab}\fi \expandafter\edef\csname label\@enumctr\endcsname{\the\@enLab}% \expandafter\let\csname the\@enumctr\endcsname\@enThe \csname c@\@enumctr\endcsname7 \expandafter\settowidth \csname leftmargin\romannumeral\@enumdepth\endcsname {\the\@enLab\hskip\labelsep}% \@enum@} \def\@enum@{\list{{\@enfont\csname label\@enumctr\endcsname}}% {\usecounter{\@enumctr}\def\makelabel##1{\hss\llap{##1}}% \ifnum \@enumdepth>1\setlength{\topsep}{\@@sep}\else \setlength{\topsep}{\@sep}\fi \ifnum \@enumdepth>1\setlength{\itemsep}{0pt plus1pt minus1pt}% \else \setlength{\itemsep}{\@@sep}\fi %\setlength\leftmargin{\leftMargin}%%%{1.8em} \setlength{\parsep}{0pt plus1pt minus1pt}% \setlength{\parskip}{0pt plus1pt minus1pt} }} \def\endenumerate{\par\ifnum \@enumdepth >1\addvspace{\@@sep}\else \addvspace{\@sep}\fi \endlist} \def\sitem{\@noitemargtrue\@item[\@itemlabel *]} \def\itemize{\@ifnextchar[{\@Itemize}{\@Itemize[]}} \def\@Itemize[#1]{\def\next{#1}% \ifnum \@itemdepth >\thr@@\@toodeep\else \advance\@itemdepth\@ne \ifx\next\@empty\else\expandafter\def\csname labelitem\romannumeral\the\@itemdepth\endcsname{#1}\fi% \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}% \expandafter\list\csname\@itemitem\endcsname {\def\makelabel##1{\hss\llap{##1}}}% \fi} \def\newdefinition#1{% \@ifnextchar[{\@odfn{#1}}{\@ndfn{#1}}}%] \def\@ndfn#1#2{% \@ifnextchar[{\@xndfn{#1}{#2}}{\@yndfn{#1}{#2}}} \def\@xndfn#1#2[#3]{% \expandafter\@ifdefinable\csname #1\endcsname {\@definecounter{#1}\@newctr{#1}[#3]% \expandafter\xdef\csname the#1\endcsname{% \expandafter\noexpand\csname the#3\endcsname \@dfncountersep \@dfncounter{#1}}% \global\@namedef{#1}{\@dfn{#1}{#2}}% \global\@namedef{end#1}{\@enddefinition}}} \def\@yndfn#1#2{% \expandafter\@ifdefinable\csname #1\endcsname {\@definecounter{#1}% \expandafter\xdef\csname the#1\endcsname{\@dfncounter{#1}}% \global\@namedef{#1}{\@dfn{#1}{#2}}% \global\@namedef{end#1}{\@enddefinition}}} \def\@odfn#1[#2]#3{% \@ifundefined{c@#2}{\@nocounterr{#2}}% {\expandafter\@ifdefinable\csname #1\endcsname {\global\@namedef{the#1}{\@nameuse{the#2}} \global\@namedef{#1}{\@dfn{#2}{#3}}% \global\@namedef{end#1}{\@enddefinition}}}} \def\@dfn#1#2{% \refstepcounter{#1}% \@ifnextchar[{\@ydfn{#1}{#2}}{\@xdfn{#1}{#2}}} \def\@xdfn#1#2{% \@begindefinition{#2}{\csname the#1\endcsname}\ignorespaces} \def\@ydfn#1#2[#3]{% \@opargbegindefinition{#2}{\csname the#1\endcsname}{#3}\ignorespaces} \def\@dfncounter#1{\noexpand\arabic{#1}} \def\@dfncountersep{.} \def\@begindefinition#1#2{\trivlist \item[\hskip\labelsep{\bfseries #1\ #2.}]\upshape} \def\@opargbegindefinition#1#2#3{\trivlist \item[\hskip\labelsep{\bfseries #1\ #2\ (#3).}]\upshape} \def\@enddefinition{\endtrivlist} \def\@begintheorem#1#2{\trivlist \let\baselinestretch\@blstr \item[\hskip \labelsep{\bfseries #1\ #2.}]\itshape} \def\@opargbegintheorem#1#2#3{\trivlist \let\baselinestretch\@blstr \item[\hskip \labelsep{\bfseries #1\ #2\ (#3).}]\itshape} \def\newproof#1{% \@ifnextchar[{\@oprf{#1}}{\@nprf{#1}}} \def\@nprf#1#2{% \@ifnextchar[{\@xnprf{#1}{#2}}{\@ynprf{#1}{#2}}} \def\@xnprf#1#2[#3]{% \expandafter\@ifdefinable\csname #1\endcsname {\@definecounter{#1}\@newctr{#1}[#3]% \expandafter\xdef\csname the#1\endcsname{% \expandafter\noexpand\csname the#3\endcsname \@prfcountersep \@prfcounter{#1}}% \global\@namedef{#1}{\@prf{#1}{#2}}% \global\@namedef{end#1}{\@endproof}}} \def\@ynprf#1#2{% \expandafter\@ifdefinable\csname #1\endcsname {\@definecounter{#1}% \expandafter\xdef\csname the#1\endcsname{\@prfcounter{#1}}% \global\@namedef{#1}{\@prf{#1}{#2}}% \global\@namedef{end#1}{\@endproof}}} \def\@oprf#1[#2]#3{% \@ifundefined{c@#2}{\@nocounterr{#2}}% {\expandafter\@ifdefinable\csname #1\endcsname {\global\@namedef{the#1}{\@nameuse{the#2}}% \global\@namedef{#1}{\@prf{#2}{#3}}% \global\@namedef{end#1}{\@endproof}}}} \def\@prf#1#2{% \refstepcounter{#1}% \@ifnextchar[{\@yprf{#1}{#2}}{\@xprf{#1}{#2}}} \def\@xprf#1#2{% \@beginproof{#2}{\csname the#1\endcsname}\ignorespaces} \def\@yprf#1#2[#3]{% \@opargbeginproof{#2}{\csname the#1\endcsname}{#3}\ignorespaces} \def\@prfcounter#1{\noexpand\arabic{#1}} \def\@prfcountersep{.} \def\@beginproof#1#2{\trivlist\let\baselinestretch\@blstr \item[\hskip \labelsep{\scshape #1.}]\rmfamily} \def\@opargbeginproof#1#2#3{\trivlist\let\baselinestretch\@blstr \item[\hskip \labelsep{\scshape #1\ (#3).}]\rmfamily} \def\@endproof{\endtrivlist} \newcommand*{\qed}{\hbox{}\hfill$\Box$} \@ifundefined{@biboptions}{\xdef\@biboptions{numbers}}{} \InputIfFileExists{\jobname.spl}{}{} \RequirePackage[\@biboptions]{natbib} \newwrite\splwrite \immediate\openout\splwrite=\jobname.spl \def\biboptions#1{\def\next{#1}\immediate\write\splwrite{% \string\g@addto@macro\string\@biboptions{% ,\expandafter\strip@prefix\meaning\next}}} \let\baselinestretch=\@blstr \ifnum\jtype=1 \RequirePackage{geometry} \geometry{twoside, paperwidth=210mm, paperheight=297mm, textheight=562pt, textwidth=384pt, centering, headheight=50pt, headsep=12pt, footskip=12pt, footnotesep=24pt plus 2pt minus 12pt, } \global\let\bibfont=\footnotesize \global\bibsep=0pt \if@twocolumn\global\@twocolumnfalse\fi \else\ifnum\jtype=3 \RequirePackage{geometry} \geometry{twoside, paperwidth=210mm, paperheight=297mm, textheight=622pt, textwidth=468pt, centering, headheight=50pt, headsep=12pt, footskip=18pt, footnotesep=24pt plus 2pt minus 12pt, columnsep=2pc } \global\let\bibfont=\footnotesize \global\bibsep=0pt \if@twocolumn\input{fleqn.clo}\fi \else\ifnum\jtype=5 \RequirePackage{geometry} \geometry{twoside, paperwidth=210mm, paperheight=297mm, textheight=682pt, textwidth=522pt, centering, headheight=50pt, headsep=12pt, footskip=18pt, footnotesep=24pt plus 2pt minus 12pt, columnsep=18pt }% \global\let\bibfont=\footnotesize \global\bibsep=0pt \input{fleqn.clo} \global\@twocolumntrue %% %% End of option '5p' %% \fi\fi\fi \def\journal#1{\gdef\@journal{#1}} \let\@journal\@empty \newenvironment{frontmatter}{}{\maketitle} \long\def\@makecaption#1#2{% \vskip\abovecaptionskip\footnotesize \sbox\@tempboxa{#1: #2}% \ifdim \wd\@tempboxa >\hsize #1: #2\par \else \global \@minipagefalse \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}% \fi \vskip\belowcaptionskip} \AtBeginDocument{\@ifpackageloaded{hyperref} {\def\@linkcolor{blue} \def\@anchorcolor{blue} \def\@citecolor{blue} \def\@filecolor{blue} \def\@urlcolor{blue} \def\@menucolor{blue} \def\@pagecolor{blue} \begingroup \@makeother\`% \@makeother\=% \edef\x{% \edef\noexpand\x{% \endgroup \noexpand\toks@{% \catcode 96=\noexpand\the\catcode`\noexpand\`\relax \catcode 61=\noexpand\the\catcode`\noexpand\=\relax }% }% \noexpand\x }% \x \@makeother\` \@makeother\= }{}} %% \def\appendixname{Appendix } \renewcommand\appendix{\par \setcounter{section}{0}% \setcounter{subsection}{0}% \setcounter{equation}{0} \gdef\thefigure{\@Alph\c@section.\arabic{figure}}% \gdef\thetable{\@Alph\c@section.\arabic{table}}% \gdef\thesection{\appendixname~\@Alph\c@section}% \@addtoreset{equation}{section}% \gdef\theequation{\@Alph\c@section.\arabic{equation}}% \addtocontents{toc}{\string\let\string\numberline\string\tmptocnumberline}{}{} } %%%% \numberline width calculation for appendix. \newdimen\appnamewidth \def\tmptocnumberline#1{% \setbox0=\hbox{\appendixname} \appnamewidth=\wd0 \addtolength\appnamewidth{2.5pc} \hb@xt@\appnamewidth{#1\hfill} } %% Added for work with amsrefs.sty \@ifpackageloaded{amsrefs}% {} {%\let\bibsection\relax% \AtBeginDocument{\def\cites@b#1#2,#3{% \begingroup[% \toks@{\InnerCite{#2}#1}% \ifx\@empty#3\@xp\@gobble\fi \cites@c#3% }}} %% %% Added for avoiding clash with cleveref.sty \@ifpackageloaded{cleveref}% {} {\def\tnotetext[#1]#2{\g@addto@macro\@tnotes{% \refstepcounter{tnote}% \immediate\write\@auxout{\string\Newlabel{#1}{\thetnote}} \def\thefootnote{\ifcase\c@tnote\or\ding{73}\or\ding{73}\ding{73}\fi}% \footnotetext{#2}}} %%% \def\fntext[#1]#2{\g@addto@macro\@fnotes{% \refstepcounter{fnote}% \immediate\write\@auxout{\string\Newlabel{#1}{\thefnote}} \def\thefootnote{\thefnote}% \global\setcounter{footnote}{\thefnote}% \footnotetext{#2}}} %%% \def\cortext[#1]#2{\g@addto@macro\@cornotes{% \refstepcounter{cnote}% \immediate\write\@auxout{\string\Newlabel{#1}{\thecnote}} \def\thefootnote{\ifcase\thecnote\or$\ast$\or $\ast\ast$\fi}% \footnotetext{#2}}} } \endinput %% %% End of file `elsarticle.cls'. RcppArmadillo/vignettes/elsarticle-harv.bst0000644000176000001440000006735312253723621020663 0ustar ripleyusers%% %% This is file `elsarticle-harv.bst', %% %% Copyright 2007, 2008, 2009 Elsevier Ltd %% %% This file is part of the 'Elsarticle Bundle'. %% --------------------------------------------- %% %% It may be distributed under the conditions of the LaTeX Project Public %% License, either version 1.2 of this license or (at your option) any %% later version. The latest version of this license is in %% http://www.latex-project.org/lppl.txt %% and version 1.2 or later is part of all distributions of LaTeX %% version 1999/12/01 or later. %% %% The list of all files belonging to the 'Elsarticle Bundle' is %% given in the file `manifest.txt'. %% %% %% $Id: elsarticle.cls,v 1.20 2008-10-13 04:24:12 cvr Exp $ %% %% %%------------------------------------------------------------------- %% This bibliography style file is intended for texts in ENGLISH %% This is an author-year citation style bibliography. As such, it is %% non-standard LaTeX, and requires a special package file %% to function properly. %% Such a package is natbib.sty by Patrick W. Daly %% The form of the \bibitem entries is %% \bibitem[Jones et al.(1990)]{key}... %% \bibitem[Jones et al.(1990)Jones, Baker, and Smith]{key}... %% The essential feature is that the label (the part in brackets) consists %% of the author names, as they should appear in the citation, with the year %% in parentheses following. There must be no space before the opening %% parenthesis! %% With natbib v5.3, a full list of authors may also follow the year. %% In natbib.sty, it is possible to define the type of enclosures that is %% really wanted (brackets or parentheses), but in either case, there must %% be parentheses in the label. %% The \cite command functions as follows: %% \citet{key} ==>> Jones et al. (1990) %% \citet*{key} ==>> Jones, Baker, and Smith (1990) %% \citep{key} ==>> (Jones et al., 1990) %% \citep*{key} ==>> (Jones, Baker, and Smith, 1990) %% \citep[chap. 2]{key} ==>> (Jones et al., 1990, chap. 2) %% \citep[e.g.][]{key} ==>> (e.g. Jones et al., 1990) %% \citep[e.g.][p. 32]{key} ==>> (e.g. Jones et al., p. 32) %% \citeauthor{key} ==>> Jones et al. %% \citeauthor*{key} ==>> Jones, Baker, and Smith %% \citeyear{key} ==>> 1990 %%--------------------------------------------------------------------- ENTRY { address author booktitle chapter edition editor howpublished institution journal key month note number organization pages publisher school series title type url volume year } {} { label extra.label sort.label short.list } INTEGERS { output.state before.all mid.sentence after.sentence after.block } FUNCTION {init.state.consts} { #0 'before.all := #1 'mid.sentence := #2 'after.sentence := #3 'after.block := } STRINGS { s t } FUNCTION {output.nonnull} { 's := output.state mid.sentence = { ", " * write$ } { output.state after.block = { add.period$ write$ newline$ "\newblock " write$ } { output.state before.all = 'write$ { add.period$ " " * write$ } if$ } if$ mid.sentence 'output.state := } if$ s } FUNCTION {output} { duplicate$ empty$ 'pop$ 'output.nonnull if$ } FUNCTION {output.check} { 't := duplicate$ empty$ { pop$ "empty " t * " in " * cite$ * warning$ } 'output.nonnull if$ } FUNCTION {fin.entry} { add.period$ write$ newline$ } FUNCTION {new.block} { output.state before.all = 'skip$ { after.block 'output.state := } if$ } FUNCTION {new.sentence} { output.state after.block = 'skip$ { output.state before.all = 'skip$ { after.sentence 'output.state := } if$ } if$ } %%SP 2003/07/25 %% No longer used FUNCTION {add.blank} { " " * before.all 'output.state := } FUNCTION {date.block} { new.sentence } FUNCTION {not} { { #0 } { #1 } if$ } FUNCTION {and} { 'skip$ { pop$ #0 } if$ } FUNCTION {or} { { pop$ #1 } 'skip$ if$ } FUNCTION {new.block.checkb} { empty$ swap$ empty$ and 'skip$ 'new.block if$ } FUNCTION {field.or.null} { duplicate$ empty$ { pop$ "" } 'skip$ if$ } FUNCTION {emphasize} { skip$ } FUNCTION {capitalize} { "u" change.case$ "t" change.case$ } FUNCTION {space.word} { " " swap$ * " " * } %% Here are the language-specific definitions for explicit words. %% Each function has a name bbl.xxx where xxx is the English word. %% The language selected here is ENGLISH FUNCTION {bbl.and} { "and"} FUNCTION {bbl.etal} { "et~al." } FUNCTION {bbl.editors} { "Eds." } FUNCTION {bbl.editor} { "Ed." } FUNCTION {bbl.edby} { "edited by" } FUNCTION {bbl.edition} { "Edition" } FUNCTION {bbl.volume} { "Vol." } FUNCTION {bbl.of} { "of" } FUNCTION {bbl.number} { "no." } FUNCTION {bbl.nr} { "no." } FUNCTION {bbl.in} { "in" } FUNCTION {bbl.pages} { "pp." } FUNCTION {bbl.page} { "p." } FUNCTION {bbl.chapter} { "Ch." } FUNCTION {bbl.techrep} { "Tech. Rep." } FUNCTION {bbl.mthesis} { "Master's thesis" } FUNCTION {bbl.phdthesis} { "Ph.D. thesis" } FUNCTION {bbl.first} { "1st" } FUNCTION {bbl.second} { "2nd" } FUNCTION {bbl.third} { "3rd" } FUNCTION {bbl.fourth} { "4th" } FUNCTION {bbl.fifth} { "5th" } FUNCTION {bbl.st} { "st" } FUNCTION {bbl.nd} { "nd" } FUNCTION {bbl.rd} { "rd" } FUNCTION {bbl.th} { "th" } MACRO {jan} {"Jan."} MACRO {feb} {"Feb."} MACRO {mar} {"Mar."} MACRO {apr} {"Apr."} MACRO {may} {"May"} MACRO {jun} {"Jun."} MACRO {jul} {"Jul."} MACRO {aug} {"Aug."} MACRO {sep} {"Sep."} MACRO {oct} {"Oct."} MACRO {nov} {"Nov."} MACRO {dec} {"Dec."} FUNCTION {eng.ord} { duplicate$ "1" swap$ * #-2 #1 substring$ "1" = { bbl.th * } { duplicate$ #-1 #1 substring$ duplicate$ "1" = { pop$ bbl.st * } { duplicate$ "2" = { pop$ bbl.nd * } { "3" = { bbl.rd * } { bbl.th * } if$ } if$ } if$ } if$ } MACRO {acmcs} {"ACM Comput. Surv."} MACRO {acta} {"Acta Inf."} MACRO {cacm} {"Commun. ACM"} MACRO {ibmjrd} {"IBM J. Res. Dev."} MACRO {ibmsj} {"IBM Syst.~J."} MACRO {ieeese} {"IEEE Trans. Softw. Eng."} MACRO {ieeetc} {"IEEE Trans. Comput."} MACRO {ieeetcad} {"IEEE Trans. Comput.-Aided Design Integrated Circuits"} MACRO {ipl} {"Inf. Process. Lett."} MACRO {jacm} {"J.~ACM"} MACRO {jcss} {"J.~Comput. Syst. Sci."} MACRO {scp} {"Sci. Comput. Programming"} MACRO {sicomp} {"SIAM J. Comput."} MACRO {tocs} {"ACM Trans. Comput. Syst."} MACRO {tods} {"ACM Trans. Database Syst."} MACRO {tog} {"ACM Trans. Gr."} MACRO {toms} {"ACM Trans. Math. Softw."} MACRO {toois} {"ACM Trans. Office Inf. Syst."} MACRO {toplas} {"ACM Trans. Prog. Lang. Syst."} MACRO {tcs} {"Theoretical Comput. Sci."} FUNCTION {write.url} { url empty$ { skip$ } { "\newline\urlprefix\url{" url * "}" * write$ newline$ } if$ } INTEGERS { nameptr namesleft numnames } FUNCTION {format.names} { 's := #1 'nameptr := s num.names$ 'numnames := numnames 'namesleft := { namesleft #0 > } { s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't := nameptr #1 > { namesleft #1 > { ", " * t * } { "," * s nameptr "{ll}" format.name$ duplicate$ "others" = { 't := } { pop$ } if$ t "others" = { " " * bbl.etal * } { " " * t * } if$ } if$ } 't if$ nameptr #1 + 'nameptr := namesleft #1 - 'namesleft := } while$ } FUNCTION {format.names.ed} { format.names } FUNCTION {format.key} { empty$ { key field.or.null } { "" } if$ } FUNCTION {format.authors} { author empty$ { "" } { author format.names } if$ } FUNCTION {format.editors} { editor empty$ { "" } { editor format.names editor num.names$ #1 > { " (" * bbl.editors * ")" * } { " (" * bbl.editor * ")" * } if$ } if$ } FUNCTION {format.in.editors} { editor empty$ { "" } { editor format.names.ed editor num.names$ #1 > { " (" * bbl.editors * ")" * } { " (" * bbl.editor * ")" * } if$ } if$ } FUNCTION {format.note} { note empty$ { "" } { note #1 #1 substring$ duplicate$ "{" = 'skip$ { output.state mid.sentence = { "l" } { "u" } if$ change.case$ } if$ note #2 global.max$ substring$ * } if$ } FUNCTION {format.title} { title empty$ { "" } { title "t" change.case$ } if$ } FUNCTION {format.full.names} {'s := #1 'nameptr := s num.names$ 'numnames := numnames 'namesleft := { namesleft #0 > } { s nameptr "{vv~}{ll}" format.name$ 't := nameptr #1 > { namesleft #1 > { ", " * t * } { numnames #2 > { "," * } 'skip$ if$ s nameptr "{ll}" format.name$ duplicate$ "others" = { 't := } { pop$ } if$ t "others" = { " " * bbl.etal * } { bbl.and space.word * t * } if$ } if$ } 't if$ nameptr #1 + 'nameptr := namesleft #1 - 'namesleft := } while$ } FUNCTION {author.editor.key.full} { author empty$ { editor empty$ { key empty$ { cite$ #1 #3 substring$ } 'key if$ } { editor format.full.names } if$ } { author format.full.names } if$ } FUNCTION {author.key.full} { author empty$ { key empty$ { cite$ #1 #3 substring$ } 'key if$ } { author format.full.names } if$ } FUNCTION {editor.key.full} { editor empty$ { key empty$ { cite$ #1 #3 substring$ } 'key if$ } { editor format.full.names } if$ } FUNCTION {make.full.names} { type$ "book" = type$ "inbook" = or 'author.editor.key.full { type$ "proceedings" = 'editor.key.full 'author.key.full if$ } if$ } FUNCTION {output.bibitem} { newline$ "\bibitem[{" write$ label write$ ")" make.full.names duplicate$ short.list = { pop$ } { * } if$ "}]{" * write$ cite$ write$ "}" write$ newline$ "" before.all 'output.state := } FUNCTION {n.dashify} { 't := "" { t empty$ not } { t #1 #1 substring$ "-" = { t #1 #2 substring$ "--" = not { "--" * t #2 global.max$ substring$ 't := } { { t #1 #1 substring$ "-" = } { "-" * t #2 global.max$ substring$ 't := } while$ } if$ } { t #1 #1 substring$ * t #2 global.max$ substring$ 't := } if$ } while$ } FUNCTION {word.in} { bbl.in capitalize ":" * " " * } FUNCTION {format.date} { year duplicate$ empty$ { "empty year in " cite$ * "; set to ????" * warning$ pop$ "????" } 'skip$ if$ month empty$ 'skip$ { month " " * swap$ * } if$ extra.label * before.all 'output.state := ", " swap$ * } FUNCTION {format.btitle} { title } FUNCTION {tie.or.space.connect} { duplicate$ text.length$ #3 < { "~" } { " " } if$ swap$ * * } FUNCTION {either.or.check} { empty$ 'pop$ { "can't use both " swap$ * " fields in " * cite$ * warning$ } if$ } FUNCTION {format.bvolume} { volume empty$ { "" } { bbl.volume volume tie.or.space.connect series empty$ 'skip$ { bbl.of space.word * series emphasize * } if$ "volume and number" number either.or.check } if$ } FUNCTION {format.number.series} { volume empty$ { number empty$ { series field.or.null } { output.state mid.sentence = { bbl.number } { bbl.number capitalize } if$ number tie.or.space.connect series empty$ { "there's a number but no series in " cite$ * warning$ } { bbl.in space.word * series * } if$ } if$ } { "" } if$ } FUNCTION {is.num} { chr.to.int$ duplicate$ "0" chr.to.int$ < not swap$ "9" chr.to.int$ > not and } FUNCTION {extract.num} { duplicate$ 't := "" 's := { t empty$ not } { t #1 #1 substring$ t #2 global.max$ substring$ 't := duplicate$ is.num { s swap$ * 's := } { pop$ "" 't := } if$ } while$ s empty$ 'skip$ { pop$ s } if$ } FUNCTION {convert.edition} { edition extract.num "l" change.case$ 's := s "first" = s "1" = or { bbl.first 't := } { s "second" = s "2" = or { bbl.second 't := } { s "third" = s "3" = or { bbl.third 't := } { s "fourth" = s "4" = or { bbl.fourth 't := } { s "fifth" = s "5" = or { bbl.fifth 't := } { s #1 #1 substring$ is.num { s eng.ord 't := } { edition 't := } if$ } if$ } if$ } if$ } if$ } if$ t } FUNCTION {format.edition} { edition empty$ { "" } { output.state mid.sentence = { convert.edition "l" change.case$ " " * bbl.edition * } { convert.edition "t" change.case$ " " * bbl.edition * } if$ } if$ } INTEGERS { multiresult } FUNCTION {multi.page.check} { 't := #0 'multiresult := { multiresult not t empty$ not and } { t #1 #1 substring$ duplicate$ "-" = swap$ duplicate$ "," = swap$ "+" = or or { #1 'multiresult := } { t #2 global.max$ substring$ 't := } if$ } while$ multiresult } FUNCTION {format.pages} { pages empty$ { "" } { pages multi.page.check { bbl.pages pages n.dashify tie.or.space.connect } { bbl.page pages tie.or.space.connect } if$ } if$ } FUNCTION {format.journal.pages} { pages empty$ 'skip$ { duplicate$ empty$ { pop$ format.pages } { ", " * pages n.dashify * } if$ } if$ } %%SP 2001/01/23 %% Only used in articles FUNCTION {format.vol.num.pages} { %%SP 2001/01/23 %% Add the leading space only if there is a volume %% volume field.or.null " " volume empty$ { pop$ "" } { volume * } if$ number empty$ 'skip$ { "~(" number * ")" * * volume empty$ { "there's a number but no volume in " cite$ * warning$ } 'skip$ if$ } if$ } FUNCTION {format.chapter.pages} { chapter empty$ { "" } { type empty$ { bbl.chapter } { type "l" change.case$ } if$ chapter tie.or.space.connect } if$ } FUNCTION {format.in.ed.booktitle} { booktitle empty$ { "" } { editor empty$ { word.in booktitle * } { word.in format.in.editors * ", " * booktitle * } if$ } if$ } FUNCTION {format.thesis.type} { type empty$ 'skip$ { pop$ type "t" change.case$ } if$ } FUNCTION {format.tr.number} { type empty$ { bbl.techrep } 'type if$ number empty$ { "t" change.case$ } { number tie.or.space.connect } if$ } FUNCTION {format.article.crossref} { word.in " \cite{" * crossref * "}" * } FUNCTION {format.book.crossref} { volume empty$ { "empty volume in " cite$ * "'s crossref of " * crossref * warning$ word.in } { bbl.volume capitalize volume tie.or.space.connect bbl.of space.word * } if$ " \cite{" * crossref * "}" * } FUNCTION {format.incoll.inproc.crossref} { word.in " \cite{" * crossref * "}" * } FUNCTION {format.org.or.pub} { 't := "" address empty$ t empty$ and 'skip$ { t empty$ { address empty$ 'skip$ { address * } if$ } { t * address empty$ 'skip$ { ", " * address * } if$ } if$ } if$ } FUNCTION {format.publisher.address} { publisher empty$ { "empty publisher in " cite$ * warning$ "" } { publisher } if$ format.org.or.pub } FUNCTION {format.organization.address} { organization empty$ { "" } { organization } if$ format.org.or.pub } FUNCTION {article} { output.bibitem format.authors "author" output.check author format.key output format.date "year" output.check date.block format.title "title" output.check new.sentence crossref missing$ { journal "journal" output.check %%SP 2001/01/23 %% Add the space in format.vol.num.pages %% add.blank before.all 'output.state := format.vol.num.pages output } { format.article.crossref output.nonnull format.pages output } if$ format.journal.pages format.note output fin.entry write.url } FUNCTION {book} { output.bibitem author empty$ { format.editors "author and editor" output.check editor format.key output } { format.authors output.nonnull crossref missing$ { "author and editor" editor either.or.check } 'skip$ if$ } if$ format.date "year" output.check date.block format.btitle "title" output.check crossref missing$ { format.edition output new.sentence format.bvolume output format.number.series output new.sentence format.publisher.address output } { new.sentence format.book.crossref output.nonnull } if$ format.note output fin.entry write.url } FUNCTION {booklet} { output.bibitem format.authors output author format.key output format.date "year" output.check date.block format.title "title" output.check new.sentence howpublished output address output format.note output fin.entry write.url } FUNCTION {inbook} { output.bibitem author empty$ { format.editors "author and editor" output.check editor format.key output } { format.authors output.nonnull crossref missing$ { "author and editor" editor either.or.check } 'skip$ if$ } if$ format.date "year" output.check date.block format.btitle "title" output.check crossref missing$ { format.edition output new.sentence format.bvolume output format.number.series output new.sentence format.publisher.address output format.chapter.pages "chapter and pages" output.check } { format.chapter.pages "chapter and pages" output.check new.sentence format.book.crossref output.nonnull } if$ format.pages "pages" output.check format.note output fin.entry write.url } FUNCTION {incollection} { output.bibitem format.authors "author" output.check author format.key output format.date "year" output.check date.block format.title "title" output.check new.sentence crossref missing$ { format.in.ed.booktitle "booktitle" output.check format.edition output new.sentence format.bvolume output format.number.series output new.sentence format.publisher.address output format.chapter.pages output } { format.incoll.inproc.crossref output.nonnull format.chapter.pages output } if$ format.pages "pages" output.check format.note output fin.entry write.url } FUNCTION {inproceedings} { output.bibitem format.authors "author" output.check author format.key output format.date "year" output.check date.block format.title "title" output.check new.sentence crossref missing$ { format.in.ed.booktitle "booktitle" output.check format.edition output new.sentence format.bvolume output format.number.series output new.sentence publisher empty$ { format.organization.address output } { organization output format.publisher.address output } if$ %%SP 2001/01/23 %% format.pages output } { format.incoll.inproc.crossref output.nonnull %%SP 2001/01/23 %% format.pages output } if$ %%SP 2001/01/23 format.pages "pages" output.check format.note output fin.entry write.url } FUNCTION {conference} { inproceedings } FUNCTION {manual} { output.bibitem format.authors output author format.key output format.date "year" output.check date.block format.btitle "title" output.check new.sentence organization output address output format.edition output format.note output fin.entry write.url } FUNCTION {mastersthesis} { output.bibitem format.authors "author" output.check author format.key output format.date "year" output.check date.block format.title "title" output.check new.sentence bbl.mthesis format.thesis.type output.nonnull school "school" output.check address output format.note output fin.entry write.url } FUNCTION {misc} { output.bibitem format.authors output author format.key output format.date "year" output.check date.block format.title output new.sentence howpublished output format.note output fin.entry write.url } FUNCTION {phdthesis} { output.bibitem format.authors "author" output.check author format.key output format.date "year" output.check date.block format.title "title" output.check new.sentence bbl.phdthesis format.thesis.type output.nonnull school "school" output.check address output format.note output fin.entry write.url } FUNCTION {proceedings} { output.bibitem format.editors output editor format.key output format.date "year" output.check date.block format.btitle "title" output.check new.sentence format.bvolume output format.number.series output new.sentence publisher empty$ { format.organization.address output } { organization output format.publisher.address output } if$ format.note output fin.entry write.url } FUNCTION {techreport} { output.bibitem format.authors "author" output.check author format.key output format.date "year" output.check date.block format.title "title" output.check new.sentence format.tr.number output.nonnull institution "institution" output.check address output format.note output fin.entry write.url } FUNCTION {unpublished} { output.bibitem format.authors "author" output.check author format.key output format.date "year" output.check date.block format.title "title" output.check format.note "note" output.check fin.entry write.url } FUNCTION {default.type} { misc } READ FUNCTION {sortify} { purify$ "l" change.case$ } INTEGERS { len } FUNCTION {chop.word} { 's := 'len := s #1 len substring$ = { s len #1 + global.max$ substring$ } 's if$ } FUNCTION {format.lab.names} { 's := s #1 "{vv~}{ll}" format.name$ s num.names$ duplicate$ #2 > { pop$ " " * bbl.etal * } { #2 < 'skip$ { s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" = { " " * bbl.etal * } { bbl.and space.word * s #2 "{vv~}{ll}" format.name$ * } if$ } if$ } if$ } FUNCTION {author.key.label} { author empty$ { key empty$ { cite$ #1 #3 substring$ } 'key if$ } { author format.lab.names } if$ } FUNCTION {author.editor.key.label} { author empty$ { editor empty$ { key empty$ { cite$ #1 #3 substring$ } 'key if$ } { editor format.lab.names } if$ } { author format.lab.names } if$ } FUNCTION {editor.key.label} { editor empty$ { key empty$ { cite$ #1 #3 substring$ } 'key if$ } { editor format.lab.names } if$ } FUNCTION {calc.short.authors} { type$ "book" = type$ "inbook" = or 'author.editor.key.label { type$ "proceedings" = 'editor.key.label 'author.key.label if$ } if$ 'short.list := } FUNCTION {calc.label} { calc.short.authors short.list "(" * year duplicate$ empty$ { pop$ "????" } 'skip$ if$ * 'label := } FUNCTION {sort.format.names} { 's := #1 'nameptr := "" s num.names$ 'numnames := numnames 'namesleft := { namesleft #0 > } { s nameptr "{vv{ } }{ll{ }}{ f{ }}{ jj{ }}" format.name$ 't := nameptr #1 > { " " * namesleft #1 = t "others" = and { "zzzzz" * } { t sortify * } if$ } { t sortify * } if$ nameptr #1 + 'nameptr := namesleft #1 - 'namesleft := } while$ } FUNCTION {sort.format.title} { 't := "A " #2 "An " #3 "The " #4 t chop.word chop.word chop.word sortify #1 global.max$ substring$ } FUNCTION {author.sort} { author empty$ { key empty$ { "to sort, need author or key in " cite$ * warning$ "" } { key sortify } if$ } { author sort.format.names } if$ } FUNCTION {author.editor.sort} { author empty$ { editor empty$ { key empty$ { "to sort, need author, editor, or key in " cite$ * warning$ "" } { key sortify } if$ } { editor sort.format.names } if$ } { author sort.format.names } if$ } FUNCTION {editor.sort} { editor empty$ { key empty$ { "to sort, need editor or key in " cite$ * warning$ "" } { key sortify } if$ } { editor sort.format.names } if$ } FUNCTION {presort} { calc.label label sortify " " * type$ "book" = type$ "inbook" = or 'author.editor.sort { type$ "proceedings" = 'editor.sort 'author.sort if$ } if$ #1 entry.max$ substring$ 'sort.label := sort.label * " " * title field.or.null sort.format.title * #1 entry.max$ substring$ 'sort.key$ := } ITERATE {presort} SORT STRINGS { last.label next.extra } INTEGERS { last.extra.num number.label } FUNCTION {initialize.extra.label.stuff} { #0 int.to.chr$ 'last.label := "" 'next.extra := #0 'last.extra.num := #0 'number.label := } FUNCTION {forward.pass} { last.label label = { last.extra.num #1 + 'last.extra.num := last.extra.num int.to.chr$ 'extra.label := } { "a" chr.to.int$ 'last.extra.num := "" 'extra.label := label 'last.label := } if$ number.label #1 + 'number.label := } FUNCTION {reverse.pass} { next.extra "b" = { "a" 'extra.label := } 'skip$ if$ extra.label 'next.extra := extra.label duplicate$ empty$ 'skip$ { "{\natexlab{" swap$ * "}}" * } if$ 'extra.label := label extra.label * 'label := } EXECUTE {initialize.extra.label.stuff} ITERATE {forward.pass} REVERSE {reverse.pass} FUNCTION {bib.sort.order} { sort.label " " * year field.or.null sortify * " " * title field.or.null sort.format.title * #1 entry.max$ substring$ 'sort.key$ := } ITERATE {bib.sort.order} SORT FUNCTION {begin.bib} { preamble$ empty$ 'skip$ { preamble$ write$ newline$ } if$ "\begin{thebibliography}{" number.label int.to.str$ * "}" * write$ newline$ "\expandafter\ifx\csname natexlab\endcsname\relax\def\natexlab#1{#1}\fi" write$ newline$ "\expandafter\ifx\csname url\endcsname\relax" write$ newline$ " \def\url#1{\texttt{#1}}\fi" write$ newline$ "\expandafter\ifx\csname urlprefix\endcsname\relax\def\urlprefix{URL }\fi" write$ newline$ } EXECUTE {begin.bib} EXECUTE {init.state.consts} ITERATE {call.type$} FUNCTION {end.bib} { newline$ "\end{thebibliography}" write$ newline$ } EXECUTE {end.bib} %% End of customized bst file %% %% End of file `elsarticle-harv.bst'. RcppArmadillo/README.md0000644000176000001440000000325412253723621014321 0ustar ripleyusers ## RcppArmadillo: R and Armadillo via Rcpp [![Build Status](https://travis-ci.org/RcppCore/RcppArmadillo.png)](https://travis-ci.org/RcppCore/RcppArmadillo) ### Overview [Armadillo](http://arma.sf.net) is a templated C++ linear algebra library written by Conrad Sanderson that aims towards a good balance between speed and ease of use. Integer, floating point and complex numbers are supported, as well as a subset of trigonometric and statistics functions. Various matrix decompositions are provided through optional integration with LAPACK and ATLAS libraries. A delayed evaluation approach is employed (during compile time) to combine several operations into one, and to reduce (or eliminate) the need for temporaries. This is accomplished through recursive templates and template meta-programming. This library is useful if C++ has been decided as the language of choice (due to speed and/or integration capabilities), rather than another language. The RcppArmadillo package includes the header files from the templated Armadillo library. Thus users do not need to install Armadillo itself in order to use RcppArmadillo. This Armadillo integration provides a nice illustration of the capabilities of the [Rcpp](http://www.rcpp.org) package for seamless R and C++ integration. ### Status The package is under active development with releases to [CRAN](http://cran.r-project.org) about once a month. ### Documentation The package contains a pdf vignette which is a pre-print of the [paper by Eddelbuettel and Sanderson](http://dx.doi.org/10.1016/j.csda.2013.02.005) in CSDA (2013, in print). ### Authors Romain Francois, Dirk Eddelbuettel and Doug Bates ### License GPL (>= 2) RcppArmadillo/MD50000644000176000001440000010537312267661346013371 0ustar ripleyusers5a2a18857d7ea0d5f0877f4320d73dd0 *ChangeLog 506643a63b345a9709e89170a8e6c70e *DESCRIPTION 96319c54633d05bbcfb0a02922bb99b7 *NAMESPACE c5c9c7a50a8fe2414d0b54d79260d115 *R/RcppArmadillo.package.skeleton.R 948aaf85334e79f50283f43c08bec2a7 *R/RcppExports.R 6b1a4108b342efb9750a27f6f17d0b4a *R/fastLm.R c425fa93fb2732616eb94c17a8141afa *R/flags.R affc9669ed4d8afcb269d69f8be890dd *R/inline.R c8147ed1e52eb6b09f481a1424bbcc43 *R/unit.test.R 29afc4dc84f5cb617ce3efb053c1dd8d *README.md 1b1c04755933b34639fbeae2ebf401d6 *build/vignette.rds 992f18c228e6bd6e0a2473b0510074b2 *cleanup ffa5d20924f6e09f6b18608f2bf45a46 *configure b6608a0367c7f14e162caddc1e7a581b *inst/CITATION 69f8a041b5d5bc3a896a06e6e7a8cfe3 *inst/NEWS.Rd 662c1aa30653a4d2667c81c1acd84c87 *inst/announce/ANNOUNCE-0.2.0.txt 0e090615ca7019263be6e7fa4b49511c *inst/doc/RcppArmadillo-intro.R 56abd60a96ee458a647321389391703e *inst/doc/RcppArmadillo-intro.Rnw fdeb5551b415d3a612869ec04b064ac9 *inst/doc/RcppArmadillo-intro.pdf 97f6b3e1612564333f6a0ef255c395fc *inst/doc/RcppArmadillo-unitTests.R 8f103df17585a5902611212fc44ca83b *inst/doc/RcppArmadillo-unitTests.Rnw e187ab143f8b34488e61a1029d340a19 *inst/doc/RcppArmadillo-unitTests.pdf 0e9e769fad655ca4804954d96673a614 *inst/examples/fastLm.r 93037baec9a906713b4ca11046a1b0fc *inst/examples/kalman/FirstKalmanR.R 4a7b51922e6d94f6dc6075eb5c0bf09f *inst/examples/kalman/Kalman.cpp 700568fe04f7c2001be4ad3ca5b6f244 *inst/examples/kalman/KalmanR.R df9eaa9c640cda72c24570759edf4cd1 *inst/examples/kalman/KalmanRimp.R 0a7e51657579311b27554fec18f1dd00 *inst/examples/kalman/benchmark.R d329b78c9f94c4d99155333f18b3f311 *inst/examples/kalman/firstExample.R c3c2e3d3d7867f6ed7574a273723dcf5 *inst/examples/kalman/kalmanExample.m 04f360597c45a3eb82ada7f23be16812 *inst/examples/kalman/kalmanM.m c17927f9637d4000daf2aa4331c7db9d *inst/examples/kalman/kalmanfilter.m 2771369ff122fc008211c246481d09a5 *inst/examples/kalman/pos.txt 9907a728a90363f3b07bb131b332449a *inst/examples/varSimulation.r 446b5281f5e18f4946d7f915cde24337 *inst/include/README cf27487b141b51b9c0d49b5d210ffa0d *inst/include/RcppArmadillo.h daa8921d68416c321159f700a0477222 *inst/include/RcppArmadillo/Col_meat.h 29697cb890d6a5fb2b205772dfc27ca2 *inst/include/RcppArmadillo/Col_proto.h 661a5044d196422b333da76a539020fa *inst/include/RcppArmadillo/Mat_meat.h 084c9564f00621b4d4ee65e6ad5dc3b5 *inst/include/RcppArmadillo/Mat_proto.h e577ccb03d814de3925c79c083f080c6 *inst/include/RcppArmadillo/Row_meat.h bbda5c00444bb23d5e5ab3e7fe7f0f1c *inst/include/RcppArmadillo/Row_proto.h 618b2d832a714b9c00254405e1637813 *inst/include/RcppArmadilloAs.h f38748652e62849f6211490534885f33 *inst/include/RcppArmadilloConfig.h 73e01e8f1630d5b7a73be263e3aeeda9 *inst/include/RcppArmadilloExtensions/sample.h b074a6176f177cb66df9fe43ff28aa2e *inst/include/RcppArmadilloForward.h 2300676d6238d833f17d3ce71a506cf4 *inst/include/RcppArmadilloLapack.h.in 2353f13b85d199492f52b65f0be1f7f1 *inst/include/RcppArmadilloSugar.h 121a23a3f4ba1c511ef9d1a349f570d5 *inst/include/RcppArmadilloWrap.h 4080aca3fedd771dd93a01022e18bdac *inst/include/armadillo 7b2bc522eb8ccc066ac7259a8609f53b *inst/include/armadillo_bits/BaseCube_bones.hpp a65c5ea15ad0a077c68ab82e78403860 *inst/include/armadillo_bits/BaseCube_meat.hpp 3241bceb6b9b9da5ecfb760794892d78 *inst/include/armadillo_bits/Base_bones.hpp ad469181019c2379d4206ea11ff9c323 *inst/include/armadillo_bits/Base_meat.hpp 6cbd6f82f329c6e8113e96b5096181df *inst/include/armadillo_bits/Col_bones.hpp 71b70f48c453c1d766f45baf182048d7 *inst/include/armadillo_bits/Col_meat.hpp 025c7105edd50b5c0b876afdc9c10a40 *inst/include/armadillo_bits/Cube_bones.hpp 73c0b4464181de45329fdabf7acb04b9 *inst/include/armadillo_bits/Cube_meat.hpp 0b24f4036042d671d53b32da1c343da4 *inst/include/armadillo_bits/GenCube_bones.hpp 5ab650e90866f757a6bbe57ef8d7da94 *inst/include/armadillo_bits/GenCube_meat.hpp 287e422717cadd17e0bc279bf296604c *inst/include/armadillo_bits/Gen_bones.hpp 8e9bf65e4ed10f4f6640d179ee2e6fdc *inst/include/armadillo_bits/Gen_meat.hpp a10b7541cb7863141db58c4d7d297923 *inst/include/armadillo_bits/GlueCube_bones.hpp b7b7269b9be54e69281b9d1deda6cf46 *inst/include/armadillo_bits/GlueCube_meat.hpp 06f02264c5e948e035051f2eb2d58042 *inst/include/armadillo_bits/Glue_bones.hpp db25c8d3e64f413bdd426ff43e739646 *inst/include/armadillo_bits/Glue_meat.hpp cfcc6fbfab7b57656fde7c0e11f25ad9 *inst/include/armadillo_bits/Mat_bones.hpp d04f33cdc99316e913c4908254cb8543 *inst/include/armadillo_bits/Mat_meat.hpp c537c7c3ac9a1714a607dd99180d5608 *inst/include/armadillo_bits/OpCube_bones.hpp fa95d3cf8bd70a9f119ef309b78802ba *inst/include/armadillo_bits/OpCube_meat.hpp 8474108cc49bc838623e1c8748708171 *inst/include/armadillo_bits/Op_bones.hpp 37beea7fbdb699cad925bb69729917c2 *inst/include/armadillo_bits/Op_meat.hpp 7e4da9572e0a6086f710a76d3adc1b48 *inst/include/armadillo_bits/Proxy.hpp 473bb2cf6ccb83f1d5bab98f3add0fe4 *inst/include/armadillo_bits/ProxyCube.hpp 4831392d5dc1badc55775b12781fba2d *inst/include/armadillo_bits/Row_bones.hpp d5c2c26cf58ab47935b734e73960d6a9 *inst/include/armadillo_bits/Row_meat.hpp 016409dbca5accd862766d676dbdf4aa *inst/include/armadillo_bits/SizeCube_bones.hpp 8c9432db45949c28a4f9f5210a4c94cb *inst/include/armadillo_bits/SizeCube_meat.hpp dd69747439e12c82e6e860e9a3596cf6 *inst/include/armadillo_bits/SizeMat_bones.hpp 380a28836be79aee821dfde4f9e7ba51 *inst/include/armadillo_bits/SizeMat_meat.hpp 24b16acd17f77d71a654640b7195b816 *inst/include/armadillo_bits/SpBase_bones.hpp bb1d3255599f216188846eeec3daf3fd *inst/include/armadillo_bits/SpBase_meat.hpp 877db3a409d17dca70c97f73a1eebe42 *inst/include/armadillo_bits/SpCol_bones.hpp 1f17ce55b150660584d6f530bae9ccdf *inst/include/armadillo_bits/SpCol_meat.hpp 30e8b8f5af882b55889431bcb9f9a696 *inst/include/armadillo_bits/SpGlue_bones.hpp d3388e15aca576defb6c3f191ceb8f89 *inst/include/armadillo_bits/SpGlue_meat.hpp 9e817c6137784b837fbbccd7f83d2cde *inst/include/armadillo_bits/SpMat_bones.hpp 47a10262022394bad26cc1deaee75157 *inst/include/armadillo_bits/SpMat_iterators_meat.hpp 8b2da38450ed83742094c82553a71c3c *inst/include/armadillo_bits/SpMat_meat.hpp 75f570ef7e94c68de537ab0543ce01f4 *inst/include/armadillo_bits/SpOp_bones.hpp cb13c96656f13d6d984f908899b68dcd *inst/include/armadillo_bits/SpOp_meat.hpp a6dbbd3e48e260cd2e36b681e3daa0d1 *inst/include/armadillo_bits/SpProxy.hpp 1dc054446f91edcd8ad3a591490eaeaf *inst/include/armadillo_bits/SpRow_bones.hpp 87adfd258f6113cbd695d72d819b5f91 *inst/include/armadillo_bits/SpRow_meat.hpp 433da3cd575a000090ab4d7c9d59254c *inst/include/armadillo_bits/SpSubview_bones.hpp bf968e0f795911431cb3483034d218a2 *inst/include/armadillo_bits/SpSubview_iterators_meat.hpp 64ecce9dee47e57f72356164b3380291 *inst/include/armadillo_bits/SpSubview_meat.hpp 35832519ecdecff234f98501e684c2b9 *inst/include/armadillo_bits/SpValProxy_bones.hpp f466a499411a0e551e48de1b8c36d47f *inst/include/armadillo_bits/SpValProxy_meat.hpp 0e0d0a87cf22f8c43dd46983e6e1d5c5 *inst/include/armadillo_bits/access.hpp deebcedb61d9b330be67f3cfdf2476ac *inst/include/armadillo_bits/arma_boost.hpp eba28ea2b8ae2d27283597c224948694 *inst/include/armadillo_bits/arma_cmath.hpp b654f2d1a7586459bb583160335f0199 *inst/include/armadillo_bits/arma_config.hpp a591cb160f9c1b4ba88c930e6d58d89e *inst/include/armadillo_bits/arma_ostream_bones.hpp 32b088662e56eb17273229a81583cd8a *inst/include/armadillo_bits/arma_ostream_meat.hpp b5db77f4de2c9fd90a8c27fa918105fa *inst/include/armadillo_bits/arma_rng.hpp 0b10b2b005ab32aecd54e65c69ad686e *inst/include/armadillo_bits/arma_rng_cxx11.hpp f977ef904e890c23dc5422221efbaad7 *inst/include/armadillo_bits/arma_rng_cxx98.hpp 076e0a1d2c0f09c4a4fbc8d6db71898e *inst/include/armadillo_bits/arma_static_check.hpp f14b7ac494a4b2aff4edbad3e220b51f *inst/include/armadillo_bits/arma_version.hpp eef018e3c78cfb4d96fd3bfd7c63185f *inst/include/armadillo_bits/arpack_bones.hpp dc8270d28d95ea084c925af4676b2949 *inst/include/armadillo_bits/arpack_wrapper.hpp 550148fa2abca6d36cca3364422ca540 *inst/include/armadillo_bits/arrayops_bones.hpp 10567d827652ccaf290950ee840941c3 *inst/include/armadillo_bits/arrayops_meat.hpp f541b0254b77aeb6158e9b6236010bbf *inst/include/armadillo_bits/atlas_bones.hpp 1462f49553a1e99a1786f679b3126eff *inst/include/armadillo_bits/atlas_wrapper.hpp 01f1628dcd203449fcb69e9b8e316459 *inst/include/armadillo_bits/auxlib_bones.hpp d7a8170c5d4913816d18c3dea9d32ef5 *inst/include/armadillo_bits/auxlib_meat.hpp a5580c22a0b5a2021c31bf0d5d6f12fb *inst/include/armadillo_bits/blas_bones.hpp d30f1279775532a697bc0d09624ec8c4 *inst/include/armadillo_bits/blas_wrapper.hpp 618b3fe5b659ea3c22df1326c02c9bb0 *inst/include/armadillo_bits/compiler_setup.hpp 59b7621d79bb0fd6d2b29a0ee4527f46 *inst/include/armadillo_bits/compiler_setup_post.hpp 3c544969b68d54a450b926403b6c043b *inst/include/armadillo_bits/cond_rel_bones.hpp ca32c18647960175f04b55810b31713d *inst/include/armadillo_bits/cond_rel_meat.hpp 3b47db4df5d3d66ef07d489c5234ddad *inst/include/armadillo_bits/config.hpp 63d16c182dc6df93402f2e7abe9a7654 *inst/include/armadillo_bits/constants.hpp 03904cca57f2c7ec21a3e75798b3cb85 *inst/include/armadillo_bits/constants_compat.hpp 4de778fbd68d9165d4e34c4d33562d70 *inst/include/armadillo_bits/debug.hpp 86df316e33557610ed9ad8d3a1b0e592 *inst/include/armadillo_bits/diagmat_proxy.hpp 88a682a1bdf19d25e8861b58be2f9b6a *inst/include/armadillo_bits/diagview_bones.hpp cfe71bc783a38204f33ca31ebff7a44a *inst/include/armadillo_bits/diagview_meat.hpp 7c30aa1a777400cf5bdc3a3482625c72 *inst/include/armadillo_bits/diskio_bones.hpp 622770994b267e07b34cd10375792abb *inst/include/armadillo_bits/diskio_meat.hpp 4145c0ac59ef8d1d680374d4343d0169 *inst/include/armadillo_bits/distr_param.hpp 35ac3ad9cd17caf0753930c74e25e586 *inst/include/armadillo_bits/eGlueCube_bones.hpp ea70b57ee4a0777b97115e43212764f1 *inst/include/armadillo_bits/eGlueCube_meat.hpp 2820cf2c958a37e9e27f5ca8447fcca5 *inst/include/armadillo_bits/eGlue_bones.hpp 8e91ba75e46b2dbdfdd5436666f40073 *inst/include/armadillo_bits/eGlue_meat.hpp 05e21119541eeccab18d80295b43d929 *inst/include/armadillo_bits/eOpCube_bones.hpp 69c35820d4b355118c10f9ab8fef4e0c *inst/include/armadillo_bits/eOpCube_meat.hpp 6d9ee6c294039c4ab9905fde9ed329e1 *inst/include/armadillo_bits/eOp_bones.hpp 5d5220b2b4dd8daf82f6cf6538db8b72 *inst/include/armadillo_bits/eOp_meat.hpp 7af256550b6162787aba61f7515a091d *inst/include/armadillo_bits/eglue_core_bones.hpp 87a2c5c8b88674abc9127d7a1f68ade6 *inst/include/armadillo_bits/eglue_core_meat.hpp 59ec7aa28c53ea4a14a8285fd5e83494 *inst/include/armadillo_bits/eop_aux.hpp 49dcbbcdb96463398a96b2dcd0e9c2ec *inst/include/armadillo_bits/eop_core_bones.hpp 6b140e6216d8f4ab4e2c9e0c3a59402d *inst/include/armadillo_bits/eop_core_meat.hpp 88c5d86c1d431ec30b18a946c169d68f *inst/include/armadillo_bits/fft_engine.hpp 3e108d930d43300d9732543430606b6f *inst/include/armadillo_bits/field_bones.hpp 364385e25e9fec26797a16d0760baab8 *inst/include/armadillo_bits/field_meat.hpp 00a5954a234c7453f2aae4999245b466 *inst/include/armadillo_bits/fn_accu.hpp d46b1d6052169d7592b2b45880930a2e *inst/include/armadillo_bits/fn_all.hpp acf17dc4714c1e4a987ede0b4216a468 *inst/include/armadillo_bits/fn_any.hpp 9b55c3f18bd4fc4f67cd36d6d3dc8a23 *inst/include/armadillo_bits/fn_as_scalar.hpp 3b48860135f5606d075f3f6bcc8bd54a *inst/include/armadillo_bits/fn_chol.hpp e2c79305bb4e13d55707ddb0c68688a8 *inst/include/armadillo_bits/fn_cond.hpp 0aa0c79ab31fdc3c7bc3d3640e68196c *inst/include/armadillo_bits/fn_conv.hpp a5df4d86a84812598ed08066fe7bf814 *inst/include/armadillo_bits/fn_conv_to.hpp dda3d5beacdbd3d96a0118d9f73f1f3a *inst/include/armadillo_bits/fn_cor.hpp 034e1789cd7be58914688871f22d0a03 *inst/include/armadillo_bits/fn_cov.hpp 3b018cc3ac83616992be17b0b1f8ad3a *inst/include/armadillo_bits/fn_cross.hpp f1c3ae6bf47d65bfd2070b4adb9feb21 *inst/include/armadillo_bits/fn_cumsum.hpp 9f85970dd6db1d90d6fdfd95ce252c40 *inst/include/armadillo_bits/fn_det.hpp de4107cd2e3e256616660e22f69126e5 *inst/include/armadillo_bits/fn_diagmat.hpp 8149374aad67685c7f068793b2c991d3 *inst/include/armadillo_bits/fn_diagvec.hpp 39363e2e4803dd384d71a46bb9fbb544 *inst/include/armadillo_bits/fn_dot.hpp c8aa206c6de8ac81af881dedfb54e91c *inst/include/armadillo_bits/fn_eig_gen.hpp 84f0d0e9792fd0f53d01421955625d4c *inst/include/armadillo_bits/fn_eig_pair.hpp 5b7052307175a4e9ae3a566a5fc81e4e *inst/include/armadillo_bits/fn_eig_sym.hpp 387addbab36f25a0293512b0672af726 *inst/include/armadillo_bits/fn_eigs_gen.hpp ac8c12889da1e63cbee98692f9b1c792 *inst/include/armadillo_bits/fn_eigs_sym.hpp 57d787656f95fea84ff5cc442926ebf7 *inst/include/armadillo_bits/fn_elem.hpp 5e55498af3f6853edb1a7a466a45fcdd *inst/include/armadillo_bits/fn_eps.hpp 1c1b9edffa02ba5c837a01a064b3c0a0 *inst/include/armadillo_bits/fn_eye.hpp 9deacbd8094a0e884628dd4939ca3c0f *inst/include/armadillo_bits/fn_fft.hpp 8590b1abdd07803d33a5e45fa10231cb *inst/include/armadillo_bits/fn_fft2.hpp a1cc281734c87c4855c226f2e9354426 *inst/include/armadillo_bits/fn_find.hpp e6a3a096fdbcd727d38a6f6508dbbb8f *inst/include/armadillo_bits/fn_flip.hpp 65aa658498b319817b12880a5021fc04 *inst/include/armadillo_bits/fn_hist.hpp 07d8411d2961de8021587c76da2cc218 *inst/include/armadillo_bits/fn_histc.hpp 2d3afea951607b407e5810353a426b6f *inst/include/armadillo_bits/fn_inplace_strans.hpp be8f5a01e19428e7145921e9041827ed *inst/include/armadillo_bits/fn_inplace_trans.hpp a7b171357d9ed95b8977c0874c682f17 *inst/include/armadillo_bits/fn_inv.hpp 1d304f20f28a91f6d5d44cc739c16fb0 *inst/include/armadillo_bits/fn_join.hpp 52250e2878dbcc3d0388b9b7fff17ad3 *inst/include/armadillo_bits/fn_kron.hpp 4633bb411d8a1d3837510875866a81a2 *inst/include/armadillo_bits/fn_log_det.hpp 80b2fba6c76a050e9711ebf795e4e563 *inst/include/armadillo_bits/fn_lu.hpp d1b6996083240b4b90ec7d82b64a9283 *inst/include/armadillo_bits/fn_max.hpp fb745ce209abf8db0cca56aaa4cf1fa2 *inst/include/armadillo_bits/fn_mean.hpp ae1a2fc753a2fd866b5f59b5d81b43f8 *inst/include/armadillo_bits/fn_median.hpp ffa0372921029bd1af0ae7f08b31587b *inst/include/armadillo_bits/fn_min.hpp 7bb9d65abcedafb71631ae39caabd1b0 *inst/include/armadillo_bits/fn_misc.hpp a18cfa715ab1059ebe730d67a188de3e *inst/include/armadillo_bits/fn_n_unique.hpp 27c1c10b43f3b7aac10270d5d2e43b1e *inst/include/armadillo_bits/fn_norm.hpp 4bbbc0d5e4d31cce8217b947623777a1 *inst/include/armadillo_bits/fn_numel.hpp c7baf494e566c8b9ea1e82c5b9a73950 *inst/include/armadillo_bits/fn_ones.hpp 65e133fa17c5caa74ae48179be5025c3 *inst/include/armadillo_bits/fn_pinv.hpp aa1867c35a22e359d87b7ac08d7ee4f0 *inst/include/armadillo_bits/fn_princomp.hpp 544f1ec36289aad93bff14b7ad7d7a56 *inst/include/armadillo_bits/fn_prod.hpp 6ddb21b278baf6e34df6fe3fd7f8acda *inst/include/armadillo_bits/fn_qr.hpp f571fa68ee44cf67b5a0234753290c67 *inst/include/armadillo_bits/fn_randi.hpp 14b8e99664c15431d4e1915cb5e3f86d *inst/include/armadillo_bits/fn_randn.hpp 33f4c0fb645e650cc7cbf5ce1485cd2f *inst/include/armadillo_bits/fn_randu.hpp 57f092b8891fa7199ec2a495ac1c73af *inst/include/armadillo_bits/fn_rank.hpp 9cb12eb55209377f0f2864f61f93cc1d *inst/include/armadillo_bits/fn_repmat.hpp d8eb5d832eb479a407a333e4f699726f *inst/include/armadillo_bits/fn_reshape.hpp a6791e00980f155c11dcc447a9796c53 *inst/include/armadillo_bits/fn_resize.hpp faff3a32b9e820f8f20f71850699b4a8 *inst/include/armadillo_bits/fn_shuffle.hpp 26f8645a62831a799230591001c57d55 *inst/include/armadillo_bits/fn_size.hpp 7e68bb8aac4e6d8eee1c488e6e1b3b03 *inst/include/armadillo_bits/fn_solve.hpp a654ab5f455aa717e54c7985107c7874 *inst/include/armadillo_bits/fn_sort.hpp 5d331a1dd3c4d7dd0c58612b11bd49e3 *inst/include/armadillo_bits/fn_sort_index.hpp 816242386bb03dd123b52c3ce0871f46 *inst/include/armadillo_bits/fn_speye.hpp aada6bd1e17732210c976363addac226 *inst/include/armadillo_bits/fn_spones.hpp 194ad8416acc4e52e49abe2005c41237 *inst/include/armadillo_bits/fn_sprandn.hpp f72daea2cf8662cb3568afdcb0d4016d *inst/include/armadillo_bits/fn_sprandu.hpp 4a56f44b67370ebb4c402d2695c6bd42 *inst/include/armadillo_bits/fn_stddev.hpp 2275ea51373baab96d5372ea932fa406 *inst/include/armadillo_bits/fn_strans.hpp 1681f65413f07f45818235e49b0fae29 *inst/include/armadillo_bits/fn_sum.hpp 5f3830522bd08de17131980709830368 *inst/include/armadillo_bits/fn_svd.hpp dcc10edaac81854ede16e0663d5d62da *inst/include/armadillo_bits/fn_syl_lyap.hpp 34d0dd92ca194b7368c8800066ba8373 *inst/include/armadillo_bits/fn_symmat.hpp 5034613c18177f89167012211de906cd *inst/include/armadillo_bits/fn_toeplitz.hpp 8f8930c17a54dd44a962cd496f1987bd *inst/include/armadillo_bits/fn_trace.hpp ed692df614f32805034b45a4d3aba5c6 *inst/include/armadillo_bits/fn_trans.hpp d6bf0b194add51f4064cea63bdd5a46d *inst/include/armadillo_bits/fn_trig.hpp edb2435dc70ba11865827ed9fbd89736 *inst/include/armadillo_bits/fn_trimat.hpp 1f1a0ab9b1814d2bf11f3436bf4b2c47 *inst/include/armadillo_bits/fn_trunc_exp.hpp 875a0cdbc996447d5f9344635e37ec3c *inst/include/armadillo_bits/fn_trunc_log.hpp 8d64dacc809b9d0119743a956c861ac5 *inst/include/armadillo_bits/fn_unique.hpp acee519dd6a47eb524897d1cdc639d05 *inst/include/armadillo_bits/fn_var.hpp 5afd2845a708e86f68d931743146f51d *inst/include/armadillo_bits/fn_vectorise.hpp 3c041c28ecddecd38e93176d7c476500 *inst/include/armadillo_bits/fn_zeros.hpp 53a2739bcfbd3d7f6a166461b6481983 *inst/include/armadillo_bits/forward_bones.hpp 6f0371deed91516c761c3cb5f590949a *inst/include/armadillo_bits/glue_conv_bones.hpp a4a5784fa1072cdbe8b6e3558d29a484 *inst/include/armadillo_bits/glue_conv_meat.hpp 5ad8515d2554950cd57e58c9d93f8b05 *inst/include/armadillo_bits/glue_cor_bones.hpp 500a489b5aa35a5d040e5d5a6d3f727c *inst/include/armadillo_bits/glue_cor_meat.hpp c2cb53471334ddd27cf848d97c1fe3d2 *inst/include/armadillo_bits/glue_cov_bones.hpp 06a2e07b488dee902afa652fb5be3746 *inst/include/armadillo_bits/glue_cov_meat.hpp e8c06e08464d71dbd2c787c22c4f0521 *inst/include/armadillo_bits/glue_cross_bones.hpp bbec81fb06e53fca1bc7e17988fe2a90 *inst/include/armadillo_bits/glue_cross_meat.hpp 87f4603eb58162c12e72306908ca9b46 *inst/include/armadillo_bits/glue_hist_bones.hpp cf63656f23c2d386c0d082e12019bb4a *inst/include/armadillo_bits/glue_hist_meat.hpp 730d2a8fd0d564ec951516513176d5e9 *inst/include/armadillo_bits/glue_histc_bones.hpp 2fafa211716749f4f1ddc0647f1b7f45 *inst/include/armadillo_bits/glue_histc_meat.hpp 39effbba54dacb1a5b004c208cb54818 *inst/include/armadillo_bits/glue_join_bones.hpp ec76bc6ae95af38107f6eafe1e1a77cc *inst/include/armadillo_bits/glue_join_meat.hpp 0a155bc11b89d94ebed5fac35553db2c *inst/include/armadillo_bits/glue_kron_bones.hpp 85e9ade3dd3a8650868bc0835e52d275 *inst/include/armadillo_bits/glue_kron_meat.hpp 45260b4ebdefe9821b020a76cca288d2 *inst/include/armadillo_bits/glue_max_bones.hpp 952aef494a90be13a14a37484b6df87a *inst/include/armadillo_bits/glue_max_meat.hpp b662b2b6fd373372745f284e48e9e5d6 *inst/include/armadillo_bits/glue_min_bones.hpp 95a9e59f6ccfb6ea005fafee50704aa5 *inst/include/armadillo_bits/glue_min_meat.hpp 40c834127fc1d74e7b28182f93008f0b *inst/include/armadillo_bits/glue_mixed_bones.hpp db3cee6a4dac60b8ea1f51ef7015ee7f *inst/include/armadillo_bits/glue_mixed_meat.hpp c9fee80d3ab3c4738131758c04efd768 *inst/include/armadillo_bits/glue_relational_bones.hpp cefaa68e893cf598b76e3a383a9822f6 *inst/include/armadillo_bits/glue_relational_meat.hpp 51fdea988cd3a6c0ad7f0595a391f9a3 *inst/include/armadillo_bits/glue_solve_bones.hpp b60b68c43006073b83c19ab53fb1edad *inst/include/armadillo_bits/glue_solve_meat.hpp 067e8bf28867eba1b2f77c8a91ec6343 *inst/include/armadillo_bits/glue_times_bones.hpp 5cc671efaf93ffb047ff521039b05d77 *inst/include/armadillo_bits/glue_times_meat.hpp 356c11c055a5c1ed552fd5a681a10c8b *inst/include/armadillo_bits/glue_toeplitz_bones.hpp 2d4627261cd67a9e94762897f33e9d33 *inst/include/armadillo_bits/glue_toeplitz_meat.hpp a85690088fb1880b978906cfcceff9a4 *inst/include/armadillo_bits/hdf5_misc.hpp 38eaf143908d1d23f95c97c445cb2988 *inst/include/armadillo_bits/include_atlas.hpp 820d6f5e649167f845ebdd69c67c5b24 *inst/include/armadillo_bits/injector_bones.hpp 21b7658cf6c720db7c61e9f449cf3601 *inst/include/armadillo_bits/injector_meat.hpp 24194b1978d3fa107b82188f5a9a20e5 *inst/include/armadillo_bits/lapack_bones.hpp 8995bf77f894ad5cfaaa107b996472c2 *inst/include/armadillo_bits/lapack_wrapper.hpp 6b6a40054e22ad8ea7007645947ccea4 *inst/include/armadillo_bits/memory.hpp 499920d3250d874da78988aa1ffa0592 *inst/include/armadillo_bits/mtGlueCube_bones.hpp 2bb68435bdae59cff57a310aa32463f8 *inst/include/armadillo_bits/mtGlueCube_meat.hpp e64751a078f6ab10a12eb123ac34ed14 *inst/include/armadillo_bits/mtGlue_bones.hpp 85cf0aeabd2383e6064768951dd4f6dd *inst/include/armadillo_bits/mtGlue_meat.hpp 65866f316ef651a5f6893b846f8e929f *inst/include/armadillo_bits/mtOpCube_bones.hpp 6d71d03b647dbd5992f2e28da1f9d837 *inst/include/armadillo_bits/mtOpCube_meat.hpp d8c44417c4be69662e0c253f19d1a1ca *inst/include/armadillo_bits/mtOp_bones.hpp 087b7db0e8f2ec3e5396093b161f7348 *inst/include/armadillo_bits/mtOp_meat.hpp 31c91971e6b476ab547bc9c4b6c1e35c *inst/include/armadillo_bits/mtSpOp_bones.hpp 3df82f6ccdd5683bcef3d9de452ee293 *inst/include/armadillo_bits/mtSpOp_meat.hpp aed70e56e348eced8ba15634c71ea160 *inst/include/armadillo_bits/mul_gemm.hpp 4abb0b5b65febefb65780f840a3ba52d *inst/include/armadillo_bits/mul_gemm_mixed.hpp 91ec74ccdbae5565828e66e8040ef5ea *inst/include/armadillo_bits/mul_gemv.hpp 25007f15da508ebaa41ee0852bda9aab *inst/include/armadillo_bits/mul_herk.hpp 488551a8f643c55938f3146f0d729623 *inst/include/armadillo_bits/mul_syrk.hpp 392750c0ae026e52a95f1452cb80089f *inst/include/armadillo_bits/op_all_bones.hpp d986776fc4f6d77919e14600424eff26 *inst/include/armadillo_bits/op_all_meat.hpp 08f2e876cfe97bbac1dbc9cadfb0cf37 *inst/include/armadillo_bits/op_any_bones.hpp 122b210158467e7e42900d9f2522d932 *inst/include/armadillo_bits/op_any_meat.hpp 39f94722048e65b213a5ababe0d85a03 *inst/include/armadillo_bits/op_chol_bones.hpp 446c8e7665d274722cd49268d0437aba *inst/include/armadillo_bits/op_chol_meat.hpp b27642194a6ef1166607f10f215d27ef *inst/include/armadillo_bits/op_cor_bones.hpp 848132602619fbd929cbbbe4671f1ed4 *inst/include/armadillo_bits/op_cor_meat.hpp 6544a7c2b3d3f7f1258e5bd55d5e483b *inst/include/armadillo_bits/op_cov_bones.hpp dd0eb272b099605fc9e5af58bf023d3b *inst/include/armadillo_bits/op_cov_meat.hpp ef23b0932a423971f6798f6127d0ba0c *inst/include/armadillo_bits/op_cumsum_bones.hpp 344edafa48a259a95993c46de6ac57c7 *inst/include/armadillo_bits/op_cumsum_meat.hpp d02063871e8c44b5ce638a559dbbb1bd *inst/include/armadillo_bits/op_cx_scalar_bones.hpp e683c3fd4b4f6306df4259d09624eec6 *inst/include/armadillo_bits/op_cx_scalar_meat.hpp 6444c9fbf9c9d88e86ae8874f7729aa6 *inst/include/armadillo_bits/op_diagmat_bones.hpp 7f675b10454ed19f5307c887128e81a6 *inst/include/armadillo_bits/op_diagmat_meat.hpp cf822d1b98c99268c662ea259684c2d9 *inst/include/armadillo_bits/op_diagvec_bones.hpp 2f683a9a8248250f5cad5f56aa4f61a8 *inst/include/armadillo_bits/op_diagvec_meat.hpp 914ed537e555ea6078af93ff69f84a9d *inst/include/armadillo_bits/op_dot_bones.hpp b296a937ef43b4a23dc1a4701a26512c *inst/include/armadillo_bits/op_dot_meat.hpp 2762ef74d6ca60c250f2ea43ae5d354d *inst/include/armadillo_bits/op_dotext_bones.hpp 9063e35c26ac086a1f4cdfed29ac9f94 *inst/include/armadillo_bits/op_dotext_meat.hpp 299c49d794761d711e19fd3d84a9e2a0 *inst/include/armadillo_bits/op_fft_bones.hpp 6edc3dc7f2246e3afe78b996a9070cc0 *inst/include/armadillo_bits/op_fft_meat.hpp a56902c71803ae88d5b6b921fdb5fe78 *inst/include/armadillo_bits/op_find_bones.hpp 401938701bdc5dbc4887517bf695591d *inst/include/armadillo_bits/op_find_meat.hpp 2c7b3d41d6357ad8378bbf1b809f631f *inst/include/armadillo_bits/op_flip_bones.hpp 25c64b68b4ce0d687543076ef6a375eb *inst/include/armadillo_bits/op_flip_meat.hpp aca0904838e395048c01be3b82685d42 *inst/include/armadillo_bits/op_hist_bones.hpp a26f874129c75e29f69c6fe2bd6602fe *inst/include/armadillo_bits/op_hist_meat.hpp ce7061e17193e38a475dceba044e0852 *inst/include/armadillo_bits/op_htrans_bones.hpp 45811f78cb9b710fbea09f98f743dae7 *inst/include/armadillo_bits/op_htrans_meat.hpp e59f2f62033b7a9665482bf5e362a933 *inst/include/armadillo_bits/op_inv_bones.hpp fd371d83c199aae30aa28eb0eaf8dd1a *inst/include/armadillo_bits/op_inv_meat.hpp 0c52dda013210b99282da3830a0297dd *inst/include/armadillo_bits/op_max_bones.hpp 2e9ce35a13b35949ba73081c42e6bc78 *inst/include/armadillo_bits/op_max_meat.hpp 241d73e5ba6417044ce4e148ad2d08cd *inst/include/armadillo_bits/op_mean_bones.hpp 05149063c8ff8376922f3f4de53682ea *inst/include/armadillo_bits/op_mean_meat.hpp 887ec7e5c3a803ff9b18125ad26896ed *inst/include/armadillo_bits/op_median_bones.hpp 6eb25d37bca95f127d448cf10eeea602 *inst/include/armadillo_bits/op_median_meat.hpp 27beffd45d7c7d493bbf801d4ccc62eb *inst/include/armadillo_bits/op_min_bones.hpp e05157db61f4fdc74171dd85a0c9ad2f *inst/include/armadillo_bits/op_min_meat.hpp 8e975935810eadc3021d52926c3b406d *inst/include/armadillo_bits/op_misc_bones.hpp 426783d2066e11a07900dc257f64732d *inst/include/armadillo_bits/op_misc_meat.hpp bc6b28043943b270d37766019e757d0f *inst/include/armadillo_bits/op_pinv_bones.hpp 29370f756ade613e05982699548d9a6b *inst/include/armadillo_bits/op_pinv_meat.hpp 29d3f1b025a8154ca10a2ffb7629acc1 *inst/include/armadillo_bits/op_princomp_bones.hpp 9d52df913b07409164ba4cbc5ce27b6d *inst/include/armadillo_bits/op_princomp_meat.hpp 9dc7ce3fc6a91034eeb5964a6a3c56fa *inst/include/armadillo_bits/op_prod_bones.hpp 553ec672d298f2a1b99705851bfb1b48 *inst/include/armadillo_bits/op_prod_meat.hpp 88aac5217aa7ca01e908eb951b4accfb *inst/include/armadillo_bits/op_relational_bones.hpp b1c866badd36493f68e55155ce545a16 *inst/include/armadillo_bits/op_relational_meat.hpp 5dcdc63221126652405cc653544623e7 *inst/include/armadillo_bits/op_repmat_bones.hpp a8a0120c998445d7fa0c6ca7d6690cab *inst/include/armadillo_bits/op_repmat_meat.hpp 947f52a04f0f5376dbe4b8a9f6011d1d *inst/include/armadillo_bits/op_reshape_bones.hpp 169205230fa2fee8cebd6318957a7ac5 *inst/include/armadillo_bits/op_reshape_meat.hpp 132c446e933172de6a22b28e9f350a8a *inst/include/armadillo_bits/op_resize_bones.hpp 5890e3de427bddf1a057b7505fedcf84 *inst/include/armadillo_bits/op_resize_meat.hpp 49f85baa216552b1ecd9324c13b58d13 *inst/include/armadillo_bits/op_shuffle_bones.hpp 84ac34c1c367d9c4abc73882aebae2b5 *inst/include/armadillo_bits/op_shuffle_meat.hpp d9ba5b5da313c3805932e97b677d1d96 *inst/include/armadillo_bits/op_sort_bones.hpp f1d02015bb0204e06cddd448ef9a6a3f *inst/include/armadillo_bits/op_sort_meat.hpp 961fb6c54577aed07ebd8ed63365a189 *inst/include/armadillo_bits/op_stddev_bones.hpp d038b1cbd905da7dc9ad64dbe38a9d7d *inst/include/armadillo_bits/op_stddev_meat.hpp 6921014209b4778224ce8a90b141fa06 *inst/include/armadillo_bits/op_strans_bones.hpp 54f13d589f7dffd7b46fdbc54f4f59a6 *inst/include/armadillo_bits/op_strans_meat.hpp bdabbb0d522577b5c62b31d5f7c46cb7 *inst/include/armadillo_bits/op_sum_bones.hpp e6c10c87a9f48160cccd1f4b2858b0f8 *inst/include/armadillo_bits/op_sum_meat.hpp cf1f53fef31aa42c9f18534e9936d92b *inst/include/armadillo_bits/op_symmat_bones.hpp e1c9edf2cbcfdfd41c609bb702cf5980 *inst/include/armadillo_bits/op_symmat_meat.hpp 412e92c405a9e3928fa6b772284bc7b9 *inst/include/armadillo_bits/op_toeplitz_bones.hpp 04ad85c8577574731a8f8c86788bd769 *inst/include/armadillo_bits/op_toeplitz_meat.hpp e4cd61813d4daad64b8b50dfe2e07d59 *inst/include/armadillo_bits/op_trimat_bones.hpp a69ce3e9f007a9c946659c8f5f6e9bbe *inst/include/armadillo_bits/op_trimat_meat.hpp ee2f233f6b41ff24f05af31685ef5872 *inst/include/armadillo_bits/op_unique_bones.hpp 5ec8970c0502a70b8a03cf9bd3acbc7c *inst/include/armadillo_bits/op_unique_meat.hpp ac12fe54def68d3cc8b8a17498fd0cd0 *inst/include/armadillo_bits/op_var_bones.hpp 4954b46922a7af820c52c5d8152c6621 *inst/include/armadillo_bits/op_var_meat.hpp 3ca020b7d29eb35a3bdc4553f81cd0ce *inst/include/armadillo_bits/op_vectorise_bones.hpp e0175392f9453f0dd2d7c3594ca8254b *inst/include/armadillo_bits/op_vectorise_meat.hpp 4a453847a93bad1e4d2f9dc7e2506337 *inst/include/armadillo_bits/operator_cube_div.hpp 23fc141f963f593e8a6c9f46e6af16bf *inst/include/armadillo_bits/operator_cube_minus.hpp d0072400b2bc90be7a6372cb9d3c8389 *inst/include/armadillo_bits/operator_cube_plus.hpp 94086f89bff0cdca12594630b418a51d *inst/include/armadillo_bits/operator_cube_relational.hpp 6363a8df40f102d67717c881bfbe4df8 *inst/include/armadillo_bits/operator_cube_schur.hpp f7a8139a086a4ea023f7684b2442308e *inst/include/armadillo_bits/operator_cube_times.hpp c942f32cfe5bfd007b6ac34e7f171c82 *inst/include/armadillo_bits/operator_div.hpp 4556f3978bb74eb21fed1f7b6011e5d9 *inst/include/armadillo_bits/operator_minus.hpp 16108bbe5b843893de647933b8130f6c *inst/include/armadillo_bits/operator_ostream.hpp cb99bb545b3032d189b4e7d5af4a217a *inst/include/armadillo_bits/operator_plus.hpp e49597c126e6624f0db4ee6748a194da *inst/include/armadillo_bits/operator_relational.hpp ae07ea0aa8590dd6546c9af024256a65 *inst/include/armadillo_bits/operator_schur.hpp 7d821569f6efbbe3bf5633709ef9787d *inst/include/armadillo_bits/operator_times.hpp f7e5ada70aa63c420a2aeff9c933a086 *inst/include/armadillo_bits/podarray_bones.hpp 3dbbfdcdb1e537cced05b995d390f9dd *inst/include/armadillo_bits/podarray_meat.hpp ce51b4a24248fc399089cdf2bb1fe4b8 *inst/include/armadillo_bits/promote_type.hpp c9e9019d19818082a6002f79df942828 *inst/include/armadillo_bits/restrictors.hpp 911f2080ac5630164007af3fd396538d *inst/include/armadillo_bits/running_stat_bones.hpp b9189ab1c2c6e86d0c4adba5f92e1f4f *inst/include/armadillo_bits/running_stat_meat.hpp be118ccb5663eeafd515b5607eb215b4 *inst/include/armadillo_bits/running_stat_vec_bones.hpp bf8b2a65f54f1e1a52293d8afc8645c0 *inst/include/armadillo_bits/running_stat_vec_meat.hpp 778391c48df38b6e6dffc321ce65da15 *inst/include/armadillo_bits/sp_auxlib_bones.hpp 9e562ca11d70680b525695437be46eba *inst/include/armadillo_bits/sp_auxlib_meat.hpp 5c537ea5ad6535bb57e184d84ec8d47c *inst/include/armadillo_bits/span.hpp 1972e126c786348a9475503421c667f3 *inst/include/armadillo_bits/spglue_minus_bones.hpp 30e2288a51638266dff48afec730f129 *inst/include/armadillo_bits/spglue_minus_meat.hpp c7d87f450c252d9f2320069010eea28c *inst/include/armadillo_bits/spglue_plus_bones.hpp 7e2ff6a57063bca4276e2a27df857a1e *inst/include/armadillo_bits/spglue_plus_meat.hpp 8d1cb3057783379dbfec9f661a9380b4 *inst/include/armadillo_bits/spglue_times_bones.hpp 7ac0f861992d5446826df880817c5947 *inst/include/armadillo_bits/spglue_times_meat.hpp dc950ed4be63af2948e359f9f3ad825c *inst/include/armadillo_bits/spop_htrans_bones.hpp 001a2b754b703405442e63266fc38eaa *inst/include/armadillo_bits/spop_htrans_meat.hpp 0847fcaa8fd4d774fef6e119c62b23ab *inst/include/armadillo_bits/spop_max_bones.hpp d730ff162033e0e0d857ab3b4e3a080f *inst/include/armadillo_bits/spop_max_meat.hpp 1f14d87a9b763956e2861c44999d14cc *inst/include/armadillo_bits/spop_mean_bones.hpp 2b75990f5e5a3607d8565c7e47ed40ec *inst/include/armadillo_bits/spop_mean_meat.hpp 9457a9ec06029e0d749911cbddb20fe5 *inst/include/armadillo_bits/spop_min_bones.hpp 8aead344d33888b6265535da85b9c3ae *inst/include/armadillo_bits/spop_min_meat.hpp cd7468c282a07a9121684020728c25ae *inst/include/armadillo_bits/spop_misc_bones.hpp abcf991e24acb957ecffab7a16c04ac8 *inst/include/armadillo_bits/spop_misc_meat.hpp 8df38693b230bf17f7943b63f983da29 *inst/include/armadillo_bits/spop_strans_bones.hpp 4c8ce8d317e6d9c6529a221695148489 *inst/include/armadillo_bits/spop_strans_meat.hpp effa6273d0c5546fb23d776430de59fe *inst/include/armadillo_bits/spop_sum_bones.hpp 5971244283550762280a078bbecbf3b1 *inst/include/armadillo_bits/spop_sum_meat.hpp 6b1745b9606ec4b7f5c372c968b45a57 *inst/include/armadillo_bits/spop_var_bones.hpp b016389b83762b11da658986eb449b63 *inst/include/armadillo_bits/spop_var_meat.hpp 37704a74e423d9c1d8c71e880cd575d2 *inst/include/armadillo_bits/strip.hpp 80c9b6456162ab875fa06c2cd9cfa005 *inst/include/armadillo_bits/subview_bones.hpp 989ac8ce15baae26883065a0f449f743 *inst/include/armadillo_bits/subview_cube_bones.hpp 57dea454dc27af1daf35e59343c2d418 *inst/include/armadillo_bits/subview_cube_meat.hpp 0f880483f58a64fca824c5c230306eac *inst/include/armadillo_bits/subview_each_bones.hpp ed7c16c8532d633b9a6999a54242bfde *inst/include/armadillo_bits/subview_each_meat.hpp 73f5e36a7187163db5e6992317277f1e *inst/include/armadillo_bits/subview_elem1_bones.hpp f3568fe5b60eb125c5ed8eaf34998169 *inst/include/armadillo_bits/subview_elem1_meat.hpp a7b7c7d2dde88d8140f841ad1c4f4408 *inst/include/armadillo_bits/subview_elem2_bones.hpp 9e0919882c3e5c8f06df713ea63460be *inst/include/armadillo_bits/subview_elem2_meat.hpp b90b4ba43e193cf24aa1192e7c95a4b7 *inst/include/armadillo_bits/subview_field_bones.hpp 32d12f2143c9cd8781323efb94df4627 *inst/include/armadillo_bits/subview_field_meat.hpp 924e9f0d8d5cac22c84c1a03a466bb0f *inst/include/armadillo_bits/subview_meat.hpp eec5625f24115eb1f96a8dee51f557a7 *inst/include/armadillo_bits/traits.hpp 37274e37814ef6d56cd129d17426d77a *inst/include/armadillo_bits/typedef_elem.hpp ddcf03cdbd912975b288f23ce9545c39 *inst/include/armadillo_bits/typedef_elem_check.hpp 670a30de5d37236a171438a9f9aae55f *inst/include/armadillo_bits/typedef_mat.hpp e8a2873697db7342734fdd06227a07b4 *inst/include/armadillo_bits/typedef_mat_fixed.hpp 3745b8394e05df99193da8d202ef9914 *inst/include/armadillo_bits/unwrap.hpp 975d9930e563dd815b483dd9f621aebc *inst/include/armadillo_bits/unwrap_cube.hpp 4e338f97c797b9d95b3723af24a297a0 *inst/include/armadillo_bits/unwrap_spmat.hpp b750fb222b83119a3d032ad456044450 *inst/include/armadillo_bits/upgrade_val.hpp 0c5aff93d09692e4f22accaadfba9741 *inst/include/armadillo_bits/wall_clock_bones.hpp 3bf4b42c7906ca5ba72e3d883f895bc9 *inst/include/armadillo_bits/wall_clock_meat.hpp 805300dc5067fe34d6f0fdc11cd1aab8 *inst/include/armadillo_bits/xvec_htrans_bones.hpp 29348c62d9f6440382b9831652d49510 *inst/include/armadillo_bits/xvec_htrans_meat.hpp 95a5e0dc5dbdec9c251c142cb4cad286 *inst/skeleton/Makevars 64be831ee13c45351b4d0839e550b59a *inst/skeleton/Makevars.win 42dfafc80b10536e5b0867c525c3da57 *inst/skeleton/rcpparma_hello_world.R 15c00859bbfd40a994917a50b804e5ac *inst/skeleton/rcpparma_hello_world.cpp d81a50bbc8fe944ac39fc6f3cb93dc15 *inst/skeleton/rcpparma_hello_world.h ec5be8c816417a29d3fbce6d663d3d30 *inst/unitTests/cpp/armadillo.cpp c06ef6645dcfbc98c280233f75f58cd4 *inst/unitTests/cpp/complex.cpp a1ddd74a7c925a4d576d6e8227dfb546 *inst/unitTests/cpp/sample.cpp f30597b75e3ac94b0017f23c8a85f4d4 *inst/unitTests/runTests.R 7f872c1a3f7f2e631bb3811e2fa12922 *inst/unitTests/runit.RcppArmadillo.R 1cbfa5b9d8a6d97a4bb664500c98a398 *inst/unitTests/runit.complex.R 9090a484989582f146f8004308a52910 *inst/unitTests/runit.fastLm.R f217131cab7b02b9a789997ac8d7a1cb *inst/unitTests/runit.sample.R 320680a7a7b17e909d057c322d7ca0bc *man/RcppArmadillo-package.Rd 30981735fa8e4b19fb0e8e7afc845e9d *man/RcppArmadillo.package.skeleton.Rd fd9f6dd1cea9eb30a62f0b2a069f2648 *man/fastLm.Rd 45ab4e60348063c0e5ff6c461a290fba *src/Makevars 64be831ee13c45351b4d0839e550b59a *src/Makevars.win 18f83f30cedbb50a7d1c0bbf6ad15196 *src/RcppArmadillo.cpp fa822b9d1b14a5e04bd3aa5781e31da1 *src/RcppExports.cpp 93303a8765db519932e28f4bda8dfe81 *src/fastLm.cpp bea1e49788f7fbe2f7d0ee1cd75dc6b7 *tests/doRUnit.R 56abd60a96ee458a647321389391703e *vignettes/RcppArmadillo-intro.Rnw 8f103df17585a5902611212fc44ca83b *vignettes/RcppArmadillo-unitTests.Rnw 96be3bd20dae05c2dfec0ce00a9525a8 *vignettes/RcppArmadillo.bib f02fe6eca6720cb2197bb40137cde7e5 *vignettes/elsarticle-harv.bst ad44f4892f75e6e05dca57a3581f78d1 *vignettes/elsarticle.cls 4eec3b07dd016502fbd0f80b6e75bf16 *vignettes/kalmanExample.pdf RcppArmadillo/build/0000755000176000001440000000000012267623072014141 5ustar ripleyusersRcppArmadillo/build/vignette.rds0000644000176000001440000000044012267623072016476 0ustar ripleyusersK0dz0z}Axî&`4x/_M֊G)L5^s{x@BnӲ|90!e(EU5f+S%}R# 5>GRɲ$>fsk6l)'9{3M<>VhWR(:4`t2gB ?`vi`f ~sߺ0C_כ5/b/.4 uQ'~m^MR WIm ƖRcppArmadillo/DESCRIPTION0000644000176000001440000000362512267661346014564 0ustar ripleyusersPackage: RcppArmadillo Type: Package Title: Rcpp integration for Armadillo templated linear algebra library Version: 0.4.000.2 Date: 2014-01-21 Author: Romain Francois, Dirk Eddelbuettel and Doug Bates Maintainer: Dirk Eddelbuettel Description: R and Armadillo integration using Rcpp Armadillo is a templated C++ linear algebra library (by Conrad Sanderson) that aims towards a good balance between speed and ease of use. Integer, floating point and complex numbers are supported, as well as a subset of trigonometric and statistics functions. Various matrix decompositions are provided through optional integration with LAPACK and ATLAS libraries. . A delayed evaluation approach is employed (during compile time) to combine several operations into one, and to reduce (or eliminate) the need for temporaries. This is accomplished through recursive templates and template meta-programming. . This library is useful if C++ has been decided as the language of choice (due to speed and/or integration capabilities), rather than another language. . The RcppArmadillo package includes the header files from the templated Armadillo library. Thus users do not need to install Armadillo itself in order to use RcppArmadillo. . This Armadillo integration provides a nice illustration of the capabilities of the Rcpp package for seamless R and C++ integration. . Armadillo is licensed under the MPL 2.0, while RcppArmadillo (the Rcpp bindings/bridge to Armadillo) is licensed under the GNU GPL version 2 or later, as is the rest of Rcpp. License: GPL (>= 2) LazyLoad: yes LinkingTo: Rcpp Imports: Rcpp Suggests: RUnit URL: https://github.com/RcppCore/RcppArmadillo, http://arma.sourceforge.net/, http://dirk.eddelbuettel.com/code/rcpp.armadillo.html Packaged: 2014-01-22 02:00:26.158371 UTC; edd NeedsCompilation: yes Repository: CRAN Date/Publication: 2014-01-22 07:19:18 RcppArmadillo/configure0000755000176000001440000000160412253723621014746 0ustar ripleyusers#!/bin/bash if [ "${R_HOME}" == "" ]; then R_HOME=$(R RHOME) fi lapack=$(${R_HOME}/bin/R CMD config LAPACK_LIBS) echo -n "* checking LAPACK_LIBS" hasRlapack=$(echo ${lapack} | grep lRlapack) if [ "${hasRlapack}" == "" ]; then ## We are using a full Lapack and can use zgesdd -- so #undef remains echo " divide-and-conquer complex SVD available via system LAPACK" cp inst/include/RcppArmadilloLapack.h.in inst/include/RcppArmadilloLapack.h else ## We are using a R's subset of Lapack and CANNOT use zgesdd -- so mark ARMA_DONT_USE_CX_GESDD as 1 echo " divide-and-conquer complex SVD unavailable via R-supplied LAPACK" echo "* divide-and-conquer algorithm for complex SVD will be redirected to default" sed -e 's/\/\/ \#undef ARMA_DONT_USE_CX_GESDD/\#define ARMA_DONT_USE_CX_GESDD/' \ inst/include/RcppArmadilloLapack.h.in > inst/include/RcppArmadilloLapack.h fi RcppArmadillo/ChangeLog0000644000176000001440000010411312267622063014613 0ustar ripleyusers2014-01-21 Dirk Eddelbuettel * DESCRIPTION: Release 0.4.000.2 * inst/NEWS: Release 0.4.000.2 * inst/include/*: Upgraded to new release 4.000.2 of Armadillo * debian/*: Similarly updated for new release to Debian 2014-01-07 Dirk Eddelbuettel * inst/include/armadillo_bits/compiler_setup.hpp: Applied one-line patch by Jan Marvin Garbuszu to permit build under recent icc; patch also passed on upstream to Conrad 2014-01-05 Dirk Eddelbuettel * DESCRIPTION: Release 0.4.000 * inst/NEWS: Release 0.4.000 * inst/include/*: Upgraded to new release 4.000 of Armadillo * debian/*: Similarly updated for new release to Debian 2013-12-09 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.930.1 * inst/NEWS: Release 0.3.930.1 * inst/include/*: Upgraded to new release 3.930.1 of Armadillo which falls back to standard complex SVD if no zgesdd * debian/*: Similarly updated for new release to Debian * configure: Test value of LAPACK_LIBS and if the Lapack version supplied by R used then define ARMA_DONT_USE_CX_GESDD * inst/include/RcppArmadilloLapack.h.in: Added header file to be processed by configure 2013-12-06 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.930.0 * inst/NEWS: Release 0.3.930.0 * inst/include/*: Upgraded to new release 3.930 of Armadillo * debian/*: Similarly updated for new release to Debian * inst/include/*: Upgraded to Armadillo 3.930 ("Dragon's Back") * inst/include/armadillo_bits/compiler_setup.hpp: Exclude POSIX memalign also if on Sun OS as per Brian Ripley's suggestion 2013-12-05 Dirk Eddelbuettel * inst/unitTests/runit.complex.R: Added unit tests for complex matrices and vector contributed by Baptiste Auguie * inst/unitTests/cpp/complex.cpp: C++ side of new tests 2013-12-04 Dirk Eddelbuettel * inst/include/*: Upgraded to 2nd beta release of Armadillo 3.930 2013-12-02 Dirk Eddelbuettel * inst/include/*: Upgraded to 1st beta release of Armadillo 3.930 2013-11-19 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.920.3 * inst/NEWS: Release 0.3.920.3 * inst/include/*: Upgraded to new release 3.920.3 of Armadillo * debian/*: Similarly updated for new release to Debian 2013-09-29 Dirk Eddelbuettel * inst/examples/fastLm.r: Added a 'const ref' example * inst/examples/varSimulation.r: Use 'const ref', skip one superfluous transpose 2013-09-28 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.920.1 * inst/NEWS: Release 0.3.920.1 * inst/include/*: Upgraded to new release 3.920.1 of Armadillo * debian/*: Similarly updated for new release to Debian * DESCRIPTION: Depends on Rcpp (>= 0.10.5) which shipped to CRAN 2013-09-27 Romain Francois * include/RcppArmadilloAs.h : handle cx_mat, using that Rcomplex is layout compatible with std::complex * unitTests/cpp/armadillo.cpp : more testing * unitTests/runit.RcppArmadillo.R : more testing 2013-09-23 Dirk Eddelbuettel * inst/include/*: Upgraded to Armadillo pre-release of 3.920.0 * DESCRIPTION: Mark as test release version 0.3.910.0.2 2013-09-15 Dirk Eddelbuettel * inst/include/RcppArmadilloAs.h: Also define ConstInputParameter * inst/include/RcppArmadilloForward.h: Ditto for declaration * inst/unitTests/runit.RcppArmadillo.R: New unit tests for these * inst/unitTests/cpp/armadillo.cpp: C++ code for new unit tests 2013-09-15 Romain Francois * include/RcppArmadilloForward.h : declaration of specializations of ConstReferenceInputParameter and ReferenceInputParameter * include/RcppArmadilloAs.h : definitions of the above 2013-09-13 Romain Francois * DESCRIPTION : require Rcpp 0.10.4.4 * include/RcppArmadilloForward.h : declaration of specializations of InputParameter for references and const reference to arma::Mat * include/RcppArmadilloAs.h : definitions of the above 2013-08-24 Romain Francois * include/RcppArmadilloExtensions/sample.h: added include guard, made functions SampleReplace, etc ... templates to avoid the multiple definitions problem 2013-08-21 Romain Francois * include/RcppArmadilloWrap.h: Less data copies for wrap< SpMat > * include/RcppArmadilloAs.h: Less data copies for as< SpMat > 2013-08-20 Romain Francois * include/RcppArmadilloWrap.h: Handle wrap * include/RcppArmadilloWrap.h: cleaner implementation for wrap< SpMat > * include/RcppArmadilloAs.h: cleaner implementation for as< SpMat > 2013-08-17 Dirk Eddelbuettel * vignettes/RcppArmadillo-intro.Rnw: Converted from LaTeX minted (which farms out to Python's pygmentize) to LaTeX listings (which is plainer, but works on CRAN) * DESCRIPTION: Remove 'BuildVignettes: FALSE' 2013-08-12 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.910.0 * inst/NEWS: Release 0.3.910.0 * inst/include/*: Upgraded to new release 3.910.0 of Armadillo * debian/*: Similarly updated for new release to Debian * vignettes/*: Moved files from inst/doc per new CRAN standards * DESCRIPTION: Set 'BuildVignettes: FALSE' as LaTeX minted mode creates issues for the CRAN builders * inst/doc/*: Include pre-built vignettes 2013-08-03 Dirk Eddelbuettel * inst/include/RcppArmadilloExtensions/spmat.h: Added basic as<> and wrap support for sparse matrices (of class dgCMatrix from the Matrix package); currently only type double is supported * inst/unitTests/runit.RcppArmadillo.R: Improved test setup a little * inst/unitTests/runit.sample.R: Ditto 2013-08-02 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.900.7 * inst/NEWS: Release 0.3.900.7 * inst/include/*: Upgraded to new release 3.900.7 of Armadillo * debian/*: Similarly updated for new release to Debian 2013-08-02 Romain Francois * include/RcppArmadillo/Row_meat.h: set vec_state correctly * include/RcppArmadillo/Col_meat.h: set vec_state correctly * include/RcppArmadillo/Mat_meat.h: set vec_state correctly 2013-07-12 Dirk Eddelbuettel * inst/unitTests/runTests.R: No longer need to test minimal versions of package 'inline' as unit tests now use Rcpp attributes * inst/unitTests/runit.RcppArmadillo.R: Don't load package 'library' * inst/examples/fastLm.r: Also rewritten to use Rcpp attributes * inst/examples/varSimulation.r: Idem * DESCRIPTION: Removed Suggests: on inline 2013-06-04 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.900.0 * inst/NEWS: Release 0.3.900.0 * inst/include/*: Upgraded to new release 3.900.0 of Armadillo * debian/*: Similarly updated for new release to Debian 2013-05-16 Dirk Eddelbuettel * inst/examples/kalman/benchmark.R: Switch from inline to sourceCpp * inst/examples/kalman/Kalman.cpp: Added Rcpp attributes function * inst/examples/kalman/KalmanCpp.R: Retired, no longer used 2013-05-13 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.820 * inst/NEWS: Release 0.3.820 * inst/include/*: Upgraded to new release 3.820 of Armadillo * debian/*: Similarly updated for new release to Debian 2013-04-30 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.810.2 * inst/NEWS: Release 0.3.810.2 * inst/include/*: Upgraded to new release 3.810.2 of Armadillo * debian/*: Similarly updated for new release to Debian 2013-04-19 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.810.0 * inst/NEWS: Release 0.3.810.0 * inst/include/*: Upgraded to new release 3.810.0 of Armadillo * debian/*: Similarly updated for new release to Debian 2013-04-05 Dirk Eddelbuettel * debian/: Package will be added to Debian as well 2013-03-29 Dirk Eddelbuettel * inst/include/RcppArmadilloExtensions/sample.h: Applied another patch by Christian Gunning * inst/unitTests/runit.sample.R (test.sample): Idem 2013-03-12 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.800.1 * inst/include/*: Upgraded to new release 3.800.1 of Armadillo * inst/unitTests/cpp/armadillo.cpp: Factored out of runit.RcppArmadillo.R to accelerate unit test run * inst/unitTests/runit.RcppArmadillo.R: Deploy refactored cpp code 2013-03-11 Dirk Eddelbuettel * inst/unitTests/cpp/sample.cpp: Regrouping C++ tests for sample() * inst/unitTests/runit.sample.R: Rewritten for sole external cpp file 2013-03-10 Dirk Eddelbuettel * inst/include/add-ons/sample.h: Added sample() function contributed by Christian Gunning * inst/unitTests/runit.sample.R: Added unit test for sample() contributed by Christian Gunning 2013-03-01 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.800.0 * DESCRIPTION: Updated Description to reflect change of Armadillo license to MPL 2.0 (which is fully compatible with GPL so no change or net effect to RcppArmadillo) * inst/include/*: Upgraded to new release 3.800.0 of Armadillo * inst/doc/RcppArmadillo-intro.Rnw: Updated vignette to preprint of the Computational Statistics & Data Analysis paper in press * inst/doc/*: Added or updated relevant support files * inst/CITATION: Added with reference to CSDA paper 2013-02-20 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.6.3 * inst/include/*: Upgraded to new release 3.6.3 of Armadillo 2013-01-29 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.6.2 * inst/include/*: Upgraded to new release 3.6.2 of Armadillo 2013-01-19 Dirk Eddelbuettel * inst/examples/kalman/: New example used in the vignette 2012-12-17 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.6.1 * inst/include/*: Upgraded to new release 3.6.1 of Armadillo 2012-12-10 Romain Francois * include/RcppArmadillo.h: compiler error if Rcpp.h is included before RcppArmadillo.h 2012-12-07 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.6.0 * inst/include/*: Upgraded to new release 3.6.0 of Armadillo 2012-11-15 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.4.4 * inst/include/*: Upgraded to new release 3.4.4 of Armadillo 2012-10-04 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.4.3 * inst/include/*: Upgraded to new release 3.4.3 of Armadillo 2012-09-25 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.4.2 * inst/include/*: Upgraded to new release 3.4.2 of Armadillo 2012-09-18 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.4.1 * inst/include/*: Upgraded to new release 3.4.1 of Armadillo 2012-09-06 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.4.0 * inst/include/*: Upgraded to new release 3.4.0 of Armadillo 2012-08-31 Dirk Eddelbuettel * inst/NEWS.Rd: Converted to Rd format 2012-08-30 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.3.91 * inst/include/*: Upgraded to release 3.3.91 (v3.4 beta 1) of Armadillo 2012-07-21 Dirk Eddelbuettel * inst/unitTests/runit.fastLm.R: expanded unit tests for fastLm 2012-07-18 Dirk Eddelbuettel * R/fastLm.R (summary.fastLm): Also display residual standard error 2012-07-14 Dirk Eddelbuettel * R/fastLm.R (fastLm.formula): Note whether intercept in formula or not; also store the result of summary() on residuals * R/fastLm.R (fastLm.default): Autmagically detect intercept use * R/fastLm.R (print.summary.fastLm): Display summary of residuals * R/fastLm.R (summary.fastLm): Distinguish between the intercept and no-intercept cases when computing R^2 2012-07-11 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.2.4 * inst/include/*: Upgraded to new release 3.2.4 of Armadillo 2012-07-01 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.2.3 * inst/include/*: Upgraded to new release 3.2.3 of Armadillo * inst/include/armadillo_bits/: Reverted files {Mat,Col,Row}_bones.hpp to the previous versions due to compilation issues under g++ 4.7 * inst/doc/RcppArmadillo-intro.Rnw: New introductory vignette based on just-submitted paper by Eddelbuettel and Sanderson * DESCRIPTION: Set Maintainer: to edd@debian.org as CRAN prefers to provide upload email from the same address the Maintainer field 2012-05-26 Dirk Eddelbuettel * inst/examples/fastLm.r: Also examine the 'two versus one' casts impact when converting SEXP to Armadillo types 2012-05-21 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.2.0 * inst/include/*: Upgraded to new release 3.2.0 of Armadillo 2012-05-15 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.1.94 * inst/include/*: Upgraded to new (beta) release 3.1.94 of Armadillo 2012-05-10 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.1.92 * inst/include/*: Upgraded to new (beta) release 3.1.92 of Armadillo 2012-05-03 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.0.3 * inst/include/*: Upgraded to new release 3.0.3 of Armadillo 2012-04-29 Dirk Eddelbuettel * inst/examples/fastLm.r: New example fastLm 2012-04-19 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.0.2 * inst/include/*: Upgraded to new release 3.0.2 of Armadillo 2012-04-17 Dirk Eddelbuettel * inst/include/RcppArmadilloConfig.h: Undefine NDEBUG to not suppress Armadillo debug messages 2012-04-12 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.0.1 * inst/include/*: Upgraded to new release 3.0.1 of Armadillo 2012-04-11 Dirk Eddelbuettel * inst/include/RcppArmadilloConfig.h: Protect define of ARMA_DEFAULT_OSTREAM by a #ifndef test 2012-04-10 Dirk Eddelbuettel * DESCRIPTION: Release 0.3.0 * inst/include/*: Upgraded to new release 3.0.0 of Armadillo 2012-04-04 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.40 * inst/include/*: Upgraded to new test release 2.99.4 of Armadillo 2012-04-02 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.39 * inst/include/*: Upgraded to new test release 2.99.3 of Armadillo 2012-03-28 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.38 * inst/include/*: Upgraded to new test release 2.99.2 of Armadillo 2012-03-24 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.37 2012-03-24 Romain Francois * inst/include/RcppArmadilloWrap.h: adapt to Armadillo 2.99.1 2012-03-19 Dirk Eddelbuettel * inst/include/*: Upgraded to new test release 2.99.1 of Armadillo 2012-03-05 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.36 * inst/include/*: Upgraded to new release 2.4.4 of Armadillo 2012-02-17 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.35 (depending on Rcpp 0.9.10) * inst/include/*: Upgraded to new release 2.4.3 of Armadillo 2012-02-01 Romain Francois * inst/include/armadillo_bits/Cube_meat.hpp : changes related to std::cout -> Rcpp::Rcout * inst/include/armadillo_bits/Mat_meat.hpp : idem * inst/include/armadillo_bits/config.hpp : idem * inst/include/armadillo_bits/debug.hpp : idem * inst/include/armadillo_bits/field_meat.hpp : idem * inst/include/armadillo_bits/forward_bones.hpp : idem * DESCRIPTION: depends on Rcpp 0.9.10 2011-12-31 Dirk Eddelbuettel * inst/include/RcppArmadillo/Mat_meat.h: Add missing semicolon in code ifdef'ed for C++0x mode, with thanks to Teo Guo Ci 2011-12-29 Dirk Eddelbuettel * src/RcppArmadillo.cpp: Force instantiation of arma version vars which helps with older OS X compiler, as suggested by Gershon Bialer 2011-12-23 Dirk Eddelbuettel * inst/unitTests/runTests.R: unit tests output 'fallback' directory changed to '..' and files are now in top-level of $pkg.Rcheck/ 2011-12-13 Dirk Eddelbuettel * man/RcppArmadillo-package.Rd: Updated to current version number, added Conrad's Technical Report as a reference 2011-12-12 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.34 * inst/include/*: Upgraded to new release 2.4.2 of Armadillo 2011-12-07 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.33 * inst/include/*: Upgraded to new release 2.4.1 of Armadillo 2011-12-04 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.32 * inst/include/*: Upgraded to new release 2.4.0 of Armadillo 2011-11-28 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.31 * inst/include/*: Upgraded to new test release 2.3.92 of Armadillo 2011-11-19 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.30 2011-11-17 Romain Francois * inst/include/RcppArmadilloSugar.h: reworked forwarding sugar expressions to arma expressions. No need for the "forward" function anymore. For now, we kept forward as a templated identity function for backwards compatibility but it is not needed anymore * inst/include/RcppArmadillo/Mat_meat.h: reworked handling of complex values * inst/unitTests/runit.RcppArmadillo.R: removed uses of forward as we don't need it anymore. 2011-11-16 Romain Francois * inst/include/RcppArmadilloForward.h: support for the new arma classes Gen and GenCube that arma uses internally * inst/include/RcppArmadilloWrap.h: idem * inst/include/RcppArmadillo/Mat_meat.h: adapted to the changed arma_type_check 2011-11-14 Dirk Eddelbuettel * inst/include/*: Upgraded to new test release 2.3.91 of Armadillo 2011-09-01 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.29 * inst/include/*: Updated to bug-fix release 2.2.3 of Armadillo 2011-08-02 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.28 * inst/include/*: Updated to release 2.2.1 of Armadillo 2011-07-22 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.27 * inst/include/*: Updated to release 2.1.91 of Armadillo 2011-07-17 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.26 * inst/include/*: Updated to release 2.0.2 of Armadillo 2011-06-30 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.25 * inst/include/*: Updated to release 2.0.1 of Armadillo 2011-06-29 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.24 * inst/include/*: Updated to release 2.0.0 of Armadillo 2011-06-23 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.23 * inst/include/*: Updated to release 1.99.5 of Armadillo 2011-06-14 Douglas Bates * R/fastLm.R, inst/unitTests/runit.fastLm.R, man/fastLm.Rd, src/fastLm.cpp: Change order of arguments in fastLm.cpp and fastLm.R and documentation. 2011-06-14 Dirk Eddelbuettel * ChangeLog, inst/NEWS: ChangeLog and NEWS entry for Doug's S3 fixes 2011-06-13 Douglas Bates * NAMESPACE: Properly export S3methods as such * man/fastLm.Rd: Similar updates to help page 2011-06-06 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.22 * inst/include/*: Updated to release 1.99.4 of Armadillo 2011-05-30 Dirk Eddelbuettel * inst/include/RcppArmadilloConfig.h: Enable sprintf on FreeBSD by undefining ARMA_HAVE_STD_SNPRINTF thanks to patch by Rainer Hurling 2011-05-27 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.21 * inst/include/*: Updated to release 1.99.3 of Armadillo 2011-05-25 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.20 * inst/include/*: Updated to release 1.99.2 of Armadillo 2011-05-16 Dirk Eddelbuettel * inst/include/*: Updated to test release 1.99.1 of Armadillo 2011-04-25 Dirk Eddelbuettel * src/RcppArmadillo.cpp: Rewritten armadillo_version as to no longer require an instance of arma::arma_version, with Thanks! to Conrad 2011-04-22 Dirk Eddelbuettel * inst/examples/varSimulation.r: New example simulating of first-order vector autoregression data set via R, compiled R and RcppArmadillo 2011-04-18 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.19 * inst/include/*: Updated to Armadillo 1.2.0 "Unscrupulous Carbon Emitter" 2011-04-08 Dirk Eddelbuettel * R/fastLm.R: In print.summary.fastLm(), use 'P.values' not 'P.value' 2011-04-03 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.18 * inst/include/*: Updated to Armadillo 1.1.92 "Jurassic Barbecue" * inst/doc/Makefile: Do not 'clean' in 'all' target 2011-03-22 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.17 * inst/include/*: Updated to Armadillo 1.1.90 "Inside Job" 2011-03-10 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.16 * inst/include/*: Updated to Armadillo 1.1.8 "Kangaroo Steak" 2011-03-04 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.15 * inst/include/*: Updated to Armadillo 1.1.6 “Baby Carpet Shark” 2011-03-02 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.14 * inst/include/RcppArmadillo/Row_meat.h: Support RTTI via vec_state * inst/include/RcppArmadillo/Col_meat.h: Support RTTI via vec_state * inst/unitTests/runit.RcppArmadillo.R: Added unit test for above 2011-02-28 Dirk Eddelbuettel * inst/doc/Makefile: Call R and Rscript relative to R_HOME/bin 2011-02-20 Dirk Eddelbuettel * src/fastLm.cpp (fastLm): Further simplified and shortened by using Rcpp::as() on the input data 2011-02-18 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.13 * inst/include/*: Updated to Armadillo 1.1.4 "Manta Lodge" 2011-02-15 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.12 * inst/include/*: Updated to Armadillo 1.1.2 "Flood Kayak" 2011-01-06 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.11 * inst/include/*: Updated to Armadillo 1.1.0 "Climate Vandal" 2010-12-12 Romain Francois * R/SHLIB.R: new unexported R function SHLIB, small wrapper around R CMD SHLIB 2010-11-25 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.10 * inst/include/*: Updated to Armadillo 1.0.0 "Antipodean Antileech” 2010-11-19 Dirk Eddelbuettel * R/fastLm.R: Also provide two R-squared measures in summary method 2010-11-19 Romain Francois * DESCRIPTION: remove dependency on GNU make * R/RcppArmadillo.package.skeleton.R: updated skeleton generator so that the dependency on GNU make is removed 2010-11-11 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.9 * inst/include/*: Updated to Armadillo 0.9.92 "Wall Street Gangster" 2010-10-16 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.8 * inst/include/*: Updated to Armadillo 0.9.90 "Water Dragon" * NEWS: moved to inst/NEWS so that it gets installed with the package * inst/ChangeLog: moved to top-level enabling 'C-x 4 a' lookups 2010-09-25 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.7 2010-09-25 Romain Francois * inst/include/RcppArmadilloWrap.h: Updated for Armadillo 0.9.80 2010-09-21 Dirk Eddelbuettel * inst/include/*: Update to Armadillo 0.9.80 "Chihuahua Muncher" 2010-09-12 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.6 2010-09-10 Romain Francois * inst/include/* : Update to Armadillo 0.9.70 "Subtropical Winter Safari" 2010-08-18 Romain Francois * inst/include/armadillo_bits/Mat_meat.hpp : not so intrusive patch that allows RcppArmadillo to add its own Mat constructors * inst/include/armadillo_bits/Mat_proto.hpp : same * inst/include/RcppArmadillo/Mat_proto.h : Mat constructor that takes a sugar expression * inst/include/RcppArmadillo/Mat_meat.h : implementation 2010-08-17 Romain Francois * inst/include/RcppArmadilloWrap.h : extracted from RcppArmadillo.h * inst/include/RcppArmadilloSugar.h : preliminary code to more interoperability between Rcpp sugar and armadillo. Defines the Rcpp::forward that allows forwarding the result of a sugar expression so that it is used in a Mat constructor. (needs more testing) * inst/unitTests/runit.RcppArmadillo.R : initial test for sugar/armadillo 2010-08-04 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.5 * Upgraded to Armadillo 0.9.60 "Killer Bush Turkey" with changes: - More flexible reshape(), allowing significantly different matrix sizes - Added matrix initialisation via the << operator - Fixes for compilation issues under Mac OS X with GCC 4.2/4.0 hybrid 2010-08-03 Romain Francois * Upgraded to Armadillo 0.9.58 beta for testing purposes * inst/include/armadillo: Reworked so that armadillo_bits/ directory can be included as is without minor tweaks to armadillo_bits/config.hpp 2010-07-28 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.4 * inst/include/armadillo_bits: Added small patch to not use asinh, acosh and atanh on win32 as the (older) MinGW compiler cannot cope. This problem will go away once R 2.12 is released as it requires gcc / g++ 4.5. 2010-07-25 Dirk Eddelbuettel * inst/include/* : upgrade to armadillo 0.9.52 "Monkey Wrench" * src/fastLm.cpp: Switch from inv() (which now throws a warning on (near) singular matrices and returns an empty matrix) to the Moore-Penrose pseudo-inverse pinv() which allows us to continue the example from the manual page. Of course, for standard use inv() is doing the right thing by issueing the warning. 2010-06-14 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.3 2010-06-14 Romain Francois * inst/include/RcppArmadilloConfig.h: Addition cconfig helping suncc 2010-06-09 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.2 2010-06-02 Romain Francois * inst/include/* : upgrade to armadillo 0.9.10 * inst/include/* : support for new mtOp and mtGlue, introduced in armadillo 0.9.10 2010-05-27 Romain Francois * R/flags.R: added RcppArmadillo:::CxxFlags() 2010-05-19 Romain Francois * DESCRIPTION: Release 0.2.1 * src/fastLm.cpp: Rename stderr to std_err 2010-05-18 Dirk Eddelbuettel * DESCRIPTION: Release 0.2.0 2010-05-18 Douglas Bates * man/fastLm/Rd: Added rank-deficient example to illustrate possible problems with fastLmPure() and fastLm() * src/fastLm/cpp: Compute sig2 via std::inner_product 2010-05-17 Dirk Eddelbuettel * inst/include/*: updated to Armadillo 0.9.8 2010-05-17 Romain Francois * inst/include/RcppArmadillo.h: workaround for win64 2010-05-13 Dirk Eddelbuettel * R/fastLm.R: fastLm() is now generic and has a formula interface as well as methods for print, summary, predict to behave like a standard model fitting function * R/fastLm.Rd: Added documentation for new methods * src/fastLm.cpp: Small additions to returned parameters to support new functionality 2010-05-04 Romain Francois * R/RcppArmadillo.package.skeleton.R: new package skeleton function similar to Rcpp::Rcpp.package.skeleton but targetting use of RcppArmadillo * README: removed and promoted to additional documentation in ?RcppArmadillo 2010-05-03 Dirk Eddelbuettel * inst/include/* : updated to armadillo 0.9.6 2010-04-03 Dirk Eddelbuettel * DESCRIPTION: Remove OS_type restriction now that RcppArmadillo includes Armadillo headers, add Doug to Authors and Maintainers 2010-04-03 Douglas Bates * inst/include/armadillo: Added the armadillo headers and the armadillo_bits directory. This is from the armadillo sources with only the armadillo_bits/config.hpp file modified. * configure: and many other configuration files. Removed the foo.in files, modified cleanup not to remove the target files. 2010-03-20 Dirk Eddelbuettel * src/fastLm.cpp: Small fix for Armadillo 0.8.2 2010-03-17 Romain Francois * src/fastLm.cpp: added some arma:: prefix * src/RcppArmadillo.cpp: update examples to use make_list and showcase various ways to use them : Named(.)=., _[.] = , Named( ., . ) 2010-03-11 Dirk Eddelbuettel * DESCRIPTION: Release 0.1.0 and initial CRAN upload 2010-03-03 Dirk Eddelbuettel * src/fastLm.cpp: Moved into its own file, some more polish 2010-03-03 Romain Francois * inst/include/RcppArmadillo.h: avoid an extra memory copy when possible (i.e. in wrap( eGlue) and wrap( eOp ) when the elem_type is int or double). * inst/include/RcppArmadilloDefines.in.h added the SCALAR macro to take care of the 0.9.0 api change * src/RcppArmadillo.cpp : fix a runtime error uisng the SCALAR macro 2010-03-02 Dirk Eddelbuettel * src/RcppArmadillo.cpp: Added bare-bones 'fastLm' function * R/fastLm.R: Added fastLm R wrapper for C++ fastLm * man/fastLm.Rd: Added manual page * inst/unitTests/runit.RcppArmadillo.R: Added unit test * NAMESPACE: Made fastLm visible 2010-03-02 Romain Francois * inst/include/RcppArmadillo.h: support for Armadillo 0.9.* 2010-03-01 Dirk Eddelbuettel * configure.in: Add configure support to test for version 0.9.0 2010-02-23 Romain Francois * inst/include/RcppArmadillo.h: support for wrap( arma::Glue ) and wrap( arma::Op ) enabling wrap()'ing arbitrary expressions involving arma::Mat objects, for example wrap( m1 + m2 ), or wrap( -m1 ) * inst/unitTests/runit.RcppArmadillo.R: new unit test for wrap( Glue ) and wrap( Op ) 2010-02-20 Dirk Eddelbuettel * configure.in: Add configure support to test for presence of 'armadillo' header and working 'libarmadillo' library; and a test for version 0.7.0 or higher (for Cube() type) * src/Makevars.in: Setup to be filled-in from configure * src/RcppArmadilloDefines.h.in: Idem * cleanup: Added to remove configure-generated files * R/flags.R: Small cleanups * src/RcppArmadillo.h: Use the #define ARMA_HAS_CUBE from the autogenerated header, reindent using Emacs' defaults 2010-02-19 Dirk Eddelbuettel * DESCRIPTION: Restrict to 'OS_type: unix' for now, set Date: as an SVN property 2010-02-19 Romain Francois * added support for field where T is wrappable 2010-02-17 Romain Francois * added support for as> as> and as> with T in : int, double, float, unsigned int * added untested support for wrap( Cube ) 2010-02-16 Dirk Eddelbuettel * Initial package structure based on first proof-of-concept 2010-02-16 Romain Francois * initial version, covering wrap(Mat), wrap(Col), wrap(Row) RcppArmadillo/man/0000755000176000001440000000000012253723621013611 5ustar ripleyusersRcppArmadillo/man/RcppArmadillo.package.skeleton.Rd0000644000176000001440000000501212253723621022044 0ustar ripleyusers\name{RcppArmadillo.package.skeleton} \alias{RcppArmadillo.package.skeleton} \title{ Create a skeleton for a new package that intends to use RcppArmadillo } \description{ \code{RcppArmadillo.package.skeleton} automates the creation of a new source package that intends to use features of RcppArmadilo. It is based on the \link[utils]{package.skeleton} function which it executes first. } \usage{ RcppArmadillo.package.skeleton(name = "anRpackage", list = character(), environment = .GlobalEnv, path = ".", force = FALSE, namespace = TRUE, code_files = character(), example_code = TRUE) } \arguments{ \item{name}{See \link[utils]{package.skeleton}} \item{list}{See \link[utils]{package.skeleton}} \item{environment}{See \link[utils]{package.skeleton}} \item{path}{See \link[utils]{package.skeleton}} \item{force}{See \link[utils]{package.skeleton}} \item{namespace}{See \link[utils]{package.skeleton}} \item{code_files}{See \link[utils]{package.skeleton}} \item{example_code}{If TRUE, example c++ code using RcppArmadillo is added to the package} } \details{ In addition to \link[utils]{package.skeleton} : The \samp{DESCRIPTION} file gains a Depends line requesting that the package depends on Rcpp and RcppArmadillo and a LinkingTo line so that the package finds Rcpp and RcppArmadillo header files. The \samp{NAMESPACE}, if any, gains a \code{useDynLib} directive. The \samp{src} directory is created if it does not exists and a \samp{Makevars} file is added setting the environment variable \samp{PKG_LIBS} to accomodate the necessary flags to link with the Rcpp library. If the \code{example_code} argument is set to \code{TRUE}, example files \samp{rcpparma_hello_world.h} and \samp{rcpparma_hello_world.cpp} are also created in the \samp{src}. An R file \samp{rcpparma_hello_world.R} is expanded in the \samp{R} directory, the \code{rcpparma_hello_world} function defined in this files makes use of the C++ function \samp{rcpparma_hello_world} defined in the C++ file. These files are given as an example and should eventually by removed from the generated package. } \value{ Nothing, used for its side effects } \seealso{ \link[utils]{package.skeleton} } \references{ Read the \emph{Writing R Extensions} manual for more details. Once you have created a \emph{source} package you need to install it: see the \emph{R Installation and Administration} manual, \code{\link{INSTALL}} and \code{\link{install.packages}}. } \examples{ \dontrun{ RcppArmadillo.package.skeleton( "foobar" ) } } \keyword{ programming } RcppArmadillo/man/fastLm.Rd0000644000176000001440000000742612253723621015337 0ustar ripleyusers\name{fastLm} \alias{fastLm} \alias{fastLmPure} \alias{fastLm.default} \alias{fastLm.formula} \concept{regression} \title{Bare-bones linear model fitting function} \description{ \code{fastLm} estimates the linear model using the \code{solve} function of \code{Armadillo} linear algebra library. } \usage{ fastLmPure(X, y) fastLm(X, \dots) \method{fastLm}{default}(X, y, \dots) \method{fastLm}{formula}(formula, data = list(), \dots) } \arguments{ \item{y}{a vector containing the explained variable.} \item{X}{a model matrix.} \item{formula}{a symbolic description of the model to be fit.} \item{data}{an optional data frame containing the variables in the model.} \item{\ldots}{not used} } \details{ Linear models should be estimated using the \code{\link{lm}} function. In some cases, \code{\link{lm.fit}} may be appropriate. The \code{fastLmPure} function provides a reference use case of the \code{Armadillo} library via the wrapper functions in the \pkg{RcppArmadillo} package. The \code{fastLm} function provides a more standard implementation of a linear model fit, offering both a default and a formula interface as well as \code{print}, \code{summary} and \code{predict} methods. Lastly, one must be be careful in timing comparisons of \code{\link{lm}} and friends versus this approach based on \code{Armadillo}. The reason that \code{Armadillo} can do something like \code{\link{lm.fit}} faster than the functions in the stats package is because \code{Armadillo} uses the Lapack version of the QR decomposition while the stats package uses a \emph{modified} Linpack version. Hence \code{Armadillo} uses level-3 BLAS code whereas the stats package uses level-1 BLAS. However, \code{Armadillo} will either fail or, worse, produce completely incorrect answers on rank-deficient model matrices whereas the functions from the stats package will handle them properly due to the modified Linpack code. An example of the type of situation requiring extra care in checking for rank deficiency is a two-way layout with missing cells (see the examples section). These cases require a special pivoting scheme of \dQuote{pivot only on (apparent) rank deficiency} which is not part of conventional linear algebra software. } \value{ \code{fastLmPure} returns a list with three components: \item{coefficients}{a vector of coefficients} \item{stderr}{a vector of the (estimated) standard errors of the coefficient estimates} \item{df.residual}{a scalar denoting the degrees of freedom in the model} \code{fastLm} returns a richer object which also includes the residuals, fitted values and call argument similar to the \code{\link{lm}} or \code{\link[MASS]{rlm}} functions.. } \seealso{\code{\link{lm}}, \code{\link{lm.fit}}} \references{Armadillo project: \url{http://arma.sourceforge.net/}} \author{ Armadillo is written by Conrad Sanderson. RcppArmadillo is written by Romain Francois, Dirk Eddelbuettel and Douglas Bates. } \examples{ data(trees, package="datasets") ## bare-bones direct interface flm <- fastLmPure( cbind(1, log(trees$Girth)), log(trees$Volume) ) print(flm) ## standard R interface for formula or data returning object of class fastLm flmmod <- fastLm( log(Volume) ~ log(Girth), data=trees) summary(flmmod) ## case where fastLm breaks down dd <- data.frame(f1 = gl(4, 6, labels = LETTERS[1:4]), f2 = gl(3, 2, labels = letters[1:3]))[-(7:8), ] xtabs(~ f2 + f1, dd) # one missing cell mm <- model.matrix(~ f1 * f2, dd) kappa(mm) # large, indicating rank deficiency set.seed(1) dd$y <- mm \%*\% seq_len(ncol(mm)) + rnorm(nrow(mm), sd = 0.1) summary(lm(y ~ f1 * f2, dd)) # detects rank deficiency summary(fastLm(y ~ f1 * f2, dd)) # some huge coefficients } \keyword{regression} RcppArmadillo/man/RcppArmadillo-package.Rd0000644000176000001440000001002412253723621020217 0ustar ripleyusers\name{RcppArmadillo-package} \alias{RcppArmadillo-package} \alias{RcppArmadillo} \alias{RcppArmadilloExample} \docType{package} \title{ Rcpp/Armadillo bridge } \description{ The package eases the integration of Armadillo types with Rcpp. } \section{Armadillo}{ \code{Armadillo} is a C++ linear algebra library (matrix maths) aiming towards a good balance between speed and ease of use. Integer, floating point and complex numbers are supported, as well as a subset of trigonometric and statistics functions. Various matrix decompositions are provided through optional integration with LAPACK and ATLAS libraries. A delayed evaluation approach is employed (during compile time) to combine several operations into one and reduce (or eliminate) the need for temporaries. This is accomplished through recursive templates and template meta-programming. This library is useful if C++ has been decided as the language of choice (due to speed and/or integration capabilities), rather than another language like Matlab or Octave. It is distributed under a license that is useful in both open-source and commercial contexts. Armadillo is primarily developed at NICTA (Australia), with contributions from around the world. } \section{RcppArmadillo}{ \code{RcppArmadillo} acts as a bridge between \code{Rcpp} and \code{Armadillo}, allowing the programmer to write code using armadillo classes that integrate seemlessly with \code{Rcpp}. } \section{Using RcppArmadillo}{ The simplest way to get started is to create a skeleton of a package using \code{RcppArmadillo}, this is done by the \code{\link{RcppArmadillo.package.skeleton}} function. The important steps are \itemize{ \item Include the \code{RcppArmadillo.h} header file, which also includes armadillo.h \item Depend and link to Rcpp and RcppArmadillo by adding these lines to the DESCRIPTION file: \preformatted{ Depends: Rcpp (>= 0.8.0), RcppArmadillo (>= 0.2.0) LinkingTo: Rcpp, RcppArmadillo } \item Link against the Rcpp, blas and lapack libraries, by adding this line in the Makevars \preformatted{PKG_LIBS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" ) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) } and this line to the Makevars.win: \preformatted{PKG_LIBS = $(shell $(R_HOME)/bin${R_ARCH_BIN}/Rscript.exe -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) } } } \section{Options: ATLAS and Boost}{ Armadillo can optionally use atlas and boost. Please refer to the Armadillo documentation \url{http://arma.sourceforge.net/} \code{RcppArmadillo} does not force these features. it is up to the third party package to enable these them for their package. If your package wants to make use of these features, you can add a subset of these lines before \code{#include } \preformatted{ #define ARMA_USE_BOOST #define ARMA_USE_BOOST_DATE #define ARMA_USE_ATLAS } when you do so, you must make sure that the corresponding features are available, which typically involves writing a configure file. Refer to Writing R Extensions for the procedure. } \section{Support}{ Please use the Rcpp-devel mailing list on r-forge for questions about RcppArmadillo (subscribe first). \url{https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel} Questions about armadillo itself should be directed to the armadillo forum \url{http://sourceforge.net/apps/phpbb/arma/} } \author{ For RcppArmadillo: Romain Francois, Dirk Eddelbuettel and Doug Bates Maintainer: Romain, Dirk and Doug For Armadillo: Conrad Sanderson } \references{ Armadillo project: \url{http://arma.sourceforge.net/} Conrad Sanderson, \href{http://arma.sourceforge.net/armadillo_nicta_2010.pdf}{Armadillo: An Open Source C++ Linear Algebra Library for Fast Prototyping and Computationally Intensive Experiments}. Technical Report, NICTA, 2010. } \keyword{ package } \keyword{ programming } \keyword{ interface } RcppArmadillo/cleanup0000755000176000001440000000117512253723621014417 0ustar ripleyusers#!/bin/sh rm -f config.log config.status confdefs.h \ src/*.o src/*.so \ vignettes/RcppArmadillo-unitTests.out \ vignettes/RcppArmadillo-unitTests.aux \ vignettes/RcppArmadillo-unitTests.log \ vignettes/RcppArmadillo-intro.out \ vignettes/RcppArmadillo*.log \ vignettes/RcppArmadillo*.aux \ vignettes/RcppArmadillo*.out \ vignettes/RcppArmadillo*.tex \ vignettes/RcppArmadillo-*.pdf \ vignettes/*.blg \ vignettes/*.bbl \ vignettes/*~ \ */*~ *~ \ inst/include/RcppArmadilloLapack.h rm -rf autom4te.cache/ \ vignettes/auto/