本文整理汇总了C++中Proxy类的典型用法代码示例。如果您正苦于以下问题:C++ Proxy类的具体用法?C++ Proxy怎么用?C++ Proxy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Proxy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: arma_extra_debug_sigprint
inline
bool
op_unique::apply_helper(Mat<typename T1::elem_type>& out, const Proxy<T1>& P)
{
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();
if(n_elem == 0) { out.set_size(n_rows, n_cols); return true; }
if(n_elem == 1)
{
const eT tmp = (Proxy<T1>::use_at) ? P.at(0,0) : P[0];
out.set_size(n_rows, n_cols);
out[0] = tmp;
return true;
}
Mat<eT> X(n_elem,1);
eT* X_mem = X.memptr();
if(Proxy<T1>::use_at == false)
{
typename Proxy<T1>::ea_type Pea = P.get_ea();
for(uword i=0; i<n_elem; ++i)
{
const eT val = Pea[i];
if(arma_isnan(val)) { out.reset(); return false; }
X_mem[i] = val;
}
}
else
{
for(uword col=0; col < n_cols; ++col)
for(uword row=0; row < n_rows; ++row)
{
const eT val = P.at(row,col);
if(arma_isnan(val)) { out.reset(); return false; }
(*X_mem) = val; X_mem++;
}
X_mem = X.memptr();
}
arma_unique_comparator<eT> comparator;
std::sort( X.begin(), X.end(), comparator );
uword N_unique = 1;
for(uword i=1; i < n_elem; ++i)
{
const eT a = X_mem[i-1];
const eT b = X_mem[i ];
const eT diff = a - b;
if(diff != eT(0)) { ++N_unique; }
}
uword out_n_rows;
uword out_n_cols;
if( (n_rows == 1) || (n_cols == 1) )
{
if(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;
}
out.set_size(out_n_rows, out_n_cols);
eT* out_mem = out.memptr();
if(n_elem > 0) { (*out_mem) = X_mem[0]; out_mem++; }
//.........这里部分代码省略.........
示例2: lock
void ListenersBase::remove_void (void* const listener)
{
ReadWriteMutex::ScopedWriteLockType lock (m_groups_mutex);
// Make sure the listener exists
#if VF_DEBUG
{
bool exists = false;
for (Groups::iterator iter = m_groups.begin(); iter != m_groups.end();)
{
Group* group = &(*iter++);
// this should never happen while we hold the mutex
jassert (!group->empty ());
if (group->contains (listener))
{
jassert (!exists); // added twice?
exists = true;
// keep going to make sure there are no empty groups
}
}
jassert (exists);
}
#endif
// Find the group and remove
for (Groups::iterator iter = m_groups.begin(); iter != m_groups.end();)
{
Group::Ptr group = &(*iter++);
// If the listener is in there, take it out.
if (group->remove (listener))
{
// Are we the last listener?
if (group->empty ())
{
// Tell proxies to remove the group
{
ReadWriteMutex::ScopedWriteLockType lock (m_proxies_mutex);
for (Proxies::iterator iter = m_proxies.begin (); iter != m_proxies.end ();)
{
Proxy* proxy = &(*iter++);
proxy->remove (group);
}
}
// Remove it from the list and manually release
// the reference since the list uses raw pointers.
m_groups.erase (m_groups.iterator_to (*group.getObject ()));
group->decReferenceCount();
// It is still possible for the group to exist at this
// point in a thread queue but it will get processed,
// do nothing, and release its own final reference.
}
break;
}
}
}
示例3: arma_sort_index_helper
inline
bool
arma_sort_index_helper(Mat<uword>& out, const Proxy<T1>& P, const uword sort_type, typename arma_not_cx<typename T1::elem_type>::result* junk = 0)
{
arma_extra_debug_sigprint();
arma_ignore(junk);
typedef typename T1::elem_type eT;
const uword n_elem = P.get_n_elem();
out.set_size(n_elem, 1);
std::vector< arma_sort_index_packet<eT, uword> > packet_vec(n_elem);
if(Proxy<T1>::prefer_at_accessor == false)
{
for(uword i=0; i<n_elem; ++i)
{
const eT val = P[i];
if(arma_isnan(val)) { out.reset(); return false; }
packet_vec[i].val = val;
packet_vec[i].index = i;
}
}
else
{
const uword n_rows = P.get_n_rows();
const uword n_cols = P.get_n_cols();
uword i = 0;
for(uword col=0; col < n_cols; ++col)
for(uword row=0; row < n_rows; ++row)
{
const eT val = P.at(row,col);
if(arma_isnan(val)) { out.reset(); return false; }
packet_vec[i].val = val;
packet_vec[i].index = i;
++i;
}
}
if(sort_type == 0)
{
// ascend
arma_sort_index_helper_ascend comparator;
if(sort_stable == false)
{
std::sort( packet_vec.begin(), packet_vec.end(), comparator );
}
else
{
std::stable_sort( packet_vec.begin(), packet_vec.end(), comparator );
}
}
else
{
// descend
arma_sort_index_helper_descend comparator;
if(sort_stable == false)
{
std::sort( packet_vec.begin(), packet_vec.end(), comparator );
}
else
{
std::stable_sort( packet_vec.begin(), packet_vec.end(), comparator );
}
}
uword* out_mem = out.memptr();
for(uword i=0; i<n_elem; ++i)
{
out_mem[i] = packet_vec[i].index;
}
return true;
}
示例4: main
int main() {
Proxy p;
p.f();
p.g();
p.h();
} ///:~
示例5: PyTuple_Size
//-------------------------------------------------------------------------------------
PyObject* Proxy::__py_pyStreamStringToClient(PyObject* self, PyObject* args)
{
uint16 currargsSize = PyTuple_Size(args);
Proxy* pobj = static_cast<Proxy*>(self);
if(pobj->clientMailbox() == NULL)
{
PyErr_Format(PyExc_AssertionError,
"Proxy::streamStringToClient: has no client.");
PyErr_PrintEx(0);
return NULL;
}
if(currargsSize > 3 || currargsSize == 0)
{
PyErr_Format(PyExc_AssertionError,
"Proxy::streamStringToClient: args max require 3, gived %d! is script[%s].\n",
currargsSize, pobj->scriptName());
PyErr_PrintEx(0);
return NULL;
}
PyObject* pyData = NULL;
PyObject* pyDesc = NULL;
int16 id = -1;
if(currargsSize == 1)
{
if(PyArg_ParseTuple(args, "O", &pyData) == -1)
{
PyErr_Format(PyExc_TypeError, "Proxy::streamStringToClient: args is error!");
PyErr_PrintEx(0);
return NULL;
}
}
else if(currargsSize == 2)
{
if(PyArg_ParseTuple(args, "O|O", &pyData, &pyDesc) == -1)
{
PyErr_Format(PyExc_TypeError, "Proxy::streamStringToClient: args is error!");
PyErr_PrintEx(0);
return NULL;
}
}
else if(currargsSize == 3)
{
if(PyArg_ParseTuple(args, "O|O|H", &pyData, &pyDesc, &id) == -1)
{
PyErr_Format(PyExc_TypeError, "Proxy::streamStringToClient: args is error!");
PyErr_PrintEx(0);
return NULL;
}
}
char* pDescr = NULL;
if(pDescr != NULL)
{
wchar_t* PyUnicode_AsWideCharStringRet1 = PyUnicode_AsWideCharString(pyDesc, NULL);
pDescr = strutil::wchar2char(PyUnicode_AsWideCharStringRet1);
PyMem_Free(PyUnicode_AsWideCharStringRet1);
}
if(pDescr && strlen(pDescr) > 255)
{
PyErr_Format(PyExc_TypeError, "Proxy::streamFileToClient: the descr-size(%d > 255)!",
strlen(pDescr));
PyErr_PrintEx(0);
free(pDescr);
return NULL;
}
int16 rid = pobj->streamStringToClient(pyData,
(pDescr == NULL ? "" : pDescr),
id);
if(pDescr)
free(pDescr);
return PyLong_FromLong(rid);
}
示例6: arma_extra_debug_sigprint
inline
typename arma_cx_only<typename T1::elem_type>::result
op_max::max(const Base<typename T1::elem_type,T1>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
typedef typename get_pod_type<eT>::result T;
const Proxy<T1> 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<T>();
if(Proxy<T1>::prefer_at_accessor == false)
{
typedef typename Proxy<T1>::ea_type ea_type;
ea_type A = P.get_ea();
uword index = 0;
for(uword i=0; i<n_elem; ++i)
{
const T tmp = std::abs(A[i]);
if(tmp > 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);
}
}
示例7: PropertyAttribute
Handle<Value> Proxy::proxyConstructor(const Arguments& args)
{
HandleScope scope;
JNIEnv *env = JNIScope::getEnv();
Local<Object> jsProxy = args.Holder();
Handle<Object> properties = Object::New();
jsProxy->Set(propertiesSymbol, properties, PropertyAttribute(DontEnum));
Handle<Object> prototype = jsProxy->GetPrototype()->ToObject();
Handle<Function> constructor = Handle<Function>::Cast(prototype->Get(constructorSymbol));
jclass javaClass = (jclass) External::Unwrap(constructor->Get(javaClassSymbol));
// If ProxyFactory::createV8Proxy invoked us, unwrap
// the pre-created Java proxy it sent.
jobject javaProxy = ProxyFactory::unwrapJavaProxy(args);
bool deleteRef = false;
if (!javaProxy) {
javaProxy = ProxyFactory::createJavaProxy(javaClass, jsProxy, args);
deleteRef = true;
}
JNIUtil::logClassName("Create proxy: %s", javaClass);
Proxy *proxy = new Proxy(javaProxy);
proxy->Wrap(jsProxy);
int length = args.Length();
if (length > 0 && args[0]->IsObject()) {
/*
Handle<Value> argsStr = V8Util::jsonStringify(args[0]);
String::Utf8Value str(argsStr);
LOGV(TAG, " with args: %s", *str);
*/
bool extend = true;
Handle<Object> createProperties = args[0]->ToObject();
Local<String> constructorName = createProperties->GetConstructorName();
if (strcmp(*String::Utf8Value(constructorName), "Arguments") == 0) {
extend = false;
int32_t argsLength = createProperties->Get(String::New("length"))->Int32Value();
if (argsLength > 1) {
Handle<Value> properties = createProperties->Get(1);
if (properties->IsObject()) {
extend = true;
createProperties = properties->ToObject();
}
}
}
if (extend) {
Handle<Array> names = createProperties->GetOwnPropertyNames();
int length = names->Length();
for (int i = 0; i < length; ++i) {
Handle<Value> name = names->Get(i);
Handle<Value> value = createProperties->Get(name);
bool isProperty = true;
if (name->IsString()) {
Handle<String> nameString = name->ToString();
if (!jsProxy->HasRealNamedCallbackProperty(nameString)
&& !jsProxy->HasRealNamedProperty(nameString)) {
jsProxy->Set(name, value);
isProperty = false;
}
}
if (isProperty) {
properties->Set(name, value);
}
}
}
}
if (!args.Data().IsEmpty() && args.Data()->IsFunction()) {
Handle<Function> proxyFn = Handle<Function>::Cast(args.Data());
Handle<Value> *fnArgs = new Handle<Value>[length];
for (int i = 0; i < length; ++i) {
fnArgs[i] = args[i];
}
proxyFn->Call(jsProxy, length, fnArgs);
}
if (deleteRef) {
JNIEnv *env = JNIScope::getEnv();
if (env) {
env->DeleteLocalRef(javaProxy);
}
}
return jsProxy;
}
示例8: arma_extra_debug_sigprint
inline
void
op_any::apply_helper(Mat<uword>& out, const Proxy<T1>& 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<T1>::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<typename Proxy<T1>::stored_type>::value == true)
{
const unwrap<typename Proxy<T1>::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<typename Proxy<T1>::stored_type>::value == true)
{
const unwrap<typename Proxy<T1>::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); }
}
}
}
}
}
示例9: arma_extra_debug_sigprint
inline
typename arma_not_cx<typename T1::elem_type>::result
op_min::min_with_index(const Proxy<T1>& P, uword& index_of_min_val)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const uword n_elem = P.get_n_elem();
if(n_elem == 0)
{
arma_debug_check(true, "min(): object has no elements");
return Datum<eT>::nan;
}
eT best_val = priv::most_pos<eT>();
uword best_index = 0;
if(Proxy<T1>::use_at == false)
{
typedef typename Proxy<T1>::ea_type ea_type;
ea_type A = P.get_ea();
for(uword i=0; i<n_elem; ++i)
{
const eT tmp = A[i];
if(tmp < best_val) { best_val = tmp; best_index = 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)
{
const eT tmp = P.at(0,i);
if(tmp < best_val) { best_val = tmp; best_index = i; }
}
}
else
if(n_cols == 1)
{
for(uword i=0; i < n_rows; ++i)
{
const eT tmp = P.at(i,0);
if(tmp < best_val) { best_val = tmp; best_index = i; }
}
}
else
{
uword count = 0;
for(uword col=0; col < n_cols; ++col)
for(uword row=0; row < n_rows; ++row)
{
const eT tmp = P.at(row,col);
if(tmp < best_val) { best_val = tmp; best_index = count; }
++count;
}
}
}
index_of_min_val = best_index;
return best_val;
}
示例10: eT
arma_hot
inline
void
op_mean::apply_noalias_proxy(Mat<typename T1::elem_type>& out, const Proxy<T1>& P, const uword dim)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
typedef typename get_pod_type<eT>::result T;
const uword P_n_rows = P.get_n_rows();
const uword P_n_cols = P.get_n_cols();
if(dim == 0)
{
out.set_size((P_n_rows > 0) ? 1 : 0, P_n_cols);
if(P_n_rows == 0) { return; }
eT* out_mem = out.memptr();
for(uword col=0; col < P_n_cols; ++col)
{
eT val1 = eT(0);
eT val2 = eT(0);
uword i,j;
for(i=0, j=1; j < P_n_rows; i+=2, j+=2)
{
val1 += P.at(i,col);
val2 += P.at(j,col);
}
if(i < P_n_rows)
{
val1 += P.at(i,col);
}
out_mem[col] = (val1 + val2) / T(P_n_rows);
}
}
else
if(dim == 1)
{
out.zeros(P_n_rows, (P_n_cols > 0) ? 1 : 0);
if(P_n_cols == 0) { return; }
eT* out_mem = out.memptr();
for(uword col=0; col < P_n_cols; ++col)
for(uword row=0; row < P_n_rows; ++row)
{
out_mem[row] += P.at(row,col);
}
out /= T(P_n_cols);
}
if(out.is_finite() == false)
{
// TODO: replace with dedicated handling to avoid unwrapping
op_mean::apply_noalias_unwrap(out, P, dim);
}
}
示例11: arma_extra_debug_sigprint
inline
void
op_all::apply_helper(Mat<uword>& out, const Proxy<T1>& 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<T1>::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<typename Proxy<T1>::stored_type>::value == true)
{
const unwrap<typename Proxy<T1>::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<typename Proxy<T1>::stored_type>::value == true)
{
const unwrap<typename Proxy<T1>::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);
}
}
}
示例12: arma_extra_debug_sigprint
inline
void
op_unique::apply(Mat<typename T1::elem_type>& out, const Op<T1, op_unique>& X)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
const Proxy<T1> 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<eT> lvec(in_n_elem);
if(Proxy<T1>::prefer_at_accessor == false)
{
typename Proxy<T1>::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;
//.........这里部分代码省略.........
示例13: unwrap
Handle<Value> Proxy::proxyOnPropertiesChanged(const Arguments& args)
{
HandleScope scope;
Handle<Object> jsProxy = args.Holder();
if (args.Length() < 1 || !args[0]->IsArray()) {
return JSException::Error("Proxy.propertiesChanged requires a list of lists of property name, the old value, and the new value");
}
JNIEnv *env = JNIScope::getEnv();
if (!env) {
return JSException::GetJNIEnvironmentError();
}
Proxy *proxy = unwrap(jsProxy);
if (!proxy) {
return JSException::Error("Failed to unwrap Proxy instance");
}
Local<Array> changes = Local<Array>::Cast(args[0]);
uint32_t length = changes->Length();
jobjectArray jChanges = env->NewObjectArray(length, JNIUtil::objectClass, NULL);
for (uint32_t i = 0; i < length; ++i) {
Local<Array> change = Local<Array>::Cast(changes->Get(i));
Local<String> name = change->Get(INDEX_NAME)->ToString();
Local<Value> oldValue = change->Get(INDEX_OLD_VALUE);
Local<Value> value = change->Get(INDEX_VALUE);
jobjectArray jChange = env->NewObjectArray(3, JNIUtil::objectClass, NULL);
jstring jName = TypeConverter::jsStringToJavaString(name);
env->SetObjectArrayElement(jChange, INDEX_NAME, jName);
env->DeleteLocalRef(jName);
bool isNew;
jobject jOldValue = TypeConverter::jsValueToJavaObject(oldValue, &isNew);
env->SetObjectArrayElement(jChange, INDEX_OLD_VALUE, jOldValue);
if (isNew) {
env->DeleteLocalRef(jOldValue);
}
jobject jValue = TypeConverter::jsValueToJavaObject(value, &isNew);
env->SetObjectArrayElement(jChange, INDEX_VALUE, jValue);
if (isNew) {
env->DeleteLocalRef(jValue);
}
env->SetObjectArrayElement(jChanges, i, jChange);
env->DeleteLocalRef(jChange);
}
jobject javaProxy = proxy->getJavaObject();
env->CallVoidMethod(javaProxy, JNIUtil::krollProxyOnPropertiesChangedMethod, jChanges);
env->DeleteLocalRef(jChanges);
if (!JavaObject::useGlobalRefs) {
env->DeleteLocalRef(javaProxy);
}
return Undefined();
}
示例14: arma_extra_debug_sigprint
inline
bool
op_pinv::apply_direct(Mat<typename T1::elem_type>& out, const Base<typename T1::elem_type,T1>& expr, typename T1::pod_type tol, const bool use_divide_and_conquer)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
typedef typename T1::pod_type T;
arma_debug_check((tol < T(0)), "pinv(): tolerance must be >= 0");
const Proxy<T1> P(expr.get_ref());
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 true;
}
// economical SVD decomposition
Mat<eT> U;
Col< T> s;
Mat<eT> 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.soft_reset();
return false;
}
const uword s_n_elem = s.n_elem;
const T* s_mem = s.memptr();
// set tolerance to default if it hasn't been specified
if( (tol == T(0)) && (s_n_elem > 0) )
{
tol = (std::max)(n_rows, n_cols) * s_mem[0] * std::numeric_limits<T>::epsilon();
}
uword count = 0;
for(uword i = 0; i < s_n_elem; ++i)
{
count += (s_mem[i] >= tol) ? uword(1) : uword(0);
}
if(count > 0)
{
Col<T> 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);
}
return true;
}
示例15: arma_vec_norm_1
arma_hot
inline
typename T1::pod_type
arma_vec_norm_1(const Proxy<T1>& P)
{
arma_extra_debug_sigprint();
typedef typename T1::pod_type T;
T acc = T(0);
if(Proxy<T1>::prefer_at_accessor == false)
{
typename Proxy<T1>::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<N; i+=2, j+=2)
{
acc1 += std::abs(A[i]);
acc2 += std::abs(A[j]);
}
if(i < N)
{
acc1 += std::abs(A[i]);
}
acc = acc1 + acc2;
}
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)
{
acc += std::abs(P.at(0,col));
}
}
else
{
for(uword col=0; col<n_cols; ++col)
{
uword i,j;
for(i=0, j=1; j<n_rows; i+=2, j+=2)
{
acc += std::abs(P.at(i,col));
acc += std::abs(P.at(j,col));
}
if(i < n_rows)
{
acc += std::abs(P.at(i,col));
}
}
}
}
return acc;
}